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
|
|---|---|---|---|---|---|---|---|---|
spiritlinxl/BTCGPU
|
test/functional/rpcnamedargs.py
|
33
|
1288
|
#!/usr/bin/env python3
# Copyright (c) 2016 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Test using named arguments for RPCs."""
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import (
assert_equal,
assert_raises_jsonrpc,
)
class NamedArgumentTest(BitcoinTestFramework):
"""
Test named arguments on RPC calls.
"""
def __init__(self):
super().__init__()
self.setup_clean_chain = False
self.num_nodes = 1
def run_test(self):
node = self.nodes[0]
h = node.help(command='getinfo')
assert(h.startswith('getinfo\n'))
assert_raises_jsonrpc(-8, 'Unknown named parameter', node.help, random='getinfo')
h = node.getblockhash(height=0)
node.getblock(blockhash=h)
assert_equal(node.echo(), [])
assert_equal(node.echo(arg0=0,arg9=9), [0] + [None]*8 + [9])
assert_equal(node.echo(arg1=1), [None, 1])
assert_equal(node.echo(arg9=None), [None]*10)
assert_equal(node.echo(arg0=0,arg3=3,arg9=9), [0] + [None]*2 + [3] + [None]*5 + [9])
if __name__ == '__main__':
NamedArgumentTest().main()
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
19,
199,
3,
1898,
334,
67,
9,
7800,
710,
21158,
11672,
19782,
199,
3,
17484,
1334,
314,
10697,
2032,
4190,
12,
1937,
314,
23073,
199,
3,
570,
9685,
503,
1455,
921,
1544,
14,
16374,
14,
1308,
15,
2383,
15,
1147,
13,
1682,
14,
8624,
14,
199,
624,
774,
1808,
4310,
2368,
367,
11785,
83,
1041,
199,
199,
504,
511,
63,
4857,
14,
396,
63,
4857,
492,
21158,
26203,
199,
504,
511,
63,
4857,
14,
1974,
492,
334,
272,
702,
63,
1452,
12,
272,
702,
63,
3536,
63,
31395,
12,
199,
9,
421,
199,
533,
16198,
5201,
774,
8,
4734,
9061,
26203,
304,
272,
408,
272,
1379,
4310,
2368,
641,
11785,
4882,
14,
272,
408,
339,
347,
636,
826,
721,
277,
304,
267,
1613,
11027,
826,
4533,
267,
291,
14,
2758,
63,
3118,
63,
4429,
275,
756,
267,
291,
14,
1507,
63,
2415,
275,
413,
339,
347,
1255,
63,
396,
8,
277,
304,
267,
1031,
275,
291,
14,
2415,
59,
16,
61,
267,
394,
275,
1031,
14,
3437,
8,
1531,
534,
32286,
358,
267,
702,
8,
72,
14,
2460,
360,
32286,
60,
78,
1333,
398,
702,
63,
3536,
63,
31395,
2801,
24,
12,
283,
5912,
4310,
2725,
297,
1031,
14,
3437,
12,
2196,
534,
32286,
358,
398,
394,
275,
1031,
14,
17785,
2227,
8,
3333,
29,
16,
9,
267,
1031,
14,
17785,
8,
25848,
29,
72,
9,
398,
702,
63,
1452,
8,
932,
14,
7878,
1062,
3073,
267,
702,
63,
1452,
8,
932,
14,
7878,
8,
1273,
16,
29,
16,
12,
1273,
25,
29,
25,
395,
359,
16,
61,
435,
359,
403,
3672,
24,
435,
359,
25,
566,
267,
702,
63,
1452,
8,
932,
14,
7878,
8,
1273,
17,
29,
17,
395,
359,
403,
12,
413,
566,
267,
702,
63,
1452,
8,
932,
14,
7878,
8,
1273,
25,
29,
403,
395,
359,
403,
3672,
709,
9,
267,
702,
63,
1452,
8,
932,
14,
7878,
8,
1273,
16,
29,
16,
12,
1273,
19,
29,
19,
12,
1273,
25,
29,
25,
395,
359,
16,
61,
435,
359,
403,
3672,
18,
435,
359,
19,
61,
435,
359,
403,
3672,
21,
435,
359,
25,
566,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
16198,
5201,
774,
1252,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
19,
199,
3,
1898,
334,
67,
9,
7800,
710,
21158,
11672,
19782,
199,
3,
17484,
1334,
314,
10697,
2032,
4190,
12,
1937,
314,
23073,
199,
3,
570,
9685,
503,
1455,
921,
1544,
14,
16374,
14,
1308,
15,
2383,
15,
1147,
13,
1682,
14,
8624,
14,
199,
624,
774,
1808,
4310,
2368,
367,
11785,
83,
1041,
199,
199,
504,
511,
63,
4857,
14,
396,
63,
4857,
492,
21158,
26203,
199,
504,
511,
63,
4857,
14,
1974,
492,
334,
272,
702,
63,
1452,
12,
272,
702,
63,
3536,
63,
31395,
12,
199,
9,
421,
199,
533,
16198,
5201,
774,
8,
4734,
9061,
26203,
304,
272,
408,
272,
1379,
4310,
2368,
641,
11785,
4882,
14,
272,
408,
339,
347,
636,
826,
721,
277,
304,
267,
1613,
11027,
826,
4533,
267,
291,
14,
2758,
63,
3118,
63,
4429,
275,
756,
267,
291,
14,
1507,
63,
2415,
275,
413,
339,
347,
1255,
63,
396,
8,
277,
304,
267,
1031,
275,
291,
14,
2415,
59,
16,
61,
267,
394,
275,
1031,
14,
3437,
8,
1531,
534,
32286,
358,
267,
702,
8,
72,
14,
2460,
360,
32286,
60,
78,
1333,
398,
702,
63,
3536,
63,
31395,
2801,
24,
12,
283,
5912,
4310,
2725,
297,
1031,
14,
3437,
12,
2196,
534,
32286,
358,
398,
394,
275,
1031,
14,
17785,
2227,
8,
3333,
29,
16,
9,
267,
1031,
14,
17785,
8,
25848,
29,
72,
9,
398,
702,
63,
1452,
8,
932,
14,
7878,
1062,
3073,
267,
702,
63,
1452,
8,
932,
14,
7878,
8,
1273,
16,
29,
16,
12,
1273,
25,
29,
25,
395,
359,
16,
61,
435,
359,
403,
3672,
24,
435,
359,
25,
566,
267,
702,
63,
1452,
8,
932,
14,
7878,
8,
1273,
17,
29,
17,
395,
359,
403,
12,
413,
566,
267,
702,
63,
1452,
8,
932,
14,
7878,
8,
1273,
25,
29,
403,
395,
359,
403,
3672,
709,
9,
267,
702,
63,
1452,
8,
932,
14,
7878,
8,
1273,
16,
29,
16,
12,
1273,
19,
29,
19,
12,
1273,
25,
29,
25,
395,
359,
16,
61,
435,
359,
403,
3672,
18,
435,
359,
19,
61,
435,
359,
403,
3672,
21,
435,
359,
25,
566,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
16198,
5201,
774,
1252,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
almarklein/bokeh
|
examples/glyphs/donut.py
|
45
|
4204
|
from __future__ import print_function
import base64
from math import pi, sin, cos
from bokeh.browserlib import view
from bokeh.colors import skyblue, seagreen, tomato, orchid, firebrick, lightgray
from bokeh.document import Document
from bokeh.embed import file_html
from bokeh.models.glyphs import Wedge, AnnularWedge, ImageURL, Text
from bokeh.models import ColumnDataSource, Plot, Range1d
from bokeh.resources import INLINE
from bokeh.sampledata.browsers import browsers_nov_2013, icons
df = browsers_nov_2013
xdr = Range1d(start=-2, end=2)
ydr = Range1d(start=-2, end=2)
title = "Web browser market share (November 2013)"
plot = Plot(title=title, x_range=xdr, y_range=ydr, plot_width=800, plot_height=800)
colors = {"Chrome": seagreen, "Firefox": tomato, "Safari": orchid, "Opera": firebrick, "IE": skyblue, "Other": lightgray}
aggregated = df.groupby("Browser").agg(sum)
selected = aggregated[aggregated.Share >= 1].copy()
selected.loc["Other"] = aggregated[aggregated.Share < 1].sum()
browsers = selected.index.tolist()
radians = lambda x: 2*pi*(x/100)
angles = selected.Share.map(radians).cumsum()
end_angles = angles.tolist()
start_angles = [0] + end_angles[:-1]
browsers_source = ColumnDataSource(dict(
start = start_angles,
end = end_angles,
colors = [colors[browser] for browser in browsers ],
))
glyph = Wedge(x=0, y=0, radius=1, line_color="white",
line_width=2, start_angle="start", end_angle="end", fill_color="colors")
plot.add_glyph(browsers_source, glyph)
def polar_to_cartesian(r, start_angles, end_angles):
cartesian = lambda r, alpha: (r*cos(alpha), r*sin(alpha))
points = []
for start, end in zip(start_angles, end_angles):
points.append(cartesian(r, (end + start)/2))
return zip(*points)
first = True
for browser, start_angle, end_angle in zip(browsers, start_angles, end_angles):
versions = df[(df.Browser == browser) & (df.Share >= 0.5)]
angles = versions.Share.map(radians).cumsum() + start_angle
end = angles.tolist() + [end_angle]
start = [start_angle] + end[:-1]
base_color = colors[browser]
fill = [ base_color.lighten(i*0.05) for i in range(len(versions) + 1) ]
text = [ number if share >= 1 else "" for number, share in zip(versions.VersionNumber, versions.Share) ]
x, y = polar_to_cartesian(1.25, start, end)
source = ColumnDataSource(dict(start=start, end=end, fill=fill))
glyph = AnnularWedge(x=0, y=0,
inner_radius=1, outer_radius=1.5, start_angle="start", end_angle="end",
line_color="white", line_width=2, fill_color="fill")
plot.add_glyph(source, glyph)
text_angle = [(start[i]+end[i])/2 for i in range(len(start))]
text_angle = [angle + pi if pi/2 < angle < 3*pi/2 else angle for angle in text_angle]
if first and text:
text.insert(0, '(version)')
offset = pi / 48
text_angle.insert(0, text_angle[0] - offset)
start.insert(0, start[0] - offset)
end.insert(0, end[0] - offset)
x, y = polar_to_cartesian(1.25, start, end)
first = False
text_source = ColumnDataSource(dict(text=text, x=x, y=y, angle=text_angle))
glyph = Text(x="x", y="y", text="text", angle="angle",
text_align="center", text_baseline="middle")
plot.add_glyph(text_source, glyph)
def to_base64(png):
return "data:image/png;base64," + base64.b64encode(png).decode("utf-8")
urls = [ to_base64(icons.get(browser, b"")) for browser in browsers ]
x, y = polar_to_cartesian(1.7, start_angles, end_angles)
icons_source = ColumnDataSource(dict(urls=urls, x=x, y=y))
glyph = ImageURL(url="urls", x="x", y="y", anchor="center")
plot.add_glyph(icons_source, glyph)
text = [ "%.02f%%" % value for value in selected.Share ]
x, y = polar_to_cartesian(0.7, start_angles, end_angles)
text_source = ColumnDataSource(dict(text=text, x=x, y=y))
glyph = Text(x="x", y="y", text="text", text_align="center", text_baseline="middle")
plot.add_glyph(text_source, glyph)
doc = Document()
doc.add(plot)
if __name__ == "__main__":
filename = "donut.html"
with open(filename, "w") as f:
f.write(file_html(doc, INLINE, "Donut Chart"))
print("Wrote %s" % filename)
view(filename)
|
bsd-3-clause
|
[
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
1300,
772,
199,
504,
3473,
492,
6682,
12,
9829,
12,
9794,
199,
199,
504,
25214,
14,
5750,
773,
492,
2455,
199,
504,
25214,
14,
7120,
492,
2386,
89,
6304,
12,
542,
643,
3441,
12,
370,
569,
79,
12,
503,
335,
344,
12,
8344,
29541,
12,
10540,
12150,
199,
504,
25214,
14,
3554,
492,
7543,
199,
504,
25214,
14,
6427,
492,
570,
63,
1360,
199,
504,
25214,
14,
992,
14,
13723,
83,
492,
644,
5173,
12,
1626,
78,
2238,
55,
5173,
12,
6047,
2632,
12,
4516,
199,
504,
25214,
14,
992,
492,
4996,
16693,
12,
14794,
12,
13114,
17,
68,
199,
504,
25214,
14,
4435,
492,
1621,
6174,
199,
504,
25214,
14,
3271,
576,
14,
5750,
83,
492,
23776,
63,
30442,
63,
6965,
12,
7016,
83,
199,
199,
1587,
275,
23776,
63,
30442,
63,
6965,
199,
199,
2207,
82,
275,
13114,
17,
68,
8,
928,
4022,
18,
12,
1284,
29,
18,
9,
199,
89,
5012,
275,
13114,
17,
68,
8,
928,
4022,
18,
12,
1284,
29,
18,
9,
199,
199,
1213,
275,
298,
5926,
7042,
26584,
8663,
334,
1944,
432,
976,
6171,
2924,
199,
2798,
275,
14794,
8,
1213,
29,
1213,
12,
671,
63,
1842,
29,
2207,
82,
12,
612,
63,
1842,
29,
89,
5012,
12,
5137,
63,
2063,
29,
6718,
12,
5137,
63,
3333,
29,
6718,
9,
199,
199,
7120,
275,
2420,
18083,
582,
542,
643,
3441,
12,
298,
27983,
582,
370,
569,
79,
12,
298,
51,
2756,
759,
582,
503,
335,
344,
12,
298,
3632,
65,
582,
8344,
29541,
12,
298,
4332,
582,
2386,
89,
6304,
12,
298,
8632,
582,
10540,
12150,
93,
199,
199,
10978,
972,
275,
4051,
14,
16968,
480,
11930,
3471,
13452,
8,
1838,
9,
199,
5511,
275,
26913,
59,
10978,
972,
14,
18713,
2356,
413,
1055,
1574,
342,
199,
5511,
14,
2102,
905,
8632,
937,
275,
26913,
59,
10978,
972,
14,
18713,
665,
413,
1055,
1838,
342,
199,
5750,
83,
275,
4895,
14,
1080,
14,
13633,
342,
199,
199,
22946,
275,
2400,
671,
26,
499,
10,
1038,
5830,
88,
15,
1960,
9,
199,
13162,
275,
4895,
14,
18713,
14,
1130,
8,
22946,
680,
23916,
342,
199,
199,
500,
63,
13162,
275,
22597,
14,
13633,
342,
199,
928,
63,
13162,
275,
359,
16,
61,
435,
1284,
63,
13162,
4439,
17,
61,
199,
199,
5750,
83,
63,
1365,
275,
4996,
16693,
8,
807,
8,
272,
1343,
221,
275,
1343,
63,
13162,
12,
272,
1284,
259,
275,
1284,
63,
13162,
12,
272,
9229,
275,
359,
7120,
59,
5750,
61,
367,
7042,
315,
23776,
2156,
199,
430,
199,
199,
13723,
275,
644,
5173,
8,
88,
29,
16,
12,
612,
29,
16,
12,
9362,
29,
17,
12,
1004,
63,
2326,
628,
7510,
401,
272,
1004,
63,
2063,
29,
18,
12,
1343,
63,
4593,
628,
928,
401,
1284,
63,
4593,
628,
500,
401,
5554,
63,
2326,
628,
7120,
531,
199,
2798,
14,
525,
63,
13723,
8,
5750,
83,
63,
1365,
12,
14165,
9,
199,
199,
318,
29167,
63,
475,
63,
7007,
19157,
8,
82,
12,
1343,
63,
13162,
12,
1284,
63,
13162,
304,
272,
9590,
19157,
275,
2400,
519,
12,
5131,
26,
334,
82,
10,
5197,
8,
4468,
395,
519,
10,
5911,
8,
4468,
430,
272,
4501,
275,
942,
339,
367,
1343,
12,
1284,
315,
3482,
8,
928,
63,
13162,
12,
1284,
63,
13162,
304,
267,
4501,
14,
740,
8,
7007,
19157,
8,
82,
12,
334,
500,
435,
1343,
2447,
18,
430,
339,
372,
3482,
2031,
3438,
9,
199,
199,
2246,
275,
715,
199,
199,
509,
7042,
12,
1343,
63,
4593,
12,
1284,
63,
4593,
315,
3482,
8,
5750,
83,
12,
1343,
63,
13162,
12,
1284,
63,
13162,
304,
272,
5459,
275,
4051,
7528,
1587,
14,
11930,
508,
7042,
9,
1253,
334,
1587,
14,
18713,
2356,
378,
14,
21,
1874,
272,
22597,
275,
5459,
14,
18713,
14,
1130,
8,
22946,
680,
23916,
342,
435,
1343,
63,
4593,
272,
1284,
275,
22597,
14,
13633,
342,
435,
359,
500,
63,
4593,
61,
272,
1343,
275,
359,
928,
63,
4593,
61,
435,
1284,
4439,
17,
61,
272,
1300,
63,
2326,
275,
9229,
59,
5750,
61,
272,
5554,
275,
359,
1300,
63,
2326,
14,
18975,
724,
8,
73,
10,
16,
14,
1717,
9,
367,
284,
315,
1425,
8,
552,
8,
6234,
9,
435,
413,
9,
1622,
272,
1318,
275,
359,
1329,
340,
8663,
2356,
413,
587,
3087,
367,
1329,
12,
8663,
315,
3482,
8,
6234,
14,
3353,
3259,
12,
5459,
14,
18713,
9,
1622,
272,
671,
12,
612,
275,
29167,
63,
475,
63,
7007,
19157,
8,
17,
14,
821,
12,
1343,
12,
1284,
9,
339,
1350,
275,
4996,
16693,
8,
807,
8,
928,
29,
928,
12,
1284,
29,
500,
12,
5554,
29,
4498,
430,
272,
14165,
275,
1626,
78,
2238,
55,
5173,
8,
88,
29,
16,
12,
612,
29,
16,
12,
267,
6506,
63,
8017,
29,
17,
12,
6890,
63,
8017,
29,
17,
14,
21,
12,
1343,
63,
4593,
628,
928,
401,
1284,
63,
4593,
628,
500,
401,
267,
1004,
63,
2326,
628,
7510,
401,
1004,
63,
2063,
29,
18,
12,
5554,
63,
2326,
628,
4498,
531,
272,
5137,
14,
525,
63,
13723,
8,
1365,
12,
14165,
9,
2378,
1318,
63,
4593,
275,
3842,
928,
59,
73,
2807,
500,
59,
73,
23067,
18,
367,
284,
315,
1425,
8,
552,
8,
928,
10524,
272,
1318,
63,
4593,
275,
359,
4593,
435,
6682,
340,
6682,
15,
18,
665,
9324,
665,
650,
10,
1038,
15,
18,
587,
9324,
367,
9324,
315,
1318,
63,
4593,
61,
339,
340,
1642,
436,
1318,
26,
267,
1318,
14,
3176,
8,
16,
12,
8189,
1023,
5942,
267,
3268,
275,
6682,
1182,
9615,
267,
1318,
63,
4593,
14,
3176,
8,
16,
12,
1318,
63,
4593,
59,
16,
61,
446,
3268,
9,
267,
1343,
14,
3176,
8,
16,
12,
1343,
59,
16,
61,
446,
3268,
9,
267,
1284,
14,
3176,
8,
16,
12,
1284,
59,
16,
61,
446,
3268,
9,
267,
671,
12,
612,
275,
29167,
63,
475,
63,
7007,
19157,
8,
17,
14,
821,
12,
1343,
12,
1284,
9,
267,
1642,
275,
756,
339,
1318,
63,
1365,
275,
4996,
16693,
8,
807,
8,
505,
29,
505,
12,
671,
29,
88,
12,
612,
29,
89,
12,
9324,
29
] |
[
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
1300,
772,
199,
504,
3473,
492,
6682,
12,
9829,
12,
9794,
199,
199,
504,
25214,
14,
5750,
773,
492,
2455,
199,
504,
25214,
14,
7120,
492,
2386,
89,
6304,
12,
542,
643,
3441,
12,
370,
569,
79,
12,
503,
335,
344,
12,
8344,
29541,
12,
10540,
12150,
199,
504,
25214,
14,
3554,
492,
7543,
199,
504,
25214,
14,
6427,
492,
570,
63,
1360,
199,
504,
25214,
14,
992,
14,
13723,
83,
492,
644,
5173,
12,
1626,
78,
2238,
55,
5173,
12,
6047,
2632,
12,
4516,
199,
504,
25214,
14,
992,
492,
4996,
16693,
12,
14794,
12,
13114,
17,
68,
199,
504,
25214,
14,
4435,
492,
1621,
6174,
199,
504,
25214,
14,
3271,
576,
14,
5750,
83,
492,
23776,
63,
30442,
63,
6965,
12,
7016,
83,
199,
199,
1587,
275,
23776,
63,
30442,
63,
6965,
199,
199,
2207,
82,
275,
13114,
17,
68,
8,
928,
4022,
18,
12,
1284,
29,
18,
9,
199,
89,
5012,
275,
13114,
17,
68,
8,
928,
4022,
18,
12,
1284,
29,
18,
9,
199,
199,
1213,
275,
298,
5926,
7042,
26584,
8663,
334,
1944,
432,
976,
6171,
2924,
199,
2798,
275,
14794,
8,
1213,
29,
1213,
12,
671,
63,
1842,
29,
2207,
82,
12,
612,
63,
1842,
29,
89,
5012,
12,
5137,
63,
2063,
29,
6718,
12,
5137,
63,
3333,
29,
6718,
9,
199,
199,
7120,
275,
2420,
18083,
582,
542,
643,
3441,
12,
298,
27983,
582,
370,
569,
79,
12,
298,
51,
2756,
759,
582,
503,
335,
344,
12,
298,
3632,
65,
582,
8344,
29541,
12,
298,
4332,
582,
2386,
89,
6304,
12,
298,
8632,
582,
10540,
12150,
93,
199,
199,
10978,
972,
275,
4051,
14,
16968,
480,
11930,
3471,
13452,
8,
1838,
9,
199,
5511,
275,
26913,
59,
10978,
972,
14,
18713,
2356,
413,
1055,
1574,
342,
199,
5511,
14,
2102,
905,
8632,
937,
275,
26913,
59,
10978,
972,
14,
18713,
665,
413,
1055,
1838,
342,
199,
5750,
83,
275,
4895,
14,
1080,
14,
13633,
342,
199,
199,
22946,
275,
2400,
671,
26,
499,
10,
1038,
5830,
88,
15,
1960,
9,
199,
13162,
275,
4895,
14,
18713,
14,
1130,
8,
22946,
680,
23916,
342,
199,
199,
500,
63,
13162,
275,
22597,
14,
13633,
342,
199,
928,
63,
13162,
275,
359,
16,
61,
435,
1284,
63,
13162,
4439,
17,
61,
199,
199,
5750,
83,
63,
1365,
275,
4996,
16693,
8,
807,
8,
272,
1343,
221,
275,
1343,
63,
13162,
12,
272,
1284,
259,
275,
1284,
63,
13162,
12,
272,
9229,
275,
359,
7120,
59,
5750,
61,
367,
7042,
315,
23776,
2156,
199,
430,
199,
199,
13723,
275,
644,
5173,
8,
88,
29,
16,
12,
612,
29,
16,
12,
9362,
29,
17,
12,
1004,
63,
2326,
628,
7510,
401,
272,
1004,
63,
2063,
29,
18,
12,
1343,
63,
4593,
628,
928,
401,
1284,
63,
4593,
628,
500,
401,
5554,
63,
2326,
628,
7120,
531,
199,
2798,
14,
525,
63,
13723,
8,
5750,
83,
63,
1365,
12,
14165,
9,
199,
199,
318,
29167,
63,
475,
63,
7007,
19157,
8,
82,
12,
1343,
63,
13162,
12,
1284,
63,
13162,
304,
272,
9590,
19157,
275,
2400,
519,
12,
5131,
26,
334,
82,
10,
5197,
8,
4468,
395,
519,
10,
5911,
8,
4468,
430,
272,
4501,
275,
942,
339,
367,
1343,
12,
1284,
315,
3482,
8,
928,
63,
13162,
12,
1284,
63,
13162,
304,
267,
4501,
14,
740,
8,
7007,
19157,
8,
82,
12,
334,
500,
435,
1343,
2447,
18,
430,
339,
372,
3482,
2031,
3438,
9,
199,
199,
2246,
275,
715,
199,
199,
509,
7042,
12,
1343,
63,
4593,
12,
1284,
63,
4593,
315,
3482,
8,
5750,
83,
12,
1343,
63,
13162,
12,
1284,
63,
13162,
304,
272,
5459,
275,
4051,
7528,
1587,
14,
11930,
508,
7042,
9,
1253,
334,
1587,
14,
18713,
2356,
378,
14,
21,
1874,
272,
22597,
275,
5459,
14,
18713,
14,
1130,
8,
22946,
680,
23916,
342,
435,
1343,
63,
4593,
272,
1284,
275,
22597,
14,
13633,
342,
435,
359,
500,
63,
4593,
61,
272,
1343,
275,
359,
928,
63,
4593,
61,
435,
1284,
4439,
17,
61,
272,
1300,
63,
2326,
275,
9229,
59,
5750,
61,
272,
5554,
275,
359,
1300,
63,
2326,
14,
18975,
724,
8,
73,
10,
16,
14,
1717,
9,
367,
284,
315,
1425,
8,
552,
8,
6234,
9,
435,
413,
9,
1622,
272,
1318,
275,
359,
1329,
340,
8663,
2356,
413,
587,
3087,
367,
1329,
12,
8663,
315,
3482,
8,
6234,
14,
3353,
3259,
12,
5459,
14,
18713,
9,
1622,
272,
671,
12,
612,
275,
29167,
63,
475,
63,
7007,
19157,
8,
17,
14,
821,
12,
1343,
12,
1284,
9,
339,
1350,
275,
4996,
16693,
8,
807,
8,
928,
29,
928,
12,
1284,
29,
500,
12,
5554,
29,
4498,
430,
272,
14165,
275,
1626,
78,
2238,
55,
5173,
8,
88,
29,
16,
12,
612,
29,
16,
12,
267,
6506,
63,
8017,
29,
17,
12,
6890,
63,
8017,
29,
17,
14,
21,
12,
1343,
63,
4593,
628,
928,
401,
1284,
63,
4593,
628,
500,
401,
267,
1004,
63,
2326,
628,
7510,
401,
1004,
63,
2063,
29,
18,
12,
5554,
63,
2326,
628,
4498,
531,
272,
5137,
14,
525,
63,
13723,
8,
1365,
12,
14165,
9,
2378,
1318,
63,
4593,
275,
3842,
928,
59,
73,
2807,
500,
59,
73,
23067,
18,
367,
284,
315,
1425,
8,
552,
8,
928,
10524,
272,
1318,
63,
4593,
275,
359,
4593,
435,
6682,
340,
6682,
15,
18,
665,
9324,
665,
650,
10,
1038,
15,
18,
587,
9324,
367,
9324,
315,
1318,
63,
4593,
61,
339,
340,
1642,
436,
1318,
26,
267,
1318,
14,
3176,
8,
16,
12,
8189,
1023,
5942,
267,
3268,
275,
6682,
1182,
9615,
267,
1318,
63,
4593,
14,
3176,
8,
16,
12,
1318,
63,
4593,
59,
16,
61,
446,
3268,
9,
267,
1343,
14,
3176,
8,
16,
12,
1343,
59,
16,
61,
446,
3268,
9,
267,
1284,
14,
3176,
8,
16,
12,
1284,
59,
16,
61,
446,
3268,
9,
267,
671,
12,
612,
275,
29167,
63,
475,
63,
7007,
19157,
8,
17,
14,
821,
12,
1343,
12,
1284,
9,
267,
1642,
275,
756,
339,
1318,
63,
1365,
275,
4996,
16693,
8,
807,
8,
505,
29,
505,
12,
671,
29,
88,
12,
612,
29,
89,
12,
9324,
29,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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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
] |
PatrickOReilly/scikit-learn
|
sklearn/decomposition/incremental_pca.py
|
83
|
10440
|
"""Incremental Principal Components Analysis."""
# Author: Kyle Kastner <kastnerkyle@gmail.com>
# Giorgio Patrini
# License: BSD 3 clause
import numpy as np
from scipy import linalg
from .base import _BasePCA
from ..utils import check_array, gen_batches
from ..utils.extmath import svd_flip, _incremental_mean_and_var
class IncrementalPCA(_BasePCA):
"""Incremental principal components analysis (IPCA).
Linear dimensionality reduction using Singular Value Decomposition of
centered data, keeping only the most significant singular vectors to
project the data to a lower dimensional space.
Depending on the size of the input data, this algorithm can be much more
memory efficient than a PCA.
This algorithm has constant memory complexity, on the order
of ``batch_size``, enabling use of np.memmap files without loading the
entire file into memory.
The computational overhead of each SVD is
``O(batch_size * n_features ** 2)``, but only 2 * batch_size samples
remain in memory at a time. There will be ``n_samples / batch_size`` SVD
computations to get the principal components, versus 1 large SVD of
complexity ``O(n_samples * n_features ** 2)`` for PCA.
Read more in the :ref:`User Guide <IncrementalPCA>`.
Parameters
----------
n_components : int or None, (default=None)
Number of components to keep. If ``n_components `` is ``None``,
then ``n_components`` is set to ``min(n_samples, n_features)``.
batch_size : int or None, (default=None)
The number of samples to use for each batch. Only used when calling
``fit``. If ``batch_size`` is ``None``, then ``batch_size``
is inferred from the data and set to ``5 * n_features``, to provide a
balance between approximation accuracy and memory consumption.
copy : bool, (default=True)
If False, X will be overwritten. ``copy=False`` can be used to
save memory but is unsafe for general use.
whiten : bool, optional
When True (False by default) the ``components_`` vectors are divided
by ``n_samples`` times ``components_`` to ensure uncorrelated outputs
with unit component-wise variances.
Whitening will remove some information from the transformed signal
(the relative variance scales of the components) but can sometimes
improve the predictive accuracy of the downstream estimators by
making data respect some hard-wired assumptions.
Attributes
----------
components_ : array, shape (n_components, n_features)
Components with maximum variance.
explained_variance_ : array, shape (n_components,)
Variance explained by each of the selected components.
explained_variance_ratio_ : array, shape (n_components,)
Percentage of variance explained by each of the selected components.
If all components are stored, the sum of explained variances is equal
to 1.0
mean_ : array, shape (n_features,)
Per-feature empirical mean, aggregate over calls to ``partial_fit``.
var_ : array, shape (n_features,)
Per-feature empirical variance, aggregate over calls to
``partial_fit``.
noise_variance_ : float
The estimated noise covariance following the Probabilistic PCA model
from Tipping and Bishop 1999. See "Pattern Recognition and
Machine Learning" by C. Bishop, 12.2.1 p. 574 or
http://www.miketipping.com/papers/met-mppca.pdf.
n_components_ : int
The estimated number of components. Relevant when
``n_components=None``.
n_samples_seen_ : int
The number of samples processed by the estimator. Will be reset on
new calls to fit, but increments across ``partial_fit`` calls.
Notes
-----
Implements the incremental PCA model from:
`D. Ross, J. Lim, R. Lin, M. Yang, Incremental Learning for Robust Visual
Tracking, International Journal of Computer Vision, Volume 77, Issue 1-3,
pp. 125-141, May 2008.`
See http://www.cs.toronto.edu/~dross/ivt/RossLimLinYang_ijcv.pdf
This model is an extension of the Sequential Karhunen-Loeve Transform from:
`A. Levy and M. Lindenbaum, Sequential Karhunen-Loeve Basis Extraction and
its Application to Images, IEEE Transactions on Image Processing, Volume 9,
Number 8, pp. 1371-1374, August 2000.`
See http://www.cs.technion.ac.il/~mic/doc/skl-ip.pdf
We have specifically abstained from an optimization used by authors of both
papers, a QR decomposition used in specific situations to reduce the
algorithmic complexity of the SVD. The source for this technique is
`Matrix Computations, Third Edition, G. Holub and C. Van Loan, Chapter 5,
section 5.4.4, pp 252-253.`. This technique has been omitted because it is
advantageous only when decomposing a matrix with ``n_samples`` (rows)
>= 5/3 * ``n_features`` (columns), and hurts the readability of the
implemented algorithm. This would be a good opportunity for future
optimization, if it is deemed necessary.
References
----------
D. Ross, J. Lim, R. Lin, M. Yang. Incremental Learning for Robust Visual
Tracking, International Journal of Computer Vision, Volume 77,
Issue 1-3, pp. 125-141, May 2008.
G. Golub and C. Van Loan. Matrix Computations, Third Edition, Chapter 5,
Section 5.4.4, pp. 252-253.
See also
--------
PCA
RandomizedPCA
KernelPCA
SparsePCA
TruncatedSVD
"""
def __init__(self, n_components=None, whiten=False, copy=True,
batch_size=None):
self.n_components = n_components
self.whiten = whiten
self.copy = copy
self.batch_size = batch_size
def fit(self, X, y=None):
"""Fit the model with X, using minibatches of size batch_size.
Parameters
----------
X: array-like, shape (n_samples, n_features)
Training data, where n_samples is the number of samples and
n_features is the number of features.
y: Passthrough for ``Pipeline`` compatibility.
Returns
-------
self: object
Returns the instance itself.
"""
self.components_ = None
self.n_samples_seen_ = 0
self.mean_ = .0
self.var_ = .0
self.singular_values_ = None
self.explained_variance_ = None
self.explained_variance_ratio_ = None
self.noise_variance_ = None
X = check_array(X, copy=self.copy, dtype=[np.float64, np.float32])
n_samples, n_features = X.shape
if self.batch_size is None:
self.batch_size_ = 5 * n_features
else:
self.batch_size_ = self.batch_size
for batch in gen_batches(n_samples, self.batch_size_):
self.partial_fit(X[batch], check_input=False)
return self
def partial_fit(self, X, y=None, check_input=True):
"""Incremental fit with X. All of X is processed as a single batch.
Parameters
----------
X: array-like, shape (n_samples, n_features)
Training data, where n_samples is the number of samples and
n_features is the number of features.
Returns
-------
self: object
Returns the instance itself.
"""
if check_input:
X = check_array(X, copy=self.copy, dtype=[np.float64, np.float32])
n_samples, n_features = X.shape
if not hasattr(self, 'components_'):
self.components_ = None
if self.n_components is None:
self.n_components_ = n_features
elif not 1 <= self.n_components <= n_features:
raise ValueError("n_components=%r invalid for n_features=%d, need "
"more rows than columns for IncrementalPCA "
"processing" % (self.n_components, n_features))
else:
self.n_components_ = self.n_components
if (self.components_ is not None) and (self.components_.shape[0] !=
self.n_components_):
raise ValueError("Number of input features has changed from %i "
"to %i between calls to partial_fit! Try "
"setting n_components to a fixed value." %
(self.components_.shape[0], self.n_components_))
# This is the first partial_fit
if not hasattr(self, 'n_samples_seen_'):
self.n_samples_seen_ = 0
self.mean_ = .0
self.var_ = .0
# Update stats - they are 0 if this is the fisrt step
col_mean, col_var, n_total_samples = \
_incremental_mean_and_var(X, last_mean=self.mean_,
last_variance=self.var_,
last_sample_count=self.n_samples_seen_)
# Whitening
if self.n_samples_seen_ == 0:
# If it is the first step, simply whiten X
X -= col_mean
else:
col_batch_mean = np.mean(X, axis=0)
X -= col_batch_mean
# Build matrix of combined previous basis and new data
mean_correction = \
np.sqrt((self.n_samples_seen_ * n_samples) /
n_total_samples) * (self.mean_ - col_batch_mean)
X = np.vstack((self.singular_values_.reshape((-1, 1)) *
self.components_, X, mean_correction))
U, S, V = linalg.svd(X, full_matrices=False)
U, V = svd_flip(U, V, u_based_decision=False)
explained_variance = S ** 2 / n_total_samples
explained_variance_ratio = S ** 2 / np.sum(col_var * n_total_samples)
self.n_samples_seen_ = n_total_samples
self.components_ = V[:self.n_components_]
self.singular_values_ = S[:self.n_components_]
self.mean_ = col_mean
self.var_ = col_var
self.explained_variance_ = explained_variance[:self.n_components_]
self.explained_variance_ratio_ = \
explained_variance_ratio[:self.n_components_]
if self.n_components_ < n_features:
self.noise_variance_ = \
explained_variance[self.n_components_:].mean()
else:
self.noise_variance_ = 0.
return self
|
bsd-3-clause
|
[
624,
10287,
25716,
11590,
17823,
21916,
1041,
199,
199,
3,
6529,
26,
1804,
1775,
1804,
1810,
1372,
665,
75,
1810,
1372,
75,
1775,
32,
6799,
14,
957,
30,
199,
3,
260,
598,
73,
1308,
2308,
510,
292,
82,
2730,
199,
3,
844,
26,
6289,
650,
8502,
199,
199,
646,
2680,
465,
980,
199,
504,
7026,
492,
16727,
199,
199,
504,
1275,
1095,
492,
485,
1563,
23852,
199,
504,
2508,
1208,
492,
1104,
63,
1144,
12,
3805,
63,
14896,
199,
504,
2508,
1208,
14,
832,
3442,
492,
26937,
63,
16114,
12,
485,
23760,
63,
3670,
63,
460,
63,
1391,
421,
199,
533,
14684,
23852,
1547,
1563,
23852,
304,
272,
408,
10287,
21646,
7323,
11284,
334,
1772,
3263,
680,
339,
12489,
6240,
6712,
16773,
1808,
428,
14257,
1594,
1487,
13000,
402,
272,
23903,
666,
12,
22181,
1454,
314,
4750,
16474,
15823,
11102,
370,
272,
2199,
314,
666,
370,
282,
5117,
28341,
4601,
14,
339,
1487,
6455,
641,
314,
1568,
402,
314,
1324,
666,
12,
642,
5563,
883,
506,
8298,
1655,
272,
4402,
13402,
2419,
282,
25266,
14,
339,
961,
5563,
965,
4413,
4402,
6114,
1209,
12,
641,
314,
1865,
272,
402,
1124,
2912,
63,
890,
4542,
29310,
675,
402,
980,
14,
5286,
1130,
1584,
1928,
8697,
314,
272,
8039,
570,
1901,
4402,
14,
339,
710,
28319,
6279,
24075,
402,
1924,
14056,
36,
365,
272,
1124,
47,
8,
2912,
63,
890,
627,
302,
63,
3179,
1011,
499,
28616,
1325,
1454,
499,
627,
3522,
63,
890,
5845,
272,
5706,
315,
4402,
737,
282,
900,
14,
6006,
911,
506,
1124,
78,
63,
3356,
1182,
3522,
63,
890,
1040,
14056,
36,
272,
28319,
1298,
370,
664,
314,
21646,
7323,
12,
809,
25253,
413,
7031,
14056,
36,
402,
272,
6114,
1209,
1124,
47,
8,
78,
63,
3356,
627,
302,
63,
3179,
1011,
499,
9719,
367,
25266,
14,
339,
5574,
1655,
315,
314,
520,
1121,
1705,
1899,
15423,
665,
10287,
23852,
14943,
339,
3897,
272,
4143,
272,
302,
63,
4608,
520,
1109,
503,
488,
12,
334,
885,
29,
403,
9,
267,
4860,
402,
7323,
370,
4215,
14,
982,
1124,
78,
63,
4608,
1124,
365,
1124,
403,
4542,
267,
2066,
1124,
78,
63,
4608,
1040,
365,
663,
370,
1124,
827,
8,
78,
63,
3356,
12,
302,
63,
3179,
20642,
339,
3522,
63,
890,
520,
1109,
503,
488,
12,
334,
885,
29,
403,
9,
267,
710,
1329,
402,
5845,
370,
675,
367,
1924,
3522,
14,
5972,
1202,
1380,
6358,
267,
1124,
3269,
4345,
982,
1124,
2912,
63,
890,
1040,
365,
1124,
403,
4542,
2066,
1124,
2912,
63,
890,
1040,
267,
365,
22515,
687,
314,
666,
436,
663,
370,
1124,
21,
627,
302,
63,
3179,
4542,
370,
5647,
282,
267,
14094,
3382,
22772,
12862,
436,
4402,
13447,
15052,
14,
339,
1331,
520,
2155,
12,
334,
885,
29,
549,
9,
267,
982,
756,
12,
1323,
911,
506,
20200,
14,
1124,
1574,
29,
797,
1040,
883,
506,
1202,
370,
267,
3354,
4402,
1325,
365,
19293,
367,
8605,
675,
14,
339,
704,
25840,
520,
2155,
12,
2716,
267,
3979,
715,
334,
797,
701,
849,
9,
314,
1124,
4608,
63,
1040,
11102,
787,
29378,
267,
701,
1124,
78,
63,
3356,
1040,
5431,
1124,
4608,
63,
1040,
370,
4868,
625,
989,
2407,
4704,
267,
543,
4137,
3931,
13,
2605,
11773,
83,
14,
398,
2816,
25840,
316,
911,
2813,
2005,
2556,
687,
314,
14834,
4673,
267,
334,
1589,
3847,
11773,
29823,
402,
314,
7323,
9,
1325,
883,
15026,
267,
19053,
314,
4557,
6648,
12862,
402,
314,
3224,
1745,
23155,
701,
267,
10663,
666,
14021,
2005,
7508,
13,
14249,
581,
21546,
14,
339,
9382,
272,
4143,
272,
7323,
63,
520,
1625,
12,
2215,
334,
78,
63,
4608,
12,
302,
63,
3179,
9,
267,
17823,
543,
5696,
11773,
14,
339,
1437,
23918,
63,
6221,
63,
520,
1625,
12,
2215,
334,
78,
63,
4608,
4258,
267,
21107,
554,
1437,
23918,
701,
1924,
402,
314,
4895,
7323,
14,
339,
1437,
23918,
63,
6221,
63,
6884,
63,
520,
1625,
12,
2215,
334,
78,
63,
4608,
4258,
267,
3492,
2946,
474,
402,
11773,
1437,
23918,
701,
1924,
402,
314,
4895,
7323,
14,
267,
982,
1006,
7323,
787,
5489,
12,
314,
3089,
402,
1437,
23918,
11773,
83,
365,
4472,
267,
370,
413,
14,
16,
339,
4615,
63,
520,
1625,
12,
2215,
334,
78,
63,
3179,
4258,
267,
3492,
13,
4445,
9052,
73,
8825,
4615,
12,
9531,
1806,
4882,
370,
1124,
6672,
63,
3269,
4345,
339,
2729,
63,
520,
1625,
12,
2215,
334,
78,
63,
3179,
4258,
267,
3492,
13,
4445,
9052,
73,
8825,
11773,
12,
9531,
1806,
4882,
370,
267,
1124,
6672,
63,
3269,
4345,
339,
11145,
63,
6221,
63,
520,
2069,
267,
710,
20077,
11145,
13263,
2569,
314,
22770,
14677,
513,
530,
25266,
1402,
267,
687,
377,
711,
4073,
436,
699,
2453,
411,
21300,
14,
1666,
298,
9959,
799,
6862,
15415,
436,
267,
18722,
29127,
2,
701,
445,
14,
699,
2453,
411,
12,
3144,
14,
18,
14,
17,
299,
14,
959,
1342,
503,
267,
1455,
921,
1544,
14,
2664,
415,
280,
3637,
14,
957,
15,
10443,
83,
15,
10207,
13,
17901,
696,
14,
5607,
14,
339,
302,
63,
4608,
63,
520,
1109,
267,
710,
20077,
1329,
402,
7323,
14,
799,
9723,
1380,
267,
1124,
78,
63,
4608,
29,
403,
4345,
339,
302,
63,
3356,
63,
8606,
63,
520,
1109,
267,
710,
1329,
402,
5845,
7686,
701,
314,
8943,
14,
12823,
506,
5305,
641,
267,
892,
4882,
370,
5542,
12,
1325,
10035,
1470,
9371,
1124,
6672,
63,
3269,
1040,
4882,
14,
339,
8144,
272,
9063,
272,
24664,
314,
16316,
25266,
1402,
687,
26,
272,
658,
36,
14,
6848,
385,
12,
1603,
14,
14620,
12,
820,
14,
29730,
12,
603,
14,
1488,
621,
12,
14684,
29127,
367,
6848,
15549,
14702,
272,
17507,
316,
12,
28220,
22142,
402,
3599,
2699,
6561,
438,
12,
15018,
8375,
12,
13383,
413,
13,
19,
12,
272,
11618,
14,
19163,
13,
12735,
12,
10162,
9079,
14,
64,
272,
1666,
1455,
921,
1544,
14,
1259,
14,
8270,
26296,
14,
8654,
22500,
68,
3685,
15,
1003,
84,
15,
3863,
385,
7219,
27889,
57,
621,
63,
7879,
5107,
14,
5607,
339,
961,
1402,
365,
376,
3329,
402,
314,
3240,
9092,
1804,
285,
72,
324,
287,
13,
2041,
4754,
19463,
687,
26,
272,
658,
33,
14,
491,
6857,
89
] |
[
10287,
25716,
11590,
17823,
21916,
1041,
199,
199,
3,
6529,
26,
1804,
1775,
1804,
1810,
1372,
665,
75,
1810,
1372,
75,
1775,
32,
6799,
14,
957,
30,
199,
3,
260,
598,
73,
1308,
2308,
510,
292,
82,
2730,
199,
3,
844,
26,
6289,
650,
8502,
199,
199,
646,
2680,
465,
980,
199,
504,
7026,
492,
16727,
199,
199,
504,
1275,
1095,
492,
485,
1563,
23852,
199,
504,
2508,
1208,
492,
1104,
63,
1144,
12,
3805,
63,
14896,
199,
504,
2508,
1208,
14,
832,
3442,
492,
26937,
63,
16114,
12,
485,
23760,
63,
3670,
63,
460,
63,
1391,
421,
199,
533,
14684,
23852,
1547,
1563,
23852,
304,
272,
408,
10287,
21646,
7323,
11284,
334,
1772,
3263,
680,
339,
12489,
6240,
6712,
16773,
1808,
428,
14257,
1594,
1487,
13000,
402,
272,
23903,
666,
12,
22181,
1454,
314,
4750,
16474,
15823,
11102,
370,
272,
2199,
314,
666,
370,
282,
5117,
28341,
4601,
14,
339,
1487,
6455,
641,
314,
1568,
402,
314,
1324,
666,
12,
642,
5563,
883,
506,
8298,
1655,
272,
4402,
13402,
2419,
282,
25266,
14,
339,
961,
5563,
965,
4413,
4402,
6114,
1209,
12,
641,
314,
1865,
272,
402,
1124,
2912,
63,
890,
4542,
29310,
675,
402,
980,
14,
5286,
1130,
1584,
1928,
8697,
314,
272,
8039,
570,
1901,
4402,
14,
339,
710,
28319,
6279,
24075,
402,
1924,
14056,
36,
365,
272,
1124,
47,
8,
2912,
63,
890,
627,
302,
63,
3179,
1011,
499,
28616,
1325,
1454,
499,
627,
3522,
63,
890,
5845,
272,
5706,
315,
4402,
737,
282,
900,
14,
6006,
911,
506,
1124,
78,
63,
3356,
1182,
3522,
63,
890,
1040,
14056,
36,
272,
28319,
1298,
370,
664,
314,
21646,
7323,
12,
809,
25253,
413,
7031,
14056,
36,
402,
272,
6114,
1209,
1124,
47,
8,
78,
63,
3356,
627,
302,
63,
3179,
1011,
499,
9719,
367,
25266,
14,
339,
5574,
1655,
315,
314,
520,
1121,
1705,
1899,
15423,
665,
10287,
23852,
14943,
339,
3897,
272,
4143,
272,
302,
63,
4608,
520,
1109,
503,
488,
12,
334,
885,
29,
403,
9,
267,
4860,
402,
7323,
370,
4215,
14,
982,
1124,
78,
63,
4608,
1124,
365,
1124,
403,
4542,
267,
2066,
1124,
78,
63,
4608,
1040,
365,
663,
370,
1124,
827,
8,
78,
63,
3356,
12,
302,
63,
3179,
20642,
339,
3522,
63,
890,
520,
1109,
503,
488,
12,
334,
885,
29,
403,
9,
267,
710,
1329,
402,
5845,
370,
675,
367,
1924,
3522,
14,
5972,
1202,
1380,
6358,
267,
1124,
3269,
4345,
982,
1124,
2912,
63,
890,
1040,
365,
1124,
403,
4542,
2066,
1124,
2912,
63,
890,
1040,
267,
365,
22515,
687,
314,
666,
436,
663,
370,
1124,
21,
627,
302,
63,
3179,
4542,
370,
5647,
282,
267,
14094,
3382,
22772,
12862,
436,
4402,
13447,
15052,
14,
339,
1331,
520,
2155,
12,
334,
885,
29,
549,
9,
267,
982,
756,
12,
1323,
911,
506,
20200,
14,
1124,
1574,
29,
797,
1040,
883,
506,
1202,
370,
267,
3354,
4402,
1325,
365,
19293,
367,
8605,
675,
14,
339,
704,
25840,
520,
2155,
12,
2716,
267,
3979,
715,
334,
797,
701,
849,
9,
314,
1124,
4608,
63,
1040,
11102,
787,
29378,
267,
701,
1124,
78,
63,
3356,
1040,
5431,
1124,
4608,
63,
1040,
370,
4868,
625,
989,
2407,
4704,
267,
543,
4137,
3931,
13,
2605,
11773,
83,
14,
398,
2816,
25840,
316,
911,
2813,
2005,
2556,
687,
314,
14834,
4673,
267,
334,
1589,
3847,
11773,
29823,
402,
314,
7323,
9,
1325,
883,
15026,
267,
19053,
314,
4557,
6648,
12862,
402,
314,
3224,
1745,
23155,
701,
267,
10663,
666,
14021,
2005,
7508,
13,
14249,
581,
21546,
14,
339,
9382,
272,
4143,
272,
7323,
63,
520,
1625,
12,
2215,
334,
78,
63,
4608,
12,
302,
63,
3179,
9,
267,
17823,
543,
5696,
11773,
14,
339,
1437,
23918,
63,
6221,
63,
520,
1625,
12,
2215,
334,
78,
63,
4608,
4258,
267,
21107,
554,
1437,
23918,
701,
1924,
402,
314,
4895,
7323,
14,
339,
1437,
23918,
63,
6221,
63,
6884,
63,
520,
1625,
12,
2215,
334,
78,
63,
4608,
4258,
267,
3492,
2946,
474,
402,
11773,
1437,
23918,
701,
1924,
402,
314,
4895,
7323,
14,
267,
982,
1006,
7323,
787,
5489,
12,
314,
3089,
402,
1437,
23918,
11773,
83,
365,
4472,
267,
370,
413,
14,
16,
339,
4615,
63,
520,
1625,
12,
2215,
334,
78,
63,
3179,
4258,
267,
3492,
13,
4445,
9052,
73,
8825,
4615,
12,
9531,
1806,
4882,
370,
1124,
6672,
63,
3269,
4345,
339,
2729,
63,
520,
1625,
12,
2215,
334,
78,
63,
3179,
4258,
267,
3492,
13,
4445,
9052,
73,
8825,
11773,
12,
9531,
1806,
4882,
370,
267,
1124,
6672,
63,
3269,
4345,
339,
11145,
63,
6221,
63,
520,
2069,
267,
710,
20077,
11145,
13263,
2569,
314,
22770,
14677,
513,
530,
25266,
1402,
267,
687,
377,
711,
4073,
436,
699,
2453,
411,
21300,
14,
1666,
298,
9959,
799,
6862,
15415,
436,
267,
18722,
29127,
2,
701,
445,
14,
699,
2453,
411,
12,
3144,
14,
18,
14,
17,
299,
14,
959,
1342,
503,
267,
1455,
921,
1544,
14,
2664,
415,
280,
3637,
14,
957,
15,
10443,
83,
15,
10207,
13,
17901,
696,
14,
5607,
14,
339,
302,
63,
4608,
63,
520,
1109,
267,
710,
20077,
1329,
402,
7323,
14,
799,
9723,
1380,
267,
1124,
78,
63,
4608,
29,
403,
4345,
339,
302,
63,
3356,
63,
8606,
63,
520,
1109,
267,
710,
1329,
402,
5845,
7686,
701,
314,
8943,
14,
12823,
506,
5305,
641,
267,
892,
4882,
370,
5542,
12,
1325,
10035,
1470,
9371,
1124,
6672,
63,
3269,
1040,
4882,
14,
339,
8144,
272,
9063,
272,
24664,
314,
16316,
25266,
1402,
687,
26,
272,
658,
36,
14,
6848,
385,
12,
1603,
14,
14620,
12,
820,
14,
29730,
12,
603,
14,
1488,
621,
12,
14684,
29127,
367,
6848,
15549,
14702,
272,
17507,
316,
12,
28220,
22142,
402,
3599,
2699,
6561,
438,
12,
15018,
8375,
12,
13383,
413,
13,
19,
12,
272,
11618,
14,
19163,
13,
12735,
12,
10162,
9079,
14,
64,
272,
1666,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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
] |
pathompongoo/ThGovJobApp
|
env/lib/python2.7/site-packages/pip/_vendor/colorama/winterm.py
|
442
|
5732
|
# Copyright Jonathan Hartley 2013. BSD 3-Clause license, see LICENSE file.
from . import win32
# from wincon.h
class WinColor(object):
BLACK = 0
BLUE = 1
GREEN = 2
CYAN = 3
RED = 4
MAGENTA = 5
YELLOW = 6
GREY = 7
# from wincon.h
class WinStyle(object):
NORMAL = 0x00 # dim text, dim background
BRIGHT = 0x08 # bright text, dim background
BRIGHT_BACKGROUND = 0x80 # dim text, bright background
class WinTerm(object):
def __init__(self):
self._default = win32.GetConsoleScreenBufferInfo(win32.STDOUT).wAttributes
self.set_attrs(self._default)
self._default_fore = self._fore
self._default_back = self._back
self._default_style = self._style
def get_attrs(self):
return self._fore + self._back * 16 + self._style
def set_attrs(self, value):
self._fore = value & 7
self._back = (value >> 4) & 7
self._style = value & (WinStyle.BRIGHT | WinStyle.BRIGHT_BACKGROUND)
def reset_all(self, on_stderr=None):
self.set_attrs(self._default)
self.set_console(attrs=self._default)
def fore(self, fore=None, light=False, on_stderr=False):
if fore is None:
fore = self._default_fore
self._fore = fore
if light:
self._style |= WinStyle.BRIGHT
self.set_console(on_stderr=on_stderr)
def back(self, back=None, light=False, on_stderr=False):
if back is None:
back = self._default_back
self._back = back
if light:
self._style |= WinStyle.BRIGHT_BACKGROUND
self.set_console(on_stderr=on_stderr)
def style(self, style=None, on_stderr=False):
if style is None:
style = self._default_style
self._style = style
self.set_console(on_stderr=on_stderr)
def set_console(self, attrs=None, on_stderr=False):
if attrs is None:
attrs = self.get_attrs()
handle = win32.STDOUT
if on_stderr:
handle = win32.STDERR
win32.SetConsoleTextAttribute(handle, attrs)
def get_position(self, handle):
position = win32.GetConsoleScreenBufferInfo(handle).dwCursorPosition
# Because Windows coordinates are 0-based,
# and win32.SetConsoleCursorPosition expects 1-based.
position.X += 1
position.Y += 1
return position
def set_cursor_position(self, position=None, on_stderr=False):
if position is None:
#I'm not currently tracking the position, so there is no default.
#position = self.get_position()
return
handle = win32.STDOUT
if on_stderr:
handle = win32.STDERR
win32.SetConsoleCursorPosition(handle, position)
def cursor_adjust(self, x, y, on_stderr=False):
handle = win32.STDOUT
if on_stderr:
handle = win32.STDERR
position = self.get_position(handle)
adjusted_position = (position.Y + y, position.X + x)
win32.SetConsoleCursorPosition(handle, adjusted_position, adjust=False)
def erase_screen(self, mode=0, on_stderr=False):
# 0 should clear from the cursor to the end of the screen.
# 1 should clear from the cursor to the beginning of the screen.
# 2 should clear the entire screen, and move cursor to (1,1)
handle = win32.STDOUT
if on_stderr:
handle = win32.STDERR
csbi = win32.GetConsoleScreenBufferInfo(handle)
# get the number of character cells in the current buffer
cells_in_screen = csbi.dwSize.X * csbi.dwSize.Y
# get number of character cells before current cursor position
cells_before_cursor = csbi.dwSize.X * csbi.dwCursorPosition.Y + csbi.dwCursorPosition.X
if mode == 0:
from_coord = csbi.dwCursorPosition
cells_to_erase = cells_in_screen - cells_before_cursor
if mode == 1:
from_coord = win32.COORD(0, 0)
cells_to_erase = cells_before_cursor
elif mode == 2:
from_coord = win32.COORD(0, 0)
cells_to_erase = cells_in_screen
# fill the entire screen with blanks
win32.FillConsoleOutputCharacter(handle, ' ', cells_to_erase, from_coord)
# now set the buffer's attributes accordingly
win32.FillConsoleOutputAttribute(handle, self.get_attrs(), cells_to_erase, from_coord)
if mode == 2:
# put the cursor where needed
win32.SetConsoleCursorPosition(handle, (1, 1))
def erase_line(self, mode=0, on_stderr=False):
# 0 should clear from the cursor to the end of the line.
# 1 should clear from the cursor to the beginning of the line.
# 2 should clear the entire line.
handle = win32.STDOUT
if on_stderr:
handle = win32.STDERR
csbi = win32.GetConsoleScreenBufferInfo(handle)
if mode == 0:
from_coord = csbi.dwCursorPosition
cells_to_erase = csbi.dwSize.X - csbi.dwCursorPosition.X
if mode == 1:
from_coord = win32.COORD(0, csbi.dwCursorPosition.Y)
cells_to_erase = csbi.dwCursorPosition.X
elif mode == 2:
from_coord = win32.COORD(0, csbi.dwCursorPosition.Y)
cells_to_erase = csbi.dwSize.X
# fill the entire screen with blanks
win32.FillConsoleOutputCharacter(handle, ' ', cells_to_erase, from_coord)
# now set the buffer's attributes accordingly
win32.FillConsoleOutputAttribute(handle, self.get_attrs(), cells_to_erase, from_coord)
def set_title(self, title):
win32.SetConsoleTitle(title)
|
gpl-3.0
|
[
3,
1898,
1603,
265,
1619,
290,
869,
580,
15515,
6171,
14,
6289,
650,
13,
16009,
4190,
12,
1937,
5113,
570,
14,
199,
504,
1275,
492,
4747,
708,
421,
199,
3,
687,
4747,
388,
14,
72,
199,
533,
13036,
4117,
8,
785,
304,
272,
26774,
257,
275,
378,
272,
31408,
259,
275,
413,
272,
598,
14824,
257,
275,
499,
272,
445,
57,
879,
259,
275,
650,
272,
23443,
258,
275,
841,
272,
603,
14565,
33,
275,
959,
272,
1488,
23575,
221,
275,
1227,
272,
598,
907,
57,
259,
275,
1520,
199,
199,
3,
687,
4747,
388,
14,
72,
199,
533,
13036,
6609,
8,
785,
304,
272,
653,
9623,
4519,
275,
378,
88,
383,
327,
8134,
1318,
12,
8134,
8020,
272,
11713,
2830,
4519,
275,
378,
88,
2036,
327,
330,
1019,
1318,
12,
8134,
8020,
272,
11713,
2830,
63,
7111,
29497,
257,
275,
378,
88,
1257,
327,
8134,
1318,
12,
330,
1019,
8020,
199,
199,
533,
13036,
21676,
8,
785,
304,
339,
347,
636,
826,
721,
277,
304,
267,
291,
423,
885,
275,
4747,
708,
14,
1002,
9270,
9616,
3299,
2354,
8,
2676,
708,
14,
13850,
680,
87,
5379,
267,
291,
14,
409,
63,
3288,
8,
277,
423,
885,
9,
267,
291,
423,
885,
63,
1707,
275,
291,
423,
1707,
267,
291,
423,
885,
63,
894,
275,
291,
423,
894,
267,
291,
423,
885,
63,
2487,
275,
291,
423,
2487,
339,
347,
664,
63,
3288,
8,
277,
304,
267,
372,
291,
423,
1707,
435,
291,
423,
894,
627,
3193,
435,
291,
423,
2487,
339,
347,
663,
63,
3288,
8,
277,
12,
574,
304,
267,
291,
423,
1707,
275,
574,
1253,
1520,
267,
291,
423,
894,
275,
334,
585,
4331,
841,
9,
1253,
1520,
267,
291,
423,
2487,
275,
574,
1253,
334,
8886,
6609,
14,
30976,
1204,
13036,
6609,
14,
30976,
63,
7111,
29497,
9,
339,
347,
5305,
63,
452,
8,
277,
12,
641,
63,
3083,
29,
403,
304,
267,
291,
14,
409,
63,
3288,
8,
277,
423,
885,
9,
267,
291,
14,
409,
63,
6614,
8,
3288,
29,
277,
423,
885,
9,
339,
347,
11257,
8,
277,
12,
11257,
29,
403,
12,
10540,
29,
797,
12,
641,
63,
3083,
29,
797,
304,
267,
340,
11257,
365,
488,
26,
288,
11257,
275,
291,
423,
885,
63,
1707,
267,
291,
423,
1707,
275,
11257,
267,
340,
10540,
26,
288,
291,
423,
2487,
8901,
13036,
6609,
14,
30976,
267,
291,
14,
409,
63,
6614,
8,
265,
63,
3083,
29,
265,
63,
3083,
9,
339,
347,
1771,
8,
277,
12,
1771,
29,
403,
12,
10540,
29,
797,
12,
641,
63,
3083,
29,
797,
304,
267,
340,
1771,
365,
488,
26,
288,
1771,
275,
291,
423,
885,
63,
894,
267,
291,
423,
894,
275,
1771,
267,
340,
10540,
26,
288,
291,
423,
2487,
8901,
13036,
6609,
14,
30976,
63,
7111,
29497,
267,
291,
14,
409,
63,
6614,
8,
265,
63,
3083,
29,
265,
63,
3083,
9,
339,
347,
3449,
8,
277,
12,
3449,
29,
403,
12,
641,
63,
3083,
29,
797,
304,
267,
340,
3449,
365,
488,
26,
288,
3449,
275,
291,
423,
885,
63,
2487,
267,
291,
423,
2487,
275,
3449,
267,
291,
14,
409,
63,
6614,
8,
265,
63,
3083,
29,
265,
63,
3083,
9,
339,
347,
663,
63,
6614,
8,
277,
12,
3290,
29,
403,
12,
641,
63,
3083,
29,
797,
304,
267,
340,
3290,
365,
488,
26,
288,
3290,
275,
291,
14,
362,
63,
3288,
342,
267,
2429,
275,
4747,
708,
14,
13850,
267,
340,
641,
63,
3083,
26,
288,
2429,
275,
4747,
708,
14,
18472,
2666,
267,
4747,
708,
14,
1084,
9270,
1872,
1646,
8,
2479,
12,
3290,
9,
339,
347,
664,
63,
3124,
8,
277,
12,
2429,
304,
267,
3421,
275,
4747,
708,
14,
1002,
9270,
9616,
3299,
2354,
8,
2479,
680,
10772,
32766,
267,
327,
13821,
5417,
8983,
787,
378,
13,
6788,
12,
267,
327,
436,
4747,
708,
14,
1084,
9270,
32766,
14292,
413,
13,
6788,
14,
267,
3421,
14,
56,
847,
413,
267,
3421,
14,
57,
847,
413,
267,
372,
3421,
339,
347,
663,
63,
3937,
63,
3124,
8,
277,
12,
3421,
29,
403,
12,
641,
63,
3083,
29,
797,
304,
267,
340,
3421,
365,
488,
26,
288,
327,
41,
6704,
440,
5544,
15161,
314,
3421,
12,
880,
2337,
365,
949,
849,
14,
288,
327,
3124,
275,
291,
14,
362,
63,
3124,
342,
288,
372,
267,
2429,
275,
4747,
708,
14,
13850,
267,
340,
641,
63,
3083,
26,
288,
2429,
275,
4747,
708,
14,
18472,
2666,
267,
4747,
708,
14,
1084,
9270,
32766,
8,
2479,
12,
3421,
9,
339,
347,
3920,
63,
10917,
8,
277,
12,
671,
12,
612,
12,
641,
63,
3083,
29,
797,
304,
267,
2429,
275,
4747,
708,
14,
13850,
267,
340,
641,
63,
3083,
26,
288,
2429,
275,
4747,
708,
14,
18472,
2666,
267,
3421,
275,
291,
14,
362,
63,
3124,
8,
2479,
9,
267,
19477,
63,
3124,
275,
334,
3124,
14,
57,
435,
612,
12,
3421,
14,
56,
435,
671,
9,
267,
4747,
708,
14,
1084,
9270,
32766,
8,
2479,
12,
19477,
63,
3124,
12,
11311,
29,
797,
9,
339,
347,
28343,
63,
5410,
8,
277,
12,
818,
29,
16,
12,
641,
63,
3083,
29,
797,
304,
267,
327,
378,
1077,
5436,
687,
314,
3920,
370,
314,
1284,
402,
314,
6426,
14,
267,
327,
413,
1077,
5436,
687,
314,
3920,
370,
314,
9608,
402,
314,
6426,
14,
267,
327,
499,
1077,
5436,
314,
8039,
6426,
12,
436,
4057,
3920,
370,
334,
17,
12,
17,
9,
267,
2429,
275,
4747,
708,
14,
13850,
267,
340,
641,
63,
3083,
26,
288,
2429,
275,
4747,
708,
14,
18472,
2666,
267,
7117,
4492,
275,
4747,
708,
14,
1002,
9270,
9616,
3299,
2354,
8,
2479,
9,
267,
327,
664,
314,
1329,
402,
4528,
10106,
315,
314,
1453,
3335,
267,
10106,
63,
262,
63,
5410,
275,
7117,
4492,
14,
10772,
2320,
14,
56,
627,
7117,
4492,
14,
10772,
2320,
14,
57,
267,
327,
664,
1329,
402,
4528,
10106,
2544,
1453,
3920,
3421,
267,
10106,
63,
5182,
63,
3937,
275,
7117,
4492,
14,
10772,
2320,
14,
56,
627,
7117,
4492,
14,
10772,
32766,
14,
57,
435,
7117,
4492,
14,
10772,
32766,
14,
56,
267,
340,
818,
508,
378,
26,
288,
687,
63,
7988,
275,
7117
] |
[
1898,
1603,
265,
1619,
290,
869,
580,
15515,
6171,
14,
6289,
650,
13,
16009,
4190,
12,
1937,
5113,
570,
14,
199,
504,
1275,
492,
4747,
708,
421,
199,
3,
687,
4747,
388,
14,
72,
199,
533,
13036,
4117,
8,
785,
304,
272,
26774,
257,
275,
378,
272,
31408,
259,
275,
413,
272,
598,
14824,
257,
275,
499,
272,
445,
57,
879,
259,
275,
650,
272,
23443,
258,
275,
841,
272,
603,
14565,
33,
275,
959,
272,
1488,
23575,
221,
275,
1227,
272,
598,
907,
57,
259,
275,
1520,
199,
199,
3,
687,
4747,
388,
14,
72,
199,
533,
13036,
6609,
8,
785,
304,
272,
653,
9623,
4519,
275,
378,
88,
383,
327,
8134,
1318,
12,
8134,
8020,
272,
11713,
2830,
4519,
275,
378,
88,
2036,
327,
330,
1019,
1318,
12,
8134,
8020,
272,
11713,
2830,
63,
7111,
29497,
257,
275,
378,
88,
1257,
327,
8134,
1318,
12,
330,
1019,
8020,
199,
199,
533,
13036,
21676,
8,
785,
304,
339,
347,
636,
826,
721,
277,
304,
267,
291,
423,
885,
275,
4747,
708,
14,
1002,
9270,
9616,
3299,
2354,
8,
2676,
708,
14,
13850,
680,
87,
5379,
267,
291,
14,
409,
63,
3288,
8,
277,
423,
885,
9,
267,
291,
423,
885,
63,
1707,
275,
291,
423,
1707,
267,
291,
423,
885,
63,
894,
275,
291,
423,
894,
267,
291,
423,
885,
63,
2487,
275,
291,
423,
2487,
339,
347,
664,
63,
3288,
8,
277,
304,
267,
372,
291,
423,
1707,
435,
291,
423,
894,
627,
3193,
435,
291,
423,
2487,
339,
347,
663,
63,
3288,
8,
277,
12,
574,
304,
267,
291,
423,
1707,
275,
574,
1253,
1520,
267,
291,
423,
894,
275,
334,
585,
4331,
841,
9,
1253,
1520,
267,
291,
423,
2487,
275,
574,
1253,
334,
8886,
6609,
14,
30976,
1204,
13036,
6609,
14,
30976,
63,
7111,
29497,
9,
339,
347,
5305,
63,
452,
8,
277,
12,
641,
63,
3083,
29,
403,
304,
267,
291,
14,
409,
63,
3288,
8,
277,
423,
885,
9,
267,
291,
14,
409,
63,
6614,
8,
3288,
29,
277,
423,
885,
9,
339,
347,
11257,
8,
277,
12,
11257,
29,
403,
12,
10540,
29,
797,
12,
641,
63,
3083,
29,
797,
304,
267,
340,
11257,
365,
488,
26,
288,
11257,
275,
291,
423,
885,
63,
1707,
267,
291,
423,
1707,
275,
11257,
267,
340,
10540,
26,
288,
291,
423,
2487,
8901,
13036,
6609,
14,
30976,
267,
291,
14,
409,
63,
6614,
8,
265,
63,
3083,
29,
265,
63,
3083,
9,
339,
347,
1771,
8,
277,
12,
1771,
29,
403,
12,
10540,
29,
797,
12,
641,
63,
3083,
29,
797,
304,
267,
340,
1771,
365,
488,
26,
288,
1771,
275,
291,
423,
885,
63,
894,
267,
291,
423,
894,
275,
1771,
267,
340,
10540,
26,
288,
291,
423,
2487,
8901,
13036,
6609,
14,
30976,
63,
7111,
29497,
267,
291,
14,
409,
63,
6614,
8,
265,
63,
3083,
29,
265,
63,
3083,
9,
339,
347,
3449,
8,
277,
12,
3449,
29,
403,
12,
641,
63,
3083,
29,
797,
304,
267,
340,
3449,
365,
488,
26,
288,
3449,
275,
291,
423,
885,
63,
2487,
267,
291,
423,
2487,
275,
3449,
267,
291,
14,
409,
63,
6614,
8,
265,
63,
3083,
29,
265,
63,
3083,
9,
339,
347,
663,
63,
6614,
8,
277,
12,
3290,
29,
403,
12,
641,
63,
3083,
29,
797,
304,
267,
340,
3290,
365,
488,
26,
288,
3290,
275,
291,
14,
362,
63,
3288,
342,
267,
2429,
275,
4747,
708,
14,
13850,
267,
340,
641,
63,
3083,
26,
288,
2429,
275,
4747,
708,
14,
18472,
2666,
267,
4747,
708,
14,
1084,
9270,
1872,
1646,
8,
2479,
12,
3290,
9,
339,
347,
664,
63,
3124,
8,
277,
12,
2429,
304,
267,
3421,
275,
4747,
708,
14,
1002,
9270,
9616,
3299,
2354,
8,
2479,
680,
10772,
32766,
267,
327,
13821,
5417,
8983,
787,
378,
13,
6788,
12,
267,
327,
436,
4747,
708,
14,
1084,
9270,
32766,
14292,
413,
13,
6788,
14,
267,
3421,
14,
56,
847,
413,
267,
3421,
14,
57,
847,
413,
267,
372,
3421,
339,
347,
663,
63,
3937,
63,
3124,
8,
277,
12,
3421,
29,
403,
12,
641,
63,
3083,
29,
797,
304,
267,
340,
3421,
365,
488,
26,
288,
327,
41,
6704,
440,
5544,
15161,
314,
3421,
12,
880,
2337,
365,
949,
849,
14,
288,
327,
3124,
275,
291,
14,
362,
63,
3124,
342,
288,
372,
267,
2429,
275,
4747,
708,
14,
13850,
267,
340,
641,
63,
3083,
26,
288,
2429,
275,
4747,
708,
14,
18472,
2666,
267,
4747,
708,
14,
1084,
9270,
32766,
8,
2479,
12,
3421,
9,
339,
347,
3920,
63,
10917,
8,
277,
12,
671,
12,
612,
12,
641,
63,
3083,
29,
797,
304,
267,
2429,
275,
4747,
708,
14,
13850,
267,
340,
641,
63,
3083,
26,
288,
2429,
275,
4747,
708,
14,
18472,
2666,
267,
3421,
275,
291,
14,
362,
63,
3124,
8,
2479,
9,
267,
19477,
63,
3124,
275,
334,
3124,
14,
57,
435,
612,
12,
3421,
14,
56,
435,
671,
9,
267,
4747,
708,
14,
1084,
9270,
32766,
8,
2479,
12,
19477,
63,
3124,
12,
11311,
29,
797,
9,
339,
347,
28343,
63,
5410,
8,
277,
12,
818,
29,
16,
12,
641,
63,
3083,
29,
797,
304,
267,
327,
378,
1077,
5436,
687,
314,
3920,
370,
314,
1284,
402,
314,
6426,
14,
267,
327,
413,
1077,
5436,
687,
314,
3920,
370,
314,
9608,
402,
314,
6426,
14,
267,
327,
499,
1077,
5436,
314,
8039,
6426,
12,
436,
4057,
3920,
370,
334,
17,
12,
17,
9,
267,
2429,
275,
4747,
708,
14,
13850,
267,
340,
641,
63,
3083,
26,
288,
2429,
275,
4747,
708,
14,
18472,
2666,
267,
7117,
4492,
275,
4747,
708,
14,
1002,
9270,
9616,
3299,
2354,
8,
2479,
9,
267,
327,
664,
314,
1329,
402,
4528,
10106,
315,
314,
1453,
3335,
267,
10106,
63,
262,
63,
5410,
275,
7117,
4492,
14,
10772,
2320,
14,
56,
627,
7117,
4492,
14,
10772,
2320,
14,
57,
267,
327,
664,
1329,
402,
4528,
10106,
2544,
1453,
3920,
3421,
267,
10106,
63,
5182,
63,
3937,
275,
7117,
4492,
14,
10772,
2320,
14,
56,
627,
7117,
4492,
14,
10772,
32766,
14,
57,
435,
7117,
4492,
14,
10772,
32766,
14,
56,
267,
340,
818,
508,
378,
26,
288,
687,
63,
7988,
275,
7117,
0
] |
[
1,
1,
1,
1,
1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common
|
tests/test_time_validation.py
|
1
|
1362
|
import remindor_common.datetimeutil as d
valid_singular = [
"now",
"1:00pm",
"1:00 pm",
"13:00",
"13",
"1300",
"1pm"
]
valid_repeating = [
"every hour",
"every hour from 1 to 1:00pm",
"every minute",
"every minute from 2:00pm to 1500",
"every 3 minutes",
"every 3 minutes from 3:30pm to 3:45 pm",
"every 2 hours",
"every 2 hours from 8 to 10"
]
invalid = [
"every minute from",
"asdf",
"every minutes to 3",
"2500",
"25",
"-1",
"every -2 minutes",
"every minute from 5 to 1",
"every minute from 5 to 5",
"8/12/13",
"October 12",
"7-21-2013"
]
print "testing valid singular times"
for row in valid_singular:
print "?" + row + "?"
value = d.str_time_simplify(row)
print "!" + str(value) + "!"
if value == None:
print "value should not be None!"
exit()
print ""
print "testing valid repeating times"
for row in valid_repeating:
print "?" + row + "?"
value = d.str_time_simplify(row)
print "!" + str(value) + "!"
if value == None:
print "value should not be None!"
exit()
print ""
print "testing invalid times"
for row in invalid:
print row
value = d.str_time_simplify(row)
print value
if value != None:
print "value should be None!"
exit()
|
gpl-3.0
|
[
646,
18798,
688,
269,
63,
2330,
14,
2083,
1974,
465,
366,
199,
199,
1078,
63,
17045,
275,
359,
272,
298,
2131,
401,
272,
298,
17,
26,
383,
7073,
401,
272,
298,
17,
26,
383,
14207,
401,
272,
298,
969,
26,
383,
401,
272,
298,
969,
401,
272,
298,
969,
383,
401,
272,
298,
17,
7073,
2,
272,
1622,
199,
199,
1078,
63,
5028,
1958,
275,
359,
272,
298,
14287,
6925,
401,
272,
298,
14287,
6925,
687,
413,
370,
413,
26,
383,
7073,
401,
272,
298,
14287,
12709,
401,
272,
298,
14287,
12709,
687,
499,
26,
383,
7073,
370,
24970,
401,
272,
298,
14287,
650,
9395,
401,
272,
298,
14287,
650,
9395,
687,
650,
26,
1216,
7073,
370,
650,
26,
2322,
14207,
401,
272,
298,
14287,
499,
10857,
401,
272,
298,
14287,
499,
10857,
687,
1695,
370,
1616,
2,
272,
1622,
199,
199,
3197,
275,
359,
272,
298,
14287,
12709,
687,
401,
272,
298,
18196,
401,
272,
298,
14287,
9395,
370,
650,
401,
272,
298,
21962,
401,
272,
298,
821,
401,
272,
3905,
17,
401,
272,
298,
14287,
446,
18,
9395,
401,
272,
298,
14287,
12709,
687,
959,
370,
413,
401,
272,
298,
14287,
12709,
687,
959,
370,
959,
401,
272,
298,
24,
15,
713,
15,
969,
401,
272,
298,
17584,
22459,
3144,
401,
272,
298,
23,
13,
2025,
13,
6965,
2,
272,
1622,
199,
199,
1361,
298,
4776,
1686,
15823,
5431,
2,
199,
509,
1962,
315,
1686,
63,
17045,
26,
272,
870,
29325,
435,
1962,
435,
29325,
272,
574,
275,
366,
14,
495,
63,
521,
63,
19084,
8,
1143,
9,
272,
870,
298,
9539,
435,
620,
8,
585,
9,
435,
298,
9539,
339,
340,
574,
508,
488,
26,
267,
870,
298,
585,
1077,
440,
506,
488,
9539,
267,
4458,
342,
199,
199,
1361,
3087,
199,
1361,
298,
4776,
1686,
6375,
1958,
5431,
2,
199,
509,
1962,
315,
1686,
63,
5028,
1958,
26,
272,
870,
29325,
435,
1962,
435,
29325,
272,
574,
275,
366,
14,
495,
63,
521,
63,
19084,
8,
1143,
9,
272,
870,
298,
9539,
435,
620,
8,
585,
9,
435,
298,
9539,
339,
340,
574,
508,
488,
26,
267,
870,
298,
585,
1077,
440,
506,
488,
9539,
267,
4458,
342,
199,
199,
1361,
3087,
199,
1361,
298,
4776,
3866,
5431,
2,
199,
509,
1962,
315,
3866,
26,
272,
870,
1962,
272,
574,
275,
366,
14,
495,
63,
521,
63,
19084,
8,
1143,
9,
272,
870,
574,
339,
340,
574,
1137,
488,
26,
267,
870,
298,
585,
1077,
506,
488,
9539,
267,
4458,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
18798,
688,
269,
63,
2330,
14,
2083,
1974,
465,
366,
199,
199,
1078,
63,
17045,
275,
359,
272,
298,
2131,
401,
272,
298,
17,
26,
383,
7073,
401,
272,
298,
17,
26,
383,
14207,
401,
272,
298,
969,
26,
383,
401,
272,
298,
969,
401,
272,
298,
969,
383,
401,
272,
298,
17,
7073,
2,
272,
1622,
199,
199,
1078,
63,
5028,
1958,
275,
359,
272,
298,
14287,
6925,
401,
272,
298,
14287,
6925,
687,
413,
370,
413,
26,
383,
7073,
401,
272,
298,
14287,
12709,
401,
272,
298,
14287,
12709,
687,
499,
26,
383,
7073,
370,
24970,
401,
272,
298,
14287,
650,
9395,
401,
272,
298,
14287,
650,
9395,
687,
650,
26,
1216,
7073,
370,
650,
26,
2322,
14207,
401,
272,
298,
14287,
499,
10857,
401,
272,
298,
14287,
499,
10857,
687,
1695,
370,
1616,
2,
272,
1622,
199,
199,
3197,
275,
359,
272,
298,
14287,
12709,
687,
401,
272,
298,
18196,
401,
272,
298,
14287,
9395,
370,
650,
401,
272,
298,
21962,
401,
272,
298,
821,
401,
272,
3905,
17,
401,
272,
298,
14287,
446,
18,
9395,
401,
272,
298,
14287,
12709,
687,
959,
370,
413,
401,
272,
298,
14287,
12709,
687,
959,
370,
959,
401,
272,
298,
24,
15,
713,
15,
969,
401,
272,
298,
17584,
22459,
3144,
401,
272,
298,
23,
13,
2025,
13,
6965,
2,
272,
1622,
199,
199,
1361,
298,
4776,
1686,
15823,
5431,
2,
199,
509,
1962,
315,
1686,
63,
17045,
26,
272,
870,
29325,
435,
1962,
435,
29325,
272,
574,
275,
366,
14,
495,
63,
521,
63,
19084,
8,
1143,
9,
272,
870,
298,
9539,
435,
620,
8,
585,
9,
435,
298,
9539,
339,
340,
574,
508,
488,
26,
267,
870,
298,
585,
1077,
440,
506,
488,
9539,
267,
4458,
342,
199,
199,
1361,
3087,
199,
1361,
298,
4776,
1686,
6375,
1958,
5431,
2,
199,
509,
1962,
315,
1686,
63,
5028,
1958,
26,
272,
870,
29325,
435,
1962,
435,
29325,
272,
574,
275,
366,
14,
495,
63,
521,
63,
19084,
8,
1143,
9,
272,
870,
298,
9539,
435,
620,
8,
585,
9,
435,
298,
9539,
339,
340,
574,
508,
488,
26,
267,
870,
298,
585,
1077,
440,
506,
488,
9539,
267,
4458,
342,
199,
199,
1361,
3087,
199,
1361,
298,
4776,
3866,
5431,
2,
199,
509,
1962,
315,
3866,
26,
272,
870,
1962,
272,
574,
275,
366,
14,
495,
63,
521,
63,
19084,
8,
1143,
9,
272,
870,
574,
339,
340,
574,
1137,
488,
26,
267,
870,
298,
585,
1077,
506,
488,
9539,
267,
4458,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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what-1.0.9-py2.6.egg/repoze/what/release.py
|
1
|
1208
|
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2008-2009, Gustavo Narea <me@gustavonarea.net>
# All Rights Reserved.
#
# This software is subject to the provisions of the BSD-like license at
# http://www.repoze.org/LICENSE.txt. A copy of the license should accompany
# this distribution. THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL
# EXPRESS OR IMPLIED WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND
# FITNESS FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""
repoze.what release information.
The version number is loaded to help the Quickstart plugin configure
repoze.what correctly, depending on the version available -- although it may
be useful on other packages.
"""
import os
_here = os.path.abspath(os.path.dirname(__file__))
_root = os.path.dirname(os.path.dirname(_here))
version = open(os.path.join(_root, 'VERSION.txt')).readline().rstrip()
# The major version: If version=='3.0.2rc4', the major version is int(3).
major_version = int(version.split('.')[0])
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
1898,
334,
67,
9,
9079,
13,
8664,
12,
598,
833,
1214,
79,
653,
6789,
665,
278,
32,
71,
833,
1214,
265,
6789,
14,
846,
30,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
961,
2032,
365,
5420,
370,
314,
1727,
1356,
402,
314,
6289,
13,
2930,
4190,
737,
199,
3,
1455,
921,
1544,
14,
3417,
806,
14,
1308,
15,
3961,
14,
2424,
14,
221,
437,
1331,
402,
314,
4190,
1077,
21727,
199,
3,
642,
4084,
14,
221,
5749,
4141,
2281,
7049,
298,
1179,
2281,
2,
2401,
1821,
2401,
11727,
199,
3,
7168,
1549,
5292,
2990,
9315,
9706,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
199,
3,
2334,
5292,
2990,
1634,
377,
16507,
12,
3169,
12,
437,
9741,
7834,
1621,
12600,
12,
2401,
199,
3,
3092,
2381,
437,
3115,
3104,
14,
199,
3,
199,
4605,
199,
199,
624,
199,
3417,
806,
14,
10058,
4683,
2556,
14,
199,
199,
1918,
1015,
1329,
365,
6511,
370,
1720,
314,
27534,
928,
3589,
7908,
199,
3417,
806,
14,
10058,
6657,
12,
10298,
641,
314,
1015,
2808,
1553,
22160,
652,
1443,
199,
1235,
2997,
641,
1163,
6117,
14,
199,
199,
624,
199,
199,
646,
747,
199,
199,
63,
1681,
275,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
3475,
3460,
493,
8964,
199,
63,
1231,
275,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
3475,
1547,
1681,
430,
199,
199,
1023,
275,
1551,
8,
736,
14,
515,
14,
904,
1547,
1231,
12,
283,
4612,
14,
2424,
11103,
6407,
1252,
6735,
342,
199,
199,
3,
710,
12160,
1015,
26,
982,
1015,
6803,
19,
14,
16,
14,
18,
1195,
20,
297,
314,
12160,
1015,
365,
1109,
8,
19,
680,
199,
8452,
63,
1023,
275,
1109,
8,
1023,
14,
1294,
19237,
16,
566,
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
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
1898,
334,
67,
9,
9079,
13,
8664,
12,
598,
833,
1214,
79,
653,
6789,
665,
278,
32,
71,
833,
1214,
265,
6789,
14,
846,
30,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
961,
2032,
365,
5420,
370,
314,
1727,
1356,
402,
314,
6289,
13,
2930,
4190,
737,
199,
3,
1455,
921,
1544,
14,
3417,
806,
14,
1308,
15,
3961,
14,
2424,
14,
221,
437,
1331,
402,
314,
4190,
1077,
21727,
199,
3,
642,
4084,
14,
221,
5749,
4141,
2281,
7049,
298,
1179,
2281,
2,
2401,
1821,
2401,
11727,
199,
3,
7168,
1549,
5292,
2990,
9315,
9706,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
199,
3,
2334,
5292,
2990,
1634,
377,
16507,
12,
3169,
12,
437,
9741,
7834,
1621,
12600,
12,
2401,
199,
3,
3092,
2381,
437,
3115,
3104,
14,
199,
3,
199,
4605,
199,
199,
624,
199,
3417,
806,
14,
10058,
4683,
2556,
14,
199,
199,
1918,
1015,
1329,
365,
6511,
370,
1720,
314,
27534,
928,
3589,
7908,
199,
3417,
806,
14,
10058,
6657,
12,
10298,
641,
314,
1015,
2808,
1553,
22160,
652,
1443,
199,
1235,
2997,
641,
1163,
6117,
14,
199,
199,
624,
199,
199,
646,
747,
199,
199,
63,
1681,
275,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
3475,
3460,
493,
8964,
199,
63,
1231,
275,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
3475,
1547,
1681,
430,
199,
199,
1023,
275,
1551,
8,
736,
14,
515,
14,
904,
1547,
1231,
12,
283,
4612,
14,
2424,
11103,
6407,
1252,
6735,
342,
199,
199,
3,
710,
12160,
1015,
26,
982,
1015,
6803,
19,
14,
16,
14,
18,
1195,
20,
297,
314,
12160,
1015,
365,
1109,
8,
19,
680,
199,
8452,
63,
1023,
275,
1109,
8,
1023,
14,
1294,
19237,
16,
566,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
t794104/ansible
|
lib/ansible/plugins/action/command.py
|
117
|
1121
|
# Copyright: (c) 2017, 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
from ansible import constants as C
from ansible.plugins.action import ActionBase
from ansible.utils.vars import merge_hash
class ActionModule(ActionBase):
def run(self, tmp=None, task_vars=None):
self._supports_async = True
results = super(ActionModule, self).run(tmp, task_vars)
del tmp # tmp no longer has any effect
# Command module has a special config option to turn off the command nanny warnings
if 'warn' not in self._task.args:
self._task.args['warn'] = C.COMMAND_WARNINGS
wrap_async = self._task.async_val and not self._connection.has_native_async
results = merge_hash(results, self._execute_module(task_vars=task_vars, wrap_async=wrap_async))
if not wrap_async:
# remove a temporary path we created
self._remove_tmp_path(self._connection._shell.tmpdir)
return results
|
gpl-3.0
|
[
3,
1898,
26,
334,
67,
9,
9708,
12,
2622,
7290,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
504,
3242,
492,
5262,
465,
445,
199,
504,
3242,
14,
5265,
14,
1287,
492,
10033,
1563,
199,
504,
3242,
14,
1208,
14,
2936,
492,
5389,
63,
2227,
421,
199,
533,
10033,
2377,
8,
3310,
1563,
304,
339,
347,
1255,
8,
277,
12,
3529,
29,
403,
12,
2120,
63,
2936,
29,
403,
304,
267,
291,
423,
9823,
63,
4146,
275,
715,
267,
2058,
275,
1613,
8,
3310,
2377,
12,
291,
680,
1065,
8,
2791,
12,
2120,
63,
2936,
9,
267,
2150,
3529,
221,
327,
3529,
949,
8088,
965,
1263,
7763,
398,
327,
5817,
859,
965,
282,
4539,
1101,
945,
370,
7485,
2331,
314,
1414,
302,
1189,
89,
3598,
267,
340,
283,
4050,
7,
440,
315,
291,
423,
1765,
14,
589,
26,
288,
291,
423,
1765,
14,
589,
459,
4050,
418,
275,
445,
14,
10761,
63,
17449,
3881,
398,
4816,
63,
4146,
275,
291,
423,
1765,
14,
4146,
63,
637,
436,
440,
291,
423,
2105,
14,
1989,
63,
6106,
63,
4146,
267,
2058,
275,
5389,
63,
2227,
8,
2604,
12,
291,
423,
2526,
63,
578,
8,
1765,
63,
2936,
29,
1765,
63,
2936,
12,
4816,
63,
4146,
29,
3823,
63,
4146,
430,
398,
340,
440,
4816,
63,
4146,
26,
288,
327,
2813,
282,
7937,
931,
781,
2737,
288,
291,
423,
2168,
63,
2791,
63,
515,
8,
277,
423,
2105,
423,
5641,
14,
8616,
9,
398,
372,
2058,
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
] |
[
1898,
26,
334,
67,
9,
9708,
12,
2622,
7290,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
504,
3242,
492,
5262,
465,
445,
199,
504,
3242,
14,
5265,
14,
1287,
492,
10033,
1563,
199,
504,
3242,
14,
1208,
14,
2936,
492,
5389,
63,
2227,
421,
199,
533,
10033,
2377,
8,
3310,
1563,
304,
339,
347,
1255,
8,
277,
12,
3529,
29,
403,
12,
2120,
63,
2936,
29,
403,
304,
267,
291,
423,
9823,
63,
4146,
275,
715,
267,
2058,
275,
1613,
8,
3310,
2377,
12,
291,
680,
1065,
8,
2791,
12,
2120,
63,
2936,
9,
267,
2150,
3529,
221,
327,
3529,
949,
8088,
965,
1263,
7763,
398,
327,
5817,
859,
965,
282,
4539,
1101,
945,
370,
7485,
2331,
314,
1414,
302,
1189,
89,
3598,
267,
340,
283,
4050,
7,
440,
315,
291,
423,
1765,
14,
589,
26,
288,
291,
423,
1765,
14,
589,
459,
4050,
418,
275,
445,
14,
10761,
63,
17449,
3881,
398,
4816,
63,
4146,
275,
291,
423,
1765,
14,
4146,
63,
637,
436,
440,
291,
423,
2105,
14,
1989,
63,
6106,
63,
4146,
267,
2058,
275,
5389,
63,
2227,
8,
2604,
12,
291,
423,
2526,
63,
578,
8,
1765,
63,
2936,
29,
1765,
63,
2936,
12,
4816,
63,
4146,
29,
3823,
63,
4146,
430,
398,
340,
440,
4816,
63,
4146,
26,
288,
327,
2813,
282,
7937,
931,
781,
2737,
288,
291,
423,
2168,
63,
2791,
63,
515,
8,
277,
423,
2105,
423,
5641,
14,
8616,
9,
398,
372,
2058,
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,
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,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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
] |
maestrano/openerp
|
openerp/addons/account/project/report/analytic_balance.py
|
60
|
7010
|
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import time
from openerp.report import report_sxw
class account_analytic_balance(report_sxw.rml_parse):
def __init__(self, cr, uid, name, context):
super(account_analytic_balance, self).__init__(cr, uid, name, context=context)
self.localcontext.update( {
'time': time,
'get_objects': self._get_objects,
'lines_g': self._lines_g,
'move_sum': self._move_sum,
'sum_all': self._sum_all,
'sum_balance': self._sum_balance,
'move_sum_balance': self._move_sum_balance,
})
self.acc_ids = []
self.read_data = []
self.empty_acc = False
self.acc_data_dict = {}# maintains a relation with an account with its successors.
self.acc_sum_list = []# maintains a list of all ids
def get_children(self, ids):
read_data = self.pool.get('account.analytic.account').read(self.cr, self.uid, ids,['child_ids','code','complete_name','balance'])
for data in read_data:
if (data['id'] not in self.acc_ids):
inculde_empty = True
if (not self.empty_acc) and data['balance'] == 0.00:
inculde_empty = False
if inculde_empty:
self.acc_ids.append(data['id'])
self.read_data.append(data)
if data['child_ids']:
self.get_children(data['child_ids'])
return True
def _get_objects(self, empty_acc):
if self.read_data:
return self.read_data
self.empty_acc = empty_acc
self.read_data = []
self.get_children(self.ids)
return self.read_data
def _lines_g(self, account_id, date1, date2):
account_analytic_obj = self.pool.get('account.analytic.account')
ids = account_analytic_obj.search(self.cr, self.uid,
[('parent_id', 'child_of', [account_id])])
self.cr.execute("SELECT aa.name AS name, aa.code AS code, \
sum(aal.amount) AS balance, sum(aal.unit_amount) AS quantity \
FROM account_analytic_line AS aal, account_account AS aa \
WHERE (aal.general_account_id=aa.id) \
AND (aal.account_id IN %s)\
AND (date>=%s) AND (date<=%s) AND aa.active \
GROUP BY aal.general_account_id, aa.name, aa.code, aal.code \
ORDER BY aal.code", (tuple(ids), date1, date2))
res = self.cr.dictfetchall()
for r in res:
if r['balance'] > 0:
r['debit'] = r['balance']
r['credit'] = 0.0
elif r['balance'] < 0:
r['debit'] = 0.0
r['credit'] = -r['balance']
else:
r['balance'] == 0
r['debit'] = 0.0
r['credit'] = 0.0
return res
def _move_sum(self, account_id, date1, date2, option):
if account_id not in self.acc_data_dict:
account_analytic_obj = self.pool.get('account.analytic.account')
ids = account_analytic_obj.search(self.cr, self.uid,[('parent_id', 'child_of', [account_id])])
self.acc_data_dict[account_id] = ids
else:
ids = self.acc_data_dict[account_id]
query_params = (tuple(ids), date1, date2)
if option == "credit":
self.cr.execute("SELECT COALESCE(-sum(amount),0.0) FROM account_analytic_line \
WHERE account_id IN %s AND date>=%s AND date<=%s AND amount<0",query_params)
elif option == "debit":
self.cr.execute("SELECT COALESCE(sum(amount),0.0) FROM account_analytic_line \
WHERE account_id IN %s\
AND date>=%s AND date<=%s AND amount>0",query_params)
elif option == "quantity":
self.cr.execute("SELECT COALESCE(sum(unit_amount),0.0) FROM account_analytic_line \
WHERE account_id IN %s\
AND date>=%s AND date<=%s",query_params)
return self.cr.fetchone()[0] or 0.0
def _move_sum_balance(self, account_id, date1, date2):
debit = self._move_sum(account_id, date1, date2, 'debit')
credit = self._move_sum(account_id, date1, date2, 'credit')
return (debit-credit)
def _sum_all(self, accounts, date1, date2, option):
account_analytic_obj = self.pool.get('account.analytic.account')
ids = map(lambda x: x['id'], accounts)
if not ids:
return 0.0
if not self.acc_sum_list:
ids2 = account_analytic_obj.search(self.cr, self.uid,[('parent_id', 'child_of', ids)])
self.acc_sum_list = ids2
else:
ids2 = self.acc_sum_list
query_params = (tuple(ids2), date1, date2)
if option == "debit":
self.cr.execute("SELECT COALESCE(sum(amount),0.0) FROM account_analytic_line \
WHERE account_id IN %s AND date>=%s AND date<=%s AND amount>0",query_params)
elif option == "credit":
self.cr.execute("SELECT COALESCE(-sum(amount),0.0) FROM account_analytic_line \
WHERE account_id IN %s AND date>=%s AND date<=%s AND amount<0",query_params)
elif option == "quantity":
self.cr.execute("SELECT COALESCE(sum(unit_amount),0.0) FROM account_analytic_line \
WHERE account_id IN %s AND date>=%s AND date<=%s",query_params)
return self.cr.fetchone()[0] or 0.0
def _sum_balance(self, accounts, date1, date2):
debit = self._sum_all(accounts, date1, date2, 'debit') or 0.0
credit = self._sum_all(accounts, date1, date2, 'credit') or 0.0
return (debit-credit)
report_sxw.report_sxw('report.account.analytic.account.balance',
'account.analytic.account', 'addons/account/project/report/analytic_balance.rml',
parser=account_analytic_balance, header="internal")
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
646,
900,
199,
199,
504,
5166,
14,
3070,
492,
3622,
63,
20851,
421,
199,
533,
2933,
63,
9782,
63,
7358,
8,
3070,
63,
20851,
14,
16300,
63,
1122,
304,
272,
347,
636,
826,
721,
277,
12,
2467,
12,
1747,
12,
536,
12,
1067,
304,
267,
1613,
8,
2048,
63,
9782,
63,
7358,
12,
291,
2843,
826,
721,
1556,
12,
1747,
12,
536,
12,
1067,
29,
1100,
9,
267,
291,
14,
17886,
14,
873,
8,
469,
288,
283,
521,
356,
900,
12,
288,
283,
362,
63,
1462,
356,
291,
423,
362,
63,
1462,
12,
288,
283,
1278,
63,
71,
356,
291,
423,
1278,
63,
71,
12,
288,
283,
1185,
63,
1838,
356,
291,
423,
1185,
63,
1838,
12,
288,
283,
1838,
63,
452,
356,
291,
423,
1838,
63,
452,
12,
288,
283,
1838,
63,
7358,
356,
291,
423,
1838,
63,
7358,
12,
288,
283,
1185,
63,
1838,
63,
7358,
356,
291,
423,
1185,
63,
1838,
63,
7358,
12,
267,
3828,
267,
291,
14,
5470,
63,
1580,
275,
942,
267,
291,
14,
739,
63,
576,
275,
942,
267,
291,
14,
1667,
63,
5470,
275,
756,
267,
291,
14,
5470,
63,
576,
63,
807,
275,
1052,
3,
11075,
83,
282,
5850,
543,
376,
2933,
543,
2399,
3182,
1384,
14,
267,
291,
14,
5470,
63,
1838,
63,
513,
275,
942,
3,
11075,
83,
282,
769,
402,
1006,
2762,
339,
347,
664,
63,
3223,
8,
277,
12,
2762,
304,
267,
1586,
63,
576,
275,
291,
14,
2293,
14,
362,
360,
2048,
14,
9782,
14,
2048,
1959,
739,
8,
277,
14,
1556,
12,
291,
14,
1535,
12,
2762,
12,
459,
1739,
63,
1580,
1673,
600,
1673,
4883,
63,
354,
1673,
7358,
1105,
267,
367,
666,
315,
1586,
63,
576,
26,
288,
340,
334,
576,
459,
344,
418,
440,
315,
291,
14,
5470,
63,
1580,
304,
355,
315,
3119,
271,
63,
1667,
275,
221,
715,
355,
340,
334,
1397,
291,
14,
1667,
63,
5470,
9,
436,
666,
459,
7358,
418,
508,
378,
14,
383,
26,
490,
315,
3119,
271,
63,
1667,
275,
756,
355,
340,
315,
3119,
271,
63,
1667,
26,
490,
291,
14,
5470,
63,
1580,
14,
740,
8,
576,
459,
344,
1105,
490,
291,
14,
739,
63,
576,
14,
740,
8,
576,
9,
490,
340,
666,
459,
1739,
63,
1580,
2565,
717,
291,
14,
362,
63,
3223,
8,
576,
459,
1739,
63,
1580,
1105,
267,
372,
715,
2378,
347,
485,
362,
63,
1462,
8,
277,
12,
2701,
63,
5470,
304,
267,
340,
291,
14,
739,
63,
576,
26,
288,
372,
291,
14,
739,
63,
576,
267,
291,
14,
1667,
63,
5470,
275,
2701,
63,
5470,
267,
291,
14,
739,
63,
576,
275,
942,
267,
291,
14,
362,
63,
3223,
8,
277,
14,
1580,
9,
267,
372,
291,
14,
739,
63,
576,
339,
347,
485,
1278,
63,
71,
8,
277,
12,
2933,
63,
344,
12,
1434,
17,
12,
1434,
18,
304,
267,
2933,
63,
9782,
63,
1113,
275,
291,
14,
2293,
14,
362,
360,
2048,
14,
9782,
14,
2048,
358,
267,
2762,
275,
2933,
63,
9782,
63,
1113,
14,
1733,
8,
277,
14,
1556,
12,
291,
14,
1535,
12,
355,
4274,
1708,
63,
344,
297,
283,
1739,
63,
1618,
297,
359,
2048,
63,
344,
24310,
267,
291,
14,
1556,
14,
2526,
480,
4859,
18319,
14,
354,
4319,
536,
12,
18319,
14,
600,
4319,
1233,
12,
971,
490,
3089,
8,
65,
279,
14,
4606,
9,
4319,
14094,
12,
3089,
8,
65,
279,
14,
3248,
63,
4606,
9,
4319,
12524,
971,
355,
4442,
2933,
63,
9782,
63,
604,
4319,
282,
279,
12,
2933,
63,
2048,
4319,
18319,
971,
355,
6038,
334,
65,
279,
14,
10706,
63,
2048,
63,
344,
29,
2158,
14,
344,
9,
971,
490,
2401,
334,
65,
279,
14,
2048,
63,
344,
1621,
450,
83,
2862,
490,
2401,
334,
602,
30,
2458,
83,
9,
2401,
334,
602,
28,
2458,
83,
9,
2401,
18319,
14,
2682,
971,
355,
15443,
6515,
282,
279,
14,
10706,
63,
2048,
63,
344,
12,
18319,
14,
354,
12,
18319,
14,
600,
12,
282,
279,
14,
600,
971,
355,
16044,
6515,
282,
279,
14,
600,
401,
334,
2960,
8,
1580,
395,
1434,
17,
12,
1434,
18,
430,
267,
522,
275,
291,
14,
1556,
14,
807,
10174,
342,
398,
367,
519,
315,
522,
26,
288,
340,
519,
459,
7358,
418,
690,
378,
26,
355,
519,
459,
12964,
418,
275,
519,
459,
7358,
418,
355,
519,
459,
9365,
418,
275,
378,
14,
16,
288,
916,
519,
459,
7358,
418,
665,
378,
26,
355,
519,
459,
12964,
418,
275,
378,
14,
16,
355,
519,
459,
9365,
418,
275,
446,
82,
459,
7358,
418,
288,
587,
26,
355,
519,
459,
7358,
418,
508,
378,
355,
519,
459,
12964,
418,
275,
378,
14,
16,
355,
519,
459,
9365,
418,
275,
378,
14,
16,
267,
372,
522,
339,
347,
485,
1185,
63,
1838,
8,
277,
12,
2933,
63,
344,
12,
1434,
17,
12,
1434,
18,
12,
945,
304,
267,
340,
2933,
63,
344
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
646,
900,
199,
199,
504,
5166,
14,
3070,
492,
3622,
63,
20851,
421,
199,
533,
2933,
63,
9782,
63,
7358,
8,
3070,
63,
20851,
14,
16300,
63,
1122,
304,
272,
347,
636,
826,
721,
277,
12,
2467,
12,
1747,
12,
536,
12,
1067,
304,
267,
1613,
8,
2048,
63,
9782,
63,
7358,
12,
291,
2843,
826,
721,
1556,
12,
1747,
12,
536,
12,
1067,
29,
1100,
9,
267,
291,
14,
17886,
14,
873,
8,
469,
288,
283,
521,
356,
900,
12,
288,
283,
362,
63,
1462,
356,
291,
423,
362,
63,
1462,
12,
288,
283,
1278,
63,
71,
356,
291,
423,
1278,
63,
71,
12,
288,
283,
1185,
63,
1838,
356,
291,
423,
1185,
63,
1838,
12,
288,
283,
1838,
63,
452,
356,
291,
423,
1838,
63,
452,
12,
288,
283,
1838,
63,
7358,
356,
291,
423,
1838,
63,
7358,
12,
288,
283,
1185,
63,
1838,
63,
7358,
356,
291,
423,
1185,
63,
1838,
63,
7358,
12,
267,
3828,
267,
291,
14,
5470,
63,
1580,
275,
942,
267,
291,
14,
739,
63,
576,
275,
942,
267,
291,
14,
1667,
63,
5470,
275,
756,
267,
291,
14,
5470,
63,
576,
63,
807,
275,
1052,
3,
11075,
83,
282,
5850,
543,
376,
2933,
543,
2399,
3182,
1384,
14,
267,
291,
14,
5470,
63,
1838,
63,
513,
275,
942,
3,
11075,
83,
282,
769,
402,
1006,
2762,
339,
347,
664,
63,
3223,
8,
277,
12,
2762,
304,
267,
1586,
63,
576,
275,
291,
14,
2293,
14,
362,
360,
2048,
14,
9782,
14,
2048,
1959,
739,
8,
277,
14,
1556,
12,
291,
14,
1535,
12,
2762,
12,
459,
1739,
63,
1580,
1673,
600,
1673,
4883,
63,
354,
1673,
7358,
1105,
267,
367,
666,
315,
1586,
63,
576,
26,
288,
340,
334,
576,
459,
344,
418,
440,
315,
291,
14,
5470,
63,
1580,
304,
355,
315,
3119,
271,
63,
1667,
275,
221,
715,
355,
340,
334,
1397,
291,
14,
1667,
63,
5470,
9,
436,
666,
459,
7358,
418,
508,
378,
14,
383,
26,
490,
315,
3119,
271,
63,
1667,
275,
756,
355,
340,
315,
3119,
271,
63,
1667,
26,
490,
291,
14,
5470,
63,
1580,
14,
740,
8,
576,
459,
344,
1105,
490,
291,
14,
739,
63,
576,
14,
740,
8,
576,
9,
490,
340,
666,
459,
1739,
63,
1580,
2565,
717,
291,
14,
362,
63,
3223,
8,
576,
459,
1739,
63,
1580,
1105,
267,
372,
715,
2378,
347,
485,
362,
63,
1462,
8,
277,
12,
2701,
63,
5470,
304,
267,
340,
291,
14,
739,
63,
576,
26,
288,
372,
291,
14,
739,
63,
576,
267,
291,
14,
1667,
63,
5470,
275,
2701,
63,
5470,
267,
291,
14,
739,
63,
576,
275,
942,
267,
291,
14,
362,
63,
3223,
8,
277,
14,
1580,
9,
267,
372,
291,
14,
739,
63,
576,
339,
347,
485,
1278,
63,
71,
8,
277,
12,
2933,
63,
344,
12,
1434,
17,
12,
1434,
18,
304,
267,
2933,
63,
9782,
63,
1113,
275,
291,
14,
2293,
14,
362,
360,
2048,
14,
9782,
14,
2048,
358,
267,
2762,
275,
2933,
63,
9782,
63,
1113,
14,
1733,
8,
277,
14,
1556,
12,
291,
14,
1535,
12,
355,
4274,
1708,
63,
344,
297,
283,
1739,
63,
1618,
297,
359,
2048,
63,
344,
24310,
267,
291,
14,
1556,
14,
2526,
480,
4859,
18319,
14,
354,
4319,
536,
12,
18319,
14,
600,
4319,
1233,
12,
971,
490,
3089,
8,
65,
279,
14,
4606,
9,
4319,
14094,
12,
3089,
8,
65,
279,
14,
3248,
63,
4606,
9,
4319,
12524,
971,
355,
4442,
2933,
63,
9782,
63,
604,
4319,
282,
279,
12,
2933,
63,
2048,
4319,
18319,
971,
355,
6038,
334,
65,
279,
14,
10706,
63,
2048,
63,
344,
29,
2158,
14,
344,
9,
971,
490,
2401,
334,
65,
279,
14,
2048,
63,
344,
1621,
450,
83,
2862,
490,
2401,
334,
602,
30,
2458,
83,
9,
2401,
334,
602,
28,
2458,
83,
9,
2401,
18319,
14,
2682,
971,
355,
15443,
6515,
282,
279,
14,
10706,
63,
2048,
63,
344,
12,
18319,
14,
354,
12,
18319,
14,
600,
12,
282,
279,
14,
600,
971,
355,
16044,
6515,
282,
279,
14,
600,
401,
334,
2960,
8,
1580,
395,
1434,
17,
12,
1434,
18,
430,
267,
522,
275,
291,
14,
1556,
14,
807,
10174,
342,
398,
367,
519,
315,
522,
26,
288,
340,
519,
459,
7358,
418,
690,
378,
26,
355,
519,
459,
12964,
418,
275,
519,
459,
7358,
418,
355,
519,
459,
9365,
418,
275,
378,
14,
16,
288,
916,
519,
459,
7358,
418,
665,
378,
26,
355,
519,
459,
12964,
418,
275,
378,
14,
16,
355,
519,
459,
9365,
418,
275,
446,
82,
459,
7358,
418,
288,
587,
26,
355,
519,
459,
7358,
418,
508,
378,
355,
519,
459,
12964,
418,
275,
378,
14,
16,
355,
519,
459,
9365,
418,
275,
378,
14,
16,
267,
372,
522,
339,
347,
485,
1185,
63,
1838,
8,
277,
12,
2933,
63,
344,
12,
1434,
17,
12,
1434,
18,
12,
945,
304,
267,
340,
2933,
63,
344,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
picleslivre/schemaprobe
|
schemaprobe.py
|
1
|
2343
|
from __future__ import unicode_literals
import sys
import functools
import json
try:
import jsonschema
except ImportError:
jsonschema = None
try:
import requests
except ImportError:
requests = None
__version__ = '1.0.0.dev1'
__all__ = ['ensure', 'JsonProbe']
# --------------
# Py2 compat
# --------------
PY2 = sys.version_info[0] == 2
if PY2:
string_types = (str, unicode)
else:
string_types = (str,)
# --------------
class JsonProbe(object):
"""
An instance that knows how to perform validations against json-schema.
"""
_jsonschema = jsonschema
def __init__(self, schema):
"""
:param schema: json-schema as json-encoded text or python datastructures.
"""
if self._jsonschema is None:
raise TypeError('Missing dependency `jsonschema`.')
self.schema = self._normalize_input(schema)
def validate(self, input):
"""
Validate `input` agains the given schema.
:param input: json-encoded text or python datastructures.
:returns: boolean
"""
data = self._normalize_input(input)
try:
jsonschema.validate(data, self.schema)
except self._jsonschema.ValidationError:
return False
else:
return True
def _normalize_input(self, input):
"""
Always return python datastructures.
:param input: json-encoded text or python datastructures.
"""
if isinstance(input, string_types):
return json.loads(input)
else:
return input
def ensure(probe):
"""
Decorator that asserts the returned value is valid against `probe`.
"""
def ensure_decorator(f):
@functools.wraps(f)
def wrapper(*args, **kwargs):
result = f(*args, **kwargs)
if probe.validate(result):
return result
else:
raise TypeError('Returned data does not conform with the given schema.')
return wrapper
return ensure_decorator
class TestCaseMixin(object):
def assertSchemaIsValid(self, probe, resource_url, msg=None):
api_sample = requests.get(resource_url)
if not probe.validate(api_sample.json()):
raise self.failureException(msg or 'Schema is invalid.')
|
bsd-2-clause
|
[
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
984,
199,
646,
9143,
199,
646,
2022,
199,
893,
26,
272,
492,
2022,
3629,
199,
2590,
3545,
26,
272,
2022,
3629,
275,
488,
199,
893,
26,
272,
492,
4145,
199,
2590,
3545,
26,
272,
4145,
275,
488,
421,
199,
363,
1023,
363,
275,
283,
17,
14,
16,
14,
16,
14,
2374,
17,
7,
199,
199,
363,
452,
363,
275,
788,
7505,
297,
283,
9653,
16939,
418,
421,
199,
3,
3001,
8648,
199,
3,
1611,
18,
8434,
199,
3,
3001,
8648,
199,
4521,
18,
275,
984,
14,
1023,
63,
815,
59,
16,
61,
508,
499,
199,
199,
692,
7843,
18,
26,
272,
1059,
63,
1313,
275,
334,
495,
12,
2649,
9,
199,
2836,
26,
272,
1059,
63,
1313,
275,
334,
495,
4258,
199,
3,
3001,
8648,
421,
199,
533,
14587,
16939,
8,
785,
304,
272,
408,
272,
1626,
1256,
626,
19428,
4212,
370,
5147,
1686,
1298,
6169,
2022,
13,
3629,
14,
272,
408,
272,
485,
1001,
3629,
275,
2022,
3629,
339,
347,
636,
826,
721,
277,
12,
4177,
304,
267,
408,
267,
520,
635,
4177,
26,
2022,
13,
3629,
465,
2022,
13,
8167,
1318,
503,
2366,
666,
13547,
14,
267,
408,
267,
340,
291,
423,
1001,
3629,
365,
488,
26,
288,
746,
3146,
360,
7718,
5936,
658,
1001,
3629,
2313,
358,
398,
291,
14,
3629,
275,
291,
423,
7721,
63,
1210,
8,
3629,
9,
339,
347,
4107,
8,
277,
12,
1324,
304,
267,
408,
267,
12134,
658,
1210,
64,
4020,
83,
314,
1627,
4177,
14,
398,
520,
635,
1324,
26,
2022,
13,
8167,
1318,
503,
2366,
666,
13547,
14,
267,
520,
5808,
26,
5046,
267,
408,
267,
666,
275,
291,
423,
7721,
63,
1210,
8,
1210,
9,
398,
862,
26,
288,
2022,
3629,
14,
3502,
8,
576,
12,
291,
14,
3629,
9,
267,
871,
291,
423,
1001,
3629,
14,
8172,
26,
288,
372,
756,
267,
587,
26,
288,
372,
715,
339,
347,
485,
7721,
63,
1210,
8,
277,
12,
1324,
304,
267,
408,
267,
16763,
372,
2366,
666,
13547,
14,
398,
520,
635,
1324,
26,
2022,
13,
8167,
1318,
503,
2366,
666,
13547,
14,
267,
408,
267,
340,
1228,
8,
1210,
12,
1059,
63,
1313,
304,
288,
372,
2022,
14,
3640,
8,
1210,
9,
267,
587,
26,
288,
372,
1324,
421,
199,
318,
4868,
8,
15944,
304,
272,
408,
272,
30684,
626,
702,
83,
314,
2138,
574,
365,
1686,
6169,
658,
15944,
2313,
272,
408,
272,
347,
4868,
63,
11547,
8,
70,
304,
267,
768,
17869,
14,
13582,
8,
70,
9,
267,
347,
4975,
2031,
589,
12,
1011,
958,
304,
288,
754,
275,
289,
2031,
589,
12,
1011,
958,
9,
288,
340,
22362,
14,
3502,
8,
1099,
304,
355,
372,
754,
288,
587,
26,
355,
746,
3146,
360,
28239,
666,
1630,
440,
26449,
543,
314,
1627,
4177,
2659,
267,
372,
4975,
272,
372,
4868,
63,
11547,
421,
199,
533,
7640,
4256,
8,
785,
304,
272,
347,
702,
6700,
1831,
3490,
8,
277,
12,
22362,
12,
2073,
63,
633,
12,
1499,
29,
403,
304,
267,
2986,
63,
3271,
275,
4145,
14,
362,
8,
1927,
63,
633,
9,
398,
340,
440,
22362,
14,
3502,
8,
1246,
63,
3271,
14,
1001,
5109,
288,
746,
291,
14,
15935,
8,
1328,
503,
283,
6700,
365,
3866,
2659,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
199,
646,
984,
199,
646,
9143,
199,
646,
2022,
199,
893,
26,
272,
492,
2022,
3629,
199,
2590,
3545,
26,
272,
2022,
3629,
275,
488,
199,
893,
26,
272,
492,
4145,
199,
2590,
3545,
26,
272,
4145,
275,
488,
421,
199,
363,
1023,
363,
275,
283,
17,
14,
16,
14,
16,
14,
2374,
17,
7,
199,
199,
363,
452,
363,
275,
788,
7505,
297,
283,
9653,
16939,
418,
421,
199,
3,
3001,
8648,
199,
3,
1611,
18,
8434,
199,
3,
3001,
8648,
199,
4521,
18,
275,
984,
14,
1023,
63,
815,
59,
16,
61,
508,
499,
199,
199,
692,
7843,
18,
26,
272,
1059,
63,
1313,
275,
334,
495,
12,
2649,
9,
199,
2836,
26,
272,
1059,
63,
1313,
275,
334,
495,
4258,
199,
3,
3001,
8648,
421,
199,
533,
14587,
16939,
8,
785,
304,
272,
408,
272,
1626,
1256,
626,
19428,
4212,
370,
5147,
1686,
1298,
6169,
2022,
13,
3629,
14,
272,
408,
272,
485,
1001,
3629,
275,
2022,
3629,
339,
347,
636,
826,
721,
277,
12,
4177,
304,
267,
408,
267,
520,
635,
4177,
26,
2022,
13,
3629,
465,
2022,
13,
8167,
1318,
503,
2366,
666,
13547,
14,
267,
408,
267,
340,
291,
423,
1001,
3629,
365,
488,
26,
288,
746,
3146,
360,
7718,
5936,
658,
1001,
3629,
2313,
358,
398,
291,
14,
3629,
275,
291,
423,
7721,
63,
1210,
8,
3629,
9,
339,
347,
4107,
8,
277,
12,
1324,
304,
267,
408,
267,
12134,
658,
1210,
64,
4020,
83,
314,
1627,
4177,
14,
398,
520,
635,
1324,
26,
2022,
13,
8167,
1318,
503,
2366,
666,
13547,
14,
267,
520,
5808,
26,
5046,
267,
408,
267,
666,
275,
291,
423,
7721,
63,
1210,
8,
1210,
9,
398,
862,
26,
288,
2022,
3629,
14,
3502,
8,
576,
12,
291,
14,
3629,
9,
267,
871,
291,
423,
1001,
3629,
14,
8172,
26,
288,
372,
756,
267,
587,
26,
288,
372,
715,
339,
347,
485,
7721,
63,
1210,
8,
277,
12,
1324,
304,
267,
408,
267,
16763,
372,
2366,
666,
13547,
14,
398,
520,
635,
1324,
26,
2022,
13,
8167,
1318,
503,
2366,
666,
13547,
14,
267,
408,
267,
340,
1228,
8,
1210,
12,
1059,
63,
1313,
304,
288,
372,
2022,
14,
3640,
8,
1210,
9,
267,
587,
26,
288,
372,
1324,
421,
199,
318,
4868,
8,
15944,
304,
272,
408,
272,
30684,
626,
702,
83,
314,
2138,
574,
365,
1686,
6169,
658,
15944,
2313,
272,
408,
272,
347,
4868,
63,
11547,
8,
70,
304,
267,
768,
17869,
14,
13582,
8,
70,
9,
267,
347,
4975,
2031,
589,
12,
1011,
958,
304,
288,
754,
275,
289,
2031,
589,
12,
1011,
958,
9,
288,
340,
22362,
14,
3502,
8,
1099,
304,
355,
372,
754,
288,
587,
26,
355,
746,
3146,
360,
28239,
666,
1630,
440,
26449,
543,
314,
1627,
4177,
2659,
267,
372,
4975,
272,
372,
4868,
63,
11547,
421,
199,
533,
7640,
4256,
8,
785,
304,
272,
347,
702,
6700,
1831,
3490,
8,
277,
12,
22362,
12,
2073,
63,
633,
12,
1499,
29,
403,
304,
267,
2986,
63,
3271,
275,
4145,
14,
362,
8,
1927,
63,
633,
9,
398,
340,
440,
22362,
14,
3502,
8,
1246,
63,
3271,
14,
1001,
5109,
288,
746,
291,
14,
15935,
8,
1328,
503,
283,
6700,
365,
3866,
2659,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
michaelpacer/scikit-image
|
skimage/restoration/tests/test_restoration.py
|
38
|
3413
|
from os.path import abspath, dirname, join as pjoin
import numpy as np
from scipy.signal import convolve2d
from scipy import ndimage as ndi
import skimage
from skimage.data import camera
from skimage import restoration
from skimage.restoration import uft
test_img = skimage.img_as_float(camera())
def test_wiener():
psf = np.ones((5, 5)) / 25
data = convolve2d(test_img, psf, 'same')
np.random.seed(0)
data += 0.1 * data.std() * np.random.standard_normal(data.shape)
deconvolved = restoration.wiener(data, psf, 0.05)
path = pjoin(dirname(abspath(__file__)), 'camera_wiener.npy')
np.testing.assert_allclose(deconvolved, np.load(path), rtol=1e-3)
_, laplacian = uft.laplacian(2, data.shape)
otf = uft.ir2tf(psf, data.shape, is_real=False)
deconvolved = restoration.wiener(data, otf, 0.05,
reg=laplacian,
is_real=False)
np.testing.assert_allclose(np.real(deconvolved),
np.load(path),
rtol=1e-3)
def test_unsupervised_wiener():
psf = np.ones((5, 5)) / 25
data = convolve2d(test_img, psf, 'same')
np.random.seed(0)
data += 0.1 * data.std() * np.random.standard_normal(data.shape)
deconvolved, _ = restoration.unsupervised_wiener(data, psf)
path = pjoin(dirname(abspath(__file__)), 'camera_unsup.npy')
np.testing.assert_allclose(deconvolved, np.load(path), rtol=1e-3)
_, laplacian = uft.laplacian(2, data.shape)
otf = uft.ir2tf(psf, data.shape, is_real=False)
np.random.seed(0)
deconvolved = restoration.unsupervised_wiener(
data, otf, reg=laplacian, is_real=False,
user_params={"callback": lambda x: None})[0]
path = pjoin(dirname(abspath(__file__)), 'camera_unsup2.npy')
np.testing.assert_allclose(np.real(deconvolved),
np.load(path),
rtol=1e-3)
def test_image_shape():
"""Test that shape of output image in deconvolution is same as input.
This addresses issue #1172.
"""
point = np.zeros((5, 5), np.float)
point[2, 2] = 1.
psf = ndi.gaussian_filter(point, sigma=1.)
# image shape: (45, 45), as reported in #1172
image = skimage.img_as_float(camera()[110:155, 225:270]) # just the face
image_conv = ndi.convolve(image, psf)
deconv_sup = restoration.wiener(image_conv, psf, 1)
deconv_un = restoration.unsupervised_wiener(image_conv, psf)[0]
# test the shape
np.testing.assert_equal(image.shape, deconv_sup.shape)
np.testing.assert_equal(image.shape, deconv_un.shape)
# test the reconstruction error
sup_relative_error = np.abs(deconv_sup - image) / image
un_relative_error = np.abs(deconv_un - image) / image
np.testing.assert_array_less(np.median(sup_relative_error), 0.1)
np.testing.assert_array_less(np.median(un_relative_error), 0.1)
def test_richardson_lucy():
psf = np.ones((5, 5)) / 25
data = convolve2d(test_img, psf, 'same')
np.random.seed(0)
data += 0.1 * data.std() * np.random.standard_normal(data.shape)
deconvolved = restoration.richardson_lucy(data, psf, 5)
path = pjoin(dirname(abspath(__file__)), 'camera_rl.npy')
np.testing.assert_allclose(deconvolved, np.load(path), rtol=1e-3)
if __name__ == '__main__':
from numpy import testing
testing.run_module_suite()
|
bsd-3-clause
|
[
504,
747,
14,
515,
492,
19529,
12,
9017,
12,
4263,
465,
299,
904,
199,
199,
646,
2680,
465,
980,
199,
504,
7026,
14,
4653,
492,
8260,
3344,
18,
68,
199,
504,
7026,
492,
302,
23335,
465,
302,
328,
199,
199,
646,
2386,
1569,
199,
504,
2386,
1569,
14,
576,
492,
15177,
199,
504,
2386,
1569,
492,
4618,
14496,
199,
504,
2386,
1569,
14,
3911,
14496,
492,
399,
856,
199,
199,
396,
63,
4060,
275,
2386,
1569,
14,
4060,
63,
305,
63,
1609,
8,
11928,
1012,
421,
199,
318,
511,
63,
14249,
727,
837,
272,
7347,
70,
275,
980,
14,
4548,
1332,
21,
12,
959,
430,
1182,
5661,
272,
666,
275,
8260,
3344,
18,
68,
8,
396,
63,
4060,
12,
7347,
70,
12,
283,
7191,
358,
272,
980,
14,
2355,
14,
5176,
8,
16,
9,
272,
666,
847,
378,
14,
17,
627,
666,
14,
1516,
342,
627,
980,
14,
2355,
14,
6807,
63,
3302,
8,
576,
14,
1392,
9,
272,
477,
5598,
7064,
275,
4618,
14496,
14,
14249,
727,
8,
576,
12,
7347,
70,
12,
378,
14,
1717,
9,
339,
931,
275,
299,
904,
8,
3475,
8,
4832,
3460,
493,
22159,
283,
11928,
63,
14249,
727,
14,
20245,
358,
272,
980,
14,
4776,
14,
479,
63,
7520,
8,
271,
5598,
7064,
12,
980,
14,
912,
8,
515,
395,
10561,
29,
17,
69,
13,
19,
9,
339,
5501,
28938,
27199,
275,
399,
856,
14,
4762,
27199,
8,
18,
12,
666,
14,
1392,
9,
272,
312,
3249,
275,
399,
856,
14,
723,
18,
3249,
8,
1190,
70,
12,
666,
14,
1392,
12,
365,
63,
3093,
29,
797,
9,
272,
477,
5598,
7064,
275,
4618,
14496,
14,
14249,
727,
8,
576,
12,
312,
3249,
12,
378,
14,
1717,
12,
3660,
1295,
29,
4762,
27199,
12,
3660,
365,
63,
3093,
29,
797,
9,
272,
980,
14,
4776,
14,
479,
63,
7520,
8,
1590,
14,
3093,
8,
271,
5598,
7064,
395,
3044,
980,
14,
912,
8,
515,
395,
3044,
10561,
29,
17,
69,
13,
19,
9,
421,
199,
318,
511,
63,
324,
4792,
17311,
63,
14249,
727,
837,
272,
7347,
70,
275,
980,
14,
4548,
1332,
21,
12,
959,
430,
1182,
5661,
272,
666,
275,
8260,
3344,
18,
68,
8,
396,
63,
4060,
12,
7347,
70,
12,
283,
7191,
358,
272,
980,
14,
2355,
14,
5176,
8,
16,
9,
272,
666,
847,
378,
14,
17,
627,
666,
14,
1516,
342,
627,
980,
14,
2355,
14,
6807,
63,
3302,
8,
576,
14,
1392,
9,
272,
477,
5598,
7064,
12,
485,
275,
4618,
14496,
14,
324,
4792,
17311,
63,
14249,
727,
8,
576,
12,
7347,
70,
9,
339,
931,
275,
299,
904,
8,
3475,
8,
4832,
3460,
493,
22159,
283,
11928,
63,
324,
1961,
14,
20245,
358,
272,
980,
14,
4776,
14,
479,
63,
7520,
8,
271,
5598,
7064,
12,
980,
14,
912,
8,
515,
395,
10561,
29,
17,
69,
13,
19,
9,
339,
5501,
28938,
27199,
275,
399,
856,
14,
4762,
27199,
8,
18,
12,
666,
14,
1392,
9,
272,
312,
3249,
275,
399,
856,
14,
723,
18,
3249,
8,
1190,
70,
12,
666,
14,
1392,
12,
365,
63,
3093,
29,
797,
9,
272,
980,
14,
2355,
14,
5176,
8,
16,
9,
272,
477,
5598,
7064,
275,
4618,
14496,
14,
324,
4792,
17311,
63,
14249,
727,
8,
267,
666,
12,
312,
3249,
12,
1295,
29,
4762,
27199,
12,
365,
63,
3093,
29,
797,
12,
267,
922,
63,
1162,
8871,
3058,
582,
2400,
671,
26,
488,
1552,
59,
16,
61,
272,
931,
275,
299,
904,
8,
3475,
8,
4832,
3460,
493,
22159,
283,
11928,
63,
324,
1961,
18,
14,
20245,
358,
272,
980,
14,
4776,
14,
479,
63,
7520,
8,
1590,
14,
3093,
8,
271,
5598,
7064,
395,
3044,
980,
14,
912,
8,
515,
395,
3044,
10561,
29,
17,
69,
13,
19,
9,
421,
199,
318,
511,
63,
1569,
63,
1392,
837,
272,
408,
774,
626,
2215,
402,
1072,
1834,
315,
477,
27625,
365,
2011,
465,
1324,
14,
339,
961,
7149,
4976,
327,
845,
2819,
14,
272,
408,
272,
2376,
275,
980,
14,
4250,
1332,
21,
12,
959,
395,
980,
14,
1609,
9,
272,
2376,
59,
18,
12,
499,
61,
275,
413,
14,
272,
7347,
70,
275,
302,
328,
14,
22911,
63,
1541,
8,
1403,
12,
10819,
29,
17,
4959,
272,
327,
1834,
2215,
26,
334,
2322,
12,
10416,
395,
465,
14581,
315,
327,
845,
2819,
272,
1834,
275,
2386,
1569,
14,
4060,
63,
305,
63,
1609,
8,
11928,
3430,
6019,
26,
11520,
12,
28842,
26,
13299,
566,
327,
2951,
314,
8870,
272,
1834,
63,
5598,
275,
302,
328,
14,
5598,
3344,
8,
1569,
12,
7347,
70,
9,
272,
477,
5598,
63,
1961,
275,
4618,
14496,
14,
14249,
727,
8,
1569,
63,
5598,
12,
7347,
70,
12,
413,
9,
272,
477,
5598,
63,
324,
275,
4618,
14496,
14,
324,
4792,
17311,
63,
14249,
727,
8,
1569,
63,
5598,
12,
7347,
70,
2788,
16,
61,
272,
327,
511,
314,
2215,
272,
980,
14,
4776,
14,
479,
63,
1452,
8,
1569,
14,
1392,
12,
477,
5598,
63,
1961,
14,
1392,
9,
272,
980,
14,
4776,
14,
479,
63,
1452,
8,
1569,
14,
1392,
12,
477,
5598,
63,
324,
14,
1392,
9,
272,
327,
511,
314,
295,
12708,
1125,
272,
1029,
63,
6188,
63,
705,
275,
980,
14,
2101,
8,
271,
5598,
63,
1961,
446,
1834,
9,
1182,
1834,
272,
625,
63,
6188,
63,
705,
275,
980,
14,
2101,
8,
271,
5598,
63,
324,
446,
1834,
9,
1182,
1834,
272,
980,
14,
4776,
14,
479,
63,
1144,
63,
2003,
8,
1590,
14,
13106,
8,
1961,
63,
6188,
63,
705,
395,
378,
14,
17,
9,
272,
980,
14,
4776,
14,
479,
63,
1144,
63,
2003,
8,
1590,
14,
13106,
8,
324,
63,
6188,
63,
705,
395,
378,
14,
17,
9,
421,
199,
318,
511,
63,
322,
1560,
795,
265,
63,
29918,
89,
837,
272,
7347,
70,
275,
980,
14,
4548,
1332,
21,
12,
959,
430,
1182,
5661,
272,
666,
275,
8260,
3344,
18,
68,
8,
396,
63,
4060,
12,
7347,
70,
12,
283,
7191,
358,
272,
980,
14,
2355,
14,
5176,
8,
16,
9,
272,
666,
847,
378,
14,
17,
627,
666,
14,
1516,
342,
627,
980,
14,
2355,
14,
6807,
63,
3302,
8,
576,
14
] |
[
747,
14,
515,
492,
19529,
12,
9017,
12,
4263,
465,
299,
904,
199,
199,
646,
2680,
465,
980,
199,
504,
7026,
14,
4653,
492,
8260,
3344,
18,
68,
199,
504,
7026,
492,
302,
23335,
465,
302,
328,
199,
199,
646,
2386,
1569,
199,
504,
2386,
1569,
14,
576,
492,
15177,
199,
504,
2386,
1569,
492,
4618,
14496,
199,
504,
2386,
1569,
14,
3911,
14496,
492,
399,
856,
199,
199,
396,
63,
4060,
275,
2386,
1569,
14,
4060,
63,
305,
63,
1609,
8,
11928,
1012,
421,
199,
318,
511,
63,
14249,
727,
837,
272,
7347,
70,
275,
980,
14,
4548,
1332,
21,
12,
959,
430,
1182,
5661,
272,
666,
275,
8260,
3344,
18,
68,
8,
396,
63,
4060,
12,
7347,
70,
12,
283,
7191,
358,
272,
980,
14,
2355,
14,
5176,
8,
16,
9,
272,
666,
847,
378,
14,
17,
627,
666,
14,
1516,
342,
627,
980,
14,
2355,
14,
6807,
63,
3302,
8,
576,
14,
1392,
9,
272,
477,
5598,
7064,
275,
4618,
14496,
14,
14249,
727,
8,
576,
12,
7347,
70,
12,
378,
14,
1717,
9,
339,
931,
275,
299,
904,
8,
3475,
8,
4832,
3460,
493,
22159,
283,
11928,
63,
14249,
727,
14,
20245,
358,
272,
980,
14,
4776,
14,
479,
63,
7520,
8,
271,
5598,
7064,
12,
980,
14,
912,
8,
515,
395,
10561,
29,
17,
69,
13,
19,
9,
339,
5501,
28938,
27199,
275,
399,
856,
14,
4762,
27199,
8,
18,
12,
666,
14,
1392,
9,
272,
312,
3249,
275,
399,
856,
14,
723,
18,
3249,
8,
1190,
70,
12,
666,
14,
1392,
12,
365,
63,
3093,
29,
797,
9,
272,
477,
5598,
7064,
275,
4618,
14496,
14,
14249,
727,
8,
576,
12,
312,
3249,
12,
378,
14,
1717,
12,
3660,
1295,
29,
4762,
27199,
12,
3660,
365,
63,
3093,
29,
797,
9,
272,
980,
14,
4776,
14,
479,
63,
7520,
8,
1590,
14,
3093,
8,
271,
5598,
7064,
395,
3044,
980,
14,
912,
8,
515,
395,
3044,
10561,
29,
17,
69,
13,
19,
9,
421,
199,
318,
511,
63,
324,
4792,
17311,
63,
14249,
727,
837,
272,
7347,
70,
275,
980,
14,
4548,
1332,
21,
12,
959,
430,
1182,
5661,
272,
666,
275,
8260,
3344,
18,
68,
8,
396,
63,
4060,
12,
7347,
70,
12,
283,
7191,
358,
272,
980,
14,
2355,
14,
5176,
8,
16,
9,
272,
666,
847,
378,
14,
17,
627,
666,
14,
1516,
342,
627,
980,
14,
2355,
14,
6807,
63,
3302,
8,
576,
14,
1392,
9,
272,
477,
5598,
7064,
12,
485,
275,
4618,
14496,
14,
324,
4792,
17311,
63,
14249,
727,
8,
576,
12,
7347,
70,
9,
339,
931,
275,
299,
904,
8,
3475,
8,
4832,
3460,
493,
22159,
283,
11928,
63,
324,
1961,
14,
20245,
358,
272,
980,
14,
4776,
14,
479,
63,
7520,
8,
271,
5598,
7064,
12,
980,
14,
912,
8,
515,
395,
10561,
29,
17,
69,
13,
19,
9,
339,
5501,
28938,
27199,
275,
399,
856,
14,
4762,
27199,
8,
18,
12,
666,
14,
1392,
9,
272,
312,
3249,
275,
399,
856,
14,
723,
18,
3249,
8,
1190,
70,
12,
666,
14,
1392,
12,
365,
63,
3093,
29,
797,
9,
272,
980,
14,
2355,
14,
5176,
8,
16,
9,
272,
477,
5598,
7064,
275,
4618,
14496,
14,
324,
4792,
17311,
63,
14249,
727,
8,
267,
666,
12,
312,
3249,
12,
1295,
29,
4762,
27199,
12,
365,
63,
3093,
29,
797,
12,
267,
922,
63,
1162,
8871,
3058,
582,
2400,
671,
26,
488,
1552,
59,
16,
61,
272,
931,
275,
299,
904,
8,
3475,
8,
4832,
3460,
493,
22159,
283,
11928,
63,
324,
1961,
18,
14,
20245,
358,
272,
980,
14,
4776,
14,
479,
63,
7520,
8,
1590,
14,
3093,
8,
271,
5598,
7064,
395,
3044,
980,
14,
912,
8,
515,
395,
3044,
10561,
29,
17,
69,
13,
19,
9,
421,
199,
318,
511,
63,
1569,
63,
1392,
837,
272,
408,
774,
626,
2215,
402,
1072,
1834,
315,
477,
27625,
365,
2011,
465,
1324,
14,
339,
961,
7149,
4976,
327,
845,
2819,
14,
272,
408,
272,
2376,
275,
980,
14,
4250,
1332,
21,
12,
959,
395,
980,
14,
1609,
9,
272,
2376,
59,
18,
12,
499,
61,
275,
413,
14,
272,
7347,
70,
275,
302,
328,
14,
22911,
63,
1541,
8,
1403,
12,
10819,
29,
17,
4959,
272,
327,
1834,
2215,
26,
334,
2322,
12,
10416,
395,
465,
14581,
315,
327,
845,
2819,
272,
1834,
275,
2386,
1569,
14,
4060,
63,
305,
63,
1609,
8,
11928,
3430,
6019,
26,
11520,
12,
28842,
26,
13299,
566,
327,
2951,
314,
8870,
272,
1834,
63,
5598,
275,
302,
328,
14,
5598,
3344,
8,
1569,
12,
7347,
70,
9,
272,
477,
5598,
63,
1961,
275,
4618,
14496,
14,
14249,
727,
8,
1569,
63,
5598,
12,
7347,
70,
12,
413,
9,
272,
477,
5598,
63,
324,
275,
4618,
14496,
14,
324,
4792,
17311,
63,
14249,
727,
8,
1569,
63,
5598,
12,
7347,
70,
2788,
16,
61,
272,
327,
511,
314,
2215,
272,
980,
14,
4776,
14,
479,
63,
1452,
8,
1569,
14,
1392,
12,
477,
5598,
63,
1961,
14,
1392,
9,
272,
980,
14,
4776,
14,
479,
63,
1452,
8,
1569,
14,
1392,
12,
477,
5598,
63,
324,
14,
1392,
9,
272,
327,
511,
314,
295,
12708,
1125,
272,
1029,
63,
6188,
63,
705,
275,
980,
14,
2101,
8,
271,
5598,
63,
1961,
446,
1834,
9,
1182,
1834,
272,
625,
63,
6188,
63,
705,
275,
980,
14,
2101,
8,
271,
5598,
63,
324,
446,
1834,
9,
1182,
1834,
272,
980,
14,
4776,
14,
479,
63,
1144,
63,
2003,
8,
1590,
14,
13106,
8,
1961,
63,
6188,
63,
705,
395,
378,
14,
17,
9,
272,
980,
14,
4776,
14,
479,
63,
1144,
63,
2003,
8,
1590,
14,
13106,
8,
324,
63,
6188,
63,
705,
395,
378,
14,
17,
9,
421,
199,
318,
511,
63,
322,
1560,
795,
265,
63,
29918,
89,
837,
272,
7347,
70,
275,
980,
14,
4548,
1332,
21,
12,
959,
430,
1182,
5661,
272,
666,
275,
8260,
3344,
18,
68,
8,
396,
63,
4060,
12,
7347,
70,
12,
283,
7191,
358,
272,
980,
14,
2355,
14,
5176,
8,
16,
9,
272,
666,
847,
378,
14,
17,
627,
666,
14,
1516,
342,
627,
980,
14,
2355,
14,
6807,
63,
3302,
8,
576,
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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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
] |
vicky2135/lucious
|
oscar/lib/python2.7/site-packages/IPython/core/tests/test_completerlib.py
|
8
|
5572
|
# -*- coding: utf-8 -*-
"""Tests for completerlib.
"""
from __future__ import absolute_import
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
import os
import shutil
import sys
import tempfile
import unittest
from os.path import join
import nose.tools as nt
from IPython.core.completerlib import magic_run_completer, module_completion
from IPython.utils import py3compat
from IPython.utils.tempdir import TemporaryDirectory
from IPython.testing.decorators import onlyif_unicode_paths
class MockEvent(object):
def __init__(self, line):
self.line = line
#-----------------------------------------------------------------------------
# Test functions begin
#-----------------------------------------------------------------------------
class Test_magic_run_completer(unittest.TestCase):
files = [u"aao.py", u"a.py", u"b.py", u"aao.txt"]
dirs = [u"adir/", "bdir/"]
def setUp(self):
self.BASETESTDIR = tempfile.mkdtemp()
for fil in self.files:
with open(join(self.BASETESTDIR, fil), "w") as sfile:
sfile.write("pass\n")
for d in self.dirs:
os.mkdir(join(self.BASETESTDIR, d))
self.oldpath = py3compat.getcwd()
os.chdir(self.BASETESTDIR)
def tearDown(self):
os.chdir(self.oldpath)
shutil.rmtree(self.BASETESTDIR)
def test_1(self):
"""Test magic_run_completer, should match two alterntives
"""
event = MockEvent(u"%run a")
mockself = None
match = set(magic_run_completer(mockself, event))
self.assertEqual(match, {u"a.py", u"aao.py", u"adir/"})
def test_2(self):
"""Test magic_run_completer, should match one alterntive
"""
event = MockEvent(u"%run aa")
mockself = None
match = set(magic_run_completer(mockself, event))
self.assertEqual(match, {u"aao.py"})
def test_3(self):
"""Test magic_run_completer with unterminated " """
event = MockEvent(u'%run "a')
mockself = None
match = set(magic_run_completer(mockself, event))
self.assertEqual(match, {u"a.py", u"aao.py", u"adir/"})
def test_completion_more_args(self):
event = MockEvent(u'%run a.py ')
match = set(magic_run_completer(None, event))
self.assertEqual(match, set(self.files + self.dirs))
def test_completion_in_dir(self):
# Github issue #3459
event = MockEvent(u'%run a.py {}'.format(join(self.BASETESTDIR, 'a')))
print(repr(event.line))
match = set(magic_run_completer(None, event))
# We specifically use replace here rather than normpath, because
# at one point there were duplicates 'adir' and 'adir/', and normpath
# would hide the failure for that.
self.assertEqual(match, {join(self.BASETESTDIR, f).replace('\\','/')
for f in (u'a.py', u'aao.py', u'aao.txt', u'adir/')})
class Test_magic_run_completer_nonascii(unittest.TestCase):
@onlyif_unicode_paths
def setUp(self):
self.BASETESTDIR = tempfile.mkdtemp()
for fil in [u"aaø.py", u"a.py", u"b.py"]:
with open(join(self.BASETESTDIR, fil), "w") as sfile:
sfile.write("pass\n")
self.oldpath = py3compat.getcwd()
os.chdir(self.BASETESTDIR)
def tearDown(self):
os.chdir(self.oldpath)
shutil.rmtree(self.BASETESTDIR)
@onlyif_unicode_paths
def test_1(self):
"""Test magic_run_completer, should match two alterntives
"""
event = MockEvent(u"%run a")
mockself = None
match = set(magic_run_completer(mockself, event))
self.assertEqual(match, {u"a.py", u"aaø.py"})
@onlyif_unicode_paths
def test_2(self):
"""Test magic_run_completer, should match one alterntive
"""
event = MockEvent(u"%run aa")
mockself = None
match = set(magic_run_completer(mockself, event))
self.assertEqual(match, {u"aaø.py"})
@onlyif_unicode_paths
def test_3(self):
"""Test magic_run_completer with unterminated " """
event = MockEvent(u'%run "a')
mockself = None
match = set(magic_run_completer(mockself, event))
self.assertEqual(match, {u"a.py", u"aaø.py"})
# module_completer:
def test_import_invalid_module():
"""Testing of issue https://github.com/ipython/ipython/issues/1107"""
invalid_module_names = {'foo-bar', 'foo:bar', '10foo'}
valid_module_names = {'foobar'}
with TemporaryDirectory() as tmpdir:
sys.path.insert( 0, tmpdir )
for name in invalid_module_names | valid_module_names:
filename = os.path.join(tmpdir, name + '.py')
open(filename, 'w').close()
s = set( module_completion('import foo') )
intersection = s.intersection(invalid_module_names)
nt.assert_equal(intersection, set())
assert valid_module_names.issubset(s), valid_module_names.intersection(s)
def test_bad_module_all():
"""Test module with invalid __all__
https://github.com/ipython/ipython/issues/9678
"""
testsdir = os.path.dirname(__file__)
sys.path.insert(0, testsdir)
try:
results = module_completion('from bad_all import ')
nt.assert_in('puppies', results)
for r in results:
nt.assert_is_instance(r, py3compat.string_types)
finally:
sys.path.remove(testsdir)
|
bsd-3-clause
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
2925,
367,
2831,
351,
773,
14,
199,
199,
624,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
18045,
199,
3,
24339,
199,
18045,
199,
199,
646,
747,
199,
646,
5145,
199,
646,
984,
199,
646,
5549,
199,
646,
2882,
199,
504,
747,
14,
515,
492,
4263,
199,
199,
646,
11354,
14,
2537,
465,
13377,
199,
199,
504,
16243,
14,
1018,
14,
18452,
773,
492,
10628,
63,
1065,
63,
18452,
12,
859,
63,
13207,
199,
504,
16243,
14,
1208,
492,
1134,
19,
5819,
199,
504,
16243,
14,
1208,
14,
11567,
492,
21791,
6231,
199,
504,
16243,
14,
4776,
14,
11582,
492,
1454,
692,
63,
2975,
63,
3771,
421,
199,
533,
4420,
2390,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
1004,
304,
267,
291,
14,
604,
275,
1004,
199,
199,
18045,
199,
3,
1379,
3423,
5386,
199,
18045,
199,
533,
1379,
63,
11523,
63,
1065,
63,
18452,
8,
2796,
14,
1746,
304,
272,
1584,
275,
359,
85,
2,
2158,
79,
14,
647,
401,
399,
2,
65,
14,
647,
401,
399,
2,
66,
14,
647,
401,
399,
2,
2158,
79,
14,
2424,
937,
272,
7606,
275,
359,
85,
2,
65,
694,
10665,
298,
66,
694,
15,
937,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
20205,
775,
1719,
3022,
275,
5549,
14,
11983,
342,
267,
367,
1794,
315,
291,
14,
1725,
26,
288,
543,
1551,
8,
904,
8,
277,
14,
20205,
775,
1719,
3022,
12,
1794,
395,
298,
87,
531,
465,
308,
493,
26,
355,
308,
493,
14,
952,
480,
1529,
60,
78,
531,
267,
367,
366,
315,
291,
14,
3220,
26,
288,
747,
14,
8215,
8,
904,
8,
277,
14,
20205,
775,
1719,
3022,
12,
366,
430,
398,
291,
14,
1753,
515,
275,
1134,
19,
5819,
14,
9458,
342,
267,
747,
14,
8563,
8,
277,
14,
20205,
775,
1719,
3022,
9,
339,
347,
6766,
8,
277,
304,
267,
747,
14,
8563,
8,
277,
14,
1753,
515,
9,
267,
5145,
14,
9242,
8,
277,
14,
20205,
775,
1719,
3022,
9,
339,
347,
511,
63,
17,
8,
277,
304,
267,
408,
774,
10628,
63,
1065,
63,
18452,
12,
1077,
1336,
2877,
8679,
7301,
267,
408,
267,
1566,
275,
4420,
2390,
8,
85,
6808,
1065,
282,
531,
267,
1683,
277,
275,
488,
267,
1336,
275,
663,
8,
11523,
63,
1065,
63,
18452,
8,
1805,
277,
12,
1566,
430,
267,
291,
14,
629,
8,
1431,
12,
469,
85,
2,
65,
14,
647,
401,
399,
2,
2158,
79,
14,
647,
401,
399,
2,
65,
694,
15,
5984,
339,
347,
511,
63,
18,
8,
277,
304,
267,
408,
774,
10628,
63,
1065,
63,
18452,
12,
1077,
1336,
1373,
8679,
857,
267,
408,
267,
1566,
275,
4420,
2390,
8,
85,
6808,
1065,
18319,
531,
267,
1683,
277,
275,
488,
267,
1336,
275,
663,
8,
11523,
63,
1065,
63,
18452,
8,
1805,
277,
12,
1566,
430,
267,
291,
14,
629,
8,
1431,
12,
469,
85,
2,
2158,
79,
14,
647,
5984,
339,
347,
511,
63,
19,
8,
277,
304,
267,
408,
774,
10628,
63,
1065,
63,
18452,
543,
625,
18375,
298,
408,
267,
1566,
275,
4420,
2390,
8,
85,
5956,
1065,
298,
65,
358,
267,
1683,
277,
275,
488,
267,
1336,
275,
663,
8,
11523,
63,
1065,
63,
18452,
8,
1805,
277,
12,
1566,
430,
267,
291,
14,
629,
8,
1431,
12,
469,
85,
2,
65,
14,
647,
401,
399,
2,
2158,
79,
14,
647,
401,
399,
2,
65,
694,
15,
5984,
339,
347,
511,
63,
13207,
63,
6878,
63,
589,
8,
277,
304,
267,
1566,
275,
4420,
2390,
8,
85,
5956,
1065,
282,
14,
647,
5320,
267,
1336,
275,
663,
8,
11523,
63,
1065,
63,
18452,
8,
403,
12,
1566,
430,
267,
291,
14,
629,
8,
1431,
12,
663,
8,
277,
14,
1725,
435,
291,
14,
3220,
430,
339,
347,
511,
63,
13207,
63,
262,
63,
694,
8,
277,
304,
267,
327,
598,
4049,
4976,
327,
1082,
1427,
267,
1566,
275,
4420,
2390,
8,
85,
5956,
1065,
282,
14,
647,
9499,
908,
8,
904,
8,
277,
14,
20205,
775,
1719,
3022,
12,
283,
65,
7058,
267,
870,
8,
2722,
8,
1430,
14,
604,
430,
267,
1336,
275,
663,
8,
11523,
63,
1065,
63,
18452,
8,
403,
12,
1566,
430,
267,
327,
2136,
22543,
675,
3350,
2348,
7830,
2419,
25962,
12,
2952,
267,
327,
737,
1373,
2376,
2337,
4898,
15755,
283,
65,
694,
7,
436,
283,
65,
694,
3678,
436,
25962,
267,
327,
3955,
13714,
314,
5988,
367,
626,
14,
267,
291,
14,
629,
8,
1431,
12,
469,
904,
8,
277,
14,
20205,
775,
1719,
3022,
12,
289,
680,
1814,
11671,
1673,
6217,
1169,
367,
289,
315,
334,
85,
7,
65,
14,
647,
297,
399,
7,
2158,
79,
14,
647,
297,
399,
7,
2158,
79,
14,
2424,
297,
399,
7,
65,
694,
6217,
1552,
199,
199,
533,
1379,
63,
11523,
63,
1065,
63,
18452,
63,
2865,
4371,
8,
2796,
14,
1746,
304,
272,
768,
2118,
692,
63,
2975,
63,
3771,
272,
347,
3613,
8,
277,
304,
267,
291,
14,
20205,
775,
1719,
3022,
275,
5549,
14,
11983,
342,
267,
367,
1794,
315,
359,
85,
2,
2158,
31087,
14,
647,
401,
399,
2,
65,
14,
647,
401,
399,
2,
66,
14,
647,
6229,
288,
543,
1551,
8,
904,
8,
277,
14,
20205,
775,
1719,
3022,
12,
1794,
395,
298,
87,
531,
465,
308,
493,
26,
355,
308,
493,
14,
952,
480,
1529,
60,
78,
531,
267,
291,
14,
1753,
515,
275,
1134,
19,
5819,
14,
9458,
342,
267,
747,
14,
8563,
8,
277,
14,
20205,
775,
1719,
3022,
9,
339,
347,
6766,
8,
277,
304,
267,
747,
14,
8563,
8,
277,
14,
1753,
515,
9,
267,
5145,
14,
9242,
8,
277,
14,
20205,
775,
1719,
3022,
9,
339,
768,
2118,
692,
63,
2975,
63,
3771,
272,
347,
511,
63,
17,
8,
277,
304,
267,
408,
774,
10628,
63,
1065,
63,
18452,
12,
1077,
1336,
2877,
8679,
7301,
267,
408,
267,
1566,
275,
4420,
2390,
8,
85,
6808,
1065,
282,
531,
267,
1683,
277,
275,
488,
267,
1336,
275,
663,
8,
11523,
63,
1065,
63,
18452,
8,
1805,
277,
12,
1566,
430,
267,
291,
14,
629,
8,
1431,
12
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
2925,
367,
2831,
351,
773,
14,
199,
199,
624,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
18045,
199,
3,
24339,
199,
18045,
199,
199,
646,
747,
199,
646,
5145,
199,
646,
984,
199,
646,
5549,
199,
646,
2882,
199,
504,
747,
14,
515,
492,
4263,
199,
199,
646,
11354,
14,
2537,
465,
13377,
199,
199,
504,
16243,
14,
1018,
14,
18452,
773,
492,
10628,
63,
1065,
63,
18452,
12,
859,
63,
13207,
199,
504,
16243,
14,
1208,
492,
1134,
19,
5819,
199,
504,
16243,
14,
1208,
14,
11567,
492,
21791,
6231,
199,
504,
16243,
14,
4776,
14,
11582,
492,
1454,
692,
63,
2975,
63,
3771,
421,
199,
533,
4420,
2390,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
1004,
304,
267,
291,
14,
604,
275,
1004,
199,
199,
18045,
199,
3,
1379,
3423,
5386,
199,
18045,
199,
533,
1379,
63,
11523,
63,
1065,
63,
18452,
8,
2796,
14,
1746,
304,
272,
1584,
275,
359,
85,
2,
2158,
79,
14,
647,
401,
399,
2,
65,
14,
647,
401,
399,
2,
66,
14,
647,
401,
399,
2,
2158,
79,
14,
2424,
937,
272,
7606,
275,
359,
85,
2,
65,
694,
10665,
298,
66,
694,
15,
937,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
20205,
775,
1719,
3022,
275,
5549,
14,
11983,
342,
267,
367,
1794,
315,
291,
14,
1725,
26,
288,
543,
1551,
8,
904,
8,
277,
14,
20205,
775,
1719,
3022,
12,
1794,
395,
298,
87,
531,
465,
308,
493,
26,
355,
308,
493,
14,
952,
480,
1529,
60,
78,
531,
267,
367,
366,
315,
291,
14,
3220,
26,
288,
747,
14,
8215,
8,
904,
8,
277,
14,
20205,
775,
1719,
3022,
12,
366,
430,
398,
291,
14,
1753,
515,
275,
1134,
19,
5819,
14,
9458,
342,
267,
747,
14,
8563,
8,
277,
14,
20205,
775,
1719,
3022,
9,
339,
347,
6766,
8,
277,
304,
267,
747,
14,
8563,
8,
277,
14,
1753,
515,
9,
267,
5145,
14,
9242,
8,
277,
14,
20205,
775,
1719,
3022,
9,
339,
347,
511,
63,
17,
8,
277,
304,
267,
408,
774,
10628,
63,
1065,
63,
18452,
12,
1077,
1336,
2877,
8679,
7301,
267,
408,
267,
1566,
275,
4420,
2390,
8,
85,
6808,
1065,
282,
531,
267,
1683,
277,
275,
488,
267,
1336,
275,
663,
8,
11523,
63,
1065,
63,
18452,
8,
1805,
277,
12,
1566,
430,
267,
291,
14,
629,
8,
1431,
12,
469,
85,
2,
65,
14,
647,
401,
399,
2,
2158,
79,
14,
647,
401,
399,
2,
65,
694,
15,
5984,
339,
347,
511,
63,
18,
8,
277,
304,
267,
408,
774,
10628,
63,
1065,
63,
18452,
12,
1077,
1336,
1373,
8679,
857,
267,
408,
267,
1566,
275,
4420,
2390,
8,
85,
6808,
1065,
18319,
531,
267,
1683,
277,
275,
488,
267,
1336,
275,
663,
8,
11523,
63,
1065,
63,
18452,
8,
1805,
277,
12,
1566,
430,
267,
291,
14,
629,
8,
1431,
12,
469,
85,
2,
2158,
79,
14,
647,
5984,
339,
347,
511,
63,
19,
8,
277,
304,
267,
408,
774,
10628,
63,
1065,
63,
18452,
543,
625,
18375,
298,
408,
267,
1566,
275,
4420,
2390,
8,
85,
5956,
1065,
298,
65,
358,
267,
1683,
277,
275,
488,
267,
1336,
275,
663,
8,
11523,
63,
1065,
63,
18452,
8,
1805,
277,
12,
1566,
430,
267,
291,
14,
629,
8,
1431,
12,
469,
85,
2,
65,
14,
647,
401,
399,
2,
2158,
79,
14,
647,
401,
399,
2,
65,
694,
15,
5984,
339,
347,
511,
63,
13207,
63,
6878,
63,
589,
8,
277,
304,
267,
1566,
275,
4420,
2390,
8,
85,
5956,
1065,
282,
14,
647,
5320,
267,
1336,
275,
663,
8,
11523,
63,
1065,
63,
18452,
8,
403,
12,
1566,
430,
267,
291,
14,
629,
8,
1431,
12,
663,
8,
277,
14,
1725,
435,
291,
14,
3220,
430,
339,
347,
511,
63,
13207,
63,
262,
63,
694,
8,
277,
304,
267,
327,
598,
4049,
4976,
327,
1082,
1427,
267,
1566,
275,
4420,
2390,
8,
85,
5956,
1065,
282,
14,
647,
9499,
908,
8,
904,
8,
277,
14,
20205,
775,
1719,
3022,
12,
283,
65,
7058,
267,
870,
8,
2722,
8,
1430,
14,
604,
430,
267,
1336,
275,
663,
8,
11523,
63,
1065,
63,
18452,
8,
403,
12,
1566,
430,
267,
327,
2136,
22543,
675,
3350,
2348,
7830,
2419,
25962,
12,
2952,
267,
327,
737,
1373,
2376,
2337,
4898,
15755,
283,
65,
694,
7,
436,
283,
65,
694,
3678,
436,
25962,
267,
327,
3955,
13714,
314,
5988,
367,
626,
14,
267,
291,
14,
629,
8,
1431,
12,
469,
904,
8,
277,
14,
20205,
775,
1719,
3022,
12,
289,
680,
1814,
11671,
1673,
6217,
1169,
367,
289,
315,
334,
85,
7,
65,
14,
647,
297,
399,
7,
2158,
79,
14,
647,
297,
399,
7,
2158,
79,
14,
2424,
297,
399,
7,
65,
694,
6217,
1552,
199,
199,
533,
1379,
63,
11523,
63,
1065,
63,
18452,
63,
2865,
4371,
8,
2796,
14,
1746,
304,
272,
768,
2118,
692,
63,
2975,
63,
3771,
272,
347,
3613,
8,
277,
304,
267,
291,
14,
20205,
775,
1719,
3022,
275,
5549,
14,
11983,
342,
267,
367,
1794,
315,
359,
85,
2,
2158,
31087,
14,
647,
401,
399,
2,
65,
14,
647,
401,
399,
2,
66,
14,
647,
6229,
288,
543,
1551,
8,
904,
8,
277,
14,
20205,
775,
1719,
3022,
12,
1794,
395,
298,
87,
531,
465,
308,
493,
26,
355,
308,
493,
14,
952,
480,
1529,
60,
78,
531,
267,
291,
14,
1753,
515,
275,
1134,
19,
5819,
14,
9458,
342,
267,
747,
14,
8563,
8,
277,
14,
20205,
775,
1719,
3022,
9,
339,
347,
6766,
8,
277,
304,
267,
747,
14,
8563,
8,
277,
14,
1753,
515,
9,
267,
5145,
14,
9242,
8,
277,
14,
20205,
775,
1719,
3022,
9,
339,
768,
2118,
692,
63,
2975,
63,
3771,
272,
347,
511,
63,
17,
8,
277,
304,
267,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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
] |
numerigraphe/sale-workflow
|
sale_exception_nostock/model/sale.py
|
33
|
9058
|
# -*- coding: utf-8 -*-
#
#
# Author: Nicolas Bessi, Leonardo Pistone
# Copyright 2013, 2014 Camptocamp SA
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#
import datetime
from openerp import models, fields, api
from openerp.tools.translate import _
class SaleOrderLine(models.Model):
"""Adds two exception functions to be called by the sale_exceptions module.
The first one will ensure that an order line can be delivered on the
delivery date, if the related product is in MTS. Validation is done by
using the shop related to the sales order line location and using the line
delay.
The second one will raise a sales exception if the current SO will break an
order already placed in future
"""
_inherit = "sale.order.line"
@api.one
def _compute_line_delivery_date(self):
date_order = self.order_id.date_order
date_order = fields.Date.from_string(date_order)
# delay is a float, that is perfectly supported by timedelta
return date_order + datetime.timedelta(days=self.delay)
def _find_parent_locations(self):
location = self.order_id.partner_shipping_id.property_stock_customer
res = [location.id]
while location.location_id:
location = location.location_id
res.append(location.id)
return res
@api.multi
def _predict_rules(self):
"""Choose a rule without a procurement.
This imitates what will be done when the order is validated, with the
difference that here we do not have a procurement yet.
"""
Rule = self.env['procurement.rule']
Warehouse = self.env['stock.warehouse']
order = self.order_id
procurement_data = order._prepare_order_line_procurement(order, self)
# normally this is the order's warehouse, but modules like
# sale_sourced_by_line change this behaviour
warehouse = Warehouse.browse(procurement_data['warehouse_id'])
domain = [('location_id', 'in', self._find_parent_locations())]
warehouse_route_ids = []
if warehouse:
domain += [
'|',
('warehouse_id', '=', warehouse.id),
('warehouse_id', '=', False)
]
warehouse_route_ids = [x.id for x in warehouse.route_ids]
product_route_ids = [
x.id
for x in self.product_id.route_ids +
self.product_id.categ_id.total_route_ids]
procurement_route_ids = [x.id for x in self.route_id]
res = Rule.search(
domain + [('route_id', 'in', procurement_route_ids)],
order='route_sequence, sequence'
)
if not res:
res = Rule.search(
domain + [('route_id', 'in', product_route_ids)],
order='route_sequence, sequence'
)
if not res:
res = warehouse_route_ids and Rule.search(
domain + [('route_id', 'in', warehouse_route_ids)],
order='route_sequence, sequence'
) or []
if not res:
res = Rule.search(domain + [('route_id', '=', False)],
order='sequence')
return res
@api.multi
def _get_line_location(self):
""" Get the source location from the predicted rule"""
rules = self._predict_rules()
if rules:
return rules[0].location_src_id
return False
@api.multi
def _is_make_to_stock(self):
"""Predict whether a make to stock rule will be chosen"""
return self._predict_procure_method() == 'make_to_stock'
@api.multi
def _predict_procure_method(self):
"""Predict the procurement method that will be chosen"""
rules = self._predict_rules()
return rules[0].procure_method
@api.multi
def _should_skip_stock_checks(self):
self.ensure_one()
if (
self.product_id and
self.product_id.type == 'product' and
self._is_make_to_stock() and
self._get_line_location() and
self._get_line_location().usage == 'internal'
):
return False
else:
return True
@api.multi
def can_command_at_delivery_date(self):
"""Predicate that checks whether a SO line can be delivered at delivery
date.
The delivery date is computed using date of the order + line delay.
The source location is predicted with a logic similar to the one that
will be used for real.
:return: True if line can be delivered on time
"""
self.ensure_one()
if self._should_skip_stock_checks():
return True
delivery_date = self._compute_line_delivery_date()[0]
delivery_date = fields.Datetime.to_string(delivery_date)
location = self._get_line_location()
assert location, _("No rules specifies a location"
" for this sale order line")
ctx = {
'to_date': delivery_date,
'compute_child': True,
'location': location.id,
}
try:
ctx['owner_id'] = self.stock_owner_id.id
except AttributeError:
# module sale_owner_stock_sourcing not installed, fine
pass
# Virtual qty is made on all childs of chosen location
prod_for_virtual_qty = (self.product_id
.with_context(ctx)
.virtual_available)
if prod_for_virtual_qty < self.product_uom_qty:
return False
return True
@api.model
def _get_states(self):
return ('waiting', 'confirmed', 'assigned')
@api.model
def _get_affected_dates(self, location_id, product_id, delivery_date):
"""Determine future dates where virtual stock has to be checked.
It will only look for stock move that pass by location_id.
If your stock location have children or you have configured automated
stock action
they must pass by the location related to SO line, else the will be
ignored
:param location_id: location id to be checked
:param product_id: product id te be checked
:return: list of dates to be checked
"""
cr = self._cr
sql = ("SELECT date FROM stock_move"
" WHERE state IN %s"
" AND date > %s"
" AND product_id = %s"
" AND location_id = %s")
cr.execute(sql, (self._get_states(),
delivery_date,
product_id,
location_id))
return (row[0] for row in cr.fetchall())
@api.multi
def future_orders_are_affected(self):
"""Predicate function that is a naive workaround for the lack of stock
reservation.
This can be a performance killer, you should not use it
if you have constantly a lot of running Orders
:return: True if future order are affected by current command line
"""
self.ensure_one()
if self._should_skip_stock_checks():
return False
delivery_date = self._compute_line_delivery_date()[0]
delivery_date = fields.Datetime.to_string(delivery_date)
location = self._get_line_location()
assert location, _("No rules specifies a location"
" for this sale order line")
ctx = {
'compute_child': True,
'location_id': location.id,
}
try:
ctx['owner_id'] = self.stock_owner_id.id
except AttributeError:
# module sale_owner_stock_sourcing not installed, fine
pass
# Virtual qty is made on all childs of chosen location
dates = self._get_affected_dates(location.id, self.product_id.id,
delivery_date)
for aff_date in dates:
ctx['to_date'] = aff_date
prod_for_virtual_qty = (self.product_id
.with_context(ctx)
.virtual_available)
if prod_for_virtual_qty < self.product_uom_qty:
return True
return False
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
199,
3,
259,
6529,
26,
30650,
761,
305,
699,
28601,
12,
7005,
265,
1005,
79,
510,
631,
368,
199,
3,
259,
1898,
6171,
12,
6927,
24569,
475,
20290,
13950,
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,
3,
199,
646,
2197,
199,
504,
5166,
492,
1709,
12,
1504,
12,
2986,
199,
504,
5166,
14,
2537,
14,
5275,
492,
485,
421,
199,
533,
428,
1895,
4738,
3049,
8,
992,
14,
1685,
304,
339,
408,
14995,
2877,
1919,
3423,
370,
506,
2797,
701,
314,
13590,
63,
3924,
859,
14,
339,
710,
1642,
1373,
911,
4868,
626,
376,
1865,
1004,
883,
506,
28218,
641,
314,
272,
18719,
1434,
12,
340,
314,
4048,
3336,
365,
315,
603,
9730,
14,
19381,
365,
4224,
701,
272,
1808,
314,
25630,
4048,
370,
314,
21702,
1865,
1004,
2909,
436,
1808,
314,
1004,
272,
7339,
14,
272,
710,
3499,
1373,
911,
746,
282,
21702,
1919,
340,
314,
1453,
3562,
911,
2059,
376,
272,
1865,
2575,
15090,
315,
6466,
339,
408,
339,
485,
6486,
275,
298,
8515,
14,
1648,
14,
604,
2,
339,
768,
1246,
14,
368,
272,
347,
485,
3357,
63,
604,
63,
14564,
63,
602,
8,
277,
304,
267,
1434,
63,
1648,
275,
291,
14,
1648,
63,
344,
14,
602,
63,
1648,
267,
1434,
63,
1648,
275,
1504,
14,
2506,
14,
504,
63,
875,
8,
602,
63,
1648,
9,
267,
327,
7339,
365,
282,
2069,
12,
626,
365,
23668,
590,
3748,
701,
6871,
267,
372,
1434,
63,
1648,
435,
2197,
14,
7473,
8,
4899,
29,
277,
14,
5814,
9,
339,
347,
485,
1623,
63,
1708,
63,
8022,
8,
277,
304,
267,
2909,
275,
291,
14,
1648,
63,
344,
14,
3899,
63,
17801,
63,
344,
14,
1829,
63,
6088,
63,
10178,
398,
522,
275,
359,
1985,
14,
344,
61,
267,
1830,
2909,
14,
1985,
63,
344,
26,
288,
2909,
275,
2909,
14,
1985,
63,
344,
288,
522,
14,
740,
8,
1985,
14,
344,
9,
267,
372,
522,
339,
768,
1246,
14,
3029,
272,
347,
485,
6892,
63,
4423,
8,
277,
304,
267,
408,
23932,
282,
2332,
1928,
282,
16214,
14,
398,
961,
284,
1147,
2335,
4052,
911,
506,
4224,
1380,
314,
1865,
365,
16468,
12,
543,
314,
267,
8865,
626,
2348,
781,
886,
440,
1172,
282,
16214,
5966,
14,
398,
408,
267,
11949,
275,
291,
14,
1813,
459,
18546,
14,
2200,
418,
267,
644,
11499,
275,
291,
14,
1813,
459,
6088,
14,
12806,
418,
398,
1865,
275,
291,
14,
1648,
63,
344,
267,
16214,
63,
576,
275,
1865,
423,
6726,
63,
1648,
63,
604,
63,
18546,
8,
1648,
12,
291,
9,
267,
327,
12252,
642,
365,
314,
1865,
1159,
13782,
12,
1325,
4621,
2839,
267,
327,
13590,
63,
1365,
68,
63,
991,
63,
604,
1570,
642,
13942,
398,
13782,
275,
644,
11499,
14,
4570,
8,
18546,
63,
576,
459,
12806,
63,
344,
1105,
398,
2881,
275,
4274,
1985,
63,
344,
297,
283,
262,
297,
291,
423,
1623,
63,
1708,
63,
8022,
24821,
267,
13782,
63,
4449,
63,
1580,
275,
942,
267,
340,
13782,
26,
288,
2881,
847,
359,
355,
11280,
297,
355,
661,
12806,
63,
344,
297,
6291,
13782,
14,
344,
395,
355,
661,
12806,
63,
344,
297,
6291,
756,
9,
288,
1622,
288,
13782,
63,
4449,
63,
1580,
275,
359,
88,
14,
344,
367,
671,
315,
13782,
14,
4449,
63,
1580,
61,
398,
3336,
63,
4449,
63,
1580,
275,
359,
288,
671,
14,
344,
288,
367,
671,
315,
291,
14,
2558,
63,
344,
14,
4449,
63,
1580,
435,
288,
291,
14,
2558,
63,
344,
14,
3533,
63,
344,
14,
2923,
63,
4449,
63,
1580,
61,
267,
16214,
63,
4449,
63,
1580,
275,
359,
88,
14,
344,
367,
671,
315,
291,
14,
4449,
63,
344,
61,
267,
522,
275,
11949,
14,
1733,
8,
288,
2881,
435,
4274,
4449,
63,
344,
297,
283,
262,
297,
16214,
63,
4449,
63,
1580,
4360,
288,
1865,
534,
4449,
63,
4041,
12,
3414,
7,
267,
776,
398,
340,
440,
522,
26,
288,
522,
275,
11949,
14,
1733,
8,
355,
2881,
435,
4274,
4449,
63,
344,
297,
283,
262,
297,
3336,
63,
4449,
63,
1580,
4360,
355,
1865,
534,
4449,
63,
4041,
12,
3414,
7,
288,
776,
288,
340,
440,
522,
26,
355,
522,
275,
13782,
63,
4449,
63,
1580,
436,
11949,
14,
1733,
8,
490,
2881,
435,
4274,
4449,
63,
344,
297,
283,
262,
297,
13782,
63,
4449,
63,
1580,
4360,
490,
1865,
534,
4449,
63,
4041,
12,
3414,
7,
355,
776,
503,
942,
355,
340,
440,
522,
26,
490,
522,
275,
11949,
14,
1733,
8,
2261,
435,
4274,
4449,
63,
344,
297,
6291,
756,
4360,
4228,
1865,
534,
4041,
358,
267,
372,
522,
339,
768,
1246,
14,
3029,
272,
347,
485,
362,
63,
604,
63,
1985,
8,
277,
304,
267,
408,
2372,
314,
1350,
2909,
687,
314,
14746,
2332,
624,
398,
4713,
275,
291,
423,
6892,
63,
4423,
342,
398,
340,
4713,
26,
288,
372,
4713,
59,
16,
1055,
1985,
63,
2164,
63,
344,
267,
372,
756,
339,
768,
1246,
14,
3029,
272,
347,
485,
374,
63,
1875,
63,
475,
63,
6088,
8,
277,
304,
267,
408,
28240,
3775,
282,
1852,
370,
10952,
2332,
911,
506,
12414,
624,
267,
372,
291,
423,
6892,
63,
4687,
608
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
199,
3,
259,
6529,
26,
30650,
761,
305,
699,
28601,
12,
7005,
265,
1005,
79,
510,
631,
368,
199,
3,
259,
1898,
6171,
12,
6927,
24569,
475,
20290,
13950,
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,
3,
199,
646,
2197,
199,
504,
5166,
492,
1709,
12,
1504,
12,
2986,
199,
504,
5166,
14,
2537,
14,
5275,
492,
485,
421,
199,
533,
428,
1895,
4738,
3049,
8,
992,
14,
1685,
304,
339,
408,
14995,
2877,
1919,
3423,
370,
506,
2797,
701,
314,
13590,
63,
3924,
859,
14,
339,
710,
1642,
1373,
911,
4868,
626,
376,
1865,
1004,
883,
506,
28218,
641,
314,
272,
18719,
1434,
12,
340,
314,
4048,
3336,
365,
315,
603,
9730,
14,
19381,
365,
4224,
701,
272,
1808,
314,
25630,
4048,
370,
314,
21702,
1865,
1004,
2909,
436,
1808,
314,
1004,
272,
7339,
14,
272,
710,
3499,
1373,
911,
746,
282,
21702,
1919,
340,
314,
1453,
3562,
911,
2059,
376,
272,
1865,
2575,
15090,
315,
6466,
339,
408,
339,
485,
6486,
275,
298,
8515,
14,
1648,
14,
604,
2,
339,
768,
1246,
14,
368,
272,
347,
485,
3357,
63,
604,
63,
14564,
63,
602,
8,
277,
304,
267,
1434,
63,
1648,
275,
291,
14,
1648,
63,
344,
14,
602,
63,
1648,
267,
1434,
63,
1648,
275,
1504,
14,
2506,
14,
504,
63,
875,
8,
602,
63,
1648,
9,
267,
327,
7339,
365,
282,
2069,
12,
626,
365,
23668,
590,
3748,
701,
6871,
267,
372,
1434,
63,
1648,
435,
2197,
14,
7473,
8,
4899,
29,
277,
14,
5814,
9,
339,
347,
485,
1623,
63,
1708,
63,
8022,
8,
277,
304,
267,
2909,
275,
291,
14,
1648,
63,
344,
14,
3899,
63,
17801,
63,
344,
14,
1829,
63,
6088,
63,
10178,
398,
522,
275,
359,
1985,
14,
344,
61,
267,
1830,
2909,
14,
1985,
63,
344,
26,
288,
2909,
275,
2909,
14,
1985,
63,
344,
288,
522,
14,
740,
8,
1985,
14,
344,
9,
267,
372,
522,
339,
768,
1246,
14,
3029,
272,
347,
485,
6892,
63,
4423,
8,
277,
304,
267,
408,
23932,
282,
2332,
1928,
282,
16214,
14,
398,
961,
284,
1147,
2335,
4052,
911,
506,
4224,
1380,
314,
1865,
365,
16468,
12,
543,
314,
267,
8865,
626,
2348,
781,
886,
440,
1172,
282,
16214,
5966,
14,
398,
408,
267,
11949,
275,
291,
14,
1813,
459,
18546,
14,
2200,
418,
267,
644,
11499,
275,
291,
14,
1813,
459,
6088,
14,
12806,
418,
398,
1865,
275,
291,
14,
1648,
63,
344,
267,
16214,
63,
576,
275,
1865,
423,
6726,
63,
1648,
63,
604,
63,
18546,
8,
1648,
12,
291,
9,
267,
327,
12252,
642,
365,
314,
1865,
1159,
13782,
12,
1325,
4621,
2839,
267,
327,
13590,
63,
1365,
68,
63,
991,
63,
604,
1570,
642,
13942,
398,
13782,
275,
644,
11499,
14,
4570,
8,
18546,
63,
576,
459,
12806,
63,
344,
1105,
398,
2881,
275,
4274,
1985,
63,
344,
297,
283,
262,
297,
291,
423,
1623,
63,
1708,
63,
8022,
24821,
267,
13782,
63,
4449,
63,
1580,
275,
942,
267,
340,
13782,
26,
288,
2881,
847,
359,
355,
11280,
297,
355,
661,
12806,
63,
344,
297,
6291,
13782,
14,
344,
395,
355,
661,
12806,
63,
344,
297,
6291,
756,
9,
288,
1622,
288,
13782,
63,
4449,
63,
1580,
275,
359,
88,
14,
344,
367,
671,
315,
13782,
14,
4449,
63,
1580,
61,
398,
3336,
63,
4449,
63,
1580,
275,
359,
288,
671,
14,
344,
288,
367,
671,
315,
291,
14,
2558,
63,
344,
14,
4449,
63,
1580,
435,
288,
291,
14,
2558,
63,
344,
14,
3533,
63,
344,
14,
2923,
63,
4449,
63,
1580,
61,
267,
16214,
63,
4449,
63,
1580,
275,
359,
88,
14,
344,
367,
671,
315,
291,
14,
4449,
63,
344,
61,
267,
522,
275,
11949,
14,
1733,
8,
288,
2881,
435,
4274,
4449,
63,
344,
297,
283,
262,
297,
16214,
63,
4449,
63,
1580,
4360,
288,
1865,
534,
4449,
63,
4041,
12,
3414,
7,
267,
776,
398,
340,
440,
522,
26,
288,
522,
275,
11949,
14,
1733,
8,
355,
2881,
435,
4274,
4449,
63,
344,
297,
283,
262,
297,
3336,
63,
4449,
63,
1580,
4360,
355,
1865,
534,
4449,
63,
4041,
12,
3414,
7,
288,
776,
288,
340,
440,
522,
26,
355,
522,
275,
13782,
63,
4449,
63,
1580,
436,
11949,
14,
1733,
8,
490,
2881,
435,
4274,
4449,
63,
344,
297,
283,
262,
297,
13782,
63,
4449,
63,
1580,
4360,
490,
1865,
534,
4449,
63,
4041,
12,
3414,
7,
355,
776,
503,
942,
355,
340,
440,
522,
26,
490,
522,
275,
11949,
14,
1733,
8,
2261,
435,
4274,
4449,
63,
344,
297,
6291,
756,
4360,
4228,
1865,
534,
4041,
358,
267,
372,
522,
339,
768,
1246,
14,
3029,
272,
347,
485,
362,
63,
604,
63,
1985,
8,
277,
304,
267,
408,
2372,
314,
1350,
2909,
687,
314,
14746,
2332,
624,
398,
4713,
275,
291,
423,
6892,
63,
4423,
342,
398,
340,
4713,
26,
288,
372,
4713,
59,
16,
1055,
1985,
63,
2164,
63,
344,
267,
372,
756,
339,
768,
1246,
14,
3029,
272,
347,
485,
374,
63,
1875,
63,
475,
63,
6088,
8,
277,
304,
267,
408,
28240,
3775,
282,
1852,
370,
10952,
2332,
911,
506,
12414,
624,
267,
372,
291,
423,
6892,
63,
4687,
608,
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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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
sighingnow/sighingnow.github.io
|
resource/k_nearest_neighbors/dating.py
|
1
|
3622
|
#! /usr/bin/env python
# -*- coding: utf-8
'''
Name: dating.py(KNN algorithm)
Training and test dataset: dating.txt
Created on Feb 8, 2015
@author: Tao He
'''
__author__ = 'Tao He'
from numpy import array as nmarray
from matplotlib import pyplot as plt
LABEL_MAP = {
'didntLike': 1,
'smallDoses': 2,
'largeDoses': 3,
}
ATTR_MAP = {
1: 'Number of frequent flyer miles earned per year',
2: 'Percentage of time spent playing video games',
3: 'Liters of ice cream consumed per week',
}
def create_dataset(filename=None):
''' Return data group and labels.
Get the data from file.
If the filename is not specialed, return None.
dataformat: flyerMiles, gameTime, icecream, label.
'''
def normalize_data(data=None):
''' Normalized dataset.
Normalize all data to range 0-1.
'''
if data is None:
return None
for column in range(data[0].__len__()):
max_val, min_val = max(data[:, column]), min(data[:, column])
for row in range(data.__len__()):
data[row][column] = (data[row][column]-min_val)/(max_val-min_val)
return data
if filename == None:
return (None, None)
group = []
labels = []
with open(filename, mode='r') as fp_data:
for line in fp_data:
group.append([float(num) for num in line[:-1].split('\t')[0:3]])
labels.append(LABEL_MAP[line[:-1].split('\t')[3]])
return normalize_data(nmarray(group)), labels
def draw_pic(group=None, labels=None, x=0, y=0):
''' Draw a subplot from data group.
'''
if group is None or labels is None:
return None
name = 'knn-dating'
figure = plt.figure(num=name, dpi=100)
ax_main = figure.add_subplot(1, 1, 1, xlabel=ATTR_MAP[x+1], ylabel=ATTR_MAP[y+1], title=name)
ax_main.scatter(group[:, x], group[:, y],
s=15*nmarray(labels),
c=[[i/LABEL_MAP.__len__()] for i in labels])
plt.show()
## plt.savefig('%s.png'%name, format='png', dpi=100)
def knn_classify(group, labels, attrs, ratio=0.5, item=0, k=3):
''' Return the type of item.
knn classify function.
'''
def get_dist(i, j):
''' Return the distence of group[i] and group[j].
'''
dist = 0.0
for attr in attrs:
dist += (group[i][attr]-group[j][attr])*(group[i][attr]-group[j][attr])
return dist
length = group.__len__()
distence = []
for i in range(int(length*ratio), length):
distence.append((i, get_dist(item, i)))
cnt = {}
distence.sort(key=lambda item: item[1])
for i in range(k):
label = labels[distence[i][0]]
if label in cnt:
cnt[label] += 1
else:
cnt[label] = 1
return sorted(cnt.items(), key=lambda item: item[1], reverse=True)[0][0]
def knn():
''' KNN classify algorithm.
'''
data, labels = create_dataset('dating.txt')
ratio, attr = 0.5, [0, 1, 2]
cnt, cnt_correct = 0, 0
length = data.__len__()
for i in range(0, int(length*ratio)):
cnt += 1
knn_type = knn_classify(data, labels, attr, ratio, i, 3)
# print('case[%d]: real: %d, knn: %d'%(i, labels[i], knn_type))
if knn_type == labels[i]:
cnt_correct += 1
print('total: %d, correct: %d, correct ratio: %f'%(cnt, cnt_correct, cnt_correct/cnt))
if __name__ == '__main__':
knn()
# vim: set sw=4, ts=4, fileencoding=utf-8
|
mit
|
[
3168,
1182,
2647,
15,
1393,
15,
1813,
2366,
202,
199,
3,
1882,
2803,
26,
2774,
13,
24,
2999,
199,
2344,
202,
199,
985,
26,
366,
1958,
14,
647,
8,
43,
7178,
5563,
9,
202,
199,
20463,
436,
511,
4789,
26,
366,
1958,
14,
2424,
2999,
199,
10502,
641,
21141,
1695,
12,
6900,
2999,
199,
32,
2502,
26,
377,
8035,
5311,
202,
199,
2344,
2999,
199,
363,
2502,
363,
275,
283,
52,
8035,
5311,
7,
2999,
199,
504,
2680,
492,
1625,
465,
16751,
1144,
202,
199,
504,
8027,
492,
1134,
2798,
465,
4488,
2999,
199,
13837,
63,
5443,
275,
469,
1128,
283,
14887,
343,
12545,
356,
413,
12,
1128,
283,
7241,
2585,
874,
356,
499,
12,
1128,
283,
9629,
2585,
874,
356,
650,
12,
202,
199,
93,
2999,
199,
5280,
63,
5443,
275,
469,
1128,
413,
26,
283,
3259,
402,
28914,
23158,
281,
333,
22894,
325,
31772,
1126,
5361,
297,
1128,
499,
26,
283,
17931,
474,
402,
900,
2249,
484,
25692,
3991,
9219,
83,
297,
1128,
650,
26,
283,
13009,
878,
402,
284,
301,
286,
1091,
16949,
1126,
8620,
297,
202,
199,
93,
2999,
199,
318,
1218,
63,
5214,
8,
1501,
29,
403,
304,
1128,
1449,
1432,
666,
1572,
436,
3628,
14,
1128,
2372,
314,
666,
687,
570,
14,
1128,
982,
314,
1788,
365,
440,
1106,
65,
1146,
12,
372,
488,
14,
2958,
666,
908,
26,
23158,
281,
45,
22894,
12,
9219,
1366,
12,
284,
31645,
1091,
12,
1768,
14,
1128,
1449,
2958,
347,
7666,
63,
576,
8,
576,
29,
403,
304,
1039,
1449,
11514,
1759,
4789,
14,
1039,
21017,
1006,
666,
370,
1425,
378,
13,
17,
14,
1039,
1449,
1039,
340,
666,
365,
488,
26,
1675,
372,
488,
1039,
367,
2763,
315,
1425,
8,
576,
59,
16,
17979,
552,
4533,
304,
1675,
1390,
63,
637,
12,
1748,
63,
637,
275,
1390,
8,
576,
3981,
2763,
2522,
1748,
8,
576,
3981,
2763,
566,
1675,
367,
1962,
315,
1425,
8,
576,
855,
552,
4533,
304,
2628,
666,
59,
1143,
1527,
2301,
61,
275,
334,
576,
59,
1143,
1527,
2301,
11285,
827,
63,
637,
15136,
988,
63,
637,
13,
827,
63,
637,
9,
1039,
372,
666,
2958,
340,
1788,
508,
488,
26,
1039,
372,
334,
403,
12,
488,
9,
1128,
1572,
275,
942,
1128,
3628,
275,
942,
1128,
543,
1551,
8,
1501,
12,
818,
534,
82,
358,
465,
4090,
63,
576,
26,
1039,
367,
1004,
315,
4090,
63,
576,
26,
1675,
1572,
14,
740,
779,
1609,
8,
1507,
9,
367,
1967,
315,
1004,
4439,
17,
1055,
1294,
2258,
84,
5832,
16,
26,
19,
3934,
1675,
3628,
14,
740,
8,
13837,
63,
5443,
59,
604,
4439,
17,
1055,
1294,
2258,
84,
5832,
19,
3934,
1128,
372,
7666,
63,
576,
8,
10756,
1144,
8,
923,
1826,
3628,
2999,
199,
318,
5954,
63,
12475,
8,
923,
29,
403,
12,
3628,
29,
403,
12,
671,
29,
16,
12,
612,
29,
16,
304,
1128,
1449,
17813,
282,
1007,
2798,
687,
666,
1572,
14,
1128,
1449,
1128,
340,
1572,
365,
488,
503,
3628,
365,
488,
26,
1039,
372,
488,
1128,
536,
275,
283,
75,
4411,
13,
9239,
7,
1128,
9658,
275,
4488,
14,
8941,
8,
1507,
29,
354,
12,
26910,
29,
1960,
9,
1128,
2185,
63,
973,
275,
9658,
14,
525,
63,
13334,
8,
17,
12,
413,
12,
413,
12,
671,
1302,
29,
5280,
63,
5443,
59,
88,
11,
17,
467,
612,
1302,
29,
5280,
63,
5443,
59,
89,
11,
17,
467,
2538,
29,
354,
9,
1128,
2185,
63,
973,
14,
13512,
8,
923,
3981,
671,
467,
1572,
3981,
612,
467,
4906,
308,
29,
1046,
10,
10756,
1144,
8,
3512,
395,
4906,
286,
16025,
73,
15,
13837,
63,
5443,
855,
552,
4533,
61,
367,
284,
315,
3628,
566,
1128,
4488,
14,
2384,
342,
1128,
925,
4488,
14,
19556,
3508,
83,
14,
4524,
5956,
354,
12,
1475,
534,
4524,
297,
26910,
29,
1960,
9,
2999,
199,
318,
1022,
4411,
63,
12334,
1399,
8,
923,
12,
3628,
12,
3290,
12,
10463,
29,
16,
14,
21,
12,
1242,
29,
16,
12,
1022,
29,
19,
304,
1128,
1449,
1432,
314,
730,
402,
1242,
14,
1128,
1022,
4411,
28837,
805,
14,
1128,
1449,
2958,
347,
664,
63,
2686,
8,
73,
12,
1335,
304,
1039,
1449,
1432,
314,
2153,
6692,
402,
1572,
59,
73,
61,
436,
1572,
59,
74,
1055,
1039,
1449,
1039,
2917,
275,
378,
14,
16,
1039,
367,
1921,
315,
3290,
26,
1675,
2917,
847,
334,
923,
59,
73,
1527,
962,
11285,
923,
59,
74,
1527,
962,
566,
5830,
923,
59,
73,
1527,
962,
11285,
923,
59,
74,
1527,
962,
566,
1039,
372,
2917,
2958,
2582,
275,
1572,
855,
552,
4533,
1128,
2153,
6692,
275,
942,
1128,
367,
284,
315,
1425,
8,
442,
8,
1267,
10,
6884,
395,
2582,
304,
1039,
2153,
6692,
14,
740,
1332,
73,
12,
664,
63,
2686,
8,
1053,
12,
284,
1724,
1128,
12703,
275,
1052,
1128,
2153,
6692,
14,
3191,
8,
498,
29,
2734,
1242,
26,
1242,
59,
17,
566,
1128,
367,
284,
315,
1425,
8,
75,
304,
1039,
1768,
275,
3628,
59,
2297,
6692,
59,
73,
1527,
16,
2677,
1039,
340,
1768,
315,
12703,
26,
1675,
12703,
59,
1302,
61,
847,
413,
1039,
587,
26,
1675,
12703,
59,
1302,
61,
275,
413,
1128,
372,
3355,
8,
6507,
14,
1744,
1062,
790,
29,
2734,
1242,
26,
1242,
59,
17,
467,
3837,
29,
549,
2788,
16,
1527,
16,
61,
2999,
199,
318,
1022,
4411,
837,
1128,
1449,
1804,
7178,
28837,
5563,
14,
1128,
1449,
1128,
666,
12,
3628,
275,
1218,
63,
5214,
360,
9239,
14,
2424,
358,
1128,
10463,
12,
1921,
275,
378,
14,
21,
12,
359,
16,
12,
413,
12,
499,
61,
1128,
12703,
12,
12703,
63,
4525,
275,
378,
12,
378,
1128,
2582,
275,
666,
855,
552,
4533,
1128,
367,
284,
315,
1425,
8,
16,
12,
1109,
8,
1267,
10,
6884,
2298,
1039,
12703,
847,
413,
1039,
1022,
4411,
63,
466,
275,
1022,
4411,
63,
12334,
1399,
8,
576,
12,
3628,
12,
1921,
12,
10463,
12,
284,
12,
650,
9,
1039,
327,
870,
360,
2546,
9722,
68,
2189,
3363,
26,
450,
68,
12,
1022,
4411,
26,
450,
68,
13328,
73,
12,
3628,
59,
73,
467,
1022,
4411,
63,
466,
430,
1039,
340,
1022,
4411,
63,
466,
508,
3628,
59,
73,
2189
] |
[
1182,
2647,
15,
1393,
15,
1813,
2366,
202,
199,
3,
1882,
2803,
26,
2774,
13,
24,
2999,
199,
2344,
202,
199,
985,
26,
366,
1958,
14,
647,
8,
43,
7178,
5563,
9,
202,
199,
20463,
436,
511,
4789,
26,
366,
1958,
14,
2424,
2999,
199,
10502,
641,
21141,
1695,
12,
6900,
2999,
199,
32,
2502,
26,
377,
8035,
5311,
202,
199,
2344,
2999,
199,
363,
2502,
363,
275,
283,
52,
8035,
5311,
7,
2999,
199,
504,
2680,
492,
1625,
465,
16751,
1144,
202,
199,
504,
8027,
492,
1134,
2798,
465,
4488,
2999,
199,
13837,
63,
5443,
275,
469,
1128,
283,
14887,
343,
12545,
356,
413,
12,
1128,
283,
7241,
2585,
874,
356,
499,
12,
1128,
283,
9629,
2585,
874,
356,
650,
12,
202,
199,
93,
2999,
199,
5280,
63,
5443,
275,
469,
1128,
413,
26,
283,
3259,
402,
28914,
23158,
281,
333,
22894,
325,
31772,
1126,
5361,
297,
1128,
499,
26,
283,
17931,
474,
402,
900,
2249,
484,
25692,
3991,
9219,
83,
297,
1128,
650,
26,
283,
13009,
878,
402,
284,
301,
286,
1091,
16949,
1126,
8620,
297,
202,
199,
93,
2999,
199,
318,
1218,
63,
5214,
8,
1501,
29,
403,
304,
1128,
1449,
1432,
666,
1572,
436,
3628,
14,
1128,
2372,
314,
666,
687,
570,
14,
1128,
982,
314,
1788,
365,
440,
1106,
65,
1146,
12,
372,
488,
14,
2958,
666,
908,
26,
23158,
281,
45,
22894,
12,
9219,
1366,
12,
284,
31645,
1091,
12,
1768,
14,
1128,
1449,
2958,
347,
7666,
63,
576,
8,
576,
29,
403,
304,
1039,
1449,
11514,
1759,
4789,
14,
1039,
21017,
1006,
666,
370,
1425,
378,
13,
17,
14,
1039,
1449,
1039,
340,
666,
365,
488,
26,
1675,
372,
488,
1039,
367,
2763,
315,
1425,
8,
576,
59,
16,
17979,
552,
4533,
304,
1675,
1390,
63,
637,
12,
1748,
63,
637,
275,
1390,
8,
576,
3981,
2763,
2522,
1748,
8,
576,
3981,
2763,
566,
1675,
367,
1962,
315,
1425,
8,
576,
855,
552,
4533,
304,
2628,
666,
59,
1143,
1527,
2301,
61,
275,
334,
576,
59,
1143,
1527,
2301,
11285,
827,
63,
637,
15136,
988,
63,
637,
13,
827,
63,
637,
9,
1039,
372,
666,
2958,
340,
1788,
508,
488,
26,
1039,
372,
334,
403,
12,
488,
9,
1128,
1572,
275,
942,
1128,
3628,
275,
942,
1128,
543,
1551,
8,
1501,
12,
818,
534,
82,
358,
465,
4090,
63,
576,
26,
1039,
367,
1004,
315,
4090,
63,
576,
26,
1675,
1572,
14,
740,
779,
1609,
8,
1507,
9,
367,
1967,
315,
1004,
4439,
17,
1055,
1294,
2258,
84,
5832,
16,
26,
19,
3934,
1675,
3628,
14,
740,
8,
13837,
63,
5443,
59,
604,
4439,
17,
1055,
1294,
2258,
84,
5832,
19,
3934,
1128,
372,
7666,
63,
576,
8,
10756,
1144,
8,
923,
1826,
3628,
2999,
199,
318,
5954,
63,
12475,
8,
923,
29,
403,
12,
3628,
29,
403,
12,
671,
29,
16,
12,
612,
29,
16,
304,
1128,
1449,
17813,
282,
1007,
2798,
687,
666,
1572,
14,
1128,
1449,
1128,
340,
1572,
365,
488,
503,
3628,
365,
488,
26,
1039,
372,
488,
1128,
536,
275,
283,
75,
4411,
13,
9239,
7,
1128,
9658,
275,
4488,
14,
8941,
8,
1507,
29,
354,
12,
26910,
29,
1960,
9,
1128,
2185,
63,
973,
275,
9658,
14,
525,
63,
13334,
8,
17,
12,
413,
12,
413,
12,
671,
1302,
29,
5280,
63,
5443,
59,
88,
11,
17,
467,
612,
1302,
29,
5280,
63,
5443,
59,
89,
11,
17,
467,
2538,
29,
354,
9,
1128,
2185,
63,
973,
14,
13512,
8,
923,
3981,
671,
467,
1572,
3981,
612,
467,
4906,
308,
29,
1046,
10,
10756,
1144,
8,
3512,
395,
4906,
286,
16025,
73,
15,
13837,
63,
5443,
855,
552,
4533,
61,
367,
284,
315,
3628,
566,
1128,
4488,
14,
2384,
342,
1128,
925,
4488,
14,
19556,
3508,
83,
14,
4524,
5956,
354,
12,
1475,
534,
4524,
297,
26910,
29,
1960,
9,
2999,
199,
318,
1022,
4411,
63,
12334,
1399,
8,
923,
12,
3628,
12,
3290,
12,
10463,
29,
16,
14,
21,
12,
1242,
29,
16,
12,
1022,
29,
19,
304,
1128,
1449,
1432,
314,
730,
402,
1242,
14,
1128,
1022,
4411,
28837,
805,
14,
1128,
1449,
2958,
347,
664,
63,
2686,
8,
73,
12,
1335,
304,
1039,
1449,
1432,
314,
2153,
6692,
402,
1572,
59,
73,
61,
436,
1572,
59,
74,
1055,
1039,
1449,
1039,
2917,
275,
378,
14,
16,
1039,
367,
1921,
315,
3290,
26,
1675,
2917,
847,
334,
923,
59,
73,
1527,
962,
11285,
923,
59,
74,
1527,
962,
566,
5830,
923,
59,
73,
1527,
962,
11285,
923,
59,
74,
1527,
962,
566,
1039,
372,
2917,
2958,
2582,
275,
1572,
855,
552,
4533,
1128,
2153,
6692,
275,
942,
1128,
367,
284,
315,
1425,
8,
442,
8,
1267,
10,
6884,
395,
2582,
304,
1039,
2153,
6692,
14,
740,
1332,
73,
12,
664,
63,
2686,
8,
1053,
12,
284,
1724,
1128,
12703,
275,
1052,
1128,
2153,
6692,
14,
3191,
8,
498,
29,
2734,
1242,
26,
1242,
59,
17,
566,
1128,
367,
284,
315,
1425,
8,
75,
304,
1039,
1768,
275,
3628,
59,
2297,
6692,
59,
73,
1527,
16,
2677,
1039,
340,
1768,
315,
12703,
26,
1675,
12703,
59,
1302,
61,
847,
413,
1039,
587,
26,
1675,
12703,
59,
1302,
61,
275,
413,
1128,
372,
3355,
8,
6507,
14,
1744,
1062,
790,
29,
2734,
1242,
26,
1242,
59,
17,
467,
3837,
29,
549,
2788,
16,
1527,
16,
61,
2999,
199,
318,
1022,
4411,
837,
1128,
1449,
1804,
7178,
28837,
5563,
14,
1128,
1449,
1128,
666,
12,
3628,
275,
1218,
63,
5214,
360,
9239,
14,
2424,
358,
1128,
10463,
12,
1921,
275,
378,
14,
21,
12,
359,
16,
12,
413,
12,
499,
61,
1128,
12703,
12,
12703,
63,
4525,
275,
378,
12,
378,
1128,
2582,
275,
666,
855,
552,
4533,
1128,
367,
284,
315,
1425,
8,
16,
12,
1109,
8,
1267,
10,
6884,
2298,
1039,
12703,
847,
413,
1039,
1022,
4411,
63,
466,
275,
1022,
4411,
63,
12334,
1399,
8,
576,
12,
3628,
12,
1921,
12,
10463,
12,
284,
12,
650,
9,
1039,
327,
870,
360,
2546,
9722,
68,
2189,
3363,
26,
450,
68,
12,
1022,
4411,
26,
450,
68,
13328,
73,
12,
3628,
59,
73,
467,
1022,
4411,
63,
466,
430,
1039,
340,
1022,
4411,
63,
466,
508,
3628,
59,
73,
2189,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
sparkslabs/kamaelia
|
Code/Python/Axon/Axon/__init__.py
|
6
|
6110
|
#
# Copyright 2010 British Broadcasting Corporation and Kamaelia Contributors(1)
#
# (1) Kamaelia Contributors are listed in the AUTHORS file and at
# http://www.kamaelia.org/AUTHORS - please extend this file,
# not this notice.
#
# 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.
# -------------------------------------------------------------------------
"""\
===============================================
Axon - the core concurrency system for Kamaelia
===============================================
Axon is a component concurrency framework. With it you can create software
"components" that can run concurrently with each other. Components have
"inboxes" and "outboxes" through with they communicate with other components.
A component may send a message to one of its outboxes. If a linkage has been
created from that outbox to another component's inbox; then that message will
arrive in the inbox of the other component. In this way, components can send
and receive data - allowing you to create systems by linking many components
together.
Each component is a microprocess - rather like a thread of execution. A
scheduler takes care of making sure all microprocesses (and therefore all
components) get regularly executed. It also looks after putting microprocesses
to sleep (when they ask to be) and waking them up (for example, when something
arrives in one of their inboxes).
Base classes for building your own components
---------------------------------------------
* **Axon.Component**
- defines the basic component. Subclass it to write your own components.
* **Axon.AdaptiveCommsComponent**
- like a basic component but with facilties to let you add and remove inboxes
and outboxes during runtime.
* **Axon.ThreadedComponent**
- like ordinary components, but which truly run in a separate thread - meaning
they can perform blocking tasks (since they don't have to yield control to
the scheduler for other components to continue executing)
Underlying concurrency system
-----------------------------
* **Axon.Microprocess**
- Turns a python generator into a schedulable microprocess - something that
can be started, paused, reawoken and stopped. Subclass it to make your own.
* **Axon.Scheduler**
- Runs the microprocesses. Manages the starting, stopping, pausing
and waking of them. Is also a microprocess itself!
Services, statistics, Instrospection
------------------------------------
* **Axon.CoordinatingAssistantTracker**
- provides mechanisms for components to advertising and discover services they
can provide for each other.
- acts as a repository for collecting statistics from components in the system
* **Axon.Introspector**
- outputs live topology data describing what components there are in a
running axon system and how they are linked together.
Exceptions, Messages and Misc
-----------------------------
* **Axon.Base**
- base metaclass for key Axon classes
* **Axon.AxonExceptions**
- classes defining various exceptions in Axon.
* **Axon.Ipc**
- classes defining various IPC messages in Axon used for signalling shutdown,
errors, notifications, etc...
* **Axon.idGen**
- unique id value generation
* **Axon.util**
- various miscellaneous support utility methods
Integration with other systems
------------------------------
* **Axon.background**
- use Axon components within other python programs by wrapping them in
a scheduler running in a separate thread
* **Axon.Handle**
- a Handle for getting data into and out of the standard inboxes and outboxes
of a component from a non Axon based piece of code. Useful in combination
with Axon.background
Internals for implementing inboxes, outboxes and linkages
---------------------------------------------------------
* **Axon.Box**
- The base implementation of inboxes and outboxes.
* **Axon.Postoffice**
- All components have one of these for creating, destroying and tracking
linkages.
* **Axon.Linkage**
- handles used to describe linkages from one postbox to another
What, no Postman? Optimisations made to Axon have dropped the Postman.
Inboxes and outboxes handle the delivery of messages themselves now.
Debugging support
-----------------
* **Axon.debug**
- defines a debugging output object.
* **Axon.debugConfigFile**
- defines a method for loading a debugging configuration file that determines
what debugging output gets displayed and what gets filtered out.
* **Axon.debugConfigDefaults**
- defines a method that supplies a default debugging configuration.
"""
import Axon.Component as Component
import Axon.Ipc as Ipc
import Axon.Linkage as Linkage
import Axon.Microprocess as Microprocess
import Axon.Postoffice as Postoffice
import Axon.Scheduler as Scheduler
import Axon.debug as debug
import Axon.util as util
import Axon.AdaptiveCommsComponent as AdaptiveCommsComponent
import Axon.AxonExceptions as AxonExceptions
import Axon.CoordinatingAssistantTracker as CoordinatingAssistantTracker
import Axon.debugConfigFile as debugConfigFile
import Axon.Box as Box
import Axon.ThreadedComponent as ThreadedComponent
import Axon.Introspector as Introspector
from Axon.Base import AxonObject, AxonType
Microprocess.microprocess.setSchedulerClass(Scheduler.scheduler)
#Microprocess.microprocess.setTrackerClass(CoordinatingAssistantTracker.coordinatingassistanttracker)
Microprocess.microprocess.setTrackerClass(None)
CoordinatingAssistantTracker.coordinatingassistanttracker()
Scheduler.scheduler() # Initialise the class.
|
apache-2.0
|
[
3,
199,
3,
1898,
7129,
699,
322,
23184,
699,
5659,
316,
11098,
436,
1804,
14541,
18865,
65,
23212,
8,
17,
9,
199,
3,
199,
3,
334,
17,
9,
1804,
14541,
18865,
65,
23212,
787,
10532,
315,
314,
10610,
570,
436,
737,
199,
3,
258,
1455,
921,
1544,
14,
7351,
391,
18865,
65,
14,
1308,
15,
5580,
4149,
446,
8749,
12247,
642,
570,
12,
199,
3,
258,
440,
642,
4245,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
18852,
199,
19659,
199,
2486,
16964,
199,
28000,
265,
446,
314,
6170,
406,
4968,
2656,
367,
1804,
14541,
18865,
65,
199,
2486,
16964,
199,
199,
28000,
265,
365,
282,
3931,
406,
4968,
10059,
14,
8777,
652,
1265,
883,
1218,
2032,
199,
2,
4608,
2,
626,
883,
1255,
406,
19767,
543,
1924,
1163,
14,
17823,
1172,
199,
2,
262,
12922,
2,
436,
298,
548,
12922,
2,
4012,
543,
2985,
26808,
543,
1163,
7323,
14,
199,
199,
33,
3931,
1443,
3222,
282,
1245,
370,
1373,
402,
2399,
734,
12922,
14,
982,
282,
26087,
965,
2757,
199,
3966,
687,
626,
734,
1977,
370,
4573,
3931,
1159,
315,
1977,
27,
2066,
626,
1245,
911,
199,
285,
6053,
315,
314,
315,
1977,
402,
314,
1163,
3931,
14,
1010,
642,
4340,
12,
7323,
883,
3222,
199,
460,
9128,
666,
446,
17266,
1265,
370,
1218,
10460,
701,
25833,
5002,
7323,
199,
6314,
14,
199,
199,
22321,
3931,
365,
282,
9967,
1412,
446,
7830,
2839,
282,
2462,
402,
6451,
14,
437,
199,
8874,
6181,
10296,
402,
10663,
3238,
1006,
9967,
11816,
334,
460,
16119,
1006,
199,
4608,
9,
664,
5578,
590,
7934,
14,
2779,
2597,
10734,
2410,
32670,
9967,
11816,
199,
475,
9435,
334,
6526,
2985,
7198,
370,
506,
9,
436,
336,
11124,
3062,
1536,
334,
509,
2893,
12,
1380,
6020,
199,
285,
322,
2310,
315,
1373,
402,
3932,
315,
12922,
680,
4388,
199,
1563,
3992,
367,
10015,
2195,
5705,
7323,
199,
1444,
8684,
199,
199,
10,
1011,
28000,
265,
14,
7004,
538,
819,
446,
7890,
314,
5678,
3931,
14,
30184,
652,
370,
2218,
2195,
5705,
7323,
14,
199,
199,
10,
1011,
28000,
265,
14,
2767,
22430,
5150,
83,
7004,
538,
819,
446,
2839,
282,
5678,
3931,
1325,
543,
21625,
382,
1417,
370,
4691,
1265,
1050,
436,
2813,
315,
12922,
272,
436,
734,
12922,
5309,
8836,
14,
199,
199,
10,
1011,
28000,
265,
14,
31699,
7004,
538,
819,
446,
2839,
24801,
7323,
12,
1325,
1314,
5651,
21797,
1255,
315,
282,
7396,
2462,
446,
11150,
272,
2985,
883,
5147,
14592,
6527,
334,
8585,
2985,
2793,
1133,
1172,
370,
1995,
3304,
370,
272,
314,
11899,
367,
1163,
7323,
370,
1980,
14043,
9,
489,
421,
199,
26104,
406,
4968,
2656,
199,
777,
8684,
199,
199,
10,
1011,
28000,
265,
14,
23990,
1412,
538,
819,
446,
16147,
83,
282,
2366,
4306,
1901,
282,
10286,
348,
461,
9967,
1412,
446,
6020,
626,
272,
883,
506,
8239,
12,
691,
2972,
12,
295,
10084,
2858,
436,
15248,
14,
30184,
652,
370,
1852,
2195,
5705,
14,
199,
199,
10,
1011,
28000,
265,
14,
11251,
538,
819,
446,
23773,
314,
9967,
11816,
14,
21612,
314,
6617,
12,
23599,
12,
691,
4941,
272,
436,
336,
11124,
402,
3062,
14,
6596,
2597,
282,
9967,
1412,
6337,
1,
4388,
199,
15803,
12,
11076,
12,
14089,
14254,
199,
1444,
375,
1362,
199,
10,
1011,
28000,
265,
14,
13940,
1958,
24486,
13652,
538,
819,
446,
6571,
562,
10832,
706,
367,
7323,
370,
19613,
1044,
436,
20131,
8500,
2985,
272,
883,
5647,
367,
1924,
1163,
14,
819,
446,
17795,
465,
282,
7611,
367,
32223,
11076,
687,
7323,
315,
314,
2656,
199,
199,
10,
1011,
28000,
265,
14,
3241,
4796,
15152,
538,
819,
446,
4704,
12166,
14611,
666,
13660,
4052,
7323,
2337,
787,
315,
282,
272,
3879,
2185,
265,
2656,
436,
4212,
2985,
787,
10632,
10451,
14,
421,
268,
199,
16836,
12,
27377,
436,
603,
10840,
199,
777,
8684,
199,
199,
10,
1011,
28000,
265,
14,
1563,
538,
819,
446,
1300,
17074,
367,
790,
437,
88,
265,
3992,
199,
199,
10,
1011,
28000,
265,
14,
28000,
265,
16836,
538,
819,
446,
3992,
12669,
7750,
4967,
315,
437,
88,
265,
14,
2043,
199,
10,
1011,
28000,
265,
14,
41,
2352,
538,
819,
446,
3992,
12669,
7750,
3531,
35,
3788,
315,
437,
88,
265,
1202,
367,
2070,
26039,
12842,
12,
272,
2552,
12,
13116,
12,
5423,
1396,
199,
199,
10,
1011,
28000,
265,
14,
344,
8168,
538,
819,
446,
3747,
1305,
574,
10152,
199,
199,
10,
1011,
28000,
265,
14,
1974,
538,
819,
446,
7750,
3201,
19549,
2291,
11420,
3102,
4388,
199,
20405,
543,
1163,
10460,
199,
777,
10965,
199,
199,
10,
1011,
28000,
265,
14,
7451,
538,
819,
446,
675,
437,
88,
265,
7323,
4453,
1163,
2366,
18572,
701,
19696,
3062,
315,
272,
282,
11899,
3879,
315,
282,
7396,
2462,
2043,
199,
10,
1011,
28000,
265,
14,
5940,
538,
819,
446,
282,
8690,
367,
10232,
666,
1901,
436,
734,
402,
314,
4465,
315,
12922,
436,
734,
12922,
272,
402,
282,
3931,
687,
282,
2222,
437,
88,
265,
4079,
14854,
402,
1233,
14,
18491,
315,
14665,
272,
543,
437,
88,
265,
14,
7451,
4388,
199,
8405,
83,
367,
18234,
315,
12922,
12,
734,
12922,
436,
2142,
7441,
199,
6489,
9960,
199,
199,
10,
1011,
28000,
265,
14,
3532,
538,
819,
446,
710,
1300,
4514,
402,
315,
12922,
436,
734,
12922,
14,
199,
199,
10,
1011,
28000,
265,
14,
6564,
18812,
538,
819,
446,
2900,
7323,
1172,
1373,
402,
3520,
367,
6425,
12,
11972,
316,
436,
15161,
272
] |
[
199,
3,
1898,
7129,
699,
322,
23184,
699,
5659,
316,
11098,
436,
1804,
14541,
18865,
65,
23212,
8,
17,
9,
199,
3,
199,
3,
334,
17,
9,
1804,
14541,
18865,
65,
23212,
787,
10532,
315,
314,
10610,
570,
436,
737,
199,
3,
258,
1455,
921,
1544,
14,
7351,
391,
18865,
65,
14,
1308,
15,
5580,
4149,
446,
8749,
12247,
642,
570,
12,
199,
3,
258,
440,
642,
4245,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
18852,
199,
19659,
199,
2486,
16964,
199,
28000,
265,
446,
314,
6170,
406,
4968,
2656,
367,
1804,
14541,
18865,
65,
199,
2486,
16964,
199,
199,
28000,
265,
365,
282,
3931,
406,
4968,
10059,
14,
8777,
652,
1265,
883,
1218,
2032,
199,
2,
4608,
2,
626,
883,
1255,
406,
19767,
543,
1924,
1163,
14,
17823,
1172,
199,
2,
262,
12922,
2,
436,
298,
548,
12922,
2,
4012,
543,
2985,
26808,
543,
1163,
7323,
14,
199,
199,
33,
3931,
1443,
3222,
282,
1245,
370,
1373,
402,
2399,
734,
12922,
14,
982,
282,
26087,
965,
2757,
199,
3966,
687,
626,
734,
1977,
370,
4573,
3931,
1159,
315,
1977,
27,
2066,
626,
1245,
911,
199,
285,
6053,
315,
314,
315,
1977,
402,
314,
1163,
3931,
14,
1010,
642,
4340,
12,
7323,
883,
3222,
199,
460,
9128,
666,
446,
17266,
1265,
370,
1218,
10460,
701,
25833,
5002,
7323,
199,
6314,
14,
199,
199,
22321,
3931,
365,
282,
9967,
1412,
446,
7830,
2839,
282,
2462,
402,
6451,
14,
437,
199,
8874,
6181,
10296,
402,
10663,
3238,
1006,
9967,
11816,
334,
460,
16119,
1006,
199,
4608,
9,
664,
5578,
590,
7934,
14,
2779,
2597,
10734,
2410,
32670,
9967,
11816,
199,
475,
9435,
334,
6526,
2985,
7198,
370,
506,
9,
436,
336,
11124,
3062,
1536,
334,
509,
2893,
12,
1380,
6020,
199,
285,
322,
2310,
315,
1373,
402,
3932,
315,
12922,
680,
4388,
199,
1563,
3992,
367,
10015,
2195,
5705,
7323,
199,
1444,
8684,
199,
199,
10,
1011,
28000,
265,
14,
7004,
538,
819,
446,
7890,
314,
5678,
3931,
14,
30184,
652,
370,
2218,
2195,
5705,
7323,
14,
199,
199,
10,
1011,
28000,
265,
14,
2767,
22430,
5150,
83,
7004,
538,
819,
446,
2839,
282,
5678,
3931,
1325,
543,
21625,
382,
1417,
370,
4691,
1265,
1050,
436,
2813,
315,
12922,
272,
436,
734,
12922,
5309,
8836,
14,
199,
199,
10,
1011,
28000,
265,
14,
31699,
7004,
538,
819,
446,
2839,
24801,
7323,
12,
1325,
1314,
5651,
21797,
1255,
315,
282,
7396,
2462,
446,
11150,
272,
2985,
883,
5147,
14592,
6527,
334,
8585,
2985,
2793,
1133,
1172,
370,
1995,
3304,
370,
272,
314,
11899,
367,
1163,
7323,
370,
1980,
14043,
9,
489,
421,
199,
26104,
406,
4968,
2656,
199,
777,
8684,
199,
199,
10,
1011,
28000,
265,
14,
23990,
1412,
538,
819,
446,
16147,
83,
282,
2366,
4306,
1901,
282,
10286,
348,
461,
9967,
1412,
446,
6020,
626,
272,
883,
506,
8239,
12,
691,
2972,
12,
295,
10084,
2858,
436,
15248,
14,
30184,
652,
370,
1852,
2195,
5705,
14,
199,
199,
10,
1011,
28000,
265,
14,
11251,
538,
819,
446,
23773,
314,
9967,
11816,
14,
21612,
314,
6617,
12,
23599,
12,
691,
4941,
272,
436,
336,
11124,
402,
3062,
14,
6596,
2597,
282,
9967,
1412,
6337,
1,
4388,
199,
15803,
12,
11076,
12,
14089,
14254,
199,
1444,
375,
1362,
199,
10,
1011,
28000,
265,
14,
13940,
1958,
24486,
13652,
538,
819,
446,
6571,
562,
10832,
706,
367,
7323,
370,
19613,
1044,
436,
20131,
8500,
2985,
272,
883,
5647,
367,
1924,
1163,
14,
819,
446,
17795,
465,
282,
7611,
367,
32223,
11076,
687,
7323,
315,
314,
2656,
199,
199,
10,
1011,
28000,
265,
14,
3241,
4796,
15152,
538,
819,
446,
4704,
12166,
14611,
666,
13660,
4052,
7323,
2337,
787,
315,
282,
272,
3879,
2185,
265,
2656,
436,
4212,
2985,
787,
10632,
10451,
14,
421,
268,
199,
16836,
12,
27377,
436,
603,
10840,
199,
777,
8684,
199,
199,
10,
1011,
28000,
265,
14,
1563,
538,
819,
446,
1300,
17074,
367,
790,
437,
88,
265,
3992,
199,
199,
10,
1011,
28000,
265,
14,
28000,
265,
16836,
538,
819,
446,
3992,
12669,
7750,
4967,
315,
437,
88,
265,
14,
2043,
199,
10,
1011,
28000,
265,
14,
41,
2352,
538,
819,
446,
3992,
12669,
7750,
3531,
35,
3788,
315,
437,
88,
265,
1202,
367,
2070,
26039,
12842,
12,
272,
2552,
12,
13116,
12,
5423,
1396,
199,
199,
10,
1011,
28000,
265,
14,
344,
8168,
538,
819,
446,
3747,
1305,
574,
10152,
199,
199,
10,
1011,
28000,
265,
14,
1974,
538,
819,
446,
7750,
3201,
19549,
2291,
11420,
3102,
4388,
199,
20405,
543,
1163,
10460,
199,
777,
10965,
199,
199,
10,
1011,
28000,
265,
14,
7451,
538,
819,
446,
675,
437,
88,
265,
7323,
4453,
1163,
2366,
18572,
701,
19696,
3062,
315,
272,
282,
11899,
3879,
315,
282,
7396,
2462,
2043,
199,
10,
1011,
28000,
265,
14,
5940,
538,
819,
446,
282,
8690,
367,
10232,
666,
1901,
436,
734,
402,
314,
4465,
315,
12922,
436,
734,
12922,
272,
402,
282,
3931,
687,
282,
2222,
437,
88,
265,
4079,
14854,
402,
1233,
14,
18491,
315,
14665,
272,
543,
437,
88,
265,
14,
7451,
4388,
199,
8405,
83,
367,
18234,
315,
12922,
12,
734,
12922,
436,
2142,
7441,
199,
6489,
9960,
199,
199,
10,
1011,
28000,
265,
14,
3532,
538,
819,
446,
710,
1300,
4514,
402,
315,
12922,
436,
734,
12922,
14,
199,
199,
10,
1011,
28000,
265,
14,
6564,
18812,
538,
819,
446,
2900,
7323,
1172,
1373,
402,
3520,
367,
6425,
12,
11972,
316,
436,
15161,
272,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
ZenDevelopmentSystems/scikit-learn
|
sklearn/cluster/mean_shift_.py
|
96
|
15434
|
"""Mean shift clustering algorithm.
Mean shift clustering aims to discover *blobs* in a smooth density of
samples. It is a centroid based algorithm, which works by updating candidates
for centroids to be the mean of the points within a given region. These
candidates are then filtered in a post-processing stage to eliminate
near-duplicates to form the final set of centroids.
Seeding is performed using a binning technique for scalability.
"""
# Authors: Conrad Lee <conradlee@gmail.com>
# Alexandre Gramfort <alexandre.gramfort@inria.fr>
# Gael Varoquaux <gael.varoquaux@normalesup.org>
# Martino Sorbaro <martino.sorbaro@ed.ac.uk>
import numpy as np
import warnings
from collections import defaultdict
from ..externals import six
from ..utils.validation import check_is_fitted
from ..utils import extmath, check_random_state, gen_batches, check_array
from ..base import BaseEstimator, ClusterMixin
from ..neighbors import NearestNeighbors
from ..metrics.pairwise import pairwise_distances_argmin
from ..externals.joblib import Parallel
from ..externals.joblib import delayed
def estimate_bandwidth(X, quantile=0.3, n_samples=None, random_state=0):
"""Estimate the bandwidth to use with the mean-shift algorithm.
That this function takes time at least quadratic in n_samples. For large
datasets, it's wise to set that parameter to a small value.
Parameters
----------
X : array-like, shape=[n_samples, n_features]
Input points.
quantile : float, default 0.3
should be between [0, 1]
0.5 means that the median of all pairwise distances is used.
n_samples : int, optional
The number of samples to use. If not given, all samples are used.
random_state : int or RandomState
Pseudo-random number generator state used for random sampling.
Returns
-------
bandwidth : float
The bandwidth parameter.
"""
random_state = check_random_state(random_state)
if n_samples is not None:
idx = random_state.permutation(X.shape[0])[:n_samples]
X = X[idx]
nbrs = NearestNeighbors(n_neighbors=int(X.shape[0] * quantile))
nbrs.fit(X)
bandwidth = 0.
for batch in gen_batches(len(X), 500):
d, _ = nbrs.kneighbors(X[batch, :], return_distance=True)
bandwidth += np.max(d, axis=1).sum()
return bandwidth / X.shape[0]
# separate function for each seed's iterative loop
def _mean_shift_single_seed(my_mean, X, nbrs, max_iter):
# For each seed, climb gradient until convergence or max_iter
bandwidth = nbrs.get_params()['radius']
stop_thresh = 1e-3 * bandwidth # when mean has converged
completed_iterations = 0
while True:
# Find mean of points within bandwidth
i_nbrs = nbrs.radius_neighbors([my_mean], bandwidth,
return_distance=False)[0]
points_within = X[i_nbrs]
if len(points_within) == 0:
break # Depending on seeding strategy this condition may occur
my_old_mean = my_mean # save the old mean
my_mean = np.mean(points_within, axis=0)
# If converged or at max_iter, adds the cluster
if (extmath.norm(my_mean - my_old_mean) < stop_thresh or
completed_iterations == max_iter):
return tuple(my_mean), len(points_within)
completed_iterations += 1
def mean_shift(X, bandwidth=None, seeds=None, bin_seeding=False,
min_bin_freq=1, cluster_all=True, max_iter=300,
max_iterations=None, n_jobs=1):
"""Perform mean shift clustering of data using a flat kernel.
Read more in the :ref:`User Guide <mean_shift>`.
Parameters
----------
X : array-like, shape=[n_samples, n_features]
Input data.
bandwidth : float, optional
Kernel bandwidth.
If bandwidth is not given, it is determined using a heuristic based on
the median of all pairwise distances. This will take quadratic time in
the number of samples. The sklearn.cluster.estimate_bandwidth function
can be used to do this more efficiently.
seeds : array-like, shape=[n_seeds, n_features] or None
Point used as initial kernel locations. If None and bin_seeding=False,
each data point is used as a seed. If None and bin_seeding=True,
see bin_seeding.
bin_seeding : boolean, default=False
If true, initial kernel locations are not locations of all
points, but rather the location of the discretized version of
points, where points are binned onto a grid whose coarseness
corresponds to the bandwidth. Setting this option to True will speed
up the algorithm because fewer seeds will be initialized.
Ignored if seeds argument is not None.
min_bin_freq : int, default=1
To speed up the algorithm, accept only those bins with at least
min_bin_freq points as seeds.
cluster_all : boolean, default True
If true, then all points are clustered, even those orphans that are
not within any kernel. Orphans are assigned to the nearest kernel.
If false, then orphans are given cluster label -1.
max_iter : int, default 300
Maximum number of iterations, per seed point before the clustering
operation terminates (for that seed point), if has not converged yet.
n_jobs : int
The number of jobs to use for the computation. This works by computing
each of the n_init runs in parallel.
If -1 all CPUs are used. If 1 is given, no parallel computing code is
used at all, which is useful for debugging. For n_jobs below -1,
(n_cpus + 1 + n_jobs) are used. Thus for n_jobs = -2, all CPUs but one
are used.
Returns
-------
cluster_centers : array, shape=[n_clusters, n_features]
Coordinates of cluster centers.
labels : array, shape=[n_samples]
Cluster labels for each point.
Notes
-----
See examples/cluster/plot_meanshift.py for an example.
"""
# FIXME To be removed in 0.18
if max_iterations is not None:
warnings.warn("The `max_iterations` parameter has been renamed to "
"`max_iter` from version 0.16. The `max_iterations` "
"parameter will be removed in 0.18", DeprecationWarning)
max_iter = max_iterations
if bandwidth is None:
bandwidth = estimate_bandwidth(X)
elif bandwidth <= 0:
raise ValueError("bandwidth needs to be greater than zero or None,\
got %f" % bandwidth)
if seeds is None:
if bin_seeding:
seeds = get_bin_seeds(X, bandwidth, min_bin_freq)
else:
seeds = X
n_samples, n_features = X.shape
center_intensity_dict = {}
nbrs = NearestNeighbors(radius=bandwidth).fit(X)
# execute iterations on all seeds in parallel
all_res = Parallel(n_jobs=n_jobs)(
delayed(_mean_shift_single_seed)
(seed, X, nbrs, max_iter) for seed in seeds)
# copy results in a dictionary
for i in range(len(seeds)):
if all_res[i] is not None:
center_intensity_dict[all_res[i][0]] = all_res[i][1]
if not center_intensity_dict:
# nothing near seeds
raise ValueError("No point was within bandwidth=%f of any seed."
" Try a different seeding strategy \
or increase the bandwidth."
% bandwidth)
# POST PROCESSING: remove near duplicate points
# If the distance between two kernels is less than the bandwidth,
# then we have to remove one because it is a duplicate. Remove the
# one with fewer points.
sorted_by_intensity = sorted(center_intensity_dict.items(),
key=lambda tup: tup[1], reverse=True)
sorted_centers = np.array([tup[0] for tup in sorted_by_intensity])
unique = np.ones(len(sorted_centers), dtype=np.bool)
nbrs = NearestNeighbors(radius=bandwidth).fit(sorted_centers)
for i, center in enumerate(sorted_centers):
if unique[i]:
neighbor_idxs = nbrs.radius_neighbors([center],
return_distance=False)[0]
unique[neighbor_idxs] = 0
unique[i] = 1 # leave the current point as unique
cluster_centers = sorted_centers[unique]
# ASSIGN LABELS: a point belongs to the cluster that it is closest to
nbrs = NearestNeighbors(n_neighbors=1).fit(cluster_centers)
labels = np.zeros(n_samples, dtype=np.int)
distances, idxs = nbrs.kneighbors(X)
if cluster_all:
labels = idxs.flatten()
else:
labels.fill(-1)
bool_selector = distances.flatten() <= bandwidth
labels[bool_selector] = idxs.flatten()[bool_selector]
return cluster_centers, labels
def get_bin_seeds(X, bin_size, min_bin_freq=1):
"""Finds seeds for mean_shift.
Finds seeds by first binning data onto a grid whose lines are
spaced bin_size apart, and then choosing those bins with at least
min_bin_freq points.
Parameters
----------
X : array-like, shape=[n_samples, n_features]
Input points, the same points that will be used in mean_shift.
bin_size : float
Controls the coarseness of the binning. Smaller values lead
to more seeding (which is computationally more expensive). If you're
not sure how to set this, set it to the value of the bandwidth used
in clustering.mean_shift.
min_bin_freq : integer, optional
Only bins with at least min_bin_freq will be selected as seeds.
Raising this value decreases the number of seeds found, which
makes mean_shift computationally cheaper.
Returns
-------
bin_seeds : array-like, shape=[n_samples, n_features]
Points used as initial kernel positions in clustering.mean_shift.
"""
# Bin points
bin_sizes = defaultdict(int)
for point in X:
binned_point = np.round(point / bin_size)
bin_sizes[tuple(binned_point)] += 1
# Select only those bins as seeds which have enough members
bin_seeds = np.array([point for point, freq in six.iteritems(bin_sizes) if
freq >= min_bin_freq], dtype=np.float32)
if len(bin_seeds) == len(X):
warnings.warn("Binning data failed with provided bin_size=%f,"
" using data points as seeds." % bin_size)
return X
bin_seeds = bin_seeds * bin_size
return bin_seeds
class MeanShift(BaseEstimator, ClusterMixin):
"""Mean shift clustering using a flat kernel.
Mean shift clustering aims to discover "blobs" in a smooth density of
samples. It is a centroid-based algorithm, which works by updating
candidates for centroids to be the mean of the points within a given
region. These candidates are then filtered in a post-processing stage to
eliminate near-duplicates to form the final set of centroids.
Seeding is performed using a binning technique for scalability.
Read more in the :ref:`User Guide <mean_shift>`.
Parameters
----------
bandwidth : float, optional
Bandwidth used in the RBF kernel.
If not given, the bandwidth is estimated using
sklearn.cluster.estimate_bandwidth; see the documentation for that
function for hints on scalability (see also the Notes, below).
seeds : array, shape=[n_samples, n_features], optional
Seeds used to initialize kernels. If not set,
the seeds are calculated by clustering.get_bin_seeds
with bandwidth as the grid size and default values for
other parameters.
bin_seeding : boolean, optional
If true, initial kernel locations are not locations of all
points, but rather the location of the discretized version of
points, where points are binned onto a grid whose coarseness
corresponds to the bandwidth. Setting this option to True will speed
up the algorithm because fewer seeds will be initialized.
default value: False
Ignored if seeds argument is not None.
min_bin_freq : int, optional
To speed up the algorithm, accept only those bins with at least
min_bin_freq points as seeds. If not defined, set to 1.
cluster_all : boolean, default True
If true, then all points are clustered, even those orphans that are
not within any kernel. Orphans are assigned to the nearest kernel.
If false, then orphans are given cluster label -1.
n_jobs : int
The number of jobs to use for the computation. This works by computing
each of the n_init runs in parallel.
If -1 all CPUs are used. If 1 is given, no parallel computing code is
used at all, which is useful for debugging. For n_jobs below -1,
(n_cpus + 1 + n_jobs) are used. Thus for n_jobs = -2, all CPUs but one
are used.
Attributes
----------
cluster_centers_ : array, [n_clusters, n_features]
Coordinates of cluster centers.
labels_ :
Labels of each point.
Notes
-----
Scalability:
Because this implementation uses a flat kernel and
a Ball Tree to look up members of each kernel, the complexity will is
to O(T*n*log(n)) in lower dimensions, with n the number of samples
and T the number of points. In higher dimensions the complexity will
tend towards O(T*n^2).
Scalability can be boosted by using fewer seeds, for example by using
a higher value of min_bin_freq in the get_bin_seeds function.
Note that the estimate_bandwidth function is much less scalable than the
mean shift algorithm and will be the bottleneck if it is used.
References
----------
Dorin Comaniciu and Peter Meer, "Mean Shift: A robust approach toward
feature space analysis". IEEE Transactions on Pattern Analysis and
Machine Intelligence. 2002. pp. 603-619.
"""
def __init__(self, bandwidth=None, seeds=None, bin_seeding=False,
min_bin_freq=1, cluster_all=True, n_jobs=1):
self.bandwidth = bandwidth
self.seeds = seeds
self.bin_seeding = bin_seeding
self.cluster_all = cluster_all
self.min_bin_freq = min_bin_freq
self.n_jobs = n_jobs
def fit(self, X, y=None):
"""Perform clustering.
Parameters
-----------
X : array-like, shape=[n_samples, n_features]
Samples to cluster.
"""
X = check_array(X)
self.cluster_centers_, self.labels_ = \
mean_shift(X, bandwidth=self.bandwidth, seeds=self.seeds,
min_bin_freq=self.min_bin_freq,
bin_seeding=self.bin_seeding,
cluster_all=self.cluster_all, n_jobs=self.n_jobs)
return self
def predict(self, X):
"""Predict the closest cluster each sample in X belongs to.
Parameters
----------
X : {array-like, sparse matrix}, shape=[n_samples, n_features]
New data to predict.
Returns
-------
labels : array, shape [n_samples,]
Index of the cluster each sample belongs to.
"""
check_is_fitted(self, "cluster_centers_")
return pairwise_distances_argmin(X, self.cluster_centers_)
|
bsd-3-clause
|
[
624,
14825,
7706,
19454,
5563,
14,
199,
199,
14825,
7706,
19454,
282,
11171,
370,
20131,
627,
21893,
10,
315,
282,
19608,
13650,
402,
199,
3356,
14,
2779,
365,
282,
27587,
4079,
5563,
12,
1314,
5419,
701,
12928,
15101,
199,
509,
13345,
26188,
370,
506,
314,
4615,
402,
314,
4501,
4453,
282,
1627,
4897,
14,
5723,
199,
16389,
787,
2066,
9806,
315,
282,
2963,
13,
6338,
9546,
370,
20714,
323,
199,
21078,
13,
18563,
370,
1824,
314,
4242,
663,
402,
13345,
26188,
14,
199,
199,
19554,
316,
365,
10585,
1808,
282,
2517,
1835,
32414,
367,
5269,
3616,
14,
199,
624,
199,
199,
3,
6642,
26,
1448,
9525,
491,
1024,
665,
388,
345,
3011,
69,
32,
6799,
14,
957,
30,
199,
3,
3515,
22986,
28547,
27211,
10279,
665,
24421,
28547,
14,
1679,
10279,
32,
262,
23714,
14,
4391,
30,
199,
3,
3515,
9647,
352,
21084,
79,
392,
10962,
665,
5294,
352,
14,
1391,
79,
392,
10962,
32,
6505,
17667,
1961,
14,
1308,
30,
199,
3,
3515,
603,
580,
10175,
428,
269,
1700,
79,
665,
77,
580,
10175,
14,
1509,
1700,
79,
32,
379,
14,
645,
14,
3210,
30,
199,
199,
646,
2680,
465,
980,
199,
646,
3598,
199,
199,
504,
5055,
492,
10018,
199,
504,
2508,
24688,
492,
3816,
199,
504,
2508,
1208,
14,
6136,
492,
1104,
63,
374,
63,
21903,
199,
504,
2508,
1208,
492,
1599,
3442,
12,
1104,
63,
2355,
63,
929,
12,
3805,
63,
14896,
12,
1104,
63,
1144,
199,
504,
2508,
1095,
492,
3523,
13183,
12,
16454,
4256,
199,
504,
2508,
11113,
492,
5612,
9540,
20011,
199,
504,
2508,
6759,
14,
25069,
492,
24859,
63,
15482,
63,
26488,
199,
504,
2508,
24688,
14,
2423,
773,
492,
27311,
199,
504,
2508,
24688,
14,
2423,
773,
492,
24725,
421,
199,
318,
14497,
63,
18358,
8,
56,
12,
31975,
29,
16,
14,
19,
12,
302,
63,
3356,
29,
403,
12,
2196,
63,
929,
29,
16,
304,
272,
408,
31020,
314,
20434,
370,
675,
543,
314,
4615,
13,
4723,
5563,
14,
339,
10314,
642,
805,
6181,
900,
737,
5210,
16744,
19826,
315,
302,
63,
3356,
14,
2104,
7031,
272,
13148,
12,
652,
1159,
336,
572,
370,
663,
626,
2725,
370,
282,
7425,
574,
14,
339,
3897,
272,
4143,
272,
1323,
520,
1625,
13,
2930,
12,
2215,
1524,
78,
63,
3356,
12,
302,
63,
3179,
61,
267,
6924,
4501,
14,
339,
31975,
520,
2069,
12,
849,
378,
14,
19,
267,
1077,
506,
3382,
359,
16,
12,
413,
61,
267,
378,
14,
21,
4910,
626,
314,
17312,
402,
1006,
24859,
15108,
365,
1202,
14,
339,
302,
63,
3356,
520,
1109,
12,
2716,
267,
710,
1329,
402,
5845,
370,
675,
14,
982,
440,
1627,
12,
1006,
5845,
787,
1202,
14,
339,
2196,
63,
929,
520,
1109,
503,
22233,
267,
510,
9917,
13,
2355,
1329,
4306,
1174,
1202,
367,
2196,
15877,
14,
339,
1803,
272,
5514,
272,
20434,
520,
2069,
267,
710,
20434,
2725,
14,
272,
408,
272,
2196,
63,
929,
275,
1104,
63,
2355,
63,
929,
8,
2355,
63,
929,
9,
272,
340,
302,
63,
3356,
365,
440,
488,
26,
267,
4280,
275,
2196,
63,
929,
14,
23832,
8,
56,
14,
1392,
59,
16,
566,
1491,
78,
63,
3356,
61,
267,
1323,
275,
1323,
59,
2996,
61,
272,
8526,
2393,
275,
5612,
9540,
20011,
8,
78,
63,
11113,
29,
442,
8,
56,
14,
1392,
59,
16,
61,
627,
31975,
430,
272,
8526,
2393,
14,
3269,
8,
56,
9,
339,
20434,
275,
378,
14,
272,
367,
3522,
315,
3805,
63,
14896,
8,
552,
8,
56,
395,
6891,
304,
267,
366,
12,
485,
275,
8526,
2393,
14,
75,
11113,
8,
56,
59,
2912,
12,
26450,
372,
63,
5590,
29,
549,
9,
267,
20434,
847,
980,
14,
988,
8,
68,
12,
3114,
29,
17,
680,
1838,
342,
339,
372,
20434,
1182,
1323,
14,
1392,
59,
16,
61,
421,
199,
3,
7396,
805,
367,
1924,
6347,
1159,
4826,
857,
4438,
199,
318,
485,
3670,
63,
4723,
63,
4780,
63,
5176,
8,
1662,
63,
3670,
12,
1323,
12,
8526,
2393,
12,
1390,
63,
1661,
304,
272,
327,
2104,
1924,
6347,
12,
5053,
887,
6709,
5133,
21346,
503,
1390,
63,
1661,
272,
20434,
275,
8526,
2393,
14,
362,
63,
1162,
12047,
8017,
418,
272,
3631,
63,
14898,
275,
413,
69,
13,
19,
627,
20434,
221,
327,
1380,
4615,
965,
3818,
3046,
272,
9709,
63,
13570,
275,
378,
272,
1830,
715,
26,
267,
327,
6668,
4615,
402,
4501,
4453,
20434,
267,
284,
63,
32330,
275,
8526,
2393,
14,
8017,
63,
11113,
779,
1662,
63,
3670,
467,
20434,
12,
4318,
372,
63,
5590,
29,
797,
2788,
16,
61,
267,
4501,
63,
12541,
275,
1323,
59,
73,
63,
32330,
61,
267,
340,
822,
8,
3438,
63,
12541,
9,
508,
378,
26,
288,
2059,
221,
327,
1487,
6455,
641,
6347,
316,
10054,
642,
5558,
1443,
4781,
267,
3002,
63,
1753,
63,
3670,
275,
3002,
63,
3670,
221,
327,
3354,
314,
2269,
4615,
267,
3002,
63,
3670,
275,
980,
14,
3670,
8,
3438,
63,
12541,
12,
3114,
29,
16,
9,
267,
327,
982,
3818,
3046,
503,
737,
1390,
63,
1661,
12,
9584,
314,
4350,
267,
340,
334,
832,
3442,
14,
4791,
8,
1662,
63,
3670,
446,
3002,
63,
1753,
63,
3670,
9,
665,
3631,
63,
14898,
503,
355,
9709,
63,
13570,
508,
1390,
63,
1661,
304,
288,
372,
2008,
8,
1662,
63,
3670,
395,
822,
8,
3438,
63,
12541,
9,
267,
9709,
63,
13570,
847,
413,
421,
199,
318,
4615,
63,
4723,
8,
56,
12,
20434,
29,
403,
12,
26825,
29,
403,
12,
2517,
63,
5176,
316,
29,
797,
12,
2049,
1748,
63,
1393,
63,
5646,
29,
17,
12,
4350,
63,
452,
29,
549,
12,
1390,
63,
1661,
29,
5863,
12,
2049,
1390,
63,
13570,
29,
403,
12,
302,
63,
6920,
29,
17,
304,
272,
408,
20906,
4615,
7706,
19454,
402,
666,
1808,
282,
6829,
5114,
14,
339,
5574,
1655,
315,
314,
520,
1121,
1705,
1899,
15423,
665,
3670,
63,
4723,
14943,
339,
3897,
272,
4143,
339,
1323,
520,
1625,
13,
2930,
12,
2215,
1524,
78,
63,
3356,
12,
302,
63,
3179,
61,
267,
6924,
666,
14,
339,
20434,
520,
2069,
12,
2716,
267,
24901,
20434,
14,
398,
982,
20434,
365,
440,
1627,
12,
652,
365,
12037,
1808,
282,
25332
] |
[
14825,
7706,
19454,
5563,
14,
199,
199,
14825,
7706,
19454,
282,
11171,
370,
20131,
627,
21893,
10,
315,
282,
19608,
13650,
402,
199,
3356,
14,
2779,
365,
282,
27587,
4079,
5563,
12,
1314,
5419,
701,
12928,
15101,
199,
509,
13345,
26188,
370,
506,
314,
4615,
402,
314,
4501,
4453,
282,
1627,
4897,
14,
5723,
199,
16389,
787,
2066,
9806,
315,
282,
2963,
13,
6338,
9546,
370,
20714,
323,
199,
21078,
13,
18563,
370,
1824,
314,
4242,
663,
402,
13345,
26188,
14,
199,
199,
19554,
316,
365,
10585,
1808,
282,
2517,
1835,
32414,
367,
5269,
3616,
14,
199,
624,
199,
199,
3,
6642,
26,
1448,
9525,
491,
1024,
665,
388,
345,
3011,
69,
32,
6799,
14,
957,
30,
199,
3,
3515,
22986,
28547,
27211,
10279,
665,
24421,
28547,
14,
1679,
10279,
32,
262,
23714,
14,
4391,
30,
199,
3,
3515,
9647,
352,
21084,
79,
392,
10962,
665,
5294,
352,
14,
1391,
79,
392,
10962,
32,
6505,
17667,
1961,
14,
1308,
30,
199,
3,
3515,
603,
580,
10175,
428,
269,
1700,
79,
665,
77,
580,
10175,
14,
1509,
1700,
79,
32,
379,
14,
645,
14,
3210,
30,
199,
199,
646,
2680,
465,
980,
199,
646,
3598,
199,
199,
504,
5055,
492,
10018,
199,
504,
2508,
24688,
492,
3816,
199,
504,
2508,
1208,
14,
6136,
492,
1104,
63,
374,
63,
21903,
199,
504,
2508,
1208,
492,
1599,
3442,
12,
1104,
63,
2355,
63,
929,
12,
3805,
63,
14896,
12,
1104,
63,
1144,
199,
504,
2508,
1095,
492,
3523,
13183,
12,
16454,
4256,
199,
504,
2508,
11113,
492,
5612,
9540,
20011,
199,
504,
2508,
6759,
14,
25069,
492,
24859,
63,
15482,
63,
26488,
199,
504,
2508,
24688,
14,
2423,
773,
492,
27311,
199,
504,
2508,
24688,
14,
2423,
773,
492,
24725,
421,
199,
318,
14497,
63,
18358,
8,
56,
12,
31975,
29,
16,
14,
19,
12,
302,
63,
3356,
29,
403,
12,
2196,
63,
929,
29,
16,
304,
272,
408,
31020,
314,
20434,
370,
675,
543,
314,
4615,
13,
4723,
5563,
14,
339,
10314,
642,
805,
6181,
900,
737,
5210,
16744,
19826,
315,
302,
63,
3356,
14,
2104,
7031,
272,
13148,
12,
652,
1159,
336,
572,
370,
663,
626,
2725,
370,
282,
7425,
574,
14,
339,
3897,
272,
4143,
272,
1323,
520,
1625,
13,
2930,
12,
2215,
1524,
78,
63,
3356,
12,
302,
63,
3179,
61,
267,
6924,
4501,
14,
339,
31975,
520,
2069,
12,
849,
378,
14,
19,
267,
1077,
506,
3382,
359,
16,
12,
413,
61,
267,
378,
14,
21,
4910,
626,
314,
17312,
402,
1006,
24859,
15108,
365,
1202,
14,
339,
302,
63,
3356,
520,
1109,
12,
2716,
267,
710,
1329,
402,
5845,
370,
675,
14,
982,
440,
1627,
12,
1006,
5845,
787,
1202,
14,
339,
2196,
63,
929,
520,
1109,
503,
22233,
267,
510,
9917,
13,
2355,
1329,
4306,
1174,
1202,
367,
2196,
15877,
14,
339,
1803,
272,
5514,
272,
20434,
520,
2069,
267,
710,
20434,
2725,
14,
272,
408,
272,
2196,
63,
929,
275,
1104,
63,
2355,
63,
929,
8,
2355,
63,
929,
9,
272,
340,
302,
63,
3356,
365,
440,
488,
26,
267,
4280,
275,
2196,
63,
929,
14,
23832,
8,
56,
14,
1392,
59,
16,
566,
1491,
78,
63,
3356,
61,
267,
1323,
275,
1323,
59,
2996,
61,
272,
8526,
2393,
275,
5612,
9540,
20011,
8,
78,
63,
11113,
29,
442,
8,
56,
14,
1392,
59,
16,
61,
627,
31975,
430,
272,
8526,
2393,
14,
3269,
8,
56,
9,
339,
20434,
275,
378,
14,
272,
367,
3522,
315,
3805,
63,
14896,
8,
552,
8,
56,
395,
6891,
304,
267,
366,
12,
485,
275,
8526,
2393,
14,
75,
11113,
8,
56,
59,
2912,
12,
26450,
372,
63,
5590,
29,
549,
9,
267,
20434,
847,
980,
14,
988,
8,
68,
12,
3114,
29,
17,
680,
1838,
342,
339,
372,
20434,
1182,
1323,
14,
1392,
59,
16,
61,
421,
199,
3,
7396,
805,
367,
1924,
6347,
1159,
4826,
857,
4438,
199,
318,
485,
3670,
63,
4723,
63,
4780,
63,
5176,
8,
1662,
63,
3670,
12,
1323,
12,
8526,
2393,
12,
1390,
63,
1661,
304,
272,
327,
2104,
1924,
6347,
12,
5053,
887,
6709,
5133,
21346,
503,
1390,
63,
1661,
272,
20434,
275,
8526,
2393,
14,
362,
63,
1162,
12047,
8017,
418,
272,
3631,
63,
14898,
275,
413,
69,
13,
19,
627,
20434,
221,
327,
1380,
4615,
965,
3818,
3046,
272,
9709,
63,
13570,
275,
378,
272,
1830,
715,
26,
267,
327,
6668,
4615,
402,
4501,
4453,
20434,
267,
284,
63,
32330,
275,
8526,
2393,
14,
8017,
63,
11113,
779,
1662,
63,
3670,
467,
20434,
12,
4318,
372,
63,
5590,
29,
797,
2788,
16,
61,
267,
4501,
63,
12541,
275,
1323,
59,
73,
63,
32330,
61,
267,
340,
822,
8,
3438,
63,
12541,
9,
508,
378,
26,
288,
2059,
221,
327,
1487,
6455,
641,
6347,
316,
10054,
642,
5558,
1443,
4781,
267,
3002,
63,
1753,
63,
3670,
275,
3002,
63,
3670,
221,
327,
3354,
314,
2269,
4615,
267,
3002,
63,
3670,
275,
980,
14,
3670,
8,
3438,
63,
12541,
12,
3114,
29,
16,
9,
267,
327,
982,
3818,
3046,
503,
737,
1390,
63,
1661,
12,
9584,
314,
4350,
267,
340,
334,
832,
3442,
14,
4791,
8,
1662,
63,
3670,
446,
3002,
63,
1753,
63,
3670,
9,
665,
3631,
63,
14898,
503,
355,
9709,
63,
13570,
508,
1390,
63,
1661,
304,
288,
372,
2008,
8,
1662,
63,
3670,
395,
822,
8,
3438,
63,
12541,
9,
267,
9709,
63,
13570,
847,
413,
421,
199,
318,
4615,
63,
4723,
8,
56,
12,
20434,
29,
403,
12,
26825,
29,
403,
12,
2517,
63,
5176,
316,
29,
797,
12,
2049,
1748,
63,
1393,
63,
5646,
29,
17,
12,
4350,
63,
452,
29,
549,
12,
1390,
63,
1661,
29,
5863,
12,
2049,
1390,
63,
13570,
29,
403,
12,
302,
63,
6920,
29,
17,
304,
272,
408,
20906,
4615,
7706,
19454,
402,
666,
1808,
282,
6829,
5114,
14,
339,
5574,
1655,
315,
314,
520,
1121,
1705,
1899,
15423,
665,
3670,
63,
4723,
14943,
339,
3897,
272,
4143,
339,
1323,
520,
1625,
13,
2930,
12,
2215,
1524,
78,
63,
3356,
12,
302,
63,
3179,
61,
267,
6924,
666,
14,
339,
20434,
520,
2069,
12,
2716,
267,
24901,
20434,
14,
398,
982,
20434,
365,
440,
1627,
12,
652,
365,
12037,
1808,
282,
25332,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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
573
|
1764
|
# Copyright (C) 2001-2006 Python Software Foundation
# Author: Barry Warsaw
# Contact: email-sig@python.org
"""Class representing image/* type MIME documents."""
__all__ = ['MIMEImage']
import imghdr
from email import encoders
from email.mime.nonmultipart import MIMENonMultipart
class MIMEImage(MIMENonMultipart):
"""Class for generating image/* type MIME documents."""
def __init__(self, _imagedata, _subtype=None,
_encoder=encoders.encode_base64, **_params):
"""Create an image/* type MIME document.
_imagedata is a string containing the raw image data. If this data
can be decoded by the standard Python `imghdr' module, then the
subtype will be automatically included in the Content-Type header.
Otherwise, you can specify the specific image subtype via the _subtype
parameter.
_encoder is a function which will perform the actual encoding for
transport of the image data. It takes one argument, which is this
Image instance. It should use get_payload() and set_payload() to
change the payload to the encoded form. It should also add any
Content-Transfer-Encoding or other headers to the message as
necessary. The default encoding is Base64.
Any additional keyword arguments are passed to the base class
constructor, which turns them into parameters on the Content-Type
header.
"""
if _subtype is None:
_subtype = imghdr.what(None, _imagedata)
if _subtype is None:
raise TypeError('Could not guess image MIME subtype')
MIMENonMultipart.__init__(self, 'image', _subtype, **_params)
self.set_payload(_imagedata)
_encoder(self)
|
bsd-3-clause
|
[
3,
1898,
334,
35,
9,
12521,
13,
7968,
2018,
2290,
2752,
199,
3,
6529,
26,
12377,
651,
644,
285,
2231,
87,
199,
3,
18684,
26,
3031,
13,
4093,
32,
1548,
14,
1308,
199,
199,
624,
2543,
6144,
1834,
6331,
730,
14735,
8247,
1041,
199,
199,
363,
452,
363,
275,
788,
17057,
3491,
418,
199,
199,
646,
3416,
3561,
5012,
199,
199,
504,
3031,
492,
10295,
83,
199,
504,
3031,
14,
7626,
14,
2865,
10123,
492,
603,
1469,
742,
265,
27242,
4388,
201,
199,
533,
14735,
3491,
8,
45,
1469,
742,
265,
27242,
304,
272,
408,
2543,
367,
12999,
1834,
6331,
730,
14735,
8247,
1041,
339,
347,
636,
826,
721,
277,
12,
485,
1569,
576,
12,
485,
10512,
29,
403,
12,
326,
485,
9347,
29,
9347,
83,
14,
2143,
63,
1095,
772,
12,
29666,
1162,
304,
267,
408,
2499,
376,
1834,
6331,
730,
14735,
2213,
14,
398,
485,
1569,
576,
365,
282,
1059,
3035,
314,
3066,
1834,
666,
14,
221,
982,
642,
666,
267,
883,
506,
11203,
701,
314,
4465,
2018,
658,
1017,
3561,
5012,
7,
859,
12,
2066,
314,
267,
15686,
911,
506,
5847,
5120,
315,
314,
6646,
13,
804,
1406,
14,
267,
6630,
12,
1265,
883,
4165,
314,
2488,
1834,
15686,
4799,
314,
485,
10512,
267,
2725,
14,
398,
485,
9347,
365,
282,
805,
1314,
911,
5147,
314,
3503,
2644,
367,
267,
7773,
402,
314,
1834,
666,
14,
221,
2779,
6181,
1373,
1423,
12,
1314,
365,
642,
267,
6047,
1256,
14,
221,
2779,
1077,
675,
664,
63,
4749,
342,
436,
663,
63,
4749,
342,
370,
267,
1570,
314,
4886,
370,
314,
5737,
1824,
14,
221,
2779,
1077,
2597,
1050,
1263,
267,
6646,
13,
11761,
13,
7630,
503,
1163,
2323,
370,
314,
1245,
465,
267,
5784,
14,
221,
710,
849,
2644,
365,
3523,
772,
14,
398,
6184,
4722,
4252,
2368,
787,
3032,
370,
314,
1300,
1021,
267,
3787,
12,
1314,
25449,
3062,
1901,
2633,
641,
314,
6646,
13,
804,
267,
1406,
14,
267,
408,
267,
340,
485,
10512,
365,
488,
26,
288,
485,
10512,
275,
3416,
3561,
5012,
14,
10058,
8,
403,
12,
485,
1569,
576,
9,
267,
340,
485,
10512,
365,
488,
26,
288,
746,
3146,
360,
6531,
440,
9519,
1834,
14735,
15686,
358,
267,
603,
1469,
742,
265,
27242,
855,
826,
721,
277,
12,
283,
1569,
297,
485,
10512,
12,
29666,
1162,
9,
267,
291,
14,
409,
63,
4749,
1547,
1569,
576,
9,
267,
485,
9347,
8,
277,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
334,
35,
9,
12521,
13,
7968,
2018,
2290,
2752,
199,
3,
6529,
26,
12377,
651,
644,
285,
2231,
87,
199,
3,
18684,
26,
3031,
13,
4093,
32,
1548,
14,
1308,
199,
199,
624,
2543,
6144,
1834,
6331,
730,
14735,
8247,
1041,
199,
199,
363,
452,
363,
275,
788,
17057,
3491,
418,
199,
199,
646,
3416,
3561,
5012,
199,
199,
504,
3031,
492,
10295,
83,
199,
504,
3031,
14,
7626,
14,
2865,
10123,
492,
603,
1469,
742,
265,
27242,
4388,
201,
199,
533,
14735,
3491,
8,
45,
1469,
742,
265,
27242,
304,
272,
408,
2543,
367,
12999,
1834,
6331,
730,
14735,
8247,
1041,
339,
347,
636,
826,
721,
277,
12,
485,
1569,
576,
12,
485,
10512,
29,
403,
12,
326,
485,
9347,
29,
9347,
83,
14,
2143,
63,
1095,
772,
12,
29666,
1162,
304,
267,
408,
2499,
376,
1834,
6331,
730,
14735,
2213,
14,
398,
485,
1569,
576,
365,
282,
1059,
3035,
314,
3066,
1834,
666,
14,
221,
982,
642,
666,
267,
883,
506,
11203,
701,
314,
4465,
2018,
658,
1017,
3561,
5012,
7,
859,
12,
2066,
314,
267,
15686,
911,
506,
5847,
5120,
315,
314,
6646,
13,
804,
1406,
14,
267,
6630,
12,
1265,
883,
4165,
314,
2488,
1834,
15686,
4799,
314,
485,
10512,
267,
2725,
14,
398,
485,
9347,
365,
282,
805,
1314,
911,
5147,
314,
3503,
2644,
367,
267,
7773,
402,
314,
1834,
666,
14,
221,
2779,
6181,
1373,
1423,
12,
1314,
365,
642,
267,
6047,
1256,
14,
221,
2779,
1077,
675,
664,
63,
4749,
342,
436,
663,
63,
4749,
342,
370,
267,
1570,
314,
4886,
370,
314,
5737,
1824,
14,
221,
2779,
1077,
2597,
1050,
1263,
267,
6646,
13,
11761,
13,
7630,
503,
1163,
2323,
370,
314,
1245,
465,
267,
5784,
14,
221,
710,
849,
2644,
365,
3523,
772,
14,
398,
6184,
4722,
4252,
2368,
787,
3032,
370,
314,
1300,
1021,
267,
3787,
12,
1314,
25449,
3062,
1901,
2633,
641,
314,
6646,
13,
804,
267,
1406,
14,
267,
408,
267,
340,
485,
10512,
365,
488,
26,
288,
485,
10512,
275,
3416,
3561,
5012,
14,
10058,
8,
403,
12,
485,
1569,
576,
9,
267,
340,
485,
10512,
365,
488,
26,
288,
746,
3146,
360,
6531,
440,
9519,
1834,
14735,
15686,
358,
267,
603,
1469,
742,
265,
27242,
855,
826,
721,
277,
12,
283,
1569,
297,
485,
10512,
12,
29666,
1162,
9,
267,
291,
14,
409,
63,
4749,
1547,
1569,
576,
9,
267,
485,
9347,
8,
277,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,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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
] |
joemphilips/cloudbiolinux
|
cloudbio/cloudman.py
|
9
|
16113
|
"""Build instructions associated with CloudMan.
http://wiki.g2.bx.psu.edu/Admin/Cloud
Adapted from Enis Afgan's code: https://bitbucket.org/afgane/mi-deployment
"""
cm_upstart = """
description "Start CloudMan contextualization script"
start on runlevel [2345]
task
exec python %s 2> %s.log
"""
import os
from fabric.api import sudo, cd, run, put
from fabric.contrib.files import exists, settings
from cloudbio.galaxy import _setup_users
from cloudbio.flavor.config import get_config_file
from cloudbio.package.shared import _yaml_to_packages
from cloudbio.custom.shared import (_make_tmp_dir, _write_to_file, _get_install,
_configure_make, _if_not_installed,
_setup_conf_file, _add_to_profiles,
_create_python_virtualenv,
_setup_simple_service,
_read_boolean)
from cloudbio.package.deb import (_apt_packages, _setup_apt_automation)
MI_REPO_ROOT_URL = "https://bitbucket.org/afgane/mi-deployment/raw/tip"
CM_REPO_ROOT_URL = "https://bitbucket.org/galaxy/cloudman/raw/tip"
def _configure_cloudman(env, use_repo_autorun=False):
"""
Configure the machine to be capable of running CloudMan.
..Also see: ``custom/cloudman.py``
"""
env.logger.debug("Configuring CloudMan")
_setup_users(env)
_setup_env(env)
_configure_logrotate(env)
_configure_ec2_autorun(env, use_repo_autorun)
_configure_sge(env)
_configure_hadoop(env)
_configure_nfs(env)
_configure_novnc(env)
_configure_desktop(env)
install_s3fs(env)
def _configure_desktop(env):
"""
Configure a desktop manager to work with VNC. Note that `xfce4` (or `jwm`)
and `vnc4server` packages need to be installed for this to have effect.
"""
if not _read_boolean(env, "configure_desktop", False):
return
# Set nginx PAM module to allow logins for any system user
if env.safe_exists("/etc/pam.d"):
env.safe_sudo('echo "@include common-auth" > /etc/pam.d/nginx')
env.safe_sudo('usermod -a -G shadow galaxy')
# Create a start script for X
_setup_conf_file(env, "/home/ubuntu/.vnc/xstartup", "xstartup", default_source="xstartup")
# Create jwmrc config file (uncomment this if using jwm window manager)
# _setup_conf_file(env, "/home/ubuntu/.jwmrc", "jwmrc.xml",
# default_source="jwmrc.xml", mode="0644")
env.logger.info("----- Done configuring desktop -----")
def _configure_novnc(env):
if not _read_boolean(env, "configure_novnc", False):
# Longer term would like this enabled by default. -John
return
if not "novnc_install_dir" in env:
env.novnc_install_dir = "/opt/novnc"
if not "vnc_password" in env:
env.vnc_password = "cl0udbi0l1nux"
if not "vnc_user" in env:
env.vnc_user = env.user
if not "vnc_display" in env:
env.vnc_display = "1"
if not "vnc_depth" in env:
env.vnc_depth = "16"
if not "vnc_geometry" in env:
env.vnc_geometry = "1024x768"
_configure_vncpasswd(env)
novnc_dir = env.novnc_install_dir
env.safe_sudo("mkdir -p '%s'" % novnc_dir)
env.safe_sudo("chown %s '%s'" % (env.user, novnc_dir))
clone_cmd = "NOVNC_DIR='%s'; rm -rf $NOVNC_DIR; git clone https://github.com/kanaka/noVNC.git $NOVNC_DIR" % novnc_dir
run(clone_cmd)
## Move vnc_auto.html which takes vnc_password as query argument
## to index.html and rewrite it so that password is autoset, no
## need to specify via query parameter.
run("sed s/password\\ =\\ /password\\ =\\ \\\'%s\\\'\\;\\\\\\\\/\\\\\\\\// '%s/vnc_auto.html' > '%s/index.html'" % (env.vnc_password, novnc_dir, novnc_dir))
_setup_conf_file(env, "/etc/init.d/novnc", "novnc_init", default_source="novnc_init")
_setup_conf_file(env, "/etc/default/novnc", "novnc_default", default_source="novnc_default.template")
_setup_conf_file(env, "/etc/init.d/vncserver", "vncserver_init", default_source="vncserver_init")
_setup_conf_file(env, "/etc/default/vncserver", "vncserver_default", default_source="vncserver_default.template")
_setup_simple_service("novnc")
_setup_simple_service("vncserver")
def _configure_vncpasswd(env):
with cd("~"):
run("mkdir -p ~/.vnc")
run("rm -rf vncpasswd")
run("git clone https://github.com/trinitronx/vncpasswd.py vncpasswd")
run("python vncpasswd/vncpasswd.py '%s' -f ~/.vnc/passwd" % env.vnc_password)
run("chmod 600 ~/.vnc/passwd")
run("rm -rf vncpasswd")
def _setup_env(env):
"""
Setup the system environment required to run CloudMan. This means
installing required system-level packages (as defined in CBL's
``packages.yaml``, or a flavor thereof) and Python dependencies
(i.e., libraries) as defined in CloudMan's ``requirements.txt`` file.
"""
# Get and install required system packages
if env.distribution in ["debian", "ubuntu"]:
config_file = get_config_file(env, "packages.yaml")
(packages, _) = _yaml_to_packages(config_file.base, 'cloudman')
# Allow flavors to modify the package list
packages = env.flavor.rewrite_config_items("packages", packages)
_setup_apt_automation()
_apt_packages(pkg_list=packages)
elif env.distribution in ["centos", "scientificlinux"]:
env.logger.warn("No CloudMan system package dependencies for CentOS")
pass
# Get and install required Python libraries
with _make_tmp_dir() as work_dir:
with cd(work_dir):
url = os.path.join(CM_REPO_ROOT_URL, 'requirements.txt')
_create_python_virtualenv(env, 'CM', reqs_url=url)
# Add a custom vimrc
vimrc_url = os.path.join(MI_REPO_ROOT_URL, 'conf_files', 'vimrc')
remote_file = '/etc/vim/vimrc'
if env.safe_exists("/etc/vim"):
env.safe_sudo("wget --output-document=%s %s" % (remote_file, vimrc_url))
env.logger.debug("Added a custom vimrc to {0}".format(remote_file))
# Setup profile
aliases = ['alias lt="ls -ltr"', 'alias ll="ls -l"']
for alias in aliases:
_add_to_profiles(alias, ['/etc/bash.bashrc'])
env.logger.info("Done setting up CloudMan's environment")
def _configure_logrotate(env):
"""
Add logrotate config file, which will automatically rotate CloudMan's log
"""
conf_file = "cloudman.logrotate"
remote = '/etc/logrotate.d/cloudman'
url = os.path.join(MI_REPO_ROOT_URL, 'conf_files', conf_file)
env.safe_sudo("wget --output-document=%s %s" % (remote, url))
env.logger.info("----- Added logrotate file to {0} -----".format(remote))
def _configure_ec2_autorun(env, use_repo_autorun=False):
"""
ec2autorun.py is a script that launches CloudMan on instance boot
and is thus required on an instance. See the script itself for the
details of what it does.
This script also adds a cloudman service to ``/etc/init``, which
actually runs ec2autorun.py as a system-level service at system boot.
"""
script = "ec2autorun.py"
remote = os.path.join(env.install_dir, "bin", script)
if not env.safe_exists(os.path.dirname(remote)):
env.safe_sudo('mkdir -p {0}'.format(os.path.dirname(remote)))
if use_repo_autorun:
# Is this used, can we eliminate use_repo_autorun?
url = os.path.join(MI_REPO_ROOT_URL, script)
env.safe_sudo("wget --output-document=%s %s" % (remote, url))
else:
install_file_dir = os.path.join(env.config_dir, os.pardir, "installed_files")
tmp_remote = os.path.join("/tmp", os.path.basename(remote))
env.safe_put(os.path.join(install_file_dir, script), tmp_remote)
env.safe_sudo("mv %s %s" % (tmp_remote, remote))
env.safe_sudo("chmod 0777 %s" % remote)
# Create upstart configuration file for boot-time script
cloudman_boot_file = 'cloudman.conf'
remote_file = '/etc/init/%s' % cloudman_boot_file
_write_to_file(cm_upstart % (remote, os.path.splitext(remote)[0]), remote_file, mode="0644")
# Setup default image user data (if configured by image_user_data_path or
# image_user_data_template_path). This specifies defaults for CloudMan when
# used with resulting image, normal userdata supplied by user will override
# these defaults.
image_user_data_path = os.path.join(env.install_dir, "bin", "IMAGE_USER_DATA")
if "image_user_data_dict" in env:
# Explicit YAML contents defined in env, just dump them as is.
import yaml
_write_to_file(yaml.dump(env.get("image_user_data_dict")), image_user_data_path, mode="0644")
else:
# Else use file or template file.
_setup_conf_file(env, image_user_data_path, "image_user_data", default_source="image_user_data")
env.logger.info("Done configuring CloudMan's ec2_autorun")
def _configure_sge(env):
"""
This method sets up the environment for SGE w/o
actually setting up SGE; it basically makes sure system paths expected
by CloudMan exist on the system.
TODO: Merge this with ``install_sge`` method in ``custom/cloudman.py``.
"""
sge_root = '/opt/sge'
if not env.safe_exists(sge_root):
env.safe_sudo("mkdir -p %s" % sge_root)
env.safe_sudo("chown sgeadmin:sgeadmin %s" % sge_root)
# Link our installed SGE to CloudMan's expected directory
sge_package_dir = "/opt/galaxy/pkg"
sge_dir = "ge6.2u5"
if not env.safe_exists(os.path.join(sge_package_dir, sge_dir)):
env.safe_sudo("mkdir -p %s" % sge_package_dir)
if not env.safe_exists(os.path.join(sge_package_dir, sge_dir)):
env.safe_sudo("ln --force -s %s/%s %s/%s" % (env.install_dir, sge_dir, sge_package_dir, sge_dir))
env.logger.info("Done configuring SGE for CloudMan")
def _configure_hadoop(env):
"""
Grab files required by CloudMan to setup a Hadoop cluster atop SGE.
"""
hadoop_root = '/opt/hadoop'
url_root = 'https://s3.amazonaws.com/cloudman'
hcm_file = 'hadoop.1.0.4__1.0.tar.gz'
si_file = 'sge_integration.1.0.tar.gz'
# Make sure we're working with a clean hadoop_home dir to avoid any version conflicts
env.safe_sudo("rm -rf {0}".format(hadoop_root))
env.safe_sudo("mkdir -p %s" % hadoop_root)
with cd(hadoop_root):
env.safe_sudo("wget --output-document={0} {1}/{0}".format(hcm_file, url_root))
env.safe_sudo("wget --output-document={0} {1}/{0}".format(si_file, url_root))
env.safe_sudo("chown -R {0} {1}".format(env.user, hadoop_root))
env.logger.info("Done configuring Hadoop for CloudMan")
def _configure_nfs(env):
"""
Edit ``/etc/exports`` to append paths that are shared over NFS by CloudMan.
In addition to the hard coded paths listed here, additional paths
can be included by setting ``extra_nfs_exports`` in ``fabricrc.txt`` as
a comma-separated list of directories.
"""
nfs_dir = "/export/data"
cloudman_dir = "/mnt/galaxy/export"
if not env.safe_exists(nfs_dir):
# For the case of rerunning this script, ensure the nfs_dir does
# not exist (exists() method does not recognize it as a file because
# by default it points to a non-existing dir/file).
with settings(warn_only=True):
env.safe_sudo('rm -rf {0}'.format(nfs_dir))
env.safe_sudo("mkdir -p %s" % os.path.dirname(nfs_dir))
env.safe_sudo("ln -s %s %s" % (cloudman_dir, nfs_dir))
env.safe_sudo("chown -R %s %s" % (env.user, os.path.dirname(nfs_dir)))
# Setup /etc/exports paths, to be used as NFS mount points
# galaxy_data_mount = env.get("galaxy_data_mount", "/mnt/galaxyData")
# galaxy_indices_mount = env.get("galaxy_indices_mount", "/mnt/galaxyIndices")
# galaxy_tools_mount = env.get("galaxy_tools_mount", "/mnt/galaxyTools")
exports = ['/opt/sge *(rw,sync,no_root_squash,no_subtree_check)',
'/opt/hadoop *(rw,sync,no_root_squash,no_subtree_check)',
# '%s *(rw,sync,no_root_squash,subtree_check,no_wdelay)' % galaxy_data_mount,
# '%s *(rw,sync,no_root_squash,no_subtree_check)' % galaxy_indices_mount,
# '%s *(rw,sync,no_root_squash,no_subtree_check)' % galaxy_tools_mount,
# '%s *(rw,sync,no_root_squash,no_subtree_check)' % nfs_dir,
# '%s/openmpi *(rw,sync,no_root_squash,no_subtree_check)' % env.install_dir
]
extra_nfs_exports = env.get("extra_nfs_exports", "")
if extra_nfs_exports:
for extra_nfs_export in extra_nfs_exports.split(","):
exports.append('%s *(rw,sync,no_root_squash,no_subtree_check)' % extra_nfs_export)
env.safe_append('/etc/exports', exports, use_sudo=True)
# Create a symlink for backward compatibility where all of CloudMan's
# stuff is expected to be in /opt/galaxy
old_dir = '/opt/galaxy'
# Because stow is used, the equivalent to CloudMan's expected path
# is actually the parent of the install_dir so use it for the symlink
new_dir = os.path.dirname(env.install_dir)
if not env.safe_exists(old_dir) and exists(new_dir):
env.safe_sudo('ln -s {0} {1}'.format(new_dir, old_dir))
env.logger.info("Done configuring NFS for CloudMan")
@_if_not_installed("s3fs")
def install_s3fs(env):
"""
Install s3fs, allowing S3 buckets to be mounted as ~POSIX file systems
"""
default_version = "1.61"
version = env.get("tool_version", default_version)
url = "http://s3fs.googlecode.com/files/s3fs-%s.tar.gz" % version
_get_install(url, env, _configure_make)
def _cleanup_ec2(env):
"""
Clean up any extra files after building. This method must be called
on an instance after being built and before creating a new machine
image. *Note* that after this method has run, key-based ssh access
to the machine is no longer possible.
"""
env.logger.info("Cleaning up for EC2 AMI creation")
# Clean up log files and such
fnames = [".bash_history", "/var/log/firstboot.done", ".nx_setup_done",
"/var/crash/*", "%s/ec2autorun.py.log" % env.install_dir,
"%s/ec2autorun.err" % env.install_dir, "%s/ec2autorun.log" % env.install_dir,
"%s/bin/ec2autorun.log" % env.install_dir]
for fname in fnames:
sudo("rm -f %s" % fname)
rmdirs = ["/mnt/galaxyData", "/mnt/cm", "/tmp/cm"]
for rmdir in rmdirs:
sudo("rm -rf %s" % rmdir)
# Seed the history with frequently used commands
env.logger.debug("Setting bash history")
local = os.path.join(env.config_dir, os.pardir, "installed_files", "bash_history")
remote = os.path.join('/home', 'ubuntu', '.bash_history')
put(local, remote, mode=0660, use_sudo=True)
# Make sure the default config dir is owned by ubuntu
sudo("chown ubuntu:ubuntu ~/.config")
# Stop Apache from starting automatically at boot (it conflicts with Galaxy's nginx)
sudo('/usr/sbin/update-rc.d -f apache2 remove')
with settings(warn_only=True):
# RabbitMQ fails to start if its database is embedded into the image
# because it saves the current IP address or host name so delete it now.
# When starting up, RabbitMQ will recreate that directory.
sudo('/etc/init.d/rabbitmq-server stop')
sudo('service rabbitmq-server stop')
# Clean up packages that are causing issues or are unnecessary
pkgs_to_remove = ['tntnet', 'tntnet-runtime', 'libtntnet9', 'vsftpd']
for ptr in pkgs_to_remove:
sudo('apt-get -y --force-yes remove --purge {0}'.format(ptr))
sudo('initctl reload-configuration')
for db_location in ['/var/lib/rabbitmq/mnesia', '/mnesia']:
if exists(db_location):
sudo('rm -rf %s' % db_location)
# remove existing ssh host key pairs
# http://docs.amazonwebservices.com/AWSEC2/latest/UserGuide/AESDG-chapter-sharingamis.html
sudo("rm -f /etc/ssh/ssh_host_*")
sudo("rm -f ~/.ssh/authorized_keys*")
sudo("rm -f /root/.ssh/authorized_keys*")
|
mit
|
[
624,
3425,
15794,
4568,
543,
8142,
2395,
14,
199,
199,
1014,
921,
6797,
14,
71,
18,
14,
13691,
14,
1190,
85,
14,
8654,
15,
4880,
15,
9089,
199,
199,
2767,
18309,
687,
3447,
374,
437,
9681,
290,
1159,
1233,
26,
4178,
921,
25668,
14,
1308,
15,
2756,
71,
5865,
15,
2664,
13,
13605,
199,
624,
199,
199,
4400,
63,
384,
928,
275,
408,
199,
1802,
258,
298,
3162,
8142,
2395,
1067,
1061,
2072,
2884,
2,
199,
199,
928,
641,
1255,
1896,
359,
5533,
21,
61,
199,
199,
1765,
199,
1628,
2366,
450,
83,
499,
30,
450,
83,
14,
793,
199,
624,
199,
646,
747,
199,
199,
504,
2630,
14,
1246,
492,
14682,
12,
12829,
12,
1255,
12,
5324,
199,
504,
2630,
14,
2828,
14,
1725,
492,
3495,
12,
2202,
199,
199,
504,
2463,
8301,
2308,
14,
24806,
492,
485,
2758,
63,
3707,
199,
504,
2463,
8301,
2308,
14,
6081,
14,
888,
492,
664,
63,
888,
63,
493,
199,
504,
2463,
8301,
2308,
14,
2491,
14,
5555,
492,
485,
5963,
63,
475,
63,
5154,
199,
504,
2463,
8301,
2308,
14,
4229,
14,
5555,
492,
6110,
1875,
63,
2791,
63,
694,
12,
485,
952,
63,
475,
63,
493,
12,
485,
362,
63,
3174,
12,
2511,
485,
6472,
63,
1875,
12,
485,
692,
63,
1397,
63,
7657,
12,
2511,
485,
2758,
63,
2190,
63,
493,
12,
485,
525,
63,
475,
63,
11225,
12,
2511,
485,
981,
63,
1548,
63,
21611,
12,
2511,
485,
2758,
63,
4129,
63,
1364,
12,
2511,
485,
739,
63,
4871,
9,
199,
504,
2463,
8301,
2308,
14,
2491,
14,
16762,
492,
6110,
6182,
63,
5154,
12,
485,
2758,
63,
6182,
63,
23867,
9,
199,
199,
10709,
63,
20424,
63,
5441,
63,
2632,
275,
298,
2859,
921,
25668,
14,
1308,
15,
2756,
71,
5865,
15,
2664,
13,
13605,
15,
1773,
15,
8996,
2,
199,
9249,
63,
20424,
63,
5441,
63,
2632,
275,
298,
2859,
921,
25668,
14,
1308,
15,
24806,
15,
4091,
1237,
15,
1773,
15,
8996,
2,
421,
199,
318,
485,
6472,
63,
4091,
1237,
8,
1813,
12,
675,
63,
3417,
63,
65,
4139,
324,
29,
797,
304,
272,
408,
272,
15453,
314,
6844,
370,
506,
4021,
461,
402,
3879,
8142,
2395,
14,
339,
2508,
31892,
1937,
26,
1124,
4229,
15,
4091,
1237,
14,
647,
1040,
272,
408,
272,
2589,
14,
2921,
14,
1757,
480,
2028,
4039,
8142,
2395,
531,
272,
485,
2758,
63,
3707,
8,
1813,
9,
272,
485,
2758,
63,
1813,
8,
1813,
9,
272,
485,
6472,
63,
793,
12873,
8,
1813,
9,
272,
485,
6472,
63,
825,
18,
63,
65,
4139,
324,
8,
1813,
12,
675,
63,
3417,
63,
65,
4139,
324,
9,
272,
485,
6472,
63,
83,
303,
8,
1813,
9,
272,
485,
6472,
63,
15449,
8,
1813,
9,
272,
485,
6472,
63,
19591,
8,
1813,
9,
272,
485,
6472,
63,
889,
24093,
8,
1813,
9,
272,
485,
6472,
63,
14487,
8,
1813,
9,
272,
3907,
63,
83,
19,
2319,
8,
1813,
9,
421,
199,
318,
485,
6472,
63,
14487,
8,
1813,
304,
272,
408,
272,
15453,
282,
19763,
5256,
370,
1736,
543,
812,
6389,
14,
3390,
626,
658,
1949,
301,
20,
64,
334,
269,
658,
74,
16240,
10522,
272,
436,
658,
24093,
20,
1000,
64,
6117,
1929,
370,
506,
4903,
367,
642,
370,
1172,
7763,
14,
272,
408,
272,
340,
440,
485,
739,
63,
4871,
8,
1813,
12,
298,
6472,
63,
14487,
401,
756,
304,
267,
372,
272,
327,
2494,
302,
19101,
510,
1156,
859,
370,
2040,
4676,
83,
367,
1263,
2656,
922,
272,
340,
2589,
14,
3489,
63,
2444,
4769,
6839,
15,
28024,
14,
68,
2349,
267,
2589,
14,
3489,
63,
12095,
360,
7878,
9244,
2613,
2863,
13,
1178,
2,
690,
1182,
6839,
15,
28024,
14,
68,
15,
25826,
358,
272,
2589,
14,
3489,
63,
12095,
360,
751,
1494,
446,
65,
446,
39,
15084,
486,
15914,
358,
272,
327,
2790,
282,
1343,
2884,
367,
1323,
272,
485,
2758,
63,
2190,
63,
493,
8,
1813,
12,
3286,
4219,
15,
21151,
8083,
24093,
15,
88,
16480,
401,
298,
88,
16480,
401,
849,
63,
1365,
628,
88,
16480,
531,
272,
327,
2790,
1335,
16240,
1195,
1101,
570,
334,
324,
3349,
642,
340,
1808,
1335,
16240,
4353,
5256,
9,
272,
327,
485,
2758,
63,
2190,
63,
493,
8,
1813,
12,
3286,
4219,
15,
21151,
8083,
74,
16240,
1195,
401,
298,
74,
16240,
1195,
14,
1652,
401,
272,
327,
258,
849,
63,
1365,
628,
74,
16240,
1195,
14,
1652,
401,
818,
628,
16,
10893,
531,
272,
2589,
14,
2921,
14,
815,
480,
9858,
23541,
1101,
4039,
19763,
9063,
531,
421,
199,
318,
485,
6472,
63,
889,
24093,
8,
1813,
304,
272,
340,
440,
485,
739,
63,
4871,
8,
1813,
12,
298,
6472,
63,
889,
24093,
401,
756,
304,
267,
327,
491,
265,
836,
6707,
3955,
2839,
642,
5223,
701,
849,
14,
446,
12923,
267,
372,
272,
340,
440,
298,
889,
24093,
63,
3174,
63,
694,
2,
315,
2589,
26,
267,
2589,
14,
889,
24093,
63,
3174,
63,
694,
275,
3286,
2992,
15,
889,
24093,
2,
272,
340,
440,
298,
24093,
63,
2060,
2,
315,
2589,
26,
267,
2589,
14,
24093,
63,
2060,
275,
298,
429,
16,
8301,
73,
16,
76,
17,
78,
2521,
2,
272,
340,
440,
298,
24093,
63,
751,
2,
315,
2589,
26,
267,
2589,
14,
24093,
63,
751,
275,
2589,
14,
751,
272,
340,
440,
298,
24093,
63,
2918,
2,
315,
2589,
26,
267,
2589,
14,
24093,
63,
2918,
275,
298,
17,
2,
272,
340,
440,
298,
24093,
63,
4631,
2,
315,
2589,
26,
267,
2589,
14,
24093,
63,
4631,
275,
298,
975,
2,
272,
340,
440,
298,
24093,
63,
7660,
2,
315,
2589,
26,
267,
2589,
14,
24093,
63,
7660,
275,
298,
7727,
88,
14408,
2,
339,
485,
6472,
63,
24093,
12671,
8,
1813,
9,
339,
949,
24093,
63,
694,
275,
2589,
14,
889,
24093,
63,
3174,
63,
694,
272,
2589,
14,
3489,
63,
12095,
480,
8215,
446,
80,
1543,
83,
4065,
450,
949,
24093,
63,
694,
9,
272,
2589,
14,
3489,
63,
12095,
480,
20933,
450,
83,
1543,
83,
4065,
450,
334,
1813,
14,
751,
12,
949,
24093,
63,
694,
430,
272,
7289,
63,
1760,
275,
298,
2826,
54,
6389,
63,
3022,
9569,
83,
13619,
14267,
446
] |
[
3425,
15794,
4568,
543,
8142,
2395,
14,
199,
199,
1014,
921,
6797,
14,
71,
18,
14,
13691,
14,
1190,
85,
14,
8654,
15,
4880,
15,
9089,
199,
199,
2767,
18309,
687,
3447,
374,
437,
9681,
290,
1159,
1233,
26,
4178,
921,
25668,
14,
1308,
15,
2756,
71,
5865,
15,
2664,
13,
13605,
199,
624,
199,
199,
4400,
63,
384,
928,
275,
408,
199,
1802,
258,
298,
3162,
8142,
2395,
1067,
1061,
2072,
2884,
2,
199,
199,
928,
641,
1255,
1896,
359,
5533,
21,
61,
199,
199,
1765,
199,
1628,
2366,
450,
83,
499,
30,
450,
83,
14,
793,
199,
624,
199,
646,
747,
199,
199,
504,
2630,
14,
1246,
492,
14682,
12,
12829,
12,
1255,
12,
5324,
199,
504,
2630,
14,
2828,
14,
1725,
492,
3495,
12,
2202,
199,
199,
504,
2463,
8301,
2308,
14,
24806,
492,
485,
2758,
63,
3707,
199,
504,
2463,
8301,
2308,
14,
6081,
14,
888,
492,
664,
63,
888,
63,
493,
199,
504,
2463,
8301,
2308,
14,
2491,
14,
5555,
492,
485,
5963,
63,
475,
63,
5154,
199,
504,
2463,
8301,
2308,
14,
4229,
14,
5555,
492,
6110,
1875,
63,
2791,
63,
694,
12,
485,
952,
63,
475,
63,
493,
12,
485,
362,
63,
3174,
12,
2511,
485,
6472,
63,
1875,
12,
485,
692,
63,
1397,
63,
7657,
12,
2511,
485,
2758,
63,
2190,
63,
493,
12,
485,
525,
63,
475,
63,
11225,
12,
2511,
485,
981,
63,
1548,
63,
21611,
12,
2511,
485,
2758,
63,
4129,
63,
1364,
12,
2511,
485,
739,
63,
4871,
9,
199,
504,
2463,
8301,
2308,
14,
2491,
14,
16762,
492,
6110,
6182,
63,
5154,
12,
485,
2758,
63,
6182,
63,
23867,
9,
199,
199,
10709,
63,
20424,
63,
5441,
63,
2632,
275,
298,
2859,
921,
25668,
14,
1308,
15,
2756,
71,
5865,
15,
2664,
13,
13605,
15,
1773,
15,
8996,
2,
199,
9249,
63,
20424,
63,
5441,
63,
2632,
275,
298,
2859,
921,
25668,
14,
1308,
15,
24806,
15,
4091,
1237,
15,
1773,
15,
8996,
2,
421,
199,
318,
485,
6472,
63,
4091,
1237,
8,
1813,
12,
675,
63,
3417,
63,
65,
4139,
324,
29,
797,
304,
272,
408,
272,
15453,
314,
6844,
370,
506,
4021,
461,
402,
3879,
8142,
2395,
14,
339,
2508,
31892,
1937,
26,
1124,
4229,
15,
4091,
1237,
14,
647,
1040,
272,
408,
272,
2589,
14,
2921,
14,
1757,
480,
2028,
4039,
8142,
2395,
531,
272,
485,
2758,
63,
3707,
8,
1813,
9,
272,
485,
2758,
63,
1813,
8,
1813,
9,
272,
485,
6472,
63,
793,
12873,
8,
1813,
9,
272,
485,
6472,
63,
825,
18,
63,
65,
4139,
324,
8,
1813,
12,
675,
63,
3417,
63,
65,
4139,
324,
9,
272,
485,
6472,
63,
83,
303,
8,
1813,
9,
272,
485,
6472,
63,
15449,
8,
1813,
9,
272,
485,
6472,
63,
19591,
8,
1813,
9,
272,
485,
6472,
63,
889,
24093,
8,
1813,
9,
272,
485,
6472,
63,
14487,
8,
1813,
9,
272,
3907,
63,
83,
19,
2319,
8,
1813,
9,
421,
199,
318,
485,
6472,
63,
14487,
8,
1813,
304,
272,
408,
272,
15453,
282,
19763,
5256,
370,
1736,
543,
812,
6389,
14,
3390,
626,
658,
1949,
301,
20,
64,
334,
269,
658,
74,
16240,
10522,
272,
436,
658,
24093,
20,
1000,
64,
6117,
1929,
370,
506,
4903,
367,
642,
370,
1172,
7763,
14,
272,
408,
272,
340,
440,
485,
739,
63,
4871,
8,
1813,
12,
298,
6472,
63,
14487,
401,
756,
304,
267,
372,
272,
327,
2494,
302,
19101,
510,
1156,
859,
370,
2040,
4676,
83,
367,
1263,
2656,
922,
272,
340,
2589,
14,
3489,
63,
2444,
4769,
6839,
15,
28024,
14,
68,
2349,
267,
2589,
14,
3489,
63,
12095,
360,
7878,
9244,
2613,
2863,
13,
1178,
2,
690,
1182,
6839,
15,
28024,
14,
68,
15,
25826,
358,
272,
2589,
14,
3489,
63,
12095,
360,
751,
1494,
446,
65,
446,
39,
15084,
486,
15914,
358,
272,
327,
2790,
282,
1343,
2884,
367,
1323,
272,
485,
2758,
63,
2190,
63,
493,
8,
1813,
12,
3286,
4219,
15,
21151,
8083,
24093,
15,
88,
16480,
401,
298,
88,
16480,
401,
849,
63,
1365,
628,
88,
16480,
531,
272,
327,
2790,
1335,
16240,
1195,
1101,
570,
334,
324,
3349,
642,
340,
1808,
1335,
16240,
4353,
5256,
9,
272,
327,
485,
2758,
63,
2190,
63,
493,
8,
1813,
12,
3286,
4219,
15,
21151,
8083,
74,
16240,
1195,
401,
298,
74,
16240,
1195,
14,
1652,
401,
272,
327,
258,
849,
63,
1365,
628,
74,
16240,
1195,
14,
1652,
401,
818,
628,
16,
10893,
531,
272,
2589,
14,
2921,
14,
815,
480,
9858,
23541,
1101,
4039,
19763,
9063,
531,
421,
199,
318,
485,
6472,
63,
889,
24093,
8,
1813,
304,
272,
340,
440,
485,
739,
63,
4871,
8,
1813,
12,
298,
6472,
63,
889,
24093,
401,
756,
304,
267,
327,
491,
265,
836,
6707,
3955,
2839,
642,
5223,
701,
849,
14,
446,
12923,
267,
372,
272,
340,
440,
298,
889,
24093,
63,
3174,
63,
694,
2,
315,
2589,
26,
267,
2589,
14,
889,
24093,
63,
3174,
63,
694,
275,
3286,
2992,
15,
889,
24093,
2,
272,
340,
440,
298,
24093,
63,
2060,
2,
315,
2589,
26,
267,
2589,
14,
24093,
63,
2060,
275,
298,
429,
16,
8301,
73,
16,
76,
17,
78,
2521,
2,
272,
340,
440,
298,
24093,
63,
751,
2,
315,
2589,
26,
267,
2589,
14,
24093,
63,
751,
275,
2589,
14,
751,
272,
340,
440,
298,
24093,
63,
2918,
2,
315,
2589,
26,
267,
2589,
14,
24093,
63,
2918,
275,
298,
17,
2,
272,
340,
440,
298,
24093,
63,
4631,
2,
315,
2589,
26,
267,
2589,
14,
24093,
63,
4631,
275,
298,
975,
2,
272,
340,
440,
298,
24093,
63,
7660,
2,
315,
2589,
26,
267,
2589,
14,
24093,
63,
7660,
275,
298,
7727,
88,
14408,
2,
339,
485,
6472,
63,
24093,
12671,
8,
1813,
9,
339,
949,
24093,
63,
694,
275,
2589,
14,
889,
24093,
63,
3174,
63,
694,
272,
2589,
14,
3489,
63,
12095,
480,
8215,
446,
80,
1543,
83,
4065,
450,
949,
24093,
63,
694,
9,
272,
2589,
14,
3489,
63,
12095,
480,
20933,
450,
83,
1543,
83,
4065,
450,
334,
1813,
14,
751,
12,
949,
24093,
63,
694,
430,
272,
7289,
63,
1760,
275,
298,
2826,
54,
6389,
63,
3022,
9569,
83,
13619,
14267,
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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
satyamrockstar2013/linux
|
tools/perf/scripts/python/check-perf-trace.py
|
1997
|
2539
|
# perf script event handlers, generated by perf script -g python
# (c) 2010, Tom Zanussi <tzanussi@gmail.com>
# Licensed under the terms of the GNU GPL License version 2
#
# This script tests basic functionality such as flag and symbol
# strings, common_xxx() calls back into perf, begin, end, unhandled
# events, etc. Basically, if this script runs successfully and
# displays expected results, Python scripting support should be ok.
import os
import sys
sys.path.append(os.environ['PERF_EXEC_PATH'] + \
'/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
from Core import *
from perf_trace_context import *
unhandled = autodict()
def trace_begin():
print "trace_begin"
pass
def trace_end():
print_unhandled()
def irq__softirq_entry(event_name, context, common_cpu,
common_secs, common_nsecs, common_pid, common_comm,
common_callchain, vec):
print_header(event_name, common_cpu, common_secs, common_nsecs,
common_pid, common_comm)
print_uncommon(context)
print "vec=%s\n" % \
(symbol_str("irq__softirq_entry", "vec", vec)),
def kmem__kmalloc(event_name, context, common_cpu,
common_secs, common_nsecs, common_pid, common_comm,
common_callchain, call_site, ptr, bytes_req, bytes_alloc,
gfp_flags):
print_header(event_name, common_cpu, common_secs, common_nsecs,
common_pid, common_comm)
print_uncommon(context)
print "call_site=%u, ptr=%u, bytes_req=%u, " \
"bytes_alloc=%u, gfp_flags=%s\n" % \
(call_site, ptr, bytes_req, bytes_alloc,
flag_str("kmem__kmalloc", "gfp_flags", gfp_flags)),
def trace_unhandled(event_name, context, event_fields_dict):
try:
unhandled[event_name] += 1
except TypeError:
unhandled[event_name] = 1
def print_header(event_name, cpu, secs, nsecs, pid, comm):
print "%-20s %5u %05u.%09u %8u %-20s " % \
(event_name, cpu, secs, nsecs, pid, comm),
# print trace fields not included in handler args
def print_uncommon(context):
print "common_preempt_count=%d, common_flags=%s, common_lock_depth=%d, " \
% (common_pc(context), trace_flag_str(common_flags(context)), \
common_lock_depth(context))
def print_unhandled():
keys = unhandled.keys()
if not keys:
return
print "\nunhandled events:\n\n",
print "%-40s %10s\n" % ("event", "count"),
print "%-40s %10s\n" % ("----------------------------------------", \
"-----------"),
for event_name in keys:
print "%-40s %10d\n" % (event_name, unhandled[event_name])
|
gpl-2.0
|
[
3,
8582,
2884,
1566,
8297,
12,
4046,
701,
8582,
2884,
446,
71,
2366,
199,
3,
334,
67,
9,
7129,
12,
21644,
29385,
665,
29453,
32,
6799,
14,
957,
30,
199,
3,
3909,
1334,
314,
2895,
402,
314,
1664,
14629,
844,
1015,
499,
199,
3,
199,
3,
961,
2884,
2295,
5678,
9330,
4066,
465,
3305,
436,
5272,
199,
3,
3326,
12,
2863,
63,
10013,
342,
4882,
1771,
1901,
8582,
12,
5386,
12,
1284,
12,
23090,
199,
3,
4474,
12,
5423,
14,
221,
10082,
1183,
12,
340,
642,
2884,
7858,
8792,
436,
199,
3,
17561,
1420,
2058,
12,
2018,
2884,
316,
2291,
1077,
506,
4112,
14,
199,
199,
646,
747,
199,
646,
984,
199,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
2314,
459,
17038,
63,
10276,
63,
3243,
418,
435,
971,
199,
198,
9807,
6429,
15,
1548,
15,
12387,
13,
3921,
13,
9562,
15,
773,
15,
12387,
15,
3921,
358,
199,
199,
504,
11672,
492,
627,
199,
504,
8582,
63,
3446,
63,
1100,
492,
627,
199,
199,
23648,
275,
27477,
342,
199,
199,
318,
3307,
63,
5037,
837,
199,
198,
1361,
298,
3446,
63,
5037,
2,
199,
198,
1529,
199,
199,
318,
3307,
63,
500,
837,
267,
870,
63,
23648,
342,
199,
199,
318,
10476,
363,
18316,
63,
2373,
8,
1430,
63,
354,
12,
1067,
12,
2863,
63,
3541,
12,
199,
198,
2330,
63,
4855,
12,
2863,
63,
9618,
12,
2863,
63,
3150,
12,
2863,
63,
1404,
12,
199,
198,
2330,
63,
1250,
4429,
12,
10782,
304,
507,
198,
1361,
63,
1291,
8,
1430,
63,
354,
12,
2863,
63,
3541,
12,
2863,
63,
4855,
12,
2863,
63,
9618,
12,
686,
198,
2330,
63,
3150,
12,
2863,
63,
1404,
9,
2234,
870,
63,
324,
2330,
8,
1100,
9,
2742,
198,
1361,
298,
6046,
2458,
83,
60,
78,
2,
450,
971,
507,
198,
8,
5155,
63,
495,
480,
7277,
363,
18316,
63,
2373,
401,
298,
6046,
401,
10782,
1826,
199,
199,
318,
1022,
5286,
363,
75,
23981,
8,
1430,
63,
354,
12,
1067,
12,
2863,
63,
3541,
12,
199,
198,
2330,
63,
4855,
12,
2863,
63,
9618,
12,
2863,
63,
3150,
12,
2863,
63,
1404,
12,
199,
198,
2330,
63,
1250,
4429,
12,
1240,
63,
2124,
12,
12448,
12,
2783,
63,
2103,
12,
2783,
63,
9373,
12,
199,
198,
71,
3997,
63,
2469,
304,
507,
198,
1361,
63,
1291,
8,
1430,
63,
354,
12,
2863,
63,
3541,
12,
2863,
63,
4855,
12,
2863,
63,
9618,
12,
686,
198,
2330,
63,
3150,
12,
2863,
63,
1404,
9,
2234,
870,
63,
324,
2330,
8,
1100,
9,
2742,
198,
1361,
298,
1250,
63,
2124,
2458,
85,
12,
12448,
2458,
85,
12,
2783,
63,
2103,
2458,
85,
12,
298,
971,
507,
198,
2,
2394,
63,
9373,
2458,
85,
12,
486,
3997,
63,
2469,
2458,
83,
60,
78,
2,
450,
971,
507,
198,
8,
1250,
63,
2124,
12,
12448,
12,
2783,
63,
2103,
12,
2783,
63,
9373,
12,
2742,
198,
4173,
63,
495,
480,
75,
5286,
363,
75,
23981,
401,
298,
71,
3997,
63,
2469,
401,
486,
3997,
63,
2469,
1826,
199,
199,
318,
3307,
63,
23648,
8,
1430,
63,
354,
12,
1067,
12,
1566,
63,
955,
63,
807,
304,
272,
862,
26,
267,
23090,
59,
1430,
63,
354,
61,
847,
413,
272,
871,
3146,
26,
267,
23090,
59,
1430,
63,
354,
61,
275,
413,
199,
199,
318,
870,
63,
1291,
8,
1430,
63,
354,
12,
5033,
12,
20091,
12,
13781,
12,
4422,
12,
1923,
304,
199,
198,
1361,
18301,
1165,
83,
450,
21,
85,
450,
1717,
85,
4111,
1643,
85,
450,
24,
85,
19752,
1165,
83,
298,
450,
971,
199,
198,
8,
1430,
63,
354,
12,
5033,
12,
20091,
12,
13781,
12,
4422,
12,
1923,
395,
199,
199,
3,
870,
3307,
1504,
440,
5120,
315,
3016,
1249,
199,
318,
870,
63,
324,
2330,
8,
1100,
304,
272,
870,
298,
2330,
63,
657,
19046,
63,
835,
2458,
68,
12,
2863,
63,
2469,
2458,
83,
12,
2863,
63,
831,
63,
4631,
2458,
68,
12,
298,
971,
267,
450,
334,
2330,
63,
2352,
8,
1100,
395,
3307,
63,
4173,
63,
495,
8,
2330,
63,
2469,
8,
1100,
1826,
971,
2049,
2863,
63,
831,
63,
4631,
8,
1100,
430,
199,
199,
318,
870,
63,
23648,
837,
272,
2883,
275,
23090,
14,
1612,
342,
272,
340,
440,
2883,
26,
267,
372,
339,
870,
1867,
78,
23648,
4474,
3427,
78,
60,
78,
401,
339,
870,
18301,
2167,
83,
221,
450,
709,
83,
60,
78,
2,
450,
1689,
1430,
401,
298,
835,
1288,
272,
870,
18301,
2167,
83,
221,
450,
709,
83,
60,
78,
2,
450,
1689,
32111,
401,
971,
639,
298,
13715,
1288,
339,
367,
1566,
63,
354,
315,
2883,
26,
199,
198,
1361,
18301,
2167,
83,
221,
450,
709,
68,
60,
78,
2,
450,
334,
1430,
63,
354,
12,
23090,
59,
1430,
63,
354,
566,
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
] |
[
8582,
2884,
1566,
8297,
12,
4046,
701,
8582,
2884,
446,
71,
2366,
199,
3,
334,
67,
9,
7129,
12,
21644,
29385,
665,
29453,
32,
6799,
14,
957,
30,
199,
3,
3909,
1334,
314,
2895,
402,
314,
1664,
14629,
844,
1015,
499,
199,
3,
199,
3,
961,
2884,
2295,
5678,
9330,
4066,
465,
3305,
436,
5272,
199,
3,
3326,
12,
2863,
63,
10013,
342,
4882,
1771,
1901,
8582,
12,
5386,
12,
1284,
12,
23090,
199,
3,
4474,
12,
5423,
14,
221,
10082,
1183,
12,
340,
642,
2884,
7858,
8792,
436,
199,
3,
17561,
1420,
2058,
12,
2018,
2884,
316,
2291,
1077,
506,
4112,
14,
199,
199,
646,
747,
199,
646,
984,
199,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
2314,
459,
17038,
63,
10276,
63,
3243,
418,
435,
971,
199,
198,
9807,
6429,
15,
1548,
15,
12387,
13,
3921,
13,
9562,
15,
773,
15,
12387,
15,
3921,
358,
199,
199,
504,
11672,
492,
627,
199,
504,
8582,
63,
3446,
63,
1100,
492,
627,
199,
199,
23648,
275,
27477,
342,
199,
199,
318,
3307,
63,
5037,
837,
199,
198,
1361,
298,
3446,
63,
5037,
2,
199,
198,
1529,
199,
199,
318,
3307,
63,
500,
837,
267,
870,
63,
23648,
342,
199,
199,
318,
10476,
363,
18316,
63,
2373,
8,
1430,
63,
354,
12,
1067,
12,
2863,
63,
3541,
12,
199,
198,
2330,
63,
4855,
12,
2863,
63,
9618,
12,
2863,
63,
3150,
12,
2863,
63,
1404,
12,
199,
198,
2330,
63,
1250,
4429,
12,
10782,
304,
507,
198,
1361,
63,
1291,
8,
1430,
63,
354,
12,
2863,
63,
3541,
12,
2863,
63,
4855,
12,
2863,
63,
9618,
12,
686,
198,
2330,
63,
3150,
12,
2863,
63,
1404,
9,
2234,
870,
63,
324,
2330,
8,
1100,
9,
2742,
198,
1361,
298,
6046,
2458,
83,
60,
78,
2,
450,
971,
507,
198,
8,
5155,
63,
495,
480,
7277,
363,
18316,
63,
2373,
401,
298,
6046,
401,
10782,
1826,
199,
199,
318,
1022,
5286,
363,
75,
23981,
8,
1430,
63,
354,
12,
1067,
12,
2863,
63,
3541,
12,
199,
198,
2330,
63,
4855,
12,
2863,
63,
9618,
12,
2863,
63,
3150,
12,
2863,
63,
1404,
12,
199,
198,
2330,
63,
1250,
4429,
12,
1240,
63,
2124,
12,
12448,
12,
2783,
63,
2103,
12,
2783,
63,
9373,
12,
199,
198,
71,
3997,
63,
2469,
304,
507,
198,
1361,
63,
1291,
8,
1430,
63,
354,
12,
2863,
63,
3541,
12,
2863,
63,
4855,
12,
2863,
63,
9618,
12,
686,
198,
2330,
63,
3150,
12,
2863,
63,
1404,
9,
2234,
870,
63,
324,
2330,
8,
1100,
9,
2742,
198,
1361,
298,
1250,
63,
2124,
2458,
85,
12,
12448,
2458,
85,
12,
2783,
63,
2103,
2458,
85,
12,
298,
971,
507,
198,
2,
2394,
63,
9373,
2458,
85,
12,
486,
3997,
63,
2469,
2458,
83,
60,
78,
2,
450,
971,
507,
198,
8,
1250,
63,
2124,
12,
12448,
12,
2783,
63,
2103,
12,
2783,
63,
9373,
12,
2742,
198,
4173,
63,
495,
480,
75,
5286,
363,
75,
23981,
401,
298,
71,
3997,
63,
2469,
401,
486,
3997,
63,
2469,
1826,
199,
199,
318,
3307,
63,
23648,
8,
1430,
63,
354,
12,
1067,
12,
1566,
63,
955,
63,
807,
304,
272,
862,
26,
267,
23090,
59,
1430,
63,
354,
61,
847,
413,
272,
871,
3146,
26,
267,
23090,
59,
1430,
63,
354,
61,
275,
413,
199,
199,
318,
870,
63,
1291,
8,
1430,
63,
354,
12,
5033,
12,
20091,
12,
13781,
12,
4422,
12,
1923,
304,
199,
198,
1361,
18301,
1165,
83,
450,
21,
85,
450,
1717,
85,
4111,
1643,
85,
450,
24,
85,
19752,
1165,
83,
298,
450,
971,
199,
198,
8,
1430,
63,
354,
12,
5033,
12,
20091,
12,
13781,
12,
4422,
12,
1923,
395,
199,
199,
3,
870,
3307,
1504,
440,
5120,
315,
3016,
1249,
199,
318,
870,
63,
324,
2330,
8,
1100,
304,
272,
870,
298,
2330,
63,
657,
19046,
63,
835,
2458,
68,
12,
2863,
63,
2469,
2458,
83,
12,
2863,
63,
831,
63,
4631,
2458,
68,
12,
298,
971,
267,
450,
334,
2330,
63,
2352,
8,
1100,
395,
3307,
63,
4173,
63,
495,
8,
2330,
63,
2469,
8,
1100,
1826,
971,
2049,
2863,
63,
831,
63,
4631,
8,
1100,
430,
199,
199,
318,
870,
63,
23648,
837,
272,
2883,
275,
23090,
14,
1612,
342,
272,
340,
440,
2883,
26,
267,
372,
339,
870,
1867,
78,
23648,
4474,
3427,
78,
60,
78,
401,
339,
870,
18301,
2167,
83,
221,
450,
709,
83,
60,
78,
2,
450,
1689,
1430,
401,
298,
835,
1288,
272,
870,
18301,
2167,
83,
221,
450,
709,
83,
60,
78,
2,
450,
1689,
32111,
401,
971,
639,
298,
13715,
1288,
339,
367,
1566,
63,
354,
315,
2883,
26,
199,
198,
1361,
18301,
2167,
83,
221,
450,
709,
68,
60,
78,
2,
450,
334,
1430,
63,
354,
12,
23090,
59,
1430,
63,
354,
566,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
chexov/rexpython
|
rexpython/test_observable.py
|
1
|
4158
|
import logging
import multiprocessing
import sys
import time
from unittest import TestCase
import rexpython as rx
logging.basicConfig(format="%(asctime)-15s %(name)-25s %(levelname)s %(process)d %(message)s")
log = logging.getLogger(__name__)
log.setLevel(logging.DEBUG)
class TestOnError(TestCase):
def test_onerror(self):
def o(em):
try:
raise ValueError("42")
except ValueError:
print "GAGA"
em.onError(sys.exc_info())
rx.Observable.create(o) \
.doOnError(lambda e: log.debug("failed. good. %s" % str(e))) \
.subscribe(rx.LambdaObserver(on_error=lambda e: log.debug("cool. on_error fired"),
on_complete=lambda: self.fail("should fail")
))
def test_onerror_multiprocess(self):
main_pid = multiprocessing.current_process().pid
def o(em):
log.error(main_pid)
log.error(multiprocessing.current_process().pid)
assert main_pid != multiprocessing.current_process().pid
try:
raise ValueError("42")
except ValueError:
log.error("GAGA")
em.onError(sys.exc_info())
log.debug("hello")
d = rx.Observable.create(o) \
.doOnError(lambda e: log.debug("failed. good. %s" % str(e))) \
.subscribeOn(multiprocessing.Process) \
.subscribe(rx.LambdaObserver(on_error=lambda e: log.debug("cool. on_error fired"),
on_complete=lambda: self.fail("should fail")
))
print ("disp", d)
class TestObservable(TestCase):
def test_blockingSubscribe(self):
d = rx.Observable.from_(xrange(1, 4)).blockingSubscribe(
on_next=lambda i: sys.stdout.write("from=%s\n" % i),
on_complete=lambda: sys.stdout.write("!! complete\n")
)
print d
def test_play(self):
def ga(i):
while True:
log.debug("ga %s" % i)
time.sleep(1)
plist = []
for i in xrange(1, 5):
p = multiprocessing.Process(target=ga, args=(i,))
p.start()
plist.append(p)
for pp in plist:
print pp
pp.join()
print "PLAY"
def test_observeOn(self):
def emit(emitter):
"""
:type emitter: rx.ObservableEmitter
"""
emitter.setDisposable(rx.ActionDisposable(lambda: sys.stdout.write("disposed")))
for i in xrange(1, 30):
log.debug("emit %s" % i)
emitter.onNext(i)
time.sleep(1)
emitter.onComplete()
log.info("hello")
log.debug("main process is %s\n" % multiprocessing.current_process().pid)
o = rx.Observable.create(emit).observeOn(multiprocessing.Process)
d = o \
.doOnNext(lambda x: log.debug("doonnext=%s" % x)).map(lambda x: x * 10) \
.blockingSubscribe(on_next=lambda x: log.debug("subscribe x=%s" % x),
on_error=lambda e: log.error("onerror!!!!1111111"))
print "d=", d
# def test_subscribeOn(self):
# def emit(emitter):
# """
#
# :type emitter: rexpython.Emitter
# """
# for i in xrange(1, 40):
# log.debug("emit %s" % i)
# emitter.onNext(i)
# time.sleep(1)
#
# o = rx.Observable.create(emit).doOnNext(lambda x: log.debug("doonnext=%s" % x))
# d = o.subscribeOn(multiprocessing.Process).subscribe(
# rx.LambdaObserver(on_next=lambda x: log.debug("subscribe x=%s" % x)))
# print "d=", d
|
mit
|
[
646,
2050,
199,
646,
12866,
199,
646,
984,
199,
646,
900,
199,
504,
2882,
492,
7640,
199,
199,
646,
295,
88,
1548,
465,
12951,
199,
199,
4806,
14,
19602,
8,
908,
17662,
18331,
7216,
1046,
83,
2818,
354,
7216,
821,
83,
2818,
20056,
9,
83,
2818,
1412,
9,
68,
2818,
1188,
9,
83,
531,
199,
199,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
793,
14,
13548,
8,
4806,
14,
5287,
9,
421,
199,
533,
1379,
3314,
547,
8,
1746,
304,
272,
347,
511,
63,
265,
705,
8,
277,
304,
267,
347,
312,
8,
5633,
304,
288,
862,
26,
355,
746,
1722,
480,
2260,
531,
288,
871,
1722,
26,
355,
870,
298,
39,
1254,
33,
2,
355,
18564,
14,
265,
547,
8,
1274,
14,
2804,
63,
815,
1012,
398,
12951,
14,
11394,
29454,
14,
981,
8,
79,
9,
971,
288,
1275,
1117,
3314,
547,
8,
2734,
325,
26,
943,
14,
1757,
480,
4892,
14,
6954,
14,
450,
83,
2,
450,
620,
8,
69,
1724,
971,
288,
1275,
10108,
8,
6872,
14,
21350,
22715,
8,
265,
63,
705,
29,
2734,
325,
26,
943,
14,
1757,
480,
18499,
14,
641,
63,
705,
31974,
1288,
1460,
641,
63,
4883,
29,
2734,
26,
291,
14,
1633,
480,
5626,
2449,
531,
1460,
5082,
339,
347,
511,
63,
265,
705,
63,
3029,
1412,
8,
277,
304,
267,
2446,
63,
3150,
275,
12866,
14,
1818,
63,
1412,
1252,
3150,
398,
347,
312,
8,
5633,
304,
288,
943,
14,
705,
8,
973,
63,
3150,
9,
288,
943,
14,
705,
8,
25725,
14,
1818,
63,
1412,
1252,
3150,
9,
288,
702,
2446,
63,
3150,
1137,
12866,
14,
1818,
63,
1412,
1252,
3150,
953,
862,
26,
355,
746,
1722,
480,
2260,
531,
288,
871,
1722,
26,
355,
943,
14,
705,
480,
39,
1254,
33,
531,
355,
18564,
14,
265,
547,
8,
1274,
14,
2804,
63,
815,
1012,
398,
943,
14,
1757,
480,
5006,
531,
398,
366,
275,
12951,
14,
11394,
29454,
14,
981,
8,
79,
9,
971,
288,
1275,
1117,
3314,
547,
8,
2734,
325,
26,
943,
14,
1757,
480,
4892,
14,
6954,
14,
450,
83,
2,
450,
620,
8,
69,
1724,
971,
288,
1275,
10108,
3314,
8,
25725,
14,
3498,
9,
971,
288,
1275,
10108,
8,
6872,
14,
21350,
22715,
8,
265,
63,
705,
29,
2734,
325,
26,
943,
14,
1757,
480,
18499,
14,
641,
63,
705,
31974,
1288,
1460,
641,
63,
4883,
29,
2734,
26,
291,
14,
1633,
480,
5626,
2449,
531,
1460,
5082,
267,
870,
1689,
13654,
401,
366,
9,
339,
1021,
1379,
11394,
29454,
8,
1746,
304,
267,
347,
511,
63,
13091,
2610,
5355,
8,
277,
304,
288,
366,
275,
12951,
14,
11394,
29454,
14,
504,
2531,
21120,
8,
17,
12,
841,
4992,
13091,
2610,
5355,
8,
355,
641,
63,
2184,
29,
2734,
284,
26,
984,
14,
2703,
14,
952,
480,
504,
2458,
83,
60,
78,
2,
450,
284,
395,
355,
641,
63,
4883,
29,
2734,
26,
984,
14,
2703,
14,
952,
480,
3480,
4890,
60,
78,
531,
288,
776,
953,
870,
366,
398,
347,
511,
63,
2802,
8,
277,
304,
288,
347,
16072,
8,
73,
304,
355,
1830,
715,
26,
490,
943,
14,
1757,
480,
5294,
450,
83,
2,
450,
284,
9,
490,
900,
14,
4532,
8,
17,
9,
953,
14459,
275,
942,
288,
367,
284,
315,
4945,
8,
17,
12,
959,
304,
355,
299,
275,
12866,
14,
3498,
8,
1375,
29,
5294,
12,
1249,
2687,
73,
4641,
355,
299,
14,
928,
342,
2234,
14459,
14,
740,
8,
80,
9,
953,
367,
11618,
315,
14459,
26,
355,
870,
11618,
355,
11618,
14,
904,
342,
953,
870,
298,
11625,
2,
398,
347,
511,
63,
2873,
4909,
3314,
8,
277,
304,
288,
347,
8689,
8,
8159,
351,
304,
355,
408,
1362,
355,
520,
466,
8689,
351,
26,
12951,
14,
11394,
29454,
37,
22541,
355,
408,
2234,
8689,
351,
14,
409,
2825,
1712,
461,
8,
6872,
14,
3310,
2825,
1712,
461,
8,
2734,
26,
984,
14,
2703,
14,
952,
480,
2297,
5824,
13324,
355,
367,
284,
315,
4945,
8,
17,
12,
4233,
304,
490,
943,
14,
1757,
480,
8159,
450,
83,
2,
450,
284,
9,
490,
8689,
351,
14,
265,
5765,
8,
73,
9,
490,
900,
14,
4532,
8,
17,
9,
355,
8689,
351,
14,
265,
14175,
342,
953,
943,
14,
815,
480,
5006,
531,
288,
943,
14,
1757,
480,
973,
2112,
365,
450,
83,
60,
78,
2,
450,
12866,
14,
1818,
63,
1412,
1252,
3150,
9,
288,
312,
275,
12951,
14,
11394,
29454,
14,
981,
8,
8159,
680,
2873,
4909,
3314,
8,
25725,
14,
3498,
9,
288,
366,
275,
312,
971,
355,
1275,
1117,
3314,
5765,
8,
2734,
671,
26,
943,
14,
1757,
480,
1117,
265,
2184,
2458,
83,
2,
450,
671,
4992,
1130,
8,
2734,
671,
26,
671,
627,
1616,
9,
971,
355,
1275,
13091,
2610,
5355,
8,
265,
63,
2184,
29,
2734,
671,
26,
943,
14,
1757,
480,
10108,
671,
2458,
83,
2,
450,
671,
395,
3521,
641,
63,
705,
29,
2734,
325,
26,
943,
14,
705,
480,
265,
705,
6386,
6984,
6673,
2237,
953,
870,
298,
68,
11107,
366,
953,
327,
347,
511,
63,
10108,
3314,
8,
277,
304,
288,
327,
258,
347,
8689,
8,
8159,
351,
304,
288,
327,
260,
408,
288,
327,
288,
327,
260,
520,
466,
8689,
351,
26,
295,
88,
1548,
14,
37,
22541,
288,
327,
260,
408,
288,
327,
260,
367,
284,
315,
4945,
8,
17,
12,
6335,
304,
288,
327,
3777,
943,
14,
1757,
480,
8159,
450,
83,
2,
450,
284,
9,
288,
327,
3777,
8689,
351,
14,
265,
5765,
8,
73,
9,
288,
327,
3777,
900,
14,
4532,
8,
17,
9,
288,
327,
288,
327,
258,
312,
275,
12951,
14,
11394,
29454,
14,
981,
8,
8159,
680,
1117,
3314,
5765,
8,
2734,
671,
26,
943,
14,
1757,
480,
1117,
265,
2184,
2458,
83,
2,
450,
671,
430,
288,
327,
258,
366,
275,
312,
14,
10108,
3314,
8,
25725,
14,
3498,
680,
10108,
8,
288,
327,
260,
12951,
14,
21350,
22715,
8,
265,
63,
2184,
29,
2734,
671,
26,
943,
14,
1757,
480,
10108,
671,
2458,
83,
2,
450,
671,
1724,
288,
327,
258,
870,
298,
68,
11107,
366,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2050,
199,
646,
12866,
199,
646,
984,
199,
646,
900,
199,
504,
2882,
492,
7640,
199,
199,
646,
295,
88,
1548,
465,
12951,
199,
199,
4806,
14,
19602,
8,
908,
17662,
18331,
7216,
1046,
83,
2818,
354,
7216,
821,
83,
2818,
20056,
9,
83,
2818,
1412,
9,
68,
2818,
1188,
9,
83,
531,
199,
199,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
793,
14,
13548,
8,
4806,
14,
5287,
9,
421,
199,
533,
1379,
3314,
547,
8,
1746,
304,
272,
347,
511,
63,
265,
705,
8,
277,
304,
267,
347,
312,
8,
5633,
304,
288,
862,
26,
355,
746,
1722,
480,
2260,
531,
288,
871,
1722,
26,
355,
870,
298,
39,
1254,
33,
2,
355,
18564,
14,
265,
547,
8,
1274,
14,
2804,
63,
815,
1012,
398,
12951,
14,
11394,
29454,
14,
981,
8,
79,
9,
971,
288,
1275,
1117,
3314,
547,
8,
2734,
325,
26,
943,
14,
1757,
480,
4892,
14,
6954,
14,
450,
83,
2,
450,
620,
8,
69,
1724,
971,
288,
1275,
10108,
8,
6872,
14,
21350,
22715,
8,
265,
63,
705,
29,
2734,
325,
26,
943,
14,
1757,
480,
18499,
14,
641,
63,
705,
31974,
1288,
1460,
641,
63,
4883,
29,
2734,
26,
291,
14,
1633,
480,
5626,
2449,
531,
1460,
5082,
339,
347,
511,
63,
265,
705,
63,
3029,
1412,
8,
277,
304,
267,
2446,
63,
3150,
275,
12866,
14,
1818,
63,
1412,
1252,
3150,
398,
347,
312,
8,
5633,
304,
288,
943,
14,
705,
8,
973,
63,
3150,
9,
288,
943,
14,
705,
8,
25725,
14,
1818,
63,
1412,
1252,
3150,
9,
288,
702,
2446,
63,
3150,
1137,
12866,
14,
1818,
63,
1412,
1252,
3150,
953,
862,
26,
355,
746,
1722,
480,
2260,
531,
288,
871,
1722,
26,
355,
943,
14,
705,
480,
39,
1254,
33,
531,
355,
18564,
14,
265,
547,
8,
1274,
14,
2804,
63,
815,
1012,
398,
943,
14,
1757,
480,
5006,
531,
398,
366,
275,
12951,
14,
11394,
29454,
14,
981,
8,
79,
9,
971,
288,
1275,
1117,
3314,
547,
8,
2734,
325,
26,
943,
14,
1757,
480,
4892,
14,
6954,
14,
450,
83,
2,
450,
620,
8,
69,
1724,
971,
288,
1275,
10108,
3314,
8,
25725,
14,
3498,
9,
971,
288,
1275,
10108,
8,
6872,
14,
21350,
22715,
8,
265,
63,
705,
29,
2734,
325,
26,
943,
14,
1757,
480,
18499,
14,
641,
63,
705,
31974,
1288,
1460,
641,
63,
4883,
29,
2734,
26,
291,
14,
1633,
480,
5626,
2449,
531,
1460,
5082,
267,
870,
1689,
13654,
401,
366,
9,
339,
1021,
1379,
11394,
29454,
8,
1746,
304,
267,
347,
511,
63,
13091,
2610,
5355,
8,
277,
304,
288,
366,
275,
12951,
14,
11394,
29454,
14,
504,
2531,
21120,
8,
17,
12,
841,
4992,
13091,
2610,
5355,
8,
355,
641,
63,
2184,
29,
2734,
284,
26,
984,
14,
2703,
14,
952,
480,
504,
2458,
83,
60,
78,
2,
450,
284,
395,
355,
641,
63,
4883,
29,
2734,
26,
984,
14,
2703,
14,
952,
480,
3480,
4890,
60,
78,
531,
288,
776,
953,
870,
366,
398,
347,
511,
63,
2802,
8,
277,
304,
288,
347,
16072,
8,
73,
304,
355,
1830,
715,
26,
490,
943,
14,
1757,
480,
5294,
450,
83,
2,
450,
284,
9,
490,
900,
14,
4532,
8,
17,
9,
953,
14459,
275,
942,
288,
367,
284,
315,
4945,
8,
17,
12,
959,
304,
355,
299,
275,
12866,
14,
3498,
8,
1375,
29,
5294,
12,
1249,
2687,
73,
4641,
355,
299,
14,
928,
342,
2234,
14459,
14,
740,
8,
80,
9,
953,
367,
11618,
315,
14459,
26,
355,
870,
11618,
355,
11618,
14,
904,
342,
953,
870,
298,
11625,
2,
398,
347,
511,
63,
2873,
4909,
3314,
8,
277,
304,
288,
347,
8689,
8,
8159,
351,
304,
355,
408,
1362,
355,
520,
466,
8689,
351,
26,
12951,
14,
11394,
29454,
37,
22541,
355,
408,
2234,
8689,
351,
14,
409,
2825,
1712,
461,
8,
6872,
14,
3310,
2825,
1712,
461,
8,
2734,
26,
984,
14,
2703,
14,
952,
480,
2297,
5824,
13324,
355,
367,
284,
315,
4945,
8,
17,
12,
4233,
304,
490,
943,
14,
1757,
480,
8159,
450,
83,
2,
450,
284,
9,
490,
8689,
351,
14,
265,
5765,
8,
73,
9,
490,
900,
14,
4532,
8,
17,
9,
355,
8689,
351,
14,
265,
14175,
342,
953,
943,
14,
815,
480,
5006,
531,
288,
943,
14,
1757,
480,
973,
2112,
365,
450,
83,
60,
78,
2,
450,
12866,
14,
1818,
63,
1412,
1252,
3150,
9,
288,
312,
275,
12951,
14,
11394,
29454,
14,
981,
8,
8159,
680,
2873,
4909,
3314,
8,
25725,
14,
3498,
9,
288,
366,
275,
312,
971,
355,
1275,
1117,
3314,
5765,
8,
2734,
671,
26,
943,
14,
1757,
480,
1117,
265,
2184,
2458,
83,
2,
450,
671,
4992,
1130,
8,
2734,
671,
26,
671,
627,
1616,
9,
971,
355,
1275,
13091,
2610,
5355,
8,
265,
63,
2184,
29,
2734,
671,
26,
943,
14,
1757,
480,
10108,
671,
2458,
83,
2,
450,
671,
395,
3521,
641,
63,
705,
29,
2734,
325,
26,
943,
14,
705,
480,
265,
705,
6386,
6984,
6673,
2237,
953,
870,
298,
68,
11107,
366,
953,
327,
347,
511,
63,
10108,
3314,
8,
277,
304,
288,
327,
258,
347,
8689,
8,
8159,
351,
304,
288,
327,
260,
408,
288,
327,
288,
327,
260,
520,
466,
8689,
351,
26,
295,
88,
1548,
14,
37,
22541,
288,
327,
260,
408,
288,
327,
260,
367,
284,
315,
4945,
8,
17,
12,
6335,
304,
288,
327,
3777,
943,
14,
1757,
480,
8159,
450,
83,
2,
450,
284,
9,
288,
327,
3777,
8689,
351,
14,
265,
5765,
8,
73,
9,
288,
327,
3777,
900,
14,
4532,
8,
17,
9,
288,
327,
288,
327,
258,
312,
275,
12951,
14,
11394,
29454,
14,
981,
8,
8159,
680,
1117,
3314,
5765,
8,
2734,
671,
26,
943,
14,
1757,
480,
1117,
265,
2184,
2458,
83,
2,
450,
671,
430,
288,
327,
258,
366,
275,
312,
14,
10108,
3314,
8,
25725,
14,
3498,
680,
10108,
8,
288,
327,
260,
12951,
14,
21350,
22715,
8,
265,
63,
2184,
29,
2734,
671,
26,
943,
14,
1757,
480,
10108,
671,
2458,
83,
2,
450,
671,
1724,
288,
327,
258,
870,
298,
68,
11107,
366,
199,
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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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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
sheppard/django-rest-framework
|
tests/test_description.py
|
79
|
3688
|
# -- coding: utf-8 --
from __future__ import unicode_literals
from django.test import TestCase
from django.utils.encoding import python_2_unicode_compatible, smart_text
from rest_framework.compat import apply_markdown
from rest_framework.views import APIView
from .description import (
UTF8_TEST_DOCSTRING, ViewWithNonASCIICharactersInDocstring
)
# We check that docstrings get nicely un-indented.
DESCRIPTION = """an example docstring
====================
* list
* list
another header
--------------
code block
indented
# hash style header #"""
# If markdown is installed we also test it's working
# (and that our wrapped forces '=' to h2 and '-' to h3)
# We support markdown < 2.1 and markdown >= 2.1
MARKED_DOWN_lt_21 = """<h2>an example docstring</h2>
<ul>
<li>list</li>
<li>list</li>
</ul>
<h3>another header</h3>
<pre><code>code block
</code></pre>
<p>indented</p>
<h2 id="hash_style_header">hash style header</h2>"""
MARKED_DOWN_gte_21 = """<h2 id="an-example-docstring">an example docstring</h2>
<ul>
<li>list</li>
<li>list</li>
</ul>
<h3 id="another-header">another header</h3>
<pre><code>code block
</code></pre>
<p>indented</p>
<h2 id="hash-style-header">hash style header</h2>"""
class TestViewNamesAndDescriptions(TestCase):
def test_view_name_uses_class_name(self):
"""
Ensure view names are based on the class name.
"""
class MockView(APIView):
pass
self.assertEqual(MockView().get_view_name(), 'Mock')
def test_view_description_uses_docstring(self):
"""Ensure view descriptions are based on the docstring."""
class MockView(APIView):
"""an example docstring
====================
* list
* list
another header
--------------
code block
indented
# hash style header #"""
self.assertEqual(MockView().get_view_description(), DESCRIPTION)
def test_view_description_supports_unicode(self):
"""
Unicode in docstrings should be respected.
"""
self.assertEqual(
ViewWithNonASCIICharactersInDocstring().get_view_description(),
smart_text(UTF8_TEST_DOCSTRING)
)
def test_view_description_can_be_empty(self):
"""
Ensure that if a view has no docstring,
then it's description is the empty string.
"""
class MockView(APIView):
pass
self.assertEqual(MockView().get_view_description(), '')
def test_view_description_can_be_promise(self):
"""
Ensure a view may have a docstring that is actually a lazily evaluated
class that can be converted to a string.
See: https://github.com/tomchristie/django-rest-framework/issues/1708
"""
# use a mock object instead of gettext_lazy to ensure that we can't end
# up with a test case string in our l10n catalog
@python_2_unicode_compatible
class MockLazyStr(object):
def __init__(self, string):
self.s = string
def __str__(self):
return self.s
class MockView(APIView):
__doc__ = MockLazyStr("a gettext string")
self.assertEqual(MockView().get_view_description(), 'a gettext string')
def test_markdown(self):
"""
Ensure markdown to HTML works as expected.
"""
if apply_markdown:
gte_21_match = apply_markdown(DESCRIPTION) == MARKED_DOWN_gte_21
lt_21_match = apply_markdown(DESCRIPTION) == MARKED_DOWN_lt_21
self.assertTrue(gte_21_match or lt_21_match)
|
bsd-2-clause
|
[
3,
1553,
2803,
26,
2774,
13,
24,
1553,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
396,
492,
7640,
199,
504,
1639,
14,
1208,
14,
2991,
492,
2366,
63,
18,
63,
2975,
63,
6490,
12,
11179,
63,
505,
199,
199,
504,
4618,
63,
4857,
14,
5819,
492,
4838,
63,
15653,
199,
504,
4618,
63,
4857,
14,
4196,
492,
3261,
2768,
199,
199,
504,
1275,
1802,
492,
334,
272,
9094,
24,
63,
2864,
63,
16618,
5353,
12,
10935,
3007,
6932,
1179,
3553,
948,
8210,
7421,
607,
3768,
875,
199,
9,
421,
199,
3,
2136,
1104,
626,
20964,
664,
14213,
590,
625,
13,
29656,
14,
199,
17705,
275,
408,
290,
2893,
9214,
199,
1280,
532,
199,
199,
10,
769,
199,
10,
769,
199,
199,
13565,
1406,
199,
10965,
339,
1233,
1853,
199,
199,
29656,
199,
199,
3,
2631,
3449,
1406,
327,
624,
199,
199,
3,
982,
18502,
365,
4903,
781,
2597,
511,
652,
1159,
6449,
199,
3,
334,
460,
626,
4154,
8072,
25983,
14051,
370,
394,
18,
436,
10791,
370,
394,
19,
9,
199,
199,
3,
2136,
2291,
18502,
665,
499,
14,
17,
436,
18502,
2356,
499,
14,
17,
199,
10520,
1149,
63,
8819,
63,
4116,
63,
2025,
275,
8894,
72,
18,
30,
290,
2893,
9214,
1108,
72,
18,
30,
199,
28,
348,
30,
199,
28,
317,
30,
513,
1108,
317,
30,
199,
28,
317,
30,
513,
1108,
317,
30,
199,
1108,
348,
30,
199,
28,
72,
19,
30,
13565,
1406,
1108,
72,
19,
30,
199,
28,
657,
2535,
600,
30,
600,
1853,
199,
1108,
600,
2957,
657,
30,
199,
28,
80,
30,
29656,
1108,
80,
30,
199,
28,
72,
18,
1305,
628,
2227,
63,
2487,
63,
1291,
1743,
2227,
3449,
1406,
1108,
72,
18,
11193,
199,
199,
10520,
1149,
63,
8819,
63,
19586,
63,
2025,
275,
8894,
72,
18,
1305,
628,
290,
13,
2694,
13,
12485,
1743,
290,
2893,
9214,
1108,
72,
18,
30,
199,
28,
348,
30,
199,
28,
317,
30,
513,
1108,
317,
30,
199,
28,
317,
30,
513,
1108,
317,
30,
199,
1108,
348,
30,
199,
28,
72,
19,
1305,
628,
13565,
13,
1291,
1743,
13565,
1406,
1108,
72,
19,
30,
199,
28,
657,
2535,
600,
30,
600,
1853,
199,
1108,
600,
2957,
657,
30,
199,
28,
80,
30,
29656,
1108,
80,
30,
199,
28,
72,
18,
1305,
628,
2227,
13,
2487,
13,
1291,
1743,
2227,
3449,
1406,
1108,
72,
18,
11193,
421,
199,
533,
1379,
2768,
5866,
3325,
5831,
83,
8,
1746,
304,
272,
347,
511,
63,
1345,
63,
354,
63,
5589,
63,
533,
63,
354,
8,
277,
304,
267,
408,
267,
7523,
2455,
1561,
787,
4079,
641,
314,
1021,
536,
14,
267,
408,
267,
1021,
4420,
2768,
8,
25778,
304,
288,
986,
267,
291,
14,
629,
8,
3346,
2768,
1252,
362,
63,
1345,
63,
354,
1062,
283,
3346,
358,
339,
347,
511,
63,
1345,
63,
1802,
63,
5589,
63,
12485,
8,
277,
304,
267,
408,
13913,
2455,
18714,
787,
4079,
641,
314,
9214,
1041,
267,
1021,
4420,
2768,
8,
25778,
304,
288,
408,
290,
2893,
9214,
288,
16248,
5918,
953,
627,
769,
288,
627,
769,
953,
4573,
1406,
288,
3001,
8648,
2234,
1233,
1853,
953,
19197,
953,
327,
2631,
3449,
1406,
327,
624,
398,
291,
14,
629,
8,
3346,
2768,
1252,
362,
63,
1345,
63,
1802,
1062,
17410,
1075,
9,
339,
347,
511,
63,
1345,
63,
1802,
63,
9823,
63,
2975,
8,
277,
304,
267,
408,
267,
6140,
315,
20964,
1077,
506,
522,
1043,
14,
267,
408,
398,
291,
14,
629,
8,
288,
10935,
3007,
6932,
1179,
3553,
948,
8210,
7421,
607,
3768,
875,
1252,
362,
63,
1345,
63,
1802,
1062,
288,
11179,
63,
505,
8,
6610,
24,
63,
2864,
63,
16618,
5353,
9,
267,
776,
339,
347,
511,
63,
1345,
63,
1802,
63,
2425,
63,
1235,
63,
1667,
8,
277,
304,
267,
408,
267,
7523,
626,
340,
282,
2455,
965,
949,
9214,
12,
267,
2066,
652,
1159,
1369,
365,
314,
2701,
1059,
14,
267,
408,
267,
1021,
4420,
2768,
8,
25778,
304,
288,
986,
267,
291,
14,
629,
8,
3346,
2768,
1252,
362,
63,
1345,
63,
1802,
1062,
4074,
339,
347,
511,
63,
1345,
63,
1802,
63,
2425,
63,
1235,
63,
12741,
572,
8,
277,
304,
267,
408,
267,
7523,
282,
2455,
1443,
1172,
282,
9214,
626,
365,
5965,
282,
29667,
3444,
13006,
267,
1021,
626,
883,
506,
6702,
370,
282,
1059,
14,
398,
1666,
26,
4178,
921,
5031,
14,
957,
15,
3151,
335,
18824,
1873,
15,
1176,
13,
3911,
13,
4857,
15,
10115,
15,
1196,
2036,
267,
408,
267,
327,
675,
282,
1683,
909,
3140,
402,
9796,
63,
6395,
370,
4868,
626,
781,
883,
1133,
1284,
267,
327,
1536,
543,
282,
511,
1930,
1059,
315,
4154,
634,
709,
78,
10594,
267,
768,
1548,
63,
18,
63,
2975,
63,
6490,
267,
1021,
4420,
14269,
2848,
8,
785,
304,
288,
347,
636,
826,
721,
277,
12,
1059,
304,
355,
291,
14,
83,
275,
1059,
953,
347,
636,
495,
721,
277,
304,
355,
372,
291,
14,
83,
398,
1021,
4420,
2768,
8,
25778,
304,
288,
636,
1301,
363,
275,
4420,
14269,
2848,
480,
65,
9796,
1059,
531,
398,
291,
14,
629,
8,
3346,
2768,
1252,
362,
63,
1345,
63,
1802,
1062,
283,
65,
9796,
1059,
358,
339,
347,
511,
63,
15653,
8,
277,
304,
267,
408,
267,
7523,
18502,
370,
4163,
5419,
465,
1420,
14,
267,
408,
267,
340,
4838,
63,
15653,
26,
288,
486,
266,
63,
2025,
63,
1431,
275,
4838,
63,
15653,
8,
17705,
9,
508,
8132,
1149,
63,
8819,
63,
19586,
63,
2025,
288,
22146,
63,
2025,
63,
1431,
275,
4838,
63,
15653,
8,
17705,
9,
508,
8132,
1149,
63,
8819,
63,
4116,
63,
2025,
288,
291,
14,
1815,
8,
19586,
63,
2025,
63,
1431,
503,
22146,
63,
2025,
63,
1431,
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
] |
[
1553,
2803,
26,
2774,
13,
24,
1553,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
396,
492,
7640,
199,
504,
1639,
14,
1208,
14,
2991,
492,
2366,
63,
18,
63,
2975,
63,
6490,
12,
11179,
63,
505,
199,
199,
504,
4618,
63,
4857,
14,
5819,
492,
4838,
63,
15653,
199,
504,
4618,
63,
4857,
14,
4196,
492,
3261,
2768,
199,
199,
504,
1275,
1802,
492,
334,
272,
9094,
24,
63,
2864,
63,
16618,
5353,
12,
10935,
3007,
6932,
1179,
3553,
948,
8210,
7421,
607,
3768,
875,
199,
9,
421,
199,
3,
2136,
1104,
626,
20964,
664,
14213,
590,
625,
13,
29656,
14,
199,
17705,
275,
408,
290,
2893,
9214,
199,
1280,
532,
199,
199,
10,
769,
199,
10,
769,
199,
199,
13565,
1406,
199,
10965,
339,
1233,
1853,
199,
199,
29656,
199,
199,
3,
2631,
3449,
1406,
327,
624,
199,
199,
3,
982,
18502,
365,
4903,
781,
2597,
511,
652,
1159,
6449,
199,
3,
334,
460,
626,
4154,
8072,
25983,
14051,
370,
394,
18,
436,
10791,
370,
394,
19,
9,
199,
199,
3,
2136,
2291,
18502,
665,
499,
14,
17,
436,
18502,
2356,
499,
14,
17,
199,
10520,
1149,
63,
8819,
63,
4116,
63,
2025,
275,
8894,
72,
18,
30,
290,
2893,
9214,
1108,
72,
18,
30,
199,
28,
348,
30,
199,
28,
317,
30,
513,
1108,
317,
30,
199,
28,
317,
30,
513,
1108,
317,
30,
199,
1108,
348,
30,
199,
28,
72,
19,
30,
13565,
1406,
1108,
72,
19,
30,
199,
28,
657,
2535,
600,
30,
600,
1853,
199,
1108,
600,
2957,
657,
30,
199,
28,
80,
30,
29656,
1108,
80,
30,
199,
28,
72,
18,
1305,
628,
2227,
63,
2487,
63,
1291,
1743,
2227,
3449,
1406,
1108,
72,
18,
11193,
199,
199,
10520,
1149,
63,
8819,
63,
19586,
63,
2025,
275,
8894,
72,
18,
1305,
628,
290,
13,
2694,
13,
12485,
1743,
290,
2893,
9214,
1108,
72,
18,
30,
199,
28,
348,
30,
199,
28,
317,
30,
513,
1108,
317,
30,
199,
28,
317,
30,
513,
1108,
317,
30,
199,
1108,
348,
30,
199,
28,
72,
19,
1305,
628,
13565,
13,
1291,
1743,
13565,
1406,
1108,
72,
19,
30,
199,
28,
657,
2535,
600,
30,
600,
1853,
199,
1108,
600,
2957,
657,
30,
199,
28,
80,
30,
29656,
1108,
80,
30,
199,
28,
72,
18,
1305,
628,
2227,
13,
2487,
13,
1291,
1743,
2227,
3449,
1406,
1108,
72,
18,
11193,
421,
199,
533,
1379,
2768,
5866,
3325,
5831,
83,
8,
1746,
304,
272,
347,
511,
63,
1345,
63,
354,
63,
5589,
63,
533,
63,
354,
8,
277,
304,
267,
408,
267,
7523,
2455,
1561,
787,
4079,
641,
314,
1021,
536,
14,
267,
408,
267,
1021,
4420,
2768,
8,
25778,
304,
288,
986,
267,
291,
14,
629,
8,
3346,
2768,
1252,
362,
63,
1345,
63,
354,
1062,
283,
3346,
358,
339,
347,
511,
63,
1345,
63,
1802,
63,
5589,
63,
12485,
8,
277,
304,
267,
408,
13913,
2455,
18714,
787,
4079,
641,
314,
9214,
1041,
267,
1021,
4420,
2768,
8,
25778,
304,
288,
408,
290,
2893,
9214,
288,
16248,
5918,
953,
627,
769,
288,
627,
769,
953,
4573,
1406,
288,
3001,
8648,
2234,
1233,
1853,
953,
19197,
953,
327,
2631,
3449,
1406,
327,
624,
398,
291,
14,
629,
8,
3346,
2768,
1252,
362,
63,
1345,
63,
1802,
1062,
17410,
1075,
9,
339,
347,
511,
63,
1345,
63,
1802,
63,
9823,
63,
2975,
8,
277,
304,
267,
408,
267,
6140,
315,
20964,
1077,
506,
522,
1043,
14,
267,
408,
398,
291,
14,
629,
8,
288,
10935,
3007,
6932,
1179,
3553,
948,
8210,
7421,
607,
3768,
875,
1252,
362,
63,
1345,
63,
1802,
1062,
288,
11179,
63,
505,
8,
6610,
24,
63,
2864,
63,
16618,
5353,
9,
267,
776,
339,
347,
511,
63,
1345,
63,
1802,
63,
2425,
63,
1235,
63,
1667,
8,
277,
304,
267,
408,
267,
7523,
626,
340,
282,
2455,
965,
949,
9214,
12,
267,
2066,
652,
1159,
1369,
365,
314,
2701,
1059,
14,
267,
408,
267,
1021,
4420,
2768,
8,
25778,
304,
288,
986,
267,
291,
14,
629,
8,
3346,
2768,
1252,
362,
63,
1345,
63,
1802,
1062,
4074,
339,
347,
511,
63,
1345,
63,
1802,
63,
2425,
63,
1235,
63,
12741,
572,
8,
277,
304,
267,
408,
267,
7523,
282,
2455,
1443,
1172,
282,
9214,
626,
365,
5965,
282,
29667,
3444,
13006,
267,
1021,
626,
883,
506,
6702,
370,
282,
1059,
14,
398,
1666,
26,
4178,
921,
5031,
14,
957,
15,
3151,
335,
18824,
1873,
15,
1176,
13,
3911,
13,
4857,
15,
10115,
15,
1196,
2036,
267,
408,
267,
327,
675,
282,
1683,
909,
3140,
402,
9796,
63,
6395,
370,
4868,
626,
781,
883,
1133,
1284,
267,
327,
1536,
543,
282,
511,
1930,
1059,
315,
4154,
634,
709,
78,
10594,
267,
768,
1548,
63,
18,
63,
2975,
63,
6490,
267,
1021,
4420,
14269,
2848,
8,
785,
304,
288,
347,
636,
826,
721,
277,
12,
1059,
304,
355,
291,
14,
83,
275,
1059,
953,
347,
636,
495,
721,
277,
304,
355,
372,
291,
14,
83,
398,
1021,
4420,
2768,
8,
25778,
304,
288,
636,
1301,
363,
275,
4420,
14269,
2848,
480,
65,
9796,
1059,
531,
398,
291,
14,
629,
8,
3346,
2768,
1252,
362,
63,
1345,
63,
1802,
1062,
283,
65,
9796,
1059,
358,
339,
347,
511,
63,
15653,
8,
277,
304,
267,
408,
267,
7523,
18502,
370,
4163,
5419,
465,
1420,
14,
267,
408,
267,
340,
4838,
63,
15653,
26,
288,
486,
266,
63,
2025,
63,
1431,
275,
4838,
63,
15653,
8,
17705,
9,
508,
8132,
1149,
63,
8819,
63,
19586,
63,
2025,
288,
22146,
63,
2025,
63,
1431,
275,
4838,
63,
15653,
8,
17705,
9,
508,
8132,
1149,
63,
8819,
63,
4116,
63,
2025,
288,
291,
14,
1815,
8,
19586,
63,
2025,
63,
1431,
503,
22146,
63,
2025,
63,
1431,
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,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
BigBrother1984/android_external_chromium_org
|
third_party/protobuf/python/stubout.py
|
671
|
4940
|
#!/usr/bin/python2.4
#
# Copyright 2008 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# This file is used for testing. The original is at:
# http://code.google.com/p/pymox/
class StubOutForTesting:
"""Sample Usage:
You want os.path.exists() to always return true during testing.
stubs = StubOutForTesting()
stubs.Set(os.path, 'exists', lambda x: 1)
...
stubs.UnsetAll()
The above changes os.path.exists into a lambda that returns 1. Once
the ... part of the code finishes, the UnsetAll() looks up the old value
of os.path.exists and restores it.
"""
def __init__(self):
self.cache = []
self.stubs = []
def __del__(self):
self.SmartUnsetAll()
self.UnsetAll()
def SmartSet(self, obj, attr_name, new_attr):
"""Replace obj.attr_name with new_attr. This method is smart and works
at the module, class, and instance level while preserving proper
inheritance. It will not stub out C types however unless that has been
explicitly allowed by the type.
This method supports the case where attr_name is a staticmethod or a
classmethod of obj.
Notes:
- If obj is an instance, then it is its class that will actually be
stubbed. Note that the method Set() does not do that: if obj is
an instance, it (and not its class) will be stubbed.
- The stubbing is using the builtin getattr and setattr. So, the __get__
and __set__ will be called when stubbing (TODO: A better idea would
probably be to manipulate obj.__dict__ instead of getattr() and
setattr()).
Raises AttributeError if the attribute cannot be found.
"""
if (inspect.ismodule(obj) or
(not inspect.isclass(obj) and obj.__dict__.has_key(attr_name))):
orig_obj = obj
orig_attr = getattr(obj, attr_name)
else:
if not inspect.isclass(obj):
mro = list(inspect.getmro(obj.__class__))
else:
mro = list(inspect.getmro(obj))
mro.reverse()
orig_attr = None
for cls in mro:
try:
orig_obj = cls
orig_attr = getattr(obj, attr_name)
except AttributeError:
continue
if orig_attr is None:
raise AttributeError("Attribute not found.")
# Calling getattr() on a staticmethod transforms it to a 'normal' function.
# We need to ensure that we put it back as a staticmethod.
old_attribute = obj.__dict__.get(attr_name)
if old_attribute is not None and isinstance(old_attribute, staticmethod):
orig_attr = staticmethod(orig_attr)
self.stubs.append((orig_obj, attr_name, orig_attr))
setattr(orig_obj, attr_name, new_attr)
def SmartUnsetAll(self):
"""Reverses all the SmartSet() calls, restoring things to their original
definition. Its okay to call SmartUnsetAll() repeatedly, as later calls
have no effect if no SmartSet() calls have been made.
"""
self.stubs.reverse()
for args in self.stubs:
setattr(*args)
self.stubs = []
def Set(self, parent, child_name, new_child):
"""Replace child_name's old definition with new_child, in the context
of the given parent. The parent could be a module when the child is a
function at module scope. Or the parent could be a class when a class'
method is being replaced. The named child is set to new_child, while
the prior definition is saved away for later, when UnsetAll() is called.
This method supports the case where child_name is a staticmethod or a
classmethod of parent.
"""
old_child = getattr(parent, child_name)
old_attribute = parent.__dict__.get(child_name)
if old_attribute is not None and isinstance(old_attribute, staticmethod):
old_child = staticmethod(old_child)
self.cache.append((parent, old_child, child_name))
setattr(parent, child_name, new_child)
def UnsetAll(self):
"""Reverses all the Set() calls, restoring things to their original
definition. Its okay to call UnsetAll() repeatedly, as later calls have
no effect if no Set() calls have been made.
"""
# Undo calls to Set() in reverse order, in case Set() was called on the
# same arguments repeatedly (want the original call to be last one undone)
self.cache.reverse()
for (parent, old_child, child_name) in self.cache:
setattr(parent, child_name, old_child)
self.cache = []
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1548,
18,
14,
20,
199,
3,
199,
3,
1898,
9079,
4475,
3277,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
420,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
3,
961,
570,
365,
1202,
367,
5343,
14,
221,
710,
3379,
365,
737,
26,
199,
3,
257,
1455,
921,
600,
14,
3098,
14,
957,
15,
80,
15,
647,
6625,
15,
199,
199,
533,
23429,
2204,
1858,
9029,
26,
523,
408,
8176,
11028,
26,
1362,
2047,
2934,
747,
14,
515,
14,
2444,
342,
370,
3544,
372,
2549,
5309,
5343,
14,
10813,
22312,
275,
23429,
2204,
1858,
9029,
342,
1362,
22312,
14,
1084,
8,
736,
14,
515,
12,
283,
2444,
297,
2400,
671,
26,
413,
9,
2126,
2263,
1362,
22312,
14,
1358,
409,
2422,
342,
10813,
710,
3432,
4493,
747,
14,
515,
14,
2444,
1901,
282,
2400,
626,
2529,
413,
14,
221,
19468,
1362,
314,
2263,
1777,
402,
314,
1233,
9578,
397,
12,
314,
1910,
409,
2422,
342,
10734,
1536,
314,
2269,
574,
1362,
402,
747,
14,
515,
14,
2444,
436,
4618,
7944,
652,
14,
819,
408,
523,
347,
636,
826,
721,
277,
304,
272,
291,
14,
1637,
275,
942,
272,
291,
14,
8957,
275,
942,
819,
347,
636,
2264,
721,
277,
304,
272,
291,
14,
29111,
1358,
409,
2422,
342,
272,
291,
14,
1358,
409,
2422,
342,
819,
347,
26017,
1084,
8,
277,
12,
1559,
12,
1921,
63,
354,
12,
892,
63,
962,
304,
272,
408,
11328,
1559,
14,
962,
63,
354,
543,
892,
63,
962,
14,
961,
1083,
365,
11179,
436,
5419,
2126,
737,
314,
859,
12,
1021,
12,
436,
1256,
2166,
1830,
876,
14717,
5576,
2126,
15433,
14,
2779,
911,
440,
10098,
734,
445,
2943,
13432,
7444,
626,
965,
2757,
2126,
7662,
4370,
701,
314,
730,
14,
10817,
961,
1083,
5171,
314,
1930,
2382,
1921,
63,
354,
365,
282,
12822,
503,
282,
2126,
18990,
402,
1559,
14,
10817,
8144,
26,
489,
446,
982,
1559,
365,
376,
1256,
12,
2066,
652,
365,
2399,
1021,
626,
911,
5965,
506,
267,
10098,
6123,
14,
3390,
626,
314,
1083,
2494,
342,
1630,
440,
886,
626,
26,
340,
1559,
365,
267,
376,
1256,
12,
652,
334,
460,
440,
2399,
1021,
9,
911,
506,
10098,
6123,
14,
489,
446,
710,
410,
9256,
316,
365,
1808,
314,
6762,
2519,
436,
5371,
14,
2002,
12,
314,
636,
362,
363,
267,
436,
636,
409,
363,
911,
506,
2797,
1380,
410,
9256,
316,
334,
11768,
26,
437,
8034,
16819,
3955,
267,
8646,
506,
370,
27232,
1559,
855,
807,
363,
3140,
402,
2519,
342,
436,
267,
5371,
8801,
10817,
6218,
4281,
340,
314,
2225,
3913,
506,
1911,
14,
272,
408,
272,
340,
334,
10955,
14,
374,
578,
8,
1113,
9,
503,
267,
334,
1397,
6485,
14,
28450,
8,
1113,
9,
436,
1559,
855,
807,
4343,
1989,
63,
498,
8,
962,
63,
354,
15206,
489,
2306,
63,
1113,
275,
1559,
489,
2306,
63,
962,
275,
2519,
8,
1113,
12,
1921,
63,
354,
9,
339,
587,
26,
489,
340,
440,
6485,
14,
28450,
8,
1113,
304,
267,
30866,
275,
769,
8,
10955,
14,
362,
17335,
8,
1113,
855,
533,
8964,
489,
587,
26,
267,
30866,
275,
769,
8,
10955,
14,
362,
17335,
8,
1113,
430,
2541,
30866,
14,
4471,
342,
2541,
2306,
63,
962,
275,
488,
2541,
367,
843,
315,
30866,
26,
267,
862,
26,
881,
2306,
63,
1113,
275,
843,
881,
2306,
63,
962,
275,
2519,
8,
1113,
12,
1921,
63,
354,
9,
267,
871,
4281,
26,
881,
1980,
339,
340,
2306,
63,
962,
365,
488,
26,
489,
746,
4281,
480,
1646,
440,
1911,
2685,
339,
327,
23892,
2519,
342,
641,
282,
12822,
18501,
652,
370,
282,
283,
3302,
7,
805,
14,
272,
327,
2136,
1929,
370,
4868,
626,
781,
5324,
652,
1771,
465,
282,
12822,
14,
272,
2269,
63,
3215,
275,
1559,
855,
807,
4343,
362,
8,
962,
63,
354,
9,
272,
340,
2269,
63,
3215,
365,
440,
488,
436,
1228,
8,
1753,
63,
3215,
12,
12822,
304,
489,
2306,
63,
962,
275,
12822,
8,
2981,
63,
962,
9,
339,
291,
14,
8957,
14,
740,
1332,
2981,
63,
1113,
12,
1921,
63,
354,
12,
2306,
63,
962,
430,
272,
5371,
8,
2981,
63,
1113,
12,
1921,
63,
354,
12,
892,
63,
962,
9,
819,
347,
26017,
1358,
409,
2422,
8,
277,
304,
272,
408,
497,
422,
874,
1006,
314,
26017,
1084,
342,
4882,
12,
4618,
6854,
7645,
370,
3932,
3379,
272,
5492,
14,
221,
22940,
5849,
370,
1240,
26017,
1358,
409,
2422,
342,
27714,
12,
465,
2945,
4882,
272,
1172,
949,
7763,
340,
949,
26017,
1084,
342,
4882,
1172,
2757,
6326,
14,
339,
408,
272,
291,
14,
8957,
14,
4471,
342,
339,
367,
1249,
315,
291,
14,
8957,
26,
489,
5371,
2031,
589,
9,
339,
291,
14,
8957,
275,
942,
819,
347,
2494,
8,
277,
12,
1676,
12,
1982,
63,
354,
12,
892,
63,
1739,
304,
272,
408,
11328,
1982,
63,
354,
1159,
2269,
5492,
543,
892,
63,
1739,
12,
315,
314,
1067,
272,
402,
314,
1627,
1676,
14,
221,
710,
1676,
4293,
506,
282,
859,
1380,
314,
1982,
365,
282,
272,
805,
737,
859,
4194,
14,
221,
4236,
314,
1676,
4293,
506,
282,
1021,
1380,
282,
1021,
7,
272,
1083,
365,
3769,
8717,
14,
221,
710,
4310,
1982,
365,
663,
370,
892,
63,
1739,
12,
1830,
272,
314,
6791,
5492,
365,
6290,
13437,
367,
2945,
12,
1380,
1910,
409,
2422,
342,
365,
2797,
14,
339,
961,
1083,
5171,
314,
1930,
2382,
1982,
63,
354,
365,
282,
12822,
503,
282,
272,
18990,
402
] |
[
2647,
15,
1393,
15,
1548,
18,
14,
20,
199,
3,
199,
3,
1898,
9079,
4475,
3277,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
420,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
3,
961,
570,
365,
1202,
367,
5343,
14,
221,
710,
3379,
365,
737,
26,
199,
3,
257,
1455,
921,
600,
14,
3098,
14,
957,
15,
80,
15,
647,
6625,
15,
199,
199,
533,
23429,
2204,
1858,
9029,
26,
523,
408,
8176,
11028,
26,
1362,
2047,
2934,
747,
14,
515,
14,
2444,
342,
370,
3544,
372,
2549,
5309,
5343,
14,
10813,
22312,
275,
23429,
2204,
1858,
9029,
342,
1362,
22312,
14,
1084,
8,
736,
14,
515,
12,
283,
2444,
297,
2400,
671,
26,
413,
9,
2126,
2263,
1362,
22312,
14,
1358,
409,
2422,
342,
10813,
710,
3432,
4493,
747,
14,
515,
14,
2444,
1901,
282,
2400,
626,
2529,
413,
14,
221,
19468,
1362,
314,
2263,
1777,
402,
314,
1233,
9578,
397,
12,
314,
1910,
409,
2422,
342,
10734,
1536,
314,
2269,
574,
1362,
402,
747,
14,
515,
14,
2444,
436,
4618,
7944,
652,
14,
819,
408,
523,
347,
636,
826,
721,
277,
304,
272,
291,
14,
1637,
275,
942,
272,
291,
14,
8957,
275,
942,
819,
347,
636,
2264,
721,
277,
304,
272,
291,
14,
29111,
1358,
409,
2422,
342,
272,
291,
14,
1358,
409,
2422,
342,
819,
347,
26017,
1084,
8,
277,
12,
1559,
12,
1921,
63,
354,
12,
892,
63,
962,
304,
272,
408,
11328,
1559,
14,
962,
63,
354,
543,
892,
63,
962,
14,
961,
1083,
365,
11179,
436,
5419,
2126,
737,
314,
859,
12,
1021,
12,
436,
1256,
2166,
1830,
876,
14717,
5576,
2126,
15433,
14,
2779,
911,
440,
10098,
734,
445,
2943,
13432,
7444,
626,
965,
2757,
2126,
7662,
4370,
701,
314,
730,
14,
10817,
961,
1083,
5171,
314,
1930,
2382,
1921,
63,
354,
365,
282,
12822,
503,
282,
2126,
18990,
402,
1559,
14,
10817,
8144,
26,
489,
446,
982,
1559,
365,
376,
1256,
12,
2066,
652,
365,
2399,
1021,
626,
911,
5965,
506,
267,
10098,
6123,
14,
3390,
626,
314,
1083,
2494,
342,
1630,
440,
886,
626,
26,
340,
1559,
365,
267,
376,
1256,
12,
652,
334,
460,
440,
2399,
1021,
9,
911,
506,
10098,
6123,
14,
489,
446,
710,
410,
9256,
316,
365,
1808,
314,
6762,
2519,
436,
5371,
14,
2002,
12,
314,
636,
362,
363,
267,
436,
636,
409,
363,
911,
506,
2797,
1380,
410,
9256,
316,
334,
11768,
26,
437,
8034,
16819,
3955,
267,
8646,
506,
370,
27232,
1559,
855,
807,
363,
3140,
402,
2519,
342,
436,
267,
5371,
8801,
10817,
6218,
4281,
340,
314,
2225,
3913,
506,
1911,
14,
272,
408,
272,
340,
334,
10955,
14,
374,
578,
8,
1113,
9,
503,
267,
334,
1397,
6485,
14,
28450,
8,
1113,
9,
436,
1559,
855,
807,
4343,
1989,
63,
498,
8,
962,
63,
354,
15206,
489,
2306,
63,
1113,
275,
1559,
489,
2306,
63,
962,
275,
2519,
8,
1113,
12,
1921,
63,
354,
9,
339,
587,
26,
489,
340,
440,
6485,
14,
28450,
8,
1113,
304,
267,
30866,
275,
769,
8,
10955,
14,
362,
17335,
8,
1113,
855,
533,
8964,
489,
587,
26,
267,
30866,
275,
769,
8,
10955,
14,
362,
17335,
8,
1113,
430,
2541,
30866,
14,
4471,
342,
2541,
2306,
63,
962,
275,
488,
2541,
367,
843,
315,
30866,
26,
267,
862,
26,
881,
2306,
63,
1113,
275,
843,
881,
2306,
63,
962,
275,
2519,
8,
1113,
12,
1921,
63,
354,
9,
267,
871,
4281,
26,
881,
1980,
339,
340,
2306,
63,
962,
365,
488,
26,
489,
746,
4281,
480,
1646,
440,
1911,
2685,
339,
327,
23892,
2519,
342,
641,
282,
12822,
18501,
652,
370,
282,
283,
3302,
7,
805,
14,
272,
327,
2136,
1929,
370,
4868,
626,
781,
5324,
652,
1771,
465,
282,
12822,
14,
272,
2269,
63,
3215,
275,
1559,
855,
807,
4343,
362,
8,
962,
63,
354,
9,
272,
340,
2269,
63,
3215,
365,
440,
488,
436,
1228,
8,
1753,
63,
3215,
12,
12822,
304,
489,
2306,
63,
962,
275,
12822,
8,
2981,
63,
962,
9,
339,
291,
14,
8957,
14,
740,
1332,
2981,
63,
1113,
12,
1921,
63,
354,
12,
2306,
63,
962,
430,
272,
5371,
8,
2981,
63,
1113,
12,
1921,
63,
354,
12,
892,
63,
962,
9,
819,
347,
26017,
1358,
409,
2422,
8,
277,
304,
272,
408,
497,
422,
874,
1006,
314,
26017,
1084,
342,
4882,
12,
4618,
6854,
7645,
370,
3932,
3379,
272,
5492,
14,
221,
22940,
5849,
370,
1240,
26017,
1358,
409,
2422,
342,
27714,
12,
465,
2945,
4882,
272,
1172,
949,
7763,
340,
949,
26017,
1084,
342,
4882,
1172,
2757,
6326,
14,
339,
408,
272,
291,
14,
8957,
14,
4471,
342,
339,
367,
1249,
315,
291,
14,
8957,
26,
489,
5371,
2031,
589,
9,
339,
291,
14,
8957,
275,
942,
819,
347,
2494,
8,
277,
12,
1676,
12,
1982,
63,
354,
12,
892,
63,
1739,
304,
272,
408,
11328,
1982,
63,
354,
1159,
2269,
5492,
543,
892,
63,
1739,
12,
315,
314,
1067,
272,
402,
314,
1627,
1676,
14,
221,
710,
1676,
4293,
506,
282,
859,
1380,
314,
1982,
365,
282,
272,
805,
737,
859,
4194,
14,
221,
4236,
314,
1676,
4293,
506,
282,
1021,
1380,
282,
1021,
7,
272,
1083,
365,
3769,
8717,
14,
221,
710,
4310,
1982,
365,
663,
370,
892,
63,
1739,
12,
1830,
272,
314,
6791,
5492,
365,
6290,
13437,
367,
2945,
12,
1380,
1910,
409,
2422,
342,
365,
2797,
14,
339,
961,
1083,
5171,
314,
1930,
2382,
1982,
63,
354,
365,
282,
12822,
503,
282,
272,
18990,
402,
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,
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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
] |
AYJAYY/KenoDB
|
keno.py
|
1
|
4245
|
# Keno Data Logging - QuickKeno
# KDL v1.5.2 - Python 3 Conversion
# Last Edit Date: 1/9/2021
from urllib.request import urlopen
import json
import time
def write_file(file_name, write_mode, file_text):
text_file = open(file_name, write_mode)
text_file.write(file_text)
text_file.close()
#get the keno json file
ma_keno_json = urlopen("http://www.masslottery.com/data/json/search/dailygames/todays/15.json")
#read from the json file
json_string = ma_keno_json.read()
#parse the json file so we can work with it
parsed_json = json.loads(json_string)
#get the min and max game and subtract them...
#...so we can get total number of games to iterate over
min_game = int(parsed_json['min'])
max_game = int(parsed_json['max'])
games = max_game - min_game
#script loop
while games > 0:
#get info from "draws" section in json file + create error log
orgOrder = parsed_json['draws'][games]['winning_num_org']
sortedOrder = parsed_json['draws'][games]['winning_num']
multiplier = parsed_json['draws'][games]['bonus']
multi_int = parsed_json['draws'][games]['bonus_value']
draw = parsed_json['draws'][games]['draw_id']
#split on dashes 19 times to split up the 20 numbers
orgOrder_split = orgOrder.split('-', 19)
#join the 20 numbers with commas to accomodate the csv
orgOrder_join = ",".join(orgOrder_split)
orgOrder_column = "\n".join(orgOrder_split)
#a way to string together the data using my "write file" function, this
#also turns everything into a string format so I can concatenate them.
long_text = str(orgOrder_join + "," + orgOrder + "," + sortedOrder + "," + multiplier + "," + multi_int + "," + draw) + "\n"
#also put the numbers in a single row for alternate file
single_row = str(orgOrder_column + "\n")
#write out to the files individually
try:
#format today's date for the filename and set it
date = time.strftime("%Y-%m-%d")
kenodbfile = "KenoFiles/Daily/kenodb" + str(date) + ".csv"
#write a new daily file
write_file(kenodbfile, "a+", long_text)
#append to the master file
write_file("KenoFiles/kenodbfull.csv", "a+", long_text)
#append to the single column file
write_file("KenoFiles/kenodbfull-1column.csv", "a+", single_row)
#in case the user is running on demand, give success messages & log them
print("Succesfully logged game #" + draw)
vlog_string = "<font size='1px'><strong>Succesfully logged game:</strong> " + draw + " <strong>|</strong> </font>" + "\n"
sys_log = "KenoFiles/SYSLOG.html"
write_file(sys_log,"a+",vlog_string)
except Exception as eW:
error_date_eW = time.strftime("%Y-%m-%d-%I:%M %p")
error_text_eW = str(eW) + " | " + "File Write Error" + " | " + error_date_eW + "<br \>" + "\n"
sys_log = "KenoFiles/SYSLOG.html"
log_html = "KenoFiles/LOG.html"
html_text = """<button type="button" class="btn btn-danger">An error has occured while writing to one of the files. Check the log in /KenoFiles</button><br \>""" + "\n"
write_file(sys_log,"a+",error_text_eW)
write_file(log_html,"a+",html_text)
print("An error has occured while writing to one of the files. Check the logs in /KenoFiles")
break
games = games - 1
#success - write to logs and print out in case this is an on demand run
games = max_game - min_game
success_date = time.strftime("%Y-%m-%d-%I:%M %p")
log_html = "KenoFiles/LOG.html"
sys_log = "KenoFiles/SYSLOG.html"
success_html = "<center><div class='bg-success' style='border:1px solid green;'><strong><font color='green'> KenoDB completed successfully" + " | " + success_date + " | Min Game: " + str(min_game) + " | Max Game: " + str(max_game) + " | Total Games: " + str(games) + "</font></strong></div></center><br \>" + "\n"
sys_success_html = """<button type="button" class="btn btn-success">KenoDB completed successfully""" + " | Date: " + success_date + " | Min Game: " + str(min_game) + " | Max Game: " + str(max_game) + " | Number Of Games: " + str(games) + "</button><br \>" + "\n"
write_file(log_html,"a+",sys_success_html)
write_file(sys_log,"a+",success_html)
print("KenoDB completed successfully")
|
gpl-3.0
|
[
3,
1804,
287,
79,
3918,
19928,
446,
27534,
43,
287,
79,
199,
3,
1804,
8045,
373,
17,
14,
21,
14,
18,
446,
2018,
650,
1448,
1023,
199,
3,
15237,
16407,
6148,
26,
413,
15,
25,
15,
22150,
199,
199,
504,
4011,
14,
1069,
492,
18279,
199,
646,
2022,
199,
646,
900,
421,
199,
318,
2218,
63,
493,
8,
493,
63,
354,
12,
2218,
63,
632,
12,
570,
63,
505,
304,
272,
1318,
63,
493,
275,
1551,
8,
493,
63,
354,
12,
2218,
63,
632,
9,
272,
1318,
63,
493,
14,
952,
8,
493,
63,
505,
9,
272,
1318,
63,
493,
14,
1600,
342,
421,
199,
3,
362,
314,
221,
917,
79,
2022,
570,
199,
391,
63,
917,
79,
63,
1001,
275,
18279,
480,
1014,
921,
1544,
14,
11535,
1653,
351,
89,
14,
957,
15,
576,
15,
1001,
15,
1733,
15,
18621,
28129,
15,
5766,
5758,
15,
1046,
14,
1001,
531,
199,
3,
739,
687,
314,
2022,
570,
199,
1001,
63,
875,
275,
610,
63,
917,
79,
63,
1001,
14,
739,
342,
199,
3,
1122,
314,
2022,
570,
880,
781,
883,
1736,
543,
652,
199,
6751,
63,
1001,
275,
2022,
14,
3640,
8,
1001,
63,
875,
9,
199,
3,
362,
314,
1748,
436,
1390,
9219,
436,
24129,
3062,
1396,
199,
3,
1396,
1152,
781,
883,
664,
3141,
1329,
402,
9219,
83,
370,
13974,
1806,
199,
827,
63,
5097,
275,
1109,
8,
6751,
63,
1001,
459,
827,
1105,
199,
988,
63,
5097,
275,
1109,
8,
6751,
63,
1001,
459,
988,
1105,
199,
28129,
275,
1390,
63,
5097,
446,
1748,
63,
5097,
199,
199,
3,
1579,
4438,
199,
6710,
9219,
83,
690,
378,
26,
272,
327,
362,
2256,
687,
298,
5485,
83,
2,
3420,
315,
2022,
570,
435,
1218,
1125,
943,
272,
5981,
4738,
275,
4565,
63,
1001,
459,
5485,
83,
3488,
28129,
2733,
2676,
1835,
63,
1507,
63,
1308,
418,
272,
3355,
4738,
275,
4565,
63,
1001,
459,
5485,
83,
3488,
28129,
2733,
2676,
1835,
63,
1507,
418,
272,
22215,
275,
4565,
63,
1001,
459,
5485,
83,
3488,
28129,
2733,
13520,
527,
418,
272,
3510,
63,
442,
275,
4565,
63,
1001,
459,
5485,
83,
3488,
28129,
2733,
13520,
527,
63,
585,
418,
272,
5954,
275,
4565,
63,
1001,
459,
5485,
83,
3488,
28129,
2733,
5485,
63,
344,
418,
272,
327,
1294,
641,
21106,
5851,
5431,
370,
3715,
1536,
314,
3388,
5579,
272,
5981,
4738,
63,
1294,
275,
5981,
4738,
14,
1294,
13858,
5851,
9,
272,
327,
904,
314,
3388,
5579,
543,
24476,
370,
1066,
957,
364,
323,
314,
7392,
272,
5981,
4738,
63,
904,
275,
19089,
904,
8,
1308,
4738,
63,
1294,
9,
272,
5981,
4738,
63,
2301,
275,
1867,
78,
1674,
904,
8,
1308,
4738,
63,
1294,
9,
272,
327,
65,
4340,
370,
1059,
10451,
314,
666,
1808,
3002,
298,
952,
570,
2,
805,
12,
642,
272,
327,
12344,
25449,
8137,
1901,
282,
1059,
1475,
880,
473,
883,
24788,
3062,
14,
272,
1846,
63,
505,
275,
620,
8,
1308,
4738,
63,
904,
435,
21147,
435,
5981,
4738,
435,
21147,
435,
3355,
4738,
435,
21147,
435,
22215,
435,
21147,
435,
3510,
63,
442,
435,
21147,
435,
5954,
9,
435,
1867,
78,
2,
272,
327,
12344,
5324,
314,
5579,
315,
282,
2849,
1962,
367,
18034,
570,
272,
2849,
63,
1143,
275,
620,
8,
1308,
4738,
63,
2301,
435,
1867,
78,
531,
339,
327,
952,
734,
370,
314,
1584,
7814,
3163,
272,
862,
26,
267,
327,
908,
11168,
1159,
1434,
367,
314,
1788,
436,
663,
652,
267,
1434,
275,
900,
14,
6205,
3647,
57,
3295,
77,
3295,
68,
531,
267,
221,
917,
13152,
493,
275,
298,
43,
287,
79,
5535,
15,
36,
17550,
15,
917,
13152,
2,
435,
620,
8,
602,
9,
435,
3680,
4737,
2,
267,
327,
952,
282,
892,
26122,
570,
267,
2218,
63,
493,
8,
917,
13152,
493,
12,
298,
65,
22758,
1846,
63,
505,
9,
267,
327,
740,
370,
314,
5288,
570,
267,
2218,
63,
493,
480,
43,
287,
79,
5535,
15,
917,
13152,
2861,
14,
4737,
401,
298,
65,
22758,
1846,
63,
505,
9,
267,
327,
740,
370,
314,
2849,
2763,
570,
267,
2218,
63,
493,
480,
43,
287,
79,
5535,
15,
917,
13152,
2861,
13,
17,
2301,
14,
4737,
401,
298,
65,
22758,
2849,
63,
1143,
9,
267,
327,
262,
1930,
314,
922,
365,
3879,
641,
29237,
12,
8120,
3182,
3788,
1253,
943,
3062,
267,
870,
480,
51,
947,
823,
5836,
10367,
9219,
20383,
435,
5954,
9,
267,
373,
793,
63,
875,
275,
3886,
4246,
1568,
534,
17,
5326,
7,
2535,
9370,
30,
51,
947,
823,
5836,
10367,
9219,
9919,
9370,
30,
298,
435,
5954,
435,
298,
665,
9370,
21521,
1108,
9370,
30,
3068,
4246,
4335,
435,
1867,
78,
2,
267,
984,
63,
793,
275,
298,
43,
287,
79,
5535,
15,
13326,
4947,
14,
1360,
2,
267,
2218,
63,
493,
8,
1274,
63,
793,
4589,
65,
22758,
86,
793,
63,
875,
9,
272,
871,
2186,
465,
325,
55,
26,
267,
1125,
63,
602,
63,
69,
55,
275,
900,
14,
6205,
3647,
57,
3295,
77,
3295,
68,
3295,
41,
2689,
45,
450,
80,
531,
267,
1125,
63,
505,
63,
69,
55,
275,
221,
620,
8,
69,
55,
9,
435,
298,
1204,
298,
435,
298,
1173,
6990,
4520,
2,
435,
298,
1204,
298,
435,
1125,
63,
602,
63,
69,
55,
435,
3886,
3289,
971,
4335,
435,
1867,
78,
2,
267,
984,
63,
793,
275,
298,
43,
287,
79,
5535,
15,
13326,
4947,
14,
1360,
2,
267,
943,
63,
1360,
275,
298,
43,
287,
79,
5535,
15,
4947,
14,
1360,
2,
267,
3517,
63,
505,
275,
8894,
3887,
730,
628,
3887,
2,
1021,
628,
9633,
19368,
13,
68,
12974,
1743,
2493,
1125,
965,
28408,
1830,
3575,
370,
1373,
402,
314,
1584,
14,
2670,
314,
943,
315,
1182,
43,
287,
79,
5535,
1108,
3887,
2535,
3289,
971,
11193,
435,
1867,
78,
2,
267,
2218,
63,
493,
8,
1274,
63,
793,
4589,
65,
22758,
705,
63,
505,
63,
69,
55,
9,
267,
2218,
63,
493,
8,
793,
63,
1360,
4589,
65,
22758,
1360,
63,
505,
9,
267,
870,
480,
2493,
1125,
965,
28408,
1830,
3575,
370,
1373,
402,
314,
1584,
14,
2670,
314,
9610,
315,
1182,
43,
287,
79,
5535,
531,
267,
2059,
339,
9219,
83,
275
] |
[
1804,
287,
79,
3918,
19928,
446,
27534,
43,
287,
79,
199,
3,
1804,
8045,
373,
17,
14,
21,
14,
18,
446,
2018,
650,
1448,
1023,
199,
3,
15237,
16407,
6148,
26,
413,
15,
25,
15,
22150,
199,
199,
504,
4011,
14,
1069,
492,
18279,
199,
646,
2022,
199,
646,
900,
421,
199,
318,
2218,
63,
493,
8,
493,
63,
354,
12,
2218,
63,
632,
12,
570,
63,
505,
304,
272,
1318,
63,
493,
275,
1551,
8,
493,
63,
354,
12,
2218,
63,
632,
9,
272,
1318,
63,
493,
14,
952,
8,
493,
63,
505,
9,
272,
1318,
63,
493,
14,
1600,
342,
421,
199,
3,
362,
314,
221,
917,
79,
2022,
570,
199,
391,
63,
917,
79,
63,
1001,
275,
18279,
480,
1014,
921,
1544,
14,
11535,
1653,
351,
89,
14,
957,
15,
576,
15,
1001,
15,
1733,
15,
18621,
28129,
15,
5766,
5758,
15,
1046,
14,
1001,
531,
199,
3,
739,
687,
314,
2022,
570,
199,
1001,
63,
875,
275,
610,
63,
917,
79,
63,
1001,
14,
739,
342,
199,
3,
1122,
314,
2022,
570,
880,
781,
883,
1736,
543,
652,
199,
6751,
63,
1001,
275,
2022,
14,
3640,
8,
1001,
63,
875,
9,
199,
3,
362,
314,
1748,
436,
1390,
9219,
436,
24129,
3062,
1396,
199,
3,
1396,
1152,
781,
883,
664,
3141,
1329,
402,
9219,
83,
370,
13974,
1806,
199,
827,
63,
5097,
275,
1109,
8,
6751,
63,
1001,
459,
827,
1105,
199,
988,
63,
5097,
275,
1109,
8,
6751,
63,
1001,
459,
988,
1105,
199,
28129,
275,
1390,
63,
5097,
446,
1748,
63,
5097,
199,
199,
3,
1579,
4438,
199,
6710,
9219,
83,
690,
378,
26,
272,
327,
362,
2256,
687,
298,
5485,
83,
2,
3420,
315,
2022,
570,
435,
1218,
1125,
943,
272,
5981,
4738,
275,
4565,
63,
1001,
459,
5485,
83,
3488,
28129,
2733,
2676,
1835,
63,
1507,
63,
1308,
418,
272,
3355,
4738,
275,
4565,
63,
1001,
459,
5485,
83,
3488,
28129,
2733,
2676,
1835,
63,
1507,
418,
272,
22215,
275,
4565,
63,
1001,
459,
5485,
83,
3488,
28129,
2733,
13520,
527,
418,
272,
3510,
63,
442,
275,
4565,
63,
1001,
459,
5485,
83,
3488,
28129,
2733,
13520,
527,
63,
585,
418,
272,
5954,
275,
4565,
63,
1001,
459,
5485,
83,
3488,
28129,
2733,
5485,
63,
344,
418,
272,
327,
1294,
641,
21106,
5851,
5431,
370,
3715,
1536,
314,
3388,
5579,
272,
5981,
4738,
63,
1294,
275,
5981,
4738,
14,
1294,
13858,
5851,
9,
272,
327,
904,
314,
3388,
5579,
543,
24476,
370,
1066,
957,
364,
323,
314,
7392,
272,
5981,
4738,
63,
904,
275,
19089,
904,
8,
1308,
4738,
63,
1294,
9,
272,
5981,
4738,
63,
2301,
275,
1867,
78,
1674,
904,
8,
1308,
4738,
63,
1294,
9,
272,
327,
65,
4340,
370,
1059,
10451,
314,
666,
1808,
3002,
298,
952,
570,
2,
805,
12,
642,
272,
327,
12344,
25449,
8137,
1901,
282,
1059,
1475,
880,
473,
883,
24788,
3062,
14,
272,
1846,
63,
505,
275,
620,
8,
1308,
4738,
63,
904,
435,
21147,
435,
5981,
4738,
435,
21147,
435,
3355,
4738,
435,
21147,
435,
22215,
435,
21147,
435,
3510,
63,
442,
435,
21147,
435,
5954,
9,
435,
1867,
78,
2,
272,
327,
12344,
5324,
314,
5579,
315,
282,
2849,
1962,
367,
18034,
570,
272,
2849,
63,
1143,
275,
620,
8,
1308,
4738,
63,
2301,
435,
1867,
78,
531,
339,
327,
952,
734,
370,
314,
1584,
7814,
3163,
272,
862,
26,
267,
327,
908,
11168,
1159,
1434,
367,
314,
1788,
436,
663,
652,
267,
1434,
275,
900,
14,
6205,
3647,
57,
3295,
77,
3295,
68,
531,
267,
221,
917,
13152,
493,
275,
298,
43,
287,
79,
5535,
15,
36,
17550,
15,
917,
13152,
2,
435,
620,
8,
602,
9,
435,
3680,
4737,
2,
267,
327,
952,
282,
892,
26122,
570,
267,
2218,
63,
493,
8,
917,
13152,
493,
12,
298,
65,
22758,
1846,
63,
505,
9,
267,
327,
740,
370,
314,
5288,
570,
267,
2218,
63,
493,
480,
43,
287,
79,
5535,
15,
917,
13152,
2861,
14,
4737,
401,
298,
65,
22758,
1846,
63,
505,
9,
267,
327,
740,
370,
314,
2849,
2763,
570,
267,
2218,
63,
493,
480,
43,
287,
79,
5535,
15,
917,
13152,
2861,
13,
17,
2301,
14,
4737,
401,
298,
65,
22758,
2849,
63,
1143,
9,
267,
327,
262,
1930,
314,
922,
365,
3879,
641,
29237,
12,
8120,
3182,
3788,
1253,
943,
3062,
267,
870,
480,
51,
947,
823,
5836,
10367,
9219,
20383,
435,
5954,
9,
267,
373,
793,
63,
875,
275,
3886,
4246,
1568,
534,
17,
5326,
7,
2535,
9370,
30,
51,
947,
823,
5836,
10367,
9219,
9919,
9370,
30,
298,
435,
5954,
435,
298,
665,
9370,
21521,
1108,
9370,
30,
3068,
4246,
4335,
435,
1867,
78,
2,
267,
984,
63,
793,
275,
298,
43,
287,
79,
5535,
15,
13326,
4947,
14,
1360,
2,
267,
2218,
63,
493,
8,
1274,
63,
793,
4589,
65,
22758,
86,
793,
63,
875,
9,
272,
871,
2186,
465,
325,
55,
26,
267,
1125,
63,
602,
63,
69,
55,
275,
900,
14,
6205,
3647,
57,
3295,
77,
3295,
68,
3295,
41,
2689,
45,
450,
80,
531,
267,
1125,
63,
505,
63,
69,
55,
275,
221,
620,
8,
69,
55,
9,
435,
298,
1204,
298,
435,
298,
1173,
6990,
4520,
2,
435,
298,
1204,
298,
435,
1125,
63,
602,
63,
69,
55,
435,
3886,
3289,
971,
4335,
435,
1867,
78,
2,
267,
984,
63,
793,
275,
298,
43,
287,
79,
5535,
15,
13326,
4947,
14,
1360,
2,
267,
943,
63,
1360,
275,
298,
43,
287,
79,
5535,
15,
4947,
14,
1360,
2,
267,
3517,
63,
505,
275,
8894,
3887,
730,
628,
3887,
2,
1021,
628,
9633,
19368,
13,
68,
12974,
1743,
2493,
1125,
965,
28408,
1830,
3575,
370,
1373,
402,
314,
1584,
14,
2670,
314,
943,
315,
1182,
43,
287,
79,
5535,
1108,
3887,
2535,
3289,
971,
11193,
435,
1867,
78,
2,
267,
2218,
63,
493,
8,
1274,
63,
793,
4589,
65,
22758,
705,
63,
505,
63,
69,
55,
9,
267,
2218,
63,
493,
8,
793,
63,
1360,
4589,
65,
22758,
1360,
63,
505,
9,
267,
870,
480,
2493,
1125,
965,
28408,
1830,
3575,
370,
1373,
402,
314,
1584,
14,
2670,
314,
9610,
315,
1182,
43,
287,
79,
5535,
531,
267,
2059,
339,
9219,
83,
275,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
mistio/libcloud
|
libcloud/test/storage/test_local.py
|
2
|
20962
|
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import with_statement
import os
import sys
import platform
import shutil
import unittest
import tempfile
import mock
from libcloud.common.types import LibcloudError
from libcloud.storage.base import Container
from libcloud.storage.base import Object
from libcloud.storage.types import ContainerDoesNotExistError
from libcloud.storage.types import ContainerAlreadyExistsError
from libcloud.storage.types import ContainerIsNotEmptyError
from libcloud.storage.types import InvalidContainerNameError
from libcloud.utils.files import exhaust_iterator
try:
from libcloud.storage.drivers.local import LocalStorageDriver
from libcloud.storage.drivers.local import LockLocalStorage
from lockfile import LockTimeout
except ImportError:
print('lockfile library is not available, skipping local_storage tests...')
LocalStorageDriver = None
LockTimeout = None
class LocalTests(unittest.TestCase):
driver_type = LocalStorageDriver
@classmethod
def create_driver(self):
self.key = tempfile.mkdtemp()
return self.driver_type(self.key, None)
def setUp(self):
self.driver = self.create_driver()
def tearDown(self):
shutil.rmtree(self.key)
self.key = None
def make_tmp_file(self, content=None):
if not content:
content = b'blah' * 1024
_, tmppath = tempfile.mkstemp()
with open(tmppath, 'wb') as fp:
fp.write(content)
return tmppath
def remove_tmp_file(self, tmppath):
try:
os.unlink(tmppath)
except Exception as e:
msg = str(e)
if 'being used by another process' in msg and platform.system().lower() == 'windows':
return
raise e
def test_list_containers_empty(self):
containers = self.driver.list_containers()
self.assertEqual(len(containers), 0)
def test_containers_success(self):
self.driver.create_container('test1')
self.driver.create_container('test2')
containers = self.driver.list_containers()
self.assertEqual(len(containers), 2)
container = containers[1]
self.assertTrue('creation_time' in container.extra)
self.assertTrue('modify_time' in container.extra)
self.assertTrue('access_time' in container.extra)
objects = self.driver.list_container_objects(container=container)
self.assertEqual(len(objects), 0)
objects = container.list_objects()
self.assertEqual(len(objects), 0)
for container in containers:
self.driver.delete_container(container)
def test_objects_success(self):
tmppath = self.make_tmp_file()
container = self.driver.create_container('test3')
obj1 = container.upload_object(tmppath, 'object1')
obj2 = container.upload_object(tmppath, 'path/object2')
obj3 = container.upload_object(tmppath, 'path/to/object3')
obj4 = container.upload_object(tmppath, 'path/to/object4.ext')
with open(tmppath, 'rb') as tmpfile:
obj5 = container.upload_object_via_stream(tmpfile, 'object5')
objects = self.driver.list_container_objects(container=container)
self.assertEqual(len(objects), 5)
prefix = os.path.join('path', 'to')
objects = self.driver.list_container_objects(container=container,
prefix=prefix)
self.assertEqual(len(objects), 2)
for obj in objects:
self.assertNotEqual(obj.hash, None)
self.assertEqual(obj.size, 4096)
self.assertEqual(obj.container.name, 'test3')
self.assertTrue('creation_time' in obj.extra)
self.assertTrue('modify_time' in obj.extra)
self.assertTrue('access_time' in obj.extra)
obj1.delete()
obj2.delete()
objects = container.list_objects()
self.assertEqual(len(objects), 3)
container.delete_object(obj3)
container.delete_object(obj4)
container.delete_object(obj5)
objects = container.list_objects()
self.assertEqual(len(objects), 0)
container.delete()
self.remove_tmp_file(tmppath)
def test_get_container_doesnt_exist(self):
try:
self.driver.get_container(container_name='container1')
except ContainerDoesNotExistError:
pass
else:
self.fail('Exception was not thrown')
def test_get_container_success(self):
self.driver.create_container('test4')
container = self.driver.get_container(container_name='test4')
self.assertTrue(container.name, 'test4')
container.delete()
def test_get_object_container_doesnt_exist(self):
try:
self.driver.get_object(container_name='test-inexistent',
object_name='test')
except ContainerDoesNotExistError:
pass
else:
self.fail('Exception was not thrown')
def test_get_object_success(self):
tmppath = self.make_tmp_file()
container = self.driver.create_container('test5')
container.upload_object(tmppath, 'test')
obj = self.driver.get_object(container_name='test5',
object_name='test')
self.assertEqual(obj.name, 'test')
self.assertEqual(obj.container.name, 'test5')
self.assertEqual(obj.size, 4096)
self.assertNotEqual(obj.hash, None)
self.assertTrue('creation_time' in obj.extra)
self.assertTrue('modify_time' in obj.extra)
self.assertTrue('access_time' in obj.extra)
obj.delete()
container.delete()
self.remove_tmp_file(tmppath)
def test_create_container_invalid_name(self):
try:
self.driver.create_container(container_name='new/container')
except InvalidContainerNameError:
pass
else:
self.fail('Exception was not thrown')
def test_create_container_already_exists(self):
container = self.driver.create_container(
container_name='new-container')
try:
self.driver.create_container(container_name='new-container')
except ContainerAlreadyExistsError:
pass
else:
self.fail('Exception was not thrown')
# success
self.driver.delete_container(container)
def test_create_container_success(self):
name = 'new_container'
container = self.driver.create_container(container_name=name)
self.assertEqual(container.name, name)
self.driver.delete_container(container)
def test_delete_container_doesnt_exist(self):
container = Container(name='new_container', extra=None,
driver=self.driver)
try:
self.driver.delete_container(container=container)
except ContainerDoesNotExistError:
pass
else:
self.fail('Exception was not thrown')
def test_delete_container_not_empty(self):
tmppath = self.make_tmp_file()
container = self.driver.create_container('test6')
obj = container.upload_object(tmppath, 'test')
try:
self.driver.delete_container(container=container)
except ContainerIsNotEmptyError:
pass
else:
self.fail('Exception was not thrown')
# success
obj.delete()
self.remove_tmp_file(tmppath)
self.assertTrue(self.driver.delete_container(container=container))
def test_delete_container_not_found(self):
container = Container(name='foo_bar_container', extra={},
driver=self.driver)
try:
self.driver.delete_container(container=container)
except ContainerDoesNotExistError:
pass
else:
self.fail('Container does not exist but an exception was not' +
'thrown')
def test_delete_container_success(self):
container = self.driver.create_container('test7')
self.assertTrue(self.driver.delete_container(container=container))
def test_download_object_success(self):
tmppath = self.make_tmp_file()
container = self.driver.create_container('test6')
obj = container.upload_object(tmppath, 'test')
destination_path = tmppath + '.temp'
result = self.driver.download_object(obj=obj,
destination_path=destination_path,
overwrite_existing=False,
delete_on_failure=True)
self.assertTrue(result)
obj.delete()
container.delete()
self.remove_tmp_file(tmppath)
os.unlink(destination_path)
def test_download_object_and_overwrite(self):
tmppath = self.make_tmp_file()
container = self.driver.create_container('test6')
obj = container.upload_object(tmppath, 'test')
destination_path = tmppath + '.temp'
result = self.driver.download_object(obj=obj,
destination_path=destination_path,
overwrite_existing=False,
delete_on_failure=True)
self.assertTrue(result)
try:
self.driver.download_object(obj=obj,
destination_path=destination_path,
overwrite_existing=False,
delete_on_failure=True)
except LibcloudError:
pass
else:
self.fail('Exception was not thrown')
result = self.driver.download_object(obj=obj,
destination_path=destination_path,
overwrite_existing=True,
delete_on_failure=True)
self.assertTrue(result)
# success
obj.delete()
container.delete()
self.remove_tmp_file(tmppath)
os.unlink(destination_path)
def test_download_object_as_stream_success(self):
tmppath = self.make_tmp_file()
container = self.driver.create_container('test6')
obj = container.upload_object(tmppath, 'test')
stream = self.driver.download_object_as_stream(obj=obj,
chunk_size=1024)
self.assertTrue(hasattr(stream, '__iter__'))
data = b''.join(stream)
self.assertTrue(len(data), 4096)
obj.delete()
container.delete()
self.remove_tmp_file(tmppath)
def test_download_object_range_success(self):
content = b'0123456789123456789'
tmppath = self.make_tmp_file(content=content)
container = self.driver.create_container('test6')
obj = container.upload_object(tmppath, 'test')
destination_path = tmppath + '.temp'
# 1. Only start_bytes provided
result = self.driver.download_object_range(obj=obj,
destination_path=destination_path,
start_bytes=4,
overwrite_existing=True,
delete_on_failure=True)
self.assertTrue(result)
with open(destination_path, 'rb') as fp:
written_content = fp.read()
self.assertEqual(written_content, b'456789123456789')
self.assertEqual(written_content, content[4:])
# 2. start_bytes and end_bytes is provided
result = self.driver.download_object_range(obj=obj,
destination_path=destination_path,
start_bytes=4,
end_bytes=6,
overwrite_existing=True,
delete_on_failure=True)
self.assertTrue(result)
with open(destination_path, 'rb') as fp:
written_content = fp.read()
self.assertEqual(written_content, b'45')
self.assertEqual(written_content, content[4:6])
result = self.driver.download_object_range(obj=obj,
destination_path=destination_path,
start_bytes=0,
end_bytes=1,
overwrite_existing=True,
delete_on_failure=True)
self.assertTrue(result)
with open(destination_path, 'rb') as fp:
written_content = fp.read()
self.assertEqual(written_content, b'0')
self.assertEqual(written_content, content[0:1])
result = self.driver.download_object_range(obj=obj,
destination_path=destination_path,
start_bytes=0,
end_bytes=2,
overwrite_existing=True,
delete_on_failure=True)
self.assertTrue(result)
with open(destination_path, 'rb') as fp:
written_content = fp.read()
self.assertEqual(written_content, b'01')
self.assertEqual(written_content, content[0:2])
result = self.driver.download_object_range(obj=obj,
destination_path=destination_path,
start_bytes=0,
end_bytes=len(content),
overwrite_existing=True,
delete_on_failure=True)
self.assertTrue(result)
with open(destination_path, 'rb') as fp:
written_content = fp.read()
self.assertEqual(written_content, b'0123456789123456789')
self.assertEqual(written_content, content[0:len(content)])
obj.delete()
container.delete()
self.remove_tmp_file(tmppath)
os.unlink(destination_path)
def test_download_object_range_as_stream_success(self):
content = b'0123456789123456789'
tmppath = self.make_tmp_file(content=content)
container = self.driver.create_container('test6')
obj = container.upload_object(tmppath, 'test')
# 1. Only start_bytes provided
stream = self.driver.download_object_range_as_stream(obj=obj,
start_bytes=4,
chunk_size=1024)
written_content = b''.join(stream)
self.assertEqual(written_content, b'456789123456789')
self.assertEqual(written_content, content[4:])
# 2. start_bytes and end_bytes is provided
stream = self.driver.download_object_range_as_stream(obj=obj,
start_bytes=4,
end_bytes=7,
chunk_size=1024)
written_content = b''.join(stream)
self.assertEqual(written_content, b'456')
self.assertEqual(written_content, content[4:7])
stream = self.driver.download_object_range_as_stream(obj=obj,
start_bytes=0,
end_bytes=1,
chunk_size=1024)
written_content = b''.join(stream)
self.assertEqual(written_content, b'0')
self.assertEqual(written_content, content[0:1])
stream = self.driver.download_object_range_as_stream(obj=obj,
start_bytes=1,
end_bytes=3,
chunk_size=1024)
written_content = b''.join(stream)
self.assertEqual(written_content, b'12')
self.assertEqual(written_content, content[1:3])
stream = self.driver.download_object_range_as_stream(obj=obj,
start_bytes=0,
end_bytes=len(content),
chunk_size=1024)
written_content = b''.join(stream)
self.assertEqual(written_content, b'0123456789123456789')
self.assertEqual(written_content, content[0:len(content)])
obj.delete()
container.delete()
self.remove_tmp_file(tmppath)
def test_download_object_range_invalid_values(self):
obj = Object('a', 500, '', {}, {}, None, None)
tmppath = self.make_tmp_file(content='')
expected_msg = 'start_bytes must be greater than 0'
self.assertRaisesRegex(ValueError, expected_msg,
self.driver.download_object_range, obj=obj,
destination_path=tmppath,
start_bytes=-1)
expected_msg = 'start_bytes must be smaller than end_bytes'
self.assertRaisesRegex(ValueError, expected_msg,
self.driver.download_object_range, obj=obj,
destination_path=tmppath,
start_bytes=5,
end_bytes=4)
expected_msg = 'start_bytes and end_bytes can\'t be the same'
self.assertRaisesRegex(ValueError, expected_msg,
self.driver.download_object_range, obj=obj,
destination_path=tmppath,
start_bytes=5,
end_bytes=5)
def test_download_object_range_as_stream_invalid_values(self):
content = b'0123456789123456789'
tmppath = self.make_tmp_file(content=content)
container = self.driver.create_container('test6')
obj = container.upload_object(tmppath, 'test')
expected_msg = 'start_bytes must be greater than 0'
stream = self.driver.download_object_range_as_stream(
obj=obj,
start_bytes=-1,
end_bytes=None,
chunk_size=1024)
self.assertRaisesRegex(ValueError, expected_msg, exhaust_iterator,
stream)
expected_msg = 'start_bytes must be smaller than end_bytes'
stream = self.driver.download_object_range_as_stream(
obj=obj,
start_bytes=5,
end_bytes=4,
chunk_size=1024)
self.assertRaisesRegex(ValueError, expected_msg, exhaust_iterator,
stream)
expected_msg = 'end_bytes is larger than file size'
stream = self.driver.download_object_range_as_stream(
obj=obj,
start_bytes=5,
end_bytes=len(content) + 1,
chunk_size=1024)
expected_msg = 'start_bytes and end_bytes can\'t be the same'
stream = self.driver.download_object_range_as_stream(
obj=obj,
start_bytes=5,
end_bytes=5,
chunk_size=1024)
obj.delete()
container.delete()
self.remove_tmp_file(tmppath)
@mock.patch("lockfile.mkdirlockfile.MkdirLockFile.acquire",
mock.MagicMock(side_effect=LockTimeout))
def test_proper_lockfile_imports(self):
# LockLocalStorage was previously using an un-imported exception
# in its __enter__ method, so the following would raise a NameError.
lls = LockLocalStorage("blah")
self.assertRaises(LibcloudError, lls.__enter__)
if not LocalStorageDriver:
class LocalTests(unittest.TestCase): # NOQA
pass
if __name__ == '__main__':
sys.exit(unittest.main())
|
apache-2.0
|
[
3,
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
503,
1655,
199,
3,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
1854,
543,
199,
3,
642,
1736,
367,
4722,
2556,
12602,
4248,
12715,
14,
199,
3,
710,
14857,
12378,
642,
570,
370,
2047,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
199,
3,
334,
1589,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
199,
3,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
504,
636,
2443,
363,
492,
543,
63,
6242,
199,
199,
646,
747,
199,
646,
984,
199,
646,
4298,
199,
646,
5145,
199,
646,
2882,
199,
646,
5549,
199,
199,
646,
1683,
199,
199,
504,
17069,
14,
2330,
14,
1313,
492,
8003,
4091,
547,
199,
504,
17069,
14,
3494,
14,
1095,
492,
15395,
199,
504,
17069,
14,
3494,
14,
1095,
492,
6935,
199,
504,
17069,
14,
3494,
14,
1313,
492,
15395,
7400,
547,
199,
504,
17069,
14,
3494,
14,
1313,
492,
15395,
16760,
23839,
199,
504,
17069,
14,
3494,
14,
1313,
492,
15395,
1831,
1763,
4699,
547,
199,
504,
17069,
14,
3494,
14,
1313,
492,
6378,
4076,
985,
547,
199,
504,
17069,
14,
1208,
14,
1725,
492,
21354,
833,
63,
5778,
199,
199,
893,
26,
272,
687,
17069,
14,
3494,
14,
13337,
14,
1832,
492,
10111,
6408,
6158,
272,
687,
17069,
14,
3494,
14,
13337,
14,
1832,
492,
15536,
5339,
6408,
272,
687,
4650,
493,
492,
15536,
6372,
199,
2590,
3545,
26,
272,
870,
360,
26204,
3555,
365,
440,
2808,
12,
16068,
2257,
63,
3494,
2295,
15103,
272,
10111,
6408,
6158,
275,
488,
272,
15536,
6372,
275,
488,
421,
199,
533,
10111,
2925,
8,
2796,
14,
1746,
304,
272,
5253,
63,
466,
275,
10111,
6408,
6158,
339,
768,
3744,
272,
347,
1218,
63,
3090,
8,
277,
304,
267,
291,
14,
498,
275,
5549,
14,
11983,
342,
267,
372,
291,
14,
3090,
63,
466,
8,
277,
14,
498,
12,
488,
9,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
3090,
275,
291,
14,
981,
63,
3090,
342,
339,
347,
6766,
8,
277,
304,
267,
5145,
14,
9242,
8,
277,
14,
498,
9,
267,
291,
14,
498,
275,
488,
339,
347,
1852,
63,
2791,
63,
493,
8,
277,
12,
1564,
29,
403,
304,
267,
340,
440,
1564,
26,
288,
1564,
275,
330,
7,
12702,
7,
627,
6619,
267,
5501,
3529,
515,
275,
5549,
14,
17721,
342,
267,
543,
1551,
8,
2791,
515,
12,
283,
6603,
358,
465,
4090,
26,
288,
4090,
14,
952,
8,
1317,
9,
267,
372,
3529,
515,
339,
347,
2813,
63,
2791,
63,
493,
8,
277,
12,
3529,
515,
304,
267,
862,
26,
288,
747,
14,
7162,
8,
2791,
515,
9,
267,
871,
2186,
465,
325,
26,
288,
1499,
275,
620,
8,
69,
9,
288,
340,
283,
1235,
316,
1202,
701,
4573,
2112,
7,
315,
1499,
436,
4298,
14,
2253,
1252,
2325,
342,
508,
283,
8258,
356,
355,
372,
288,
746,
325,
339,
347,
511,
63,
513,
63,
13577,
63,
1667,
8,
277,
304,
267,
15333,
275,
291,
14,
3090,
14,
513,
63,
13577,
342,
267,
291,
14,
629,
8,
552,
8,
13577,
395,
378,
9,
339,
347,
511,
63,
13577,
63,
3742,
8,
277,
304,
267,
291,
14,
3090,
14,
981,
63,
3600,
360,
396,
17,
358,
267,
291,
14,
3090,
14,
981,
63,
3600,
360,
396,
18,
358,
267,
15333,
275,
291,
14,
3090,
14,
513,
63,
13577,
342,
267,
291,
14,
629,
8,
552,
8,
13577,
395,
499,
9,
398,
3970,
275,
15333,
59,
17,
61,
398,
291,
14,
1815,
360,
8782,
63,
521,
7,
315,
3970,
14,
2911,
9,
267,
291,
14,
1815,
360,
8951,
63,
521,
7,
315,
3970,
14,
2911,
9,
267,
291,
14,
1815,
360,
2732,
63,
521,
7,
315,
3970,
14,
2911,
9,
398,
2251,
275,
291,
14,
3090,
14,
513,
63,
3600,
63,
1462,
8,
3600,
29,
3600,
9,
267,
291,
14,
629,
8,
552,
8,
1462,
395,
378,
9,
398,
2251,
275,
3970,
14,
513,
63,
1462,
342,
267,
291,
14,
629,
8,
552,
8,
1462,
395,
378,
9,
398,
367,
3970,
315,
15333,
26,
288,
291,
14,
3090,
14,
1807,
63,
3600,
8,
3600,
9,
339,
347,
511,
63,
1462,
63,
3742,
8,
277,
304,
267,
3529,
515,
275,
291,
14,
1875,
63,
2791,
63,
493,
342,
398,
3970,
275,
291,
14,
3090,
14,
981,
63,
3600,
360,
396,
19,
358,
267,
1559,
17,
275,
3970,
14,
5064,
63,
785,
8,
2791,
515,
12,
283,
785,
17,
358,
267,
1559,
18,
275,
3970,
14,
5064,
63,
785,
8,
2791,
515,
12,
283,
515,
15,
785,
18,
358,
267,
1559,
19,
275,
3970,
14,
5064,
63,
785,
8,
2791,
515,
12,
283,
515,
15,
475,
15,
785,
19,
358,
267,
1559,
20,
275,
3970,
14,
5064,
63,
785,
8,
2791,
515,
12,
283,
515,
15,
475,
15,
785,
20,
14,
832,
358,
267,
543,
1551,
8,
2791,
515,
12,
283,
4848,
358,
465,
25137,
26,
288,
1559,
21,
275,
3970,
14,
5064,
63,
785,
63,
12897,
63,
1745,
8,
21930,
12,
283,
785,
21,
358,
398,
2251,
275,
291,
14,
3090,
14,
513,
63,
3600,
63,
1462,
8,
3600,
29,
3600,
9,
267,
291,
14,
629,
8,
552,
8,
1462,
395,
959,
9,
398,
2403,
275,
747,
14,
515,
14,
904,
360,
515,
297,
283,
475,
358,
267,
2251,
275,
291,
14,
3090,
14,
513,
63,
3600,
63,
1462,
8,
3600,
29,
3600,
12,
9349,
2403,
29,
1861,
9,
267,
291,
14,
629,
8,
552,
8,
1462,
395,
499,
9,
398,
367,
1559,
315,
2251,
26,
288,
291,
14,
7418,
8,
1113,
14,
2227,
12,
488,
9
] |
[
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
503,
1655,
199,
3,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
1854,
543,
199,
3,
642,
1736,
367,
4722,
2556,
12602,
4248,
12715,
14,
199,
3,
710,
14857,
12378,
642,
570,
370,
2047,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
199,
3,
334,
1589,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
199,
3,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
504,
636,
2443,
363,
492,
543,
63,
6242,
199,
199,
646,
747,
199,
646,
984,
199,
646,
4298,
199,
646,
5145,
199,
646,
2882,
199,
646,
5549,
199,
199,
646,
1683,
199,
199,
504,
17069,
14,
2330,
14,
1313,
492,
8003,
4091,
547,
199,
504,
17069,
14,
3494,
14,
1095,
492,
15395,
199,
504,
17069,
14,
3494,
14,
1095,
492,
6935,
199,
504,
17069,
14,
3494,
14,
1313,
492,
15395,
7400,
547,
199,
504,
17069,
14,
3494,
14,
1313,
492,
15395,
16760,
23839,
199,
504,
17069,
14,
3494,
14,
1313,
492,
15395,
1831,
1763,
4699,
547,
199,
504,
17069,
14,
3494,
14,
1313,
492,
6378,
4076,
985,
547,
199,
504,
17069,
14,
1208,
14,
1725,
492,
21354,
833,
63,
5778,
199,
199,
893,
26,
272,
687,
17069,
14,
3494,
14,
13337,
14,
1832,
492,
10111,
6408,
6158,
272,
687,
17069,
14,
3494,
14,
13337,
14,
1832,
492,
15536,
5339,
6408,
272,
687,
4650,
493,
492,
15536,
6372,
199,
2590,
3545,
26,
272,
870,
360,
26204,
3555,
365,
440,
2808,
12,
16068,
2257,
63,
3494,
2295,
15103,
272,
10111,
6408,
6158,
275,
488,
272,
15536,
6372,
275,
488,
421,
199,
533,
10111,
2925,
8,
2796,
14,
1746,
304,
272,
5253,
63,
466,
275,
10111,
6408,
6158,
339,
768,
3744,
272,
347,
1218,
63,
3090,
8,
277,
304,
267,
291,
14,
498,
275,
5549,
14,
11983,
342,
267,
372,
291,
14,
3090,
63,
466,
8,
277,
14,
498,
12,
488,
9,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
3090,
275,
291,
14,
981,
63,
3090,
342,
339,
347,
6766,
8,
277,
304,
267,
5145,
14,
9242,
8,
277,
14,
498,
9,
267,
291,
14,
498,
275,
488,
339,
347,
1852,
63,
2791,
63,
493,
8,
277,
12,
1564,
29,
403,
304,
267,
340,
440,
1564,
26,
288,
1564,
275,
330,
7,
12702,
7,
627,
6619,
267,
5501,
3529,
515,
275,
5549,
14,
17721,
342,
267,
543,
1551,
8,
2791,
515,
12,
283,
6603,
358,
465,
4090,
26,
288,
4090,
14,
952,
8,
1317,
9,
267,
372,
3529,
515,
339,
347,
2813,
63,
2791,
63,
493,
8,
277,
12,
3529,
515,
304,
267,
862,
26,
288,
747,
14,
7162,
8,
2791,
515,
9,
267,
871,
2186,
465,
325,
26,
288,
1499,
275,
620,
8,
69,
9,
288,
340,
283,
1235,
316,
1202,
701,
4573,
2112,
7,
315,
1499,
436,
4298,
14,
2253,
1252,
2325,
342,
508,
283,
8258,
356,
355,
372,
288,
746,
325,
339,
347,
511,
63,
513,
63,
13577,
63,
1667,
8,
277,
304,
267,
15333,
275,
291,
14,
3090,
14,
513,
63,
13577,
342,
267,
291,
14,
629,
8,
552,
8,
13577,
395,
378,
9,
339,
347,
511,
63,
13577,
63,
3742,
8,
277,
304,
267,
291,
14,
3090,
14,
981,
63,
3600,
360,
396,
17,
358,
267,
291,
14,
3090,
14,
981,
63,
3600,
360,
396,
18,
358,
267,
15333,
275,
291,
14,
3090,
14,
513,
63,
13577,
342,
267,
291,
14,
629,
8,
552,
8,
13577,
395,
499,
9,
398,
3970,
275,
15333,
59,
17,
61,
398,
291,
14,
1815,
360,
8782,
63,
521,
7,
315,
3970,
14,
2911,
9,
267,
291,
14,
1815,
360,
8951,
63,
521,
7,
315,
3970,
14,
2911,
9,
267,
291,
14,
1815,
360,
2732,
63,
521,
7,
315,
3970,
14,
2911,
9,
398,
2251,
275,
291,
14,
3090,
14,
513,
63,
3600,
63,
1462,
8,
3600,
29,
3600,
9,
267,
291,
14,
629,
8,
552,
8,
1462,
395,
378,
9,
398,
2251,
275,
3970,
14,
513,
63,
1462,
342,
267,
291,
14,
629,
8,
552,
8,
1462,
395,
378,
9,
398,
367,
3970,
315,
15333,
26,
288,
291,
14,
3090,
14,
1807,
63,
3600,
8,
3600,
9,
339,
347,
511,
63,
1462,
63,
3742,
8,
277,
304,
267,
3529,
515,
275,
291,
14,
1875,
63,
2791,
63,
493,
342,
398,
3970,
275,
291,
14,
3090,
14,
981,
63,
3600,
360,
396,
19,
358,
267,
1559,
17,
275,
3970,
14,
5064,
63,
785,
8,
2791,
515,
12,
283,
785,
17,
358,
267,
1559,
18,
275,
3970,
14,
5064,
63,
785,
8,
2791,
515,
12,
283,
515,
15,
785,
18,
358,
267,
1559,
19,
275,
3970,
14,
5064,
63,
785,
8,
2791,
515,
12,
283,
515,
15,
475,
15,
785,
19,
358,
267,
1559,
20,
275,
3970,
14,
5064,
63,
785,
8,
2791,
515,
12,
283,
515,
15,
475,
15,
785,
20,
14,
832,
358,
267,
543,
1551,
8,
2791,
515,
12,
283,
4848,
358,
465,
25137,
26,
288,
1559,
21,
275,
3970,
14,
5064,
63,
785,
63,
12897,
63,
1745,
8,
21930,
12,
283,
785,
21,
358,
398,
2251,
275,
291,
14,
3090,
14,
513,
63,
3600,
63,
1462,
8,
3600,
29,
3600,
9,
267,
291,
14,
629,
8,
552,
8,
1462,
395,
959,
9,
398,
2403,
275,
747,
14,
515,
14,
904,
360,
515,
297,
283,
475,
358,
267,
2251,
275,
291,
14,
3090,
14,
513,
63,
3600,
63,
1462,
8,
3600,
29,
3600,
12,
9349,
2403,
29,
1861,
9,
267,
291,
14,
629,
8,
552,
8,
1462,
395,
499,
9,
398,
367,
1559,
315,
2251,
26,
288,
291,
14,
7418,
8,
1113,
14,
2227,
12,
488,
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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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
] |
ColdSauce/IsSittingOnButt
|
server/env/lib/python2.7/site-packages/pip/_vendor/__init__.py
|
252
|
2508
|
"""
pip._vendor is for vendoring dependencies of pip to prevent needing pip to
depend on something external.
Files inside of pip._vendor should be considered immutable and should only be
updated to versions from upstream.
"""
from __future__ import absolute_import
import glob
import os.path
import sys
# Downstream redistributors which have debundled our dependencies should also
# patch this value to be true. This will trigger the additional patching
# to cause things like "six" to be available as pip.
DEBUNDLED = False
# By default, look in this directory for a bunch of .whl files which we will
# add to the beginning of sys.path before attempting to import anything. This
# is done to support downstream re-distributors like Debian and Fedora who
# wish to create their own Wheels for our dependencies to aid in debundling.
WHEEL_DIR = os.path.abspath(os.path.dirname(__file__))
# Define a small helper function to alias our vendored modules to the real ones
# if the vendored ones do not exist. This idea of this was taken from
# https://github.com/kennethreitz/requests/pull/2567.
def vendored(modulename):
vendored_name = "{0}.{1}".format(__name__, modulename)
try:
__import__(vendored_name, globals(), locals(), level=0)
except ImportError:
__import__(modulename, globals(), locals(), level=0)
sys.modules[vendored_name] = sys.modules[modulename]
base, head = vendored_name.rsplit(".", 1)
setattr(sys.modules[base], head, sys.modules[modulename])
# If we're operating in a debundled setup, then we want to go ahead and trigger
# the aliasing of our vendored libraries as well as looking for wheels to add
# to our sys.path. This will cause all of this code to be a no-op typically
# however downstream redistributors can enable it in a consistent way across
# all platforms.
if DEBUNDLED:
# Actually look inside of WHEEL_DIR to find .whl files and add them to the
# front of our sys.path.
sys.path[:] = glob.glob(os.path.join(WHEEL_DIR, "*.whl")) + sys.path
# Actually alias all of our vendored dependencies.
vendored("cachecontrol")
vendored("colorama")
vendored("distlib")
vendored("html5lib")
vendored("lockfile")
vendored("six")
vendored("six.moves")
vendored("six.moves.urllib")
vendored("packaging")
vendored("packaging.version")
vendored("packaging.specifiers")
vendored("pkg_resources")
vendored("progress")
vendored("retrying")
vendored("requests")
|
apache-2.0
|
[
624,
199,
9983,
423,
9884,
365,
367,
373,
500,
6854,
5124,
402,
7305,
370,
7981,
1929,
316,
7305,
370,
199,
26434,
641,
6020,
5957,
14,
199,
199,
5535,
6272,
402,
7305,
423,
9884,
1077,
506,
8652,
17092,
436,
1077,
1454,
506,
199,
5334,
370,
5459,
687,
18932,
14,
199,
624,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
646,
5739,
199,
646,
747,
14,
515,
199,
646,
984,
199,
199,
3,
13392,
1745,
295,
20231,
6622,
1314,
1172,
32610,
725,
1146,
4154,
5124,
1077,
2597,
199,
3,
3371,
642,
574,
370,
506,
2549,
14,
961,
911,
6804,
314,
4722,
3371,
316,
199,
3,
370,
7675,
7645,
2839,
298,
4174,
2,
370,
506,
2808,
465,
7305,
14,
199,
1093,
32044,
5290,
275,
756,
199,
199,
3,
4885,
849,
12,
3648,
315,
642,
2082,
367,
282,
22219,
402,
1275,
2191,
76,
1584,
1314,
781,
911,
199,
3,
1050,
370,
314,
9608,
402,
984,
14,
515,
2544,
19595,
370,
492,
7003,
14,
961,
199,
3,
365,
4224,
370,
2291,
3224,
1745,
295,
13,
20231,
6622,
2839,
30445,
436,
481,
379,
11131,
3963,
199,
3,
13809,
370,
1218,
3932,
5705,
26161,
83,
367,
4154,
5124,
370,
23939,
315,
32610,
725,
2983,
14,
199,
31588,
2901,
63,
3022,
275,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
3475,
3460,
493,
8964,
421,
199,
3,
13930,
282,
7425,
5922,
805,
370,
5162,
4154,
373,
500,
2908,
4621,
370,
314,
3363,
7869,
199,
3,
340,
314,
373,
500,
2908,
7869,
886,
440,
2187,
14,
961,
16819,
402,
642,
1990,
9394,
687,
199,
3,
4178,
921,
5031,
14,
957,
15,
917,
685,
273,
264,
23751,
15,
6615,
15,
9302,
15,
821,
1822,
14,
199,
318,
373,
500,
2908,
8,
22582,
304,
272,
373,
500,
2908,
63,
354,
275,
5310,
16,
26944,
17,
5469,
908,
3460,
354,
3108,
30045,
9,
339,
862,
26,
267,
636,
646,
721,
86,
500,
2908,
63,
354,
12,
7992,
1062,
9480,
1062,
2166,
29,
16,
9,
272,
871,
3545,
26,
267,
636,
646,
721,
22582,
12,
7992,
1062,
9480,
1062,
2166,
29,
16,
9,
267,
984,
14,
3112,
59,
86,
500,
2908,
63,
354,
61,
275,
984,
14,
3112,
59,
22582,
61,
267,
1300,
12,
4854,
275,
373,
500,
2908,
63,
354,
14,
13490,
30381,
413,
9,
267,
5371,
8,
1274,
14,
3112,
59,
1095,
467,
4854,
12,
984,
14,
3112,
59,
22582,
566,
421,
199,
3,
982,
781,
3984,
17406,
315,
282,
32610,
725,
1146,
3272,
12,
2066,
781,
2934,
370,
2621,
23417,
436,
6804,
199,
3,
314,
5162,
316,
402,
4154,
373,
500,
2908,
8363,
465,
5521,
465,
10023,
367,
28300,
370,
1050,
199,
3,
370,
4154,
984,
14,
515,
14,
961,
911,
7675,
1006,
402,
642,
1233,
370,
506,
282,
949,
13,
411,
13609,
199,
3,
13432,
3224,
1745,
295,
20231,
6622,
883,
4756,
652,
315,
282,
12137,
4340,
9371,
199,
3,
1006,
10677,
14,
199,
692,
3265,
32044,
5290,
26,
272,
327,
18982,
3163,
3648,
6272,
402,
644,
1645,
2901,
63,
3022,
370,
2342,
1275,
2191,
76,
1584,
436,
1050,
3062,
370,
314,
272,
327,
13738,
402,
4154,
984,
14,
515,
14,
272,
984,
14,
515,
5873,
275,
5739,
14,
6463,
8,
736,
14,
515,
14,
904,
8,
31588,
2901,
63,
3022,
12,
298,
4856,
2191,
76,
2237,
435,
984,
14,
515,
339,
327,
18982,
3163,
5162,
1006,
402,
4154,
373,
500,
2908,
5124,
14,
272,
373,
500,
2908,
480,
1637,
2785,
531,
272,
373,
500,
2908,
480,
2326,
14541,
531,
272,
373,
500,
2908,
480,
2686,
773,
531,
272,
373,
500,
2908,
480,
1360,
21,
773,
531,
272,
373,
500,
2908,
480,
26204,
531,
272,
373,
500,
2908,
480,
4174,
531,
272,
373,
500,
2908,
480,
4174,
14,
4912,
531,
272,
373,
500,
2908,
480,
4174,
14,
4912,
14,
4078,
531,
272,
373,
500,
2908,
480,
27796,
531,
272,
373,
500,
2908,
480,
27796,
14,
1023,
531,
272,
373,
500,
2908,
480,
27796,
14,
31659,
531,
272,
373,
500,
2908,
480,
4600,
63,
4435,
531,
272,
373,
500,
2908,
480,
5734,
531,
272,
373,
500,
2908,
480,
7154,
316,
531,
272,
373,
500,
2908,
480,
6615,
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
] |
[
199,
9983,
423,
9884,
365,
367,
373,
500,
6854,
5124,
402,
7305,
370,
7981,
1929,
316,
7305,
370,
199,
26434,
641,
6020,
5957,
14,
199,
199,
5535,
6272,
402,
7305,
423,
9884,
1077,
506,
8652,
17092,
436,
1077,
1454,
506,
199,
5334,
370,
5459,
687,
18932,
14,
199,
624,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
646,
5739,
199,
646,
747,
14,
515,
199,
646,
984,
199,
199,
3,
13392,
1745,
295,
20231,
6622,
1314,
1172,
32610,
725,
1146,
4154,
5124,
1077,
2597,
199,
3,
3371,
642,
574,
370,
506,
2549,
14,
961,
911,
6804,
314,
4722,
3371,
316,
199,
3,
370,
7675,
7645,
2839,
298,
4174,
2,
370,
506,
2808,
465,
7305,
14,
199,
1093,
32044,
5290,
275,
756,
199,
199,
3,
4885,
849,
12,
3648,
315,
642,
2082,
367,
282,
22219,
402,
1275,
2191,
76,
1584,
1314,
781,
911,
199,
3,
1050,
370,
314,
9608,
402,
984,
14,
515,
2544,
19595,
370,
492,
7003,
14,
961,
199,
3,
365,
4224,
370,
2291,
3224,
1745,
295,
13,
20231,
6622,
2839,
30445,
436,
481,
379,
11131,
3963,
199,
3,
13809,
370,
1218,
3932,
5705,
26161,
83,
367,
4154,
5124,
370,
23939,
315,
32610,
725,
2983,
14,
199,
31588,
2901,
63,
3022,
275,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
3475,
3460,
493,
8964,
421,
199,
3,
13930,
282,
7425,
5922,
805,
370,
5162,
4154,
373,
500,
2908,
4621,
370,
314,
3363,
7869,
199,
3,
340,
314,
373,
500,
2908,
7869,
886,
440,
2187,
14,
961,
16819,
402,
642,
1990,
9394,
687,
199,
3,
4178,
921,
5031,
14,
957,
15,
917,
685,
273,
264,
23751,
15,
6615,
15,
9302,
15,
821,
1822,
14,
199,
318,
373,
500,
2908,
8,
22582,
304,
272,
373,
500,
2908,
63,
354,
275,
5310,
16,
26944,
17,
5469,
908,
3460,
354,
3108,
30045,
9,
339,
862,
26,
267,
636,
646,
721,
86,
500,
2908,
63,
354,
12,
7992,
1062,
9480,
1062,
2166,
29,
16,
9,
272,
871,
3545,
26,
267,
636,
646,
721,
22582,
12,
7992,
1062,
9480,
1062,
2166,
29,
16,
9,
267,
984,
14,
3112,
59,
86,
500,
2908,
63,
354,
61,
275,
984,
14,
3112,
59,
22582,
61,
267,
1300,
12,
4854,
275,
373,
500,
2908,
63,
354,
14,
13490,
30381,
413,
9,
267,
5371,
8,
1274,
14,
3112,
59,
1095,
467,
4854,
12,
984,
14,
3112,
59,
22582,
566,
421,
199,
3,
982,
781,
3984,
17406,
315,
282,
32610,
725,
1146,
3272,
12,
2066,
781,
2934,
370,
2621,
23417,
436,
6804,
199,
3,
314,
5162,
316,
402,
4154,
373,
500,
2908,
8363,
465,
5521,
465,
10023,
367,
28300,
370,
1050,
199,
3,
370,
4154,
984,
14,
515,
14,
961,
911,
7675,
1006,
402,
642,
1233,
370,
506,
282,
949,
13,
411,
13609,
199,
3,
13432,
3224,
1745,
295,
20231,
6622,
883,
4756,
652,
315,
282,
12137,
4340,
9371,
199,
3,
1006,
10677,
14,
199,
692,
3265,
32044,
5290,
26,
272,
327,
18982,
3163,
3648,
6272,
402,
644,
1645,
2901,
63,
3022,
370,
2342,
1275,
2191,
76,
1584,
436,
1050,
3062,
370,
314,
272,
327,
13738,
402,
4154,
984,
14,
515,
14,
272,
984,
14,
515,
5873,
275,
5739,
14,
6463,
8,
736,
14,
515,
14,
904,
8,
31588,
2901,
63,
3022,
12,
298,
4856,
2191,
76,
2237,
435,
984,
14,
515,
339,
327,
18982,
3163,
5162,
1006,
402,
4154,
373,
500,
2908,
5124,
14,
272,
373,
500,
2908,
480,
1637,
2785,
531,
272,
373,
500,
2908,
480,
2326,
14541,
531,
272,
373,
500,
2908,
480,
2686,
773,
531,
272,
373,
500,
2908,
480,
1360,
21,
773,
531,
272,
373,
500,
2908,
480,
26204,
531,
272,
373,
500,
2908,
480,
4174,
531,
272,
373,
500,
2908,
480,
4174,
14,
4912,
531,
272,
373,
500,
2908,
480,
4174,
14,
4912,
14,
4078,
531,
272,
373,
500,
2908,
480,
27796,
531,
272,
373,
500,
2908,
480,
27796,
14,
1023,
531,
272,
373,
500,
2908,
480,
27796,
14,
31659,
531,
272,
373,
500,
2908,
480,
4600,
63,
4435,
531,
272,
373,
500,
2908,
480,
5734,
531,
272,
373,
500,
2908,
480,
7154,
316,
531,
272,
373,
500,
2908,
480,
6615,
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,
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,
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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
] |
willthames/ansible
|
lib/ansible/modules/messaging/rabbitmq_binding.py
|
69
|
7328
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
# (c) 2015, Manuel Sousa <manuel.sousa@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/>.
#
ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'],
'supported_by': 'community'}
DOCUMENTATION = '''
---
module: rabbitmq_binding
author: "Manuel Sousa (@manuel-sousa)"
version_added: "2.0"
short_description: This module manages rabbitMQ bindings
description:
- This module uses rabbitMQ Rest API to create/delete bindings
requirements: [ "requests >= 1.0.0" ]
options:
state:
description:
- Whether the exchange should be present or absent
- Only present implemented atm
choices: [ "present", "absent" ]
required: false
default: present
name:
description:
- source exchange to create binding on
required: true
aliases: [ "src", "source" ]
login_user:
description:
- rabbitMQ user for connection
required: false
default: guest
login_password:
description:
- rabbitMQ password for connection
required: false
default: false
login_host:
description:
- rabbitMQ host for connection
required: false
default: localhost
login_port:
description:
- rabbitMQ management api port
required: false
default: 15672
vhost:
description:
- rabbitMQ virtual host
- default vhost is /
required: false
default: "/"
destination:
description:
- destination exchange or queue for the binding
required: true
aliases: [ "dst", "dest" ]
destination_type:
description:
- Either queue or exchange
required: true
choices: [ "queue", "exchange" ]
aliases: [ "type", "dest_type" ]
routing_key:
description:
- routing key for the binding
- default is #
required: false
default: "#"
arguments:
description:
- extra arguments for exchange. If defined this argument is a key/value dictionary
required: false
default: {}
'''
EXAMPLES = '''
# Bind myQueue to directExchange with routing key info
- rabbitmq_binding:
name: directExchange
destination: myQueue
type: queue
routing_key: info
# Bind directExchange to topicExchange with routing key *.info
- rabbitmq_binding:
name: topicExchange
destination: topicExchange
type: exchange
routing_key: '*.info'
'''
import requests
import urllib
import json
def main():
module = AnsibleModule(
argument_spec = dict(
state = dict(default='present', choices=['present', 'absent'], type='str'),
name = dict(required=True, aliases=[ "src", "source" ], type='str'),
login_user = dict(default='guest', type='str'),
login_password = dict(default='guest', type='str', no_log=True),
login_host = dict(default='localhost', type='str'),
login_port = dict(default='15672', type='str'),
vhost = dict(default='/', type='str'),
destination = dict(required=True, aliases=[ "dst", "dest"], type='str'),
destination_type = dict(required=True, aliases=[ "type", "dest_type"], choices=[ "queue", "exchange" ],type='str'),
routing_key = dict(default='#', type='str'),
arguments = dict(default=dict(), type='dict')
),
supports_check_mode = True
)
if module.params['destination_type'] == "queue":
dest_type="q"
else:
dest_type="e"
if module.params['routing_key'] == "":
props = "~"
else:
props = urllib.quote(module.params['routing_key'],'')
url = "http://%s:%s/api/bindings/%s/e/%s/%s/%s/%s" % (
module.params['login_host'],
module.params['login_port'],
urllib.quote(module.params['vhost'],''),
urllib.quote(module.params['name'],''),
dest_type,
urllib.quote(module.params['destination'],''),
props
)
# Check if exchange already exists
r = requests.get( url, auth=(module.params['login_user'],module.params['login_password']))
if r.status_code==200:
binding_exists = True
response = r.json()
elif r.status_code==404:
binding_exists = False
response = r.text
else:
module.fail_json(
msg = "Invalid response from RESTAPI when trying to check if exchange exists",
details = r.text
)
if module.params['state']=='present':
change_required = not binding_exists
else:
change_required = binding_exists
# Exit if check_mode
if module.check_mode:
module.exit_json(
changed= change_required,
name = module.params['name'],
details = response,
arguments = module.params['arguments']
)
# Do changes
if change_required:
if module.params['state'] == 'present':
url = "http://%s:%s/api/bindings/%s/e/%s/%s/%s" % (
module.params['login_host'],
module.params['login_port'],
urllib.quote(module.params['vhost'],''),
urllib.quote(module.params['name'],''),
dest_type,
urllib.quote(module.params['destination'],'')
)
r = requests.post(
url,
auth = (module.params['login_user'],module.params['login_password']),
headers = { "content-type": "application/json"},
data = json.dumps({
"routing_key": module.params['routing_key'],
"arguments": module.params['arguments']
})
)
elif module.params['state'] == 'absent':
r = requests.delete( url, auth = (module.params['login_user'],module.params['login_password']))
if r.status_code == 204 or r.status_code == 201:
module.exit_json(
changed = True,
name = module.params['name'],
destination = module.params['destination']
)
else:
module.fail_json(
msg = "Error creating exchange",
status = r.status_code,
details = r.text
)
else:
module.exit_json(
changed = False,
name = module.params['name']
)
# import module snippets
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,
334,
67,
9,
6900,
12,
4688,
13086,
428,
1785,
65,
665,
1237,
13086,
14,
1152,
527,
65,
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,
3,
199,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
16,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
936,
421,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
29773,
29490,
63,
9140,
199,
2502,
26,
298,
2395,
13086,
428,
1785,
65,
8593,
1237,
13086,
13,
1152,
527,
65,
2924,
199,
1023,
63,
3270,
26,
298,
18,
14,
16,
2,
199,
199,
3612,
63,
1802,
26,
961,
859,
31965,
29773,
2075,
14449,
17792,
199,
1802,
26,
523,
446,
961,
859,
4440,
29773,
2075,
14449,
30417,
3261,
370,
1218,
15,
1807,
17792,
199,
7538,
26,
359,
298,
6615,
2356,
413,
14,
16,
14,
16,
2,
1622,
199,
1419,
26,
272,
1174,
26,
267,
1369,
26,
288,
446,
7480,
314,
15343,
1077,
506,
3451,
503,
9552,
288,
446,
5972,
3451,
6366,
737,
77,
267,
3415,
26,
359,
298,
1881,
401,
298,
5575,
2,
1622,
267,
1415,
26,
3055,
267,
849,
26,
3451,
272,
536,
26,
267,
1369,
26,
288,
446,
1350,
15343,
370,
1218,
11696,
641,
267,
1415,
26,
2549,
267,
5481,
26,
359,
298,
2164,
401,
298,
1365,
2,
1622,
272,
4676,
63,
751,
26,
267,
1369,
26,
288,
446,
29773,
2075,
14449,
922,
367,
1950,
267,
1415,
26,
3055,
267,
849,
26,
13980,
272,
4676,
63,
2060,
26,
267,
1369,
26,
288,
446,
29773,
2075,
14449,
2505,
367,
1950,
267,
1415,
26,
3055,
267,
849,
26,
3055,
272,
4676,
63,
1102,
26,
267,
1369,
26,
288,
446,
29773,
2075,
14449,
1591,
367,
1950,
267,
1415,
26,
3055,
267,
849,
26,
11667,
272,
4676,
63,
719,
26,
267,
1369,
26,
288,
446,
29773,
2075,
14449,
10041,
2986,
1844,
267,
1415,
26,
3055,
267,
849,
26,
32609,
2819,
272,
373,
1102,
26,
267,
1369,
26,
288,
446,
29773,
2075,
14449,
5791,
1591,
288,
446,
849,
373,
1102,
365,
1182,
267,
1415,
26,
3055,
267,
849,
26,
10609,
272,
5724,
26,
267,
1369,
26,
288,
446,
5724,
15343,
503,
4126,
367,
314,
11696,
267,
1415,
26,
2549,
267,
5481,
26,
359,
298,
5119,
401,
298,
2614,
2,
1622,
272,
5724,
63,
466,
26,
267,
1369,
26,
288,
446,
13083,
4126,
503,
15343,
267,
1415,
26,
2549,
267,
3415,
26,
359,
298,
1825,
401,
298,
14197,
2,
1622,
267,
5481,
26,
359,
298,
466,
401,
298,
2614,
63,
466,
2,
1622,
272,
14870,
63,
498,
26,
267,
1369,
26,
288,
446,
14870,
790,
367,
314,
11696,
288,
446,
849,
365,
327,
267,
1415,
26,
3055,
267,
849,
26,
5426,
2,
272,
2368,
26,
267,
1369,
26,
288,
446,
2402,
2368,
367,
15343,
14,
982,
3247,
642,
1423,
365,
282,
790,
15,
585,
2600,
267,
1415,
26,
3055,
267,
849,
26,
1052,
199,
2344,
199,
199,
8918,
275,
1449,
199,
3,
22630,
3002,
3737,
370,
4125,
13188,
543,
14870,
790,
2256,
199,
13,
29773,
29490,
63,
9140,
26,
272,
536,
26,
4125,
13188,
272,
5724,
26,
3002,
3737,
272,
730,
26,
4126,
272,
14870,
63,
498,
26,
2256,
199,
199,
3,
22630,
4125,
13188,
370,
7482,
13188,
543,
14870,
790,
23588,
815,
199,
13,
29773,
29490,
63,
9140,
26,
272,
536,
26,
7482,
13188,
272,
5724,
26,
7482,
13188,
272,
730,
26,
15343,
272,
14870,
63,
498,
26,
11937,
815,
7,
199,
2344,
199,
199,
646,
4145,
199,
646,
4011,
199,
646,
2022,
199,
199,
318,
2446,
837,
272,
859,
275,
6953,
8,
267,
1423,
63,
1650,
275,
1211,
8,
288,
1174,
275,
1211,
8,
885,
534,
1881,
297,
3415,
2968,
1881,
297,
283,
5575,
995,
730,
534,
495,
659,
288,
536,
275,
1211,
8,
2427,
29,
549,
12,
5481,
1524,
298,
2164,
401,
298,
1365,
2,
2156,
730,
534,
495,
659,
288,
4676,
63,
751,
275,
1211,
8,
885,
534,
10409,
297,
730,
534,
495,
659,
288,
4676,
63,
2060,
275,
1211,
8,
885,
534,
10409,
297,
730,
534,
495,
297,
949,
63,
793,
29,
549,
395,
288,
4676,
63,
1102,
275,
1211,
8,
885,
534,
5967,
297,
730,
534,
495,
659,
288,
4676,
63,
719,
275,
1211,
8,
885,
534,
1046,
20298,
297,
730,
534,
495,
659,
288,
373,
1102,
275,
1211,
8,
885,
25412,
730,
534,
495,
659,
288,
5724,
275,
1211,
8,
2427,
29,
549,
12,
5481,
1524,
298,
5119,
401,
298,
2614,
2255,
730,
534,
495,
659,
288,
5724,
63,
466,
275,
1211,
8,
2427,
29,
549,
12,
5481,
1524,
298,
466,
401,
298,
2614,
63,
466,
2255,
3415,
1524,
298,
1825,
401,
298,
14197,
2,
2156,
466,
534,
495,
659,
288,
14870,
63,
498,
275,
1211,
8,
885,
534,
23470,
730,
534,
495,
659,
288,
2368,
275,
1211,
8,
885,
29,
807,
1062,
730,
534,
807,
358,
267,
2318,
267,
5171,
63,
1074,
63,
632,
275,
715,
272,
776,
339,
340,
859,
14,
1162,
459,
6881,
63,
466,
418,
508,
298,
1825,
582,
267,
2053,
63,
466,
628,
81,
2,
272,
587,
26,
267,
2053,
63,
466,
628,
69,
2,
339,
340,
859,
14,
1162,
459,
9492,
63,
498,
418
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
334,
67,
9,
6900,
12,
4688,
13086,
428,
1785,
65,
665,
1237,
13086,
14,
1152,
527,
65,
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,
3,
199,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
16,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
936,
421,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
29773,
29490,
63,
9140,
199,
2502,
26,
298,
2395,
13086,
428,
1785,
65,
8593,
1237,
13086,
13,
1152,
527,
65,
2924,
199,
1023,
63,
3270,
26,
298,
18,
14,
16,
2,
199,
199,
3612,
63,
1802,
26,
961,
859,
31965,
29773,
2075,
14449,
17792,
199,
1802,
26,
523,
446,
961,
859,
4440,
29773,
2075,
14449,
30417,
3261,
370,
1218,
15,
1807,
17792,
199,
7538,
26,
359,
298,
6615,
2356,
413,
14,
16,
14,
16,
2,
1622,
199,
1419,
26,
272,
1174,
26,
267,
1369,
26,
288,
446,
7480,
314,
15343,
1077,
506,
3451,
503,
9552,
288,
446,
5972,
3451,
6366,
737,
77,
267,
3415,
26,
359,
298,
1881,
401,
298,
5575,
2,
1622,
267,
1415,
26,
3055,
267,
849,
26,
3451,
272,
536,
26,
267,
1369,
26,
288,
446,
1350,
15343,
370,
1218,
11696,
641,
267,
1415,
26,
2549,
267,
5481,
26,
359,
298,
2164,
401,
298,
1365,
2,
1622,
272,
4676,
63,
751,
26,
267,
1369,
26,
288,
446,
29773,
2075,
14449,
922,
367,
1950,
267,
1415,
26,
3055,
267,
849,
26,
13980,
272,
4676,
63,
2060,
26,
267,
1369,
26,
288,
446,
29773,
2075,
14449,
2505,
367,
1950,
267,
1415,
26,
3055,
267,
849,
26,
3055,
272,
4676,
63,
1102,
26,
267,
1369,
26,
288,
446,
29773,
2075,
14449,
1591,
367,
1950,
267,
1415,
26,
3055,
267,
849,
26,
11667,
272,
4676,
63,
719,
26,
267,
1369,
26,
288,
446,
29773,
2075,
14449,
10041,
2986,
1844,
267,
1415,
26,
3055,
267,
849,
26,
32609,
2819,
272,
373,
1102,
26,
267,
1369,
26,
288,
446,
29773,
2075,
14449,
5791,
1591,
288,
446,
849,
373,
1102,
365,
1182,
267,
1415,
26,
3055,
267,
849,
26,
10609,
272,
5724,
26,
267,
1369,
26,
288,
446,
5724,
15343,
503,
4126,
367,
314,
11696,
267,
1415,
26,
2549,
267,
5481,
26,
359,
298,
5119,
401,
298,
2614,
2,
1622,
272,
5724,
63,
466,
26,
267,
1369,
26,
288,
446,
13083,
4126,
503,
15343,
267,
1415,
26,
2549,
267,
3415,
26,
359,
298,
1825,
401,
298,
14197,
2,
1622,
267,
5481,
26,
359,
298,
466,
401,
298,
2614,
63,
466,
2,
1622,
272,
14870,
63,
498,
26,
267,
1369,
26,
288,
446,
14870,
790,
367,
314,
11696,
288,
446,
849,
365,
327,
267,
1415,
26,
3055,
267,
849,
26,
5426,
2,
272,
2368,
26,
267,
1369,
26,
288,
446,
2402,
2368,
367,
15343,
14,
982,
3247,
642,
1423,
365,
282,
790,
15,
585,
2600,
267,
1415,
26,
3055,
267,
849,
26,
1052,
199,
2344,
199,
199,
8918,
275,
1449,
199,
3,
22630,
3002,
3737,
370,
4125,
13188,
543,
14870,
790,
2256,
199,
13,
29773,
29490,
63,
9140,
26,
272,
536,
26,
4125,
13188,
272,
5724,
26,
3002,
3737,
272,
730,
26,
4126,
272,
14870,
63,
498,
26,
2256,
199,
199,
3,
22630,
4125,
13188,
370,
7482,
13188,
543,
14870,
790,
23588,
815,
199,
13,
29773,
29490,
63,
9140,
26,
272,
536,
26,
7482,
13188,
272,
5724,
26,
7482,
13188,
272,
730,
26,
15343,
272,
14870,
63,
498,
26,
11937,
815,
7,
199,
2344,
199,
199,
646,
4145,
199,
646,
4011,
199,
646,
2022,
199,
199,
318,
2446,
837,
272,
859,
275,
6953,
8,
267,
1423,
63,
1650,
275,
1211,
8,
288,
1174,
275,
1211,
8,
885,
534,
1881,
297,
3415,
2968,
1881,
297,
283,
5575,
995,
730,
534,
495,
659,
288,
536,
275,
1211,
8,
2427,
29,
549,
12,
5481,
1524,
298,
2164,
401,
298,
1365,
2,
2156,
730,
534,
495,
659,
288,
4676,
63,
751,
275,
1211,
8,
885,
534,
10409,
297,
730,
534,
495,
659,
288,
4676,
63,
2060,
275,
1211,
8,
885,
534,
10409,
297,
730,
534,
495,
297,
949,
63,
793,
29,
549,
395,
288,
4676,
63,
1102,
275,
1211,
8,
885,
534,
5967,
297,
730,
534,
495,
659,
288,
4676,
63,
719,
275,
1211,
8,
885,
534,
1046,
20298,
297,
730,
534,
495,
659,
288,
373,
1102,
275,
1211,
8,
885,
25412,
730,
534,
495,
659,
288,
5724,
275,
1211,
8,
2427,
29,
549,
12,
5481,
1524,
298,
5119,
401,
298,
2614,
2255,
730,
534,
495,
659,
288,
5724,
63,
466,
275,
1211,
8,
2427,
29,
549,
12,
5481,
1524,
298,
466,
401,
298,
2614,
63,
466,
2255,
3415,
1524,
298,
1825,
401,
298,
14197,
2,
2156,
466,
534,
495,
659,
288,
14870,
63,
498,
275,
1211,
8,
885,
534,
23470,
730,
534,
495,
659,
288,
2368,
275,
1211,
8,
885,
29,
807,
1062,
730,
534,
807,
358,
267,
2318,
267,
5171,
63,
1074,
63,
632,
275,
715,
272,
776,
339,
340,
859,
14,
1162,
459,
6881,
63,
466,
418,
508,
298,
1825,
582,
267,
2053,
63,
466,
628,
81,
2,
272,
587,
26,
267,
2053,
63,
466,
628,
69,
2,
339,
340,
859,
14,
1162,
459,
9492,
63,
498,
418,
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,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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
] |
dkodnik/Ant
|
addons/auth_openid/controllers/__init__.py
|
443
|
1033
|
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2011 OpenERP SA (<http://openerp.com>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import main
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
7760,
7653,
13950,
8642,
1014,
921,
11267,
14,
957,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
646,
2446,
199,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
7760,
7653,
13950,
8642,
1014,
921,
11267,
14,
957,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
646,
2446,
199,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
nephila/djangocms-blog
|
djangocms_blog/liveblog/migrations/0001_initial.py
|
1
|
2058
|
import django.db.models.deletion
import filer.fields.image
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("cms", "0013_urlconfrevision"),
("filer", "0003_thumbnailoption"),
]
operations = [
migrations.CreateModel(
name="Liveblog",
fields=[
(
"cmsplugin_ptr",
models.OneToOneField(
parent_link=True,
auto_created=True,
primary_key=True,
serialize=False,
to="cms.CMSPlugin",
on_delete=django.db.models.deletion.CASCADE,
),
),
("body", models.TextField(verbose_name="body")),
("publish", models.BooleanField(default=False, verbose_name="publish liveblog entry")),
(
"image",
filer.fields.image.FilerImageField(
related_name="djangocms_blog_liveblog_image",
on_delete=django.db.models.deletion.SET_NULL,
verbose_name="image",
blank=True,
to="filer.Image",
null=True,
),
),
(
"thumbnail",
models.ForeignKey(
related_name="djangocms_blog_liveblog_thumbnail",
on_delete=django.db.models.deletion.SET_NULL,
verbose_name="thumbnail size",
blank=True,
to="filer.ThumbnailOption",
null=True,
),
),
],
options={
"verbose_name": "liveblog entry",
"verbose_name_plural": "liveblog entries",
},
bases=("cms.cmsplugin",),
),
]
|
bsd-3-clause
|
[
646,
1639,
14,
697,
14,
992,
14,
14281,
199,
646,
570,
82,
14,
955,
14,
1569,
199,
504,
1639,
14,
697,
492,
6180,
12,
1709,
421,
199,
533,
12090,
8,
7685,
14,
9816,
304,
339,
5124,
275,
359,
267,
1689,
10781,
401,
298,
24250,
63,
21801,
5792,
1288,
267,
1689,
29292,
401,
298,
16861,
63,
16534,
3540,
11737,
494,
1288,
272,
1622,
339,
5331,
275,
359,
267,
6180,
14,
14907,
8,
288,
536,
628,
17458,
11486,
401,
288,
1504,
1524,
355,
334,
490,
298,
4400,
30873,
63,
4695,
401,
490,
1709,
14,
14298,
8,
717,
1676,
63,
1073,
29,
549,
12,
717,
2599,
63,
3966,
29,
549,
12,
717,
5062,
63,
498,
29,
549,
12,
717,
8437,
29,
797,
12,
717,
370,
628,
10781,
14,
17834,
5061,
401,
717,
641,
63,
1807,
29,
1176,
14,
697,
14,
992,
14,
14281,
14,
10855,
12,
490,
2318,
355,
2318,
355,
1689,
2030,
401,
1709,
14,
6254,
8,
3832,
63,
354,
628,
2030,
8150,
355,
1689,
4763,
401,
1709,
14,
5036,
8,
885,
29,
797,
12,
3376,
63,
354,
628,
4763,
12166,
11486,
2397,
8150,
355,
334,
490,
298,
1569,
401,
490,
570,
82,
14,
955,
14,
1569,
14,
1173,
82,
21910,
8,
717,
4048,
63,
354,
628,
12816,
679,
706,
63,
11486,
63,
6442,
11486,
63,
1569,
401,
717,
641,
63,
1807,
29,
1176,
14,
697,
14,
992,
14,
14281,
14,
3597,
63,
8084,
12,
717,
3376,
63,
354,
628,
1569,
401,
717,
4596,
29,
549,
12,
717,
370,
628,
29292,
14,
3491,
401,
717,
2973,
29,
549,
12,
490,
2318,
355,
2318,
355,
334,
490,
298,
8311,
401,
490,
1709,
14,
3190,
8,
717,
4048,
63,
354,
628,
12816,
679,
706,
63,
11486,
63,
6442,
11486,
63,
8311,
401,
717,
641,
63,
1807,
29,
1176,
14,
697,
14,
992,
14,
14281,
14,
3597,
63,
8084,
12,
717,
3376,
63,
354,
628,
8311,
1568,
401,
717,
4596,
29,
549,
12,
717,
370,
628,
29292,
14,
2719,
5820,
2602,
401,
717,
2973,
29,
549,
12,
490,
2318,
355,
2318,
288,
2156,
288,
1511,
3126,
355,
298,
3832,
63,
354,
582,
298,
6442,
11486,
2397,
401,
355,
298,
3832,
63,
354,
63,
10019,
582,
298,
6442,
11486,
4811,
401,
288,
1660,
288,
9768,
15387,
10781,
14,
4400,
30873,
18529,
267,
2318,
272,
1622,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1639,
14,
697,
14,
992,
14,
14281,
199,
646,
570,
82,
14,
955,
14,
1569,
199,
504,
1639,
14,
697,
492,
6180,
12,
1709,
421,
199,
533,
12090,
8,
7685,
14,
9816,
304,
339,
5124,
275,
359,
267,
1689,
10781,
401,
298,
24250,
63,
21801,
5792,
1288,
267,
1689,
29292,
401,
298,
16861,
63,
16534,
3540,
11737,
494,
1288,
272,
1622,
339,
5331,
275,
359,
267,
6180,
14,
14907,
8,
288,
536,
628,
17458,
11486,
401,
288,
1504,
1524,
355,
334,
490,
298,
4400,
30873,
63,
4695,
401,
490,
1709,
14,
14298,
8,
717,
1676,
63,
1073,
29,
549,
12,
717,
2599,
63,
3966,
29,
549,
12,
717,
5062,
63,
498,
29,
549,
12,
717,
8437,
29,
797,
12,
717,
370,
628,
10781,
14,
17834,
5061,
401,
717,
641,
63,
1807,
29,
1176,
14,
697,
14,
992,
14,
14281,
14,
10855,
12,
490,
2318,
355,
2318,
355,
1689,
2030,
401,
1709,
14,
6254,
8,
3832,
63,
354,
628,
2030,
8150,
355,
1689,
4763,
401,
1709,
14,
5036,
8,
885,
29,
797,
12,
3376,
63,
354,
628,
4763,
12166,
11486,
2397,
8150,
355,
334,
490,
298,
1569,
401,
490,
570,
82,
14,
955,
14,
1569,
14,
1173,
82,
21910,
8,
717,
4048,
63,
354,
628,
12816,
679,
706,
63,
11486,
63,
6442,
11486,
63,
1569,
401,
717,
641,
63,
1807,
29,
1176,
14,
697,
14,
992,
14,
14281,
14,
3597,
63,
8084,
12,
717,
3376,
63,
354,
628,
1569,
401,
717,
4596,
29,
549,
12,
717,
370,
628,
29292,
14,
3491,
401,
717,
2973,
29,
549,
12,
490,
2318,
355,
2318,
355,
334,
490,
298,
8311,
401,
490,
1709,
14,
3190,
8,
717,
4048,
63,
354,
628,
12816,
679,
706,
63,
11486,
63,
6442,
11486,
63,
8311,
401,
717,
641,
63,
1807,
29,
1176,
14,
697,
14,
992,
14,
14281,
14,
3597,
63,
8084,
12,
717,
3376,
63,
354,
628,
8311,
1568,
401,
717,
4596,
29,
549,
12,
717,
370,
628,
29292,
14,
2719,
5820,
2602,
401,
717,
2973,
29,
549,
12,
490,
2318,
355,
2318,
288,
2156,
288,
1511,
3126,
355,
298,
3832,
63,
354,
582,
298,
6442,
11486,
2397,
401,
355,
298,
3832,
63,
354,
63,
10019,
582,
298,
6442,
11486,
4811,
401,
288,
1660,
288,
9768,
15387,
10781,
14,
4400,
30873,
18529,
267,
2318,
272,
1622,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
nirmeshk/oh-mainline
|
vendor/packages/typecheck/tests/test_internals.py
|
16
|
49297
|
import support
from support import TODO, TestCase, test_hash, test_equality
if __name__ == '__main__':
support.adjust_path()
### /Bookkeeping ###
import typecheck
def check_type(typ, obj):
typecheck.check_type(typ, None, obj)
class SingleTests(TestCase):
def test_success_builtin_types(self):
from typecheck import Single
check_type(Single(int), 7)
check_type(Single(float), 7.0)
def test_success_userdef_classes_oldstyle(self):
from typecheck import Single
class A: pass
class B(A): pass
check_type(Single(A), A())
check_type(Single(A), B())
check_type(Single(B) ,B())
def test_success_userdef_classes_newstyle(self):
from typecheck import Single
class A(object): pass
class B(A): pass
check_type(Single(A), A())
check_type(Single(A), B())
check_type(Single(B), B())
def test_failure(self):
from typecheck import Single, _TC_TypeError
try:
check_type(Single(int), 7.0)
except _TC_TypeError, e:
assert e.right == int
assert e.wrong == float
else:
raise AssertionError("Failed to raise the proper exception")
def test_equality(self):
from typecheck import Single
class A(object): pass
class B(A): pass
eq_tests = [
(Single(int), Single(int)),
(Single(A), Single(A)),
(Single(B), Single(B)) ]
ne_tests = [
(Single(int), Single(float)),
(Single(A), Single(B)) ]
test_equality(eq_tests, ne_tests)
def test_hash(self):
from typecheck import Single
class A(object): pass
class B(A): pass
eq_tests = [
(Single(int), Single(int)),
(Single(A), Single(A)),
(Single(B), Single(B)) ]
ne_tests = [
(Single(int), Single(float)),
(Single(A), Single(B)) ]
test_hash(eq_tests, ne_tests)
class DictTests(TestCase):
def setUp(self):
from typecheck import Dict
def dic(obj):
check_type(Dict(key=str, val=int), obj)
self.dict = dic
def test_success(self):
self.dict({})
self.dict({ 'a': 1, 'b': 2 })
def test_key_failure(self):
from typecheck import _TC_KeyError, _TC_TypeError
try:
self.dict({1.0: 1, 'b': 2})
except _TC_KeyError, e:
assert e.key == 1.0
assert isinstance(e.inner, _TC_TypeError)
assert e.inner.wrong == float
assert e.inner.right == str
else:
self.fail("Passed incorrectly")
def test_val_failure(self):
from typecheck import _TC_KeyValError, _TC_TypeError
try:
# 1.0 is not an integer
self.dict({'a': 1.0, 'b': 2})
except _TC_KeyValError, e:
assert e.key == 'a'
assert e.val == 1.0
assert isinstance(e.inner, _TC_TypeError)
assert e.inner.wrong == float
assert e.inner.right == int
else:
self.fail("Passed incorrectly")
def test_type_failure(self):
from typecheck import _TC_TypeError
try:
self.dict( 5.0 )
except _TC_TypeError, e:
assert e.wrong is float
assert e.right == { str: int }
else:
self.fail("Passed incorrectly")
def test_equality(self):
from typecheck import Dict
class A(object): pass
class B(A): pass
eq_tests = [
(Dict(str, int), Dict(str, int)),
(Dict(str, A), Dict(str, A)),
(Dict(str, Dict(str, int)), Dict(str, Dict(str, int))) ]
ne_tests = [
(Dict(str, int), Dict(int, str)),
(Dict(str, int), {'a': 5}),
(Dict(str, Dict(str, int)), Dict(str, Dict(int, str))) ]
test_equality(eq_tests, ne_tests)
def test_hash(self):
from typecheck import Dict
class A(object): pass
class B(A): pass
eq_tests = [
(Dict(str, int), Dict(str, int)),
(Dict(str, A), Dict(str, A)),
(Dict(str, Dict(str, int)), Dict(str, Dict(str, int))) ]
ne_tests = [
(Dict(str, int), Dict(int, str)),
(Dict(str, Dict(str, int)), Dict(str, Dict(int, str))) ]
test_hash(eq_tests, ne_tests)
class TupleTests(TestCase):
def setUp(self):
from typecheck import Tuple
def tup(obj):
check_type(Tuple(int, float, int), obj)
self.tuple = tup
def test_success(self):
self.tuple( (4, 5.0, 4) )
def test_type_failure(self):
from typecheck import _TC_TypeError
try:
self.tuple( [4, 5, 6] )
except _TC_TypeError, e:
assert e.right == (int, float, int)
assert e.wrong == [int]
else:
self.fail("Passed incorrectly")
def test_index_failure(self):
from typecheck import _TC_IndexError, _TC_TypeError
try:
self.tuple( (5, 'a', 4) )
except _TC_IndexError, e:
assert e.index == 1
assert isinstance(e.inner, _TC_TypeError)
assert e.inner.wrong == str
assert e.inner.right == float
else:
self.fail("Passed incorrectly")
def test_length_error(self):
from typecheck import _TC_TypeError
try:
self.tuple( (3, 4) )
except _TC_TypeError, e:
assert e.wrong == (int, int)
assert e.right == (int, float, int)
else:
self.fail("Passed incorrectly")
def test_equality(self):
from typecheck import Tuple
class A(object): pass
class B(A): pass
eq_tests = [
(Tuple(str, int), Tuple(str, int)),
(Tuple(str, A), Tuple(str, A)),
(Tuple(), Tuple()),
(Tuple(str, Tuple(str, int)), Tuple(str, Tuple(str, int))) ]
ne_tests = [
(Tuple(str, int), Tuple(int, str)),
(Tuple(str, int), (str, int)),
(Tuple(A, A), Tuple(A, B)),
(Tuple(str, int, float), Tuple()),
(Tuple(str, Tuple(str, int)), Tuple(str, Tuple(int, str))) ]
test_equality(eq_tests, ne_tests)
def test_hash(self):
from typecheck import Tuple
class A(object): pass
class B(A): pass
eq_tests = [
(Tuple(str, int), Tuple(str, int)),
(Tuple(str, A), Tuple(str, A)),
(Tuple(), Tuple()),
(Tuple(str, Tuple(str, int)), Tuple(str, Tuple(str, int))) ]
ne_tests = [
(Tuple(str, int), Tuple(int, str)),
(Tuple(A, A), Tuple(A, B)),
(Tuple(str, int, float), Tuple()),
(Tuple(str, Tuple(str, int)), Tuple(str, Tuple(int, str))) ]
test_hash(eq_tests, ne_tests)
def test_empty_tuple_success(self):
from typecheck import Tuple
check_type(Tuple(), tuple())
def test_empty_tuple_failure(self):
from typecheck import Tuple, _TC_TypeError
try:
check_type(Tuple(), (5, 6))
except _TC_TypeError, e:
assert e.wrong == (int, int)
assert e.right == ()
else:
self.fail("Passed incorrectly")
class SingleType_ListTests(TestCase):
def setUp(self):
from typecheck import List
def lis(obj):
check_type(List(int), obj)
self.list = lis
def test_success(self):
self.list([])
self.list([ 4, 5, 6, 7 ])
def test_index_failure(self):
from typecheck import _TC_IndexError, _TC_TypeError
try:
self.list( [4,5,6,7.0] )
except _TC_IndexError, e:
assert e.index == 3
assert isinstance(e.inner, _TC_TypeError)
assert e.inner.right == int
assert e.inner.wrong == float
else:
self.fail("Passed incorrectly")
def test_type_failure(self):
from typecheck import _TC_TypeError
try:
self.list( { 'f': 4 } )
except _TC_TypeError, e:
assert e.right == [int]
assert e.wrong == {str: int}
else:
self.fail("Passed incorrectly")
def test_equality(self):
from typecheck import List
class A(object): pass
class B(A): pass
eq_tests = [
(List(str), List(str)),
(List(A), List(A)),
(List(), List()),
(List(List(int)), List(List(int))) ]
ne_tests = [
(List(str), List(int)),
(List(A), List(B)),
(List(), List(int)),
(List(List(int)), List(List(List(int)))),
(List(int), List(int, int)),
(List(int), [int]) ]
test_equality(eq_tests, ne_tests)
def test_hash(self):
from typecheck import List
class A(object): pass
class B(A): pass
eq_tests = [
(List(str), List(str)),
(List(A), List(A)),
(List(), List()),
(List(List(int)), List(List(int))) ]
ne_tests = [
(List(str), List(int)),
(List(A), List(B)),
(List(), List(int)),
(List(List(int)), List(List(List(int)))),
(List(int), List(int, int)) ]
test_hash(eq_tests, ne_tests)
class Pattern_ListTests(TestCase):
def setUp(self):
from typecheck import List
def lis(obj):
check_type(List(int, float), obj)
self.list = lis
def test_success(self):
self.list([])
self.list([ 4, 5.0 ])
self.list([ 4, 5.0, 8, 9.0 ])
self.list([ 4, 5.0, 9, 8.0, 4, 5.0 ])
def test_index_failure(self):
from typecheck import _TC_IndexError, _TC_TypeError
try:
# 5 is not a float
self.list( [4,5,6,7.0] )
except _TC_IndexError, e:
assert e.index == 1
assert isinstance(e.inner, _TC_TypeError)
assert e.inner.wrong == int
assert e.inner.right == float
else:
self.fail("Passed incorrectly")
def test_type_failure(self):
from typecheck import _TC_TypeError
try:
self.list( { 'f': 4 } )
except _TC_TypeError, e:
assert e.right == [int, float]
assert e.wrong == {str: int}
else:
self.fail("Passed incorrectly")
def test_length_failure(self):
from typecheck import _TC_LengthError
try:
self.list( [4,5.0,6,7.0, 6] )
except _TC_LengthError, e:
assert e.wrong == 5
else:
self.fail("Passed incorrectly")
def test_equality(self):
from typecheck import List
class A(object): pass
class B(A): pass
eq_tests = [
(List(str, str), List(str, str)),
(List(A, B), List(A, B)),
(List(List(int, int), int), List(List(int, int), int)) ]
ne_tests = [
(List(str, int), List(int, str)),
(List(A, B), List(B, B)),
(List(A, B), List(A, A)),
(List(), List(int, int)),
(List(List(int, int)), List(List(List(int, int)))),
(List(int, int), List(int, int, int)),
(List(int, int), [int, int]) ]
test_equality(eq_tests, ne_tests)
def test_hash(self):
from typecheck import List
class A(object): pass
class B(A): pass
eq_tests = [
(List(str, str), List(str, str)),
(List(A, B), List(A, B)),
(List(List(int, int), int), List(List(int, int), int)) ]
ne_tests = [
(List(str, int), List(int, str)),
(List(A, B), List(B, B)),
(List(A, B), List(A, A)),
(List(), List(int, int)),
(List(List(int, int)), List(List(List(int, int)))),
(List(int, int), List(int, int, int)) ]
test_hash(eq_tests, ne_tests)
class NestedTests(TestCase):
def test_patterned_lists_in_lists(self):
from typecheck import _TC_IndexError, List, _TC_TypeError
def list1(obj):
check_type(List( [int, str] ), obj)
# This should pass (list of lists)
list1( [[4,"foo"], [6,"foo",7,"bar"]] )
try:
# 6 is not list of alternating integers and strings
list1( [[4,"foo"], 6] )
except _TC_IndexError, e:
assert e.index == 1
assert isinstance(e.inner, _TC_TypeError)
assert e.inner.right == [int, str]
assert e.inner.wrong == int
else:
self.fail("Passed incorrectly")
def test_patterned_lists_of_patterned_lists(self):
from typecheck import _TC_IndexError, List, Or, _TC_TypeError
# [[[i, s]]] (list of lists of lists of alternating ints and strs)
def list2(obj):
check_type(List( [[int, str]] ), obj)
list2( [ [[4,"foo"], [5,"bar"]], [[4,"baz",7,"foo"]] ] )
try:
# The error is in [4,[6]]; the [6] isn't a string
list2( [[[6,"a"], [7,"r",8,"q"], [4,[6]], [6,"aaa"]]] )
except _TC_IndexError, e:
assert e.index == 0
assert isinstance(e.inner, _TC_IndexError)
assert e.inner.index == 2
assert isinstance(e.inner.inner, _TC_IndexError)
assert e.inner.inner.index == 1
assert isinstance(e.inner.inner.inner, _TC_TypeError)
assert e.inner.inner.inner.right == str
assert e.inner.inner.inner.wrong == [int]
else:
self.fail("Passed incorrectly")
def test_nested_monotype_lists(self):
from typecheck import _TC_IndexError, List, _TC_TypeError
def list1(obj):
check_type(List( [int] ), obj)
# This should pass (list of lists)
list1( [[4,5], [6,7,8]] )
try:
# This should raise an exception
list1( [[4,5], 6] )
except _TC_IndexError, e:
assert e.index == 1
assert isinstance(e.inner, _TC_TypeError)
assert e.inner.wrong == int
assert e.inner.right == [int]
else:
self.fail("Passed incorrectly")
def test_doubly_nested_monotype_lists(self):
from typecheck import _TC_IndexError, List, Or
from typecheck import _TC_TypeError
# [[[i]]] (list of lists of lists of integers)
def list2(obj):
check_type(List( [[int]] ), obj)
list2( [[[4,5], [5,6]], [[4]]] )
try:
# The error is in [4,[6]]; the [6] isn't an integer
list2( [[[6], [7], [4,[6]], [6]]] )
except _TC_IndexError, e:
assert e.index == 0
assert isinstance(e.inner, _TC_IndexError)
assert e.inner.index == 2
assert isinstance(e.inner.inner, _TC_IndexError)
assert e.inner.inner.index == 1
assert isinstance(e.inner.inner.inner, _TC_TypeError)
assert e.inner.inner.inner.right == int
assert e.inner.inner.inner.wrong == [int]
else:
self.fail("Passed incorrectly")
def test_lists_of_tuples(self):
from typecheck import _TC_IndexError, List, _TC_TypeError
# lists of 2-tuples of integer x float
def list3(obj):
check_type(List( (int, float) ), obj)
list3( [(1, 2.0), (2, 3.0), (3, 4.0)] )
try:
# The types are flipped
list3( [(2.0, 1), (3.0, 4)] )
except _TC_IndexError, e:
assert e.index == 0
assert isinstance(e.inner, _TC_IndexError)
assert e.index == 0
assert isinstance(e.inner.inner, _TC_TypeError)
assert e.inner.inner.right == int
assert e.inner.inner.wrong == float
else:
self.fail("Passed incorrectly")
def test_singly_nested_tuples(self):
from typecheck import _TC_IndexError, Tuple, _TC_TypeError
def tup1(obj):
check_type(Tuple( (int, int), int ), obj)
# This should pass
tup1( ((4,5), 6) )
try:
# This should raise an exception
tup1( ([4,5], 6) )
except _TC_IndexError, e:
assert e.index == 0
assert isinstance(e.inner, _TC_TypeError)
assert e.inner.right == (int, int)
assert e.inner.wrong == [int]
else:
self.fail("Passed incorrectly")
def test_doubly_nested_tuples(self):
from typecheck import _TC_IndexError, Tuple, _TC_TypeError
# (((i, i), i), i)
# Triply-nested 2-tuples of integers
tup1 = Tuple( (int, int), int )
def tup2(obj):
check_type(Tuple(tup1, int), obj)
tup2( (((4, 5), 6), 7) )
try:
# [4,5] is not a 2-tuple of int x int
tup2( (([4,5], 6), 7) )
except _TC_IndexError, e:
assert e.index == 0
assert isinstance(e.inner, _TC_IndexError)
assert e.inner.index == 0
assert isinstance(e.inner.inner, _TC_TypeError)
assert e.inner.inner.right == (int, int)
assert e.inner.inner.wrong == [int]
else:
self.fail("Passed incorrectly")
def test_tuples_of_lists(self):
from typecheck import _TC_IndexError, Tuple, _TC_TypeError
# 2-tuples of list of integers x list of strs
def tup3(obj):
check_type(Tuple( [int], [str] ), obj)
# Should pass
tup3( ([4,5,6], ["a","b","c"]) )
try:
tup3( (["a","b","c"], [4,5,6]) )
except _TC_IndexError, e:
assert e.index == 0
assert isinstance(e.inner, _TC_IndexError)
assert e.index == 0
assert isinstance(e.inner.inner, _TC_TypeError)
assert e.inner.inner.right == int
assert e.inner.inner.wrong == str
else:
self.fail("Passed incorrectly")
def test_nested_dict_as_val(self):
from typecheck import _TC_KeyError, _TC_KeyValError, Dict, _TC_TypeError
# int -> {int -> float}
def dict1(obj):
check_type(Dict( int, {int: float}), obj)
# Should pass
dict1( {6: {6: 7.0, 8: 9.0}} )
try:
# Should fail (7.0 is not an integer)
dict1( {6: {7.0: 8.0}} )
except _TC_KeyValError, e:
assert e.key == 6
assert e.val == {7.0: 8.0}
assert isinstance(e.inner, _TC_KeyError)
assert e.inner.key == 7.0
assert isinstance(e.inner.inner, _TC_TypeError)
assert e.inner.inner.right == int
assert e.inner.inner.wrong == float
else:
self.fail("Passed incorrectly")
def test_nested_tuple_as_key(self):
from typecheck import _TC_KeyError, _TC_IndexError, Dict
from typecheck import _TC_TypeError
# (int, int) -> float
def dict2(obj):
check_type(Dict( (int, int), float ), obj)
dict2( {(4,5): 5.0, (9,9): 9.0} )
try:
# Should fail; 5.0 in (5.0, 5) is not an integer
dict2( {(5.0, 5): 5.0} )
except _TC_KeyError, e:
assert e.key == (5.0, 5)
assert isinstance(e.inner, _TC_IndexError)
assert e.inner.index == 0
assert isinstance(e.inner.inner, _TC_TypeError)
assert e.inner.inner.right == int
assert e.inner.inner.wrong == float
else:
self.fail("Passed incorrectly")
class ExtensibleSigTests(TestCase):
def setUp(self):
from typecheck import register_type, _TC_TypeError, unregister_type
import types
class ExactValue(object):
def __init__(self, value):
self.type = value
def __typecheck__(self, func, to_check):
if to_check != self.type:
raise _TC_TypeError(to_check, self.type)
@classmethod
def __typesig__(cls, obj):
# Note that you can either include this test
# or your classes (like ExactValue) can inherit
# from CheckType; either works, but you have
# to do one or the other.
if isinstance(obj, cls):
return obj
if isinstance(obj, int):
return cls(obj)
self.ExactValue = ExactValue
register_type(ExactValue)
def tearDown(self):
from typecheck import unregister_type, is_registered_type
if is_registered_type(self.ExactValue):
unregister_type(self.ExactValue)
def test_register(self):
from typecheck import typecheck_args, TypeCheckError, _TC_IndexError, _TC_TypeError
@typecheck_args(5, 6)
def foo(a, b):
return a, b
assert foo(5, 6) == (5, 6)
try:
foo('a', 5)
except TypeCheckError, e:
assert isinstance(e.internal, _TC_TypeError)
assert e.internal.wrong == str
assert e.internal.right == 5
else:
raise AssertionError("Succeeded incorrectly")
def test_double_register(self):
from typecheck import register_type
register_type(self.ExactValue)
def test_unregister_def(self):
from typecheck import register_type, typecheck_args
from typecheck import unregister_type
@typecheck_args(5, 6)
def foo(a, b):
return a, b
assert foo(5, 6) == (5, 6)
unregister_type(self.ExactValue)
try:
@typecheck_args(5, 6)
def foo(a, b):
return a, b
except AssertionError:
pass
else:
raise AssertionError("Succeeded incorrectly")
def test_unregister_call_again(self):
from typecheck import typecheck_args, unregister_type, TypeCheckError, _TC_IndexError
from typecheck import _TC_TypeError
@typecheck_args(5, 6)
def foo(a, b):
return a, b
assert foo(5, 6) == (5, 6)
unregister_type(self.ExactValue)
try:
foo('a', 5)
except TypeCheckError, e:
assert isinstance(e.internal, _TC_TypeError)
assert e.internal.wrong == str
assert e.internal.right == 5
else:
raise AssertionError("Succeeded incorrectly")
class Test_Function(TestCase):
def test_works_with_Type_function(self):
from typecheck import Type, Function
def foo(*vargs):
return vargs
assert isinstance(Type(foo), Function)
def test_works_with_Type_call_method_newstyle(self):
from typecheck import Type, Function
class Foo(object):
def __call__(self, *vargs):
return vargs
assert isinstance(Type(Foo()), Function)
def test_works_with_Type_call_method_classic(self):
from typecheck import Type, Function
class Foo:
def __call__(self, *vargs):
return vargs
assert isinstance(Type(Foo()), Function)
def test_works_with_Type_classmethod_newstyle(self):
from typecheck import Type, Function
class Foo(object):
@classmethod
def foo(*vargs):
return vargs
assert isinstance(Type(Foo.foo), Function)
def test_works_with_Type_classmethod_classic(self):
from typecheck import Type, Function
class Foo:
@classmethod
def foo(*vargs):
return vargs
assert isinstance(Type(Foo.foo), Function)
def test_works_with_Type_instancemethod_newstyle(self):
from typecheck import Type, Function
class Foo(object):
def foo(*vargs):
return vargs
assert isinstance(Type(Foo().foo), Function)
def test_works_with_Type_instancemethod_classic(self):
from typecheck import Type, Function
class Foo:
def foo(*vargs):
return vargs
assert isinstance(Type(Foo().foo), Function)
def test_works_with_Type_staticmethod_newstyle(self):
from typecheck import Type, Function
class Foo(object):
@staticmethod
def foo(*vargs):
return vargs
assert isinstance(Type(Foo.foo), Function)
def test_works_with_Type_staticmethod_classic(self):
from typecheck import Type, Function
class Foo:
@staticmethod
def foo(*vargs):
return vargs
assert isinstance(Type(Foo.foo), Function)
def test_str(self):
from typecheck import Function
def foo(*vargs):
return vargs
assert str(Function(foo)) == "Function(%s)" % foo
def test_repr(self):
from typecheck import Function
def foo(*vargs):
return vargs
assert repr(Function(foo)) == "Function(%s)" % foo
def test_check_type_errors_pass_through(self):
from typecheck import Function, check_type
class MyCustomException(Exception):
pass
def checker_function(*vargs):
raise MyCustomException(*vargs)
try:
check_type(Function(checker_function), None, 66)
except MyCustomException, e:
assert e.args == (66,)
else:
raise AssertionError("Failed to raise MyCustomException")
def test_check_type_None_means_success(self):
from typecheck import Function, check_type
def checker_function(*vargs):
return None
check_type(Function(checker_function), None, 66)
def test_check_type_true_values_mean_success(self):
from typecheck import Function, check_type
def checker_function(*vargs):
return True
check_type(Function(checker_function), None, 66)
def checker_function(*vargs):
return 5
check_type(Function(checker_function), None, 66)
def checker_function(*vargs):
return "abc"
check_type(Function(checker_function), None, 66)
def test_check_type_false_values_mean_success(self):
from typecheck import Function, check_type
def checker_function(*vargs):
return []
check_type(Function(checker_function), None, 66)
def checker_function(*vargs):
return {}
check_type(Function(checker_function), None, 66)
def test_check_type_False_means_failure(self):
from typecheck import Function, check_type, _TC_FunctionError
def checker_function(*vargs):
return False
try:
check_type(Function(checker_function), None, 66)
except _TC_FunctionError, e:
assert e.checking_func is checker_function
assert e.rejected_obj == 66
else:
raise AssertionError("Failed to raise _TC_FunctionError")
# (0 == False) == True
def checker_function(*vargs):
return 0
try:
check_type(Function(checker_function), None, 66)
except _TC_FunctionError, e:
assert e.checking_func is checker_function
assert e.rejected_obj == 66
else:
raise AssertionError("Failed to raise _TC_FunctionError")
def convert_mapping(mapping):
if mapping is None:
return None
# k[0] is necessary because k looks like ("string", string_type)
return dict([(k[0], v.type) for k, v in mapping.items()])
def active_mapping():
from typecheck import TypeVariables as TV
return convert_mapping(TV._TypeVariables__active_mapping)
class Test_TypeVariables(TestCase):
def tearDown(self):
from typecheck import TypeVariables
# Give ourselves a clean slate
TypeVariables._TypeVariables__gen_mappings = {}
TypeVariables._TypeVariables__mapping_stack = []
TypeVariables._TypeVariables__active_mapping = None
def test_equality(self):
from typecheck import TypeVariables
assert TypeVariables('a') != TypeVariables('b')
assert TypeVariables('a') == TypeVariables('a')
assert TypeVariables('a') != TypeVariables(u'a')
def test_hash(self):
from typecheck import TypeVariables
assert hash(TypeVariables('a')) != hash(TypeVariables('b'))
assert hash(TypeVariables('a')) == hash(TypeVariables('a'))
assert hash(TypeVariables('a')) != hash(TypeVariables(u'a'))
def test_args_and_return_pass(self):
from typecheck import accepts, returns
from typecheck import TypeVariables
def run_test(dec):
@dec('a', int, 'a')
def foo(a, b, c):
return a, b, c
class A: pass
a = A()
for args in ((5, 5, 5), (5.0, 5, 7.0), ([4, 5], 5, [8, 9, 10]), (a, 5, a)):
assert foo(*args) == args
assert TypeVariables._TypeVariables__mapping_stack == []
assert TypeVariables._TypeVariables__active_mapping is None
assert len(TypeVariables._TypeVariables__gen_mappings) == 0
run_test(accepts)
run_test(returns)
def test_args_fail(self):
from typecheck import accepts, calculate_type
from typecheck import TypeCheckError, _TC_TypeError
from typecheck import TypeVariables
class Bad: pass
bad = Bad()
@accepts('a', int, 'a')
def foo(a, b, c):
return a, b, c
class A: pass
a = A()
for args in ((5, 5, bad), (5.0, 5, bad), ([4, 5], 5, bad), (a, 5, bad)):
try:
foo(*args)
except TypeCheckError, e:
assert isinstance(e.internal, _TC_TypeError)
assert e.internal.right == calculate_type(args[0])
assert e.internal.wrong == Bad
assert TypeVariables._TypeVariables__mapping_stack == []
assert TypeVariables._TypeVariables__active_mapping is None
assert len(TypeVariables._TypeVariables__gen_mappings) == 0
else:
raise AssertionError("Failed to raise TypeCheckError at the proper place")
def test_return_fail(self):
from typecheck import returns, calculate_type
from typecheck import TypeCheckError, _TC_IndexError, _TC_TypeError
from typecheck import TypeVariables
class Bad: pass
bad = Bad()
@returns('a', int, 'a')
def foo(a, b, c):
return a, b, c
class A: pass
a = A()
for args in ((5, 5, bad), (5.0, 5, bad), ([4, 5], 5, bad), (a, 5, bad)):
try:
foo(*args)
except TypeCheckError, e:
assert isinstance(e.internal, _TC_IndexError)
assert e.internal.index == 2
assert isinstance(e.internal.inner, _TC_TypeError)
assert e.internal.inner.right == calculate_type(args[0])
assert e.internal.inner.wrong == Bad
assert TypeVariables._TypeVariables__mapping_stack == []
assert TypeVariables._TypeVariables__active_mapping is None
assert len(TypeVariables._TypeVariables__gen_mappings) == 0
else:
raise AssertionError("Failed to raise TypeCheckError at the proper place")
def test_yield_pass(self):
from typecheck import yields
from typecheck import TypeVariables
@yields('a', int, 'a')
def foo(a, b, c):
yield a, b, c
class A: pass
a = A()
for args in ((5, 5, 5), (5.0, 5, 7.0), ([4, 5], 5, [8, 9, 10]), (a, 5, a)):
g = foo(*args)
assert g.next() == args
try:
g.next()
except StopIteration:
pass
else:
raise AssertionError("Failed to raise StopIteration at the right place")
assert TypeVariables._TypeVariables__mapping_stack == []
assert TypeVariables._TypeVariables__active_mapping is None
assert len(TypeVariables._TypeVariables__gen_mappings) == 0
def test_yield_fail(self):
from typecheck import yields
from typecheck import TypeCheckError, _TC_IndexError, _TC_TypeError
from typecheck import calculate_type, _TC_GeneratorError
from typecheck import TypeVariables
gen_mappings = TypeVariables._TypeVariables__gen_mappings
class Bad: pass
bad = Bad()
@yields('a', int, 'a')
def foo(a, b, c):
yield a, b, bad
class A: pass
a = A()
for args in ((5, 5, 5), (5.0, 5, 7.0), ([4, 5], 5, [8, 9, 10]), (a, 5, a)):
g = foo(*args)
try:
assert g.next() == args
except TypeCheckError, e:
assert isinstance(e.internal, _TC_GeneratorError)
assert e.internal.yield_no == 1
assert isinstance(e.internal.inner, _TC_IndexError)
assert e.internal.inner.index == 2
assert isinstance(e.internal.inner.inner, _TC_TypeError)
assert e.internal.inner.inner.right == calculate_type(args[0])
assert e.internal.inner.inner.wrong == Bad
assert len(gen_mappings) == 1
assert convert_mapping(gen_mappings.values()[0]) == {'a': calculate_type(args[0])}
else:
raise AssertionError("Failed to raise TypeCheckError at the right place")
try:
g.next()
except StopIteration:
assert TypeVariables._TypeVariables__mapping_stack == []
assert TypeVariables._TypeVariables__active_mapping is None
assert len(gen_mappings) == 0
else:
raise AssertionError("Failed to raise StopIteration at the right place")
assert TypeVariables._TypeVariables__mapping_stack == []
assert TypeVariables._TypeVariables__active_mapping is None
assert len(gen_mappings) == 0
def test_args_return_pass(self):
from typecheck import returns, accepts
from typecheck import TypeVariables
def run_test(dec_1, dec_2):
@dec_1('a', 'b', int, 'a', 'b')
@dec_2('a', 'b', int, 'a', 'b')
def foo(a, b, c, d, e):
return a, b, c, d, e
class A: pass
class B: pass
a = A()
b = B()
for args in ((5, 5.0, 6, 7, 7.0), ('a', 4, 6, 'b', 6), (a, b, 5, a, b)):
assert foo(*args) == args
assert TypeVariables._TypeVariables__mapping_stack == []
assert TypeVariables._TypeVariables__active_mapping is None
assert len(TypeVariables._TypeVariables__gen_mappings) == 0
run_test(returns, accepts)
run_test(accepts, returns)
def test_args_return_fail(self):
from typecheck import accepts, returns, calculate_type
from typecheck import TypeCheckError, _TC_IndexError, _TC_TypeError
from typecheck import TypeVariables
class Bad: pass
bad = Bad()
def run_test(dec_1, dec_2):
@dec_1
@dec_2
def foo(a, b, c, d, e):
return a, b, c, bad, e
class A: pass
class B: pass
a = A()
b = B()
for args in ((5, 5.0, 6, 7, 7.0), ('a', 4, 6, 'b', 6), (a, b, 5, a, b)):
try:
foo(*args)
except TypeCheckError, e:
assert isinstance(e.internal, _TC_IndexError)
assert e.internal.index == 3
assert isinstance(e.internal.inner, _TC_TypeError)
assert e.internal.inner.right == calculate_type(args[0])
assert e.internal.inner.wrong == Bad
assert TypeVariables._TypeVariables__mapping_stack == []
assert TypeVariables._TypeVariables__active_mapping is None
assert len(TypeVariables._TypeVariables__gen_mappings) == 0
else:
raise AssertionError("Failed to raise TypeCheckError at the proper place")
t_r = returns('a', 'b', int, 'a', 'b')
t_a = accepts('a', 'b', int, 'a', 'b')
run_test(t_r, t_a)
run_test(t_a, t_r)
def test_args_yield_pass(self):
from typecheck import yields, accepts
from typecheck import TypeVariables
gen_mappings = TypeVariables._TypeVariables__gen_mappings
def run_test(dec_1, dec_2):
@dec_1('a', 'b', int, 'a', 'b')
@dec_2('a', 'b', int, 'a', 'b')
def foo(a, b, c, d, e):
yield a, b, c, d, e
class A: pass
class B: pass
a = A()
b = B()
problem_set = [0]*3
problem_set[0] = ((5, 5.0, 6, 7, 7.0), {'a': int, 'b': float})
problem_set[1] = (('a', 4, 6, 'b', 6), {'a': str, 'b': int})
problem_set[2] = ((a, b, 5, a, b), {'a': A, 'b': B})
for args, mapping in problem_set:
gen = foo(*args)
assert gen.next() == args
assert TypeVariables._TypeVariables__mapping_stack == []
assert TypeVariables._TypeVariables__active_mapping == None
assert len(gen_mappings) == 1
assert convert_mapping(gen_mappings.values()[0]) == mapping
try:
gen.next()
except StopIteration:
pass
else:
raise AssertionError("Failed to raise StopIteration at the right time")
assert TypeVariables._TypeVariables__mapping_stack == []
assert TypeVariables._TypeVariables__active_mapping is None
assert len(gen_mappings) == 0
run_test(yields, accepts)
run_test(accepts, yields)
assert TypeVariables._TypeVariables__mapping_stack == []
assert TypeVariables._TypeVariables__active_mapping is None
assert len(TypeVariables._TypeVariables__gen_mappings) == 0
def test_args_yield_fail(self):
from typecheck import yields, accepts
from typecheck import TypeCheckError, _TC_IndexError, _TC_TypeError
from typecheck import calculate_type, _TC_GeneratorError
from typecheck import TypeVariables
gen_mappings = TypeVariables._TypeVariables__gen_mappings
class Bad: pass
bad = Bad()
def run_test(dec_1, dec_2):
@dec_1('a', 'b', int, 'a', 'b')
@dec_2('a', 'b', int, 'a', 'b')
def foo(a, b, c, d, e):
yield bad, b, c, bad, e
class A: pass
class B: pass
a = A()
b = B()
problem_set = [0]*3
problem_set[0] = ((5, 5.0, 6, 7, 7.0), {'a': int, 'b': float})
problem_set[1] = (('a', 4, 6, 'b', 6), {'a': str, 'b': int})
problem_set[2] = ((a, b, 5, a, b), {'a': A, 'b': B})
for args, mapping in problem_set:
gen = foo(*args)
try:
assert gen.next() == args
except TypeCheckError, e:
assert isinstance(e.internal, _TC_GeneratorError)
assert e.internal.yield_no == 1
assert isinstance(e.internal.inner, _TC_IndexError)
assert e.internal.inner.index == 0
assert isinstance(e.internal.inner.inner, _TC_TypeError)
assert e.internal.inner.inner.wrong == Bad
assert e.internal.inner.inner.right == calculate_type(args[0])
assert TypeVariables._TypeVariables__mapping_stack == []
assert TypeVariables._TypeVariables__active_mapping == None
assert len(gen_mappings) == 1
assert convert_mapping(gen_mappings.values()[0]) == mapping
try:
gen.next()
except StopIteration:
assert TypeVariables._TypeVariables__mapping_stack == []
assert TypeVariables._TypeVariables__active_mapping is None
assert len(gen_mappings) == 0
else:
raise AssertionError("Failed to raise StopIteration at the right time")
run_test(yields, accepts)
run_test(accepts, yields)
assert TypeVariables._TypeVariables__mapping_stack == []
assert TypeVariables._TypeVariables__active_mapping is None
assert len(TypeVariables._TypeVariables__gen_mappings) == 0
def test_recursive_functions(self):
from typecheck import returns, accepts
from typecheck import TypeVariables
mapping_stack = TypeVariables._TypeVariables__mapping_stack
mappings = [None, {'a': str}, {'a': (int, int)}, {'a': float}, None]
stack = list(mappings)
stack.reverse()
stack.pop()
def check(n):
assert active_mapping() == mappings[n]
assert [convert_mapping(m) for m in mapping_stack] == stack[:-n]
def run_test(dec_1, dec_2):
@dec_1
@dec_2
def foo(obj_1, obj_2, n):
if n == 1:
check(n)
return [obj_1, obj_2]
elif n == 2:
check(n)
foo('jabber', 'wocky', n-1)
check(n)
return [(4, 5), (6, 7)]
elif n == 3:
check(n)
foo((5, 6), (7, 8), n-1)
check(n)
return [obj_1, obj_2]
assert foo(6.0, 7.0, 3) == [6.0, 7.0]
assert mapping_stack == []
assert TypeVariables._TypeVariables__active_mapping == None
assert len(TypeVariables._TypeVariables__gen_mappings) == 0
t_r = returns(['a'])
t_a = accepts('a', 'a', int)
run_test(t_r, t_a)
run_test(t_a, t_r)
def test_incorrect_generator_usage(self):
from typecheck import yields, accepts
from typecheck import TypeVariables
gen_mappings = TypeVariables._TypeVariables__gen_mappings
@accepts('a')
@yields('a')
def gen(obj):
yield obj
assert gen.type_yield == 'a'
assert gen.type_args == {'obj': 'a'}
for i in range(1, 4):
g = gen(5)
assert gen.type_yield == g.type_yield
assert g.next() == 5
del g
assert TypeVariables._TypeVariables__mapping_stack == []
assert TypeVariables._TypeVariables__active_mapping == None
assert len(gen_mappings) == 0
def test_args_yield_on_method_fail(self):
from typecheck import yields, TypeCheckError
from typecheck import _TC_IndexError, _TC_TypeError
from typecheck import _TC_GeneratorError, accepts
from typecheck import TypeVariables
class Test(object):
@accepts('a', int, int)
@yields('a', int, 'a')
def foo(self, a, b):
yield b, a, b
assert Test.foo.type_yield == ('a', int, 'a')
assert Test.foo.type_args == {'self': 'a', 'a': int, 'b': int}
def run_test():
try:
assert Test().foo(4, 6).next() == (6, 4, 6)
except TypeCheckError, e:
assert isinstance(e.internal, _TC_GeneratorError)
assert e.internal.yield_no == 1
assert isinstance(e.internal.inner, _TC_IndexError)
assert e.internal.inner.index == 0
assert isinstance(e.internal.inner.inner, _TC_TypeError)
assert e.internal.inner.inner.wrong == int
assert e.internal.inner.inner.right == Test
else:
raise AssertionError("Failed to raise TypeCheckError")
run_test()
assert TypeVariables._TypeVariables__mapping_stack == []
assert TypeVariables._TypeVariables__active_mapping == None
assert len(TypeVariables._TypeVariables__gen_mappings) == 0
def test_unicode_tvars(self):
from typecheck import accepts, calculate_type
from typecheck import TypeCheckError, _TC_TypeError
from typecheck import TypeVariables
class Bad: pass
bad = Bad()
@accepts(u'a', int, u'a')
def foo(a, b, c):
return a, b, c
class A: pass
a = A()
for args in ((5, 5, bad), (5.0, 5, bad), ([4, 5], 5, bad), (a, 5, bad)):
try:
foo(*args)
except TypeCheckError, e:
assert isinstance(e.internal, _TC_TypeError)
assert e.internal.right == calculate_type(args[0])
assert e.internal.wrong == Bad
assert TypeVariables._TypeVariables__mapping_stack == []
assert TypeVariables._TypeVariables__active_mapping is None
assert len(TypeVariables._TypeVariables__gen_mappings) == 0
else:
raise AssertionError("Failed to raise TypeCheckError at the proper place")
def test_unicode_and_ascii_tvars_1(self):
from typecheck import accepts, returns
@accepts(u'a', 'a')
@returns('a', u'a')
def flip(a, b):
return b, a
flip(5, 7.0)
def test_unicode_and_ascii_tvars_2(self):
from typecheck import accepts, returns, TypeCheckError
from typecheck import _TC_IndexError, _TC_TypeError, TypeVariables
# The signature is wrong (for the function, not the test)
@accepts(u'a', 'a')
@returns('a', u'a')
def foo(a, b):
return a, b
try:
foo(4, 5.0)
except TypeCheckError, e:
assert isinstance(e.internal, _TC_IndexError)
assert e.internal.index == 0
assert isinstance(e.internal.inner, _TC_TypeError)
assert e.internal.inner.right is float
assert e.internal.inner.wrong is int
assert TypeVariables._TypeVariables__mapping_stack == []
assert TypeVariables._TypeVariables__active_mapping is None
assert len(TypeVariables._TypeVariables__gen_mappings) == 0
else:
raise AssertionError('Failed to raise TypeCheckError')
def test_same_tvar_nested_calls(self):
from typecheck import accepts, returns
from typecheck import TypeVariables
Foo = TypeVariables("this is the foo tvar")
@accepts(Foo)
@returns(Foo)
def bar(a):
return int(baz(float(a)))
@accepts(Foo)
@returns(Foo)
def baz(a):
return a
assert bar(4) == float(4)
### Bookkeeping ###
if __name__ == '__main__':
import __main__
support.run_all_tests(__main__)
|
agpl-3.0
|
[
646,
2291,
199,
504,
2291,
492,
3254,
12,
7640,
12,
511,
63,
2227,
12,
511,
63,
20982,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
2291,
14,
10917,
63,
515,
342,
199,
5680,
1182,
8696,
3250,
316,
6754,
199,
199,
646,
730,
1074,
199,
199,
318,
1104,
63,
466,
8,
9749,
12,
1559,
304,
272,
730,
1074,
14,
1074,
63,
466,
8,
9749,
12,
488,
12,
1559,
9,
199,
199,
533,
13050,
2925,
8,
1746,
304,
272,
347,
511,
63,
3742,
63,
5351,
63,
1313,
8,
277,
304,
267,
687,
730,
1074,
492,
13050,
2728,
1104,
63,
466,
8,
7200,
8,
442,
395,
1520,
9,
267,
1104,
63,
466,
8,
7200,
8,
1609,
395,
1520,
14,
16,
9,
339,
347,
511,
63,
3742,
63,
751,
318,
63,
2888,
63,
1753,
2487,
8,
277,
304,
267,
687,
730,
1074,
492,
13050,
10631,
1021,
437,
26,
986,
267,
1021,
699,
8,
33,
304,
986,
2728,
1104,
63,
466,
8,
7200,
8,
33,
395,
437,
1012,
267,
1104,
63,
466,
8,
7200,
8,
33,
395,
699,
1012,
267,
1104,
63,
466,
8,
7200,
8,
34,
9,
2360,
34,
1012,
5493,
347,
511,
63,
3742,
63,
751,
318,
63,
2888,
63,
1222,
2487,
8,
277,
304,
267,
687,
730,
1074,
492,
13050,
10631,
1021,
437,
8,
785,
304,
986,
267,
1021,
699,
8,
33,
304,
986,
2728,
1104,
63,
466,
8,
7200,
8,
33,
395,
437,
1012,
267,
1104,
63,
466,
8,
7200,
8,
33,
395,
699,
1012,
267,
1104,
63,
466,
8,
7200,
8,
34,
395,
699,
1012,
5493,
347,
511,
63,
5328,
8,
277,
304,
267,
687,
730,
1074,
492,
13050,
12,
485,
5708,
63,
4333,
2728,
862,
26,
288,
1104,
63,
466,
8,
7200,
8,
442,
395,
1520,
14,
16,
9,
267,
871,
485,
5708,
63,
4333,
12,
325,
26,
288,
702,
325,
14,
1019,
508,
1109,
288,
702,
325,
14,
10603,
508,
2069,
267,
587,
26,
288,
746,
9070,
480,
4276,
370,
746,
314,
5576,
1919,
531,
15567,
347,
511,
63,
20982,
8,
277,
304,
267,
687,
730,
1074,
492,
13050,
2728,
1021,
437,
8,
785,
304,
986,
267,
1021,
699,
8,
33,
304,
986,
2728,
3850,
63,
2219,
275,
359,
288,
334,
7200,
8,
442,
395,
13050,
8,
442,
1826,
288,
334,
7200,
8,
33,
395,
13050,
8,
33,
1826,
288,
334,
7200,
8,
34,
395,
13050,
8,
34,
430,
1622,
10631,
1279,
63,
2219,
275,
359,
288,
334,
7200,
8,
442,
395,
13050,
8,
1609,
1826,
288,
334,
7200,
8,
33,
395,
13050,
8,
34,
430,
1622,
2728,
511,
63,
20982,
8,
4077,
63,
2219,
12,
1279,
63,
2219,
9,
5493,
347,
511,
63,
2227,
8,
277,
304,
267,
687,
730,
1074,
492,
13050,
2728,
1021,
437,
8,
785,
304,
986,
267,
1021,
699,
8,
33,
304,
986,
2728,
3850,
63,
2219,
275,
359,
288,
334,
7200,
8,
442,
395,
13050,
8,
442,
1826,
288,
334,
7200,
8,
33,
395,
13050,
8,
33,
1826,
288,
334,
7200,
8,
34,
395,
13050,
8,
34,
430,
1622,
10631,
1279,
63,
2219,
275,
359,
288,
334,
7200,
8,
442,
395,
13050,
8,
1609,
1826,
288,
334,
7200,
8,
33,
395,
13050,
8,
34,
430,
1622,
2728,
511,
63,
2227,
8,
4077,
63,
2219,
12,
1279,
63,
2219,
9,
199,
199,
533,
7448,
2925,
8,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
687,
730,
1074,
492,
7448,
13857,
347,
12219,
8,
1113,
304,
288,
1104,
63,
466,
8,
2141,
8,
498,
29,
495,
12,
1139,
29,
442,
395,
1559,
9,
13857,
291,
14,
807,
275,
12219,
339,
347,
511,
63,
3742,
8,
277,
304,
267,
291,
14,
807,
14079,
267,
291,
14,
807,
2561,
283,
65,
356,
413,
12,
283,
66,
356,
499,
3828,
339,
347,
511,
63,
498,
63,
5328,
8,
277,
304,
267,
687,
730,
1074,
492,
485,
5708,
63,
10230,
12,
485,
5708,
63,
4333,
13857,
862,
26,
288,
291,
14,
807,
2561,
17,
14,
16,
26,
413,
12,
283,
66,
356,
499,
1552,
267,
871,
485,
5708,
63,
10230,
12,
325,
26,
288,
702,
325,
14,
498,
508,
413,
14,
16,
288,
702,
1228,
8,
69,
14,
5216,
12,
485,
5708,
63,
4333,
9,
288,
702,
325,
14,
5216,
14,
10603,
508,
2069,
288,
702,
325,
14,
5216,
14,
1019,
508,
620,
267,
587,
26,
288,
291,
14,
1633,
480,
48,
2744,
22743,
531,
5493,
347,
511,
63,
637,
63,
5328,
8,
277,
304,
267,
687,
730,
1074,
492,
485,
5708,
63,
1197,
7562,
547,
12,
485,
5708,
63,
4333,
13857,
862,
26,
288,
327,
413,
14,
16,
365,
440,
376,
3000,
288,
291,
14,
807,
3252,
65,
356,
413,
14,
16,
12,
283,
66,
356,
499,
1552,
267,
871,
485,
5708,
63,
1197,
7562,
547,
12,
325,
26,
288,
702,
325,
14,
498,
508,
283,
65,
7,
288,
702,
325,
14,
637,
508,
413,
14,
16,
288,
702,
1228,
8,
69,
14,
5216,
12,
485,
5708,
63,
4333,
9,
288,
702,
325,
14,
5216,
14,
10603,
508,
2069,
288,
702,
325,
14,
5216,
14,
1019,
508,
1109,
267,
587,
26,
288,
291,
14,
1633,
480,
48,
2744,
22743,
531,
15567,
347,
511,
63,
466,
63,
5328,
8,
277,
304,
267,
687,
730,
1074,
492,
485,
5708,
63,
4333,
13857,
862,
26,
288,
291,
14,
807,
8,
959,
14,
16,
776,
267,
871,
485,
5708,
63,
4333,
12,
325,
26,
288,
702,
325,
14,
10603,
365,
2069,
288,
702,
325,
14,
1019,
508,
469,
620,
26,
1109,
789,
267,
587,
26,
288,
291,
14,
1633,
480,
48,
2744,
22743,
531,
15567,
347,
511,
63,
20982,
8,
277,
304,
267,
687,
730,
1074,
492,
7448,
2728,
1021,
437,
8,
785,
304,
986,
267,
1021,
699,
8,
33,
304,
986,
2728,
3850,
63,
2219,
275,
359,
288,
334,
2141,
8,
495,
12,
1109,
395,
7448,
8,
495,
12,
1109,
1826,
288,
334,
2141,
8,
495,
12,
437,
395,
7448,
8,
495,
12,
437,
1826,
288,
334,
2141,
8,
495,
12,
7448,
8,
495,
12,
1109,
1826,
7448,
8,
495,
12,
7448,
8,
495,
12,
1109,
1724,
1622,
10631,
1279,
63,
2219,
275,
359,
288,
334,
2141,
8,
495,
12,
1109,
395,
7448,
8,
442,
12,
620,
1826,
288,
334
] |
[
2291,
199,
504,
2291,
492,
3254,
12,
7640,
12,
511,
63,
2227,
12,
511,
63,
20982,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
2291,
14,
10917,
63,
515,
342,
199,
5680,
1182,
8696,
3250,
316,
6754,
199,
199,
646,
730,
1074,
199,
199,
318,
1104,
63,
466,
8,
9749,
12,
1559,
304,
272,
730,
1074,
14,
1074,
63,
466,
8,
9749,
12,
488,
12,
1559,
9,
199,
199,
533,
13050,
2925,
8,
1746,
304,
272,
347,
511,
63,
3742,
63,
5351,
63,
1313,
8,
277,
304,
267,
687,
730,
1074,
492,
13050,
2728,
1104,
63,
466,
8,
7200,
8,
442,
395,
1520,
9,
267,
1104,
63,
466,
8,
7200,
8,
1609,
395,
1520,
14,
16,
9,
339,
347,
511,
63,
3742,
63,
751,
318,
63,
2888,
63,
1753,
2487,
8,
277,
304,
267,
687,
730,
1074,
492,
13050,
10631,
1021,
437,
26,
986,
267,
1021,
699,
8,
33,
304,
986,
2728,
1104,
63,
466,
8,
7200,
8,
33,
395,
437,
1012,
267,
1104,
63,
466,
8,
7200,
8,
33,
395,
699,
1012,
267,
1104,
63,
466,
8,
7200,
8,
34,
9,
2360,
34,
1012,
5493,
347,
511,
63,
3742,
63,
751,
318,
63,
2888,
63,
1222,
2487,
8,
277,
304,
267,
687,
730,
1074,
492,
13050,
10631,
1021,
437,
8,
785,
304,
986,
267,
1021,
699,
8,
33,
304,
986,
2728,
1104,
63,
466,
8,
7200,
8,
33,
395,
437,
1012,
267,
1104,
63,
466,
8,
7200,
8,
33,
395,
699,
1012,
267,
1104,
63,
466,
8,
7200,
8,
34,
395,
699,
1012,
5493,
347,
511,
63,
5328,
8,
277,
304,
267,
687,
730,
1074,
492,
13050,
12,
485,
5708,
63,
4333,
2728,
862,
26,
288,
1104,
63,
466,
8,
7200,
8,
442,
395,
1520,
14,
16,
9,
267,
871,
485,
5708,
63,
4333,
12,
325,
26,
288,
702,
325,
14,
1019,
508,
1109,
288,
702,
325,
14,
10603,
508,
2069,
267,
587,
26,
288,
746,
9070,
480,
4276,
370,
746,
314,
5576,
1919,
531,
15567,
347,
511,
63,
20982,
8,
277,
304,
267,
687,
730,
1074,
492,
13050,
2728,
1021,
437,
8,
785,
304,
986,
267,
1021,
699,
8,
33,
304,
986,
2728,
3850,
63,
2219,
275,
359,
288,
334,
7200,
8,
442,
395,
13050,
8,
442,
1826,
288,
334,
7200,
8,
33,
395,
13050,
8,
33,
1826,
288,
334,
7200,
8,
34,
395,
13050,
8,
34,
430,
1622,
10631,
1279,
63,
2219,
275,
359,
288,
334,
7200,
8,
442,
395,
13050,
8,
1609,
1826,
288,
334,
7200,
8,
33,
395,
13050,
8,
34,
430,
1622,
2728,
511,
63,
20982,
8,
4077,
63,
2219,
12,
1279,
63,
2219,
9,
5493,
347,
511,
63,
2227,
8,
277,
304,
267,
687,
730,
1074,
492,
13050,
2728,
1021,
437,
8,
785,
304,
986,
267,
1021,
699,
8,
33,
304,
986,
2728,
3850,
63,
2219,
275,
359,
288,
334,
7200,
8,
442,
395,
13050,
8,
442,
1826,
288,
334,
7200,
8,
33,
395,
13050,
8,
33,
1826,
288,
334,
7200,
8,
34,
395,
13050,
8,
34,
430,
1622,
10631,
1279,
63,
2219,
275,
359,
288,
334,
7200,
8,
442,
395,
13050,
8,
1609,
1826,
288,
334,
7200,
8,
33,
395,
13050,
8,
34,
430,
1622,
2728,
511,
63,
2227,
8,
4077,
63,
2219,
12,
1279,
63,
2219,
9,
199,
199,
533,
7448,
2925,
8,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
687,
730,
1074,
492,
7448,
13857,
347,
12219,
8,
1113,
304,
288,
1104,
63,
466,
8,
2141,
8,
498,
29,
495,
12,
1139,
29,
442,
395,
1559,
9,
13857,
291,
14,
807,
275,
12219,
339,
347,
511,
63,
3742,
8,
277,
304,
267,
291,
14,
807,
14079,
267,
291,
14,
807,
2561,
283,
65,
356,
413,
12,
283,
66,
356,
499,
3828,
339,
347,
511,
63,
498,
63,
5328,
8,
277,
304,
267,
687,
730,
1074,
492,
485,
5708,
63,
10230,
12,
485,
5708,
63,
4333,
13857,
862,
26,
288,
291,
14,
807,
2561,
17,
14,
16,
26,
413,
12,
283,
66,
356,
499,
1552,
267,
871,
485,
5708,
63,
10230,
12,
325,
26,
288,
702,
325,
14,
498,
508,
413,
14,
16,
288,
702,
1228,
8,
69,
14,
5216,
12,
485,
5708,
63,
4333,
9,
288,
702,
325,
14,
5216,
14,
10603,
508,
2069,
288,
702,
325,
14,
5216,
14,
1019,
508,
620,
267,
587,
26,
288,
291,
14,
1633,
480,
48,
2744,
22743,
531,
5493,
347,
511,
63,
637,
63,
5328,
8,
277,
304,
267,
687,
730,
1074,
492,
485,
5708,
63,
1197,
7562,
547,
12,
485,
5708,
63,
4333,
13857,
862,
26,
288,
327,
413,
14,
16,
365,
440,
376,
3000,
288,
291,
14,
807,
3252,
65,
356,
413,
14,
16,
12,
283,
66,
356,
499,
1552,
267,
871,
485,
5708,
63,
1197,
7562,
547,
12,
325,
26,
288,
702,
325,
14,
498,
508,
283,
65,
7,
288,
702,
325,
14,
637,
508,
413,
14,
16,
288,
702,
1228,
8,
69,
14,
5216,
12,
485,
5708,
63,
4333,
9,
288,
702,
325,
14,
5216,
14,
10603,
508,
2069,
288,
702,
325,
14,
5216,
14,
1019,
508,
1109,
267,
587,
26,
288,
291,
14,
1633,
480,
48,
2744,
22743,
531,
15567,
347,
511,
63,
466,
63,
5328,
8,
277,
304,
267,
687,
730,
1074,
492,
485,
5708,
63,
4333,
13857,
862,
26,
288,
291,
14,
807,
8,
959,
14,
16,
776,
267,
871,
485,
5708,
63,
4333,
12,
325,
26,
288,
702,
325,
14,
10603,
365,
2069,
288,
702,
325,
14,
1019,
508,
469,
620,
26,
1109,
789,
267,
587,
26,
288,
291,
14,
1633,
480,
48,
2744,
22743,
531,
15567,
347,
511,
63,
20982,
8,
277,
304,
267,
687,
730,
1074,
492,
7448,
2728,
1021,
437,
8,
785,
304,
986,
267,
1021,
699,
8,
33,
304,
986,
2728,
3850,
63,
2219,
275,
359,
288,
334,
2141,
8,
495,
12,
1109,
395,
7448,
8,
495,
12,
1109,
1826,
288,
334,
2141,
8,
495,
12,
437,
395,
7448,
8,
495,
12,
437,
1826,
288,
334,
2141,
8,
495,
12,
7448,
8,
495,
12,
1109,
1826,
7448,
8,
495,
12,
7448,
8,
495,
12,
1109,
1724,
1622,
10631,
1279,
63,
2219,
275,
359,
288,
334,
2141,
8,
495,
12,
1109,
395,
7448,
8,
442,
12,
620,
1826,
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,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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
] |
Mirantis/swift-encrypt
|
swift/common/ring/utils.py
|
1
|
2880
|
from collections import defaultdict
def tiers_for_dev(dev):
"""
Returns a tuple of tiers for a given device in ascending order by
length.
:returns: tuple of tiers
"""
t1 = dev['zone']
t2 = "{ip}:{port}".format(ip=dev.get('ip'), port=dev.get('port'))
t3 = dev['id']
return ((t1,),
(t1, t2),
(t1, t2, t3))
def build_tier_tree(devices):
"""
Construct the tier tree from the zone layout.
The tier tree is a dictionary that maps tiers to their child tiers.
A synthetic root node of () is generated so that there's one tree,
not a forest.
Example:
zone 1 -+---- 192.168.1.1:6000 -+---- device id 0
| |
| +---- device id 1
| |
| +---- device id 2
|
+---- 192.168.1.2:6000 -+---- device id 3
|
+---- device id 4
|
+---- device id 5
zone 2 -+---- 192.168.2.1:6000 -+---- device id 6
| |
| +---- device id 7
| |
| +---- device id 8
|
+---- 192.168.2.2:6000 -+---- device id 9
|
+---- device id 10
|
+---- device id 11
The tier tree would look like:
{
(): [(1,), (2,)],
(1,): [(1, 192.168.1.1:6000),
(1, 192.168.1.2:6000)],
(2,): [(2, 192.168.2.1:6000),
(2, 192.168.2.2:6000)],
(1, 192.168.1.1:6000): [(1, 192.168.1.1:6000, 0),
(1, 192.168.1.1:6000, 1),
(1, 192.168.1.1:6000, 2)],
(1, 192.168.1.2:6000): [(1, 192.168.1.2:6000, 3),
(1, 192.168.1.2:6000, 4),
(1, 192.168.1.2:6000, 5)],
(2, 192.168.2.1:6000): [(2, 192.168.2.1:6000, 6),
(2, 192.168.2.1:6000, 7),
(2, 192.168.2.1:6000, 8)],
(2, 192.168.2.2:6000): [(2, 192.168.2.2:6000, 9),
(2, 192.168.2.2:6000, 10),
(2, 192.168.2.2:6000, 11)],
}
:devices: device dicts from which to generate the tree
:returns: tier tree
"""
tier2children = defaultdict(set)
for dev in devices:
for tier in tiers_for_dev(dev):
if len(tier) > 1:
tier2children[tier[0:-1]].add(tier)
else:
tier2children[()].add(tier)
return tier2children
|
apache-2.0
|
[
504,
5055,
492,
10018,
421,
199,
318,
3367,
1192,
63,
509,
63,
2374,
8,
2374,
304,
272,
408,
272,
1803,
282,
2008,
402,
3367,
1192,
367,
282,
1627,
2243,
315,
24525,
1865,
701,
272,
2582,
14,
339,
520,
5808,
26,
2008,
402,
3367,
1192,
272,
408,
272,
307,
17,
275,
4866,
459,
2619,
418,
272,
307,
18,
275,
5310,
711,
16495,
719,
5469,
908,
8,
711,
29,
2374,
14,
362,
360,
711,
659,
1844,
29,
2374,
14,
362,
360,
719,
1333,
272,
307,
19,
275,
4866,
459,
344,
418,
339,
372,
3666,
84,
17,
4706,
288,
334,
84,
17,
12,
307,
18,
395,
288,
334,
84,
17,
12,
307,
18,
12,
307,
19,
430,
421,
199,
318,
1900,
63,
13949,
63,
2350,
8,
6410,
304,
272,
408,
272,
9215,
314,
31800,
3123,
687,
314,
5718,
7054,
14,
339,
710,
31800,
3123,
365,
282,
2600,
626,
9033,
3367,
1192,
370,
3932,
1982,
3367,
1192,
14,
272,
437,
9560,
21231,
1738,
1031,
402,
6248,
365,
4046,
880,
626,
2337,
1159,
1373,
3123,
12,
272,
440,
282,
27882,
14,
339,
5679,
26,
339,
5718,
413,
446,
11,
375,
13567,
14,
6568,
14,
17,
14,
17,
26,
32623,
446,
11,
375,
2243,
1305,
378,
288,
1204,
9668,
1204,
288,
1204,
9668,
435,
375,
2243,
1305,
413,
288,
1204,
9668,
1204,
288,
1204,
9668,
435,
375,
2243,
1305,
499,
288,
1204,
288,
435,
375,
13567,
14,
6568,
14,
17,
14,
18,
26,
32623,
446,
11,
375,
2243,
1305,
650,
2511,
1204,
2511,
435,
375,
2243,
1305,
841,
2511,
1204,
2511,
435,
375,
2243,
1305,
959,
2378,
5718,
499,
446,
11,
375,
13567,
14,
6568,
14,
18,
14,
17,
26,
32623,
446,
11,
375,
2243,
1305,
1227,
288,
1204,
9668,
1204,
288,
1204,
9668,
435,
375,
2243,
1305,
1520,
288,
1204,
9668,
1204,
288,
1204,
9668,
435,
375,
2243,
1305,
1695,
288,
1204,
288,
435,
375,
13567,
14,
6568,
14,
18,
14,
18,
26,
32623,
446,
11,
375,
2243,
1305,
1749,
2511,
1204,
2511,
435,
375,
2243,
1305,
1616,
2511,
1204,
2511,
435,
375,
2243,
1305,
4119,
339,
710,
31800,
3123,
3955,
3648,
2839,
26,
272,
469,
489,
23390,
3842,
17,
4706,
334,
18,
32444,
2541,
334,
17,
16095,
3842,
17,
12,
13567,
14,
6568,
14,
17,
14,
17,
26,
32623,
395,
1467,
334,
17,
12,
13567,
14,
6568,
14,
17,
14,
18,
26,
32623,
4360,
489,
334,
18,
16095,
3842,
18,
12,
13567,
14,
6568,
14,
18,
14,
17,
26,
32623,
395,
1467,
334,
18,
12,
13567,
14,
6568,
14,
18,
14,
18,
26,
32623,
4360,
2541,
334,
17,
12,
13567,
14,
6568,
14,
17,
14,
17,
26,
32623,
304,
3842,
17,
12,
13567,
14,
6568,
14,
17,
14,
17,
26,
32623,
12,
378,
395,
2892,
334,
17,
12,
13567,
14,
6568,
14,
17,
14,
17,
26,
32623,
12,
413,
395,
2892,
334,
17,
12,
13567,
14,
6568,
14,
17,
14,
17,
26,
32623,
12,
499,
4360,
489,
334,
17,
12,
13567,
14,
6568,
14,
17,
14,
18,
26,
32623,
304,
3842,
17,
12,
13567,
14,
6568,
14,
17,
14,
18,
26,
32623,
12,
650,
395,
2892,
334,
17,
12,
13567,
14,
6568,
14,
17,
14,
18,
26,
32623,
12,
841,
395,
2892,
334,
17,
12,
13567,
14,
6568,
14,
17,
14,
18,
26,
32623,
12,
959,
4360,
489,
334,
18,
12,
13567,
14,
6568,
14,
18,
14,
17,
26,
32623,
304,
3842,
18,
12,
13567,
14,
6568,
14,
18,
14,
17,
26,
32623,
12,
1227,
395,
2892,
334,
18,
12,
13567,
14,
6568,
14,
18,
14,
17,
26,
32623,
12,
1520,
395,
2892,
334,
18,
12,
13567,
14,
6568,
14,
18,
14,
17,
26,
32623,
12,
1695,
4360,
489,
334,
18,
12,
13567,
14,
6568,
14,
18,
14,
18,
26,
32623,
304,
3842,
18,
12,
13567,
14,
6568,
14,
18,
14,
18,
26,
32623,
12,
1749,
395,
2892,
334,
18,
12,
13567,
14,
6568,
14,
18,
14,
18,
26,
32623,
12,
1616,
395,
2892,
334,
18,
12,
13567,
14,
6568,
14,
18,
14,
18,
26,
32623,
12,
4119,
4360,
272,
789,
339,
520,
6410,
26,
2243,
10809,
687,
1314,
370,
3550,
314,
3123,
272,
520,
5808,
26,
31800,
3123,
339,
408,
272,
31800,
18,
3223,
275,
10018,
8,
409,
9,
272,
367,
4866,
315,
7256,
26,
267,
367,
31800,
315,
3367,
1192,
63,
509,
63,
2374,
8,
2374,
304,
288,
340,
822,
8,
13949,
9,
690,
413,
26,
355,
31800,
18,
3223,
59,
13949,
59,
16,
6809,
17,
20230,
525,
8,
13949,
9,
288,
587,
26,
355,
31800,
18,
3223,
59,
342,
1055,
525,
8,
13949,
9,
272,
372,
31800,
18,
3223,
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
] |
[
5055,
492,
10018,
421,
199,
318,
3367,
1192,
63,
509,
63,
2374,
8,
2374,
304,
272,
408,
272,
1803,
282,
2008,
402,
3367,
1192,
367,
282,
1627,
2243,
315,
24525,
1865,
701,
272,
2582,
14,
339,
520,
5808,
26,
2008,
402,
3367,
1192,
272,
408,
272,
307,
17,
275,
4866,
459,
2619,
418,
272,
307,
18,
275,
5310,
711,
16495,
719,
5469,
908,
8,
711,
29,
2374,
14,
362,
360,
711,
659,
1844,
29,
2374,
14,
362,
360,
719,
1333,
272,
307,
19,
275,
4866,
459,
344,
418,
339,
372,
3666,
84,
17,
4706,
288,
334,
84,
17,
12,
307,
18,
395,
288,
334,
84,
17,
12,
307,
18,
12,
307,
19,
430,
421,
199,
318,
1900,
63,
13949,
63,
2350,
8,
6410,
304,
272,
408,
272,
9215,
314,
31800,
3123,
687,
314,
5718,
7054,
14,
339,
710,
31800,
3123,
365,
282,
2600,
626,
9033,
3367,
1192,
370,
3932,
1982,
3367,
1192,
14,
272,
437,
9560,
21231,
1738,
1031,
402,
6248,
365,
4046,
880,
626,
2337,
1159,
1373,
3123,
12,
272,
440,
282,
27882,
14,
339,
5679,
26,
339,
5718,
413,
446,
11,
375,
13567,
14,
6568,
14,
17,
14,
17,
26,
32623,
446,
11,
375,
2243,
1305,
378,
288,
1204,
9668,
1204,
288,
1204,
9668,
435,
375,
2243,
1305,
413,
288,
1204,
9668,
1204,
288,
1204,
9668,
435,
375,
2243,
1305,
499,
288,
1204,
288,
435,
375,
13567,
14,
6568,
14,
17,
14,
18,
26,
32623,
446,
11,
375,
2243,
1305,
650,
2511,
1204,
2511,
435,
375,
2243,
1305,
841,
2511,
1204,
2511,
435,
375,
2243,
1305,
959,
2378,
5718,
499,
446,
11,
375,
13567,
14,
6568,
14,
18,
14,
17,
26,
32623,
446,
11,
375,
2243,
1305,
1227,
288,
1204,
9668,
1204,
288,
1204,
9668,
435,
375,
2243,
1305,
1520,
288,
1204,
9668,
1204,
288,
1204,
9668,
435,
375,
2243,
1305,
1695,
288,
1204,
288,
435,
375,
13567,
14,
6568,
14,
18,
14,
18,
26,
32623,
446,
11,
375,
2243,
1305,
1749,
2511,
1204,
2511,
435,
375,
2243,
1305,
1616,
2511,
1204,
2511,
435,
375,
2243,
1305,
4119,
339,
710,
31800,
3123,
3955,
3648,
2839,
26,
272,
469,
489,
23390,
3842,
17,
4706,
334,
18,
32444,
2541,
334,
17,
16095,
3842,
17,
12,
13567,
14,
6568,
14,
17,
14,
17,
26,
32623,
395,
1467,
334,
17,
12,
13567,
14,
6568,
14,
17,
14,
18,
26,
32623,
4360,
489,
334,
18,
16095,
3842,
18,
12,
13567,
14,
6568,
14,
18,
14,
17,
26,
32623,
395,
1467,
334,
18,
12,
13567,
14,
6568,
14,
18,
14,
18,
26,
32623,
4360,
2541,
334,
17,
12,
13567,
14,
6568,
14,
17,
14,
17,
26,
32623,
304,
3842,
17,
12,
13567,
14,
6568,
14,
17,
14,
17,
26,
32623,
12,
378,
395,
2892,
334,
17,
12,
13567,
14,
6568,
14,
17,
14,
17,
26,
32623,
12,
413,
395,
2892,
334,
17,
12,
13567,
14,
6568,
14,
17,
14,
17,
26,
32623,
12,
499,
4360,
489,
334,
17,
12,
13567,
14,
6568,
14,
17,
14,
18,
26,
32623,
304,
3842,
17,
12,
13567,
14,
6568,
14,
17,
14,
18,
26,
32623,
12,
650,
395,
2892,
334,
17,
12,
13567,
14,
6568,
14,
17,
14,
18,
26,
32623,
12,
841,
395,
2892,
334,
17,
12,
13567,
14,
6568,
14,
17,
14,
18,
26,
32623,
12,
959,
4360,
489,
334,
18,
12,
13567,
14,
6568,
14,
18,
14,
17,
26,
32623,
304,
3842,
18,
12,
13567,
14,
6568,
14,
18,
14,
17,
26,
32623,
12,
1227,
395,
2892,
334,
18,
12,
13567,
14,
6568,
14,
18,
14,
17,
26,
32623,
12,
1520,
395,
2892,
334,
18,
12,
13567,
14,
6568,
14,
18,
14,
17,
26,
32623,
12,
1695,
4360,
489,
334,
18,
12,
13567,
14,
6568,
14,
18,
14,
18,
26,
32623,
304,
3842,
18,
12,
13567,
14,
6568,
14,
18,
14,
18,
26,
32623,
12,
1749,
395,
2892,
334,
18,
12,
13567,
14,
6568,
14,
18,
14,
18,
26,
32623,
12,
1616,
395,
2892,
334,
18,
12,
13567,
14,
6568,
14,
18,
14,
18,
26,
32623,
12,
4119,
4360,
272,
789,
339,
520,
6410,
26,
2243,
10809,
687,
1314,
370,
3550,
314,
3123,
272,
520,
5808,
26,
31800,
3123,
339,
408,
272,
31800,
18,
3223,
275,
10018,
8,
409,
9,
272,
367,
4866,
315,
7256,
26,
267,
367,
31800,
315,
3367,
1192,
63,
509,
63,
2374,
8,
2374,
304,
288,
340,
822,
8,
13949,
9,
690,
413,
26,
355,
31800,
18,
3223,
59,
13949,
59,
16,
6809,
17,
20230,
525,
8,
13949,
9,
288,
587,
26,
355,
31800,
18,
3223,
59,
342,
1055,
525,
8,
13949,
9,
272,
372,
31800,
18,
3223,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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""
import json
import logging
import re
import sys
from contextlib import contextmanager
from robottelo.common import conf
from robottelo.common.helpers import csv_to_dictionary
try:
import paramiko
except ImportError:
print "Please install paramiko."
sys.exit(-1)
logger = logging.getLogger(__name__)
class SSHCommandResult(object):
"""Structure that returns in all ssh commands results."""
def __init__(
self, stdout=None, stderr=None, return_code=0, output_format=None):
self.stdout = stdout
self.stderr = stderr
self.return_code = return_code
self.output_format = output_format
# Does not make sense to return suspicious output if ($? <> 0)
if output_format and self.return_code == 0:
if output_format == 'csv':
self.stdout = csv_to_dictionary(stdout) if stdout else {}
if output_format == 'json':
self.stdout = json.loads(stdout) if stdout else None
def _call_paramiko_sshclient():
"""Call ``paramiko.SSHClient``.
This function does not alter the behaviour of ``paramiko.SSHClient``. It
exists soley for the sake of easing unit testing: it can be overridden for
mocking purposes.
"""
return paramiko.SSHClient()
@contextmanager
def _get_connection(
hostname=None, username=None, key_filename=None, timeout=10):
"""Yield an ssh connection object.
The connection will be configured with the specified arguments or will
fall-back to server configuration in the configuration file.
Yield this SSH connection. The connection is automatically closed when the
caller is done using it using ``contextlib``, so clients should use the
``with`` statement to handle the object::
with _get_connection() as connection:
...
:param str hostname: The hosname of the server to stablish connection. If
it is ``None`` ``server.hostname`` from configuration's ``main``
section will be used.
:param str username: The username to use when connecting. If it is ``None``
``server.hostname`` from configuration's ``main`` section will be used.
:param str key_filename: The path of the ssh private key to use when
connecting to the server. If it is ``None`` ``server.hostname`` from
configuration's ``main`` section will be used.
:param int timeout: Time to wait for stablish the connection.
:return: An SSH connection.
:rtype: paramiko.SSHClient
"""
if hostname is None:
hostname = conf.properties['main.server.hostname']
if username is None:
username = conf.properties['main.server.ssh.username']
if key_filename is None:
key_filename = conf.properties['main.server.ssh.key_private']
client = _call_paramiko_sshclient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(
hostname=hostname,
username=username,
key_filename=key_filename,
timeout=timeout
)
client_id = hex(id(client))
try:
logger.info('Instantiated Paramiko client {0}'.format(client_id))
yield client
finally:
logger.info('Destroying Paramiko client {0}'.format(client_id))
client.close()
logger.info('Destroyed Paramiko client {0}'.format(client_id))
def upload_file(local_file, remote_file=None):
"""
Uploads a remote file to a normal server or
uploads a file to sauce labs via VPN tunnel.
"""
remote = int(conf.properties['main.remote'])
if not remote_file:
remote_file = local_file
if not remote:
with _get_connection() as connection:
sftp = connection.open_sftp()
sftp.put(local_file, remote_file)
sftp.close()
# TODO: Upload file to sauce labs via VPN tunnel in the else part.
def download_file(remote_file, local_file=None):
"""Download a remote file using sftp"""
if local_file is None:
local_file = remote_file
with _get_connection() as connection:
sftp = connection.open_sftp()
sftp.get(remote_file, local_file)
sftp.close()
def command(cmd, hostname=None, output_format=None, timeout=None):
"""
Executes SSH command(s) on remote hostname.
Defaults to main.server.hostname.
"""
# Set a default timeout of 120 seconds
if timeout is None:
timeout = 120
# Variable to hold results returned from the command
stdout = stderr = errorcode = None
# Remove escape code for colors displayed in the output
regex = re.compile(r'\x1b\[\d\d?m')
hostname = hostname or conf.properties['main.server.hostname']
logger.debug(">>> [%s] %s", hostname, cmd)
with _get_connection(hostname=hostname) as connection:
_, stdout, stderr = connection.exec_command(cmd, timeout)
errorcode = stdout.channel.recv_exit_status()
stdout = stdout.read()
stderr = stderr.read()
if stdout:
stdout = stdout.decode('utf-8')
logger.debug("<<<\n%s", stdout)
if stdout and output_format != 'json':
# For output we don't really want to see all of Rails traffic
# information, so strip it out.
# Empty fields are returned as "" which gives us u'""'
stdout = stdout.replace('""', '')
stdout = u"".join(stdout).split("\n")
stdout = [
regex.sub('', line) for line in stdout if not line.startswith("[")
]
# Ignore stderr if errorcode == 0. This is necessary since
# we're running Foreman in verbose mode which generates a lot
# of output return as stderr.
errors = [] if errorcode == 0 else stderr
if errors:
errors = regex.sub('', "".join(errors))
logger.debug("<<< %s", errors)
return SSHCommandResult(
stdout, errors, errorcode, output_format)
|
gpl-3.0
|
[
624,
199,
17505,
859,
370,
2429,
314,
5709,
8635,
1950,
199,
624,
199,
199,
646,
2022,
199,
646,
2050,
199,
646,
295,
199,
646,
984,
199,
199,
504,
15502,
492,
27608,
199,
504,
14544,
266,
320,
14,
2330,
492,
3743,
199,
504,
14544,
266,
320,
14,
2330,
14,
7546,
492,
7392,
63,
475,
63,
9086,
199,
199,
893,
26,
272,
492,
26162,
199,
2590,
3545,
26,
272,
870,
298,
8254,
3907,
26162,
2122,
272,
984,
14,
2224,
2801,
17,
9,
199,
199,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
12027,
3110,
2889,
8,
785,
304,
272,
408,
10766,
626,
2529,
315,
1006,
8635,
3718,
2058,
1041,
339,
347,
636,
826,
721,
288,
291,
12,
3839,
29,
403,
12,
4635,
29,
403,
12,
372,
63,
600,
29,
16,
12,
1072,
63,
908,
29,
403,
304,
267,
291,
14,
2703,
275,
3839,
267,
291,
14,
3083,
275,
4635,
267,
291,
14,
1107,
63,
600,
275,
372,
63,
600,
267,
291,
14,
1199,
63,
908,
275,
1072,
63,
908,
267,
327,
221,
12078,
440,
1852,
12249,
370,
372,
308,
28651,
1072,
340,
334,
4,
31,
20941,
378,
9,
267,
340,
1072,
63,
908,
436,
291,
14,
1107,
63,
600,
508,
378,
26,
288,
340,
1072,
63,
908,
508,
283,
4737,
356,
355,
291,
14,
2703,
275,
7392,
63,
475,
63,
9086,
8,
2703,
9,
340,
3839,
587,
1052,
288,
340,
1072,
63,
908,
508,
283,
1001,
356,
355,
291,
14,
2703,
275,
2022,
14,
3640,
8,
2703,
9,
340,
3839,
587,
488,
421,
199,
318,
485,
1250,
63,
635,
16625,
63,
5510,
1258,
837,
272,
408,
2176,
1124,
635,
16625,
14,
13716,
3041,
4345,
339,
961,
805,
1630,
440,
17355,
314,
13942,
402,
1124,
635,
16625,
14,
13716,
3041,
4345,
2779,
272,
3495,
880,
15515,
367,
314,
308,
1728,
402,
9600,
316,
4137,
5343,
26,
652,
883,
506,
10087,
367,
272,
1683,
316,
12901,
14,
339,
408,
272,
372,
26162,
14,
13716,
3041,
342,
421,
199,
32,
14237,
199,
318,
485,
362,
63,
2105,
8,
267,
6246,
29,
403,
12,
3434,
29,
403,
12,
790,
63,
1501,
29,
403,
12,
2653,
29,
709,
304,
272,
408,
22889,
376,
8635,
1950,
909,
14,
339,
710,
1950,
911,
506,
7526,
543,
314,
2013,
2368,
503,
911,
272,
11264,
13,
894,
370,
1654,
2897,
315,
314,
2897,
570,
14,
339,
23771,
642,
12027,
1950,
14,
710,
1950,
365,
5847,
6876,
1380,
314,
272,
8025,
365,
4224,
1808,
652,
1808,
1124,
23464,
4542,
880,
13431,
1077,
675,
314,
272,
1124,
1045,
1040,
5164,
370,
2429,
314,
909,
447,
398,
543,
485,
362,
63,
2105,
342,
465,
1950,
26,
288,
2263,
339,
520,
635,
620,
6246,
26,
710,
394,
736,
354,
402,
314,
1654,
370,
410,
13306,
1950,
14,
982,
267,
652,
365,
1124,
403,
1040,
1124,
1000,
14,
4269,
1040,
687,
2897,
1159,
1124,
973,
1040,
267,
3420,
911,
506,
1202,
14,
272,
520,
635,
620,
3434,
26,
710,
3434,
370,
675,
1380,
18170,
14,
982,
652,
365,
1124,
403,
1040,
267,
1124,
1000,
14,
4269,
1040,
687,
2897,
1159,
1124,
973,
1040,
3420,
911,
506,
1202,
14,
272,
520,
635,
620,
790,
63,
1501,
26,
710,
931,
402,
314,
8635,
5726,
790,
370,
675,
1380,
267,
18170,
370,
314,
1654,
14,
982,
652,
365,
1124,
403,
1040,
1124,
1000,
14,
4269,
1040,
687,
267,
2897,
1159,
1124,
973,
1040,
3420,
911,
506,
1202,
14,
272,
520,
635,
1109,
2653,
26,
4703,
370,
3618,
367,
410,
13306,
314,
1950,
14,
339,
520,
1107,
26,
1626,
12027,
1950,
14,
272,
520,
4500,
26,
26162,
14,
13716,
3041,
339,
408,
272,
340,
6246,
365,
488,
26,
267,
6246,
275,
3743,
14,
3282,
459,
973,
14,
1000,
14,
4269,
418,
272,
340,
3434,
365,
488,
26,
267,
3434,
275,
3743,
14,
3282,
459,
973,
14,
1000,
14,
5510,
14,
2473,
418,
272,
340,
790,
63,
1501,
365,
488,
26,
267,
790,
63,
1501,
275,
3743,
14,
3282,
459,
973,
14,
1000,
14,
5510,
14,
498,
63,
4239,
418,
339,
1890,
275,
485,
1250,
63,
635,
16625,
63,
5510,
1258,
342,
272,
1890,
14,
409,
63,
4752,
63,
1102,
63,
498,
63,
3185,
8,
635,
16625,
14,
3358,
1123,
4845,
1012,
272,
1890,
14,
2242,
8,
267,
6246,
29,
4269,
12,
267,
3434,
29,
2473,
12,
267,
790,
63,
1501,
29,
498,
63,
1501,
12,
267,
2653,
29,
2593,
272,
776,
339,
1890,
63,
344,
275,
6318,
8,
344,
8,
1258,
430,
272,
862,
26,
267,
2512,
14,
815,
360,
10083,
4466,
972,
12608,
16625,
1890,
469,
16,
5285,
908,
8,
1258,
63,
344,
430,
267,
1995,
1890,
272,
3753,
26,
267,
2512,
14,
815,
360,
14704,
316,
12608,
16625,
1890,
469,
16,
5285,
908,
8,
1258,
63,
344,
430,
267,
1890,
14,
1600,
342,
267,
2512,
14,
815,
360,
14704,
379,
12608,
16625,
1890,
469,
16,
5285,
908,
8,
1258,
63,
344,
430,
421,
199,
318,
5802,
63,
493,
8,
1832,
63,
493,
12,
3982,
63,
493,
29,
403,
304,
272,
408,
272,
4949,
3640,
282,
3982,
570,
370,
282,
3293,
1654,
503,
272,
26598,
282,
570,
370,
2937,
3683,
634,
2101,
4799,
29057,
21496,
14,
272,
408,
339,
3982,
275,
1109,
8,
2190,
14,
3282,
459,
973,
14,
3846,
1105,
339,
340,
440,
3982,
63,
493,
26,
267,
3982,
63,
493,
275,
2257,
63,
493,
339,
340,
440,
3982,
26,
267,
543,
485,
362,
63,
2105,
342,
465,
1950,
26,
288,
308,
8915,
275,
1950,
14,
1490,
63,
25032,
342,
288,
308,
8915,
14,
524,
8,
1832,
63,
493,
12,
3982,
63,
493,
9,
288,
308,
8915,
14,
1600,
342,
272,
327,
3254,
26,
19149,
570,
370,
2937,
3683,
634,
2101,
4799,
29057,
21496,
315,
314,
587,
1777,
14,
421,
199,
318,
5235,
63,
493,
8,
3846,
63,
493,
12,
2257,
63,
493,
29,
403,
304,
272,
408,
11950,
282,
3982,
570,
1808,
308,
8915,
624,
339,
340,
2257,
63,
493,
365,
488,
26,
267,
2257,
63,
493,
275,
3982,
63,
493,
339,
543,
485,
362,
63,
2105,
342,
465,
1950,
26,
267,
308,
8915,
275,
1950,
14,
1490,
63,
25032,
342,
267,
308,
8915,
14,
362,
8,
3846,
63,
493,
12,
2257,
63,
493,
9,
267,
308,
8915
] |
[
199,
17505,
859,
370,
2429,
314,
5709,
8635,
1950,
199,
624,
199,
199,
646,
2022,
199,
646,
2050,
199,
646,
295,
199,
646,
984,
199,
199,
504,
15502,
492,
27608,
199,
504,
14544,
266,
320,
14,
2330,
492,
3743,
199,
504,
14544,
266,
320,
14,
2330,
14,
7546,
492,
7392,
63,
475,
63,
9086,
199,
199,
893,
26,
272,
492,
26162,
199,
2590,
3545,
26,
272,
870,
298,
8254,
3907,
26162,
2122,
272,
984,
14,
2224,
2801,
17,
9,
199,
199,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
12027,
3110,
2889,
8,
785,
304,
272,
408,
10766,
626,
2529,
315,
1006,
8635,
3718,
2058,
1041,
339,
347,
636,
826,
721,
288,
291,
12,
3839,
29,
403,
12,
4635,
29,
403,
12,
372,
63,
600,
29,
16,
12,
1072,
63,
908,
29,
403,
304,
267,
291,
14,
2703,
275,
3839,
267,
291,
14,
3083,
275,
4635,
267,
291,
14,
1107,
63,
600,
275,
372,
63,
600,
267,
291,
14,
1199,
63,
908,
275,
1072,
63,
908,
267,
327,
221,
12078,
440,
1852,
12249,
370,
372,
308,
28651,
1072,
340,
334,
4,
31,
20941,
378,
9,
267,
340,
1072,
63,
908,
436,
291,
14,
1107,
63,
600,
508,
378,
26,
288,
340,
1072,
63,
908,
508,
283,
4737,
356,
355,
291,
14,
2703,
275,
7392,
63,
475,
63,
9086,
8,
2703,
9,
340,
3839,
587,
1052,
288,
340,
1072,
63,
908,
508,
283,
1001,
356,
355,
291,
14,
2703,
275,
2022,
14,
3640,
8,
2703,
9,
340,
3839,
587,
488,
421,
199,
318,
485,
1250,
63,
635,
16625,
63,
5510,
1258,
837,
272,
408,
2176,
1124,
635,
16625,
14,
13716,
3041,
4345,
339,
961,
805,
1630,
440,
17355,
314,
13942,
402,
1124,
635,
16625,
14,
13716,
3041,
4345,
2779,
272,
3495,
880,
15515,
367,
314,
308,
1728,
402,
9600,
316,
4137,
5343,
26,
652,
883,
506,
10087,
367,
272,
1683,
316,
12901,
14,
339,
408,
272,
372,
26162,
14,
13716,
3041,
342,
421,
199,
32,
14237,
199,
318,
485,
362,
63,
2105,
8,
267,
6246,
29,
403,
12,
3434,
29,
403,
12,
790,
63,
1501,
29,
403,
12,
2653,
29,
709,
304,
272,
408,
22889,
376,
8635,
1950,
909,
14,
339,
710,
1950,
911,
506,
7526,
543,
314,
2013,
2368,
503,
911,
272,
11264,
13,
894,
370,
1654,
2897,
315,
314,
2897,
570,
14,
339,
23771,
642,
12027,
1950,
14,
710,
1950,
365,
5847,
6876,
1380,
314,
272,
8025,
365,
4224,
1808,
652,
1808,
1124,
23464,
4542,
880,
13431,
1077,
675,
314,
272,
1124,
1045,
1040,
5164,
370,
2429,
314,
909,
447,
398,
543,
485,
362,
63,
2105,
342,
465,
1950,
26,
288,
2263,
339,
520,
635,
620,
6246,
26,
710,
394,
736,
354,
402,
314,
1654,
370,
410,
13306,
1950,
14,
982,
267,
652,
365,
1124,
403,
1040,
1124,
1000,
14,
4269,
1040,
687,
2897,
1159,
1124,
973,
1040,
267,
3420,
911,
506,
1202,
14,
272,
520,
635,
620,
3434,
26,
710,
3434,
370,
675,
1380,
18170,
14,
982,
652,
365,
1124,
403,
1040,
267,
1124,
1000,
14,
4269,
1040,
687,
2897,
1159,
1124,
973,
1040,
3420,
911,
506,
1202,
14,
272,
520,
635,
620,
790,
63,
1501,
26,
710,
931,
402,
314,
8635,
5726,
790,
370,
675,
1380,
267,
18170,
370,
314,
1654,
14,
982,
652,
365,
1124,
403,
1040,
1124,
1000,
14,
4269,
1040,
687,
267,
2897,
1159,
1124,
973,
1040,
3420,
911,
506,
1202,
14,
272,
520,
635,
1109,
2653,
26,
4703,
370,
3618,
367,
410,
13306,
314,
1950,
14,
339,
520,
1107,
26,
1626,
12027,
1950,
14,
272,
520,
4500,
26,
26162,
14,
13716,
3041,
339,
408,
272,
340,
6246,
365,
488,
26,
267,
6246,
275,
3743,
14,
3282,
459,
973,
14,
1000,
14,
4269,
418,
272,
340,
3434,
365,
488,
26,
267,
3434,
275,
3743,
14,
3282,
459,
973,
14,
1000,
14,
5510,
14,
2473,
418,
272,
340,
790,
63,
1501,
365,
488,
26,
267,
790,
63,
1501,
275,
3743,
14,
3282,
459,
973,
14,
1000,
14,
5510,
14,
498,
63,
4239,
418,
339,
1890,
275,
485,
1250,
63,
635,
16625,
63,
5510,
1258,
342,
272,
1890,
14,
409,
63,
4752,
63,
1102,
63,
498,
63,
3185,
8,
635,
16625,
14,
3358,
1123,
4845,
1012,
272,
1890,
14,
2242,
8,
267,
6246,
29,
4269,
12,
267,
3434,
29,
2473,
12,
267,
790,
63,
1501,
29,
498,
63,
1501,
12,
267,
2653,
29,
2593,
272,
776,
339,
1890,
63,
344,
275,
6318,
8,
344,
8,
1258,
430,
272,
862,
26,
267,
2512,
14,
815,
360,
10083,
4466,
972,
12608,
16625,
1890,
469,
16,
5285,
908,
8,
1258,
63,
344,
430,
267,
1995,
1890,
272,
3753,
26,
267,
2512,
14,
815,
360,
14704,
316,
12608,
16625,
1890,
469,
16,
5285,
908,
8,
1258,
63,
344,
430,
267,
1890,
14,
1600,
342,
267,
2512,
14,
815,
360,
14704,
379,
12608,
16625,
1890,
469,
16,
5285,
908,
8,
1258,
63,
344,
430,
421,
199,
318,
5802,
63,
493,
8,
1832,
63,
493,
12,
3982,
63,
493,
29,
403,
304,
272,
408,
272,
4949,
3640,
282,
3982,
570,
370,
282,
3293,
1654,
503,
272,
26598,
282,
570,
370,
2937,
3683,
634,
2101,
4799,
29057,
21496,
14,
272,
408,
339,
3982,
275,
1109,
8,
2190,
14,
3282,
459,
973,
14,
3846,
1105,
339,
340,
440,
3982,
63,
493,
26,
267,
3982,
63,
493,
275,
2257,
63,
493,
339,
340,
440,
3982,
26,
267,
543,
485,
362,
63,
2105,
342,
465,
1950,
26,
288,
308,
8915,
275,
1950,
14,
1490,
63,
25032,
342,
288,
308,
8915,
14,
524,
8,
1832,
63,
493,
12,
3982,
63,
493,
9,
288,
308,
8915,
14,
1600,
342,
272,
327,
3254,
26,
19149,
570,
370,
2937,
3683,
634,
2101,
4799,
29057,
21496,
315,
314,
587,
1777,
14,
421,
199,
318,
5235,
63,
493,
8,
3846,
63,
493,
12,
2257,
63,
493,
29,
403,
304,
272,
408,
11950,
282,
3982,
570,
1808,
308,
8915,
624,
339,
340,
2257,
63,
493,
365,
488,
26,
267,
2257,
63,
493,
275,
3982,
63,
493,
339,
543,
485,
362,
63,
2105,
342,
465,
1950,
26,
267,
308,
8915,
275,
1950,
14,
1490,
63,
25032,
342,
267,
308,
8915,
14,
362,
8,
3846,
63,
493,
12,
2257,
63,
493,
9,
267,
308,
8915,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
chrisjaquet/FreeCAD
|
src/Mod/Draft/importAirfoilDAT.py
|
25
|
6141
|
# -*- coding: utf-8 -*-
#***************************************************************************
#* *
#* Copyright (c) 2010 Heiko Jakob <heiko.jakob@gediegos.de> *
#* *
#* This program is free software; you can redistribute it and/or modify *
#* it under the terms of the GNU Lesser General Public License (LGPL) *
#* as published by the Free Software Foundation; either version 2 of *
#* the License, or (at your option) any later version. *
#* for detail see the LICENCE text file. *
#* *
#* 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 Library General Public License for more details. *
#* *
#* You should have received a copy of the GNU Library General Public *
#* License along with this program; if not, write to the Free Software *
#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
#* USA *
#* *
#***************************************************************************
__title__="FreeCAD Draft Workbench - Airfoil data importer"
__author__ = "Heiko Jakob <heiko.jakob@gediegos.de>"
import re, FreeCAD, FreeCADGui, Part, cProfile, os, string
from FreeCAD import Vector, Base
from Draft import makeWire
if open.__module__ == '__builtin__':
pythonopen = open
useDraftWire = True
def decodeName(name):
"decodes encoded strings"
try:
decodedName = (name.decode("utf8"))
except UnicodeDecodeError:
try:
decodedName = (name.decode("latin1"))
except UnicodeDecodeError:
print("AirfoilDAT: error: couldn't determine character encoding")
decodedName = name
return decodedName
def open(filename):
"called when freecad opens a file"
docname = os.path.splitext(os.path.basename(filename))[0]
doc = FreeCAD.newDocument(docname)
doc.Label = decodeName(docname[:-4])
process(doc,filename)
def insert(filename,docname):
"called when freecad imports a file"
groupname = os.path.splitext(os.path.basename(filename))[0]
try:
doc=FreeCAD.getDocument(docname)
except NameError:
doc=FreeCAD.newDocument(docname)
importgroup = doc.addObject("App::DocumentObjectGroup",groupname)
importgroup.Label = decodeName(groupname)
process(doc,filename)
def process(doc,filename):
# The common airfoil dat format has many flavors
# This code should work with almost every dialect
# Regex to identify data rows and throw away unused metadata
regex = re.compile(r'^\s*(?P<xval>(\-|\d*)\.\d+(E\-?\d+)?)\,?\s*(?P<yval>\-?\s*\d*\.\d+(E\-?\d+)?)\s*$')
afile = pythonopen(filename,'r')
# read the airfoil name which is always at the first line
airfoilname = afile.readline().strip()
coords=[]
upside=True
last_x=None
# Collect the data for the upper and the lower side seperately if possible
for lin in afile:
curdat = regex.match(lin)
if curdat != None:
x = float(curdat.group("xval"))
y = float(curdat.group("yval"))
# the normal processing
coords.append(Vector(x,y,0))
# End of if curdat != None
# End of for lin in file
afile.close()
if len(coords) < 3:
print('Did not find enough coordinates\n')
return
# sometimes coords are divided in upper an lower side
# so that x-coordinate begin new from leading or trailing edge
# check for start coordinates in the middle of list
if coords[0:-1].count(coords[0]) > 1:
flippoint = coords.index(coords[0],1)
upper = coords[0:flippoint]
lower = coords[flippoint+1:]
lower.reverse()
for i in lower:
upper.append(i)
coords = upper
# do we use the parametric Draft Wire?
if useDraftWire:
obj = makeWire ( coords, True )
#obj.label = airfoilname
else:
# alternate solution, uses common Part Faces
lines = []
first_v = None
last_v = None
for v in coords:
if first_v == None:
first_v = v
# End of if first_v == None
# Line between v and last_v if they're not equal
if (last_v != None) and (last_v != v):
lines.append(Part.makeLine(last_v, v))
# End of if (last_v != None) and (last_v != v)
# The new last_v
last_v = v
# End of for v in upper
# close the wire if needed
if last_v != first_v:
lines.append(Part.makeLine(last_v, first_v))
# End of if last_v != first_v
wire = Part.Wire(lines)
face = Part.Face(wire)
obj = FreeCAD.ActiveDocument.addObject('Part::Feature',airfoilname)
obj.Shape = face
doc.recompute()
|
lgpl-2.1
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
202,
199,
3,
17623,
202,
199,
15002,
17997,
627,
202,
199,
15002,
257,
1898,
334,
67,
9,
7129,
5311,
16625,
1603,
1151,
2873,
665,
426,
16625,
14,
74,
1151,
2873,
32,
303,
328,
5902,
736,
14,
271,
30,
4519,
627,
202,
199,
15002,
17997,
627,
202,
199,
15002,
257,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
221,
627,
202,
199,
15002,
257,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
844,
334,
44,
12006,
9,
259,
627,
202,
199,
15002,
257,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
258,
627,
202,
199,
15002,
257,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
7861,
627,
202,
199,
15002,
257,
367,
10093,
1937,
314,
5059,
6013,
1318,
570,
14,
2476,
627,
202,
199,
15002,
17997,
627,
202,
199,
15002,
257,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
755,
627,
202,
199,
15002,
257,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
263,
627,
202,
199,
15002,
257,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
260,
627,
202,
199,
15002,
257,
1664,
11243,
1696,
1684,
844,
367,
1655,
2436,
14,
8295,
627,
202,
199,
15002,
17997,
627,
202,
199,
15002,
257,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
11243,
1696,
1684,
258,
627,
202,
199,
15002,
257,
844,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
257,
627,
202,
199,
15002,
257,
2752,
12,
3277,
2020,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
221,
15673,
13,
13421,
221,
627,
202,
199,
15002,
257,
8217,
6208,
257,
627,
202,
199,
15002,
17997,
627,
202,
199,
3,
17623,
2999,
199,
363,
1213,
363,
628,
10146,
17238,
28090,
9361,
16571,
446,
22102,
545,
382,
666,
13479,
2,
202,
199,
363,
2502,
363,
275,
298,
1966,
16625,
1603,
1151,
2873,
665,
426,
16625,
14,
74,
1151,
2873,
32,
303,
328,
5902,
736,
14,
271,
4335,
2999,
199,
646,
295,
12,
20914,
12,
20914,
4324,
12,
14320,
12,
286,
5736,
12,
747,
12,
1059,
202,
199,
504,
20914,
492,
11388,
12,
3523,
202,
199,
504,
28090,
492,
1852,
25791,
2999,
199,
692,
1551,
855,
578,
363,
508,
2560,
5351,
3706,
1039,
2366,
1490,
275,
1551,
2999,
199,
1180,
18332,
25791,
275,
715,
2999,
199,
318,
4849,
985,
8,
354,
304,
1223,
198,
2,
2708,
83,
5737,
3326,
2,
1223,
198,
893,
26,
4122,
198,
16167,
985,
275,
334,
354,
14,
2708,
480,
1624,
24,
2237,
1223,
198,
2590,
18965,
26,
4122,
198,
893,
26,
7903,
198,
16167,
985,
275,
334,
354,
14,
2708,
480,
10378,
17,
2237,
4122,
198,
2590,
18965,
26,
7903,
198,
1361,
480,
28948,
545,
382,
6521,
26,
1125,
26,
21554,
1133,
6705,
4528,
2644,
531,
7903,
198,
16167,
985,
275,
536,
1223,
198,
1107,
11203,
985,
2999,
199,
318,
1551,
8,
1501,
304,
1223,
198,
2,
3527,
1380,
20673,
825,
350,
30848,
282,
570,
2,
1223,
198,
21828,
275,
747,
14,
515,
14,
7973,
8,
736,
14,
515,
14,
4846,
8,
1501,
11515,
16,
61,
1223,
198,
1301,
275,
20914,
14,
1222,
5564,
8,
21828,
9,
1223,
198,
1301,
14,
4314,
275,
4849,
985,
8,
21828,
4439,
20,
566,
1223,
198,
1412,
8,
1301,
12,
1501,
9,
2999,
199,
318,
5518,
8,
1501,
12,
21828,
304,
1223,
198,
2,
3527,
1380,
20673,
825,
350,
8925,
282,
570,
2,
1223,
198,
923,
354,
275,
747,
14,
515,
14,
7973,
8,
736,
14,
515,
14,
4846,
8,
1501,
11515,
16,
61,
1223,
198,
893,
26,
4122,
198,
1301,
29,
10146,
17238,
14,
362,
5564,
8,
21828,
9,
1223,
198,
2590,
12746,
26,
4122,
198,
1301,
29,
10146,
17238,
14,
1222,
5564,
8,
21828,
9,
1223,
198,
646,
923,
275,
1382,
14,
525,
1692,
480,
2640,
447,
5564,
1692,
2448,
401,
923,
354,
9,
1223,
198,
646,
923,
14,
4314,
275,
4849,
985,
8,
923,
354,
9,
1223,
198,
1412,
8,
1301,
12,
1501,
9,
2999,
199,
318,
2112,
8,
1301,
12,
1501,
304,
258,
1039,
327,
710,
2863,
12321,
545,
382,
6394,
1475,
965,
5002,
23547,
1039,
327,
961,
1233,
1077,
1736,
543,
18871,
4036,
10982,
8428,
1039,
327,
12939,
370,
10405,
666,
4730,
436,
7978,
13437,
9563,
3341,
1039,
5163,
275,
295,
14,
2014,
8,
82,
15542,
83,
30957,
48,
28,
88,
637,
30,
2961,
13,
6113,
68,
10,
2862,
3134,
68,
15622,
37,
16185,
8995,
68,
19544,
2862,
12,
8995,
83,
30957,
48,
28,
89,
637,
3072,
13,
8995,
83,
7590,
68,
7590,
3134,
68,
15622,
37,
16185,
8995,
68,
19544,
2862,
83,
10,
9988,
1039,
282,
493,
275,
2366,
1490,
8,
1501,
2584,
82,
358,
1039,
327,
1586,
314,
12321,
545,
382,
536,
1314,
365,
3544,
737,
314,
1642,
1004,
1039,
12321,
545,
382,
354,
275,
282,
493,
14,
6407,
1252,
1913,
342,
8428,
1039,
13259,
9811,
1039,
1536,
2441,
29,
549,
1039,
2061,
63,
88,
29,
403,
1223,
8428,
4341,
327,
19649,
314,
666,
367,
314,
7008,
436,
314,
5117,
5366,
542,
529,
13824,
340,
3962,
420,
1039,
367,
7403,
315,
282,
493,
26,
2628,
1094,
4616,
275,
5163,
14,
1431,
8,
472,
9,
2628,
340,
1094,
4616,
1137,
488,
26,
259,
202,
586,
8282,
671,
275,
2069,
8,
895,
4616,
14,
923,
480,
88,
637,
2237,
8282,
612,
275,
2069,
8,
895,
4616,
14,
923,
480,
89,
637,
2237,
2999,
717,
327,
314,
3293,
6661,
8282,
13259,
14,
740,
8,
3646,
8,
88,
12,
89,
12,
16,
430,
4483,
24216,
327,
9599,
402,
340,
1094,
4616,
1137,
488,
1039,
327,
9599,
402,
367,
7403,
315,
570,
1039,
282,
493,
14,
1600,
342,
8740,
8740,
13594,
340,
822,
8,
8032,
9,
665,
650,
26,
2628,
870,
360,
17366,
440,
2342,
8321,
8983,
60,
78,
358,
2628,
372,
221,
20085,
1039,
327,
15026,
13259,
787,
29378,
315,
7008,
376,
5117,
5366,
1039,
327,
880,
626,
671,
13,
20493,
5386,
892,
687,
9186,
503,
8520,
6275,
1039,
327,
1104,
367,
1343,
8983,
315,
314,
12180,
402,
769,
463,
4341,
340,
13259,
59,
16,
6809,
17,
1055,
835,
8
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
202,
199,
3,
17623,
202,
199,
15002,
17997,
627,
202,
199,
15002,
257,
1898,
334,
67,
9,
7129,
5311,
16625,
1603,
1151,
2873,
665,
426,
16625,
14,
74,
1151,
2873,
32,
303,
328,
5902,
736,
14,
271,
30,
4519,
627,
202,
199,
15002,
17997,
627,
202,
199,
15002,
257,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
221,
627,
202,
199,
15002,
257,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
844,
334,
44,
12006,
9,
259,
627,
202,
199,
15002,
257,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
258,
627,
202,
199,
15002,
257,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
7861,
627,
202,
199,
15002,
257,
367,
10093,
1937,
314,
5059,
6013,
1318,
570,
14,
2476,
627,
202,
199,
15002,
17997,
627,
202,
199,
15002,
257,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
755,
627,
202,
199,
15002,
257,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
263,
627,
202,
199,
15002,
257,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
260,
627,
202,
199,
15002,
257,
1664,
11243,
1696,
1684,
844,
367,
1655,
2436,
14,
8295,
627,
202,
199,
15002,
17997,
627,
202,
199,
15002,
257,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
11243,
1696,
1684,
258,
627,
202,
199,
15002,
257,
844,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
257,
627,
202,
199,
15002,
257,
2752,
12,
3277,
2020,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
221,
15673,
13,
13421,
221,
627,
202,
199,
15002,
257,
8217,
6208,
257,
627,
202,
199,
15002,
17997,
627,
202,
199,
3,
17623,
2999,
199,
363,
1213,
363,
628,
10146,
17238,
28090,
9361,
16571,
446,
22102,
545,
382,
666,
13479,
2,
202,
199,
363,
2502,
363,
275,
298,
1966,
16625,
1603,
1151,
2873,
665,
426,
16625,
14,
74,
1151,
2873,
32,
303,
328,
5902,
736,
14,
271,
4335,
2999,
199,
646,
295,
12,
20914,
12,
20914,
4324,
12,
14320,
12,
286,
5736,
12,
747,
12,
1059,
202,
199,
504,
20914,
492,
11388,
12,
3523,
202,
199,
504,
28090,
492,
1852,
25791,
2999,
199,
692,
1551,
855,
578,
363,
508,
2560,
5351,
3706,
1039,
2366,
1490,
275,
1551,
2999,
199,
1180,
18332,
25791,
275,
715,
2999,
199,
318,
4849,
985,
8,
354,
304,
1223,
198,
2,
2708,
83,
5737,
3326,
2,
1223,
198,
893,
26,
4122,
198,
16167,
985,
275,
334,
354,
14,
2708,
480,
1624,
24,
2237,
1223,
198,
2590,
18965,
26,
4122,
198,
893,
26,
7903,
198,
16167,
985,
275,
334,
354,
14,
2708,
480,
10378,
17,
2237,
4122,
198,
2590,
18965,
26,
7903,
198,
1361,
480,
28948,
545,
382,
6521,
26,
1125,
26,
21554,
1133,
6705,
4528,
2644,
531,
7903,
198,
16167,
985,
275,
536,
1223,
198,
1107,
11203,
985,
2999,
199,
318,
1551,
8,
1501,
304,
1223,
198,
2,
3527,
1380,
20673,
825,
350,
30848,
282,
570,
2,
1223,
198,
21828,
275,
747,
14,
515,
14,
7973,
8,
736,
14,
515,
14,
4846,
8,
1501,
11515,
16,
61,
1223,
198,
1301,
275,
20914,
14,
1222,
5564,
8,
21828,
9,
1223,
198,
1301,
14,
4314,
275,
4849,
985,
8,
21828,
4439,
20,
566,
1223,
198,
1412,
8,
1301,
12,
1501,
9,
2999,
199,
318,
5518,
8,
1501,
12,
21828,
304,
1223,
198,
2,
3527,
1380,
20673,
825,
350,
8925,
282,
570,
2,
1223,
198,
923,
354,
275,
747,
14,
515,
14,
7973,
8,
736,
14,
515,
14,
4846,
8,
1501,
11515,
16,
61,
1223,
198,
893,
26,
4122,
198,
1301,
29,
10146,
17238,
14,
362,
5564,
8,
21828,
9,
1223,
198,
2590,
12746,
26,
4122,
198,
1301,
29,
10146,
17238,
14,
1222,
5564,
8,
21828,
9,
1223,
198,
646,
923,
275,
1382,
14,
525,
1692,
480,
2640,
447,
5564,
1692,
2448,
401,
923,
354,
9,
1223,
198,
646,
923,
14,
4314,
275,
4849,
985,
8,
923,
354,
9,
1223,
198,
1412,
8,
1301,
12,
1501,
9,
2999,
199,
318,
2112,
8,
1301,
12,
1501,
304,
258,
1039,
327,
710,
2863,
12321,
545,
382,
6394,
1475,
965,
5002,
23547,
1039,
327,
961,
1233,
1077,
1736,
543,
18871,
4036,
10982,
8428,
1039,
327,
12939,
370,
10405,
666,
4730,
436,
7978,
13437,
9563,
3341,
1039,
5163,
275,
295,
14,
2014,
8,
82,
15542,
83,
30957,
48,
28,
88,
637,
30,
2961,
13,
6113,
68,
10,
2862,
3134,
68,
15622,
37,
16185,
8995,
68,
19544,
2862,
12,
8995,
83,
30957,
48,
28,
89,
637,
3072,
13,
8995,
83,
7590,
68,
7590,
3134,
68,
15622,
37,
16185,
8995,
68,
19544,
2862,
83,
10,
9988,
1039,
282,
493,
275,
2366,
1490,
8,
1501,
2584,
82,
358,
1039,
327,
1586,
314,
12321,
545,
382,
536,
1314,
365,
3544,
737,
314,
1642,
1004,
1039,
12321,
545,
382,
354,
275,
282,
493,
14,
6407,
1252,
1913,
342,
8428,
1039,
13259,
9811,
1039,
1536,
2441,
29,
549,
1039,
2061,
63,
88,
29,
403,
1223,
8428,
4341,
327,
19649,
314,
666,
367,
314,
7008,
436,
314,
5117,
5366,
542,
529,
13824,
340,
3962,
420,
1039,
367,
7403,
315,
282,
493,
26,
2628,
1094,
4616,
275,
5163,
14,
1431,
8,
472,
9,
2628,
340,
1094,
4616,
1137,
488,
26,
259,
202,
586,
8282,
671,
275,
2069,
8,
895,
4616,
14,
923,
480,
88,
637,
2237,
8282,
612,
275,
2069,
8,
895,
4616,
14,
923,
480,
89,
637,
2237,
2999,
717,
327,
314,
3293,
6661,
8282,
13259,
14,
740,
8,
3646,
8,
88,
12,
89,
12,
16,
430,
4483,
24216,
327,
9599,
402,
340,
1094,
4616,
1137,
488,
1039,
327,
9599,
402,
367,
7403,
315,
570,
1039,
282,
493,
14,
1600,
342,
8740,
8740,
13594,
340,
822,
8,
8032,
9,
665,
650,
26,
2628,
870,
360,
17366,
440,
2342,
8321,
8983,
60,
78,
358,
2628,
372,
221,
20085,
1039,
327,
15026,
13259,
787,
29378,
315,
7008,
376,
5117,
5366,
1039,
327,
880,
626,
671,
13,
20493,
5386,
892,
687,
9186,
503,
8520,
6275,
1039,
327,
1104,
367,
1343,
8983,
315,
314,
12180,
402,
769,
463,
4341,
340,
13259,
59,
16,
6809,
17,
1055,
835,
8,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Obus/scikit-learn
|
benchmarks/bench_plot_approximate_neighbors.py
|
85
|
6377
|
"""
Benchmark for approximate nearest neighbor search using
locality sensitive hashing forest.
There are two types of benchmarks.
First, accuracy of LSHForest queries are measured for various
hyper-parameters and index sizes.
Second, speed up of LSHForest queries compared to brute force
method in exact nearest neighbors is measures for the
aforementioned settings. In general, speed up is increasing as
the index size grows.
"""
from __future__ import division
import numpy as np
from tempfile import gettempdir
from time import time
from sklearn.neighbors import NearestNeighbors
from sklearn.neighbors.approximate import LSHForest
from sklearn.datasets import make_blobs
from sklearn.externals.joblib import Memory
m = Memory(cachedir=gettempdir())
@m.cache()
def make_data(n_samples, n_features, n_queries, random_state=0):
"""Create index and query data."""
print('Generating random blob-ish data')
X, _ = make_blobs(n_samples=n_samples + n_queries,
n_features=n_features, centers=100,
shuffle=True, random_state=random_state)
# Keep the last samples as held out query vectors: note since we used
# shuffle=True we have ensured that index and query vectors are
# samples from the same distribution (a mixture of 100 gaussians in this
# case)
return X[:n_samples], X[n_samples:]
def calc_exact_neighbors(X, queries, n_queries, n_neighbors):
"""Measures average times for exact neighbor queries."""
print ('Building NearestNeighbors for %d samples in %d dimensions' %
(X.shape[0], X.shape[1]))
nbrs = NearestNeighbors(algorithm='brute', metric='cosine').fit(X)
average_time = 0
t0 = time()
neighbors = nbrs.kneighbors(queries, n_neighbors=n_neighbors,
return_distance=False)
average_time = (time() - t0) / n_queries
return neighbors, average_time
def calc_accuracy(X, queries, n_queries, n_neighbors, exact_neighbors,
average_time_exact, **lshf_params):
"""Calculates accuracy and the speed up of LSHForest."""
print('Building LSHForest for %d samples in %d dimensions' %
(X.shape[0], X.shape[1]))
lshf = LSHForest(**lshf_params)
t0 = time()
lshf.fit(X)
lshf_build_time = time() - t0
print('Done in %0.3fs' % lshf_build_time)
accuracy = 0
t0 = time()
approx_neighbors = lshf.kneighbors(queries, n_neighbors=n_neighbors,
return_distance=False)
average_time_approx = (time() - t0) / n_queries
for i in range(len(queries)):
accuracy += np.in1d(approx_neighbors[i], exact_neighbors[i]).mean()
accuracy /= n_queries
speed_up = average_time_exact / average_time_approx
print('Average time for lshf neighbor queries: %0.3fs' %
average_time_approx)
print ('Average time for exact neighbor queries: %0.3fs' %
average_time_exact)
print ('Average Accuracy : %0.2f' % accuracy)
print ('Speed up: %0.1fx' % speed_up)
return speed_up, accuracy
if __name__ == '__main__':
import matplotlib.pyplot as plt
# Initialize index sizes
n_samples = [int(1e3), int(1e4), int(1e5), int(1e6)]
n_features = int(1e2)
n_queries = 100
n_neighbors = 10
X_index, X_query = make_data(np.max(n_samples), n_features, n_queries,
random_state=0)
params_list = [{'n_estimators': 3, 'n_candidates': 50},
{'n_estimators': 5, 'n_candidates': 70},
{'n_estimators': 10, 'n_candidates': 100}]
accuracies = np.zeros((len(n_samples), len(params_list)), dtype=float)
speed_ups = np.zeros((len(n_samples), len(params_list)), dtype=float)
for i, sample_size in enumerate(n_samples):
print ('==========================================================')
print ('Sample size: %i' % sample_size)
print ('------------------------')
exact_neighbors, average_time_exact = calc_exact_neighbors(
X_index[:sample_size], X_query, n_queries, n_neighbors)
for j, params in enumerate(params_list):
print ('LSHF parameters: n_estimators = %i, n_candidates = %i' %
(params['n_estimators'], params['n_candidates']))
speed_ups[i, j], accuracies[i, j] = calc_accuracy(
X_index[:sample_size], X_query, n_queries, n_neighbors,
exact_neighbors, average_time_exact, random_state=0, **params)
print ('')
print ('==========================================================')
# Set labels for LSHForest parameters
colors = ['c', 'm', 'y']
p1 = plt.Rectangle((0, 0), 0.1, 0.1, fc=colors[0])
p2 = plt.Rectangle((0, 0), 0.1, 0.1, fc=colors[1])
p3 = plt.Rectangle((0, 0), 0.1, 0.1, fc=colors[2])
labels = ['n_estimators=' + str(params_list[0]['n_estimators']) +
', n_candidates=' + str(params_list[0]['n_candidates']),
'n_estimators=' + str(params_list[1]['n_estimators']) +
', n_candidates=' + str(params_list[1]['n_candidates']),
'n_estimators=' + str(params_list[2]['n_estimators']) +
', n_candidates=' + str(params_list[2]['n_candidates'])]
# Plot precision
plt.figure()
plt.legend((p1, p2, p3), (labels[0], labels[1], labels[2]),
loc='upper left')
for i in range(len(params_list)):
plt.scatter(n_samples, accuracies[:, i], c=colors[i])
plt.plot(n_samples, accuracies[:, i], c=colors[i])
plt.ylim([0, 1.3])
plt.xlim(np.min(n_samples), np.max(n_samples))
plt.semilogx()
plt.ylabel("Precision@10")
plt.xlabel("Index size")
plt.grid(which='both')
plt.title("Precision of first 10 neighbors with index size")
# Plot speed up
plt.figure()
plt.legend((p1, p2, p3), (labels[0], labels[1], labels[2]),
loc='upper left')
for i in range(len(params_list)):
plt.scatter(n_samples, speed_ups[:, i], c=colors[i])
plt.plot(n_samples, speed_ups[:, i], c=colors[i])
plt.ylim(0, np.max(speed_ups))
plt.xlim(np.min(n_samples), np.max(n_samples))
plt.semilogx()
plt.ylabel("Speed up")
plt.xlabel("Index size")
plt.grid(which='both')
plt.title("Relationship between Speed up and index size")
plt.show()
|
bsd-3-clause
|
[
624,
199,
18644,
367,
19917,
17173,
15503,
2754,
1808,
199,
1832,
1209,
18423,
25223,
27882,
14,
199,
199,
10924,
787,
2877,
2943,
402,
12338,
83,
14,
199,
199,
7147,
12,
12862,
402,
491,
3234,
21668,
9212,
787,
27396,
367,
7750,
199,
9547,
13,
3214,
436,
1478,
10627,
14,
199,
199,
11906,
12,
8112,
1536,
402,
491,
3234,
21668,
9212,
13524,
370,
11665,
938,
3542,
199,
765,
315,
5835,
17173,
15845,
365,
17616,
1482,
367,
314,
199,
65,
1707,
32016,
379,
2202,
14,
1010,
8605,
12,
8112,
1536,
365,
22255,
465,
199,
1589,
1478,
1568,
486,
3838,
14,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
4629,
199,
199,
646,
2680,
465,
980,
199,
504,
5549,
492,
664,
11567,
199,
504,
900,
492,
900,
199,
199,
504,
6357,
14,
11113,
492,
5612,
9540,
20011,
199,
504,
6357,
14,
11113,
14,
16815,
6897,
492,
491,
3234,
21668,
199,
504,
6357,
14,
12281,
492,
1852,
63,
21893,
199,
504,
6357,
14,
24688,
14,
2423,
773,
492,
15825,
199,
199,
77,
275,
15825,
8,
1637,
694,
29,
31572,
1012,
421,
199,
32,
77,
14,
1637,
342,
199,
318,
1852,
63,
576,
8,
78,
63,
3356,
12,
302,
63,
3179,
12,
302,
63,
10590,
12,
2196,
63,
929,
29,
16,
304,
272,
408,
2499,
1478,
436,
1827,
666,
1041,
272,
870,
360,
29244,
2196,
9182,
13,
2453,
666,
358,
272,
1323,
12,
485,
275,
1852,
63,
21893,
8,
78,
63,
3356,
29,
78,
63,
3356,
435,
302,
63,
10590,
12,
1993,
302,
63,
3179,
29,
78,
63,
3179,
12,
19190,
29,
1960,
12,
1993,
13031,
29,
549,
12,
2196,
63,
929,
29,
2355,
63,
929,
9,
339,
327,
14797,
314,
2061,
5845,
465,
23608,
734,
1827,
11102,
26,
5317,
3967,
781,
1202,
272,
327,
13031,
29,
549,
781,
1172,
12889,
3297,
626,
1478,
436,
1827,
11102,
787,
272,
327,
5845,
687,
314,
2011,
4084,
334,
65,
31885,
402,
2948,
16072,
17759,
796,
315,
642,
272,
327,
1930,
9,
272,
372,
1323,
1491,
78,
63,
3356,
467,
1323,
59,
78,
63,
3356,
2938,
421,
199,
318,
12831,
63,
7327,
63,
11113,
8,
56,
12,
9212,
12,
302,
63,
10590,
12,
302,
63,
11113,
304,
272,
408,
1352,
305,
1482,
8095,
5431,
367,
5835,
15503,
9212,
1041,
272,
870,
661,
16461,
5612,
9540,
20011,
367,
450,
68,
5845,
315,
450,
68,
7365,
7,
450,
1779,
334,
56,
14,
1392,
59,
16,
467,
1323,
14,
1392,
59,
17,
2459,
272,
8526,
2393,
275,
5612,
9540,
20011,
8,
8833,
534,
3289,
938,
297,
6370,
534,
28485,
1959,
3269,
8,
56,
9,
272,
8095,
63,
521,
275,
378,
339,
307,
16,
275,
900,
342,
272,
15845,
275,
8526,
2393,
14,
75,
11113,
8,
10590,
12,
302,
63,
11113,
29,
78,
63,
11113,
12,
1816,
372,
63,
5590,
29,
797,
9,
272,
8095,
63,
521,
275,
334,
521,
342,
446,
307,
16,
9,
1182,
302,
63,
10590,
272,
372,
15845,
12,
8095,
63,
521,
421,
199,
318,
12831,
63,
13374,
8,
56,
12,
9212,
12,
302,
63,
10590,
12,
302,
63,
11113,
12,
5835,
63,
11113,
12,
2116,
8095,
63,
521,
63,
7327,
12,
1011,
478,
9188,
63,
1162,
304,
272,
408,
13862,
2335,
12862,
436,
314,
8112,
1536,
402,
491,
3234,
21668,
1041,
272,
870,
360,
16461,
491,
3234,
21668,
367,
450,
68,
5845,
315,
450,
68,
7365,
7,
450,
881,
334,
56,
14,
1392,
59,
16,
467,
1323,
14,
1392,
59,
17,
2459,
272,
9100,
9188,
275,
491,
3234,
21668,
3682,
478,
9188,
63,
1162,
9,
272,
307,
16,
275,
900,
342,
272,
9100,
9188,
14,
3269,
8,
56,
9,
272,
9100,
9188,
63,
1506,
63,
521,
275,
900,
342,
446,
307,
16,
272,
870,
360,
10759,
315,
450,
16,
14,
19,
2319,
7,
450,
9100,
9188,
63,
1506,
63,
521,
9,
339,
12862,
275,
378,
339,
307,
16,
275,
900,
342,
272,
14106,
63,
11113,
275,
9100,
9188,
14,
75,
11113,
8,
10590,
12,
302,
63,
11113,
29,
78,
63,
11113,
12,
4318,
372,
63,
5590,
29,
797,
9,
272,
8095,
63,
521,
63,
16815,
275,
334,
521,
342,
446,
307,
16,
9,
1182,
302,
63,
10590,
339,
367,
284,
315,
1425,
8,
552,
8,
10590,
2298,
267,
12862,
847,
980,
14,
262,
17,
68,
8,
16815,
63,
11113,
59,
73,
467,
5835,
63,
11113,
59,
73,
6575,
3670,
342,
339,
12862,
12257,
302,
63,
10590,
272,
8112,
63,
384,
275,
8095,
63,
521,
63,
7327,
1182,
8095,
63,
521,
63,
16815,
339,
870,
360,
17400,
900,
367,
9100,
9188,
15503,
9212,
26,
450,
16,
14,
19,
2319,
7,
450,
881,
8095,
63,
521,
63,
16815,
9,
272,
870,
661,
17400,
900,
367,
5835,
15503,
9212,
26,
450,
16,
14,
19,
2319,
7,
450,
1779,
8095,
63,
521,
63,
7327,
9,
272,
870,
661,
17400,
4473,
7933,
520,
450,
16,
14,
18,
70,
7,
450,
12862,
9,
272,
870,
661,
15146,
1536,
26,
450,
16,
14,
17,
12220,
7,
450,
8112,
63,
384,
9,
339,
372,
8112,
63,
384,
12,
12862,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
492,
8027,
14,
13563,
465,
4488,
272,
327,
11578,
1478,
10627,
272,
302,
63,
3356,
275,
359,
442,
8,
17,
69,
19,
395,
1109,
8,
17,
69,
20,
395,
1109,
8,
17,
69,
21,
395,
1109,
8,
17,
69,
22,
1874,
272,
302,
63,
3179,
275,
1109,
8,
17,
69,
18,
9,
272,
302,
63,
10590,
275,
2948,
272,
302,
63,
11113,
275,
1616,
339,
1323,
63,
1080,
12,
1323,
63,
1131,
275,
1852,
63,
576,
8,
1590,
14,
988,
8,
78,
63,
3356,
395,
302,
63,
3179,
12,
302,
63,
10590,
12,
639,
2196,
63,
929,
29,
16,
9,
339,
1862,
63,
513,
275,
9016,
78,
63,
10646,
356,
650,
12,
283,
78,
63,
16389,
356,
5238,
1386,
673,
791,
78,
63,
10646,
356,
959,
12,
283,
78,
63,
16389,
356,
10045,
1386,
673,
791,
78,
63,
10646,
356,
1616,
12,
283,
78,
63,
16389,
356,
2948,
11049,
339,
1066,
895,
65,
2578,
275,
980,
14,
4250,
1332,
552,
8,
78,
63,
3356,
395,
822,
8,
1162,
63,
513,
1826,
2152,
29,
1609,
9,
272,
8112,
63,
15203,
275,
980,
14,
4250,
1332,
552,
8,
78,
63,
3356
] |
[
199,
18644,
367,
19917,
17173,
15503,
2754,
1808,
199,
1832,
1209,
18423,
25223,
27882,
14,
199,
199,
10924,
787,
2877,
2943,
402,
12338,
83,
14,
199,
199,
7147,
12,
12862,
402,
491,
3234,
21668,
9212,
787,
27396,
367,
7750,
199,
9547,
13,
3214,
436,
1478,
10627,
14,
199,
199,
11906,
12,
8112,
1536,
402,
491,
3234,
21668,
9212,
13524,
370,
11665,
938,
3542,
199,
765,
315,
5835,
17173,
15845,
365,
17616,
1482,
367,
314,
199,
65,
1707,
32016,
379,
2202,
14,
1010,
8605,
12,
8112,
1536,
365,
22255,
465,
199,
1589,
1478,
1568,
486,
3838,
14,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
4629,
199,
199,
646,
2680,
465,
980,
199,
504,
5549,
492,
664,
11567,
199,
504,
900,
492,
900,
199,
199,
504,
6357,
14,
11113,
492,
5612,
9540,
20011,
199,
504,
6357,
14,
11113,
14,
16815,
6897,
492,
491,
3234,
21668,
199,
504,
6357,
14,
12281,
492,
1852,
63,
21893,
199,
504,
6357,
14,
24688,
14,
2423,
773,
492,
15825,
199,
199,
77,
275,
15825,
8,
1637,
694,
29,
31572,
1012,
421,
199,
32,
77,
14,
1637,
342,
199,
318,
1852,
63,
576,
8,
78,
63,
3356,
12,
302,
63,
3179,
12,
302,
63,
10590,
12,
2196,
63,
929,
29,
16,
304,
272,
408,
2499,
1478,
436,
1827,
666,
1041,
272,
870,
360,
29244,
2196,
9182,
13,
2453,
666,
358,
272,
1323,
12,
485,
275,
1852,
63,
21893,
8,
78,
63,
3356,
29,
78,
63,
3356,
435,
302,
63,
10590,
12,
1993,
302,
63,
3179,
29,
78,
63,
3179,
12,
19190,
29,
1960,
12,
1993,
13031,
29,
549,
12,
2196,
63,
929,
29,
2355,
63,
929,
9,
339,
327,
14797,
314,
2061,
5845,
465,
23608,
734,
1827,
11102,
26,
5317,
3967,
781,
1202,
272,
327,
13031,
29,
549,
781,
1172,
12889,
3297,
626,
1478,
436,
1827,
11102,
787,
272,
327,
5845,
687,
314,
2011,
4084,
334,
65,
31885,
402,
2948,
16072,
17759,
796,
315,
642,
272,
327,
1930,
9,
272,
372,
1323,
1491,
78,
63,
3356,
467,
1323,
59,
78,
63,
3356,
2938,
421,
199,
318,
12831,
63,
7327,
63,
11113,
8,
56,
12,
9212,
12,
302,
63,
10590,
12,
302,
63,
11113,
304,
272,
408,
1352,
305,
1482,
8095,
5431,
367,
5835,
15503,
9212,
1041,
272,
870,
661,
16461,
5612,
9540,
20011,
367,
450,
68,
5845,
315,
450,
68,
7365,
7,
450,
1779,
334,
56,
14,
1392,
59,
16,
467,
1323,
14,
1392,
59,
17,
2459,
272,
8526,
2393,
275,
5612,
9540,
20011,
8,
8833,
534,
3289,
938,
297,
6370,
534,
28485,
1959,
3269,
8,
56,
9,
272,
8095,
63,
521,
275,
378,
339,
307,
16,
275,
900,
342,
272,
15845,
275,
8526,
2393,
14,
75,
11113,
8,
10590,
12,
302,
63,
11113,
29,
78,
63,
11113,
12,
1816,
372,
63,
5590,
29,
797,
9,
272,
8095,
63,
521,
275,
334,
521,
342,
446,
307,
16,
9,
1182,
302,
63,
10590,
272,
372,
15845,
12,
8095,
63,
521,
421,
199,
318,
12831,
63,
13374,
8,
56,
12,
9212,
12,
302,
63,
10590,
12,
302,
63,
11113,
12,
5835,
63,
11113,
12,
2116,
8095,
63,
521,
63,
7327,
12,
1011,
478,
9188,
63,
1162,
304,
272,
408,
13862,
2335,
12862,
436,
314,
8112,
1536,
402,
491,
3234,
21668,
1041,
272,
870,
360,
16461,
491,
3234,
21668,
367,
450,
68,
5845,
315,
450,
68,
7365,
7,
450,
881,
334,
56,
14,
1392,
59,
16,
467,
1323,
14,
1392,
59,
17,
2459,
272,
9100,
9188,
275,
491,
3234,
21668,
3682,
478,
9188,
63,
1162,
9,
272,
307,
16,
275,
900,
342,
272,
9100,
9188,
14,
3269,
8,
56,
9,
272,
9100,
9188,
63,
1506,
63,
521,
275,
900,
342,
446,
307,
16,
272,
870,
360,
10759,
315,
450,
16,
14,
19,
2319,
7,
450,
9100,
9188,
63,
1506,
63,
521,
9,
339,
12862,
275,
378,
339,
307,
16,
275,
900,
342,
272,
14106,
63,
11113,
275,
9100,
9188,
14,
75,
11113,
8,
10590,
12,
302,
63,
11113,
29,
78,
63,
11113,
12,
4318,
372,
63,
5590,
29,
797,
9,
272,
8095,
63,
521,
63,
16815,
275,
334,
521,
342,
446,
307,
16,
9,
1182,
302,
63,
10590,
339,
367,
284,
315,
1425,
8,
552,
8,
10590,
2298,
267,
12862,
847,
980,
14,
262,
17,
68,
8,
16815,
63,
11113,
59,
73,
467,
5835,
63,
11113,
59,
73,
6575,
3670,
342,
339,
12862,
12257,
302,
63,
10590,
272,
8112,
63,
384,
275,
8095,
63,
521,
63,
7327,
1182,
8095,
63,
521,
63,
16815,
339,
870,
360,
17400,
900,
367,
9100,
9188,
15503,
9212,
26,
450,
16,
14,
19,
2319,
7,
450,
881,
8095,
63,
521,
63,
16815,
9,
272,
870,
661,
17400,
900,
367,
5835,
15503,
9212,
26,
450,
16,
14,
19,
2319,
7,
450,
1779,
8095,
63,
521,
63,
7327,
9,
272,
870,
661,
17400,
4473,
7933,
520,
450,
16,
14,
18,
70,
7,
450,
12862,
9,
272,
870,
661,
15146,
1536,
26,
450,
16,
14,
17,
12220,
7,
450,
8112,
63,
384,
9,
339,
372,
8112,
63,
384,
12,
12862,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
492,
8027,
14,
13563,
465,
4488,
272,
327,
11578,
1478,
10627,
272,
302,
63,
3356,
275,
359,
442,
8,
17,
69,
19,
395,
1109,
8,
17,
69,
20,
395,
1109,
8,
17,
69,
21,
395,
1109,
8,
17,
69,
22,
1874,
272,
302,
63,
3179,
275,
1109,
8,
17,
69,
18,
9,
272,
302,
63,
10590,
275,
2948,
272,
302,
63,
11113,
275,
1616,
339,
1323,
63,
1080,
12,
1323,
63,
1131,
275,
1852,
63,
576,
8,
1590,
14,
988,
8,
78,
63,
3356,
395,
302,
63,
3179,
12,
302,
63,
10590,
12,
639,
2196,
63,
929,
29,
16,
9,
339,
1862,
63,
513,
275,
9016,
78,
63,
10646,
356,
650,
12,
283,
78,
63,
16389,
356,
5238,
1386,
673,
791,
78,
63,
10646,
356,
959,
12,
283,
78,
63,
16389,
356,
10045,
1386,
673,
791,
78,
63,
10646,
356,
1616,
12,
283,
78,
63,
16389,
356,
2948,
11049,
339,
1066,
895,
65,
2578,
275,
980,
14,
4250,
1332,
552,
8,
78,
63,
3356,
395,
822,
8,
1162,
63,
513,
1826,
2152,
29,
1609,
9,
272,
8112,
63,
15203,
275,
980,
14,
4250,
1332,
552,
8,
78,
63,
3356,
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,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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
] |
gdgellatly/OCB1
|
openerp/osv/osv.py
|
8
|
10312
|
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
#.apidoc title: Objects Services (OSV)
from functools import wraps
import logging
import threading
from psycopg2 import IntegrityError, OperationalError, errorcodes
import orm
import openerp
import openerp.netsvc as netsvc
import openerp.pooler as pooler
import openerp.sql_db as sql_db
from openerp.tools.translate import translate
from openerp.osv.orm import MetaModel, Model, TransientModel, AbstractModel
import openerp.exceptions
from openerp.tools.config import config
import time
import random
import sys
_logger = logging.getLogger(__name__)
PG_CONCURRENCY_ERRORS_TO_RETRY = (errorcodes.LOCK_NOT_AVAILABLE, errorcodes.SERIALIZATION_FAILURE, errorcodes.DEADLOCK_DETECTED)
MAX_TRIES_ON_CONCURRENCY_FAILURE = 5
# Deprecated.
class except_osv(Exception):
def __init__(self, name, value):
self.name = name
self.value = value
self.args = (name, value)
service = None
class object_proxy(object):
def __init__(self):
global service
service = self
def check(f):
@wraps(f)
def wrapper(self, dbname, *args, **kwargs):
""" Wraps around OSV functions and normalises a few exceptions
"""
def tr(src, ttype):
# We try to do the same as the _(), but without the frame
# inspection, since we aready are wrapping an osv function
# trans_obj = self.get('ir.translation') cannot work yet :(
ctx = {}
if not kwargs:
if args and isinstance(args[-1], dict):
ctx = args[-1]
elif isinstance(kwargs, dict):
ctx = kwargs.get('context', {})
uid = 1
if args and isinstance(args[0], (long, int)):
uid = args[0]
lang = ctx and ctx.get('lang')
if not (lang or hasattr(src, '__call__')):
return src
# We open a *new* cursor here, one reason is that failed SQL
# queries (as in IntegrityError) will invalidate the current one.
cr = False
if hasattr(src, '__call__'):
# callable. We need to find the right parameters to call
# the orm._sql_message(self, cr, uid, ids, context) function,
# or we skip..
# our signature is f(osv_pool, dbname [,uid, obj, method, args])
try:
if args and len(args) > 1:
obj = self.get(args[1])
if len(args) > 3 and isinstance(args[3], (long, int, list)):
ids = args[3]
else:
ids = []
cr = sql_db.db_connect(dbname).cursor()
return src(obj, cr, uid, ids, context=(ctx or {}))
except Exception:
pass
finally:
if cr: cr.close()
return False # so that the original SQL error will
# be returned, it is the best we have.
try:
cr = sql_db.db_connect(dbname).cursor()
res = translate(cr, name=False, source_type=ttype,
lang=lang, source=src)
if res:
return res
else:
return src
finally:
if cr: cr.close()
def _(src):
return tr(src, 'code')
tries = 0
while True:
try:
if pooler.get_pool(dbname)._init:
raise except_osv('Database not ready', 'Currently, this database is not fully loaded and can not be used.')
return f(self, dbname, *args, **kwargs)
except OperationalError, e:
# Automatically retry the typical transaction serialization errors
if e.pgcode not in PG_CONCURRENCY_ERRORS_TO_RETRY:
raise
if tries >= MAX_TRIES_ON_CONCURRENCY_FAILURE:
_logger.warning("%s, maximum number of tries reached" % errorcodes.lookup(e.pgcode))
raise
wait_time = random.uniform(0.0, 2 ** tries)
tries += 1
_logger.info("%s, retry %d/%d in %.04f sec..." % (errorcodes.lookup(e.pgcode), tries, MAX_TRIES_ON_CONCURRENCY_FAILURE, wait_time))
time.sleep(wait_time)
except orm.except_orm, inst:
if config['debug_mode']: raise
_, _, tb = sys.exc_info()
raise except_osv(inst.name, inst.value), None, tb
except except_osv:
raise
except IntegrityError, inst:
if config['debug_mode']: raise
osv_pool = pooler.get_pool(dbname)
for key in osv_pool._sql_error.keys():
if key in inst[0]:
netsvc.abort_response(1, _('Constraint Error'), 'warning',
tr(osv_pool._sql_error[key], 'sql_constraint') or inst[0])
if inst.pgcode in (errorcodes.NOT_NULL_VIOLATION, errorcodes.FOREIGN_KEY_VIOLATION, errorcodes.RESTRICT_VIOLATION):
msg = _('The operation cannot be completed, probably due to the following:\n- deletion: you may be trying to delete a record while other records still reference it\n- creation/update: a mandatory field is not correctly set')
_logger.debug("IntegrityError", exc_info=True)
try:
errortxt = inst.pgerror.replace('«','"').replace('»','"')
if '"public".' in errortxt:
context = errortxt.split('"public".')[1]
model_name = table = context.split('"')[1]
else:
last_quote_end = errortxt.rfind('"')
last_quote_begin = errortxt.rfind('"', 0, last_quote_end)
model_name = table = errortxt[last_quote_begin+1:last_quote_end].strip()
model = table.replace("_",".")
model_obj = osv_pool.get(model)
if model_obj:
model_name = model_obj._description or model_obj._name
msg += _('\n\n[object with reference: %s - %s]') % (model_name, model)
except Exception:
pass
netsvc.abort_response(1, _('Integrity Error'), 'warning', msg)
else:
netsvc.abort_response(1, _('Integrity Error'), 'warning', inst[0])
except Exception:
_logger.exception("Uncaught exception")
raise
return wrapper
def execute_cr(self, cr, uid, obj, method, *args, **kw):
object = pooler.get_pool(cr.dbname).get(obj)
if not object:
raise except_osv('Object Error', 'Object %s doesn\'t exist' % str(obj))
return getattr(object, method)(cr, uid, *args, **kw)
def execute_kw(self, db, uid, obj, method, args, kw=None):
return self.execute(db, uid, obj, method, *args, **kw or {})
@check
def execute(self, db, uid, obj, method, *args, **kw):
cr = pooler.get_db(db).cursor()
try:
try:
if method.startswith('_'):
raise except_osv('Access Denied', 'Private methods (such as %s) cannot be called remotely.' % (method,))
res = self.execute_cr(cr, uid, obj, method, *args, **kw)
if res is None:
_logger.warning('The method %s of the object %s can not return `None` !', method, obj)
cr.commit()
except Exception:
cr.rollback()
raise
finally:
cr.close()
return res
def exec_workflow_cr(self, cr, uid, obj, signal, *args):
object = pooler.get_pool(cr.dbname).get(obj)
if not object:
raise except_osv('Object Error', 'Object %s doesn\'t exist' % str(obj))
res_id = args[0]
return object._workflow_signal(cr, uid, [res_id], signal)[res_id]
@check
def exec_workflow(self, db, uid, obj, signal, *args):
cr = pooler.get_db(db).cursor()
try:
try:
res = self.exec_workflow_cr(cr, uid, obj, signal, *args)
cr.commit()
except Exception:
cr.rollback()
raise
finally:
cr.close()
return res
# deprecated - for backward compatibility.
osv = Model
osv_memory = TransientModel
osv_abstract = AbstractModel # ;-)
def start_object_proxy():
object_proxy()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
8664,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
31827,
27703,
679,
2538,
26,
26794,
21813,
334,
3100,
54,
9,
199,
199,
504,
9143,
492,
14018,
199,
646,
2050,
199,
646,
5796,
199,
199,
504,
15492,
18,
492,
26864,
12,
6654,
6279,
547,
12,
1125,
6021,
199,
199,
646,
9813,
199,
646,
5166,
199,
646,
5166,
14,
846,
10599,
465,
1851,
10599,
199,
646,
5166,
14,
555,
79,
1435,
465,
1115,
79,
1435,
199,
646,
5166,
14,
3009,
63,
697,
465,
3875,
63,
697,
199,
504,
5166,
14,
2537,
14,
5275,
492,
9028,
199,
504,
5166,
14,
4795,
14,
1025,
492,
6288,
1685,
12,
5822,
12,
19894,
14928,
1685,
12,
11836,
1685,
199,
646,
5166,
14,
3924,
199,
504,
5166,
14,
2537,
14,
888,
492,
1101,
199,
199,
646,
900,
199,
646,
2196,
199,
646,
984,
199,
199,
63,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
11115,
63,
1864,
7013,
24861,
63,
21477,
63,
2566,
63,
27778,
275,
334,
705,
6021,
14,
4406,
63,
4609,
63,
17377,
12,
1125,
6021,
14,
19637,
22800,
63,
13989,
12,
1125,
6021,
14,
29031,
4406,
63,
17442,
3582,
1149,
9,
199,
4283,
63,
1766,
2563,
63,
615,
63,
1864,
7013,
24861,
63,
13989,
275,
959,
199,
199,
3,
17993,
14,
199,
533,
871,
63,
4795,
8,
1726,
304,
272,
347,
636,
826,
721,
277,
12,
536,
12,
574,
304,
267,
291,
14,
354,
275,
536,
267,
291,
14,
585,
275,
574,
267,
291,
14,
589,
275,
334,
354,
12,
574,
9,
199,
199,
1364,
275,
488,
199,
199,
533,
909,
63,
3280,
8,
785,
304,
272,
347,
636,
826,
721,
277,
304,
267,
2288,
2435,
267,
2435,
275,
291,
339,
347,
1104,
8,
70,
304,
267,
768,
13582,
8,
70,
9,
267,
347,
4975,
8,
277,
12,
21842,
12,
627,
589,
12,
1011,
958,
304,
288,
408,
644,
8146,
6818,
4403,
54,
3423,
436,
3293,
1388,
282,
9284,
4967,
288,
408,
953,
347,
5651,
8,
2164,
12,
17860,
304,
355,
327,
2136,
862,
370,
886,
314,
2011,
465,
314,
485,
1062,
1325,
1928,
314,
2787,
355,
327,
5261,
10303,
12,
3967,
781,
282,
2179,
787,
19696,
376,
9506,
805,
355,
327,
1752,
63,
1113,
275,
291,
14,
362,
360,
723,
14,
6893,
358,
3913,
1736,
5966,
520,
8,
355,
4027,
275,
1052,
355,
340,
440,
2074,
26,
490,
340,
1249,
436,
1228,
8,
589,
1988,
17,
467,
1211,
304,
717,
4027,
275,
1249,
1988,
17,
61,
355,
916,
1228,
8,
958,
12,
1211,
304,
490,
4027,
275,
2074,
14,
362,
360,
1100,
297,
5009,
2234,
1747,
275,
413,
355,
340,
1249,
436,
1228,
8,
589,
59,
16,
467,
334,
2809,
12,
1109,
2298,
490,
1747,
275,
1249,
59,
16,
61,
2234,
6339,
275,
4027,
436,
4027,
14,
362,
360,
4159,
358,
355,
340,
440,
334,
4159,
503,
2688,
8,
2164,
12,
2560,
1250,
363,
8109,
490,
372,
2928,
2234,
327,
2136,
1551,
282,
627,
1222,
10,
3920,
2348,
12,
1373,
4499,
365,
626,
3405,
5385,
355,
327,
9212,
334,
305,
315,
26864,
9,
911,
24841,
314,
1453,
1373,
14,
355,
2467,
275,
756,
2234,
340,
2688,
8,
2164,
12,
2560,
1250,
12168,
490,
327,
4550,
14,
2136,
1929,
370,
2342,
314,
2451,
2633,
370,
1240,
490,
327,
314,
221,
9813,
423,
3009,
63,
1188,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
1067,
9,
805,
12,
490,
327,
503,
781,
3372,
703,
490,
327,
4154,
4955,
365,
289,
8,
4795,
63,
2293,
12,
21842,
359,
12,
1535,
12,
1559,
12,
1083,
12,
1249,
566,
490,
862,
26,
717,
340,
1249,
436,
822,
8,
589,
9,
690,
413,
26,
1169,
1559,
275,
291,
14,
362,
8,
589,
59,
17,
566,
1169,
340,
822,
8,
589,
9,
690,
650,
436,
1228,
8,
589,
59,
19,
467,
334,
2809,
12,
1109,
12,
769,
2298,
1816,
2762,
275,
1249,
59,
19,
61,
1169,
587,
26,
1816,
2762,
275,
942,
717,
2467,
275,
3875,
63,
697,
14,
697,
63,
2242,
8,
13238,
680,
3937,
342,
717,
372,
2928,
8,
1113,
12,
2467,
12,
1747,
12,
2762,
12,
1067,
2687,
3799,
503,
17003,
490,
871,
2186,
26,
717,
986,
490,
3753,
26,
717,
340,
2467,
26,
2467,
14,
1600,
342,
4951,
372,
756,
327,
880,
626,
314,
3379,
5385,
1125,
911,
639,
327,
506,
2138,
12,
652,
365,
314,
5526,
781,
1172,
14,
2234,
862,
26,
490,
2467,
275,
3875,
63,
697,
14,
697,
63,
2242,
8,
13238,
680,
3937,
342,
490,
522,
275,
9028,
8,
1556,
12,
536,
29,
797,
12,
1350,
63,
466,
29,
21002,
12,
2511,
6339,
29,
4159,
12,
1350,
29,
2164,
9,
490,
340,
522,
26,
717,
372,
522,
490,
587,
26,
717,
372,
2928,
355,
3753,
26,
490,
340,
2467,
26,
2467,
14,
1600,
342,
953,
347,
12561,
2164,
304,
355,
372,
5651,
8,
2164,
12,
283,
600,
358,
953,
11275,
275,
378,
288,
1830,
715,
26,
355,
862,
26,
490,
340,
1115,
79,
1435,
14,
362,
63,
2293,
8,
13238,
10445,
826
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
8664,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
31827,
27703,
679,
2538,
26,
26794,
21813,
334,
3100,
54,
9,
199,
199,
504,
9143,
492,
14018,
199,
646,
2050,
199,
646,
5796,
199,
199,
504,
15492,
18,
492,
26864,
12,
6654,
6279,
547,
12,
1125,
6021,
199,
199,
646,
9813,
199,
646,
5166,
199,
646,
5166,
14,
846,
10599,
465,
1851,
10599,
199,
646,
5166,
14,
555,
79,
1435,
465,
1115,
79,
1435,
199,
646,
5166,
14,
3009,
63,
697,
465,
3875,
63,
697,
199,
504,
5166,
14,
2537,
14,
5275,
492,
9028,
199,
504,
5166,
14,
4795,
14,
1025,
492,
6288,
1685,
12,
5822,
12,
19894,
14928,
1685,
12,
11836,
1685,
199,
646,
5166,
14,
3924,
199,
504,
5166,
14,
2537,
14,
888,
492,
1101,
199,
199,
646,
900,
199,
646,
2196,
199,
646,
984,
199,
199,
63,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
11115,
63,
1864,
7013,
24861,
63,
21477,
63,
2566,
63,
27778,
275,
334,
705,
6021,
14,
4406,
63,
4609,
63,
17377,
12,
1125,
6021,
14,
19637,
22800,
63,
13989,
12,
1125,
6021,
14,
29031,
4406,
63,
17442,
3582,
1149,
9,
199,
4283,
63,
1766,
2563,
63,
615,
63,
1864,
7013,
24861,
63,
13989,
275,
959,
199,
199,
3,
17993,
14,
199,
533,
871,
63,
4795,
8,
1726,
304,
272,
347,
636,
826,
721,
277,
12,
536,
12,
574,
304,
267,
291,
14,
354,
275,
536,
267,
291,
14,
585,
275,
574,
267,
291,
14,
589,
275,
334,
354,
12,
574,
9,
199,
199,
1364,
275,
488,
199,
199,
533,
909,
63,
3280,
8,
785,
304,
272,
347,
636,
826,
721,
277,
304,
267,
2288,
2435,
267,
2435,
275,
291,
339,
347,
1104,
8,
70,
304,
267,
768,
13582,
8,
70,
9,
267,
347,
4975,
8,
277,
12,
21842,
12,
627,
589,
12,
1011,
958,
304,
288,
408,
644,
8146,
6818,
4403,
54,
3423,
436,
3293,
1388,
282,
9284,
4967,
288,
408,
953,
347,
5651,
8,
2164,
12,
17860,
304,
355,
327,
2136,
862,
370,
886,
314,
2011,
465,
314,
485,
1062,
1325,
1928,
314,
2787,
355,
327,
5261,
10303,
12,
3967,
781,
282,
2179,
787,
19696,
376,
9506,
805,
355,
327,
1752,
63,
1113,
275,
291,
14,
362,
360,
723,
14,
6893,
358,
3913,
1736,
5966,
520,
8,
355,
4027,
275,
1052,
355,
340,
440,
2074,
26,
490,
340,
1249,
436,
1228,
8,
589,
1988,
17,
467,
1211,
304,
717,
4027,
275,
1249,
1988,
17,
61,
355,
916,
1228,
8,
958,
12,
1211,
304,
490,
4027,
275,
2074,
14,
362,
360,
1100,
297,
5009,
2234,
1747,
275,
413,
355,
340,
1249,
436,
1228,
8,
589,
59,
16,
467,
334,
2809,
12,
1109,
2298,
490,
1747,
275,
1249,
59,
16,
61,
2234,
6339,
275,
4027,
436,
4027,
14,
362,
360,
4159,
358,
355,
340,
440,
334,
4159,
503,
2688,
8,
2164,
12,
2560,
1250,
363,
8109,
490,
372,
2928,
2234,
327,
2136,
1551,
282,
627,
1222,
10,
3920,
2348,
12,
1373,
4499,
365,
626,
3405,
5385,
355,
327,
9212,
334,
305,
315,
26864,
9,
911,
24841,
314,
1453,
1373,
14,
355,
2467,
275,
756,
2234,
340,
2688,
8,
2164,
12,
2560,
1250,
12168,
490,
327,
4550,
14,
2136,
1929,
370,
2342,
314,
2451,
2633,
370,
1240,
490,
327,
314,
221,
9813,
423,
3009,
63,
1188,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
1067,
9,
805,
12,
490,
327,
503,
781,
3372,
703,
490,
327,
4154,
4955,
365,
289,
8,
4795,
63,
2293,
12,
21842,
359,
12,
1535,
12,
1559,
12,
1083,
12,
1249,
566,
490,
862,
26,
717,
340,
1249,
436,
822,
8,
589,
9,
690,
413,
26,
1169,
1559,
275,
291,
14,
362,
8,
589,
59,
17,
566,
1169,
340,
822,
8,
589,
9,
690,
650,
436,
1228,
8,
589,
59,
19,
467,
334,
2809,
12,
1109,
12,
769,
2298,
1816,
2762,
275,
1249,
59,
19,
61,
1169,
587,
26,
1816,
2762,
275,
942,
717,
2467,
275,
3875,
63,
697,
14,
697,
63,
2242,
8,
13238,
680,
3937,
342,
717,
372,
2928,
8,
1113,
12,
2467,
12,
1747,
12,
2762,
12,
1067,
2687,
3799,
503,
17003,
490,
871,
2186,
26,
717,
986,
490,
3753,
26,
717,
340,
2467,
26,
2467,
14,
1600,
342,
4951,
372,
756,
327,
880,
626,
314,
3379,
5385,
1125,
911,
639,
327,
506,
2138,
12,
652,
365,
314,
5526,
781,
1172,
14,
2234,
862,
26,
490,
2467,
275,
3875,
63,
697,
14,
697,
63,
2242,
8,
13238,
680,
3937,
342,
490,
522,
275,
9028,
8,
1556,
12,
536,
29,
797,
12,
1350,
63,
466,
29,
21002,
12,
2511,
6339,
29,
4159,
12,
1350,
29,
2164,
9,
490,
340,
522,
26,
717,
372,
522,
490,
587,
26,
717,
372,
2928,
355,
3753,
26,
490,
340,
2467,
26,
2467,
14,
1600,
342,
953,
347,
12561,
2164,
304,
355,
372,
5651,
8,
2164,
12,
283,
600,
358,
953,
11275,
275,
378,
288,
1830,
715,
26,
355,
862,
26,
490,
340,
1115,
79,
1435,
14,
362,
63,
2293,
8,
13238,
10445,
826,
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
] |
jamescpipe/python-oauth2
|
example/client.py
|
375
|
6700
|
"""
The MIT License
Copyright (c) 2007 Leah Culver
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
Example consumer. This is not recommended for production.
Instead, you'll want to create your own subclass of OAuthClient
or find one that works with your web framework.
"""
import httplib
import time
import oauth.oauth as oauth
# settings for the local test consumer
SERVER = 'localhost'
PORT = 8080
# fake urls for the test server (matches ones in server.py)
REQUEST_TOKEN_URL = 'https://photos.example.net/request_token'
ACCESS_TOKEN_URL = 'https://photos.example.net/access_token'
AUTHORIZATION_URL = 'https://photos.example.net/authorize'
CALLBACK_URL = 'http://printer.example.com/request_token_ready'
RESOURCE_URL = 'http://photos.example.net/photos'
# key and secret granted by the service provider for this consumer application - same as the MockOAuthDataStore
CONSUMER_KEY = 'key'
CONSUMER_SECRET = 'secret'
# example client using httplib with headers
class SimpleOAuthClient(oauth.OAuthClient):
def __init__(self, server, port=httplib.HTTP_PORT, request_token_url='', access_token_url='', authorization_url=''):
self.server = server
self.port = port
self.request_token_url = request_token_url
self.access_token_url = access_token_url
self.authorization_url = authorization_url
self.connection = httplib.HTTPConnection("%s:%d" % (self.server, self.port))
def fetch_request_token(self, oauth_request):
# via headers
# -> OAuthToken
self.connection.request(oauth_request.http_method, self.request_token_url, headers=oauth_request.to_header())
response = self.connection.getresponse()
return oauth.OAuthToken.from_string(response.read())
def fetch_access_token(self, oauth_request):
# via headers
# -> OAuthToken
self.connection.request(oauth_request.http_method, self.access_token_url, headers=oauth_request.to_header())
response = self.connection.getresponse()
return oauth.OAuthToken.from_string(response.read())
def authorize_token(self, oauth_request):
# via url
# -> typically just some okay response
self.connection.request(oauth_request.http_method, oauth_request.to_url())
response = self.connection.getresponse()
return response.read()
def access_resource(self, oauth_request):
# via post body
# -> some protected resources
headers = {'Content-Type' :'application/x-www-form-urlencoded'}
self.connection.request('POST', RESOURCE_URL, body=oauth_request.to_postdata(), headers=headers)
response = self.connection.getresponse()
return response.read()
def run_example():
# setup
print '** OAuth Python Library Example **'
client = SimpleOAuthClient(SERVER, PORT, REQUEST_TOKEN_URL, ACCESS_TOKEN_URL, AUTHORIZATION_URL)
consumer = oauth.OAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET)
signature_method_plaintext = oauth.OAuthSignatureMethod_PLAINTEXT()
signature_method_hmac_sha1 = oauth.OAuthSignatureMethod_HMAC_SHA1()
pause()
# get request token
print '* Obtain a request token ...'
pause()
oauth_request = oauth.OAuthRequest.from_consumer_and_token(consumer, callback=CALLBACK_URL, http_url=client.request_token_url)
oauth_request.sign_request(signature_method_plaintext, consumer, None)
print 'REQUEST (via headers)'
print 'parameters: %s' % str(oauth_request.parameters)
pause()
token = client.fetch_request_token(oauth_request)
print 'GOT'
print 'key: %s' % str(token.key)
print 'secret: %s' % str(token.secret)
print 'callback confirmed? %s' % str(token.callback_confirmed)
pause()
print '* Authorize the request token ...'
pause()
oauth_request = oauth.OAuthRequest.from_token_and_callback(token=token, http_url=client.authorization_url)
print 'REQUEST (via url query string)'
print 'parameters: %s' % str(oauth_request.parameters)
pause()
# this will actually occur only on some callback
response = client.authorize_token(oauth_request)
print 'GOT'
print response
# sad way to get the verifier
import urlparse, cgi
query = urlparse.urlparse(response)[4]
params = cgi.parse_qs(query, keep_blank_values=False)
verifier = params['oauth_verifier'][0]
print 'verifier: %s' % verifier
pause()
# get access token
print '* Obtain an access token ...'
pause()
oauth_request = oauth.OAuthRequest.from_consumer_and_token(consumer, token=token, verifier=verifier, http_url=client.access_token_url)
oauth_request.sign_request(signature_method_plaintext, consumer, token)
print 'REQUEST (via headers)'
print 'parameters: %s' % str(oauth_request.parameters)
pause()
token = client.fetch_access_token(oauth_request)
print 'GOT'
print 'key: %s' % str(token.key)
print 'secret: %s' % str(token.secret)
pause()
# access some protected resources
print '* Access protected resources ...'
pause()
parameters = {'file': 'vacation.jpg', 'size': 'original'} # resource specific params
oauth_request = oauth.OAuthRequest.from_consumer_and_token(consumer, token=token, http_method='POST', http_url=RESOURCE_URL, parameters=parameters)
oauth_request.sign_request(signature_method_hmac_sha1, consumer, token)
print 'REQUEST (via post body)'
print 'parameters: %s' % str(oauth_request.parameters)
pause()
params = client.access_resource(oauth_request)
print 'GOT'
print 'non-oauth parameters: %s' % params
pause()
def pause():
print ''
time.sleep(1)
if __name__ == '__main__':
run_example()
print 'Done.'
|
mit
|
[
624,
199,
1918,
10697,
844,
199,
199,
7384,
334,
67,
9,
10219,
491,
4489,
72,
445,
348,
422,
199,
199,
7980,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
1331,
199,
1618,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
298,
10337,
1288,
370,
7962,
199,
262,
314,
2290,
1928,
10588,
12,
5893,
1928,
12305,
314,
4481,
199,
475,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
11207,
12,
13473,
12,
436,
15,
269,
12743,
199,
16847,
402,
314,
2290,
12,
436,
370,
11291,
12103,
370,
12676,
314,
2290,
365,
199,
70,
13399,
370,
886,
880,
12,
5420,
370,
314,
2569,
3704,
26,
199,
199,
1918,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
315,
199,
452,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
199,
18061,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
1549,
199,
8947,
5177,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
3169,
12,
199,
38,
3061,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
7000,
2334,
199,
5580,
4149,
1549,
5877,
8164,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
199,
2673,
2477,
12,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
199,
1877,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
199,
18061,
4141,
14,
199,
199,
9846,
9790,
14,
961,
365,
440,
14318,
367,
9920,
14,
199,
13962,
13558,
12,
1265,
7171,
2934,
370,
1218,
2195,
5705,
5516,
402,
11715,
3041,
199,
269,
2342,
1373,
626,
5419,
543,
2195,
3330,
10059,
14,
199,
624,
199,
199,
646,
8809,
199,
646,
900,
199,
646,
9725,
14,
6126,
465,
9725,
199,
199,
3,
2202,
367,
314,
2257,
511,
9790,
199,
6613,
275,
283,
5967,
7,
199,
3657,
275,
30220,
199,
199,
3,
4026,
8187,
367,
314,
511,
1654,
334,
6742,
7869,
315,
1654,
14,
647,
9,
199,
6780,
63,
8803,
63,
2632,
275,
283,
2859,
921,
25211,
14,
2694,
14,
846,
15,
1069,
63,
1418,
7,
199,
11074,
63,
8803,
63,
2632,
275,
283,
2859,
921,
25211,
14,
2694,
14,
846,
15,
2732,
63,
1418,
7,
199,
25303,
2594,
63,
2632,
275,
283,
2859,
921,
25211,
14,
2694,
14,
846,
15,
14204,
7,
199,
28100,
63,
2632,
275,
283,
1014,
921,
11835,
14,
2694,
14,
957,
15,
1069,
63,
1418,
63,
2179,
7,
199,
14110,
63,
2632,
275,
283,
1014,
921,
25211,
14,
2694,
14,
846,
15,
25211,
7,
199,
199,
3,
790,
436,
7565,
10009,
701,
314,
2435,
5022,
367,
642,
9790,
4223,
446,
2011,
465,
314,
4420,
12906,
1451,
5502,
199,
1864,
13285,
540,
63,
3078,
275,
283,
498,
7,
199,
1864,
13285,
540,
63,
12961,
275,
283,
4731,
7,
199,
199,
3,
2893,
1890,
1808,
8809,
543,
2323,
199,
533,
5870,
12906,
3041,
8,
6126,
14,
12906,
3041,
304,
339,
347,
636,
826,
721,
277,
12,
1654,
12,
1844,
29,
12942,
14,
2856,
63,
3657,
12,
1056,
63,
1418,
63,
633,
4581,
2879,
63,
1418,
63,
633,
4581,
13448,
63,
633,
9280,
267,
291,
14,
1000,
275,
1654,
267,
291,
14,
719,
275,
1844,
267,
291,
14,
1069,
63,
1418,
63,
633,
275,
1056,
63,
1418,
63,
633,
267,
291,
14,
2732,
63,
1418,
63,
633,
275,
2879,
63,
1418,
63,
633,
267,
291,
14,
15846,
63,
633,
275,
13448,
63,
633,
267,
291,
14,
2105,
275,
8809,
14,
19114,
3647,
83,
2689,
68,
2,
450,
334,
277,
14,
1000,
12,
291,
14,
719,
430,
339,
347,
5267,
63,
1069,
63,
1418,
8,
277,
12,
9725,
63,
1069,
304,
267,
327,
4799,
2323,
267,
327,
1035,
11715,
3264,
267,
291,
14,
2105,
14,
1069,
8,
6126,
63,
1069,
14,
1014,
63,
765,
12,
291,
14,
1069,
63,
1418,
63,
633,
12,
2323,
29,
6126,
63,
1069,
14,
475,
63,
1291,
1012,
4960,
1177,
275,
291,
14,
2105,
14,
25006,
342,
267,
372,
9725,
14,
12906,
3264,
14,
504,
63,
875,
8,
1310,
14,
739,
1012,
339,
347,
5267,
63,
2732,
63,
1418,
8,
277,
12,
9725,
63,
1069,
304,
267,
327,
4799,
2323,
267,
327,
1035,
11715,
3264,
267,
291,
14,
2105,
14,
1069,
8,
6126,
63,
1069,
14,
1014,
63,
765,
12,
291,
14,
2732,
63,
1418,
63,
633,
12,
2323,
29,
6126,
63,
1069,
14,
475,
63,
1291,
1012,
4960,
1177,
275,
291,
14,
2105,
14,
25006,
342,
267,
372,
9725,
14,
12906,
3264,
14,
504,
63,
875,
8,
1310,
14,
739,
1012,
339,
347,
20210,
63,
1418,
8,
277,
12,
9725,
63,
1069,
304,
267,
327,
4799,
1166,
267,
327,
1035,
13609,
2951,
2005,
5849,
1177,
267,
291,
14,
2105,
14,
1069,
8,
6126,
63,
1069,
14,
1014,
63,
765,
12,
9725,
63,
1069,
14,
475,
63,
633,
1012,
4960,
1177,
275,
291,
14,
2105,
14,
25006,
342,
267,
372,
1177,
14,
739,
342,
339,
347,
2879,
63,
1927,
8,
277,
12,
9725,
63,
1069,
304,
267,
327,
4799,
2963,
2396,
267,
327,
1035,
2005,
17819,
5944,
267,
2323,
275,
791,
2714,
13,
804,
7,
520,
7,
3578,
15,
88,
13,
1544,
13,
964,
13,
21886,
936,
267,
291,
14,
2105,
14,
1069,
360,
4030,
297,
30061,
63,
2632,
12,
2396,
29,
6126,
63,
1069,
14,
475,
63,
1932,
576,
1062,
2323,
29,
2139,
9,
267,
1177,
275,
291,
14,
2105,
14,
25006,
342,
267,
372,
1177,
14,
739,
342,
199,
199,
318,
1255,
63,
2694,
837,
339,
327,
3272,
272,
870,
23940,
11715,
2018,
11243,
5679,
1011,
7,
272,
1890,
275,
5870,
12906,
3041,
8,
6613,
12,
25562,
12,
31325,
63,
8803,
63,
2632,
12,
437,
10203,
63,
8803,
63,
2632,
12,
7560,
7123,
2594,
63,
2632,
9,
272,
9790,
275,
9725,
14,
12906,
18186,
8,
1864,
13285,
540,
63,
3078,
12,
1868,
13285,
540,
63,
12961,
9,
272,
4955,
63,
765,
63,
17426,
275,
9725,
14,
12906,
10014,
3767,
63,
2749,
33,
2919,
2472,
342,
272,
4955,
63,
765,
63,
18537,
63,
4835,
17,
275,
9725,
14,
12906,
10014,
3767,
63,
23034,
63,
8461,
17,
342,
272,
16834,
342,
339,
327,
664,
1056,
1526,
272,
870,
6438,
17985,
877,
282,
1056,
1526,
2263,
7,
272,
16834,
342,
272
] |
[
199,
1918,
10697,
844,
199,
199,
7384,
334,
67,
9,
10219,
491,
4489,
72,
445,
348,
422,
199,
199,
7980,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
1331,
199,
1618,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
298,
10337,
1288,
370,
7962,
199,
262,
314,
2290,
1928,
10588,
12,
5893,
1928,
12305,
314,
4481,
199,
475,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
11207,
12,
13473,
12,
436,
15,
269,
12743,
199,
16847,
402,
314,
2290,
12,
436,
370,
11291,
12103,
370,
12676,
314,
2290,
365,
199,
70,
13399,
370,
886,
880,
12,
5420,
370,
314,
2569,
3704,
26,
199,
199,
1918,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
315,
199,
452,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
199,
18061,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
1549,
199,
8947,
5177,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
3169,
12,
199,
38,
3061,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
7000,
2334,
199,
5580,
4149,
1549,
5877,
8164,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
199,
2673,
2477,
12,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
199,
1877,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
199,
18061,
4141,
14,
199,
199,
9846,
9790,
14,
961,
365,
440,
14318,
367,
9920,
14,
199,
13962,
13558,
12,
1265,
7171,
2934,
370,
1218,
2195,
5705,
5516,
402,
11715,
3041,
199,
269,
2342,
1373,
626,
5419,
543,
2195,
3330,
10059,
14,
199,
624,
199,
199,
646,
8809,
199,
646,
900,
199,
646,
9725,
14,
6126,
465,
9725,
199,
199,
3,
2202,
367,
314,
2257,
511,
9790,
199,
6613,
275,
283,
5967,
7,
199,
3657,
275,
30220,
199,
199,
3,
4026,
8187,
367,
314,
511,
1654,
334,
6742,
7869,
315,
1654,
14,
647,
9,
199,
6780,
63,
8803,
63,
2632,
275,
283,
2859,
921,
25211,
14,
2694,
14,
846,
15,
1069,
63,
1418,
7,
199,
11074,
63,
8803,
63,
2632,
275,
283,
2859,
921,
25211,
14,
2694,
14,
846,
15,
2732,
63,
1418,
7,
199,
25303,
2594,
63,
2632,
275,
283,
2859,
921,
25211,
14,
2694,
14,
846,
15,
14204,
7,
199,
28100,
63,
2632,
275,
283,
1014,
921,
11835,
14,
2694,
14,
957,
15,
1069,
63,
1418,
63,
2179,
7,
199,
14110,
63,
2632,
275,
283,
1014,
921,
25211,
14,
2694,
14,
846,
15,
25211,
7,
199,
199,
3,
790,
436,
7565,
10009,
701,
314,
2435,
5022,
367,
642,
9790,
4223,
446,
2011,
465,
314,
4420,
12906,
1451,
5502,
199,
1864,
13285,
540,
63,
3078,
275,
283,
498,
7,
199,
1864,
13285,
540,
63,
12961,
275,
283,
4731,
7,
199,
199,
3,
2893,
1890,
1808,
8809,
543,
2323,
199,
533,
5870,
12906,
3041,
8,
6126,
14,
12906,
3041,
304,
339,
347,
636,
826,
721,
277,
12,
1654,
12,
1844,
29,
12942,
14,
2856,
63,
3657,
12,
1056,
63,
1418,
63,
633,
4581,
2879,
63,
1418,
63,
633,
4581,
13448,
63,
633,
9280,
267,
291,
14,
1000,
275,
1654,
267,
291,
14,
719,
275,
1844,
267,
291,
14,
1069,
63,
1418,
63,
633,
275,
1056,
63,
1418,
63,
633,
267,
291,
14,
2732,
63,
1418,
63,
633,
275,
2879,
63,
1418,
63,
633,
267,
291,
14,
15846,
63,
633,
275,
13448,
63,
633,
267,
291,
14,
2105,
275,
8809,
14,
19114,
3647,
83,
2689,
68,
2,
450,
334,
277,
14,
1000,
12,
291,
14,
719,
430,
339,
347,
5267,
63,
1069,
63,
1418,
8,
277,
12,
9725,
63,
1069,
304,
267,
327,
4799,
2323,
267,
327,
1035,
11715,
3264,
267,
291,
14,
2105,
14,
1069,
8,
6126,
63,
1069,
14,
1014,
63,
765,
12,
291,
14,
1069,
63,
1418,
63,
633,
12,
2323,
29,
6126,
63,
1069,
14,
475,
63,
1291,
1012,
4960,
1177,
275,
291,
14,
2105,
14,
25006,
342,
267,
372,
9725,
14,
12906,
3264,
14,
504,
63,
875,
8,
1310,
14,
739,
1012,
339,
347,
5267,
63,
2732,
63,
1418,
8,
277,
12,
9725,
63,
1069,
304,
267,
327,
4799,
2323,
267,
327,
1035,
11715,
3264,
267,
291,
14,
2105,
14,
1069,
8,
6126,
63,
1069,
14,
1014,
63,
765,
12,
291,
14,
2732,
63,
1418,
63,
633,
12,
2323,
29,
6126,
63,
1069,
14,
475,
63,
1291,
1012,
4960,
1177,
275,
291,
14,
2105,
14,
25006,
342,
267,
372,
9725,
14,
12906,
3264,
14,
504,
63,
875,
8,
1310,
14,
739,
1012,
339,
347,
20210,
63,
1418,
8,
277,
12,
9725,
63,
1069,
304,
267,
327,
4799,
1166,
267,
327,
1035,
13609,
2951,
2005,
5849,
1177,
267,
291,
14,
2105,
14,
1069,
8,
6126,
63,
1069,
14,
1014,
63,
765,
12,
9725,
63,
1069,
14,
475,
63,
633,
1012,
4960,
1177,
275,
291,
14,
2105,
14,
25006,
342,
267,
372,
1177,
14,
739,
342,
339,
347,
2879,
63,
1927,
8,
277,
12,
9725,
63,
1069,
304,
267,
327,
4799,
2963,
2396,
267,
327,
1035,
2005,
17819,
5944,
267,
2323,
275,
791,
2714,
13,
804,
7,
520,
7,
3578,
15,
88,
13,
1544,
13,
964,
13,
21886,
936,
267,
291,
14,
2105,
14,
1069,
360,
4030,
297,
30061,
63,
2632,
12,
2396,
29,
6126,
63,
1069,
14,
475,
63,
1932,
576,
1062,
2323,
29,
2139,
9,
267,
1177,
275,
291,
14,
2105,
14,
25006,
342,
267,
372,
1177,
14,
739,
342,
199,
199,
318,
1255,
63,
2694,
837,
339,
327,
3272,
272,
870,
23940,
11715,
2018,
11243,
5679,
1011,
7,
272,
1890,
275,
5870,
12906,
3041,
8,
6613,
12,
25562,
12,
31325,
63,
8803,
63,
2632,
12,
437,
10203,
63,
8803,
63,
2632,
12,
7560,
7123,
2594,
63,
2632,
9,
272,
9790,
275,
9725,
14,
12906,
18186,
8,
1864,
13285,
540,
63,
3078,
12,
1868,
13285,
540,
63,
12961,
9,
272,
4955,
63,
765,
63,
17426,
275,
9725,
14,
12906,
10014,
3767,
63,
2749,
33,
2919,
2472,
342,
272,
4955,
63,
765,
63,
18537,
63,
4835,
17,
275,
9725,
14,
12906,
10014,
3767,
63,
23034,
63,
8461,
17,
342,
272,
16834,
342,
339,
327,
664,
1056,
1526,
272,
870,
6438,
17985,
877,
282,
1056,
1526,
2263,
7,
272,
16834,
342,
272,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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435
|
"""
WSGI config for techbikers project.
This module contains the WSGI application used by Django's development server
and any production WSGI deployments. It should expose a module-level variable
named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover
this application via the ``WSGI_APPLICATION`` setting.
Usually you will have the standard Django WSGI application here, but it also
might make sense to replace the whole Django WSGI application with a custom one
that later delegates to the Django one. For example, you could introduce WSGI
middleware here, or combine a Django application with an application of another
framework.
"""
import os
# We defer to a DJANGO_SETTINGS_MODULE already in the environment. This breaks
# if running multiple sites in the same mod_wsgi process. To fix this, use
# mod_wsgi daemon mode with each site in its own daemon process, or use
# os.environ["DJANGO_SETTINGS_MODULE"] = "techbikers.settings"
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "server.settings.production")
# This application object is used by any WSGI server configured to use this
# file. This includes Django's development server, if the WSGI_APPLICATION
# setting points here.
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
# Apply Sentry middleware.
from raven.contrib.django.raven_compat.middleware.wsgi import Sentry
application = Sentry(application)
|
mit
|
[
624,
199,
16828,
1101,
367,
28222,
66,
3258,
1192,
2199,
14,
199,
199,
2765,
859,
3509,
314,
9279,
4223,
1202,
701,
5634,
1159,
16367,
1654,
199,
460,
1263,
9920,
9279,
12287,
1470,
14,
2779,
1077,
23705,
282,
859,
13,
1896,
1750,
199,
4579,
1124,
3578,
4345,
5634,
1159,
1124,
1065,
1000,
1040,
436,
1124,
1065,
30076,
1040,
3718,
20131,
199,
3749,
4223,
4799,
314,
1124,
16828,
63,
24051,
1040,
4260,
14,
199,
199,
23642,
3163,
1265,
911,
1172,
314,
4465,
5634,
9279,
4223,
2348,
12,
1325,
652,
2597,
199,
77,
1070,
1852,
12249,
370,
3350,
314,
8852,
5634,
9279,
4223,
543,
282,
3537,
1373,
199,
9099,
2945,
18703,
2335,
370,
314,
5634,
1373,
14,
2104,
2893,
12,
1265,
4293,
13318,
3402,
9279,
199,
5754,
2348,
12,
503,
13323,
282,
5634,
4223,
543,
376,
4223,
402,
4573,
199,
4857,
14,
199,
199,
624,
199,
646,
747,
199,
199,
3,
2136,
10133,
370,
282,
577,
42,
18822,
63,
13931,
63,
10001,
2575,
315,
314,
3734,
14,
961,
18277,
199,
3,
340,
3879,
3663,
15424,
315,
314,
2011,
3413,
63,
6508,
2112,
14,
4005,
5325,
642,
12,
675,
199,
3,
3413,
63,
6508,
11128,
818,
543,
1924,
4770,
315,
2399,
5705,
11128,
2112,
12,
503,
675,
199,
3,
747,
14,
2314,
905,
22848,
63,
13931,
63,
10001,
937,
275,
298,
15970,
66,
3258,
1192,
14,
1751,
2,
199,
736,
14,
2314,
14,
5486,
480,
22848,
63,
13931,
63,
10001,
401,
298,
1000,
14,
1751,
14,
10777,
531,
199,
199,
3,
961,
4223,
909,
365,
1202,
701,
1263,
9279,
1654,
7526,
370,
675,
642,
199,
3,
570,
14,
961,
6952,
5634,
1159,
16367,
1654,
12,
340,
314,
9279,
63,
24051,
199,
3,
4260,
4501,
2348,
14,
199,
504,
1639,
14,
1018,
14,
6508,
492,
664,
63,
6508,
63,
3578,
199,
3578,
275,
664,
63,
6508,
63,
3578,
342,
199,
199,
3,
14618,
428,
2373,
10816,
14,
199,
504,
660,
1856,
14,
2828,
14,
1176,
14,
345,
1856,
63,
5819,
14,
5754,
14,
6508,
492,
428,
2373,
199,
3578,
275,
428,
2373,
8,
3578,
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
] |
[
199,
16828,
1101,
367,
28222,
66,
3258,
1192,
2199,
14,
199,
199,
2765,
859,
3509,
314,
9279,
4223,
1202,
701,
5634,
1159,
16367,
1654,
199,
460,
1263,
9920,
9279,
12287,
1470,
14,
2779,
1077,
23705,
282,
859,
13,
1896,
1750,
199,
4579,
1124,
3578,
4345,
5634,
1159,
1124,
1065,
1000,
1040,
436,
1124,
1065,
30076,
1040,
3718,
20131,
199,
3749,
4223,
4799,
314,
1124,
16828,
63,
24051,
1040,
4260,
14,
199,
199,
23642,
3163,
1265,
911,
1172,
314,
4465,
5634,
9279,
4223,
2348,
12,
1325,
652,
2597,
199,
77,
1070,
1852,
12249,
370,
3350,
314,
8852,
5634,
9279,
4223,
543,
282,
3537,
1373,
199,
9099,
2945,
18703,
2335,
370,
314,
5634,
1373,
14,
2104,
2893,
12,
1265,
4293,
13318,
3402,
9279,
199,
5754,
2348,
12,
503,
13323,
282,
5634,
4223,
543,
376,
4223,
402,
4573,
199,
4857,
14,
199,
199,
624,
199,
646,
747,
199,
199,
3,
2136,
10133,
370,
282,
577,
42,
18822,
63,
13931,
63,
10001,
2575,
315,
314,
3734,
14,
961,
18277,
199,
3,
340,
3879,
3663,
15424,
315,
314,
2011,
3413,
63,
6508,
2112,
14,
4005,
5325,
642,
12,
675,
199,
3,
3413,
63,
6508,
11128,
818,
543,
1924,
4770,
315,
2399,
5705,
11128,
2112,
12,
503,
675,
199,
3,
747,
14,
2314,
905,
22848,
63,
13931,
63,
10001,
937,
275,
298,
15970,
66,
3258,
1192,
14,
1751,
2,
199,
736,
14,
2314,
14,
5486,
480,
22848,
63,
13931,
63,
10001,
401,
298,
1000,
14,
1751,
14,
10777,
531,
199,
199,
3,
961,
4223,
909,
365,
1202,
701,
1263,
9279,
1654,
7526,
370,
675,
642,
199,
3,
570,
14,
961,
6952,
5634,
1159,
16367,
1654,
12,
340,
314,
9279,
63,
24051,
199,
3,
4260,
4501,
2348,
14,
199,
504,
1639,
14,
1018,
14,
6508,
492,
664,
63,
6508,
63,
3578,
199,
3578,
275,
664,
63,
6508,
63,
3578,
342,
199,
199,
3,
14618,
428,
2373,
10816,
14,
199,
504,
660,
1856,
14,
2828,
14,
1176,
14,
345,
1856,
63,
5819,
14,
5754,
14,
6508,
492,
428,
2373,
199,
3578,
275,
428,
2373,
8,
3578,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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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
] |
geomagpy/magpy
|
magpy/lib/format_lemi.py
|
1
|
19241
|
'''
Path: magpy.lib.format_lemi
Part of package: stream (read/write)
Type: Input filter, part of read library
PURPOSE:
Auxiliary input filter for Lemi data.
CONTAINS:
isLEMIBIN: (Func) Checks if file is LEMI format binary file.
readLEMIBIN: (Func) Reads current LEMI data format binary files.
isLEMIBIN1: (Func) Checks if file is LEMI format data file.
readLEMIBIN1: (Func) Reads outdated LEMI data format binary files.
isLEMIHF: (Func) Checks if file is LEMI format data file.
readLEMIHF: (Func) Reads outdated LEMI data format text files.
DEPENDENCIES:
None.
CALLED BY:
magpy.lib.magpy_formats
'''
from __future__ import print_function
from __future__ import unicode_literals
from __future__ import absolute_import
from __future__ import division
from io import open
from magpy.stream import *
def h2d(x):
'''
Hexadecimal to decimal (for format LEMIBIN2)
Because the binary for dates is in binary-decimal, not just binary.
'''
y = int(x/16)*10 + x%16
return y
def isLEMIHF(filename):
'''
Checks whether a file is ASCII Lemi txt file format.
'''
try:
temp = open(filename, 'rt').readline()
except:
return False
try:
elem = temp.split()
if len(elem) == 13:
try:
testtime = datetime.strptime(elem[0]+'-'+elem[1]+'-'+elem[2],'%Y-%m-%d')
except:
return False
else:
return False
except:
return False
#loggerlib.info("format_lemi: Found Lemi 10Hz ascii file %s." % filename)
return True
def isLEMIBIN1(filename):
'''
Checks whether a file is Binary Lemi file format.
'''
try:
temp = open(filename, 'rb').read(32)
data= struct.unpack('<4cb6B11Bcbbhhhb', temp)
except:
return False
try:
if not data[0].decode('ascii') == 'L':
return False
if not data[22].decode('ascii') in (['A','P']):
return false
except:
return False
#loggerlib.info("format_lemi: Found Lemi 10Hz binary file %s." % filename)
return True
def isLEMIBIN(filename):
'''
Checks whether a file is Binary Lemi025 file format. (2nd format. Used at Conrad Observatory.)
'''
try:
temp = open(filename, 'rb').read(169)
if temp[:20].decode('ascii').startswith("LemiBin"):
return True
else:
data= struct.unpack('<4cb6B8hb30f3BcB6hL', temp)
except:
return False
try:
if not data[0].decode('ascii') == 'L':
return False
if not data[53].decode('ascii') in (['A','P']):
return false
except:
return False
print ("Reading a Lemi Binary format")
#loggerlib.info("format_lemi: Found Lemi 10Hz binary file %s." % filename)
return True
def readLEMIHF(filename, headonly=False, **kwargs):
'''
Reading IAGA2002 LEMI format data.
'''
starttime = kwargs.get('starttime')
endtime = kwargs.get('endtime')
getfile = True
fh = open(filename, 'rt')
# read file and split text into channels
stream = DataStream()
array = [[] for key in KEYLIST]
# Check whether header information is already present
headers = {}
data = []
key = None
xpos = KEYLIST.index('x')
ypos = KEYLIST.index('y')
zpos = KEYLIST.index('z')
t1pos = KEYLIST.index('t1')
t2pos = KEYLIST.index('t2')
var2pos = KEYLIST.index('var2')
var3pos = KEYLIST.index('var3')
# get day from filename (platform independent)
# --------------------------------------
splitpath = os.path.split(filename)
tmpdaystring = splitpath[1].split('.')[0]
daystring = re.findall(r'\d+',tmpdaystring)[0]
if len(daystring) > 8:
daystring = daystring[:8]
try:
day = datetime.strftime(datetime.strptime(daystring, '%Y%m%d'),'%Y-%m-%d')
# Select only files within eventually defined time range
if starttime:
if not datetime.strptime(day,'%Y-%m-%d') >= datetime.strptime(datetime.strftime(stream._testtime(starttime),'%Y-%m-%d'),'%Y-%m-%d'):
getfile = False
if endtime:
if not datetime.strptime(day,'%Y-%m-%d') <= datetime.strptime(datetime.strftime(stream._testtime(endtime),'%Y-%m-%d'),'%Y-%m-%d'):
getfile = False
except:
loggerlib.warning("readLEMIHF: Wrong dateformat in Filename %s." % filename)
pass
if getfile:
loggerlib.info('readLEMIHF: Reading %s...' % (filename))
for line in fh:
if line.isspace():
# blank line
continue
elif headonly:
# skip data for option headonly
continue
else:
#row = LineStruct()
elem = line.split()
tim = date2num(datetime.strptime(elem[0]+'-'+elem[1]+'-'+elem[2]+'T'+elem[3]+':'+elem[4]+':'+elem[5],'%Y-%m-%dT%H:%M:%S.%f'))
#row.time = tim
array[0].append(tim)
array[xpos].append(float(elem[6]))
array[ypos].append(float(elem[7]))
array[zpos].append(float(elem[8]))
if len(elem) > 8:
try:
array[t1pos].append(float(elem[9]))
array[t2pos].append(float(elem[10]))
array[var2pos].append(float(elem[11]))
array[var3pos].append(float(elem[12]))
except:
pass
headers['col-x'] = 'x'
headers['unit-col-x'] = 'nT'
headers['col-y'] = 'y'
headers['unit-col-y'] = 'nT'
headers['col-z'] = 'z'
headers['unit-col-z'] = 'nT'
if len(elem) > 8:
headers['col-t1'] = 'Tsens'
headers['unit-col-t1'] = 'C'
headers['col-t2'] = 'Tel'
headers['unit-col-t2'] = 'C'
headers['col-var2'] = 'VCC'
headers['unit-col-var2'] = 'V'
headers['col-var3'] = 'Index'
headers['unit-col-var3'] = ''
else:
headers = stream.header
stream =[]
fh.close()
for idx,ar in enumerate(array):
if len(ar) > 0:
array[idx] = np.asarray(array[idx])
headers['DataFormat'] = 'Lviv-LEMI-Buffer'
return DataStream([LineStruct()], headers, np.asarray(array).astype(object))
def readLEMIBIN(filename, headonly=False, **kwargs):
'''
Function for reading current data format of LEMI data.
KWARGS:
tenHz: (bool) to use 10Hz data
timeshift: (float) providing a time shift, which is added to PC time column (usually NTP)
COMPLETE DATA STRUCTURE:'<4cb6B8hb30f3BcBcc5hL'
--TAG: data[0:4] # L025
--TIME (LEMI): 2000+h2d(data[5]),h2d(data[6]),h2d(data[7]),h2d(data[8]),h2d(data[9]),h2d(data[10])
--T (sensor): data[11]/100.
--T (electr.): data[12]/100.
--BIAS: data[13],data[14],data[15]
--BIAS FIELD: data[16]/400.,data[17]/400.,data[18]/400.
--(EMPTY) data[19]
--DATA1: data[20]*1000.,data[21]*1000.,data[22]*1000.
--DATA2: data[23]*1000.,data[24]*1000.,data[25]*1000.
--DATA3: data[26]*1000.,data[27]*1000.,data[28]*1000.
--DATA4: data[29]*1000.,data[30]*1000.,data[31]*1000.
--DATA5: data[32]*1000.,data[33]*1000.,data[34]*1000.
--DATA6: data[35]*1000.,data[36]*1000.,data[37]*1000.
--DATA7: data[38]*1000.,data[39]*1000.,data[40]*1000.
--DATA8: data[41]*1000.,data[42]*1000.,data[43]*1000.
--DATA9: data[44]*1000.,data[45]*1000.,data[46]*1000.
--DATA10: data[47]*1000.,data[48]*1000.,data[49]*1000.
--MODE: data[50] # Mode: 1, 2 or 3
--FLASH % FREE: data[51]
--BATTERY (V): data[52]
--GPS STATUS: data[53] # A (active) or P (passive)
--(EMPTY) data[54]
--TIME (PC): 2000+data[55],data[56],data[57],data[58],data[59],data[60],data[61]
'''
# Reading Lemi025 Binary format data.
starttime = kwargs.get('starttime')
endtime = kwargs.get('endtime')
debug = kwargs.get('debug')
getfile = True
timeshift = kwargs.get('timeshift')
gpstime = kwargs.get('gpstime')
sectime = kwargs.get('sectime')
#print "Reading LEMIBIN -- careful --- check time shifts and used time column (used during acquisition and read????)"
timediff = []
## Moved the following into acquisition
if not timeshift:
timeshift = 0.0 # milliseconds and time delay (PC-GPS) are already considered in acquisition
if not gpstime:
gpstime = False # if true then PC time will be saved to the sectime column and gps time will occupy the time column
# Check whether its the new (with ntp time) or old (without ntp) format
temp = open(filename, 'rb').read(169)
if temp[:60].decode('ascii').startswith("LemiBin"):
# current format
sensorid = temp[:60].split()[1]
sensorid = sensorid.decode('ascii')
dataheader = True
lemiformat = "current"
packcode = '<4cb6B8hb30f3BcB6hL'
linelength = 169
stime = True
if debug:
print ("SensorID", sensorid)
else:
# old format
data = struct.unpack('<4cb6B8hb30f3BcBcc5hL', temp)
if data[55] == 'L':
dataheader = False
lemiformat = "out-dated"
packcode = '<4cb6B8hb30f3BcB'
linelength = 153
stime = False
elif data[0] == 'L' and data[55] != 'L':
dataheader = False
lemiformat = "current (without header)"
packcode = '<4cb6B8hb30f3BcB6hL'
linelength = 169
stime = True
else:
loggerlib.error("readLEMIBIN: Something, somewhere, went very wrong.")
fh = open(filename, 'rb')
stream = DataStream([],{})
array = [[] for key in KEYLIST]
data = []
key = None
theday = extractDateFromString(filename)
try:
if starttime:
if not theday[-1] >= datetime.date(stream._testtime(starttime)):
getfile = False
if endtime:
if not theday[0] <= datetime.date(stream._testtime(endtime)):
getfile = False
except:
getfile = True
if getfile:
loggerlib.info("read: %s Format: Binary LEMI format (%s)." % (filename,lemiformat))
if dataheader == True:
junkheader = fh.readline()
stream.header['SensorID'] = sensorid
loggerlib.info('readLEMIBIN: Reading %s...' % (filename))
stream.header['col-x'] = 'x'
stream.header['unit-col-x'] = 'nT'
stream.header['col-y'] = 'y'
stream.header['unit-col-y'] = 'nT'
stream.header['col-z'] = 'z'
stream.header['unit-col-z'] = 'nT'
stream.header['col-t1'] = 'Ts'
stream.header['unit-col-t1'] = 'deg'
stream.header['col-t2'] = 'Te'
stream.header['unit-col-t2'] = 'deg'
stream.header['col-var2'] = 'Voltage'
stream.header['unit-col-var2'] = 'V'
stream.header['col-str1'] = 'GPS-Status'
timediff = []
line = fh.read(linelength)
while len(line) > 0:
try:
data= struct.unpack(str(packcode),line)
except Exception as e:
loggerlib.warning('readLEMIBIN: Error reading data. There is probably a broken line.')
loggerlib.warning('readLEMIBIN: Error string: "%s"' % e)
loggerlib.warning('readLEMIBIN: Aborting data read.')
line = ''
bfx = data[16]/400.
bfy = data[17]/400.
bfz = data[18]/400.
stream.header['DataCompensationX'] = bfx
stream.header['DataCompensationY'] = bfy
stream.header['DataCompensationZ'] = bfz
# get GPSstate
gpsstate = data[53]
#if gpsstate == 'A':
#if not sectime:
if not gpsstate == 'P' or not sectime: # Verify these condiditions - particulary when comparing bufferfile and mqtt transmission
time = datetime(2000+h2d(data[5]),h2d(data[6]),h2d(data[7]),h2d(data[8]),h2d(data[9]),h2d(data[10])) # Lemi GPS time
sectime = datetime(2000+data[55],data[56],data[57],data[58],data[59],data[60],data[61])+timedelta(microseconds=timeshift*1000.) # PC time
timediff.append((date2num(time)-date2num(sectime))*24.*3600.) # in seconds
else:
try:
time = datetime(2000+data[55],data[56],data[57],data[58],data[59],data[60],data[61])+timedelta(microseconds=timeshift*1000.) # PC time
except:
loggerlib.error("readLEMIBIN: Error reading line. Aborting read. (See docs.)")
try:
sectime = datetime(2000+h2d(data[5]),h2d(data[6]),h2d(data[7]),h2d(data[8]),h2d(data[9]),h2d(data[10])) # Lemi GPS time
timediff.append((date2num(time)-date2num(sectime))*24.*3600.) # in seconds
except:
loggerlib.warning("readLEMIBIN: Could not read secondary time column.")
#--------------------TODO--------------------------------------------
# This is usually an error that comes about during an interruption of data writing
# that leads to only a partial line being written. Normal data usually follows if the
# data logger starts up again within the same day.
# ---> It can be remedied using an iterative search for the next appearing "L025" tag
# in the binary data. See magpy/acquisition/lemiprotocol.py for an example of this
# iterative search.
#--------------------------------------------------------------------
xpos = KEYLIST.index('x')
ypos = KEYLIST.index('y')
zpos = KEYLIST.index('z')
t1pos = KEYLIST.index('t1')
t2pos = KEYLIST.index('t2')
var2pos = KEYLIST.index('var2')
str1pos = KEYLIST.index('str1')
secpos = KEYLIST.index('sectime')
for i in range(10):
tim = date2num(time+timedelta(microseconds=(100000.*i)))
array[0].append(tim)
array[xpos].append((data[20+i*3])*1000.)
array[ypos].append((data[21+i*3])*1000.)
array[zpos].append((data[22+i*3])*1000.)
array[t1pos].append(data[11]/100.)
array[t2pos].append(data[12]/100.)
array[var2pos].append(data[52]/10.)
array[str1pos].append(data[53])
sectim = date2num(sectime+timedelta(microseconds=(100000.*i)))
array[secpos].append(sectim)
line = fh.read(linelength)
fh.close()
gpstime = True
if gpstime and len(timediff) > 0:
loggerlib.info("readLEMIBIN2: Time difference (in sec) between GPS and PC (GPS-PC): %f sec +- %f" % (np.mean(timediff), np.std(timediff)))
print("Time difference between GPS and PC (GPS-PC):", np.mean(timediff), np.std(timediff))
if sectime:
print("contains secondary time column with NTP time")
for idx,ar in enumerate(array):
if len(ar) > 0:
array[idx] = np.asarray(array[idx]).astype(object)
stream.header['DataFormat'] = 'Lviv-LEMI'
return DataStream([LineStruct()], stream.header, np.asarray(array))
def readLEMIBIN1(filename, headonly=False, **kwargs):
'''
Function for reading LEMI format data.
NOTE: This function reads an outdated data format.
Timeshift of ~0.3 seconds must be accounted for.
(This timeshift is corrected for in current acquisition.lemiprotocol.)
'''
starttime = kwargs.get('starttime')
endtime = kwargs.get('endtime')
debug = kwargs.get('debug')
getfile = True
fh = open(filename, 'rb')
# read file and split text into channels
stream = DataStream()
array = [[] for key in KEYLIST]
# Check whether header infromation is already present
headers = {}
data = []
key = None
theday = extractDateFromString(filename)
try:
if starttime:
if not theday[-1] >= datetime.date(stream._testtime(starttime)):
getfile = False
if endtime:
if not theday[0] <= datetime.date(stream._testtime(endtime)):
getfile = False
except:
# Date format not recognized. Need to read all files
getfile = True
if getfile:
loggerlib.info('readLEMIBIN1: Reading %s' % (filename))
headers['col-x'] = 'x'
headers['unit-col-x'] = 'nT'
headers['col-y'] = 'y'
headers['unit-col-y'] = 'nT'
headers['col-z'] = 'z'
headers['unit-col-z'] = 'nT'
xpos = KEYLIST.index('x')
ypos = KEYLIST.index('y')
zpos = KEYLIST.index('z')
t1pos = KEYLIST.index('t1')
t2pos = KEYLIST.index('t2')
line = fh.read(32)
#print (line, len(line))
while len(line) > 0:
data= struct.unpack("<4cb6B11Bcbbhhhb", line)
data = [el.decode('ascii') if isinstance(el, basestring) else el for el in data]
bfx = data[-4]/400.
bfy = data[-3]/400.
bfz = data[-2]/400.
headers['DataCompensationX'] = bfx
headers['DataCompensationY'] = bfy
headers['DataCompensationZ'] = bfz
headers['SensorID'] = line[0:4].decode('ascii')
newtime = []
for i in range (5,11):
newtime.append(h2d(data[i]))
currsec = newtime[-1]
newtime.append(0.0)
for i in range (0,30):
row = LineStruct()
line = fh.read(16)
data= struct.unpack('<3f2h', line)
microsec = i/10.
if microsec >= 2:
secadd = 2.
elif microsec >= 1:
secadd = 1.
else:
secadd = 0.
newtime[-1] = microsec-secadd
newtime[-2] = currsec+secadd
time = datetime(2000+newtime[0],newtime[1],newtime[2],newtime[3],newtime[4],int(newtime[5]),int(newtime[6]*1000000))
array[0].append(date2num(time))
array[xpos].append((data[0])*1000.)
array[ypos].append((data[1])*1000.)
array[zpos].append((data[2])*1000.)
array[t1pos].append(data[3]/100.)
array[t2pos].append(data[4]/100.)
line = fh.read(32)
fh.close()
#print "Finished file reading of %s" % filename
for idx,ar in enumerate(array):
if len(ar) > 0:
array[idx] = np.asarray(array[idx]).astype(object)
headers['DataFormat'] = 'Lviv-LEMI-old'
return DataStream([LineStruct()], headers, np.asarray(array))
|
bsd-3-clause
|
[
2344,
199,
2042,
26,
7861,
8127,
647,
14,
773,
14,
908,
63,
274,
2664,
199,
8416,
402,
2559,
26,
263,
2547,
334,
739,
15,
952,
9,
199,
804,
26,
7861,
6924,
2457,
12,
1777,
402,
1586,
3555,
199,
199,
48,
1230,
3064,
26,
267,
437,
2521,
20524,
1324,
2457,
367,
7005,
2664,
666,
14,
199,
199,
25207,
51,
26,
267,
365,
906,
10535,
568,
26,
420,
334,
7465,
9,
13813,
340,
570,
365,
491,
2769,
41,
1475,
3366,
570,
14,
267,
1586,
906,
10535,
568,
26,
259,
334,
7465,
9,
26129,
1453,
491,
2769,
41,
666,
1475,
3366,
1584,
14,
267,
365,
906,
10535,
568,
17,
26,
258,
334,
7465,
9,
13813,
340,
570,
365,
491,
2769,
41,
1475,
666,
570,
14,
267,
1586,
906,
10535,
568,
17,
26,
257,
334,
7465,
9,
26129,
734,
19074,
491,
2769,
41,
666,
1475,
3366,
1584,
14,
267,
365,
906,
10709,
25500,
26,
755,
334,
7465,
9,
13813,
340,
570,
365,
491,
2769,
41,
1475,
666,
570,
14,
267,
1586,
906,
10709,
25500,
26,
258,
334,
7465,
9,
26129,
734,
19074,
491,
2769,
41,
666,
1475,
1318,
1584,
14,
199,
199,
25743,
9415,
2563,
26,
267,
488,
14,
199,
199,
13329,
5290,
6515,
26,
267,
8127,
647,
14,
773,
14,
5615,
647,
63,
6321,
199,
2344,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
5890,
492,
1551,
199,
199,
504,
8127,
647,
14,
1745,
492,
627,
199,
199,
318,
394,
18,
68,
8,
88,
304,
272,
1449,
272,
28333,
19423,
370,
6107,
334,
509,
1475,
491,
2769,
2100,
568,
18,
9,
272,
13821,
314,
3366,
367,
10831,
365,
315,
3366,
13,
6355,
12,
440,
2951,
3366,
14,
272,
1449,
272,
612,
275,
1109,
8,
88,
15,
975,
3342,
709,
435,
671,
5,
975,
272,
372,
612,
199,
199,
318,
365,
906,
10709,
25500,
8,
1501,
304,
272,
1449,
272,
13813,
3775,
282,
570,
365,
10485,
7005,
2664,
9444,
570,
1475,
14,
272,
1449,
272,
862,
26,
267,
2388,
275,
1551,
8,
1501,
12,
283,
2591,
1959,
6407,
342,
272,
871,
26,
267,
372,
756,
272,
862,
26,
267,
6193,
275,
2388,
14,
1294,
342,
267,
340,
822,
8,
6086,
9,
508,
4944,
26,
288,
862,
26,
355,
511,
521,
275,
2197,
14,
9866,
8,
6086,
59,
16,
2807,
12418,
6828,
6086,
59,
17,
2807,
12418,
6828,
6086,
59,
18,
467,
5956,
57,
3295,
77,
3295,
68,
358,
288,
871,
26,
355,
372,
756,
267,
587,
26,
288,
372,
756,
272,
871,
26,
267,
372,
756,
339,
327,
2921,
773,
14,
815,
480,
908,
63,
274,
2664,
26,
2643,
7005,
2664,
1616,
13026,
13294,
570,
450,
83,
2122,
450,
1788,
9,
272,
372,
715,
421,
199,
318,
365,
906,
10535,
568,
17,
8,
1501,
304,
272,
1449,
272,
13813,
3775,
282,
570,
365,
14161,
7005,
2664,
570,
1475,
14,
272,
1449,
272,
862,
26,
267,
2388,
275,
1551,
8,
1501,
12,
283,
4848,
1959,
739,
8,
708,
9,
267,
666,
29,
2702,
14,
5301,
4827,
20,
2894,
22,
34,
845,
34,
21933,
12156,
16168,
297,
2388,
9,
272,
871,
26,
267,
372,
756,
339,
862,
26,
267,
340,
440,
666,
59,
16,
1055,
2708,
360,
4371,
358,
508,
283,
44,
356,
288,
372,
756,
267,
340,
440,
666,
59,
1081,
1055,
2708,
360,
4371,
358,
315,
21022,
33,
1673,
48,
9090,
288,
372,
3055,
272,
871,
26,
267,
372,
756,
339,
327,
2921,
773,
14,
815,
480,
908,
63,
274,
2664,
26,
2643,
7005,
2664,
1616,
13026,
3366,
570,
450,
83,
2122,
450,
1788,
9,
272,
372,
715,
421,
199,
318,
365,
906,
10535,
568,
8,
1501,
304,
272,
1449,
272,
13813,
3775,
282,
570,
365,
14161,
7005,
2664,
18823,
570,
1475,
14,
334,
18,
977,
1475,
14,
8051,
737,
1448,
9525,
17985,
7297,
8658,
4959,
272,
1449,
272,
862,
26,
267,
2388,
275,
1551,
8,
1501,
12,
283,
4848,
1959,
739,
8,
10143,
9,
267,
340,
2388,
1491,
1165,
1055,
2708,
360,
4371,
1959,
2460,
480,
2553,
2664,
13394,
2349,
288,
372,
715,
267,
587,
26,
288,
666,
29,
2702,
14,
5301,
4827,
20,
2894,
22,
34,
24,
16168,
1216,
70,
19,
34,
67,
34,
22,
72,
44,
297,
2388,
9,
272,
871,
26,
267,
372,
756,
339,
862,
26,
267,
340,
440,
666,
59,
16,
1055,
2708,
360,
4371,
358,
508,
283,
44,
356,
288,
372,
756,
267,
340,
440,
666,
59,
2481,
1055,
2708,
360,
4371,
358,
315,
21022,
33,
1673,
48,
9090,
288,
372,
3055,
272,
871,
26,
267,
372,
756,
339,
870,
1689,
20568,
282,
7005,
2664,
14161,
1475,
531,
272,
327,
2921,
773,
14,
815,
480,
908,
63,
274,
2664,
26,
2643,
7005,
2664,
1616,
13026,
3366,
570,
450,
83,
2122,
450,
1788,
9,
272,
372,
715,
421,
199,
318,
1586,
906,
10709,
25500,
8,
1501,
12,
4854,
2118,
29,
797,
12,
1011,
958,
304,
272,
1449,
272,
799,
5384,
473,
1254,
33,
15135,
491,
2769,
41,
1475,
666,
14,
272,
1449,
339,
1343,
521,
275,
2074,
14,
362,
360,
32183,
358,
272,
1284,
521,
275,
2074,
14,
362,
360,
500,
521,
358,
272,
664,
493,
275,
715,
339,
11155,
275,
1551,
8,
1501,
12,
283,
2591,
358,
272,
327,
1586,
570,
436,
3715,
1318,
1901,
9245,
272,
2547,
275,
3918,
3296,
342,
272,
1625,
275,
3474,
61,
367,
790,
315,
9301,
4924,
61,
272,
327,
2670,
3775,
1406,
2556,
365,
2575,
3451,
272,
2323,
275,
1052,
272,
666,
275,
942,
272,
790,
275,
488,
339,
671,
1712,
275,
9301,
4924,
14,
1080,
360,
88,
358,
272,
612,
1712,
275,
9301,
4924,
14,
1080,
360,
89,
358,
272,
1315,
1712,
275,
9301,
4924,
14,
1080,
360,
90,
358,
272,
307,
17,
1712,
275,
9301,
4924,
14,
1080,
360,
84,
17,
358,
272,
307,
18,
1712,
275,
9301,
4924,
14,
1080,
360,
84,
18,
358,
272,
2729,
18,
1712,
275,
9301,
4924,
14,
1080,
360,
1391,
18,
358,
272,
2729,
19,
1712,
275,
9301,
4924,
14,
1080,
360,
1391,
19,
358,
339,
327,
664,
5382,
687,
1788,
334,
3246,
12717,
9,
272,
327,
11016,
8648
] |
[
199,
2042,
26,
7861,
8127,
647,
14,
773,
14,
908,
63,
274,
2664,
199,
8416,
402,
2559,
26,
263,
2547,
334,
739,
15,
952,
9,
199,
804,
26,
7861,
6924,
2457,
12,
1777,
402,
1586,
3555,
199,
199,
48,
1230,
3064,
26,
267,
437,
2521,
20524,
1324,
2457,
367,
7005,
2664,
666,
14,
199,
199,
25207,
51,
26,
267,
365,
906,
10535,
568,
26,
420,
334,
7465,
9,
13813,
340,
570,
365,
491,
2769,
41,
1475,
3366,
570,
14,
267,
1586,
906,
10535,
568,
26,
259,
334,
7465,
9,
26129,
1453,
491,
2769,
41,
666,
1475,
3366,
1584,
14,
267,
365,
906,
10535,
568,
17,
26,
258,
334,
7465,
9,
13813,
340,
570,
365,
491,
2769,
41,
1475,
666,
570,
14,
267,
1586,
906,
10535,
568,
17,
26,
257,
334,
7465,
9,
26129,
734,
19074,
491,
2769,
41,
666,
1475,
3366,
1584,
14,
267,
365,
906,
10709,
25500,
26,
755,
334,
7465,
9,
13813,
340,
570,
365,
491,
2769,
41,
1475,
666,
570,
14,
267,
1586,
906,
10709,
25500,
26,
258,
334,
7465,
9,
26129,
734,
19074,
491,
2769,
41,
666,
1475,
1318,
1584,
14,
199,
199,
25743,
9415,
2563,
26,
267,
488,
14,
199,
199,
13329,
5290,
6515,
26,
267,
8127,
647,
14,
773,
14,
5615,
647,
63,
6321,
199,
2344,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
5890,
492,
1551,
199,
199,
504,
8127,
647,
14,
1745,
492,
627,
199,
199,
318,
394,
18,
68,
8,
88,
304,
272,
1449,
272,
28333,
19423,
370,
6107,
334,
509,
1475,
491,
2769,
2100,
568,
18,
9,
272,
13821,
314,
3366,
367,
10831,
365,
315,
3366,
13,
6355,
12,
440,
2951,
3366,
14,
272,
1449,
272,
612,
275,
1109,
8,
88,
15,
975,
3342,
709,
435,
671,
5,
975,
272,
372,
612,
199,
199,
318,
365,
906,
10709,
25500,
8,
1501,
304,
272,
1449,
272,
13813,
3775,
282,
570,
365,
10485,
7005,
2664,
9444,
570,
1475,
14,
272,
1449,
272,
862,
26,
267,
2388,
275,
1551,
8,
1501,
12,
283,
2591,
1959,
6407,
342,
272,
871,
26,
267,
372,
756,
272,
862,
26,
267,
6193,
275,
2388,
14,
1294,
342,
267,
340,
822,
8,
6086,
9,
508,
4944,
26,
288,
862,
26,
355,
511,
521,
275,
2197,
14,
9866,
8,
6086,
59,
16,
2807,
12418,
6828,
6086,
59,
17,
2807,
12418,
6828,
6086,
59,
18,
467,
5956,
57,
3295,
77,
3295,
68,
358,
288,
871,
26,
355,
372,
756,
267,
587,
26,
288,
372,
756,
272,
871,
26,
267,
372,
756,
339,
327,
2921,
773,
14,
815,
480,
908,
63,
274,
2664,
26,
2643,
7005,
2664,
1616,
13026,
13294,
570,
450,
83,
2122,
450,
1788,
9,
272,
372,
715,
421,
199,
318,
365,
906,
10535,
568,
17,
8,
1501,
304,
272,
1449,
272,
13813,
3775,
282,
570,
365,
14161,
7005,
2664,
570,
1475,
14,
272,
1449,
272,
862,
26,
267,
2388,
275,
1551,
8,
1501,
12,
283,
4848,
1959,
739,
8,
708,
9,
267,
666,
29,
2702,
14,
5301,
4827,
20,
2894,
22,
34,
845,
34,
21933,
12156,
16168,
297,
2388,
9,
272,
871,
26,
267,
372,
756,
339,
862,
26,
267,
340,
440,
666,
59,
16,
1055,
2708,
360,
4371,
358,
508,
283,
44,
356,
288,
372,
756,
267,
340,
440,
666,
59,
1081,
1055,
2708,
360,
4371,
358,
315,
21022,
33,
1673,
48,
9090,
288,
372,
3055,
272,
871,
26,
267,
372,
756,
339,
327,
2921,
773,
14,
815,
480,
908,
63,
274,
2664,
26,
2643,
7005,
2664,
1616,
13026,
3366,
570,
450,
83,
2122,
450,
1788,
9,
272,
372,
715,
421,
199,
318,
365,
906,
10535,
568,
8,
1501,
304,
272,
1449,
272,
13813,
3775,
282,
570,
365,
14161,
7005,
2664,
18823,
570,
1475,
14,
334,
18,
977,
1475,
14,
8051,
737,
1448,
9525,
17985,
7297,
8658,
4959,
272,
1449,
272,
862,
26,
267,
2388,
275,
1551,
8,
1501,
12,
283,
4848,
1959,
739,
8,
10143,
9,
267,
340,
2388,
1491,
1165,
1055,
2708,
360,
4371,
1959,
2460,
480,
2553,
2664,
13394,
2349,
288,
372,
715,
267,
587,
26,
288,
666,
29,
2702,
14,
5301,
4827,
20,
2894,
22,
34,
24,
16168,
1216,
70,
19,
34,
67,
34,
22,
72,
44,
297,
2388,
9,
272,
871,
26,
267,
372,
756,
339,
862,
26,
267,
340,
440,
666,
59,
16,
1055,
2708,
360,
4371,
358,
508,
283,
44,
356,
288,
372,
756,
267,
340,
440,
666,
59,
2481,
1055,
2708,
360,
4371,
358,
315,
21022,
33,
1673,
48,
9090,
288,
372,
3055,
272,
871,
26,
267,
372,
756,
339,
870,
1689,
20568,
282,
7005,
2664,
14161,
1475,
531,
272,
327,
2921,
773,
14,
815,
480,
908,
63,
274,
2664,
26,
2643,
7005,
2664,
1616,
13026,
3366,
570,
450,
83,
2122,
450,
1788,
9,
272,
372,
715,
421,
199,
318,
1586,
906,
10709,
25500,
8,
1501,
12,
4854,
2118,
29,
797,
12,
1011,
958,
304,
272,
1449,
272,
799,
5384,
473,
1254,
33,
15135,
491,
2769,
41,
1475,
666,
14,
272,
1449,
339,
1343,
521,
275,
2074,
14,
362,
360,
32183,
358,
272,
1284,
521,
275,
2074,
14,
362,
360,
500,
521,
358,
272,
664,
493,
275,
715,
339,
11155,
275,
1551,
8,
1501,
12,
283,
2591,
358,
272,
327,
1586,
570,
436,
3715,
1318,
1901,
9245,
272,
2547,
275,
3918,
3296,
342,
272,
1625,
275,
3474,
61,
367,
790,
315,
9301,
4924,
61,
272,
327,
2670,
3775,
1406,
2556,
365,
2575,
3451,
272,
2323,
275,
1052,
272,
666,
275,
942,
272,
790,
275,
488,
339,
671,
1712,
275,
9301,
4924,
14,
1080,
360,
88,
358,
272,
612,
1712,
275,
9301,
4924,
14,
1080,
360,
89,
358,
272,
1315,
1712,
275,
9301,
4924,
14,
1080,
360,
90,
358,
272,
307,
17,
1712,
275,
9301,
4924,
14,
1080,
360,
84,
17,
358,
272,
307,
18,
1712,
275,
9301,
4924,
14,
1080,
360,
84,
18,
358,
272,
2729,
18,
1712,
275,
9301,
4924,
14,
1080,
360,
1391,
18,
358,
272,
2729,
19,
1712,
275,
9301,
4924,
14,
1080,
360,
1391,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
kenshay/ImageScript
|
ProgramData/SystemFiles/Python/Lib/site-packages/OpenGL/raw/GL/VERSION/GL_4_0.py
|
9
|
11219
|
'''Autogenerated by xml_generate script, do not edit!'''
from OpenGL import platform as _p, arrays
# Code generation uses this
from OpenGL.raw.GL import _types as _cs
# End users want this...
from OpenGL.raw.GL._types import *
from OpenGL.raw.GL import _errors
from OpenGL.constant import Constant as _C
import ctypes
_EXTENSION_NAME = 'GL_VERSION_GL_4_0'
def _f( function ):
return _p.createFunction( function,_p.PLATFORM.GL,'GL_VERSION_GL_4_0',error_checker=_errors._error_checker)
GL_ACTIVE_SUBROUTINES=_C('GL_ACTIVE_SUBROUTINES',0x8DE5)
GL_ACTIVE_SUBROUTINE_MAX_LENGTH=_C('GL_ACTIVE_SUBROUTINE_MAX_LENGTH',0x8E48)
GL_ACTIVE_SUBROUTINE_UNIFORMS=_C('GL_ACTIVE_SUBROUTINE_UNIFORMS',0x8DE6)
GL_ACTIVE_SUBROUTINE_UNIFORM_LOCATIONS=_C('GL_ACTIVE_SUBROUTINE_UNIFORM_LOCATIONS',0x8E47)
GL_ACTIVE_SUBROUTINE_UNIFORM_MAX_LENGTH=_C('GL_ACTIVE_SUBROUTINE_UNIFORM_MAX_LENGTH',0x8E49)
GL_COMPATIBLE_SUBROUTINES=_C('GL_COMPATIBLE_SUBROUTINES',0x8E4B)
GL_DOUBLE_MAT2=_C('GL_DOUBLE_MAT2',0x8F46)
GL_DOUBLE_MAT2x3=_C('GL_DOUBLE_MAT2x3',0x8F49)
GL_DOUBLE_MAT2x4=_C('GL_DOUBLE_MAT2x4',0x8F4A)
GL_DOUBLE_MAT3=_C('GL_DOUBLE_MAT3',0x8F47)
GL_DOUBLE_MAT3x2=_C('GL_DOUBLE_MAT3x2',0x8F4B)
GL_DOUBLE_MAT3x4=_C('GL_DOUBLE_MAT3x4',0x8F4C)
GL_DOUBLE_MAT4=_C('GL_DOUBLE_MAT4',0x8F48)
GL_DOUBLE_MAT4x2=_C('GL_DOUBLE_MAT4x2',0x8F4D)
GL_DOUBLE_MAT4x3=_C('GL_DOUBLE_MAT4x3',0x8F4E)
GL_DOUBLE_VEC2=_C('GL_DOUBLE_VEC2',0x8FFC)
GL_DOUBLE_VEC3=_C('GL_DOUBLE_VEC3',0x8FFD)
GL_DOUBLE_VEC4=_C('GL_DOUBLE_VEC4',0x8FFE)
GL_DRAW_INDIRECT_BUFFER=_C('GL_DRAW_INDIRECT_BUFFER',0x8F3F)
GL_DRAW_INDIRECT_BUFFER_BINDING=_C('GL_DRAW_INDIRECT_BUFFER_BINDING',0x8F43)
GL_FRACTIONAL_EVEN=_C('GL_FRACTIONAL_EVEN',0x8E7C)
GL_FRACTIONAL_ODD=_C('GL_FRACTIONAL_ODD',0x8E7B)
GL_FRAGMENT_INTERPOLATION_OFFSET_BITS=_C('GL_FRAGMENT_INTERPOLATION_OFFSET_BITS',0x8E5D)
GL_GEOMETRY_SHADER_INVOCATIONS=_C('GL_GEOMETRY_SHADER_INVOCATIONS',0x887F)
GL_INT_SAMPLER_CUBE_MAP_ARRAY=_C('GL_INT_SAMPLER_CUBE_MAP_ARRAY',0x900E)
GL_ISOLINES=_C('GL_ISOLINES',0x8E7A)
GL_MAX_COMBINED_TESS_CONTROL_UNIFORM_COMPONENTS=_C('GL_MAX_COMBINED_TESS_CONTROL_UNIFORM_COMPONENTS',0x8E1E)
GL_MAX_COMBINED_TESS_EVALUATION_UNIFORM_COMPONENTS=_C('GL_MAX_COMBINED_TESS_EVALUATION_UNIFORM_COMPONENTS',0x8E1F)
GL_MAX_FRAGMENT_INTERPOLATION_OFFSET=_C('GL_MAX_FRAGMENT_INTERPOLATION_OFFSET',0x8E5C)
GL_MAX_GEOMETRY_SHADER_INVOCATIONS=_C('GL_MAX_GEOMETRY_SHADER_INVOCATIONS',0x8E5A)
GL_MAX_PATCH_VERTICES=_C('GL_MAX_PATCH_VERTICES',0x8E7D)
GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET=_C('GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET',0x8E5F)
GL_MAX_SUBROUTINES=_C('GL_MAX_SUBROUTINES',0x8DE7)
GL_MAX_SUBROUTINE_UNIFORM_LOCATIONS=_C('GL_MAX_SUBROUTINE_UNIFORM_LOCATIONS',0x8DE8)
GL_MAX_TESS_CONTROL_INPUT_COMPONENTS=_C('GL_MAX_TESS_CONTROL_INPUT_COMPONENTS',0x886C)
GL_MAX_TESS_CONTROL_OUTPUT_COMPONENTS=_C('GL_MAX_TESS_CONTROL_OUTPUT_COMPONENTS',0x8E83)
GL_MAX_TESS_CONTROL_TEXTURE_IMAGE_UNITS=_C('GL_MAX_TESS_CONTROL_TEXTURE_IMAGE_UNITS',0x8E81)
GL_MAX_TESS_CONTROL_TOTAL_OUTPUT_COMPONENTS=_C('GL_MAX_TESS_CONTROL_TOTAL_OUTPUT_COMPONENTS',0x8E85)
GL_MAX_TESS_CONTROL_UNIFORM_BLOCKS=_C('GL_MAX_TESS_CONTROL_UNIFORM_BLOCKS',0x8E89)
GL_MAX_TESS_CONTROL_UNIFORM_COMPONENTS=_C('GL_MAX_TESS_CONTROL_UNIFORM_COMPONENTS',0x8E7F)
GL_MAX_TESS_EVALUATION_INPUT_COMPONENTS=_C('GL_MAX_TESS_EVALUATION_INPUT_COMPONENTS',0x886D)
GL_MAX_TESS_EVALUATION_OUTPUT_COMPONENTS=_C('GL_MAX_TESS_EVALUATION_OUTPUT_COMPONENTS',0x8E86)
GL_MAX_TESS_EVALUATION_TEXTURE_IMAGE_UNITS=_C('GL_MAX_TESS_EVALUATION_TEXTURE_IMAGE_UNITS',0x8E82)
GL_MAX_TESS_EVALUATION_UNIFORM_BLOCKS=_C('GL_MAX_TESS_EVALUATION_UNIFORM_BLOCKS',0x8E8A)
GL_MAX_TESS_EVALUATION_UNIFORM_COMPONENTS=_C('GL_MAX_TESS_EVALUATION_UNIFORM_COMPONENTS',0x8E80)
GL_MAX_TESS_GEN_LEVEL=_C('GL_MAX_TESS_GEN_LEVEL',0x8E7E)
GL_MAX_TESS_PATCH_COMPONENTS=_C('GL_MAX_TESS_PATCH_COMPONENTS',0x8E84)
GL_MAX_TRANSFORM_FEEDBACK_BUFFERS=_C('GL_MAX_TRANSFORM_FEEDBACK_BUFFERS',0x8E70)
GL_MAX_VERTEX_STREAMS=_C('GL_MAX_VERTEX_STREAMS',0x8E71)
GL_MAX_VERTEX_STREAMS=_C('GL_MAX_VERTEX_STREAMS',0x8E71)
GL_MIN_FRAGMENT_INTERPOLATION_OFFSET=_C('GL_MIN_FRAGMENT_INTERPOLATION_OFFSET',0x8E5B)
GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET=_C('GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET',0x8E5E)
GL_MIN_SAMPLE_SHADING_VALUE=_C('GL_MIN_SAMPLE_SHADING_VALUE',0x8C37)
GL_NUM_COMPATIBLE_SUBROUTINES=_C('GL_NUM_COMPATIBLE_SUBROUTINES',0x8E4A)
GL_PATCHES=_C('GL_PATCHES',0x000E)
GL_PATCH_DEFAULT_INNER_LEVEL=_C('GL_PATCH_DEFAULT_INNER_LEVEL',0x8E73)
GL_PATCH_DEFAULT_OUTER_LEVEL=_C('GL_PATCH_DEFAULT_OUTER_LEVEL',0x8E74)
GL_PATCH_VERTICES=_C('GL_PATCH_VERTICES',0x8E72)
GL_PROXY_TEXTURE_CUBE_MAP_ARRAY=_C('GL_PROXY_TEXTURE_CUBE_MAP_ARRAY',0x900B)
GL_QUADS=_C('GL_QUADS',0x0007)
GL_SAMPLER_CUBE_MAP_ARRAY=_C('GL_SAMPLER_CUBE_MAP_ARRAY',0x900C)
GL_SAMPLER_CUBE_MAP_ARRAY_SHADOW=_C('GL_SAMPLER_CUBE_MAP_ARRAY_SHADOW',0x900D)
GL_SAMPLE_SHADING=_C('GL_SAMPLE_SHADING',0x8C36)
GL_TESS_CONTROL_OUTPUT_VERTICES=_C('GL_TESS_CONTROL_OUTPUT_VERTICES',0x8E75)
GL_TESS_CONTROL_SHADER=_C('GL_TESS_CONTROL_SHADER',0x8E88)
GL_TESS_EVALUATION_SHADER=_C('GL_TESS_EVALUATION_SHADER',0x8E87)
GL_TESS_GEN_MODE=_C('GL_TESS_GEN_MODE',0x8E76)
GL_TESS_GEN_POINT_MODE=_C('GL_TESS_GEN_POINT_MODE',0x8E79)
GL_TESS_GEN_SPACING=_C('GL_TESS_GEN_SPACING',0x8E77)
GL_TESS_GEN_VERTEX_ORDER=_C('GL_TESS_GEN_VERTEX_ORDER',0x8E78)
GL_TEXTURE_BINDING_CUBE_MAP_ARRAY=_C('GL_TEXTURE_BINDING_CUBE_MAP_ARRAY',0x900A)
GL_TEXTURE_CUBE_MAP_ARRAY=_C('GL_TEXTURE_CUBE_MAP_ARRAY',0x9009)
GL_TRANSFORM_FEEDBACK=_C('GL_TRANSFORM_FEEDBACK',0x8E22)
GL_TRANSFORM_FEEDBACK_BINDING=_C('GL_TRANSFORM_FEEDBACK_BINDING',0x8E25)
GL_TRANSFORM_FEEDBACK_BUFFER_ACTIVE=_C('GL_TRANSFORM_FEEDBACK_BUFFER_ACTIVE',0x8E24)
GL_TRANSFORM_FEEDBACK_BUFFER_PAUSED=_C('GL_TRANSFORM_FEEDBACK_BUFFER_PAUSED',0x8E23)
GL_UNIFORM_BLOCK_REFERENCED_BY_TESS_CONTROL_SHADER=_C('GL_UNIFORM_BLOCK_REFERENCED_BY_TESS_CONTROL_SHADER',0x84F0)
GL_UNIFORM_BLOCK_REFERENCED_BY_TESS_EVALUATION_SHADER=_C('GL_UNIFORM_BLOCK_REFERENCED_BY_TESS_EVALUATION_SHADER',0x84F1)
GL_UNSIGNED_INT_SAMPLER_CUBE_MAP_ARRAY=_C('GL_UNSIGNED_INT_SAMPLER_CUBE_MAP_ARRAY',0x900F)
@_f
@_p.types(None,_cs.GLenum,_cs.GLuint,_cs.GLuint)
def glBeginQueryIndexed(target,index,id):pass
@_f
@_p.types(None,_cs.GLenum,_cs.GLuint)
def glBindTransformFeedback(target,id):pass
@_f
@_p.types(None,_cs.GLuint,_cs.GLenum,_cs.GLenum)
def glBlendEquationSeparatei(buf,modeRGB,modeAlpha):pass
@_f
@_p.types(None,_cs.GLuint,_cs.GLenum)
def glBlendEquationi(buf,mode):pass
@_f
@_p.types(None,_cs.GLuint,_cs.GLenum,_cs.GLenum,_cs.GLenum,_cs.GLenum)
def glBlendFuncSeparatei(buf,srcRGB,dstRGB,srcAlpha,dstAlpha):pass
@_f
@_p.types(None,_cs.GLuint,_cs.GLenum,_cs.GLenum)
def glBlendFunci(buf,src,dst):pass
@_f
@_p.types(None,_cs.GLsizei,arrays.GLuintArray)
def glDeleteTransformFeedbacks(n,ids):pass
@_f
@_p.types(None,_cs.GLenum,ctypes.c_void_p)
def glDrawArraysIndirect(mode,indirect):pass
@_f
@_p.types(None,_cs.GLenum,_cs.GLenum,ctypes.c_void_p)
def glDrawElementsIndirect(mode,type,indirect):pass
@_f
@_p.types(None,_cs.GLenum,_cs.GLuint)
def glDrawTransformFeedback(mode,id):pass
@_f
@_p.types(None,_cs.GLenum,_cs.GLuint,_cs.GLuint)
def glDrawTransformFeedbackStream(mode,id,stream):pass
@_f
@_p.types(None,_cs.GLenum,_cs.GLuint)
def glEndQueryIndexed(target,index):pass
@_f
@_p.types(None,_cs.GLsizei,arrays.GLuintArray)
def glGenTransformFeedbacks(n,ids):pass
@_f
@_p.types(None,_cs.GLuint,_cs.GLenum,_cs.GLuint,_cs.GLsizei,arrays.GLsizeiArray,arrays.GLcharArray)
def glGetActiveSubroutineName(program,shadertype,index,bufsize,length,name):pass
@_f
@_p.types(None,_cs.GLuint,_cs.GLenum,_cs.GLuint,_cs.GLsizei,arrays.GLsizeiArray,arrays.GLcharArray)
def glGetActiveSubroutineUniformName(program,shadertype,index,bufsize,length,name):pass
@_f
@_p.types(None,_cs.GLuint,_cs.GLenum,_cs.GLuint,_cs.GLenum,arrays.GLintArray)
def glGetActiveSubroutineUniformiv(program,shadertype,index,pname,values):pass
@_f
@_p.types(None,_cs.GLuint,_cs.GLenum,_cs.GLenum,arrays.GLintArray)
def glGetProgramStageiv(program,shadertype,pname,values):pass
@_f
@_p.types(None,_cs.GLenum,_cs.GLuint,_cs.GLenum,arrays.GLintArray)
def glGetQueryIndexediv(target,index,pname,params):pass
@_f
@_p.types(_cs.GLuint,_cs.GLuint,_cs.GLenum,arrays.GLcharArray)
def glGetSubroutineIndex(program,shadertype,name):pass
@_f
@_p.types(_cs.GLint,_cs.GLuint,_cs.GLenum,arrays.GLcharArray)
def glGetSubroutineUniformLocation(program,shadertype,name):pass
@_f
@_p.types(None,_cs.GLenum,_cs.GLint,arrays.GLuintArray)
def glGetUniformSubroutineuiv(shadertype,location,params):pass
@_f
@_p.types(None,_cs.GLuint,_cs.GLint,arrays.GLdoubleArray)
def glGetUniformdv(program,location,params):pass
@_f
@_p.types(_cs.GLboolean,_cs.GLuint)
def glIsTransformFeedback(id):pass
@_f
@_p.types(None,_cs.GLfloat)
def glMinSampleShading(value):pass
@_f
@_p.types(None,_cs.GLenum,arrays.GLfloatArray)
def glPatchParameterfv(pname,values):pass
@_f
@_p.types(None,_cs.GLenum,_cs.GLint)
def glPatchParameteri(pname,value):pass
@_f
@_p.types(None,)
def glPauseTransformFeedback():pass
@_f
@_p.types(None,)
def glResumeTransformFeedback():pass
@_f
@_p.types(None,_cs.GLint,_cs.GLdouble)
def glUniform1d(location,x):pass
@_f
@_p.types(None,_cs.GLint,_cs.GLsizei,arrays.GLdoubleArray)
def glUniform1dv(location,count,value):pass
@_f
@_p.types(None,_cs.GLint,_cs.GLdouble,_cs.GLdouble)
def glUniform2d(location,x,y):pass
@_f
@_p.types(None,_cs.GLint,_cs.GLsizei,arrays.GLdoubleArray)
def glUniform2dv(location,count,value):pass
@_f
@_p.types(None,_cs.GLint,_cs.GLdouble,_cs.GLdouble,_cs.GLdouble)
def glUniform3d(location,x,y,z):pass
@_f
@_p.types(None,_cs.GLint,_cs.GLsizei,arrays.GLdoubleArray)
def glUniform3dv(location,count,value):pass
@_f
@_p.types(None,_cs.GLint,_cs.GLdouble,_cs.GLdouble,_cs.GLdouble,_cs.GLdouble)
def glUniform4d(location,x,y,z,w):pass
@_f
@_p.types(None,_cs.GLint,_cs.GLsizei,arrays.GLdoubleArray)
def glUniform4dv(location,count,value):pass
@_f
@_p.types(None,_cs.GLint,_cs.GLsizei,_cs.GLboolean,arrays.GLdoubleArray)
def glUniformMatrix2dv(location,count,transpose,value):pass
@_f
@_p.types(None,_cs.GLint,_cs.GLsizei,_cs.GLboolean,arrays.GLdoubleArray)
def glUniformMatrix2x3dv(location,count,transpose,value):pass
@_f
@_p.types(None,_cs.GLint,_cs.GLsizei,_cs.GLboolean,arrays.GLdoubleArray)
def glUniformMatrix2x4dv(location,count,transpose,value):pass
@_f
@_p.types(None,_cs.GLint,_cs.GLsizei,_cs.GLboolean,arrays.GLdoubleArray)
def glUniformMatrix3dv(location,count,transpose,value):pass
@_f
@_p.types(None,_cs.GLint,_cs.GLsizei,_cs.GLboolean,arrays.GLdoubleArray)
def glUniformMatrix3x2dv(location,count,transpose,value):pass
@_f
@_p.types(None,_cs.GLint,_cs.GLsizei,_cs.GLboolean,arrays.GLdoubleArray)
def glUniformMatrix3x4dv(location,count,transpose,value):pass
@_f
@_p.types(None,_cs.GLint,_cs.GLsizei,_cs.GLboolean,arrays.GLdoubleArray)
def glUniformMatrix4dv(location,count,transpose,value):pass
@_f
@_p.types(None,_cs.GLint,_cs.GLsizei,_cs.GLboolean,arrays.GLdoubleArray)
def glUniformMatrix4x2dv(location,count,transpose,value):pass
@_f
@_p.types(None,_cs.GLint,_cs.GLsizei,_cs.GLboolean,arrays.GLdoubleArray)
def glUniformMatrix4x3dv(location,count,transpose,value):pass
@_f
@_p.types(None,_cs.GLenum,_cs.GLsizei,arrays.GLuintArray)
def glUniformSubroutinesuiv(shadertype,count,indices):pass
|
gpl-3.0
|
[
2344,
23570,
16741,
701,
2748,
63,
4208,
2884,
12,
886,
440,
5283,
1,
2344,
199,
504,
24374,
492,
4298,
465,
485,
80,
12,
6572,
199,
3,
5495,
10152,
4440,
642,
199,
504,
24374,
14,
1773,
14,
2226,
492,
485,
1313,
465,
485,
1259,
199,
3,
9599,
4390,
2934,
642,
1396,
199,
504,
24374,
14,
1773,
14,
2226,
423,
1313,
492,
627,
199,
504,
24374,
14,
1773,
14,
2226,
492,
485,
2550,
199,
504,
24374,
14,
4083,
492,
19991,
465,
485,
35,
199,
199,
646,
5577,
199,
63,
15498,
63,
2339,
275,
283,
2226,
63,
4612,
63,
2226,
63,
20,
63,
16,
7,
199,
318,
485,
70,
8,
805,
3461,
272,
372,
485,
80,
14,
981,
3481,
8,
805,
16987,
80,
14,
17805,
14,
2226,
2584,
2226,
63,
4612,
63,
2226,
63,
20,
63,
16,
297,
705,
63,
6743,
3699,
2550,
423,
705,
63,
6743,
9,
199,
2226,
63,
10401,
63,
6348,
14999,
568,
654,
3699,
35,
360,
2226,
63,
10401,
63,
6348,
14999,
568,
654,
297,
16,
88,
24,
1093,
21,
9,
199,
2226,
63,
10401,
63,
6348,
14999,
3565,
63,
4283,
63,
9127,
3699,
35,
360,
2226,
63,
10401,
63,
6348,
14999,
3565,
63,
4283,
63,
9127,
297,
16,
88,
24,
37,
2006,
9,
199,
2226,
63,
10401,
63,
6348,
14999,
3565,
63,
15134,
11518,
3699,
35,
360,
2226,
63,
10401,
63,
6348,
14999,
3565,
63,
15134,
11518,
297,
16,
88,
24,
1093,
22,
9,
199,
2226,
63,
10401,
63,
6348,
14999,
3565,
63,
30507,
63,
5752,
12969,
3699,
35,
360,
2226,
63,
10401,
63,
6348,
14999,
3565,
63,
30507,
63,
5752,
12969,
297,
16,
88,
24,
37,
2417,
9,
199,
2226,
63,
10401,
63,
6348,
14999,
3565,
63,
30507,
63,
4283,
63,
9127,
3699,
35,
360,
2226,
63,
10401,
63,
6348,
14999,
3565,
63,
30507,
63,
4283,
63,
9127,
297,
16,
88,
24,
37,
1887,
9,
199,
2226,
63,
29720,
7187,
63,
6348,
14999,
568,
654,
3699,
35,
360,
2226,
63,
29720,
7187,
63,
6348,
14999,
568,
654,
297,
16,
88,
24,
37,
20,
34,
9,
199,
2226,
63,
14989,
63,
16996,
18,
3699,
35,
360,
2226,
63,
14989,
63,
16996,
18,
297,
16,
88,
24,
38,
2466,
9,
199,
2226,
63,
14989,
63,
16996,
18,
88,
19,
3699,
35,
360,
2226,
63,
14989,
63,
16996,
18,
88,
19,
297,
16,
88,
24,
38,
1887,
9,
199,
2226,
63,
14989,
63,
16996,
18,
88,
20,
3699,
35,
360,
2226,
63,
14989,
63,
16996,
18,
88,
20,
297,
16,
88,
24,
38,
20,
33,
9,
199,
2226,
63,
14989,
63,
16996,
19,
3699,
35,
360,
2226,
63,
14989,
63,
16996,
19,
297,
16,
88,
24,
38,
2417,
9,
199,
2226,
63,
14989,
63,
16996,
19,
88,
18,
3699,
35,
360,
2226,
63,
14989,
63,
16996,
19,
88,
18,
297,
16,
88,
24,
38,
20,
34,
9,
199,
2226,
63,
14989,
63,
16996,
19,
88,
20,
3699,
35,
360,
2226,
63,
14989,
63,
16996,
19,
88,
20,
297,
16,
88,
24,
38,
20,
35,
9,
199,
2226,
63,
14989,
63,
16996,
20,
3699,
35,
360,
2226,
63,
14989,
63,
16996,
20,
297,
16,
88,
24,
38,
2006,
9,
199,
2226,
63,
14989,
63,
16996,
20,
88,
18,
3699,
35,
360,
2226,
63,
14989,
63,
16996,
20,
88,
18,
297,
16,
88,
24,
38,
20,
36,
9,
199,
2226,
63,
14989,
63,
16996,
20,
88,
19,
3699,
35,
360,
2226,
63,
14989,
63,
16996,
20,
88,
19,
297,
16,
88,
24,
38,
20,
37,
9,
199,
2226,
63,
14989,
63,
2524,
35,
18,
3699,
35,
360,
2226,
63,
14989,
63,
2524,
35,
18,
297,
16,
88,
24,
1665,
35,
9,
199,
2226,
63,
14989,
63,
2524,
35,
19,
3699,
35,
360,
2226,
63,
14989,
63,
2524,
35,
19,
297,
16,
88,
24,
24192,
9,
199,
2226,
63,
14989,
63,
2524,
35,
20,
3699,
35,
360,
2226,
63,
14989,
63,
2524,
35,
20,
297,
16,
88,
24,
1665,
37,
9,
199,
2226,
63,
12118,
63,
568,
6098,
63,
10960,
3699,
35,
360,
2226,
63,
12118,
63,
568,
6098,
63,
10960,
297,
16,
88,
24,
38,
19,
38,
9,
199,
2226,
63,
12118,
63,
568,
6098,
63,
10960,
63,
28347,
3699,
35,
360,
2226,
63,
12118,
63,
568,
6098,
63,
10960,
63,
28347,
297,
16,
88,
24,
38,
2824,
9,
199,
2226,
63,
38,
20656,
748,
63,
37,
8253,
3699,
35,
360,
2226,
63,
38,
20656,
748,
63,
37,
8253,
297,
16,
88,
24,
37,
23,
35,
9,
199,
2226,
63,
38,
20656,
748,
63,
47,
5745,
3699,
35,
360,
2226,
63,
38,
20656,
748,
63,
47,
5745,
297,
16,
88,
24,
37,
23,
34,
9,
199,
2226,
63,
28147,
63,
3843,
32713,
2594,
63,
14839,
63,
14662,
3699,
35,
360,
2226,
63,
28147,
63,
3843,
32713,
2594,
63,
14839,
63,
14662,
297,
16,
88,
24,
37,
21,
36,
9,
199,
2226,
63,
28472,
63,
3234,
21372,
63,
568,
10662,
35,
12969,
3699,
35,
360,
2226,
63,
28472,
63,
3234,
21372,
63,
568,
10662,
35,
12969,
297,
16,
88,
15989,
38,
9,
199,
2226,
63,
2919,
63,
51,
7855,
540,
63,
35,
21857,
63,
5443,
63,
12322,
3699,
35,
360,
2226,
63,
2919,
63,
51,
7855,
540,
63,
35,
21857,
63,
5443,
63,
12322,
297,
16,
88,
17518,
37,
9,
199,
2226,
63,
1311,
2228,
568,
654,
3699,
35,
360,
2226,
63,
1311,
2228,
568,
654,
297,
16,
88,
24,
37,
23,
33,
9,
199,
2226,
63,
4283,
63,
1439,
4567,
568,
1149,
63,
52,
1608,
63,
13060,
63,
30507,
63,
20360,
51,
3699,
35,
360,
2226,
63,
4283,
63,
1439,
4567,
568,
1149,
63,
52,
1608,
63,
13060,
63,
30507,
63,
20360,
51,
297,
16,
88,
24,
37,
17,
37,
9,
199,
2226,
63,
4283,
63,
1439,
4567,
568,
1149,
63,
52,
1608,
63,
28805,
53,
2594,
63,
30507,
63,
20360,
51,
3699,
35,
360,
2226,
63,
4283,
63,
1439,
4567,
568,
1149,
63,
52,
1608,
63,
28805,
53,
2594,
63,
30507,
63,
20360,
51,
297,
16,
88,
24,
37,
17,
38,
9,
199,
2226,
63,
4283,
63,
28147,
63,
3843,
32713,
2594,
63,
14839,
3699,
35,
360,
2226,
63,
4283,
63,
28147,
63,
3843,
32713,
2594,
63,
14839,
297,
16,
88,
24,
37,
21,
35
] |
[
23570,
16741,
701,
2748,
63,
4208,
2884,
12,
886,
440,
5283,
1,
2344,
199,
504,
24374,
492,
4298,
465,
485,
80,
12,
6572,
199,
3,
5495,
10152,
4440,
642,
199,
504,
24374,
14,
1773,
14,
2226,
492,
485,
1313,
465,
485,
1259,
199,
3,
9599,
4390,
2934,
642,
1396,
199,
504,
24374,
14,
1773,
14,
2226,
423,
1313,
492,
627,
199,
504,
24374,
14,
1773,
14,
2226,
492,
485,
2550,
199,
504,
24374,
14,
4083,
492,
19991,
465,
485,
35,
199,
199,
646,
5577,
199,
63,
15498,
63,
2339,
275,
283,
2226,
63,
4612,
63,
2226,
63,
20,
63,
16,
7,
199,
318,
485,
70,
8,
805,
3461,
272,
372,
485,
80,
14,
981,
3481,
8,
805,
16987,
80,
14,
17805,
14,
2226,
2584,
2226,
63,
4612,
63,
2226,
63,
20,
63,
16,
297,
705,
63,
6743,
3699,
2550,
423,
705,
63,
6743,
9,
199,
2226,
63,
10401,
63,
6348,
14999,
568,
654,
3699,
35,
360,
2226,
63,
10401,
63,
6348,
14999,
568,
654,
297,
16,
88,
24,
1093,
21,
9,
199,
2226,
63,
10401,
63,
6348,
14999,
3565,
63,
4283,
63,
9127,
3699,
35,
360,
2226,
63,
10401,
63,
6348,
14999,
3565,
63,
4283,
63,
9127,
297,
16,
88,
24,
37,
2006,
9,
199,
2226,
63,
10401,
63,
6348,
14999,
3565,
63,
15134,
11518,
3699,
35,
360,
2226,
63,
10401,
63,
6348,
14999,
3565,
63,
15134,
11518,
297,
16,
88,
24,
1093,
22,
9,
199,
2226,
63,
10401,
63,
6348,
14999,
3565,
63,
30507,
63,
5752,
12969,
3699,
35,
360,
2226,
63,
10401,
63,
6348,
14999,
3565,
63,
30507,
63,
5752,
12969,
297,
16,
88,
24,
37,
2417,
9,
199,
2226,
63,
10401,
63,
6348,
14999,
3565,
63,
30507,
63,
4283,
63,
9127,
3699,
35,
360,
2226,
63,
10401,
63,
6348,
14999,
3565,
63,
30507,
63,
4283,
63,
9127,
297,
16,
88,
24,
37,
1887,
9,
199,
2226,
63,
29720,
7187,
63,
6348,
14999,
568,
654,
3699,
35,
360,
2226,
63,
29720,
7187,
63,
6348,
14999,
568,
654,
297,
16,
88,
24,
37,
20,
34,
9,
199,
2226,
63,
14989,
63,
16996,
18,
3699,
35,
360,
2226,
63,
14989,
63,
16996,
18,
297,
16,
88,
24,
38,
2466,
9,
199,
2226,
63,
14989,
63,
16996,
18,
88,
19,
3699,
35,
360,
2226,
63,
14989,
63,
16996,
18,
88,
19,
297,
16,
88,
24,
38,
1887,
9,
199,
2226,
63,
14989,
63,
16996,
18,
88,
20,
3699,
35,
360,
2226,
63,
14989,
63,
16996,
18,
88,
20,
297,
16,
88,
24,
38,
20,
33,
9,
199,
2226,
63,
14989,
63,
16996,
19,
3699,
35,
360,
2226,
63,
14989,
63,
16996,
19,
297,
16,
88,
24,
38,
2417,
9,
199,
2226,
63,
14989,
63,
16996,
19,
88,
18,
3699,
35,
360,
2226,
63,
14989,
63,
16996,
19,
88,
18,
297,
16,
88,
24,
38,
20,
34,
9,
199,
2226,
63,
14989,
63,
16996,
19,
88,
20,
3699,
35,
360,
2226,
63,
14989,
63,
16996,
19,
88,
20,
297,
16,
88,
24,
38,
20,
35,
9,
199,
2226,
63,
14989,
63,
16996,
20,
3699,
35,
360,
2226,
63,
14989,
63,
16996,
20,
297,
16,
88,
24,
38,
2006,
9,
199,
2226,
63,
14989,
63,
16996,
20,
88,
18,
3699,
35,
360,
2226,
63,
14989,
63,
16996,
20,
88,
18,
297,
16,
88,
24,
38,
20,
36,
9,
199,
2226,
63,
14989,
63,
16996,
20,
88,
19,
3699,
35,
360,
2226,
63,
14989,
63,
16996,
20,
88,
19,
297,
16,
88,
24,
38,
20,
37,
9,
199,
2226,
63,
14989,
63,
2524,
35,
18,
3699,
35,
360,
2226,
63,
14989,
63,
2524,
35,
18,
297,
16,
88,
24,
1665,
35,
9,
199,
2226,
63,
14989,
63,
2524,
35,
19,
3699,
35,
360,
2226,
63,
14989,
63,
2524,
35,
19,
297,
16,
88,
24,
24192,
9,
199,
2226,
63,
14989,
63,
2524,
35,
20,
3699,
35,
360,
2226,
63,
14989,
63,
2524,
35,
20,
297,
16,
88,
24,
1665,
37,
9,
199,
2226,
63,
12118,
63,
568,
6098,
63,
10960,
3699,
35,
360,
2226,
63,
12118,
63,
568,
6098,
63,
10960,
297,
16,
88,
24,
38,
19,
38,
9,
199,
2226,
63,
12118,
63,
568,
6098,
63,
10960,
63,
28347,
3699,
35,
360,
2226,
63,
12118,
63,
568,
6098,
63,
10960,
63,
28347,
297,
16,
88,
24,
38,
2824,
9,
199,
2226,
63,
38,
20656,
748,
63,
37,
8253,
3699,
35,
360,
2226,
63,
38,
20656,
748,
63,
37,
8253,
297,
16,
88,
24,
37,
23,
35,
9,
199,
2226,
63,
38,
20656,
748,
63,
47,
5745,
3699,
35,
360,
2226,
63,
38,
20656,
748,
63,
47,
5745,
297,
16,
88,
24,
37,
23,
34,
9,
199,
2226,
63,
28147,
63,
3843,
32713,
2594,
63,
14839,
63,
14662,
3699,
35,
360,
2226,
63,
28147,
63,
3843,
32713,
2594,
63,
14839,
63,
14662,
297,
16,
88,
24,
37,
21,
36,
9,
199,
2226,
63,
28472,
63,
3234,
21372,
63,
568,
10662,
35,
12969,
3699,
35,
360,
2226,
63,
28472,
63,
3234,
21372,
63,
568,
10662,
35,
12969,
297,
16,
88,
15989,
38,
9,
199,
2226,
63,
2919,
63,
51,
7855,
540,
63,
35,
21857,
63,
5443,
63,
12322,
3699,
35,
360,
2226,
63,
2919,
63,
51,
7855,
540,
63,
35,
21857,
63,
5443,
63,
12322,
297,
16,
88,
17518,
37,
9,
199,
2226,
63,
1311,
2228,
568,
654,
3699,
35,
360,
2226,
63,
1311,
2228,
568,
654,
297,
16,
88,
24,
37,
23,
33,
9,
199,
2226,
63,
4283,
63,
1439,
4567,
568,
1149,
63,
52,
1608,
63,
13060,
63,
30507,
63,
20360,
51,
3699,
35,
360,
2226,
63,
4283,
63,
1439,
4567,
568,
1149,
63,
52,
1608,
63,
13060,
63,
30507,
63,
20360,
51,
297,
16,
88,
24,
37,
17,
37,
9,
199,
2226,
63,
4283,
63,
1439,
4567,
568,
1149,
63,
52,
1608,
63,
28805,
53,
2594,
63,
30507,
63,
20360,
51,
3699,
35,
360,
2226,
63,
4283,
63,
1439,
4567,
568,
1149,
63,
52,
1608,
63,
28805,
53,
2594,
63,
30507,
63,
20360,
51,
297,
16,
88,
24,
37,
17,
38,
9,
199,
2226,
63,
4283,
63,
28147,
63,
3843,
32713,
2594,
63,
14839,
3699,
35,
360,
2226,
63,
4283,
63,
28147,
63,
3843,
32713,
2594,
63,
14839,
297,
16,
88,
24,
37,
21,
35,
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
] |
fitermay/intellij-community
|
python/lib/Lib/site-packages/django/contrib/localflavor/uk/forms.py
|
313
|
1943
|
"""
UK-specific Form helpers
"""
import re
from django.forms.fields import CharField, Select
from django.forms import ValidationError
from django.utils.translation import ugettext_lazy as _
class UKPostcodeField(CharField):
"""
A form field that validates its input is a UK postcode.
The regular expression used is sourced from the schema for British Standard
BS7666 address types: http://www.govtalk.gov.uk/gdsc/schemas/bs7666-v2-0.xsd
The value is uppercased and a space added in the correct place, if required.
"""
default_error_messages = {
'invalid': _(u'Enter a valid postcode.'),
}
outcode_pattern = '[A-PR-UWYZ]([0-9]{1,2}|([A-HIK-Y][0-9](|[0-9]|[ABEHMNPRVWXY]))|[0-9][A-HJKSTUW])'
incode_pattern = '[0-9][ABD-HJLNP-UW-Z]{2}'
postcode_regex = re.compile(r'^(GIR 0AA|%s %s)$' % (outcode_pattern, incode_pattern))
space_regex = re.compile(r' *(%s)$' % incode_pattern)
def clean(self, value):
value = super(UKPostcodeField, self).clean(value)
if value == u'':
return value
postcode = value.upper().strip()
# Put a single space before the incode (second part).
postcode = self.space_regex.sub(r' \1', postcode)
if not self.postcode_regex.search(postcode):
raise ValidationError(self.error_messages['invalid'])
return postcode
class UKCountySelect(Select):
"""
A Select widget that uses a list of UK Counties/Regions as its choices.
"""
def __init__(self, attrs=None):
from uk_regions import UK_REGION_CHOICES
super(UKCountySelect, self).__init__(attrs, choices=UK_REGION_CHOICES)
class UKNationSelect(Select):
"""
A Select widget that uses a list of UK Nations as its choices.
"""
def __init__(self, attrs=None):
from uk_regions import UK_NATIONS_CHOICES
super(UKNationSelect, self).__init__(attrs, choices=UK_NATIONS_CHOICES)
|
apache-2.0
|
[
624,
199,
26667,
13,
6100,
8204,
10897,
199,
624,
199,
199,
646,
295,
199,
199,
504,
1639,
14,
3351,
14,
955,
492,
12064,
12,
9496,
199,
504,
1639,
14,
3351,
492,
8505,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
485,
199,
199,
533,
738,
43,
6564,
600,
792,
8,
2183,
304,
272,
408,
272,
437,
1824,
901,
626,
29280,
2399,
1324,
365,
282,
738,
43,
2963,
600,
14,
339,
710,
5578,
3965,
1202,
365,
1350,
68,
687,
314,
4177,
367,
699,
322,
23184,
9739,
272,
699,
51,
23,
11829,
2287,
2943,
26,
1455,
921,
1544,
14,
1939,
5941,
4878,
14,
16294,
14,
3210,
15,
7136,
551,
15,
9482,
15,
1533,
23,
11829,
13,
86,
18,
13,
16,
14,
10515,
339,
710,
574,
365,
22681,
68,
436,
282,
4601,
3483,
315,
314,
3211,
4192,
12,
340,
1415,
14,
272,
408,
272,
849,
63,
705,
63,
3431,
275,
469,
267,
283,
3197,
356,
12561,
85,
7,
8468,
282,
1686,
2963,
600,
8038,
272,
789,
272,
734,
600,
63,
3401,
275,
6730,
33,
13,
3311,
13,
53,
55,
26184,
61,
779,
16,
13,
25,
8194,
17,
12,
18,
22441,
779,
33,
13,
11183,
43,
13,
57,
1527,
16,
13,
25,
8738,
17884,
16,
13,
25,
32673,
1217,
24948,
16237,
3311,
54,
55,
8195,
2459,
17884,
16,
13,
25,
1527,
33,
13,
22313,
43,
840,
53,
55,
566,
7,
272,
315,
600,
63,
3401,
275,
6730,
16,
13,
25,
1527,
1217,
36,
13,
22313,
44,
14970,
13,
53,
55,
13,
58,
8194,
18,
6834,
272,
2963,
600,
63,
3821,
275,
295,
14,
2014,
8,
82,
31996,
39,
3927,
378,
2276,
15287,
83,
450,
83,
9,
12913,
450,
334,
548,
600,
63,
3401,
12,
315,
600,
63,
3401,
430,
272,
4601,
63,
3821,
275,
295,
14,
2014,
8,
82,
7,
627,
4042,
83,
9,
12913,
450,
315,
600,
63,
3401,
9,
339,
347,
3633,
8,
277,
12,
574,
304,
267,
574,
275,
1613,
8,
26667,
6564,
600,
792,
12,
291,
680,
3118,
8,
585,
9,
267,
340,
574,
508,
399,
7,
356,
288,
372,
574,
267,
2963,
600,
275,
574,
14,
4142,
1252,
1913,
342,
267,
327,
16280,
282,
2849,
4601,
2544,
314,
315,
600,
334,
4375,
1777,
680,
267,
2963,
600,
275,
291,
14,
2638,
63,
3821,
14,
954,
8,
82,
7,
971,
17,
297,
2963,
600,
9,
267,
340,
440,
291,
14,
1932,
600,
63,
3821,
14,
1733,
8,
1932,
600,
304,
288,
746,
8505,
8,
277,
14,
705,
63,
3431,
459,
3197,
1105,
267,
372,
2963,
600,
199,
199,
533,
738,
43,
24532,
369,
5446,
8,
5446,
304,
272,
408,
272,
437,
9496,
3938,
626,
4440,
282,
769,
402,
738,
43,
1849,
324,
1417,
15,
10708,
83,
465,
2399,
3415,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
3290,
29,
403,
304,
267,
687,
399,
75,
63,
11963,
492,
738,
43,
63,
23030,
63,
16236,
267,
1613,
8,
26667,
24532,
369,
5446,
12,
291,
2843,
826,
721,
3288,
12,
3415,
29,
26667,
63,
23030,
63,
16236,
9,
199,
199,
533,
738,
43,
46,
425,
5446,
8,
5446,
304,
272,
408,
272,
437,
9496,
3938,
626,
4440,
282,
769,
402,
738,
43,
653,
1298,
465,
2399,
3415,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
3290,
29,
403,
304,
267,
687,
399,
75,
63,
11963,
492,
738,
43,
63,
46,
12969,
63,
16236,
267,
1613,
8,
26667,
46,
425,
5446,
12,
291,
2843,
826,
721,
3288,
12,
3415,
29,
26667,
63,
46,
12969,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
26667,
13,
6100,
8204,
10897,
199,
624,
199,
199,
646,
295,
199,
199,
504,
1639,
14,
3351,
14,
955,
492,
12064,
12,
9496,
199,
504,
1639,
14,
3351,
492,
8505,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
485,
199,
199,
533,
738,
43,
6564,
600,
792,
8,
2183,
304,
272,
408,
272,
437,
1824,
901,
626,
29280,
2399,
1324,
365,
282,
738,
43,
2963,
600,
14,
339,
710,
5578,
3965,
1202,
365,
1350,
68,
687,
314,
4177,
367,
699,
322,
23184,
9739,
272,
699,
51,
23,
11829,
2287,
2943,
26,
1455,
921,
1544,
14,
1939,
5941,
4878,
14,
16294,
14,
3210,
15,
7136,
551,
15,
9482,
15,
1533,
23,
11829,
13,
86,
18,
13,
16,
14,
10515,
339,
710,
574,
365,
22681,
68,
436,
282,
4601,
3483,
315,
314,
3211,
4192,
12,
340,
1415,
14,
272,
408,
272,
849,
63,
705,
63,
3431,
275,
469,
267,
283,
3197,
356,
12561,
85,
7,
8468,
282,
1686,
2963,
600,
8038,
272,
789,
272,
734,
600,
63,
3401,
275,
6730,
33,
13,
3311,
13,
53,
55,
26184,
61,
779,
16,
13,
25,
8194,
17,
12,
18,
22441,
779,
33,
13,
11183,
43,
13,
57,
1527,
16,
13,
25,
8738,
17884,
16,
13,
25,
32673,
1217,
24948,
16237,
3311,
54,
55,
8195,
2459,
17884,
16,
13,
25,
1527,
33,
13,
22313,
43,
840,
53,
55,
566,
7,
272,
315,
600,
63,
3401,
275,
6730,
16,
13,
25,
1527,
1217,
36,
13,
22313,
44,
14970,
13,
53,
55,
13,
58,
8194,
18,
6834,
272,
2963,
600,
63,
3821,
275,
295,
14,
2014,
8,
82,
31996,
39,
3927,
378,
2276,
15287,
83,
450,
83,
9,
12913,
450,
334,
548,
600,
63,
3401,
12,
315,
600,
63,
3401,
430,
272,
4601,
63,
3821,
275,
295,
14,
2014,
8,
82,
7,
627,
4042,
83,
9,
12913,
450,
315,
600,
63,
3401,
9,
339,
347,
3633,
8,
277,
12,
574,
304,
267,
574,
275,
1613,
8,
26667,
6564,
600,
792,
12,
291,
680,
3118,
8,
585,
9,
267,
340,
574,
508,
399,
7,
356,
288,
372,
574,
267,
2963,
600,
275,
574,
14,
4142,
1252,
1913,
342,
267,
327,
16280,
282,
2849,
4601,
2544,
314,
315,
600,
334,
4375,
1777,
680,
267,
2963,
600,
275,
291,
14,
2638,
63,
3821,
14,
954,
8,
82,
7,
971,
17,
297,
2963,
600,
9,
267,
340,
440,
291,
14,
1932,
600,
63,
3821,
14,
1733,
8,
1932,
600,
304,
288,
746,
8505,
8,
277,
14,
705,
63,
3431,
459,
3197,
1105,
267,
372,
2963,
600,
199,
199,
533,
738,
43,
24532,
369,
5446,
8,
5446,
304,
272,
408,
272,
437,
9496,
3938,
626,
4440,
282,
769,
402,
738,
43,
1849,
324,
1417,
15,
10708,
83,
465,
2399,
3415,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
3290,
29,
403,
304,
267,
687,
399,
75,
63,
11963,
492,
738,
43,
63,
23030,
63,
16236,
267,
1613,
8,
26667,
24532,
369,
5446,
12,
291,
2843,
826,
721,
3288,
12,
3415,
29,
26667,
63,
23030,
63,
16236,
9,
199,
199,
533,
738,
43,
46,
425,
5446,
8,
5446,
304,
272,
408,
272,
437,
9496,
3938,
626,
4440,
282,
769,
402,
738,
43,
653,
1298,
465,
2399,
3415,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
3290,
29,
403,
304,
267,
687,
399,
75,
63,
11963,
492,
738,
43,
63,
46,
12969,
63,
16236,
267,
1613,
8,
26667,
46,
425,
5446,
12,
291,
2843,
826,
721,
3288,
12,
3415,
29,
26667,
63,
46,
12969,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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
] |
priyam0074/musicApp
|
node_modules/node-gyp/gyp/pylib/gyp/common.py
|
1292
|
20063
|
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
from __future__ import with_statement
import collections
import errno
import filecmp
import os.path
import re
import tempfile
import sys
# A minimal memoizing decorator. It'll blow up if the args aren't immutable,
# among other "problems".
class memoize(object):
def __init__(self, func):
self.func = func
self.cache = {}
def __call__(self, *args):
try:
return self.cache[args]
except KeyError:
result = self.func(*args)
self.cache[args] = result
return result
class GypError(Exception):
"""Error class representing an error, which is to be presented
to the user. The main entry point will catch and display this.
"""
pass
def ExceptionAppend(e, msg):
"""Append a message to the given exception's message."""
if not e.args:
e.args = (msg,)
elif len(e.args) == 1:
e.args = (str(e.args[0]) + ' ' + msg,)
else:
e.args = (str(e.args[0]) + ' ' + msg,) + e.args[1:]
def FindQualifiedTargets(target, qualified_list):
"""
Given a list of qualified targets, return the qualified targets for the
specified |target|.
"""
return [t for t in qualified_list if ParseQualifiedTarget(t)[1] == target]
def ParseQualifiedTarget(target):
# Splits a qualified target into a build file, target name and toolset.
# NOTE: rsplit is used to disambiguate the Windows drive letter separator.
target_split = target.rsplit(':', 1)
if len(target_split) == 2:
[build_file, target] = target_split
else:
build_file = None
target_split = target.rsplit('#', 1)
if len(target_split) == 2:
[target, toolset] = target_split
else:
toolset = None
return [build_file, target, toolset]
def ResolveTarget(build_file, target, toolset):
# This function resolves a target into a canonical form:
# - a fully defined build file, either absolute or relative to the current
# directory
# - a target name
# - a toolset
#
# build_file is the file relative to which 'target' is defined.
# target is the qualified target.
# toolset is the default toolset for that target.
[parsed_build_file, target, parsed_toolset] = ParseQualifiedTarget(target)
if parsed_build_file:
if build_file:
# If a relative path, parsed_build_file is relative to the directory
# containing build_file. If build_file is not in the current directory,
# parsed_build_file is not a usable path as-is. Resolve it by
# interpreting it as relative to build_file. If parsed_build_file is
# absolute, it is usable as a path regardless of the current directory,
# and os.path.join will return it as-is.
build_file = os.path.normpath(os.path.join(os.path.dirname(build_file),
parsed_build_file))
# Further (to handle cases like ../cwd), make it relative to cwd)
if not os.path.isabs(build_file):
build_file = RelativePath(build_file, '.')
else:
build_file = parsed_build_file
if parsed_toolset:
toolset = parsed_toolset
return [build_file, target, toolset]
def BuildFile(fully_qualified_target):
# Extracts the build file from the fully qualified target.
return ParseQualifiedTarget(fully_qualified_target)[0]
def GetEnvironFallback(var_list, default):
"""Look up a key in the environment, with fallback to secondary keys
and finally falling back to a default value."""
for var in var_list:
if var in os.environ:
return os.environ[var]
return default
def QualifiedTarget(build_file, target, toolset):
# "Qualified" means the file that a target was defined in and the target
# name, separated by a colon, suffixed by a # and the toolset name:
# /path/to/file.gyp:target_name#toolset
fully_qualified = build_file + ':' + target
if toolset:
fully_qualified = fully_qualified + '#' + toolset
return fully_qualified
@memoize
def RelativePath(path, relative_to, follow_path_symlink=True):
# Assuming both |path| and |relative_to| are relative to the current
# directory, returns a relative path that identifies path relative to
# relative_to.
# If |follow_symlink_path| is true (default) and |path| is a symlink, then
# this method returns a path to the real file represented by |path|. If it is
# false, this method returns a path to the symlink. If |path| is not a
# symlink, this option has no effect.
# Convert to normalized (and therefore absolute paths).
if follow_path_symlink:
path = os.path.realpath(path)
else:
path = os.path.abspath(path)
relative_to = os.path.realpath(relative_to)
# On Windows, we can't create a relative path to a different drive, so just
# use the absolute path.
if sys.platform == 'win32':
if (os.path.splitdrive(path)[0].lower() !=
os.path.splitdrive(relative_to)[0].lower()):
return path
# Split the paths into components.
path_split = path.split(os.path.sep)
relative_to_split = relative_to.split(os.path.sep)
# Determine how much of the prefix the two paths share.
prefix_len = len(os.path.commonprefix([path_split, relative_to_split]))
# Put enough ".." components to back up out of relative_to to the common
# prefix, and then append the part of path_split after the common prefix.
relative_split = [os.path.pardir] * (len(relative_to_split) - prefix_len) + \
path_split[prefix_len:]
if len(relative_split) == 0:
# The paths were the same.
return ''
# Turn it back into a string and we're done.
return os.path.join(*relative_split)
@memoize
def InvertRelativePath(path, toplevel_dir=None):
"""Given a path like foo/bar that is relative to toplevel_dir, return
the inverse relative path back to the toplevel_dir.
E.g. os.path.normpath(os.path.join(path, InvertRelativePath(path)))
should always produce the empty string, unless the path contains symlinks.
"""
if not path:
return path
toplevel_dir = '.' if toplevel_dir is None else toplevel_dir
return RelativePath(toplevel_dir, os.path.join(toplevel_dir, path))
def FixIfRelativePath(path, relative_to):
# Like RelativePath but returns |path| unchanged if it is absolute.
if os.path.isabs(path):
return path
return RelativePath(path, relative_to)
def UnrelativePath(path, relative_to):
# Assuming that |relative_to| is relative to the current directory, and |path|
# is a path relative to the dirname of |relative_to|, returns a path that
# identifies |path| relative to the current directory.
rel_dir = os.path.dirname(relative_to)
return os.path.normpath(os.path.join(rel_dir, path))
# re objects used by EncodePOSIXShellArgument. See IEEE 1003.1 XCU.2.2 at
# http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_02
# and the documentation for various shells.
# _quote is a pattern that should match any argument that needs to be quoted
# with double-quotes by EncodePOSIXShellArgument. It matches the following
# characters appearing anywhere in an argument:
# \t, \n, space parameter separators
# # comments
# $ expansions (quoted to always expand within one argument)
# % called out by IEEE 1003.1 XCU.2.2
# & job control
# ' quoting
# (, ) subshell execution
# *, ?, [ pathname expansion
# ; command delimiter
# <, >, | redirection
# = assignment
# {, } brace expansion (bash)
# ~ tilde expansion
# It also matches the empty string, because "" (or '') is the only way to
# represent an empty string literal argument to a POSIX shell.
#
# This does not match the characters in _escape, because those need to be
# backslash-escaped regardless of whether they appear in a double-quoted
# string.
_quote = re.compile('[\t\n #$%&\'()*;<=>?[{|}~]|^$')
# _escape is a pattern that should match any character that needs to be
# escaped with a backslash, whether or not the argument matched the _quote
# pattern. _escape is used with re.sub to backslash anything in _escape's
# first match group, hence the (parentheses) in the regular expression.
#
# _escape matches the following characters appearing anywhere in an argument:
# " to prevent POSIX shells from interpreting this character for quoting
# \ to prevent POSIX shells from interpreting this character for escaping
# ` to prevent POSIX shells from interpreting this character for command
# substitution
# Missing from this list is $, because the desired behavior of
# EncodePOSIXShellArgument is to permit parameter (variable) expansion.
#
# Also missing from this list is !, which bash will interpret as the history
# expansion character when history is enabled. bash does not enable history
# by default in non-interactive shells, so this is not thought to be a problem.
# ! was omitted from this list because bash interprets "\!" as a literal string
# including the backslash character (avoiding history expansion but retaining
# the backslash), which would not be correct for argument encoding. Handling
# this case properly would also be problematic because bash allows the history
# character to be changed with the histchars shell variable. Fortunately,
# as history is not enabled in non-interactive shells and
# EncodePOSIXShellArgument is only expected to encode for non-interactive
# shells, there is no room for error here by ignoring !.
_escape = re.compile(r'(["\\`])')
def EncodePOSIXShellArgument(argument):
"""Encodes |argument| suitably for consumption by POSIX shells.
argument may be quoted and escaped as necessary to ensure that POSIX shells
treat the returned value as a literal representing the argument passed to
this function. Parameter (variable) expansions beginning with $ are allowed
to remain intact without escaping the $, to allow the argument to contain
references to variables to be expanded by the shell.
"""
if not isinstance(argument, str):
argument = str(argument)
if _quote.search(argument):
quote = '"'
else:
quote = ''
encoded = quote + re.sub(_escape, r'\\\1', argument) + quote
return encoded
def EncodePOSIXShellList(list):
"""Encodes |list| suitably for consumption by POSIX shells.
Returns EncodePOSIXShellArgument for each item in list, and joins them
together using the space character as an argument separator.
"""
encoded_arguments = []
for argument in list:
encoded_arguments.append(EncodePOSIXShellArgument(argument))
return ' '.join(encoded_arguments)
def DeepDependencyTargets(target_dicts, roots):
"""Returns the recursive list of target dependencies."""
dependencies = set()
pending = set(roots)
while pending:
# Pluck out one.
r = pending.pop()
# Skip if visited already.
if r in dependencies:
continue
# Add it.
dependencies.add(r)
# Add its children.
spec = target_dicts[r]
pending.update(set(spec.get('dependencies', [])))
pending.update(set(spec.get('dependencies_original', [])))
return list(dependencies - set(roots))
def BuildFileTargets(target_list, build_file):
"""From a target_list, returns the subset from the specified build_file.
"""
return [p for p in target_list if BuildFile(p) == build_file]
def AllTargets(target_list, target_dicts, build_file):
"""Returns all targets (direct and dependencies) for the specified build_file.
"""
bftargets = BuildFileTargets(target_list, build_file)
deptargets = DeepDependencyTargets(target_dicts, bftargets)
return bftargets + deptargets
def WriteOnDiff(filename):
"""Write to a file only if the new contents differ.
Arguments:
filename: name of the file to potentially write to.
Returns:
A file like object which will write to temporary file and only overwrite
the target if it differs (on close).
"""
class Writer(object):
"""Wrapper around file which only covers the target if it differs."""
def __init__(self):
# Pick temporary file.
tmp_fd, self.tmp_path = tempfile.mkstemp(
suffix='.tmp',
prefix=os.path.split(filename)[1] + '.gyp.',
dir=os.path.split(filename)[0])
try:
self.tmp_file = os.fdopen(tmp_fd, 'wb')
except Exception:
# Don't leave turds behind.
os.unlink(self.tmp_path)
raise
def __getattr__(self, attrname):
# Delegate everything else to self.tmp_file
return getattr(self.tmp_file, attrname)
def close(self):
try:
# Close tmp file.
self.tmp_file.close()
# Determine if different.
same = False
try:
same = filecmp.cmp(self.tmp_path, filename, False)
except OSError, e:
if e.errno != errno.ENOENT:
raise
if same:
# The new file is identical to the old one, just get rid of the new
# one.
os.unlink(self.tmp_path)
else:
# The new file is different from the old one, or there is no old one.
# Rename the new file to the permanent name.
#
# tempfile.mkstemp uses an overly restrictive mode, resulting in a
# file that can only be read by the owner, regardless of the umask.
# There's no reason to not respect the umask here, which means that
# an extra hoop is required to fetch it and reset the new file's mode.
#
# No way to get the umask without setting a new one? Set a safe one
# and then set it back to the old value.
umask = os.umask(077)
os.umask(umask)
os.chmod(self.tmp_path, 0666 & ~umask)
if sys.platform == 'win32' and os.path.exists(filename):
# NOTE: on windows (but not cygwin) rename will not replace an
# existing file, so it must be preceded with a remove. Sadly there
# is no way to make the switch atomic.
os.remove(filename)
os.rename(self.tmp_path, filename)
except Exception:
# Don't leave turds behind.
os.unlink(self.tmp_path)
raise
return Writer()
def EnsureDirExists(path):
"""Make sure the directory for |path| exists."""
try:
os.makedirs(os.path.dirname(path))
except OSError:
pass
def GetFlavor(params):
"""Returns |params.flavor| if it's set, the system's default flavor else."""
flavors = {
'cygwin': 'win',
'win32': 'win',
'darwin': 'mac',
}
if 'flavor' in params:
return params['flavor']
if sys.platform in flavors:
return flavors[sys.platform]
if sys.platform.startswith('sunos'):
return 'solaris'
if sys.platform.startswith('freebsd'):
return 'freebsd'
if sys.platform.startswith('openbsd'):
return 'openbsd'
if sys.platform.startswith('netbsd'):
return 'netbsd'
if sys.platform.startswith('aix'):
return 'aix'
return 'linux'
def CopyTool(flavor, out_path):
"""Finds (flock|mac|win)_tool.gyp in the gyp directory and copies it
to |out_path|."""
# aix and solaris just need flock emulation. mac and win use more complicated
# support scripts.
prefix = {
'aix': 'flock',
'solaris': 'flock',
'mac': 'mac',
'win': 'win'
}.get(flavor, None)
if not prefix:
return
# Slurp input file.
source_path = os.path.join(
os.path.dirname(os.path.abspath(__file__)), '%s_tool.py' % prefix)
with open(source_path) as source_file:
source = source_file.readlines()
# Add header and write it out.
tool_path = os.path.join(out_path, 'gyp-%s-tool' % prefix)
with open(tool_path, 'w') as tool_file:
tool_file.write(
''.join([source[0], '# Generated by gyp. Do not edit.\n'] + source[1:]))
# Make file executable.
os.chmod(tool_path, 0755)
# From Alex Martelli,
# http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52560
# ASPN: Python Cookbook: Remove duplicates from a sequence
# First comment, dated 2001/10/13.
# (Also in the printed Python Cookbook.)
def uniquer(seq, idfun=None):
if idfun is None:
idfun = lambda x: x
seen = {}
result = []
for item in seq:
marker = idfun(item)
if marker in seen: continue
seen[marker] = 1
result.append(item)
return result
# Based on http://code.activestate.com/recipes/576694/.
class OrderedSet(collections.MutableSet):
def __init__(self, iterable=None):
self.end = end = []
end += [None, end, end] # sentinel node for doubly linked list
self.map = {} # key --> [key, prev, next]
if iterable is not None:
self |= iterable
def __len__(self):
return len(self.map)
def __contains__(self, key):
return key in self.map
def add(self, key):
if key not in self.map:
end = self.end
curr = end[1]
curr[2] = end[1] = self.map[key] = [key, curr, end]
def discard(self, key):
if key in self.map:
key, prev_item, next_item = self.map.pop(key)
prev_item[2] = next_item
next_item[1] = prev_item
def __iter__(self):
end = self.end
curr = end[2]
while curr is not end:
yield curr[0]
curr = curr[2]
def __reversed__(self):
end = self.end
curr = end[1]
while curr is not end:
yield curr[0]
curr = curr[1]
# The second argument is an addition that causes a pylint warning.
def pop(self, last=True): # pylint: disable=W0221
if not self:
raise KeyError('set is empty')
key = self.end[1][0] if last else self.end[2][0]
self.discard(key)
return key
def __repr__(self):
if not self:
return '%s()' % (self.__class__.__name__,)
return '%s(%r)' % (self.__class__.__name__, list(self))
def __eq__(self, other):
if isinstance(other, OrderedSet):
return len(self) == len(other) and list(self) == list(other)
return set(self) == set(other)
# Extensions to the recipe.
def update(self, iterable):
for i in iterable:
if i not in self:
self.add(i)
class CycleError(Exception):
"""An exception raised when an unexpected cycle is detected."""
def __init__(self, nodes):
self.nodes = nodes
def __str__(self):
return 'CycleError: cycle involving: ' + str(self.nodes)
def TopologicallySorted(graph, get_edges):
r"""Topologically sort based on a user provided edge definition.
Args:
graph: A list of node names.
get_edges: A function mapping from node name to a hashable collection
of node names which this node has outgoing edges to.
Returns:
A list containing all of the node in graph in topological order.
It is assumed that calling get_edges once for each node and caching is
cheaper than repeatedly calling get_edges.
Raises:
CycleError in the event of a cycle.
Example:
graph = {'a': '$(b) $(c)', 'b': 'hi', 'c': '$(b)'}
def GetEdges(node):
return re.findall(r'\$\(([^))]\)', graph[node])
print TopologicallySorted(graph.keys(), GetEdges)
==>
['a', 'c', b']
"""
get_edges = memoize(get_edges)
visited = set()
visiting = set()
ordered_nodes = []
def Visit(node):
if node in visiting:
raise CycleError(visiting)
if node in visited:
return
visited.add(node)
visiting.add(node)
for neighbor in get_edges(node):
Visit(neighbor)
visiting.remove(node)
ordered_nodes.insert(0, node)
for node in sorted(graph):
Visit(node)
return ordered_nodes
def CrossCompileRequested():
# TODO: figure out how to not build extra host objects in the
# non-cross-compile case when this is enabled, and enable unconditionally.
return (os.environ.get('GYP_CROSSCOMPILE') or
os.environ.get('AR_host') or
os.environ.get('CC_host') or
os.environ.get('CXX_host') or
os.environ.get('AR_target') or
os.environ.get('CC_target') or
os.environ.get('CXX_target'))
|
mit
|
[
3,
1898,
334,
67,
9,
6029,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
504,
636,
2443,
363,
492,
543,
63,
6242,
199,
199,
646,
5055,
199,
646,
7554,
199,
646,
570,
5730,
199,
646,
747,
14,
515,
199,
646,
295,
199,
646,
5549,
199,
646,
984,
421,
199,
3,
437,
13460,
11955,
9147,
7531,
14,
2779,
7171,
28511,
1536,
340,
314,
1249,
10621,
1133,
17092,
12,
199,
3,
16885,
1163,
298,
22959,
1674,
199,
533,
11955,
794,
8,
785,
304,
523,
347,
636,
826,
721,
277,
12,
2562,
304,
272,
291,
14,
1532,
275,
2562,
272,
291,
14,
1637,
275,
1052,
523,
347,
636,
1250,
721,
277,
12,
627,
589,
304,
272,
862,
26,
489,
372,
291,
14,
1637,
59,
589,
61,
272,
871,
4067,
26,
489,
754,
275,
291,
14,
1532,
2031,
589,
9,
489,
291,
14,
1637,
59,
589,
61,
275,
754,
489,
372,
754,
421,
199,
533,
18151,
8,
1726,
304,
523,
408,
547,
1021,
6144,
376,
1125,
12,
1314,
365,
370,
506,
26568,
523,
370,
314,
922,
14,
221,
710,
2446,
2397,
2376,
911,
8579,
436,
2929,
642,
14,
523,
408,
523,
986,
421,
199,
318,
2186,
8310,
8,
69,
12,
1499,
304,
523,
408,
8310,
282,
1245,
370,
314,
1627,
1919,
1159,
1245,
1041,
523,
340,
440,
325,
14,
589,
26,
272,
325,
14,
589,
275,
334,
1328,
4258,
523,
916,
822,
8,
69,
14,
589,
9,
508,
413,
26,
272,
325,
14,
589,
275,
334,
495,
8,
69,
14,
589,
59,
16,
566,
435,
283,
283,
435,
1499,
4258,
523,
587,
26,
272,
325,
14,
589,
275,
334,
495,
8,
69,
14,
589,
59,
16,
566,
435,
283,
283,
435,
1499,
4258,
435,
325,
14,
589,
59,
17,
2938,
421,
199,
318,
6668,
23279,
14126,
8,
1375,
12,
12313,
63,
513,
304,
523,
408,
523,
9138,
282,
769,
402,
12313,
4545,
12,
372,
314,
12313,
4545,
367,
314,
523,
2013,
1204,
1375,
18257,
523,
408,
523,
372,
359,
84,
367,
307,
315,
12313,
63,
513,
340,
6077,
30663,
8,
84,
2788,
17,
61,
508,
1347,
61,
421,
199,
318,
6077,
30663,
8,
1375,
304,
523,
327,
11740,
83,
282,
12313,
1347,
1901,
282,
1900,
570,
12,
1347,
536,
436,
20070,
14,
819,
327,
6944,
26,
519,
1294,
365,
1202,
370,
2153,
16902,
4767,
314,
5417,
12912,
8082,
9432,
14,
523,
1347,
63,
1294,
275,
1347,
14,
13490,
16451,
413,
9,
523,
340,
822,
8,
1375,
63,
1294,
9,
508,
499,
26,
272,
359,
1506,
63,
493,
12,
1347,
61,
275,
1347,
63,
1294,
523,
587,
26,
272,
1900,
63,
493,
275,
488,
819,
1347,
63,
1294,
275,
1347,
14,
13490,
7863,
297,
413,
9,
523,
340,
822,
8,
1375,
63,
1294,
9,
508,
499,
26,
272,
359,
1375,
12,
20070,
61,
275,
1347,
63,
1294,
523,
587,
26,
272,
20070,
275,
488,
819,
372,
359,
1506,
63,
493,
12,
1347,
12,
20070,
61,
421,
199,
318,
31096,
4277,
8,
1506,
63,
493,
12,
1347,
12,
20070,
304,
523,
327,
961,
805,
32253,
282,
1347,
1901,
282,
11358,
1824,
26,
523,
327,
446,
282,
9999,
3247,
1900,
570,
12,
1902,
3679,
503,
3847,
370,
314,
1453,
523,
327,
2082,
523,
327,
446,
282,
1347,
536,
523,
327,
446,
282,
20070,
523,
327,
523,
327,
1900,
63,
493,
365,
314,
570,
3847,
370,
1314,
283,
1375,
7,
365,
3247,
14,
523,
327,
1347,
365,
314,
12313,
1347,
14,
523,
327,
20070,
365,
314,
849,
20070,
367,
626,
1347,
14,
523,
359,
6751,
63,
1506,
63,
493,
12,
1347,
12,
4565,
63,
12081,
61,
275,
6077,
30663,
8,
1375,
9,
819,
340,
4565,
63,
1506,
63,
493,
26,
272,
340,
1900,
63,
493,
26,
489,
327,
982,
282,
3847,
931,
12,
4565,
63,
1506,
63,
493,
365,
3847,
370,
314,
2082,
489,
327,
3035,
1900,
63,
493,
14,
221,
982,
1900,
63,
493,
365,
440,
315,
314,
1453,
2082,
12,
489,
327,
4565,
63,
1506,
63,
493,
365,
440,
282,
18025,
931,
465,
13,
374,
14,
221,
31096,
652,
701,
489,
327,
6421,
1337,
652,
465,
3847,
370,
1900,
63,
493,
14,
221,
982,
4565,
63,
1506,
63,
493,
365,
489,
327,
3679,
12,
652,
365,
18025,
465,
282,
931,
15270,
402,
314,
1453,
2082,
12,
489,
327,
436,
747,
14,
515,
14,
904,
911,
372,
652,
465,
13,
374,
14,
489,
1900,
63,
493,
275,
747,
14,
515,
14,
9267,
8,
736,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
8,
1506,
63,
493,
395,
1740,
4565,
63,
1506,
63,
493,
430,
489,
327,
28876,
334,
475,
2429,
5560,
2839,
24272,
6525,
395,
1852,
652,
3847,
370,
8288,
9,
489,
340,
440,
747,
14,
515,
14,
17896,
8,
1506,
63,
493,
304,
267,
1900,
63,
493,
275,
22419,
2042,
8,
1506,
63,
493,
12,
20093,
272,
587,
26,
489,
1900,
63,
493,
275,
4565,
63,
1506,
63,
493,
819,
340,
4565,
63,
12081,
26,
272,
20070,
275,
4565,
63,
12081,
819,
372,
359,
1506,
63,
493,
12,
1347,
12,
20070,
61,
421,
199,
318,
6516,
1173,
8,
5836,
63,
11661,
63,
1375,
304,
523,
327,
12892,
83,
314,
1900,
570,
687,
314,
9999,
12313,
1347,
14,
523,
372,
6077,
30663,
8,
5836,
63,
11661,
63,
1375,
2788,
16,
61,
421,
199,
318,
2372,
23027,
21860,
8,
1391,
63,
513,
12,
849,
304,
523,
408,
20926,
1536,
282,
790,
315,
314,
3734,
12,
543,
9567,
370,
13851,
2883,
523,
436,
3753,
32039,
1771,
370,
282,
849,
574,
1041,
523,
367,
2729,
315,
2729,
63,
513,
26,
272,
340,
2729,
315,
747,
14,
2314,
26,
489,
372,
747,
14,
2314,
59,
1391,
61,
523,
372,
849,
421,
199,
318,
19933,
4541,
4277,
8,
1506,
63,
493,
12,
1347,
12,
20070,
304,
523,
327,
298,
23279,
2,
4910,
314,
570,
626,
282,
1347,
1990,
3247,
315,
436,
314,
1347,
523,
327,
536,
12,
11673,
701,
282,
18307,
12,
4739,
379,
701,
282,
327,
436,
314,
20070,
536,
26,
523,
327,
1182,
515,
15,
475,
15,
493,
14,
6179,
26,
1375,
63,
354,
3
] |
[
1898,
334,
67,
9,
6029,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
504,
636,
2443,
363,
492,
543,
63,
6242,
199,
199,
646,
5055,
199,
646,
7554,
199,
646,
570,
5730,
199,
646,
747,
14,
515,
199,
646,
295,
199,
646,
5549,
199,
646,
984,
421,
199,
3,
437,
13460,
11955,
9147,
7531,
14,
2779,
7171,
28511,
1536,
340,
314,
1249,
10621,
1133,
17092,
12,
199,
3,
16885,
1163,
298,
22959,
1674,
199,
533,
11955,
794,
8,
785,
304,
523,
347,
636,
826,
721,
277,
12,
2562,
304,
272,
291,
14,
1532,
275,
2562,
272,
291,
14,
1637,
275,
1052,
523,
347,
636,
1250,
721,
277,
12,
627,
589,
304,
272,
862,
26,
489,
372,
291,
14,
1637,
59,
589,
61,
272,
871,
4067,
26,
489,
754,
275,
291,
14,
1532,
2031,
589,
9,
489,
291,
14,
1637,
59,
589,
61,
275,
754,
489,
372,
754,
421,
199,
533,
18151,
8,
1726,
304,
523,
408,
547,
1021,
6144,
376,
1125,
12,
1314,
365,
370,
506,
26568,
523,
370,
314,
922,
14,
221,
710,
2446,
2397,
2376,
911,
8579,
436,
2929,
642,
14,
523,
408,
523,
986,
421,
199,
318,
2186,
8310,
8,
69,
12,
1499,
304,
523,
408,
8310,
282,
1245,
370,
314,
1627,
1919,
1159,
1245,
1041,
523,
340,
440,
325,
14,
589,
26,
272,
325,
14,
589,
275,
334,
1328,
4258,
523,
916,
822,
8,
69,
14,
589,
9,
508,
413,
26,
272,
325,
14,
589,
275,
334,
495,
8,
69,
14,
589,
59,
16,
566,
435,
283,
283,
435,
1499,
4258,
523,
587,
26,
272,
325,
14,
589,
275,
334,
495,
8,
69,
14,
589,
59,
16,
566,
435,
283,
283,
435,
1499,
4258,
435,
325,
14,
589,
59,
17,
2938,
421,
199,
318,
6668,
23279,
14126,
8,
1375,
12,
12313,
63,
513,
304,
523,
408,
523,
9138,
282,
769,
402,
12313,
4545,
12,
372,
314,
12313,
4545,
367,
314,
523,
2013,
1204,
1375,
18257,
523,
408,
523,
372,
359,
84,
367,
307,
315,
12313,
63,
513,
340,
6077,
30663,
8,
84,
2788,
17,
61,
508,
1347,
61,
421,
199,
318,
6077,
30663,
8,
1375,
304,
523,
327,
11740,
83,
282,
12313,
1347,
1901,
282,
1900,
570,
12,
1347,
536,
436,
20070,
14,
819,
327,
6944,
26,
519,
1294,
365,
1202,
370,
2153,
16902,
4767,
314,
5417,
12912,
8082,
9432,
14,
523,
1347,
63,
1294,
275,
1347,
14,
13490,
16451,
413,
9,
523,
340,
822,
8,
1375,
63,
1294,
9,
508,
499,
26,
272,
359,
1506,
63,
493,
12,
1347,
61,
275,
1347,
63,
1294,
523,
587,
26,
272,
1900,
63,
493,
275,
488,
819,
1347,
63,
1294,
275,
1347,
14,
13490,
7863,
297,
413,
9,
523,
340,
822,
8,
1375,
63,
1294,
9,
508,
499,
26,
272,
359,
1375,
12,
20070,
61,
275,
1347,
63,
1294,
523,
587,
26,
272,
20070,
275,
488,
819,
372,
359,
1506,
63,
493,
12,
1347,
12,
20070,
61,
421,
199,
318,
31096,
4277,
8,
1506,
63,
493,
12,
1347,
12,
20070,
304,
523,
327,
961,
805,
32253,
282,
1347,
1901,
282,
11358,
1824,
26,
523,
327,
446,
282,
9999,
3247,
1900,
570,
12,
1902,
3679,
503,
3847,
370,
314,
1453,
523,
327,
2082,
523,
327,
446,
282,
1347,
536,
523,
327,
446,
282,
20070,
523,
327,
523,
327,
1900,
63,
493,
365,
314,
570,
3847,
370,
1314,
283,
1375,
7,
365,
3247,
14,
523,
327,
1347,
365,
314,
12313,
1347,
14,
523,
327,
20070,
365,
314,
849,
20070,
367,
626,
1347,
14,
523,
359,
6751,
63,
1506,
63,
493,
12,
1347,
12,
4565,
63,
12081,
61,
275,
6077,
30663,
8,
1375,
9,
819,
340,
4565,
63,
1506,
63,
493,
26,
272,
340,
1900,
63,
493,
26,
489,
327,
982,
282,
3847,
931,
12,
4565,
63,
1506,
63,
493,
365,
3847,
370,
314,
2082,
489,
327,
3035,
1900,
63,
493,
14,
221,
982,
1900,
63,
493,
365,
440,
315,
314,
1453,
2082,
12,
489,
327,
4565,
63,
1506,
63,
493,
365,
440,
282,
18025,
931,
465,
13,
374,
14,
221,
31096,
652,
701,
489,
327,
6421,
1337,
652,
465,
3847,
370,
1900,
63,
493,
14,
221,
982,
4565,
63,
1506,
63,
493,
365,
489,
327,
3679,
12,
652,
365,
18025,
465,
282,
931,
15270,
402,
314,
1453,
2082,
12,
489,
327,
436,
747,
14,
515,
14,
904,
911,
372,
652,
465,
13,
374,
14,
489,
1900,
63,
493,
275,
747,
14,
515,
14,
9267,
8,
736,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
8,
1506,
63,
493,
395,
1740,
4565,
63,
1506,
63,
493,
430,
489,
327,
28876,
334,
475,
2429,
5560,
2839,
24272,
6525,
395,
1852,
652,
3847,
370,
8288,
9,
489,
340,
440,
747,
14,
515,
14,
17896,
8,
1506,
63,
493,
304,
267,
1900,
63,
493,
275,
22419,
2042,
8,
1506,
63,
493,
12,
20093,
272,
587,
26,
489,
1900,
63,
493,
275,
4565,
63,
1506,
63,
493,
819,
340,
4565,
63,
12081,
26,
272,
20070,
275,
4565,
63,
12081,
819,
372,
359,
1506,
63,
493,
12,
1347,
12,
20070,
61,
421,
199,
318,
6516,
1173,
8,
5836,
63,
11661,
63,
1375,
304,
523,
327,
12892,
83,
314,
1900,
570,
687,
314,
9999,
12313,
1347,
14,
523,
372,
6077,
30663,
8,
5836,
63,
11661,
63,
1375,
2788,
16,
61,
421,
199,
318,
2372,
23027,
21860,
8,
1391,
63,
513,
12,
849,
304,
523,
408,
20926,
1536,
282,
790,
315,
314,
3734,
12,
543,
9567,
370,
13851,
2883,
523,
436,
3753,
32039,
1771,
370,
282,
849,
574,
1041,
523,
367,
2729,
315,
2729,
63,
513,
26,
272,
340,
2729,
315,
747,
14,
2314,
26,
489,
372,
747,
14,
2314,
59,
1391,
61,
523,
372,
849,
421,
199,
318,
19933,
4541,
4277,
8,
1506,
63,
493,
12,
1347,
12,
20070,
304,
523,
327,
298,
23279,
2,
4910,
314,
570,
626,
282,
1347,
1990,
3247,
315,
436,
314,
1347,
523,
327,
536,
12,
11673,
701,
282,
18307,
12,
4739,
379,
701,
282,
327,
436,
314,
20070,
536,
26,
523,
327,
1182,
515,
15,
475,
15,
493,
14,
6179,
26,
1375,
63,
354,
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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
agogear/python-1
|
renzongxian/0010/0010.py
|
40
|
1168
|
# Source:https://github.com/Show-Me-the-Code/show-me-the-code
# Author:renzongxian
# Date:2014-12-21
# Python 3.4
"""
第 0010 题:使用 Python 生成字母验证码图片
"""
from PIL import Image, ImageDraw, ImageFont
import string
import random
def generate_authenticode():
# Generate random letters
letters = ''.join([random.choice(string.ascii_letters) for i in range(4)])
# Set the size of the image
width = 100
height = 40
# Generate an image
im = Image.new("RGB", (width, height), (255, 255, 255))
# Draw letters on the image
dr = ImageDraw.Draw(im)
font = ImageFont.truetype("arial.ttf", 30)
for i in range(4):
dr.text((5+i*20, 5), letters[i], (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)), font)
del dr
# Change the background color
for x in range(width):
for y in range(height):
if im.getpixel((x, y)) == (255, 255, 255):
im.putpixel((x, y), (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)))
# Save the image
im.save('t1.png')
if __name__ == "__main__":
generate_authenticode()
|
mit
|
[
3,
5800,
26,
2859,
921,
5031,
14,
957,
15,
6824,
13,
1352,
13,
1589,
13,
3034,
15,
2384,
13,
278,
13,
1589,
13,
600,
199,
3,
6529,
26,
828,
90,
951,
88,
5653,
199,
3,
6148,
26,
7280,
13,
713,
13,
2025,
199,
3,
2018,
650,
14,
20,
199,
199,
624,
199,
199,
25238,
106,
378,
9523,
10469,
96,
247,
25742,
30026,
2018,
221,
29319,
16888,
26032,
28285,
236,
166,
104,
235,
20886,
8967,
14339,
123,
19431,
230,
199,
199,
624,
199,
199,
504,
14937,
492,
6047,
12,
6047,
9654,
12,
6047,
6986,
199,
646,
1059,
199,
646,
2196,
421,
199,
318,
3550,
63,
1178,
287,
280,
600,
837,
272,
327,
7958,
2196,
14435,
272,
14435,
275,
6522,
904,
779,
2355,
14,
5095,
8,
875,
14,
4371,
63,
16415,
9,
367,
284,
315,
1425,
8,
20,
3948,
339,
327,
2494,
314,
1568,
402,
314,
1834,
272,
3462,
275,
2948,
272,
4569,
275,
6335,
339,
327,
7958,
376,
1834,
272,
3416,
275,
6047,
14,
1222,
480,
12067,
401,
334,
2063,
12,
4569,
395,
334,
2299,
12,
5450,
12,
5450,
430,
339,
327,
17813,
14435,
641,
314,
1834,
272,
16642,
275,
6047,
9654,
14,
9654,
8,
1017,
9,
272,
5023,
275,
6047,
6986,
14,
2052,
466,
480,
759,
279,
14,
32264,
401,
4233,
9,
272,
367,
284,
315,
1425,
8,
20,
304,
267,
16642,
14,
505,
1332,
21,
11,
73,
10,
1165,
12,
959,
395,
14435,
59,
73,
467,
334,
2355,
14,
8393,
8,
16,
12,
5450,
395,
2196,
14,
8393,
8,
16,
12,
5450,
395,
2196,
14,
8393,
8,
16,
12,
5450,
1826,
5023,
9,
272,
2150,
16642,
339,
327,
7743,
314,
8020,
3164,
272,
367,
671,
315,
1425,
8,
2063,
304,
267,
367,
612,
315,
1425,
8,
3333,
304,
288,
340,
3416,
14,
362,
8435,
1332,
88,
12,
612,
430,
508,
334,
2299,
12,
5450,
12,
5450,
304,
355,
3416,
14,
524,
8435,
1332,
88,
12,
612,
395,
334,
2355,
14,
8393,
8,
16,
12,
5450,
395,
2196,
14,
8393,
8,
16,
12,
5450,
395,
2196,
14,
8393,
8,
16,
12,
5450,
1724,
339,
327,
11063,
314,
1834,
272,
3416,
14,
2117,
360,
84,
17,
14,
4524,
358,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
3550,
63,
1178,
287,
280,
600,
342,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
5800,
26,
2859,
921,
5031,
14,
957,
15,
6824,
13,
1352,
13,
1589,
13,
3034,
15,
2384,
13,
278,
13,
1589,
13,
600,
199,
3,
6529,
26,
828,
90,
951,
88,
5653,
199,
3,
6148,
26,
7280,
13,
713,
13,
2025,
199,
3,
2018,
650,
14,
20,
199,
199,
624,
199,
199,
25238,
106,
378,
9523,
10469,
96,
247,
25742,
30026,
2018,
221,
29319,
16888,
26032,
28285,
236,
166,
104,
235,
20886,
8967,
14339,
123,
19431,
230,
199,
199,
624,
199,
199,
504,
14937,
492,
6047,
12,
6047,
9654,
12,
6047,
6986,
199,
646,
1059,
199,
646,
2196,
421,
199,
318,
3550,
63,
1178,
287,
280,
600,
837,
272,
327,
7958,
2196,
14435,
272,
14435,
275,
6522,
904,
779,
2355,
14,
5095,
8,
875,
14,
4371,
63,
16415,
9,
367,
284,
315,
1425,
8,
20,
3948,
339,
327,
2494,
314,
1568,
402,
314,
1834,
272,
3462,
275,
2948,
272,
4569,
275,
6335,
339,
327,
7958,
376,
1834,
272,
3416,
275,
6047,
14,
1222,
480,
12067,
401,
334,
2063,
12,
4569,
395,
334,
2299,
12,
5450,
12,
5450,
430,
339,
327,
17813,
14435,
641,
314,
1834,
272,
16642,
275,
6047,
9654,
14,
9654,
8,
1017,
9,
272,
5023,
275,
6047,
6986,
14,
2052,
466,
480,
759,
279,
14,
32264,
401,
4233,
9,
272,
367,
284,
315,
1425,
8,
20,
304,
267,
16642,
14,
505,
1332,
21,
11,
73,
10,
1165,
12,
959,
395,
14435,
59,
73,
467,
334,
2355,
14,
8393,
8,
16,
12,
5450,
395,
2196,
14,
8393,
8,
16,
12,
5450,
395,
2196,
14,
8393,
8,
16,
12,
5450,
1826,
5023,
9,
272,
2150,
16642,
339,
327,
7743,
314,
8020,
3164,
272,
367,
671,
315,
1425,
8,
2063,
304,
267,
367,
612,
315,
1425,
8,
3333,
304,
288,
340,
3416,
14,
362,
8435,
1332,
88,
12,
612,
430,
508,
334,
2299,
12,
5450,
12,
5450,
304,
355,
3416,
14,
524,
8435,
1332,
88,
12,
612,
395,
334,
2355,
14,
8393,
8,
16,
12,
5450,
395,
2196,
14,
8393,
8,
16,
12,
5450,
395,
2196,
14,
8393,
8,
16,
12,
5450,
1724,
339,
327,
11063,
314,
1834,
272,
3416,
14,
2117,
360,
84,
17,
14,
4524,
358,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
3550,
63,
1178,
287,
280,
600,
342,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
sergiohs84/sdk
|
tests/sync_test_megasync.py
|
15
|
8754
|
"""
Application for testing syncing algorithm
(c) 2013-2014 by Mega Limited, Wellsford, New Zealand
This file is part of the MEGA SDK - Client Access Engine.
Applications using the MEGA API must present a valid application key
and comply with the the rules set forth in the Terms of Service.
The MEGA SDK 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.
@copyright Simplified (2-clause) BSD License.
You should have received a copy of the license along with this
program.
"""
import sys
import os
import time
import subprocess
from sync_test_base import get_random_str
from sync_test import SyncTest
from sync_test_app import SyncTestApp
import unittest
import xmlrunner
import logging
import argparse
import platform
class SyncTestMegaSyncApp(SyncTestApp):
"""
operates with megasync application
"""
def __init__(self, work_dir, remote_folder, delete_tmp_files=True, use_large_files=True):
"""
work_dir: a temporary folder to place generated files
remote_folder: a remote folder to sync
"""
self.megasync_ch_in = None
self.megasync_ch_out = None
self.local_mount_in = os.path.join(work_dir, "sync_in")
self.local_mount_out = os.path.join(work_dir, "sync_out")
self.work_dir = os.path.join(work_dir, "tmp")
self.remote_folder = remote_folder
# init base class
super(SyncTestMegaSyncApp, self).__init__(self.local_mount_in, self.local_mount_out, self.work_dir, delete_tmp_files, use_large_files)
try:
os.makedirs(self.local_mount_in)
except OSError:
pass
try:
os.makedirs(self.local_mount_out)
except OSError:
pass
try:
os.makedirs(self.work_dir)
except OSError:
pass
if not os.access(self.local_mount_in, os.W_OK | os.X_OK):
raise Exception("Not enough permissions to create / write to directory")
if not os.access(self.local_mount_out, os.W_OK | os.X_OK):
raise Exception("Not enough permissions to create / write to directory")
if not os.access(self.work_dir, os.W_OK | os.X_OK):
raise Exception("Not enough permissions to create / write to directory")
def start_megasync(self, local_folder, type_str):
"""
fork and launch "megasimplesync" application
local_folder: local folder to sync
"""
# launch megasimplesync
base_path = os.path.join(os.path.dirname(__file__), '..')
# the app is either in examples/ or in the project's root
if platform.system() == "Windows":
app_name = "megasimplesync.exe"
else:
app_name = "megasimplesync"
bin_path = os.path.join(base_path, "examples")
tmp = os.path.join(bin_path, app_name)
if not os.path.isfile(tmp) or not os.access(tmp, os.X_OK):
bin_path = os.path.join(base_path, "")
tmp = os.path.join(bin_path, app_name)
if not os.path.isfile(tmp) or not os.access(tmp, os.X_OK):
raise Exception("megasimplesync application is not found!")
pargs = [os.path.join(bin_path, app_name), local_folder, self.remote_folder]
output_fname = os.path.join(self.work_dir, "megasimplesync" + "_" + type_str + "_" + get_random_str() + ".log")
output_log = open(output_fname, "w")
logging.info("Launching cmd: \"%s\", log: \"%s\"" % (" ".join(pargs), output_fname))
try:
ch = subprocess.Popen(pargs, universal_newlines=True, stdout=output_log, stderr=subprocess.STDOUT, bufsize=1, shell=False, env=os.environ)
except OSError, e:
logging.error("Failed to launch megasimplesync process: %s" % e)
return None
return ch
def sync(self):
"""
TODO: wait for full synchronization
"""
time.sleep(5)
def start(self):
"""
prepare and run tests
"""
if os.environ.get('MEGA_EMAIL') is None or os.environ.get('MEGA_PWD') is None:
logging.error("Environment variables MEGA_EMAIL and MEGA_PWD are not set !")
return False
# start "in" instance
self.megasync_ch_in = self.start_megasync(self.local_mount_in, "in")
# pause
time.sleep(5)
# start "out" instance
self.megasync_ch_out = self.start_megasync(self.local_mount_out, "out")
# check both instances
if self.megasync_ch_in is None or self.megasync_ch_out is None:
return False
return True
def finish(self):
"""
kill megasync instances, remove temp folders
"""
self.sync()
# kill instances
for _ in range(0, 5):
if self.megasync_ch_in:
self.megasync_ch_in.terminate()
time.sleep(5)
else:
break
for _ in range(0, 5):
if self.megasync_ch_out:
self.megasync_ch_out.terminate()
time.sleep(5)
else:
break
def is_alive(self):
"""
return True if application instance is running
"""
if not self.megasync_ch_in or not self.megasync_ch_out:
return False
return self.megasync_ch_in.poll() is None and self.megasync_ch_out.poll() is None
def pause(self):
"""
pause application
"""
def unpause(self):
"""
unpause application
"""
if __name__ == "__main__":
parser = argparse.ArgumentParser(epilog="Please set MEGA_EMAIL and MEGA_PWD environment variables.")
parser.add_argument("--test1", help="test_create_delete_files", action="store_true")
parser.add_argument("--test2", help="test_create_rename_delete_files", action="store_true")
parser.add_argument("--test3", help="test_create_delete_dirs", action="store_true")
parser.add_argument("--test4", help="test_create_rename_delete_dirs", action="store_true")
parser.add_argument("--test5", help="test_sync_files_write", action="store_true")
parser.add_argument("--test6", help="test_local_operations", action="store_true")
parser.add_argument("--test7", help="test_update_mtime", action="store_true")
parser.add_argument("--test8", help="test_create_rename_delete_unicode_files_dirs", action="store_true")
parser.add_argument("-a", "--all", help="run all tests", action="store_true")
parser.add_argument("-b", "--basic", help="run basic, stable tests", action="store_true")
parser.add_argument("-d", "--debug", help="use debug output", action="store_true")
parser.add_argument("-l", "--large", help="use large files for testing", action="store_true")
parser.add_argument("-n", "--nodelete", help="Do not delete work files", action="store_false")
parser.add_argument("work_dir", help="local work directory")
parser.add_argument("sync_dir", help="remote directory for synchronization")
args = parser.parse_args()
if args.debug:
lvl = logging.DEBUG
# megasync will use verbose output
os.environ["MEGA_DEBUG"] = "2"
else:
lvl = logging.INFO
if args.all:
args.test1 = args.test2 = args.test3 = args.test4 = args.test5 = args.test6 = args.test7 = args.test8 = True
if args.basic:
args.test1 = args.test2 = args.test3 = args.test4 = True
# logging stuff, output to stdout
logging.StreamHandler(sys.stdout)
logging.basicConfig(format='[%(asctime)s] %(message)s', datefmt='%Y-%m-%d %H:%M:%S', level=lvl)
with SyncTestMegaSyncApp(args.work_dir, args.sync_dir, args.nodelete, args.large) as app:
suite = unittest.TestSuite()
if args.test1:
suite.addTest(SyncTest("test_create_delete_files", app))
if args.test2:
suite.addTest(SyncTest("test_create_rename_delete_files", app))
if args.test3:
suite.addTest(SyncTest("test_create_delete_dirs", app, ))
if args.test4:
suite.addTest(SyncTest("test_create_rename_delete_dirs", app))
if args.test5:
suite.addTest(SyncTest("test_sync_files_write", app))
if args.test6:
suite.addTest(SyncTest("test_local_operations", app))
if args.test7:
suite.addTest(SyncTest("test_update_mtime", app))
if args.test8:
suite.addTest(SyncTest("test_create_rename_delete_unicode_files_dirs", app))
testRunner = xmlrunner.XMLTestRunner(output='test-reports')
testRunner.run(suite)
|
bsd-2-clause
|
[
624,
199,
13515,
367,
5343,
7604,
316,
5563,
421,
334,
67,
9,
6171,
13,
7280,
701,
3194,
5294,
23954,
12,
644,
6840,
18090,
12,
7053,
3107,
69,
279,
460,
421,
961,
570,
365,
1777,
402,
314,
603,
4680,
33,
15610,
446,
6810,
11003,
12580,
14,
421,
24636,
1808,
314,
603,
4680,
33,
3261,
1471,
3451,
282,
1686,
4223,
790,
199,
436,
1013,
590,
543,
314,
314,
4713,
663,
367,
273,
315,
314,
13861,
706,
402,
7591,
14,
421,
710,
603,
4680,
33,
15610,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
421,
768,
7307,
29094,
30200,
334,
18,
13,
8501,
9,
6289,
844,
14,
421,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
4190,
3180,
543,
642,
199,
2240,
14,
199,
624,
199,
199,
646,
984,
199,
646,
747,
199,
646,
900,
199,
646,
3873,
199,
504,
7604,
63,
396,
63,
1095,
492,
664,
63,
2355,
63,
495,
199,
504,
7604,
63,
396,
492,
22407,
774,
199,
504,
7604,
63,
396,
63,
571,
492,
22407,
774,
2640,
199,
646,
2882,
199,
646,
2748,
5933,
199,
646,
2050,
199,
646,
7534,
199,
646,
4298,
421,
199,
533,
22407,
774,
1352,
5294,
10878,
2640,
8,
10878,
774,
2640,
304,
272,
408,
272,
1758,
2335,
543,
562,
71,
4146,
4223,
272,
408,
272,
347,
636,
826,
721,
277,
12,
1736,
63,
694,
12,
3982,
63,
3741,
12,
3145,
63,
2791,
63,
1725,
29,
549,
12,
675,
63,
9629,
63,
1725,
29,
549,
304,
267,
408,
267,
1736,
63,
694,
26,
282,
7937,
4922,
370,
4192,
4046,
1584,
267,
3982,
63,
3741,
26,
282,
3982,
4922,
370,
7604,
267,
408,
398,
291,
14,
32177,
4146,
63,
335,
63,
262,
275,
488,
267,
291,
14,
32177,
4146,
63,
335,
63,
548,
275,
488,
398,
291,
14,
1832,
63,
3956,
63,
262,
275,
747,
14,
515,
14,
904,
8,
800,
63,
694,
12,
298,
5186,
63,
262,
531,
267,
291,
14,
1832,
63,
3956,
63,
548,
275,
747,
14,
515,
14,
904,
8,
800,
63,
694,
12,
298,
5186,
63,
548,
531,
398,
291,
14,
800,
63,
694,
275,
747,
14,
515,
14,
904,
8,
800,
63,
694,
12,
298,
2791,
531,
267,
291,
14,
3846,
63,
3741,
275,
3982,
63,
3741,
398,
327,
4205,
1300,
1021,
267,
1613,
8,
10878,
774,
1352,
5294,
10878,
2640,
12,
291,
2843,
826,
721,
277,
14,
1832,
63,
3956,
63,
262,
12,
291,
14,
1832,
63,
3956,
63,
548,
12,
291,
14,
800,
63,
694,
12,
3145,
63,
2791,
63,
1725,
12,
675,
63,
9629,
63,
1725,
9,
398,
862,
26,
288,
747,
14,
8347,
8,
277,
14,
1832,
63,
3956,
63,
262,
9,
267,
871,
6440,
26,
288,
986,
398,
862,
26,
288,
747,
14,
8347,
8,
277,
14,
1832,
63,
3956,
63,
548,
9,
267,
871,
6440,
26,
288,
986,
398,
862,
26,
288,
747,
14,
8347,
8,
277,
14,
800,
63,
694,
9,
267,
871,
6440,
26,
288,
986,
398,
340,
440,
747,
14,
2732,
8,
277,
14,
1832,
63,
3956,
63,
262,
12,
747,
14,
55,
63,
3593,
1204,
747,
14,
56,
63,
3593,
304,
288,
746,
2186,
480,
1763,
8321,
3443,
370,
1218,
1182,
2218,
370,
2082,
531,
398,
340,
440,
747,
14,
2732,
8,
277,
14,
1832,
63,
3956,
63,
548,
12,
747,
14,
55,
63,
3593,
1204,
747,
14,
56,
63,
3593,
304,
288,
746,
2186,
480,
1763,
8321,
3443,
370,
1218,
1182,
2218,
370,
2082,
531,
398,
340,
440,
747,
14,
2732,
8,
277,
14,
800,
63,
694,
12,
747,
14,
55,
63,
3593,
1204,
747,
14,
56,
63,
3593,
304,
288,
746,
2186,
480,
1763,
8321,
3443,
370,
1218,
1182,
2218,
370,
2082,
531,
339,
347,
1343,
63,
32177,
4146,
8,
277,
12,
2257,
63,
3741,
12,
730,
63,
495,
304,
267,
408,
267,
14926,
436,
10623,
298,
278,
24364,
1729,
5186,
2,
4223,
267,
2257,
63,
3741,
26,
2257,
4922,
370,
7604,
267,
408,
267,
327,
10623,
562,
24364,
1729,
5186,
267,
1300,
63,
515,
275,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
11541,
358,
398,
327,
314,
1145,
365,
1902,
315,
7251,
15,
503,
315,
314,
2199,
1159,
1738,
267,
340,
4298,
14,
2253,
342,
508,
298,
8647,
582,
288,
1145,
63,
354,
275,
298,
278,
24364,
1729,
5186,
14,
5803,
2,
267,
587,
26,
288,
1145,
63,
354,
275,
298,
278,
24364,
1729,
5186,
2,
267,
2517,
63,
515,
275,
747,
14,
515,
14,
904,
8,
1095,
63,
515,
12,
298,
8589,
531,
267,
3529,
275,
747,
14,
515,
14,
904,
8,
1393,
63,
515,
12,
1145,
63,
354,
9,
267,
340,
440,
747,
14,
515,
14,
6292,
8,
2791,
9,
503,
440,
747,
14,
2732,
8,
2791,
12,
747,
14,
56,
63,
3593,
304,
288,
2517,
63,
515,
275,
747,
14,
515,
14,
904,
8,
1095,
63,
515,
12,
6899,
288,
3529,
275,
747,
14,
515,
14,
904,
8,
1393,
63,
515,
12,
1145,
63,
354,
9,
288,
340,
440,
747,
14,
515,
14,
6292,
8,
2791,
9,
503,
440,
747,
14,
2732,
8,
2791,
12,
747,
14,
56,
63,
3593,
304,
355,
746,
2186,
480,
278,
24364,
1729,
5186,
4223,
365,
440,
1911,
9124,
398,
299,
589,
275,
359,
736,
14,
515,
14,
904,
8,
1393,
63,
515,
12,
1145,
63,
354,
395,
2257,
63,
3741,
12,
291,
14,
3846,
63,
3741,
61,
267,
1072,
63,
5252,
275,
747,
14,
515,
14,
904,
8,
277,
14,
800,
63,
694,
12,
298,
278,
24364,
1729,
5186,
2,
435,
14220,
435,
730,
63,
495,
435,
14220,
435,
664,
63,
2355,
63,
495,
342,
435,
3680,
793,
531,
267,
1072,
63,
793,
275,
1551,
8,
1199,
63,
5252,
12,
298,
87,
531,
398,
2050,
14,
815,
480,
18543,
316,
2088,
26,
18321,
83,
20756,
943,
26,
18321,
83,
18781,
450,
1689,
3680,
904,
8,
462,
458,
395,
1072,
63,
5252,
430,
398,
862,
26,
288,
682,
275,
3873,
14,
7942,
8,
462,
458,
12,
17508,
63,
13839,
29,
549,
12,
3839,
29,
1199,
63,
793,
12,
4635,
29,
5781,
14,
13850
] |
[
199,
13515,
367,
5343,
7604,
316,
5563,
421,
334,
67,
9,
6171,
13,
7280,
701,
3194,
5294,
23954,
12,
644,
6840,
18090,
12,
7053,
3107,
69,
279,
460,
421,
961,
570,
365,
1777,
402,
314,
603,
4680,
33,
15610,
446,
6810,
11003,
12580,
14,
421,
24636,
1808,
314,
603,
4680,
33,
3261,
1471,
3451,
282,
1686,
4223,
790,
199,
436,
1013,
590,
543,
314,
314,
4713,
663,
367,
273,
315,
314,
13861,
706,
402,
7591,
14,
421,
710,
603,
4680,
33,
15610,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
421,
768,
7307,
29094,
30200,
334,
18,
13,
8501,
9,
6289,
844,
14,
421,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
4190,
3180,
543,
642,
199,
2240,
14,
199,
624,
199,
199,
646,
984,
199,
646,
747,
199,
646,
900,
199,
646,
3873,
199,
504,
7604,
63,
396,
63,
1095,
492,
664,
63,
2355,
63,
495,
199,
504,
7604,
63,
396,
492,
22407,
774,
199,
504,
7604,
63,
396,
63,
571,
492,
22407,
774,
2640,
199,
646,
2882,
199,
646,
2748,
5933,
199,
646,
2050,
199,
646,
7534,
199,
646,
4298,
421,
199,
533,
22407,
774,
1352,
5294,
10878,
2640,
8,
10878,
774,
2640,
304,
272,
408,
272,
1758,
2335,
543,
562,
71,
4146,
4223,
272,
408,
272,
347,
636,
826,
721,
277,
12,
1736,
63,
694,
12,
3982,
63,
3741,
12,
3145,
63,
2791,
63,
1725,
29,
549,
12,
675,
63,
9629,
63,
1725,
29,
549,
304,
267,
408,
267,
1736,
63,
694,
26,
282,
7937,
4922,
370,
4192,
4046,
1584,
267,
3982,
63,
3741,
26,
282,
3982,
4922,
370,
7604,
267,
408,
398,
291,
14,
32177,
4146,
63,
335,
63,
262,
275,
488,
267,
291,
14,
32177,
4146,
63,
335,
63,
548,
275,
488,
398,
291,
14,
1832,
63,
3956,
63,
262,
275,
747,
14,
515,
14,
904,
8,
800,
63,
694,
12,
298,
5186,
63,
262,
531,
267,
291,
14,
1832,
63,
3956,
63,
548,
275,
747,
14,
515,
14,
904,
8,
800,
63,
694,
12,
298,
5186,
63,
548,
531,
398,
291,
14,
800,
63,
694,
275,
747,
14,
515,
14,
904,
8,
800,
63,
694,
12,
298,
2791,
531,
267,
291,
14,
3846,
63,
3741,
275,
3982,
63,
3741,
398,
327,
4205,
1300,
1021,
267,
1613,
8,
10878,
774,
1352,
5294,
10878,
2640,
12,
291,
2843,
826,
721,
277,
14,
1832,
63,
3956,
63,
262,
12,
291,
14,
1832,
63,
3956,
63,
548,
12,
291,
14,
800,
63,
694,
12,
3145,
63,
2791,
63,
1725,
12,
675,
63,
9629,
63,
1725,
9,
398,
862,
26,
288,
747,
14,
8347,
8,
277,
14,
1832,
63,
3956,
63,
262,
9,
267,
871,
6440,
26,
288,
986,
398,
862,
26,
288,
747,
14,
8347,
8,
277,
14,
1832,
63,
3956,
63,
548,
9,
267,
871,
6440,
26,
288,
986,
398,
862,
26,
288,
747,
14,
8347,
8,
277,
14,
800,
63,
694,
9,
267,
871,
6440,
26,
288,
986,
398,
340,
440,
747,
14,
2732,
8,
277,
14,
1832,
63,
3956,
63,
262,
12,
747,
14,
55,
63,
3593,
1204,
747,
14,
56,
63,
3593,
304,
288,
746,
2186,
480,
1763,
8321,
3443,
370,
1218,
1182,
2218,
370,
2082,
531,
398,
340,
440,
747,
14,
2732,
8,
277,
14,
1832,
63,
3956,
63,
548,
12,
747,
14,
55,
63,
3593,
1204,
747,
14,
56,
63,
3593,
304,
288,
746,
2186,
480,
1763,
8321,
3443,
370,
1218,
1182,
2218,
370,
2082,
531,
398,
340,
440,
747,
14,
2732,
8,
277,
14,
800,
63,
694,
12,
747,
14,
55,
63,
3593,
1204,
747,
14,
56,
63,
3593,
304,
288,
746,
2186,
480,
1763,
8321,
3443,
370,
1218,
1182,
2218,
370,
2082,
531,
339,
347,
1343,
63,
32177,
4146,
8,
277,
12,
2257,
63,
3741,
12,
730,
63,
495,
304,
267,
408,
267,
14926,
436,
10623,
298,
278,
24364,
1729,
5186,
2,
4223,
267,
2257,
63,
3741,
26,
2257,
4922,
370,
7604,
267,
408,
267,
327,
10623,
562,
24364,
1729,
5186,
267,
1300,
63,
515,
275,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
11541,
358,
398,
327,
314,
1145,
365,
1902,
315,
7251,
15,
503,
315,
314,
2199,
1159,
1738,
267,
340,
4298,
14,
2253,
342,
508,
298,
8647,
582,
288,
1145,
63,
354,
275,
298,
278,
24364,
1729,
5186,
14,
5803,
2,
267,
587,
26,
288,
1145,
63,
354,
275,
298,
278,
24364,
1729,
5186,
2,
267,
2517,
63,
515,
275,
747,
14,
515,
14,
904,
8,
1095,
63,
515,
12,
298,
8589,
531,
267,
3529,
275,
747,
14,
515,
14,
904,
8,
1393,
63,
515,
12,
1145,
63,
354,
9,
267,
340,
440,
747,
14,
515,
14,
6292,
8,
2791,
9,
503,
440,
747,
14,
2732,
8,
2791,
12,
747,
14,
56,
63,
3593,
304,
288,
2517,
63,
515,
275,
747,
14,
515,
14,
904,
8,
1095,
63,
515,
12,
6899,
288,
3529,
275,
747,
14,
515,
14,
904,
8,
1393,
63,
515,
12,
1145,
63,
354,
9,
288,
340,
440,
747,
14,
515,
14,
6292,
8,
2791,
9,
503,
440,
747,
14,
2732,
8,
2791,
12,
747,
14,
56,
63,
3593,
304,
355,
746,
2186,
480,
278,
24364,
1729,
5186,
4223,
365,
440,
1911,
9124,
398,
299,
589,
275,
359,
736,
14,
515,
14,
904,
8,
1393,
63,
515,
12,
1145,
63,
354,
395,
2257,
63,
3741,
12,
291,
14,
3846,
63,
3741,
61,
267,
1072,
63,
5252,
275,
747,
14,
515,
14,
904,
8,
277,
14,
800,
63,
694,
12,
298,
278,
24364,
1729,
5186,
2,
435,
14220,
435,
730,
63,
495,
435,
14220,
435,
664,
63,
2355,
63,
495,
342,
435,
3680,
793,
531,
267,
1072,
63,
793,
275,
1551,
8,
1199,
63,
5252,
12,
298,
87,
531,
398,
2050,
14,
815,
480,
18543,
316,
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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
] |
murdej/h2pws
|
h2pws.py
|
1
|
2618
|
import time
import BaseHTTPServer
from urlparse import urlparse, parse_qs
import subprocess
import base64
import qrcode
import qrcode.image.svg
import cStringIO
#1630-1800
HOST_NAME = 'localhost' # !!!REMEMBER TO CHANGE THIS!!!
PORT_NUMBER = 8000 # Maybe set this to 9000.
class MyHandler(BaseHTTPServer.BaseHTTPRequestHandler):
def do_HEAD(s):
s.send_response(200)
s.send_header("Content-type", "text/html")
s.end_headers()
def do_GET(s):
"""Respond to a GET request."""
s.send_response(200)
s.send_header("Content-type", "text/html")
s.end_headers()
s.wfile.write("<html><head><title></title></head>")
s.wfile.write("<body><p>Send html source by POST.</p>")
# s.wfile.write("<p>You accessed path: %s</p>" % s.path)
s.wfile.write("</body></html>")
def do_POST(s):
"""Respond to a POST request."""
s.send_response(200)
s.send_header("Content-type", "application/x-pdf")
s.end_headers()
# params
url_params = parse_qs(urlparse(s.path).query)
args = ["wkhtmltopdf"]
for n in [ 'orientation', 'page-size', 'margin-bottom', 'margin-left', 'margin-right', 'margin-top' ]:
if n in url_params:
args += [ '--' + n, url_params[n][0] ]
args += ["-", "-"]
print args
html = s.rfile.read(int(s.headers.getheader('content-length')))
# Replace "qr::xxxxxxxxxxxxxxxxx" to sql qr code
if "qr-to-svg" in url_params :
new_html = ''
pos = 0
while True:
begin_str = '"qr::'
pos_a = html.find(begin_str, pos)
if pos_a == -1: break
# copy text before
new_html += html[pos:pos_a]
# extract src of QR code
pos_a += len(begin_str)
pos_b = html.find('"', pos_a + 1)
qr_src = html[pos_a:pos_b]
print "qr:src='" + qr_src + "'"
# new_html += '[[' + qr_src + ']]'
factory = qrcode.image.svg.SvgPathImage
img = qrcode.make(qr_src, image_factory=factory)
output = cStringIO.StringIO()
img.save(output)
svgb = 'data:image/svg+xml;base64,' + base64.b64encode(output.getvalue())
output.close()
new_html += svgb
pos = pos_b
new_html += html[pos:]
html = new_html
p = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
p.stdin.write(html)
p.stdin.close()
s.wfile.write(p.stdout.read())
p.wait()
if __name__ == '__main__':
server_class = BaseHTTPServer.HTTPServer
httpd = server_class((HOST_NAME, PORT_NUMBER), MyHandler)
print time.asctime(), "Server Starts - %s:%s" % (HOST_NAME, PORT_NUMBER)
try:
httpd.serve_forever()
except KeyboardInterrupt:
pass
httpd.server_close()
print time.asctime(), "Server Stops - %s:%s" % (HOST_NAME, PORT_NUMBER)
|
gpl-2.0
|
[
646,
900,
199,
646,
3523,
14938,
199,
504,
7097,
492,
7097,
12,
2198,
63,
6177,
199,
646,
3873,
199,
646,
1300,
772,
221,
199,
646,
29757,
600,
199,
646,
29757,
600,
14,
1569,
14,
10273,
199,
646,
15073,
199,
199,
3,
975,
1216,
13,
1085,
383,
199,
199,
5449,
63,
2339,
275,
283,
5967,
7,
327,
221,
21512,
907,
26682,
2296,
6624,
9011,
5749,
21512,
199,
3657,
63,
9190,
275,
29855,
327,
23038,
663,
642,
370,
1749,
1493,
14,
421,
199,
533,
4932,
2461,
8,
1563,
14938,
14,
1563,
23518,
304,
4388,
198,
318,
886,
63,
5211,
8,
83,
304,
507,
198,
83,
14,
2254,
63,
1310,
8,
1840,
9,
507,
198,
83,
14,
2254,
63,
1291,
480,
2714,
13,
466,
401,
298,
505,
15,
1360,
531,
507,
198,
83,
14,
500,
63,
2139,
342,
4388,
198,
318,
886,
63,
2970,
8,
83,
304,
507,
198,
624,
1322,
31717,
370,
282,
9576,
1056,
1041,
507,
198,
83,
14,
2254,
63,
1310,
8,
1840,
9,
507,
198,
83,
14,
2254,
63,
1291,
480,
2714,
13,
466,
401,
298,
505,
15,
1360,
531,
507,
198,
83,
14,
500,
63,
2139,
342,
507,
198,
83,
14,
18076,
14,
952,
6757,
1360,
2535,
2993,
2535,
1213,
2957,
1213,
2957,
2993,
9579,
507,
198,
83,
14,
18076,
14,
952,
6757,
2030,
2535,
80,
30,
6795,
3517,
1350,
701,
8761,
9758,
80,
9579,
507,
198,
3,
308,
14,
18076,
14,
952,
6757,
80,
30,
5556,
13810,
931,
26,
450,
83,
1108,
80,
4335,
450,
308,
14,
515,
9,
507,
198,
83,
14,
18076,
14,
952,
23790,
2030,
2957,
1360,
9579,
4388,
198,
318,
886,
63,
4030,
8,
83,
304,
507,
198,
624,
1322,
31717,
370,
282,
8761,
1056,
1041,
507,
198,
83,
14,
2254,
63,
1310,
8,
1840,
9,
507,
198,
83,
14,
2254,
63,
1291,
480,
2714,
13,
466,
401,
298,
3578,
15,
88,
13,
5607,
531,
507,
198,
83,
14,
500,
63,
2139,
342,
9068,
198,
3,
1862,
507,
198,
633,
63,
1162,
275,
2198,
63,
6177,
8,
10290,
8,
83,
14,
515,
680,
1131,
9,
507,
198,
589,
275,
2097,
14947,
1360,
2119,
1587,
937,
507,
198,
509,
302,
315,
359,
283,
17001,
297,
283,
1606,
13,
890,
297,
283,
9650,
13,
8305,
297,
283,
9650,
13,
3039,
297,
283,
9650,
13,
1019,
297,
283,
9650,
13,
2119,
7,
16246,
686,
198,
692,
302,
315,
1166,
63,
1162,
26,
1585,
198,
589,
847,
359,
2850,
7,
435,
302,
12,
1166,
63,
1162,
59,
78,
1527,
16,
61,
1622,
507,
198,
589,
847,
16984,
401,
3905,
937,
507,
198,
1361,
1249,
507,
198,
1360,
275,
308,
14,
23830,
14,
739,
8,
442,
8,
83,
14,
2139,
14,
19958,
360,
1317,
13,
1267,
7058,
507,
198,
3,
14402,
298,
16596,
447,
16754,
88,
2,
370,
3875,
29757,
1233,
507,
198,
692,
298,
16596,
13,
475,
13,
10273,
2,
315,
1166,
63,
1162,
520,
686,
198,
1222,
63,
1360,
275,
2125,
686,
198,
1712,
275,
378,
686,
198,
6710,
715,
26,
1585,
198,
5037,
63,
495,
275,
5522,
16596,
447,
7,
1585,
198,
1712,
63,
65,
275,
3517,
14,
1623,
8,
5037,
63,
495,
12,
2086,
9,
1585,
198,
692,
2086,
63,
65,
508,
446,
17,
26,
2059,
1585,
198,
3,
1331,
1318,
2544,
1585,
198,
1222,
63,
1360,
847,
3517,
59,
1712,
26,
1712,
63,
65,
61,
1585,
198,
3,
5536,
2928,
402,
1413,
50,
1233,
1585,
198,
1712,
63,
65,
847,
822,
8,
5037,
63,
495,
9,
1585,
198,
1712,
63,
66,
275,
3517,
14,
1623,
20630,
2086,
63,
65,
435,
413,
9,
1585,
198,
16596,
63,
2164,
275,
3517,
59,
1712,
63,
65,
26,
1712,
63,
66,
61,
1585,
198,
1361,
298,
16596,
26,
2164,
534,
2,
435,
29757,
63,
2164,
435,
21673,
16737,
198,
3,
892,
63,
1360,
847,
6730,
459,
435,
29757,
63,
2164,
435,
283,
2677,
7,
1585,
198,
3702,
275,
29757,
600,
14,
1569,
14,
10273,
14,
51,
10929,
2042,
3491,
1585,
198,
4060,
275,
29757,
600,
14,
1875,
8,
16596,
63,
2164,
12,
1834,
63,
3702,
29,
3702,
9,
1585,
198,
1199,
275,
15073,
14,
6424,
342,
1585,
198,
4060,
14,
2117,
8,
1199,
9,
1585,
198,
2772,
4908,
275,
283,
576,
26,
1569,
15,
10273,
11,
1652,
27,
1095,
772,
2584,
435,
1300,
772,
14,
66,
772,
2143,
8,
1199,
14,
7150,
1012,
1585,
198,
1199,
14,
1600,
342,
1585,
198,
1222,
63,
1360,
847,
19291,
4908,
1585,
198,
1712,
275,
2086,
63,
66,
6319,
198,
1222,
63,
1360,
847,
3517,
59,
1712,
2938,
686,
198,
1360,
275,
892,
63,
1360,
2742,
198,
80,
275,
3873,
14,
7942,
8,
589,
12,
9009,
29,
5781,
14,
6089,
12,
3839,
29,
5781,
14,
6089,
9,
507,
198,
80,
14,
6626,
14,
952,
8,
1360,
9,
507,
198,
80,
14,
6626,
14,
1600,
342,
9068,
198,
83,
14,
18076,
14,
952,
8,
80,
14,
2703,
14,
739,
1012,
507,
198,
80,
14,
2573,
342,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
199,
198,
1000,
63,
533,
275,
3523,
14938,
14,
14938,
199,
198,
21594,
275,
1654,
63,
533,
1332,
5449,
63,
2339,
12,
25562,
63,
9190,
395,
4932,
2461,
9,
199,
198,
1361,
900,
14,
18331,
1062,
298,
3120,
7707,
83,
446,
450,
83,
2689,
83,
2,
450,
334,
5449,
63,
2339,
12,
25562,
63,
9190,
9,
199,
198,
893,
26,
507,
198,
21594,
14,
4909,
63,
21327,
342,
199,
198,
2590,
13483,
26,
507,
198,
1529,
199,
198,
21594,
14,
1000,
63,
1600,
342,
199,
198,
1361,
900,
14,
18331,
1062,
298,
3120,
1933,
1483,
446,
450,
83,
2689,
83,
2,
450,
334,
5449,
63,
2339,
12,
25562,
63,
9190,
9,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
900,
199,
646,
3523,
14938,
199,
504,
7097,
492,
7097,
12,
2198,
63,
6177,
199,
646,
3873,
199,
646,
1300,
772,
221,
199,
646,
29757,
600,
199,
646,
29757,
600,
14,
1569,
14,
10273,
199,
646,
15073,
199,
199,
3,
975,
1216,
13,
1085,
383,
199,
199,
5449,
63,
2339,
275,
283,
5967,
7,
327,
221,
21512,
907,
26682,
2296,
6624,
9011,
5749,
21512,
199,
3657,
63,
9190,
275,
29855,
327,
23038,
663,
642,
370,
1749,
1493,
14,
421,
199,
533,
4932,
2461,
8,
1563,
14938,
14,
1563,
23518,
304,
4388,
198,
318,
886,
63,
5211,
8,
83,
304,
507,
198,
83,
14,
2254,
63,
1310,
8,
1840,
9,
507,
198,
83,
14,
2254,
63,
1291,
480,
2714,
13,
466,
401,
298,
505,
15,
1360,
531,
507,
198,
83,
14,
500,
63,
2139,
342,
4388,
198,
318,
886,
63,
2970,
8,
83,
304,
507,
198,
624,
1322,
31717,
370,
282,
9576,
1056,
1041,
507,
198,
83,
14,
2254,
63,
1310,
8,
1840,
9,
507,
198,
83,
14,
2254,
63,
1291,
480,
2714,
13,
466,
401,
298,
505,
15,
1360,
531,
507,
198,
83,
14,
500,
63,
2139,
342,
507,
198,
83,
14,
18076,
14,
952,
6757,
1360,
2535,
2993,
2535,
1213,
2957,
1213,
2957,
2993,
9579,
507,
198,
83,
14,
18076,
14,
952,
6757,
2030,
2535,
80,
30,
6795,
3517,
1350,
701,
8761,
9758,
80,
9579,
507,
198,
3,
308,
14,
18076,
14,
952,
6757,
80,
30,
5556,
13810,
931,
26,
450,
83,
1108,
80,
4335,
450,
308,
14,
515,
9,
507,
198,
83,
14,
18076,
14,
952,
23790,
2030,
2957,
1360,
9579,
4388,
198,
318,
886,
63,
4030,
8,
83,
304,
507,
198,
624,
1322,
31717,
370,
282,
8761,
1056,
1041,
507,
198,
83,
14,
2254,
63,
1310,
8,
1840,
9,
507,
198,
83,
14,
2254,
63,
1291,
480,
2714,
13,
466,
401,
298,
3578,
15,
88,
13,
5607,
531,
507,
198,
83,
14,
500,
63,
2139,
342,
9068,
198,
3,
1862,
507,
198,
633,
63,
1162,
275,
2198,
63,
6177,
8,
10290,
8,
83,
14,
515,
680,
1131,
9,
507,
198,
589,
275,
2097,
14947,
1360,
2119,
1587,
937,
507,
198,
509,
302,
315,
359,
283,
17001,
297,
283,
1606,
13,
890,
297,
283,
9650,
13,
8305,
297,
283,
9650,
13,
3039,
297,
283,
9650,
13,
1019,
297,
283,
9650,
13,
2119,
7,
16246,
686,
198,
692,
302,
315,
1166,
63,
1162,
26,
1585,
198,
589,
847,
359,
2850,
7,
435,
302,
12,
1166,
63,
1162,
59,
78,
1527,
16,
61,
1622,
507,
198,
589,
847,
16984,
401,
3905,
937,
507,
198,
1361,
1249,
507,
198,
1360,
275,
308,
14,
23830,
14,
739,
8,
442,
8,
83,
14,
2139,
14,
19958,
360,
1317,
13,
1267,
7058,
507,
198,
3,
14402,
298,
16596,
447,
16754,
88,
2,
370,
3875,
29757,
1233,
507,
198,
692,
298,
16596,
13,
475,
13,
10273,
2,
315,
1166,
63,
1162,
520,
686,
198,
1222,
63,
1360,
275,
2125,
686,
198,
1712,
275,
378,
686,
198,
6710,
715,
26,
1585,
198,
5037,
63,
495,
275,
5522,
16596,
447,
7,
1585,
198,
1712,
63,
65,
275,
3517,
14,
1623,
8,
5037,
63,
495,
12,
2086,
9,
1585,
198,
692,
2086,
63,
65,
508,
446,
17,
26,
2059,
1585,
198,
3,
1331,
1318,
2544,
1585,
198,
1222,
63,
1360,
847,
3517,
59,
1712,
26,
1712,
63,
65,
61,
1585,
198,
3,
5536,
2928,
402,
1413,
50,
1233,
1585,
198,
1712,
63,
65,
847,
822,
8,
5037,
63,
495,
9,
1585,
198,
1712,
63,
66,
275,
3517,
14,
1623,
20630,
2086,
63,
65,
435,
413,
9,
1585,
198,
16596,
63,
2164,
275,
3517,
59,
1712,
63,
65,
26,
1712,
63,
66,
61,
1585,
198,
1361,
298,
16596,
26,
2164,
534,
2,
435,
29757,
63,
2164,
435,
21673,
16737,
198,
3,
892,
63,
1360,
847,
6730,
459,
435,
29757,
63,
2164,
435,
283,
2677,
7,
1585,
198,
3702,
275,
29757,
600,
14,
1569,
14,
10273,
14,
51,
10929,
2042,
3491,
1585,
198,
4060,
275,
29757,
600,
14,
1875,
8,
16596,
63,
2164,
12,
1834,
63,
3702,
29,
3702,
9,
1585,
198,
1199,
275,
15073,
14,
6424,
342,
1585,
198,
4060,
14,
2117,
8,
1199,
9,
1585,
198,
2772,
4908,
275,
283,
576,
26,
1569,
15,
10273,
11,
1652,
27,
1095,
772,
2584,
435,
1300,
772,
14,
66,
772,
2143,
8,
1199,
14,
7150,
1012,
1585,
198,
1199,
14,
1600,
342,
1585,
198,
1222,
63,
1360,
847,
19291,
4908,
1585,
198,
1712,
275,
2086,
63,
66,
6319,
198,
1222,
63,
1360,
847,
3517,
59,
1712,
2938,
686,
198,
1360,
275,
892,
63,
1360,
2742,
198,
80,
275,
3873,
14,
7942,
8,
589,
12,
9009,
29,
5781,
14,
6089,
12,
3839,
29,
5781,
14,
6089,
9,
507,
198,
80,
14,
6626,
14,
952,
8,
1360,
9,
507,
198,
80,
14,
6626,
14,
1600,
342,
9068,
198,
83,
14,
18076,
14,
952,
8,
80,
14,
2703,
14,
739,
1012,
507,
198,
80,
14,
2573,
342,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
199,
198,
1000,
63,
533,
275,
3523,
14938,
14,
14938,
199,
198,
21594,
275,
1654,
63,
533,
1332,
5449,
63,
2339,
12,
25562,
63,
9190,
395,
4932,
2461,
9,
199,
198,
1361,
900,
14,
18331,
1062,
298,
3120,
7707,
83,
446,
450,
83,
2689,
83,
2,
450,
334,
5449,
63,
2339,
12,
25562,
63,
9190,
9,
199,
198,
893,
26,
507,
198,
21594,
14,
4909,
63,
21327,
342,
199,
198,
2590,
13483,
26,
507,
198,
1529,
199,
198,
21594,
14,
1000,
63,
1600,
342,
199,
198,
1361,
900,
14,
18331,
1062,
298,
3120,
1933,
1483,
446,
450,
83,
2689,
83,
2,
450,
334,
5449,
63,
2339,
12,
25562,
63,
9190,
9,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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,
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
] |
allanlei/babel
|
babel/localedata.py
|
136
|
6247
|
# -*- coding: utf-8 -*-
"""
babel.localedata
~~~~~~~~~~~~~~~~
Low-level locale data access.
:note: The `Locale` class, which uses this module under the hood, provides a
more convenient interface for accessing the locale data.
:copyright: (c) 2013 by the Babel Team.
:license: BSD, see LICENSE for more details.
"""
import os
import threading
from collections import MutableMapping
from babel._compat import pickle
_cache = {}
_cache_lock = threading.RLock()
_dirname = os.path.join(os.path.dirname(__file__), 'localedata')
def exists(name):
"""Check whether locale data is available for the given locale. Ther
return value is `True` if it exists, `False` otherwise.
:param name: the locale identifier string
"""
if name in _cache:
return True
return os.path.exists(os.path.join(_dirname, '%s.dat' % name))
def locale_identifiers():
"""Return a list of all locale identifiers for which locale data is
available.
.. versionadded:: 0.8.1
:return: a list of locale identifiers (strings)
"""
return [stem for stem, extension in [
os.path.splitext(filename) for filename in os.listdir(_dirname)
] if extension == '.dat' and stem != 'root']
def load(name, merge_inherited=True):
"""Load the locale data for the given locale.
The locale data is a dictionary that contains much of the data defined by
the Common Locale Data Repository (CLDR). This data is stored as a
collection of pickle files inside the ``babel`` package.
>>> d = load('en_US')
>>> d['languages']['sv']
u'Swedish'
Note that the results are cached, and subsequent requests for the same
locale return the same dictionary:
>>> d1 = load('en_US')
>>> d2 = load('en_US')
>>> d1 is d2
True
:param name: the locale identifier string (or "root")
:param merge_inherited: whether the inherited data should be merged into
the data of the requested locale
:raise `IOError`: if no locale data file is found for the given locale
identifer, or one of the locales it inherits from
"""
_cache_lock.acquire()
try:
data = _cache.get(name)
if not data:
# Load inherited data
if name == 'root' or not merge_inherited:
data = {}
else:
parts = name.split('_')
if len(parts) == 1:
parent = 'root'
else:
parent = '_'.join(parts[:-1])
data = load(parent).copy()
filename = os.path.join(_dirname, '%s.dat' % name)
fileobj = open(filename, 'rb')
try:
if name != 'root' and merge_inherited:
merge(data, pickle.load(fileobj))
else:
data = pickle.load(fileobj)
_cache[name] = data
finally:
fileobj.close()
return data
finally:
_cache_lock.release()
def merge(dict1, dict2):
"""Merge the data from `dict2` into the `dict1` dictionary, making copies
of nested dictionaries.
>>> d = {1: 'foo', 3: 'baz'}
>>> merge(d, {1: 'Foo', 2: 'Bar'})
>>> items = d.items(); items.sort(); items
[(1, 'Foo'), (2, 'Bar'), (3, 'baz')]
:param dict1: the dictionary to merge into
:param dict2: the dictionary containing the data that should be merged
"""
for key, val2 in dict2.items():
if val2 is not None:
val1 = dict1.get(key)
if isinstance(val2, dict):
if val1 is None:
val1 = {}
if isinstance(val1, Alias):
val1 = (val1, val2)
elif isinstance(val1, tuple):
alias, others = val1
others = others.copy()
merge(others, val2)
val1 = (alias, others)
else:
val1 = val1.copy()
merge(val1, val2)
else:
val1 = val2
dict1[key] = val1
class Alias(object):
"""Representation of an alias in the locale data.
An alias is a value that refers to some other part of the locale data,
as specified by the `keys`.
"""
def __init__(self, keys):
self.keys = tuple(keys)
def __repr__(self):
return '<%s %r>' % (type(self).__name__, self.keys)
def resolve(self, data):
"""Resolve the alias based on the given data.
This is done recursively, so if one alias resolves to a second alias,
that second alias will also be resolved.
:param data: the locale data
:type data: `dict`
"""
base = data
for key in self.keys:
data = data[key]
if isinstance(data, Alias):
data = data.resolve(base)
elif isinstance(data, tuple):
alias, others = data
data = alias.resolve(base)
return data
class LocaleDataDict(MutableMapping):
"""Dictionary wrapper that automatically resolves aliases to the actual
values.
"""
def __init__(self, data, base=None):
self._data = data
if base is None:
base = data
self.base = base
def __len__(self):
return len(self._data)
def __iter__(self):
return iter(self._data)
def __getitem__(self, key):
orig = val = self._data[key]
if isinstance(val, Alias): # resolve an alias
val = val.resolve(self.base)
if isinstance(val, tuple): # Merge a partial dict with an alias
alias, others = val
val = alias.resolve(self.base).copy()
merge(val, others)
if type(val) is dict: # Return a nested alias-resolving dict
val = LocaleDataDict(val, base=self.base)
if val is not orig:
self._data[key] = val
return val
def __setitem__(self, key, value):
self._data[key] = value
def __delitem__(self, key):
del self._data[key]
def copy(self):
return LocaleDataDict(self._data.copy(), base=self.base)
|
bsd-3-clause
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
29178,
14,
5508,
576,
272,
18294,
339,
21766,
13,
1896,
5867,
666,
2879,
14,
339,
520,
4610,
26,
710,
658,
20342,
64,
1021,
12,
1314,
4440,
642,
859,
1334,
314,
2636,
364,
12,
6571,
282,
1779,
1655,
22700,
3217,
367,
18549,
314,
5867,
666,
14,
339,
520,
7307,
26,
334,
67,
9,
6171,
701,
314,
699,
902,
11682,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
1655,
2436,
14,
199,
624,
199,
199,
646,
747,
199,
646,
5796,
199,
504,
5055,
492,
29396,
199,
199,
504,
29178,
423,
5819,
492,
5927,
421,
199,
63,
1637,
275,
1052,
199,
63,
1637,
63,
831,
275,
5796,
14,
30550,
342,
199,
63,
3475,
275,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
283,
5508,
576,
358,
421,
199,
318,
3495,
8,
354,
304,
272,
408,
1799,
3775,
5867,
666,
365,
2808,
367,
314,
1627,
5867,
14,
221,
377,
2523,
272,
372,
574,
365,
658,
549,
64,
340,
652,
3495,
12,
658,
797,
64,
4257,
14,
339,
520,
635,
536,
26,
314,
5867,
5148,
1059,
272,
408,
272,
340,
536,
315,
485,
1637,
26,
267,
372,
715,
272,
372,
747,
14,
515,
14,
2444,
8,
736,
14,
515,
14,
904,
1547,
3475,
12,
1543,
83,
14,
4616,
7,
450,
536,
430,
421,
199,
318,
5867,
63,
14227,
837,
272,
408,
1767,
282,
769,
402,
1006,
5867,
14154,
367,
1314,
5867,
666,
365,
272,
2808,
14,
339,
2508,
7445,
447,
378,
14,
24,
14,
17,
339,
520,
1107,
26,
282,
769,
402,
5867,
14154,
334,
5465,
9,
272,
408,
272,
372,
359,
18446,
367,
17408,
12,
3329,
315,
359,
267,
747,
14,
515,
14,
7973,
8,
1501,
9,
367,
1788,
315,
747,
14,
7374,
1547,
3475,
9,
272,
1622,
340,
3329,
508,
1987,
4616,
7,
436,
17408,
1137,
283,
1231,
418,
421,
199,
318,
2248,
8,
354,
12,
5389,
63,
17571,
29,
549,
304,
272,
408,
6200,
314,
5867,
666,
367,
314,
1627,
5867,
14,
339,
710,
5867,
666,
365,
282,
2600,
626,
3509,
8298,
402,
314,
666,
3247,
701,
272,
314,
13964,
28298,
3918,
24426,
334,
1981,
4564,
680,
961,
666,
365,
5489,
465,
282,
272,
3245,
402,
5927,
1584,
6272,
314,
1124,
66,
902,
1040,
2559,
14,
339,
1306,
366,
275,
2248,
360,
287,
63,
1668,
358,
272,
1306,
366,
459,
13209,
2545,
2772,
418,
272,
399,
7,
51,
1129,
29159,
7,
339,
3390,
626,
314,
2058,
787,
6328,
12,
436,
13372,
4145,
367,
314,
2011,
272,
5867,
372,
314,
2011,
2600,
26,
339,
1306,
366,
17,
275,
2248,
360,
287,
63,
1668,
358,
272,
1306,
366,
18,
275,
2248,
360,
287,
63,
1668,
358,
272,
1306,
366,
17,
365,
366,
18,
272,
715,
339,
520,
635,
536,
26,
314,
5867,
5148,
1059,
334,
269,
298,
1231,
531,
272,
520,
635,
5389,
63,
17571,
26,
3775,
314,
12623,
666,
1077,
506,
9545,
1901,
1169,
314,
666,
402,
314,
5839,
5867,
272,
520,
3730,
658,
13760,
8340,
340,
949,
5867,
666,
570,
365,
1911,
367,
314,
1627,
5867,
1993,
6120,
280,
2412,
12,
503,
1373,
402,
314,
24847,
652,
21592,
687,
272,
408,
272,
485,
1637,
63,
831,
14,
8174,
342,
272,
862,
26,
267,
666,
275,
485,
1637,
14,
362,
8,
354,
9,
267,
340,
440,
666,
26,
288,
327,
7190,
12623,
666,
288,
340,
536,
508,
283,
1231,
7,
503,
440,
5389,
63,
17571,
26,
355,
666,
275,
1052,
288,
587,
26,
355,
4184,
275,
536,
14,
1294,
26341,
355,
340,
822,
8,
4181,
9,
508,
413,
26,
490,
1676,
275,
283,
1231,
7,
355,
587,
26,
490,
1676,
275,
2513,
1370,
904,
8,
4181,
4439,
17,
566,
355,
666,
275,
2248,
8,
1708,
680,
1574,
342,
288,
1788,
275,
747,
14,
515,
14,
904,
1547,
3475,
12,
1543,
83,
14,
4616,
7,
450,
536,
9,
288,
11099,
275,
1551,
8,
1501,
12,
283,
4848,
358,
288,
862,
26,
355,
340,
536,
1137,
283,
1231,
7,
436,
5389,
63,
17571,
26,
490,
5389,
8,
576,
12,
5927,
14,
912,
8,
9234,
430,
355,
587,
26,
490,
666,
275,
5927,
14,
912,
8,
9234,
9,
355,
485,
1637,
59,
354,
61,
275,
666,
288,
3753,
26,
355,
11099,
14,
1600,
342,
267,
372,
666,
272,
3753,
26,
267,
485,
1637,
63,
831,
14,
3221,
342,
421,
199,
318,
5389,
8,
807,
17,
12,
1211,
18,
304,
272,
408,
11359,
314,
666,
687,
658,
807,
18,
64,
1901,
314,
658,
807,
17,
64,
2600,
12,
10663,
6866,
272,
402,
6032,
11196,
14,
339,
1306,
366,
275,
469,
17,
26,
283,
1421,
297,
650,
26,
283,
6185,
936,
272,
1306,
5389,
8,
68,
12,
469,
17,
26,
283,
5686,
297,
499,
26,
283,
5281,
3071,
272,
1306,
2974,
275,
366,
14,
1744,
7303,
2974,
14,
3191,
7303,
2974,
272,
3842,
17,
12,
283,
5686,
659,
334,
18,
12,
283,
5281,
659,
334,
19,
12,
283,
6185,
5440,
339,
520,
635,
1211,
17,
26,
314,
2600,
370,
5389,
1901,
272,
520,
635,
1211,
18,
26,
314,
2600,
3035,
314,
666,
626,
1077,
506,
9545,
272,
408,
272,
367,
790,
12,
1139,
18,
315,
1211,
18,
14,
1744,
837,
267,
340,
1139,
18,
365,
440,
488,
26,
288,
1139,
17,
275,
1211,
17,
14,
362,
8,
498,
9,
288,
340,
1228,
8,
637,
18,
12,
1211,
304,
355,
340,
1139,
17,
365,
488,
26,
490,
1139,
17,
275,
1052,
355,
340,
1228,
8,
637,
17,
12,
24777,
304,
490,
1139,
17,
275,
334,
637,
17,
12,
1139,
18,
9,
355,
916,
1228,
8,
637,
17,
12,
2008,
304,
490,
5162,
12,
11789,
275,
1139,
17,
490,
11789,
275,
11789,
14,
1574,
342,
490,
5389,
8,
21714,
12,
1139,
18,
9,
490,
1139,
17,
275,
334,
3620,
12,
11789,
9,
355,
587,
26,
490,
1139,
17,
275,
1139,
17,
14,
1574,
342,
490,
5389,
8,
637,
17,
12,
1139,
18,
9,
288,
587,
26,
355,
1139,
17,
275,
1139,
18,
288,
1211,
17,
59,
498,
61,
275,
1139,
17,
421,
199,
533,
24777,
8,
785,
304,
272,
408,
20609,
402,
376,
5162,
315,
314,
5867,
666,
14,
339,
1626,
5162,
365,
282,
574
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
29178,
14,
5508,
576,
272,
18294,
339,
21766,
13,
1896,
5867,
666,
2879,
14,
339,
520,
4610,
26,
710,
658,
20342,
64,
1021,
12,
1314,
4440,
642,
859,
1334,
314,
2636,
364,
12,
6571,
282,
1779,
1655,
22700,
3217,
367,
18549,
314,
5867,
666,
14,
339,
520,
7307,
26,
334,
67,
9,
6171,
701,
314,
699,
902,
11682,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
1655,
2436,
14,
199,
624,
199,
199,
646,
747,
199,
646,
5796,
199,
504,
5055,
492,
29396,
199,
199,
504,
29178,
423,
5819,
492,
5927,
421,
199,
63,
1637,
275,
1052,
199,
63,
1637,
63,
831,
275,
5796,
14,
30550,
342,
199,
63,
3475,
275,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
283,
5508,
576,
358,
421,
199,
318,
3495,
8,
354,
304,
272,
408,
1799,
3775,
5867,
666,
365,
2808,
367,
314,
1627,
5867,
14,
221,
377,
2523,
272,
372,
574,
365,
658,
549,
64,
340,
652,
3495,
12,
658,
797,
64,
4257,
14,
339,
520,
635,
536,
26,
314,
5867,
5148,
1059,
272,
408,
272,
340,
536,
315,
485,
1637,
26,
267,
372,
715,
272,
372,
747,
14,
515,
14,
2444,
8,
736,
14,
515,
14,
904,
1547,
3475,
12,
1543,
83,
14,
4616,
7,
450,
536,
430,
421,
199,
318,
5867,
63,
14227,
837,
272,
408,
1767,
282,
769,
402,
1006,
5867,
14154,
367,
1314,
5867,
666,
365,
272,
2808,
14,
339,
2508,
7445,
447,
378,
14,
24,
14,
17,
339,
520,
1107,
26,
282,
769,
402,
5867,
14154,
334,
5465,
9,
272,
408,
272,
372,
359,
18446,
367,
17408,
12,
3329,
315,
359,
267,
747,
14,
515,
14,
7973,
8,
1501,
9,
367,
1788,
315,
747,
14,
7374,
1547,
3475,
9,
272,
1622,
340,
3329,
508,
1987,
4616,
7,
436,
17408,
1137,
283,
1231,
418,
421,
199,
318,
2248,
8,
354,
12,
5389,
63,
17571,
29,
549,
304,
272,
408,
6200,
314,
5867,
666,
367,
314,
1627,
5867,
14,
339,
710,
5867,
666,
365,
282,
2600,
626,
3509,
8298,
402,
314,
666,
3247,
701,
272,
314,
13964,
28298,
3918,
24426,
334,
1981,
4564,
680,
961,
666,
365,
5489,
465,
282,
272,
3245,
402,
5927,
1584,
6272,
314,
1124,
66,
902,
1040,
2559,
14,
339,
1306,
366,
275,
2248,
360,
287,
63,
1668,
358,
272,
1306,
366,
459,
13209,
2545,
2772,
418,
272,
399,
7,
51,
1129,
29159,
7,
339,
3390,
626,
314,
2058,
787,
6328,
12,
436,
13372,
4145,
367,
314,
2011,
272,
5867,
372,
314,
2011,
2600,
26,
339,
1306,
366,
17,
275,
2248,
360,
287,
63,
1668,
358,
272,
1306,
366,
18,
275,
2248,
360,
287,
63,
1668,
358,
272,
1306,
366,
17,
365,
366,
18,
272,
715,
339,
520,
635,
536,
26,
314,
5867,
5148,
1059,
334,
269,
298,
1231,
531,
272,
520,
635,
5389,
63,
17571,
26,
3775,
314,
12623,
666,
1077,
506,
9545,
1901,
1169,
314,
666,
402,
314,
5839,
5867,
272,
520,
3730,
658,
13760,
8340,
340,
949,
5867,
666,
570,
365,
1911,
367,
314,
1627,
5867,
1993,
6120,
280,
2412,
12,
503,
1373,
402,
314,
24847,
652,
21592,
687,
272,
408,
272,
485,
1637,
63,
831,
14,
8174,
342,
272,
862,
26,
267,
666,
275,
485,
1637,
14,
362,
8,
354,
9,
267,
340,
440,
666,
26,
288,
327,
7190,
12623,
666,
288,
340,
536,
508,
283,
1231,
7,
503,
440,
5389,
63,
17571,
26,
355,
666,
275,
1052,
288,
587,
26,
355,
4184,
275,
536,
14,
1294,
26341,
355,
340,
822,
8,
4181,
9,
508,
413,
26,
490,
1676,
275,
283,
1231,
7,
355,
587,
26,
490,
1676,
275,
2513,
1370,
904,
8,
4181,
4439,
17,
566,
355,
666,
275,
2248,
8,
1708,
680,
1574,
342,
288,
1788,
275,
747,
14,
515,
14,
904,
1547,
3475,
12,
1543,
83,
14,
4616,
7,
450,
536,
9,
288,
11099,
275,
1551,
8,
1501,
12,
283,
4848,
358,
288,
862,
26,
355,
340,
536,
1137,
283,
1231,
7,
436,
5389,
63,
17571,
26,
490,
5389,
8,
576,
12,
5927,
14,
912,
8,
9234,
430,
355,
587,
26,
490,
666,
275,
5927,
14,
912,
8,
9234,
9,
355,
485,
1637,
59,
354,
61,
275,
666,
288,
3753,
26,
355,
11099,
14,
1600,
342,
267,
372,
666,
272,
3753,
26,
267,
485,
1637,
63,
831,
14,
3221,
342,
421,
199,
318,
5389,
8,
807,
17,
12,
1211,
18,
304,
272,
408,
11359,
314,
666,
687,
658,
807,
18,
64,
1901,
314,
658,
807,
17,
64,
2600,
12,
10663,
6866,
272,
402,
6032,
11196,
14,
339,
1306,
366,
275,
469,
17,
26,
283,
1421,
297,
650,
26,
283,
6185,
936,
272,
1306,
5389,
8,
68,
12,
469,
17,
26,
283,
5686,
297,
499,
26,
283,
5281,
3071,
272,
1306,
2974,
275,
366,
14,
1744,
7303,
2974,
14,
3191,
7303,
2974,
272,
3842,
17,
12,
283,
5686,
659,
334,
18,
12,
283,
5281,
659,
334,
19,
12,
283,
6185,
5440,
339,
520,
635,
1211,
17,
26,
314,
2600,
370,
5389,
1901,
272,
520,
635,
1211,
18,
26,
314,
2600,
3035,
314,
666,
626,
1077,
506,
9545,
272,
408,
272,
367,
790,
12,
1139,
18,
315,
1211,
18,
14,
1744,
837,
267,
340,
1139,
18,
365,
440,
488,
26,
288,
1139,
17,
275,
1211,
17,
14,
362,
8,
498,
9,
288,
340,
1228,
8,
637,
18,
12,
1211,
304,
355,
340,
1139,
17,
365,
488,
26,
490,
1139,
17,
275,
1052,
355,
340,
1228,
8,
637,
17,
12,
24777,
304,
490,
1139,
17,
275,
334,
637,
17,
12,
1139,
18,
9,
355,
916,
1228,
8,
637,
17,
12,
2008,
304,
490,
5162,
12,
11789,
275,
1139,
17,
490,
11789,
275,
11789,
14,
1574,
342,
490,
5389,
8,
21714,
12,
1139,
18,
9,
490,
1139,
17,
275,
334,
3620,
12,
11789,
9,
355,
587,
26,
490,
1139,
17,
275,
1139,
17,
14,
1574,
342,
490,
5389,
8,
637,
17,
12,
1139,
18,
9,
288,
587,
26,
355,
1139,
17,
275,
1139,
18,
288,
1211,
17,
59,
498,
61,
275,
1139,
17,
421,
199,
533,
24777,
8,
785,
304,
272,
408,
20609,
402,
376,
5162,
315,
314,
5867,
666,
14,
339,
1626,
5162,
365,
282,
574,
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
] |
texib/bitcoin-zoo
|
member/views.py
|
1
|
3349
|
from django.shortcuts import render
from django.contrib.auth.models import User, Group
from django.contrib.auth import login
from django.contrib.auth import logout
from django.contrib.auth import authenticate
from django.http import HttpResponseRedirect
from rest_framework import viewsets
from rest_framework.authentication import SessionAuthentication, BasicAuthentication
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from rest_framework.views import APIView
from serializer import UserSerializer, GroupSerializer
from rest_framework import status
from rest_framework import parsers
from rest_framework import renderers
from rest_framework_jwt import utils
from rest_framework_jwt.authentication import JSONWebTokenAuthentication as jwt_auth
from rest_framework_jwt.serializers import JSONWebTokenSerializer
# userena
from userena import views
class UserViewSet(viewsets.ModelViewSet):
"""
API endpoint that allows users to be viewed or edited.
"""
authentication_classes = (BasicAuthentication, )
queryset = User.objects.all()
serializer_class = UserSerializer
class GroupViewSet(viewsets.ModelViewSet):
"""
API endpoint that allows groups to be viewed or edited.
"""
queryset = Group.objects.all()
serializer_class = GroupSerializer
def signup(request):
'''
a simple overwritten the signup view
'''
return views.signup(request, success_url='/home/')
def signout(request):
'''
'''
return views.signout(request, template_name='home.html')
def signin(request):
'''
'''
# this is a little trick to hack the userena signin function
return views.signin(request, redirect_signin_function=lambda *arg: '/home/')
class testSignin(APIView):
'''
API View that receives a POST with a user's username and password.
Returns a JSON Web Token that can be used for authenticated requests.
'''
throttle_classes = ()
permission_classes = ()
authentication_classes = ()
parser_classes = (parsers.FormParser, parsers.JSONParser,)
renderer_classes = (renderers.JSONRenderer,)
serializer_class = JSONWebTokenSerializer
jwt = jwt_auth()
def post(self, request):
'''
a known issue now...
a segment fault happens if you login and then logout and login again..
'''
serializer = testSignin.serializer_class(data=request.DATA)
if serializer.is_valid():
payload = utils.jwt_decode_handler(serializer.object['token'])
user = self.jwt.authenticate_credentials(payload)
# below is a tric for authenticate..
# due to the authentication in django -- it need username and password,
# however, decode of jwt doesn't contain password.
user.backend = 'django.contrib.auth.backends.ModelBackend'
# user = authenticate(username=user, nopass=True)
if user is not None:
if user.is_active:
login(request, user)
return HttpResponseRedirect('/home/')
else:
raise Exception('user not active')
else:
raise Exception('not valid user')
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
mit
|
[
504,
1639,
14,
17469,
492,
3795,
199,
504,
1639,
14,
2828,
14,
1178,
14,
992,
492,
2876,
12,
5611,
199,
504,
1639,
14,
2828,
14,
1178,
492,
4676,
199,
504,
1639,
14,
2828,
14,
1178,
492,
22079,
199,
504,
1639,
14,
2828,
14,
1178,
492,
12895,
199,
504,
1639,
14,
1014,
492,
14935,
199,
199,
504,
4618,
63,
4857,
492,
2455,
2193,
199,
504,
4618,
63,
4857,
14,
11725,
492,
8596,
10348,
12,
10082,
10348,
199,
504,
4618,
63,
4857,
14,
6060,
492,
6596,
30871,
199,
504,
4618,
63,
4857,
14,
1310,
492,
7232,
199,
504,
4618,
63,
4857,
14,
4196,
492,
3261,
2768,
199,
504,
9146,
492,
2876,
7299,
12,
5611,
7299,
199,
504,
4618,
63,
4857,
492,
2004,
199,
504,
4618,
63,
4857,
492,
21295,
199,
504,
4618,
63,
4857,
492,
2903,
26529,
199,
504,
4618,
63,
4857,
63,
30033,
492,
3778,
199,
504,
4618,
63,
4857,
63,
30033,
14,
11725,
492,
4840,
5926,
3264,
10348,
465,
1335,
9115,
63,
1178,
199,
504,
4618,
63,
4857,
63,
30033,
14,
12844,
492,
4840,
5926,
3264,
7299,
199,
3,
675,
28359,
199,
504,
675,
28359,
492,
6858,
421,
199,
533,
2876,
21902,
8,
1345,
2193,
14,
1685,
21902,
304,
272,
408,
272,
3261,
6037,
626,
6127,
4390,
370,
506,
2455,
379,
503,
21062,
14,
272,
408,
339,
6299,
63,
2888,
275,
334,
6845,
10348,
12,
776,
339,
7594,
275,
2876,
14,
1462,
14,
452,
342,
272,
9146,
63,
533,
275,
2876,
7299,
421,
199,
533,
5611,
21902,
8,
1345,
2193,
14,
1685,
21902,
304,
272,
408,
272,
3261,
6037,
626,
6127,
4652,
370,
506,
2455,
379,
503,
21062,
14,
272,
408,
272,
7594,
275,
5611,
14,
1462,
14,
452,
342,
272,
9146,
63,
533,
275,
5611,
7299,
421,
199,
318,
2070,
384,
8,
1069,
304,
272,
1449,
272,
282,
3486,
20200,
314,
2070,
384,
2455,
272,
1449,
272,
372,
6858,
14,
19799,
8,
1069,
12,
3182,
63,
633,
8805,
4219,
6217,
421,
199,
318,
2070,
548,
8,
1069,
304,
272,
1449,
272,
1449,
272,
372,
6858,
14,
1037,
548,
8,
1069,
12,
1978,
63,
354,
534,
4219,
14,
1360,
358,
421,
199,
318,
2070,
262,
8,
1069,
304,
272,
1449,
272,
1449,
272,
327,
642,
365,
282,
12050,
20907,
370,
11176,
314,
675,
28359,
2070,
262,
805,
272,
372,
6858,
14,
1037,
262,
8,
1069,
12,
4660,
63,
1037,
262,
63,
1593,
29,
2734,
627,
1273,
26,
1994,
4219,
6217,
421,
199,
533,
511,
4940,
262,
8,
25778,
304,
339,
1449,
272,
3261,
10935,
626,
23192,
282,
8761,
543,
282,
922,
1159,
3434,
436,
2505,
14,
339,
1803,
282,
4840,
6001,
8767,
626,
883,
506,
1202,
367,
15082,
4145,
14,
272,
1449,
339,
27048,
63,
2888,
275,
6248,
272,
4983,
63,
2888,
275,
6248,
272,
6299,
63,
2888,
275,
6248,
272,
1798,
63,
2888,
275,
334,
11531,
14,
2821,
2842,
12,
21295,
14,
6243,
2842,
4258,
272,
11889,
63,
2888,
275,
334,
828,
26529,
14,
6243,
11355,
4258,
272,
9146,
63,
533,
275,
4840,
5926,
3264,
7299,
272,
1335,
9115,
275,
1335,
9115,
63,
1178,
342,
339,
347,
2963,
8,
277,
12,
1056,
304,
267,
1449,
267,
282,
6040,
4976,
3063,
1396,
267,
282,
8135,
16898,
10986,
340,
1265,
4676,
436,
2066,
22079,
436,
4676,
4020,
703,
267,
1449,
267,
9146,
275,
511,
4940,
262,
14,
8349,
63,
533,
8,
576,
29,
1069,
14,
3998,
9,
398,
340,
9146,
14,
374,
63,
1078,
837,
953,
4886,
275,
3778,
14,
30033,
63,
2708,
63,
2232,
8,
8349,
14,
785,
459,
1418,
1105,
288,
922,
275,
291,
14,
30033,
14,
13975,
63,
6942,
8,
4749,
9,
953,
327,
5084,
365,
282,
307,
1567,
367,
12895,
703,
288,
327,
7037,
370,
314,
6299,
315,
1639,
1553,
652,
1929,
3434,
436,
2505,
12,
288,
327,
13432,
12,
4849,
402,
1335,
9115,
3181,
1133,
1395,
2505,
14,
288,
922,
14,
4620,
275,
283,
1176,
14,
2828,
14,
1178,
14,
7765,
14,
1685,
8447,
7,
288,
327,
922,
275,
12895,
8,
2473,
29,
751,
12,
302,
411,
405,
29,
549,
9,
288,
340,
922,
365,
440,
488,
26,
355,
340,
922,
14,
374,
63,
2682,
26,
490,
4676,
8,
1069,
12,
922,
9,
490,
372,
14935,
2336,
4219,
6217,
355,
587,
26,
490,
746,
2186,
360,
751,
440,
4702,
358,
953,
587,
26,
355,
746,
2186,
360,
1397,
1686,
922,
358,
398,
372,
7232,
8,
8349,
14,
2550,
12,
2004,
29,
1205,
14,
2856,
63,
5303,
63,
9439,
63,
6780,
9,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1639,
14,
17469,
492,
3795,
199,
504,
1639,
14,
2828,
14,
1178,
14,
992,
492,
2876,
12,
5611,
199,
504,
1639,
14,
2828,
14,
1178,
492,
4676,
199,
504,
1639,
14,
2828,
14,
1178,
492,
22079,
199,
504,
1639,
14,
2828,
14,
1178,
492,
12895,
199,
504,
1639,
14,
1014,
492,
14935,
199,
199,
504,
4618,
63,
4857,
492,
2455,
2193,
199,
504,
4618,
63,
4857,
14,
11725,
492,
8596,
10348,
12,
10082,
10348,
199,
504,
4618,
63,
4857,
14,
6060,
492,
6596,
30871,
199,
504,
4618,
63,
4857,
14,
1310,
492,
7232,
199,
504,
4618,
63,
4857,
14,
4196,
492,
3261,
2768,
199,
504,
9146,
492,
2876,
7299,
12,
5611,
7299,
199,
504,
4618,
63,
4857,
492,
2004,
199,
504,
4618,
63,
4857,
492,
21295,
199,
504,
4618,
63,
4857,
492,
2903,
26529,
199,
504,
4618,
63,
4857,
63,
30033,
492,
3778,
199,
504,
4618,
63,
4857,
63,
30033,
14,
11725,
492,
4840,
5926,
3264,
10348,
465,
1335,
9115,
63,
1178,
199,
504,
4618,
63,
4857,
63,
30033,
14,
12844,
492,
4840,
5926,
3264,
7299,
199,
3,
675,
28359,
199,
504,
675,
28359,
492,
6858,
421,
199,
533,
2876,
21902,
8,
1345,
2193,
14,
1685,
21902,
304,
272,
408,
272,
3261,
6037,
626,
6127,
4390,
370,
506,
2455,
379,
503,
21062,
14,
272,
408,
339,
6299,
63,
2888,
275,
334,
6845,
10348,
12,
776,
339,
7594,
275,
2876,
14,
1462,
14,
452,
342,
272,
9146,
63,
533,
275,
2876,
7299,
421,
199,
533,
5611,
21902,
8,
1345,
2193,
14,
1685,
21902,
304,
272,
408,
272,
3261,
6037,
626,
6127,
4652,
370,
506,
2455,
379,
503,
21062,
14,
272,
408,
272,
7594,
275,
5611,
14,
1462,
14,
452,
342,
272,
9146,
63,
533,
275,
5611,
7299,
421,
199,
318,
2070,
384,
8,
1069,
304,
272,
1449,
272,
282,
3486,
20200,
314,
2070,
384,
2455,
272,
1449,
272,
372,
6858,
14,
19799,
8,
1069,
12,
3182,
63,
633,
8805,
4219,
6217,
421,
199,
318,
2070,
548,
8,
1069,
304,
272,
1449,
272,
1449,
272,
372,
6858,
14,
1037,
548,
8,
1069,
12,
1978,
63,
354,
534,
4219,
14,
1360,
358,
421,
199,
318,
2070,
262,
8,
1069,
304,
272,
1449,
272,
1449,
272,
327,
642,
365,
282,
12050,
20907,
370,
11176,
314,
675,
28359,
2070,
262,
805,
272,
372,
6858,
14,
1037,
262,
8,
1069,
12,
4660,
63,
1037,
262,
63,
1593,
29,
2734,
627,
1273,
26,
1994,
4219,
6217,
421,
199,
533,
511,
4940,
262,
8,
25778,
304,
339,
1449,
272,
3261,
10935,
626,
23192,
282,
8761,
543,
282,
922,
1159,
3434,
436,
2505,
14,
339,
1803,
282,
4840,
6001,
8767,
626,
883,
506,
1202,
367,
15082,
4145,
14,
272,
1449,
339,
27048,
63,
2888,
275,
6248,
272,
4983,
63,
2888,
275,
6248,
272,
6299,
63,
2888,
275,
6248,
272,
1798,
63,
2888,
275,
334,
11531,
14,
2821,
2842,
12,
21295,
14,
6243,
2842,
4258,
272,
11889,
63,
2888,
275,
334,
828,
26529,
14,
6243,
11355,
4258,
272,
9146,
63,
533,
275,
4840,
5926,
3264,
7299,
272,
1335,
9115,
275,
1335,
9115,
63,
1178,
342,
339,
347,
2963,
8,
277,
12,
1056,
304,
267,
1449,
267,
282,
6040,
4976,
3063,
1396,
267,
282,
8135,
16898,
10986,
340,
1265,
4676,
436,
2066,
22079,
436,
4676,
4020,
703,
267,
1449,
267,
9146,
275,
511,
4940,
262,
14,
8349,
63,
533,
8,
576,
29,
1069,
14,
3998,
9,
398,
340,
9146,
14,
374,
63,
1078,
837,
953,
4886,
275,
3778,
14,
30033,
63,
2708,
63,
2232,
8,
8349,
14,
785,
459,
1418,
1105,
288,
922,
275,
291,
14,
30033,
14,
13975,
63,
6942,
8,
4749,
9,
953,
327,
5084,
365,
282,
307,
1567,
367,
12895,
703,
288,
327,
7037,
370,
314,
6299,
315,
1639,
1553,
652,
1929,
3434,
436,
2505,
12,
288,
327,
13432,
12,
4849,
402,
1335,
9115,
3181,
1133,
1395,
2505,
14,
288,
922,
14,
4620,
275,
283,
1176,
14,
2828,
14,
1178,
14,
7765,
14,
1685,
8447,
7,
288,
327,
922,
275,
12895,
8,
2473,
29,
751,
12,
302,
411,
405,
29,
549,
9,
288,
340,
922,
365,
440,
488,
26,
355,
340,
922,
14,
374,
63,
2682,
26,
490,
4676,
8,
1069,
12,
922,
9,
490,
372,
14935,
2336,
4219,
6217,
355,
587,
26,
490,
746,
2186,
360,
751,
440,
4702,
358,
953,
587,
26,
355,
746,
2186,
360,
1397,
1686,
922,
358,
398,
372,
7232,
8,
8349,
14,
2550,
12,
2004,
29,
1205,
14,
2856,
63,
5303,
63,
9439,
63,
6780,
9,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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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
] |
Grassboy/plugin.video.plurkTrend
|
youtube_dl/extractor/ehow.py
|
9
|
1735
|
import re
from ..utils import (
compat_urllib_parse,
determine_ext
)
from .common import InfoExtractor
class EHowIE(InfoExtractor):
IE_NAME = u'eHow'
_VALID_URL = r'(?:https?://)?(?:www\.)?ehow\.com/[^/_?]*_(?P<id>[0-9]+)'
_TEST = {
u'url': u'http://www.ehow.com/video_12245069_hardwood-flooring-basics.html',
u'file': u'12245069.flv',
u'md5': u'9809b4e3f115ae2088440bcb4efbf371',
u'info_dict': {
u"title": u"Hardwood Flooring Basics",
u"description": u"Hardwood flooring may be time consuming, but its ultimately a pretty straightforward concept. Learn about hardwood flooring basics with help from a hardware flooring business owner in this free video...",
u"uploader": u"Erick Nathan"
}
}
def _real_extract(self, url):
mobj = re.match(self._VALID_URL, url)
video_id = mobj.group('id')
webpage = self._download_webpage(url, video_id)
video_url = self._search_regex(r'(?:file|source)=(http[^\'"&]*)',
webpage, u'video URL')
final_url = compat_urllib_parse.unquote(video_url)
uploader = self._search_regex(r'<meta name="uploader" content="(.+?)" />',
webpage, u'uploader')
title = self._og_search_title(webpage).replace(' | eHow', '')
ext = determine_ext(final_url)
return {
'_type': 'video',
'id': video_id,
'url': final_url,
'ext': ext,
'title': title,
'thumbnail': self._og_search_thumbnail(webpage),
'description': self._og_search_description(webpage),
'uploader': uploader,
}
|
mit
|
[
646,
295,
199,
199,
504,
2508,
1208,
492,
334,
272,
8434,
63,
4078,
63,
1122,
12,
272,
6705,
63,
832,
199,
9,
199,
504,
1275,
2330,
492,
21298,
421,
199,
533,
662,
18335,
4332,
8,
18283,
304,
272,
15292,
63,
2339,
275,
399,
7,
69,
18335,
7,
272,
485,
5600,
63,
2632,
275,
519,
20459,
2859,
14144,
5547,
5169,
1544,
20316,
69,
1917,
4537,
957,
15,
4735,
15607,
31,
3672,
63,
2229,
48,
28,
344,
9514,
16,
13,
25,
29716,
272,
485,
2864,
275,
469,
267,
399,
7,
633,
356,
399,
7,
1014,
921,
1544,
14,
69,
1917,
14,
957,
15,
3722,
63,
713,
1194,
1400,
1876,
63,
8726,
22736,
13,
11289,
316,
13,
4316,
83,
14,
1360,
297,
267,
399,
7,
493,
356,
399,
7,
713,
1194,
1400,
1876,
14,
22753,
297,
267,
399,
6704,
68,
21,
356,
399,
7,
25,
11782,
66,
20,
69,
19,
70,
7680,
3624,
1165,
1299,
14162,
66,
2894,
20,
2829,
4361,
16124,
297,
267,
399,
7,
815,
63,
807,
356,
469,
288,
399,
2,
1213,
582,
399,
2,
16464,
22736,
11844,
316,
10082,
83,
401,
288,
399,
2,
1802,
582,
399,
2,
16464,
22736,
19841,
316,
1443,
506,
900,
406,
26745,
12,
1325,
2399,
221,
1141,
77,
13824,
282,
7268,
23669,
6688,
19834,
14,
7005,
1060,
3595,
7508,
22736,
19841,
316,
5678,
83,
543,
1720,
687,
282,
14991,
19841,
316,
26440,
5771,
315,
642,
2867,
3991,
23966,
272,
1057,
198,
85,
2,
13671,
582,
399,
2,
37,
27091,
653,
1619,
290,
2,
267,
789,
272,
789,
339,
347,
485,
3093,
63,
5005,
8,
277,
12,
1166,
304,
267,
14208,
275,
295,
14,
1431,
8,
277,
423,
5600,
63,
2632,
12,
1166,
9,
267,
3991,
63,
344,
275,
14208,
14,
923,
360,
344,
358,
267,
9248,
275,
291,
423,
4249,
63,
12022,
8,
633,
12,
3991,
63,
344,
9,
267,
3991,
63,
633,
275,
291,
423,
1733,
63,
3821,
8,
82,
20459,
493,
92,
1365,
9,
2687,
1014,
4735,
3985,
2,
6,
3672,
3196,
288,
9248,
12,
399,
7,
3722,
2851,
358,
267,
4242,
63,
633,
275,
8434,
63,
4078,
63,
1122,
14,
12240,
8,
3722,
63,
633,
9,
18418,
25257,
275,
291,
423,
1733,
63,
3821,
8,
82,
7601,
2024,
536,
628,
13671,
2,
1564,
628,
28149,
2924,
1182,
4206,
288,
9248,
12,
399,
7,
13671,
358,
267,
2538,
275,
291,
423,
974,
63,
1733,
63,
1213,
8,
12022,
680,
1814,
360,
1204,
325,
18335,
297,
4074,
267,
1599,
275,
6705,
63,
832,
8,
5094,
63,
633,
9,
398,
372,
469,
288,
2513,
466,
356,
755,
283,
3722,
297,
288,
283,
344,
356,
3515,
3991,
63,
344,
12,
288,
283,
633,
356,
260,
4242,
63,
633,
12,
288,
283,
832,
356,
260,
1599,
12,
288,
283,
1213,
356,
755,
2538,
12,
288,
283,
8311,
356,
257,
291,
423,
974,
63,
1733,
63,
8311,
8,
12022,
395,
288,
283,
1802,
356,
291,
423,
974,
63,
1733,
63,
1802,
8,
12022,
395,
288,
283,
13671,
356,
259,
25257,
12,
267,
789,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
295,
199,
199,
504,
2508,
1208,
492,
334,
272,
8434,
63,
4078,
63,
1122,
12,
272,
6705,
63,
832,
199,
9,
199,
504,
1275,
2330,
492,
21298,
421,
199,
533,
662,
18335,
4332,
8,
18283,
304,
272,
15292,
63,
2339,
275,
399,
7,
69,
18335,
7,
272,
485,
5600,
63,
2632,
275,
519,
20459,
2859,
14144,
5547,
5169,
1544,
20316,
69,
1917,
4537,
957,
15,
4735,
15607,
31,
3672,
63,
2229,
48,
28,
344,
9514,
16,
13,
25,
29716,
272,
485,
2864,
275,
469,
267,
399,
7,
633,
356,
399,
7,
1014,
921,
1544,
14,
69,
1917,
14,
957,
15,
3722,
63,
713,
1194,
1400,
1876,
63,
8726,
22736,
13,
11289,
316,
13,
4316,
83,
14,
1360,
297,
267,
399,
7,
493,
356,
399,
7,
713,
1194,
1400,
1876,
14,
22753,
297,
267,
399,
6704,
68,
21,
356,
399,
7,
25,
11782,
66,
20,
69,
19,
70,
7680,
3624,
1165,
1299,
14162,
66,
2894,
20,
2829,
4361,
16124,
297,
267,
399,
7,
815,
63,
807,
356,
469,
288,
399,
2,
1213,
582,
399,
2,
16464,
22736,
11844,
316,
10082,
83,
401,
288,
399,
2,
1802,
582,
399,
2,
16464,
22736,
19841,
316,
1443,
506,
900,
406,
26745,
12,
1325,
2399,
221,
1141,
77,
13824,
282,
7268,
23669,
6688,
19834,
14,
7005,
1060,
3595,
7508,
22736,
19841,
316,
5678,
83,
543,
1720,
687,
282,
14991,
19841,
316,
26440,
5771,
315,
642,
2867,
3991,
23966,
272,
1057,
198,
85,
2,
13671,
582,
399,
2,
37,
27091,
653,
1619,
290,
2,
267,
789,
272,
789,
339,
347,
485,
3093,
63,
5005,
8,
277,
12,
1166,
304,
267,
14208,
275,
295,
14,
1431,
8,
277,
423,
5600,
63,
2632,
12,
1166,
9,
267,
3991,
63,
344,
275,
14208,
14,
923,
360,
344,
358,
267,
9248,
275,
291,
423,
4249,
63,
12022,
8,
633,
12,
3991,
63,
344,
9,
267,
3991,
63,
633,
275,
291,
423,
1733,
63,
3821,
8,
82,
20459,
493,
92,
1365,
9,
2687,
1014,
4735,
3985,
2,
6,
3672,
3196,
288,
9248,
12,
399,
7,
3722,
2851,
358,
267,
4242,
63,
633,
275,
8434,
63,
4078,
63,
1122,
14,
12240,
8,
3722,
63,
633,
9,
18418,
25257,
275,
291,
423,
1733,
63,
3821,
8,
82,
7601,
2024,
536,
628,
13671,
2,
1564,
628,
28149,
2924,
1182,
4206,
288,
9248,
12,
399,
7,
13671,
358,
267,
2538,
275,
291,
423,
974,
63,
1733,
63,
1213,
8,
12022,
680,
1814,
360,
1204,
325,
18335,
297,
4074,
267,
1599,
275,
6705,
63,
832,
8,
5094,
63,
633,
9,
398,
372,
469,
288,
2513,
466,
356,
755,
283,
3722,
297,
288,
283,
344,
356,
3515,
3991,
63,
344,
12,
288,
283,
633,
356,
260,
4242,
63,
633,
12,
288,
283,
832,
356,
260,
1599,
12,
288,
283,
1213,
356,
755,
2538,
12,
288,
283,
8311,
356,
257,
291,
423,
974,
63,
1733,
63,
8311,
8,
12022,
395,
288,
283,
1802,
356,
291,
423,
974,
63,
1733,
63,
1802,
8,
12022,
395,
288,
283,
13671,
356,
259,
25257,
12,
267,
789,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
dnowatsc/Varial
|
varial/operations.py
|
1
|
23334
|
"""
Operations on wrappers
"""
import array
import __builtin__
import ctypes
import collections
import functools
from ROOT import THStack, TGraphAsymmErrors
import history
import wrappers
class OperationError(Exception): pass
class TooFewWrpsError(OperationError): pass
class TooManyWrpsError(OperationError): pass
class WrongInputError(OperationError): pass
class NoLumiMatchError(OperationError): pass
def iterableize(obj):
if isinstance(obj, collections.Iterable):
return obj
else:
return [obj]
def add_wrp_kws(func):
"""Pops 'wrp_kws' from given keywords and updates returned wrapper."""
@functools.wraps(func)
def catch_wrp_kws(*args, **kws):
wrp_kws = kws.pop('wrp_kws', {})
ret = func(*args, **kws)
ret.__dict__.update(wrp_kws)
return ret
return catch_wrp_kws
@add_wrp_kws
@history.track_history
def stack(wrps):
"""
Applies only to HistoWrappers. Returns StackWrapper.
Checks lumi to be equal among all wrappers.
>>> from ROOT import TH1I
>>> h1 = TH1I("h1", "", 2, .5, 4.5)
>>> h1.Fill(1,4)
1
>>> w1 = wrappers.HistoWrapper(h1, lumi=2.)
>>> h2 = TH1I("h2", "", 2, .5, 4.5)
>>> h2.Fill(1,3)
1
>>> h2.Fill(3,6)
2
>>> w2 = wrappers.HistoWrapper(h2, lumi=2.)
>>> w3 = stack([w1, w2])
>>> w3.histo.Integral()
13.0
>>> w3.lumi
2.0
"""
wrps = iterableize(wrps)
stk_wrp = None
lumi = 0.
info = None
sample = ""
for wrp in wrps:
if not isinstance(wrp, wrappers.HistoWrapper): # histo check
raise WrongInputError(
"stack accepts only HistoWrappers. wrp: "
+ str(wrp)
)
if not stk_wrp: # stack init
stk_wrp = THStack(wrp.name, wrp.title)
lumi = wrp.lumi
info = wrp.all_info()
sample = wrp.sample
elif lumi != wrp.lumi: # lumi check
raise NoLumiMatchError(
"stack needs lumis to match. (%f != %f)" % (lumi, wrp.lumi)
)
if sample != wrp.sample: # add to stack
sample = ""
stk_wrp.Add(wrp.histo)
if not info:
raise TooFewWrpsError(
"At least one Wrapper must be provided."
)
if not sample:
del info["sample"]
return wrappers.StackWrapper(stk_wrp, **info)
@add_wrp_kws
@history.track_history
def sum(wrps):
"""
Applies only to HistoWrappers. Returns HistoWrapper. Adds lumi up.
>>> from ROOT import TH1I
>>> h1 = TH1I("h1", "", 2, .5, 4.5)
>>> h1.Fill(1)
1
>>> w1 = wrappers.HistoWrapper(h1, lumi=2.)
>>> h2 = TH1I("h2", "", 2, .5, 4.5)
>>> h2.Fill(1)
1
>>> h2.Fill(3)
2
>>> w2 = wrappers.HistoWrapper(h2, lumi=3.)
>>> w3 = sum([w1, w2])
>>> w3.histo.Integral()
3.0
>>> w3.lumi
5.0
"""
wrps = iterableize(wrps)
histo = None
lumi = 0.
info = None
for wrp in wrps:
if not isinstance(wrp, wrappers.HistoWrapper):
raise WrongInputError(
"sum accepts only HistoWrappers. wrp: "
+ str(wrp)
)
if histo:
histo.Add(wrp.histo)
else:
histo = wrp.histo.Clone()
info = wrp.all_info()
lumi += wrp.lumi
if not info:
raise TooFewWrpsError(
"At least one Wrapper must be provided."
)
info["lumi"] = lumi
return wrappers.HistoWrapper(histo, **info)
@add_wrp_kws
@history.track_history
def diff(wrps):
"""
Applies only to HistoWrappers. Returns HistoWrapper. Takes lumi from first.
>>> from ROOT import TH1I
>>> h1 = TH1I("h1", "", 2, .5, 4.5)
>>> h1.Fill(1, 2)
1
>>> w1 = wrappers.HistoWrapper(h1, lumi=2.)
>>> h2 = TH1I("h2", "", 2, .5, 4.5)
>>> h2.Fill(1)
1
>>> w2 = wrappers.HistoWrapper(h2, lumi=3.)
>>> w3 = diff([w1, w2])
>>> w3.histo.Integral()
1.0
>>> w3.lumi
2.0
"""
wrps = iterableize(wrps)
histo = None
lumi = 0.
info = None
for wrp in wrps:
if not isinstance(wrp, wrappers.HistoWrapper):
raise WrongInputError(
"sum accepts only HistoWrappers. wrp: "
+ str(wrp)
)
if histo:
histo.Add(wrp.histo, -1.)
else:
histo = wrp.histo.Clone()
info = wrp.all_info()
lumi = wrp.lumi
if not info:
raise TooFewWrpsError(
"At least one Wrapper must be provided."
)
info["lumi"] = lumi
return wrappers.HistoWrapper(histo, **info)
@add_wrp_kws
@history.track_history
def merge(wrps):
"""
Applies only to HistoWrapper. Returns HistoWrapper. Normalizes histos to lumi.
>>> from ROOT import TH1I
>>> h1 = TH1I("h1", "", 2, .5, 2.5)
>>> h1.Fill(1,4)
1
>>> w1 = wrappers.HistoWrapper(h1, lumi=2.)
>>> h2 = TH1I("h2", "", 2, .5, 2.5)
>>> h2.Fill(1,3)
1
>>> h2.Fill(2,6)
2
>>> w2 = wrappers.HistoWrapper(h2, lumi=3.)
>>> w3 = merge([w1, w2])
>>> w3.histo.Integral()
5.0
>>> w3.lumi
1.0
"""
wrps = iterableize(wrps)
histo = None
info = None
for wrp in wrps:
if not isinstance(wrp, wrappers.HistoWrapper):
raise WrongInputError(
"merge accepts only HistoWrappers. wrp: "
+ str(wrp)
)
if histo:
histo.Add(wrp.histo, 1. / wrp.lumi)
else:
histo = wrp.histo.Clone()
histo.Scale(1. / wrp.lumi)
info = wrp.all_info()
if not info:
raise TooFewWrpsError(
"At least one Wrapper must be provided."
)
info["lumi"] = 1.
return wrappers.HistoWrapper(histo, **info)
@add_wrp_kws
@history.track_history
def prod(wrps):
"""
Applies to HistoWrapper and FloatWrapper. Returns HistoWrapper. Takes lumi from first.
>>> from ROOT import TH1I
>>> h1 = TH1I("h1", "", 2, .5, 2.5)
>>> h1.Fill(1)
1
>>> w1 = wrappers.HistoWrapper(h1, lumi=2, history="w1")
>>> h2 = TH1I("h2", "", 2, .5, 2.5)
>>> h2.Fill(1)
1
>>> h2.Fill(2)
2
>>> w2 = wrappers.HistoWrapper(h2, lumi=3)
>>> w3 = prod([w1, w2])
>>> w3.histo.Integral()
1.0
>>> w3.lumi
1.0
>>> w4 = wrappers.FloatWrapper(2.)
>>> w5 = prod([w1, w4])
>>> w5.histo.Integral()
2.0
"""
wrps = iterableize(wrps)
histo = None
info = None
lumi = 1.
for wrp in wrps:
if histo:
if isinstance(wrp, wrappers.HistoWrapper):
histo.Multiply(wrp.histo)
lumi = 1.
elif not isinstance(wrp, wrappers.FloatWrapper):
raise WrongInputError(
"prod accepts only HistoWrappers and FloatWrappers. wrp: "
+ str(wrp)
)
else:
histo.Scale(wrp.float)
lumi *= wrp.float
else:
if not isinstance(wrp, wrappers.HistoWrapper):
raise WrongInputError(
"prod expects first argument to be of type HistoWrapper. wrp: "
+ str(wrp)
)
histo = wrp.histo.Clone()
info = wrp.all_info()
lumi = wrp.lumi
if not info:
raise TooFewWrpsError(
"At least one Wrapper must be provided."
)
info["lumi"] = lumi
return wrappers.HistoWrapper(histo, **info)
@add_wrp_kws
@history.track_history
def div(wrps):
"""
Applies to HistoWrapper and FloatWrapper. Returns HistoWrapper. Takes lumi from first.
>>> from ROOT import TH1I
>>> h1 = TH1I("h1", "", 2, .5, 2.5)
>>> h1.Fill(1,4)
1
>>> w1 = wrappers.HistoWrapper(h1, lumi=2)
>>> h2 = TH1I("h2", "", 2, .5, 2.5)
>>> h2.Fill(1,2)
1
>>> w2 = wrappers.HistoWrapper(h2, lumi=3)
>>> w3 = div([w1, w2])
>>> w3.histo.Integral()
2.0
>>> w4 = wrappers.FloatWrapper(2., history="w4")
>>> w5 = div([w1, w4])
>>> w5.histo.Integral()
2.0
"""
wrps = iterableize(wrps)
wrps = iter(wrps)
try:
nominator = next(wrps)
denominator = next(wrps)
except StopIteration:
raise TooFewWrpsError("div needs exactly two Wrappers.")
try:
wrps.next()
raise TooManyWrpsError("div needs exactly two Wrappers.")
except StopIteration:
pass
if not isinstance(nominator, wrappers.HistoWrapper):
raise WrongInputError(
"div needs nominator to be of type HistoWrapper. nominator: "
+ str(nominator)
)
if not (isinstance(denominator, wrappers.HistoWrapper) or
isinstance(denominator, wrappers.FloatWrapper)):
raise WrongInputError(
"div needs denominator to be of type HistoWrapper or FloatWrapper. denominator: "
+ str(denominator)
)
histo = nominator.histo.Clone()
lumi = nominator.lumi
if isinstance(denominator, wrappers.HistoWrapper):
histo.Divide(denominator.histo)
lumi = 1.
else:
histo.Scale(1. / denominator.float)
lumi /= denominator.float
info = nominator.all_info()
info["lumi"] = lumi
return wrappers.HistoWrapper(histo, **info)
@add_wrp_kws
@history.track_history
def lumi(wrp):
"""
Applies to HistoWrapper. Returns FloatWrapper.
>>> from ROOT import TH1I
>>> h1 = TH1I("h1", "", 2, .5, 2.5)
>>> h1.Fill(1)
1
>>> w1 = wrappers.HistoWrapper(h1, lumi=2.)
>>> w2 = lumi(w1)
>>> w2.float
2.0
"""
if not isinstance(wrp, wrappers.HistoWrapper):
raise WrongInputError(
"lumi needs argument of type HistoWrapper. histo: "
+ str(wrp)
)
info = wrp.all_info()
return wrappers.FloatWrapper(wrp.lumi, **info)
@add_wrp_kws
@history.track_history
def norm_to_lumi(wrp):
"""
Applies to HistoWrapper. Returns HistoWrapper.
>>> from ROOT import TH1I
>>> h1 = TH1I("h1", "", 2, .5, 2.5)
>>> h1.Fill(1, 4)
1
>>> w1 = wrappers.HistoWrapper(h1, lumi=2.)
>>> w1.histo.Integral()
4.0
>>> w2 = norm_to_lumi(w1)
>>> w2.histo.Integral()
2.0
"""
if not isinstance(wrp, wrappers.HistoWrapper):
raise WrongInputError(
"norm_to_lumi needs argument of type HistoWrapper. histo: "
+ str(wrp)
)
histo = wrp.histo.Clone()
histo.Scale(1. / wrp.lumi)
info = wrp.all_info()
info["lumi"] = 1.
return wrappers.HistoWrapper(histo, **info)
@add_wrp_kws
@history.track_history
def norm_to_integral(wrp, use_bin_width=False):
"""
Applies to HistoWrapper. Returns HistoWrapper.
>>> from ROOT import TH1I
>>> h1 = TH1I("h1", "", 2, .5, 2.5)
>>> h1.Fill(1, 4)
1
>>> w1 = wrappers.HistoWrapper(h1, lumi=2.)
>>> w1.histo.Integral()
4.0
>>> w2 = norm_to_integral(w1)
>>> w2.histo.Integral()
1.0
"""
if not isinstance(wrp, wrappers.HistoWrapper):
raise WrongInputError(
"norm_to_integral needs argument of type HistoWrapper. histo: "
+ str(wrp)
)
histo = wrp.histo.Clone()
option = "width" if use_bin_width else ""
integr = wrp.histo.Integral(option) or 1.
histo.Scale(1. / integr)
info = wrp.all_info()
info["lumi"] /= integr
return wrappers.HistoWrapper(histo, **info)
@add_wrp_kws
@history.track_history
def copy(wrp):
"""
Applies to HistoWrapper. Returns HistoWrapper.
>>> from ROOT import TH1I
>>> h1 = TH1I("h1", "", 2, .5, 2.5)
>>> h1.Fill(1, 4)
1
>>> w1 = wrappers.HistoWrapper(h1, lumi=2.)
>>> w2=copy(w1)
>>> w2.histo.GetName()
'h1'
>>> w1.name == w2.name
True
>>> w1.histo.Integral() == w2.histo.Integral()
True
>>> w1.histo != w2.histo
True
"""
if not isinstance(wrp, wrappers.HistoWrapper):
raise WrongInputError(
"copy needs argument of type HistoWrapper. histo: "
+ str(wrp)
)
histo = wrp.histo.Clone()
info = wrp.all_info()
return wrappers.HistoWrapper(histo, **info)
@add_wrp_kws
@history.track_history
def rebin(wrp, bin_bounds, norm_by_bin_width=False):
"""
Applies to HistoWrapper. Returns Histowrapper.
>>> from ROOT import TH1I
>>> h1 = TH1I("h1", "", 4, .5, 4.5)
>>> h1.Fill(1)
1
>>> h1.Fill(2)
2
>>> w1 = wrappers.HistoWrapper(h1, lumi=2.)
>>> w2=rebin(w1, [.5, 2.5, 4.5])
>>> w1.histo.GetNbinsX()
4
>>> w2.histo.GetNbinsX()
2
>>> w2.histo.GetBinContent(1)
2.0
>>> w2.histo.GetBinContent(2)
0.0
"""
if not isinstance(wrp, wrappers.HistoWrapper):
raise WrongInputError(
"rebin needs argument of type HistoWrapper. histo: "
+ str(wrp)
)
if len(bin_bounds) < 2:
raise OperationError(
"Number of bins < 2, must include at least one bin!"
)
bin_bounds = array.array("d", bin_bounds)
orig_bin_width = wrp.histo.GetBinWidth(1)
histo = wrp.histo.Rebin(
len(bin_bounds) - 1,
wrp.name,
bin_bounds
)
if norm_by_bin_width:
for i in xrange(histo.GetNbinsX()+1):
factor = histo.GetBinWidth(i) / orig_bin_width
histo.SetBinContent(i, histo.GetBinContent(i) / factor)
histo.SetBinError(i, histo.GetBinError(i) / factor)
info = wrp.all_info()
return wrappers.HistoWrapper(histo, **info)
@add_wrp_kws
@history.track_history
def trim(wrp, left=True, right=True):
"""
Applies to HistoWrapper. Returns Histowrapper.
If left / right are set to values, these are applied. Otherwise empty bins
are cut off.
>>> from ROOT import TH1I
>>> w1 = wrappers.HistoWrapper(TH1I("h1", "", 10, .5, 10.5))
>>> w1.histo.Fill(5)
5
>>> w2 = trim(w1)
>>> w2.histo.GetNbinsX()
1
>>> w2.histo.GetXaxis().GetXmin()
4.5
>>> w2.histo.GetXaxis().GetXmax()
5.5
>>> w2 = trim(w1, 3.5, 7.5)
>>> w2.histo.GetNbinsX()
4
>>> w2.histo.GetXaxis().GetXmin()
3.5
>>> w2.histo.GetXaxis().GetXmax()
7.5
"""
if not isinstance(wrp, wrappers.HistoWrapper):
raise WrongInputError(
"trim needs argument of type HistoWrapper. histo: "
+ str(wrp)
)
# find left / right values if not given
histo = wrp.histo
axis = histo.GetXaxis()
n_bins = histo.GetNbinsX()
if type(left) == bool:
if left:
for i in xrange(n_bins+1):
if histo.GetBinContent(i):
left = axis.GetBinLowEdge(i)
break
else:
left = axis.GetXmin()
if type(right) == bool:
if right:
for i in xrange(n_bins+1, 0, -1):
if histo.GetBinContent(i):
right = axis.GetBinUpEdge(i)
break
else:
right = axis.GetXmax()
if left > right:
raise OperationError("bounds: left > right")
# create new bin_bounds
index = 0
while axis.GetBinLowEdge(index) < left:
index += 1
bin_bounds = [axis.GetBinLowEdge(index)]
while axis.GetBinUpEdge(index) <= right:
bin_bounds.append(axis.GetBinUpEdge(index))
index += 1
return rebin(wrp, bin_bounds)
@add_wrp_kws
@history.track_history
def mv_in(wrp, overflow=True, underflow=True):
"""
Moves under- and/or overflow bin into first/last bin.
>>> from ROOT import TH1I
>>> h1 = TH1I("h1", "", 2, .5, 4.5)
>>> h1.Fill(0)
-1
>>> h1.Fill(5,3)
-1
>>> w1 = wrappers.HistoWrapper(h1)
>>> w1.histo.Integral()
0.0
>>> w2 = mv_in(w1, False, False)
>>> w2.histo.Integral()
0.0
>>> w3 = mv_in(w1, True, False)
>>> w3.histo.Integral()
3.0
>>> w4 = mv_in(w1, False, True)
>>> w4.histo.Integral()
1.0
>>> w5 = mv_in(w1, True, True)
>>> w5.histo.Integral()
4.0
"""
if not isinstance(wrp, wrappers.HistoWrapper):
raise WrongInputError(
"mv_bin needs argument of type HistoWrapper. histo: "
+ str(wrp)
)
histo = wrp.histo.Clone()
nbins = histo.GetNbinsX()
if underflow:
firstbin = histo.GetBinContent(0)
firstbin += histo.GetBinContent(1)
histo.SetBinContent(1, firstbin)
histo.SetBinContent(0, 0.)
if overflow:
lastbin = histo.GetBinContent(nbins + 1)
lastbin += histo.GetBinContent(nbins)
histo.SetBinContent(nbins, lastbin)
histo.SetBinContent(histo.GetNbinsX() + 1, 0.)
return wrappers.HistoWrapper(histo, **wrp.all_info())
@add_wrp_kws
@history.track_history
def integral(wrp, use_bin_width=False):
"""
Integral. Applies to HistoWrapper. Returns FloatWrapper.
>>> from ROOT import TH1I
>>> h1 = TH1I("h1", "", 2, .5, 4.5)
>>> h1.Fill(1)
1
>>> h1.Fill(3,3)
2
>>> w1 = wrappers.HistoWrapper(h1)
>>> w2 = integral(w1)
>>> w2.float
4.0
>>> w3 = integral(w1, True)
>>> w3.float
8.0
"""
if not isinstance(wrp, wrappers.HistoWrapper):
raise WrongInputError(
"int needs argument of type HistoWrapper. histo: "
+ str(wrp)
)
option = "width" if use_bin_width else ""
info = wrp.all_info()
return wrappers.FloatWrapper(wrp.histo.Integral(option), **info)
@add_wrp_kws
@history.track_history
def int_l(wrp, use_bin_width=False):
"""
Left-sided integral. Applies to HistoWrapper. Returns HistoWrapper.
>>> from ROOT import TH1I
>>> h1 = TH1I("h1", "", 2, .5, 4.5)
>>> h1.Fill(1)
1
>>> h1.Fill(3,2)
2
>>> w1 = wrappers.HistoWrapper(h1)
>>> w2 = int_l(w1)
>>> w2.histo.GetBinContent(1)
1.0
>>> w2.histo.GetBinContent(2)
3.0
>>> w2 = int_l(w1, True)
>>> w2.histo.GetBinContent(1)
2.0
>>> w2.histo.GetBinContent(2)
6.0
"""
if not isinstance(wrp, wrappers.HistoWrapper):
raise WrongInputError(
"int_l needs argument of type HistoWrapper. histo: "
+ str(wrp)
)
int_histo = wrp.histo.Clone()
option = "width" if use_bin_width else ""
for i in xrange(int_histo.GetNbinsX(), 0, -1):
error = ctypes.c_double()
value = int_histo.IntegralAndError(1, i, error, option)
int_histo.SetBinContent(i, value)
int_histo.SetBinError(i, error.value)
info = wrp.all_info()
return wrappers.HistoWrapper(int_histo, **info)
@add_wrp_kws
@history.track_history
def int_r(wrp, use_bin_width=False):
"""
Applies to HistoWrapper. Returns HistoWrapper.
>>> from ROOT import TH1I
>>> h1 = TH1I("h1", "", 2, .5, 4.5)
>>> h1.Fill(1)
1
>>> h1.Fill(3,2)
2
>>> w1 = wrappers.HistoWrapper(h1)
>>> w2 = int_r(w1)
>>> w2.histo.GetBinContent(1)
3.0
>>> w2.histo.GetBinContent(2)
2.0
>>> w2 = int_r(w1, True)
>>> w2.histo.GetBinContent(1)
6.0
>>> w2.histo.GetBinContent(2)
4.0
"""
if not isinstance(wrp, wrappers.HistoWrapper):
raise WrongInputError(
"int_r needs argument of type HistoWrapper. histo: "
+ str(wrp)
)
int_histo = wrp.histo.Clone()
option = "width" if use_bin_width else ""
n_bins = int_histo.GetNbinsX()
for i in xrange(1, 1 + n_bins):
error = ctypes.c_double()
value = int_histo.IntegralAndError(i, n_bins, error, option)
int_histo.SetBinContent(i, value)
int_histo.SetBinError(i, error.value)
info = wrp.all_info()
return wrappers.HistoWrapper(int_histo, **info)
@add_wrp_kws
@history.track_history
def chi2(wrps, x_min=0, x_max=0):
"""
Expects two Histowrappers. Returns FloatWrapper.
"""
wrps = iterableize(wrps)
wrps = iter(wrps)
try:
first, second = next(wrps), next(wrps)
except StopIteration:
raise TooFewWrpsError("chi2 needs exactly two HistoWrappers.")
try:
wrps.next()
raise TooManyWrpsError("chi2 needs exactly two HistoWrappers.")
except StopIteration:
pass
for w in (first, second):
if not isinstance(w, wrappers.HistoWrapper):
raise WrongInputError(
"chi2 needs type HistoWrapper. w: "
+ str(w)
)
if not first.histo.GetNbinsX() == second.histo.GetNbinsX():
raise WrongInputError(
"chi2 needs histos with same number of bins."
)
if not x_max:
x_max = int(first.histo.GetNbinsX() - 1)
def get_weight_for_bin(i):
val = (first.histo.GetBinContent(i+1)
- second.histo.GetBinContent(i+1))**2
err1 = first.histo.GetBinError(i+1)
err2 = second.histo.GetBinError(i+1)
if err1 and err2:
return val / (err1**2 + err2**2)
else:
return 0.
chi2_val = __builtin__.sum(
get_weight_for_bin(i)
for i in xrange(x_min, x_max)
)
info = second.all_info()
info.update(first.all_info())
return wrappers.FloatWrapper(
chi2_val,
**info
)
@add_wrp_kws
@history.track_history
def eff(wrps, option=''):
"""
Applies to HistoWrappers only. Returns GraphWrapper. Takes lumi from first.
>>> from ROOT import TH1I
>>> h1 = TH1I("h1", "", 2, .5, 2.5)
>>> h1.Fill(1)
1
>>> h1.Fill(1)
1
>>> w1 = wrappers.HistoWrapper(h1, lumi=2)
>>> h2 = TH1I("h2", "", 2, .5, 2.5)
>>> h2.Sumw2()
>>> h2.Fill(1)
1
>>> h2.Fill(1)
1
>>> h2.Fill(1)
1
>>> h2.Fill(2)
2
>>> w2 = wrappers.HistoWrapper(h2, lumi=3)
>>> w3 = eff([w1, w2])
>>> w3.graph.GetN()
2
>>> hi = w3.graph.GetErrorYhigh(0)
>>> lo = w3.graph.GetErrorYlow(0)
>>> abs(hi - 0.277375360987) < 1e-10
True
>>> abs(lo - 0.414534706284) < 1e-10
True
"""
wrps = iterableize(wrps)
wrps = iter(wrps)
try:
nominator = next(wrps)
denominator = next(wrps)
except StopIteration:
raise TooFewWrpsError("eff needs exactly two Wrappers.")
try:
wrps.next()
raise TooManyWrpsError("eff needs exactly two Wrappers.")
except StopIteration:
pass
if not isinstance(nominator, wrappers.HistoWrapper):
raise WrongInputError(
"eff needs nominator to be of type HistoWrapper. nominator: "
+ str(nominator)
)
if not (isinstance(denominator, wrappers.HistoWrapper)):
raise WrongInputError(
"eff needs denominator to be of type HistoWrapper. denominator: "
+ str(denominator)
)
graph = TGraphAsymmErrors(nominator.histo, denominator.histo, option)
graph.GetXaxis().SetTitle(nominator.histo.GetXaxis().GetTitle())
info = nominator.all_info()
return wrappers.GraphWrapper(graph, **info)
if __name__ == "__main__":
import ROOT
ROOT.TH1.AddDirectory(False)
import doctest
doctest.testmod()
|
gpl-3.0
|
[
624,
199,
12929,
641,
17995,
199,
624,
199,
199,
646,
1625,
199,
646,
636,
5351,
363,
199,
646,
5577,
199,
646,
5055,
199,
646,
9143,
199,
504,
16547,
492,
4221,
4851,
12,
377,
4578,
33,
1786,
596,
9298,
199,
199,
646,
7994,
199,
646,
17995,
421,
199,
533,
6654,
5263,
8,
1726,
304,
986,
199,
533,
22893,
38,
546,
55,
82,
1190,
547,
8,
3632,
5263,
304,
986,
199,
533,
22893,
4089,
55,
82,
1190,
547,
8,
3632,
5263,
304,
986,
199,
533,
30801,
3205,
547,
8,
3632,
5263,
304,
986,
199,
533,
3091,
44,
453,
73,
4486,
547,
8,
3632,
5263,
304,
986,
421,
199,
318,
6076,
794,
8,
1113,
304,
272,
340,
1228,
8,
1113,
12,
5055,
14,
20852,
304,
267,
372,
1559,
272,
587,
26,
267,
372,
359,
1113,
61,
421,
199,
318,
1050,
63,
87,
4599,
63,
28769,
8,
1532,
304,
272,
408,
48,
1483,
283,
87,
4599,
63,
28769,
7,
687,
1627,
7681,
436,
7029,
2138,
4975,
1041,
339,
768,
17869,
14,
13582,
8,
1532,
9,
272,
347,
8579,
63,
87,
4599,
63,
28769,
2031,
589,
12,
1011,
28769,
304,
267,
336,
4599,
63,
28769,
275,
4775,
83,
14,
1935,
360,
87,
4599,
63,
28769,
297,
5009,
267,
2203,
275,
2562,
2031,
589,
12,
1011,
28769,
9,
267,
2203,
855,
807,
4343,
873,
8,
87,
4599,
63,
28769,
9,
267,
372,
2203,
272,
372,
8579,
63,
87,
4599,
63,
28769,
421,
199,
32,
525,
63,
87,
4599,
63,
28769,
199,
32,
5570,
14,
3885,
63,
5570,
199,
318,
3464,
8,
17097,
1190,
304,
272,
408,
272,
4693,
6528,
1454,
370,
869,
7133,
4590,
83,
14,
1803,
13894,
4590,
14,
272,
13813,
634,
453,
73,
370,
506,
4472,
16885,
1006,
17995,
14,
339,
1306,
687,
16547,
492,
4221,
17,
41,
272,
1306,
394,
17,
275,
4221,
17,
41,
480,
72,
17,
401,
4873,
499,
12,
1275,
21,
12,
841,
14,
21,
9,
272,
1306,
394,
17,
14,
12914,
8,
17,
12,
20,
9,
272,
413,
272,
1306,
336,
17,
275,
17995,
14,
40,
7133,
4590,
8,
72,
17,
12,
634,
453,
73,
29,
18,
4959,
272,
1306,
394,
18,
275,
4221,
17,
41,
480,
72,
18,
401,
4873,
499,
12,
1275,
21,
12,
841,
14,
21,
9,
272,
1306,
394,
18,
14,
12914,
8,
17,
12,
19,
9,
272,
413,
272,
1306,
394,
18,
14,
12914,
8,
19,
12,
22,
9,
272,
499,
272,
1306,
336,
18,
275,
17995,
14,
40,
7133,
4590,
8,
72,
18,
12,
634,
453,
73,
29,
18,
4959,
272,
1306,
336,
19,
275,
3464,
779,
87,
17,
12,
336,
18,
566,
272,
1306,
336,
19,
14,
72,
7133,
14,
18949,
342,
272,
4944,
14,
16,
272,
1306,
336,
19,
14,
25065,
73,
272,
499,
14,
16,
272,
408,
272,
19865,
1190,
259,
275,
6076,
794,
8,
17097,
1190,
9,
272,
410,
75,
63,
87,
4599,
275,
488,
272,
634,
453,
73,
259,
275,
378,
14,
272,
2256,
259,
275,
488,
272,
2690,
221,
275,
3087,
272,
367,
336,
4599,
315,
19865,
1190,
26,
267,
340,
440,
1228,
8,
87,
4599,
12,
17995,
14,
40,
7133,
4590,
304,
3515,
327,
394,
7133,
1104,
288,
746,
30801,
3205,
547,
8,
355,
298,
2340,
11479,
1454,
869,
7133,
4590,
83,
14,
336,
4599,
26,
298,
355,
435,
620,
8,
87,
4599,
9,
288,
776,
267,
340,
440,
410,
75,
63,
87,
4599,
26,
2476,
260,
327,
3464,
4205,
288,
410,
75,
63,
87,
4599,
275,
4221,
4851,
8,
87,
4599,
14,
354,
12,
336,
4599,
14,
1213,
9,
288,
634,
453,
73,
275,
336,
4599,
14,
25065,
73,
288,
2256,
275,
336,
4599,
14,
452,
63,
815,
342,
288,
2690,
275,
336,
4599,
14,
3271,
267,
916,
634,
453,
73,
1137,
336,
4599,
14,
25065,
73,
26,
22456,
327,
634,
453,
73,
1104,
288,
746,
3091,
44,
453,
73,
4486,
547,
8,
355,
298,
2340,
4839,
634,
453,
374,
370,
1336,
14,
4366,
70,
1137,
450,
70,
2924,
450,
334,
25065,
73,
12,
336,
4599,
14,
25065,
73,
9,
288,
776,
267,
340,
2690,
1137,
336,
4599,
14,
3271,
26,
13293,
327,
1050,
370,
3464,
288,
2690,
275,
3087,
267,
410,
75,
63,
87,
4599,
14,
1123,
8,
87,
4599,
14,
72,
7133,
9,
272,
340,
440,
2256,
26,
267,
746,
22893,
38,
546,
55,
82,
1190,
547,
8,
288,
298,
1271,
5210,
1373,
21947,
1471,
506,
2741,
2122,
267,
776,
272,
340,
440,
2690,
26,
267,
2150,
2256,
905,
3271,
937,
272,
372,
17995,
14,
4851,
4590,
8,
270,
75,
63,
87,
4599,
12,
1011,
815,
9,
421,
199,
32,
525,
63,
87,
4599,
63,
28769,
199,
32,
5570,
14,
3885,
63,
5570,
199,
318,
3089,
8,
17097,
1190,
304,
272,
408,
272,
4693,
6528,
1454,
370,
869,
7133,
4590,
83,
14,
1803,
869,
7133,
4590,
14,
15747,
634,
453,
73,
1536,
14,
2286,
1306,
687,
16547,
492,
4221,
17,
41,
272,
1306,
394,
17,
275,
4221,
17,
41,
480,
72,
17,
401,
4873,
499,
12,
1275,
21,
12,
841,
14,
21,
9,
272,
1306,
394,
17,
14,
12914,
8,
17,
9,
272,
413,
272,
1306,
336,
17,
275,
17995,
14,
40,
7133,
4590,
8,
72,
17,
12,
634,
453,
73,
29,
18,
4959,
272,
1306,
394,
18,
275,
4221,
17,
41,
480,
72,
18,
401,
4873,
499,
12,
1275,
21,
12,
841,
14,
21,
9,
272,
1306,
394,
18,
14,
12914,
8,
17,
9,
272,
413,
272,
1306,
394,
18,
14,
12914,
8,
19,
9,
272,
499,
272,
1306,
336,
18,
275,
17995,
14,
40,
7133,
4590,
8,
72,
18,
12,
634,
453,
73,
29,
19,
4959,
272,
1306,
336,
19,
275,
3089,
779,
87,
17,
12,
336,
18,
566,
272,
1306,
336,
19,
14,
72,
7133,
14,
18949,
342,
272,
650,
14,
16,
272,
1306,
336,
19,
14,
25065,
73,
272,
959,
14,
16,
272,
408,
272,
19865,
1190,
275,
6076,
794,
8,
17097,
1190,
9,
272,
394,
7133,
275,
488,
272,
634,
453,
73,
275,
378,
14,
272,
2256,
275,
488,
272,
367,
336,
4599,
315,
19865,
1190,
26,
267,
340,
440,
1228,
8,
87,
4599,
12,
17995,
14,
40,
7133,
4590,
304,
288,
746,
30801,
3205,
547,
8,
355,
298,
1838,
11479,
1454
] |
[
199,
12929,
641,
17995,
199,
624,
199,
199,
646,
1625,
199,
646,
636,
5351,
363,
199,
646,
5577,
199,
646,
5055,
199,
646,
9143,
199,
504,
16547,
492,
4221,
4851,
12,
377,
4578,
33,
1786,
596,
9298,
199,
199,
646,
7994,
199,
646,
17995,
421,
199,
533,
6654,
5263,
8,
1726,
304,
986,
199,
533,
22893,
38,
546,
55,
82,
1190,
547,
8,
3632,
5263,
304,
986,
199,
533,
22893,
4089,
55,
82,
1190,
547,
8,
3632,
5263,
304,
986,
199,
533,
30801,
3205,
547,
8,
3632,
5263,
304,
986,
199,
533,
3091,
44,
453,
73,
4486,
547,
8,
3632,
5263,
304,
986,
421,
199,
318,
6076,
794,
8,
1113,
304,
272,
340,
1228,
8,
1113,
12,
5055,
14,
20852,
304,
267,
372,
1559,
272,
587,
26,
267,
372,
359,
1113,
61,
421,
199,
318,
1050,
63,
87,
4599,
63,
28769,
8,
1532,
304,
272,
408,
48,
1483,
283,
87,
4599,
63,
28769,
7,
687,
1627,
7681,
436,
7029,
2138,
4975,
1041,
339,
768,
17869,
14,
13582,
8,
1532,
9,
272,
347,
8579,
63,
87,
4599,
63,
28769,
2031,
589,
12,
1011,
28769,
304,
267,
336,
4599,
63,
28769,
275,
4775,
83,
14,
1935,
360,
87,
4599,
63,
28769,
297,
5009,
267,
2203,
275,
2562,
2031,
589,
12,
1011,
28769,
9,
267,
2203,
855,
807,
4343,
873,
8,
87,
4599,
63,
28769,
9,
267,
372,
2203,
272,
372,
8579,
63,
87,
4599,
63,
28769,
421,
199,
32,
525,
63,
87,
4599,
63,
28769,
199,
32,
5570,
14,
3885,
63,
5570,
199,
318,
3464,
8,
17097,
1190,
304,
272,
408,
272,
4693,
6528,
1454,
370,
869,
7133,
4590,
83,
14,
1803,
13894,
4590,
14,
272,
13813,
634,
453,
73,
370,
506,
4472,
16885,
1006,
17995,
14,
339,
1306,
687,
16547,
492,
4221,
17,
41,
272,
1306,
394,
17,
275,
4221,
17,
41,
480,
72,
17,
401,
4873,
499,
12,
1275,
21,
12,
841,
14,
21,
9,
272,
1306,
394,
17,
14,
12914,
8,
17,
12,
20,
9,
272,
413,
272,
1306,
336,
17,
275,
17995,
14,
40,
7133,
4590,
8,
72,
17,
12,
634,
453,
73,
29,
18,
4959,
272,
1306,
394,
18,
275,
4221,
17,
41,
480,
72,
18,
401,
4873,
499,
12,
1275,
21,
12,
841,
14,
21,
9,
272,
1306,
394,
18,
14,
12914,
8,
17,
12,
19,
9,
272,
413,
272,
1306,
394,
18,
14,
12914,
8,
19,
12,
22,
9,
272,
499,
272,
1306,
336,
18,
275,
17995,
14,
40,
7133,
4590,
8,
72,
18,
12,
634,
453,
73,
29,
18,
4959,
272,
1306,
336,
19,
275,
3464,
779,
87,
17,
12,
336,
18,
566,
272,
1306,
336,
19,
14,
72,
7133,
14,
18949,
342,
272,
4944,
14,
16,
272,
1306,
336,
19,
14,
25065,
73,
272,
499,
14,
16,
272,
408,
272,
19865,
1190,
259,
275,
6076,
794,
8,
17097,
1190,
9,
272,
410,
75,
63,
87,
4599,
275,
488,
272,
634,
453,
73,
259,
275,
378,
14,
272,
2256,
259,
275,
488,
272,
2690,
221,
275,
3087,
272,
367,
336,
4599,
315,
19865,
1190,
26,
267,
340,
440,
1228,
8,
87,
4599,
12,
17995,
14,
40,
7133,
4590,
304,
3515,
327,
394,
7133,
1104,
288,
746,
30801,
3205,
547,
8,
355,
298,
2340,
11479,
1454,
869,
7133,
4590,
83,
14,
336,
4599,
26,
298,
355,
435,
620,
8,
87,
4599,
9,
288,
776,
267,
340,
440,
410,
75,
63,
87,
4599,
26,
2476,
260,
327,
3464,
4205,
288,
410,
75,
63,
87,
4599,
275,
4221,
4851,
8,
87,
4599,
14,
354,
12,
336,
4599,
14,
1213,
9,
288,
634,
453,
73,
275,
336,
4599,
14,
25065,
73,
288,
2256,
275,
336,
4599,
14,
452,
63,
815,
342,
288,
2690,
275,
336,
4599,
14,
3271,
267,
916,
634,
453,
73,
1137,
336,
4599,
14,
25065,
73,
26,
22456,
327,
634,
453,
73,
1104,
288,
746,
3091,
44,
453,
73,
4486,
547,
8,
355,
298,
2340,
4839,
634,
453,
374,
370,
1336,
14,
4366,
70,
1137,
450,
70,
2924,
450,
334,
25065,
73,
12,
336,
4599,
14,
25065,
73,
9,
288,
776,
267,
340,
2690,
1137,
336,
4599,
14,
3271,
26,
13293,
327,
1050,
370,
3464,
288,
2690,
275,
3087,
267,
410,
75,
63,
87,
4599,
14,
1123,
8,
87,
4599,
14,
72,
7133,
9,
272,
340,
440,
2256,
26,
267,
746,
22893,
38,
546,
55,
82,
1190,
547,
8,
288,
298,
1271,
5210,
1373,
21947,
1471,
506,
2741,
2122,
267,
776,
272,
340,
440,
2690,
26,
267,
2150,
2256,
905,
3271,
937,
272,
372,
17995,
14,
4851,
4590,
8,
270,
75,
63,
87,
4599,
12,
1011,
815,
9,
421,
199,
32,
525,
63,
87,
4599,
63,
28769,
199,
32,
5570,
14,
3885,
63,
5570,
199,
318,
3089,
8,
17097,
1190,
304,
272,
408,
272,
4693,
6528,
1454,
370,
869,
7133,
4590,
83,
14,
1803,
869,
7133,
4590,
14,
15747,
634,
453,
73,
1536,
14,
2286,
1306,
687,
16547,
492,
4221,
17,
41,
272,
1306,
394,
17,
275,
4221,
17,
41,
480,
72,
17,
401,
4873,
499,
12,
1275,
21,
12,
841,
14,
21,
9,
272,
1306,
394,
17,
14,
12914,
8,
17,
9,
272,
413,
272,
1306,
336,
17,
275,
17995,
14,
40,
7133,
4590,
8,
72,
17,
12,
634,
453,
73,
29,
18,
4959,
272,
1306,
394,
18,
275,
4221,
17,
41,
480,
72,
18,
401,
4873,
499,
12,
1275,
21,
12,
841,
14,
21,
9,
272,
1306,
394,
18,
14,
12914,
8,
17,
9,
272,
413,
272,
1306,
394,
18,
14,
12914,
8,
19,
9,
272,
499,
272,
1306,
336,
18,
275,
17995,
14,
40,
7133,
4590,
8,
72,
18,
12,
634,
453,
73,
29,
19,
4959,
272,
1306,
336,
19,
275,
3089,
779,
87,
17,
12,
336,
18,
566,
272,
1306,
336,
19,
14,
72,
7133,
14,
18949,
342,
272,
650,
14,
16,
272,
1306,
336,
19,
14,
25065,
73,
272,
959,
14,
16,
272,
408,
272,
19865,
1190,
275,
6076,
794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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
] |
nmercier/linux-cross-gcc
|
linux/lib/python2.7/dist-packages/numpy/distutils/extension.py
|
162
|
3043
|
"""distutils.extension
Provides the Extension class, used to describe C/C++ extension
modules in setup scripts.
Overridden to support f2py.
"""
from __future__ import division, absolute_import, print_function
import sys
import re
from distutils.extension import Extension as old_Extension
if sys.version_info[0] >= 3:
basestring = str
cxx_ext_re = re.compile(r'.*[.](cpp|cxx|cc)\Z', re.I).match
fortran_pyf_ext_re = re.compile(r'.*[.](f90|f95|f77|for|ftn|f|pyf)\Z', re.I).match
class Extension(old_Extension):
def __init__ (self, name, sources,
include_dirs=None,
define_macros=None,
undef_macros=None,
library_dirs=None,
libraries=None,
runtime_library_dirs=None,
extra_objects=None,
extra_compile_args=None,
extra_link_args=None,
export_symbols=None,
swig_opts=None,
depends=None,
language=None,
f2py_options=None,
module_dirs=None,
extra_f77_compile_args=None,
extra_f90_compile_args=None,
):
old_Extension.__init__(self, name, [],
include_dirs,
define_macros,
undef_macros,
library_dirs,
libraries,
runtime_library_dirs,
extra_objects,
extra_compile_args,
extra_link_args,
export_symbols)
# Avoid assert statements checking that sources contains strings:
self.sources = sources
# Python 2.4 distutils new features
self.swig_opts = swig_opts or []
# swig_opts is assumed to be a list. Here we handle the case where it
# is specified as a string instead.
if isinstance(self.swig_opts, basestring):
import warnings
msg = "swig_opts is specified as a string instead of a list"
warnings.warn(msg, SyntaxWarning)
self.swig_opts = self.swig_opts.split()
# Python 2.3 distutils new features
self.depends = depends or []
self.language = language
# numpy_distutils features
self.f2py_options = f2py_options or []
self.module_dirs = module_dirs or []
self.extra_f77_compile_args = extra_f77_compile_args or []
self.extra_f90_compile_args = extra_f90_compile_args or []
return
def has_cxx_sources(self):
for source in self.sources:
if cxx_ext_re(str(source)):
return True
return False
def has_f2py_sources(self):
for source in self.sources:
if fortran_pyf_ext_re(source):
return True
return False
# class Extension
|
bsd-3-clause
|
[
624,
13350,
14,
3435,
199,
199,
17473,
314,
13282,
1021,
12,
1202,
370,
13743,
445,
15,
35,
4176,
3329,
199,
3112,
315,
3272,
10554,
14,
199,
199,
5674,
8639,
370,
2291,
289,
18,
647,
14,
199,
199,
624,
199,
504,
636,
2443,
363,
492,
4629,
12,
3679,
63,
646,
12,
870,
63,
1593,
199,
199,
646,
984,
199,
646,
295,
199,
504,
7065,
14,
3435,
492,
13282,
465,
2269,
63,
6382,
199,
199,
692,
984,
14,
1023,
63,
815,
59,
16,
61,
2356,
650,
26,
272,
7116,
275,
620,
421,
199,
9634,
63,
832,
63,
264,
275,
295,
14,
2014,
8,
82,
1370,
23033,
14,
8738,
5910,
92,
9634,
92,
2055,
2862,
58,
297,
295,
14,
41,
680,
1431,
199,
18496,
63,
647,
70,
63,
832,
63,
264,
275,
295,
14,
2014,
8,
82,
1370,
23033,
14,
8738,
70,
2710,
92,
70,
2720,
92,
70,
1138,
92,
509,
92,
856,
78,
92,
70,
92,
647,
70,
2862,
58,
297,
295,
14,
41,
680,
1431,
199,
199,
533,
13282,
8,
1753,
63,
6382,
304,
272,
347,
636,
826,
363,
334,
277,
12,
536,
12,
5274,
12,
2116,
2387,
63,
3220,
29,
403,
12,
2116,
5627,
63,
16358,
29,
403,
12,
2116,
625,
318,
63,
16358,
29,
403,
12,
2116,
3555,
63,
3220,
29,
403,
12,
2116,
8363,
29,
403,
12,
2116,
8836,
63,
4342,
63,
3220,
29,
403,
12,
2116,
2402,
63,
1462,
29,
403,
12,
2116,
2402,
63,
2014,
63,
589,
29,
403,
12,
2116,
2402,
63,
1073,
63,
589,
29,
403,
12,
2116,
4843,
63,
7450,
29,
403,
12,
2116,
30057,
63,
3291,
29,
403,
12,
2116,
8350,
29,
403,
12,
2116,
2637,
29,
403,
12,
2116,
289,
18,
647,
63,
1419,
29,
403,
12,
2116,
859,
63,
3220,
29,
403,
12,
2116,
2402,
63,
70,
1138,
63,
2014,
63,
589,
29,
403,
12,
2116,
2402,
63,
70,
2710,
63,
2014,
63,
589,
29,
403,
12,
326,
3461,
267,
2269,
63,
6382,
855,
826,
721,
277,
12,
536,
12,
990,
3044,
2387,
63,
3220,
12,
3044,
5627,
63,
16358,
12,
3044,
625,
318,
63,
16358,
12,
3044,
3555,
63,
3220,
12,
3044,
8363,
12,
3044,
8836,
63,
4342,
63,
3220,
12,
3044,
2402,
63,
1462,
12,
3044,
2402,
63,
2014,
63,
589,
12,
3044,
2402,
63,
1073,
63,
589,
12,
3044,
4843,
63,
7450,
9,
267,
327,
19503,
702,
9834,
7907,
626,
5274,
3509,
3326,
26,
267,
291,
14,
4553,
275,
5274,
398,
327,
2018,
499,
14,
20,
7065,
892,
4534,
267,
291,
14,
9676,
63,
3291,
275,
30057,
63,
3291,
503,
942,
267,
327,
30057,
63,
3291,
365,
10826,
370,
506,
282,
769,
14,
11842,
781,
2429,
314,
1930,
2382,
652,
267,
327,
365,
2013,
465,
282,
1059,
3140,
14,
267,
340,
1228,
8,
277,
14,
9676,
63,
3291,
12,
7116,
304,
288,
492,
3598,
288,
1499,
275,
298,
9676,
63,
3291,
365,
2013,
465,
282,
1059,
3140,
402,
282,
769,
2,
288,
3598,
14,
4050,
8,
1328,
12,
18377,
3849,
9,
288,
291,
14,
9676,
63,
3291,
275,
291,
14,
9676,
63,
3291,
14,
1294,
342,
398,
327,
2018,
499,
14,
19,
7065,
892,
4534,
267,
291,
14,
8912,
275,
8350,
503,
942,
267,
291,
14,
3671,
275,
2637,
398,
327,
2680,
63,
13350,
4534,
267,
291,
14,
70,
18,
647,
63,
1419,
275,
289,
18,
647,
63,
1419,
503,
942,
267,
291,
14,
578,
63,
3220,
275,
859,
63,
3220,
503,
942,
267,
291,
14,
2911,
63,
70,
1138,
63,
2014,
63,
589,
275,
2402,
63,
70,
1138,
63,
2014,
63,
589,
503,
942,
267,
291,
14,
2911,
63,
70,
2710,
63,
2014,
63,
589,
275,
2402,
63,
70,
2710,
63,
2014,
63,
589,
503,
942,
398,
372,
339,
347,
965,
63,
9634,
63,
4553,
8,
277,
304,
267,
367,
1350,
315,
291,
14,
4553,
26,
288,
340,
17327,
63,
832,
63,
264,
8,
495,
8,
1365,
2298,
355,
372,
715,
267,
372,
756,
339,
347,
965,
63,
70,
18,
647,
63,
4553,
8,
277,
304,
267,
367,
1350,
315,
291,
14,
4553,
26,
288,
340,
289,
14522,
63,
647,
70,
63,
832,
63,
264,
8,
1365,
304,
355,
372,
715,
267,
372,
756,
199,
199,
3,
1021,
13282,
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
] |
[
13350,
14,
3435,
199,
199,
17473,
314,
13282,
1021,
12,
1202,
370,
13743,
445,
15,
35,
4176,
3329,
199,
3112,
315,
3272,
10554,
14,
199,
199,
5674,
8639,
370,
2291,
289,
18,
647,
14,
199,
199,
624,
199,
504,
636,
2443,
363,
492,
4629,
12,
3679,
63,
646,
12,
870,
63,
1593,
199,
199,
646,
984,
199,
646,
295,
199,
504,
7065,
14,
3435,
492,
13282,
465,
2269,
63,
6382,
199,
199,
692,
984,
14,
1023,
63,
815,
59,
16,
61,
2356,
650,
26,
272,
7116,
275,
620,
421,
199,
9634,
63,
832,
63,
264,
275,
295,
14,
2014,
8,
82,
1370,
23033,
14,
8738,
5910,
92,
9634,
92,
2055,
2862,
58,
297,
295,
14,
41,
680,
1431,
199,
18496,
63,
647,
70,
63,
832,
63,
264,
275,
295,
14,
2014,
8,
82,
1370,
23033,
14,
8738,
70,
2710,
92,
70,
2720,
92,
70,
1138,
92,
509,
92,
856,
78,
92,
70,
92,
647,
70,
2862,
58,
297,
295,
14,
41,
680,
1431,
199,
199,
533,
13282,
8,
1753,
63,
6382,
304,
272,
347,
636,
826,
363,
334,
277,
12,
536,
12,
5274,
12,
2116,
2387,
63,
3220,
29,
403,
12,
2116,
5627,
63,
16358,
29,
403,
12,
2116,
625,
318,
63,
16358,
29,
403,
12,
2116,
3555,
63,
3220,
29,
403,
12,
2116,
8363,
29,
403,
12,
2116,
8836,
63,
4342,
63,
3220,
29,
403,
12,
2116,
2402,
63,
1462,
29,
403,
12,
2116,
2402,
63,
2014,
63,
589,
29,
403,
12,
2116,
2402,
63,
1073,
63,
589,
29,
403,
12,
2116,
4843,
63,
7450,
29,
403,
12,
2116,
30057,
63,
3291,
29,
403,
12,
2116,
8350,
29,
403,
12,
2116,
2637,
29,
403,
12,
2116,
289,
18,
647,
63,
1419,
29,
403,
12,
2116,
859,
63,
3220,
29,
403,
12,
2116,
2402,
63,
70,
1138,
63,
2014,
63,
589,
29,
403,
12,
2116,
2402,
63,
70,
2710,
63,
2014,
63,
589,
29,
403,
12,
326,
3461,
267,
2269,
63,
6382,
855,
826,
721,
277,
12,
536,
12,
990,
3044,
2387,
63,
3220,
12,
3044,
5627,
63,
16358,
12,
3044,
625,
318,
63,
16358,
12,
3044,
3555,
63,
3220,
12,
3044,
8363,
12,
3044,
8836,
63,
4342,
63,
3220,
12,
3044,
2402,
63,
1462,
12,
3044,
2402,
63,
2014,
63,
589,
12,
3044,
2402,
63,
1073,
63,
589,
12,
3044,
4843,
63,
7450,
9,
267,
327,
19503,
702,
9834,
7907,
626,
5274,
3509,
3326,
26,
267,
291,
14,
4553,
275,
5274,
398,
327,
2018,
499,
14,
20,
7065,
892,
4534,
267,
291,
14,
9676,
63,
3291,
275,
30057,
63,
3291,
503,
942,
267,
327,
30057,
63,
3291,
365,
10826,
370,
506,
282,
769,
14,
11842,
781,
2429,
314,
1930,
2382,
652,
267,
327,
365,
2013,
465,
282,
1059,
3140,
14,
267,
340,
1228,
8,
277,
14,
9676,
63,
3291,
12,
7116,
304,
288,
492,
3598,
288,
1499,
275,
298,
9676,
63,
3291,
365,
2013,
465,
282,
1059,
3140,
402,
282,
769,
2,
288,
3598,
14,
4050,
8,
1328,
12,
18377,
3849,
9,
288,
291,
14,
9676,
63,
3291,
275,
291,
14,
9676,
63,
3291,
14,
1294,
342,
398,
327,
2018,
499,
14,
19,
7065,
892,
4534,
267,
291,
14,
8912,
275,
8350,
503,
942,
267,
291,
14,
3671,
275,
2637,
398,
327,
2680,
63,
13350,
4534,
267,
291,
14,
70,
18,
647,
63,
1419,
275,
289,
18,
647,
63,
1419,
503,
942,
267,
291,
14,
578,
63,
3220,
275,
859,
63,
3220,
503,
942,
267,
291,
14,
2911,
63,
70,
1138,
63,
2014,
63,
589,
275,
2402,
63,
70,
1138,
63,
2014,
63,
589,
503,
942,
267,
291,
14,
2911,
63,
70,
2710,
63,
2014,
63,
589,
275,
2402,
63,
70,
2710,
63,
2014,
63,
589,
503,
942,
398,
372,
339,
347,
965,
63,
9634,
63,
4553,
8,
277,
304,
267,
367,
1350,
315,
291,
14,
4553,
26,
288,
340,
17327,
63,
832,
63,
264,
8,
495,
8,
1365,
2298,
355,
372,
715,
267,
372,
756,
339,
347,
965,
63,
70,
18,
647,
63,
4553,
8,
277,
304,
267,
367,
1350,
315,
291,
14,
4553,
26,
288,
340,
289,
14522,
63,
647,
70,
63,
832,
63,
264,
8,
1365,
304,
355,
372,
715,
267,
372,
756,
199,
199,
3,
1021,
13282,
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,
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,
0
] |
jhoffmann/lcd-notification
|
Adafruit_CharLCDPlate.py
|
22
|
18347
|
#!/usr/bin/python
# Python library for Adafruit RGB-backlit LCD plate for Raspberry Pi.
# Written by Adafruit Industries. MIT license.
# This is essentially a complete rewrite, but the calling syntax
# and constants are based on code from lrvick and LiquidCrystal.
# lrvic - https://github.com/lrvick/raspi-hd44780/blob/master/hd44780.py
# LiquidCrystal - https://github.com/arduino/Arduino/blob/master/libraries/LiquidCrystal/LiquidCrystal.cpp
from Adafruit_I2C import Adafruit_I2C
from time import sleep
class Adafruit_CharLCDPlate(Adafruit_I2C):
# ----------------------------------------------------------------------
# Constants
# Port expander registers
MCP23017_IOCON_BANK0 = 0x0A # IOCON when Bank 0 active
MCP23017_IOCON_BANK1 = 0x15 # IOCON when Bank 1 active
# These are register addresses when in Bank 1 only:
MCP23017_GPIOA = 0x09
MCP23017_IODIRB = 0x10
MCP23017_GPIOB = 0x19
# Port expander input pin definitions
SELECT = 0
RIGHT = 1
DOWN = 2
UP = 3
LEFT = 4
# LED colors
OFF = 0x00
RED = 0x01
GREEN = 0x02
BLUE = 0x04
YELLOW = RED + GREEN
TEAL = GREEN + BLUE
VIOLET = RED + BLUE
WHITE = RED + GREEN + BLUE
ON = RED + GREEN + BLUE
# LCD Commands
LCD_CLEARDISPLAY = 0x01
LCD_RETURNHOME = 0x02
LCD_ENTRYMODESET = 0x04
LCD_DISPLAYCONTROL = 0x08
LCD_CURSORSHIFT = 0x10
LCD_FUNCTIONSET = 0x20
LCD_SETCGRAMADDR = 0x40
LCD_SETDDRAMADDR = 0x80
# Flags for display on/off control
LCD_DISPLAYON = 0x04
LCD_DISPLAYOFF = 0x00
LCD_CURSORON = 0x02
LCD_CURSOROFF = 0x00
LCD_BLINKON = 0x01
LCD_BLINKOFF = 0x00
# Flags for display entry mode
LCD_ENTRYRIGHT = 0x00
LCD_ENTRYLEFT = 0x02
LCD_ENTRYSHIFTINCREMENT = 0x01
LCD_ENTRYSHIFTDECREMENT = 0x00
# Flags for display/cursor shift
LCD_DISPLAYMOVE = 0x08
LCD_CURSORMOVE = 0x00
LCD_MOVERIGHT = 0x04
LCD_MOVELEFT = 0x00
# ----------------------------------------------------------------------
# Constructor
def __init__(self, busnum=-1, addr=0x20, debug=False):
self.i2c = Adafruit_I2C(addr, busnum, debug)
# I2C is relatively slow. MCP output port states are cached
# so we don't need to constantly poll-and-change bit states.
self.porta, self.portb, self.ddrb = 0, 0, 0b00010000
# Set MCP23017 IOCON register to Bank 0 with sequential operation.
# If chip is already set for Bank 0, this will just write to OLATB,
# which won't seriously bother anything on the plate right now
# (blue backlight LED will come on, but that's done in the next
# step anyway).
self.i2c.bus.write_byte_data(
self.i2c.address, self.MCP23017_IOCON_BANK1, 0)
# Brute force reload ALL registers to known state. This also
# sets up all the input pins, pull-ups, etc. for the Pi Plate.
self.i2c.bus.write_i2c_block_data(
self.i2c.address, 0,
[ 0b00111111, # IODIRA R+G LEDs=outputs, buttons=inputs
self.ddrb , # IODIRB LCD D7=input, Blue LED=output
0b00111111, # IPOLA Invert polarity on button inputs
0b00000000, # IPOLB
0b00000000, # GPINTENA Disable interrupt-on-change
0b00000000, # GPINTENB
0b00000000, # DEFVALA
0b00000000, # DEFVALB
0b00000000, # INTCONA
0b00000000, # INTCONB
0b00000000, # IOCON
0b00000000, # IOCON
0b00111111, # GPPUA Enable pull-ups on buttons
0b00000000, # GPPUB
0b00000000, # INTFA
0b00000000, # INTFB
0b00000000, # INTCAPA
0b00000000, # INTCAPB
self.porta, # GPIOA
self.portb, # GPIOB
self.porta, # OLATA 0 on all outputs; side effect of
self.portb ]) # OLATB turning on R+G+B backlight LEDs.
# Switch to Bank 1 and disable sequential operation.
# From this point forward, the register addresses do NOT match
# the list immediately above. Instead, use the constants defined
# at the start of the class. Also, the address register will no
# longer increment automatically after this -- multi-byte
# operations must be broken down into single-byte calls.
self.i2c.bus.write_byte_data(
self.i2c.address, self.MCP23017_IOCON_BANK0, 0b10100000)
self.displayshift = (self.LCD_CURSORMOVE |
self.LCD_MOVERIGHT)
self.displaymode = (self.LCD_ENTRYLEFT |
self.LCD_ENTRYSHIFTDECREMENT)
self.displaycontrol = (self.LCD_DISPLAYON |
self.LCD_CURSOROFF |
self.LCD_BLINKOFF)
self.write(0x33) # Init
self.write(0x32) # Init
self.write(0x28) # 2 line 5x8 matrix
self.write(self.LCD_CLEARDISPLAY)
self.write(self.LCD_CURSORSHIFT | self.displayshift)
self.write(self.LCD_ENTRYMODESET | self.displaymode)
self.write(self.LCD_DISPLAYCONTROL | self.displaycontrol)
self.write(self.LCD_RETURNHOME)
# ----------------------------------------------------------------------
# Write operations
# The LCD data pins (D4-D7) connect to MCP pins 12-9 (PORTB4-1), in
# that order. Because this sequence is 'reversed,' a direct shift
# won't work. This table remaps 4-bit data values to MCP PORTB
# outputs, incorporating both the reverse and shift.
flip = ( 0b00000000, 0b00010000, 0b00001000, 0b00011000,
0b00000100, 0b00010100, 0b00001100, 0b00011100,
0b00000010, 0b00010010, 0b00001010, 0b00011010,
0b00000110, 0b00010110, 0b00001110, 0b00011110 )
# Low-level 4-bit interface for LCD output. This doesn't actually
# write data, just returns a byte array of the PORTB state over time.
# Can concatenate the output of multiple calls (up to 8) for more
# efficient batch write.
def out4(self, bitmask, value):
hi = bitmask | self.flip[value >> 4]
lo = bitmask | self.flip[value & 0x0F]
return [hi | 0b00100000, hi, lo | 0b00100000, lo]
# The speed of LCD accesses is inherently limited by I2C through the
# port expander. A 'well behaved program' is expected to poll the
# LCD to know that a prior instruction completed. But the timing of
# most instructions is a known uniform 37 mS. The enable strobe
# can't even be twiddled that fast through I2C, so it's a safe bet
# with these instructions to not waste time polling (which requires
# several I2C transfers for reconfiguring the port direction).
# The D7 pin is set as input when a potentially time-consuming
# instruction has been issued (e.g. screen clear), as well as on
# startup, and polling will then occur before more commands or data
# are issued.
pollables = ( LCD_CLEARDISPLAY, LCD_RETURNHOME )
# Write byte, list or string value to LCD
def write(self, value, char_mode=False):
""" Send command/data to LCD """
# If pin D7 is in input state, poll LCD busy flag until clear.
if self.ddrb & 0b00010000:
lo = (self.portb & 0b00000001) | 0b01000000
hi = lo | 0b00100000 # E=1 (strobe)
self.i2c.bus.write_byte_data(
self.i2c.address, self.MCP23017_GPIOB, lo)
while True:
# Strobe high (enable)
self.i2c.bus.write_byte(self.i2c.address, hi)
# First nybble contains busy state
bits = self.i2c.bus.read_byte(self.i2c.address)
# Strobe low, high, low. Second nybble (A3) is ignored.
self.i2c.bus.write_i2c_block_data(
self.i2c.address, self.MCP23017_GPIOB, [lo, hi, lo])
if (bits & 0b00000010) == 0: break # D7=0, not busy
self.portb = lo
# Polling complete, change D7 pin to output
self.ddrb &= 0b11101111
self.i2c.bus.write_byte_data(self.i2c.address,
self.MCP23017_IODIRB, self.ddrb)
bitmask = self.portb & 0b00000001 # Mask out PORTB LCD control bits
if char_mode: bitmask |= 0b10000000 # Set data bit if not a command
# If string or list, iterate through multiple write ops
if isinstance(value, str):
last = len(value) - 1 # Last character in string
data = [] # Start with blank list
for i, v in enumerate(value): # For each character...
# Append 4 bytes to list representing PORTB over time.
# First the high 4 data bits with strobe (enable) set
# and unset, then same with low 4 data bits (strobe 1/0).
data.extend(self.out4(bitmask, ord(v)))
# I2C block data write is limited to 32 bytes max.
# If limit reached, write data so far and clear.
# Also do this on last byte if not otherwise handled.
if (len(data) >= 32) or (i == last):
self.i2c.bus.write_i2c_block_data(
self.i2c.address, self.MCP23017_GPIOB, data)
self.portb = data[-1] # Save state of last byte out
data = [] # Clear list for next iteration
elif isinstance(value, list):
# Same as above, but for list instead of string
last = len(value) - 1
data = []
for i, v in enumerate(value):
data.extend(self.out4(bitmask, v))
if (len(data) >= 32) or (i == last):
self.i2c.bus.write_i2c_block_data(
self.i2c.address, self.MCP23017_GPIOB, data)
self.portb = data[-1]
data = []
else:
# Single byte
data = self.out4(bitmask, value)
self.i2c.bus.write_i2c_block_data(
self.i2c.address, self.MCP23017_GPIOB, data)
self.portb = data[-1]
# If a poll-worthy instruction was issued, reconfigure D7
# pin as input to indicate need for polling on next call.
if (not char_mode) and (value in self.pollables):
self.ddrb |= 0b00010000
self.i2c.bus.write_byte_data(self.i2c.address,
self.MCP23017_IODIRB, self.ddrb)
# ----------------------------------------------------------------------
# Utility methods
def begin(self, cols, lines):
self.currline = 0
self.numlines = lines
self.clear()
# Puts the MCP23017 back in Bank 0 + sequential write mode so
# that other code using the 'classic' library can still work.
# Any code using this newer version of the library should
# consider adding an atexit() handler that calls this.
def stop(self):
self.porta = 0b11000000 # Turn off LEDs on the way out
self.portb = 0b00000001
sleep(0.0015)
self.i2c.bus.write_byte_data(
self.i2c.address, self.MCP23017_IOCON_BANK1, 0)
self.i2c.bus.write_i2c_block_data(
self.i2c.address, 0,
[ 0b00111111, # IODIRA
self.ddrb , # IODIRB
0b00000000, # IPOLA
0b00000000, # IPOLB
0b00000000, # GPINTENA
0b00000000, # GPINTENB
0b00000000, # DEFVALA
0b00000000, # DEFVALB
0b00000000, # INTCONA
0b00000000, # INTCONB
0b00000000, # IOCON
0b00000000, # IOCON
0b00111111, # GPPUA
0b00000000, # GPPUB
0b00000000, # INTFA
0b00000000, # INTFB
0b00000000, # INTCAPA
0b00000000, # INTCAPB
self.porta, # GPIOA
self.portb, # GPIOB
self.porta, # OLATA
self.portb ]) # OLATB
def clear(self):
self.write(self.LCD_CLEARDISPLAY)
def home(self):
self.write(self.LCD_RETURNHOME)
row_offsets = ( 0x00, 0x40, 0x14, 0x54 )
def setCursor(self, col, row):
if row > self.numlines: row = self.numlines - 1
elif row < 0: row = 0
self.write(self.LCD_SETDDRAMADDR | (col + self.row_offsets[row]))
def display(self):
""" Turn the display on (quickly) """
self.displaycontrol |= self.LCD_DISPLAYON
self.write(self.LCD_DISPLAYCONTROL | self.displaycontrol)
def noDisplay(self):
""" Turn the display off (quickly) """
self.displaycontrol &= ~self.LCD_DISPLAYON
self.write(self.LCD_DISPLAYCONTROL | self.displaycontrol)
def cursor(self):
""" Underline cursor on """
self.displaycontrol |= self.LCD_CURSORON
self.write(self.LCD_DISPLAYCONTROL | self.displaycontrol)
def noCursor(self):
""" Underline cursor off """
self.displaycontrol &= ~self.LCD_CURSORON
self.write(self.LCD_DISPLAYCONTROL | self.displaycontrol)
def ToggleCursor(self):
""" Toggles the underline cursor On/Off """
self.displaycontrol ^= self.LCD_CURSORON
self.write(self.LCD_DISPLAYCONTROL | self.displaycontrol)
def blink(self):
""" Turn on the blinking cursor """
self.displaycontrol |= self.LCD_BLINKON
self.write(self.LCD_DISPLAYCONTROL | self.displaycontrol)
def noBlink(self):
""" Turn off the blinking cursor """
self.displaycontrol &= ~self.LCD_BLINKON
self.write(self.LCD_DISPLAYCONTROL | self.displaycontrol)
def ToggleBlink(self):
""" Toggles the blinking cursor """
self.displaycontrol ^= self.LCD_BLINKON
self.write(self.LCD_DISPLAYCONTROL | self.displaycontrol)
def scrollDisplayLeft(self):
""" These commands scroll the display without changing the RAM """
self.displayshift = self.LCD_DISPLAYMOVE | self.LCD_MOVELEFT
self.write(self.LCD_CURSORSHIFT | self.displayshift)
def scrollDisplayRight(self):
""" These commands scroll the display without changing the RAM """
self.displayshift = self.LCD_DISPLAYMOVE | self.LCD_MOVERIGHT
self.write(self.LCD_CURSORSHIFT | self.displayshift)
def leftToRight(self):
""" This is for text that flows left to right """
self.displaymode |= self.LCD_ENTRYLEFT
self.write(self.LCD_ENTRYMODESET | self.displaymode)
def rightToLeft(self):
""" This is for text that flows right to left """
self.displaymode &= ~self.LCD_ENTRYLEFT
self.write(self.LCD_ENTRYMODESET | self.displaymode)
def autoscroll(self):
""" This will 'right justify' text from the cursor """
self.displaymode |= self.LCD_ENTRYSHIFTINCREMENT
self.write(self.LCD_ENTRYMODESET | self.displaymode)
def noAutoscroll(self):
""" This will 'left justify' text from the cursor """
self.displaymode &= ~self.LCD_ENTRYSHIFTINCREMENT
self.write(self.LCD_ENTRYMODESET | self.displaymode)
def createChar(self, location, bitmap):
self.write(self.LCD_SETCGRAMADDR | ((location & 7) << 3))
self.write(bitmap, True)
self.write(self.LCD_SETDDRAMADDR)
def message(self, text):
""" Send string to LCD. Newline wraps to second line"""
lines = str(text).split('\n') # Split at newline(s)
for i, line in enumerate(lines): # For each substring...
if i > 0: # If newline(s),
self.write(0xC0) # set DDRAM address to 2nd line
self.write(line, True) # Issue substring
def backlight(self, color):
c = ~color
self.porta = (self.porta & 0b00111111) | ((c & 0b011) << 6)
self.portb = (self.portb & 0b11111110) | ((c & 0b100) >> 2)
# Has to be done as two writes because sequential operation is off.
self.i2c.bus.write_byte_data(
self.i2c.address, self.MCP23017_GPIOA, self.porta)
self.i2c.bus.write_byte_data(
self.i2c.address, self.MCP23017_GPIOB, self.portb)
# Read state of single button
def buttonPressed(self, b):
return (self.i2c.readU8(self.MCP23017_GPIOA) >> b) & 1
# Read and return bitmask of combined button state
def buttons(self):
return self.i2c.readU8(self.MCP23017_GPIOA) & 0b11111
# ----------------------------------------------------------------------
# Test code
if __name__ == '__main__':
lcd = Adafruit_CharLCDPlate()
lcd.begin(16, 2)
lcd.clear()
lcd.message("Adafruit RGB LCD\nPlate w/Keypad!")
sleep(1)
col = (('Red' , lcd.RED) , ('Yellow', lcd.YELLOW), ('Green' , lcd.GREEN),
('Teal', lcd.TEAL), ('Blue' , lcd.BLUE) , ('Violet', lcd.VIOLET),
('Off' , lcd.OFF) , ('On' , lcd.ON))
print "Cycle thru backlight colors"
for c in col:
print c[0]
lcd.clear()
lcd.message(c[0])
lcd.backlight(c[1])
sleep(0.5)
btn = ((lcd.SELECT, 'Select', lcd.ON),
(lcd.LEFT , 'Left' , lcd.RED),
(lcd.UP , 'Up' , lcd.BLUE),
(lcd.DOWN , 'Down' , lcd.GREEN),
(lcd.RIGHT , 'Right' , lcd.VIOLET))
print "Try buttons on plate"
lcd.clear()
lcd.message("Try buttons")
prev = -1
while True:
for b in btn:
if lcd.buttonPressed(b[0]):
if b is not prev:
print b[1]
lcd.clear()
lcd.message(b[1])
lcd.backlight(b[2])
prev = b
break
|
mit
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
199,
3,
2018,
3555,
367,
437,
983,
4391,
4993,
19013,
13,
894,
1051,
491,
7695,
299,
750,
367,
820,
20222,
605,
651,
19835,
14,
199,
3,
27694,
701,
437,
983,
4391,
4993,
473,
977,
85,
816,
397,
14,
221,
10697,
4190,
14,
199,
199,
3,
961,
365,
28891,
282,
4890,
19913,
12,
1325,
314,
6358,
6302,
199,
3,
436,
5262,
787,
4079,
641,
1233,
687,
13645,
433,
346,
436,
24157,
28398,
35,
651,
32100,
14,
199,
3,
13645,
31629,
446,
4178,
921,
5031,
14,
957,
15,
7493,
433,
346,
15,
6360,
1038,
13,
7952,
20773,
1257,
15,
6582,
15,
4133,
15,
7952,
20773,
1257,
14,
647,
199,
3,
24157,
28398,
35,
651,
32100,
446,
4178,
921,
5031,
14,
957,
15,
1005,
85,
10175,
15,
31924,
10175,
15,
6582,
15,
4133,
15,
10159,
15,
13009,
28398,
35,
651,
32100,
15,
13009,
28398,
35,
651,
32100,
14,
5910,
199,
199,
504,
437,
983,
4391,
4993,
63,
41,
18,
35,
492,
437,
983,
4391,
4993,
63,
41,
18,
35,
199,
504,
900,
492,
9435,
199,
199,
533,
437,
983,
4391,
4993,
63,
1610,
7027,
11741,
750,
8,
33,
983,
4391,
4993,
63,
41,
18,
35,
304,
339,
327,
20359,
272,
327,
22296,
339,
327,
10977,
1437,
11438,
24493,
272,
603,
2890,
1789,
9570,
63,
2090,
1864,
63,
34,
15874,
16,
259,
275,
378,
88,
16,
33,
221,
327,
5004,
1864,
1380,
28721,
378,
4702,
272,
603,
2890,
1789,
9570,
63,
2090,
1864,
63,
34,
15874,
17,
259,
275,
378,
88,
1046,
221,
327,
5004,
1864,
1380,
28721,
413,
4702,
272,
327,
5723,
787,
2274,
7149,
1380,
315,
28721,
413,
1454,
26,
272,
603,
2890,
1789,
9570,
63,
21071,
33,
3515,
275,
378,
88,
1643,
272,
603,
2890,
1789,
9570,
63,
2090,
3022,
34,
260,
275,
378,
88,
709,
272,
603,
2890,
1789,
9570,
63,
21071,
34,
3515,
275,
378,
88,
1167,
339,
327,
10977,
1437,
11438,
1324,
10713,
10269,
272,
10468,
8295,
275,
378,
272,
7052,
7861,
275,
413,
272,
10163,
8540,
275,
499,
272,
7215,
10473,
275,
650,
272,
6578,
8540,
275,
841,
339,
327,
491,
1149,
9229,
272,
32633,
9326,
275,
378,
88,
383,
272,
23443,
9326,
275,
378,
88,
614,
272,
598,
14824,
7861,
275,
378,
88,
996,
272,
31408,
8540,
275,
378,
88,
966,
272,
1488,
23575,
8295,
275,
23443,
435,
598,
14824,
272,
10686,
748,
8540,
275,
598,
14824,
435,
31408,
272,
812,
2090,
44,
775,
8295,
275,
23443,
435,
31408,
272,
20483,
7861,
275,
23443,
435,
598,
14824,
435,
31408,
272,
5258,
10473,
275,
23443,
435,
598,
14824,
435,
31408,
339,
327,
491,
7695,
5817,
83,
272,
491,
7695,
63,
20706,
20993,
263,
275,
378,
88,
614,
272,
491,
7695,
63,
9677,
9524,
3515,
275,
378,
88,
996,
272,
491,
7695,
63,
7285,
31095,
775,
263,
275,
378,
88,
966,
272,
491,
7695,
63,
20993,
13060,
420,
275,
378,
88,
2036,
272,
491,
7695,
63,
31321,
18013,
260,
275,
378,
88,
709,
272,
491,
7695,
63,
29865,
775,
260,
275,
378,
88,
1165,
272,
491,
7695,
63,
3597,
35,
10896,
7803,
263,
275,
378,
88,
2167,
272,
491,
7695,
63,
3597,
36,
4564,
1156,
7803,
263,
275,
378,
88,
1257,
339,
327,
24870,
367,
2929,
641,
15,
1997,
3304,
272,
491,
7695,
63,
20993,
615,
3698,
275,
378,
88,
966,
272,
491,
7695,
63,
20993,
7517,
3515,
275,
378,
88,
383,
272,
491,
7695,
63,
31321,
615,
3322,
275,
378,
88,
996,
272,
491,
7695,
63,
31321,
7517,
3698,
275,
378,
88,
383,
272,
491,
7695,
63,
34,
7916,
615,
3777,
275,
378,
88,
614,
272,
491,
7695,
63,
34,
7916,
7517,
3322,
275,
378,
88,
383,
339,
327,
24870,
367,
2929,
2397,
818,
272,
491,
7695,
63,
1309,
50,
5716,
3515,
275,
378,
88,
383,
272,
491,
7695,
63,
7285,
9894,
3698,
275,
378,
88,
996,
272,
491,
7695,
63,
7285,
18013,
568,
31431,
275,
378,
88,
614,
272,
491,
7695,
63,
7285,
18013,
1093,
31431,
275,
378,
88,
383,
339,
327,
24870,
367,
2929,
15,
3937,
7706,
272,
491,
7695,
63,
20993,
16207,
275,
378,
88,
2036,
272,
491,
7695,
63,
31321,
16207,
221,
275,
378,
88,
383,
272,
491,
7695,
63,
2679,
2111,
2830,
257,
275,
378,
88,
966,
272,
491,
7695,
63,
16207,
9894,
259,
275,
378,
88,
383,
2378,
327,
20359,
272,
327,
20297,
339,
347,
636,
826,
721,
277,
12,
10414,
1507,
4022,
17,
12,
5552,
29,
16,
88,
1165,
12,
3105,
29,
797,
304,
398,
291,
14,
73,
18,
67,
275,
437,
983,
4391,
4993,
63,
41,
18,
35,
8,
2697,
12,
10414,
1507,
12,
3105,
9,
398,
327,
473,
18,
35,
365,
13773,
9462,
11999,
14,
221,
603,
2890,
1072,
1844,
6363,
787,
6328,
267,
327,
880,
781,
2793,
1133,
1929,
370,
4413,
590,
11271,
13,
460,
13,
1461,
4546,
6363,
14,
267,
291,
14,
719,
65,
12,
291,
14,
719,
66,
12,
291,
14,
617,
4848,
275,
378,
12,
378,
12,
378,
66,
4183,
993,
398,
327,
2494,
603,
2890,
1789,
9570,
5004,
1864,
2274,
370,
28721,
378,
543,
23381,
3439,
14,
267,
327,
982,
682,
711,
365,
2575,
663,
367,
28721,
378,
12,
642,
911,
2951,
2218,
370,
593,
20307,
34,
12,
267,
327,
1314,
7859,
1133,
542,
322,
1785,
590,
26962,
7003,
641,
314,
299,
750,
2451,
3063,
267,
327,
334,
6304,
1771,
4040,
491,
1149,
911,
11492,
641,
12,
1325,
626,
1159,
4224,
315,
314,
2163,
267,
327,
3650,
15988,
680,
267,
291,
14,
73,
18,
67,
14,
5610,
14,
952,
63,
4414,
63,
576,
8,
881,
291,
14,
73,
18,
67,
14,
1562,
12,
291,
14,
45,
2890,
1789,
9570,
63,
2090,
1864,
63,
34,
15874,
17,
12,
378,
9,
398,
327,
699,
82,
938,
3542,
13101,
11727,
24493,
370,
6040,
1174,
14,
221,
961,
2597,
267,
327,
5951,
1536,
1006,
314,
1324,
30541,
12,
10299,
13,
15203,
12,
5423,
14,
367,
314,
19835,
510,
750,
14,
267,
291,
14,
73,
18,
67,
14,
5610,
14,
952,
63,
73,
18,
67,
63,
1457,
63,
576,
8,
881,
291,
14,
73,
18,
67,
14,
1562,
12,
378,
12,
23664,
359,
378,
66,
383,
6984,
845,
12,
257,
327,
5004,
1914,
2847,
259
] |
[
2647,
15,
1393,
15,
1548,
199,
199,
3,
2018,
3555,
367,
437,
983,
4391,
4993,
19013,
13,
894,
1051,
491,
7695,
299,
750,
367,
820,
20222,
605,
651,
19835,
14,
199,
3,
27694,
701,
437,
983,
4391,
4993,
473,
977,
85,
816,
397,
14,
221,
10697,
4190,
14,
199,
199,
3,
961,
365,
28891,
282,
4890,
19913,
12,
1325,
314,
6358,
6302,
199,
3,
436,
5262,
787,
4079,
641,
1233,
687,
13645,
433,
346,
436,
24157,
28398,
35,
651,
32100,
14,
199,
3,
13645,
31629,
446,
4178,
921,
5031,
14,
957,
15,
7493,
433,
346,
15,
6360,
1038,
13,
7952,
20773,
1257,
15,
6582,
15,
4133,
15,
7952,
20773,
1257,
14,
647,
199,
3,
24157,
28398,
35,
651,
32100,
446,
4178,
921,
5031,
14,
957,
15,
1005,
85,
10175,
15,
31924,
10175,
15,
6582,
15,
4133,
15,
10159,
15,
13009,
28398,
35,
651,
32100,
15,
13009,
28398,
35,
651,
32100,
14,
5910,
199,
199,
504,
437,
983,
4391,
4993,
63,
41,
18,
35,
492,
437,
983,
4391,
4993,
63,
41,
18,
35,
199,
504,
900,
492,
9435,
199,
199,
533,
437,
983,
4391,
4993,
63,
1610,
7027,
11741,
750,
8,
33,
983,
4391,
4993,
63,
41,
18,
35,
304,
339,
327,
20359,
272,
327,
22296,
339,
327,
10977,
1437,
11438,
24493,
272,
603,
2890,
1789,
9570,
63,
2090,
1864,
63,
34,
15874,
16,
259,
275,
378,
88,
16,
33,
221,
327,
5004,
1864,
1380,
28721,
378,
4702,
272,
603,
2890,
1789,
9570,
63,
2090,
1864,
63,
34,
15874,
17,
259,
275,
378,
88,
1046,
221,
327,
5004,
1864,
1380,
28721,
413,
4702,
272,
327,
5723,
787,
2274,
7149,
1380,
315,
28721,
413,
1454,
26,
272,
603,
2890,
1789,
9570,
63,
21071,
33,
3515,
275,
378,
88,
1643,
272,
603,
2890,
1789,
9570,
63,
2090,
3022,
34,
260,
275,
378,
88,
709,
272,
603,
2890,
1789,
9570,
63,
21071,
34,
3515,
275,
378,
88,
1167,
339,
327,
10977,
1437,
11438,
1324,
10713,
10269,
272,
10468,
8295,
275,
378,
272,
7052,
7861,
275,
413,
272,
10163,
8540,
275,
499,
272,
7215,
10473,
275,
650,
272,
6578,
8540,
275,
841,
339,
327,
491,
1149,
9229,
272,
32633,
9326,
275,
378,
88,
383,
272,
23443,
9326,
275,
378,
88,
614,
272,
598,
14824,
7861,
275,
378,
88,
996,
272,
31408,
8540,
275,
378,
88,
966,
272,
1488,
23575,
8295,
275,
23443,
435,
598,
14824,
272,
10686,
748,
8540,
275,
598,
14824,
435,
31408,
272,
812,
2090,
44,
775,
8295,
275,
23443,
435,
31408,
272,
20483,
7861,
275,
23443,
435,
598,
14824,
435,
31408,
272,
5258,
10473,
275,
23443,
435,
598,
14824,
435,
31408,
339,
327,
491,
7695,
5817,
83,
272,
491,
7695,
63,
20706,
20993,
263,
275,
378,
88,
614,
272,
491,
7695,
63,
9677,
9524,
3515,
275,
378,
88,
996,
272,
491,
7695,
63,
7285,
31095,
775,
263,
275,
378,
88,
966,
272,
491,
7695,
63,
20993,
13060,
420,
275,
378,
88,
2036,
272,
491,
7695,
63,
31321,
18013,
260,
275,
378,
88,
709,
272,
491,
7695,
63,
29865,
775,
260,
275,
378,
88,
1165,
272,
491,
7695,
63,
3597,
35,
10896,
7803,
263,
275,
378,
88,
2167,
272,
491,
7695,
63,
3597,
36,
4564,
1156,
7803,
263,
275,
378,
88,
1257,
339,
327,
24870,
367,
2929,
641,
15,
1997,
3304,
272,
491,
7695,
63,
20993,
615,
3698,
275,
378,
88,
966,
272,
491,
7695,
63,
20993,
7517,
3515,
275,
378,
88,
383,
272,
491,
7695,
63,
31321,
615,
3322,
275,
378,
88,
996,
272,
491,
7695,
63,
31321,
7517,
3698,
275,
378,
88,
383,
272,
491,
7695,
63,
34,
7916,
615,
3777,
275,
378,
88,
614,
272,
491,
7695,
63,
34,
7916,
7517,
3322,
275,
378,
88,
383,
339,
327,
24870,
367,
2929,
2397,
818,
272,
491,
7695,
63,
1309,
50,
5716,
3515,
275,
378,
88,
383,
272,
491,
7695,
63,
7285,
9894,
3698,
275,
378,
88,
996,
272,
491,
7695,
63,
7285,
18013,
568,
31431,
275,
378,
88,
614,
272,
491,
7695,
63,
7285,
18013,
1093,
31431,
275,
378,
88,
383,
339,
327,
24870,
367,
2929,
15,
3937,
7706,
272,
491,
7695,
63,
20993,
16207,
275,
378,
88,
2036,
272,
491,
7695,
63,
31321,
16207,
221,
275,
378,
88,
383,
272,
491,
7695,
63,
2679,
2111,
2830,
257,
275,
378,
88,
966,
272,
491,
7695,
63,
16207,
9894,
259,
275,
378,
88,
383,
2378,
327,
20359,
272,
327,
20297,
339,
347,
636,
826,
721,
277,
12,
10414,
1507,
4022,
17,
12,
5552,
29,
16,
88,
1165,
12,
3105,
29,
797,
304,
398,
291,
14,
73,
18,
67,
275,
437,
983,
4391,
4993,
63,
41,
18,
35,
8,
2697,
12,
10414,
1507,
12,
3105,
9,
398,
327,
473,
18,
35,
365,
13773,
9462,
11999,
14,
221,
603,
2890,
1072,
1844,
6363,
787,
6328,
267,
327,
880,
781,
2793,
1133,
1929,
370,
4413,
590,
11271,
13,
460,
13,
1461,
4546,
6363,
14,
267,
291,
14,
719,
65,
12,
291,
14,
719,
66,
12,
291,
14,
617,
4848,
275,
378,
12,
378,
12,
378,
66,
4183,
993,
398,
327,
2494,
603,
2890,
1789,
9570,
5004,
1864,
2274,
370,
28721,
378,
543,
23381,
3439,
14,
267,
327,
982,
682,
711,
365,
2575,
663,
367,
28721,
378,
12,
642,
911,
2951,
2218,
370,
593,
20307,
34,
12,
267,
327,
1314,
7859,
1133,
542,
322,
1785,
590,
26962,
7003,
641,
314,
299,
750,
2451,
3063,
267,
327,
334,
6304,
1771,
4040,
491,
1149,
911,
11492,
641,
12,
1325,
626,
1159,
4224,
315,
314,
2163,
267,
327,
3650,
15988,
680,
267,
291,
14,
73,
18,
67,
14,
5610,
14,
952,
63,
4414,
63,
576,
8,
881,
291,
14,
73,
18,
67,
14,
1562,
12,
291,
14,
45,
2890,
1789,
9570,
63,
2090,
1864,
63,
34,
15874,
17,
12,
378,
9,
398,
327,
699,
82,
938,
3542,
13101,
11727,
24493,
370,
6040,
1174,
14,
221,
961,
2597,
267,
327,
5951,
1536,
1006,
314,
1324,
30541,
12,
10299,
13,
15203,
12,
5423,
14,
367,
314,
19835,
510,
750,
14,
267,
291,
14,
73,
18,
67,
14,
5610,
14,
952,
63,
73,
18,
67,
63,
1457,
63,
576,
8,
881,
291,
14,
73,
18,
67,
14,
1562,
12,
378,
12,
23664,
359,
378,
66,
383,
6984,
845,
12,
257,
327,
5004,
1914,
2847,
259,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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2015 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).
from __future__ import (absolute_import, division, generators, nested_scopes, print_function,
unicode_literals, with_statement)
import os
from collections import defaultdict
from twitter.common.collections import OrderedSet
from pants.backend.jvm.targets.jvm_target import JvmTarget
from pants.backend.jvm.targets.scala_library import ScalaLibrary
from pants.backend.jvm.targets.unpacked_jars import UnpackedJars
from pants.backend.jvm.tasks.classpath_util import ClasspathUtil
from pants.build_graph.aliased_target import AliasTarget
from pants.build_graph.build_graph import sort_targets
from pants.build_graph.resources import Resources
from pants.build_graph.target import Target
from pants.build_graph.target_scopes import Scopes
from pants.java.distribution.distribution import DistributionLocator
from pants.util.memo import memoized_method, memoized_property
class JvmDependencyAnalyzer(object):
"""Helper class for tasks which need to analyze source dependencies.
Primary purpose is to provide a classfile --> target mapping, which subclasses can use in
determining which targets correspond to the actual source dependencies of any given target.
"""
def __init__(self, buildroot, runtime_classpath, product_deps_by_src):
self.buildroot = buildroot
self.runtime_classpath = runtime_classpath
self.product_deps_by_src = product_deps_by_src
@memoized_method
def files_for_target(self, target):
"""Yields a sequence of abs path of source, class or jar files provided by the target.
The runtime classpath for a target must already have been finalized for a target in order
to compute its provided files.
"""
def gen():
# Compute src -> target.
if isinstance(target, JvmTarget):
for src in target.sources_relative_to_buildroot():
yield os.path.join(self.buildroot, src)
# TODO(Tejal Desai): pantsbuild/pants/65: Remove java_sources attribute for ScalaLibrary
if isinstance(target, ScalaLibrary):
for java_source in target.java_sources:
for src in java_source.sources_relative_to_buildroot():
yield os.path.join(self.buildroot, src)
# Compute classfile -> target and jar -> target.
files = ClasspathUtil.classpath_contents((target,), self.runtime_classpath)
# And jars; for binary deps, zinc doesn't emit precise deps (yet).
cp_entries = ClasspathUtil.classpath((target,), self.runtime_classpath)
jars = [cpe for cpe in cp_entries if ClasspathUtil.is_jar(cpe)]
for coll in [files, jars]:
for f in coll:
yield f
return set(gen())
def targets_by_file(self, targets):
"""Returns a map from abs path of source, class or jar file to an OrderedSet of targets.
The value is usually a singleton, because a source or class file belongs to a single target.
However a single jar may be provided (transitively or intransitively) by multiple JarLibrary
targets. But if there is a JarLibrary target that depends on a jar directly, then that
"canonical" target will be the first one in the list of targets.
"""
targets_by_file = defaultdict(OrderedSet)
for target in targets:
for f in self.files_for_target(target):
targets_by_file[f].add(target)
return targets_by_file
def targets_for_class(self, target, classname):
"""Search which targets from `target`'s transitive dependencies contain `classname`."""
targets_with_class = set()
for target in target.closure():
if classname in self._target_classes(target):
targets_with_class.add(target)
return targets_with_class
@memoized_method
def _target_classes(self, target):
"""Set of target's provided classes.
Call at the target level is to memoize efficiently.
"""
target_classes = set()
contents = ClasspathUtil.classpath_contents((target,), self.runtime_classpath)
for f in contents:
classname = ClasspathUtil.classname_for_rel_classfile(f)
if classname:
target_classes.add(classname)
return target_classes
def _jar_classfiles(self, jar_file):
"""Returns an iterator over the classfiles inside jar_file."""
for cls in ClasspathUtil.classpath_entries_contents([jar_file]):
if cls.endswith(b'.class'):
yield cls
def count_products(self, target):
contents = ClasspathUtil.classpath_contents((target,), self.runtime_classpath)
# Generators don't implement len.
return sum(1 for _ in contents)
@memoized_property
def bootstrap_jar_classfiles(self):
"""Returns a set of classfiles from the JVM bootstrap jars."""
bootstrap_jar_classfiles = set()
for jar_file in self._find_all_bootstrap_jars():
for cls in self._jar_classfiles(jar_file):
bootstrap_jar_classfiles.add(cls)
return bootstrap_jar_classfiles
def _find_all_bootstrap_jars(self):
def get_path(key):
return DistributionLocator.cached().system_properties.get(key, '').split(':')
def find_jars_in_dirs(dirs):
ret = []
for d in dirs:
if os.path.isdir(d):
ret.extend(filter(lambda s: s.endswith('.jar'), os.listdir(d)))
return ret
# Note: assumes HotSpot, or some JVM that supports sun.boot.class.path.
# TODO: Support other JVMs? Not clear if there's a standard way to do so.
# May include loose classes dirs.
boot_classpath = get_path('sun.boot.class.path')
# Note that per the specs, overrides and extensions must be in jars.
# Loose class files will not be found by the JVM.
override_jars = find_jars_in_dirs(get_path('java.endorsed.dirs'))
extension_jars = find_jars_in_dirs(get_path('java.ext.dirs'))
# Note that this order matters: it reflects the classloading order.
bootstrap_jars = filter(os.path.isfile, override_jars + boot_classpath + extension_jars)
return bootstrap_jars # Technically, may include loose class dirs from boot_classpath.
def compute_transitive_deps_by_target(self, targets):
"""Map from target to all the targets it depends on, transitively."""
# Sort from least to most dependent.
sorted_targets = reversed(sort_targets(targets))
transitive_deps_by_target = defaultdict(set)
# Iterate in dep order, to accumulate the transitive deps for each target.
for target in sorted_targets:
transitive_deps = set()
for dep in target.dependencies:
transitive_deps.update(transitive_deps_by_target.get(dep, []))
transitive_deps.add(dep)
# Need to handle the case where a java_sources target has dependencies.
# In particular if it depends back on the original target.
if hasattr(target, 'java_sources'):
for java_source_target in target.java_sources:
for transitive_dep in java_source_target.dependencies:
transitive_deps_by_target[java_source_target].add(transitive_dep)
transitive_deps_by_target[target] = transitive_deps
return transitive_deps_by_target
def resolve_aliases(self, target, scope=None):
"""Resolve aliases in the direct dependencies of the target.
:param target: The direct dependencies of this target are included.
:param scope: When specified, only deps with this scope are included. This is more
than a filter, because it prunes the subgraphs represented by aliases with
un-matched scopes.
:returns: An iterator of (resolved_dependency, resolved_from) tuples.
`resolved_from` is the top level target alias that depends on `resolved_dependency`,
and `None` if `resolved_dependency` is not a dependency of a target alias.
"""
for declared in target.dependencies:
if scope is not None and declared.scope != scope:
# Only `DEFAULT` scoped deps are eligible for the unused dep check.
continue
elif type(declared) in (AliasTarget, Target):
# Is an alias. Recurse to expand.
for r, _ in self.resolve_aliases(declared, scope=scope):
yield r, declared
else:
yield declared, None
def compute_unused_deps(self, target):
"""Computes unused deps for the given Target.
:returns: A set of directly declared but unused targets, and a set of suggested replacements.
"""
# Flatten the product deps of this target.
product_deps = set()
for dep_entries in self.product_deps_by_src.get(target, {}).values():
product_deps.update(dep_entries)
# Determine which of the DEFAULT deps in the declared set of this target were used.
used = set()
unused = set()
for dep, _ in self.resolve_aliases(target, scope=Scopes.DEFAULT):
if dep in used or dep in unused:
continue
# TODO: What's a better way to accomplish this check? Filtering by `has_sources` would
# incorrectly skip "empty" `*_library` targets, which could then be used as a loophole.
if isinstance(dep, (Resources, UnpackedJars)):
continue
# If any of the target's jars or classfiles were used, consider it used.
if product_deps.isdisjoint(self.files_for_target(dep)):
unused.add(dep)
else:
used.add(dep)
# If there were no unused deps, break.
if not unused:
return {}
# For any deps that were used, count their derived-from targets used as well.
# TODO: Refactor to do some of this above once tests are in place.
for dep in list(used):
for derived_from in dep.derived_from_chain:
if derived_from in unused:
unused.remove(derived_from)
used.add(derived_from)
# Prune derived targets that would be in the set twice.
for dep in list(unused):
if set(dep.derived_from_chain) & unused:
unused.remove(dep)
if not unused:
return {}
# For any deps that were not used, determine whether their transitive deps were used, and
# recommend those as replacements.
replacements = {}
for dep in unused:
replacements[dep] = set()
for t in dep.closure():
if t in used or t in unused:
continue
if not product_deps.isdisjoint(self.files_for_target(t)):
replacements[dep].add(t.concrete_derived_from)
return replacements
|
apache-2.0
|
[
3,
2803,
29,
1624,
13,
24,
199,
3,
1898,
6900,
510,
2285,
2199,
8417,
334,
3239,
6483,
14,
1064,
680,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
3239,
5113,
680,
199,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
16952,
12,
6032,
63,
14129,
12,
870,
63,
1593,
12,
717,
2649,
63,
5955,
12,
543,
63,
6242,
9,
199,
199,
646,
747,
199,
504,
5055,
492,
10018,
199,
199,
504,
15811,
14,
2330,
14,
7882,
492,
23617,
199,
199,
504,
18081,
14,
4620,
14,
15813,
14,
4684,
14,
15813,
63,
1375,
492,
1603,
2611,
4277,
199,
504,
18081,
14,
4620,
14,
15813,
14,
4684,
14,
28708,
63,
4342,
492,
17619,
65,
7424,
199,
504,
18081,
14,
4620,
14,
15813,
14,
4684,
14,
24497,
63,
32262,
492,
1910,
12286,
42,
4291,
199,
504,
18081,
14,
4620,
14,
15813,
14,
5054,
14,
26977,
63,
1974,
492,
8089,
515,
9562,
199,
504,
18081,
14,
1506,
63,
2180,
14,
26930,
63,
1375,
492,
24777,
4277,
199,
504,
18081,
14,
1506,
63,
2180,
14,
1506,
63,
2180,
492,
4069,
63,
4684,
199,
504,
18081,
14,
1506,
63,
2180,
14,
4435,
492,
26250,
199,
504,
18081,
14,
1506,
63,
2180,
14,
1375,
492,
10256,
199,
504,
18081,
14,
1506,
63,
2180,
14,
1375,
63,
14129,
492,
20488,
83,
199,
504,
18081,
14,
6138,
14,
4972,
14,
4972,
492,
11839,
10725,
199,
504,
18081,
14,
1974,
14,
11979,
492,
11955,
1759,
63,
765,
12,
11955,
1759,
63,
1829,
421,
199,
533,
1603,
2611,
14403,
17606,
8,
785,
304,
523,
408,
4433,
1021,
367,
6527,
1314,
1929,
370,
19897,
1350,
5124,
14,
819,
26710,
12016,
365,
370,
5647,
282,
1021,
493,
10541,
1347,
4412,
12,
1314,
9180,
883,
675,
315,
523,
26638,
1314,
4545,
17118,
370,
314,
3503,
1350,
5124,
402,
1263,
1627,
1347,
14,
523,
408,
819,
347,
636,
826,
721,
277,
12,
1900,
1231,
12,
8836,
63,
26977,
12,
3336,
63,
5846,
63,
991,
63,
2164,
304,
272,
291,
14,
1506,
1231,
275,
1900,
1231,
272,
291,
14,
7726,
63,
26977,
275,
8836,
63,
26977,
272,
291,
14,
2558,
63,
5846,
63,
991,
63,
2164,
275,
3336,
63,
5846,
63,
991,
63,
2164,
819,
768,
20457,
63,
765,
523,
347,
1584,
63,
509,
63,
1375,
8,
277,
12,
1347,
304,
272,
408,
22889,
83,
282,
3414,
402,
2853,
931,
402,
1350,
12,
1021,
503,
16290,
1584,
2741,
701,
314,
1347,
14,
339,
710,
8836,
1021,
515,
367,
282,
1347,
1471,
2575,
1172,
2757,
4242,
1759,
367,
282,
1347,
315,
1865,
272,
370,
4526,
2399,
2741,
1584,
14,
272,
408,
272,
347,
3805,
837,
489,
327,
8354,
2928,
1035,
1347,
14,
489,
340,
1228,
8,
1375,
12,
1603,
2611,
4277,
304,
267,
367,
2928,
315,
1347,
14,
4553,
63,
6188,
63,
475,
63,
1506,
1231,
837,
881,
1995,
747,
14,
515,
14,
904,
8,
277,
14,
1506,
1231,
12,
2928,
9,
489,
327,
3254,
8,
6301,
74,
279,
8055,
5789,
304,
18081,
1506,
15,
21970,
15,
2182,
26,
5852,
12120,
63,
4553,
2225,
367,
17619,
65,
7424,
489,
340,
1228,
8,
1375,
12,
17619,
65,
7424,
304,
267,
367,
12120,
63,
1365,
315,
1347,
14,
6138,
63,
4553,
26,
881,
367,
2928,
315,
12120,
63,
1365,
14,
4553,
63,
6188,
63,
475,
63,
1506,
1231,
837,
288,
1995,
747,
14,
515,
14,
904,
8,
277,
14,
1506,
1231,
12,
2928,
9,
2541,
327,
8354,
1021,
493,
1035,
1347,
436,
16290,
1035,
1347,
14,
489,
1584,
275,
8089,
515,
9562,
14,
26977,
63,
4407,
1332,
1375,
4706,
291,
14,
7726,
63,
26977,
9,
489,
327,
6061,
1335,
4291,
27,
367,
3366,
10140,
12,
1315,
6559,
3181,
1133,
8689,
28334,
10140,
334,
28064,
680,
489,
7667,
63,
3189,
275,
8089,
515,
9562,
14,
26977,
1332,
1375,
4706,
291,
14,
7726,
63,
26977,
9,
489,
1335,
4291,
275,
359,
67,
321,
367,
286,
321,
315,
7667,
63,
3189,
340,
8089,
515,
9562,
14,
374,
63,
7338,
8,
67,
321,
1874,
489,
367,
23721,
315,
359,
1725,
12,
1335,
4291,
2189,
267,
367,
289,
315,
23721,
26,
881,
1995,
289,
272,
372,
663,
8,
2268,
1012,
819,
347,
4545,
63,
991,
63,
493,
8,
277,
12,
4545,
304,
272,
408,
3407,
282,
2341,
687,
2853,
931,
402,
1350,
12,
1021,
503,
16290,
570,
370,
376,
23617,
402,
4545,
14,
339,
710,
574,
365,
9987,
282,
19768,
12,
2952,
282,
1350,
503,
1021,
570,
15006,
370,
282,
2849,
1347,
14,
272,
9738,
282,
2849,
16290,
1443,
506,
2741,
334,
3936,
338,
9462,
503,
315,
3936,
338,
9462,
9,
701,
3663,
1603,
285,
7424,
272,
4545,
14,
11017,
340,
2337,
365,
282,
1603,
285,
7424,
1347,
626,
8350,
641,
282,
16290,
5370,
12,
2066,
626,
272,
298,
13109,
2,
1347,
911,
506,
314,
1642,
1373,
315,
314,
769,
402,
4545,
14,
272,
408,
272,
4545,
63,
991,
63,
493,
275,
10018,
8,
22567,
1084,
9,
339,
367,
1347,
315,
4545,
26,
489,
367,
289,
315,
291,
14,
1725,
63,
509,
63,
1375,
8,
1375,
304,
267,
4545,
63,
991,
63,
493,
59,
70,
1055,
525,
8,
1375,
9,
339,
372,
4545,
63,
991,
63,
493,
819,
347,
4545,
63,
509,
63,
533,
8,
277,
12,
1347,
12,
15876,
304,
272,
408,
5278,
1314,
4545,
687,
658,
1375,
19097,
83,
7115,
3013,
5124,
1395,
658,
19851,
17105,
272,
4545,
63,
1045,
63,
533,
275,
663,
342,
272,
367,
1347,
315,
1347,
14,
13008,
837,
489,
340,
15876,
315,
291,
423,
1375,
63,
2888,
8,
1375,
304,
267,
4545,
63,
1045,
63,
533,
14,
525,
8,
1375,
9,
339,
372,
4545,
63,
1045,
63,
533,
819,
768,
20457,
63,
765,
523,
347,
485,
1375,
63,
2888,
8,
277,
12,
1347,
304,
272,
408,
1084,
402,
1347,
1159,
2741,
3992,
14,
339,
6523,
737,
314,
1347,
2166,
365,
370,
11955,
794,
30427,
14,
272,
408,
272,
1347,
63,
2888,
275,
663,
342,
272,
4072,
275,
8089,
515,
9562,
14,
26977,
63,
4407,
1332,
1375,
4706,
291,
14,
7726,
63,
26977,
9,
272,
367,
289,
315,
4072,
26,
489,
15876,
275,
8089,
515,
9562,
14,
19851,
63,
509,
63,
3369,
63,
533,
493,
8,
70,
9,
489,
340,
15876,
26
] |
[
2803,
29,
1624,
13,
24,
199,
3,
1898,
6900,
510,
2285,
2199,
8417,
334,
3239,
6483,
14,
1064,
680,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
3239,
5113,
680,
199,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
16952,
12,
6032,
63,
14129,
12,
870,
63,
1593,
12,
717,
2649,
63,
5955,
12,
543,
63,
6242,
9,
199,
199,
646,
747,
199,
504,
5055,
492,
10018,
199,
199,
504,
15811,
14,
2330,
14,
7882,
492,
23617,
199,
199,
504,
18081,
14,
4620,
14,
15813,
14,
4684,
14,
15813,
63,
1375,
492,
1603,
2611,
4277,
199,
504,
18081,
14,
4620,
14,
15813,
14,
4684,
14,
28708,
63,
4342,
492,
17619,
65,
7424,
199,
504,
18081,
14,
4620,
14,
15813,
14,
4684,
14,
24497,
63,
32262,
492,
1910,
12286,
42,
4291,
199,
504,
18081,
14,
4620,
14,
15813,
14,
5054,
14,
26977,
63,
1974,
492,
8089,
515,
9562,
199,
504,
18081,
14,
1506,
63,
2180,
14,
26930,
63,
1375,
492,
24777,
4277,
199,
504,
18081,
14,
1506,
63,
2180,
14,
1506,
63,
2180,
492,
4069,
63,
4684,
199,
504,
18081,
14,
1506,
63,
2180,
14,
4435,
492,
26250,
199,
504,
18081,
14,
1506,
63,
2180,
14,
1375,
492,
10256,
199,
504,
18081,
14,
1506,
63,
2180,
14,
1375,
63,
14129,
492,
20488,
83,
199,
504,
18081,
14,
6138,
14,
4972,
14,
4972,
492,
11839,
10725,
199,
504,
18081,
14,
1974,
14,
11979,
492,
11955,
1759,
63,
765,
12,
11955,
1759,
63,
1829,
421,
199,
533,
1603,
2611,
14403,
17606,
8,
785,
304,
523,
408,
4433,
1021,
367,
6527,
1314,
1929,
370,
19897,
1350,
5124,
14,
819,
26710,
12016,
365,
370,
5647,
282,
1021,
493,
10541,
1347,
4412,
12,
1314,
9180,
883,
675,
315,
523,
26638,
1314,
4545,
17118,
370,
314,
3503,
1350,
5124,
402,
1263,
1627,
1347,
14,
523,
408,
819,
347,
636,
826,
721,
277,
12,
1900,
1231,
12,
8836,
63,
26977,
12,
3336,
63,
5846,
63,
991,
63,
2164,
304,
272,
291,
14,
1506,
1231,
275,
1900,
1231,
272,
291,
14,
7726,
63,
26977,
275,
8836,
63,
26977,
272,
291,
14,
2558,
63,
5846,
63,
991,
63,
2164,
275,
3336,
63,
5846,
63,
991,
63,
2164,
819,
768,
20457,
63,
765,
523,
347,
1584,
63,
509,
63,
1375,
8,
277,
12,
1347,
304,
272,
408,
22889,
83,
282,
3414,
402,
2853,
931,
402,
1350,
12,
1021,
503,
16290,
1584,
2741,
701,
314,
1347,
14,
339,
710,
8836,
1021,
515,
367,
282,
1347,
1471,
2575,
1172,
2757,
4242,
1759,
367,
282,
1347,
315,
1865,
272,
370,
4526,
2399,
2741,
1584,
14,
272,
408,
272,
347,
3805,
837,
489,
327,
8354,
2928,
1035,
1347,
14,
489,
340,
1228,
8,
1375,
12,
1603,
2611,
4277,
304,
267,
367,
2928,
315,
1347,
14,
4553,
63,
6188,
63,
475,
63,
1506,
1231,
837,
881,
1995,
747,
14,
515,
14,
904,
8,
277,
14,
1506,
1231,
12,
2928,
9,
489,
327,
3254,
8,
6301,
74,
279,
8055,
5789,
304,
18081,
1506,
15,
21970,
15,
2182,
26,
5852,
12120,
63,
4553,
2225,
367,
17619,
65,
7424,
489,
340,
1228,
8,
1375,
12,
17619,
65,
7424,
304,
267,
367,
12120,
63,
1365,
315,
1347,
14,
6138,
63,
4553,
26,
881,
367,
2928,
315,
12120,
63,
1365,
14,
4553,
63,
6188,
63,
475,
63,
1506,
1231,
837,
288,
1995,
747,
14,
515,
14,
904,
8,
277,
14,
1506,
1231,
12,
2928,
9,
2541,
327,
8354,
1021,
493,
1035,
1347,
436,
16290,
1035,
1347,
14,
489,
1584,
275,
8089,
515,
9562,
14,
26977,
63,
4407,
1332,
1375,
4706,
291,
14,
7726,
63,
26977,
9,
489,
327,
6061,
1335,
4291,
27,
367,
3366,
10140,
12,
1315,
6559,
3181,
1133,
8689,
28334,
10140,
334,
28064,
680,
489,
7667,
63,
3189,
275,
8089,
515,
9562,
14,
26977,
1332,
1375,
4706,
291,
14,
7726,
63,
26977,
9,
489,
1335,
4291,
275,
359,
67,
321,
367,
286,
321,
315,
7667,
63,
3189,
340,
8089,
515,
9562,
14,
374,
63,
7338,
8,
67,
321,
1874,
489,
367,
23721,
315,
359,
1725,
12,
1335,
4291,
2189,
267,
367,
289,
315,
23721,
26,
881,
1995,
289,
272,
372,
663,
8,
2268,
1012,
819,
347,
4545,
63,
991,
63,
493,
8,
277,
12,
4545,
304,
272,
408,
3407,
282,
2341,
687,
2853,
931,
402,
1350,
12,
1021,
503,
16290,
570,
370,
376,
23617,
402,
4545,
14,
339,
710,
574,
365,
9987,
282,
19768,
12,
2952,
282,
1350,
503,
1021,
570,
15006,
370,
282,
2849,
1347,
14,
272,
9738,
282,
2849,
16290,
1443,
506,
2741,
334,
3936,
338,
9462,
503,
315,
3936,
338,
9462,
9,
701,
3663,
1603,
285,
7424,
272,
4545,
14,
11017,
340,
2337,
365,
282,
1603,
285,
7424,
1347,
626,
8350,
641,
282,
16290,
5370,
12,
2066,
626,
272,
298,
13109,
2,
1347,
911,
506,
314,
1642,
1373,
315,
314,
769,
402,
4545,
14,
272,
408,
272,
4545,
63,
991,
63,
493,
275,
10018,
8,
22567,
1084,
9,
339,
367,
1347,
315,
4545,
26,
489,
367,
289,
315,
291,
14,
1725,
63,
509,
63,
1375,
8,
1375,
304,
267,
4545,
63,
991,
63,
493,
59,
70,
1055,
525,
8,
1375,
9,
339,
372,
4545,
63,
991,
63,
493,
819,
347,
4545,
63,
509,
63,
533,
8,
277,
12,
1347,
12,
15876,
304,
272,
408,
5278,
1314,
4545,
687,
658,
1375,
19097,
83,
7115,
3013,
5124,
1395,
658,
19851,
17105,
272,
4545,
63,
1045,
63,
533,
275,
663,
342,
272,
367,
1347,
315,
1347,
14,
13008,
837,
489,
340,
15876,
315,
291,
423,
1375,
63,
2888,
8,
1375,
304,
267,
4545,
63,
1045,
63,
533,
14,
525,
8,
1375,
9,
339,
372,
4545,
63,
1045,
63,
533,
819,
768,
20457,
63,
765,
523,
347,
485,
1375,
63,
2888,
8,
277,
12,
1347,
304,
272,
408,
1084,
402,
1347,
1159,
2741,
3992,
14,
339,
6523,
737,
314,
1347,
2166,
365,
370,
11955,
794,
30427,
14,
272,
408,
272,
1347,
63,
2888,
275,
663,
342,
272,
4072,
275,
8089,
515,
9562,
14,
26977,
63,
4407,
1332,
1375,
4706,
291,
14,
7726,
63,
26977,
9,
272,
367,
289,
315,
4072,
26,
489,
15876,
275,
8089,
515,
9562,
14,
19851,
63,
509,
63,
3369,
63,
533,
493,
8,
70,
9,
489,
340,
15876,
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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
dancingdan/tensorflow
|
tensorflow/python/training/server_lib_test.py
|
7
|
21270
|
# Copyright 2017 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Tests for tf.GrpcServer."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import time
import numpy as np
from tensorflow.core.protobuf import config_pb2
from tensorflow.core.protobuf import tensorflow_server_pb2
from tensorflow.python.client import session
from tensorflow.python.framework import constant_op
from tensorflow.python.framework import dtypes
from tensorflow.python.framework import errors_impl
from tensorflow.python.framework import ops
from tensorflow.python.ops import array_ops
from tensorflow.python.ops import data_flow_ops
from tensorflow.python.ops import math_ops
from tensorflow.python.ops import variables
from tensorflow.python.platform import test
from tensorflow.python.training import input as input_ops
from tensorflow.python.training import queue_runner_impl
from tensorflow.python.training import server_lib
class GrpcServerTest(test.TestCase):
def __init__(self, methodName="runTest"): # pylint: disable=invalid-name
super(GrpcServerTest, self).__init__(methodName)
self._cached_server = server_lib.Server.create_local_server()
def testRunStep(self):
server = self._cached_server
with session.Session(server.target) as sess:
c = constant_op.constant([[2, 1]])
d = constant_op.constant([[1], [2]])
e = math_ops.matmul(c, d)
self.assertAllEqual([[4]], sess.run(e))
# TODO(mrry): Add `server.stop()` and `server.join()` when these work.
def testMultipleSessions(self):
server = self._cached_server
c = constant_op.constant([[2, 1]])
d = constant_op.constant([[1], [2]])
e = math_ops.matmul(c, d)
sess_1 = session.Session(server.target)
sess_2 = session.Session(server.target)
self.assertAllEqual([[4]], sess_1.run(e))
self.assertAllEqual([[4]], sess_2.run(e))
sess_1.close()
sess_2.close()
# TODO(mrry): Add `server.stop()` and `server.join()` when these work.
# Verifies various reset failures.
def testResetFails(self):
# Creates variable with container name.
with ops.container("test0"):
v0 = variables.VariableV1(1.0, name="v0")
# Creates variable with default container.
v1 = variables.VariableV1(2.0, name="v1")
# Verifies resetting the non-existent target returns error.
with self.assertRaises(errors_impl.NotFoundError):
session.Session.reset("nonexistent", ["test0"])
# Verifies resetting with config.
# Verifies that resetting target with no server times out.
with self.assertRaises(errors_impl.DeadlineExceededError):
session.Session.reset(
"grpc://localhost:0", ["test0"],
config=config_pb2.ConfigProto(operation_timeout_in_ms=5))
# Verifies no containers are reset with non-existent container.
server = self._cached_server
sess = session.Session(server.target)
sess.run(variables.global_variables_initializer())
self.assertAllEqual(1.0, sess.run(v0))
self.assertAllEqual(2.0, sess.run(v1))
# No container is reset, but the server is reset.
session.Session.reset(server.target, ["test1"])
# Verifies that both variables are still valid.
sess = session.Session(server.target)
self.assertAllEqual(1.0, sess.run(v0))
self.assertAllEqual(2.0, sess.run(v1))
def _useRPCConfig(self):
"""Return a `tf.ConfigProto` that ensures we use the RPC stack for tests.
This configuration ensures that we continue to exercise the gRPC
stack when testing, rather than using the in-process optimization,
which avoids using gRPC as the transport between a client and
master in the same process.
Returns:
A `tf.ConfigProto`.
"""
return config_pb2.ConfigProto(rpc_options=config_pb2.RPCOptions(
use_rpc_for_inprocess_master=True))
def testLargeConstant(self):
server = self._cached_server
with session.Session(server.target, config=self._useRPCConfig()) as sess:
const_val = np.empty([10000, 3000], dtype=np.float32)
const_val.fill(0.5)
c = constant_op.constant(const_val)
shape_t = array_ops.shape(c)
self.assertAllEqual([10000, 3000], sess.run(shape_t))
def testLargeFetch(self):
server = self._cached_server
with session.Session(server.target, config=self._useRPCConfig()) as sess:
c = array_ops.fill([10000, 3000], 0.5)
expected_val = np.empty([10000, 3000], dtype=np.float32)
expected_val.fill(0.5)
self.assertAllEqual(expected_val, sess.run(c))
def testLargeFeed(self):
server = self._cached_server
with session.Session(server.target, config=self._useRPCConfig()) as sess:
feed_val = np.empty([10000, 3000], dtype=np.float32)
feed_val.fill(0.5)
p = array_ops.placeholder(dtypes.float32, shape=[10000, 3000])
min_t = math_ops.reduce_min(p)
max_t = math_ops.reduce_max(p)
min_val, max_val = sess.run([min_t, max_t], feed_dict={p: feed_val})
self.assertEqual(0.5, min_val)
self.assertEqual(0.5, max_val)
def testCloseCancelsBlockingOperation(self):
server = self._cached_server
sess = session.Session(server.target, config=self._useRPCConfig())
q = data_flow_ops.FIFOQueue(10, [dtypes.float32])
enqueue_op = q.enqueue(37.0)
dequeue_t = q.dequeue()
sess.run(enqueue_op)
sess.run(dequeue_t)
def blocking_dequeue():
with self.assertRaisesRegexp(errors_impl.CancelledError,
"Session::Close"):
sess.run(dequeue_t)
blocking_thread = self.checkedThread(blocking_dequeue)
blocking_thread.start()
time.sleep(0.5)
sess.close()
blocking_thread.join()
def testInteractiveSession(self):
server = self._cached_server
# Session creation will warn (in C++) that the place_pruned_graph option
# is not supported, but it should successfully ignore it.
sess = session.InteractiveSession(server.target)
c = constant_op.constant(42.0)
self.assertEqual(42.0, c.eval())
sess.close()
def testSetConfiguration(self):
config = config_pb2.ConfigProto(
gpu_options=config_pb2.GPUOptions(per_process_gpu_memory_fraction=0.1))
# Configure a server using the default local server options.
server = server_lib.Server.create_local_server(config=config, start=False)
self.assertEqual(0.1, server.server_def.default_session_config.gpu_options.
per_process_gpu_memory_fraction)
# Configure a server using an explicit ServerDefd with an
# overridden config.
cluster_def = server_lib.ClusterSpec({
"localhost": ["localhost:0"]
}).as_cluster_def()
server_def = tensorflow_server_pb2.ServerDef(
cluster=cluster_def,
job_name="localhost",
task_index=0,
protocol="grpc")
server = server_lib.Server(server_def, config=config, start=False)
self.assertEqual(0.1, server.server_def.default_session_config.gpu_options.
per_process_gpu_memory_fraction)
def testInvalidHostname(self):
with self.assertRaisesRegexp(errors_impl.InvalidArgumentError, "port"):
_ = server_lib.Server(
{
"local": ["localhost"]
}, job_name="local", task_index=0)
def testTimeoutRaisesException(self):
server = self._cached_server
q = data_flow_ops.FIFOQueue(1, [dtypes.float32])
blocking_t = q.dequeue()
with session.Session(server.target) as sess:
with self.assertRaises(errors_impl.DeadlineExceededError):
sess.run(blocking_t, options=config_pb2.RunOptions(timeout_in_ms=1000))
with session.Session(server.target, config=self._useRPCConfig()) as sess:
with self.assertRaises(errors_impl.DeadlineExceededError):
sess.run(blocking_t, options=config_pb2.RunOptions(timeout_in_ms=1000))
def testTwoServersSamePort(self):
# Starting a server with the same target as the cached server should fail.
server = self._cached_server
with self.assertRaises(errors_impl.UnknownError):
_ = server_lib.Server(
{"local_2": [server.target[len("grpc://"):]]})
def testExtendAfterQueueRunners(self):
server = self._cached_server
with session.Session(server.target) as sess:
input_queue = input_ops.input_producer(constant_op.constant(
[0.], dtype=dtypes.float32))
self.assertIsNotNone(input_queue)
var = variables.VariableV1(1., dtype=dtypes.float32, trainable=False,
name="var")
sess.run(variables.global_variables_initializer())
queue_runner_impl.start_queue_runners(sess)
sess.run(var.assign(3.0))
def testIsolateSessionState(self):
server = self._cached_server
init_value = array_ops.placeholder(dtypes.int32)
v = variables.VariableV1(init_value, validate_shape=False, name="v")
sharing_config = config_pb2.ConfigProto(isolate_session_state=False)
sharing_sess_0 = session.Session(server.target, config=sharing_config)
sharing_sess_1 = session.Session(server.target, config=sharing_config)
isolate_config = config_pb2.ConfigProto(isolate_session_state=True)
isolate_sess_0 = session.Session(server.target, config=isolate_config)
isolate_sess_1 = session.Session(server.target, config=isolate_config)
# Initially all variables are initialized.
for sess in [sharing_sess_0, sharing_sess_1,
isolate_sess_0, isolate_sess_1]:
with self.assertRaises(errors_impl.FailedPreconditionError):
sess.run(v)
# Shared sessions will see each other's updates, but isolated sessions
# will not.
sharing_sess_0.run(v.initializer, feed_dict={init_value: 86})
self.assertAllEqual(86, sharing_sess_0.run(v))
self.assertAllEqual(86, sharing_sess_1.run(v))
with self.assertRaises(errors_impl.FailedPreconditionError):
isolate_sess_0.run(v)
with self.assertRaises(errors_impl.FailedPreconditionError):
isolate_sess_1.run(v)
# Changing the shape works because `validate_shape` is False.
sharing_sess_1.run(v.initializer, feed_dict={init_value: [86, 99]})
self.assertAllEqual([86, 99], sharing_sess_0.run(v))
self.assertAllEqual([86, 99], sharing_sess_1.run(v))
with self.assertRaises(errors_impl.FailedPreconditionError):
isolate_sess_0.run(v)
with self.assertRaises(errors_impl.FailedPreconditionError):
isolate_sess_1.run(v)
# Initializing in an isolated session will only affect the state in that
# session.
isolate_sess_0.run(v.initializer, feed_dict={init_value: 37})
self.assertAllEqual([86, 99], sharing_sess_0.run(v))
self.assertAllEqual([86, 99], sharing_sess_1.run(v))
self.assertAllEqual(37, isolate_sess_0.run(v))
with self.assertRaises(errors_impl.FailedPreconditionError):
isolate_sess_1.run(v)
# Isolated sessions can have different shapes for the same variable.
isolate_sess_1.run(v.initializer, feed_dict={init_value: [19, 86]})
self.assertAllEqual([86, 99], sharing_sess_0.run(v))
self.assertAllEqual([86, 99], sharing_sess_1.run(v))
self.assertAllEqual(37, isolate_sess_0.run(v))
self.assertAllEqual([19, 86], isolate_sess_1.run(v))
def testShapeChangingIsolateState(self):
server = self._cached_server
sharing_config = config_pb2.ConfigProto(isolate_session_state=False)
isolate_config = config_pb2.ConfigProto(isolate_session_state=True)
with ops.Graph().as_default():
w_vector = variables.VariableV1([1, 2, 3], name="w")
with session.Session(server.target, config=sharing_config) as sess:
with self.assertRaises(errors_impl.FailedPreconditionError):
sess.run(w_vector)
sess.run(w_vector.initializer)
self.assertAllEqual([1, 2, 3], sess.run(w_vector))
with ops.Graph().as_default():
w_vector = variables.VariableV1([4, 5, 6], name="w")
with session.Session(server.target, config=sharing_config) as sess:
self.assertAllEqual([1, 2, 3], sess.run(w_vector))
sess.run(w_vector.initializer)
self.assertAllEqual([4, 5, 6], sess.run(w_vector))
with ops.Graph().as_default():
w_scalar = variables.VariableV1(86, name="w")
with session.Session(server.target, config=sharing_config) as sess:
with self.assertRaises(errors_impl.InvalidArgumentError):
sess.run(w_scalar.initializer)
with ops.Graph().as_default():
w_scalar = variables.VariableV1(37, name="w")
with session.Session(server.target, config=isolate_config) as sess:
with self.assertRaises(errors_impl.FailedPreconditionError):
sess.run(w_scalar)
sess.run(w_scalar.initializer)
self.assertAllEqual(37, sess.run(w_scalar))
class ServerDefTest(test.TestCase):
def testLocalServer(self):
cluster_def = server_lib.ClusterSpec({
"local": ["localhost:2222"]
}).as_cluster_def()
server_def = tensorflow_server_pb2.ServerDef(
cluster=cluster_def, job_name="local", task_index=0, protocol="grpc")
self.assertProtoEquals("""
cluster {
job { name: 'local' tasks { key: 0 value: 'localhost:2222' } }
}
job_name: 'local' task_index: 0 protocol: 'grpc'
""", server_def)
# Verifies round trip from Proto->Spec->Proto is correct.
cluster_spec = server_lib.ClusterSpec(cluster_def)
self.assertProtoEquals(cluster_def, cluster_spec.as_cluster_def())
def testTwoProcesses(self):
cluster_def = server_lib.ClusterSpec({
"local": ["localhost:2222", "localhost:2223"]
}).as_cluster_def()
server_def = tensorflow_server_pb2.ServerDef(
cluster=cluster_def, job_name="local", task_index=1, protocol="grpc")
self.assertProtoEquals("""
cluster {
job { name: 'local' tasks { key: 0 value: 'localhost:2222' }
tasks { key: 1 value: 'localhost:2223' } }
}
job_name: 'local' task_index: 1 protocol: 'grpc'
""", server_def)
# Verifies round trip from Proto->Spec->Proto is correct.
cluster_spec = server_lib.ClusterSpec(cluster_def)
self.assertProtoEquals(cluster_def, cluster_spec.as_cluster_def())
def testTwoJobs(self):
cluster_def = server_lib.ClusterSpec({
"ps": ["ps0:2222", "ps1:2222"],
"worker": ["worker0:2222", "worker1:2222", "worker2:2222"]
}).as_cluster_def()
server_def = tensorflow_server_pb2.ServerDef(
cluster=cluster_def, job_name="worker", task_index=2, protocol="grpc")
self.assertProtoEquals("""
cluster {
job { name: 'ps' tasks { key: 0 value: 'ps0:2222' }
tasks { key: 1 value: 'ps1:2222' } }
job { name: 'worker' tasks { key: 0 value: 'worker0:2222' }
tasks { key: 1 value: 'worker1:2222' }
tasks { key: 2 value: 'worker2:2222' } }
}
job_name: 'worker' task_index: 2 protocol: 'grpc'
""", server_def)
# Verifies round trip from Proto->Spec->Proto is correct.
cluster_spec = server_lib.ClusterSpec(cluster_def)
self.assertProtoEquals(cluster_def, cluster_spec.as_cluster_def())
def testDenseAndSparseJobs(self):
cluster_def = server_lib.ClusterSpec({
"ps": ["ps0:2222", "ps1:2222"],
"worker": {
0: "worker0:2222",
2: "worker2:2222"
}
}).as_cluster_def()
server_def = tensorflow_server_pb2.ServerDef(
cluster=cluster_def, job_name="worker", task_index=2, protocol="grpc")
self.assertProtoEquals("""
cluster {
job { name: 'ps' tasks { key: 0 value: 'ps0:2222' }
tasks { key: 1 value: 'ps1:2222' } }
job { name: 'worker' tasks { key: 0 value: 'worker0:2222' }
tasks { key: 2 value: 'worker2:2222' } }
}
job_name: 'worker' task_index: 2 protocol: 'grpc'
""", server_def)
# Verifies round trip from Proto->Spec->Proto is correct.
cluster_spec = server_lib.ClusterSpec(cluster_def)
self.assertProtoEquals(cluster_def, cluster_spec.as_cluster_def())
class ClusterSpecTest(test.TestCase):
def testStringConversion(self):
cluster_spec = server_lib.ClusterSpec({
"ps": ["ps0:1111"],
"worker": ["worker0:3333", "worker1:4444"]
})
expected_str = (
"ClusterSpec({'ps': ['ps0:1111'], 'worker': ['worker0:3333', "
"'worker1:4444']})")
self.assertEqual(expected_str, str(cluster_spec))
def testProtoDictDefEquivalences(self):
cluster_spec = server_lib.ClusterSpec({
"ps": ["ps0:2222", "ps1:2222"],
"worker": ["worker0:2222", "worker1:2222", "worker2:2222"]
})
expected_proto = """
job { name: 'ps' tasks { key: 0 value: 'ps0:2222' }
tasks { key: 1 value: 'ps1:2222' } }
job { name: 'worker' tasks { key: 0 value: 'worker0:2222' }
tasks { key: 1 value: 'worker1:2222' }
tasks { key: 2 value: 'worker2:2222' } }
"""
self.assertProtoEquals(expected_proto, cluster_spec.as_cluster_def())
self.assertProtoEquals(
expected_proto, server_lib.ClusterSpec(cluster_spec).as_cluster_def())
self.assertProtoEquals(
expected_proto,
server_lib.ClusterSpec(cluster_spec.as_cluster_def()).as_cluster_def())
self.assertProtoEquals(
expected_proto,
server_lib.ClusterSpec(cluster_spec.as_dict()).as_cluster_def())
def testClusterSpecAccessors(self):
original_dict = {
"ps": ["ps0:2222", "ps1:2222"],
"worker": ["worker0:2222", "worker1:2222", "worker2:2222"],
"sparse": {
0: "sparse0:2222",
3: "sparse3:2222"
}
}
cluster_spec = server_lib.ClusterSpec(original_dict)
self.assertEqual(original_dict, cluster_spec.as_dict())
self.assertEqual(2, cluster_spec.num_tasks("ps"))
self.assertEqual(3, cluster_spec.num_tasks("worker"))
self.assertEqual(2, cluster_spec.num_tasks("sparse"))
with self.assertRaises(ValueError):
cluster_spec.num_tasks("unknown")
self.assertEqual("ps0:2222", cluster_spec.task_address("ps", 0))
self.assertEqual("sparse0:2222", cluster_spec.task_address("sparse", 0))
with self.assertRaises(ValueError):
cluster_spec.task_address("unknown", 0)
with self.assertRaises(ValueError):
cluster_spec.task_address("sparse", 2)
self.assertEqual([0, 1], cluster_spec.task_indices("ps"))
self.assertEqual([0, 1, 2], cluster_spec.task_indices("worker"))
self.assertEqual([0, 3], cluster_spec.task_indices("sparse"))
with self.assertRaises(ValueError):
cluster_spec.task_indices("unknown")
# NOTE(mrry): `ClusterSpec.job_tasks()` is not recommended for use
# with sparse jobs.
self.assertEqual(["ps0:2222", "ps1:2222"], cluster_spec.job_tasks("ps"))
self.assertEqual(["worker0:2222", "worker1:2222", "worker2:2222"],
cluster_spec.job_tasks("worker"))
self.assertEqual(["sparse0:2222", None, None, "sparse3:2222"],
cluster_spec.job_tasks("sparse"))
with self.assertRaises(ValueError):
cluster_spec.job_tasks("unknown")
def testEmptyClusterSpecIsFalse(self):
self.assertFalse(server_lib.ClusterSpec({}))
def testNonEmptyClusterSpecIsTrue(self):
self.assertTrue(server_lib.ClusterSpec({"job": ["host:port"]}))
def testEq(self):
self.assertEquals(server_lib.ClusterSpec({}), server_lib.ClusterSpec({}))
self.assertEquals(
server_lib.ClusterSpec({
"job": ["host:2222"]
}),
server_lib.ClusterSpec({
"job": ["host:2222"]
}),)
self.assertEquals(
server_lib.ClusterSpec({
"job": {
0: "host:2222"
}
}), server_lib.ClusterSpec({
"job": ["host:2222"]
}))
def testNe(self):
self.assertNotEquals(
server_lib.ClusterSpec({}),
server_lib.ClusterSpec({
"job": ["host:2223"]
}),)
self.assertNotEquals(
server_lib.ClusterSpec({
"job1": ["host:2222"]
}),
server_lib.ClusterSpec({
"job2": ["host:2222"]
}),)
self.assertNotEquals(
server_lib.ClusterSpec({
"job": ["host:2222"]
}),
server_lib.ClusterSpec({
"job": ["host:2223"]
}),)
self.assertNotEquals(
server_lib.ClusterSpec({
"job": ["host:2222", "host:2223"]
}),
server_lib.ClusterSpec({
"job": ["host:2223", "host:2222"]
}),)
if __name__ == "__main__":
test.main()
|
apache-2.0
|
[
3,
1898,
9708,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
2925,
367,
2833,
14,
39,
4354,
3120,
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,
900,
199,
199,
646,
2680,
465,
980,
199,
199,
504,
3228,
14,
1018,
14,
7204,
492,
1101,
63,
3317,
18,
199,
504,
3228,
14,
1018,
14,
7204,
492,
3228,
63,
1000,
63,
3317,
18,
199,
504,
3228,
14,
1548,
14,
1258,
492,
2351,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4413,
63,
411,
199,
504,
3228,
14,
1548,
14,
4857,
492,
6674,
199,
504,
3228,
14,
1548,
14,
4857,
492,
2552,
63,
5472,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4156,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1625,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
666,
63,
1659,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3473,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
2860,
199,
504,
3228,
14,
1548,
14,
3246,
492,
511,
199,
504,
3228,
14,
1548,
14,
7588,
492,
1324,
465,
1324,
63,
1483,
199,
504,
3228,
14,
1548,
14,
7588,
492,
4126,
63,
5933,
63,
5472,
199,
504,
3228,
14,
1548,
14,
7588,
492,
1654,
63,
773,
421,
199,
533,
598,
4354,
3120,
774,
8,
396,
14,
1746,
304,
819,
347,
636,
826,
721,
277,
12,
23352,
628,
27850,
2349,
221,
327,
4287,
26,
3507,
29,
3197,
13,
354,
272,
1613,
8,
39,
4354,
3120,
774,
12,
291,
2843,
826,
721,
765,
985,
9,
272,
291,
423,
5245,
63,
1000,
275,
1654,
63,
773,
14,
3120,
14,
981,
63,
1832,
63,
1000,
342,
819,
347,
511,
2540,
7801,
8,
277,
304,
272,
1654,
275,
291,
423,
5245,
63,
1000,
339,
543,
2351,
14,
4434,
8,
1000,
14,
1375,
9,
465,
4043,
26,
489,
286,
275,
4413,
63,
411,
14,
4083,
4038,
18,
12,
413,
3934,
489,
366,
275,
4413,
63,
411,
14,
4083,
4038,
17,
467,
359,
18,
3934,
489,
325,
275,
3473,
63,
1483,
14,
14465,
8,
67,
12,
366,
9,
489,
291,
14,
7069,
4038,
20,
2365,
4043,
14,
1065,
8,
69,
430,
272,
327,
3254,
8,
13118,
651,
304,
2654,
658,
1000,
14,
2379,
11995,
436,
658,
1000,
14,
904,
11995,
1380,
3520,
1736,
14,
819,
347,
511,
8433,
51,
30414,
8,
277,
304,
272,
1654,
275,
291,
423,
5245,
63,
1000,
339,
286,
275,
4413,
63,
411,
14,
4083,
4038,
18,
12,
413,
3934,
272,
366,
275,
4413,
63,
411,
14,
4083,
4038,
17,
467,
359,
18,
3934,
272,
325,
275,
3473,
63,
1483,
14,
14465,
8,
67,
12,
366,
9,
339,
4043,
63,
17,
275,
2351,
14,
4434,
8,
1000,
14,
1375,
9,
272,
4043,
63,
18,
275,
2351,
14,
4434,
8,
1000,
14,
1375,
9,
339,
291,
14,
7069,
4038,
20,
2365,
4043,
63,
17,
14,
1065,
8,
69,
430,
272,
291,
14,
7069,
4038,
20,
2365,
4043,
63,
18,
14,
1065,
8,
69,
430,
339,
4043,
63,
17,
14,
1600,
342,
272,
4043,
63,
18,
14,
1600,
342,
272,
327,
3254,
8,
13118,
651,
304,
2654,
658,
1000,
14,
2379,
11995,
436,
658,
1000,
14,
904,
11995,
1380,
3520,
1736,
14,
819,
327,
26114,
7750,
5305,
9081,
14,
523,
347,
511,
9637,
4874,
83,
8,
277,
304,
272,
327,
10560,
1750,
543,
3970,
536,
14,
272,
543,
4156,
14,
3600,
480,
396,
16,
2349,
489,
373,
16,
275,
2860,
14,
2773,
54,
17,
8,
17,
14,
16,
12,
536,
628,
86,
16,
531,
272,
327,
10560,
1750,
543,
849,
3970,
14,
272,
373,
17,
275,
2860,
14,
2773,
54,
17,
8,
18,
14,
16,
12,
536,
628,
86,
17,
531,
272,
327,
26114,
5305,
1337,
314,
2222,
13,
15025,
1347,
2529,
1125,
14,
272,
543,
291,
14,
1855,
8,
2550,
63,
5472,
14,
10870,
304,
489,
2351,
14,
4434,
14,
3958,
480,
21573,
401,
2097,
396,
16,
3135,
339,
327,
26114,
5305,
1337,
543,
1101,
14,
272,
327,
26114,
626,
5305,
1337,
1347,
543,
949,
1654,
5431,
734,
14,
272,
543,
291,
14,
1855,
8,
2550,
63,
5472,
14,
22147,
604,
24748,
547,
304,
489,
2351,
14,
4434,
14,
3958,
8,
881,
298,
15391,
921,
5967,
26,
16,
401,
2097,
396,
16,
2255,
881,
1101,
29,
888,
63,
3317,
18,
14,
2028,
8548,
8,
5735,
63,
2593,
63,
262,
63,
706,
29,
21,
430,
339,
327,
26114,
949,
15333,
787,
5305,
543,
2222,
13,
15025,
3970,
14,
272,
1654,
275,
291,
423,
5245,
63,
1000,
272,
4043,
275,
2351,
14,
4434,
8,
1000,
14,
1375,
9,
272,
4043,
14,
1065,
8,
3669,
14,
2966,
63,
3669,
63,
6498,
1012,
272,
291,
14,
7069,
8,
17,
14,
16,
12,
4043,
14,
1065,
8,
86,
16,
430,
272,
291,
14,
7069,
8,
18,
14,
16,
12,
4043,
14,
1065,
8,
86,
17,
430,
272,
327,
3091,
3970,
365,
5305,
12,
1325,
314,
1654,
365,
5305,
14,
272,
2351,
14,
4434,
14,
3958,
8,
1000,
14,
1375,
12,
2097,
396,
17,
3135,
272,
327,
26114,
626,
3865,
2860,
787,
5139,
1686,
14,
272,
4043,
275,
2351,
14,
4434,
8,
1000,
14,
1375,
9,
272,
291,
14,
7069,
8,
17,
14,
16,
12,
4043,
14,
1065,
8,
86,
16,
430,
272,
291,
14,
7069,
8,
18,
14,
16,
12,
4043,
14
] |
[
1898,
9708,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
2925,
367,
2833,
14,
39,
4354,
3120,
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,
900,
199,
199,
646,
2680,
465,
980,
199,
199,
504,
3228,
14,
1018,
14,
7204,
492,
1101,
63,
3317,
18,
199,
504,
3228,
14,
1018,
14,
7204,
492,
3228,
63,
1000,
63,
3317,
18,
199,
504,
3228,
14,
1548,
14,
1258,
492,
2351,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4413,
63,
411,
199,
504,
3228,
14,
1548,
14,
4857,
492,
6674,
199,
504,
3228,
14,
1548,
14,
4857,
492,
2552,
63,
5472,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4156,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1625,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
666,
63,
1659,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3473,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
2860,
199,
504,
3228,
14,
1548,
14,
3246,
492,
511,
199,
504,
3228,
14,
1548,
14,
7588,
492,
1324,
465,
1324,
63,
1483,
199,
504,
3228,
14,
1548,
14,
7588,
492,
4126,
63,
5933,
63,
5472,
199,
504,
3228,
14,
1548,
14,
7588,
492,
1654,
63,
773,
421,
199,
533,
598,
4354,
3120,
774,
8,
396,
14,
1746,
304,
819,
347,
636,
826,
721,
277,
12,
23352,
628,
27850,
2349,
221,
327,
4287,
26,
3507,
29,
3197,
13,
354,
272,
1613,
8,
39,
4354,
3120,
774,
12,
291,
2843,
826,
721,
765,
985,
9,
272,
291,
423,
5245,
63,
1000,
275,
1654,
63,
773,
14,
3120,
14,
981,
63,
1832,
63,
1000,
342,
819,
347,
511,
2540,
7801,
8,
277,
304,
272,
1654,
275,
291,
423,
5245,
63,
1000,
339,
543,
2351,
14,
4434,
8,
1000,
14,
1375,
9,
465,
4043,
26,
489,
286,
275,
4413,
63,
411,
14,
4083,
4038,
18,
12,
413,
3934,
489,
366,
275,
4413,
63,
411,
14,
4083,
4038,
17,
467,
359,
18,
3934,
489,
325,
275,
3473,
63,
1483,
14,
14465,
8,
67,
12,
366,
9,
489,
291,
14,
7069,
4038,
20,
2365,
4043,
14,
1065,
8,
69,
430,
272,
327,
3254,
8,
13118,
651,
304,
2654,
658,
1000,
14,
2379,
11995,
436,
658,
1000,
14,
904,
11995,
1380,
3520,
1736,
14,
819,
347,
511,
8433,
51,
30414,
8,
277,
304,
272,
1654,
275,
291,
423,
5245,
63,
1000,
339,
286,
275,
4413,
63,
411,
14,
4083,
4038,
18,
12,
413,
3934,
272,
366,
275,
4413,
63,
411,
14,
4083,
4038,
17,
467,
359,
18,
3934,
272,
325,
275,
3473,
63,
1483,
14,
14465,
8,
67,
12,
366,
9,
339,
4043,
63,
17,
275,
2351,
14,
4434,
8,
1000,
14,
1375,
9,
272,
4043,
63,
18,
275,
2351,
14,
4434,
8,
1000,
14,
1375,
9,
339,
291,
14,
7069,
4038,
20,
2365,
4043,
63,
17,
14,
1065,
8,
69,
430,
272,
291,
14,
7069,
4038,
20,
2365,
4043,
63,
18,
14,
1065,
8,
69,
430,
339,
4043,
63,
17,
14,
1600,
342,
272,
4043,
63,
18,
14,
1600,
342,
272,
327,
3254,
8,
13118,
651,
304,
2654,
658,
1000,
14,
2379,
11995,
436,
658,
1000,
14,
904,
11995,
1380,
3520,
1736,
14,
819,
327,
26114,
7750,
5305,
9081,
14,
523,
347,
511,
9637,
4874,
83,
8,
277,
304,
272,
327,
10560,
1750,
543,
3970,
536,
14,
272,
543,
4156,
14,
3600,
480,
396,
16,
2349,
489,
373,
16,
275,
2860,
14,
2773,
54,
17,
8,
17,
14,
16,
12,
536,
628,
86,
16,
531,
272,
327,
10560,
1750,
543,
849,
3970,
14,
272,
373,
17,
275,
2860,
14,
2773,
54,
17,
8,
18,
14,
16,
12,
536,
628,
86,
17,
531,
272,
327,
26114,
5305,
1337,
314,
2222,
13,
15025,
1347,
2529,
1125,
14,
272,
543,
291,
14,
1855,
8,
2550,
63,
5472,
14,
10870,
304,
489,
2351,
14,
4434,
14,
3958,
480,
21573,
401,
2097,
396,
16,
3135,
339,
327,
26114,
5305,
1337,
543,
1101,
14,
272,
327,
26114,
626,
5305,
1337,
1347,
543,
949,
1654,
5431,
734,
14,
272,
543,
291,
14,
1855,
8,
2550,
63,
5472,
14,
22147,
604,
24748,
547,
304,
489,
2351,
14,
4434,
14,
3958,
8,
881,
298,
15391,
921,
5967,
26,
16,
401,
2097,
396,
16,
2255,
881,
1101,
29,
888,
63,
3317,
18,
14,
2028,
8548,
8,
5735,
63,
2593,
63,
262,
63,
706,
29,
21,
430,
339,
327,
26114,
949,
15333,
787,
5305,
543,
2222,
13,
15025,
3970,
14,
272,
1654,
275,
291,
423,
5245,
63,
1000,
272,
4043,
275,
2351,
14,
4434,
8,
1000,
14,
1375,
9,
272,
4043,
14,
1065,
8,
3669,
14,
2966,
63,
3669,
63,
6498,
1012,
272,
291,
14,
7069,
8,
17,
14,
16,
12,
4043,
14,
1065,
8,
86,
16,
430,
272,
291,
14,
7069,
8,
18,
14,
16,
12,
4043,
14,
1065,
8,
86,
17,
430,
272,
327,
3091,
3970,
365,
5305,
12,
1325,
314,
1654,
365,
5305,
14,
272,
2351,
14,
4434,
14,
3958,
8,
1000,
14,
1375,
12,
2097,
396,
17,
3135,
272,
327,
26114,
626,
3865,
2860,
787,
5139,
1686,
14,
272,
4043,
275,
2351,
14,
4434,
8,
1000,
14,
1375,
9,
272,
291,
14,
7069,
8,
17,
14,
16,
12,
4043,
14,
1065,
8,
86,
16,
430,
272,
291,
14,
7069,
8,
18,
14,
16,
12,
4043,
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,
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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
] |
flavour/ifrc_qa
|
modules/tests/org/create_facility.py
|
1
|
2200
|
""" Sahana Eden Automated Test - INV023 Create Facilty
@copyright: 2011-2016 (c) Sahana Software Foundation
@license: MIT
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
"""
from tests.web2unittest import SeleniumUnitTest
class CreateFacility(SeleniumUnitTest):
def test_inv023_create_facility(self):
"""
@case:INV023
@description: Create a Facility
@TestDoc: https://docs.google.com/spreadsheet/ccc?key=0AmB3hMcgB-3idG1XNGhhRG9QWF81dUlKLXpJaFlCMFE
@Test Wiki: http://eden.sahanafoundation.org/wiki/DeveloperGuidelines/Testing
"""
print "\n"
self.login(account="admin", nexturl="org/facility/create")
self.create("org_facility",
[( "name",
"International Federation of Red Cross and Red Crescent Societies"),
( "organisation_id",
"Acme Suppliers"),
( "comments",
"testing purpose only"),
]
)
# END =========================================================================
|
mit
|
[
624,
428,
11326,
6738,
662,
848,
27722,
23513,
1379,
446,
1621,
54,
16771,
2790,
481,
645,
382,
369,
339,
768,
7307,
26,
7760,
13,
9261,
334,
67,
9,
428,
11326,
6738,
2290,
2752,
272,
768,
1682,
26,
10697,
339,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
272,
12408,
282,
1331,
402,
642,
2032,
436,
4568,
3794,
272,
1584,
334,
1589,
298,
10337,
1288,
370,
7962,
315,
314,
2290,
1928,
272,
10588,
12,
5893,
1928,
12305,
314,
4481,
370,
675,
12,
272,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
11207,
12,
13473,
12,
436,
15,
269,
12743,
272,
6866,
402,
314,
2290,
12,
436,
370,
11291,
12103,
370,
12676,
314,
272,
2290,
365,
13985,
370,
886,
880,
12,
5420,
370,
314,
2569,
272,
3704,
26,
339,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
272,
5120,
315,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
339,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
272,
7168,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
272,
1634,
3169,
12,
3092,
2381,
437,
3115,
3104,
2401,
272,
13229,
14,
1621,
4825,
6461,
7000,
2334,
10610,
1549,
5877,
272,
8164,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
272,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
272,
4442,
12,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
272,
5010,
13198,
1621,
2334,
4141,
14,
199,
624,
199,
199,
504,
2295,
14,
2520,
18,
2796,
492,
3240,
9465,
29037,
199,
199,
533,
2790,
1906,
12498,
8,
31315,
29037,
304,
272,
347,
511,
63,
5350,
16771,
63,
981,
63,
22354,
8,
277,
304,
267,
408,
288,
768,
2546,
26,
568,
54,
16771,
288,
768,
1802,
26,
2790,
282,
10859,
12498,
953,
768,
774,
3768,
26,
4178,
921,
4757,
14,
3098,
14,
957,
15,
19930,
15,
19504,
31,
498,
29,
16,
24566,
34,
19,
72,
45,
12595,
34,
13,
19,
344,
39,
17,
56,
12259,
12156,
14058,
25,
49,
29046,
2835,
68,
18505,
14307,
56,
80,
42,
65,
7579,
9249,
5100,
288,
768,
774,
644,
11545,
26,
1455,
921,
69,
848,
14,
2231,
72,
6738,
4214,
425,
14,
1308,
15,
6797,
15,
31032,
4324,
271,
1278,
15,
9029,
267,
408,
267,
870,
1867,
78,
2,
398,
291,
14,
2886,
8,
2048,
628,
2113,
401,
2163,
633,
628,
1308,
15,
22354,
15,
981,
531,
398,
291,
14,
981,
480,
1308,
63,
22354,
401,
490,
3842,
298,
354,
401,
2432,
298,
30886,
7949,
32643,
402,
9572,
28965,
436,
9572,
445,
470,
2946,
2002,
559,
69,
1417,
1288,
2151,
334,
298,
17425,
63,
344,
401,
2432,
298,
1945,
278,
29083,
14035,
1288,
2151,
334,
298,
6223,
401,
2432,
298,
4776,
12016,
1454,
1288,
2151,
1622,
2151,
776,
199,
199,
3,
7729,
7819,
763,
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
] |
[
428,
11326,
6738,
662,
848,
27722,
23513,
1379,
446,
1621,
54,
16771,
2790,
481,
645,
382,
369,
339,
768,
7307,
26,
7760,
13,
9261,
334,
67,
9,
428,
11326,
6738,
2290,
2752,
272,
768,
1682,
26,
10697,
339,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
272,
12408,
282,
1331,
402,
642,
2032,
436,
4568,
3794,
272,
1584,
334,
1589,
298,
10337,
1288,
370,
7962,
315,
314,
2290,
1928,
272,
10588,
12,
5893,
1928,
12305,
314,
4481,
370,
675,
12,
272,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
11207,
12,
13473,
12,
436,
15,
269,
12743,
272,
6866,
402,
314,
2290,
12,
436,
370,
11291,
12103,
370,
12676,
314,
272,
2290,
365,
13985,
370,
886,
880,
12,
5420,
370,
314,
2569,
272,
3704,
26,
339,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
272,
5120,
315,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
339,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
272,
7168,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
272,
1634,
3169,
12,
3092,
2381,
437,
3115,
3104,
2401,
272,
13229,
14,
1621,
4825,
6461,
7000,
2334,
10610,
1549,
5877,
272,
8164,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
272,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
272,
4442,
12,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
272,
5010,
13198,
1621,
2334,
4141,
14,
199,
624,
199,
199,
504,
2295,
14,
2520,
18,
2796,
492,
3240,
9465,
29037,
199,
199,
533,
2790,
1906,
12498,
8,
31315,
29037,
304,
272,
347,
511,
63,
5350,
16771,
63,
981,
63,
22354,
8,
277,
304,
267,
408,
288,
768,
2546,
26,
568,
54,
16771,
288,
768,
1802,
26,
2790,
282,
10859,
12498,
953,
768,
774,
3768,
26,
4178,
921,
4757,
14,
3098,
14,
957,
15,
19930,
15,
19504,
31,
498,
29,
16,
24566,
34,
19,
72,
45,
12595,
34,
13,
19,
344,
39,
17,
56,
12259,
12156,
14058,
25,
49,
29046,
2835,
68,
18505,
14307,
56,
80,
42,
65,
7579,
9249,
5100,
288,
768,
774,
644,
11545,
26,
1455,
921,
69,
848,
14,
2231,
72,
6738,
4214,
425,
14,
1308,
15,
6797,
15,
31032,
4324,
271,
1278,
15,
9029,
267,
408,
267,
870,
1867,
78,
2,
398,
291,
14,
2886,
8,
2048,
628,
2113,
401,
2163,
633,
628,
1308,
15,
22354,
15,
981,
531,
398,
291,
14,
981,
480,
1308,
63,
22354,
401,
490,
3842,
298,
354,
401,
2432,
298,
30886,
7949,
32643,
402,
9572,
28965,
436,
9572,
445,
470,
2946,
2002,
559,
69,
1417,
1288,
2151,
334,
298,
17425,
63,
344,
401,
2432,
298,
1945,
278,
29083,
14035,
1288,
2151,
334,
298,
6223,
401,
2432,
298,
4776,
12016,
1454,
1288,
2151,
1622,
2151,
776,
199,
199,
3,
7729,
7819,
763,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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se import make_option
from django.conf import settings
from django.core.management.base import BaseCommand, CommandError
from olympia.landfill.generators import generate_addons
class Command(BaseCommand):
"""
Generate example addons for development/testing purpose.
Addons will have 1 preview image, 2 translations (French and
Spanish), 5 ratings and might be featured randomly. If you don't
provide any --owner email address, all created add-ons will have
'nobody@mozilla.org' as owner. If you don't provide any --app name,
all created add-ons will have 'firefox' as application.
Categories from production (Alerts & Updates, Appearance, etc)
will be created and randomly populated with generated addons.
Usage:
python manage.py generate_addons <num_addons>
[--owner <email>] [--app <application>]
"""
help = __doc__
option_list = BaseCommand.option_list + (
make_option('--owner', action='store', dest='email',
default='nobody@mozilla.org',
help="Specific owner's email to be created."),
make_option('--app', action='store', dest='app_name',
default='firefox',
help="Specific application targeted by add-ons creation."),
)
def handle(self, *args, **kwargs):
if not settings.DEBUG:
raise CommandError('You can only run this command with your '
'DEBUG setting set to True.')
num = int(args[0])
email = kwargs.get('email')
app_name = kwargs.get('app_name')
generate_addons(num, email, app_name)
|
bsd-3-clause
|
[
504,
8691,
492,
1852,
63,
1422,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1018,
14,
8110,
14,
1095,
492,
22239,
12,
14393,
199,
199,
504,
312,
590,
311,
4674,
14,
9688,
4498,
14,
20748,
492,
3550,
63,
10788,
421,
199,
533,
5817,
8,
25150,
304,
272,
408,
272,
7958,
2893,
21293,
367,
16367,
15,
4776,
12016,
14,
339,
2654,
4654,
911,
1172,
413,
19653,
1834,
12,
499,
15547,
334,
38,
15148,
436,
272,
32091,
2453,
395,
959,
32026,
780,
436,
5594,
506,
13953,
3297,
19311,
14,
982,
1265,
2793,
1133,
272,
5647,
1263,
1553,
4597,
3031,
2287,
12,
1006,
2737,
1050,
13,
4654,
911,
1172,
272,
283,
889,
2030,
32,
12102,
14,
1308,
7,
465,
5771,
14,
982,
1265,
2793,
1133,
5647,
1263,
1553,
571,
536,
12,
272,
1006,
2737,
1050,
13,
4654,
911,
1172,
283,
15394,
7,
465,
4223,
14,
339,
23995,
6112,
687,
9920,
334,
33,
16676,
1253,
24663,
12,
13450,
16343,
554,
12,
5423,
9,
272,
911,
506,
2737,
436,
19311,
16460,
543,
4046,
21293,
14,
339,
11028,
26,
398,
2366,
9635,
14,
647,
3550,
63,
10788,
665,
1507,
63,
10788,
30,
288,
19344,
4597,
665,
2123,
19109,
19344,
571,
665,
3578,
19109,
339,
408,
339,
1720,
275,
636,
1301,
363,
272,
945,
63,
513,
275,
22239,
14,
1422,
63,
513,
435,
334,
267,
1852,
63,
1422,
4517,
4597,
297,
1595,
534,
1617,
297,
2053,
534,
2123,
297,
490,
849,
534,
889,
2030,
32,
12102,
14,
1308,
297,
490,
1720,
628,
16786,
5771,
1159,
3031,
370,
506,
2737,
7651,
267,
1852,
63,
1422,
4517,
571,
297,
1595,
534,
1617,
297,
2053,
534,
571,
63,
354,
297,
490,
849,
534,
15394,
297,
490,
1720,
628,
16786,
4223,
307,
20174,
701,
1050,
13,
4654,
7143,
7651,
272,
776,
339,
347,
2429,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
340,
440,
2202,
14,
5287,
26,
288,
746,
14393,
360,
5556,
883,
1454,
1255,
642,
1414,
543,
2195,
283,
3044,
283,
5287,
4260,
663,
370,
715,
2659,
267,
1967,
275,
1109,
8,
589,
59,
16,
566,
267,
3031,
275,
2074,
14,
362,
360,
2123,
358,
267,
1145,
63,
354,
275,
2074,
14,
362,
360,
571,
63,
354,
358,
267,
3550,
63,
10788,
8,
1507,
12,
3031,
12,
1145,
63,
354,
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
] |
[
8691,
492,
1852,
63,
1422,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1018,
14,
8110,
14,
1095,
492,
22239,
12,
14393,
199,
199,
504,
312,
590,
311,
4674,
14,
9688,
4498,
14,
20748,
492,
3550,
63,
10788,
421,
199,
533,
5817,
8,
25150,
304,
272,
408,
272,
7958,
2893,
21293,
367,
16367,
15,
4776,
12016,
14,
339,
2654,
4654,
911,
1172,
413,
19653,
1834,
12,
499,
15547,
334,
38,
15148,
436,
272,
32091,
2453,
395,
959,
32026,
780,
436,
5594,
506,
13953,
3297,
19311,
14,
982,
1265,
2793,
1133,
272,
5647,
1263,
1553,
4597,
3031,
2287,
12,
1006,
2737,
1050,
13,
4654,
911,
1172,
272,
283,
889,
2030,
32,
12102,
14,
1308,
7,
465,
5771,
14,
982,
1265,
2793,
1133,
5647,
1263,
1553,
571,
536,
12,
272,
1006,
2737,
1050,
13,
4654,
911,
1172,
283,
15394,
7,
465,
4223,
14,
339,
23995,
6112,
687,
9920,
334,
33,
16676,
1253,
24663,
12,
13450,
16343,
554,
12,
5423,
9,
272,
911,
506,
2737,
436,
19311,
16460,
543,
4046,
21293,
14,
339,
11028,
26,
398,
2366,
9635,
14,
647,
3550,
63,
10788,
665,
1507,
63,
10788,
30,
288,
19344,
4597,
665,
2123,
19109,
19344,
571,
665,
3578,
19109,
339,
408,
339,
1720,
275,
636,
1301,
363,
272,
945,
63,
513,
275,
22239,
14,
1422,
63,
513,
435,
334,
267,
1852,
63,
1422,
4517,
4597,
297,
1595,
534,
1617,
297,
2053,
534,
2123,
297,
490,
849,
534,
889,
2030,
32,
12102,
14,
1308,
297,
490,
1720,
628,
16786,
5771,
1159,
3031,
370,
506,
2737,
7651,
267,
1852,
63,
1422,
4517,
571,
297,
1595,
534,
1617,
297,
2053,
534,
571,
63,
354,
297,
490,
849,
534,
15394,
297,
490,
1720,
628,
16786,
4223,
307,
20174,
701,
1050,
13,
4654,
7143,
7651,
272,
776,
339,
347,
2429,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
340,
440,
2202,
14,
5287,
26,
288,
746,
14393,
360,
5556,
883,
1454,
1255,
642,
1414,
543,
2195,
283,
3044,
283,
5287,
4260,
663,
370,
715,
2659,
267,
1967,
275,
1109,
8,
589,
59,
16,
566,
267,
3031,
275,
2074,
14,
362,
360,
2123,
358,
267,
1145,
63,
354,
275,
2074,
14,
362,
360,
571,
63,
354,
358,
267,
3550,
63,
10788,
8,
1507,
12,
3031,
12,
1145,
63,
354,
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,
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
] |
KhronosGroup/COLLADA-CTS
|
StandardDataSets/1_5/collada/asset/coverage/geographic_location/absolute/absolute.py
|
1
|
4333
|
# Copyright (c) 2012 The Khronos Group Inc.
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and /or associated documentation files (the "Materials "), to deal in the Materials without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Materials, and to permit persons to whom the Materials are furnished to do so, subject to
# the following conditions:
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Materials.
# THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
# See Core.Logic.FJudgementContext for the information
# of the 'context' parameter.
# This sample judging object does the following:
#
# JudgeBaseline: just verifies that the standard steps did not crash.
# JudgeSuperior: also verifies that the validation steps are not in error.
# JudgeExemplary: same as intermediate badge.
# We import an assistant script that includes the common verifications
# methods. The assistant buffers its checks, so that running them again
# does not incurs an unnecessary performance hint.
from StandardDataSets.scripts import JudgeAssistant
# Please feed your node list here:
tagLst = [['asset', 'coverage', 'geographic_location', 'longitude'],
['asset', 'coverage', 'geographic_location', 'latitude'],
['asset', 'coverage', 'geographic_location', 'altitude']]
attrName = 'mode'
attrVal = ''
dataToCheck = ''
class SimpleJudgingObject:
def __init__(self, _tagLst, _attrName, _attrVal, _data):
self.tagList = _tagLst
self.attrName = _attrName
self.attrVal = _attrVal
self.dataToCheck = _data
self.status_baseline = False
self.status_superior = False
self.status_exemplary = False
self.__assistant = JudgeAssistant.JudgeAssistant()
def JudgeBaseline(self, context):
# No step should not crash
self.__assistant.CheckCrashes(context)
# Import/export/validate must exist and pass, while Render must only exist.
self.__assistant.CheckSteps(context, ["Import", "Export", "Validate"], ["Render"])
self.status_baseline = self.__assistant.GetResults()
return self.status_baseline
# To pass intermediate you need to pass basic, this object could also include additional
# tests that were specific to the intermediate badge.
def JudgeSuperior(self, context):
self.status_superior = self.status_baseline
return self.status_superior
# To pass advanced you need to pass intermediate, this object could also include additional
# tests that were specific to the advanced badge
def JudgeExemplary(self, context):
# if superior fails, no point in further checking
if (self.status_superior == False):
self.status_exemplary = self.status_superior
return self.status_exemplary
# Compare the rendered images
self.__assistant.CompareRenderedImages(context)
self.__assistant.ElementDataPreserved(context, self.tagList[0], "float")
self.__assistant.ElementDataPreserved(context, self.tagList[1], "float")
self.__assistant.ElementDataPreserved(context, self.tagList[2], "float")
self.__assistant.AttributePreserved(context, self.tagList[2], self.attrName)
self.status_exemplary = self.__assistant.DeferJudgement(context)
return self.status_exemplary
# This is where all the work occurs: "judgingObject" is an absolutely necessary token.
# The dynamic loader looks very specifically for a class instance named "judgingObject".
#
judgingObject = SimpleJudgingObject(tagLst, attrName, attrVal, dataToCheck);
|
mit
|
[
202,
199,
3,
1898,
334,
67,
9,
6029,
710,
1804,
72,
2641,
736,
5611,
3277,
14,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
1331,
402,
642,
2032,
436,
1182,
269,
4568,
3794,
1584,
334,
1589,
298,
15787,
83,
26261,
370,
7962,
315,
314,
26570,
83,
1928,
10588,
12,
5893,
1928,
12305,
314,
4481,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
11207,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
314,
26570,
83,
12,
436,
370,
11291,
12103,
370,
12676,
314,
26570,
83,
787,
13985,
370,
886,
880,
12,
5420,
370,
199,
3,
314,
2569,
3704,
26,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
221,
199,
3,
315,
1006,
6866,
503,
13393,
12468,
402,
314,
26570,
83,
14,
221,
199,
3,
2334,
603,
10447,
4938,
51,
9315,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
3169,
12,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
7000,
2334,
10610,
1549,
5877,
8164,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
603,
10447,
4938,
51,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
2334,
603,
10447,
4938,
51,
14,
2999,
199,
3,
1666,
11672,
14,
32140,
14,
38,
42,
16603,
434,
2998,
367,
314,
2556,
202,
199,
3,
402,
314,
283,
1100,
7,
2725,
14,
2999,
199,
3,
961,
2690,
1335,
1181,
1540,
909,
1630,
314,
2569,
26,
202,
199,
3,
202,
199,
3,
1603,
16603,
1563,
604,
26,
2951,
22694,
626,
314,
4465,
7124,
8103,
440,
12420,
14,
202,
199,
3,
1603,
16603,
11823,
15499,
26,
2597,
22694,
626,
314,
6411,
7124,
787,
440,
315,
1125,
14,
202,
199,
3,
1603,
16603,
920,
2109,
76,
695,
26,
2011,
465,
13197,
23122,
14,
2999,
199,
3,
2136,
492,
376,
465,
18832,
2884,
626,
6952,
314,
2863,
14786,
83,
202,
199,
3,
3102,
14,
710,
465,
18832,
19383,
2399,
5920,
12,
880,
626,
3879,
3062,
4020,
202,
199,
3,
1630,
440,
315,
17255,
376,
23361,
10238,
8328,
14,
202,
199,
504,
9739,
1451,
9899,
14,
6429,
492,
1603,
16603,
24486,
2999,
199,
3,
7754,
4733,
2195,
1031,
769,
2348,
26,
202,
199,
1450,
30525,
275,
11194,
6562,
297,
283,
10828,
297,
283,
6721,
9770,
63,
1985,
297,
283,
13803,
995,
16765,
788,
6562,
297,
283,
10828,
297,
283,
6721,
9770,
63,
1985,
297,
283,
13331,
995,
16765,
788,
6562,
297,
283,
10828,
297,
283,
6721,
9770,
63,
1985,
297,
283,
27539,
6538,
202,
199,
962,
985,
275,
283,
632,
7,
202,
199,
962,
7562,
275,
2125,
202,
199,
576,
1378,
1799,
275,
2125,
2999,
199,
533,
5870,
42,
1181,
1540,
1692,
26,
1128,
347,
636,
826,
721,
277,
12,
485,
1450,
30525,
12,
485,
962,
985,
12,
485,
962,
7562,
12,
485,
576,
304,
1039,
291,
14,
1450,
1296,
275,
485,
1450,
30525,
1039,
291,
14,
962,
985,
275,
485,
962,
985,
1039,
291,
14,
962,
7562,
275,
485,
962,
7562,
1039,
291,
14,
576,
1378,
1799,
275,
485,
576,
1039,
291,
14,
1205,
63,
14232,
275,
756,
1039,
291,
14,
1205,
63,
4792,
15499,
275,
756,
1039,
291,
14,
1205,
63,
476,
2109,
76,
695,
275,
756,
1039,
291,
855,
7310,
275,
1603,
16603,
24486,
14,
42,
16603,
24486,
342,
26016,
347,
1603,
16603,
1563,
604,
8,
277,
12,
1067,
304,
1039,
327,
3091,
3650,
1077,
440,
12420,
1039,
291,
855,
7310,
14,
1799,
17345,
9030,
8,
1100,
9,
13594,
327,
3161,
15,
3790,
15,
3502,
1471,
2187,
436,
986,
12,
1830,
17769,
1471,
1454,
2187,
14,
1039,
291,
855,
7310,
14,
1799,
20960,
8,
1100,
12,
2097,
6295,
401,
298,
11399,
401,
298,
12584,
2255,
2097,
9216,
3135,
13594,
291,
14,
1205,
63,
14232,
275,
291,
855,
7310,
14,
1002,
6579,
342,
1039,
372,
291,
14,
1205,
63,
14232,
15497,
1128,
327,
4005,
986,
13197,
1265,
1929,
370,
986,
5678,
12,
642,
909,
4293,
2597,
2387,
4722,
26259,
327,
2295,
626,
4898,
2488,
370,
314,
13197,
23122,
14,
1128,
347,
1603,
16603,
11823,
15499,
8,
277,
12,
1067,
304,
1039,
291,
14,
1205,
63,
4792,
15499,
275,
291,
14,
1205,
63,
14232,
1039,
372,
291,
14,
1205,
63,
4792,
15499,
221,
17554,
1128,
327,
4005,
986,
19472,
1265,
1929,
370,
986,
13197,
12,
642,
909,
4293,
2597,
2387,
4722,
1128,
327,
2295,
626,
4898,
2488,
370,
314,
19472,
23122,
1128,
347,
1603,
16603,
920,
2109,
76,
695,
8,
277,
12,
1067,
304,
1223,
198,
3,
340,
1613,
15499,
6918,
12,
949,
2376,
315,
9848,
7907,
1039,
340,
334,
277,
14,
1205,
63,
4792,
15499,
508,
756,
304,
1675,
291,
14,
1205,
63,
476,
2109,
76,
695,
275,
291,
14,
1205,
63,
4792,
15499,
1675,
372,
291,
14,
1205,
63,
476,
2109,
76,
695,
13594,
327,
18955,
314,
8018,
5935,
1039,
291,
855,
7310,
14,
16051,
5349,
2995,
18882,
8,
1100,
9,
13594,
291,
855,
7310,
14,
2162,
1451,
2398,
2485,
8,
1100,
12,
291,
14,
1450,
1296,
59,
16,
467,
298,
1609,
531,
1039,
291,
855,
7310,
14,
2162,
1451,
2398,
2485,
8,
1100,
12,
291,
14,
1450,
1296,
59,
17,
467,
298,
1609,
531,
1039,
291,
855,
7310,
14,
2162,
1451,
2398,
2485,
8,
1100,
12,
291,
14,
1450,
1296,
59,
18,
467,
298,
1609,
531,
1039,
291,
855,
7310,
14,
1646,
2398,
2485,
8,
1100,
12,
291,
14,
1450,
1296,
59,
18,
467,
291,
14,
962,
985,
9,
4341,
291,
14,
1205,
63,
476,
2109,
76,
695,
275,
291,
855,
7310,
14,
872,
2412,
42,
16603,
434,
8,
1100,
9,
1039,
372,
291,
14,
1205,
63,
476,
2109,
76,
695,
30199,
202,
199,
3,
961,
365,
2382,
1006,
314,
1736,
11058,
26,
298,
74,
1181,
1540,
1692,
2,
365,
376,
3679,
590,
5784,
1526,
14,
202,
199,
3,
710,
8336,
5077,
10734,
7437,
22543,
367,
282,
1021,
1256,
4310,
298,
74,
1181,
1540,
1692,
1674,
202,
199,
3,
202,
199,
74,
1181,
1540,
1692,
275,
5870,
42,
1181,
1540,
1692,
8,
1450,
30525
] |
[
199,
3,
1898,
334,
67,
9,
6029,
710,
1804,
72,
2641,
736,
5611,
3277,
14,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
1331,
402,
642,
2032,
436,
1182,
269,
4568,
3794,
1584,
334,
1589,
298,
15787,
83,
26261,
370,
7962,
315,
314,
26570,
83,
1928,
10588,
12,
5893,
1928,
12305,
314,
4481,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
11207,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
314,
26570,
83,
12,
436,
370,
11291,
12103,
370,
12676,
314,
26570,
83,
787,
13985,
370,
886,
880,
12,
5420,
370,
199,
3,
314,
2569,
3704,
26,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
221,
199,
3,
315,
1006,
6866,
503,
13393,
12468,
402,
314,
26570,
83,
14,
221,
199,
3,
2334,
603,
10447,
4938,
51,
9315,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
3169,
12,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
7000,
2334,
10610,
1549,
5877,
8164,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
603,
10447,
4938,
51,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
2334,
603,
10447,
4938,
51,
14,
2999,
199,
3,
1666,
11672,
14,
32140,
14,
38,
42,
16603,
434,
2998,
367,
314,
2556,
202,
199,
3,
402,
314,
283,
1100,
7,
2725,
14,
2999,
199,
3,
961,
2690,
1335,
1181,
1540,
909,
1630,
314,
2569,
26,
202,
199,
3,
202,
199,
3,
1603,
16603,
1563,
604,
26,
2951,
22694,
626,
314,
4465,
7124,
8103,
440,
12420,
14,
202,
199,
3,
1603,
16603,
11823,
15499,
26,
2597,
22694,
626,
314,
6411,
7124,
787,
440,
315,
1125,
14,
202,
199,
3,
1603,
16603,
920,
2109,
76,
695,
26,
2011,
465,
13197,
23122,
14,
2999,
199,
3,
2136,
492,
376,
465,
18832,
2884,
626,
6952,
314,
2863,
14786,
83,
202,
199,
3,
3102,
14,
710,
465,
18832,
19383,
2399,
5920,
12,
880,
626,
3879,
3062,
4020,
202,
199,
3,
1630,
440,
315,
17255,
376,
23361,
10238,
8328,
14,
202,
199,
504,
9739,
1451,
9899,
14,
6429,
492,
1603,
16603,
24486,
2999,
199,
3,
7754,
4733,
2195,
1031,
769,
2348,
26,
202,
199,
1450,
30525,
275,
11194,
6562,
297,
283,
10828,
297,
283,
6721,
9770,
63,
1985,
297,
283,
13803,
995,
16765,
788,
6562,
297,
283,
10828,
297,
283,
6721,
9770,
63,
1985,
297,
283,
13331,
995,
16765,
788,
6562,
297,
283,
10828,
297,
283,
6721,
9770,
63,
1985,
297,
283,
27539,
6538,
202,
199,
962,
985,
275,
283,
632,
7,
202,
199,
962,
7562,
275,
2125,
202,
199,
576,
1378,
1799,
275,
2125,
2999,
199,
533,
5870,
42,
1181,
1540,
1692,
26,
1128,
347,
636,
826,
721,
277,
12,
485,
1450,
30525,
12,
485,
962,
985,
12,
485,
962,
7562,
12,
485,
576,
304,
1039,
291,
14,
1450,
1296,
275,
485,
1450,
30525,
1039,
291,
14,
962,
985,
275,
485,
962,
985,
1039,
291,
14,
962,
7562,
275,
485,
962,
7562,
1039,
291,
14,
576,
1378,
1799,
275,
485,
576,
1039,
291,
14,
1205,
63,
14232,
275,
756,
1039,
291,
14,
1205,
63,
4792,
15499,
275,
756,
1039,
291,
14,
1205,
63,
476,
2109,
76,
695,
275,
756,
1039,
291,
855,
7310,
275,
1603,
16603,
24486,
14,
42,
16603,
24486,
342,
26016,
347,
1603,
16603,
1563,
604,
8,
277,
12,
1067,
304,
1039,
327,
3091,
3650,
1077,
440,
12420,
1039,
291,
855,
7310,
14,
1799,
17345,
9030,
8,
1100,
9,
13594,
327,
3161,
15,
3790,
15,
3502,
1471,
2187,
436,
986,
12,
1830,
17769,
1471,
1454,
2187,
14,
1039,
291,
855,
7310,
14,
1799,
20960,
8,
1100,
12,
2097,
6295,
401,
298,
11399,
401,
298,
12584,
2255,
2097,
9216,
3135,
13594,
291,
14,
1205,
63,
14232,
275,
291,
855,
7310,
14,
1002,
6579,
342,
1039,
372,
291,
14,
1205,
63,
14232,
15497,
1128,
327,
4005,
986,
13197,
1265,
1929,
370,
986,
5678,
12,
642,
909,
4293,
2597,
2387,
4722,
26259,
327,
2295,
626,
4898,
2488,
370,
314,
13197,
23122,
14,
1128,
347,
1603,
16603,
11823,
15499,
8,
277,
12,
1067,
304,
1039,
291,
14,
1205,
63,
4792,
15499,
275,
291,
14,
1205,
63,
14232,
1039,
372,
291,
14,
1205,
63,
4792,
15499,
221,
17554,
1128,
327,
4005,
986,
19472,
1265,
1929,
370,
986,
13197,
12,
642,
909,
4293,
2597,
2387,
4722,
1128,
327,
2295,
626,
4898,
2488,
370,
314,
19472,
23122,
1128,
347,
1603,
16603,
920,
2109,
76,
695,
8,
277,
12,
1067,
304,
1223,
198,
3,
340,
1613,
15499,
6918,
12,
949,
2376,
315,
9848,
7907,
1039,
340,
334,
277,
14,
1205,
63,
4792,
15499,
508,
756,
304,
1675,
291,
14,
1205,
63,
476,
2109,
76,
695,
275,
291,
14,
1205,
63,
4792,
15499,
1675,
372,
291,
14,
1205,
63,
476,
2109,
76,
695,
13594,
327,
18955,
314,
8018,
5935,
1039,
291,
855,
7310,
14,
16051,
5349,
2995,
18882,
8,
1100,
9,
13594,
291,
855,
7310,
14,
2162,
1451,
2398,
2485,
8,
1100,
12,
291,
14,
1450,
1296,
59,
16,
467,
298,
1609,
531,
1039,
291,
855,
7310,
14,
2162,
1451,
2398,
2485,
8,
1100,
12,
291,
14,
1450,
1296,
59,
17,
467,
298,
1609,
531,
1039,
291,
855,
7310,
14,
2162,
1451,
2398,
2485,
8,
1100,
12,
291,
14,
1450,
1296,
59,
18,
467,
298,
1609,
531,
1039,
291,
855,
7310,
14,
1646,
2398,
2485,
8,
1100,
12,
291,
14,
1450,
1296,
59,
18,
467,
291,
14,
962,
985,
9,
4341,
291,
14,
1205,
63,
476,
2109,
76,
695,
275,
291,
855,
7310,
14,
872,
2412,
42,
16603,
434,
8,
1100,
9,
1039,
372,
291,
14,
1205,
63,
476,
2109,
76,
695,
30199,
202,
199,
3,
961,
365,
2382,
1006,
314,
1736,
11058,
26,
298,
74,
1181,
1540,
1692,
2,
365,
376,
3679,
590,
5784,
1526,
14,
202,
199,
3,
710,
8336,
5077,
10734,
7437,
22543,
367,
282,
1021,
1256,
4310,
298,
74,
1181,
1540,
1692,
1674,
202,
199,
3,
202,
199,
74,
1181,
1540,
1692,
275,
5870,
42,
1181,
1540,
1692,
8,
1450,
30525,
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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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
] |
dushu1203/chromium.src
|
build/android/pylib/uiautomator/test_runner.py
|
9
|
3330
|
# Copyright (c) 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Class for running uiautomator tests on a single device."""
from pylib import constants
from pylib import flag_changer
from pylib.device import intent
from pylib.instrumentation import test_options as instr_test_options
from pylib.instrumentation import test_runner as instr_test_runner
class TestRunner(instr_test_runner.TestRunner):
"""Responsible for running a series of tests connected to a single device."""
def __init__(self, test_options, device, shard_index, test_pkg):
"""Create a new TestRunner.
Args:
test_options: A UIAutomatorOptions object.
device: Attached android device.
shard_index: Shard index.
test_pkg: A TestPackage object.
"""
# Create an InstrumentationOptions object to pass to the super class
instrumentation_options = instr_test_options.InstrumentationOptions(
test_options.tool,
test_options.cleanup_test_files,
test_options.annotations,
test_options.exclude_annotations,
test_options.test_filter,
test_options.test_data,
test_options.save_perf_json,
test_options.screenshot_failures,
wait_for_debugger=False,
coverage_dir=None,
test_apk=None,
test_apk_path=None,
test_apk_jar_path=None,
test_runner=None,
test_support_apk_path=None,
device_flags=None,
isolate_file_path=None,
set_asserts=test_options.set_asserts)
super(TestRunner, self).__init__(instrumentation_options, device,
shard_index, test_pkg)
cmdline_file = constants.PACKAGE_INFO[test_options.package].cmdline_file
self.flags = None
if cmdline_file:
self.flags = flag_changer.FlagChanger(self.device, cmdline_file)
self._package = constants.PACKAGE_INFO[test_options.package].package
self._activity = constants.PACKAGE_INFO[test_options.package].activity
#override
def InstallTestPackage(self):
self.test_pkg.Install(self.device)
#override
def _RunTest(self, test, timeout):
self.device.ClearApplicationState(self._package)
if self.flags:
annotations = self.test_pkg.GetTestAnnotations(test)
if 'FirstRunExperience' == annotations.get('Feature', None):
self.flags.RemoveFlags(['--disable-fre'])
else:
self.flags.AddFlags(['--disable-fre'])
self.device.StartActivity(
intent.Intent(action='android.intent.action.MAIN',
activity=self._activity,
package=self._package),
blocking=True,
force_stop=True)
cmd = ['uiautomator', 'runtest',
self.test_pkg.UIAUTOMATOR_PATH + self.test_pkg.GetPackageName(),
'-e', 'class', test]
return self.device.RunShellCommand(cmd, timeout=timeout, retries=0)
#override
def _GenerateTestResult(self, test, instr_statuses, start_ms, duration_ms):
# uiautomator emits its summary status with INSTRUMENTATION_STATUS_CODE,
# not INSTRUMENTATION_CODE, so we have to drop if off the list of statuses.
return super(TestRunner, self)._GenerateTestResult(
test, instr_statuses[:-1], start_ms, duration_ms)
|
bsd-3-clause
|
[
3,
1898,
334,
67,
9,
6171,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
2543,
367,
3879,
8574,
2495,
569,
269,
2295,
641,
282,
2849,
2243,
1041,
199,
199,
504,
29219,
492,
5262,
199,
504,
29219,
492,
3305,
63,
335,
12974,
199,
504,
29219,
14,
1782,
492,
21020,
199,
504,
29219,
14,
13321,
425,
492,
511,
63,
1419,
465,
18885,
63,
396,
63,
1419,
199,
504,
29219,
14,
13321,
425,
492,
511,
63,
5933,
465,
18885,
63,
396,
63,
5933,
421,
199,
533,
1379,
7446,
8,
21309,
63,
396,
63,
5933,
14,
13649,
304,
523,
408,
1322,
678,
1164,
367,
3879,
282,
6779,
402,
2295,
8539,
370,
282,
2849,
2243,
1041,
819,
347,
636,
826,
721,
277,
12,
511,
63,
1419,
12,
2243,
12,
11814,
63,
1080,
12,
511,
63,
4600,
304,
272,
408,
2499,
282,
892,
1379,
7446,
14,
339,
3033,
26,
489,
511,
63,
1419,
26,
437,
14041,
3358,
569,
269,
4558,
909,
14,
489,
2243,
26,
2854,
7159,
15516,
2243,
14,
489,
11814,
63,
1080,
26,
5244,
1005,
1478,
14,
489,
511,
63,
4600,
26,
437,
1379,
8599,
909,
14,
272,
408,
272,
327,
2790,
376,
25767,
425,
4558,
909,
370,
986,
370,
314,
1613,
1021,
272,
14498,
425,
63,
1419,
275,
18885,
63,
396,
63,
1419,
14,
14915,
425,
4558,
8,
267,
511,
63,
1419,
14,
3557,
12,
267,
511,
63,
1419,
14,
7661,
63,
396,
63,
1725,
12,
267,
511,
63,
1419,
14,
11270,
12,
267,
511,
63,
1419,
14,
5473,
63,
11270,
12,
267,
511,
63,
1419,
14,
396,
63,
1541,
12,
267,
511,
63,
1419,
14,
396,
63,
576,
12,
267,
511,
63,
1419,
14,
2117,
63,
9452,
63,
1001,
12,
267,
511,
63,
1419,
14,
23269,
63,
9968,
12,
267,
3618,
63,
509,
63,
17612,
29,
797,
12,
267,
11745,
63,
694,
29,
403,
12,
267,
511,
63,
23582,
29,
403,
12,
267,
511,
63,
23582,
63,
515,
29,
403,
12,
267,
511,
63,
23582,
63,
7338,
63,
515,
29,
403,
12,
267,
511,
63,
5933,
29,
403,
12,
267,
511,
63,
4058,
63,
23582,
63,
515,
29,
403,
12,
267,
2243,
63,
2469,
29,
403,
12,
267,
365,
16288,
63,
493,
63,
515,
29,
403,
12,
267,
663,
63,
479,
83,
29,
396,
63,
1419,
14,
409,
63,
479,
83,
9,
272,
1613,
8,
13649,
12,
291,
2843,
826,
721,
13321,
425,
63,
1419,
12,
2243,
12,
3660,
11814,
63,
1080,
12,
511,
63,
4600,
9,
339,
21206,
63,
493,
275,
5262,
14,
19265,
63,
4531,
59,
396,
63,
1419,
14,
2491,
1055,
15612,
63,
493,
272,
291,
14,
2469,
275,
488,
272,
340,
21206,
63,
493,
26,
489,
291,
14,
2469,
275,
3305,
63,
335,
12974,
14,
5318,
1049,
12974,
8,
277,
14,
1782,
12,
21206,
63,
493,
9,
272,
291,
423,
2491,
275,
5262,
14,
19265,
63,
4531,
59,
396,
63,
1419,
14,
2491,
1055,
2491,
272,
291,
423,
8240,
275,
5262,
14,
19265,
63,
4531,
59,
396,
63,
1419,
14,
2491,
1055,
8240,
819,
327,
4415,
523,
347,
13276,
774,
8599,
8,
277,
304,
272,
291,
14,
396,
63,
4600,
14,
8154,
8,
277,
14,
1782,
9,
819,
327,
4415,
523,
347,
485,
2540,
774,
8,
277,
12,
511,
12,
2653,
304,
272,
291,
14,
1782,
14,
9721,
5039,
2223,
8,
277,
423,
2491,
9,
272,
340,
291,
14,
2469,
26,
489,
15538,
275,
291,
14,
396,
63,
4600,
14,
28967,
21761,
1298,
8,
396,
9,
489,
340,
283,
7147,
2540,
920,
24242,
7,
508,
15538,
14,
362,
360,
5968,
297,
488,
304,
267,
291,
14,
2469,
14,
5587,
6381,
18510,
5993,
13,
20153,
1105,
489,
587,
26,
267,
291,
14,
2469,
14,
1123,
6381,
18510,
5993,
13,
20153,
1105,
272,
291,
14,
1782,
14,
3162,
14350,
8,
267,
21020,
14,
607,
767,
8,
1287,
534,
6238,
14,
17456,
14,
1287,
14,
5848,
297,
1993,
10679,
29,
277,
423,
8240,
12,
1993,
2559,
29,
277,
423,
2491,
395,
267,
14592,
29,
549,
12,
267,
3542,
63,
2379,
29,
549,
9,
272,
2088,
275,
788,
1907,
2495,
569,
269,
297,
283,
1065,
396,
297,
1779,
291,
14,
396,
63,
4600,
14,
6379,
10774,
7474,
6467,
63,
3243,
435,
291,
14,
396,
63,
4600,
14,
1002,
8599,
985,
1062,
1779,
2475,
69,
297,
283,
533,
297,
511,
61,
272,
372,
291,
14,
1782,
14,
2540,
8529,
3110,
8,
1760,
12,
2653,
29,
2593,
12,
10086,
29,
16,
9,
819,
327,
4415,
523,
347,
485,
6864,
13120,
8,
277,
12,
511,
12,
18885,
63,
17084,
12,
1343,
63,
706,
12,
7373,
63,
706,
304,
272,
327,
8574,
2495,
569,
269,
8689,
83,
2399,
6212,
2004,
543,
1621,
3027,
18272,
2594,
63,
6305,
63,
6012,
12,
272,
327,
440,
1621,
3027,
18272,
2594,
63,
6012,
12,
880,
781,
1172,
370,
5978,
340,
2331,
314,
769,
402,
24498,
14,
272,
372,
1613,
8,
13649,
12,
291,
10445,
6864,
13120,
8,
267,
511,
12,
18885,
63,
17084,
4439,
17,
467,
1343,
63,
706,
12,
7373,
63,
706,
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
] |
[
1898,
334,
67,
9,
6171,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
2543,
367,
3879,
8574,
2495,
569,
269,
2295,
641,
282,
2849,
2243,
1041,
199,
199,
504,
29219,
492,
5262,
199,
504,
29219,
492,
3305,
63,
335,
12974,
199,
504,
29219,
14,
1782,
492,
21020,
199,
504,
29219,
14,
13321,
425,
492,
511,
63,
1419,
465,
18885,
63,
396,
63,
1419,
199,
504,
29219,
14,
13321,
425,
492,
511,
63,
5933,
465,
18885,
63,
396,
63,
5933,
421,
199,
533,
1379,
7446,
8,
21309,
63,
396,
63,
5933,
14,
13649,
304,
523,
408,
1322,
678,
1164,
367,
3879,
282,
6779,
402,
2295,
8539,
370,
282,
2849,
2243,
1041,
819,
347,
636,
826,
721,
277,
12,
511,
63,
1419,
12,
2243,
12,
11814,
63,
1080,
12,
511,
63,
4600,
304,
272,
408,
2499,
282,
892,
1379,
7446,
14,
339,
3033,
26,
489,
511,
63,
1419,
26,
437,
14041,
3358,
569,
269,
4558,
909,
14,
489,
2243,
26,
2854,
7159,
15516,
2243,
14,
489,
11814,
63,
1080,
26,
5244,
1005,
1478,
14,
489,
511,
63,
4600,
26,
437,
1379,
8599,
909,
14,
272,
408,
272,
327,
2790,
376,
25767,
425,
4558,
909,
370,
986,
370,
314,
1613,
1021,
272,
14498,
425,
63,
1419,
275,
18885,
63,
396,
63,
1419,
14,
14915,
425,
4558,
8,
267,
511,
63,
1419,
14,
3557,
12,
267,
511,
63,
1419,
14,
7661,
63,
396,
63,
1725,
12,
267,
511,
63,
1419,
14,
11270,
12,
267,
511,
63,
1419,
14,
5473,
63,
11270,
12,
267,
511,
63,
1419,
14,
396,
63,
1541,
12,
267,
511,
63,
1419,
14,
396,
63,
576,
12,
267,
511,
63,
1419,
14,
2117,
63,
9452,
63,
1001,
12,
267,
511,
63,
1419,
14,
23269,
63,
9968,
12,
267,
3618,
63,
509,
63,
17612,
29,
797,
12,
267,
11745,
63,
694,
29,
403,
12,
267,
511,
63,
23582,
29,
403,
12,
267,
511,
63,
23582,
63,
515,
29,
403,
12,
267,
511,
63,
23582,
63,
7338,
63,
515,
29,
403,
12,
267,
511,
63,
5933,
29,
403,
12,
267,
511,
63,
4058,
63,
23582,
63,
515,
29,
403,
12,
267,
2243,
63,
2469,
29,
403,
12,
267,
365,
16288,
63,
493,
63,
515,
29,
403,
12,
267,
663,
63,
479,
83,
29,
396,
63,
1419,
14,
409,
63,
479,
83,
9,
272,
1613,
8,
13649,
12,
291,
2843,
826,
721,
13321,
425,
63,
1419,
12,
2243,
12,
3660,
11814,
63,
1080,
12,
511,
63,
4600,
9,
339,
21206,
63,
493,
275,
5262,
14,
19265,
63,
4531,
59,
396,
63,
1419,
14,
2491,
1055,
15612,
63,
493,
272,
291,
14,
2469,
275,
488,
272,
340,
21206,
63,
493,
26,
489,
291,
14,
2469,
275,
3305,
63,
335,
12974,
14,
5318,
1049,
12974,
8,
277,
14,
1782,
12,
21206,
63,
493,
9,
272,
291,
423,
2491,
275,
5262,
14,
19265,
63,
4531,
59,
396,
63,
1419,
14,
2491,
1055,
2491,
272,
291,
423,
8240,
275,
5262,
14,
19265,
63,
4531,
59,
396,
63,
1419,
14,
2491,
1055,
8240,
819,
327,
4415,
523,
347,
13276,
774,
8599,
8,
277,
304,
272,
291,
14,
396,
63,
4600,
14,
8154,
8,
277,
14,
1782,
9,
819,
327,
4415,
523,
347,
485,
2540,
774,
8,
277,
12,
511,
12,
2653,
304,
272,
291,
14,
1782,
14,
9721,
5039,
2223,
8,
277,
423,
2491,
9,
272,
340,
291,
14,
2469,
26,
489,
15538,
275,
291,
14,
396,
63,
4600,
14,
28967,
21761,
1298,
8,
396,
9,
489,
340,
283,
7147,
2540,
920,
24242,
7,
508,
15538,
14,
362,
360,
5968,
297,
488,
304,
267,
291,
14,
2469,
14,
5587,
6381,
18510,
5993,
13,
20153,
1105,
489,
587,
26,
267,
291,
14,
2469,
14,
1123,
6381,
18510,
5993,
13,
20153,
1105,
272,
291,
14,
1782,
14,
3162,
14350,
8,
267,
21020,
14,
607,
767,
8,
1287,
534,
6238,
14,
17456,
14,
1287,
14,
5848,
297,
1993,
10679,
29,
277,
423,
8240,
12,
1993,
2559,
29,
277,
423,
2491,
395,
267,
14592,
29,
549,
12,
267,
3542,
63,
2379,
29,
549,
9,
272,
2088,
275,
788,
1907,
2495,
569,
269,
297,
283,
1065,
396,
297,
1779,
291,
14,
396,
63,
4600,
14,
6379,
10774,
7474,
6467,
63,
3243,
435,
291,
14,
396,
63,
4600,
14,
1002,
8599,
985,
1062,
1779,
2475,
69,
297,
283,
533,
297,
511,
61,
272,
372,
291,
14,
1782,
14,
2540,
8529,
3110,
8,
1760,
12,
2653,
29,
2593,
12,
10086,
29,
16,
9,
819,
327,
4415,
523,
347,
485,
6864,
13120,
8,
277,
12,
511,
12,
18885,
63,
17084,
12,
1343,
63,
706,
12,
7373,
63,
706,
304,
272,
327,
8574,
2495,
569,
269,
8689,
83,
2399,
6212,
2004,
543,
1621,
3027,
18272,
2594,
63,
6305,
63,
6012,
12,
272,
327,
440,
1621,
3027,
18272,
2594,
63,
6012,
12,
880,
781,
1172,
370,
5978,
340,
2331,
314,
769,
402,
24498,
14,
272,
372,
1613,
8,
13649,
12,
291,
10445,
6864,
13120,
8,
267,
511,
12,
18885,
63,
17084,
4439,
17,
467,
1343,
63,
706,
12,
7373,
63,
706,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
joelsmith/openshift-tools
|
ansible/roles/lib_openshift_3.2/build/ansible/oadm_manage_node.py
|
13
|
2805
|
# pylint: skip-file
def main():
'''
ansible oadm module for manage-node
'''
module = AnsibleModule(
argument_spec=dict(
debug=dict(default=False, type='bool'),
kubeconfig=dict(default='/etc/origin/master/admin.kubeconfig', type='str'),
node=dict(default=None, type='list'),
selector=dict(default=None, type='str'),
pod_selector=dict(default=None, type='str'),
schedulable=dict(default=None, type='bool'),
list_pods=dict(default=False, type='bool'),
evacuate=dict(default=False, type='bool'),
dry_run=dict(default=False, type='bool'),
force=dict(default=False, type='bool'),
grace_period=dict(default=None, type='int'),
),
mutually_exclusive=[["selector", "node"], ['evacuate', 'list_pods'], ['list_pods', 'schedulable']],
required_one_of=[["node", "selector"]],
supports_check_mode=True,
)
nconfig = ManageNodeConfig(module.params['kubeconfig'],
{'node': {'value': module.params['node'], 'include': True},
'selector': {'value': module.params['selector'], 'include': True},
'pod_selector': {'value': module.params['pod_selector'], 'include': True},
'schedulable': {'value': module.params['schedulable'], 'include': True},
'list_pods': {'value': module.params['list_pods'], 'include': True},
'evacuate': {'value': module.params['evacuate'], 'include': True},
'dry_run': {'value': module.params['dry_run'], 'include': True},
'force': {'value': module.params['force'], 'include': True},
'grace_period': {'value': module.params['grace_period'], 'include': True},
})
oadm_mn = ManageNode(nconfig)
# Run the oadm manage-node commands
results = None
changed = False
if module.params['schedulable'] != None:
results = oadm_mn.schedulable()
if not results.has_key('changed'):
changed = True
if module.params['evacuate']:
results = oadm_mn.evacuate()
changed = True
elif module.params['list_pods']:
results = oadm_mn.list_pods()
if not results or results['returncode'] != 0:
module.fail_json(msg=results)
module.exit_json(changed=changed, results=results, state="present")
# pylint: disable=redefined-builtin, unused-wildcard-import, wildcard-import, locally-disabled
# import module snippets. This are required
if __name__ == "__main__":
from ansible.module_utils.basic import *
main()
|
apache-2.0
|
[
3,
4287,
26,
3372,
13,
493,
199,
199,
318,
2446,
837,
272,
1449,
272,
3242,
312,
14464,
859,
367,
9635,
13,
932,
272,
1449,
339,
859,
275,
6953,
8,
267,
1423,
63,
1650,
29,
807,
8,
288,
3105,
29,
807,
8,
885,
29,
797,
12,
730,
534,
2245,
659,
288,
23091,
888,
29,
807,
8,
885,
8805,
6839,
15,
6493,
15,
4133,
15,
2113,
14,
29192,
297,
730,
534,
495,
659,
288,
1031,
29,
807,
8,
885,
29,
403,
12,
730,
534,
513,
659,
288,
9759,
29,
807,
8,
885,
29,
403,
12,
730,
534,
495,
659,
288,
15329,
63,
6662,
29,
807,
8,
885,
29,
403,
12,
730,
534,
495,
659,
288,
10286,
348,
461,
29,
807,
8,
885,
29,
403,
12,
730,
534,
2245,
659,
288,
769,
63,
12656,
83,
29,
807,
8,
885,
29,
797,
12,
730,
534,
2245,
659,
288,
8145,
645,
4767,
29,
807,
8,
885,
29,
797,
12,
730,
534,
2245,
659,
288,
9951,
63,
1065,
29,
807,
8,
885,
29,
797,
12,
730,
534,
2245,
659,
288,
3542,
29,
807,
8,
885,
29,
797,
12,
730,
534,
2245,
659,
288,
19756,
63,
5191,
29,
807,
8,
885,
29,
403,
12,
730,
534,
442,
659,
267,
2318,
267,
16108,
63,
12730,
1524,
905,
6662,
401,
298,
932,
2255,
788,
6857,
645,
4767,
297,
283,
513,
63,
12656,
83,
995,
788,
513,
63,
12656,
83,
297,
283,
10487,
348,
461,
2157,
267,
1415,
63,
368,
63,
1618,
1524,
905,
932,
401,
298,
6662,
18396,
398,
5171,
63,
1074,
63,
632,
29,
549,
12,
272,
776,
339,
302,
888,
275,
14944,
1716,
2028,
8,
578,
14,
1162,
459,
29192,
995,
3044,
791,
932,
356,
791,
585,
356,
859,
14,
1162,
459,
932,
995,
283,
2613,
356,
715,
1386,
1816,
283,
6662,
356,
791,
585,
356,
859,
14,
1162,
459,
6662,
995,
283,
2613,
356,
715,
1386,
1816,
283,
12656,
63,
6662,
356,
791,
585,
356,
859,
14,
1162,
459,
12656,
63,
6662,
995,
283,
2613,
356,
715,
1386,
1816,
283,
10487,
348,
461,
356,
791,
585,
356,
859,
14,
1162,
459,
10487,
348,
461,
995,
283,
2613,
356,
715,
1386,
1816,
283,
513,
63,
12656,
83,
356,
791,
585,
356,
859,
14,
1162,
459,
513,
63,
12656,
83,
995,
283,
2613,
356,
715,
1386,
1816,
283,
6857,
645,
4767,
356,
791,
585,
356,
859,
14,
1162,
459,
6857,
645,
4767,
995,
283,
2613,
356,
715,
1386,
1816,
283,
10481,
63,
1065,
356,
791,
585,
356,
859,
14,
1162,
459,
10481,
63,
1065,
995,
283,
2613,
356,
715,
1386,
1816,
283,
3990,
356,
791,
585,
356,
859,
14,
1162,
459,
3990,
995,
283,
2613,
356,
715,
1386,
1816,
283,
20631,
63,
5191,
356,
791,
585,
356,
859,
14,
1162,
459,
20631,
63,
5191,
995,
283,
2613,
356,
715,
1386,
3044,
3828,
2378,
312,
14464,
63,
10344,
275,
14944,
1716,
8,
78,
888,
9,
272,
327,
3378,
314,
312,
14464,
9635,
13,
932,
3718,
272,
2058,
275,
488,
272,
2896,
275,
756,
272,
340,
859,
14,
1162,
459,
10487,
348,
461,
418,
1137,
488,
26,
267,
2058,
275,
312,
14464,
63,
10344,
14,
10487,
348,
461,
342,
267,
340,
440,
2058,
14,
1989,
63,
498,
360,
2489,
735,
288,
2896,
275,
715,
339,
340,
859,
14,
1162,
459,
6857,
645,
4767,
2565,
267,
2058,
275,
312,
14464,
63,
10344,
14,
6857,
645,
4767,
342,
267,
2896,
275,
715,
272,
916,
859,
14,
1162,
459,
513,
63,
12656,
83,
2565,
267,
2058,
275,
312,
14464,
63,
10344,
14,
513,
63,
12656,
83,
342,
339,
340,
440,
2058,
503,
2058,
459,
9913,
418,
1137,
378,
26,
267,
859,
14,
1633,
63,
1001,
8,
1328,
29,
2604,
9,
339,
859,
14,
2224,
63,
1001,
8,
2489,
29,
2489,
12,
2058,
29,
2604,
12,
1174,
628,
1881,
531,
199,
199,
3,
4287,
26,
3507,
29,
27913,
13,
5351,
12,
9563,
13,
16692,
13,
646,
12,
16792,
13,
646,
12,
17738,
13,
7011,
199,
3,
492,
859,
19484,
14,
221,
961,
787,
1415,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
687,
3242,
14,
578,
63,
1208,
14,
4316,
492,
627,
272,
2446,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
4287,
26,
3372,
13,
493,
199,
199,
318,
2446,
837,
272,
1449,
272,
3242,
312,
14464,
859,
367,
9635,
13,
932,
272,
1449,
339,
859,
275,
6953,
8,
267,
1423,
63,
1650,
29,
807,
8,
288,
3105,
29,
807,
8,
885,
29,
797,
12,
730,
534,
2245,
659,
288,
23091,
888,
29,
807,
8,
885,
8805,
6839,
15,
6493,
15,
4133,
15,
2113,
14,
29192,
297,
730,
534,
495,
659,
288,
1031,
29,
807,
8,
885,
29,
403,
12,
730,
534,
513,
659,
288,
9759,
29,
807,
8,
885,
29,
403,
12,
730,
534,
495,
659,
288,
15329,
63,
6662,
29,
807,
8,
885,
29,
403,
12,
730,
534,
495,
659,
288,
10286,
348,
461,
29,
807,
8,
885,
29,
403,
12,
730,
534,
2245,
659,
288,
769,
63,
12656,
83,
29,
807,
8,
885,
29,
797,
12,
730,
534,
2245,
659,
288,
8145,
645,
4767,
29,
807,
8,
885,
29,
797,
12,
730,
534,
2245,
659,
288,
9951,
63,
1065,
29,
807,
8,
885,
29,
797,
12,
730,
534,
2245,
659,
288,
3542,
29,
807,
8,
885,
29,
797,
12,
730,
534,
2245,
659,
288,
19756,
63,
5191,
29,
807,
8,
885,
29,
403,
12,
730,
534,
442,
659,
267,
2318,
267,
16108,
63,
12730,
1524,
905,
6662,
401,
298,
932,
2255,
788,
6857,
645,
4767,
297,
283,
513,
63,
12656,
83,
995,
788,
513,
63,
12656,
83,
297,
283,
10487,
348,
461,
2157,
267,
1415,
63,
368,
63,
1618,
1524,
905,
932,
401,
298,
6662,
18396,
398,
5171,
63,
1074,
63,
632,
29,
549,
12,
272,
776,
339,
302,
888,
275,
14944,
1716,
2028,
8,
578,
14,
1162,
459,
29192,
995,
3044,
791,
932,
356,
791,
585,
356,
859,
14,
1162,
459,
932,
995,
283,
2613,
356,
715,
1386,
1816,
283,
6662,
356,
791,
585,
356,
859,
14,
1162,
459,
6662,
995,
283,
2613,
356,
715,
1386,
1816,
283,
12656,
63,
6662,
356,
791,
585,
356,
859,
14,
1162,
459,
12656,
63,
6662,
995,
283,
2613,
356,
715,
1386,
1816,
283,
10487,
348,
461,
356,
791,
585,
356,
859,
14,
1162,
459,
10487,
348,
461,
995,
283,
2613,
356,
715,
1386,
1816,
283,
513,
63,
12656,
83,
356,
791,
585,
356,
859,
14,
1162,
459,
513,
63,
12656,
83,
995,
283,
2613,
356,
715,
1386,
1816,
283,
6857,
645,
4767,
356,
791,
585,
356,
859,
14,
1162,
459,
6857,
645,
4767,
995,
283,
2613,
356,
715,
1386,
1816,
283,
10481,
63,
1065,
356,
791,
585,
356,
859,
14,
1162,
459,
10481,
63,
1065,
995,
283,
2613,
356,
715,
1386,
1816,
283,
3990,
356,
791,
585,
356,
859,
14,
1162,
459,
3990,
995,
283,
2613,
356,
715,
1386,
1816,
283,
20631,
63,
5191,
356,
791,
585,
356,
859,
14,
1162,
459,
20631,
63,
5191,
995,
283,
2613,
356,
715,
1386,
3044,
3828,
2378,
312,
14464,
63,
10344,
275,
14944,
1716,
8,
78,
888,
9,
272,
327,
3378,
314,
312,
14464,
9635,
13,
932,
3718,
272,
2058,
275,
488,
272,
2896,
275,
756,
272,
340,
859,
14,
1162,
459,
10487,
348,
461,
418,
1137,
488,
26,
267,
2058,
275,
312,
14464,
63,
10344,
14,
10487,
348,
461,
342,
267,
340,
440,
2058,
14,
1989,
63,
498,
360,
2489,
735,
288,
2896,
275,
715,
339,
340,
859,
14,
1162,
459,
6857,
645,
4767,
2565,
267,
2058,
275,
312,
14464,
63,
10344,
14,
6857,
645,
4767,
342,
267,
2896,
275,
715,
272,
916,
859,
14,
1162,
459,
513,
63,
12656,
83,
2565,
267,
2058,
275,
312,
14464,
63,
10344,
14,
513,
63,
12656,
83,
342,
339,
340,
440,
2058,
503,
2058,
459,
9913,
418,
1137,
378,
26,
267,
859,
14,
1633,
63,
1001,
8,
1328,
29,
2604,
9,
339,
859,
14,
2224,
63,
1001,
8,
2489,
29,
2489,
12,
2058,
29,
2604,
12,
1174,
628,
1881,
531,
199,
199,
3,
4287,
26,
3507,
29,
27913,
13,
5351,
12,
9563,
13,
16692,
13,
646,
12,
16792,
13,
646,
12,
17738,
13,
7011,
199,
3,
492,
859,
19484,
14,
221,
961,
787,
1415,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
687,
3242,
14,
578,
63,
1208,
14,
4316,
492,
627,
272,
2446,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
facebookexperimental/eden
|
eden/hg-server/tests/test-remotenames-convert-t.py
|
2
|
1076
|
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
from __future__ import absolute_import
from testutil.dott import feature, sh, testtmp # noqa: F401
sh % "setconfig 'extensions.treemanifest=!'"
# Set up extension and repos
(
sh % "cat"
<< r"""
[extensions]
remotenames=
convert=
"""
>> "$HGRCPATH"
)
sh % "hg init repo1"
sh % "cd repo1"
sh % "echo a" > "a"
sh % "hg add a"
sh % "hg commit -qm a"
sh % "hg boo bm2"
sh % "cd .."
sh % "hg clone repo1 repo2" == r"""
updating to branch default
1 files updated, 0 files merged, 0 files removed, 0 files unresolved"""
# Test colors
sh % "hg -R repo2 bookmark --remote" == " default/bm2 cb9a9f314b8b"
sh % "hg convert repo2 repo3" == r"""
initializing destination repo3 repository
scanning source...
sorting...
converting...
0 a
updating bookmarks"""
sh % "hg -R repo3 bookmark" == " default/bm2 cb9a9f314b8b"
|
gpl-2.0
|
[
3,
1898,
334,
67,
9,
27107,
12,
3277,
14,
436,
2399,
29172,
2335,
14,
199,
3,
199,
3,
961,
2032,
1443,
506,
1202,
436,
1854,
7182,
370,
314,
2895,
402,
314,
199,
3,
1664,
1696,
1684,
844,
1015,
499,
503,
1263,
2945,
1015,
14,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
504,
511,
1974,
14,
3287,
84,
492,
3878,
12,
1033,
12,
511,
2791,
221,
327,
8151,
26,
481,
8854,
421,
199,
609,
450,
298,
409,
888,
283,
5359,
14,
2350,
6418,
29,
1,
4065,
199,
3,
2494,
1536,
3329,
436,
20416,
199,
199,
8,
272,
1033,
450,
298,
3385,
2,
272,
5213,
519,
624,
199,
59,
5359,
61,
199,
3846,
1247,
29,
199,
3916,
29,
199,
624,
272,
4331,
7880,
40,
3975,
35,
3243,
2,
199,
9,
199,
199,
609,
450,
298,
9208,
4205,
3831,
17,
2,
199,
609,
450,
298,
2866,
3831,
17,
2,
199,
609,
450,
298,
7878,
282,
2,
690,
298,
65,
2,
199,
609,
450,
298,
9208,
1050,
282,
2,
199,
609,
450,
298,
9208,
5532,
446,
17976,
282,
2,
199,
609,
450,
298,
9208,
1234,
79,
25425,
18,
2,
199,
609,
450,
298,
2866,
2508,
2,
199,
609,
450,
298,
9208,
7289,
3831,
17,
3831,
18,
2,
508,
519,
624,
272,
12928,
370,
5246,
849,
272,
413,
1584,
4588,
12,
378,
1584,
9545,
12,
378,
1584,
4829,
12,
378,
1584,
625,
13697,
624,
199,
199,
3,
1379,
9229,
199,
199,
609,
450,
298,
9208,
446,
50,
3831,
18,
23799,
1553,
3846,
2,
508,
298,
257,
849,
15,
12648,
18,
5185,
7434,
25,
65,
25,
70,
8988,
66,
24,
66,
2,
199,
609,
450,
298,
9208,
3957,
3831,
18,
3831,
19,
2,
508,
519,
624,
272,
29141,
5724,
3831,
19,
7611,
272,
24928,
1350,
1396,
272,
13351,
1396,
272,
13806,
1396,
272,
378,
282,
272,
12928,
32410,
624,
199,
609,
450,
298,
9208,
446,
50,
3831,
19,
23799,
2,
508,
298,
257,
849,
15,
12648,
18,
5185,
7434,
25,
65,
25,
70,
8988,
66,
24,
66,
2,
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
] |
[
1898,
334,
67,
9,
27107,
12,
3277,
14,
436,
2399,
29172,
2335,
14,
199,
3,
199,
3,
961,
2032,
1443,
506,
1202,
436,
1854,
7182,
370,
314,
2895,
402,
314,
199,
3,
1664,
1696,
1684,
844,
1015,
499,
503,
1263,
2945,
1015,
14,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
504,
511,
1974,
14,
3287,
84,
492,
3878,
12,
1033,
12,
511,
2791,
221,
327,
8151,
26,
481,
8854,
421,
199,
609,
450,
298,
409,
888,
283,
5359,
14,
2350,
6418,
29,
1,
4065,
199,
3,
2494,
1536,
3329,
436,
20416,
199,
199,
8,
272,
1033,
450,
298,
3385,
2,
272,
5213,
519,
624,
199,
59,
5359,
61,
199,
3846,
1247,
29,
199,
3916,
29,
199,
624,
272,
4331,
7880,
40,
3975,
35,
3243,
2,
199,
9,
199,
199,
609,
450,
298,
9208,
4205,
3831,
17,
2,
199,
609,
450,
298,
2866,
3831,
17,
2,
199,
609,
450,
298,
7878,
282,
2,
690,
298,
65,
2,
199,
609,
450,
298,
9208,
1050,
282,
2,
199,
609,
450,
298,
9208,
5532,
446,
17976,
282,
2,
199,
609,
450,
298,
9208,
1234,
79,
25425,
18,
2,
199,
609,
450,
298,
2866,
2508,
2,
199,
609,
450,
298,
9208,
7289,
3831,
17,
3831,
18,
2,
508,
519,
624,
272,
12928,
370,
5246,
849,
272,
413,
1584,
4588,
12,
378,
1584,
9545,
12,
378,
1584,
4829,
12,
378,
1584,
625,
13697,
624,
199,
199,
3,
1379,
9229,
199,
199,
609,
450,
298,
9208,
446,
50,
3831,
18,
23799,
1553,
3846,
2,
508,
298,
257,
849,
15,
12648,
18,
5185,
7434,
25,
65,
25,
70,
8988,
66,
24,
66,
2,
199,
609,
450,
298,
9208,
3957,
3831,
18,
3831,
19,
2,
508,
519,
624,
272,
29141,
5724,
3831,
19,
7611,
272,
24928,
1350,
1396,
272,
13351,
1396,
272,
13806,
1396,
272,
378,
282,
272,
12928,
32410,
624,
199,
609,
450,
298,
9208,
446,
50,
3831,
19,
23799,
2,
508,
298,
257,
849,
15,
12648,
18,
5185,
7434,
25,
65,
25,
70,
8988,
66,
24,
66,
2,
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,
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,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Foord
# Backport for other versions of Python available from
# http://pypi.python.org/pypi/mock
__all__ = (
'Mock',
'MagicMock',
'patch',
'sentinel',
'DEFAULT',
'ANY',
'call',
'create_autospec',
'FILTER_DIR',
'NonCallableMock',
'NonCallableMagicMock',
'mock_open',
'PropertyMock',
)
__version__ = '1.0'
import inspect
import pprint
import sys
from functools import wraps, partial
BaseExceptions = (BaseException,)
if 'java' in sys.platform:
# jython
import java
BaseExceptions = (BaseException, java.lang.Throwable)
FILTER_DIR = True
# Workaround for issue #12370
# Without this, the __class__ properties wouldn't be set correctly
_safe_super = super
def _is_instance_mock(obj):
# can't use isinstance on Mock objects because they override __class__
# The base class for all mocks is NonCallableMock
return issubclass(type(obj), NonCallableMock)
def _is_exception(obj):
return (
isinstance(obj, BaseExceptions) or
isinstance(obj, type) and issubclass(obj, BaseExceptions)
)
class _slotted(object):
__slots__ = ['a']
DescriptorTypes = (
type(_slotted.a),
property,
)
def _get_signature_object(func, as_instance, eat_self):
"""
Given an arbitrary, possibly callable object, try to create a suitable
signature object.
Return a (reduced func, signature) tuple, or None.
"""
if isinstance(func, type) and not as_instance:
# If it's a type and should be modelled as a type, use __init__.
try:
func = func.__init__
except AttributeError:
return None
# Skip the `self` argument in __init__
eat_self = True
elif not isinstance(func, FunctionTypes):
# If we really want to model an instance of the passed type,
# __call__ should be looked up, not __init__.
try:
func = func.__call__
except AttributeError:
return None
if eat_self:
sig_func = partial(func, None)
else:
sig_func = func
try:
return func, inspect.signature(sig_func)
except ValueError:
# Certain callable types are not supported by inspect.signature()
return None
def _check_signature(func, mock, skipfirst, instance=False):
sig = _get_signature_object(func, instance, skipfirst)
if sig is None:
return
func, sig = sig
def checksig(_mock_self, *args, **kwargs):
sig.bind(*args, **kwargs)
_copy_func_details(func, checksig)
type(mock)._mock_check_sig = checksig
def _copy_func_details(func, funcopy):
funcopy.__name__ = func.__name__
funcopy.__doc__ = func.__doc__
try:
funcopy.__text_signature__ = func.__text_signature__
except AttributeError:
pass
# we explicitly don't copy func.__dict__ into this copy as it would
# expose original attributes that should be mocked
try:
funcopy.__module__ = func.__module__
except AttributeError:
pass
try:
funcopy.__defaults__ = func.__defaults__
except AttributeError:
pass
try:
funcopy.__kwdefaults__ = func.__kwdefaults__
except AttributeError:
pass
def _callable(obj):
if isinstance(obj, type):
return True
if getattr(obj, '__call__', None) is not None:
return True
return False
def _is_list(obj):
# checks for list or tuples
# XXXX badly named!
return type(obj) in (list, tuple)
def _instance_callable(obj):
"""Given an object, return True if the object is callable.
For classes, return True if instances would be callable."""
if not isinstance(obj, type):
# already an instance
return getattr(obj, '__call__', None) is not None
# *could* be broken by a class overriding __mro__ or __dict__ via
# a metaclass
for base in (obj,) + obj.__mro__:
if base.__dict__.get('__call__') is not None:
return True
return False
def _set_signature(mock, original, instance=False):
# creates a function with signature (*args, **kwargs) that delegates to a
# mock. It still does signature checking by calling a lambda with the same
# signature as the original.
if not _callable(original):
return
skipfirst = isinstance(original, type)
result = _get_signature_object(original, instance, skipfirst)
if result is None:
return
func, sig = result
def checksig(*args, **kwargs):
sig.bind(*args, **kwargs)
_copy_func_details(func, checksig)
name = original.__name__
if not name.isidentifier():
name = 'funcopy'
context = {'_checksig_': checksig, 'mock': mock}
src = """def %s(*args, **kwargs):
_checksig_(*args, **kwargs)
return mock(*args, **kwargs)""" % name
exec (src, context)
funcopy = context[name]
_setup_func(funcopy, mock)
return funcopy
def _setup_func(funcopy, mock):
funcopy.mock = mock
# can't use isinstance with mocks
if not _is_instance_mock(mock):
return
def assert_called_with(*args, **kwargs):
return mock.assert_called_with(*args, **kwargs)
def assert_called_once_with(*args, **kwargs):
return mock.assert_called_once_with(*args, **kwargs)
def assert_has_calls(*args, **kwargs):
return mock.assert_has_calls(*args, **kwargs)
def assert_any_call(*args, **kwargs):
return mock.assert_any_call(*args, **kwargs)
def reset_mock():
funcopy.method_calls = _CallList()
funcopy.mock_calls = _CallList()
mock.reset_mock()
ret = funcopy.return_value
if _is_instance_mock(ret) and not ret is mock:
ret.reset_mock()
funcopy.called = False
funcopy.call_count = 0
funcopy.call_args = None
funcopy.call_args_list = _CallList()
funcopy.method_calls = _CallList()
funcopy.mock_calls = _CallList()
funcopy.return_value = mock.return_value
funcopy.side_effect = mock.side_effect
funcopy._mock_children = mock._mock_children
funcopy.assert_called_with = assert_called_with
funcopy.assert_called_once_with = assert_called_once_with
funcopy.assert_has_calls = assert_has_calls
funcopy.assert_any_call = assert_any_call
funcopy.reset_mock = reset_mock
mock._mock_delegate = funcopy
def _is_magic(name):
return '__%s__' % name[2:-2] == name
class _SentinelObject(object):
"A unique, named, sentinel object."
def __init__(self, name):
self.name = name
def __repr__(self):
return 'sentinel.%s' % self.name
class _Sentinel(object):
"""Access attributes to return a named object, usable as a sentinel."""
def __init__(self):
self._sentinels = {}
def __getattr__(self, name):
if name == '__bases__':
# Without this help(unittest.mock) raises an exception
raise AttributeError
return self._sentinels.setdefault(name, _SentinelObject(name))
sentinel = _Sentinel()
DEFAULT = sentinel.DEFAULT
_missing = sentinel.MISSING
_deleted = sentinel.DELETED
def _copy(value):
if type(value) in (dict, list, tuple, set):
return type(value)(value)
return value
_allowed_names = set(
[
'return_value', '_mock_return_value', 'side_effect',
'_mock_side_effect', '_mock_parent', '_mock_new_parent',
'_mock_name', '_mock_new_name'
]
)
def _delegating_property(name):
_allowed_names.add(name)
_the_name = '_mock_' + name
def _get(self, name=name, _the_name=_the_name):
sig = self._mock_delegate
if sig is None:
return getattr(self, _the_name)
return getattr(sig, name)
def _set(self, value, name=name, _the_name=_the_name):
sig = self._mock_delegate
if sig is None:
self.__dict__[_the_name] = value
else:
setattr(sig, name, value)
return property(_get, _set)
class _CallList(list):
def __contains__(self, value):
if not isinstance(value, list):
return list.__contains__(self, value)
len_value = len(value)
len_self = len(self)
if len_value > len_self:
return False
for i in range(0, len_self - len_value + 1):
sub_list = self[i:i+len_value]
if sub_list == value:
return True
return False
def __repr__(self):
return pprint.pformat(list(self))
def _check_and_set_parent(parent, value, name, new_name):
if not _is_instance_mock(value):
return False
if ((value._mock_name or value._mock_new_name) or
(value._mock_parent is not None) or
(value._mock_new_parent is not None)):
return False
_parent = parent
while _parent is not None:
# setting a mock (value) as a child or return value of itself
# should not modify the mock
if _parent is value:
return False
_parent = _parent._mock_new_parent
if new_name:
value._mock_new_parent = parent
value._mock_new_name = new_name
if name:
value._mock_parent = parent
value._mock_name = name
return True
# Internal class to identify if we wrapped an iterator object or not.
class _MockIter(object):
def __init__(self, obj):
self.obj = iter(obj)
def __iter__(self):
return self
def __next__(self):
return next(self.obj)
class Base(object):
_mock_return_value = DEFAULT
_mock_side_effect = None
def __init__(self, *args, **kwargs):
pass
class NonCallableMock(Base):
"""A non-callable version of `Mock`"""
def __new__(cls, *args, **kw):
# every instance has its own class
# so we can create magic methods on the
# class without stomping on other mocks
new = type(cls.__name__, (cls,), {'__doc__': cls.__doc__})
instance = object.__new__(new)
return instance
def __init__(
self, spec=None, wraps=None, name=None, spec_set=None,
parent=None, _spec_state=None, _new_name='', _new_parent=None,
_spec_as_instance=False, _eat_self=None, **kwargs
):
if _new_parent is None:
_new_parent = parent
__dict__ = self.__dict__
__dict__['_mock_parent'] = parent
__dict__['_mock_name'] = name
__dict__['_mock_new_name'] = _new_name
__dict__['_mock_new_parent'] = _new_parent
if spec_set is not None:
spec = spec_set
spec_set = True
if _eat_self is None:
_eat_self = parent is not None
self._mock_add_spec(spec, spec_set, _spec_as_instance, _eat_self)
__dict__['_mock_children'] = {}
__dict__['_mock_wraps'] = wraps
__dict__['_mock_delegate'] = None
__dict__['_mock_called'] = False
__dict__['_mock_call_args'] = None
__dict__['_mock_call_count'] = 0
__dict__['_mock_call_args_list'] = _CallList()
__dict__['_mock_mock_calls'] = _CallList()
__dict__['method_calls'] = _CallList()
if kwargs:
self.configure_mock(**kwargs)
_safe_super(NonCallableMock, self).__init__(
spec, wraps, name, spec_set, parent,
_spec_state
)
def attach_mock(self, mock, attribute):
"""
Attach a mock as an attribute of this one, replacing its name and
parent. Calls to the attached mock will be recorded in the
`method_calls` and `mock_calls` attributes of this one."""
mock._mock_parent = None
mock._mock_new_parent = None
mock._mock_name = ''
mock._mock_new_name = None
setattr(self, attribute, mock)
def mock_add_spec(self, spec, spec_set=False):
"""Add a spec to a mock. `spec` can either be an object or a
list of strings. Only attributes on the `spec` can be fetched as
attributes from the mock.
If `spec_set` is True then only attributes on the spec can be set."""
self._mock_add_spec(spec, spec_set)
def _mock_add_spec(self, spec, spec_set, _spec_as_instance=False,
_eat_self=False):
_spec_class = None
_spec_signature = None
if spec is not None and not _is_list(spec):
if isinstance(spec, type):
_spec_class = spec
else:
_spec_class = _get_class(spec)
res = _get_signature_object(spec,
_spec_as_instance, _eat_self)
_spec_signature = res and res[1]
spec = dir(spec)
__dict__ = self.__dict__
__dict__['_spec_class'] = _spec_class
__dict__['_spec_set'] = spec_set
__dict__['_spec_signature'] = _spec_signature
__dict__['_mock_methods'] = spec
def __get_return_value(self):
ret = self._mock_return_value
if self._mock_delegate is not None:
ret = self._mock_delegate.return_value
if ret is DEFAULT:
ret = self._get_child_mock(
_new_parent=self, _new_name='()'
)
self.return_value = ret
return ret
def __set_return_value(self, value):
if self._mock_delegate is not None:
self._mock_delegate.return_value = value
else:
self._mock_return_value = value
_check_and_set_parent(self, value, None, '()')
__return_value_doc = "The value to be returned when the mock is called."
return_value = property(__get_return_value, __set_return_value,
__return_value_doc)
@property
def __class__(self):
if self._spec_class is None:
return type(self)
return self._spec_class
called = _delegating_property('called')
call_count = _delegating_property('call_count')
call_args = _delegating_property('call_args')
call_args_list = _delegating_property('call_args_list')
mock_calls = _delegating_property('mock_calls')
def __get_side_effect(self):
delegated = self._mock_delegate
if delegated is None:
return self._mock_side_effect
sf = delegated.side_effect
if sf is not None and not callable(sf) and not isinstance(sf, _MockIter):
sf = _MockIter(sf)
delegated.side_effect = sf
return sf
def __set_side_effect(self, value):
value = _try_iter(value)
delegated = self._mock_delegate
if delegated is None:
self._mock_side_effect = value
else:
delegated.side_effect = value
side_effect = property(__get_side_effect, __set_side_effect)
def reset_mock(self):
"Restore the mock object to its initial state."
self.called = False
self.call_args = None
self.call_count = 0
self.mock_calls = _CallList()
self.call_args_list = _CallList()
self.method_calls = _CallList()
for child in self._mock_children.values():
if isinstance(child, _SpecState):
continue
child.reset_mock()
ret = self._mock_return_value
if _is_instance_mock(ret) and ret is not self:
ret.reset_mock()
def configure_mock(self, **kwargs):
"""Set attributes on the mock through keyword arguments.
Attributes plus return values and side effects can be set on child
mocks using standard dot notation and unpacking a dictionary in the
method call:
>>> attrs = {'method.return_value': 3, 'other.side_effect': KeyError}
>>> mock.configure_mock(**attrs)"""
for arg, val in sorted(kwargs.items(),
# we sort on the number of dots so that
# attributes are set before we set attributes on
# attributes
key=lambda entry: entry[0].count('.')):
args = arg.split('.')
final = args.pop()
obj = self
for entry in args:
obj = getattr(obj, entry)
setattr(obj, final, val)
def __getattr__(self, name):
if name == '_mock_methods':
raise AttributeError(name)
elif self._mock_methods is not None:
if name not in self._mock_methods or name in _all_magics:
raise AttributeError("Mock object has no attribute %r" % name)
elif _is_magic(name):
raise AttributeError(name)
result = self._mock_children.get(name)
if result is _deleted:
raise AttributeError(name)
elif result is None:
wraps = None
if self._mock_wraps is not None:
# XXXX should we get the attribute without triggering code
# execution?
wraps = getattr(self._mock_wraps, name)
result = self._get_child_mock(
parent=self, name=name, wraps=wraps, _new_name=name,
_new_parent=self
)
self._mock_children[name] = result
elif isinstance(result, _SpecState):
result = create_autospec(
result.spec, result.spec_set, result.instance,
result.parent, result.name
)
self._mock_children[name] = result
return result
def __repr__(self):
_name_list = [self._mock_new_name]
_parent = self._mock_new_parent
last = self
dot = '.'
if _name_list == ['()']:
dot = ''
seen = set()
while _parent is not None:
last = _parent
_name_list.append(_parent._mock_new_name + dot)
dot = '.'
if _parent._mock_new_name == '()':
dot = ''
_parent = _parent._mock_new_parent
# use ids here so as not to call __hash__ on the mocks
if id(_parent) in seen:
break
seen.add(id(_parent))
_name_list = list(reversed(_name_list))
_first = last._mock_name or 'mock'
if len(_name_list) > 1:
if _name_list[1] not in ('()', '().'):
_first += '.'
_name_list[0] = _first
name = ''.join(_name_list)
name_string = ''
if name not in ('mock', 'mock.'):
name_string = ' name=%r' % name
spec_string = ''
if self._spec_class is not None:
spec_string = ' spec=%r'
if self._spec_set:
spec_string = ' spec_set=%r'
spec_string = spec_string % self._spec_class.__name__
return "<%s%s%s id='%s'>" % (
type(self).__name__,
name_string,
spec_string,
id(self)
)
def __dir__(self):
"""Filter the output of `dir(mock)` to only useful members."""
if not FILTER_DIR:
return object.__dir__(self)
extras = self._mock_methods or []
from_type = dir(type(self))
from_dict = list(self.__dict__)
from_type = [e for e in from_type if not e.startswith('_')]
from_dict = [e for e in from_dict if not e.startswith('_') or
_is_magic(e)]
return sorted(set(extras + from_type + from_dict +
list(self._mock_children)))
def __setattr__(self, name, value):
if name in _allowed_names:
# property setters go through here
return object.__setattr__(self, name, value)
elif (self._spec_set and self._mock_methods is not None and
name not in self._mock_methods and
name not in self.__dict__):
raise AttributeError("Mock object has no attribute '%s'" % name)
elif name in _unsupported_magics:
msg = 'Attempting to set unsupported magic method %r.' % name
raise AttributeError(msg)
elif name in _all_magics:
if self._mock_methods is not None and name not in self._mock_methods:
raise AttributeError("Mock object has no attribute '%s'" % name)
if not _is_instance_mock(value):
setattr(type(self), name, _get_method(name, value))
original = value
value = lambda *args, **kw: original(self, *args, **kw)
else:
# only set _new_name and not name so that mock_calls is tracked
# but not method calls
_check_and_set_parent(self, value, None, name)
setattr(type(self), name, value)
self._mock_children[name] = value
elif name == '__class__':
self._spec_class = value
return
else:
if _check_and_set_parent(self, value, name, name):
self._mock_children[name] = value
return object.__setattr__(self, name, value)
def __delattr__(self, name):
if name in _all_magics and name in type(self).__dict__:
delattr(type(self), name)
if name not in self.__dict__:
# for magic methods that are still MagicProxy objects and
# not set on the instance itself
return
if name in self.__dict__:
object.__delattr__(self, name)
obj = self._mock_children.get(name, _missing)
if obj is _deleted:
raise AttributeError(name)
if obj is not _missing:
del self._mock_children[name]
self._mock_children[name] = _deleted
def _format_mock_call_signature(self, args, kwargs):
name = self._mock_name or 'mock'
return _format_call_signature(name, args, kwargs)
def _format_mock_failure_message(self, args, kwargs):
message = 'Expected call: %s\nActual call: %s'
expected_string = self._format_mock_call_signature(args, kwargs)
call_args = self.call_args
if len(call_args) == 3:
call_args = call_args[1:]
actual_string = self._format_mock_call_signature(*call_args)
return message % (expected_string, actual_string)
def _call_matcher(self, _call):
"""
Given a call (or simply a (args, kwargs) tuple), return a
comparison key suitable for matching with other calls.
This is a best effort method which relies on the spec's signature,
if available, or falls back on the arguments themselves.
"""
sig = self._spec_signature
if sig is not None:
if len(_call) == 2:
name = ''
args, kwargs = _call
else:
name, args, kwargs = _call
try:
return name, sig.bind(*args, **kwargs)
except TypeError as e:
return e.with_traceback(None)
else:
return _call
def assert_called_with(_mock_self, *args, **kwargs):
"""assert that the mock was called with the specified arguments.
Raises an AssertionError if the args and keyword args passed in are
different to the last call to the mock."""
self = _mock_self
if self.call_args is None:
expected = self._format_mock_call_signature(args, kwargs)
raise AssertionError('Expected call: %s\nNot called' % (expected,))
def _error_message():
msg = self._format_mock_failure_message(args, kwargs)
return msg
expected = self._call_matcher((args, kwargs))
actual = self._call_matcher(self.call_args)
if expected != actual:
cause = expected if isinstance(expected, Exception) else None
raise AssertionError(_error_message()) from cause
def assert_called_once_with(_mock_self, *args, **kwargs):
"""assert that the mock was called exactly once and with the specified
arguments."""
self = _mock_self
if not self.call_count == 1:
msg = ("Expected '%s' to be called once. Called %s times." %
(self._mock_name or 'mock', self.call_count))
raise AssertionError(msg)
return self.assert_called_with(*args, **kwargs)
def assert_has_calls(self, calls, any_order=False):
"""assert the mock has been called with the specified calls.
The `mock_calls` list is checked for the calls.
If `any_order` is False (the default) then the calls must be
sequential. There can be extra calls before or after the
specified calls.
If `any_order` is True then the calls can be in any order, but
they must all appear in `mock_calls`."""
expected = [self._call_matcher(c) for c in calls]
cause = expected if isinstance(expected, Exception) else None
all_calls = _CallList(self._call_matcher(c) for c in self.mock_calls)
if not any_order:
if expected not in all_calls:
raise AssertionError(
'Calls not found.\nExpected: %r\n'
'Actual: %r' % (calls, self.mock_calls)
) from cause
return
all_calls = list(all_calls)
not_found = []
for kall in expected:
try:
all_calls.remove(kall)
except ValueError:
not_found.append(kall)
if not_found:
raise AssertionError(
'%r not all found in call list' % (tuple(not_found),)
) from cause
def assert_any_call(self, *args, **kwargs):
"""assert the mock has been called with the specified arguments.
The assert passes if the mock has *ever* been called, unlike
`assert_called_with` and `assert_called_once_with` that only pass if
the call is the most recent one."""
expected = self._call_matcher((args, kwargs))
actual = [self._call_matcher(c) for c in self.call_args_list]
if expected not in actual:
cause = expected if isinstance(expected, Exception) else None
expected_string = self._format_mock_call_signature(args, kwargs)
raise AssertionError(
'%s call not found' % expected_string
) from cause
def _get_child_mock(self, **kw):
"""Create the child mocks for attributes and return value.
By default child mocks will be the same type as the parent.
Subclasses of Mock may want to override this to customize the way
child mocks are made.
For non-callable mocks the callable variant will be used (rather than
any custom subclass)."""
_type = type(self)
if not issubclass(_type, CallableMixin):
if issubclass(_type, NonCallableMagicMock):
klass = MagicMock
elif issubclass(_type, NonCallableMock) :
klass = Mock
else:
klass = _type.__mro__[1]
return klass(**kw)
def _try_iter(obj):
if obj is None:
return obj
if _is_exception(obj):
return obj
if _callable(obj):
return obj
try:
return iter(obj)
except TypeError:
# XXXX backwards compatibility
# but this will blow up on first call - so maybe we should fail early?
return obj
class CallableMixin(Base):
def __init__(self, spec=None, side_effect=None, return_value=DEFAULT,
wraps=None, name=None, spec_set=None, parent=None,
_spec_state=None, _new_name='', _new_parent=None, **kwargs):
self.__dict__['_mock_return_value'] = return_value
_safe_super(CallableMixin, self).__init__(
spec, wraps, name, spec_set, parent,
_spec_state, _new_name, _new_parent, **kwargs
)
self.side_effect = side_effect
def _mock_check_sig(self, *args, **kwargs):
# stub method that can be replaced with one with a specific signature
pass
def __call__(_mock_self, *args, **kwargs):
# can't use self in-case a function / method we are mocking uses self
# in the signature
_mock_self._mock_check_sig(*args, **kwargs)
return _mock_self._mock_call(*args, **kwargs)
def _mock_call(_mock_self, *args, **kwargs):
self = _mock_self
self.called = True
self.call_count += 1
_new_name = self._mock_new_name
_new_parent = self._mock_new_parent
_call = _Call((args, kwargs), two=True)
self.call_args = _call
self.call_args_list.append(_call)
self.mock_calls.append(_Call(('', args, kwargs)))
seen = set()
skip_next_dot = _new_name == '()'
do_method_calls = self._mock_parent is not None
name = self._mock_name
while _new_parent is not None:
this_mock_call = _Call((_new_name, args, kwargs))
if _new_parent._mock_new_name:
dot = '.'
if skip_next_dot:
dot = ''
skip_next_dot = False
if _new_parent._mock_new_name == '()':
skip_next_dot = True
_new_name = _new_parent._mock_new_name + dot + _new_name
if do_method_calls:
if _new_name == name:
this_method_call = this_mock_call
else:
this_method_call = _Call((name, args, kwargs))
_new_parent.method_calls.append(this_method_call)
do_method_calls = _new_parent._mock_parent is not None
if do_method_calls:
name = _new_parent._mock_name + '.' + name
_new_parent.mock_calls.append(this_mock_call)
_new_parent = _new_parent._mock_new_parent
# use ids here so as not to call __hash__ on the mocks
_new_parent_id = id(_new_parent)
if _new_parent_id in seen:
break
seen.add(_new_parent_id)
ret_val = DEFAULT
effect = self.side_effect
if effect is not None:
if _is_exception(effect):
raise effect
if not _callable(effect):
result = next(effect)
if _is_exception(result):
raise result
if result is DEFAULT:
result = self.return_value
return result
ret_val = effect(*args, **kwargs)
if (self._mock_wraps is not None and
self._mock_return_value is DEFAULT):
return self._mock_wraps(*args, **kwargs)
if ret_val is DEFAULT:
ret_val = self.return_value
return ret_val
class Mock(CallableMixin, NonCallableMock):
"""
Create a new `Mock` object. `Mock` takes several optional arguments
that specify the behaviour of the Mock object:
* `spec`: This can be either a list of strings or an existing object (a
class or instance) that acts as the specification for the mock object. If
you pass in an object then a list of strings is formed by calling dir on
the object (excluding unsupported magic attributes and methods). Accessing
any attribute not in this list will raise an `AttributeError`.
If `spec` is an object (rather than a list of strings) then
`mock.__class__` returns the class of the spec object. This allows mocks
to pass `isinstance` tests.
* `spec_set`: A stricter variant of `spec`. If used, attempting to *set*
or get an attribute on the mock that isn't on the object passed as
`spec_set` will raise an `AttributeError`.
* `side_effect`: A function to be called whenever the Mock is called. See
the `side_effect` attribute. Useful for raising exceptions or
dynamically changing return values. The function is called with the same
arguments as the mock, and unless it returns `DEFAULT`, the return
value of this function is used as the return value.
If `side_effect` is an iterable then each call to the mock will return
the next value from the iterable. If any of the members of the iterable
are exceptions they will be raised instead of returned.
* `return_value`: The value returned when the mock is called. By default
this is a new Mock (created on first access). See the
`return_value` attribute.
* `wraps`: Item for the mock object to wrap. If `wraps` is not None then
calling the Mock will pass the call through to the wrapped object
(returning the real result). Attribute access on the mock will return a
Mock object that wraps the corresponding attribute of the wrapped object
(so attempting to access an attribute that doesn't exist will raise an
`AttributeError`).
If the mock has an explicit `return_value` set then calls are not passed
to the wrapped object and the `return_value` is returned instead.
* `name`: If the mock has a name then it will be used in the repr of the
mock. This can be useful for debugging. The name is propagated to child
mocks.
Mocks can also be called with arbitrary keyword arguments. These will be
used to set attributes on the mock after it is created.
"""
def _dot_lookup(thing, comp, import_path):
try:
return getattr(thing, comp)
except AttributeError:
__import__(import_path)
return getattr(thing, comp)
def _importer(target):
components = target.split('.')
import_path = components.pop(0)
thing = __import__(import_path)
for comp in components:
import_path += ".%s" % comp
thing = _dot_lookup(thing, comp, import_path)
return thing
def _is_started(patcher):
# XXXX horrible
return hasattr(patcher, 'is_local')
class _patch(object):
attribute_name = None
_active_patches = []
def __init__(
self, getter, attribute, new, spec, create,
spec_set, autospec, new_callable, kwargs
):
if new_callable is not None:
if new is not DEFAULT:
raise ValueError(
"Cannot use 'new' and 'new_callable' together"
)
if autospec is not None:
raise ValueError(
"Cannot use 'autospec' and 'new_callable' together"
)
self.getter = getter
self.attribute = attribute
self.new = new
self.new_callable = new_callable
self.spec = spec
self.create = create
self.has_local = False
self.spec_set = spec_set
self.autospec = autospec
self.kwargs = kwargs
self.additional_patchers = []
def copy(self):
patcher = _patch(
self.getter, self.attribute, self.new, self.spec,
self.create, self.spec_set,
self.autospec, self.new_callable, self.kwargs
)
patcher.attribute_name = self.attribute_name
patcher.additional_patchers = [
p.copy() for p in self.additional_patchers
]
return patcher
def __call__(self, func):
if isinstance(func, type):
return self.decorate_class(func)
return self.decorate_callable(func)
def decorate_class(self, klass):
for attr in dir(klass):
if not attr.startswith(patch.TEST_PREFIX):
continue
attr_value = getattr(klass, attr)
if not hasattr(attr_value, "__call__"):
continue
patcher = self.copy()
setattr(klass, attr, patcher(attr_value))
return klass
def decorate_callable(self, func):
if hasattr(func, 'patchings'):
func.patchings.append(self)
return func
@wraps(func)
def patched(*args, **keywargs):
extra_args = []
entered_patchers = []
exc_info = tuple()
try:
for patching in patched.patchings:
arg = patching.__enter__()
entered_patchers.append(patching)
if patching.attribute_name is not None:
keywargs.update(arg)
elif patching.new is DEFAULT:
extra_args.append(arg)
args += tuple(extra_args)
return func(*args, **keywargs)
except:
if (patching not in entered_patchers and
_is_started(patching)):
# the patcher may have been started, but an exception
# raised whilst entering one of its additional_patchers
entered_patchers.append(patching)
# Pass the exception to __exit__
exc_info = sys.exc_info()
# re-raise the exception
raise
finally:
for patching in reversed(entered_patchers):
patching.__exit__(*exc_info)
patched.patchings = [self]
return patched
def get_original(self):
target = self.getter()
name = self.attribute
original = DEFAULT
local = False
try:
original = target.__dict__[name]
except (AttributeError, KeyError):
original = getattr(target, name, DEFAULT)
else:
local = True
if not self.create and original is DEFAULT:
raise AttributeError(
"%s does not have the attribute %r" % (target, name)
)
return original, local
def __enter__(self):
"""Perform the patch."""
new, spec, spec_set = self.new, self.spec, self.spec_set
autospec, kwargs = self.autospec, self.kwargs
new_callable = self.new_callable
self.target = self.getter()
# normalise False to None
if spec is False:
spec = None
if spec_set is False:
spec_set = None
if autospec is False:
autospec = None
if spec is not None and autospec is not None:
raise TypeError("Can't specify spec and autospec")
if ((spec is not None or autospec is not None) and
spec_set not in (True, None)):
raise TypeError("Can't provide explicit spec_set *and* spec or autospec")
original, local = self.get_original()
if new is DEFAULT and autospec is None:
inherit = False
if spec is True:
# set spec to the object we are replacing
spec = original
if spec_set is True:
spec_set = original
spec = None
elif spec is not None:
if spec_set is True:
spec_set = spec
spec = None
elif spec_set is True:
spec_set = original
if spec is not None or spec_set is not None:
if original is DEFAULT:
raise TypeError("Can't use 'spec' with create=True")
if isinstance(original, type):
# If we're patching out a class and there is a spec
inherit = True
Klass = MagicMock
_kwargs = {}
if new_callable is not None:
Klass = new_callable
elif spec is not None or spec_set is not None:
this_spec = spec
if spec_set is not None:
this_spec = spec_set
if _is_list(this_spec):
not_callable = '__call__' not in this_spec
else:
not_callable = not callable(this_spec)
if not_callable:
Klass = NonCallableMagicMock
if spec is not None:
_kwargs['spec'] = spec
if spec_set is not None:
_kwargs['spec_set'] = spec_set
# add a name to mocks
if (isinstance(Klass, type) and
issubclass(Klass, NonCallableMock) and self.attribute):
_kwargs['name'] = self.attribute
_kwargs.update(kwargs)
new = Klass(**_kwargs)
if inherit and _is_instance_mock(new):
# we can only tell if the instance should be callable if the
# spec is not a list
this_spec = spec
if spec_set is not None:
this_spec = spec_set
if (not _is_list(this_spec) and not
_instance_callable(this_spec)):
Klass = NonCallableMagicMock
_kwargs.pop('name')
new.return_value = Klass(_new_parent=new, _new_name='()',
**_kwargs)
elif autospec is not None:
# spec is ignored, new *must* be default, spec_set is treated
# as a boolean. Should we check spec is not None and that spec_set
# is a bool?
if new is not DEFAULT:
raise TypeError(
"autospec creates the mock for you. Can't specify "
"autospec and new."
)
if original is DEFAULT:
raise TypeError("Can't use 'autospec' with create=True")
spec_set = bool(spec_set)
if autospec is True:
autospec = original
new = create_autospec(autospec, spec_set=spec_set,
_name=self.attribute, **kwargs)
elif kwargs:
# can't set keyword args when we aren't creating the mock
# XXXX If new is a Mock we could call new.configure_mock(**kwargs)
raise TypeError("Can't pass kwargs to a mock we aren't creating")
new_attr = new
self.temp_original = original
self.is_local = local
setattr(self.target, self.attribute, new_attr)
if self.attribute_name is not None:
extra_args = {}
if self.new is DEFAULT:
extra_args[self.attribute_name] = new
for patching in self.additional_patchers:
arg = patching.__enter__()
if patching.new is DEFAULT:
extra_args.update(arg)
return extra_args
return new
def __exit__(self, *exc_info):
"""Undo the patch."""
if not _is_started(self):
raise RuntimeError('stop called on unstarted patcher')
if self.is_local and self.temp_original is not DEFAULT:
setattr(self.target, self.attribute, self.temp_original)
else:
delattr(self.target, self.attribute)
if not self.create and not hasattr(self.target, self.attribute):
# needed for proxy objects like django settings
setattr(self.target, self.attribute, self.temp_original)
del self.temp_original
del self.is_local
del self.target
for patcher in reversed(self.additional_patchers):
if _is_started(patcher):
patcher.__exit__(*exc_info)
def start(self):
"""Activate a patch, returning any created mock."""
result = self.__enter__()
self._active_patches.append(self)
return result
def stop(self):
"""Stop an active patch."""
try:
self._active_patches.remove(self)
except ValueError:
# If the patch hasn't been started this will fail
pass
return self.__exit__()
def _get_target(target):
try:
target, attribute = target.rsplit('.', 1)
except (TypeError, ValueError):
raise TypeError("Need a valid target to patch. You supplied: %r" %
(target,))
getter = lambda: _importer(target)
return getter, attribute
def _patch_object(
target, attribute, new=DEFAULT, spec=None,
create=False, spec_set=None, autospec=None,
new_callable=None, **kwargs
):
"""
patch the named member (`attribute`) on an object (`target`) with a mock
object.
`patch.object` can be used as a decorator, class decorator or a context
manager. Arguments `new`, `spec`, `create`, `spec_set`,
`autospec` and `new_callable` have the same meaning as for `patch`. Like
`patch`, `patch.object` takes arbitrary keyword arguments for configuring
the mock object it creates.
When used as a class decorator `patch.object` honours `patch.TEST_PREFIX`
for choosing which methods to wrap.
"""
getter = lambda: target
return _patch(
getter, attribute, new, spec, create,
spec_set, autospec, new_callable, kwargs
)
def _patch_multiple(target, spec=None, create=False, spec_set=None,
autospec=None, new_callable=None, **kwargs):
"""Perform multiple patches in a single call. It takes the object to be
patched (either as an object or a string to fetch the object by importing)
and keyword arguments for the patches::
with patch.multiple(settings, FIRST_PATCH='one', SECOND_PATCH='two'):
...
Use `DEFAULT` as the value if you want `patch.multiple` to create
mocks for you. In this case the created mocks are passed into a decorated
function by keyword, and a dictionary is returned when `patch.multiple` is
used as a context manager.
`patch.multiple` can be used as a decorator, class decorator or a context
manager. The arguments `spec`, `spec_set`, `create`,
`autospec` and `new_callable` have the same meaning as for `patch`. These
arguments will be applied to *all* patches done by `patch.multiple`.
When used as a class decorator `patch.multiple` honours `patch.TEST_PREFIX`
for choosing which methods to wrap.
"""
if type(target) is str:
getter = lambda: _importer(target)
else:
getter = lambda: target
if not kwargs:
raise ValueError(
'Must supply at least one keyword argument with patch.multiple'
)
# need to wrap in a list for python 3, where items is a view
items = list(kwargs.items())
attribute, new = items[0]
patcher = _patch(
getter, attribute, new, spec, create, spec_set,
autospec, new_callable, {}
)
patcher.attribute_name = attribute
for attribute, new in items[1:]:
this_patcher = _patch(
getter, attribute, new, spec, create, spec_set,
autospec, new_callable, {}
)
this_patcher.attribute_name = attribute
patcher.additional_patchers.append(this_patcher)
return patcher
def patch(
target, new=DEFAULT, spec=None, create=False,
spec_set=None, autospec=None, new_callable=None, **kwargs
):
"""
`patch` acts as a function decorator, class decorator or a context
manager. Inside the body of the function or with statement, the `target`
is patched with a `new` object. When the function/with statement exits
the patch is undone.
If `new` is omitted, then the target is replaced with a
`MagicMock`. If `patch` is used as a decorator and `new` is
omitted, the created mock is passed in as an extra argument to the
decorated function. If `patch` is used as a context manager the created
mock is returned by the context manager.
`target` should be a string in the form `'package.module.ClassName'`. The
`target` is imported and the specified object replaced with the `new`
object, so the `target` must be importable from the environment you are
calling `patch` from. The target is imported when the decorated function
is executed, not at decoration time.
The `spec` and `spec_set` keyword arguments are passed to the `MagicMock`
if patch is creating one for you.
In addition you can pass `spec=True` or `spec_set=True`, which causes
patch to pass in the object being mocked as the spec/spec_set object.
`new_callable` allows you to specify a different class, or callable object,
that will be called to create the `new` object. By default `MagicMock` is
used.
A more powerful form of `spec` is `autospec`. If you set `autospec=True`
then the mock with be created with a spec from the object being replaced.
All attributes of the mock will also have the spec of the corresponding
attribute of the object being replaced. Methods and functions being
mocked will have their arguments checked and will raise a `TypeError` if
they are called with the wrong signature. For mocks replacing a class,
their return value (the 'instance') will have the same spec as the class.
Instead of `autospec=True` you can pass `autospec=some_object` to use an
arbitrary object as the spec instead of the one being replaced.
By default `patch` will fail to replace attributes that don't exist. If
you pass in `create=True`, and the attribute doesn't exist, patch will
create the attribute for you when the patched function is called, and
delete it again afterwards. This is useful for writing tests against
attributes that your production code creates at runtime. It is off by
default because it can be dangerous. With it switched on you can write
passing tests against APIs that don't actually exist!
Patch can be used as a `TestCase` class decorator. It works by
decorating each test method in the class. This reduces the boilerplate
code when your test methods share a common patchings set. `patch` finds
tests by looking for method names that start with `patch.TEST_PREFIX`.
By default this is `test`, which matches the way `unittest` finds tests.
You can specify an alternative prefix by setting `patch.TEST_PREFIX`.
Patch can be used as a context manager, with the with statement. Here the
patching applies to the indented block after the with statement. If you
use "as" then the patched object will be bound to the name after the
"as"; very useful if `patch` is creating a mock object for you.
`patch` takes arbitrary keyword arguments. These will be passed to
the `Mock` (or `new_callable`) on construction.
`patch.dict(...)`, `patch.multiple(...)` and `patch.object(...)` are
available for alternate use-cases.
"""
getter, attribute = _get_target(target)
return _patch(
getter, attribute, new, spec, create,
spec_set, autospec, new_callable, kwargs
)
class _patch_dict(object):
"""
Patch a dictionary, or dictionary like object, and restore the dictionary
to its original state after the test.
`in_dict` can be a dictionary or a mapping like container. If it is a
mapping then it must at least support getting, setting and deleting items
plus iterating over keys.
`in_dict` can also be a string specifying the name of the dictionary, which
will then be fetched by importing it.
`values` can be a dictionary of values to set in the dictionary. `values`
can also be an iterable of `(key, value)` pairs.
If `clear` is True then the dictionary will be cleared before the new
values are set.
`patch.dict` can also be called with arbitrary keyword arguments to set
values in the dictionary::
with patch.dict('sys.modules', mymodule=Mock(), other_module=Mock()):
...
`patch.dict` can be used as a context manager, decorator or class
decorator. When used as a class decorator `patch.dict` honours
`patch.TEST_PREFIX` for choosing which methods to wrap.
"""
def __init__(self, in_dict, values=(), clear=False, **kwargs):
if isinstance(in_dict, str):
in_dict = _importer(in_dict)
self.in_dict = in_dict
# support any argument supported by dict(...) constructor
self.values = dict(values)
self.values.update(kwargs)
self.clear = clear
self._original = None
def __call__(self, f):
if isinstance(f, type):
return self.decorate_class(f)
@wraps(f)
def _inner(*args, **kw):
self._patch_dict()
try:
return f(*args, **kw)
finally:
self._unpatch_dict()
return _inner
def decorate_class(self, klass):
for attr in dir(klass):
attr_value = getattr(klass, attr)
if (attr.startswith(patch.TEST_PREFIX) and
hasattr(attr_value, "__call__")):
decorator = _patch_dict(self.in_dict, self.values, self.clear)
decorated = decorator(attr_value)
setattr(klass, attr, decorated)
return klass
def __enter__(self):
"""Patch the dict."""
self._patch_dict()
def _patch_dict(self):
values = self.values
in_dict = self.in_dict
clear = self.clear
try:
original = in_dict.copy()
except AttributeError:
# dict like object with no copy method
# must support iteration over keys
original = {}
for key in in_dict:
original[key] = in_dict[key]
self._original = original
if clear:
_clear_dict(in_dict)
try:
in_dict.update(values)
except AttributeError:
# dict like object with no update method
for key in values:
in_dict[key] = values[key]
def _unpatch_dict(self):
in_dict = self.in_dict
original = self._original
_clear_dict(in_dict)
try:
in_dict.update(original)
except AttributeError:
for key in original:
in_dict[key] = original[key]
def __exit__(self, *args):
"""Unpatch the dict."""
self._unpatch_dict()
return False
start = __enter__
stop = __exit__
def _clear_dict(in_dict):
try:
in_dict.clear()
except AttributeError:
keys = list(in_dict)
for key in keys:
del in_dict[key]
def _patch_stopall():
"""Stop all active patches. LIFO to unroll nested patches."""
for patch in reversed(_patch._active_patches):
patch.stop()
patch.object = _patch_object
patch.dict = _patch_dict
patch.multiple = _patch_multiple
patch.stopall = _patch_stopall
patch.TEST_PREFIX = 'test'
magic_methods = (
"lt le gt ge eq ne "
"getitem setitem delitem "
"len contains iter "
"hash str sizeof "
"enter exit "
"divmod neg pos abs invert "
"complex int float index "
"trunc floor ceil "
"bool next "
)
numerics = (
"add sub mul div floordiv mod lshift rshift and xor or pow truediv"
)
inplace = ' '.join('i%s' % n for n in numerics.split())
right = ' '.join('r%s' % n for n in numerics.split())
# not including __prepare__, __instancecheck__, __subclasscheck__
# (as they are metaclass methods)
# __del__ is not supported at all as it causes problems if it exists
_non_defaults = set('__%s__' % method for method in [
'get', 'set', 'delete', 'reversed', 'missing', 'reduce', 'reduce_ex',
'getinitargs', 'getnewargs', 'getstate', 'setstate', 'getformat',
'setformat', 'repr', 'dir', 'subclasses', 'format',
])
def _get_method(name, func):
"Turns a callable object (like a mock) into a real function"
def method(self, *args, **kw):
return func(self, *args, **kw)
method.__name__ = name
return method
_magics = set(
'__%s__' % method for method in
' '.join([magic_methods, numerics, inplace, right]).split()
)
_all_magics = _magics | _non_defaults
_unsupported_magics = set([
'__getattr__', '__setattr__',
'__init__', '__new__', '__prepare__'
'__instancecheck__', '__subclasscheck__',
'__del__'
])
_calculate_return_value = {
'__hash__': lambda self: object.__hash__(self),
'__str__': lambda self: object.__str__(self),
'__sizeof__': lambda self: object.__sizeof__(self),
}
_return_values = {
'__lt__': NotImplemented,
'__gt__': NotImplemented,
'__le__': NotImplemented,
'__ge__': NotImplemented,
'__int__': 1,
'__contains__': False,
'__len__': 0,
'__exit__': False,
'__complex__': 1j,
'__float__': 1.0,
'__bool__': True,
'__index__': 1,
}
def _get_eq(self):
def __eq__(other):
ret_val = self.__eq__._mock_return_value
if ret_val is not DEFAULT:
return ret_val
return self is other
return __eq__
def _get_ne(self):
def __ne__(other):
if self.__ne__._mock_return_value is not DEFAULT:
return DEFAULT
return self is not other
return __ne__
def _get_iter(self):
def __iter__():
ret_val = self.__iter__._mock_return_value
if ret_val is DEFAULT:
return iter([])
# if ret_val was already an iterator, then calling iter on it should
# return the iterator unchanged
return iter(ret_val)
return __iter__
_side_effect_methods = {
'__eq__': _get_eq,
'__ne__': _get_ne,
'__iter__': _get_iter,
}
def _set_return_value(mock, method, name):
fixed = _return_values.get(name, DEFAULT)
if fixed is not DEFAULT:
method.return_value = fixed
return
return_calulator = _calculate_return_value.get(name)
if return_calulator is not None:
try:
return_value = return_calulator(mock)
except AttributeError:
# XXXX why do we return AttributeError here?
# set it as a side_effect instead?
return_value = AttributeError(name)
method.return_value = return_value
return
side_effector = _side_effect_methods.get(name)
if side_effector is not None:
method.side_effect = side_effector(mock)
class MagicMixin(object):
def __init__(self, *args, **kw):
_safe_super(MagicMixin, self).__init__(*args, **kw)
self._mock_set_magics()
def _mock_set_magics(self):
these_magics = _magics
if self._mock_methods is not None:
these_magics = _magics.intersection(self._mock_methods)
remove_magics = set()
remove_magics = _magics - these_magics
for entry in remove_magics:
if entry in type(self).__dict__:
# remove unneeded magic methods
delattr(self, entry)
# don't overwrite existing attributes if called a second time
these_magics = these_magics - set(type(self).__dict__)
_type = type(self)
for entry in these_magics:
setattr(_type, entry, MagicProxy(entry, self))
class NonCallableMagicMock(MagicMixin, NonCallableMock):
"""A version of `MagicMock` that isn't callable."""
def mock_add_spec(self, spec, spec_set=False):
"""Add a spec to a mock. `spec` can either be an object or a
list of strings. Only attributes on the `spec` can be fetched as
attributes from the mock.
If `spec_set` is True then only attributes on the spec can be set."""
self._mock_add_spec(spec, spec_set)
self._mock_set_magics()
class MagicMock(MagicMixin, Mock):
"""
MagicMock is a subclass of Mock with default implementations
of most of the magic methods. You can use MagicMock without having to
configure the magic methods yourself.
If you use the `spec` or `spec_set` arguments then *only* magic
methods that exist in the spec will be created.
Attributes and the return value of a `MagicMock` will also be `MagicMocks`.
"""
def mock_add_spec(self, spec, spec_set=False):
"""Add a spec to a mock. `spec` can either be an object or a
list of strings. Only attributes on the `spec` can be fetched as
attributes from the mock.
If `spec_set` is True then only attributes on the spec can be set."""
self._mock_add_spec(spec, spec_set)
self._mock_set_magics()
class MagicProxy(object):
def __init__(self, name, parent):
self.name = name
self.parent = parent
def __call__(self, *args, **kwargs):
m = self.create_mock()
return m(*args, **kwargs)
def create_mock(self):
entry = self.name
parent = self.parent
m = parent._get_child_mock(name=entry, _new_name=entry,
_new_parent=parent)
setattr(parent, entry, m)
_set_return_value(parent, m, entry)
return m
def __get__(self, obj, _type=None):
return self.create_mock()
class _ANY(object):
"A helper object that compares equal to everything."
def __eq__(self, other):
return True
def __ne__(self, other):
return False
def __repr__(self):
return '<ANY>'
ANY = _ANY()
def _format_call_signature(name, args, kwargs):
message = '%s(%%s)' % name
formatted_args = ''
args_string = ', '.join([repr(arg) for arg in args])
kwargs_string = ', '.join([
'%s=%r' % (key, value) for key, value in kwargs.items()
])
if args_string:
formatted_args = args_string
if kwargs_string:
if formatted_args:
formatted_args += ', '
formatted_args += kwargs_string
return message % formatted_args
class _Call(tuple):
"""
A tuple for holding the results of a call to a mock, either in the form
`(args, kwargs)` or `(name, args, kwargs)`.
If args or kwargs are empty then a call tuple will compare equal to
a tuple without those values. This makes comparisons less verbose::
_Call(('name', (), {})) == ('name',)
_Call(('name', (1,), {})) == ('name', (1,))
_Call(((), {'a': 'b'})) == ({'a': 'b'},)
The `_Call` object provides a useful shortcut for comparing with call::
_Call(((1, 2), {'a': 3})) == call(1, 2, a=3)
_Call(('foo', (1, 2), {'a': 3})) == call.foo(1, 2, a=3)
If the _Call has no name then it will match any name.
"""
def __new__(cls, value=(), name=None, parent=None, two=False,
from_kall=True):
name = ''
args = ()
kwargs = {}
_len = len(value)
if _len == 3:
name, args, kwargs = value
elif _len == 2:
first, second = value
if isinstance(first, str):
name = first
if isinstance(second, tuple):
args = second
else:
kwargs = second
else:
args, kwargs = first, second
elif _len == 1:
value, = value
if isinstance(value, str):
name = value
elif isinstance(value, tuple):
args = value
else:
kwargs = value
if two:
return tuple.__new__(cls, (args, kwargs))
return tuple.__new__(cls, (name, args, kwargs))
def __init__(self, value=(), name=None, parent=None, two=False,
from_kall=True):
self.name = name
self.parent = parent
self.from_kall = from_kall
def __eq__(self, other):
if other is ANY:
return True
try:
len_other = len(other)
except TypeError:
return False
self_name = ''
if len(self) == 2:
self_args, self_kwargs = self
else:
self_name, self_args, self_kwargs = self
other_name = ''
if len_other == 0:
other_args, other_kwargs = (), {}
elif len_other == 3:
other_name, other_args, other_kwargs = other
elif len_other == 1:
value, = other
if isinstance(value, tuple):
other_args = value
other_kwargs = {}
elif isinstance(value, str):
other_name = value
other_args, other_kwargs = (), {}
else:
other_args = ()
other_kwargs = value
else:
# len 2
# could be (name, args) or (name, kwargs) or (args, kwargs)
first, second = other
if isinstance(first, str):
other_name = first
if isinstance(second, tuple):
other_args, other_kwargs = second, {}
else:
other_args, other_kwargs = (), second
else:
other_args, other_kwargs = first, second
if self_name and other_name != self_name:
return False
# this order is important for ANY to work!
return (other_args, other_kwargs) == (self_args, self_kwargs)
def __ne__(self, other):
return not self.__eq__(other)
def __call__(self, *args, **kwargs):
if self.name is None:
return _Call(('', args, kwargs), name='()')
name = self.name + '()'
return _Call((self.name, args, kwargs), name=name, parent=self)
def __getattr__(self, attr):
if self.name is None:
return _Call(name=attr, from_kall=False)
name = '%s.%s' % (self.name, attr)
return _Call(name=name, parent=self, from_kall=False)
def __repr__(self):
if not self.from_kall:
name = self.name or 'call'
if name.startswith('()'):
name = 'call%s' % name
return name
if len(self) == 2:
name = 'call'
args, kwargs = self
else:
name, args, kwargs = self
if not name:
name = 'call'
elif not name.startswith('()'):
name = 'call.%s' % name
else:
name = 'call%s' % name
return _format_call_signature(name, args, kwargs)
def call_list(self):
"""For a call object that represents multiple calls, `call_list`
returns a list of all the intermediate calls as well as the
final call."""
vals = []
thing = self
while thing is not None:
if thing.from_kall:
vals.append(thing)
thing = thing.parent
return _CallList(reversed(vals))
call = _Call(from_kall=False)
def create_autospec(spec, spec_set=False, instance=False, _parent=None,
_name=None, **kwargs):
"""Create a mock object using another object as a spec. Attributes on the
mock will use the corresponding attribute on the `spec` object as their
spec.
Functions or methods being mocked will have their arguments checked
to check that they are called with the correct signature.
If `spec_set` is True then attempting to set attributes that don't exist
on the spec object will raise an `AttributeError`.
If a class is used as a spec then the return value of the mock (the
instance of the class) will have the same spec. You can use a class as the
spec for an instance object by passing `instance=True`. The returned mock
will only be callable if instances of the mock are callable.
`create_autospec` also takes arbitrary keyword arguments that are passed to
the constructor of the created mock."""
if _is_list(spec):
# can't pass a list instance to the mock constructor as it will be
# interpreted as a list of strings
spec = type(spec)
is_type = isinstance(spec, type)
_kwargs = {'spec': spec}
if spec_set:
_kwargs = {'spec_set': spec}
elif spec is None:
# None we mock with a normal mock without a spec
_kwargs = {}
if _kwargs and instance:
_kwargs['_spec_as_instance'] = True
_kwargs.update(kwargs)
Klass = MagicMock
if type(spec) in DescriptorTypes:
# descriptors don't have a spec
# because we don't know what type they return
_kwargs = {}
elif not _callable(spec):
Klass = NonCallableMagicMock
elif is_type and instance and not _instance_callable(spec):
Klass = NonCallableMagicMock
_name = _kwargs.pop('name', _name)
_new_name = _name
if _parent is None:
# for a top level object no _new_name should be set
_new_name = ''
mock = Klass(parent=_parent, _new_parent=_parent, _new_name=_new_name,
name=_name, **_kwargs)
if isinstance(spec, FunctionTypes):
# should only happen at the top level because we don't
# recurse for functions
mock = _set_signature(mock, spec)
else:
_check_signature(spec, mock, is_type, instance)
if _parent is not None and not instance:
_parent._mock_children[_name] = mock
if is_type and not instance and 'return_value' not in kwargs:
mock.return_value = create_autospec(spec, spec_set, instance=True,
_name='()', _parent=mock)
for entry in dir(spec):
if _is_magic(entry):
# MagicMock already does the useful magic methods for us
continue
# XXXX do we need a better way of getting attributes without
# triggering code execution (?) Probably not - we need the actual
# object to mock it so we would rather trigger a property than mock
# the property descriptor. Likewise we want to mock out dynamically
# provided attributes.
# XXXX what about attributes that raise exceptions other than
# AttributeError on being fetched?
# we could be resilient against it, or catch and propagate the
# exception when the attribute is fetched from the mock
try:
original = getattr(spec, entry)
except AttributeError:
continue
kwargs = {'spec': original}
if spec_set:
kwargs = {'spec_set': original}
if not isinstance(original, FunctionTypes):
new = _SpecState(original, spec_set, mock, entry, instance)
mock._mock_children[entry] = new
else:
parent = mock
if isinstance(spec, FunctionTypes):
parent = mock.mock
skipfirst = _must_skip(spec, entry, is_type)
kwargs['_eat_self'] = skipfirst
new = MagicMock(parent=parent, name=entry, _new_name=entry,
_new_parent=parent,
**kwargs)
mock._mock_children[entry] = new
_check_signature(original, new, skipfirst=skipfirst)
# so functions created with _set_signature become instance attributes,
# *plus* their underlying mock exists in _mock_children of the parent
# mock. Adding to _mock_children may be unnecessary where we are also
# setting as an instance attribute?
if isinstance(new, FunctionTypes):
setattr(mock, entry, new)
return mock
def _must_skip(spec, entry, is_type):
"""
Return whether we should skip the first argument on spec's `entry`
attribute.
"""
if not isinstance(spec, type):
if entry in getattr(spec, '__dict__', {}):
# instance attribute - shouldn't skip
return False
spec = spec.__class__
for klass in spec.__mro__:
result = klass.__dict__.get(entry, DEFAULT)
if result is DEFAULT:
continue
if isinstance(result, (staticmethod, classmethod)):
return False
elif isinstance(getattr(result, '__get__', None), MethodWrapperTypes):
# Normal method => skip if looked up on type
# (if looked up on instance, self is already skipped)
return is_type
else:
return False
# shouldn't get here unless function is a dynamically provided attribute
# XXXX untested behaviour
return is_type
def _get_class(obj):
try:
return obj.__class__
except AttributeError:
# it is possible for objects to have no __class__
return type(obj)
class _SpecState(object):
def __init__(self, spec, spec_set=False, parent=None,
name=None, ids=None, instance=False):
self.spec = spec
self.ids = ids
self.spec_set = spec_set
self.parent = parent
self.instance = instance
self.name = name
FunctionTypes = (
# python function
type(create_autospec),
# instance method
type(ANY.__eq__),
)
MethodWrapperTypes = (
type(ANY.__eq__.__get__),
)
file_spec = None
def _iterate_read_data(read_data):
# Helper for mock_open:
# Retrieve lines from read_data via a generator so that separate calls to
# readline, read, and readlines are properly interleaved
data_as_list = ['{}\n'.format(l) for l in read_data.split('\n')]
if data_as_list[-1] == '\n':
# If the last line ended in a newline, the list comprehension will have an
# extra entry that's just a newline. Remove this.
data_as_list = data_as_list[:-1]
else:
# If there wasn't an extra newline by itself, then the file being
# emulated doesn't have a newline to end the last line remove the
# newline that our naive format() added
data_as_list[-1] = data_as_list[-1][:-1]
for line in data_as_list:
yield line
def mock_open(mock=None, read_data=''):
"""
A helper function to create a mock to replace the use of `open`. It works
for `open` called directly or used as a context manager.
The `mock` argument is the mock object to configure. If `None` (the
default) then a `MagicMock` will be created for you, with the API limited
to methods or attributes available on standard file handles.
`read_data` is a string for the `read` methoddline`, and `readlines` of the
file handle to return. This is an empty string by default.
"""
def _readlines_side_effect(*args, **kwargs):
if handle.readlines.return_value is not None:
return handle.readlines.return_value
return list(_data)
def _read_side_effect(*args, **kwargs):
if handle.read.return_value is not None:
return handle.read.return_value
return ''.join(_data)
def _readline_side_effect():
if handle.readline.return_value is not None:
while True:
yield handle.readline.return_value
for line in _data:
yield line
global file_spec
if file_spec is None:
import _io
file_spec = list(set(dir(_io.TextIOWrapper)).union(set(dir(_io.BytesIO))))
if mock is None:
mock = MagicMock(name='open', spec=open)
handle = MagicMock(spec=file_spec)
handle.__enter__.return_value = handle
_data = _iterate_read_data(read_data)
handle.write.return_value = None
handle.read.return_value = None
handle.readline.return_value = None
handle.readlines.return_value = None
handle.read.side_effect = _read_side_effect
handle.readline.side_effect = _readline_side_effect()
handle.readlines.side_effect = _readlines_side_effect
mock.return_value = handle
return mock
class PropertyMock(Mock):
"""
A mock intended to be used as a property, or other descriptor, on a class.
`PropertyMock` provides `__get__` and `__set__` methods so you can specify
a return value when it is fetched.
Fetching a `PropertyMock` instance from an object calls the mock, with
no args. Setting it calls the mock with the value being set.
"""
def _get_child_mock(self, **kwargs):
return MagicMock(**kwargs)
def __get__(self, obj, obj_type):
return self()
def __set__(self, obj, val):
self(val)
|
lgpl-3.0
|
[
3,
1683,
14,
647,
199,
3,
1379,
7249,
367,
1683,
316,
436,
3371,
316,
14,
199,
3,
16593,
8368,
379,
701,
16922,
481,
79,
2181,
199,
3,
10257,
719,
367,
1163,
5459,
402,
2018,
2808,
687,
199,
3,
1455,
921,
17343,
14,
1548,
14,
1308,
15,
17343,
15,
1805,
199,
199,
363,
452,
363,
275,
334,
272,
283,
3346,
297,
272,
283,
11988,
297,
272,
283,
2068,
297,
272,
283,
13400,
297,
272,
283,
3472,
297,
272,
283,
8974,
297,
272,
283,
1250,
297,
272,
283,
981,
63,
22303,
297,
272,
283,
9905,
63,
3022,
297,
272,
283,
6932,
16410,
3346,
297,
272,
283,
6932,
16410,
11988,
297,
272,
283,
1805,
63,
1490,
297,
272,
283,
3697,
3346,
297,
199,
9,
421,
199,
363,
1023,
363,
275,
283,
17,
14,
16,
7,
421,
199,
646,
6485,
199,
646,
10933,
199,
646,
984,
199,
504,
9143,
492,
14018,
12,
7417,
421,
199,
1563,
16836,
275,
334,
29900,
4258,
199,
692,
283,
6138,
7,
315,
984,
14,
3246,
26,
272,
327,
1335,
11361,
272,
492,
12120,
272,
3523,
16836,
275,
334,
29900,
12,
12120,
14,
4159,
14,
2719,
1143,
461,
9,
421,
199,
9905,
63,
3022,
275,
715,
199,
199,
3,
9361,
11659,
367,
4976,
327,
713,
13812,
199,
3,
23952,
642,
12,
314,
636,
533,
363,
4382,
3955,
78,
1133,
506,
663,
6657,
199,
63,
3489,
63,
4792,
275,
1613,
199,
199,
318,
485,
374,
63,
842,
63,
1805,
8,
1113,
304,
272,
327,
883,
1133,
675,
1228,
641,
4420,
2251,
2952,
2985,
4278,
636,
533,
363,
272,
327,
710,
1300,
1021,
367,
1006,
26500,
365,
10172,
16410,
3346,
272,
372,
11602,
8,
466,
8,
1113,
395,
10172,
16410,
3346,
9,
421,
199,
318,
485,
374,
63,
1971,
8,
1113,
304,
272,
372,
334,
267,
1228,
8,
1113,
12,
3523,
16836,
9,
503,
267,
1228,
8,
1113,
12,
730,
9,
436,
11602,
8,
1113,
12,
3523,
16836,
9,
272,
776,
421,
199,
533,
485,
7998,
471,
8,
785,
304,
272,
636,
7257,
363,
275,
788,
65,
418,
421,
199,
4311,
4100,
275,
334,
272,
730,
1547,
7998,
471,
14,
65,
395,
272,
3324,
12,
199,
9,
421,
199,
318,
485,
362,
63,
5233,
63,
785,
8,
1532,
12,
465,
63,
842,
12,
325,
292,
63,
277,
304,
272,
408,
272,
9138,
376,
9697,
12,
12570,
4550,
909,
12,
862,
370,
1218,
282,
11233,
272,
4955,
909,
14,
272,
1432,
282,
334,
19523,
2562,
12,
4955,
9,
2008,
12,
503,
488,
14,
272,
408,
272,
340,
1228,
8,
1532,
12,
730,
9,
436,
440,
465,
63,
842,
26,
267,
327,
982,
652,
1159,
282,
730,
436,
1077,
506,
1402,
1146,
465,
282,
730,
12,
675,
636,
826,
4343,
267,
862,
26,
288,
2562,
275,
2562,
855,
826,
363,
267,
871,
4281,
26,
288,
372,
488,
267,
327,
8232,
314,
658,
277,
64,
1423,
315,
636,
826,
363,
267,
325,
292,
63,
277,
275,
715,
272,
916,
440,
1228,
8,
1532,
12,
6801,
4100,
304,
267,
327,
982,
781,
7710,
2934,
370,
1402,
376,
1256,
402,
314,
3032,
730,
12,
267,
327,
636,
1250,
363,
1077,
506,
21182,
1536,
12,
440,
636,
826,
4343,
267,
862,
26,
288,
2562,
275,
2562,
855,
1250,
363,
267,
871,
4281,
26,
288,
372,
488,
272,
340,
325,
292,
63,
277,
26,
267,
5259,
63,
1532,
275,
7417,
8,
1532,
12,
488,
9,
272,
587,
26,
267,
5259,
63,
1532,
275,
2562,
272,
862,
26,
267,
372,
2562,
12,
6485,
14,
5233,
8,
4093,
63,
1532,
9,
272,
871,
1722,
26,
267,
327,
11002,
877,
4550,
2943,
787,
440,
3748,
701,
6485,
14,
5233,
342,
267,
372,
488,
421,
199,
318,
485,
1074,
63,
5233,
8,
1532,
12,
1683,
12,
3372,
2246,
12,
1256,
29,
797,
304,
272,
5259,
275,
485,
362,
63,
5233,
63,
785,
8,
1532,
12,
1256,
12,
3372,
2246,
9,
272,
340,
5259,
365,
488,
26,
267,
372,
272,
2562,
12,
5259,
275,
5259,
272,
347,
1104,
4093,
1547,
1805,
63,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
5259,
14,
3409,
2031,
589,
12,
1011,
958,
9,
272,
485,
1574,
63,
1532,
63,
5087,
8,
1532,
12,
1104,
4093,
9,
272,
730,
8,
1805,
10445,
1805,
63,
1074,
63,
4093,
275,
1104,
4093,
421,
199,
318,
485,
1574,
63,
1532,
63,
5087,
8,
1532,
12,
9627,
1574,
304,
272,
9627,
1574,
855,
354,
363,
275,
2562,
855,
354,
363,
272,
9627,
1574,
855,
1301,
363,
275,
2562,
855,
1301,
363,
272,
862,
26,
267,
9627,
1574,
855,
505,
63,
5233,
363,
275,
2562,
855,
505,
63,
5233,
363,
272,
871,
4281,
26,
267,
986,
272,
327,
781,
7662,
2793,
1133,
1331,
2562,
855,
807,
363,
1901,
642,
1331,
465,
652,
3955,
272,
327,
23705,
3379,
3004,
626,
1077,
506,
16991,
272,
862,
26,
267,
9627,
1574,
855,
578,
363,
275,
2562,
855,
578,
363,
272,
871,
4281,
26,
267,
986,
272,
862,
26,
267,
9627,
1574,
855,
4322,
363,
275,
2562,
855,
4322,
363,
272,
871,
4281,
26,
267,
986,
272,
862,
26,
267,
9627,
1574,
855,
829,
4322,
363,
275,
2562,
855,
829,
4322,
363,
272,
871,
4281,
26,
267,
986,
421,
199,
318,
485,
8296,
8,
1113,
304,
272,
340,
1228,
8,
1113,
12,
730,
304,
267,
372,
715,
272,
340,
2519,
8,
1113,
12,
2560,
1250,
7500,
488,
9,
365,
440,
488,
26,
267,
372,
715,
272,
372,
756,
421,
199,
318,
485,
374,
63,
513,
8,
1113,
304,
272,
327,
5920,
367,
769,
503,
6346,
272,
327,
5787,
56,
4875,
590,
4310,
1,
272,
372,
730,
8,
1113,
9,
315,
334,
513,
12,
2008,
9,
421,
199,
318,
485,
842,
63,
8296,
8,
1113,
304,
272,
408,
13735,
376,
909,
12,
372,
715,
340,
314,
909,
365,
4550,
14,
272,
2104,
3992,
12,
372,
715,
340,
4454,
3955,
506,
4550,
1041,
272,
340,
440,
1228,
8,
1113,
12,
730,
304,
267,
327,
2575,
376,
1256,
267,
372,
2519,
8,
1113,
12,
2560,
1250,
7500,
488,
9,
365,
440,
488,
339,
327,
627,
15153,
10,
506,
10529,
701,
282,
1021,
18972,
636,
17335,
363,
503,
636,
807,
363,
4799,
272,
327,
282,
17074,
272,
367,
1300,
315,
334,
1113,
4258,
435,
1559
] |
[
1683,
14,
647,
199,
3,
1379,
7249,
367,
1683,
316,
436,
3371,
316,
14,
199,
3,
16593,
8368,
379,
701,
16922,
481,
79,
2181,
199,
3,
10257,
719,
367,
1163,
5459,
402,
2018,
2808,
687,
199,
3,
1455,
921,
17343,
14,
1548,
14,
1308,
15,
17343,
15,
1805,
199,
199,
363,
452,
363,
275,
334,
272,
283,
3346,
297,
272,
283,
11988,
297,
272,
283,
2068,
297,
272,
283,
13400,
297,
272,
283,
3472,
297,
272,
283,
8974,
297,
272,
283,
1250,
297,
272,
283,
981,
63,
22303,
297,
272,
283,
9905,
63,
3022,
297,
272,
283,
6932,
16410,
3346,
297,
272,
283,
6932,
16410,
11988,
297,
272,
283,
1805,
63,
1490,
297,
272,
283,
3697,
3346,
297,
199,
9,
421,
199,
363,
1023,
363,
275,
283,
17,
14,
16,
7,
421,
199,
646,
6485,
199,
646,
10933,
199,
646,
984,
199,
504,
9143,
492,
14018,
12,
7417,
421,
199,
1563,
16836,
275,
334,
29900,
4258,
199,
692,
283,
6138,
7,
315,
984,
14,
3246,
26,
272,
327,
1335,
11361,
272,
492,
12120,
272,
3523,
16836,
275,
334,
29900,
12,
12120,
14,
4159,
14,
2719,
1143,
461,
9,
421,
199,
9905,
63,
3022,
275,
715,
199,
199,
3,
9361,
11659,
367,
4976,
327,
713,
13812,
199,
3,
23952,
642,
12,
314,
636,
533,
363,
4382,
3955,
78,
1133,
506,
663,
6657,
199,
63,
3489,
63,
4792,
275,
1613,
199,
199,
318,
485,
374,
63,
842,
63,
1805,
8,
1113,
304,
272,
327,
883,
1133,
675,
1228,
641,
4420,
2251,
2952,
2985,
4278,
636,
533,
363,
272,
327,
710,
1300,
1021,
367,
1006,
26500,
365,
10172,
16410,
3346,
272,
372,
11602,
8,
466,
8,
1113,
395,
10172,
16410,
3346,
9,
421,
199,
318,
485,
374,
63,
1971,
8,
1113,
304,
272,
372,
334,
267,
1228,
8,
1113,
12,
3523,
16836,
9,
503,
267,
1228,
8,
1113,
12,
730,
9,
436,
11602,
8,
1113,
12,
3523,
16836,
9,
272,
776,
421,
199,
533,
485,
7998,
471,
8,
785,
304,
272,
636,
7257,
363,
275,
788,
65,
418,
421,
199,
4311,
4100,
275,
334,
272,
730,
1547,
7998,
471,
14,
65,
395,
272,
3324,
12,
199,
9,
421,
199,
318,
485,
362,
63,
5233,
63,
785,
8,
1532,
12,
465,
63,
842,
12,
325,
292,
63,
277,
304,
272,
408,
272,
9138,
376,
9697,
12,
12570,
4550,
909,
12,
862,
370,
1218,
282,
11233,
272,
4955,
909,
14,
272,
1432,
282,
334,
19523,
2562,
12,
4955,
9,
2008,
12,
503,
488,
14,
272,
408,
272,
340,
1228,
8,
1532,
12,
730,
9,
436,
440,
465,
63,
842,
26,
267,
327,
982,
652,
1159,
282,
730,
436,
1077,
506,
1402,
1146,
465,
282,
730,
12,
675,
636,
826,
4343,
267,
862,
26,
288,
2562,
275,
2562,
855,
826,
363,
267,
871,
4281,
26,
288,
372,
488,
267,
327,
8232,
314,
658,
277,
64,
1423,
315,
636,
826,
363,
267,
325,
292,
63,
277,
275,
715,
272,
916,
440,
1228,
8,
1532,
12,
6801,
4100,
304,
267,
327,
982,
781,
7710,
2934,
370,
1402,
376,
1256,
402,
314,
3032,
730,
12,
267,
327,
636,
1250,
363,
1077,
506,
21182,
1536,
12,
440,
636,
826,
4343,
267,
862,
26,
288,
2562,
275,
2562,
855,
1250,
363,
267,
871,
4281,
26,
288,
372,
488,
272,
340,
325,
292,
63,
277,
26,
267,
5259,
63,
1532,
275,
7417,
8,
1532,
12,
488,
9,
272,
587,
26,
267,
5259,
63,
1532,
275,
2562,
272,
862,
26,
267,
372,
2562,
12,
6485,
14,
5233,
8,
4093,
63,
1532,
9,
272,
871,
1722,
26,
267,
327,
11002,
877,
4550,
2943,
787,
440,
3748,
701,
6485,
14,
5233,
342,
267,
372,
488,
421,
199,
318,
485,
1074,
63,
5233,
8,
1532,
12,
1683,
12,
3372,
2246,
12,
1256,
29,
797,
304,
272,
5259,
275,
485,
362,
63,
5233,
63,
785,
8,
1532,
12,
1256,
12,
3372,
2246,
9,
272,
340,
5259,
365,
488,
26,
267,
372,
272,
2562,
12,
5259,
275,
5259,
272,
347,
1104,
4093,
1547,
1805,
63,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
5259,
14,
3409,
2031,
589,
12,
1011,
958,
9,
272,
485,
1574,
63,
1532,
63,
5087,
8,
1532,
12,
1104,
4093,
9,
272,
730,
8,
1805,
10445,
1805,
63,
1074,
63,
4093,
275,
1104,
4093,
421,
199,
318,
485,
1574,
63,
1532,
63,
5087,
8,
1532,
12,
9627,
1574,
304,
272,
9627,
1574,
855,
354,
363,
275,
2562,
855,
354,
363,
272,
9627,
1574,
855,
1301,
363,
275,
2562,
855,
1301,
363,
272,
862,
26,
267,
9627,
1574,
855,
505,
63,
5233,
363,
275,
2562,
855,
505,
63,
5233,
363,
272,
871,
4281,
26,
267,
986,
272,
327,
781,
7662,
2793,
1133,
1331,
2562,
855,
807,
363,
1901,
642,
1331,
465,
652,
3955,
272,
327,
23705,
3379,
3004,
626,
1077,
506,
16991,
272,
862,
26,
267,
9627,
1574,
855,
578,
363,
275,
2562,
855,
578,
363,
272,
871,
4281,
26,
267,
986,
272,
862,
26,
267,
9627,
1574,
855,
4322,
363,
275,
2562,
855,
4322,
363,
272,
871,
4281,
26,
267,
986,
272,
862,
26,
267,
9627,
1574,
855,
829,
4322,
363,
275,
2562,
855,
829,
4322,
363,
272,
871,
4281,
26,
267,
986,
421,
199,
318,
485,
8296,
8,
1113,
304,
272,
340,
1228,
8,
1113,
12,
730,
304,
267,
372,
715,
272,
340,
2519,
8,
1113,
12,
2560,
1250,
7500,
488,
9,
365,
440,
488,
26,
267,
372,
715,
272,
372,
756,
421,
199,
318,
485,
374,
63,
513,
8,
1113,
304,
272,
327,
5920,
367,
769,
503,
6346,
272,
327,
5787,
56,
4875,
590,
4310,
1,
272,
372,
730,
8,
1113,
9,
315,
334,
513,
12,
2008,
9,
421,
199,
318,
485,
842,
63,
8296,
8,
1113,
304,
272,
408,
13735,
376,
909,
12,
372,
715,
340,
314,
909,
365,
4550,
14,
272,
2104,
3992,
12,
372,
715,
340,
4454,
3955,
506,
4550,
1041,
272,
340,
440,
1228,
8,
1113,
12,
730,
304,
267,
327,
2575,
376,
1256,
267,
372,
2519,
8,
1113,
12,
2560,
1250,
7500,
488,
9,
365,
440,
488,
339,
327,
627,
15153,
10,
506,
10529,
701,
282,
1021,
18972,
636,
17335,
363,
503,
636,
807,
363,
4799,
272,
327,
282,
17074,
272,
367,
1300,
315,
334,
1113,
4258,
435,
1559,
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,
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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
] |
ericzundel/pants
|
contrib/scalajs/src/python/pants/contrib/scalajs/register.py
|
17
|
1525
|
# coding=utf-8
# Copyright 2015 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).
from __future__ import (absolute_import, division, generators, nested_scopes, print_function,
unicode_literals, with_statement)
from pants.build_graph.build_file_aliases import BuildFileAliases
from pants.goal.task_registrar import TaskRegistrar as task
from pants.contrib.node.tasks.node_resolve import NodeResolve
from pants.contrib.scalajs.subsystems.scala_js_platform import ScalaJSPlatform
from pants.contrib.scalajs.targets.scala_js_binary import ScalaJSBinary
from pants.contrib.scalajs.targets.scala_js_library import ScalaJSLibrary
from pants.contrib.scalajs.tasks.scala_js_link import ScalaJSLink
from pants.contrib.scalajs.tasks.scala_js_zinc_compile import ScalaJSZincCompile
def build_file_aliases():
return BuildFileAliases(
targets={
'scala_js_binary': ScalaJSBinary,
'scala_js_library': ScalaJSLibrary,
},
)
def register_goals():
NodeResolve.register_resolver_for_type(ScalaJSBinary, ScalaJSPlatform)
# NB: These task/goal assignments are pretty nuts, but are necessary in order to
# prevent product-graph cycles between the JVM and node.js.
# see https://github.com/pantsbuild/pants/labels/engine
task(name='scala-js-compile', action=ScalaJSZincCompile).install('resolve')
task(name='scala-js-link', action=ScalaJSLink).install('resolve')
def global_subsystems():
return {ScalaJSPlatform}
|
apache-2.0
|
[
3,
2803,
29,
1624,
13,
24,
199,
3,
1898,
6900,
510,
2285,
2199,
8417,
334,
3239,
6483,
14,
1064,
680,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
3239,
5113,
680,
199,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
16952,
12,
6032,
63,
14129,
12,
870,
63,
1593,
12,
717,
2649,
63,
5955,
12,
543,
63,
6242,
9,
199,
199,
504,
18081,
14,
1506,
63,
2180,
14,
1506,
63,
493,
63,
8602,
492,
6516,
1173,
6985,
3274,
199,
504,
18081,
14,
16117,
14,
1765,
63,
1135,
31777,
492,
8495,
2872,
31777,
465,
2120,
199,
199,
504,
18081,
14,
2828,
14,
932,
14,
5054,
14,
932,
63,
6983,
492,
5013,
27459,
199,
504,
18081,
14,
2828,
14,
28708,
3596,
14,
954,
19135,
14,
28708,
63,
3596,
63,
3246,
492,
17619,
65,
11378,
10397,
199,
504,
18081,
14,
2828,
14,
28708,
3596,
14,
4684,
14,
28708,
63,
3596,
63,
3008,
492,
17619,
65,
11378,
6636,
199,
504,
18081,
14,
2828,
14,
28708,
3596,
14,
4684,
14,
28708,
63,
3596,
63,
4342,
492,
17619,
65,
11378,
7424,
199,
504,
18081,
14,
2828,
14,
28708,
3596,
14,
5054,
14,
28708,
63,
3596,
63,
1073,
492,
17619,
65,
11378,
3834,
199,
504,
18081,
14,
2828,
14,
28708,
3596,
14,
5054,
14,
28708,
63,
3596,
63,
90,
6559,
63,
2014,
492,
17619,
65,
11378,
58,
6559,
12626,
421,
199,
318,
1900,
63,
493,
63,
8602,
837,
523,
372,
6516,
1173,
6985,
3274,
8,
272,
4545,
3126,
489,
283,
28708,
63,
3596,
63,
3008,
356,
17619,
65,
11378,
6636,
12,
489,
283,
28708,
63,
3596,
63,
4342,
356,
17619,
65,
11378,
7424,
12,
272,
1660,
523,
776,
421,
199,
318,
2274,
63,
30970,
837,
523,
5013,
27459,
14,
2683,
63,
7717,
63,
509,
63,
466,
8,
10249,
65,
11378,
6636,
12,
17619,
65,
11378,
10397,
9,
523,
327,
25377,
26,
5723,
2120,
15,
16117,
18121,
787,
7268,
302,
14608,
12,
1325,
787,
5784,
315,
1865,
370,
523,
327,
7981,
3336,
13,
2180,
19001,
3382,
314,
1603,
6849,
436,
1031,
14,
3596,
14,
523,
327,
257,
1937,
4178,
921,
5031,
14,
957,
15,
21970,
1506,
15,
21970,
15,
3512,
15,
3908,
523,
2120,
8,
354,
534,
28708,
13,
3596,
13,
2014,
297,
1595,
29,
10249,
65,
11378,
58,
6559,
12626,
680,
3174,
360,
6983,
358,
523,
2120,
8,
354,
534,
28708,
13,
3596,
13,
1073,
297,
1595,
29,
10249,
65,
11378,
3834,
680,
3174,
360,
6983,
358,
421,
199,
318,
2288,
63,
954,
19135,
837,
523,
372,
469,
10249,
65,
11378,
10397,
93,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2803,
29,
1624,
13,
24,
199,
3,
1898,
6900,
510,
2285,
2199,
8417,
334,
3239,
6483,
14,
1064,
680,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
3239,
5113,
680,
199,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
16952,
12,
6032,
63,
14129,
12,
870,
63,
1593,
12,
717,
2649,
63,
5955,
12,
543,
63,
6242,
9,
199,
199,
504,
18081,
14,
1506,
63,
2180,
14,
1506,
63,
493,
63,
8602,
492,
6516,
1173,
6985,
3274,
199,
504,
18081,
14,
16117,
14,
1765,
63,
1135,
31777,
492,
8495,
2872,
31777,
465,
2120,
199,
199,
504,
18081,
14,
2828,
14,
932,
14,
5054,
14,
932,
63,
6983,
492,
5013,
27459,
199,
504,
18081,
14,
2828,
14,
28708,
3596,
14,
954,
19135,
14,
28708,
63,
3596,
63,
3246,
492,
17619,
65,
11378,
10397,
199,
504,
18081,
14,
2828,
14,
28708,
3596,
14,
4684,
14,
28708,
63,
3596,
63,
3008,
492,
17619,
65,
11378,
6636,
199,
504,
18081,
14,
2828,
14,
28708,
3596,
14,
4684,
14,
28708,
63,
3596,
63,
4342,
492,
17619,
65,
11378,
7424,
199,
504,
18081,
14,
2828,
14,
28708,
3596,
14,
5054,
14,
28708,
63,
3596,
63,
1073,
492,
17619,
65,
11378,
3834,
199,
504,
18081,
14,
2828,
14,
28708,
3596,
14,
5054,
14,
28708,
63,
3596,
63,
90,
6559,
63,
2014,
492,
17619,
65,
11378,
58,
6559,
12626,
421,
199,
318,
1900,
63,
493,
63,
8602,
837,
523,
372,
6516,
1173,
6985,
3274,
8,
272,
4545,
3126,
489,
283,
28708,
63,
3596,
63,
3008,
356,
17619,
65,
11378,
6636,
12,
489,
283,
28708,
63,
3596,
63,
4342,
356,
17619,
65,
11378,
7424,
12,
272,
1660,
523,
776,
421,
199,
318,
2274,
63,
30970,
837,
523,
5013,
27459,
14,
2683,
63,
7717,
63,
509,
63,
466,
8,
10249,
65,
11378,
6636,
12,
17619,
65,
11378,
10397,
9,
523,
327,
25377,
26,
5723,
2120,
15,
16117,
18121,
787,
7268,
302,
14608,
12,
1325,
787,
5784,
315,
1865,
370,
523,
327,
7981,
3336,
13,
2180,
19001,
3382,
314,
1603,
6849,
436,
1031,
14,
3596,
14,
523,
327,
257,
1937,
4178,
921,
5031,
14,
957,
15,
21970,
1506,
15,
21970,
15,
3512,
15,
3908,
523,
2120,
8,
354,
534,
28708,
13,
3596,
13,
2014,
297,
1595,
29,
10249,
65,
11378,
58,
6559,
12626,
680,
3174,
360,
6983,
358,
523,
2120,
8,
354,
534,
28708,
13,
3596,
13,
1073,
297,
1595,
29,
10249,
65,
11378,
3834,
680,
3174,
360,
6983,
358,
421,
199,
318,
2288,
63,
954,
19135,
837,
523,
372,
469,
10249,
65,
11378,
10397,
93,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
ministryofjustice/manchester_traffic_offences_pleas
|
apps/plea/tests/test_accessibility_switcher.py
|
1
|
2202
|
from django.test import TestCase
from django.test.client import Client
from django.conf import settings
from importlib import import_module
from waffle.models import Switch
class TestAccessibilitySwitcher(TestCase):
def setUp(self):
self.client = Client()
# http://code.djangoproject.com/ticket/10899
settings.SESSION_ENGINE = 'django.contrib.sessions.backends.file'
engine = import_module(settings.SESSION_ENGINE)
store = engine.SessionStore()
store.save()
self.session = store
self.client.cookies[settings.SESSION_COOKIE_NAME] = store.session_key
def test_a11y_testing_waffle_switch_off(self):
response = self.client.get("/set-a11y-testing/")
self.assertEqual(response.status_code, 404)
def test_a11y_testing_mode_tota11y(self):
Switch.objects.create(name="enable_a11y_testing", active=True)
response = self.client.get("/set-a11y-testing/?mode=tota11y")
response = self.client.get("/")
self.assertContains(response, "/static/javascripts/vendor/tota11y.min.js")
def test_a11y_testing_mode_google(self):
Switch.objects.create(name="enable_a11y_testing", active=True)
response = self.client.get("/set-a11y-testing/?mode=google")
response = self.client.get("/")
self.assertContains(response, "/static/javascripts/vendor/axs_testing.js")
def test_a11y_testing_mode_off(self):
Switch.objects.create(name="enable_a11y_testing", active=True)
response = self.client.get("/set-a11y-testing/?mode=off")
response = self.client.get("/")
self.assertNotContains(response, "/static/javascripts/vendor/tota11y.min.js")
self.assertNotContains(response, "/static/javascripts/vendor/axs_testing.js")
def test_a11y_testing_mode_wrong(self):
Switch.objects.create(name="enable_a11y_testing", active=True)
response = self.client.get("/set-a11y-testing/?mode=gfhdjaks")
response = self.client.get("/")
self.assertNotContains(response, "/static/javascripts/vendor/tota11y.min.js")
self.assertNotContains(response, "/static/javascripts/vendor/axs_testing.js")
|
mit
|
[
504,
1639,
14,
396,
492,
7640,
199,
504,
1639,
14,
396,
14,
1258,
492,
6810,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
14802,
492,
492,
63,
578,
199,
199,
504,
336,
9181,
274,
14,
992,
492,
17711,
421,
199,
533,
1379,
1945,
823,
4783,
10167,
281,
8,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
1258,
275,
6810,
342,
267,
327,
1455,
921,
600,
14,
14013,
14,
957,
15,
9201,
15,
8079,
1020,
267,
2202,
14,
12763,
63,
15956,
275,
283,
1176,
14,
2828,
14,
11676,
14,
7765,
14,
493,
7,
267,
6869,
275,
492,
63,
578,
8,
1751,
14,
12763,
63,
15956,
9,
267,
3877,
275,
6869,
14,
4434,
5502,
342,
267,
3877,
14,
2117,
342,
267,
291,
14,
1730,
275,
3877,
267,
291,
14,
1258,
14,
7792,
59,
1751,
14,
12763,
63,
13665,
63,
2339,
61,
275,
3877,
14,
1730,
63,
498,
339,
347,
511,
63,
65,
845,
89,
63,
4776,
63,
758,
556,
274,
63,
5656,
63,
1997,
8,
277,
304,
267,
1177,
275,
291,
14,
1258,
14,
362,
4769,
409,
13,
65,
845,
89,
13,
4776,
13589,
398,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
7901,
9,
339,
347,
511,
63,
65,
845,
89,
63,
4776,
63,
632,
63,
84,
12041,
845,
89,
8,
277,
304,
267,
17711,
14,
1462,
14,
981,
8,
354,
628,
4296,
63,
65,
845,
89,
63,
4776,
401,
4702,
29,
549,
9,
398,
1177,
275,
291,
14,
1258,
14,
362,
4769,
409,
13,
65,
845,
89,
13,
4776,
10197,
632,
29,
84,
12041,
845,
89,
531,
267,
1177,
275,
291,
14,
1258,
14,
362,
19031,
398,
291,
14,
9535,
8,
1310,
12,
3286,
1986,
15,
9554,
83,
15,
9884,
15,
84,
12041,
845,
89,
14,
827,
14,
3596,
531,
339,
347,
511,
63,
65,
845,
89,
63,
4776,
63,
632,
63,
3098,
8,
277,
304,
267,
17711,
14,
1462,
14,
981,
8,
354,
628,
4296,
63,
65,
845,
89,
63,
4776,
401,
4702,
29,
549,
9,
398,
1177,
275,
291,
14,
1258,
14,
362,
4769,
409,
13,
65,
845,
89,
13,
4776,
10197,
632,
29,
3098,
531,
267,
1177,
275,
291,
14,
1258,
14,
362,
19031,
398,
291,
14,
9535,
8,
1310,
12,
3286,
1986,
15,
9554,
83,
15,
9884,
15,
1219,
83,
63,
4776,
14,
3596,
531,
339,
347,
511,
63,
65,
845,
89,
63,
4776,
63,
632,
63,
1997,
8,
277,
304,
267,
17711,
14,
1462,
14,
981,
8,
354,
628,
4296,
63,
65,
845,
89,
63,
4776,
401,
4702,
29,
549,
9,
398,
1177,
275,
291,
14,
1258,
14,
362,
4769,
409,
13,
65,
845,
89,
13,
4776,
10197,
632,
29,
1997,
531,
267,
1177,
275,
291,
14,
1258,
14,
362,
19031,
398,
291,
14,
23218,
8,
1310,
12,
3286,
1986,
15,
9554,
83,
15,
9884,
15,
84,
12041,
845,
89,
14,
827,
14,
3596,
531,
267,
291,
14,
23218,
8,
1310,
12,
3286,
1986,
15,
9554,
83,
15,
9884,
15,
1219,
83,
63,
4776,
14,
3596,
531,
339,
347,
511,
63,
65,
845,
89,
63,
4776,
63,
632,
63,
10603,
8,
277,
304,
267,
17711,
14,
1462,
14,
981,
8,
354,
628,
4296,
63,
65,
845,
89,
63,
4776,
401,
4702,
29,
549,
9,
398,
1177,
275,
291,
14,
1258,
14,
362,
4769,
409,
13,
65,
845,
89,
13,
4776,
10197,
632,
29,
7102,
7952,
74,
14631,
531,
267,
1177,
275,
291,
14,
1258,
14,
362,
19031,
398,
291,
14,
23218,
8,
1310,
12,
3286,
1986,
15,
9554,
83,
15,
9884,
15,
84,
12041,
845,
89,
14,
827,
14,
3596,
531,
267,
291,
14,
23218,
8,
1310,
12,
3286,
1986,
15,
9554,
83,
15,
9884,
15,
1219,
83,
63,
4776,
14,
3596,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1639,
14,
396,
492,
7640,
199,
504,
1639,
14,
396,
14,
1258,
492,
6810,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
14802,
492,
492,
63,
578,
199,
199,
504,
336,
9181,
274,
14,
992,
492,
17711,
421,
199,
533,
1379,
1945,
823,
4783,
10167,
281,
8,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
1258,
275,
6810,
342,
267,
327,
1455,
921,
600,
14,
14013,
14,
957,
15,
9201,
15,
8079,
1020,
267,
2202,
14,
12763,
63,
15956,
275,
283,
1176,
14,
2828,
14,
11676,
14,
7765,
14,
493,
7,
267,
6869,
275,
492,
63,
578,
8,
1751,
14,
12763,
63,
15956,
9,
267,
3877,
275,
6869,
14,
4434,
5502,
342,
267,
3877,
14,
2117,
342,
267,
291,
14,
1730,
275,
3877,
267,
291,
14,
1258,
14,
7792,
59,
1751,
14,
12763,
63,
13665,
63,
2339,
61,
275,
3877,
14,
1730,
63,
498,
339,
347,
511,
63,
65,
845,
89,
63,
4776,
63,
758,
556,
274,
63,
5656,
63,
1997,
8,
277,
304,
267,
1177,
275,
291,
14,
1258,
14,
362,
4769,
409,
13,
65,
845,
89,
13,
4776,
13589,
398,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
7901,
9,
339,
347,
511,
63,
65,
845,
89,
63,
4776,
63,
632,
63,
84,
12041,
845,
89,
8,
277,
304,
267,
17711,
14,
1462,
14,
981,
8,
354,
628,
4296,
63,
65,
845,
89,
63,
4776,
401,
4702,
29,
549,
9,
398,
1177,
275,
291,
14,
1258,
14,
362,
4769,
409,
13,
65,
845,
89,
13,
4776,
10197,
632,
29,
84,
12041,
845,
89,
531,
267,
1177,
275,
291,
14,
1258,
14,
362,
19031,
398,
291,
14,
9535,
8,
1310,
12,
3286,
1986,
15,
9554,
83,
15,
9884,
15,
84,
12041,
845,
89,
14,
827,
14,
3596,
531,
339,
347,
511,
63,
65,
845,
89,
63,
4776,
63,
632,
63,
3098,
8,
277,
304,
267,
17711,
14,
1462,
14,
981,
8,
354,
628,
4296,
63,
65,
845,
89,
63,
4776,
401,
4702,
29,
549,
9,
398,
1177,
275,
291,
14,
1258,
14,
362,
4769,
409,
13,
65,
845,
89,
13,
4776,
10197,
632,
29,
3098,
531,
267,
1177,
275,
291,
14,
1258,
14,
362,
19031,
398,
291,
14,
9535,
8,
1310,
12,
3286,
1986,
15,
9554,
83,
15,
9884,
15,
1219,
83,
63,
4776,
14,
3596,
531,
339,
347,
511,
63,
65,
845,
89,
63,
4776,
63,
632,
63,
1997,
8,
277,
304,
267,
17711,
14,
1462,
14,
981,
8,
354,
628,
4296,
63,
65,
845,
89,
63,
4776,
401,
4702,
29,
549,
9,
398,
1177,
275,
291,
14,
1258,
14,
362,
4769,
409,
13,
65,
845,
89,
13,
4776,
10197,
632,
29,
1997,
531,
267,
1177,
275,
291,
14,
1258,
14,
362,
19031,
398,
291,
14,
23218,
8,
1310,
12,
3286,
1986,
15,
9554,
83,
15,
9884,
15,
84,
12041,
845,
89,
14,
827,
14,
3596,
531,
267,
291,
14,
23218,
8,
1310,
12,
3286,
1986,
15,
9554,
83,
15,
9884,
15,
1219,
83,
63,
4776,
14,
3596,
531,
339,
347,
511,
63,
65,
845,
89,
63,
4776,
63,
632,
63,
10603,
8,
277,
304,
267,
17711,
14,
1462,
14,
981,
8,
354,
628,
4296,
63,
65,
845,
89,
63,
4776,
401,
4702,
29,
549,
9,
398,
1177,
275,
291,
14,
1258,
14,
362,
4769,
409,
13,
65,
845,
89,
13,
4776,
10197,
632,
29,
7102,
7952,
74,
14631,
531,
267,
1177,
275,
291,
14,
1258,
14,
362,
19031,
398,
291,
14,
23218,
8,
1310,
12,
3286,
1986,
15,
9554,
83,
15,
9884,
15,
84,
12041,
845,
89,
14,
827,
14,
3596,
531,
267,
291,
14,
23218,
8,
1310,
12,
3286,
1986,
15,
9554,
83,
15,
9884,
15,
1219,
83,
63,
4776,
14,
3596,
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,
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,
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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
] |
encbladexp/ansible
|
test/lib/ansible_test/_internal/git.py
|
56
|
4379
|
"""Wrapper around git command-line tools."""
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import re
from . import types as t
from .util import (
SubprocessError,
raw_command,
)
class Git:
"""Wrapper around git command-line tools."""
def __init__(self, root=None): # type: (t.Optional[str]) -> None
self.git = 'git'
self.root = root
def get_diff(self, args, git_options=None):
"""
:type args: list[str]
:type git_options: list[str] | None
:rtype: list[str]
"""
cmd = ['diff'] + args
if git_options is None:
git_options = ['-c', 'core.quotePath=']
return self.run_git_split(git_options + cmd, '\n', str_errors='replace')
def get_diff_names(self, args):
"""
:type args: list[str]
:rtype: list[str]
"""
cmd = ['diff', '--name-only', '--no-renames', '-z'] + args
return self.run_git_split(cmd, '\0')
def get_submodule_paths(self): # type: () -> t.List[str]
"""Return a list of submodule paths recursively."""
cmd = ['submodule', 'status', '--recursive']
output = self.run_git_split(cmd, '\n')
submodule_paths = [re.search(r'^.[0-9a-f]+ (?P<path>[^ ]+)', line).group('path') for line in output]
# status is returned for all submodules in the current git repository relative to the current directory
# when the current directory is not the root of the git repository this can yield relative paths which are not below the current directory
# this can occur when multiple collections are in a git repo and some collections are submodules when others are not
# specifying "." as the path to enumerate would limit results to the current directory, but can cause the git command to fail with the error:
# error: pathspec '.' did not match any file(s) known to git
# this can occur when the current directory contains no files tracked by git
# instead we'll filter out the relative paths, since we're only interested in those at or below the current directory
submodule_paths = [path for path in submodule_paths if not path.startswith('../')]
return submodule_paths
def get_file_names(self, args):
"""
:type args: list[str]
:rtype: list[str]
"""
cmd = ['ls-files', '-z'] + args
return self.run_git_split(cmd, '\0')
def get_branches(self):
"""
:rtype: list[str]
"""
cmd = ['for-each-ref', 'refs/heads/', '--format', '%(refname:strip=2)']
return self.run_git_split(cmd)
def get_branch(self):
"""
:rtype: str
"""
cmd = ['symbolic-ref', '--short', 'HEAD']
return self.run_git(cmd).strip()
def get_rev_list(self, commits=None, max_count=None):
"""
:type commits: list[str] | None
:type max_count: int | None
:rtype: list[str]
"""
cmd = ['rev-list']
if commits:
cmd += commits
else:
cmd += ['HEAD']
if max_count:
cmd += ['--max-count', '%s' % max_count]
return self.run_git_split(cmd)
def get_branch_fork_point(self, branch):
"""
:type branch: str
:rtype: str
"""
cmd = ['merge-base', '--fork-point', branch]
return self.run_git(cmd).strip()
def is_valid_ref(self, ref):
"""
:type ref: str
:rtype: bool
"""
cmd = ['show', ref]
try:
self.run_git(cmd, str_errors='replace')
return True
except SubprocessError:
return False
def run_git_split(self, cmd, separator=None, str_errors='strict'):
"""
:type cmd: list[str]
:type separator: str | None
:type str_errors: str
:rtype: list[str]
"""
output = self.run_git(cmd, str_errors=str_errors).strip(separator)
if not output:
return []
return output.split(separator)
def run_git(self, cmd, str_errors='strict'):
"""
:type cmd: list[str]
:type str_errors: str
:rtype: str
"""
return raw_command([self.git] + cmd, cwd=self.root, capture=True, str_errors=str_errors)[0]
|
gpl-3.0
|
[
624,
4590,
6818,
6135,
1414,
13,
604,
7249,
1041,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
646,
295,
199,
199,
504,
1275,
492,
2943,
465,
307,
199,
199,
504,
1275,
1974,
492,
334,
272,
4804,
1412,
547,
12,
272,
3066,
63,
1531,
12,
199,
9,
421,
199,
533,
12579,
26,
272,
408,
4590,
6818,
6135,
1414,
13,
604,
7249,
1041,
272,
347,
636,
826,
721,
277,
12,
1738,
29,
403,
304,
221,
327,
730,
26,
334,
84,
14,
7012,
59,
495,
566,
1035,
488,
267,
291,
14,
3187,
275,
283,
3187,
7,
267,
291,
14,
1231,
275,
1738,
339,
347,
664,
63,
3028,
8,
277,
12,
1249,
12,
6135,
63,
1419,
29,
403,
304,
267,
408,
267,
520,
466,
1249,
26,
769,
59,
495,
61,
267,
520,
466,
6135,
63,
1419,
26,
769,
59,
495,
61,
1204,
488,
267,
520,
4500,
26,
769,
59,
495,
61,
267,
408,
267,
2088,
275,
788,
3028,
418,
435,
1249,
267,
340,
6135,
63,
1419,
365,
488,
26,
288,
6135,
63,
1419,
275,
11573,
67,
297,
283,
1018,
14,
3513,
2042,
29,
418,
267,
372,
291,
14,
1065,
63,
3187,
63,
1294,
8,
3187,
63,
1419,
435,
2088,
12,
1557,
78,
297,
620,
63,
2550,
534,
1814,
358,
339,
347,
664,
63,
3028,
63,
1247,
8,
277,
12,
1249,
304,
267,
408,
267,
520,
466,
1249,
26,
769,
59,
495,
61,
267,
520,
4500,
26,
769,
59,
495,
61,
267,
408,
267,
2088,
275,
788,
3028,
297,
2850,
354,
13,
2118,
297,
2850,
889,
13,
264,
1247,
297,
2475,
90,
418,
435,
1249,
267,
372,
291,
14,
1065,
63,
3187,
63,
1294,
8,
1760,
12,
1557,
16,
358,
339,
347,
664,
63,
16229,
63,
3771,
8,
277,
304,
221,
327,
730,
26,
6248,
1035,
307,
14,
1296,
59,
495,
61,
267,
408,
1767,
282,
769,
402,
22988,
3792,
15035,
1041,
267,
2088,
275,
788,
16229,
297,
283,
1205,
297,
2850,
9931,
418,
267,
1072,
275,
291,
14,
1065,
63,
3187,
63,
1294,
8,
1760,
12,
1557,
78,
358,
267,
22988,
63,
3771,
275,
359,
264,
14,
1733,
8,
82,
4289,
24097,
16,
13,
25,
65,
13,
70,
2807,
7558,
48,
28,
515,
13489,
1622,
14705,
1004,
680,
923,
360,
515,
358,
367,
1004,
315,
1072,
61,
398,
327,
2004,
365,
2138,
367,
1006,
29449,
315,
314,
1453,
6135,
7611,
3847,
370,
314,
1453,
2082,
267,
327,
1380,
314,
1453,
2082,
365,
440,
314,
1738,
402,
314,
6135,
7611,
642,
883,
1995,
3847,
3792,
1314,
787,
440,
5084,
314,
1453,
2082,
267,
327,
642,
883,
4781,
1380,
3663,
5055,
787,
315,
282,
6135,
3831,
436,
2005,
5055,
787,
29449,
1380,
11789,
787,
440,
267,
327,
9176,
14530,
465,
314,
931,
370,
3874,
3955,
2304,
2058,
370,
314,
1453,
2082,
12,
1325,
883,
7675,
314,
6135,
1414,
370,
2449,
543,
314,
1125,
26,
267,
327,
257,
1125,
26,
931,
1650,
7815,
8103,
440,
1336,
1263,
570,
8,
83,
9,
6040,
370,
6135,
267,
327,
642,
883,
4781,
1380,
314,
1453,
2082,
3509,
949,
1584,
23268,
701,
6135,
267,
327,
3140,
781,
7171,
2457,
734,
314,
3847,
3792,
12,
3967,
781,
3984,
1454,
22201,
315,
5204,
737,
503,
5084,
314,
1453,
2082,
267,
22988,
63,
3771,
275,
359,
515,
367,
931,
315,
22988,
63,
3771,
340,
440,
931,
14,
2460,
24592,
5440,
398,
372,
22988,
63,
3771,
339,
347,
664,
63,
493,
63,
1247,
8,
277,
12,
1249,
304,
267,
408,
267,
520,
466,
1249,
26,
769,
59,
495,
61,
267,
520,
4500,
26,
769,
59,
495,
61,
267,
408,
267,
2088,
275,
788,
478,
13,
1725,
297,
2475,
90,
418,
435,
1249,
267,
372,
291,
14,
1065,
63,
3187,
63,
1294,
8,
1760,
12,
1557,
16,
358,
339,
347,
664,
63,
16896,
8,
277,
304,
267,
408,
267,
520,
4500,
26,
769,
59,
495,
61,
267,
408,
267,
2088,
275,
788,
509,
13,
10885,
13,
1121,
297,
283,
7655,
15,
17033,
3678,
2850,
908,
297,
9487,
29124,
26,
1913,
29,
18,
9,
418,
267,
372,
291,
14,
1065,
63,
3187,
63,
1294,
8,
1760,
9,
339,
347,
664,
63,
4694,
8,
277,
304,
267,
408,
267,
520,
4500,
26,
620,
267,
408,
267,
2088,
275,
788,
22836,
13,
1121,
297,
2850,
3612,
297,
283,
5211,
418,
267,
372,
291,
14,
1065,
63,
3187,
8,
1760,
680,
1913,
342,
339,
347,
664,
63,
4964,
63,
513,
8,
277,
12,
20835,
29,
403,
12,
1390,
63,
835,
29,
403,
304,
267,
408,
267,
520,
466,
20835,
26,
769,
59,
495,
61,
1204,
488,
267,
520,
466,
1390,
63,
835,
26,
1109,
1204,
488,
267,
520,
4500,
26,
769,
59,
495,
61,
267,
408,
267,
2088,
275,
788,
4964,
13,
513,
418,
398,
340,
20835,
26,
288,
2088,
847,
20835,
267,
587,
26,
288,
2088,
847,
788,
5211,
418,
398,
340,
1390,
63,
835,
26,
288,
2088,
847,
14574,
988,
13,
835,
297,
1543,
83,
7,
450,
1390,
63,
835,
61,
398,
372,
291,
14,
1065,
63,
3187,
63,
1294,
8,
1760,
9,
339,
347,
664,
63,
4694,
63,
11796,
63,
1403,
8,
277,
12,
5246,
304,
267,
408,
267,
520,
466,
5246,
26,
620,
267,
520,
4500,
26,
620,
267,
408,
267,
2088,
275,
788,
5628,
13,
1095,
297,
2850,
11796,
13,
1403,
297,
5246,
61,
267,
372,
291,
14,
1065,
63,
3187,
8,
1760,
680,
1913,
342,
339,
347,
365,
63,
1078,
63,
1121,
8,
277,
12,
2984,
304,
267,
408,
267,
520,
466,
2984,
26,
620,
267,
520,
4500,
26,
2155,
267,
408,
267,
2088,
275,
788,
2384,
297,
2984,
61,
267,
862,
26,
288,
291,
14,
1065,
63,
3187,
8,
1760,
12,
620,
63,
2550,
534,
1814,
358,
288,
372,
715,
267,
871,
4804,
1412,
547,
26,
288,
372,
756,
339,
347,
1255,
63,
3187,
63,
1294,
8,
277,
12,
2088,
12,
9432,
29,
403,
12,
620,
63,
2550,
534,
4768,
735,
267,
408,
267,
520,
466,
2088,
26,
769,
59,
495,
61,
267,
520,
466,
9432,
26,
620,
1204,
488,
267,
520,
466,
620,
63,
2550,
26,
620,
267,
520,
4500,
26,
769,
59,
495,
61,
267,
408,
267,
1072
] |
[
4590,
6818,
6135,
1414,
13,
604,
7249,
1041,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
646,
295,
199,
199,
504,
1275,
492,
2943,
465,
307,
199,
199,
504,
1275,
1974,
492,
334,
272,
4804,
1412,
547,
12,
272,
3066,
63,
1531,
12,
199,
9,
421,
199,
533,
12579,
26,
272,
408,
4590,
6818,
6135,
1414,
13,
604,
7249,
1041,
272,
347,
636,
826,
721,
277,
12,
1738,
29,
403,
304,
221,
327,
730,
26,
334,
84,
14,
7012,
59,
495,
566,
1035,
488,
267,
291,
14,
3187,
275,
283,
3187,
7,
267,
291,
14,
1231,
275,
1738,
339,
347,
664,
63,
3028,
8,
277,
12,
1249,
12,
6135,
63,
1419,
29,
403,
304,
267,
408,
267,
520,
466,
1249,
26,
769,
59,
495,
61,
267,
520,
466,
6135,
63,
1419,
26,
769,
59,
495,
61,
1204,
488,
267,
520,
4500,
26,
769,
59,
495,
61,
267,
408,
267,
2088,
275,
788,
3028,
418,
435,
1249,
267,
340,
6135,
63,
1419,
365,
488,
26,
288,
6135,
63,
1419,
275,
11573,
67,
297,
283,
1018,
14,
3513,
2042,
29,
418,
267,
372,
291,
14,
1065,
63,
3187,
63,
1294,
8,
3187,
63,
1419,
435,
2088,
12,
1557,
78,
297,
620,
63,
2550,
534,
1814,
358,
339,
347,
664,
63,
3028,
63,
1247,
8,
277,
12,
1249,
304,
267,
408,
267,
520,
466,
1249,
26,
769,
59,
495,
61,
267,
520,
4500,
26,
769,
59,
495,
61,
267,
408,
267,
2088,
275,
788,
3028,
297,
2850,
354,
13,
2118,
297,
2850,
889,
13,
264,
1247,
297,
2475,
90,
418,
435,
1249,
267,
372,
291,
14,
1065,
63,
3187,
63,
1294,
8,
1760,
12,
1557,
16,
358,
339,
347,
664,
63,
16229,
63,
3771,
8,
277,
304,
221,
327,
730,
26,
6248,
1035,
307,
14,
1296,
59,
495,
61,
267,
408,
1767,
282,
769,
402,
22988,
3792,
15035,
1041,
267,
2088,
275,
788,
16229,
297,
283,
1205,
297,
2850,
9931,
418,
267,
1072,
275,
291,
14,
1065,
63,
3187,
63,
1294,
8,
1760,
12,
1557,
78,
358,
267,
22988,
63,
3771,
275,
359,
264,
14,
1733,
8,
82,
4289,
24097,
16,
13,
25,
65,
13,
70,
2807,
7558,
48,
28,
515,
13489,
1622,
14705,
1004,
680,
923,
360,
515,
358,
367,
1004,
315,
1072,
61,
398,
327,
2004,
365,
2138,
367,
1006,
29449,
315,
314,
1453,
6135,
7611,
3847,
370,
314,
1453,
2082,
267,
327,
1380,
314,
1453,
2082,
365,
440,
314,
1738,
402,
314,
6135,
7611,
642,
883,
1995,
3847,
3792,
1314,
787,
440,
5084,
314,
1453,
2082,
267,
327,
642,
883,
4781,
1380,
3663,
5055,
787,
315,
282,
6135,
3831,
436,
2005,
5055,
787,
29449,
1380,
11789,
787,
440,
267,
327,
9176,
14530,
465,
314,
931,
370,
3874,
3955,
2304,
2058,
370,
314,
1453,
2082,
12,
1325,
883,
7675,
314,
6135,
1414,
370,
2449,
543,
314,
1125,
26,
267,
327,
257,
1125,
26,
931,
1650,
7815,
8103,
440,
1336,
1263,
570,
8,
83,
9,
6040,
370,
6135,
267,
327,
642,
883,
4781,
1380,
314,
1453,
2082,
3509,
949,
1584,
23268,
701,
6135,
267,
327,
3140,
781,
7171,
2457,
734,
314,
3847,
3792,
12,
3967,
781,
3984,
1454,
22201,
315,
5204,
737,
503,
5084,
314,
1453,
2082,
267,
22988,
63,
3771,
275,
359,
515,
367,
931,
315,
22988,
63,
3771,
340,
440,
931,
14,
2460,
24592,
5440,
398,
372,
22988,
63,
3771,
339,
347,
664,
63,
493,
63,
1247,
8,
277,
12,
1249,
304,
267,
408,
267,
520,
466,
1249,
26,
769,
59,
495,
61,
267,
520,
4500,
26,
769,
59,
495,
61,
267,
408,
267,
2088,
275,
788,
478,
13,
1725,
297,
2475,
90,
418,
435,
1249,
267,
372,
291,
14,
1065,
63,
3187,
63,
1294,
8,
1760,
12,
1557,
16,
358,
339,
347,
664,
63,
16896,
8,
277,
304,
267,
408,
267,
520,
4500,
26,
769,
59,
495,
61,
267,
408,
267,
2088,
275,
788,
509,
13,
10885,
13,
1121,
297,
283,
7655,
15,
17033,
3678,
2850,
908,
297,
9487,
29124,
26,
1913,
29,
18,
9,
418,
267,
372,
291,
14,
1065,
63,
3187,
63,
1294,
8,
1760,
9,
339,
347,
664,
63,
4694,
8,
277,
304,
267,
408,
267,
520,
4500,
26,
620,
267,
408,
267,
2088,
275,
788,
22836,
13,
1121,
297,
2850,
3612,
297,
283,
5211,
418,
267,
372,
291,
14,
1065,
63,
3187,
8,
1760,
680,
1913,
342,
339,
347,
664,
63,
4964,
63,
513,
8,
277,
12,
20835,
29,
403,
12,
1390,
63,
835,
29,
403,
304,
267,
408,
267,
520,
466,
20835,
26,
769,
59,
495,
61,
1204,
488,
267,
520,
466,
1390,
63,
835,
26,
1109,
1204,
488,
267,
520,
4500,
26,
769,
59,
495,
61,
267,
408,
267,
2088,
275,
788,
4964,
13,
513,
418,
398,
340,
20835,
26,
288,
2088,
847,
20835,
267,
587,
26,
288,
2088,
847,
788,
5211,
418,
398,
340,
1390,
63,
835,
26,
288,
2088,
847,
14574,
988,
13,
835,
297,
1543,
83,
7,
450,
1390,
63,
835,
61,
398,
372,
291,
14,
1065,
63,
3187,
63,
1294,
8,
1760,
9,
339,
347,
664,
63,
4694,
63,
11796,
63,
1403,
8,
277,
12,
5246,
304,
267,
408,
267,
520,
466,
5246,
26,
620,
267,
520,
4500,
26,
620,
267,
408,
267,
2088,
275,
788,
5628,
13,
1095,
297,
2850,
11796,
13,
1403,
297,
5246,
61,
267,
372,
291,
14,
1065,
63,
3187,
8,
1760,
680,
1913,
342,
339,
347,
365,
63,
1078,
63,
1121,
8,
277,
12,
2984,
304,
267,
408,
267,
520,
466,
2984,
26,
620,
267,
520,
4500,
26,
2155,
267,
408,
267,
2088,
275,
788,
2384,
297,
2984,
61,
267,
862,
26,
288,
291,
14,
1065,
63,
3187,
8,
1760,
12,
620,
63,
2550,
534,
1814,
358,
288,
372,
715,
267,
871,
4804,
1412,
547,
26,
288,
372,
756,
339,
347,
1255,
63,
3187,
63,
1294,
8,
277,
12,
2088,
12,
9432,
29,
403,
12,
620,
63,
2550,
534,
4768,
735,
267,
408,
267,
520,
466,
2088,
26,
769,
59,
495,
61,
267,
520,
466,
9432,
26,
620,
1204,
488,
267,
520,
466,
620,
63,
2550,
26,
620,
267,
520,
4500,
26,
769,
59,
495,
61,
267,
408,
267,
1072,
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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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
Distrotech/clamav
|
libclamav/c++/llvm/utils/lit/setup.py
|
21
|
1665
|
import lit
# FIXME: Support distutils?
from setuptools import setup, find_packages
setup(
name = "Lit",
version = lit.__version__,
author = lit.__author__,
author_email = lit.__email__,
url = 'http://llvm.org',
license = 'BSD',
description = "A Software Testing Tool",
keywords = 'test C++ automatic discovery',
long_description = """\
Lit
+++
About
=====
Lit is a portable tool for executing LLVM and Clang style test suites,
summarizing their results, and providing indication of failures. Lit is designed
to be a lightweight testing tool with as simple a user interface as possible.
Features
========
* Portable!
* Flexible test discovery.
* Parallel test execution.
* Support for multiple test formats and test suite designs.
Documentation
=============
The offical Lit documentation is in the man page, available online in the `LLVM
Command Guide http://llvm.org/cmds/lit.html`_.
Source
======
The Lit source is available as part of LLVM, in the `LLVM SVN repository
<http://llvm.org/svn/llvm-project/llvm/trunk/utils/lit`_.
""",
classifiers=[
'Development Status :: 3 - Alpha',
'Environment :: Console',
'Intended Audience :: Developers',
'License :: OSI Approved :: University of Illinois/NCSA Open Source License',
'Natural Language :: English',
'Operating System :: OS Independent',
'Progamming Language :: Python',
'Topic :: Software Development :: Testing',
],
zip_safe = False,
packages = find_packages(),
entry_points = {
'console_scripts': [
'lit = lit:main',
],
}
)
|
gpl-2.0
|
[
646,
28649,
199,
199,
3,
7600,
26,
12502,
7065,
31,
199,
504,
9116,
492,
3272,
12,
2342,
63,
5154,
199,
2758,
8,
272,
536,
275,
298,
44,
390,
401,
272,
1015,
275,
28649,
855,
1023,
3108,
339,
4132,
275,
28649,
855,
2502,
3108,
272,
4132,
63,
2123,
275,
28649,
855,
2123,
3108,
272,
1166,
275,
283,
1014,
921,
29257,
14,
1308,
297,
272,
4190,
275,
283,
15400,
297,
339,
1369,
275,
298,
33,
2290,
11940,
15650,
401,
272,
7681,
275,
283,
396,
445,
4176,
4834,
13172,
297,
272,
1846,
63,
1802,
275,
9638,
199,
44,
390,
199,
4176,
11,
199,
199,
18816,
199,
19989,
199,
199,
44,
390,
365,
282,
1844,
461,
4744,
367,
14043,
491,
28631,
436,
445,
4159,
3449,
511,
24203,
12,
199,
1838,
4584,
9147,
3932,
2058,
12,
436,
13070,
2539,
1063,
402,
9081,
14,
491,
390,
365,
19829,
199,
475,
506,
282,
10540,
3463,
5343,
4744,
543,
465,
3486,
282,
922,
3217,
465,
3962,
14,
421,
199,
10807,
199,
763,
421,
627,
10977,
461,
1,
199,
627,
481,
8196,
511,
13172,
14,
199,
627,
27311,
511,
6451,
14,
199,
627,
12502,
367,
3663,
511,
6752,
436,
511,
5241,
477,
20440,
14,
421,
199,
17763,
199,
9152,
199,
199,
1918,
402,
329,
915,
491,
390,
3794,
365,
315,
314,
2169,
2034,
12,
2808,
18470,
315,
314,
658,
4464,
6849,
199,
3110,
15423,
1455,
921,
29257,
14,
1308,
15,
12975,
15,
1051,
14,
1360,
32578,
421,
199,
2980,
199,
23476,
199,
199,
1918,
491,
390,
1350,
365,
2808,
465,
1777,
402,
491,
28631,
12,
315,
314,
658,
4464,
6849,
24639,
7611,
199,
28,
1014,
921,
29257,
14,
1308,
15,
6836,
15,
29257,
13,
1715,
15,
29257,
15,
13409,
15,
1208,
15,
1051,
32578,
199,
7208,
339,
19137,
1524,
267,
283,
23753,
9795,
3800,
650,
446,
32657,
297,
267,
283,
8263,
3800,
19809,
297,
267,
283,
23910,
23975,
3800,
23493,
297,
267,
283,
3761,
3800,
25718,
26330,
3800,
15904,
402,
473,
76,
472,
79,
374,
15,
46,
3298,
33,
3232,
5800,
844,
297,
267,
283,
23604,
4889,
8466,
3800,
20144,
297,
267,
283,
23699,
6187,
3800,
4403,
1010,
7106,
297,
267,
283,
919,
17740,
14566,
8466,
3800,
2018,
297,
267,
283,
12157,
3800,
2290,
15290,
3800,
11940,
297,
267,
2156,
339,
3482,
63,
3489,
275,
756,
12,
272,
6117,
275,
2342,
63,
5154,
1062,
272,
2397,
63,
3438,
275,
469,
267,
283,
6614,
63,
6429,
356,
359,
288,
283,
1051,
275,
28649,
26,
973,
297,
288,
2156,
267,
789,
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
] |
[
28649,
199,
199,
3,
7600,
26,
12502,
7065,
31,
199,
504,
9116,
492,
3272,
12,
2342,
63,
5154,
199,
2758,
8,
272,
536,
275,
298,
44,
390,
401,
272,
1015,
275,
28649,
855,
1023,
3108,
339,
4132,
275,
28649,
855,
2502,
3108,
272,
4132,
63,
2123,
275,
28649,
855,
2123,
3108,
272,
1166,
275,
283,
1014,
921,
29257,
14,
1308,
297,
272,
4190,
275,
283,
15400,
297,
339,
1369,
275,
298,
33,
2290,
11940,
15650,
401,
272,
7681,
275,
283,
396,
445,
4176,
4834,
13172,
297,
272,
1846,
63,
1802,
275,
9638,
199,
44,
390,
199,
4176,
11,
199,
199,
18816,
199,
19989,
199,
199,
44,
390,
365,
282,
1844,
461,
4744,
367,
14043,
491,
28631,
436,
445,
4159,
3449,
511,
24203,
12,
199,
1838,
4584,
9147,
3932,
2058,
12,
436,
13070,
2539,
1063,
402,
9081,
14,
491,
390,
365,
19829,
199,
475,
506,
282,
10540,
3463,
5343,
4744,
543,
465,
3486,
282,
922,
3217,
465,
3962,
14,
421,
199,
10807,
199,
763,
421,
627,
10977,
461,
1,
199,
627,
481,
8196,
511,
13172,
14,
199,
627,
27311,
511,
6451,
14,
199,
627,
12502,
367,
3663,
511,
6752,
436,
511,
5241,
477,
20440,
14,
421,
199,
17763,
199,
9152,
199,
199,
1918,
402,
329,
915,
491,
390,
3794,
365,
315,
314,
2169,
2034,
12,
2808,
18470,
315,
314,
658,
4464,
6849,
199,
3110,
15423,
1455,
921,
29257,
14,
1308,
15,
12975,
15,
1051,
14,
1360,
32578,
421,
199,
2980,
199,
23476,
199,
199,
1918,
491,
390,
1350,
365,
2808,
465,
1777,
402,
491,
28631,
12,
315,
314,
658,
4464,
6849,
24639,
7611,
199,
28,
1014,
921,
29257,
14,
1308,
15,
6836,
15,
29257,
13,
1715,
15,
29257,
15,
13409,
15,
1208,
15,
1051,
32578,
199,
7208,
339,
19137,
1524,
267,
283,
23753,
9795,
3800,
650,
446,
32657,
297,
267,
283,
8263,
3800,
19809,
297,
267,
283,
23910,
23975,
3800,
23493,
297,
267,
283,
3761,
3800,
25718,
26330,
3800,
15904,
402,
473,
76,
472,
79,
374,
15,
46,
3298,
33,
3232,
5800,
844,
297,
267,
283,
23604,
4889,
8466,
3800,
20144,
297,
267,
283,
23699,
6187,
3800,
4403,
1010,
7106,
297,
267,
283,
919,
17740,
14566,
8466,
3800,
2018,
297,
267,
283,
12157,
3800,
2290,
15290,
3800,
11940,
297,
267,
2156,
339,
3482,
63,
3489,
275,
756,
12,
272,
6117,
275,
2342,
63,
5154,
1062,
272,
2397,
63,
3438,
275,
469,
267,
283,
6614,
63,
6429,
356,
359,
288,
283,
1051,
275,
28649,
26,
973,
297,
288,
2156,
267,
789,
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,
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,
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013, 2014 Sourcefabric z.u. and contributors.
#
# For the full copyright and license information, please see the
# AUTHORS and LICENSE files distributed with this source code, or
# at https://www.sourcefabric.org/superdesk/license
from content_api.items.service import ItemsService
from flask import g
from superdesk import get_resource_privileges
from superdesk.errors import SuperdeskApiError
class SearchService(ItemsService):
"""This class wraps the external Items API endpoint implemented by ItemsService but will allow the filtering by
subscriber and the return of aggregates
"""
# Usage is something like :-
# http://localhost:5000/api/search_capi?where={"headline":"muppets"}&start_date=1975-12-31
# &subscribers=558384d31d41c849d9614500
#
# or for all subscribers
# http://localhost:5000/api/search_capi?where={"headline":"muppets"}&start_date=1975-12-31
allowed_params = {
'start_date', 'end_date',
'include_fields', 'exclude_fields',
'max_results', 'page',
'where', 'version',
'subscribers', 'aggregations',
'q', 'default_operator', 'sort', 'filter',
'service', 'subject', 'genre', 'urgency',
'priority', 'type', 'item_source'
}
excluded_fields_from_response = {}
def _filter_empty_vals(self, data):
"""Filter out `None` values from a given dict."""
return dict(filter(lambda x: x[1], data.items()))
def _format_cv_item(self, item):
return self._filter_empty_vals({
'qcode': item.get('code'),
'name': item.get('name'),
})
def _map_response(self, response):
"""
Map the fields names that are changed as part of the ninjs formatting back to the internal values
:param response:
:return:
"""
if not response:
return None
for item in response:
self._map_item(item)
return response
def _map_item(self, item):
"""Maps the associations.
:param dict item:
:return:
"""
if not item:
return
if item.get('service'):
item['anpa_category'] = [self._format_cv_item(item) for item in (item.get('service') or [])]
item.pop('service')
if item.get('subject'):
item['subject'] = [self._format_cv_item(item) for item in (item.get('subject') or [])]
if item.get('genre'):
item['genre'] = [self._format_cv_item(item) for item in (item.get('genre') or [])]
if item.get('place'):
item['place'] = [self._format_cv_item(item) for item in (item.get('place') or [])]
if item.get('signal'):
item['flags'] = {'marked_for_legal': True for signal in item.get('signal')
if signal.get('code') == 'cwarn'}
def find_one(self, req, **lookup):
self.check_get_access_privilege()
response = super().find_one(req, **lookup)
self._map_item(response)
return response
def get(self, req, lookup):
# if there is a subscriber argumment map it into the lookup
self.check_get_access_privilege()
if req and req.args and req.args.get('subscribers'):
lookup = {'subscribers': req.args.get('subscribers')}
g.subscriber = req.args.get('subscribers')
response = super().get(req, lookup)
if response.count() > 0:
return self._map_response(response)
return response
def _process_fetched_object(self, document):
"""Does some processing on the raw document fetched from database.
It sets the item's `uri` field and removes all the fields added by the
`Eve` framework that are not part of the NINJS standard (except for
the HATEOAS `_links` object).
It also sets the URLs for all externally referenced media content.
:param dict document: MongoDB document to process
"""
self._process_item_renditions(document)
self._process_item_associations(document)
self._map_associations(document)
def _map_associations(self, item):
"""Map association response.
:param dict item:
"""
allowed_items = {}
if item.get('associations'):
for k, v in item.get('associations', {}).items():
if v is None:
continue
self._map_item(v)
v['_id'] = v.get('guid', v.get('_id'))
allowed_items[k] = v
item['associations'] = allowed_items
def check_get_access_privilege(self):
"""Checks if user is authorized to perform get operation on search api.
If authorized then request is
forwarded otherwise throws forbidden error.
:raises: SuperdeskApiError.forbiddenError() if user is unauthorized to access the Legal Archive resources.
"""
if not hasattr(g, 'user'):
return
privileges = g.user.get('active_privileges', {})
resource_privileges = get_resource_privileges(self.datasource).get('GET', None)
if privileges.get(resource_privileges, 0) == 0:
raise SuperdeskApiError.forbiddenError()
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
27,
1882,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
17897,
10368,
14,
199,
3,
199,
3,
1898,
6171,
12,
6927,
5800,
4991,
1315,
14,
85,
14,
436,
8417,
14,
199,
3,
199,
3,
2104,
314,
2615,
4248,
436,
4190,
2556,
12,
8749,
1937,
314,
199,
3,
10610,
436,
5113,
1584,
1854,
543,
642,
1350,
1233,
12,
503,
199,
3,
737,
4178,
921,
1544,
14,
1365,
4991,
14,
1308,
15,
4792,
10368,
15,
1682,
199,
199,
504,
1564,
63,
1246,
14,
1744,
14,
1364,
492,
20720,
3167,
199,
504,
7209,
492,
486,
199,
199,
504,
1613,
10368,
492,
664,
63,
1927,
63,
27852,
199,
504,
1613,
10368,
14,
2550,
492,
17897,
10368,
7394,
547,
421,
199,
533,
8730,
3167,
8,
7412,
3167,
304,
272,
408,
2765,
1021,
14018,
314,
5957,
20720,
3261,
6037,
6366,
701,
20720,
3167,
1325,
911,
2040,
314,
14545,
701,
272,
22148,
436,
314,
372,
402,
27535,
272,
408,
339,
327,
11028,
365,
6020,
2839,
22901,
272,
327,
221,
1455,
921,
5967,
26,
13128,
15,
1246,
15,
1733,
63,
14145,
31,
4509,
8871,
11268,
5122,
77,
384,
14582,
3570,
6,
928,
63,
602,
29,
1167,
2194,
13,
713,
13,
2192,
272,
327,
263,
1253,
24962,
29,
1229,
2658,
1349,
68,
2192,
68,
2953,
67,
14866,
68,
2534,
1079,
5783,
272,
327,
272,
327,
259,
503,
367,
1006,
22148,
83,
272,
327,
259,
1455,
921,
5967,
26,
13128,
15,
1246,
15,
1733,
63,
14145,
31,
4509,
8871,
11268,
5122,
77,
384,
14582,
3570,
6,
928,
63,
602,
29,
1167,
2194,
13,
713,
13,
2192,
339,
4370,
63,
1162,
275,
469,
267,
283,
928,
63,
602,
297,
283,
500,
63,
602,
297,
267,
283,
2613,
63,
955,
297,
283,
5473,
63,
955,
297,
267,
283,
988,
63,
2604,
297,
283,
1606,
297,
267,
283,
4509,
297,
283,
1023,
297,
267,
283,
24962,
297,
283,
10978,
1298,
297,
267,
283,
81,
297,
283,
885,
63,
3856,
297,
283,
3191,
297,
283,
1541,
297,
267,
283,
1364,
297,
283,
5875,
297,
283,
23553,
297,
283,
300,
27798,
297,
267,
283,
6693,
297,
283,
466,
297,
283,
1053,
63,
1365,
7,
272,
789,
339,
8789,
63,
955,
63,
504,
63,
1310,
275,
1052,
339,
347,
485,
1541,
63,
1667,
63,
3643,
8,
277,
12,
666,
304,
267,
408,
4131,
734,
658,
403,
64,
1338,
687,
282,
1627,
1211,
1041,
267,
372,
1211,
8,
1541,
8,
2734,
671,
26,
671,
59,
17,
467,
666,
14,
1744,
4059,
339,
347,
485,
908,
63,
5107,
63,
1053,
8,
277,
12,
1242,
304,
267,
372,
291,
423,
1541,
63,
1667,
63,
3643,
2561,
288,
283,
81,
600,
356,
1242,
14,
362,
360,
600,
659,
288,
283,
354,
356,
1242,
14,
362,
360,
354,
659,
267,
3828,
339,
347,
485,
1130,
63,
1310,
8,
277,
12,
1177,
304,
267,
408,
267,
9672,
314,
1504,
1561,
626,
787,
2896,
465,
1777,
402,
314,
302,
262,
3596,
10803,
1771,
370,
314,
5007,
1338,
267,
520,
635,
1177,
26,
267,
520,
1107,
26,
267,
408,
267,
340,
440,
1177,
26,
288,
372,
488,
398,
367,
1242,
315,
1177,
26,
288,
291,
423,
1130,
63,
1053,
8,
1053,
9,
398,
372,
1177,
339,
347,
485,
1130,
63,
1053,
8,
277,
12,
1242,
304,
267,
408,
24995,
314,
4035,
1298,
14,
267,
520,
635,
1211,
1242,
26,
267,
520,
1107,
26,
267,
408,
267,
340,
440,
1242,
26,
288,
372,
398,
340,
1242,
14,
362,
360,
1364,
735,
288,
1242,
459,
290,
387,
63,
3710,
418,
275,
359,
277,
423,
908,
63,
5107,
63,
1053,
8,
1053,
9,
367,
1242,
315,
334,
1053,
14,
362,
360,
1364,
358,
503,
3073,
61,
288,
1242,
14,
1935,
360,
1364,
358,
398,
340,
1242,
14,
362,
360,
5875,
735,
288,
1242,
459,
5875,
418,
275,
359,
277,
423,
908,
63,
5107,
63,
1053,
8,
1053,
9,
367,
1242,
315,
334,
1053,
14,
362,
360,
5875,
358,
503,
3073,
61,
398,
340,
1242,
14,
362,
360,
23553,
735,
288,
1242,
459,
23553,
418,
275,
359,
277,
423,
908,
63,
5107,
63,
1053,
8,
1053,
9,
367,
1242,
315,
334,
1053,
14,
362,
360,
23553,
358,
503,
3073,
61,
398,
340,
1242,
14,
362,
360,
2778,
735,
288,
1242,
459,
2778,
418,
275,
359,
277,
423,
908,
63,
5107,
63,
1053,
8,
1053,
9,
367,
1242,
315,
334,
1053,
14,
362,
360,
2778,
358,
503,
3073,
61,
398,
340,
1242,
14,
362,
360,
4653,
735,
288,
1242,
459,
2469,
418,
275,
791,
17938,
63,
509,
63,
9666,
356,
715,
367,
4673,
315,
1242,
14,
362,
360,
4653,
358,
2490,
340,
4673,
14,
362,
360,
600,
358,
508,
283,
67,
4050,
936,
339,
347,
2342,
63,
368,
8,
277,
12,
2648,
12,
1011,
3892,
304,
267,
291,
14,
1074,
63,
362,
63,
2732,
63,
1359,
17228,
342,
267,
1177,
275,
1613,
1252,
1623,
63,
368,
8,
2103,
12,
1011,
3892,
9,
267,
291,
423,
1130,
63,
1053,
8,
1310,
9,
267,
372,
1177,
339,
347,
664,
8,
277,
12,
2648,
12,
4237,
304,
267,
327,
340,
2337,
365,
282,
22148,
1680,
453,
434,
2341,
652,
1901,
314,
4237,
267,
291,
14,
1074,
63,
362,
63,
2732,
63,
1359,
17228,
342,
267,
340,
2648,
436,
2648,
14,
589,
436,
2648,
14,
589,
14,
362,
360,
24962,
735,
288,
4237,
275,
791,
24962,
356,
2648,
14,
589,
14,
362,
360,
24962,
21004,
288,
486,
14,
17256,
275,
2648,
14,
589,
14,
362,
360,
24962,
358,
398,
1177,
275,
1613,
1252,
362,
8,
2103,
12,
4237,
9,
267,
340,
1177,
14,
835,
342,
690,
378,
26,
288,
372,
291,
423,
1130,
63,
1310,
8,
1310,
9,
267,
372,
1177,
339,
347,
485,
1412,
63,
27236,
63,
785,
8,
277,
12,
2213,
304,
267,
408,
6586,
2005,
6661,
641,
314,
3066,
2213,
19251,
687,
3050,
14,
398,
2779,
5951,
314,
1242,
1159,
658,
2302,
64,
901,
436,
14185,
1006,
314,
1504,
3483,
701,
314,
267,
658,
37,
432,
64,
10059,
626,
787,
440,
1777,
402,
314,
653,
568,
11378,
4465,
334,
2590,
367,
267,
314,
869,
1951,
47,
1179,
18494,
4614,
64,
909,
680,
267,
2779,
2597,
5951,
314,
10867,
367,
1006,
21815,
1183,
11812,
5898,
1564,
14
] |
[
1882,
2803,
26,
2774,
13,
24,
27,
1882,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
17897,
10368,
14,
199,
3,
199,
3,
1898,
6171,
12,
6927,
5800,
4991,
1315,
14,
85,
14,
436,
8417,
14,
199,
3,
199,
3,
2104,
314,
2615,
4248,
436,
4190,
2556,
12,
8749,
1937,
314,
199,
3,
10610,
436,
5113,
1584,
1854,
543,
642,
1350,
1233,
12,
503,
199,
3,
737,
4178,
921,
1544,
14,
1365,
4991,
14,
1308,
15,
4792,
10368,
15,
1682,
199,
199,
504,
1564,
63,
1246,
14,
1744,
14,
1364,
492,
20720,
3167,
199,
504,
7209,
492,
486,
199,
199,
504,
1613,
10368,
492,
664,
63,
1927,
63,
27852,
199,
504,
1613,
10368,
14,
2550,
492,
17897,
10368,
7394,
547,
421,
199,
533,
8730,
3167,
8,
7412,
3167,
304,
272,
408,
2765,
1021,
14018,
314,
5957,
20720,
3261,
6037,
6366,
701,
20720,
3167,
1325,
911,
2040,
314,
14545,
701,
272,
22148,
436,
314,
372,
402,
27535,
272,
408,
339,
327,
11028,
365,
6020,
2839,
22901,
272,
327,
221,
1455,
921,
5967,
26,
13128,
15,
1246,
15,
1733,
63,
14145,
31,
4509,
8871,
11268,
5122,
77,
384,
14582,
3570,
6,
928,
63,
602,
29,
1167,
2194,
13,
713,
13,
2192,
272,
327,
263,
1253,
24962,
29,
1229,
2658,
1349,
68,
2192,
68,
2953,
67,
14866,
68,
2534,
1079,
5783,
272,
327,
272,
327,
259,
503,
367,
1006,
22148,
83,
272,
327,
259,
1455,
921,
5967,
26,
13128,
15,
1246,
15,
1733,
63,
14145,
31,
4509,
8871,
11268,
5122,
77,
384,
14582,
3570,
6,
928,
63,
602,
29,
1167,
2194,
13,
713,
13,
2192,
339,
4370,
63,
1162,
275,
469,
267,
283,
928,
63,
602,
297,
283,
500,
63,
602,
297,
267,
283,
2613,
63,
955,
297,
283,
5473,
63,
955,
297,
267,
283,
988,
63,
2604,
297,
283,
1606,
297,
267,
283,
4509,
297,
283,
1023,
297,
267,
283,
24962,
297,
283,
10978,
1298,
297,
267,
283,
81,
297,
283,
885,
63,
3856,
297,
283,
3191,
297,
283,
1541,
297,
267,
283,
1364,
297,
283,
5875,
297,
283,
23553,
297,
283,
300,
27798,
297,
267,
283,
6693,
297,
283,
466,
297,
283,
1053,
63,
1365,
7,
272,
789,
339,
8789,
63,
955,
63,
504,
63,
1310,
275,
1052,
339,
347,
485,
1541,
63,
1667,
63,
3643,
8,
277,
12,
666,
304,
267,
408,
4131,
734,
658,
403,
64,
1338,
687,
282,
1627,
1211,
1041,
267,
372,
1211,
8,
1541,
8,
2734,
671,
26,
671,
59,
17,
467,
666,
14,
1744,
4059,
339,
347,
485,
908,
63,
5107,
63,
1053,
8,
277,
12,
1242,
304,
267,
372,
291,
423,
1541,
63,
1667,
63,
3643,
2561,
288,
283,
81,
600,
356,
1242,
14,
362,
360,
600,
659,
288,
283,
354,
356,
1242,
14,
362,
360,
354,
659,
267,
3828,
339,
347,
485,
1130,
63,
1310,
8,
277,
12,
1177,
304,
267,
408,
267,
9672,
314,
1504,
1561,
626,
787,
2896,
465,
1777,
402,
314,
302,
262,
3596,
10803,
1771,
370,
314,
5007,
1338,
267,
520,
635,
1177,
26,
267,
520,
1107,
26,
267,
408,
267,
340,
440,
1177,
26,
288,
372,
488,
398,
367,
1242,
315,
1177,
26,
288,
291,
423,
1130,
63,
1053,
8,
1053,
9,
398,
372,
1177,
339,
347,
485,
1130,
63,
1053,
8,
277,
12,
1242,
304,
267,
408,
24995,
314,
4035,
1298,
14,
267,
520,
635,
1211,
1242,
26,
267,
520,
1107,
26,
267,
408,
267,
340,
440,
1242,
26,
288,
372,
398,
340,
1242,
14,
362,
360,
1364,
735,
288,
1242,
459,
290,
387,
63,
3710,
418,
275,
359,
277,
423,
908,
63,
5107,
63,
1053,
8,
1053,
9,
367,
1242,
315,
334,
1053,
14,
362,
360,
1364,
358,
503,
3073,
61,
288,
1242,
14,
1935,
360,
1364,
358,
398,
340,
1242,
14,
362,
360,
5875,
735,
288,
1242,
459,
5875,
418,
275,
359,
277,
423,
908,
63,
5107,
63,
1053,
8,
1053,
9,
367,
1242,
315,
334,
1053,
14,
362,
360,
5875,
358,
503,
3073,
61,
398,
340,
1242,
14,
362,
360,
23553,
735,
288,
1242,
459,
23553,
418,
275,
359,
277,
423,
908,
63,
5107,
63,
1053,
8,
1053,
9,
367,
1242,
315,
334,
1053,
14,
362,
360,
23553,
358,
503,
3073,
61,
398,
340,
1242,
14,
362,
360,
2778,
735,
288,
1242,
459,
2778,
418,
275,
359,
277,
423,
908,
63,
5107,
63,
1053,
8,
1053,
9,
367,
1242,
315,
334,
1053,
14,
362,
360,
2778,
358,
503,
3073,
61,
398,
340,
1242,
14,
362,
360,
4653,
735,
288,
1242,
459,
2469,
418,
275,
791,
17938,
63,
509,
63,
9666,
356,
715,
367,
4673,
315,
1242,
14,
362,
360,
4653,
358,
2490,
340,
4673,
14,
362,
360,
600,
358,
508,
283,
67,
4050,
936,
339,
347,
2342,
63,
368,
8,
277,
12,
2648,
12,
1011,
3892,
304,
267,
291,
14,
1074,
63,
362,
63,
2732,
63,
1359,
17228,
342,
267,
1177,
275,
1613,
1252,
1623,
63,
368,
8,
2103,
12,
1011,
3892,
9,
267,
291,
423,
1130,
63,
1053,
8,
1310,
9,
267,
372,
1177,
339,
347,
664,
8,
277,
12,
2648,
12,
4237,
304,
267,
327,
340,
2337,
365,
282,
22148,
1680,
453,
434,
2341,
652,
1901,
314,
4237,
267,
291,
14,
1074,
63,
362,
63,
2732,
63,
1359,
17228,
342,
267,
340,
2648,
436,
2648,
14,
589,
436,
2648,
14,
589,
14,
362,
360,
24962,
735,
288,
4237,
275,
791,
24962,
356,
2648,
14,
589,
14,
362,
360,
24962,
21004,
288,
486,
14,
17256,
275,
2648,
14,
589,
14,
362,
360,
24962,
358,
398,
1177,
275,
1613,
1252,
362,
8,
2103,
12,
4237,
9,
267,
340,
1177,
14,
835,
342,
690,
378,
26,
288,
372,
291,
423,
1130,
63,
1310,
8,
1310,
9,
267,
372,
1177,
339,
347,
485,
1412,
63,
27236,
63,
785,
8,
277,
12,
2213,
304,
267,
408,
6586,
2005,
6661,
641,
314,
3066,
2213,
19251,
687,
3050,
14,
398,
2779,
5951,
314,
1242,
1159,
658,
2302,
64,
901,
436,
14185,
1006,
314,
1504,
3483,
701,
314,
267,
658,
37,
432,
64,
10059,
626,
787,
440,
1777,
402,
314,
653,
568,
11378,
4465,
334,
2590,
367,
267,
314,
869,
1951,
47,
1179,
18494,
4614,
64,
909,
680,
267,
2779,
2597,
5951,
314,
10867,
367,
1006,
21815,
1183,
11812,
5898,
1564,
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,
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
] |
opennode/nodeconductor-assembly-waldur
|
src/waldur_mastermind/packages/executors.py
|
1
|
4271
|
from waldur_core.core import executors as core_executors
from waldur_core.core import tasks as core_tasks
from waldur_core.core import utils as core_utils
from waldur_core.structure import executors as structure_executors
from waldur_mastermind.packages.serializers import _get_template_quotas
from waldur_openstack.openstack import executors as openstack_executors
from . import tasks
class OpenStackPackageCreateExecutor(core_executors.BaseExecutor):
@classmethod
def get_task_signature(cls, package, serialized_package, **kwargs):
tenant = package.tenant
serialized_tenant = core_utils.serialize_instance(tenant)
service_settings = package.service_settings
serialized_service_settings = core_utils.serialize_instance(service_settings)
create_tenant = openstack_executors.TenantCreateExecutor.get_task_signature(
tenant, serialized_tenant, **kwargs
)
set_tenant_ok = openstack_executors.TenantCreateExecutor.get_success_signature(
tenant, serialized_tenant
)
populate_service_settings = tasks.OpenStackPackageSettingsPopulationTask().si(
serialized_package
)
create_service_settings = structure_executors.ServiceSettingsCreateExecutor.get_task_signature(
service_settings, serialized_service_settings
)
return (
create_tenant
| set_tenant_ok
| populate_service_settings
| create_service_settings
)
@classmethod
def get_success_signature(cls, package, serialized_package, **kwargs):
""" Get Celery signature of task that should be applied on successful execution. """
service_settings = package.service_settings
serialized_service_settings = core_utils.serialize_instance(service_settings)
return core_tasks.StateTransitionTask().si(
serialized_service_settings, state_transition='set_ok'
)
@classmethod
def get_failure_signature(cls, package, serialized_package, **kwargs):
return tasks.OpenStackPackageErrorTask().s(serialized_package)
class OpenStackPackageChangeExecutor(core_executors.BaseExecutor):
@classmethod
def get_success_signature(
cls,
tenant,
serialized_tenant,
new_template,
old_package,
service_settings,
**kwargs
):
service_settings = core_utils.serialize_instance(service_settings)
return tasks.LogOpenStackPackageChange().si(
serialized_tenant,
event='succeeded',
new_package=new_template.name,
old_package=old_package.template.name,
service_settings=service_settings,
)
@classmethod
def get_failure_signature(
cls,
tenant,
serialized_tenant,
new_template,
old_package,
service_settings,
**kwargs
):
service_settings = core_utils.serialize_instance(service_settings)
return tasks.LogOpenStackPackageChange().si(
serialized_tenant,
event='failed',
new_package=new_template.name,
old_package=old_package.template.name,
service_settings=service_settings,
)
@classmethod
def get_task_signature(
cls,
tenant,
serialized_tenant,
new_template,
old_package,
service_settings,
**kwargs
):
quotas = {
quota_field.name: value
for quota_field, value in _get_template_quotas(new_template).items()
}
push_quotas = openstack_executors.TenantPushQuotasExecutor.as_signature(
tenant, quotas=quotas
)
serialized_new_template = core_utils.serialize_instance(new_template)
serialized_old_package = core_utils.serialize_instance(old_package)
serialized_service_settings = core_utils.serialize_instance(service_settings)
success_package_change = tasks.OpenStackPackageSuccessTask().si(
serialized_tenant,
serialized_new_template,
serialized_old_package,
serialized_service_settings,
)
return push_quotas | success_package_change
|
mit
|
[
504,
336,
27075,
300,
63,
1018,
14,
1018,
492,
2146,
6622,
465,
6170,
63,
1628,
6622,
199,
504,
336,
27075,
300,
63,
1018,
14,
1018,
492,
6527,
465,
6170,
63,
5054,
199,
504,
336,
27075,
300,
63,
1018,
14,
1018,
492,
3778,
465,
6170,
63,
1208,
199,
504,
336,
27075,
300,
63,
1018,
14,
6976,
492,
2146,
6622,
465,
5523,
63,
1628,
6622,
199,
504,
336,
27075,
300,
63,
4133,
77,
688,
14,
5154,
14,
12844,
492,
485,
362,
63,
1160,
63,
17056,
199,
504,
336,
27075,
300,
63,
8512,
14,
8512,
492,
2146,
6622,
465,
13869,
63,
1628,
6622,
199,
199,
504,
1275,
492,
6527,
421,
199,
533,
14260,
8599,
2499,
16752,
8,
1018,
63,
1628,
6622,
14,
1563,
16752,
304,
272,
768,
3744,
272,
347,
664,
63,
1765,
63,
5233,
8,
1886,
12,
2559,
12,
6380,
63,
2491,
12,
1011,
958,
304,
267,
8261,
275,
2559,
14,
4647,
267,
6380,
63,
4647,
275,
6170,
63,
1208,
14,
3549,
63,
842,
8,
4647,
9,
267,
2435,
63,
1751,
275,
2559,
14,
1364,
63,
1751,
267,
6380,
63,
1364,
63,
1751,
275,
6170,
63,
1208,
14,
3549,
63,
842,
8,
1364,
63,
1751,
9,
398,
1218,
63,
4647,
275,
13869,
63,
1628,
6622,
14,
27807,
2499,
16752,
14,
362,
63,
1765,
63,
5233,
8,
288,
8261,
12,
6380,
63,
4647,
12,
1011,
958,
267,
776,
267,
663,
63,
4647,
63,
745,
275,
13869,
63,
1628,
6622,
14,
27807,
2499,
16752,
14,
362,
63,
3742,
63,
5233,
8,
288,
8261,
12,
6380,
63,
4647,
267,
776,
398,
13904,
63,
1364,
63,
1751,
275,
6527,
14,
26208,
8599,
5268,
31824,
4476,
1252,
338,
8,
288,
6380,
63,
2491,
267,
776,
398,
1218,
63,
1364,
63,
1751,
275,
5523,
63,
1628,
6622,
14,
3167,
5268,
2499,
16752,
14,
362,
63,
1765,
63,
5233,
8,
288,
2435,
63,
1751,
12,
6380,
63,
1364,
63,
1751,
267,
776,
398,
372,
334,
288,
1218,
63,
4647,
288,
1204,
663,
63,
4647,
63,
745,
288,
1204,
13904,
63,
1364,
63,
1751,
288,
1204,
1218,
63,
1364,
63,
1751,
267,
776,
339,
768,
3744,
272,
347,
664,
63,
3742,
63,
5233,
8,
1886,
12,
2559,
12,
6380,
63,
2491,
12,
1011,
958,
304,
267,
408,
2372,
445,
19028,
4955,
402,
2120,
626,
1077,
506,
6781,
641,
9512,
6451,
14,
408,
267,
2435,
63,
1751,
275,
2559,
14,
1364,
63,
1751,
267,
6380,
63,
1364,
63,
1751,
275,
6170,
63,
1208,
14,
3549,
63,
842,
8,
1364,
63,
1751,
9,
267,
372,
6170,
63,
5054,
14,
2223,
21881,
4476,
1252,
338,
8,
288,
6380,
63,
1364,
63,
1751,
12,
1174,
63,
14143,
534,
409,
63,
745,
7,
267,
776,
339,
768,
3744,
272,
347,
664,
63,
5328,
63,
5233,
8,
1886,
12,
2559,
12,
6380,
63,
2491,
12,
1011,
958,
304,
267,
372,
6527,
14,
26208,
8599,
547,
4476,
1252,
83,
8,
8397,
63,
2491,
9,
421,
199,
533,
14260,
8599,
4001,
16752,
8,
1018,
63,
1628,
6622,
14,
1563,
16752,
304,
272,
768,
3744,
272,
347,
664,
63,
3742,
63,
5233,
8,
267,
843,
12,
267,
8261,
12,
267,
6380,
63,
4647,
12,
267,
892,
63,
1160,
12,
267,
2269,
63,
2491,
12,
267,
2435,
63,
1751,
12,
267,
1011,
958,
272,
3461,
267,
2435,
63,
1751,
275,
6170,
63,
1208,
14,
3549,
63,
842,
8,
1364,
63,
1751,
9,
267,
372,
6527,
14,
2445,
26208,
8599,
4001,
1252,
338,
8,
288,
6380,
63,
4647,
12,
288,
1566,
534,
20003,
297,
288,
892,
63,
2491,
29,
1222,
63,
1160,
14,
354,
12,
288,
2269,
63,
2491,
29,
1753,
63,
2491,
14,
1160,
14,
354,
12,
288,
2435,
63,
1751,
29,
1364,
63,
1751,
12,
267,
776,
339,
768,
3744,
272,
347,
664,
63,
5328,
63,
5233,
8,
267,
843,
12,
267,
8261,
12,
267,
6380,
63,
4647,
12,
267,
892,
63,
1160,
12,
267,
2269,
63,
2491,
12,
267,
2435,
63,
1751,
12,
267,
1011,
958,
272,
3461,
267,
2435,
63,
1751,
275,
6170,
63,
1208,
14,
3549,
63,
842,
8,
1364,
63,
1751,
9,
267,
372,
6527,
14,
2445,
26208,
8599,
4001,
1252,
338,
8,
288,
6380,
63,
4647,
12,
288,
1566,
534,
4892,
297,
288,
892,
63,
2491,
29,
1222,
63,
1160,
14,
354,
12,
288,
2269,
63,
2491,
29,
1753,
63,
2491,
14,
1160,
14,
354,
12,
288,
2435,
63,
1751,
29,
1364,
63,
1751,
12,
267,
776,
339,
768,
3744,
272,
347,
664,
63,
1765,
63,
5233,
8,
267,
843,
12,
267,
8261,
12,
267,
6380,
63,
4647,
12,
267,
892,
63,
1160,
12,
267,
2269,
63,
2491,
12,
267,
2435,
63,
1751,
12,
267,
1011,
958,
272,
3461,
267,
22874,
275,
469,
288,
12132,
63,
698,
14,
354,
26,
574,
288,
367,
12132,
63,
698,
12,
574,
315,
485,
362,
63,
1160,
63,
17056,
8,
1222,
63,
1160,
680,
1744,
342,
267,
789,
267,
6675,
63,
17056,
275,
13869,
63,
1628,
6622,
14,
27807,
10731,
2371,
357,
305,
16752,
14,
305,
63,
5233,
8,
288,
8261,
12,
22874,
29,
17056,
267,
776,
398,
6380,
63,
1222,
63,
1160,
275,
6170,
63,
1208,
14,
3549,
63,
842,
8,
1222,
63,
1160,
9,
267,
6380,
63,
1753,
63,
2491,
275,
6170,
63,
1208,
14,
3549,
63,
842,
8,
1753,
63,
2491,
9,
267,
6380,
63,
1364,
63,
1751,
275,
6170,
63,
1208,
14,
3549,
63,
842,
8,
1364,
63,
1751,
9,
398,
3182,
63,
2491,
63,
1461,
275,
6527,
14,
26208,
8599,
8300,
4476,
1252,
338,
8,
288,
6380,
63,
4647,
12,
288,
6380,
63,
1222,
63,
1160,
12,
288,
6380,
63,
1753,
63,
2491,
12,
288,
6380,
63,
1364,
63,
1751,
12,
267,
776,
267,
372,
6675,
63,
17056,
1204,
3182,
63,
2491,
63,
1461,
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
] |
[
336,
27075,
300,
63,
1018,
14,
1018,
492,
2146,
6622,
465,
6170,
63,
1628,
6622,
199,
504,
336,
27075,
300,
63,
1018,
14,
1018,
492,
6527,
465,
6170,
63,
5054,
199,
504,
336,
27075,
300,
63,
1018,
14,
1018,
492,
3778,
465,
6170,
63,
1208,
199,
504,
336,
27075,
300,
63,
1018,
14,
6976,
492,
2146,
6622,
465,
5523,
63,
1628,
6622,
199,
504,
336,
27075,
300,
63,
4133,
77,
688,
14,
5154,
14,
12844,
492,
485,
362,
63,
1160,
63,
17056,
199,
504,
336,
27075,
300,
63,
8512,
14,
8512,
492,
2146,
6622,
465,
13869,
63,
1628,
6622,
199,
199,
504,
1275,
492,
6527,
421,
199,
533,
14260,
8599,
2499,
16752,
8,
1018,
63,
1628,
6622,
14,
1563,
16752,
304,
272,
768,
3744,
272,
347,
664,
63,
1765,
63,
5233,
8,
1886,
12,
2559,
12,
6380,
63,
2491,
12,
1011,
958,
304,
267,
8261,
275,
2559,
14,
4647,
267,
6380,
63,
4647,
275,
6170,
63,
1208,
14,
3549,
63,
842,
8,
4647,
9,
267,
2435,
63,
1751,
275,
2559,
14,
1364,
63,
1751,
267,
6380,
63,
1364,
63,
1751,
275,
6170,
63,
1208,
14,
3549,
63,
842,
8,
1364,
63,
1751,
9,
398,
1218,
63,
4647,
275,
13869,
63,
1628,
6622,
14,
27807,
2499,
16752,
14,
362,
63,
1765,
63,
5233,
8,
288,
8261,
12,
6380,
63,
4647,
12,
1011,
958,
267,
776,
267,
663,
63,
4647,
63,
745,
275,
13869,
63,
1628,
6622,
14,
27807,
2499,
16752,
14,
362,
63,
3742,
63,
5233,
8,
288,
8261,
12,
6380,
63,
4647,
267,
776,
398,
13904,
63,
1364,
63,
1751,
275,
6527,
14,
26208,
8599,
5268,
31824,
4476,
1252,
338,
8,
288,
6380,
63,
2491,
267,
776,
398,
1218,
63,
1364,
63,
1751,
275,
5523,
63,
1628,
6622,
14,
3167,
5268,
2499,
16752,
14,
362,
63,
1765,
63,
5233,
8,
288,
2435,
63,
1751,
12,
6380,
63,
1364,
63,
1751,
267,
776,
398,
372,
334,
288,
1218,
63,
4647,
288,
1204,
663,
63,
4647,
63,
745,
288,
1204,
13904,
63,
1364,
63,
1751,
288,
1204,
1218,
63,
1364,
63,
1751,
267,
776,
339,
768,
3744,
272,
347,
664,
63,
3742,
63,
5233,
8,
1886,
12,
2559,
12,
6380,
63,
2491,
12,
1011,
958,
304,
267,
408,
2372,
445,
19028,
4955,
402,
2120,
626,
1077,
506,
6781,
641,
9512,
6451,
14,
408,
267,
2435,
63,
1751,
275,
2559,
14,
1364,
63,
1751,
267,
6380,
63,
1364,
63,
1751,
275,
6170,
63,
1208,
14,
3549,
63,
842,
8,
1364,
63,
1751,
9,
267,
372,
6170,
63,
5054,
14,
2223,
21881,
4476,
1252,
338,
8,
288,
6380,
63,
1364,
63,
1751,
12,
1174,
63,
14143,
534,
409,
63,
745,
7,
267,
776,
339,
768,
3744,
272,
347,
664,
63,
5328,
63,
5233,
8,
1886,
12,
2559,
12,
6380,
63,
2491,
12,
1011,
958,
304,
267,
372,
6527,
14,
26208,
8599,
547,
4476,
1252,
83,
8,
8397,
63,
2491,
9,
421,
199,
533,
14260,
8599,
4001,
16752,
8,
1018,
63,
1628,
6622,
14,
1563,
16752,
304,
272,
768,
3744,
272,
347,
664,
63,
3742,
63,
5233,
8,
267,
843,
12,
267,
8261,
12,
267,
6380,
63,
4647,
12,
267,
892,
63,
1160,
12,
267,
2269,
63,
2491,
12,
267,
2435,
63,
1751,
12,
267,
1011,
958,
272,
3461,
267,
2435,
63,
1751,
275,
6170,
63,
1208,
14,
3549,
63,
842,
8,
1364,
63,
1751,
9,
267,
372,
6527,
14,
2445,
26208,
8599,
4001,
1252,
338,
8,
288,
6380,
63,
4647,
12,
288,
1566,
534,
20003,
297,
288,
892,
63,
2491,
29,
1222,
63,
1160,
14,
354,
12,
288,
2269,
63,
2491,
29,
1753,
63,
2491,
14,
1160,
14,
354,
12,
288,
2435,
63,
1751,
29,
1364,
63,
1751,
12,
267,
776,
339,
768,
3744,
272,
347,
664,
63,
5328,
63,
5233,
8,
267,
843,
12,
267,
8261,
12,
267,
6380,
63,
4647,
12,
267,
892,
63,
1160,
12,
267,
2269,
63,
2491,
12,
267,
2435,
63,
1751,
12,
267,
1011,
958,
272,
3461,
267,
2435,
63,
1751,
275,
6170,
63,
1208,
14,
3549,
63,
842,
8,
1364,
63,
1751,
9,
267,
372,
6527,
14,
2445,
26208,
8599,
4001,
1252,
338,
8,
288,
6380,
63,
4647,
12,
288,
1566,
534,
4892,
297,
288,
892,
63,
2491,
29,
1222,
63,
1160,
14,
354,
12,
288,
2269,
63,
2491,
29,
1753,
63,
2491,
14,
1160,
14,
354,
12,
288,
2435,
63,
1751,
29,
1364,
63,
1751,
12,
267,
776,
339,
768,
3744,
272,
347,
664,
63,
1765,
63,
5233,
8,
267,
843,
12,
267,
8261,
12,
267,
6380,
63,
4647,
12,
267,
892,
63,
1160,
12,
267,
2269,
63,
2491,
12,
267,
2435,
63,
1751,
12,
267,
1011,
958,
272,
3461,
267,
22874,
275,
469,
288,
12132,
63,
698,
14,
354,
26,
574,
288,
367,
12132,
63,
698,
12,
574,
315,
485,
362,
63,
1160,
63,
17056,
8,
1222,
63,
1160,
680,
1744,
342,
267,
789,
267,
6675,
63,
17056,
275,
13869,
63,
1628,
6622,
14,
27807,
10731,
2371,
357,
305,
16752,
14,
305,
63,
5233,
8,
288,
8261,
12,
22874,
29,
17056,
267,
776,
398,
6380,
63,
1222,
63,
1160,
275,
6170,
63,
1208,
14,
3549,
63,
842,
8,
1222,
63,
1160,
9,
267,
6380,
63,
1753,
63,
2491,
275,
6170,
63,
1208,
14,
3549,
63,
842,
8,
1753,
63,
2491,
9,
267,
6380,
63,
1364,
63,
1751,
275,
6170,
63,
1208,
14,
3549,
63,
842,
8,
1364,
63,
1751,
9,
398,
3182,
63,
2491,
63,
1461,
275,
6527,
14,
26208,
8599,
8300,
4476,
1252,
338,
8,
288,
6380,
63,
4647,
12,
288,
6380,
63,
1222,
63,
1160,
12,
288,
6380,
63,
1753,
63,
2491,
12,
288,
6380,
63,
1364,
63,
1751,
12,
267,
776,
267,
372,
6675,
63,
17056,
1204,
3182,
63,
2491,
63,
1461,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
synapse-wireless/bulk-reprogramming
|
snappyImages/synapse/hexFunctions.py
|
1
|
1980
|
# Copyright (C) 2013 Synapse Wireless, Inc.
# Subject to your agreement of the disclaimer set forth below, permission is given by
# Synapse Wireless, Inc. ("Synapse") to you to freely modify, redistribute or include
# this SNAPpy code in any program. The purpose of this code is to help you understand
# and learn about SNAPpy by code examples.
# BY USING ALL OR ANY PORTION OF THIS SNAPPY CODE, YOU ACCEPT AND AGREE TO THE BELOW
# DISCLAIMER. If you do not accept or agree to the below disclaimer, then you may not
# use, modify, or distribute this SNAPpy code.
# THE CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY OF
# ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES
# THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR
# PURPOSE OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
# COVERED CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT,
# YOU (NOT THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY
# NECESSARY SERVICING, REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES WILL SYNAPSE BE
# LIABLE TO YOU, OR ANY OTHER PERSON OR ENTITY, FOR ANY LOSS OF USE, REVENUE OR
# PROFIT, LOST OR DAMAGED DATA, OR OTHER COMMERCIAL OR ECONOMIC LOSS OR FOR ANY
# DAMAGES WHATSOEVER RELATED TO YOUR USE OR RELIANCE UPON THE SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGES OR IF SUCH DAMAGES ARE FORESEEABLE. THIS
# DISCLAIMER OF WARRANTY AND LIABILITY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
# NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER THIS DISCLAIMER.
"""Hex Functions."""
def hexNibble(nibble):
''' Convert a numeric nibble 0x0-0xF to the ASCII string "0"-"F" '''
hexStr = "0123456789ABCDEF"
return hexStr[nibble & 0xF]
def hexByte(byte):
''' print a byte in hex - input is an integer, not a string; returns a string '''
return hexNibble(byte >> 4) + hexNibble(byte)
|
apache-2.0
|
[
3,
1898,
334,
35,
9,
6171,
29988,
19111,
644,
3621,
2003,
12,
3277,
14,
199,
3,
26793,
370,
2195,
25025,
402,
314,
6450,
663,
367,
273,
5084,
12,
4983,
365,
1627,
701,
199,
3,
29988,
19111,
644,
3621,
2003,
12,
3277,
14,
1689,
17746,
19111,
531,
370,
1265,
370,
20673,
7742,
2811,
12,
3604,
503,
2387,
199,
3,
642,
428,
46,
1282,
647,
1233,
315,
1263,
2240,
14,
710,
12016,
402,
642,
1233,
365,
370,
1720,
1265,
20647,
199,
3,
436,
12537,
3595,
428,
46,
1282,
647,
701,
1233,
7251,
14,
199,
3,
6515,
32210,
11727,
1549,
1821,
25562,
1075,
1634,
5749,
428,
46,
1282,
4521,
22547,
12,
1488,
22050,
28538,
2401,
26787,
5271,
2296,
2334,
6262,
5896,
199,
3,
8990,
540,
14,
982,
1265,
886,
440,
4729,
503,
10601,
370,
314,
5084,
6450,
12,
2066,
1265,
1443,
440,
199,
3,
675,
12,
2811,
12,
503,
11207,
642,
428,
46,
1282,
647,
1233,
14,
199,
3,
2334,
22547,
2281,
7049,
6778,
11733,
5749,
5113,
5258,
1261,
298,
1179,
2281,
2,
4207,
12,
2428,
3408,
1634,
199,
3,
1821,
3826,
12,
662,
1571,
540,
3651,
14956,
10934,
1549,
5292,
12,
6931,
12,
2428,
5138,
2594,
12,
2990,
199,
3,
4221,
619,
2334,
5099,
2111,
1149,
22547,
2281,
481,
5271,
1634,
23566,
3582,
51,
12,
3121,
2617,
12,
481,
649,
2381,
437,
3115,
199,
3,
3104,
1549,
11214,
13,
568,
12559,
1206,
14,
2334,
5070,
13247,
907,
820,
22481,
4319,
2296,
2334,
7813,
748,
1922,
2401,
13873,
30340,
1634,
2334,
199,
3,
5099,
2111,
1149,
22547,
2281,
1663,
1488,
22050,
14,
428,
31909,
1821,
5099,
2111,
1149,
22547,
3611,
2524,
23566,
3582,
5399,
1621,
1821,
12565,
11401,
12,
199,
3,
1488,
22050,
334,
4609,
2334,
26105,
3265,
2524,
1484,
4227,
1549,
1821,
5010,
4432,
5406,
726,
9,
17567,
13847,
2334,
5099,
840,
1634,
1821,
199,
3,
653,
4220,
1608,
4392,
7017,
54,
948,
1206,
12,
5363,
28263,
1549,
18886,
4168,
1075,
14,
6778,
11733,
4825,
9003,
5497,
840,
879,
16734,
644,
14961,
10046,
46,
1282,
899,
6262,
199,
3,
7024,
2296,
1488,
22050,
12,
1549,
1821,
5010,
13873,
3377,
1549,
32526,
1922,
12,
2381,
1821,
9102,
1634,
4815,
12,
5363,
8253,
4187,
1549,
199,
3,
3611,
38,
649,
12,
3412,
840,
1549,
5179,
1254,
1149,
7126,
12,
1549,
5010,
31457,
1549,
662,
1864,
7474,
948,
9102,
1549,
2381,
1821,
199,
3,
6736,
28752,
4118,
27362,
820,
2901,
6989,
2296,
1488,
11237,
4815,
1549,
5363,
2673,
7140,
7215,
615,
2334,
4141,
12,
9704,
8036,
199,
3,
9691,
1634,
2334,
9726,
1634,
9712,
6736,
1549,
8036,
9712,
6736,
9315,
2381,
654,
8699,
2617,
14,
5749,
199,
3,
8990,
540,
1634,
3408,
2401,
5603,
1868,
8821,
934,
654,
1261,
221,
1608,
8246,
3076,
1634,
5749,
5113,
14,
199,
3,
4825,
4815,
1634,
1821,
5099,
2111,
1149,
22547,
2281,
7560,
7123,
1149,
869,
28106,
6131,
540,
3651,
7177,
6778,
11733,
5749,
8990,
540,
14,
199,
199,
624,
10373,
17471,
1041,
421,
199,
318,
6318,
46,
30012,
8,
78,
30012,
304,
272,
1449,
7905,
282,
8950,
302,
30012,
378,
88,
16,
13,
16,
6287,
370,
314,
10485,
1059,
298,
16,
2,
23245,
38,
2,
1449,
272,
6318,
2848,
275,
298,
11371,
18820,
2,
272,
372,
6318,
2848,
59,
78,
30012,
1253,
378,
6287,
61,
421,
199,
318,
6318,
4861,
8,
4414,
304,
272,
1449,
870,
282,
3696,
315,
6318,
446,
1324,
365,
376,
3000,
12,
440,
282,
1059,
27,
2529,
282,
1059,
1449,
272,
372,
6318,
46,
30012,
8,
4414,
4331,
841,
9,
435,
6318,
46,
30012,
8,
4414,
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
] |
[
1898,
334,
35,
9,
6171,
29988,
19111,
644,
3621,
2003,
12,
3277,
14,
199,
3,
26793,
370,
2195,
25025,
402,
314,
6450,
663,
367,
273,
5084,
12,
4983,
365,
1627,
701,
199,
3,
29988,
19111,
644,
3621,
2003,
12,
3277,
14,
1689,
17746,
19111,
531,
370,
1265,
370,
20673,
7742,
2811,
12,
3604,
503,
2387,
199,
3,
642,
428,
46,
1282,
647,
1233,
315,
1263,
2240,
14,
710,
12016,
402,
642,
1233,
365,
370,
1720,
1265,
20647,
199,
3,
436,
12537,
3595,
428,
46,
1282,
647,
701,
1233,
7251,
14,
199,
3,
6515,
32210,
11727,
1549,
1821,
25562,
1075,
1634,
5749,
428,
46,
1282,
4521,
22547,
12,
1488,
22050,
28538,
2401,
26787,
5271,
2296,
2334,
6262,
5896,
199,
3,
8990,
540,
14,
982,
1265,
886,
440,
4729,
503,
10601,
370,
314,
5084,
6450,
12,
2066,
1265,
1443,
440,
199,
3,
675,
12,
2811,
12,
503,
11207,
642,
428,
46,
1282,
647,
1233,
14,
199,
3,
2334,
22547,
2281,
7049,
6778,
11733,
5749,
5113,
5258,
1261,
298,
1179,
2281,
2,
4207,
12,
2428,
3408,
1634,
199,
3,
1821,
3826,
12,
662,
1571,
540,
3651,
14956,
10934,
1549,
5292,
12,
6931,
12,
2428,
5138,
2594,
12,
2990,
199,
3,
4221,
619,
2334,
5099,
2111,
1149,
22547,
2281,
481,
5271,
1634,
23566,
3582,
51,
12,
3121,
2617,
12,
481,
649,
2381,
437,
3115,
199,
3,
3104,
1549,
11214,
13,
568,
12559,
1206,
14,
2334,
5070,
13247,
907,
820,
22481,
4319,
2296,
2334,
7813,
748,
1922,
2401,
13873,
30340,
1634,
2334,
199,
3,
5099,
2111,
1149,
22547,
2281,
1663,
1488,
22050,
14,
428,
31909,
1821,
5099,
2111,
1149,
22547,
3611,
2524,
23566,
3582,
5399,
1621,
1821,
12565,
11401,
12,
199,
3,
1488,
22050,
334,
4609,
2334,
26105,
3265,
2524,
1484,
4227,
1549,
1821,
5010,
4432,
5406,
726,
9,
17567,
13847,
2334,
5099,
840,
1634,
1821,
199,
3,
653,
4220,
1608,
4392,
7017,
54,
948,
1206,
12,
5363,
28263,
1549,
18886,
4168,
1075,
14,
6778,
11733,
4825,
9003,
5497,
840,
879,
16734,
644,
14961,
10046,
46,
1282,
899,
6262,
199,
3,
7024,
2296,
1488,
22050,
12,
1549,
1821,
5010,
13873,
3377,
1549,
32526,
1922,
12,
2381,
1821,
9102,
1634,
4815,
12,
5363,
8253,
4187,
1549,
199,
3,
3611,
38,
649,
12,
3412,
840,
1549,
5179,
1254,
1149,
7126,
12,
1549,
5010,
31457,
1549,
662,
1864,
7474,
948,
9102,
1549,
2381,
1821,
199,
3,
6736,
28752,
4118,
27362,
820,
2901,
6989,
2296,
1488,
11237,
4815,
1549,
5363,
2673,
7140,
7215,
615,
2334,
4141,
12,
9704,
8036,
199,
3,
9691,
1634,
2334,
9726,
1634,
9712,
6736,
1549,
8036,
9712,
6736,
9315,
2381,
654,
8699,
2617,
14,
5749,
199,
3,
8990,
540,
1634,
3408,
2401,
5603,
1868,
8821,
934,
654,
1261,
221,
1608,
8246,
3076,
1634,
5749,
5113,
14,
199,
3,
4825,
4815,
1634,
1821,
5099,
2111,
1149,
22547,
2281,
7560,
7123,
1149,
869,
28106,
6131,
540,
3651,
7177,
6778,
11733,
5749,
8990,
540,
14,
199,
199,
624,
10373,
17471,
1041,
421,
199,
318,
6318,
46,
30012,
8,
78,
30012,
304,
272,
1449,
7905,
282,
8950,
302,
30012,
378,
88,
16,
13,
16,
6287,
370,
314,
10485,
1059,
298,
16,
2,
23245,
38,
2,
1449,
272,
6318,
2848,
275,
298,
11371,
18820,
2,
272,
372,
6318,
2848,
59,
78,
30012,
1253,
378,
6287,
61,
421,
199,
318,
6318,
4861,
8,
4414,
304,
272,
1449,
870,
282,
3696,
315,
6318,
446,
1324,
365,
376,
3000,
12,
440,
282,
1059,
27,
2529,
282,
1059,
1449,
272,
372,
6318,
46,
30012,
8,
4414,
4331,
841,
9,
435,
6318,
46,
30012,
8,
4414,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
NeovaHealth/odoo
|
addons/association/__openerp__.py
|
260
|
1700
|
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
{
'name': 'Associations Management',
'version': '0.1',
'category': 'Specific Industry Applications',
'description': """
This module is to configure modules related to an association.
==============================================================
It installs the profile for associations to manage events, registrations, memberships,
membership products (schemes).
""",
'author': 'OpenERP SA',
'depends': ['base_setup', 'membership', 'event'],
'data': ['security/ir.model.access.csv', 'profile_association.xml'],
'demo': [],
'installable': True,
'auto_install': False,
'website': 'https://www.odoo.com'
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
421,
199,
91,
272,
283,
354,
356,
283,
14889,
1298,
8259,
297,
272,
283,
1023,
356,
283,
16,
14,
17,
297,
272,
283,
3710,
356,
283,
16786,
473,
977,
11409,
89,
24636,
297,
272,
283,
1802,
356,
408,
199,
2765,
859,
365,
370,
7908,
4621,
4048,
370,
376,
20640,
14,
199,
12813,
17224,
199,
199,
7940,
25801,
314,
4690,
367,
4035,
1298,
370,
9635,
4474,
12,
25483,
3801,
12,
14616,
83,
12,
221,
199,
13105,
7585,
334,
26818,
680,
272,
10327,
272,
283,
2502,
356,
283,
25347,
13950,
297,
272,
283,
8912,
356,
788,
1095,
63,
2758,
297,
283,
13105,
297,
283,
1430,
995,
272,
283,
576,
356,
788,
4416,
15,
723,
14,
1238,
14,
2732,
14,
4737,
297,
283,
2913,
63,
20252,
14,
1652,
995,
272,
283,
8768,
356,
990,
272,
283,
21762,
356,
715,
12,
272,
283,
2495,
63,
3174,
356,
756,
12,
272,
283,
7360,
356,
283,
2859,
921,
1544,
14,
22058,
14,
957,
7,
199,
93,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
421,
199,
91,
272,
283,
354,
356,
283,
14889,
1298,
8259,
297,
272,
283,
1023,
356,
283,
16,
14,
17,
297,
272,
283,
3710,
356,
283,
16786,
473,
977,
11409,
89,
24636,
297,
272,
283,
1802,
356,
408,
199,
2765,
859,
365,
370,
7908,
4621,
4048,
370,
376,
20640,
14,
199,
12813,
17224,
199,
199,
7940,
25801,
314,
4690,
367,
4035,
1298,
370,
9635,
4474,
12,
25483,
3801,
12,
14616,
83,
12,
221,
199,
13105,
7585,
334,
26818,
680,
272,
10327,
272,
283,
2502,
356,
283,
25347,
13950,
297,
272,
283,
8912,
356,
788,
1095,
63,
2758,
297,
283,
13105,
297,
283,
1430,
995,
272,
283,
576,
356,
788,
4416,
15,
723,
14,
1238,
14,
2732,
14,
4737,
297,
283,
2913,
63,
20252,
14,
1652,
995,
272,
283,
8768,
356,
990,
272,
283,
21762,
356,
715,
12,
272,
283,
2495,
63,
3174,
356,
756,
12,
272,
283,
7360,
356,
283,
2859,
921,
1544,
14,
22058,
14,
957,
7,
199,
93,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
iEngage/python-sdk
|
iengage_client/models/tag.py
|
1
|
3896
|
# coding: utf-8
"""
Stakeholder engagement API
This API enables Intelligent Engagement for your Business. iEngage is a platform that combines process, augmented intelligence and rewards to help you intelligently engage customers.
OpenAPI spec version: 1.0
Generated by: https://github.com/swagger-api/swagger-codegen.git
"""
from pprint import pformat
from six import iteritems
import re
class Tag(object):
"""
NOTE: This class is auto generated by the swagger code generator program.
Do not edit the class manually.
"""
def __init__(self, tag_id=None, tag_name=None, count=None):
"""
Tag - a model defined in Swagger
:param dict swaggerTypes: The key is attribute name
and the value is attribute type.
:param dict attributeMap: The key is attribute name
and the value is json key in definition.
"""
self.swagger_types = {
'tag_id': 'int',
'tag_name': 'str',
'count': 'int'
}
self.attribute_map = {
'tag_id': 'tagId',
'tag_name': 'tagName',
'count': 'count'
}
self._tag_id = tag_id
self._tag_name = tag_name
self._count = count
@property
def tag_id(self):
"""
Gets the tag_id of this Tag.
:return: The tag_id of this Tag.
:rtype: int
"""
return self._tag_id
@tag_id.setter
def tag_id(self, tag_id):
"""
Sets the tag_id of this Tag.
:param tag_id: The tag_id of this Tag.
:type: int
"""
self._tag_id = tag_id
@property
def tag_name(self):
"""
Gets the tag_name of this Tag.
:return: The tag_name of this Tag.
:rtype: str
"""
return self._tag_name
@tag_name.setter
def tag_name(self, tag_name):
"""
Sets the tag_name of this Tag.
:param tag_name: The tag_name of this Tag.
:type: str
"""
self._tag_name = tag_name
@property
def count(self):
"""
Gets the count of this Tag.
:return: The count of this Tag.
:rtype: int
"""
return self._count
@count.setter
def count(self, count):
"""
Sets the count of this Tag.
:param count: The count of this Tag.
:type: int
"""
self._count = count
def to_dict(self):
"""
Returns the model properties as a dict
"""
result = {}
for attr, _ in iteritems(self.swagger_types):
value = getattr(self, attr)
if isinstance(value, list):
result[attr] = list(map(
lambda x: x.to_dict() if hasattr(x, "to_dict") else x,
value
))
elif hasattr(value, "to_dict"):
result[attr] = value.to_dict()
elif isinstance(value, dict):
result[attr] = dict(map(
lambda item: (item[0], item[1].to_dict())
if hasattr(item[1], "to_dict") else item,
value.items()
))
else:
result[attr] = value
return result
def to_str(self):
"""
Returns the string representation of the model
"""
return pformat(self.to_dict())
def __repr__(self):
"""
For `print` and `pprint`
"""
return self.to_str()
def __eq__(self, other):
"""
Returns true if both objects are equal
"""
return self.__dict__ == other.__dict__
def __ne__(self, other):
"""
Returns true if both objects are not equal
"""
return not self == other
|
apache-2.0
|
[
3,
2803,
26,
2774,
13,
24,
199,
199,
624,
272,
7083,
415,
4302,
20171,
4103,
3261,
339,
961,
3261,
22741,
8883,
24024,
18960,
4103,
367,
2195,
23813,
14,
284,
16197,
474,
365,
282,
4298,
626,
5300,
3746,
2112,
12,
18336,
2509,
4661,
31566,
436,
295,
4751,
370,
1720,
1265,
4661,
24024,
590,
20171,
474,
286,
28078,
14,
339,
3232,
3735,
3158,
1015,
26,
413,
14,
16,
2286,
17065,
701,
26,
4178,
921,
5031,
14,
957,
15,
29940,
13,
1246,
15,
29940,
13,
600,
2268,
14,
3187,
199,
624,
421,
199,
504,
10933,
492,
30843,
199,
504,
3816,
492,
10849,
199,
646,
295,
421,
199,
533,
8053,
8,
785,
304,
272,
408,
272,
6944,
26,
961,
1021,
365,
2599,
4046,
701,
314,
5584,
16267,
1233,
4306,
2240,
14,
272,
4226,
440,
5283,
314,
1021,
10250,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
1947,
63,
344,
29,
403,
12,
1947,
63,
354,
29,
403,
12,
2338,
29,
403,
304,
267,
408,
267,
8053,
446,
282,
1402,
3247,
315,
16666,
16267,
398,
520,
635,
1211,
5584,
16267,
4100,
26,
710,
790,
365,
2225,
536,
3303,
436,
314,
574,
365,
2225,
730,
14,
267,
520,
635,
1211,
2225,
2956,
26,
710,
790,
365,
2225,
536,
3303,
436,
314,
574,
365,
2022,
790,
315,
5492,
14,
267,
408,
267,
291,
14,
29940,
63,
1313,
275,
469,
288,
283,
1450,
63,
344,
356,
283,
442,
297,
288,
283,
1450,
63,
354,
356,
283,
495,
297,
288,
283,
835,
356,
283,
442,
7,
267,
789,
398,
291,
14,
3215,
63,
1130,
275,
469,
288,
283,
1450,
63,
344,
356,
283,
1450,
1304,
297,
288,
283,
1450,
63,
354,
356,
283,
20183,
297,
288,
283,
835,
356,
283,
835,
7,
267,
789,
398,
291,
423,
1450,
63,
344,
275,
1947,
63,
344,
267,
291,
423,
1450,
63,
354,
275,
1947,
63,
354,
267,
291,
423,
835,
275,
2338,
339,
768,
1829,
272,
347,
1947,
63,
344,
8,
277,
304,
267,
408,
267,
14509,
314,
1947,
63,
344,
402,
642,
8053,
14,
398,
520,
1107,
26,
710,
1947,
63,
344,
402,
642,
8053,
14,
267,
520,
4500,
26,
1109,
267,
408,
267,
372,
291,
423,
1450,
63,
344,
339,
768,
1450,
63,
344,
14,
8345,
272,
347,
1947,
63,
344,
8,
277,
12,
1947,
63,
344,
304,
267,
408,
267,
10729,
314,
1947,
63,
344,
402,
642,
8053,
14,
398,
520,
635,
1947,
63,
344,
26,
710,
1947,
63,
344,
402,
642,
8053,
14,
267,
520,
466,
26,
1109,
267,
408,
398,
291,
423,
1450,
63,
344,
275,
1947,
63,
344,
339,
768,
1829,
272,
347,
1947,
63,
354,
8,
277,
304,
267,
408,
267,
14509,
314,
1947,
63,
354,
402,
642,
8053,
14,
398,
520,
1107,
26,
710,
1947,
63,
354,
402,
642,
8053,
14,
267,
520,
4500,
26,
620,
267,
408,
267,
372,
291,
423,
1450,
63,
354,
339,
768,
1450,
63,
354,
14,
8345,
272,
347,
1947,
63,
354,
8,
277,
12,
1947,
63,
354,
304,
267,
408,
267,
10729,
314,
1947,
63,
354,
402,
642,
8053,
14,
398,
520,
635,
1947,
63,
354,
26,
710,
1947,
63,
354,
402,
642,
8053,
14,
267,
520,
466,
26,
620,
267,
408,
398,
291,
423,
1450,
63,
354,
275,
1947,
63,
354,
339,
768,
1829,
272,
347,
2338,
8,
277,
304,
267,
408,
267,
14509,
314,
2338,
402,
642,
8053,
14,
398,
520,
1107,
26,
710,
2338,
402,
642,
8053,
14,
267,
520,
4500,
26,
1109,
267,
408,
267,
372,
291,
423,
835,
339,
768,
835,
14,
8345,
272,
347,
2338,
8,
277,
12,
2338,
304,
267,
408,
267,
10729,
314,
2338,
402,
642,
8053,
14,
398,
520,
635,
2338,
26,
710,
2338,
402,
642,
8053,
14,
267,
520,
466,
26,
1109,
267,
408,
398,
291,
423,
835,
275,
2338,
339,
347,
370,
63,
807,
8,
277,
304,
267,
408,
267,
1803,
314,
1402,
4382,
465,
282,
1211,
267,
408,
267,
754,
275,
1052,
398,
367,
1921,
12,
485,
315,
10849,
8,
277,
14,
29940,
63,
1313,
304,
288,
574,
275,
2519,
8,
277,
12,
1921,
9,
288,
340,
1228,
8,
585,
12,
769,
304,
355,
754,
59,
962,
61,
275,
769,
8,
1130,
8,
490,
2400,
671,
26,
671,
14,
475,
63,
807,
342,
340,
2688,
8,
88,
12,
298,
475,
63,
807,
531,
587,
671,
12,
490,
574,
355,
5082,
288,
916,
2688,
8,
585,
12,
298,
475,
63,
807,
2349,
355,
754,
59,
962,
61,
275,
574,
14,
475,
63,
807,
342,
288,
916,
1228,
8,
585,
12,
1211,
304,
355,
754,
59,
962,
61,
275,
1211,
8,
1130,
8,
490,
2400,
1242,
26,
334,
1053,
59,
16,
467,
1242,
59,
17,
1055,
475,
63,
807,
1012,
490,
340,
2688,
8,
1053,
59,
17,
467,
298,
475,
63,
807,
531,
587,
1242,
12,
490,
574,
14,
1744,
342,
355,
5082,
288,
587,
26,
355,
754,
59,
962,
61,
275,
574,
398,
372,
754,
339,
347,
370,
63,
495,
8,
277,
304,
267,
408,
267,
1803,
314,
1059,
6025,
402,
314,
1402,
267,
408,
267,
372,
30843,
8,
277,
14,
475,
63,
807,
1012,
339,
347,
636,
2722,
721,
277,
304,
267,
408,
267,
2104,
658,
1361,
64,
436,
658,
15380,
64,
267,
408,
267,
372,
291,
14,
475,
63,
495,
342,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
408,
267,
1803,
2549,
340,
3865,
2251,
787,
4472,
267,
408,
267,
372,
291,
855,
807,
363,
508,
1163,
855,
807,
363,
339,
347,
636,
685,
721,
277,
12,
1163,
304,
267,
408,
267,
1803,
2549,
340,
3865,
2251,
787,
440,
4472,
267,
408,
267,
372,
440,
291,
508,
1163,
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
] |
[
2803,
26,
2774,
13,
24,
199,
199,
624,
272,
7083,
415,
4302,
20171,
4103,
3261,
339,
961,
3261,
22741,
8883,
24024,
18960,
4103,
367,
2195,
23813,
14,
284,
16197,
474,
365,
282,
4298,
626,
5300,
3746,
2112,
12,
18336,
2509,
4661,
31566,
436,
295,
4751,
370,
1720,
1265,
4661,
24024,
590,
20171,
474,
286,
28078,
14,
339,
3232,
3735,
3158,
1015,
26,
413,
14,
16,
2286,
17065,
701,
26,
4178,
921,
5031,
14,
957,
15,
29940,
13,
1246,
15,
29940,
13,
600,
2268,
14,
3187,
199,
624,
421,
199,
504,
10933,
492,
30843,
199,
504,
3816,
492,
10849,
199,
646,
295,
421,
199,
533,
8053,
8,
785,
304,
272,
408,
272,
6944,
26,
961,
1021,
365,
2599,
4046,
701,
314,
5584,
16267,
1233,
4306,
2240,
14,
272,
4226,
440,
5283,
314,
1021,
10250,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
1947,
63,
344,
29,
403,
12,
1947,
63,
354,
29,
403,
12,
2338,
29,
403,
304,
267,
408,
267,
8053,
446,
282,
1402,
3247,
315,
16666,
16267,
398,
520,
635,
1211,
5584,
16267,
4100,
26,
710,
790,
365,
2225,
536,
3303,
436,
314,
574,
365,
2225,
730,
14,
267,
520,
635,
1211,
2225,
2956,
26,
710,
790,
365,
2225,
536,
3303,
436,
314,
574,
365,
2022,
790,
315,
5492,
14,
267,
408,
267,
291,
14,
29940,
63,
1313,
275,
469,
288,
283,
1450,
63,
344,
356,
283,
442,
297,
288,
283,
1450,
63,
354,
356,
283,
495,
297,
288,
283,
835,
356,
283,
442,
7,
267,
789,
398,
291,
14,
3215,
63,
1130,
275,
469,
288,
283,
1450,
63,
344,
356,
283,
1450,
1304,
297,
288,
283,
1450,
63,
354,
356,
283,
20183,
297,
288,
283,
835,
356,
283,
835,
7,
267,
789,
398,
291,
423,
1450,
63,
344,
275,
1947,
63,
344,
267,
291,
423,
1450,
63,
354,
275,
1947,
63,
354,
267,
291,
423,
835,
275,
2338,
339,
768,
1829,
272,
347,
1947,
63,
344,
8,
277,
304,
267,
408,
267,
14509,
314,
1947,
63,
344,
402,
642,
8053,
14,
398,
520,
1107,
26,
710,
1947,
63,
344,
402,
642,
8053,
14,
267,
520,
4500,
26,
1109,
267,
408,
267,
372,
291,
423,
1450,
63,
344,
339,
768,
1450,
63,
344,
14,
8345,
272,
347,
1947,
63,
344,
8,
277,
12,
1947,
63,
344,
304,
267,
408,
267,
10729,
314,
1947,
63,
344,
402,
642,
8053,
14,
398,
520,
635,
1947,
63,
344,
26,
710,
1947,
63,
344,
402,
642,
8053,
14,
267,
520,
466,
26,
1109,
267,
408,
398,
291,
423,
1450,
63,
344,
275,
1947,
63,
344,
339,
768,
1829,
272,
347,
1947,
63,
354,
8,
277,
304,
267,
408,
267,
14509,
314,
1947,
63,
354,
402,
642,
8053,
14,
398,
520,
1107,
26,
710,
1947,
63,
354,
402,
642,
8053,
14,
267,
520,
4500,
26,
620,
267,
408,
267,
372,
291,
423,
1450,
63,
354,
339,
768,
1450,
63,
354,
14,
8345,
272,
347,
1947,
63,
354,
8,
277,
12,
1947,
63,
354,
304,
267,
408,
267,
10729,
314,
1947,
63,
354,
402,
642,
8053,
14,
398,
520,
635,
1947,
63,
354,
26,
710,
1947,
63,
354,
402,
642,
8053,
14,
267,
520,
466,
26,
620,
267,
408,
398,
291,
423,
1450,
63,
354,
275,
1947,
63,
354,
339,
768,
1829,
272,
347,
2338,
8,
277,
304,
267,
408,
267,
14509,
314,
2338,
402,
642,
8053,
14,
398,
520,
1107,
26,
710,
2338,
402,
642,
8053,
14,
267,
520,
4500,
26,
1109,
267,
408,
267,
372,
291,
423,
835,
339,
768,
835,
14,
8345,
272,
347,
2338,
8,
277,
12,
2338,
304,
267,
408,
267,
10729,
314,
2338,
402,
642,
8053,
14,
398,
520,
635,
2338,
26,
710,
2338,
402,
642,
8053,
14,
267,
520,
466,
26,
1109,
267,
408,
398,
291,
423,
835,
275,
2338,
339,
347,
370,
63,
807,
8,
277,
304,
267,
408,
267,
1803,
314,
1402,
4382,
465,
282,
1211,
267,
408,
267,
754,
275,
1052,
398,
367,
1921,
12,
485,
315,
10849,
8,
277,
14,
29940,
63,
1313,
304,
288,
574,
275,
2519,
8,
277,
12,
1921,
9,
288,
340,
1228,
8,
585,
12,
769,
304,
355,
754,
59,
962,
61,
275,
769,
8,
1130,
8,
490,
2400,
671,
26,
671,
14,
475,
63,
807,
342,
340,
2688,
8,
88,
12,
298,
475,
63,
807,
531,
587,
671,
12,
490,
574,
355,
5082,
288,
916,
2688,
8,
585,
12,
298,
475,
63,
807,
2349,
355,
754,
59,
962,
61,
275,
574,
14,
475,
63,
807,
342,
288,
916,
1228,
8,
585,
12,
1211,
304,
355,
754,
59,
962,
61,
275,
1211,
8,
1130,
8,
490,
2400,
1242,
26,
334,
1053,
59,
16,
467,
1242,
59,
17,
1055,
475,
63,
807,
1012,
490,
340,
2688,
8,
1053,
59,
17,
467,
298,
475,
63,
807,
531,
587,
1242,
12,
490,
574,
14,
1744,
342,
355,
5082,
288,
587,
26,
355,
754,
59,
962,
61,
275,
574,
398,
372,
754,
339,
347,
370,
63,
495,
8,
277,
304,
267,
408,
267,
1803,
314,
1059,
6025,
402,
314,
1402,
267,
408,
267,
372,
30843,
8,
277,
14,
475,
63,
807,
1012,
339,
347,
636,
2722,
721,
277,
304,
267,
408,
267,
2104,
658,
1361,
64,
436,
658,
15380,
64,
267,
408,
267,
372,
291,
14,
475,
63,
495,
342,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
408,
267,
1803,
2549,
340,
3865,
2251,
787,
4472,
267,
408,
267,
372,
291,
855,
807,
363,
508,
1163,
855,
807,
363,
339,
347,
636,
685,
721,
277,
12,
1163,
304,
267,
408,
267,
1803,
2549,
340,
3865,
2251,
787,
440,
4472,
267,
408,
267,
372,
440,
291,
508,
1163,
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,
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,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,
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
] |
macanjang/googletest
|
scripts/upload.py
|
2511
|
51024
|
#!/usr/bin/env python
#
# Copyright 2007 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Tool for uploading diffs from a version control system to the codereview app.
Usage summary: upload.py [options] [-- diff_options]
Diff options are passed to the diff command of the underlying system.
Supported version control systems:
Git
Mercurial
Subversion
It is important for Git/Mercurial users to specify a tree/node/branch to diff
against by using the '--rev' option.
"""
# This code is derived from appcfg.py in the App Engine SDK (open source),
# and from ASPN recipe #146306.
import cookielib
import getpass
import logging
import md5
import mimetypes
import optparse
import os
import re
import socket
import subprocess
import sys
import urllib
import urllib2
import urlparse
try:
import readline
except ImportError:
pass
# The logging verbosity:
# 0: Errors only.
# 1: Status messages.
# 2: Info logs.
# 3: Debug logs.
verbosity = 1
# Max size of patch or base file.
MAX_UPLOAD_SIZE = 900 * 1024
def GetEmail(prompt):
"""Prompts the user for their email address and returns it.
The last used email address is saved to a file and offered up as a suggestion
to the user. If the user presses enter without typing in anything the last
used email address is used. If the user enters a new address, it is saved
for next time we prompt.
"""
last_email_file_name = os.path.expanduser("~/.last_codereview_email_address")
last_email = ""
if os.path.exists(last_email_file_name):
try:
last_email_file = open(last_email_file_name, "r")
last_email = last_email_file.readline().strip("\n")
last_email_file.close()
prompt += " [%s]" % last_email
except IOError, e:
pass
email = raw_input(prompt + ": ").strip()
if email:
try:
last_email_file = open(last_email_file_name, "w")
last_email_file.write(email)
last_email_file.close()
except IOError, e:
pass
else:
email = last_email
return email
def StatusUpdate(msg):
"""Print a status message to stdout.
If 'verbosity' is greater than 0, print the message.
Args:
msg: The string to print.
"""
if verbosity > 0:
print msg
def ErrorExit(msg):
"""Print an error message to stderr and exit."""
print >>sys.stderr, msg
sys.exit(1)
class ClientLoginError(urllib2.HTTPError):
"""Raised to indicate there was an error authenticating with ClientLogin."""
def __init__(self, url, code, msg, headers, args):
urllib2.HTTPError.__init__(self, url, code, msg, headers, None)
self.args = args
self.reason = args["Error"]
class AbstractRpcServer(object):
"""Provides a common interface for a simple RPC server."""
def __init__(self, host, auth_function, host_override=None, extra_headers={},
save_cookies=False):
"""Creates a new HttpRpcServer.
Args:
host: The host to send requests to.
auth_function: A function that takes no arguments and returns an
(email, password) tuple when called. Will be called if authentication
is required.
host_override: The host header to send to the server (defaults to host).
extra_headers: A dict of extra headers to append to every request.
save_cookies: If True, save the authentication cookies to local disk.
If False, use an in-memory cookiejar instead. Subclasses must
implement this functionality. Defaults to False.
"""
self.host = host
self.host_override = host_override
self.auth_function = auth_function
self.authenticated = False
self.extra_headers = extra_headers
self.save_cookies = save_cookies
self.opener = self._GetOpener()
if self.host_override:
logging.info("Server: %s; Host: %s", self.host, self.host_override)
else:
logging.info("Server: %s", self.host)
def _GetOpener(self):
"""Returns an OpenerDirector for making HTTP requests.
Returns:
A urllib2.OpenerDirector object.
"""
raise NotImplementedError()
def _CreateRequest(self, url, data=None):
"""Creates a new urllib request."""
logging.debug("Creating request for: '%s' with payload:\n%s", url, data)
req = urllib2.Request(url, data=data)
if self.host_override:
req.add_header("Host", self.host_override)
for key, value in self.extra_headers.iteritems():
req.add_header(key, value)
return req
def _GetAuthToken(self, email, password):
"""Uses ClientLogin to authenticate the user, returning an auth token.
Args:
email: The user's email address
password: The user's password
Raises:
ClientLoginError: If there was an error authenticating with ClientLogin.
HTTPError: If there was some other form of HTTP error.
Returns:
The authentication token returned by ClientLogin.
"""
account_type = "GOOGLE"
if self.host.endswith(".google.com"):
# Needed for use inside Google.
account_type = "HOSTED"
req = self._CreateRequest(
url="https://www.google.com/accounts/ClientLogin",
data=urllib.urlencode({
"Email": email,
"Passwd": password,
"service": "ah",
"source": "rietveld-codereview-upload",
"accountType": account_type,
}),
)
try:
response = self.opener.open(req)
response_body = response.read()
response_dict = dict(x.split("=")
for x in response_body.split("\n") if x)
return response_dict["Auth"]
except urllib2.HTTPError, e:
if e.code == 403:
body = e.read()
response_dict = dict(x.split("=", 1) for x in body.split("\n") if x)
raise ClientLoginError(req.get_full_url(), e.code, e.msg,
e.headers, response_dict)
else:
raise
def _GetAuthCookie(self, auth_token):
"""Fetches authentication cookies for an authentication token.
Args:
auth_token: The authentication token returned by ClientLogin.
Raises:
HTTPError: If there was an error fetching the authentication cookies.
"""
# This is a dummy value to allow us to identify when we're successful.
continue_location = "http://localhost/"
args = {"continue": continue_location, "auth": auth_token}
req = self._CreateRequest("http://%s/_ah/login?%s" %
(self.host, urllib.urlencode(args)))
try:
response = self.opener.open(req)
except urllib2.HTTPError, e:
response = e
if (response.code != 302 or
response.info()["location"] != continue_location):
raise urllib2.HTTPError(req.get_full_url(), response.code, response.msg,
response.headers, response.fp)
self.authenticated = True
def _Authenticate(self):
"""Authenticates the user.
The authentication process works as follows:
1) We get a username and password from the user
2) We use ClientLogin to obtain an AUTH token for the user
(see http://code.google.com/apis/accounts/AuthForInstalledApps.html).
3) We pass the auth token to /_ah/login on the server to obtain an
authentication cookie. If login was successful, it tries to redirect
us to the URL we provided.
If we attempt to access the upload API without first obtaining an
authentication cookie, it returns a 401 response and directs us to
authenticate ourselves with ClientLogin.
"""
for i in range(3):
credentials = self.auth_function()
try:
auth_token = self._GetAuthToken(credentials[0], credentials[1])
except ClientLoginError, e:
if e.reason == "BadAuthentication":
print >>sys.stderr, "Invalid username or password."
continue
if e.reason == "CaptchaRequired":
print >>sys.stderr, (
"Please go to\n"
"https://www.google.com/accounts/DisplayUnlockCaptcha\n"
"and verify you are a human. Then try again.")
break
if e.reason == "NotVerified":
print >>sys.stderr, "Account not verified."
break
if e.reason == "TermsNotAgreed":
print >>sys.stderr, "User has not agreed to TOS."
break
if e.reason == "AccountDeleted":
print >>sys.stderr, "The user account has been deleted."
break
if e.reason == "AccountDisabled":
print >>sys.stderr, "The user account has been disabled."
break
if e.reason == "ServiceDisabled":
print >>sys.stderr, ("The user's access to the service has been "
"disabled.")
break
if e.reason == "ServiceUnavailable":
print >>sys.stderr, "The service is not available; try again later."
break
raise
self._GetAuthCookie(auth_token)
return
def Send(self, request_path, payload=None,
content_type="application/octet-stream",
timeout=None,
**kwargs):
"""Sends an RPC and returns the response.
Args:
request_path: The path to send the request to, eg /api/appversion/create.
payload: The body of the request, or None to send an empty request.
content_type: The Content-Type header to use.
timeout: timeout in seconds; default None i.e. no timeout.
(Note: for large requests on OS X, the timeout doesn't work right.)
kwargs: Any keyword arguments are converted into query string parameters.
Returns:
The response body, as a string.
"""
# TODO: Don't require authentication. Let the server say
# whether it is necessary.
if not self.authenticated:
self._Authenticate()
old_timeout = socket.getdefaulttimeout()
socket.setdefaulttimeout(timeout)
try:
tries = 0
while True:
tries += 1
args = dict(kwargs)
url = "http://%s%s" % (self.host, request_path)
if args:
url += "?" + urllib.urlencode(args)
req = self._CreateRequest(url=url, data=payload)
req.add_header("Content-Type", content_type)
try:
f = self.opener.open(req)
response = f.read()
f.close()
return response
except urllib2.HTTPError, e:
if tries > 3:
raise
elif e.code == 401:
self._Authenticate()
## elif e.code >= 500 and e.code < 600:
## # Server Error - try again.
## continue
else:
raise
finally:
socket.setdefaulttimeout(old_timeout)
class HttpRpcServer(AbstractRpcServer):
"""Provides a simplified RPC-style interface for HTTP requests."""
def _Authenticate(self):
"""Save the cookie jar after authentication."""
super(HttpRpcServer, self)._Authenticate()
if self.save_cookies:
StatusUpdate("Saving authentication cookies to %s" % self.cookie_file)
self.cookie_jar.save()
def _GetOpener(self):
"""Returns an OpenerDirector that supports cookies and ignores redirects.
Returns:
A urllib2.OpenerDirector object.
"""
opener = urllib2.OpenerDirector()
opener.add_handler(urllib2.ProxyHandler())
opener.add_handler(urllib2.UnknownHandler())
opener.add_handler(urllib2.HTTPHandler())
opener.add_handler(urllib2.HTTPDefaultErrorHandler())
opener.add_handler(urllib2.HTTPSHandler())
opener.add_handler(urllib2.HTTPErrorProcessor())
if self.save_cookies:
self.cookie_file = os.path.expanduser("~/.codereview_upload_cookies")
self.cookie_jar = cookielib.MozillaCookieJar(self.cookie_file)
if os.path.exists(self.cookie_file):
try:
self.cookie_jar.load()
self.authenticated = True
StatusUpdate("Loaded authentication cookies from %s" %
self.cookie_file)
except (cookielib.LoadError, IOError):
# Failed to load cookies - just ignore them.
pass
else:
# Create an empty cookie file with mode 600
fd = os.open(self.cookie_file, os.O_CREAT, 0600)
os.close(fd)
# Always chmod the cookie file
os.chmod(self.cookie_file, 0600)
else:
# Don't save cookies across runs of update.py.
self.cookie_jar = cookielib.CookieJar()
opener.add_handler(urllib2.HTTPCookieProcessor(self.cookie_jar))
return opener
parser = optparse.OptionParser(usage="%prog [options] [-- diff_options]")
parser.add_option("-y", "--assume_yes", action="store_true",
dest="assume_yes", default=False,
help="Assume that the answer to yes/no questions is 'yes'.")
# Logging
group = parser.add_option_group("Logging options")
group.add_option("-q", "--quiet", action="store_const", const=0,
dest="verbose", help="Print errors only.")
group.add_option("-v", "--verbose", action="store_const", const=2,
dest="verbose", default=1,
help="Print info level logs (default).")
group.add_option("--noisy", action="store_const", const=3,
dest="verbose", help="Print all logs.")
# Review server
group = parser.add_option_group("Review server options")
group.add_option("-s", "--server", action="store", dest="server",
default="codereview.appspot.com",
metavar="SERVER",
help=("The server to upload to. The format is host[:port]. "
"Defaults to 'codereview.appspot.com'."))
group.add_option("-e", "--email", action="store", dest="email",
metavar="EMAIL", default=None,
help="The username to use. Will prompt if omitted.")
group.add_option("-H", "--host", action="store", dest="host",
metavar="HOST", default=None,
help="Overrides the Host header sent with all RPCs.")
group.add_option("--no_cookies", action="store_false",
dest="save_cookies", default=True,
help="Do not save authentication cookies to local disk.")
# Issue
group = parser.add_option_group("Issue options")
group.add_option("-d", "--description", action="store", dest="description",
metavar="DESCRIPTION", default=None,
help="Optional description when creating an issue.")
group.add_option("-f", "--description_file", action="store",
dest="description_file", metavar="DESCRIPTION_FILE",
default=None,
help="Optional path of a file that contains "
"the description when creating an issue.")
group.add_option("-r", "--reviewers", action="store", dest="reviewers",
metavar="REVIEWERS", default=None,
help="Add reviewers (comma separated email addresses).")
group.add_option("--cc", action="store", dest="cc",
metavar="CC", default=None,
help="Add CC (comma separated email addresses).")
# Upload options
group = parser.add_option_group("Patch options")
group.add_option("-m", "--message", action="store", dest="message",
metavar="MESSAGE", default=None,
help="A message to identify the patch. "
"Will prompt if omitted.")
group.add_option("-i", "--issue", type="int", action="store",
metavar="ISSUE", default=None,
help="Issue number to which to add. Defaults to new issue.")
group.add_option("--download_base", action="store_true",
dest="download_base", default=False,
help="Base files will be downloaded by the server "
"(side-by-side diffs may not work on files with CRs).")
group.add_option("--rev", action="store", dest="revision",
metavar="REV", default=None,
help="Branch/tree/revision to diff against (used by DVCS).")
group.add_option("--send_mail", action="store_true",
dest="send_mail", default=False,
help="Send notification email to reviewers.")
def GetRpcServer(options):
"""Returns an instance of an AbstractRpcServer.
Returns:
A new AbstractRpcServer, on which RPC calls can be made.
"""
rpc_server_class = HttpRpcServer
def GetUserCredentials():
"""Prompts the user for a username and password."""
email = options.email
if email is None:
email = GetEmail("Email (login for uploading to %s)" % options.server)
password = getpass.getpass("Password for %s: " % email)
return (email, password)
# If this is the dev_appserver, use fake authentication.
host = (options.host or options.server).lower()
if host == "localhost" or host.startswith("localhost:"):
email = options.email
if email is None:
email = "test@example.com"
logging.info("Using debug user %s. Override with --email" % email)
server = rpc_server_class(
options.server,
lambda: (email, "password"),
host_override=options.host,
extra_headers={"Cookie":
'dev_appserver_login="%s:False"' % email},
save_cookies=options.save_cookies)
# Don't try to talk to ClientLogin.
server.authenticated = True
return server
return rpc_server_class(options.server, GetUserCredentials,
host_override=options.host,
save_cookies=options.save_cookies)
def EncodeMultipartFormData(fields, files):
"""Encode form fields for multipart/form-data.
Args:
fields: A sequence of (name, value) elements for regular form fields.
files: A sequence of (name, filename, value) elements for data to be
uploaded as files.
Returns:
(content_type, body) ready for httplib.HTTP instance.
Source:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/146306
"""
BOUNDARY = '-M-A-G-I-C---B-O-U-N-D-A-R-Y-'
CRLF = '\r\n'
lines = []
for (key, value) in fields:
lines.append('--' + BOUNDARY)
lines.append('Content-Disposition: form-data; name="%s"' % key)
lines.append('')
lines.append(value)
for (key, filename, value) in files:
lines.append('--' + BOUNDARY)
lines.append('Content-Disposition: form-data; name="%s"; filename="%s"' %
(key, filename))
lines.append('Content-Type: %s' % GetContentType(filename))
lines.append('')
lines.append(value)
lines.append('--' + BOUNDARY + '--')
lines.append('')
body = CRLF.join(lines)
content_type = 'multipart/form-data; boundary=%s' % BOUNDARY
return content_type, body
def GetContentType(filename):
"""Helper to guess the content-type from the filename."""
return mimetypes.guess_type(filename)[0] or 'application/octet-stream'
# Use a shell for subcommands on Windows to get a PATH search.
use_shell = sys.platform.startswith("win")
def RunShellWithReturnCode(command, print_output=False,
universal_newlines=True):
"""Executes a command and returns the output from stdout and the return code.
Args:
command: Command to execute.
print_output: If True, the output is printed to stdout.
If False, both stdout and stderr are ignored.
universal_newlines: Use universal_newlines flag (default: True).
Returns:
Tuple (output, return code)
"""
logging.info("Running %s", command)
p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
shell=use_shell, universal_newlines=universal_newlines)
if print_output:
output_array = []
while True:
line = p.stdout.readline()
if not line:
break
print line.strip("\n")
output_array.append(line)
output = "".join(output_array)
else:
output = p.stdout.read()
p.wait()
errout = p.stderr.read()
if print_output and errout:
print >>sys.stderr, errout
p.stdout.close()
p.stderr.close()
return output, p.returncode
def RunShell(command, silent_ok=False, universal_newlines=True,
print_output=False):
data, retcode = RunShellWithReturnCode(command, print_output,
universal_newlines)
if retcode:
ErrorExit("Got error status from %s:\n%s" % (command, data))
if not silent_ok and not data:
ErrorExit("No output from %s" % command)
return data
class VersionControlSystem(object):
"""Abstract base class providing an interface to the VCS."""
def __init__(self, options):
"""Constructor.
Args:
options: Command line options.
"""
self.options = options
def GenerateDiff(self, args):
"""Return the current diff as a string.
Args:
args: Extra arguments to pass to the diff command.
"""
raise NotImplementedError(
"abstract method -- subclass %s must override" % self.__class__)
def GetUnknownFiles(self):
"""Return a list of files unknown to the VCS."""
raise NotImplementedError(
"abstract method -- subclass %s must override" % self.__class__)
def CheckForUnknownFiles(self):
"""Show an "are you sure?" prompt if there are unknown files."""
unknown_files = self.GetUnknownFiles()
if unknown_files:
print "The following files are not added to version control:"
for line in unknown_files:
print line
prompt = "Are you sure to continue?(y/N) "
answer = raw_input(prompt).strip()
if answer != "y":
ErrorExit("User aborted")
def GetBaseFile(self, filename):
"""Get the content of the upstream version of a file.
Returns:
A tuple (base_content, new_content, is_binary, status)
base_content: The contents of the base file.
new_content: For text files, this is empty. For binary files, this is
the contents of the new file, since the diff output won't contain
information to reconstruct the current file.
is_binary: True iff the file is binary.
status: The status of the file.
"""
raise NotImplementedError(
"abstract method -- subclass %s must override" % self.__class__)
def GetBaseFiles(self, diff):
"""Helper that calls GetBase file for each file in the patch.
Returns:
A dictionary that maps from filename to GetBaseFile's tuple. Filenames
are retrieved based on lines that start with "Index:" or
"Property changes on:".
"""
files = {}
for line in diff.splitlines(True):
if line.startswith('Index:') or line.startswith('Property changes on:'):
unused, filename = line.split(':', 1)
# On Windows if a file has property changes its filename uses '\'
# instead of '/'.
filename = filename.strip().replace('\\', '/')
files[filename] = self.GetBaseFile(filename)
return files
def UploadBaseFiles(self, issue, rpc_server, patch_list, patchset, options,
files):
"""Uploads the base files (and if necessary, the current ones as well)."""
def UploadFile(filename, file_id, content, is_binary, status, is_base):
"""Uploads a file to the server."""
file_too_large = False
if is_base:
type = "base"
else:
type = "current"
if len(content) > MAX_UPLOAD_SIZE:
print ("Not uploading the %s file for %s because it's too large." %
(type, filename))
file_too_large = True
content = ""
checksum = md5.new(content).hexdigest()
if options.verbose > 0 and not file_too_large:
print "Uploading %s file for %s" % (type, filename)
url = "/%d/upload_content/%d/%d" % (int(issue), int(patchset), file_id)
form_fields = [("filename", filename),
("status", status),
("checksum", checksum),
("is_binary", str(is_binary)),
("is_current", str(not is_base)),
]
if file_too_large:
form_fields.append(("file_too_large", "1"))
if options.email:
form_fields.append(("user", options.email))
ctype, body = EncodeMultipartFormData(form_fields,
[("data", filename, content)])
response_body = rpc_server.Send(url, body,
content_type=ctype)
if not response_body.startswith("OK"):
StatusUpdate(" --> %s" % response_body)
sys.exit(1)
patches = dict()
[patches.setdefault(v, k) for k, v in patch_list]
for filename in patches.keys():
base_content, new_content, is_binary, status = files[filename]
file_id_str = patches.get(filename)
if file_id_str.find("nobase") != -1:
base_content = None
file_id_str = file_id_str[file_id_str.rfind("_") + 1:]
file_id = int(file_id_str)
if base_content != None:
UploadFile(filename, file_id, base_content, is_binary, status, True)
if new_content != None:
UploadFile(filename, file_id, new_content, is_binary, status, False)
def IsImage(self, filename):
"""Returns true if the filename has an image extension."""
mimetype = mimetypes.guess_type(filename)[0]
if not mimetype:
return False
return mimetype.startswith("image/")
class SubversionVCS(VersionControlSystem):
"""Implementation of the VersionControlSystem interface for Subversion."""
def __init__(self, options):
super(SubversionVCS, self).__init__(options)
if self.options.revision:
match = re.match(r"(\d+)(:(\d+))?", self.options.revision)
if not match:
ErrorExit("Invalid Subversion revision %s." % self.options.revision)
self.rev_start = match.group(1)
self.rev_end = match.group(3)
else:
self.rev_start = self.rev_end = None
# Cache output from "svn list -r REVNO dirname".
# Keys: dirname, Values: 2-tuple (ouput for start rev and end rev).
self.svnls_cache = {}
# SVN base URL is required to fetch files deleted in an older revision.
# Result is cached to not guess it over and over again in GetBaseFile().
required = self.options.download_base or self.options.revision is not None
self.svn_base = self._GuessBase(required)
def GuessBase(self, required):
"""Wrapper for _GuessBase."""
return self.svn_base
def _GuessBase(self, required):
"""Returns the SVN base URL.
Args:
required: If true, exits if the url can't be guessed, otherwise None is
returned.
"""
info = RunShell(["svn", "info"])
for line in info.splitlines():
words = line.split()
if len(words) == 2 and words[0] == "URL:":
url = words[1]
scheme, netloc, path, params, query, fragment = urlparse.urlparse(url)
username, netloc = urllib.splituser(netloc)
if username:
logging.info("Removed username from base URL")
if netloc.endswith("svn.python.org"):
if netloc == "svn.python.org":
if path.startswith("/projects/"):
path = path[9:]
elif netloc != "pythondev@svn.python.org":
ErrorExit("Unrecognized Python URL: %s" % url)
base = "http://svn.python.org/view/*checkout*%s/" % path
logging.info("Guessed Python base = %s", base)
elif netloc.endswith("svn.collab.net"):
if path.startswith("/repos/"):
path = path[6:]
base = "http://svn.collab.net/viewvc/*checkout*%s/" % path
logging.info("Guessed CollabNet base = %s", base)
elif netloc.endswith(".googlecode.com"):
path = path + "/"
base = urlparse.urlunparse(("http", netloc, path, params,
query, fragment))
logging.info("Guessed Google Code base = %s", base)
else:
path = path + "/"
base = urlparse.urlunparse((scheme, netloc, path, params,
query, fragment))
logging.info("Guessed base = %s", base)
return base
if required:
ErrorExit("Can't find URL in output from svn info")
return None
def GenerateDiff(self, args):
cmd = ["svn", "diff"]
if self.options.revision:
cmd += ["-r", self.options.revision]
cmd.extend(args)
data = RunShell(cmd)
count = 0
for line in data.splitlines():
if line.startswith("Index:") or line.startswith("Property changes on:"):
count += 1
logging.info(line)
if not count:
ErrorExit("No valid patches found in output from svn diff")
return data
def _CollapseKeywords(self, content, keyword_str):
"""Collapses SVN keywords."""
# svn cat translates keywords but svn diff doesn't. As a result of this
# behavior patching.PatchChunks() fails with a chunk mismatch error.
# This part was originally written by the Review Board development team
# who had the same problem (http://reviews.review-board.org/r/276/).
# Mapping of keywords to known aliases
svn_keywords = {
# Standard keywords
'Date': ['Date', 'LastChangedDate'],
'Revision': ['Revision', 'LastChangedRevision', 'Rev'],
'Author': ['Author', 'LastChangedBy'],
'HeadURL': ['HeadURL', 'URL'],
'Id': ['Id'],
# Aliases
'LastChangedDate': ['LastChangedDate', 'Date'],
'LastChangedRevision': ['LastChangedRevision', 'Rev', 'Revision'],
'LastChangedBy': ['LastChangedBy', 'Author'],
'URL': ['URL', 'HeadURL'],
}
def repl(m):
if m.group(2):
return "$%s::%s$" % (m.group(1), " " * len(m.group(3)))
return "$%s$" % m.group(1)
keywords = [keyword
for name in keyword_str.split(" ")
for keyword in svn_keywords.get(name, [])]
return re.sub(r"\$(%s):(:?)([^\$]+)\$" % '|'.join(keywords), repl, content)
def GetUnknownFiles(self):
status = RunShell(["svn", "status", "--ignore-externals"], silent_ok=True)
unknown_files = []
for line in status.split("\n"):
if line and line[0] == "?":
unknown_files.append(line)
return unknown_files
def ReadFile(self, filename):
"""Returns the contents of a file."""
file = open(filename, 'rb')
result = ""
try:
result = file.read()
finally:
file.close()
return result
def GetStatus(self, filename):
"""Returns the status of a file."""
if not self.options.revision:
status = RunShell(["svn", "status", "--ignore-externals", filename])
if not status:
ErrorExit("svn status returned no output for %s" % filename)
status_lines = status.splitlines()
# If file is in a cl, the output will begin with
# "\n--- Changelist 'cl_name':\n". See
# http://svn.collab.net/repos/svn/trunk/notes/changelist-design.txt
if (len(status_lines) == 3 and
not status_lines[0] and
status_lines[1].startswith("--- Changelist")):
status = status_lines[2]
else:
status = status_lines[0]
# If we have a revision to diff against we need to run "svn list"
# for the old and the new revision and compare the results to get
# the correct status for a file.
else:
dirname, relfilename = os.path.split(filename)
if dirname not in self.svnls_cache:
cmd = ["svn", "list", "-r", self.rev_start, dirname or "."]
out, returncode = RunShellWithReturnCode(cmd)
if returncode:
ErrorExit("Failed to get status for %s." % filename)
old_files = out.splitlines()
args = ["svn", "list"]
if self.rev_end:
args += ["-r", self.rev_end]
cmd = args + [dirname or "."]
out, returncode = RunShellWithReturnCode(cmd)
if returncode:
ErrorExit("Failed to run command %s" % cmd)
self.svnls_cache[dirname] = (old_files, out.splitlines())
old_files, new_files = self.svnls_cache[dirname]
if relfilename in old_files and relfilename not in new_files:
status = "D "
elif relfilename in old_files and relfilename in new_files:
status = "M "
else:
status = "A "
return status
def GetBaseFile(self, filename):
status = self.GetStatus(filename)
base_content = None
new_content = None
# If a file is copied its status will be "A +", which signifies
# "addition-with-history". See "svn st" for more information. We need to
# upload the original file or else diff parsing will fail if the file was
# edited.
if status[0] == "A" and status[3] != "+":
# We'll need to upload the new content if we're adding a binary file
# since diff's output won't contain it.
mimetype = RunShell(["svn", "propget", "svn:mime-type", filename],
silent_ok=True)
base_content = ""
is_binary = mimetype and not mimetype.startswith("text/")
if is_binary and self.IsImage(filename):
new_content = self.ReadFile(filename)
elif (status[0] in ("M", "D", "R") or
(status[0] == "A" and status[3] == "+") or # Copied file.
(status[0] == " " and status[1] == "M")): # Property change.
args = []
if self.options.revision:
url = "%s/%s@%s" % (self.svn_base, filename, self.rev_start)
else:
# Don't change filename, it's needed later.
url = filename
args += ["-r", "BASE"]
cmd = ["svn"] + args + ["propget", "svn:mime-type", url]
mimetype, returncode = RunShellWithReturnCode(cmd)
if returncode:
# File does not exist in the requested revision.
# Reset mimetype, it contains an error message.
mimetype = ""
get_base = False
is_binary = mimetype and not mimetype.startswith("text/")
if status[0] == " ":
# Empty base content just to force an upload.
base_content = ""
elif is_binary:
if self.IsImage(filename):
get_base = True
if status[0] == "M":
if not self.rev_end:
new_content = self.ReadFile(filename)
else:
url = "%s/%s@%s" % (self.svn_base, filename, self.rev_end)
new_content = RunShell(["svn", "cat", url],
universal_newlines=True, silent_ok=True)
else:
base_content = ""
else:
get_base = True
if get_base:
if is_binary:
universal_newlines = False
else:
universal_newlines = True
if self.rev_start:
# "svn cat -r REV delete_file.txt" doesn't work. cat requires
# the full URL with "@REV" appended instead of using "-r" option.
url = "%s/%s@%s" % (self.svn_base, filename, self.rev_start)
base_content = RunShell(["svn", "cat", url],
universal_newlines=universal_newlines,
silent_ok=True)
else:
base_content = RunShell(["svn", "cat", filename],
universal_newlines=universal_newlines,
silent_ok=True)
if not is_binary:
args = []
if self.rev_start:
url = "%s/%s@%s" % (self.svn_base, filename, self.rev_start)
else:
url = filename
args += ["-r", "BASE"]
cmd = ["svn"] + args + ["propget", "svn:keywords", url]
keywords, returncode = RunShellWithReturnCode(cmd)
if keywords and not returncode:
base_content = self._CollapseKeywords(base_content, keywords)
else:
StatusUpdate("svn status returned unexpected output: %s" % status)
sys.exit(1)
return base_content, new_content, is_binary, status[0:5]
class GitVCS(VersionControlSystem):
"""Implementation of the VersionControlSystem interface for Git."""
def __init__(self, options):
super(GitVCS, self).__init__(options)
# Map of filename -> hash of base file.
self.base_hashes = {}
def GenerateDiff(self, extra_args):
# This is more complicated than svn's GenerateDiff because we must convert
# the diff output to include an svn-style "Index:" line as well as record
# the hashes of the base files, so we can upload them along with our diff.
if self.options.revision:
extra_args = [self.options.revision] + extra_args
gitdiff = RunShell(["git", "diff", "--full-index"] + extra_args)
svndiff = []
filecount = 0
filename = None
for line in gitdiff.splitlines():
match = re.match(r"diff --git a/(.*) b/.*$", line)
if match:
filecount += 1
filename = match.group(1)
svndiff.append("Index: %s\n" % filename)
else:
# The "index" line in a git diff looks like this (long hashes elided):
# index 82c0d44..b2cee3f 100755
# We want to save the left hash, as that identifies the base file.
match = re.match(r"index (\w+)\.\.", line)
if match:
self.base_hashes[filename] = match.group(1)
svndiff.append(line + "\n")
if not filecount:
ErrorExit("No valid patches found in output from git diff")
return "".join(svndiff)
def GetUnknownFiles(self):
status = RunShell(["git", "ls-files", "--exclude-standard", "--others"],
silent_ok=True)
return status.splitlines()
def GetBaseFile(self, filename):
hash = self.base_hashes[filename]
base_content = None
new_content = None
is_binary = False
if hash == "0" * 40: # All-zero hash indicates no base file.
status = "A"
base_content = ""
else:
status = "M"
base_content, returncode = RunShellWithReturnCode(["git", "show", hash])
if returncode:
ErrorExit("Got error status from 'git show %s'" % hash)
return (base_content, new_content, is_binary, status)
class MercurialVCS(VersionControlSystem):
"""Implementation of the VersionControlSystem interface for Mercurial."""
def __init__(self, options, repo_dir):
super(MercurialVCS, self).__init__(options)
# Absolute path to repository (we can be in a subdir)
self.repo_dir = os.path.normpath(repo_dir)
# Compute the subdir
cwd = os.path.normpath(os.getcwd())
assert cwd.startswith(self.repo_dir)
self.subdir = cwd[len(self.repo_dir):].lstrip(r"\/")
if self.options.revision:
self.base_rev = self.options.revision
else:
self.base_rev = RunShell(["hg", "parent", "-q"]).split(':')[1].strip()
def _GetRelPath(self, filename):
"""Get relative path of a file according to the current directory,
given its logical path in the repo."""
assert filename.startswith(self.subdir), filename
return filename[len(self.subdir):].lstrip(r"\/")
def GenerateDiff(self, extra_args):
# If no file specified, restrict to the current subdir
extra_args = extra_args or ["."]
cmd = ["hg", "diff", "--git", "-r", self.base_rev] + extra_args
data = RunShell(cmd, silent_ok=True)
svndiff = []
filecount = 0
for line in data.splitlines():
m = re.match("diff --git a/(\S+) b/(\S+)", line)
if m:
# Modify line to make it look like as it comes from svn diff.
# With this modification no changes on the server side are required
# to make upload.py work with Mercurial repos.
# NOTE: for proper handling of moved/copied files, we have to use
# the second filename.
filename = m.group(2)
svndiff.append("Index: %s" % filename)
svndiff.append("=" * 67)
filecount += 1
logging.info(line)
else:
svndiff.append(line)
if not filecount:
ErrorExit("No valid patches found in output from hg diff")
return "\n".join(svndiff) + "\n"
def GetUnknownFiles(self):
"""Return a list of files unknown to the VCS."""
args = []
status = RunShell(["hg", "status", "--rev", self.base_rev, "-u", "."],
silent_ok=True)
unknown_files = []
for line in status.splitlines():
st, fn = line.split(" ", 1)
if st == "?":
unknown_files.append(fn)
return unknown_files
def GetBaseFile(self, filename):
# "hg status" and "hg cat" both take a path relative to the current subdir
# rather than to the repo root, but "hg diff" has given us the full path
# to the repo root.
base_content = ""
new_content = None
is_binary = False
oldrelpath = relpath = self._GetRelPath(filename)
# "hg status -C" returns two lines for moved/copied files, one otherwise
out = RunShell(["hg", "status", "-C", "--rev", self.base_rev, relpath])
out = out.splitlines()
# HACK: strip error message about missing file/directory if it isn't in
# the working copy
if out[0].startswith('%s: ' % relpath):
out = out[1:]
if len(out) > 1:
# Moved/copied => considered as modified, use old filename to
# retrieve base contents
oldrelpath = out[1].strip()
status = "M"
else:
status, _ = out[0].split(' ', 1)
if status != "A":
base_content = RunShell(["hg", "cat", "-r", self.base_rev, oldrelpath],
silent_ok=True)
is_binary = "\0" in base_content # Mercurial's heuristic
if status != "R":
new_content = open(relpath, "rb").read()
is_binary = is_binary or "\0" in new_content
if is_binary and base_content:
# Fetch again without converting newlines
base_content = RunShell(["hg", "cat", "-r", self.base_rev, oldrelpath],
silent_ok=True, universal_newlines=False)
if not is_binary or not self.IsImage(relpath):
new_content = None
return base_content, new_content, is_binary, status
# NOTE: The SplitPatch function is duplicated in engine.py, keep them in sync.
def SplitPatch(data):
"""Splits a patch into separate pieces for each file.
Args:
data: A string containing the output of svn diff.
Returns:
A list of 2-tuple (filename, text) where text is the svn diff output
pertaining to filename.
"""
patches = []
filename = None
diff = []
for line in data.splitlines(True):
new_filename = None
if line.startswith('Index:'):
unused, new_filename = line.split(':', 1)
new_filename = new_filename.strip()
elif line.startswith('Property changes on:'):
unused, temp_filename = line.split(':', 1)
# When a file is modified, paths use '/' between directories, however
# when a property is modified '\' is used on Windows. Make them the same
# otherwise the file shows up twice.
temp_filename = temp_filename.strip().replace('\\', '/')
if temp_filename != filename:
# File has property changes but no modifications, create a new diff.
new_filename = temp_filename
if new_filename:
if filename and diff:
patches.append((filename, ''.join(diff)))
filename = new_filename
diff = [line]
continue
if diff is not None:
diff.append(line)
if filename and diff:
patches.append((filename, ''.join(diff)))
return patches
def UploadSeparatePatches(issue, rpc_server, patchset, data, options):
"""Uploads a separate patch for each file in the diff output.
Returns a list of [patch_key, filename] for each file.
"""
patches = SplitPatch(data)
rv = []
for patch in patches:
if len(patch[1]) > MAX_UPLOAD_SIZE:
print ("Not uploading the patch for " + patch[0] +
" because the file is too large.")
continue
form_fields = [("filename", patch[0])]
if not options.download_base:
form_fields.append(("content_upload", "1"))
files = [("data", "data.diff", patch[1])]
ctype, body = EncodeMultipartFormData(form_fields, files)
url = "/%d/upload_patch/%d" % (int(issue), int(patchset))
print "Uploading patch for " + patch[0]
response_body = rpc_server.Send(url, body, content_type=ctype)
lines = response_body.splitlines()
if not lines or lines[0] != "OK":
StatusUpdate(" --> %s" % response_body)
sys.exit(1)
rv.append([lines[1], patch[0]])
return rv
def GuessVCS(options):
"""Helper to guess the version control system.
This examines the current directory, guesses which VersionControlSystem
we're using, and returns an instance of the appropriate class. Exit with an
error if we can't figure it out.
Returns:
A VersionControlSystem instance. Exits if the VCS can't be guessed.
"""
# Mercurial has a command to get the base directory of a repository
# Try running it, but don't die if we don't have hg installed.
# NOTE: we try Mercurial first as it can sit on top of an SVN working copy.
try:
out, returncode = RunShellWithReturnCode(["hg", "root"])
if returncode == 0:
return MercurialVCS(options, out.strip())
except OSError, (errno, message):
if errno != 2: # ENOENT -- they don't have hg installed.
raise
# Subversion has a .svn in all working directories.
if os.path.isdir('.svn'):
logging.info("Guessed VCS = Subversion")
return SubversionVCS(options)
# Git has a command to test if you're in a git tree.
# Try running it, but don't die if we don't have git installed.
try:
out, returncode = RunShellWithReturnCode(["git", "rev-parse",
"--is-inside-work-tree"])
if returncode == 0:
return GitVCS(options)
except OSError, (errno, message):
if errno != 2: # ENOENT -- they don't have git installed.
raise
ErrorExit(("Could not guess version control system. "
"Are you in a working copy directory?"))
def RealMain(argv, data=None):
"""The real main function.
Args:
argv: Command line arguments.
data: Diff contents. If None (default) the diff is generated by
the VersionControlSystem implementation returned by GuessVCS().
Returns:
A 2-tuple (issue id, patchset id).
The patchset id is None if the base files are not uploaded by this
script (applies only to SVN checkouts).
"""
logging.basicConfig(format=("%(asctime).19s %(levelname)s %(filename)s:"
"%(lineno)s %(message)s "))
os.environ['LC_ALL'] = 'C'
options, args = parser.parse_args(argv[1:])
global verbosity
verbosity = options.verbose
if verbosity >= 3:
logging.getLogger().setLevel(logging.DEBUG)
elif verbosity >= 2:
logging.getLogger().setLevel(logging.INFO)
vcs = GuessVCS(options)
if isinstance(vcs, SubversionVCS):
# base field is only allowed for Subversion.
# Note: Fetching base files may become deprecated in future releases.
base = vcs.GuessBase(options.download_base)
else:
base = None
if not base and options.download_base:
options.download_base = True
logging.info("Enabled upload of base file")
if not options.assume_yes:
vcs.CheckForUnknownFiles()
if data is None:
data = vcs.GenerateDiff(args)
files = vcs.GetBaseFiles(data)
if verbosity >= 1:
print "Upload server:", options.server, "(change with -s/--server)"
if options.issue:
prompt = "Message describing this patch set: "
else:
prompt = "New issue subject: "
message = options.message or raw_input(prompt).strip()
if not message:
ErrorExit("A non-empty message is required")
rpc_server = GetRpcServer(options)
form_fields = [("subject", message)]
if base:
form_fields.append(("base", base))
if options.issue:
form_fields.append(("issue", str(options.issue)))
if options.email:
form_fields.append(("user", options.email))
if options.reviewers:
for reviewer in options.reviewers.split(','):
if "@" in reviewer and not reviewer.split("@")[1].count(".") == 1:
ErrorExit("Invalid email address: %s" % reviewer)
form_fields.append(("reviewers", options.reviewers))
if options.cc:
for cc in options.cc.split(','):
if "@" in cc and not cc.split("@")[1].count(".") == 1:
ErrorExit("Invalid email address: %s" % cc)
form_fields.append(("cc", options.cc))
description = options.description
if options.description_file:
if options.description:
ErrorExit("Can't specify description and description_file")
file = open(options.description_file, 'r')
description = file.read()
file.close()
if description:
form_fields.append(("description", description))
# Send a hash of all the base file so the server can determine if a copy
# already exists in an earlier patchset.
base_hashes = ""
for file, info in files.iteritems():
if not info[0] is None:
checksum = md5.new(info[0]).hexdigest()
if base_hashes:
base_hashes += "|"
base_hashes += checksum + ":" + file
form_fields.append(("base_hashes", base_hashes))
# If we're uploading base files, don't send the email before the uploads, so
# that it contains the file status.
if options.send_mail and options.download_base:
form_fields.append(("send_mail", "1"))
if not options.download_base:
form_fields.append(("content_upload", "1"))
if len(data) > MAX_UPLOAD_SIZE:
print "Patch is large, so uploading file patches separately."
uploaded_diff_file = []
form_fields.append(("separate_patches", "1"))
else:
uploaded_diff_file = [("data", "data.diff", data)]
ctype, body = EncodeMultipartFormData(form_fields, uploaded_diff_file)
response_body = rpc_server.Send("/upload", body, content_type=ctype)
patchset = None
if not options.download_base or not uploaded_diff_file:
lines = response_body.splitlines()
if len(lines) >= 2:
msg = lines[0]
patchset = lines[1].strip()
patches = [x.split(" ", 1) for x in lines[2:]]
else:
msg = response_body
else:
msg = response_body
StatusUpdate(msg)
if not response_body.startswith("Issue created.") and \
not response_body.startswith("Issue updated."):
sys.exit(0)
issue = msg[msg.rfind("/")+1:]
if not uploaded_diff_file:
result = UploadSeparatePatches(issue, rpc_server, patchset, data, options)
if not options.download_base:
patches = result
if not options.download_base:
vcs.UploadBaseFiles(issue, rpc_server, patches, patchset, options, files)
if options.send_mail:
rpc_server.Send("/" + issue + "/mail", payload="")
return issue, patchset
def main():
try:
RealMain(sys.argv)
except KeyboardInterrupt:
print
StatusUpdate("Interrupted.")
sys.exit(1)
if __name__ == "__main__":
main()
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
10219,
4475,
3277,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
624,
5157,
367,
24349,
14981,
687,
282,
1015,
3304,
2656,
370,
314,
1233,
8578,
1145,
14,
199,
199,
7692,
6212,
26,
5802,
14,
647,
359,
1419,
61,
19344,
3915,
63,
1419,
61,
199,
199,
10746,
1511,
787,
3032,
370,
314,
3915,
1414,
402,
314,
8793,
2656,
14,
199,
199,
10682,
1015,
3304,
10460,
26,
523,
12579,
523,
30522,
523,
31098,
199,
199,
7940,
365,
11012,
367,
12579,
15,
16797,
18977,
4390,
370,
4165,
282,
3123,
15,
932,
15,
4694,
370,
3915,
199,
17777,
701,
1808,
314,
2850,
4964,
7,
945,
14,
199,
624,
199,
3,
961,
1233,
365,
7131,
687,
1145,
4128,
14,
647,
315,
314,
4693,
12580,
15610,
334,
1490,
1350,
395,
199,
3,
436,
687,
4319,
9060,
17121,
327,
11432,
11363,
14,
199,
199,
646,
26234,
199,
646,
18354,
199,
646,
2050,
199,
646,
6128,
21,
199,
646,
13290,
199,
646,
8691,
199,
646,
747,
199,
646,
295,
199,
646,
2838,
199,
646,
3873,
199,
646,
984,
199,
646,
4011,
199,
646,
4011,
18,
199,
646,
7097,
199,
199,
893,
26,
523,
492,
14441,
199,
2590,
3545,
26,
523,
986,
199,
199,
3,
710,
2050,
8661,
26,
199,
3,
221,
378,
26,
20456,
1454,
14,
199,
3,
221,
413,
26,
9795,
3788,
14,
199,
3,
221,
499,
26,
10332,
9610,
14,
199,
3,
221,
650,
26,
14245,
9610,
14,
199,
9833,
275,
413,
199,
199,
3,
8228,
1568,
402,
3371,
503,
1300,
570,
14,
199,
4283,
63,
16418,
63,
4305,
275,
27151,
627,
6619,
421,
199,
318,
2372,
7035,
8,
7650,
304,
523,
408,
919,
311,
1086,
314,
922,
367,
3932,
3031,
2287,
436,
2529,
652,
14,
819,
710,
2061,
1202,
3031,
2287,
365,
6290,
370,
282,
570,
436,
402,
22941,
1536,
465,
282,
18453,
1636,
523,
370,
314,
922,
14,
982,
314,
922,
299,
4357,
9509,
1928,
14090,
315,
7003,
314,
2061,
523,
1202,
3031,
2287,
365,
1202,
14,
982,
314,
922,
655,
878,
282,
892,
2287,
12,
652,
365,
6290,
523,
367,
2163,
900,
781,
8457,
14,
819,
408,
523,
2061,
63,
2123,
63,
493,
63,
354,
275,
747,
14,
515,
14,
12131,
20793,
8083,
2019,
63,
600,
8578,
63,
2123,
63,
1562,
531,
523,
2061,
63,
2123,
275,
3087,
523,
340,
747,
14,
515,
14,
2444,
8,
2019,
63,
2123,
63,
493,
63,
354,
304,
272,
862,
26,
489,
2061,
63,
2123,
63,
493,
275,
1551,
8,
2019,
63,
2123,
63,
493,
63,
354,
12,
298,
82,
531,
489,
2061,
63,
2123,
275,
2061,
63,
2123,
63,
493,
14,
6407,
1252,
1913,
4582,
78,
531,
489,
2061,
63,
2123,
63,
493,
14,
1600,
342,
489,
8457,
847,
298,
8978,
83,
8480,
450,
2061,
63,
2123,
272,
871,
5925,
12,
325,
26,
489,
986,
523,
3031,
275,
3066,
63,
1210,
8,
7650,
435,
7244,
298,
680,
1913,
342,
523,
340,
3031,
26,
272,
862,
26,
489,
2061,
63,
2123,
63,
493,
275,
1551,
8,
2019,
63,
2123,
63,
493,
63,
354,
12,
298,
87,
531,
489,
2061,
63,
2123,
63,
493,
14,
952,
8,
2123,
9,
489,
2061,
63,
2123,
63,
493,
14,
1600,
342,
272,
871,
5925,
12,
325,
26,
489,
986,
523,
587,
26,
272,
3031,
275,
2061,
63,
2123,
523,
372,
3031,
421,
199,
318,
9795,
4152,
8,
1328,
304,
523,
408,
5375,
282,
2004,
1245,
370,
3839,
14,
819,
982,
283,
9833,
7,
365,
8932,
2419,
378,
12,
870,
314,
1245,
14,
819,
3033,
26,
272,
1499,
26,
710,
1059,
370,
870,
14,
523,
408,
523,
340,
8661,
690,
378,
26,
272,
870,
1499,
421,
199,
318,
28379,
8,
1328,
304,
523,
408,
5375,
376,
1125,
1245,
370,
4635,
436,
4458,
1041,
523,
870,
4331,
1274,
14,
3083,
12,
1499,
523,
984,
14,
2224,
8,
17,
9,
421,
199,
533,
6810,
8880,
547,
8,
4078,
18,
14,
12815,
304,
523,
408,
16894,
370,
6623,
2337,
1990,
376,
1125,
28532,
1958,
543,
6810,
8880,
1041,
819,
347,
636,
826,
721,
277,
12,
1166,
12,
1233,
12,
1499,
12,
2323,
12,
1249,
304,
272,
4011,
18,
14,
12815,
855,
826,
721,
277,
12,
1166,
12,
1233,
12,
1499,
12,
2323,
12,
488,
9,
272,
291,
14,
589,
275,
1249,
272,
291,
14,
5764,
275,
1249,
905,
547,
937,
421,
199,
533,
11836,
30980,
8,
785,
304,
523,
408,
17473,
282,
2863,
3217,
367,
282,
3486,
11785,
1654,
1041,
819,
347,
636,
826,
721,
277,
12,
1591,
12,
1790,
63,
1593,
12,
1591,
63,
4415,
29,
403,
12,
2402,
63,
2139,
10324,
2049,
3354,
63,
7792,
29,
797,
304,
272,
408,
10607,
282,
892,
4760,
30980,
14,
339,
3033,
26,
489,
1591,
26,
710,
1591,
370,
3222,
4145,
370,
14,
489,
1790,
63,
1593,
26,
437,
805,
626,
6181,
949,
2368,
436,
2529,
376,
267,
334,
2123,
12,
2505,
9,
2008,
1380,
2797,
14,
12823,
506,
2797,
340,
6299,
267,
365,
1415,
14,
489,
1591,
63,
4415,
26,
710,
1591,
1406,
370,
3222,
370,
314,
1654,
334,
4322,
370,
1591,
680,
489,
2402,
63,
2139,
26,
437,
1211,
402,
2402,
2323,
370,
5666,
370,
4036,
1056,
14,
489,
3354,
63,
7792,
26,
982,
715,
12,
3354,
314,
6299,
10049,
370,
2257,
4543,
14,
267,
982,
756,
12,
675,
376,
315,
13,
4844,
29038,
3140,
14,
221,
20196,
1471,
267,
5669,
642,
9330,
14,
221,
7827,
370,
756,
14,
272,
408
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
10219,
4475,
3277,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
624,
5157,
367,
24349,
14981,
687,
282,
1015,
3304,
2656,
370,
314,
1233,
8578,
1145,
14,
199,
199,
7692,
6212,
26,
5802,
14,
647,
359,
1419,
61,
19344,
3915,
63,
1419,
61,
199,
199,
10746,
1511,
787,
3032,
370,
314,
3915,
1414,
402,
314,
8793,
2656,
14,
199,
199,
10682,
1015,
3304,
10460,
26,
523,
12579,
523,
30522,
523,
31098,
199,
199,
7940,
365,
11012,
367,
12579,
15,
16797,
18977,
4390,
370,
4165,
282,
3123,
15,
932,
15,
4694,
370,
3915,
199,
17777,
701,
1808,
314,
2850,
4964,
7,
945,
14,
199,
624,
199,
3,
961,
1233,
365,
7131,
687,
1145,
4128,
14,
647,
315,
314,
4693,
12580,
15610,
334,
1490,
1350,
395,
199,
3,
436,
687,
4319,
9060,
17121,
327,
11432,
11363,
14,
199,
199,
646,
26234,
199,
646,
18354,
199,
646,
2050,
199,
646,
6128,
21,
199,
646,
13290,
199,
646,
8691,
199,
646,
747,
199,
646,
295,
199,
646,
2838,
199,
646,
3873,
199,
646,
984,
199,
646,
4011,
199,
646,
4011,
18,
199,
646,
7097,
199,
199,
893,
26,
523,
492,
14441,
199,
2590,
3545,
26,
523,
986,
199,
199,
3,
710,
2050,
8661,
26,
199,
3,
221,
378,
26,
20456,
1454,
14,
199,
3,
221,
413,
26,
9795,
3788,
14,
199,
3,
221,
499,
26,
10332,
9610,
14,
199,
3,
221,
650,
26,
14245,
9610,
14,
199,
9833,
275,
413,
199,
199,
3,
8228,
1568,
402,
3371,
503,
1300,
570,
14,
199,
4283,
63,
16418,
63,
4305,
275,
27151,
627,
6619,
421,
199,
318,
2372,
7035,
8,
7650,
304,
523,
408,
919,
311,
1086,
314,
922,
367,
3932,
3031,
2287,
436,
2529,
652,
14,
819,
710,
2061,
1202,
3031,
2287,
365,
6290,
370,
282,
570,
436,
402,
22941,
1536,
465,
282,
18453,
1636,
523,
370,
314,
922,
14,
982,
314,
922,
299,
4357,
9509,
1928,
14090,
315,
7003,
314,
2061,
523,
1202,
3031,
2287,
365,
1202,
14,
982,
314,
922,
655,
878,
282,
892,
2287,
12,
652,
365,
6290,
523,
367,
2163,
900,
781,
8457,
14,
819,
408,
523,
2061,
63,
2123,
63,
493,
63,
354,
275,
747,
14,
515,
14,
12131,
20793,
8083,
2019,
63,
600,
8578,
63,
2123,
63,
1562,
531,
523,
2061,
63,
2123,
275,
3087,
523,
340,
747,
14,
515,
14,
2444,
8,
2019,
63,
2123,
63,
493,
63,
354,
304,
272,
862,
26,
489,
2061,
63,
2123,
63,
493,
275,
1551,
8,
2019,
63,
2123,
63,
493,
63,
354,
12,
298,
82,
531,
489,
2061,
63,
2123,
275,
2061,
63,
2123,
63,
493,
14,
6407,
1252,
1913,
4582,
78,
531,
489,
2061,
63,
2123,
63,
493,
14,
1600,
342,
489,
8457,
847,
298,
8978,
83,
8480,
450,
2061,
63,
2123,
272,
871,
5925,
12,
325,
26,
489,
986,
523,
3031,
275,
3066,
63,
1210,
8,
7650,
435,
7244,
298,
680,
1913,
342,
523,
340,
3031,
26,
272,
862,
26,
489,
2061,
63,
2123,
63,
493,
275,
1551,
8,
2019,
63,
2123,
63,
493,
63,
354,
12,
298,
87,
531,
489,
2061,
63,
2123,
63,
493,
14,
952,
8,
2123,
9,
489,
2061,
63,
2123,
63,
493,
14,
1600,
342,
272,
871,
5925,
12,
325,
26,
489,
986,
523,
587,
26,
272,
3031,
275,
2061,
63,
2123,
523,
372,
3031,
421,
199,
318,
9795,
4152,
8,
1328,
304,
523,
408,
5375,
282,
2004,
1245,
370,
3839,
14,
819,
982,
283,
9833,
7,
365,
8932,
2419,
378,
12,
870,
314,
1245,
14,
819,
3033,
26,
272,
1499,
26,
710,
1059,
370,
870,
14,
523,
408,
523,
340,
8661,
690,
378,
26,
272,
870,
1499,
421,
199,
318,
28379,
8,
1328,
304,
523,
408,
5375,
376,
1125,
1245,
370,
4635,
436,
4458,
1041,
523,
870,
4331,
1274,
14,
3083,
12,
1499,
523,
984,
14,
2224,
8,
17,
9,
421,
199,
533,
6810,
8880,
547,
8,
4078,
18,
14,
12815,
304,
523,
408,
16894,
370,
6623,
2337,
1990,
376,
1125,
28532,
1958,
543,
6810,
8880,
1041,
819,
347,
636,
826,
721,
277,
12,
1166,
12,
1233,
12,
1499,
12,
2323,
12,
1249,
304,
272,
4011,
18,
14,
12815,
855,
826,
721,
277,
12,
1166,
12,
1233,
12,
1499,
12,
2323,
12,
488,
9,
272,
291,
14,
589,
275,
1249,
272,
291,
14,
5764,
275,
1249,
905,
547,
937,
421,
199,
533,
11836,
30980,
8,
785,
304,
523,
408,
17473,
282,
2863,
3217,
367,
282,
3486,
11785,
1654,
1041,
819,
347,
636,
826,
721,
277,
12,
1591,
12,
1790,
63,
1593,
12,
1591,
63,
4415,
29,
403,
12,
2402,
63,
2139,
10324,
2049,
3354,
63,
7792,
29,
797,
304,
272,
408,
10607,
282,
892,
4760,
30980,
14,
339,
3033,
26,
489,
1591,
26,
710,
1591,
370,
3222,
4145,
370,
14,
489,
1790,
63,
1593,
26,
437,
805,
626,
6181,
949,
2368,
436,
2529,
376,
267,
334,
2123,
12,
2505,
9,
2008,
1380,
2797,
14,
12823,
506,
2797,
340,
6299,
267,
365,
1415,
14,
489,
1591,
63,
4415,
26,
710,
1591,
1406,
370,
3222,
370,
314,
1654,
334,
4322,
370,
1591,
680,
489,
2402,
63,
2139,
26,
437,
1211,
402,
2402,
2323,
370,
5666,
370,
4036,
1056,
14,
489,
3354,
63,
7792,
26,
982,
715,
12,
3354,
314,
6299,
10049,
370,
2257,
4543,
14,
267,
982,
756,
12,
675,
376,
315,
13,
4844,
29038,
3140,
14,
221,
20196,
1471,
267,
5669,
642,
9330,
14,
221,
7827,
370,
756,
14,
272,
408,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
huoxudong125/poedit
|
deps/boost/tools/build/src/build/engine.py
|
14
|
7374
|
# Copyright Pedro Ferreira 2005.
# Copyright Vladimir Prus 2007.
# Distributed under the Boost
# Software License, Version 1.0. (See accompanying
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
bjam_interface = __import__('bjam')
import operator
import re
import b2.build.property_set as property_set
import b2.util
class BjamAction:
"""Class representing bjam action defined from Python."""
def __init__(self, action_name, function):
self.action_name = action_name
self.function = function
def __call__(self, targets, sources, property_set):
# Bjam actions defined from Python have only the command
# to execute, and no associated jam procedural code. So
# passing 'property_set' to it is not necessary.
bjam_interface.call("set-update-action", self.action_name,
targets, sources, [])
if self.function:
self.function(targets, sources, property_set)
class BjamNativeAction:
"""Class representing bjam action defined by Jam code.
We still allow to associate a Python callable that will
be called when this action is installed on any target.
"""
def __init__(self, action_name, function):
self.action_name = action_name
self.function = function
def __call__(self, targets, sources, property_set):
if self.function:
self.function(targets, sources, property_set)
p = []
if property_set:
p = property_set.raw()
b2.util.set_jam_action(self.action_name, targets, sources, p)
action_modifiers = {"updated": 0x01,
"together": 0x02,
"ignore": 0x04,
"quietly": 0x08,
"piecemeal": 0x10,
"existing": 0x20}
class Engine:
""" The abstract interface to a build engine.
For now, the naming of targets, and special handling of some
target variables like SEARCH and LOCATE make this class coupled
to bjam engine.
"""
def __init__ (self):
self.actions = {}
def add_dependency (self, targets, sources):
"""Adds a dependency from 'targets' to 'sources'
Both 'targets' and 'sources' can be either list
of target names, or a single target name.
"""
if isinstance (targets, str):
targets = [targets]
if isinstance (sources, str):
sources = [sources]
for target in targets:
for source in sources:
self.do_add_dependency (target, source)
def get_target_variable(self, targets, variable):
"""Gets the value of `variable` on set on the first target in `targets`.
Args:
targets (str or list): one or more targets to get the variable from.
variable (str): the name of the variable
Returns:
the value of `variable` set on `targets` (list)
Example:
>>> ENGINE = get_manager().engine()
>>> ENGINE.set_target_variable(targets, 'MY-VAR', 'Hello World')
>>> ENGINE.get_target_variable(targets, 'MY-VAR')
['Hello World']
Equivalent Jam code:
MY-VAR on $(targets) = "Hello World" ;
echo [ on $(targets) return $(MY-VAR) ] ;
"Hello World"
"""
return bjam_interface.call('get-target-variable', targets, variable)
def set_target_variable (self, targets, variable, value, append=0):
""" Sets a target variable.
The 'variable' will be available to bjam when it decides
where to generate targets, and will also be available to
updating rule for that 'taret'.
"""
if isinstance (targets, str):
targets = [targets]
for target in targets:
self.do_set_target_variable (target, variable, value, append)
def set_update_action (self, action_name, targets, sources, properties=property_set.empty()):
""" Binds a target to the corresponding update action.
If target needs to be updated, the action registered
with action_name will be used.
The 'action_name' must be previously registered by
either 'register_action' or 'register_bjam_action'
method.
"""
assert(isinstance(properties, property_set.PropertySet))
if isinstance (targets, str):
targets = [targets]
self.do_set_update_action (action_name, targets, sources, properties)
def register_action (self, action_name, command, bound_list = [], flags = [],
function = None):
"""Creates a new build engine action.
Creates on bjam side an action named 'action_name', with
'command' as the command to be executed, 'bound_variables'
naming the list of variables bound when the command is executed
and specified flag.
If 'function' is not None, it should be a callable taking three
parameters:
- targets
- sources
- instance of the property_set class
This function will be called by set_update_action, and can
set additional target variables.
"""
if self.actions.has_key(action_name):
raise "Bjam action %s is already defined" % action_name
assert(isinstance(flags, list))
bjam_flags = reduce(operator.or_,
(action_modifiers[flag] for flag in flags), 0)
# We allow command to be empty so that we can define 'action' as pure
# python function that would do some conditional logic and then relay
# to other actions.
assert command or function
if command:
bjam_interface.define_action(action_name, command, bound_list, bjam_flags)
self.actions[action_name] = BjamAction(action_name, function)
def register_bjam_action (self, action_name, function=None):
"""Informs self that 'action_name' is declared in bjam.
From this point, 'action_name' is a valid argument to the
set_update_action method. The action_name should be callable
in the global module of bjam.
"""
# We allow duplicate calls to this rule for the same
# action name. This way, jamfile rules that take action names
# can just register them without specially checking if
# action is already registered.
if not self.actions.has_key(action_name):
self.actions[action_name] = BjamNativeAction(action_name, function)
# Overridables
def do_set_update_action (self, action_name, targets, sources, property_set):
action = self.actions.get(action_name)
if not action:
raise Exception("No action %s was registered" % action_name)
action(targets, sources, property_set)
def do_set_target_variable (self, target, variable, value, append):
if append:
bjam_interface.call("set-target-variable", target, variable, value, "true")
else:
bjam_interface.call("set-target-variable", target, variable, value)
def do_add_dependency (self, target, source):
bjam_interface.call("DEPENDS", target, source)
|
mit
|
[
3,
1898,
510,
379,
293,
481,
281,
264,
20936,
11811,
14,
199,
3,
1898,
812,
416,
3572,
723,
510,
20791,
10219,
14,
199,
3,
17484,
1334,
314,
30470,
199,
3,
2290,
844,
12,
3394,
413,
14,
16,
14,
334,
9295,
23073,
199,
3,
570,
5113,
63,
17,
63,
16,
14,
2424,
503,
1331,
737,
1455,
921,
1544,
14,
15589,
14,
1308,
15,
3961,
63,
17,
63,
16,
14,
2424,
9,
199,
199,
468,
455,
63,
3266,
275,
636,
646,
19734,
468,
455,
358,
199,
199,
646,
4182,
199,
646,
295,
199,
199,
646,
330,
18,
14,
1506,
14,
1829,
63,
409,
465,
3324,
63,
409,
199,
646,
330,
18,
14,
1974,
199,
199,
533,
699,
16997,
3310,
26,
272,
408,
2543,
6144,
330,
16997,
1595,
3247,
687,
2018,
1041,
2286,
347,
636,
826,
721,
277,
12,
1595,
63,
354,
12,
805,
304,
267,
291,
14,
1287,
63,
354,
275,
1595,
63,
354,
267,
291,
14,
1593,
275,
805,
15567,
347,
636,
1250,
721,
277,
12,
4545,
12,
5274,
12,
3324,
63,
409,
304,
398,
327,
699,
16997,
5445,
3247,
687,
2018,
1172,
1454,
314,
1414,
267,
327,
370,
5341,
12,
436,
949,
4568,
1335,
455,
557,
6867,
4889,
1233,
14,
2002,
267,
327,
9476,
283,
1829,
63,
409,
7,
370,
652,
365,
440,
5784,
14,
267,
330,
16997,
63,
3266,
14,
1250,
480,
409,
13,
873,
13,
1287,
401,
291,
14,
1287,
63,
354,
12,
1169,
4545,
12,
5274,
12,
3073,
267,
340,
291,
14,
1593,
26,
288,
291,
14,
1593,
8,
4684,
12,
5274,
12,
3324,
63,
409,
9,
199,
199,
533,
699,
16997,
19675,
3310,
26,
272,
408,
2543,
6144,
330,
16997,
1595,
3247,
701,
1603,
455,
1233,
14,
339,
2136,
5139,
2040,
370,
20133,
282,
2018,
4550,
626,
911,
272,
506,
2797,
1380,
642,
1595,
365,
4903,
641,
1263,
1347,
14,
272,
408,
2286,
347,
636,
826,
721,
277,
12,
1595,
63,
354,
12,
805,
304,
267,
291,
14,
1287,
63,
354,
275,
1595,
63,
354,
267,
291,
14,
1593,
275,
805,
5493,
347,
636,
1250,
721,
277,
12,
4545,
12,
5274,
12,
3324,
63,
409,
304,
267,
340,
291,
14,
1593,
26,
288,
291,
14,
1593,
8,
4684,
12,
5274,
12,
3324,
63,
409,
9,
2728,
299,
275,
942,
267,
340,
3324,
63,
409,
26,
288,
299,
275,
3324,
63,
409,
14,
1773,
342,
398,
330,
18,
14,
1974,
14,
409,
63,
16997,
63,
1287,
8,
277,
14,
1287,
63,
354,
12,
4545,
12,
5274,
12,
299,
9,
268,
199,
1287,
63,
17431,
275,
2420,
5334,
582,
378,
88,
614,
12,
490,
298,
6314,
582,
378,
88,
996,
12,
490,
298,
4247,
582,
378,
88,
966,
12,
490,
298,
10243,
590,
582,
378,
88,
2036,
12,
490,
298,
20082,
278,
279,
582,
378,
88,
709,
12,
490,
298,
5952,
582,
378,
88,
1165,
93,
199,
199,
533,
12580,
26,
272,
408,
710,
9006,
3217,
370,
282,
1900,
6869,
14,
339,
2104,
3063,
12,
314,
19720,
402,
4545,
12,
436,
4539,
7252,
402,
2005,
272,
1347,
2860,
2839,
5795,
7762,
436,
3412,
35,
1951,
1852,
642,
1021,
512,
10769,
272,
370,
330,
16997,
6869,
14,
272,
408,
272,
347,
636,
826,
363,
334,
277,
304,
267,
291,
14,
3723,
275,
1052,
339,
347,
1050,
63,
8575,
334,
277,
12,
4545,
12,
5274,
304,
267,
408,
14995,
282,
5936,
687,
283,
4684,
7,
370,
283,
4553,
7,
398,
17650,
283,
4684,
7,
436,
283,
4553,
7,
883,
506,
1902,
769,
267,
402,
1347,
1561,
12,
503,
282,
2849,
1347,
536,
14,
267,
408,
267,
340,
1228,
334,
4684,
12,
620,
304,
288,
4545,
275,
359,
4684,
61,
267,
340,
1228,
334,
4553,
12,
620,
304,
288,
5274,
275,
359,
4553,
61,
398,
367,
1347,
315,
4545,
26,
288,
367,
1350,
315,
5274,
26,
355,
291,
14,
1117,
63,
525,
63,
8575,
334,
1375,
12,
1350,
9,
339,
347,
664,
63,
1375,
63,
1975,
8,
277,
12,
4545,
12,
1750,
304,
267,
408,
14426,
314,
574,
402,
658,
1975,
64,
641,
663,
641,
314,
1642,
1347,
315,
658,
4684,
2313,
398,
3033,
26,
288,
4545,
334,
495,
503,
769,
304,
1373,
503,
1655,
4545,
370,
664,
314,
1750,
687,
14,
288,
1750,
334,
495,
304,
314,
536,
402,
314,
1750,
398,
1803,
26,
1467,
314,
574,
402,
658,
1975,
64,
663,
641,
658,
4684,
64,
334,
513,
9,
398,
5679,
26,
953,
1306,
5070,
14331,
275,
664,
63,
2609,
1252,
3908,
342,
288,
1306,
5070,
14331,
14,
409,
63,
1375,
63,
1975,
8,
4684,
12,
283,
12339,
13,
5568,
297,
283,
6257,
13064,
358,
288,
1306,
5070,
14331,
14,
362,
63,
1375,
63,
1975,
8,
4684,
12,
283,
12339,
13,
5568,
358,
288,
788,
6257,
13064,
418,
398,
24228,
1603,
455,
1233,
26,
953,
603,
57,
13,
5568,
641,
7714,
4684,
9,
275,
298,
6257,
13064,
2,
8700,
288,
11343,
359,
641,
7714,
4684,
9,
372,
7714,
12339,
13,
5568,
9,
1622,
8700,
288,
298,
6257,
13064,
2,
267,
408,
267,
372,
330,
16997,
63,
3266,
14,
1250,
360,
362,
13,
1375,
13,
1975,
297,
4545,
12,
1750,
9,
339,
347,
663,
63,
1375,
63,
1975,
334,
277,
12,
4545,
12,
1750,
12,
574,
12,
5666,
29,
16,
304,
267,
408,
10729,
282,
1347,
1750,
14,
398,
710,
283,
1975,
7,
911,
506,
2808,
370,
330,
16997,
1380,
652,
12985,
3424,
267,
2382,
370,
3550,
4545,
12,
436,
911,
2597,
506,
2808,
370,
267,
12928,
2332,
367,
626,
283,
502,
3292,
1370,
267,
408,
267,
340,
1228,
334,
4684,
12,
620,
304,
7205,
4545,
275,
359,
4684,
61,
398,
367,
1347,
315,
4545,
26,
288,
291,
14,
1117,
63,
409,
63,
1375,
63,
1975,
334,
1375,
12,
1750,
12,
574,
12,
5666,
9,
339,
347,
663,
63,
873,
63,
1287,
334,
277,
12,
1595,
63,
354,
12,
4545,
12,
5274,
12,
4382,
29,
1829,
63,
409,
14,
1667,
5109,
267,
408,
699,
18212,
282,
1347,
370,
314,
5226,
1678,
1595,
14,
288,
982,
1347,
4839,
370,
506,
4588,
12,
314,
1595,
7264,
288,
543,
1595,
63,
354,
911,
506,
1202,
14,
288,
710,
283,
1287,
63,
354,
7,
1471,
506,
10889,
7264,
701,
288,
1902,
283,
2683,
63,
1287,
7,
503,
283,
2683
] |
[
1898,
510,
379,
293,
481,
281,
264,
20936,
11811,
14,
199,
3,
1898,
812,
416,
3572,
723,
510,
20791,
10219,
14,
199,
3,
17484,
1334,
314,
30470,
199,
3,
2290,
844,
12,
3394,
413,
14,
16,
14,
334,
9295,
23073,
199,
3,
570,
5113,
63,
17,
63,
16,
14,
2424,
503,
1331,
737,
1455,
921,
1544,
14,
15589,
14,
1308,
15,
3961,
63,
17,
63,
16,
14,
2424,
9,
199,
199,
468,
455,
63,
3266,
275,
636,
646,
19734,
468,
455,
358,
199,
199,
646,
4182,
199,
646,
295,
199,
199,
646,
330,
18,
14,
1506,
14,
1829,
63,
409,
465,
3324,
63,
409,
199,
646,
330,
18,
14,
1974,
199,
199,
533,
699,
16997,
3310,
26,
272,
408,
2543,
6144,
330,
16997,
1595,
3247,
687,
2018,
1041,
2286,
347,
636,
826,
721,
277,
12,
1595,
63,
354,
12,
805,
304,
267,
291,
14,
1287,
63,
354,
275,
1595,
63,
354,
267,
291,
14,
1593,
275,
805,
15567,
347,
636,
1250,
721,
277,
12,
4545,
12,
5274,
12,
3324,
63,
409,
304,
398,
327,
699,
16997,
5445,
3247,
687,
2018,
1172,
1454,
314,
1414,
267,
327,
370,
5341,
12,
436,
949,
4568,
1335,
455,
557,
6867,
4889,
1233,
14,
2002,
267,
327,
9476,
283,
1829,
63,
409,
7,
370,
652,
365,
440,
5784,
14,
267,
330,
16997,
63,
3266,
14,
1250,
480,
409,
13,
873,
13,
1287,
401,
291,
14,
1287,
63,
354,
12,
1169,
4545,
12,
5274,
12,
3073,
267,
340,
291,
14,
1593,
26,
288,
291,
14,
1593,
8,
4684,
12,
5274,
12,
3324,
63,
409,
9,
199,
199,
533,
699,
16997,
19675,
3310,
26,
272,
408,
2543,
6144,
330,
16997,
1595,
3247,
701,
1603,
455,
1233,
14,
339,
2136,
5139,
2040,
370,
20133,
282,
2018,
4550,
626,
911,
272,
506,
2797,
1380,
642,
1595,
365,
4903,
641,
1263,
1347,
14,
272,
408,
2286,
347,
636,
826,
721,
277,
12,
1595,
63,
354,
12,
805,
304,
267,
291,
14,
1287,
63,
354,
275,
1595,
63,
354,
267,
291,
14,
1593,
275,
805,
5493,
347,
636,
1250,
721,
277,
12,
4545,
12,
5274,
12,
3324,
63,
409,
304,
267,
340,
291,
14,
1593,
26,
288,
291,
14,
1593,
8,
4684,
12,
5274,
12,
3324,
63,
409,
9,
2728,
299,
275,
942,
267,
340,
3324,
63,
409,
26,
288,
299,
275,
3324,
63,
409,
14,
1773,
342,
398,
330,
18,
14,
1974,
14,
409,
63,
16997,
63,
1287,
8,
277,
14,
1287,
63,
354,
12,
4545,
12,
5274,
12,
299,
9,
268,
199,
1287,
63,
17431,
275,
2420,
5334,
582,
378,
88,
614,
12,
490,
298,
6314,
582,
378,
88,
996,
12,
490,
298,
4247,
582,
378,
88,
966,
12,
490,
298,
10243,
590,
582,
378,
88,
2036,
12,
490,
298,
20082,
278,
279,
582,
378,
88,
709,
12,
490,
298,
5952,
582,
378,
88,
1165,
93,
199,
199,
533,
12580,
26,
272,
408,
710,
9006,
3217,
370,
282,
1900,
6869,
14,
339,
2104,
3063,
12,
314,
19720,
402,
4545,
12,
436,
4539,
7252,
402,
2005,
272,
1347,
2860,
2839,
5795,
7762,
436,
3412,
35,
1951,
1852,
642,
1021,
512,
10769,
272,
370,
330,
16997,
6869,
14,
272,
408,
272,
347,
636,
826,
363,
334,
277,
304,
267,
291,
14,
3723,
275,
1052,
339,
347,
1050,
63,
8575,
334,
277,
12,
4545,
12,
5274,
304,
267,
408,
14995,
282,
5936,
687,
283,
4684,
7,
370,
283,
4553,
7,
398,
17650,
283,
4684,
7,
436,
283,
4553,
7,
883,
506,
1902,
769,
267,
402,
1347,
1561,
12,
503,
282,
2849,
1347,
536,
14,
267,
408,
267,
340,
1228,
334,
4684,
12,
620,
304,
288,
4545,
275,
359,
4684,
61,
267,
340,
1228,
334,
4553,
12,
620,
304,
288,
5274,
275,
359,
4553,
61,
398,
367,
1347,
315,
4545,
26,
288,
367,
1350,
315,
5274,
26,
355,
291,
14,
1117,
63,
525,
63,
8575,
334,
1375,
12,
1350,
9,
339,
347,
664,
63,
1375,
63,
1975,
8,
277,
12,
4545,
12,
1750,
304,
267,
408,
14426,
314,
574,
402,
658,
1975,
64,
641,
663,
641,
314,
1642,
1347,
315,
658,
4684,
2313,
398,
3033,
26,
288,
4545,
334,
495,
503,
769,
304,
1373,
503,
1655,
4545,
370,
664,
314,
1750,
687,
14,
288,
1750,
334,
495,
304,
314,
536,
402,
314,
1750,
398,
1803,
26,
1467,
314,
574,
402,
658,
1975,
64,
663,
641,
658,
4684,
64,
334,
513,
9,
398,
5679,
26,
953,
1306,
5070,
14331,
275,
664,
63,
2609,
1252,
3908,
342,
288,
1306,
5070,
14331,
14,
409,
63,
1375,
63,
1975,
8,
4684,
12,
283,
12339,
13,
5568,
297,
283,
6257,
13064,
358,
288,
1306,
5070,
14331,
14,
362,
63,
1375,
63,
1975,
8,
4684,
12,
283,
12339,
13,
5568,
358,
288,
788,
6257,
13064,
418,
398,
24228,
1603,
455,
1233,
26,
953,
603,
57,
13,
5568,
641,
7714,
4684,
9,
275,
298,
6257,
13064,
2,
8700,
288,
11343,
359,
641,
7714,
4684,
9,
372,
7714,
12339,
13,
5568,
9,
1622,
8700,
288,
298,
6257,
13064,
2,
267,
408,
267,
372,
330,
16997,
63,
3266,
14,
1250,
360,
362,
13,
1375,
13,
1975,
297,
4545,
12,
1750,
9,
339,
347,
663,
63,
1375,
63,
1975,
334,
277,
12,
4545,
12,
1750,
12,
574,
12,
5666,
29,
16,
304,
267,
408,
10729,
282,
1347,
1750,
14,
398,
710,
283,
1975,
7,
911,
506,
2808,
370,
330,
16997,
1380,
652,
12985,
3424,
267,
2382,
370,
3550,
4545,
12,
436,
911,
2597,
506,
2808,
370,
267,
12928,
2332,
367,
626,
283,
502,
3292,
1370,
267,
408,
267,
340,
1228,
334,
4684,
12,
620,
304,
7205,
4545,
275,
359,
4684,
61,
398,
367,
1347,
315,
4545,
26,
288,
291,
14,
1117,
63,
409,
63,
1375,
63,
1975,
334,
1375,
12,
1750,
12,
574,
12,
5666,
9,
339,
347,
663,
63,
873,
63,
1287,
334,
277,
12,
1595,
63,
354,
12,
4545,
12,
5274,
12,
4382,
29,
1829,
63,
409,
14,
1667,
5109,
267,
408,
699,
18212,
282,
1347,
370,
314,
5226,
1678,
1595,
14,
288,
982,
1347,
4839,
370,
506,
4588,
12,
314,
1595,
7264,
288,
543,
1595,
63,
354,
911,
506,
1202,
14,
288,
710,
283,
1287,
63,
354,
7,
1471,
506,
10889,
7264,
701,
288,
1902,
283,
2683,
63,
1287,
7,
503,
283,
2683,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
openiitbombayx/edx-platform
|
lms/djangoapps/courseware/tests/test_favicon.py
|
125
|
1841
|
from django.conf import settings
from django.core.urlresolvers import clear_url_caches, resolve
from django.test import TestCase
from django.test.utils import override_settings
from mock import patch
from nose.plugins.attrib import attr
import sys
@attr('shard_1')
class FaviconTestCase(TestCase):
def setUp(self):
super(FaviconTestCase, self).setUp()
def test_favicon_redirect(self):
resp = self.client.get("/favicon.ico")
self.assertEqual(resp.status_code, 301)
self.assertRedirects(
resp,
"/static/images/favicon.ico",
status_code=301, target_status_code=404 # @@@ how to avoid 404?
)
@override_settings(FAVICON_PATH="images/foo.ico")
def test_favicon_redirect_with_favicon_path_setting(self):
# for some reason I had to put this inline rather than just using
# the UrlResetMixin
urlconf = settings.ROOT_URLCONF
if urlconf in sys.modules:
reload(sys.modules[urlconf])
clear_url_caches()
resolve("/")
resp = self.client.get("/favicon.ico")
self.assertEqual(resp.status_code, 301)
self.assertRedirects(
resp,
"/static/images/foo.ico",
status_code=301, target_status_code=404 # @@@ how to avoid 404?
)
@patch.dict("django.conf.settings.FEATURES", {"USE_CUSTOM_THEME": True})
@override_settings(THEME_NAME="bar")
def test_favicon_redirect_with_theme(self):
self.assertEqual(settings.FEATURES["USE_CUSTOM_THEME"], True)
resp = self.client.get("/favicon.ico")
self.assertEqual(resp.status_code, 301)
self.assertRedirects(
resp,
"/static/images/foo.ico",
status_code=301, target_status_code=404 # @@@ how to avoid 404?
)
|
agpl-3.0
|
[
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1018,
14,
16522,
492,
5436,
63,
633,
63,
17595,
12,
7512,
199,
199,
504,
1639,
14,
396,
492,
7640,
199,
504,
1639,
14,
396,
14,
1208,
492,
4278,
63,
1751,
199,
199,
504,
1683,
492,
3371,
199,
504,
11354,
14,
5265,
14,
6640,
492,
1921,
199,
199,
646,
984,
421,
199,
32,
962,
360,
10810,
63,
17,
358,
199,
533,
481,
7194,
388,
1746,
8,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
1906,
16700,
1746,
12,
291,
680,
5996,
342,
339,
347,
511,
63,
22229,
63,
4876,
8,
277,
304,
267,
3085,
275,
291,
14,
1258,
14,
362,
4769,
22229,
14,
12802,
531,
267,
291,
14,
629,
8,
4518,
14,
1205,
63,
600,
12,
19660,
9,
267,
291,
14,
17466,
8,
288,
3085,
12,
288,
3286,
1986,
15,
4782,
15,
22229,
14,
12802,
401,
288,
2004,
63,
600,
29,
8507,
12,
1347,
63,
1205,
63,
600,
29,
5188,
221,
327,
768,
7492,
4212,
370,
5126,
7901,
31,
267,
776,
339,
768,
4415,
63,
1751,
8,
2078,
54,
15903,
63,
3243,
628,
4782,
15,
1421,
14,
12802,
531,
272,
347,
511,
63,
22229,
63,
4876,
63,
1045,
63,
22229,
63,
515,
63,
6031,
8,
277,
304,
398,
327,
367,
2005,
4499,
473,
10530,
370,
5324,
642,
8308,
7830,
2419,
2951,
1808,
267,
327,
314,
20503,
9637,
4256,
398,
30009,
275,
2202,
14,
5441,
63,
18125,
267,
340,
30009,
315,
984,
14,
3112,
26,
288,
13101,
8,
1274,
14,
3112,
59,
21801,
566,
267,
5436,
63,
633,
63,
17595,
342,
267,
7512,
19031,
398,
3085,
275,
291,
14,
1258,
14,
362,
4769,
22229,
14,
12802,
531,
267,
291,
14,
629,
8,
4518,
14,
1205,
63,
600,
12,
19660,
9,
267,
291,
14,
17466,
8,
288,
3085,
12,
288,
3286,
1986,
15,
4782,
15,
1421,
14,
12802,
401,
288,
2004,
63,
600,
29,
8507,
12,
1347,
63,
1205,
63,
600,
29,
5188,
221,
327,
768,
7492,
4212,
370,
5126,
7901,
31,
267,
776,
339,
768,
2068,
14,
807,
480,
1176,
14,
2190,
14,
1751,
14,
13313,
401,
2420,
4701,
63,
20519,
63,
18061,
3635,
582,
715,
1552,
272,
768,
4415,
63,
1751,
8,
18061,
3635,
63,
2339,
628,
1700,
531,
272,
347,
511,
63,
22229,
63,
4876,
63,
1045,
63,
7915,
8,
277,
304,
267,
291,
14,
629,
8,
1751,
14,
13313,
905,
4701,
63,
20519,
63,
18061,
3635,
2255,
715,
9,
398,
3085,
275,
291,
14,
1258,
14,
362,
4769,
22229,
14,
12802,
531,
267,
291,
14,
629,
8,
4518,
14,
1205,
63,
600,
12,
19660,
9,
267,
291,
14,
17466,
8,
288,
3085,
12,
288,
3286,
1986,
15,
4782,
15,
1421,
14,
12802,
401,
288,
2004,
63,
600,
29,
8507,
12,
1347,
63,
1205,
63,
600,
29,
5188,
221,
327,
768,
7492,
4212,
370,
5126,
7901,
31,
267,
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
] |
[
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1018,
14,
16522,
492,
5436,
63,
633,
63,
17595,
12,
7512,
199,
199,
504,
1639,
14,
396,
492,
7640,
199,
504,
1639,
14,
396,
14,
1208,
492,
4278,
63,
1751,
199,
199,
504,
1683,
492,
3371,
199,
504,
11354,
14,
5265,
14,
6640,
492,
1921,
199,
199,
646,
984,
421,
199,
32,
962,
360,
10810,
63,
17,
358,
199,
533,
481,
7194,
388,
1746,
8,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
1906,
16700,
1746,
12,
291,
680,
5996,
342,
339,
347,
511,
63,
22229,
63,
4876,
8,
277,
304,
267,
3085,
275,
291,
14,
1258,
14,
362,
4769,
22229,
14,
12802,
531,
267,
291,
14,
629,
8,
4518,
14,
1205,
63,
600,
12,
19660,
9,
267,
291,
14,
17466,
8,
288,
3085,
12,
288,
3286,
1986,
15,
4782,
15,
22229,
14,
12802,
401,
288,
2004,
63,
600,
29,
8507,
12,
1347,
63,
1205,
63,
600,
29,
5188,
221,
327,
768,
7492,
4212,
370,
5126,
7901,
31,
267,
776,
339,
768,
4415,
63,
1751,
8,
2078,
54,
15903,
63,
3243,
628,
4782,
15,
1421,
14,
12802,
531,
272,
347,
511,
63,
22229,
63,
4876,
63,
1045,
63,
22229,
63,
515,
63,
6031,
8,
277,
304,
398,
327,
367,
2005,
4499,
473,
10530,
370,
5324,
642,
8308,
7830,
2419,
2951,
1808,
267,
327,
314,
20503,
9637,
4256,
398,
30009,
275,
2202,
14,
5441,
63,
18125,
267,
340,
30009,
315,
984,
14,
3112,
26,
288,
13101,
8,
1274,
14,
3112,
59,
21801,
566,
267,
5436,
63,
633,
63,
17595,
342,
267,
7512,
19031,
398,
3085,
275,
291,
14,
1258,
14,
362,
4769,
22229,
14,
12802,
531,
267,
291,
14,
629,
8,
4518,
14,
1205,
63,
600,
12,
19660,
9,
267,
291,
14,
17466,
8,
288,
3085,
12,
288,
3286,
1986,
15,
4782,
15,
1421,
14,
12802,
401,
288,
2004,
63,
600,
29,
8507,
12,
1347,
63,
1205,
63,
600,
29,
5188,
221,
327,
768,
7492,
4212,
370,
5126,
7901,
31,
267,
776,
339,
768,
2068,
14,
807,
480,
1176,
14,
2190,
14,
1751,
14,
13313,
401,
2420,
4701,
63,
20519,
63,
18061,
3635,
582,
715,
1552,
272,
768,
4415,
63,
1751,
8,
18061,
3635,
63,
2339,
628,
1700,
531,
272,
347,
511,
63,
22229,
63,
4876,
63,
1045,
63,
7915,
8,
277,
304,
267,
291,
14,
629,
8,
1751,
14,
13313,
905,
4701,
63,
20519,
63,
18061,
3635,
2255,
715,
9,
398,
3085,
275,
291,
14,
1258,
14,
362,
4769,
22229,
14,
12802,
531,
267,
291,
14,
629,
8,
4518,
14,
1205,
63,
600,
12,
19660,
9,
267,
291,
14,
17466,
8,
288,
3085,
12,
288,
3286,
1986,
15,
4782,
15,
1421,
14,
12802,
401,
288,
2004,
63,
600,
29,
8507,
12,
1347,
63,
1205,
63,
600,
29,
5188,
221,
327,
768,
7492,
4212,
370,
5126,
7901,
31,
267,
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,
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
] |
CristianBB/SickRage
|
lib/unidecode/x0fc.py
|
253
|
3595
|
data = (
'', # 0x00
'', # 0x01
'', # 0x02
'', # 0x03
'', # 0x04
'', # 0x05
'', # 0x06
'', # 0x07
'', # 0x08
'', # 0x09
'', # 0x0a
'', # 0x0b
'', # 0x0c
'', # 0x0d
'', # 0x0e
'', # 0x0f
'', # 0x10
'', # 0x11
'', # 0x12
'', # 0x13
'', # 0x14
'', # 0x15
'', # 0x16
'', # 0x17
'', # 0x18
'', # 0x19
'', # 0x1a
'', # 0x1b
'', # 0x1c
'', # 0x1d
'', # 0x1e
'', # 0x1f
'', # 0x20
'', # 0x21
'', # 0x22
'', # 0x23
'', # 0x24
'', # 0x25
'', # 0x26
'', # 0x27
'', # 0x28
'', # 0x29
'', # 0x2a
'', # 0x2b
'', # 0x2c
'', # 0x2d
'', # 0x2e
'', # 0x2f
'', # 0x30
'', # 0x31
'', # 0x32
'', # 0x33
'', # 0x34
'', # 0x35
'', # 0x36
'', # 0x37
'', # 0x38
'', # 0x39
'', # 0x3a
'', # 0x3b
'', # 0x3c
'', # 0x3d
'', # 0x3e
'', # 0x3f
'', # 0x40
'', # 0x41
'', # 0x42
'', # 0x43
'', # 0x44
'', # 0x45
'', # 0x46
'', # 0x47
'', # 0x48
'', # 0x49
'', # 0x4a
'', # 0x4b
'', # 0x4c
'', # 0x4d
'', # 0x4e
'', # 0x4f
'', # 0x50
'', # 0x51
'', # 0x52
'', # 0x53
'', # 0x54
'', # 0x55
'', # 0x56
'', # 0x57
'', # 0x58
'', # 0x59
'', # 0x5a
'', # 0x5b
'', # 0x5c
'', # 0x5d
'', # 0x5e
'', # 0x5f
'', # 0x60
'', # 0x61
'', # 0x62
'', # 0x63
'', # 0x64
'', # 0x65
'', # 0x66
'', # 0x67
'', # 0x68
'', # 0x69
'', # 0x6a
'', # 0x6b
'', # 0x6c
'', # 0x6d
'', # 0x6e
'', # 0x6f
'', # 0x70
'', # 0x71
'', # 0x72
'', # 0x73
'', # 0x74
'', # 0x75
'', # 0x76
'', # 0x77
'', # 0x78
'', # 0x79
'', # 0x7a
'', # 0x7b
'', # 0x7c
'', # 0x7d
'', # 0x7e
'', # 0x7f
'', # 0x80
'', # 0x81
'', # 0x82
'', # 0x83
'', # 0x84
'', # 0x85
'', # 0x86
'', # 0x87
'', # 0x88
'', # 0x89
'', # 0x8a
'', # 0x8b
'', # 0x8c
'', # 0x8d
'', # 0x8e
'', # 0x8f
'', # 0x90
'', # 0x91
'', # 0x92
'', # 0x93
'', # 0x94
'', # 0x95
'', # 0x96
'', # 0x97
'', # 0x98
'', # 0x99
'', # 0x9a
'', # 0x9b
'', # 0x9c
'', # 0x9d
'', # 0x9e
'', # 0x9f
'', # 0xa0
'', # 0xa1
'', # 0xa2
'', # 0xa3
'', # 0xa4
'', # 0xa5
'', # 0xa6
'', # 0xa7
'', # 0xa8
'', # 0xa9
'', # 0xaa
'', # 0xab
'', # 0xac
'', # 0xad
'', # 0xae
'', # 0xaf
'', # 0xb0
'', # 0xb1
'', # 0xb2
'', # 0xb3
'', # 0xb4
'', # 0xb5
'', # 0xb6
'', # 0xb7
'', # 0xb8
'', # 0xb9
'', # 0xba
'', # 0xbb
'', # 0xbc
'', # 0xbd
'', # 0xbe
'', # 0xbf
'', # 0xc0
'', # 0xc1
'', # 0xc2
'', # 0xc3
'', # 0xc4
'', # 0xc5
'', # 0xc6
'', # 0xc7
'', # 0xc8
'', # 0xc9
'', # 0xca
'', # 0xcb
'', # 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
'', # 0xe6
'', # 0xe7
'', # 0xe8
'', # 0xe9
'', # 0xea
'', # 0xeb
'', # 0xec
'', # 0xed
'', # 0xee
'', # 0xef
'', # 0xf0
'', # 0xf1
'', # 0xf2
'', # 0xf3
'', # 0xf4
'', # 0xf5
'', # 0xf6
'', # 0xf7
'', # 0xf8
'', # 0xf9
'', # 0xfa
'', # 0xfb
'', # 0xfc
'', # 0xfd
'', # 0xfe
'', # 0xff
)
|
gpl-3.0
|
[
576,
275,
334,
199,
6448,
259,
327,
378,
88,
383,
199,
6448,
259,
327,
378,
88,
614,
199,
6448,
259,
327,
378,
88,
996,
199,
6448,
259,
327,
378,
88,
1644,
199,
6448,
259,
327,
378,
88,
966,
199,
6448,
259,
327,
378,
88,
1717,
199,
6448,
259,
327,
378,
88,
1690,
199,
6448,
259,
327,
378,
88,
1780,
199,
6448,
259,
327,
378,
88,
2036,
199,
6448,
259,
327,
378,
88,
1643,
199,
6448,
259,
327,
378,
88,
16,
65,
199,
6448,
259,
327,
378,
88,
16,
66,
199,
6448,
259,
327,
378,
88,
16,
67,
199,
6448,
259,
327,
378,
88,
16,
68,
199,
6448,
259,
327,
378,
88,
16,
69,
199,
6448,
259,
327,
378,
88,
16,
70,
199,
6448,
259,
327,
378,
88,
709,
199,
6448,
259,
327,
378,
88,
845,
199,
6448,
259,
327,
378,
88,
713,
199,
6448,
259,
327,
378,
88,
969,
199,
6448,
259,
327,
378,
88,
1079,
199,
6448,
259,
327,
378,
88,
1046,
199,
6448,
259,
327,
378,
88,
975,
199,
6448,
259,
327,
378,
88,
1196,
199,
6448,
259,
327,
378,
88,
1085,
199,
6448,
259,
327,
378,
88,
1167,
199,
6448,
259,
327,
378,
88,
17,
65,
199,
6448,
259,
327,
378,
88,
17,
66,
199,
6448,
259,
327,
378,
88,
17,
67,
199,
6448,
259,
327,
378,
88,
17,
68,
199,
6448,
259,
327,
378,
88,
17,
69,
199,
6448,
259,
327,
378,
88,
17,
70,
199,
6448,
259,
327,
378,
88,
1165,
199,
6448,
259,
327,
378,
88,
2025,
199,
6448,
259,
327,
378,
88,
1081,
199,
6448,
259,
327,
378,
88,
1789,
199,
6448,
259,
327,
378,
88,
1194,
199,
6448,
259,
327,
378,
88,
821,
199,
6448,
259,
327,
378,
88,
1479,
199,
6448,
259,
327,
378,
88,
1465,
199,
6448,
259,
327,
378,
88,
1651,
199,
6448,
259,
327,
378,
88,
1398,
199,
6448,
259,
327,
378,
88,
18,
65,
199,
6448,
259,
327,
378,
88,
18,
66,
199,
6448,
259,
327,
378,
88,
18,
67,
199,
6448,
259,
327,
378,
88,
18,
68,
199,
6448,
259,
327,
378,
88,
18,
69,
199,
6448,
259,
327,
378,
88,
18,
70,
199,
6448,
259,
327,
378,
88,
1216,
199,
6448,
259,
327,
378,
88,
2192,
199,
6448,
259,
327,
378,
88,
708,
199,
6448,
259,
327,
378,
88,
1153,
199,
6448,
259,
327,
378,
88,
1082,
199,
6448,
259,
327,
378,
88,
1276,
199,
6448,
259,
327,
378,
88,
1344,
199,
6448,
259,
327,
378,
88,
1401,
199,
6448,
259,
327,
378,
88,
1703,
199,
6448,
259,
327,
378,
88,
1355,
199,
6448,
259,
327,
378,
88,
19,
65,
199,
6448,
259,
327,
378,
88,
19,
66,
199,
6448,
259,
327,
378,
88,
19,
67,
199,
6448,
259,
327,
378,
88,
19,
68,
199,
6448,
259,
327,
378,
88,
19,
69,
199,
6448,
259,
327,
378,
88,
19,
70,
199,
6448,
259,
327,
378,
88,
2167,
199,
6448,
259,
327,
378,
88,
2953,
199,
6448,
259,
327,
378,
88,
2260,
199,
6448,
259,
327,
378,
88,
2824,
199,
6448,
259,
327,
378,
88,
1602,
199,
6448,
259,
327,
378,
88,
2322,
199,
6448,
259,
327,
378,
88,
2466,
199,
6448,
259,
327,
378,
88,
2417,
199,
6448,
259,
327,
378,
88,
2006,
199,
6448,
259,
327,
378,
88,
1887,
199,
6448,
259,
327,
378,
88,
20,
65,
199,
6448,
259,
327,
378,
88,
20,
66,
199,
6448,
259,
327,
378,
88,
20,
67,
199,
6448,
259,
327,
378,
88,
20,
68,
199,
6448,
259,
327,
378,
88,
20,
69,
199,
6448,
259,
327,
378,
88,
20,
70,
199,
6448,
259,
327,
378,
88,
1400,
199,
6448,
259,
327,
378,
88,
2869,
199,
6448,
259,
327,
378,
88,
2528,
199,
6448,
259,
327,
378,
88,
2481,
199,
6448,
259,
327,
378,
88,
1477,
199,
6448,
259,
327,
378,
88,
1229,
199,
6448,
259,
327,
378,
88,
1367,
199,
6448,
259,
327,
378,
88,
1641,
199,
6448,
259,
327,
378,
88,
2010,
199,
6448,
259,
327,
378,
88,
1427,
199,
6448,
259,
327,
378,
88,
21,
65,
199,
6448,
259,
327,
378,
88,
21,
66,
199,
6448,
259,
327,
378,
88,
21,
67,
199,
6448,
259,
327,
378,
88,
21,
68,
199,
6448,
259,
327,
378,
88,
21,
69,
199,
6448,
259,
327,
378,
88,
21,
70,
199,
6448,
259,
327,
378,
88,
2259,
199,
6448,
259,
327,
378,
88,
2976,
199,
6448,
259,
327,
378,
88,
2789,
199,
6448,
259,
327,
378,
88,
2766,
199,
6448,
259,
327,
378,
88,
772,
199,
6448,
259,
327,
378,
88,
2182,
199,
6448,
259,
327,
378,
88,
1272,
199,
6448,
259,
327,
378,
88,
1822,
199,
6448,
259,
327,
378,
88,
2333,
199,
6448,
259,
327,
378,
88,
1876,
199,
6448,
259,
327,
378,
88,
22,
65,
199,
6448,
259,
327,
378,
88,
22,
66,
199,
6448,
259,
327,
378,
88,
22,
67,
199,
6448,
259,
327,
378,
88,
22,
68,
199,
6448,
259,
327,
378,
88,
22,
69,
199,
6448,
259,
327,
378,
88,
22,
70,
199,
6448,
259,
327,
378,
88,
2760,
199,
6448,
259,
327,
378,
88,
3172,
199,
6448,
259,
327,
378,
88,
2819,
199,
6448,
259,
327,
378,
88,
2898,
199,
6448,
259,
327,
378,
88,
1342,
199,
6448,
259,
327,
378,
88,
2194,
199,
6448,
259,
327,
378,
88,
2114,
199,
6448,
259,
327,
378,
88,
1138,
199,
6448,
259,
327,
378,
88,
2277,
199,
6448,
259,
327,
378,
88,
1965,
199,
6448,
259,
327,
378,
88,
23,
65,
199,
6448,
259,
327,
378,
88,
23,
66,
199,
6448,
259,
327,
378,
88,
23,
67,
199,
6448,
259,
327,
378,
88,
23,
68,
199,
6448,
259,
327,
378,
88,
23,
69,
199,
6448,
259,
327,
378,
88,
23,
70,
199,
6448,
259,
327,
378,
88,
1257,
199,
6448,
259,
327,
378,
88,
2835,
199,
6448,
259,
327,
378,
88,
2564,
199,
6448,
259,
327,
378,
88,
2658,
199,
6448,
259,
327,
378,
88,
1349,
199,
6448,
259,
327,
378,
88,
2426,
199,
6448,
259,
327,
378,
88,
1184,
199,
6448,
259,
327,
378,
88,
1555,
199,
6448,
259,
327,
378,
88,
1299,
199,
6448,
259,
327,
378,
88,
1407,
199,
6448,
259,
327,
378,
88,
24
] |
[
275,
334,
199,
6448,
259,
327,
378,
88,
383,
199,
6448,
259,
327,
378,
88,
614,
199,
6448,
259,
327,
378,
88,
996,
199,
6448,
259,
327,
378,
88,
1644,
199,
6448,
259,
327,
378,
88,
966,
199,
6448,
259,
327,
378,
88,
1717,
199,
6448,
259,
327,
378,
88,
1690,
199,
6448,
259,
327,
378,
88,
1780,
199,
6448,
259,
327,
378,
88,
2036,
199,
6448,
259,
327,
378,
88,
1643,
199,
6448,
259,
327,
378,
88,
16,
65,
199,
6448,
259,
327,
378,
88,
16,
66,
199,
6448,
259,
327,
378,
88,
16,
67,
199,
6448,
259,
327,
378,
88,
16,
68,
199,
6448,
259,
327,
378,
88,
16,
69,
199,
6448,
259,
327,
378,
88,
16,
70,
199,
6448,
259,
327,
378,
88,
709,
199,
6448,
259,
327,
378,
88,
845,
199,
6448,
259,
327,
378,
88,
713,
199,
6448,
259,
327,
378,
88,
969,
199,
6448,
259,
327,
378,
88,
1079,
199,
6448,
259,
327,
378,
88,
1046,
199,
6448,
259,
327,
378,
88,
975,
199,
6448,
259,
327,
378,
88,
1196,
199,
6448,
259,
327,
378,
88,
1085,
199,
6448,
259,
327,
378,
88,
1167,
199,
6448,
259,
327,
378,
88,
17,
65,
199,
6448,
259,
327,
378,
88,
17,
66,
199,
6448,
259,
327,
378,
88,
17,
67,
199,
6448,
259,
327,
378,
88,
17,
68,
199,
6448,
259,
327,
378,
88,
17,
69,
199,
6448,
259,
327,
378,
88,
17,
70,
199,
6448,
259,
327,
378,
88,
1165,
199,
6448,
259,
327,
378,
88,
2025,
199,
6448,
259,
327,
378,
88,
1081,
199,
6448,
259,
327,
378,
88,
1789,
199,
6448,
259,
327,
378,
88,
1194,
199,
6448,
259,
327,
378,
88,
821,
199,
6448,
259,
327,
378,
88,
1479,
199,
6448,
259,
327,
378,
88,
1465,
199,
6448,
259,
327,
378,
88,
1651,
199,
6448,
259,
327,
378,
88,
1398,
199,
6448,
259,
327,
378,
88,
18,
65,
199,
6448,
259,
327,
378,
88,
18,
66,
199,
6448,
259,
327,
378,
88,
18,
67,
199,
6448,
259,
327,
378,
88,
18,
68,
199,
6448,
259,
327,
378,
88,
18,
69,
199,
6448,
259,
327,
378,
88,
18,
70,
199,
6448,
259,
327,
378,
88,
1216,
199,
6448,
259,
327,
378,
88,
2192,
199,
6448,
259,
327,
378,
88,
708,
199,
6448,
259,
327,
378,
88,
1153,
199,
6448,
259,
327,
378,
88,
1082,
199,
6448,
259,
327,
378,
88,
1276,
199,
6448,
259,
327,
378,
88,
1344,
199,
6448,
259,
327,
378,
88,
1401,
199,
6448,
259,
327,
378,
88,
1703,
199,
6448,
259,
327,
378,
88,
1355,
199,
6448,
259,
327,
378,
88,
19,
65,
199,
6448,
259,
327,
378,
88,
19,
66,
199,
6448,
259,
327,
378,
88,
19,
67,
199,
6448,
259,
327,
378,
88,
19,
68,
199,
6448,
259,
327,
378,
88,
19,
69,
199,
6448,
259,
327,
378,
88,
19,
70,
199,
6448,
259,
327,
378,
88,
2167,
199,
6448,
259,
327,
378,
88,
2953,
199,
6448,
259,
327,
378,
88,
2260,
199,
6448,
259,
327,
378,
88,
2824,
199,
6448,
259,
327,
378,
88,
1602,
199,
6448,
259,
327,
378,
88,
2322,
199,
6448,
259,
327,
378,
88,
2466,
199,
6448,
259,
327,
378,
88,
2417,
199,
6448,
259,
327,
378,
88,
2006,
199,
6448,
259,
327,
378,
88,
1887,
199,
6448,
259,
327,
378,
88,
20,
65,
199,
6448,
259,
327,
378,
88,
20,
66,
199,
6448,
259,
327,
378,
88,
20,
67,
199,
6448,
259,
327,
378,
88,
20,
68,
199,
6448,
259,
327,
378,
88,
20,
69,
199,
6448,
259,
327,
378,
88,
20,
70,
199,
6448,
259,
327,
378,
88,
1400,
199,
6448,
259,
327,
378,
88,
2869,
199,
6448,
259,
327,
378,
88,
2528,
199,
6448,
259,
327,
378,
88,
2481,
199,
6448,
259,
327,
378,
88,
1477,
199,
6448,
259,
327,
378,
88,
1229,
199,
6448,
259,
327,
378,
88,
1367,
199,
6448,
259,
327,
378,
88,
1641,
199,
6448,
259,
327,
378,
88,
2010,
199,
6448,
259,
327,
378,
88,
1427,
199,
6448,
259,
327,
378,
88,
21,
65,
199,
6448,
259,
327,
378,
88,
21,
66,
199,
6448,
259,
327,
378,
88,
21,
67,
199,
6448,
259,
327,
378,
88,
21,
68,
199,
6448,
259,
327,
378,
88,
21,
69,
199,
6448,
259,
327,
378,
88,
21,
70,
199,
6448,
259,
327,
378,
88,
2259,
199,
6448,
259,
327,
378,
88,
2976,
199,
6448,
259,
327,
378,
88,
2789,
199,
6448,
259,
327,
378,
88,
2766,
199,
6448,
259,
327,
378,
88,
772,
199,
6448,
259,
327,
378,
88,
2182,
199,
6448,
259,
327,
378,
88,
1272,
199,
6448,
259,
327,
378,
88,
1822,
199,
6448,
259,
327,
378,
88,
2333,
199,
6448,
259,
327,
378,
88,
1876,
199,
6448,
259,
327,
378,
88,
22,
65,
199,
6448,
259,
327,
378,
88,
22,
66,
199,
6448,
259,
327,
378,
88,
22,
67,
199,
6448,
259,
327,
378,
88,
22,
68,
199,
6448,
259,
327,
378,
88,
22,
69,
199,
6448,
259,
327,
378,
88,
22,
70,
199,
6448,
259,
327,
378,
88,
2760,
199,
6448,
259,
327,
378,
88,
3172,
199,
6448,
259,
327,
378,
88,
2819,
199,
6448,
259,
327,
378,
88,
2898,
199,
6448,
259,
327,
378,
88,
1342,
199,
6448,
259,
327,
378,
88,
2194,
199,
6448,
259,
327,
378,
88,
2114,
199,
6448,
259,
327,
378,
88,
1138,
199,
6448,
259,
327,
378,
88,
2277,
199,
6448,
259,
327,
378,
88,
1965,
199,
6448,
259,
327,
378,
88,
23,
65,
199,
6448,
259,
327,
378,
88,
23,
66,
199,
6448,
259,
327,
378,
88,
23,
67,
199,
6448,
259,
327,
378,
88,
23,
68,
199,
6448,
259,
327,
378,
88,
23,
69,
199,
6448,
259,
327,
378,
88,
23,
70,
199,
6448,
259,
327,
378,
88,
1257,
199,
6448,
259,
327,
378,
88,
2835,
199,
6448,
259,
327,
378,
88,
2564,
199,
6448,
259,
327,
378,
88,
2658,
199,
6448,
259,
327,
378,
88,
1349,
199,
6448,
259,
327,
378,
88,
2426,
199,
6448,
259,
327,
378,
88,
1184,
199,
6448,
259,
327,
378,
88,
1555,
199,
6448,
259,
327,
378,
88,
1299,
199,
6448,
259,
327,
378,
88,
1407,
199,
6448,
259,
327,
378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1,
1,
1,
1,
1
] |
scieloorg/opac
|
opac/tests/test_main_views_abstract.py
|
1
|
4558
|
# coding: utf-8
# import unittest
# from unittest.mock import patch, Mock
from unittest.mock import patch
import flask
from flask import url_for, g, current_app
# from flask import render_template
# from flask_babelex import gettext as _
from .base import BaseTestCase
from . import utils
class TestArticleDetailV3Abstract(BaseTestCase):
def _get_response(self, article_data=None, part='abstract', pid_v2=None,
abstract_lang=None):
with current_app.test_request_context():
utils.makeOneCollection()
self.journal = utils.makeOneJournal()
issue = utils.makeOneIssue({'journal': self.journal})
_article_data = {
'title': 'Article Y',
'original_language': 'en',
'languages': ['es', 'pt', 'en'],
'issue': issue,
'journal': self.journal,
'abstracts': [
{"language": "en", "text": "Abstract in English"},
],
'url_segment': '10-11',
'translated_titles': [
{'language': 'es', 'name': u'Artículo en español'},
{'language': 'pt', 'name': u'Artigo en Português'},
],
'pid': 'PIDV2'
}
_article_data.update(article_data or {})
self.article = utils.makeOneArticle(_article_data)
if pid_v2:
url = '%s?script=sci_abstract&pid=%s' % (
url_for('main.router_legacy'), pid_v2)
else:
url = url_for(
'main.article_detail_v3',
url_seg=self.journal.url_segment,
article_pid_v3=self.article.aid,
part=part,
lang=abstract_lang,
)
response = self.client.get(url)
return response
def test_abstract_pid_v3_returns_404_and_displays_invalid_part_value_message(self):
expected = "Não existe 'abst'. No seu lugar use 'abstract'"
response = self._get_response(part='abst')
self.assertStatus(response, 404)
result = response.data.decode('utf-8')
self.assertIn(expected, result)
def test_abstract_pid_v3_returns_status_code_200(self):
response = self._get_response(abstract_lang="en")
self.assertStatus(response, 200)
@patch("webapp.main.views.render_html")
def test_abstract_pid_v3(self, mock_render_html):
mock_render_html.return_value = (
"abstract do documento",
['en', 'es', 'pt'],
)
expected = "abstract do documento"
response = self._get_response(abstract_lang="en")
result = response.data.decode('utf-8')
mock_render_html.assert_called_once_with(self.article, "en", True)
self.assertIn(expected, result)
@patch("webapp.main.views.render_html")
def test_abstract_pid_v3_does_not_return_abstract_but_fulltext_if_part_is_None(self, mock_render_html):
mock_render_html.return_value = (
"texto do documento",
['en', 'es', 'pt'],
)
expected = "texto do documento"
response = self._get_response(part=None)
result = response.data.decode('utf-8')
mock_render_html.assert_called_once_with(self.article, "en", False)
self.assertIn(expected, result)
def test_abstract_pid_v3_returns_404_because_lang_is_missing(self):
expected = "Não existe 'False'. No seu lugar use 'abstract'"
response = self._get_response(part=False)
self.assertStatus(response, 404)
result = response.data.decode('utf-8')
self.assertIn(expected, result)
def test_abstract_pid_v3_returns_404_and_displays_invalid_part_value_message_if_part_is_False(self):
expected = "Não existe 'False'. No seu lugar use 'abstract'"
response = self._get_response(part=False)
self.assertStatus(response, 404)
result = response.data.decode('utf-8')
self.assertIn(expected, result)
@patch("webapp.main.views.render_html")
def test_router_legacy_calls(self, mock_f):
response = self._get_response(pid_v2='pidv2')
self.assertRedirects(
response,
url_for(
'main.article_detail_v3',
url_seg=self.journal.url_segment,
article_pid_v3=self.article.aid,
part='abstract',
lang="en",
),
)
|
bsd-2-clause
|
[
3,
2803,
26,
2774,
13,
24,
199,
3,
492,
2882,
199,
3,
687,
2882,
14,
1805,
492,
3371,
12,
4420,
199,
504,
2882,
14,
1805,
492,
3371,
199,
199,
646,
7209,
199,
504,
7209,
492,
1166,
63,
509,
12,
486,
12,
1453,
63,
571,
199,
3,
687,
7209,
492,
3795,
63,
1160,
199,
3,
687,
7209,
63,
66,
7570,
3113,
492,
9796,
465,
485,
199,
199,
504,
1275,
1095,
492,
3523,
1746,
199,
199,
504,
1275,
492,
3778,
421,
199,
533,
1379,
7221,
8064,
54,
19,
8458,
8,
20760,
304,
272,
347,
485,
362,
63,
1310,
8,
277,
12,
9772,
63,
576,
29,
403,
12,
1777,
534,
6198,
297,
4422,
63,
86,
18,
29,
403,
12,
1993,
9006,
63,
4159,
29,
403,
304,
267,
543,
1453,
63,
571,
14,
396,
63,
1069,
63,
1100,
837,
288,
3778,
14,
32273,
7768,
342,
288,
291,
14,
7067,
275,
3778,
14,
32273,
25909,
342,
288,
4976,
275,
3778,
14,
32273,
17106,
3252,
7067,
356,
291,
14,
7067,
1552,
953,
485,
6934,
63,
576,
275,
469,
355,
283,
1213,
356,
283,
7221,
1488,
297,
355,
283,
5043,
63,
3671,
356,
283,
287,
297,
355,
283,
13209,
356,
788,
397,
297,
283,
541,
297,
283,
287,
995,
355,
283,
5237,
356,
4976,
12,
355,
283,
7067,
356,
291,
14,
7067,
12,
355,
283,
6198,
83,
356,
359,
490,
2420,
3671,
582,
298,
287,
401,
298,
505,
582,
298,
8458,
315,
20144,
6018,
355,
2156,
355,
283,
633,
63,
9255,
356,
283,
709,
13,
845,
297,
355,
283,
18065,
63,
8916,
356,
359,
490,
791,
3671,
356,
283,
397,
297,
283,
354,
356,
399,
7,
28922,
13676,
67,
13957,
655,
325,
3770,
22692,
393,
2267,
490,
791,
3671,
356,
283,
541,
297,
283,
354,
356,
399,
7,
1596,
280,
1939,
655,
10977,
1518,
85,
28413,
83,
2267,
355,
2156,
355,
283,
3150,
356,
283,
16098,
54,
18,
7,
288,
789,
288,
485,
6934,
63,
576,
14,
873,
8,
6934,
63,
576,
503,
5009,
288,
291,
14,
6934,
275,
3778,
14,
32273,
7221,
1547,
6934,
63,
576,
9,
288,
340,
4422,
63,
86,
18,
26,
355,
1166,
275,
1543,
83,
31,
1579,
29,
9907,
63,
6198,
6,
3150,
2458,
83,
7,
450,
334,
717,
1166,
63,
509,
360,
973,
14,
4995,
63,
10000,
659,
4422,
63,
86,
18,
9,
288,
587,
26,
355,
1166,
275,
1166,
63,
509,
8,
490,
283,
973,
14,
6934,
63,
5506,
63,
86,
19,
297,
490,
1166,
63,
8359,
29,
277,
14,
7067,
14,
633,
63,
9255,
12,
490,
9772,
63,
3150,
63,
86,
19,
29,
277,
14,
6934,
14,
21745,
12,
490,
1777,
29,
2064,
12,
490,
6339,
29,
6198,
63,
4159,
12,
355,
776,
288,
1177,
275,
291,
14,
1258,
14,
362,
8,
633,
9,
288,
372,
1177,
339,
347,
511,
63,
6198,
63,
3150,
63,
86,
19,
63,
5808,
63,
5188,
63,
460,
63,
13654,
9316,
63,
3197,
63,
2064,
63,
585,
63,
1188,
8,
277,
304,
267,
1420,
275,
298,
46,
16299,
444,
29729,
283,
371,
270,
1370,
3091,
542,
85,
634,
21922,
675,
283,
6198,
4065,
267,
1177,
275,
291,
423,
362,
63,
1310,
8,
2064,
534,
371,
270,
358,
267,
291,
14,
479,
3694,
8,
1310,
12,
7901,
9,
267,
754,
275,
1177,
14,
576,
14,
2708,
360,
1624,
13,
24,
358,
267,
291,
14,
4080,
8,
2062,
12,
754,
9,
339,
347,
511,
63,
6198,
63,
3150,
63,
86,
19,
63,
5808,
63,
1205,
63,
600,
63,
1840,
8,
277,
304,
267,
1177,
275,
291,
423,
362,
63,
1310,
8,
6198,
63,
4159,
628,
287,
531,
267,
291,
14,
479,
3694,
8,
1310,
12,
1926,
9,
339,
768,
2068,
480,
22632,
14,
973,
14,
4196,
14,
3352,
63,
1360,
531,
272,
347,
511,
63,
6198,
63,
3150,
63,
86,
19,
8,
277,
12,
1683,
63,
3352,
63,
1360,
304,
267,
1683,
63,
3352,
63,
1360,
14,
1107,
63,
585,
275,
334,
288,
298,
6198,
886,
2213,
79,
401,
288,
788,
287,
297,
283,
397,
297,
283,
541,
995,
267,
776,
267,
1420,
275,
298,
6198,
886,
2213,
79,
2,
267,
1177,
275,
291,
423,
362,
63,
1310,
8,
6198,
63,
4159,
628,
287,
531,
267,
754,
275,
1177,
14,
576,
14,
2708,
360,
1624,
13,
24,
358,
267,
1683,
63,
3352,
63,
1360,
14,
479,
63,
3527,
63,
5089,
63,
1045,
8,
277,
14,
6934,
12,
298,
287,
401,
715,
9,
267,
291,
14,
4080,
8,
2062,
12,
754,
9,
339,
768,
2068,
480,
22632,
14,
973,
14,
4196,
14,
3352,
63,
1360,
531,
272,
347,
511,
63,
6198,
63,
3150,
63,
86,
19,
63,
9105,
63,
1397,
63,
1107,
63,
6198,
63,
7911,
63,
2861,
505,
63,
692,
63,
2064,
63,
374,
63,
403,
8,
277,
12,
1683,
63,
3352,
63,
1360,
304,
267,
1683,
63,
3352,
63,
1360,
14,
1107,
63,
585,
275,
334,
288,
298,
505,
79,
886,
2213,
79,
401,
288,
788,
287,
297,
283,
397,
297,
283,
541,
995,
267,
776,
267,
1420,
275,
298,
505,
79,
886,
2213,
79,
2,
267,
1177,
275,
291,
423,
362,
63,
1310,
8,
2064,
29,
403,
9,
267,
754,
275,
1177,
14,
576,
14,
2708,
360,
1624,
13,
24,
358,
267,
1683,
63,
3352,
63,
1360,
14,
479,
63,
3527,
63,
5089,
63,
1045,
8,
277,
14,
6934,
12,
298,
287,
401,
756,
9,
267,
291,
14,
4080,
8,
2062,
12,
754,
9,
339,
347,
511,
63,
6198,
63,
3150,
63,
86,
19,
63,
5808,
63,
5188,
63,
20684,
63,
4159,
63,
374,
63,
4752,
8,
277,
304,
267,
1420,
275,
298,
46,
16299,
444,
29729,
283,
797,
1370,
3091,
542,
85,
634,
21922,
675,
283,
6198,
4065,
267,
1177,
275,
291,
423,
362,
63,
1310,
8,
2064,
29,
797,
9,
267,
291,
14,
479,
3694,
8,
1310,
12,
7901,
9,
267,
754,
275,
1177,
14,
576,
14,
2708,
360,
1624,
13,
24,
358,
267,
291,
14,
4080,
8,
2062,
12,
754,
9,
339,
347,
511,
63,
6198,
63,
3150,
63,
86,
19,
63,
5808,
63,
5188,
63,
460,
63,
13654,
9316,
63,
3197,
63,
2064,
63,
585,
63,
1188,
63,
692,
63,
2064,
63,
374,
63,
797,
8,
277,
304,
267,
1420,
275,
298,
46,
16299
] |
[
2803,
26,
2774,
13,
24,
199,
3,
492,
2882,
199,
3,
687,
2882,
14,
1805,
492,
3371,
12,
4420,
199,
504,
2882,
14,
1805,
492,
3371,
199,
199,
646,
7209,
199,
504,
7209,
492,
1166,
63,
509,
12,
486,
12,
1453,
63,
571,
199,
3,
687,
7209,
492,
3795,
63,
1160,
199,
3,
687,
7209,
63,
66,
7570,
3113,
492,
9796,
465,
485,
199,
199,
504,
1275,
1095,
492,
3523,
1746,
199,
199,
504,
1275,
492,
3778,
421,
199,
533,
1379,
7221,
8064,
54,
19,
8458,
8,
20760,
304,
272,
347,
485,
362,
63,
1310,
8,
277,
12,
9772,
63,
576,
29,
403,
12,
1777,
534,
6198,
297,
4422,
63,
86,
18,
29,
403,
12,
1993,
9006,
63,
4159,
29,
403,
304,
267,
543,
1453,
63,
571,
14,
396,
63,
1069,
63,
1100,
837,
288,
3778,
14,
32273,
7768,
342,
288,
291,
14,
7067,
275,
3778,
14,
32273,
25909,
342,
288,
4976,
275,
3778,
14,
32273,
17106,
3252,
7067,
356,
291,
14,
7067,
1552,
953,
485,
6934,
63,
576,
275,
469,
355,
283,
1213,
356,
283,
7221,
1488,
297,
355,
283,
5043,
63,
3671,
356,
283,
287,
297,
355,
283,
13209,
356,
788,
397,
297,
283,
541,
297,
283,
287,
995,
355,
283,
5237,
356,
4976,
12,
355,
283,
7067,
356,
291,
14,
7067,
12,
355,
283,
6198,
83,
356,
359,
490,
2420,
3671,
582,
298,
287,
401,
298,
505,
582,
298,
8458,
315,
20144,
6018,
355,
2156,
355,
283,
633,
63,
9255,
356,
283,
709,
13,
845,
297,
355,
283,
18065,
63,
8916,
356,
359,
490,
791,
3671,
356,
283,
397,
297,
283,
354,
356,
399,
7,
28922,
13676,
67,
13957,
655,
325,
3770,
22692,
393,
2267,
490,
791,
3671,
356,
283,
541,
297,
283,
354,
356,
399,
7,
1596,
280,
1939,
655,
10977,
1518,
85,
28413,
83,
2267,
355,
2156,
355,
283,
3150,
356,
283,
16098,
54,
18,
7,
288,
789,
288,
485,
6934,
63,
576,
14,
873,
8,
6934,
63,
576,
503,
5009,
288,
291,
14,
6934,
275,
3778,
14,
32273,
7221,
1547,
6934,
63,
576,
9,
288,
340,
4422,
63,
86,
18,
26,
355,
1166,
275,
1543,
83,
31,
1579,
29,
9907,
63,
6198,
6,
3150,
2458,
83,
7,
450,
334,
717,
1166,
63,
509,
360,
973,
14,
4995,
63,
10000,
659,
4422,
63,
86,
18,
9,
288,
587,
26,
355,
1166,
275,
1166,
63,
509,
8,
490,
283,
973,
14,
6934,
63,
5506,
63,
86,
19,
297,
490,
1166,
63,
8359,
29,
277,
14,
7067,
14,
633,
63,
9255,
12,
490,
9772,
63,
3150,
63,
86,
19,
29,
277,
14,
6934,
14,
21745,
12,
490,
1777,
29,
2064,
12,
490,
6339,
29,
6198,
63,
4159,
12,
355,
776,
288,
1177,
275,
291,
14,
1258,
14,
362,
8,
633,
9,
288,
372,
1177,
339,
347,
511,
63,
6198,
63,
3150,
63,
86,
19,
63,
5808,
63,
5188,
63,
460,
63,
13654,
9316,
63,
3197,
63,
2064,
63,
585,
63,
1188,
8,
277,
304,
267,
1420,
275,
298,
46,
16299,
444,
29729,
283,
371,
270,
1370,
3091,
542,
85,
634,
21922,
675,
283,
6198,
4065,
267,
1177,
275,
291,
423,
362,
63,
1310,
8,
2064,
534,
371,
270,
358,
267,
291,
14,
479,
3694,
8,
1310,
12,
7901,
9,
267,
754,
275,
1177,
14,
576,
14,
2708,
360,
1624,
13,
24,
358,
267,
291,
14,
4080,
8,
2062,
12,
754,
9,
339,
347,
511,
63,
6198,
63,
3150,
63,
86,
19,
63,
5808,
63,
1205,
63,
600,
63,
1840,
8,
277,
304,
267,
1177,
275,
291,
423,
362,
63,
1310,
8,
6198,
63,
4159,
628,
287,
531,
267,
291,
14,
479,
3694,
8,
1310,
12,
1926,
9,
339,
768,
2068,
480,
22632,
14,
973,
14,
4196,
14,
3352,
63,
1360,
531,
272,
347,
511,
63,
6198,
63,
3150,
63,
86,
19,
8,
277,
12,
1683,
63,
3352,
63,
1360,
304,
267,
1683,
63,
3352,
63,
1360,
14,
1107,
63,
585,
275,
334,
288,
298,
6198,
886,
2213,
79,
401,
288,
788,
287,
297,
283,
397,
297,
283,
541,
995,
267,
776,
267,
1420,
275,
298,
6198,
886,
2213,
79,
2,
267,
1177,
275,
291,
423,
362,
63,
1310,
8,
6198,
63,
4159,
628,
287,
531,
267,
754,
275,
1177,
14,
576,
14,
2708,
360,
1624,
13,
24,
358,
267,
1683,
63,
3352,
63,
1360,
14,
479,
63,
3527,
63,
5089,
63,
1045,
8,
277,
14,
6934,
12,
298,
287,
401,
715,
9,
267,
291,
14,
4080,
8,
2062,
12,
754,
9,
339,
768,
2068,
480,
22632,
14,
973,
14,
4196,
14,
3352,
63,
1360,
531,
272,
347,
511,
63,
6198,
63,
3150,
63,
86,
19,
63,
9105,
63,
1397,
63,
1107,
63,
6198,
63,
7911,
63,
2861,
505,
63,
692,
63,
2064,
63,
374,
63,
403,
8,
277,
12,
1683,
63,
3352,
63,
1360,
304,
267,
1683,
63,
3352,
63,
1360,
14,
1107,
63,
585,
275,
334,
288,
298,
505,
79,
886,
2213,
79,
401,
288,
788,
287,
297,
283,
397,
297,
283,
541,
995,
267,
776,
267,
1420,
275,
298,
505,
79,
886,
2213,
79,
2,
267,
1177,
275,
291,
423,
362,
63,
1310,
8,
2064,
29,
403,
9,
267,
754,
275,
1177,
14,
576,
14,
2708,
360,
1624,
13,
24,
358,
267,
1683,
63,
3352,
63,
1360,
14,
479,
63,
3527,
63,
5089,
63,
1045,
8,
277,
14,
6934,
12,
298,
287,
401,
756,
9,
267,
291,
14,
4080,
8,
2062,
12,
754,
9,
339,
347,
511,
63,
6198,
63,
3150,
63,
86,
19,
63,
5808,
63,
5188,
63,
20684,
63,
4159,
63,
374,
63,
4752,
8,
277,
304,
267,
1420,
275,
298,
46,
16299,
444,
29729,
283,
797,
1370,
3091,
542,
85,
634,
21922,
675,
283,
6198,
4065,
267,
1177,
275,
291,
423,
362,
63,
1310,
8,
2064,
29,
797,
9,
267,
291,
14,
479,
3694,
8,
1310,
12,
7901,
9,
267,
754,
275,
1177,
14,
576,
14,
2708,
360,
1624,
13,
24,
358,
267,
291,
14,
4080,
8,
2062,
12,
754,
9,
339,
347,
511,
63,
6198,
63,
3150,
63,
86,
19,
63,
5808,
63,
5188,
63,
460,
63,
13654,
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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
] |
rebel1/kernel_2.6.36_nvidia_base
|
tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/SchedGui.py
|
183
|
5410
|
# SchedGui.py - Python extension for perf trace, basic GUI code for
# traces drawing and overview.
#
# Copyright (C) 2010 by Frederic Weisbecker <fweisbec@gmail.com>
#
# This software is distributed under the terms of the GNU General
# Public License ("GPL") version 2 as published by the Free Software
# Foundation.
try:
import wx
except ImportError:
raise ImportError, "You need to install the wxpython lib for this script"
class RootFrame(wx.Frame):
Y_OFFSET = 100
RECT_HEIGHT = 100
RECT_SPACE = 50
EVENT_MARKING_WIDTH = 5
def __init__(self, sched_tracer, title, parent = None, id = -1):
wx.Frame.__init__(self, parent, id, title)
(self.screen_width, self.screen_height) = wx.GetDisplaySize()
self.screen_width -= 10
self.screen_height -= 10
self.zoom = 0.5
self.scroll_scale = 20
self.sched_tracer = sched_tracer
self.sched_tracer.set_root_win(self)
(self.ts_start, self.ts_end) = sched_tracer.interval()
self.update_width_virtual()
self.nr_rects = sched_tracer.nr_rectangles() + 1
self.height_virtual = RootFrame.Y_OFFSET + (self.nr_rects * (RootFrame.RECT_HEIGHT + RootFrame.RECT_SPACE))
# whole window panel
self.panel = wx.Panel(self, size=(self.screen_width, self.screen_height))
# scrollable container
self.scroll = wx.ScrolledWindow(self.panel)
self.scroll.SetScrollbars(self.scroll_scale, self.scroll_scale, self.width_virtual / self.scroll_scale, self.height_virtual / self.scroll_scale)
self.scroll.EnableScrolling(True, True)
self.scroll.SetFocus()
# scrollable drawing area
self.scroll_panel = wx.Panel(self.scroll, size=(self.screen_width - 15, self.screen_height / 2))
self.scroll_panel.Bind(wx.EVT_PAINT, self.on_paint)
self.scroll_panel.Bind(wx.EVT_KEY_DOWN, self.on_key_press)
self.scroll_panel.Bind(wx.EVT_LEFT_DOWN, self.on_mouse_down)
self.scroll.Bind(wx.EVT_PAINT, self.on_paint)
self.scroll.Bind(wx.EVT_KEY_DOWN, self.on_key_press)
self.scroll.Bind(wx.EVT_LEFT_DOWN, self.on_mouse_down)
self.scroll.Fit()
self.Fit()
self.scroll_panel.SetDimensions(-1, -1, self.width_virtual, self.height_virtual, wx.SIZE_USE_EXISTING)
self.txt = None
self.Show(True)
def us_to_px(self, val):
return val / (10 ** 3) * self.zoom
def px_to_us(self, val):
return (val / self.zoom) * (10 ** 3)
def scroll_start(self):
(x, y) = self.scroll.GetViewStart()
return (x * self.scroll_scale, y * self.scroll_scale)
def scroll_start_us(self):
(x, y) = self.scroll_start()
return self.px_to_us(x)
def paint_rectangle_zone(self, nr, color, top_color, start, end):
offset_px = self.us_to_px(start - self.ts_start)
width_px = self.us_to_px(end - self.ts_start)
offset_py = RootFrame.Y_OFFSET + (nr * (RootFrame.RECT_HEIGHT + RootFrame.RECT_SPACE))
width_py = RootFrame.RECT_HEIGHT
dc = self.dc
if top_color is not None:
(r, g, b) = top_color
top_color = wx.Colour(r, g, b)
brush = wx.Brush(top_color, wx.SOLID)
dc.SetBrush(brush)
dc.DrawRectangle(offset_px, offset_py, width_px, RootFrame.EVENT_MARKING_WIDTH)
width_py -= RootFrame.EVENT_MARKING_WIDTH
offset_py += RootFrame.EVENT_MARKING_WIDTH
(r ,g, b) = color
color = wx.Colour(r, g, b)
brush = wx.Brush(color, wx.SOLID)
dc.SetBrush(brush)
dc.DrawRectangle(offset_px, offset_py, width_px, width_py)
def update_rectangles(self, dc, start, end):
start += self.ts_start
end += self.ts_start
self.sched_tracer.fill_zone(start, end)
def on_paint(self, event):
dc = wx.PaintDC(self.scroll_panel)
self.dc = dc
width = min(self.width_virtual, self.screen_width)
(x, y) = self.scroll_start()
start = self.px_to_us(x)
end = self.px_to_us(x + width)
self.update_rectangles(dc, start, end)
def rect_from_ypixel(self, y):
y -= RootFrame.Y_OFFSET
rect = y / (RootFrame.RECT_HEIGHT + RootFrame.RECT_SPACE)
height = y % (RootFrame.RECT_HEIGHT + RootFrame.RECT_SPACE)
if rect < 0 or rect > self.nr_rects - 1 or height > RootFrame.RECT_HEIGHT:
return -1
return rect
def update_summary(self, txt):
if self.txt:
self.txt.Destroy()
self.txt = wx.StaticText(self.panel, -1, txt, (0, (self.screen_height / 2) + 50))
def on_mouse_down(self, event):
(x, y) = event.GetPositionTuple()
rect = self.rect_from_ypixel(y)
if rect == -1:
return
t = self.px_to_us(x) + self.ts_start
self.sched_tracer.mouse_down(rect, t)
def update_width_virtual(self):
self.width_virtual = self.us_to_px(self.ts_end - self.ts_start)
def __zoom(self, x):
self.update_width_virtual()
(xpos, ypos) = self.scroll.GetViewStart()
xpos = self.us_to_px(x) / self.scroll_scale
self.scroll.SetScrollbars(self.scroll_scale, self.scroll_scale, self.width_virtual / self.scroll_scale, self.height_virtual / self.scroll_scale, xpos, ypos)
self.Refresh()
def zoom_in(self):
x = self.scroll_start_us()
self.zoom *= 2
self.__zoom(x)
def zoom_out(self):
x = self.scroll_start_us()
self.zoom /= 2
self.__zoom(x)
def on_key_press(self, event):
key = event.GetRawKeyCode()
if key == ord("+"):
self.zoom_in()
return
if key == ord("-"):
self.zoom_out()
return
key = event.GetKeyCode()
(x, y) = self.scroll.GetViewStart()
if key == wx.WXK_RIGHT:
self.scroll.Scroll(x + 1, y)
elif key == wx.WXK_LEFT:
self.scroll.Scroll(x - 1, y)
elif key == wx.WXK_DOWN:
self.scroll.Scroll(x, y + 1)
elif key == wx.WXK_UP:
self.scroll.Scroll(x, y - 1)
|
gpl-2.0
|
[
3,
428,
1809,
4324,
14,
647,
446,
2018,
3329,
367,
8582,
3307,
12,
5678,
17160,
1233,
367,
199,
3,
198,
198,
28388,
17455,
436,
23503,
14,
199,
3,
199,
3,
1898,
334,
35,
9,
7129,
701,
481,
21919,
1567,
2136,
374,
1235,
22043,
665,
70,
1129,
374,
24554,
32,
6799,
14,
957,
30,
199,
3,
199,
3,
961,
2032,
365,
1854,
1334,
314,
2895,
402,
314,
1664,
1696,
199,
3,
1684,
844,
1689,
12006,
531,
1015,
499,
465,
3267,
701,
314,
2868,
2290,
199,
3,
2752,
14,
421,
199,
893,
26,
199,
198,
646,
4818,
199,
2590,
3545,
26,
199,
198,
3730,
3545,
12,
298,
5556,
1929,
370,
3907,
314,
4818,
1548,
1973,
367,
642,
2884,
2,
421,
199,
533,
19059,
8,
6323,
14,
3160,
304,
199,
198,
57,
63,
14839,
275,
2948,
199,
198,
4168,
63,
13509,
275,
2948,
199,
198,
4168,
63,
11658,
275,
5238,
199,
198,
8193,
63,
10520,
1206,
63,
11139,
275,
959,
421,
198,
318,
636,
826,
721,
277,
12,
10286,
63,
16825,
12,
2538,
12,
1676,
275,
488,
12,
1305,
275,
446,
17,
304,
507,
198,
6323,
14,
3160,
855,
826,
721,
277,
12,
1676,
12,
1305,
12,
2538,
9,
2742,
198,
8,
277,
14,
5410,
63,
2063,
12,
291,
14,
5410,
63,
3333,
9,
275,
4818,
14,
1002,
7687,
2320,
342,
507,
198,
277,
14,
5410,
63,
2063,
4862,
1616,
507,
198,
277,
14,
5410,
63,
3333,
4862,
1616,
507,
198,
277,
14,
10598,
275,
378,
14,
21,
507,
198,
277,
14,
6755,
63,
3467,
275,
3388,
507,
198,
277,
14,
10487,
63,
16825,
275,
10286,
63,
16825,
507,
198,
277,
14,
10487,
63,
16825,
14,
409,
63,
1231,
63,
2676,
8,
277,
9,
507,
198,
8,
277,
14,
1086,
63,
928,
12,
291,
14,
1086,
63,
500,
9,
275,
10286,
63,
16825,
14,
4284,
342,
507,
198,
277,
14,
873,
63,
2063,
63,
2065,
342,
507,
198,
277,
14,
7865,
63,
23411,
275,
10286,
63,
16825,
14,
7865,
63,
1201,
13162,
342,
435,
413,
507,
198,
277,
14,
3333,
63,
2065,
275,
19059,
14,
57,
63,
14839,
435,
334,
277,
14,
7865,
63,
23411,
627,
334,
6405,
3160,
14,
4168,
63,
13509,
435,
19059,
14,
4168,
63,
11658,
430,
2742,
198,
3,
8852,
4353,
12748,
507,
198,
277,
14,
7885,
275,
4818,
14,
10185,
8,
277,
12,
1568,
2687,
277,
14,
5410,
63,
2063,
12,
291,
14,
5410,
63,
3333,
430,
2742,
198,
3,
13704,
461,
3970,
507,
198,
277,
14,
6755,
275,
4818,
14,
29145,
4301,
8,
277,
14,
7885,
9,
507,
198,
277,
14,
6755,
14,
1084,
13127,
16264,
8,
277,
14,
6755,
63,
3467,
12,
291,
14,
6755,
63,
3467,
12,
291,
14,
2063,
63,
2065,
1182,
291,
14,
6755,
63,
3467,
12,
291,
14,
3333,
63,
2065,
1182,
291,
14,
6755,
63,
3467,
9,
507,
198,
277,
14,
6755,
14,
6476,
13127,
316,
8,
549,
12,
715,
9,
507,
198,
277,
14,
6755,
14,
1084,
17310,
342,
2742,
198,
3,
13704,
461,
17455,
9150,
507,
198,
277,
14,
6755,
63,
7885,
275,
4818,
14,
10185,
8,
277,
14,
6755,
12,
1568,
2687,
277,
14,
5410,
63,
2063,
446,
4114,
12,
291,
14,
5410,
63,
3333,
1182,
499,
430,
507,
198,
277,
14,
6755,
63,
7885,
14,
8198,
8,
6323,
14,
12093,
63,
8470,
2919,
12,
291,
14,
265,
63,
17486,
9,
507,
198,
277,
14,
6755,
63,
7885,
14,
8198,
8,
6323,
14,
12093,
63,
3078,
63,
8819,
12,
291,
14,
265,
63,
498,
63,
2915,
9,
507,
198,
277,
14,
6755,
63,
7885,
14,
8198,
8,
6323,
14,
12093,
63,
9894,
63,
8819,
12,
291,
14,
265,
63,
10544,
63,
2110,
9,
507,
198,
277,
14,
6755,
14,
8198,
8,
6323,
14,
12093,
63,
8470,
2919,
12,
291,
14,
265,
63,
17486,
9,
507,
198,
277,
14,
6755,
14,
8198,
8,
6323,
14,
12093,
63,
3078,
63,
8819,
12,
291,
14,
265,
63,
498,
63,
2915,
9,
507,
198,
277,
14,
6755,
14,
8198,
8,
6323,
14,
12093,
63,
9894,
63,
8819,
12,
291,
14,
265,
63,
10544,
63,
2110,
9,
2742,
198,
277,
14,
6755,
14,
13776,
342,
507,
198,
277,
14,
13776,
342,
2742,
198,
277,
14,
6755,
63,
7885,
14,
1084,
23370,
2801,
17,
12,
446,
17,
12,
291,
14,
2063,
63,
2065,
12,
291,
14,
3333,
63,
2065,
12,
4818,
14,
4305,
63,
4701,
63,
13301,
1206,
9,
2742,
198,
277,
14,
2424,
275,
488,
2742,
198,
277,
14,
6824,
8,
549,
9,
421,
198,
318,
2739,
63,
475,
63,
5326,
8,
277,
12,
1139,
304,
507,
198,
1107,
1139,
1182,
334,
709,
1011,
650,
9,
627,
291,
14,
10598,
421,
198,
318,
21162,
63,
475,
63,
527,
8,
277,
12,
1139,
304,
507,
198,
1107,
334,
637,
1182,
291,
14,
10598,
9,
627,
334,
709,
1011,
650,
9,
421,
198,
318,
13704,
63,
928,
8,
277,
304,
507,
198,
8,
88,
12,
612,
9,
275,
291,
14,
6755,
14,
1002,
2768,
3162,
342,
507,
198,
1107,
334,
88,
627,
291,
14,
6755,
63,
3467,
12,
612,
627,
291,
14,
6755,
63,
3467,
9,
421,
198,
318,
13704,
63,
928,
63,
527,
8,
277,
304,
507,
198,
8,
88,
12,
612,
9,
275,
291,
14,
6755,
63,
928,
342,
507,
198,
1107,
291,
14,
5326,
63,
475,
63,
527,
8,
88,
9,
421,
198,
318,
32055,
63,
19954,
63,
2619,
8,
277,
12,
14762,
12,
3164,
12,
2746,
63,
2326,
12,
1343,
12,
1284,
304,
507,
198,
2743,
63,
5326,
275,
291,
14,
527,
63,
475,
63,
5326,
8,
928,
446,
291,
14,
1086,
63,
928,
9,
507,
198,
2063,
63,
5326,
275,
291,
14,
527,
63,
475,
63,
5326,
8,
500,
446,
291,
14,
1086,
63,
928,
9,
2742,
198,
2743,
63,
647,
275,
19059,
14,
57,
63,
14839,
435,
334,
7865,
627,
334,
6405,
3160,
14,
4168,
63,
13509,
435,
19059,
14,
4168,
63,
11658,
430,
507,
198,
2063,
63,
647,
275,
19059,
14,
4168,
63,
13509,
2742,
198,
3833,
275,
291,
14,
3833,
2742,
198,
692,
2746,
63,
2326,
365,
440,
488,
26,
686,
198,
8,
82,
12,
486,
12,
330,
9,
275,
2746,
63,
2326,
686,
198,
2119,
63,
2326,
275,
4818,
14
] |
[
428,
1809,
4324,
14,
647,
446,
2018,
3329,
367,
8582,
3307,
12,
5678,
17160,
1233,
367,
199,
3,
198,
198,
28388,
17455,
436,
23503,
14,
199,
3,
199,
3,
1898,
334,
35,
9,
7129,
701,
481,
21919,
1567,
2136,
374,
1235,
22043,
665,
70,
1129,
374,
24554,
32,
6799,
14,
957,
30,
199,
3,
199,
3,
961,
2032,
365,
1854,
1334,
314,
2895,
402,
314,
1664,
1696,
199,
3,
1684,
844,
1689,
12006,
531,
1015,
499,
465,
3267,
701,
314,
2868,
2290,
199,
3,
2752,
14,
421,
199,
893,
26,
199,
198,
646,
4818,
199,
2590,
3545,
26,
199,
198,
3730,
3545,
12,
298,
5556,
1929,
370,
3907,
314,
4818,
1548,
1973,
367,
642,
2884,
2,
421,
199,
533,
19059,
8,
6323,
14,
3160,
304,
199,
198,
57,
63,
14839,
275,
2948,
199,
198,
4168,
63,
13509,
275,
2948,
199,
198,
4168,
63,
11658,
275,
5238,
199,
198,
8193,
63,
10520,
1206,
63,
11139,
275,
959,
421,
198,
318,
636,
826,
721,
277,
12,
10286,
63,
16825,
12,
2538,
12,
1676,
275,
488,
12,
1305,
275,
446,
17,
304,
507,
198,
6323,
14,
3160,
855,
826,
721,
277,
12,
1676,
12,
1305,
12,
2538,
9,
2742,
198,
8,
277,
14,
5410,
63,
2063,
12,
291,
14,
5410,
63,
3333,
9,
275,
4818,
14,
1002,
7687,
2320,
342,
507,
198,
277,
14,
5410,
63,
2063,
4862,
1616,
507,
198,
277,
14,
5410,
63,
3333,
4862,
1616,
507,
198,
277,
14,
10598,
275,
378,
14,
21,
507,
198,
277,
14,
6755,
63,
3467,
275,
3388,
507,
198,
277,
14,
10487,
63,
16825,
275,
10286,
63,
16825,
507,
198,
277,
14,
10487,
63,
16825,
14,
409,
63,
1231,
63,
2676,
8,
277,
9,
507,
198,
8,
277,
14,
1086,
63,
928,
12,
291,
14,
1086,
63,
500,
9,
275,
10286,
63,
16825,
14,
4284,
342,
507,
198,
277,
14,
873,
63,
2063,
63,
2065,
342,
507,
198,
277,
14,
7865,
63,
23411,
275,
10286,
63,
16825,
14,
7865,
63,
1201,
13162,
342,
435,
413,
507,
198,
277,
14,
3333,
63,
2065,
275,
19059,
14,
57,
63,
14839,
435,
334,
277,
14,
7865,
63,
23411,
627,
334,
6405,
3160,
14,
4168,
63,
13509,
435,
19059,
14,
4168,
63,
11658,
430,
2742,
198,
3,
8852,
4353,
12748,
507,
198,
277,
14,
7885,
275,
4818,
14,
10185,
8,
277,
12,
1568,
2687,
277,
14,
5410,
63,
2063,
12,
291,
14,
5410,
63,
3333,
430,
2742,
198,
3,
13704,
461,
3970,
507,
198,
277,
14,
6755,
275,
4818,
14,
29145,
4301,
8,
277,
14,
7885,
9,
507,
198,
277,
14,
6755,
14,
1084,
13127,
16264,
8,
277,
14,
6755,
63,
3467,
12,
291,
14,
6755,
63,
3467,
12,
291,
14,
2063,
63,
2065,
1182,
291,
14,
6755,
63,
3467,
12,
291,
14,
3333,
63,
2065,
1182,
291,
14,
6755,
63,
3467,
9,
507,
198,
277,
14,
6755,
14,
6476,
13127,
316,
8,
549,
12,
715,
9,
507,
198,
277,
14,
6755,
14,
1084,
17310,
342,
2742,
198,
3,
13704,
461,
17455,
9150,
507,
198,
277,
14,
6755,
63,
7885,
275,
4818,
14,
10185,
8,
277,
14,
6755,
12,
1568,
2687,
277,
14,
5410,
63,
2063,
446,
4114,
12,
291,
14,
5410,
63,
3333,
1182,
499,
430,
507,
198,
277,
14,
6755,
63,
7885,
14,
8198,
8,
6323,
14,
12093,
63,
8470,
2919,
12,
291,
14,
265,
63,
17486,
9,
507,
198,
277,
14,
6755,
63,
7885,
14,
8198,
8,
6323,
14,
12093,
63,
3078,
63,
8819,
12,
291,
14,
265,
63,
498,
63,
2915,
9,
507,
198,
277,
14,
6755,
63,
7885,
14,
8198,
8,
6323,
14,
12093,
63,
9894,
63,
8819,
12,
291,
14,
265,
63,
10544,
63,
2110,
9,
507,
198,
277,
14,
6755,
14,
8198,
8,
6323,
14,
12093,
63,
8470,
2919,
12,
291,
14,
265,
63,
17486,
9,
507,
198,
277,
14,
6755,
14,
8198,
8,
6323,
14,
12093,
63,
3078,
63,
8819,
12,
291,
14,
265,
63,
498,
63,
2915,
9,
507,
198,
277,
14,
6755,
14,
8198,
8,
6323,
14,
12093,
63,
9894,
63,
8819,
12,
291,
14,
265,
63,
10544,
63,
2110,
9,
2742,
198,
277,
14,
6755,
14,
13776,
342,
507,
198,
277,
14,
13776,
342,
2742,
198,
277,
14,
6755,
63,
7885,
14,
1084,
23370,
2801,
17,
12,
446,
17,
12,
291,
14,
2063,
63,
2065,
12,
291,
14,
3333,
63,
2065,
12,
4818,
14,
4305,
63,
4701,
63,
13301,
1206,
9,
2742,
198,
277,
14,
2424,
275,
488,
2742,
198,
277,
14,
6824,
8,
549,
9,
421,
198,
318,
2739,
63,
475,
63,
5326,
8,
277,
12,
1139,
304,
507,
198,
1107,
1139,
1182,
334,
709,
1011,
650,
9,
627,
291,
14,
10598,
421,
198,
318,
21162,
63,
475,
63,
527,
8,
277,
12,
1139,
304,
507,
198,
1107,
334,
637,
1182,
291,
14,
10598,
9,
627,
334,
709,
1011,
650,
9,
421,
198,
318,
13704,
63,
928,
8,
277,
304,
507,
198,
8,
88,
12,
612,
9,
275,
291,
14,
6755,
14,
1002,
2768,
3162,
342,
507,
198,
1107,
334,
88,
627,
291,
14,
6755,
63,
3467,
12,
612,
627,
291,
14,
6755,
63,
3467,
9,
421,
198,
318,
13704,
63,
928,
63,
527,
8,
277,
304,
507,
198,
8,
88,
12,
612,
9,
275,
291,
14,
6755,
63,
928,
342,
507,
198,
1107,
291,
14,
5326,
63,
475,
63,
527,
8,
88,
9,
421,
198,
318,
32055,
63,
19954,
63,
2619,
8,
277,
12,
14762,
12,
3164,
12,
2746,
63,
2326,
12,
1343,
12,
1284,
304,
507,
198,
2743,
63,
5326,
275,
291,
14,
527,
63,
475,
63,
5326,
8,
928,
446,
291,
14,
1086,
63,
928,
9,
507,
198,
2063,
63,
5326,
275,
291,
14,
527,
63,
475,
63,
5326,
8,
500,
446,
291,
14,
1086,
63,
928,
9,
2742,
198,
2743,
63,
647,
275,
19059,
14,
57,
63,
14839,
435,
334,
7865,
627,
334,
6405,
3160,
14,
4168,
63,
13509,
435,
19059,
14,
4168,
63,
11658,
430,
507,
198,
2063,
63,
647,
275,
19059,
14,
4168,
63,
13509,
2742,
198,
3833,
275,
291,
14,
3833,
2742,
198,
692,
2746,
63,
2326,
365,
440,
488,
26,
686,
198,
8,
82,
12,
486,
12,
330,
9,
275,
2746,
63,
2326,
686,
198,
2119,
63,
2326,
275,
4818,
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,
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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
] |
silverfix/django-concierge
|
concierge/urls.py
|
1
|
1808
|
# -*- coding: utf-8 -
from django.conf.urls import url
from django.contrib.auth import views as django_auth_views
from . import forms
from . import views
urlpatterns = [
url(r'^signup/$', views.SignupView.as_view(template_name='concierge/signup.html'), name='signup'),
url(r'^login/$', django_auth_views.login,
{'authentication_form': forms.LoginForm, 'template_name': 'concierge/login.html'}, name='login'),
url(r'^logout/$', views.LogoutView.as_view(template_name='concierge/logout.html'), name='logout'),
url(r'^password_change/$', django_auth_views.password_change, name='password_change'),
url(r'^password_change/done/$', django_auth_views.password_change_done, name='password_change_done'),
url(r'^password_reset/$', django_auth_views.password_reset,
kwargs={
'template_name': 'concierge/password_reset_form.html',
'post_reset_redirect': 'concierge:password_reset_done',
'email_template_name': 'concierge/password_reset_email.html'
}, name='password_reset'),
url(r'^password_reset/done/$', django_auth_views.password_reset_done,
kwargs={
'template_name': 'concierge/password_reset_done.html',
},
name='password_reset_done'),
url(r'^reset/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$',
django_auth_views.password_reset_confirm,
kwargs={
'template_name': 'concierge/password_reset_confirm.html',
'post_reset_redirect': 'concierge:password_reset_complete'
}, name='password_reset_confirm'),
url(r'^reset/done/$', django_auth_views.password_reset_complete,
kwargs={
'template_name': 'concierge/password_reset_complete.html'
}, name='password_reset_complete'),
]
|
bsd-3-clause
|
[
3,
1882,
2803,
26,
2774,
13,
24,
446,
199,
199,
504,
1639,
14,
2190,
14,
3603,
492,
1166,
199,
199,
504,
1639,
14,
2828,
14,
1178,
492,
6858,
465,
1639,
63,
1178,
63,
4196,
199,
199,
504,
1275,
492,
4513,
199,
504,
1275,
492,
6858,
199,
199,
20050,
275,
359,
272,
1166,
8,
82,
4289,
19799,
10884,
6858,
14,
4940,
384,
2768,
14,
305,
63,
1345,
8,
1160,
63,
354,
534,
388,
559,
8042,
15,
19799,
14,
1360,
659,
536,
534,
19799,
659,
272,
1166,
8,
82,
4289,
2886,
10884,
1639,
63,
1178,
63,
4196,
14,
2886,
12,
267,
791,
11725,
63,
964,
356,
4513,
14,
8880,
2821,
12,
283,
1160,
63,
354,
356,
283,
388,
559,
8042,
15,
2886,
14,
1360,
2267,
536,
534,
2886,
659,
272,
1166,
8,
82,
4289,
11646,
10884,
6858,
14,
2445,
548,
2768,
14,
305,
63,
1345,
8,
1160,
63,
354,
534,
388,
559,
8042,
15,
11646,
14,
1360,
659,
536,
534,
11646,
659,
272,
1166,
8,
82,
4289,
2060,
63,
1461,
10884,
1639,
63,
1178,
63,
4196,
14,
2060,
63,
1461,
12,
536,
534,
2060,
63,
1461,
659,
272,
1166,
8,
82,
4289,
2060,
63,
1461,
15,
4456,
10884,
1639,
63,
1178,
63,
4196,
14,
2060,
63,
1461,
63,
4456,
12,
536,
534,
2060,
63,
1461,
63,
4456,
659,
272,
1166,
8,
82,
4289,
2060,
63,
3958,
10884,
1639,
63,
1178,
63,
4196,
14,
2060,
63,
3958,
12,
267,
2074,
3126,
288,
283,
1160,
63,
354,
356,
283,
388,
559,
8042,
15,
2060,
63,
3958,
63,
964,
14,
1360,
297,
288,
283,
1932,
63,
3958,
63,
4876,
356,
283,
388,
559,
8042,
26,
2060,
63,
3958,
63,
4456,
297,
288,
283,
2123,
63,
1160,
63,
354,
356,
283,
388,
559,
8042,
15,
2060,
63,
3958,
63,
2123,
14,
1360,
7,
267,
1660,
536,
534,
2060,
63,
3958,
659,
272,
1166,
8,
82,
4289,
2060,
63,
3958,
15,
4456,
10884,
1639,
63,
1178,
63,
4196,
14,
2060,
63,
3958,
63,
4456,
12,
267,
2074,
3126,
288,
283,
1160,
63,
354,
356,
283,
388,
559,
8042,
15,
2060,
63,
3958,
63,
4456,
14,
1360,
297,
267,
1660,
267,
536,
534,
2060,
63,
3958,
63,
4456,
659,
272,
1166,
8,
82,
4289,
3958,
9448,
48,
28,
1535,
66,
772,
9514,
16,
13,
25,
33,
13,
13163,
13,
90,
63,
16185,
24598,
2229,
48,
28,
1418,
9514,
16,
13,
25,
33,
13,
13163,
13,
90,
8194,
17,
12,
969,
17063,
59,
16,
13,
25,
33,
13,
13163,
13,
90,
8194,
17,
12,
1165,
1552,
10884,
267,
1639,
63,
1178,
63,
4196,
14,
2060,
63,
3958,
63,
9548,
12,
267,
2074,
3126,
288,
283,
1160,
63,
354,
356,
283,
388,
559,
8042,
15,
2060,
63,
3958,
63,
9548,
14,
1360,
297,
288,
283,
1932,
63,
3958,
63,
4876,
356,
283,
388,
559,
8042,
26,
2060,
63,
3958,
63,
4883,
7,
267,
1660,
536,
534,
2060,
63,
3958,
63,
9548,
659,
272,
1166,
8,
82,
4289,
3958,
15,
4456,
10884,
1639,
63,
1178,
63,
4196,
14,
2060,
63,
3958,
63,
4883,
12,
267,
2074,
3126,
288,
283,
1160,
63,
354,
356,
283,
388,
559,
8042,
15,
2060,
63,
3958,
63,
4883,
14,
1360,
7,
267,
1660,
536,
534,
2060,
63,
3958,
63,
4883,
659,
199,
61,
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
] |
[
1882,
2803,
26,
2774,
13,
24,
446,
199,
199,
504,
1639,
14,
2190,
14,
3603,
492,
1166,
199,
199,
504,
1639,
14,
2828,
14,
1178,
492,
6858,
465,
1639,
63,
1178,
63,
4196,
199,
199,
504,
1275,
492,
4513,
199,
504,
1275,
492,
6858,
199,
199,
20050,
275,
359,
272,
1166,
8,
82,
4289,
19799,
10884,
6858,
14,
4940,
384,
2768,
14,
305,
63,
1345,
8,
1160,
63,
354,
534,
388,
559,
8042,
15,
19799,
14,
1360,
659,
536,
534,
19799,
659,
272,
1166,
8,
82,
4289,
2886,
10884,
1639,
63,
1178,
63,
4196,
14,
2886,
12,
267,
791,
11725,
63,
964,
356,
4513,
14,
8880,
2821,
12,
283,
1160,
63,
354,
356,
283,
388,
559,
8042,
15,
2886,
14,
1360,
2267,
536,
534,
2886,
659,
272,
1166,
8,
82,
4289,
11646,
10884,
6858,
14,
2445,
548,
2768,
14,
305,
63,
1345,
8,
1160,
63,
354,
534,
388,
559,
8042,
15,
11646,
14,
1360,
659,
536,
534,
11646,
659,
272,
1166,
8,
82,
4289,
2060,
63,
1461,
10884,
1639,
63,
1178,
63,
4196,
14,
2060,
63,
1461,
12,
536,
534,
2060,
63,
1461,
659,
272,
1166,
8,
82,
4289,
2060,
63,
1461,
15,
4456,
10884,
1639,
63,
1178,
63,
4196,
14,
2060,
63,
1461,
63,
4456,
12,
536,
534,
2060,
63,
1461,
63,
4456,
659,
272,
1166,
8,
82,
4289,
2060,
63,
3958,
10884,
1639,
63,
1178,
63,
4196,
14,
2060,
63,
3958,
12,
267,
2074,
3126,
288,
283,
1160,
63,
354,
356,
283,
388,
559,
8042,
15,
2060,
63,
3958,
63,
964,
14,
1360,
297,
288,
283,
1932,
63,
3958,
63,
4876,
356,
283,
388,
559,
8042,
26,
2060,
63,
3958,
63,
4456,
297,
288,
283,
2123,
63,
1160,
63,
354,
356,
283,
388,
559,
8042,
15,
2060,
63,
3958,
63,
2123,
14,
1360,
7,
267,
1660,
536,
534,
2060,
63,
3958,
659,
272,
1166,
8,
82,
4289,
2060,
63,
3958,
15,
4456,
10884,
1639,
63,
1178,
63,
4196,
14,
2060,
63,
3958,
63,
4456,
12,
267,
2074,
3126,
288,
283,
1160,
63,
354,
356,
283,
388,
559,
8042,
15,
2060,
63,
3958,
63,
4456,
14,
1360,
297,
267,
1660,
267,
536,
534,
2060,
63,
3958,
63,
4456,
659,
272,
1166,
8,
82,
4289,
3958,
9448,
48,
28,
1535,
66,
772,
9514,
16,
13,
25,
33,
13,
13163,
13,
90,
63,
16185,
24598,
2229,
48,
28,
1418,
9514,
16,
13,
25,
33,
13,
13163,
13,
90,
8194,
17,
12,
969,
17063,
59,
16,
13,
25,
33,
13,
13163,
13,
90,
8194,
17,
12,
1165,
1552,
10884,
267,
1639,
63,
1178,
63,
4196,
14,
2060,
63,
3958,
63,
9548,
12,
267,
2074,
3126,
288,
283,
1160,
63,
354,
356,
283,
388,
559,
8042,
15,
2060,
63,
3958,
63,
9548,
14,
1360,
297,
288,
283,
1932,
63,
3958,
63,
4876,
356,
283,
388,
559,
8042,
26,
2060,
63,
3958,
63,
4883,
7,
267,
1660,
536,
534,
2060,
63,
3958,
63,
9548,
659,
272,
1166,
8,
82,
4289,
3958,
15,
4456,
10884,
1639,
63,
1178,
63,
4196,
14,
2060,
63,
3958,
63,
4883,
12,
267,
2074,
3126,
288,
283,
1160,
63,
354,
356,
283,
388,
559,
8042,
15,
2060,
63,
3958,
63,
4883,
14,
1360,
7,
267,
1660,
536,
534,
2060,
63,
3958,
63,
4883,
659,
199,
61,
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,
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,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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
] |
resmo/ansible
|
test/units/modules/network/onyx/test_onyx_lldp.py
|
23
|
2383
|
#
# (c) 2016 Red Hat Inc.
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from units.compat.mock import patch
from ansible.modules.network.onyx import onyx_lldp
from units.modules.utils import set_module_args
from .onyx_module import TestOnyxModule, load_fixture
class TestOnyxInterfaceModule(TestOnyxModule):
module = onyx_lldp
def setUp(self):
super(TestOnyxInterfaceModule, self).setUp()
self.mock_get_config = patch.object(
onyx_lldp.OnyxLldpModule, "_get_lldp_config")
self.get_config = self.mock_get_config.start()
self.mock_load_config = patch(
'ansible.module_utils.network.onyx.onyx.load_config')
self.load_config = self.mock_load_config.start()
def tearDown(self):
super(TestOnyxInterfaceModule, self).tearDown()
self.mock_get_config.stop()
self.mock_load_config.stop()
def load_fixtures(self, commands=None, transport='cli'):
if commands == ['lldp']:
self.get_config.return_value = None
else:
config_file = 'onyx_lldp_show.cfg'
self.get_config.return_value = load_fixture(config_file)
self.load_config.return_value = None
def test_lldp_no_change(self):
set_module_args(dict())
self.execute_module(changed=False)
def test_lldp_disable(self):
set_module_args(dict(state='absent'))
commands = ['no lldp']
self.execute_module(changed=True, commands=commands)
def test_lldp_enable(self):
set_module_args(dict(state='present'))
commands = ['lldp']
self.execute_module(changed=True, commands=commands)
|
gpl-3.0
|
[
3,
199,
3,
334,
67,
9,
7800,
9572,
13002,
3277,
14,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
3,
4155,
2803,
1655,
2366,
19,
13,
2453,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
504,
6204,
14,
5819,
14,
1805,
492,
3371,
199,
504,
3242,
14,
3112,
14,
1200,
14,
5220,
88,
492,
641,
20937,
63,
24319,
199,
504,
6204,
14,
3112,
14,
1208,
492,
663,
63,
578,
63,
589,
199,
504,
1275,
5220,
88,
63,
578,
492,
1379,
3314,
20937,
2377,
12,
2248,
63,
5997,
421,
199,
533,
1379,
3314,
20937,
4267,
2377,
8,
774,
3314,
20937,
2377,
304,
339,
859,
275,
641,
20937,
63,
24319,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
774,
3314,
20937,
4267,
2377,
12,
291,
680,
5996,
342,
267,
291,
14,
1805,
63,
362,
63,
888,
275,
3371,
14,
785,
8,
288,
641,
20937,
63,
24319,
14,
3314,
20937,
44,
17288,
2377,
12,
2668,
362,
63,
24319,
63,
888,
531,
267,
291,
14,
362,
63,
888,
275,
291,
14,
1805,
63,
362,
63,
888,
14,
928,
342,
398,
291,
14,
1805,
63,
912,
63,
888,
275,
3371,
8,
288,
283,
4853,
14,
578,
63,
1208,
14,
1200,
14,
5220,
88,
14,
5220,
88,
14,
912,
63,
888,
358,
267,
291,
14,
912,
63,
888,
275,
291,
14,
1805,
63,
912,
63,
888,
14,
928,
342,
339,
347,
6766,
8,
277,
304,
267,
1613,
8,
774,
3314,
20937,
4267,
2377,
12,
291,
680,
12336,
342,
267,
291,
14,
1805,
63,
362,
63,
888,
14,
2379,
342,
267,
291,
14,
1805,
63,
912,
63,
888,
14,
2379,
342,
339,
347,
2248,
63,
8769,
8,
277,
12,
3718,
29,
403,
12,
7773,
534,
2764,
735,
267,
340,
3718,
508,
788,
24319,
2565,
288,
291,
14,
362,
63,
888,
14,
1107,
63,
585,
275,
488,
267,
587,
26,
288,
1101,
63,
493,
275,
283,
5220,
88,
63,
24319,
63,
2384,
14,
4128,
7,
288,
291,
14,
362,
63,
888,
14,
1107,
63,
585,
275,
2248,
63,
5997,
8,
888,
63,
493,
9,
267,
291,
14,
912,
63,
888,
14,
1107,
63,
585,
275,
488,
339,
347,
511,
63,
24319,
63,
889,
63,
1461,
8,
277,
304,
267,
663,
63,
578,
63,
589,
8,
807,
1012,
267,
291,
14,
2526,
63,
578,
8,
2489,
29,
797,
9,
339,
347,
511,
63,
24319,
63,
5993,
8,
277,
304,
267,
663,
63,
578,
63,
589,
8,
807,
8,
929,
534,
5575,
1333,
267,
3718,
275,
788,
889,
28768,
418,
267,
291,
14,
2526,
63,
578,
8,
2489,
29,
549,
12,
3718,
29,
4405,
9,
339,
347,
511,
63,
24319,
63,
4296,
8,
277,
304,
267,
663,
63,
578,
63,
589,
8,
807,
8,
929,
534,
1881,
1333,
267,
3718,
275,
788,
24319,
418,
267,
291,
14,
2526,
63,
578,
8,
2489,
29,
549,
12,
3718,
29,
4405,
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
] |
[
199,
3,
334,
67,
9,
7800,
9572,
13002,
3277,
14,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
3,
4155,
2803,
1655,
2366,
19,
13,
2453,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
504,
6204,
14,
5819,
14,
1805,
492,
3371,
199,
504,
3242,
14,
3112,
14,
1200,
14,
5220,
88,
492,
641,
20937,
63,
24319,
199,
504,
6204,
14,
3112,
14,
1208,
492,
663,
63,
578,
63,
589,
199,
504,
1275,
5220,
88,
63,
578,
492,
1379,
3314,
20937,
2377,
12,
2248,
63,
5997,
421,
199,
533,
1379,
3314,
20937,
4267,
2377,
8,
774,
3314,
20937,
2377,
304,
339,
859,
275,
641,
20937,
63,
24319,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
774,
3314,
20937,
4267,
2377,
12,
291,
680,
5996,
342,
267,
291,
14,
1805,
63,
362,
63,
888,
275,
3371,
14,
785,
8,
288,
641,
20937,
63,
24319,
14,
3314,
20937,
44,
17288,
2377,
12,
2668,
362,
63,
24319,
63,
888,
531,
267,
291,
14,
362,
63,
888,
275,
291,
14,
1805,
63,
362,
63,
888,
14,
928,
342,
398,
291,
14,
1805,
63,
912,
63,
888,
275,
3371,
8,
288,
283,
4853,
14,
578,
63,
1208,
14,
1200,
14,
5220,
88,
14,
5220,
88,
14,
912,
63,
888,
358,
267,
291,
14,
912,
63,
888,
275,
291,
14,
1805,
63,
912,
63,
888,
14,
928,
342,
339,
347,
6766,
8,
277,
304,
267,
1613,
8,
774,
3314,
20937,
4267,
2377,
12,
291,
680,
12336,
342,
267,
291,
14,
1805,
63,
362,
63,
888,
14,
2379,
342,
267,
291,
14,
1805,
63,
912,
63,
888,
14,
2379,
342,
339,
347,
2248,
63,
8769,
8,
277,
12,
3718,
29,
403,
12,
7773,
534,
2764,
735,
267,
340,
3718,
508,
788,
24319,
2565,
288,
291,
14,
362,
63,
888,
14,
1107,
63,
585,
275,
488,
267,
587,
26,
288,
1101,
63,
493,
275,
283,
5220,
88,
63,
24319,
63,
2384,
14,
4128,
7,
288,
291,
14,
362,
63,
888,
14,
1107,
63,
585,
275,
2248,
63,
5997,
8,
888,
63,
493,
9,
267,
291,
14,
912,
63,
888,
14,
1107,
63,
585,
275,
488,
339,
347,
511,
63,
24319,
63,
889,
63,
1461,
8,
277,
304,
267,
663,
63,
578,
63,
589,
8,
807,
1012,
267,
291,
14,
2526,
63,
578,
8,
2489,
29,
797,
9,
339,
347,
511,
63,
24319,
63,
5993,
8,
277,
304,
267,
663,
63,
578,
63,
589,
8,
807,
8,
929,
534,
5575,
1333,
267,
3718,
275,
788,
889,
28768,
418,
267,
291,
14,
2526,
63,
578,
8,
2489,
29,
549,
12,
3718,
29,
4405,
9,
339,
347,
511,
63,
24319,
63,
4296,
8,
277,
304,
267,
663,
63,
578,
63,
589,
8,
807,
8,
929,
534,
1881,
1333,
267,
3718,
275,
788,
24319,
418,
267,
291,
14,
2526,
63,
578,
8,
2489,
29,
549,
12,
3718,
29,
4405,
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,
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,
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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
] |
markllama/openshift-ansible
|
roles/lib_openshift/library/oc_serviceaccount_secret.py
|
18
|
60388
|
#!/usr/bin/env python
# pylint: disable=missing-docstring
# flake8: noqa: T001
# ___ ___ _ _ ___ ___ _ _____ ___ ___
# / __| __| \| | __| _ \ /_\_ _| __| \
# | (_ | _|| .` | _|| / / _ \| | | _|| |) |
# \___|___|_|\_|___|_|_\/_/_\_\_|_|___|___/_ _____
# | \ / _ \ | \| |/ _ \_ _| | __| \_ _|_ _|
# | |) | (_) | | .` | (_) || | | _|| |) | | | |
# |___/ \___/ |_|\_|\___/ |_| |___|___/___| |_|
#
# Copyright 2016 Red Hat, Inc. and/or its affiliates
# and other contributors as indicated by the @author tags.
#
# 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.
#
# -*- -*- -*- Begin included fragment: lib/import.py -*- -*- -*-
'''
OpenShiftCLI class that wraps the oc commands in a subprocess
'''
# pylint: disable=too-many-lines
from __future__ import print_function
import atexit
import copy
import fcntl
import json
import time
import os
import re
import shutil
import subprocess
import tempfile
# pylint: disable=import-error
try:
import ruamel.yaml as yaml
except ImportError:
import yaml
from ansible.module_utils.basic import AnsibleModule
# -*- -*- -*- End included fragment: lib/import.py -*- -*- -*-
# -*- -*- -*- Begin included fragment: doc/serviceaccount_secret -*- -*- -*-
DOCUMENTATION = '''
---
module: oc_serviceaccount_secret
short_description: Module to manage openshift service account secrets
description:
- Manage openshift service account secrets programmatically.
options:
state:
description:
- If present, the service account will be linked with the secret if it is not already. If absent, the service account will be unlinked from the secret if it is already linked. If list, information about the service account secrets will be gathered and returned as part of the Ansible call results.
required: false
default: present
choices: ["present", "absent", "list"]
aliases: []
kubeconfig:
description:
- The path for the kubeconfig file to use for authentication
required: false
default: /etc/origin/master/admin.kubeconfig
aliases: []
debug:
description:
- Turn on debug output.
required: false
default: false
aliases: []
service_account:
description:
- Name of the service account.
required: true
default: None
aliases: []
namespace:
description:
- Namespace of the service account and secret.
required: true
default: None
aliases: []
secret:
description:
- The secret that should be linked to the service account.
required: false
default: None
aliases: []
author:
- "Kenny Woodson <kwoodson@redhat.com>"
extends_documentation_fragment: []
'''
EXAMPLES = '''
- name: get secrets of a service account
oc_serviceaccount_secret:
state: list
service_account: builder
namespace: default
register: sasecretout
- name: Link a service account to a specific secret
oc_serviceaccount_secret:
service_account: builder
secret: mynewsecret
namespace: default
register: sasecretout
'''
# -*- -*- -*- End included fragment: doc/serviceaccount_secret -*- -*- -*-
# -*- -*- -*- Begin included fragment: ../../lib_utils/src/class/yedit.py -*- -*- -*-
class YeditException(Exception): # pragma: no cover
''' Exception class for Yedit '''
pass
# pylint: disable=too-many-public-methods,too-many-instance-attributes
class Yedit(object): # pragma: no cover
''' Class to modify yaml files '''
re_valid_key = r"(((\[-?\d+\])|([0-9a-zA-Z%s/_-]+)).?)+$"
re_key = r"(?:\[(-?\d+)\])|([0-9a-zA-Z{}/_-]+)"
com_sep = set(['.', '#', '|', ':'])
# pylint: disable=too-many-arguments
def __init__(self,
filename=None,
content=None,
content_type='yaml',
separator='.',
backup_ext=None,
backup=False):
self.content = content
self._separator = separator
self.filename = filename
self.__yaml_dict = content
self.content_type = content_type
self.backup = backup
if backup_ext is None:
self.backup_ext = ".{}".format(time.strftime("%Y%m%dT%H%M%S"))
else:
self.backup_ext = backup_ext
self.load(content_type=self.content_type)
if self.__yaml_dict is None:
self.__yaml_dict = {}
@property
def separator(self):
''' getter method for separator '''
return self._separator
@separator.setter
def separator(self, inc_sep):
''' setter method for separator '''
self._separator = inc_sep
@property
def yaml_dict(self):
''' getter method for yaml_dict '''
return self.__yaml_dict
@yaml_dict.setter
def yaml_dict(self, value):
''' setter method for yaml_dict '''
self.__yaml_dict = value
@staticmethod
def parse_key(key, sep='.'):
'''parse the key allowing the appropriate separator'''
common_separators = list(Yedit.com_sep - set([sep]))
return re.findall(Yedit.re_key.format(''.join(common_separators)), key)
@staticmethod
def valid_key(key, sep='.'):
'''validate the incoming key'''
common_separators = list(Yedit.com_sep - set([sep]))
if not re.match(Yedit.re_valid_key.format(''.join(common_separators)), key):
return False
return True
# pylint: disable=too-many-return-statements,too-many-branches
@staticmethod
def remove_entry(data, key, index=None, value=None, sep='.'):
''' remove data at location key '''
if key == '' and isinstance(data, dict):
if value is not None:
data.pop(value)
elif index is not None:
raise YeditException("remove_entry for a dictionary does not have an index {}".format(index))
else:
data.clear()
return True
elif key == '' and isinstance(data, list):
ind = None
if value is not None:
try:
ind = data.index(value)
except ValueError:
return False
elif index is not None:
ind = index
else:
del data[:]
if ind is not None:
data.pop(ind)
return True
if not (key and Yedit.valid_key(key, sep)) and \
isinstance(data, (list, dict)):
return None
key_indexes = Yedit.parse_key(key, sep)
for arr_ind, dict_key in key_indexes[:-1]:
if dict_key and isinstance(data, dict):
data = data.get(dict_key)
elif (arr_ind and isinstance(data, list) and
int(arr_ind) <= len(data) - 1):
data = data[int(arr_ind)]
else:
return None
# process last index for remove
# expected list entry
if key_indexes[-1][0]:
if isinstance(data, list) and int(key_indexes[-1][0]) <= len(data) - 1: # noqa: E501
del data[int(key_indexes[-1][0])]
return True
# expected dict entry
elif key_indexes[-1][1]:
if isinstance(data, dict):
del data[key_indexes[-1][1]]
return True
@staticmethod
def add_entry(data, key, item=None, sep='.'):
''' Get an item from a dictionary with key notation a.b.c
d = {'a': {'b': 'c'}}}
key = a#b
return c
'''
if key == '':
pass
elif (not (key and Yedit.valid_key(key, sep)) and
isinstance(data, (list, dict))):
return None
key_indexes = Yedit.parse_key(key, sep)
for arr_ind, dict_key in key_indexes[:-1]:
if dict_key:
if isinstance(data, dict) and dict_key in data and data[dict_key]: # noqa: E501
data = data[dict_key]
continue
elif data and not isinstance(data, dict):
raise YeditException("Unexpected item type found while going through key " +
"path: {} (at key: {})".format(key, dict_key))
data[dict_key] = {}
data = data[dict_key]
elif (arr_ind and isinstance(data, list) and
int(arr_ind) <= len(data) - 1):
data = data[int(arr_ind)]
else:
raise YeditException("Unexpected item type found while going through key path: {}".format(key))
if key == '':
data = item
# process last index for add
# expected list entry
elif key_indexes[-1][0] and isinstance(data, list) and int(key_indexes[-1][0]) <= len(data) - 1: # noqa: E501
data[int(key_indexes[-1][0])] = item
# expected dict entry
elif key_indexes[-1][1] and isinstance(data, dict):
data[key_indexes[-1][1]] = item
# didn't add/update to an existing list, nor add/update key to a dict
# so we must have been provided some syntax like a.b.c[<int>] = "data" for a
# non-existent array
else:
raise YeditException("Error adding to object at path: {}".format(key))
return data
@staticmethod
def get_entry(data, key, sep='.'):
''' Get an item from a dictionary with key notation a.b.c
d = {'a': {'b': 'c'}}}
key = a.b
return c
'''
if key == '':
pass
elif (not (key and Yedit.valid_key(key, sep)) and
isinstance(data, (list, dict))):
return None
key_indexes = Yedit.parse_key(key, sep)
for arr_ind, dict_key in key_indexes:
if dict_key and isinstance(data, dict):
data = data.get(dict_key)
elif (arr_ind and isinstance(data, list) and
int(arr_ind) <= len(data) - 1):
data = data[int(arr_ind)]
else:
return None
return data
@staticmethod
def _write(filename, contents):
''' Actually write the file contents to disk. This helps with mocking. '''
tmp_filename = filename + '.yedit'
with open(tmp_filename, 'w') as yfd:
fcntl.flock(yfd, fcntl.LOCK_EX | fcntl.LOCK_NB)
yfd.write(contents)
fcntl.flock(yfd, fcntl.LOCK_UN)
os.rename(tmp_filename, filename)
def write(self):
''' write to file '''
if not self.filename:
raise YeditException('Please specify a filename.')
if self.backup and self.file_exists():
shutil.copy(self.filename, '{}{}'.format(self.filename, self.backup_ext))
# Try to set format attributes if supported
try:
self.yaml_dict.fa.set_block_style()
except AttributeError:
pass
# Try to use RoundTripDumper if supported.
if self.content_type == 'yaml':
try:
Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper))
except AttributeError:
Yedit._write(self.filename, yaml.safe_dump(self.yaml_dict, default_flow_style=False))
elif self.content_type == 'json':
Yedit._write(self.filename, json.dumps(self.yaml_dict, indent=4, sort_keys=True))
else:
raise YeditException('Unsupported content_type: {}.'.format(self.content_type) +
'Please specify a content_type of yaml or json.')
return (True, self.yaml_dict)
def read(self):
''' read from file '''
# check if it exists
if self.filename is None or not self.file_exists():
return None
contents = None
with open(self.filename) as yfd:
contents = yfd.read()
return contents
def file_exists(self):
''' return whether file exists '''
if os.path.exists(self.filename):
return True
return False
def load(self, content_type='yaml'):
''' return yaml file '''
contents = self.read()
if not contents and not self.content:
return None
if self.content:
if isinstance(self.content, dict):
self.yaml_dict = self.content
return self.yaml_dict
elif isinstance(self.content, str):
contents = self.content
# check if it is yaml
try:
if content_type == 'yaml' and contents:
# Try to set format attributes if supported
try:
self.yaml_dict.fa.set_block_style()
except AttributeError:
pass
# Try to use RoundTripLoader if supported.
try:
self.yaml_dict = yaml.load(contents, yaml.RoundTripLoader)
except AttributeError:
self.yaml_dict = yaml.safe_load(contents)
# Try to set format attributes if supported
try:
self.yaml_dict.fa.set_block_style()
except AttributeError:
pass
elif content_type == 'json' and contents:
self.yaml_dict = json.loads(contents)
except yaml.YAMLError as err:
# Error loading yaml or json
raise YeditException('Problem with loading yaml file. {}'.format(err))
return self.yaml_dict
def get(self, key):
''' get a specified key'''
try:
entry = Yedit.get_entry(self.yaml_dict, key, self.separator)
except KeyError:
entry = None
return entry
def pop(self, path, key_or_item):
''' remove a key, value pair from a dict or an item for a list'''
try:
entry = Yedit.get_entry(self.yaml_dict, path, self.separator)
except KeyError:
entry = None
if entry is None:
return (False, self.yaml_dict)
if isinstance(entry, dict):
# AUDIT:maybe-no-member makes sense due to fuzzy types
# pylint: disable=maybe-no-member
if key_or_item in entry:
entry.pop(key_or_item)
return (True, self.yaml_dict)
return (False, self.yaml_dict)
elif isinstance(entry, list):
# AUDIT:maybe-no-member makes sense due to fuzzy types
# pylint: disable=maybe-no-member
ind = None
try:
ind = entry.index(key_or_item)
except ValueError:
return (False, self.yaml_dict)
entry.pop(ind)
return (True, self.yaml_dict)
return (False, self.yaml_dict)
def delete(self, path, index=None, value=None):
''' remove path from a dict'''
try:
entry = Yedit.get_entry(self.yaml_dict, path, self.separator)
except KeyError:
entry = None
if entry is None:
return (False, self.yaml_dict)
result = Yedit.remove_entry(self.yaml_dict, path, index, value, self.separator)
if not result:
return (False, self.yaml_dict)
return (True, self.yaml_dict)
def exists(self, path, value):
''' check if value exists at path'''
try:
entry = Yedit.get_entry(self.yaml_dict, path, self.separator)
except KeyError:
entry = None
if isinstance(entry, list):
if value in entry:
return True
return False
elif isinstance(entry, dict):
if isinstance(value, dict):
rval = False
for key, val in value.items():
if entry[key] != val:
rval = False
break
else:
rval = True
return rval
return value in entry
return entry == value
def append(self, path, value):
'''append value to a list'''
try:
entry = Yedit.get_entry(self.yaml_dict, path, self.separator)
except KeyError:
entry = None
if entry is None:
self.put(path, [])
entry = Yedit.get_entry(self.yaml_dict, path, self.separator)
if not isinstance(entry, list):
return (False, self.yaml_dict)
# AUDIT:maybe-no-member makes sense due to loading data from
# a serialized format.
# pylint: disable=maybe-no-member
entry.append(value)
return (True, self.yaml_dict)
# pylint: disable=too-many-arguments
def update(self, path, value, index=None, curr_value=None):
''' put path, value into a dict '''
try:
entry = Yedit.get_entry(self.yaml_dict, path, self.separator)
except KeyError:
entry = None
if isinstance(entry, dict):
# AUDIT:maybe-no-member makes sense due to fuzzy types
# pylint: disable=maybe-no-member
if not isinstance(value, dict):
raise YeditException('Cannot replace key, value entry in dict with non-dict type. ' +
'value=[{}] type=[{}]'.format(value, type(value)))
entry.update(value)
return (True, self.yaml_dict)
elif isinstance(entry, list):
# AUDIT:maybe-no-member makes sense due to fuzzy types
# pylint: disable=maybe-no-member
ind = None
if curr_value:
try:
ind = entry.index(curr_value)
except ValueError:
return (False, self.yaml_dict)
elif index is not None:
ind = index
if ind is not None and entry[ind] != value:
entry[ind] = value
return (True, self.yaml_dict)
# see if it exists in the list
try:
ind = entry.index(value)
except ValueError:
# doesn't exist, append it
entry.append(value)
return (True, self.yaml_dict)
# already exists, return
if ind is not None:
return (False, self.yaml_dict)
return (False, self.yaml_dict)
def put(self, path, value):
''' put path, value into a dict '''
try:
entry = Yedit.get_entry(self.yaml_dict, path, self.separator)
except KeyError:
entry = None
if entry == value:
return (False, self.yaml_dict)
# deepcopy didn't work
# Try to use ruamel.yaml and fallback to pyyaml
try:
tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict,
default_flow_style=False),
yaml.RoundTripLoader)
except AttributeError:
tmp_copy = copy.deepcopy(self.yaml_dict)
# set the format attributes if available
try:
tmp_copy.fa.set_block_style()
except AttributeError:
pass
result = Yedit.add_entry(tmp_copy, path, value, self.separator)
if result is None:
return (False, self.yaml_dict)
# When path equals "" it is a special case.
# "" refers to the root of the document
# Only update the root path (entire document) when its a list or dict
if path == '':
if isinstance(result, list) or isinstance(result, dict):
self.yaml_dict = result
return (True, self.yaml_dict)
return (False, self.yaml_dict)
self.yaml_dict = tmp_copy
return (True, self.yaml_dict)
def create(self, path, value):
''' create a yaml file '''
if not self.file_exists():
# deepcopy didn't work
# Try to use ruamel.yaml and fallback to pyyaml
try:
tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict,
default_flow_style=False),
yaml.RoundTripLoader)
except AttributeError:
tmp_copy = copy.deepcopy(self.yaml_dict)
# set the format attributes if available
try:
tmp_copy.fa.set_block_style()
except AttributeError:
pass
result = Yedit.add_entry(tmp_copy, path, value, self.separator)
if result is not None:
self.yaml_dict = tmp_copy
return (True, self.yaml_dict)
return (False, self.yaml_dict)
@staticmethod
def get_curr_value(invalue, val_type):
'''return the current value'''
if invalue is None:
return None
curr_value = invalue
if val_type == 'yaml':
curr_value = yaml.safe_load(str(invalue))
elif val_type == 'json':
curr_value = json.loads(invalue)
return curr_value
@staticmethod
def parse_value(inc_value, vtype=''):
'''determine value type passed'''
true_bools = ['y', 'Y', 'yes', 'Yes', 'YES', 'true', 'True', 'TRUE',
'on', 'On', 'ON', ]
false_bools = ['n', 'N', 'no', 'No', 'NO', 'false', 'False', 'FALSE',
'off', 'Off', 'OFF']
# It came in as a string but you didn't specify value_type as string
# we will convert to bool if it matches any of the above cases
if isinstance(inc_value, str) and 'bool' in vtype:
if inc_value not in true_bools and inc_value not in false_bools:
raise YeditException('Not a boolean type. str=[{}] vtype=[{}]'.format(inc_value, vtype))
elif isinstance(inc_value, bool) and 'str' in vtype:
inc_value = str(inc_value)
# There is a special case where '' will turn into None after yaml loading it so skip
if isinstance(inc_value, str) and inc_value == '':
pass
# If vtype is not str then go ahead and attempt to yaml load it.
elif isinstance(inc_value, str) and 'str' not in vtype:
try:
inc_value = yaml.safe_load(inc_value)
except Exception:
raise YeditException('Could not determine type of incoming value. ' +
'value=[{}] vtype=[{}]'.format(type(inc_value), vtype))
return inc_value
@staticmethod
def process_edits(edits, yamlfile):
'''run through a list of edits and process them one-by-one'''
results = []
for edit in edits:
value = Yedit.parse_value(edit['value'], edit.get('value_type', ''))
if edit.get('action') == 'update':
# pylint: disable=line-too-long
curr_value = Yedit.get_curr_value(
Yedit.parse_value(edit.get('curr_value')),
edit.get('curr_value_format'))
rval = yamlfile.update(edit['key'],
value,
edit.get('index'),
curr_value)
elif edit.get('action') == 'append':
rval = yamlfile.append(edit['key'], value)
else:
rval = yamlfile.put(edit['key'], value)
if rval[0]:
results.append({'key': edit['key'], 'edit': rval[1]})
return {'changed': len(results) > 0, 'results': results}
# pylint: disable=too-many-return-statements,too-many-branches
@staticmethod
def run_ansible(params):
'''perform the idempotent crud operations'''
yamlfile = Yedit(filename=params['src'],
backup=params['backup'],
content_type=params['content_type'],
backup_ext=params['backup_ext'],
separator=params['separator'])
state = params['state']
if params['src']:
rval = yamlfile.load()
if yamlfile.yaml_dict is None and state != 'present':
return {'failed': True,
'msg': 'Error opening file [{}]. Verify that the '.format(params['src']) +
'file exists, that it is has correct permissions, and is valid yaml.'}
if state == 'list':
if params['content']:
content = Yedit.parse_value(params['content'], params['content_type'])
yamlfile.yaml_dict = content
if params['key']:
rval = yamlfile.get(params['key'])
return {'changed': False, 'result': rval, 'state': state}
elif state == 'absent':
if params['content']:
content = Yedit.parse_value(params['content'], params['content_type'])
yamlfile.yaml_dict = content
if params['update']:
rval = yamlfile.pop(params['key'], params['value'])
else:
rval = yamlfile.delete(params['key'], params['index'], params['value'])
if rval[0] and params['src']:
yamlfile.write()
return {'changed': rval[0], 'result': rval[1], 'state': state}
elif state == 'present':
# check if content is different than what is in the file
if params['content']:
content = Yedit.parse_value(params['content'], params['content_type'])
# We had no edits to make and the contents are the same
if yamlfile.yaml_dict == content and \
params['value'] is None:
return {'changed': False, 'result': yamlfile.yaml_dict, 'state': state}
yamlfile.yaml_dict = content
# If we were passed a key, value then
# we enapsulate it in a list and process it
# Key, Value passed to the module : Converted to Edits list #
edits = []
_edit = {}
if params['value'] is not None:
_edit['value'] = params['value']
_edit['value_type'] = params['value_type']
_edit['key'] = params['key']
if params['update']:
_edit['action'] = 'update'
_edit['curr_value'] = params['curr_value']
_edit['curr_value_format'] = params['curr_value_format']
_edit['index'] = params['index']
elif params['append']:
_edit['action'] = 'append'
edits.append(_edit)
elif params['edits'] is not None:
edits = params['edits']
if edits:
results = Yedit.process_edits(edits, yamlfile)
# if there were changes and a src provided to us we need to write
if results['changed'] and params['src']:
yamlfile.write()
return {'changed': results['changed'], 'result': results['results'], 'state': state}
# no edits to make
if params['src']:
# pylint: disable=redefined-variable-type
rval = yamlfile.write()
return {'changed': rval[0],
'result': rval[1],
'state': state}
# We were passed content but no src, key or value, or edits. Return contents in memory
return {'changed': False, 'result': yamlfile.yaml_dict, 'state': state}
return {'failed': True, 'msg': 'Unkown state passed'}
# -*- -*- -*- End included fragment: ../../lib_utils/src/class/yedit.py -*- -*- -*-
# -*- -*- -*- Begin included fragment: lib/base.py -*- -*- -*-
# pylint: disable=too-many-lines
# noqa: E301,E302,E303,T001
class OpenShiftCLIError(Exception):
'''Exception class for openshiftcli'''
pass
ADDITIONAL_PATH_LOOKUPS = ['/usr/local/bin', os.path.expanduser('~/bin')]
def locate_oc_binary():
''' Find and return oc binary file '''
# https://github.com/openshift/openshift-ansible/issues/3410
# oc can be in /usr/local/bin in some cases, but that may not
# be in $PATH due to ansible/sudo
paths = os.environ.get("PATH", os.defpath).split(os.pathsep) + ADDITIONAL_PATH_LOOKUPS
oc_binary = 'oc'
# Use shutil.which if it is available, otherwise fallback to a naive path search
try:
which_result = shutil.which(oc_binary, path=os.pathsep.join(paths))
if which_result is not None:
oc_binary = which_result
except AttributeError:
for path in paths:
if os.path.exists(os.path.join(path, oc_binary)):
oc_binary = os.path.join(path, oc_binary)
break
return oc_binary
# pylint: disable=too-few-public-methods
class OpenShiftCLI(object):
''' Class to wrap the command line tools '''
def __init__(self,
namespace,
kubeconfig='/etc/origin/master/admin.kubeconfig',
verbose=False,
all_namespaces=False):
''' Constructor for OpenshiftCLI '''
self.namespace = namespace
self.verbose = verbose
self.kubeconfig = Utils.create_tmpfile_copy(kubeconfig)
self.all_namespaces = all_namespaces
self.oc_binary = locate_oc_binary()
# Pylint allows only 5 arguments to be passed.
# pylint: disable=too-many-arguments
def _replace_content(self, resource, rname, content, edits=None, force=False, sep='.'):
''' replace the current object with the content '''
res = self._get(resource, rname)
if not res['results']:
return res
fname = Utils.create_tmpfile(rname + '-')
yed = Yedit(fname, res['results'][0], separator=sep)
updated = False
if content is not None:
changes = []
for key, value in content.items():
changes.append(yed.put(key, value))
if any([change[0] for change in changes]):
updated = True
elif edits is not None:
results = Yedit.process_edits(edits, yed)
if results['changed']:
updated = True
if updated:
yed.write()
atexit.register(Utils.cleanup, [fname])
return self._replace(fname, force)
return {'returncode': 0, 'updated': False}
def _replace(self, fname, force=False):
'''replace the current object with oc replace'''
# We are removing the 'resourceVersion' to handle
# a race condition when modifying oc objects
yed = Yedit(fname)
results = yed.delete('metadata.resourceVersion')
if results[0]:
yed.write()
cmd = ['replace', '-f', fname]
if force:
cmd.append('--force')
return self.openshift_cmd(cmd)
def _create_from_content(self, rname, content):
'''create a temporary file and then call oc create on it'''
fname = Utils.create_tmpfile(rname + '-')
yed = Yedit(fname, content=content)
yed.write()
atexit.register(Utils.cleanup, [fname])
return self._create(fname)
def _create(self, fname):
'''call oc create on a filename'''
return self.openshift_cmd(['create', '-f', fname])
def _delete(self, resource, name=None, selector=None):
'''call oc delete on a resource'''
cmd = ['delete', resource]
if selector is not None:
cmd.append('--selector={}'.format(selector))
elif name is not None:
cmd.append(name)
else:
raise OpenShiftCLIError('Either name or selector is required when calling delete.')
return self.openshift_cmd(cmd)
def _process(self, template_name, create=False, params=None, template_data=None): # noqa: E501
'''process a template
template_name: the name of the template to process
create: whether to send to oc create after processing
params: the parameters for the template
template_data: the incoming template's data; instead of a file
'''
cmd = ['process']
if template_data:
cmd.extend(['-f', '-'])
else:
cmd.append(template_name)
if params:
param_str = ["{}={}".format(key, str(value).replace("'", r'"')) for key, value in params.items()]
cmd.append('-p')
cmd.extend(param_str)
results = self.openshift_cmd(cmd, output=True, input_data=template_data)
if results['returncode'] != 0 or not create:
return results
fname = Utils.create_tmpfile(template_name + '-')
yed = Yedit(fname, results['results'])
yed.write()
atexit.register(Utils.cleanup, [fname])
return self.openshift_cmd(['create', '-f', fname])
def _get(self, resource, name=None, selector=None, field_selector=None):
'''return a resource by name '''
cmd = ['get', resource]
if selector is not None:
cmd.append('--selector={}'.format(selector))
if field_selector is not None:
cmd.append('--field-selector={}'.format(field_selector))
# Name cannot be used with selector or field_selector.
if selector is None and field_selector is None and name is not None:
cmd.append(name)
cmd.extend(['-o', 'json'])
rval = self.openshift_cmd(cmd, output=True)
# Ensure results are retuned in an array
if 'items' in rval:
rval['results'] = rval['items']
elif not isinstance(rval['results'], list):
rval['results'] = [rval['results']]
return rval
def _schedulable(self, node=None, selector=None, schedulable=True):
''' perform oadm manage-node scheduable '''
cmd = ['manage-node']
if node:
cmd.extend(node)
else:
cmd.append('--selector={}'.format(selector))
cmd.append('--schedulable={}'.format(schedulable))
return self.openshift_cmd(cmd, oadm=True, output=True, output_type='raw') # noqa: E501
def _list_pods(self, node=None, selector=None, pod_selector=None):
''' perform oadm list pods
node: the node in which to list pods
selector: the label selector filter if provided
pod_selector: the pod selector filter if provided
'''
cmd = ['manage-node']
if node:
cmd.extend(node)
else:
cmd.append('--selector={}'.format(selector))
if pod_selector:
cmd.append('--pod-selector={}'.format(pod_selector))
cmd.extend(['--list-pods', '-o', 'json'])
return self.openshift_cmd(cmd, oadm=True, output=True, output_type='raw')
# pylint: disable=too-many-arguments
def _evacuate(self, node=None, selector=None, pod_selector=None, dry_run=False, grace_period=None, force=False):
''' perform oadm manage-node evacuate '''
cmd = ['manage-node']
if node:
cmd.extend(node)
else:
cmd.append('--selector={}'.format(selector))
if dry_run:
cmd.append('--dry-run')
if pod_selector:
cmd.append('--pod-selector={}'.format(pod_selector))
if grace_period:
cmd.append('--grace-period={}'.format(int(grace_period)))
if force:
cmd.append('--force')
cmd.append('--evacuate')
return self.openshift_cmd(cmd, oadm=True, output=True, output_type='raw')
def _version(self):
''' return the openshift version'''
return self.openshift_cmd(['version'], output=True, output_type='raw')
def _import_image(self, url=None, name=None, tag=None):
''' perform image import '''
cmd = ['import-image']
image = '{0}'.format(name)
if tag:
image += ':{0}'.format(tag)
cmd.append(image)
if url:
cmd.append('--from={0}/{1}'.format(url, image))
cmd.append('-n{0}'.format(self.namespace))
cmd.append('--confirm')
return self.openshift_cmd(cmd)
def _run(self, cmds, input_data):
''' Actually executes the command. This makes mocking easier. '''
curr_env = os.environ.copy()
curr_env.update({'KUBECONFIG': self.kubeconfig})
proc = subprocess.Popen(cmds,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
env=curr_env)
stdout, stderr = proc.communicate(input_data)
return proc.returncode, stdout.decode('utf-8'), stderr.decode('utf-8')
# pylint: disable=too-many-arguments,too-many-branches
def openshift_cmd(self, cmd, oadm=False, output=False, output_type='json', input_data=None):
'''Base command for oc '''
cmds = [self.oc_binary]
if oadm:
cmds.append('adm')
cmds.extend(cmd)
if self.all_namespaces:
cmds.extend(['--all-namespaces'])
elif self.namespace is not None and self.namespace.lower() not in ['none', 'emtpy']: # E501
cmds.extend(['-n', self.namespace])
if self.verbose:
print(' '.join(cmds))
try:
returncode, stdout, stderr = self._run(cmds, input_data)
except OSError as ex:
returncode, stdout, stderr = 1, '', 'Failed to execute {}: {}'.format(subprocess.list2cmdline(cmds), ex)
rval = {"returncode": returncode,
"cmd": ' '.join(cmds)}
if output_type == 'json':
rval['results'] = {}
if output and stdout:
try:
rval['results'] = json.loads(stdout)
except ValueError as verr:
if "No JSON object could be decoded" in verr.args:
rval['err'] = verr.args
elif output_type == 'raw':
rval['results'] = stdout if output else ''
if self.verbose:
print("STDOUT: {0}".format(stdout))
print("STDERR: {0}".format(stderr))
if 'err' in rval or returncode != 0:
rval.update({"stderr": stderr,
"stdout": stdout})
return rval
class Utils(object): # pragma: no cover
''' utilities for openshiftcli modules '''
@staticmethod
def _write(filename, contents):
''' Actually write the file contents to disk. This helps with mocking. '''
with open(filename, 'w') as sfd:
sfd.write(str(contents))
@staticmethod
def create_tmp_file_from_contents(rname, data, ftype='yaml'):
''' create a file in tmp with name and contents'''
tmp = Utils.create_tmpfile(prefix=rname)
if ftype == 'yaml':
# AUDIT:no-member makes sense here due to ruamel.YAML/PyYAML usage
# pylint: disable=no-member
if hasattr(yaml, 'RoundTripDumper'):
Utils._write(tmp, yaml.dump(data, Dumper=yaml.RoundTripDumper))
else:
Utils._write(tmp, yaml.safe_dump(data, default_flow_style=False))
elif ftype == 'json':
Utils._write(tmp, json.dumps(data))
else:
Utils._write(tmp, data)
# Register cleanup when module is done
atexit.register(Utils.cleanup, [tmp])
return tmp
@staticmethod
def create_tmpfile_copy(inc_file):
'''create a temporary copy of a file'''
tmpfile = Utils.create_tmpfile('lib_openshift-')
Utils._write(tmpfile, open(inc_file).read())
# Cleanup the tmpfile
atexit.register(Utils.cleanup, [tmpfile])
return tmpfile
@staticmethod
def create_tmpfile(prefix='tmp'):
''' Generates and returns a temporary file name '''
with tempfile.NamedTemporaryFile(prefix=prefix, delete=False) as tmp:
return tmp.name
@staticmethod
def create_tmp_files_from_contents(content, content_type=None):
'''Turn an array of dict: filename, content into a files array'''
if not isinstance(content, list):
content = [content]
files = []
for item in content:
path = Utils.create_tmp_file_from_contents(item['path'] + '-',
item['data'],
ftype=content_type)
files.append({'name': os.path.basename(item['path']),
'path': path})
return files
@staticmethod
def cleanup(files):
'''Clean up on exit '''
for sfile in files:
if os.path.exists(sfile):
if os.path.isdir(sfile):
shutil.rmtree(sfile)
elif os.path.isfile(sfile):
os.remove(sfile)
@staticmethod
def exists(results, _name):
''' Check to see if the results include the name '''
if not results:
return False
if Utils.find_result(results, _name):
return True
return False
@staticmethod
def find_result(results, _name):
''' Find the specified result by name'''
rval = None
for result in results:
if 'metadata' in result and result['metadata']['name'] == _name:
rval = result
break
return rval
@staticmethod
def get_resource_file(sfile, sfile_type='yaml'):
''' return the service file '''
contents = None
with open(sfile) as sfd:
contents = sfd.read()
if sfile_type == 'yaml':
# AUDIT:no-member makes sense here due to ruamel.YAML/PyYAML usage
# pylint: disable=no-member
if hasattr(yaml, 'RoundTripLoader'):
contents = yaml.load(contents, yaml.RoundTripLoader)
else:
contents = yaml.safe_load(contents)
elif sfile_type == 'json':
contents = json.loads(contents)
return contents
@staticmethod
def filter_versions(stdout):
''' filter the oc version output '''
version_dict = {}
version_search = ['oc', 'openshift', 'kubernetes']
for line in stdout.strip().split('\n'):
for term in version_search:
if not line:
continue
if line.startswith(term):
version_dict[term] = line.split()[-1]
# horrible hack to get openshift version in Openshift 3.2
# By default "oc version in 3.2 does not return an "openshift" version
if "openshift" not in version_dict:
version_dict["openshift"] = version_dict["oc"]
return version_dict
@staticmethod
def add_custom_versions(versions):
''' create custom versions strings '''
versions_dict = {}
for tech, version in versions.items():
# clean up "-" from version
if "-" in version:
version = version.split("-")[0]
if version.startswith('v'):
version = version[1:] # Remove the 'v' prefix
versions_dict[tech + '_numeric'] = version.split('+')[0]
# "3.3.0.33" is what we have, we want "3.3"
versions_dict[tech + '_short'] = "{}.{}".format(*version.split('.'))
return versions_dict
@staticmethod
def openshift_installed():
''' check if openshift is installed '''
import rpm
transaction_set = rpm.TransactionSet()
rpmquery = transaction_set.dbMatch("name", "atomic-openshift")
return rpmquery.count() > 0
# Disabling too-many-branches. This is a yaml dictionary comparison function
# pylint: disable=too-many-branches,too-many-return-statements,too-many-statements
@staticmethod
def check_def_equal(user_def, result_def, skip_keys=None, debug=False):
''' Given a user defined definition, compare it with the results given back by our query. '''
# Currently these values are autogenerated and we do not need to check them
skip = ['metadata', 'status']
if skip_keys:
skip.extend(skip_keys)
for key, value in result_def.items():
if key in skip:
continue
# Both are lists
if isinstance(value, list):
if key not in user_def:
if debug:
print('User data does not have key [%s]' % key)
print('User data: %s' % user_def)
return False
if not isinstance(user_def[key], list):
if debug:
print('user_def[key] is not a list key=[%s] user_def[key]=%s' % (key, user_def[key]))
return False
if len(user_def[key]) != len(value):
if debug:
print("List lengths are not equal.")
print("key=[%s]: user_def[%s] != value[%s]" % (key, len(user_def[key]), len(value)))
print("user_def: %s" % user_def[key])
print("value: %s" % value)
return False
for values in zip(user_def[key], value):
if isinstance(values[0], dict) and isinstance(values[1], dict):
if debug:
print('sending list - list')
print(type(values[0]))
print(type(values[1]))
result = Utils.check_def_equal(values[0], values[1], skip_keys=skip_keys, debug=debug)
if not result:
print('list compare returned false')
return False
elif value != user_def[key]:
if debug:
print('value should be identical')
print(user_def[key])
print(value)
return False
# recurse on a dictionary
elif isinstance(value, dict):
if key not in user_def:
if debug:
print("user_def does not have key [%s]" % key)
return False
if not isinstance(user_def[key], dict):
if debug:
print("dict returned false: not instance of dict")
return False
# before passing ensure keys match
api_values = set(value.keys()) - set(skip)
user_values = set(user_def[key].keys()) - set(skip)
if api_values != user_values:
if debug:
print("keys are not equal in dict")
print(user_values)
print(api_values)
return False
result = Utils.check_def_equal(user_def[key], value, skip_keys=skip_keys, debug=debug)
if not result:
if debug:
print("dict returned false")
print(result)
return False
# Verify each key, value pair is the same
else:
if key not in user_def or value != user_def[key]:
if debug:
print("value not equal; user_def does not have key")
print(key)
print(value)
if key in user_def:
print(user_def[key])
return False
if debug:
print('returning true')
return True
class OpenShiftCLIConfig(object):
'''Generic Config'''
def __init__(self, rname, namespace, kubeconfig, options):
self.kubeconfig = kubeconfig
self.name = rname
self.namespace = namespace
self._options = options
@property
def config_options(self):
''' return config options '''
return self._options
def to_option_list(self, ascommalist=''):
'''return all options as a string
if ascommalist is set to the name of a key, and
the value of that key is a dict, format the dict
as a list of comma delimited key=value pairs'''
return self.stringify(ascommalist)
def stringify(self, ascommalist=''):
''' return the options hash as cli params in a string
if ascommalist is set to the name of a key, and
the value of that key is a dict, format the dict
as a list of comma delimited key=value pairs '''
rval = []
for key in sorted(self.config_options.keys()):
data = self.config_options[key]
if data['include'] \
and (data['value'] is not None or isinstance(data['value'], int)):
if key == ascommalist:
val = ','.join(['{}={}'.format(kk, vv) for kk, vv in sorted(data['value'].items())])
else:
val = data['value']
rval.append('--{}={}'.format(key.replace('_', '-'), val))
return rval
# -*- -*- -*- End included fragment: lib/base.py -*- -*- -*-
# -*- -*- -*- Begin included fragment: lib/serviceaccount.py -*- -*- -*-
class ServiceAccountConfig(object):
'''Service account config class
This class stores the options and returns a default service account
'''
# pylint: disable=too-many-arguments
def __init__(self, sname, namespace, kubeconfig, secrets=None, image_pull_secrets=None):
self.name = sname
self.kubeconfig = kubeconfig
self.namespace = namespace
self.secrets = secrets or []
self.image_pull_secrets = image_pull_secrets or []
self.data = {}
self.create_dict()
def create_dict(self):
''' instantiate a properly structured volume '''
self.data['apiVersion'] = 'v1'
self.data['kind'] = 'ServiceAccount'
self.data['metadata'] = {}
self.data['metadata']['name'] = self.name
self.data['metadata']['namespace'] = self.namespace
self.data['secrets'] = []
if self.secrets:
for sec in self.secrets:
self.data['secrets'].append({"name": sec})
self.data['imagePullSecrets'] = []
if self.image_pull_secrets:
for sec in self.image_pull_secrets:
self.data['imagePullSecrets'].append({"name": sec})
class ServiceAccount(Yedit):
''' Class to wrap the oc command line tools '''
image_pull_secrets_path = "imagePullSecrets"
secrets_path = "secrets"
def __init__(self, content):
'''ServiceAccount constructor'''
super(ServiceAccount, self).__init__(content=content)
self._secrets = None
self._image_pull_secrets = None
@property
def image_pull_secrets(self):
''' property for image_pull_secrets '''
if self._image_pull_secrets is None:
self._image_pull_secrets = self.get(ServiceAccount.image_pull_secrets_path) or []
return self._image_pull_secrets
@image_pull_secrets.setter
def image_pull_secrets(self, secrets):
''' property for secrets '''
self._image_pull_secrets = secrets
@property
def secrets(self):
''' property for secrets '''
if not self._secrets:
self._secrets = self.get(ServiceAccount.secrets_path) or []
return self._secrets
@secrets.setter
def secrets(self, secrets):
''' property for secrets '''
self._secrets = secrets
def delete_secret(self, inc_secret):
''' remove a secret '''
remove_idx = None
for idx, sec in enumerate(self.secrets):
if sec['name'] == inc_secret:
remove_idx = idx
break
if remove_idx:
del self.secrets[remove_idx]
return True
return False
def delete_image_pull_secret(self, inc_secret):
''' remove a image_pull_secret '''
remove_idx = None
for idx, sec in enumerate(self.image_pull_secrets):
if sec['name'] == inc_secret:
remove_idx = idx
break
if remove_idx:
del self.image_pull_secrets[remove_idx]
return True
return False
def find_secret(self, inc_secret):
'''find secret'''
for secret in self.secrets:
if secret['name'] == inc_secret:
return secret
return None
def find_image_pull_secret(self, inc_secret):
'''find secret'''
for secret in self.image_pull_secrets:
if secret['name'] == inc_secret:
return secret
return None
def add_secret(self, inc_secret):
'''add secret'''
if self.secrets:
self.secrets.append({"name": inc_secret}) # pylint: disable=no-member
else:
self.put(ServiceAccount.secrets_path, [{"name": inc_secret}])
def add_image_pull_secret(self, inc_secret):
'''add image_pull_secret'''
if self.image_pull_secrets:
self.image_pull_secrets.append({"name": inc_secret}) # pylint: disable=no-member
else:
self.put(ServiceAccount.image_pull_secrets_path, [{"name": inc_secret}])
# -*- -*- -*- End included fragment: lib/serviceaccount.py -*- -*- -*-
# -*- -*- -*- Begin included fragment: class/oc_serviceaccount_secret.py -*- -*- -*-
class OCServiceAccountSecret(OpenShiftCLI):
''' Class to wrap the oc command line tools '''
kind = 'sa'
def __init__(self, config, verbose=False):
''' Constructor for OpenshiftOC '''
super(OCServiceAccountSecret, self).__init__(config.namespace, kubeconfig=config.kubeconfig, verbose=verbose)
self.config = config
self.verbose = verbose
self._service_account = None
@property
def service_account(self):
''' Property for the service account '''
if not self._service_account:
self.get()
return self._service_account
@service_account.setter
def service_account(self, data):
''' setter for the service account '''
self._service_account = data
def exists(self, in_secret):
''' verifies if secret exists in the service account '''
result = self.service_account.find_secret(in_secret)
if not result:
return False
return True
def get(self):
''' get the service account definition from the master '''
sao = self._get(OCServiceAccountSecret.kind, self.config.name)
if sao['returncode'] == 0:
self.service_account = ServiceAccount(content=sao['results'][0])
sao['results'] = self.service_account.get('secrets')
return sao
def delete(self):
''' delete secrets '''
modified = []
for rem_secret in self.config.secrets:
modified.append(self.service_account.delete_secret(rem_secret))
if any(modified):
return self._replace_content(OCServiceAccountSecret.kind, self.config.name, self.service_account.yaml_dict)
return {'returncode': 0, 'changed': False}
def put(self):
''' place secrets into sa '''
modified = False
for add_secret in self.config.secrets:
if not self.service_account.find_secret(add_secret):
self.service_account.add_secret(add_secret)
modified = True
if modified:
return self._replace_content(OCServiceAccountSecret.kind, self.config.name, self.service_account.yaml_dict)
return {'returncode': 0, 'changed': False}
@staticmethod
# pylint: disable=too-many-return-statements,too-many-branches
# TODO: This function should be refactored into its individual parts.
def run_ansible(params, check_mode):
''' run the oc_serviceaccount_secret module'''
sconfig = ServiceAccountConfig(params['service_account'],
params['namespace'],
params['kubeconfig'],
[params['secret']],
None)
oc_sa_sec = OCServiceAccountSecret(sconfig, verbose=params['debug'])
state = params['state']
api_rval = oc_sa_sec.get()
#####
# Get
#####
if state == 'list':
return {'changed': False, 'results': api_rval['results'], 'state': "list"}
########
# Delete
########
if state == 'absent':
if oc_sa_sec.exists(params['secret']):
if check_mode:
return {'changed': True, 'msg': 'Would have removed the " + \
"secret from the service account.'}
api_rval = oc_sa_sec.delete()
return {'changed': True, 'results': api_rval, 'state': "absent"}
return {'changed': False, 'state': "absent"}
if state == 'present':
########
# Create
########
if not oc_sa_sec.exists(params['secret']):
if check_mode:
return {'changed': True, 'msg': 'Would have added the ' + \
'secret to the service account.'}
# Create it here
api_rval = oc_sa_sec.put()
if api_rval['returncode'] != 0:
return {'failed': True, 'msg': api_rval}
# return the created object
api_rval = oc_sa_sec.get()
if api_rval['returncode'] != 0:
return {'failed': True, 'msg': api_rval}
return {'changed': True, 'results': api_rval, 'state': "present"}
return {'changed': False, 'results': api_rval, 'state': "present"}
return {'failed': True,
'changed': False,
'msg': 'Unknown state passed. %s' % state,
'state': 'unknown'}
# -*- -*- -*- End included fragment: class/oc_serviceaccount_secret.py -*- -*- -*-
# -*- -*- -*- Begin included fragment: ansible/oc_serviceaccount_secret.py -*- -*- -*-
def main():
'''
ansible oc module to manage service account secrets.
'''
module = AnsibleModule(
argument_spec=dict(
kubeconfig=dict(default='/etc/origin/master/admin.kubeconfig', type='str'),
state=dict(default='present', type='str',
choices=['present', 'absent', 'list']),
debug=dict(default=False, type='bool'),
namespace=dict(default=None, required=True, type='str'),
secret=dict(default=None, type='str'),
service_account=dict(required=True, type='str'),
),
supports_check_mode=True,
)
rval = OCServiceAccountSecret.run_ansible(module.params, module.check_mode)
if 'failed' in rval:
module.fail_json(**rval)
module.exit_json(**rval)
if __name__ == '__main__':
main()
# -*- -*- -*- End included fragment: ansible/oc_serviceaccount_secret.py -*- -*- -*-
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
4287,
26,
3507,
29,
4752,
13,
12485,
199,
3,
27510,
24,
26,
8151,
26,
377,
4587,
199,
3,
258,
31111,
31111,
485,
221,
485,
31111,
31111,
259,
485,
636,
8989,
31111,
31111,
199,
3,
259,
1182,
636,
92,
636,
92,
971,
92,
1204,
636,
92,
485,
971,
221,
1182,
18005,
63,
257,
485,
92,
636,
92,
257,
971,
199,
3,
257,
1204,
6110,
1204,
485,
10644,
1275,
64,
1204,
485,
10644,
257,
1182,
1182,
485,
971,
92,
1204,
1204,
485,
10644,
1204,
9,
1204,
199,
3,
259,
971,
8989,
92,
8989,
30007,
6113,
63,
92,
8989,
30007,
92,
18005,
15607,
15607,
60,
18005,
63,
30007,
92,
8989,
92,
8989,
15607,
636,
8989,
199,
3,
257,
1204,
257,
971,
1182,
485,
971,
221,
1204,
971,
92,
1204,
15,
485,
971,
63,
257,
485,
92,
1204,
636,
92,
257,
971,
63,
485,
30007,
257,
485,
92,
199,
3,
257,
1204,
1204,
9,
1204,
334,
4602,
1204,
1204,
1275,
64,
1204,
334,
4602,
12208,
1204,
257,
1204,
485,
10644,
1204,
9,
1204,
1204,
221,
1204,
1204,
199,
3,
257,
1204,
8989,
15,
971,
8989,
15,
221,
1204,
63,
6113,
63,
6113,
8989,
15,
1204,
63,
92,
257,
1204,
8989,
92,
8989,
15,
8989,
92,
1204,
63,
92,
199,
3,
199,
3,
1898,
7800,
9572,
13002,
12,
3277,
14,
436,
15,
269,
2399,
29172,
2335,
199,
3,
436,
1163,
8417,
465,
22141,
701,
314,
768,
2502,
3762,
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,
3,
199,
199,
3,
1882,
1882,
1882,
25754,
5120,
7956,
26,
1973,
15,
646,
14,
647,
1882,
1882,
1882,
199,
2344,
2043,
3232,
14379,
7802,
1021,
626,
14018,
314,
4244,
3718,
315,
282,
3873,
199,
2344,
199,
3,
4287,
26,
3507,
29,
7354,
13,
3479,
13,
1278,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
646,
19840,
199,
646,
1331,
199,
646,
12871,
199,
646,
2022,
199,
646,
900,
199,
646,
747,
199,
646,
295,
199,
646,
5145,
199,
646,
3873,
199,
646,
5549,
199,
3,
4287,
26,
3507,
29,
646,
13,
705,
199,
893,
26,
272,
492,
519,
85,
14868,
14,
5963,
465,
8864,
199,
2590,
3545,
26,
272,
492,
8864,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
199,
199,
3,
1882,
1882,
1882,
9599,
5120,
7956,
26,
1973,
15,
646,
14,
647,
1882,
1882,
1882,
199,
199,
3,
1882,
1882,
1882,
25754,
5120,
7956,
26,
1382,
15,
1364,
2048,
63,
4731,
1882,
1882,
1882,
199,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
4244,
63,
1364,
2048,
63,
4731,
199,
3612,
63,
1802,
26,
5673,
370,
9635,
1551,
4723,
2435,
2933,
25563,
199,
1802,
26,
523,
446,
14944,
1551,
4723,
2435,
2933,
25563,
2240,
17174,
14,
199,
1419,
26,
523,
1174,
26,
272,
1369,
26,
272,
446,
982,
3451,
12,
314,
2435,
2933,
911,
506,
10632,
543,
314,
7565,
340,
652,
365,
440,
2575,
14,
982,
9552,
12,
314,
2435,
2933,
911,
506,
625,
12751,
687,
314,
7565,
340,
652,
365,
2575,
10632,
14,
982,
769,
12,
2556,
3595,
314,
2435,
2933,
25563,
911,
506,
16072,
31051,
436,
2138,
465,
1777,
402,
314,
2622,
1240,
2058,
14,
272,
1415,
26,
3055,
272,
849,
26,
3451,
272,
3415,
26,
2097,
1881,
401,
298,
5575,
401,
298,
513,
937,
272,
5481,
26,
942,
523,
23091,
888,
26,
272,
1369,
26,
272,
446,
710,
931,
367,
314,
23091,
888,
570,
370,
675,
367,
6299,
272,
1415,
26,
3055,
272,
849,
26,
1182,
6839,
15,
6493,
15,
4133,
15,
2113,
14,
29192,
272,
5481,
26,
942,
523,
3105,
26,
272,
1369,
26,
272,
446,
16147,
641,
3105,
1072,
14,
272,
1415,
26,
3055,
272,
849,
26,
3055,
272,
5481,
26,
942,
523,
2435,
63,
2048,
26,
272,
1369,
26,
272,
446,
2812,
402,
314,
2435,
2933,
14,
272,
1415,
26,
2549,
272,
849,
26,
488,
272,
5481,
26,
942,
523,
3231,
26,
272,
1369,
26,
272,
446,
19317,
402,
314,
2435,
2933,
436,
7565,
14,
272,
1415,
26,
2549,
272,
849,
26,
488,
272,
5481,
26,
942,
523,
7565,
26,
272,
1369,
26,
272,
446,
710,
7565,
626,
1077,
506,
10632,
370,
314,
2435,
2933,
14,
272,
1415,
26,
3055,
272,
849,
26,
488,
272,
5481,
26,
942,
199,
2502,
26,
199,
13,
298,
43,
287,
9745,
644,
23521,
834,
665,
829,
23521,
834,
32,
17164,
14,
957,
4335,
199,
11036,
63,
9970,
63,
7677,
26,
942,
199,
2344,
199,
199,
8918,
275,
1449,
523,
446,
536,
26,
664,
25563,
402,
282,
2435,
2933,
272,
4244,
63,
1364,
2048,
63,
4731,
26,
489,
1174,
26,
769,
489,
2435,
63,
2048,
26,
6545,
489,
3231,
26,
849,
272,
2274,
26,
308,
482,
1353,
475,
337,
8330,
446,
536,
26,
10967,
282,
2435,
2933,
370,
282,
2488,
7565,
272,
4244,
63,
1364,
2048,
63,
4731,
26,
489,
2435,
63,
2048,
26,
6545,
489,
7565,
26,
3002,
1222,
4731,
489,
3231,
26,
849,
272,
2274,
26,
308,
482,
1353,
475,
337,
199,
2344,
199,
199,
3,
1882,
1882,
1882,
9599,
5120,
7956,
26,
1382,
15,
1364,
2048,
63,
4731,
1882,
1882,
1882,
199,
199,
3,
1882,
1882,
1882,
25754,
5120,
7956,
26,
24272,
5093,
773,
63,
1208,
15,
2164,
15,
533,
15,
89,
3773,
14,
647,
1882,
1882,
1882,
421,
199,
533,
28774,
1726,
8,
1726,
304,
221,
327,
11942,
26,
949,
8486,
272,
1449,
2186,
1021,
367,
28774,
1449,
272,
986,
421,
199,
3
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
4287,
26,
3507,
29,
4752,
13,
12485,
199,
3,
27510,
24,
26,
8151,
26,
377,
4587,
199,
3,
258,
31111,
31111,
485,
221,
485,
31111,
31111,
259,
485,
636,
8989,
31111,
31111,
199,
3,
259,
1182,
636,
92,
636,
92,
971,
92,
1204,
636,
92,
485,
971,
221,
1182,
18005,
63,
257,
485,
92,
636,
92,
257,
971,
199,
3,
257,
1204,
6110,
1204,
485,
10644,
1275,
64,
1204,
485,
10644,
257,
1182,
1182,
485,
971,
92,
1204,
1204,
485,
10644,
1204,
9,
1204,
199,
3,
259,
971,
8989,
92,
8989,
30007,
6113,
63,
92,
8989,
30007,
92,
18005,
15607,
15607,
60,
18005,
63,
30007,
92,
8989,
92,
8989,
15607,
636,
8989,
199,
3,
257,
1204,
257,
971,
1182,
485,
971,
221,
1204,
971,
92,
1204,
15,
485,
971,
63,
257,
485,
92,
1204,
636,
92,
257,
971,
63,
485,
30007,
257,
485,
92,
199,
3,
257,
1204,
1204,
9,
1204,
334,
4602,
1204,
1204,
1275,
64,
1204,
334,
4602,
12208,
1204,
257,
1204,
485,
10644,
1204,
9,
1204,
1204,
221,
1204,
1204,
199,
3,
257,
1204,
8989,
15,
971,
8989,
15,
221,
1204,
63,
6113,
63,
6113,
8989,
15,
1204,
63,
92,
257,
1204,
8989,
92,
8989,
15,
8989,
92,
1204,
63,
92,
199,
3,
199,
3,
1898,
7800,
9572,
13002,
12,
3277,
14,
436,
15,
269,
2399,
29172,
2335,
199,
3,
436,
1163,
8417,
465,
22141,
701,
314,
768,
2502,
3762,
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,
3,
199,
199,
3,
1882,
1882,
1882,
25754,
5120,
7956,
26,
1973,
15,
646,
14,
647,
1882,
1882,
1882,
199,
2344,
2043,
3232,
14379,
7802,
1021,
626,
14018,
314,
4244,
3718,
315,
282,
3873,
199,
2344,
199,
3,
4287,
26,
3507,
29,
7354,
13,
3479,
13,
1278,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
646,
19840,
199,
646,
1331,
199,
646,
12871,
199,
646,
2022,
199,
646,
900,
199,
646,
747,
199,
646,
295,
199,
646,
5145,
199,
646,
3873,
199,
646,
5549,
199,
3,
4287,
26,
3507,
29,
646,
13,
705,
199,
893,
26,
272,
492,
519,
85,
14868,
14,
5963,
465,
8864,
199,
2590,
3545,
26,
272,
492,
8864,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
199,
199,
3,
1882,
1882,
1882,
9599,
5120,
7956,
26,
1973,
15,
646,
14,
647,
1882,
1882,
1882,
199,
199,
3,
1882,
1882,
1882,
25754,
5120,
7956,
26,
1382,
15,
1364,
2048,
63,
4731,
1882,
1882,
1882,
199,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
4244,
63,
1364,
2048,
63,
4731,
199,
3612,
63,
1802,
26,
5673,
370,
9635,
1551,
4723,
2435,
2933,
25563,
199,
1802,
26,
523,
446,
14944,
1551,
4723,
2435,
2933,
25563,
2240,
17174,
14,
199,
1419,
26,
523,
1174,
26,
272,
1369,
26,
272,
446,
982,
3451,
12,
314,
2435,
2933,
911,
506,
10632,
543,
314,
7565,
340,
652,
365,
440,
2575,
14,
982,
9552,
12,
314,
2435,
2933,
911,
506,
625,
12751,
687,
314,
7565,
340,
652,
365,
2575,
10632,
14,
982,
769,
12,
2556,
3595,
314,
2435,
2933,
25563,
911,
506,
16072,
31051,
436,
2138,
465,
1777,
402,
314,
2622,
1240,
2058,
14,
272,
1415,
26,
3055,
272,
849,
26,
3451,
272,
3415,
26,
2097,
1881,
401,
298,
5575,
401,
298,
513,
937,
272,
5481,
26,
942,
523,
23091,
888,
26,
272,
1369,
26,
272,
446,
710,
931,
367,
314,
23091,
888,
570,
370,
675,
367,
6299,
272,
1415,
26,
3055,
272,
849,
26,
1182,
6839,
15,
6493,
15,
4133,
15,
2113,
14,
29192,
272,
5481,
26,
942,
523,
3105,
26,
272,
1369,
26,
272,
446,
16147,
641,
3105,
1072,
14,
272,
1415,
26,
3055,
272,
849,
26,
3055,
272,
5481,
26,
942,
523,
2435,
63,
2048,
26,
272,
1369,
26,
272,
446,
2812,
402,
314,
2435,
2933,
14,
272,
1415,
26,
2549,
272,
849,
26,
488,
272,
5481,
26,
942,
523,
3231,
26,
272,
1369,
26,
272,
446,
19317,
402,
314,
2435,
2933,
436,
7565,
14,
272,
1415,
26,
2549,
272,
849,
26,
488,
272,
5481,
26,
942,
523,
7565,
26,
272,
1369,
26,
272,
446,
710,
7565,
626,
1077,
506,
10632,
370,
314,
2435,
2933,
14,
272,
1415,
26,
3055,
272,
849,
26,
488,
272,
5481,
26,
942,
199,
2502,
26,
199,
13,
298,
43,
287,
9745,
644,
23521,
834,
665,
829,
23521,
834,
32,
17164,
14,
957,
4335,
199,
11036,
63,
9970,
63,
7677,
26,
942,
199,
2344,
199,
199,
8918,
275,
1449,
523,
446,
536,
26,
664,
25563,
402,
282,
2435,
2933,
272,
4244,
63,
1364,
2048,
63,
4731,
26,
489,
1174,
26,
769,
489,
2435,
63,
2048,
26,
6545,
489,
3231,
26,
849,
272,
2274,
26,
308,
482,
1353,
475,
337,
8330,
446,
536,
26,
10967,
282,
2435,
2933,
370,
282,
2488,
7565,
272,
4244,
63,
1364,
2048,
63,
4731,
26,
489,
2435,
63,
2048,
26,
6545,
489,
7565,
26,
3002,
1222,
4731,
489,
3231,
26,
849,
272,
2274,
26,
308,
482,
1353,
475,
337,
199,
2344,
199,
199,
3,
1882,
1882,
1882,
9599,
5120,
7956,
26,
1382,
15,
1364,
2048,
63,
4731,
1882,
1882,
1882,
199,
199,
3,
1882,
1882,
1882,
25754,
5120,
7956,
26,
24272,
5093,
773,
63,
1208,
15,
2164,
15,
533,
15,
89,
3773,
14,
647,
1882,
1882,
1882,
421,
199,
533,
28774,
1726,
8,
1726,
304,
221,
327,
11942,
26,
949,
8486,
272,
1449,
2186,
1021,
367,
28774,
1449,
272,
986,
421,
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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
zerobatu/edx-platform
|
common/lib/xmodule/xmodule/modulestore/tests/factories.py
|
34
|
21631
|
"""
Factories for use in tests of XBlocks.
"""
import functools
import pymongo.message
import threading
import traceback
from collections import defaultdict
from decorator import contextmanager
from uuid import uuid4
from factory import Factory, Sequence, lazy_attribute_sequence, lazy_attribute
from factory.containers import CyclicDefinitionError
from mock import patch
from nose.tools import assert_less_equal, assert_greater_equal
import dogstats_wrapper as dog_stats_api
from opaque_keys.edx.locations import Location
from opaque_keys.edx.keys import UsageKey
from xblock.core import XBlock
from xmodule.modulestore import prefer_xmodules, ModuleStoreEnum
from xmodule.tabs import CourseTab
from xmodule.x_module import DEPRECATION_VSCOMPAT_EVENT
class Dummy(object):
pass
class XModuleFactoryLock(threading.local):
"""
This class exists to store whether XModuleFactory can be accessed in a safe
way (meaning, in a context where the data it creates will be cleaned up).
Users of XModuleFactory (or its subclasses) should only call XModuleFactoryLock.enable
after ensuring that a) the modulestore will be cleaned up, and b) that XModuleFactoryLock.disable
will be called.
"""
def __init__(self):
super(XModuleFactoryLock, self).__init__()
self._enabled = False
def enable(self):
"""
Enable XModuleFactories. This should only be turned in a context
where the modulestore will be reset at the end of the test (such
as inside ModuleStoreTestCase).
"""
self._enabled = True
def disable(self):
"""
Disable XModuleFactories. This should be called once the data
from the factory has been cleaned up.
"""
self._enabled = False
def is_enabled(self):
"""
Return whether XModuleFactories are enabled.
"""
return self._enabled
XMODULE_FACTORY_LOCK = XModuleFactoryLock()
class XModuleFactory(Factory):
"""
Factory for XModules
"""
# We have to give a Factory a FACTORY_FOR.
# However, the class that we create is actually determined by the category
# specified in the factory
FACTORY_FOR = Dummy
@lazy_attribute
def modulestore(self):
msg = "XMODULE_FACTORY_LOCK not enabled. Please use ModuleStoreTestCase as your test baseclass."
assert XMODULE_FACTORY_LOCK.is_enabled(), msg
from xmodule.modulestore.django import modulestore
return modulestore()
last_course = threading.local()
class CourseFactory(XModuleFactory):
"""
Factory for XModule courses.
"""
org = Sequence('org.{}'.format)
number = Sequence('course_{}'.format)
display_name = Sequence('Run {}'.format)
# pylint: disable=unused-argument
@classmethod
def _create(cls, target_class, **kwargs):
"""
Create and return a new course. For performance reasons, we do not emit
signals during this process, but if you need signals to run, you can
pass `emit_signals=True` to this method.
"""
# All class attributes (from this class and base classes) are
# passed in via **kwargs. However, some of those aren't actual field values,
# so pop those off for use separately
org = kwargs.pop('org', None)
# because the factory provides a default 'number' arg, prefer the non-defaulted 'course' arg if any
number = kwargs.pop('course', kwargs.pop('number', None))
store = kwargs.pop('modulestore')
name = kwargs.get('name', kwargs.get('run', Location.clean(kwargs.get('display_name'))))
run = kwargs.pop('run', name)
user_id = kwargs.pop('user_id', ModuleStoreEnum.UserID.test)
emit_signals = kwargs.get('emit_signals', False)
# Pass the metadata just as field=value pairs
kwargs.update(kwargs.pop('metadata', {}))
default_store_override = kwargs.pop('default_store', None)
with store.branch_setting(ModuleStoreEnum.Branch.draft_preferred):
course_key = store.make_course_key(org, number, run)
with store.bulk_operations(course_key, emit_signals=emit_signals):
if default_store_override is not None:
with store.default_store(default_store_override):
new_course = store.create_course(org, number, run, user_id, fields=kwargs)
else:
new_course = store.create_course(org, number, run, user_id, fields=kwargs)
last_course.loc = new_course.location
return new_course
class LibraryFactory(XModuleFactory):
"""
Factory for creating a content library
"""
org = Sequence('org{}'.format)
library = Sequence('lib{}'.format)
display_name = Sequence('Test Library {}'.format)
# pylint: disable=unused-argument
@classmethod
def _create(cls, target_class, **kwargs):
"""
Create a library with a unique name and key.
All class attributes (from this class and base classes) are automagically
passed in via **kwargs.
"""
# some of the kwargst actual field values, so pop those off for use separately:
org = kwargs.pop('org')
library = kwargs.pop('library')
store = kwargs.pop('modulestore')
user_id = kwargs.pop('user_id', ModuleStoreEnum.UserID.test)
# Pass the metadata just as field=value pairs
kwargs.update(kwargs.pop('metadata', {}))
default_store_override = kwargs.pop('default_store', ModuleStoreEnum.Type.split)
with store.default_store(default_store_override):
new_library = store.create_library(org, library, user_id, fields=kwargs)
return new_library
class ItemFactory(XModuleFactory):
"""
Factory for XModule items.
"""
category = 'chapter'
parent = None
@lazy_attribute_sequence
def display_name(self, n):
return "{} {}".format(self.category, n)
@lazy_attribute
def location(self):
if self.display_name is None:
dest_name = uuid4().hex
else:
dest_name = self.display_name.replace(" ", "_")
new_location = self.parent_location.course_key.make_usage_key(
self.category,
dest_name
)
return new_location
@lazy_attribute
def parent_location(self):
default_location = getattr(last_course, 'loc', None)
try:
parent = self.parent
# This error is raised if the caller hasn't provided either parent or parent_location
# In this case, we'll just return the default parent_location
except CyclicDefinitionError:
return default_location
if parent is None:
return default_location
return parent.location
@classmethod
def _create(cls, target_class, **kwargs):
"""
Uses ``**kwargs``:
:parent_location: (required): the location of the parent module
(e.g. the parent course or section)
:category: the category of the resulting item.
:data: (optional): the data for the item
(e.g. XML problem definition for a problem item)
:display_name: (optional): the display name of the item
:metadata: (optional): dictionary of metadata attributes
:boilerplate: (optional) the boilerplate for overriding field values
:publish_item: (optional) whether or not to publish the item (default is True)
:target_class: is ignored
"""
# All class attributes (from this class and base classes) are
# passed in via **kwargs. However, some of those aren't actual field values,
# so pop those off for use separately
# catch any old style users before they get into trouble
assert 'template' not in kwargs
parent_location = kwargs.pop('parent_location', None)
data = kwargs.pop('data', None)
category = kwargs.pop('category', None)
display_name = kwargs.pop('display_name', None)
metadata = kwargs.pop('metadata', {})
location = kwargs.pop('location')
user_id = kwargs.pop('user_id', ModuleStoreEnum.UserID.test)
publish_item = kwargs.pop('publish_item', True)
assert isinstance(location, UsageKey)
assert location != parent_location
store = kwargs.pop('modulestore')
# This code was based off that in cms/djangoapps/contentstore/views.py
parent = kwargs.pop('parent', None) or store.get_item(parent_location)
with store.branch_setting(ModuleStoreEnum.Branch.draft_preferred):
if 'boilerplate' in kwargs:
template_id = kwargs.pop('boilerplate')
clz = XBlock.load_class(category, select=prefer_xmodules)
template = clz.get_template(template_id)
assert template is not None
metadata.update(template.get('metadata', {}))
if not isinstance(data, basestring):
data.update(template.get('data'))
# replace the display name with an optional parameter passed in from the caller
if display_name is not None:
metadata['display_name'] = display_name
module = store.create_child(
user_id,
parent.location,
location.block_type,
block_id=location.block_id,
metadata=metadata,
definition_data=data,
runtime=parent.runtime,
fields=kwargs,
)
# VS[compat] cdodge: This is a hack because static_tabs also have references from the course module, so
# if we add one then we need to also add it to the policy information (i.e. metadata)
# we should remove this once we can break this reference from the course to static tabs
if category == 'static_tab':
dog_stats_api.increment(
DEPRECATION_VSCOMPAT_EVENT,
tags=(
"location:itemfactory_create_static_tab",
u"block:{}".format(location.block_type),
)
)
course = store.get_course(location.course_key)
course.tabs.append(
CourseTab.load('static_tab', name='Static Tab', url_slug=location.name)
)
store.update_item(course, user_id)
# parent and publish the item, so it can be accessed
if 'detached' not in module._class_tags:
parent.children.append(location)
store.update_item(parent, user_id)
if publish_item:
published_parent = store.publish(parent.location, user_id)
# module is last child of parent
return published_parent.get_children()[-1]
else:
return store.get_item(location)
elif publish_item:
return store.publish(location, user_id)
else:
return module
@contextmanager
def check_exact_number_of_calls(object_with_method, method_name, num_calls):
"""
Instruments the given method on the given object to verify the number of calls to the
method is exactly equal to 'num_calls'.
"""
with check_number_of_calls(object_with_method, method_name, num_calls, num_calls):
yield
def check_number_of_calls(object_with_method, method_name, maximum_calls, minimum_calls=1):
"""
Instruments the given method on the given object to verify the number of calls to the method is
less than or equal to the expected maximum_calls and greater than or equal to the expected minimum_calls.
"""
return check_sum_of_calls(object_with_method, [method_name], maximum_calls, minimum_calls)
class StackTraceCounter(object):
"""
A class that counts unique stack traces underneath a particular stack frame.
"""
def __init__(self, stack_depth, include_arguments=True):
"""
Arguments:
stack_depth (int): The number of stack frames above this constructor to capture.
include_arguments (bool): Whether to store the arguments that are passed
when capturing a stack trace.
"""
self.include_arguments = include_arguments
self._top_of_stack = traceback.extract_stack(limit=stack_depth)[0]
if self.include_arguments:
self._stacks = defaultdict(lambda: defaultdict(int))
else:
self._stacks = defaultdict(int)
def capture_stack(self, args, kwargs):
"""
Record the stack frames starting at the caller of this method, and
ending at the top of the stack as defined by the ``stack_depth``.
Arguments:
args: The positional arguments to capture at this stack frame
kwargs: The keyword arguments to capture at this stack frame
"""
# pylint: disable=broad-except
stack = traceback.extract_stack()[:-2]
if self._top_of_stack in stack:
stack = stack[stack.index(self._top_of_stack):]
if self.include_arguments:
safe_args = []
for arg in args:
try:
safe_args.append(repr(arg))
except Exception as exc:
safe_args.append('<un-repr-able value: {}'.format(exc))
safe_kwargs = {}
for key, kwarg in kwargs.items():
try:
safe_kwargs[key] = repr(kwarg)
except Exception as exc:
safe_kwargs[key] = '<un-repr-able value: {}'.format(exc)
self._stacks[tuple(stack)][tuple(safe_args), tuple(safe_kwargs.items())] += 1
else:
self._stacks[tuple(stack)] += 1
@property
def total_calls(self):
"""
Return the total number of stacks recorded.
"""
return sum(self.stack_calls(stack) for stack in self._stacks)
def stack_calls(self, stack):
"""
Return the number of calls to the supplied ``stack``.
"""
if self.include_arguments:
return sum(self._stacks[stack].values())
else:
return self._stacks[stack]
def __iter__(self):
"""
Iterate over all unique captured stacks.
"""
return iter(sorted(self._stacks.keys(), key=lambda stack: (self.stack_calls(stack), stack), reverse=True))
def __getitem__(self, stack):
"""
Return the set of captured calls with the supplied stack.
"""
return self._stacks[stack]
@classmethod
def capture_call(cls, func, stack_depth, include_arguments=True):
"""
A decorator that wraps ``func``, and captures each call to ``func``,
recording the stack trace, and optionally the arguments that the function
is called with.
Arguments:
func: the function to wrap
stack_depth: how far up the stack to truncate the stored stack traces (
this is counted from the call to ``capture_call``, rather than calls
to the captured function).
"""
stacks = StackTraceCounter(stack_depth, include_arguments)
# pylint: disable=missing-docstring
@functools.wraps(func)
def capture(*args, **kwargs):
stacks.capture_stack(args, kwargs)
return func(*args, **kwargs)
capture.stack_counter = stacks
return capture
@contextmanager
def check_sum_of_calls(object_, methods, maximum_calls, minimum_calls=1, include_arguments=True):
"""
Instruments the given methods on the given object to verify that the total sum of calls made to the
methods falls between minumum_calls and maximum_calls.
"""
mocks = {
method: StackTraceCounter.capture_call(
getattr(object_, method),
stack_depth=7,
include_arguments=include_arguments
)
for method in methods
}
with patch.multiple(object_, **mocks):
yield
call_count = sum(capture_fn.stack_counter.total_calls for capture_fn in mocks.values())
# Assertion errors don't handle multi-line values, so pretty-print to std-out instead
if not minimum_calls <= call_count <= maximum_calls:
messages = ["Expected between {} and {} calls, {} were made.\n\n".format(
minimum_calls,
maximum_calls,
call_count,
)]
for method_name, capture_fn in mocks.items():
stack_counter = capture_fn.stack_counter
messages.append("{!r} was called {} times:\n".format(
method_name,
stack_counter.total_calls
))
for stack in stack_counter:
messages.append(" called {} times:\n\n".format(stack_counter.stack_calls(stack)))
messages.append(" " + " ".join(traceback.format_list(stack)))
messages.append("\n\n")
if include_arguments:
for (args, kwargs), count in stack_counter[stack].items():
messages.append(" called {} times with:\n".format(count))
messages.append(" args: {}\n".format(args))
messages.append(" kwargs: {}\n\n".format(dict(kwargs)))
print "".join(messages)
# verify the counter actually worked by ensuring we have counted greater than (or equal to) the minimum calls
assert_greater_equal(call_count, minimum_calls)
# now verify the number of actual calls is less than (or equal to) the expected maximum
assert_less_equal(call_count, maximum_calls)
def mongo_uses_error_check(store):
"""
Does mongo use the error check as a separate message?
"""
if hasattr(store, 'mongo_wire_version'):
return store.mongo_wire_version() <= 1
if hasattr(store, 'modulestores'):
return any([mongo_uses_error_check(substore) for substore in store.modulestores])
return False
@contextmanager
def check_mongo_calls_range(max_finds=float("inf"), min_finds=0, max_sends=None, min_sends=None):
"""
Instruments the given store to count the number of calls to find (incl find_one) and the number
of calls to send_message which is for insert, update, and remove (if you provide num_sends). At the
end of the with statement, it compares the counts to the bounds provided in the arguments.
:param max_finds: the maximum number of find calls expected
:param min_finds: the minimum number of find calls expected
:param max_sends: If non-none, make sure number of send calls are <=max_sends
:param min_sends: If non-none, make sure number of send calls are >=min_sends
"""
with check_sum_of_calls(
pymongo.message,
['query', 'get_more'],
max_finds,
min_finds,
):
if max_sends is not None or min_sends is not None:
with check_sum_of_calls(
pymongo.message,
# mongo < 2.6 uses insert, update, delete and _do_batched_insert. >= 2.6 _do_batched_write
['insert', 'update', 'delete', '_do_batched_write_command', '_do_batched_insert', ],
max_sends if max_sends is not None else float("inf"),
min_sends if min_sends is not None else 0,
):
yield
else:
yield
@contextmanager
def check_mongo_calls(num_finds=0, num_sends=None):
"""
Instruments the given store to count the number of calls to find (incl find_one) and the number
of calls to send_message which is for insert, update, and remove (if you provide num_sends). At the
end of the with statement, it compares the counts to the num_finds and num_sends.
:param num_finds: the exact number of find calls expected
:param num_sends: If none, don't instrument the send calls. If non-none, count and compare to
the given int value.
"""
with check_mongo_calls_range(num_finds, num_finds, num_sends, num_sends):
yield
# This dict represents the attribute keys for a course's 'about' info.
# Note: The 'video' attribute is intentionally excluded as it must be
# handled separately; its value maps to an alternate key name.
# Reference : cms/djangoapps/models/settings/course_details.py
ABOUT_ATTRIBUTES = {
'effort': "Testing effort",
}
class CourseAboutFactory(XModuleFactory):
"""
Factory for XModule course about.
"""
@classmethod
def _create(cls, target_class, **kwargs): # pylint: disable=unused-argument
"""
Uses **kwargs:
effort: effor information
video : video link
"""
user_id = kwargs.pop('user_id', None)
course_id, course_runtime = kwargs.pop("course_id"), kwargs.pop("course_runtime")
store = kwargs.pop('modulestore')
for about_key in ABOUT_ATTRIBUTES:
about_item = store.create_xblock(course_runtime, course_id, 'about', about_key)
about_item.data = ABOUT_ATTRIBUTES[about_key]
store.update_item(about_item, user_id, allow_not_found=True)
about_item = store.create_xblock(course_runtime, course_id, 'about', 'video')
about_item.data = "www.youtube.com/embed/testing-video-link"
store.update_item(about_item, user_id, allow_not_found=True)
|
agpl-3.0
|
[
624,
199,
1906,
4253,
367,
675,
315,
2295,
402,
15398,
83,
14,
199,
624,
199,
199,
646,
9143,
199,
646,
21878,
14,
1188,
199,
646,
5796,
199,
646,
5190,
199,
504,
5055,
492,
10018,
199,
504,
7531,
492,
27608,
199,
504,
5377,
492,
5377,
20,
199,
199,
504,
6434,
492,
23616,
12,
10975,
12,
9617,
63,
3215,
63,
4041,
12,
9617,
63,
3215,
199,
504,
6434,
14,
13577,
492,
18461,
17542,
10701,
547,
199,
504,
1683,
492,
3371,
199,
504,
11354,
14,
2537,
492,
702,
63,
2003,
63,
1452,
12,
702,
63,
13154,
63,
1452,
199,
646,
23454,
3200,
63,
5029,
465,
23454,
63,
3200,
63,
1246,
199,
199,
504,
15058,
63,
1612,
14,
8268,
14,
8022,
492,
12625,
199,
504,
15058,
63,
1612,
14,
8268,
14,
1612,
492,
11028,
1197,
199,
504,
12971,
14,
1018,
492,
15398,
199,
504,
9872,
14,
10012,
492,
16602,
63,
88,
3112,
12,
23431,
199,
504,
9872,
14,
8741,
492,
5531,
7690,
199,
504,
9872,
14,
88,
63,
578,
492,
3265,
14246,
2594,
63,
7428,
29720,
63,
8193,
421,
199,
533,
9762,
8,
785,
304,
272,
986,
421,
199,
533,
25656,
2927,
6432,
8,
12562,
14,
1832,
304,
272,
408,
272,
961,
1021,
3495,
370,
3877,
3775,
25656,
2927,
883,
506,
13810,
315,
282,
5048,
272,
4340,
334,
3670,
316,
12,
315,
282,
1067,
2382,
314,
666,
652,
8491,
911,
506,
12364,
1536,
680,
339,
20123,
402,
25656,
2927,
334,
269,
2399,
9180,
9,
1077,
1454,
1240,
25656,
2927,
6432,
14,
4296,
272,
2410,
12889,
4039,
626,
282,
9,
314,
10996,
911,
506,
12364,
1536,
12,
436,
330,
9,
626,
25656,
2927,
6432,
14,
5993,
272,
911,
506,
2797,
14,
272,
408,
272,
347,
636,
826,
721,
277,
304,
267,
1613,
8,
56,
2377,
2927,
6432,
12,
291,
2843,
826,
4533,
267,
291,
423,
3827,
275,
756,
339,
347,
4756,
8,
277,
304,
267,
408,
267,
12030,
25656,
1906,
4253,
14,
961,
1077,
1454,
506,
19136,
315,
282,
1067,
267,
2382,
314,
10996,
911,
506,
5305,
737,
314,
1284,
402,
314,
511,
334,
10180,
267,
465,
6272,
17996,
1746,
680,
267,
408,
267,
291,
423,
3827,
275,
715,
339,
347,
3507,
8,
277,
304,
267,
408,
267,
17534,
25656,
1906,
4253,
14,
961,
1077,
506,
2797,
5403,
314,
666,
267,
687,
314,
6434,
965,
2757,
12364,
1536,
14,
267,
408,
267,
291,
423,
3827,
275,
756,
339,
347,
365,
63,
3827,
8,
277,
304,
267,
408,
267,
1432,
3775,
25656,
1906,
4253,
787,
5223,
14,
267,
408,
267,
372,
291,
423,
3827,
421,
199,
56,
10001,
63,
18164,
5347,
63,
4406,
275,
25656,
2927,
6432,
342,
421,
199,
533,
25656,
2927,
8,
2927,
304,
272,
408,
272,
23616,
367,
1323,
17981,
272,
408,
339,
327,
2136,
1172,
370,
8120,
282,
23616,
282,
481,
3036,
5347,
63,
2707,
14,
272,
327,
9738,
12,
314,
1021,
626,
781,
1218,
365,
5965,
12037,
701,
314,
4637,
272,
327,
2013,
315,
314,
6434,
272,
481,
3036,
5347,
63,
2707,
275,
9762,
339,
768,
6395,
63,
3215,
272,
347,
10996,
8,
277,
304,
267,
1499,
275,
298,
56,
10001,
63,
18164,
5347,
63,
4406,
440,
5223,
14,
7754,
675,
17996,
1746,
465,
2195,
511,
1300,
533,
2122,
267,
702,
1323,
10001,
63,
18164,
5347,
63,
4406,
14,
374,
63,
3827,
1062,
1499,
398,
687,
9872,
14,
10012,
14,
1176,
492,
10996,
267,
372,
10996,
342,
421,
199,
2019,
63,
1972,
275,
5796,
14,
1832,
342,
421,
199,
533,
17862,
8,
56,
2377,
2927,
304,
272,
408,
272,
23616,
367,
25656,
13588,
14,
272,
408,
272,
5981,
275,
10975,
360,
1308,
14,
11123,
908,
9,
272,
1329,
275,
10975,
360,
1972,
63,
11123,
908,
9,
272,
2929,
63,
354,
275,
10975,
360,
2540,
9499,
908,
9,
339,
327,
4287,
26,
3507,
29,
8618,
13,
2094,
272,
768,
3744,
272,
347,
485,
981,
8,
1886,
12,
1347,
63,
533,
12,
1011,
958,
304,
267,
408,
267,
2790,
436,
372,
282,
892,
2518,
14,
2104,
10238,
14872,
12,
781,
886,
440,
8689,
267,
10166,
5309,
642,
2112,
12,
1325,
340,
1265,
1929,
10166,
370,
1255,
12,
1265,
883,
267,
986,
658,
8159,
63,
10458,
29,
549,
64,
370,
642,
1083,
14,
267,
408,
267,
327,
2900,
1021,
3004,
334,
504,
642,
1021,
436,
1300,
3992,
9,
787,
267,
327,
3032,
315,
4799,
1011,
958,
14,
9738,
12,
2005,
402,
5204,
10621,
1133,
3503,
901,
1338,
12,
267,
327,
880,
4560,
5204,
2331,
367,
675,
18159,
267,
5981,
275,
2074,
14,
1935,
360,
1308,
297,
488,
9,
267,
327,
2952,
314,
6434,
6571,
282,
849,
283,
1955,
7,
1680,
12,
16602,
314,
2222,
13,
27205,
471,
283,
1972,
7,
1680,
340,
1263,
267,
1329,
275,
2074,
14,
1935,
360,
1972,
297,
2074,
14,
1935,
360,
1955,
297,
488,
430,
267,
3877,
275,
2074,
14,
1935,
360,
10012,
358,
267,
536,
275,
2074,
14,
362,
360,
354,
297,
2074,
14,
362,
360,
1065,
297,
12625,
14,
3118,
8,
958,
14,
362,
360,
2918,
63,
354,
31789,
267,
1255,
275,
2074,
14,
1935,
360,
1065,
297,
536,
9,
267,
922,
63,
344,
275,
2074,
14,
1935,
360,
751,
63,
344,
297,
23431,
14,
28659,
14,
396,
9,
267,
8689,
63,
10458,
275,
2074,
14,
362,
360,
8159,
63,
10458,
297,
756,
9,
398,
327,
8325,
314,
3341,
2951,
465,
901,
29,
585,
6342,
267,
2074,
14,
873,
8,
958,
14,
1935,
360,
2343,
297,
17003,
267,
849,
63,
1617,
63,
4415,
275,
2074,
14,
1935,
360,
885,
63,
1617,
297,
488,
9,
398,
543,
3877,
14,
4694,
63,
6031,
8,
25142,
14,
12526,
14,
7185,
63,
17477,
304,
288,
2518,
63,
498,
275,
3877,
14,
1875,
63,
1972,
63,
498,
8,
1308,
12,
1329,
12,
1255,
9,
288,
543,
3877,
14,
9377,
63,
8170,
8,
1972,
63,
498,
12,
8689,
63,
10458,
29,
8159,
63,
10458,
304,
355,
340,
849,
63,
1617,
63,
4415,
365,
440,
488,
26,
490,
543,
3877,
14,
885,
63,
1617,
8,
885,
63,
1617,
63,
4415,
304,
717,
892,
63,
1972,
275,
3877,
14,
981,
63,
1972,
8,
1308,
12,
1329,
12,
1255,
12,
922,
63,
344,
12,
1504,
29,
958,
9,
355,
587,
26,
490,
892,
63,
1972,
275,
3877,
14,
981,
63
] |
[
199,
1906,
4253,
367,
675,
315,
2295,
402,
15398,
83,
14,
199,
624,
199,
199,
646,
9143,
199,
646,
21878,
14,
1188,
199,
646,
5796,
199,
646,
5190,
199,
504,
5055,
492,
10018,
199,
504,
7531,
492,
27608,
199,
504,
5377,
492,
5377,
20,
199,
199,
504,
6434,
492,
23616,
12,
10975,
12,
9617,
63,
3215,
63,
4041,
12,
9617,
63,
3215,
199,
504,
6434,
14,
13577,
492,
18461,
17542,
10701,
547,
199,
504,
1683,
492,
3371,
199,
504,
11354,
14,
2537,
492,
702,
63,
2003,
63,
1452,
12,
702,
63,
13154,
63,
1452,
199,
646,
23454,
3200,
63,
5029,
465,
23454,
63,
3200,
63,
1246,
199,
199,
504,
15058,
63,
1612,
14,
8268,
14,
8022,
492,
12625,
199,
504,
15058,
63,
1612,
14,
8268,
14,
1612,
492,
11028,
1197,
199,
504,
12971,
14,
1018,
492,
15398,
199,
504,
9872,
14,
10012,
492,
16602,
63,
88,
3112,
12,
23431,
199,
504,
9872,
14,
8741,
492,
5531,
7690,
199,
504,
9872,
14,
88,
63,
578,
492,
3265,
14246,
2594,
63,
7428,
29720,
63,
8193,
421,
199,
533,
9762,
8,
785,
304,
272,
986,
421,
199,
533,
25656,
2927,
6432,
8,
12562,
14,
1832,
304,
272,
408,
272,
961,
1021,
3495,
370,
3877,
3775,
25656,
2927,
883,
506,
13810,
315,
282,
5048,
272,
4340,
334,
3670,
316,
12,
315,
282,
1067,
2382,
314,
666,
652,
8491,
911,
506,
12364,
1536,
680,
339,
20123,
402,
25656,
2927,
334,
269,
2399,
9180,
9,
1077,
1454,
1240,
25656,
2927,
6432,
14,
4296,
272,
2410,
12889,
4039,
626,
282,
9,
314,
10996,
911,
506,
12364,
1536,
12,
436,
330,
9,
626,
25656,
2927,
6432,
14,
5993,
272,
911,
506,
2797,
14,
272,
408,
272,
347,
636,
826,
721,
277,
304,
267,
1613,
8,
56,
2377,
2927,
6432,
12,
291,
2843,
826,
4533,
267,
291,
423,
3827,
275,
756,
339,
347,
4756,
8,
277,
304,
267,
408,
267,
12030,
25656,
1906,
4253,
14,
961,
1077,
1454,
506,
19136,
315,
282,
1067,
267,
2382,
314,
10996,
911,
506,
5305,
737,
314,
1284,
402,
314,
511,
334,
10180,
267,
465,
6272,
17996,
1746,
680,
267,
408,
267,
291,
423,
3827,
275,
715,
339,
347,
3507,
8,
277,
304,
267,
408,
267,
17534,
25656,
1906,
4253,
14,
961,
1077,
506,
2797,
5403,
314,
666,
267,
687,
314,
6434,
965,
2757,
12364,
1536,
14,
267,
408,
267,
291,
423,
3827,
275,
756,
339,
347,
365,
63,
3827,
8,
277,
304,
267,
408,
267,
1432,
3775,
25656,
1906,
4253,
787,
5223,
14,
267,
408,
267,
372,
291,
423,
3827,
421,
199,
56,
10001,
63,
18164,
5347,
63,
4406,
275,
25656,
2927,
6432,
342,
421,
199,
533,
25656,
2927,
8,
2927,
304,
272,
408,
272,
23616,
367,
1323,
17981,
272,
408,
339,
327,
2136,
1172,
370,
8120,
282,
23616,
282,
481,
3036,
5347,
63,
2707,
14,
272,
327,
9738,
12,
314,
1021,
626,
781,
1218,
365,
5965,
12037,
701,
314,
4637,
272,
327,
2013,
315,
314,
6434,
272,
481,
3036,
5347,
63,
2707,
275,
9762,
339,
768,
6395,
63,
3215,
272,
347,
10996,
8,
277,
304,
267,
1499,
275,
298,
56,
10001,
63,
18164,
5347,
63,
4406,
440,
5223,
14,
7754,
675,
17996,
1746,
465,
2195,
511,
1300,
533,
2122,
267,
702,
1323,
10001,
63,
18164,
5347,
63,
4406,
14,
374,
63,
3827,
1062,
1499,
398,
687,
9872,
14,
10012,
14,
1176,
492,
10996,
267,
372,
10996,
342,
421,
199,
2019,
63,
1972,
275,
5796,
14,
1832,
342,
421,
199,
533,
17862,
8,
56,
2377,
2927,
304,
272,
408,
272,
23616,
367,
25656,
13588,
14,
272,
408,
272,
5981,
275,
10975,
360,
1308,
14,
11123,
908,
9,
272,
1329,
275,
10975,
360,
1972,
63,
11123,
908,
9,
272,
2929,
63,
354,
275,
10975,
360,
2540,
9499,
908,
9,
339,
327,
4287,
26,
3507,
29,
8618,
13,
2094,
272,
768,
3744,
272,
347,
485,
981,
8,
1886,
12,
1347,
63,
533,
12,
1011,
958,
304,
267,
408,
267,
2790,
436,
372,
282,
892,
2518,
14,
2104,
10238,
14872,
12,
781,
886,
440,
8689,
267,
10166,
5309,
642,
2112,
12,
1325,
340,
1265,
1929,
10166,
370,
1255,
12,
1265,
883,
267,
986,
658,
8159,
63,
10458,
29,
549,
64,
370,
642,
1083,
14,
267,
408,
267,
327,
2900,
1021,
3004,
334,
504,
642,
1021,
436,
1300,
3992,
9,
787,
267,
327,
3032,
315,
4799,
1011,
958,
14,
9738,
12,
2005,
402,
5204,
10621,
1133,
3503,
901,
1338,
12,
267,
327,
880,
4560,
5204,
2331,
367,
675,
18159,
267,
5981,
275,
2074,
14,
1935,
360,
1308,
297,
488,
9,
267,
327,
2952,
314,
6434,
6571,
282,
849,
283,
1955,
7,
1680,
12,
16602,
314,
2222,
13,
27205,
471,
283,
1972,
7,
1680,
340,
1263,
267,
1329,
275,
2074,
14,
1935,
360,
1972,
297,
2074,
14,
1935,
360,
1955,
297,
488,
430,
267,
3877,
275,
2074,
14,
1935,
360,
10012,
358,
267,
536,
275,
2074,
14,
362,
360,
354,
297,
2074,
14,
362,
360,
1065,
297,
12625,
14,
3118,
8,
958,
14,
362,
360,
2918,
63,
354,
31789,
267,
1255,
275,
2074,
14,
1935,
360,
1065,
297,
536,
9,
267,
922,
63,
344,
275,
2074,
14,
1935,
360,
751,
63,
344,
297,
23431,
14,
28659,
14,
396,
9,
267,
8689,
63,
10458,
275,
2074,
14,
362,
360,
8159,
63,
10458,
297,
756,
9,
398,
327,
8325,
314,
3341,
2951,
465,
901,
29,
585,
6342,
267,
2074,
14,
873,
8,
958,
14,
1935,
360,
2343,
297,
17003,
267,
849,
63,
1617,
63,
4415,
275,
2074,
14,
1935,
360,
885,
63,
1617,
297,
488,
9,
398,
543,
3877,
14,
4694,
63,
6031,
8,
25142,
14,
12526,
14,
7185,
63,
17477,
304,
288,
2518,
63,
498,
275,
3877,
14,
1875,
63,
1972,
63,
498,
8,
1308,
12,
1329,
12,
1255,
9,
288,
543,
3877,
14,
9377,
63,
8170,
8,
1972,
63,
498,
12,
8689,
63,
10458,
29,
8159,
63,
10458,
304,
355,
340,
849,
63,
1617,
63,
4415,
365,
440,
488,
26,
490,
543,
3877,
14,
885,
63,
1617,
8,
885,
63,
1617,
63,
4415,
304,
717,
892,
63,
1972,
275,
3877,
14,
981,
63,
1972,
8,
1308,
12,
1329,
12,
1255,
12,
922,
63,
344,
12,
1504,
29,
958,
9,
355,
587,
26,
490,
892,
63,
1972,
275,
3877,
14,
981,
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,
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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
] |
lowtraxx/kernel
|
tools/perf/scripts/python/syscall-counts-by-pid.py
|
11180
|
1927
|
# system call counts, by pid
# (c) 2010, Tom Zanussi <tzanussi@gmail.com>
# Licensed under the terms of the GNU GPL License version 2
#
# Displays system-wide system call totals, broken down by syscall.
# If a [comm] arg is specified, only syscalls called by [comm] are displayed.
import os, sys
sys.path.append(os.environ['PERF_EXEC_PATH'] + \
'/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
from perf_trace_context import *
from Core import *
from Util import syscall_name
usage = "perf script -s syscall-counts-by-pid.py [comm]\n";
for_comm = None
for_pid = None
if len(sys.argv) > 2:
sys.exit(usage)
if len(sys.argv) > 1:
try:
for_pid = int(sys.argv[1])
except:
for_comm = sys.argv[1]
syscalls = autodict()
def trace_begin():
print "Press control+C to stop and show the summary"
def trace_end():
print_syscall_totals()
def raw_syscalls__sys_enter(event_name, context, common_cpu,
common_secs, common_nsecs, common_pid, common_comm,
id, args):
if (for_comm and common_comm != for_comm) or \
(for_pid and common_pid != for_pid ):
return
try:
syscalls[common_comm][common_pid][id] += 1
except TypeError:
syscalls[common_comm][common_pid][id] = 1
def print_syscall_totals():
if for_comm is not None:
print "\nsyscall events for %s:\n\n" % (for_comm),
else:
print "\nsyscall events by comm/pid:\n\n",
print "%-40s %10s\n" % ("comm [pid]/syscalls", "count"),
print "%-40s %10s\n" % ("----------------------------------------", \
"----------"),
comm_keys = syscalls.keys()
for comm in comm_keys:
pid_keys = syscalls[comm].keys()
for pid in pid_keys:
print "\n%s [%d]\n" % (comm, pid),
id_keys = syscalls[comm][pid].keys()
for id, val in sorted(syscalls[comm][pid].iteritems(), \
key = lambda(k, v): (v, k), reverse = True):
print " %-38s %10d\n" % (syscall_name(id), val),
|
gpl-2.0
|
[
3,
2656,
1240,
8242,
12,
701,
4422,
199,
3,
334,
67,
9,
7129,
12,
21644,
29385,
665,
29453,
32,
6799,
14,
957,
30,
199,
3,
3909,
1334,
314,
2895,
402,
314,
1664,
14629,
844,
1015,
499,
199,
3,
199,
3,
28750,
2656,
13,
13062,
2656,
1240,
23576,
12,
10529,
3224,
701,
18901,
14,
199,
3,
982,
282,
359,
1404,
61,
1680,
365,
2013,
12,
1454,
19473,
2797,
701,
359,
1404,
61,
787,
9080,
14,
199,
199,
646,
747,
12,
984,
199,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
2314,
459,
17038,
63,
10276,
63,
3243,
418,
435,
971,
199,
198,
9807,
6429,
15,
1548,
15,
12387,
13,
3921,
13,
9562,
15,
773,
15,
12387,
15,
3921,
358,
199,
199,
504,
8582,
63,
3446,
63,
1100,
492,
627,
199,
504,
11672,
492,
627,
199,
504,
21248,
492,
18901,
63,
354,
199,
199,
3807,
275,
298,
9452,
2884,
446,
83,
18901,
13,
6851,
13,
991,
13,
3150,
14,
647,
359,
1404,
7272,
78,
11436,
199,
199,
509,
63,
1404,
275,
488,
199,
509,
63,
3150,
275,
488,
199,
199,
692,
822,
8,
1274,
14,
3020,
9,
690,
499,
26,
199,
198,
1274,
14,
2224,
8,
3807,
9,
199,
199,
692,
822,
8,
1274,
14,
3020,
9,
690,
413,
26,
199,
198,
893,
26,
507,
198,
509,
63,
3150,
275,
1109,
8,
1274,
14,
3020,
59,
17,
566,
199,
198,
2590,
26,
507,
198,
509,
63,
1404,
275,
984,
14,
3020,
59,
17,
61,
199,
199,
14507,
275,
27477,
342,
199,
199,
318,
3307,
63,
5037,
837,
199,
198,
1361,
298,
14414,
3304,
11,
35,
370,
3631,
436,
2498,
314,
6212,
2,
199,
199,
318,
3307,
63,
500,
837,
199,
198,
1361,
63,
19444,
63,
17552,
342,
199,
199,
318,
3066,
63,
14507,
363,
1274,
63,
4200,
8,
1430,
63,
354,
12,
1067,
12,
2863,
63,
3541,
12,
199,
198,
2330,
63,
4855,
12,
2863,
63,
9618,
12,
2863,
63,
3150,
12,
2863,
63,
1404,
12,
199,
198,
344,
12,
1249,
304,
421,
198,
692,
334,
509,
63,
1404,
436,
2863,
63,
1404,
1137,
367,
63,
1404,
9,
503,
971,
21979,
334,
509,
63,
3150,
221,
436,
2863,
63,
3150,
221,
1137,
367,
63,
3150,
3461,
507,
198,
1107,
199,
198,
893,
26,
507,
198,
14507,
59,
2330,
63,
1404,
1527,
2330,
63,
3150,
1527,
344,
61,
847,
413,
199,
198,
2590,
3146,
26,
507,
198,
14507,
59,
2330,
63,
1404,
1527,
2330,
63,
3150,
1527,
344,
61,
275,
413,
199,
199,
318,
870,
63,
19444,
63,
17552,
837,
272,
340,
367,
63,
1404,
365,
440,
488,
26,
6722,
870,
1867,
26605,
4474,
367,
450,
83,
3427,
78,
60,
78,
2,
450,
334,
509,
63,
1404,
395,
272,
587,
26,
6722,
870,
1867,
26605,
4474,
701,
1923,
15,
3150,
3427,
78,
60,
78,
401,
339,
870,
18301,
2167,
83,
221,
450,
709,
83,
60,
78,
2,
450,
1689,
1404,
359,
3150,
12978,
14507,
401,
298,
835,
1288,
272,
870,
18301,
2167,
83,
221,
450,
709,
83,
60,
78,
2,
450,
1689,
32111,
401,
971,
639,
298,
9460,
1288,
339,
1923,
63,
1612,
275,
19473,
14,
1612,
342,
272,
367,
1923,
315,
1923,
63,
1612,
26,
6722,
4422,
63,
1612,
275,
19473,
59,
1404,
1055,
1612,
342,
6722,
367,
4422,
315,
4422,
63,
1612,
26,
15075,
870,
1867,
78,
5,
83,
8978,
68,
7272,
78,
2,
450,
334,
1404,
12,
4422,
395,
15075,
1305,
63,
1612,
275,
19473,
59,
1404,
1527,
3150,
1055,
1612,
342,
15075,
367,
1305,
12,
1139,
315,
3355,
8,
14507,
59,
1404,
1527,
3150,
1055,
4611,
1062,
971,
1871,
221,
790,
275,
2400,
8,
75,
12,
373,
304,
334,
86,
12,
1022,
395,
221,
3837,
275,
715,
304,
24449,
870,
298,
221,
19752,
1703,
83,
221,
450,
709,
68,
60,
78,
2,
450,
334,
19444,
63,
354,
8,
344,
395,
1139,
395,
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
] |
[
2656,
1240,
8242,
12,
701,
4422,
199,
3,
334,
67,
9,
7129,
12,
21644,
29385,
665,
29453,
32,
6799,
14,
957,
30,
199,
3,
3909,
1334,
314,
2895,
402,
314,
1664,
14629,
844,
1015,
499,
199,
3,
199,
3,
28750,
2656,
13,
13062,
2656,
1240,
23576,
12,
10529,
3224,
701,
18901,
14,
199,
3,
982,
282,
359,
1404,
61,
1680,
365,
2013,
12,
1454,
19473,
2797,
701,
359,
1404,
61,
787,
9080,
14,
199,
199,
646,
747,
12,
984,
199,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
2314,
459,
17038,
63,
10276,
63,
3243,
418,
435,
971,
199,
198,
9807,
6429,
15,
1548,
15,
12387,
13,
3921,
13,
9562,
15,
773,
15,
12387,
15,
3921,
358,
199,
199,
504,
8582,
63,
3446,
63,
1100,
492,
627,
199,
504,
11672,
492,
627,
199,
504,
21248,
492,
18901,
63,
354,
199,
199,
3807,
275,
298,
9452,
2884,
446,
83,
18901,
13,
6851,
13,
991,
13,
3150,
14,
647,
359,
1404,
7272,
78,
11436,
199,
199,
509,
63,
1404,
275,
488,
199,
509,
63,
3150,
275,
488,
199,
199,
692,
822,
8,
1274,
14,
3020,
9,
690,
499,
26,
199,
198,
1274,
14,
2224,
8,
3807,
9,
199,
199,
692,
822,
8,
1274,
14,
3020,
9,
690,
413,
26,
199,
198,
893,
26,
507,
198,
509,
63,
3150,
275,
1109,
8,
1274,
14,
3020,
59,
17,
566,
199,
198,
2590,
26,
507,
198,
509,
63,
1404,
275,
984,
14,
3020,
59,
17,
61,
199,
199,
14507,
275,
27477,
342,
199,
199,
318,
3307,
63,
5037,
837,
199,
198,
1361,
298,
14414,
3304,
11,
35,
370,
3631,
436,
2498,
314,
6212,
2,
199,
199,
318,
3307,
63,
500,
837,
199,
198,
1361,
63,
19444,
63,
17552,
342,
199,
199,
318,
3066,
63,
14507,
363,
1274,
63,
4200,
8,
1430,
63,
354,
12,
1067,
12,
2863,
63,
3541,
12,
199,
198,
2330,
63,
4855,
12,
2863,
63,
9618,
12,
2863,
63,
3150,
12,
2863,
63,
1404,
12,
199,
198,
344,
12,
1249,
304,
421,
198,
692,
334,
509,
63,
1404,
436,
2863,
63,
1404,
1137,
367,
63,
1404,
9,
503,
971,
21979,
334,
509,
63,
3150,
221,
436,
2863,
63,
3150,
221,
1137,
367,
63,
3150,
3461,
507,
198,
1107,
199,
198,
893,
26,
507,
198,
14507,
59,
2330,
63,
1404,
1527,
2330,
63,
3150,
1527,
344,
61,
847,
413,
199,
198,
2590,
3146,
26,
507,
198,
14507,
59,
2330,
63,
1404,
1527,
2330,
63,
3150,
1527,
344,
61,
275,
413,
199,
199,
318,
870,
63,
19444,
63,
17552,
837,
272,
340,
367,
63,
1404,
365,
440,
488,
26,
6722,
870,
1867,
26605,
4474,
367,
450,
83,
3427,
78,
60,
78,
2,
450,
334,
509,
63,
1404,
395,
272,
587,
26,
6722,
870,
1867,
26605,
4474,
701,
1923,
15,
3150,
3427,
78,
60,
78,
401,
339,
870,
18301,
2167,
83,
221,
450,
709,
83,
60,
78,
2,
450,
1689,
1404,
359,
3150,
12978,
14507,
401,
298,
835,
1288,
272,
870,
18301,
2167,
83,
221,
450,
709,
83,
60,
78,
2,
450,
1689,
32111,
401,
971,
639,
298,
9460,
1288,
339,
1923,
63,
1612,
275,
19473,
14,
1612,
342,
272,
367,
1923,
315,
1923,
63,
1612,
26,
6722,
4422,
63,
1612,
275,
19473,
59,
1404,
1055,
1612,
342,
6722,
367,
4422,
315,
4422,
63,
1612,
26,
15075,
870,
1867,
78,
5,
83,
8978,
68,
7272,
78,
2,
450,
334,
1404,
12,
4422,
395,
15075,
1305,
63,
1612,
275,
19473,
59,
1404,
1527,
3150,
1055,
1612,
342,
15075,
367,
1305,
12,
1139,
315,
3355,
8,
14507,
59,
1404,
1527,
3150,
1055,
4611,
1062,
971,
1871,
221,
790,
275,
2400,
8,
75,
12,
373,
304,
334,
86,
12,
1022,
395,
221,
3837,
275,
715,
304,
24449,
870,
298,
221,
19752,
1703,
83,
221,
450,
709,
68,
60,
78,
2,
450,
334,
19444,
63,
354,
8,
344,
395,
1139,
395,
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,
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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# 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
import os
import json
import pytest
import sys
if sys.version_info < (2, 7):
pytestmark = pytest.mark.skip("F5 Ansible modules require Python >= 2.7")
from ansible.module_utils.basic import AnsibleModule
try:
from library.modules.bigip_wait import Parameters
from library.modules.bigip_wait import ModuleManager
from library.modules.bigip_wait import ArgumentSpec
# In Ansible 2.8, Ansible changed import paths.
from test.units.compat import unittest
from test.units.compat.mock import Mock
from test.units.compat.mock import patch
from test.units.modules.utils import set_module_args
except ImportError:
from ansible.modules.network.f5.bigip_wait import Parameters
from ansible.modules.network.f5.bigip_wait import ModuleManager
from ansible.modules.network.f5.bigip_wait import ArgumentSpec
# Ansible 2.8 imports
from units.compat import unittest
from units.compat.mock import Mock
from units.compat.mock import patch
from units.modules.utils import set_module_args
fixture_path = os.path.join(os.path.dirname(__file__), 'fixtures')
fixture_data = {}
def load_fixture(name):
path = os.path.join(fixture_path, name)
if path in fixture_data:
return fixture_data[path]
with open(path) as f:
data = f.read()
try:
data = json.loads(data)
except Exception:
pass
fixture_data[path] = data
return data
class TestParameters(unittest.TestCase):
def test_module_parameters(self):
args = dict(
delay=3,
timeout=500,
sleep=10,
msg='We timed out during waiting for BIG-IP :-('
)
p = Parameters(params=args)
assert p.delay == 3
assert p.timeout == 500
assert p.sleep == 10
assert p.msg == 'We timed out during waiting for BIG-IP :-('
def test_module_string_parameters(self):
args = dict(
delay='3',
timeout='500',
sleep='10',
msg='We timed out during waiting for BIG-IP :-('
)
p = Parameters(params=args)
assert p.delay == 3
assert p.timeout == 500
assert p.sleep == 10
assert p.msg == 'We timed out during waiting for BIG-IP :-('
class TestManager(unittest.TestCase):
def setUp(self):
self.spec = ArgumentSpec()
self.patcher1 = patch('time.sleep')
self.patcher1.start()
def tearDown(self):
self.patcher1.stop()
def test_wait_already_available(self, *args):
set_module_args(dict(
password='password',
server='localhost',
user='admin'
))
module = AnsibleModule(
argument_spec=self.spec.argument_spec,
supports_check_mode=self.spec.supports_check_mode
)
# Override methods to force specific logic in the module to happen
mm = ModuleManager(module=module)
mm._connect_to_device = Mock(return_value=True)
mm._device_is_rebooting = Mock(return_value=False)
mm._is_mprov_running_on_device = Mock(return_value=False)
mm._get_client_connection = Mock(return_value=True)
results = mm.exec_module()
assert results['changed'] is False
assert results['elapsed'] == 0
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
334,
67,
9,
9708,
481,
21,
17138,
3277,
14,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
646,
747,
199,
646,
2022,
199,
646,
4613,
199,
646,
984,
199,
199,
692,
984,
14,
1023,
63,
815,
665,
334,
18,
12,
1520,
304,
272,
4613,
1657,
275,
4613,
14,
1657,
14,
2759,
480,
38,
21,
2622,
4621,
4409,
2018,
2356,
499,
14,
23,
531,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
199,
199,
893,
26,
272,
687,
3555,
14,
3112,
14,
17833,
63,
2573,
492,
3897,
272,
687,
3555,
14,
3112,
14,
17833,
63,
2573,
492,
24118,
272,
687,
3555,
14,
3112,
14,
17833,
63,
2573,
492,
28405,
339,
327,
1010,
2622,
499,
14,
24,
12,
2622,
2896,
492,
3792,
14,
272,
687,
511,
14,
5260,
14,
5819,
492,
2882,
272,
687,
511,
14,
5260,
14,
5819,
14,
1805,
492,
4420,
272,
687,
511,
14,
5260,
14,
5819,
14,
1805,
492,
3371,
339,
687,
511,
14,
5260,
14,
3112,
14,
1208,
492,
663,
63,
578,
63,
589,
199,
2590,
3545,
26,
272,
687,
3242,
14,
3112,
14,
1200,
14,
70,
21,
14,
17833,
63,
2573,
492,
3897,
272,
687,
3242,
14,
3112,
14,
1200,
14,
70,
21,
14,
17833,
63,
2573,
492,
24118,
272,
687,
3242,
14,
3112,
14,
1200,
14,
70,
21,
14,
17833,
63,
2573,
492,
28405,
339,
327,
2622,
499,
14,
24,
8925,
272,
687,
6204,
14,
5819,
492,
2882,
272,
687,
6204,
14,
5819,
14,
1805,
492,
4420,
272,
687,
6204,
14,
5819,
14,
1805,
492,
3371,
339,
687,
6204,
14,
3112,
14,
1208,
492,
663,
63,
578,
63,
589,
421,
199,
5997,
63,
515,
275,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
283,
8769,
358,
199,
5997,
63,
576,
275,
1052,
421,
199,
318,
2248,
63,
5997,
8,
354,
304,
272,
931,
275,
747,
14,
515,
14,
904,
8,
5997,
63,
515,
12,
536,
9,
339,
340,
931,
315,
10949,
63,
576,
26,
267,
372,
10949,
63,
576,
59,
515,
61,
339,
543,
1551,
8,
515,
9,
465,
289,
26,
267,
666,
275,
289,
14,
739,
342,
339,
862,
26,
267,
666,
275,
2022,
14,
3640,
8,
576,
9,
272,
871,
2186,
26,
267,
986,
339,
10949,
63,
576,
59,
515,
61,
275,
666,
272,
372,
666,
421,
199,
533,
1379,
5976,
8,
2796,
14,
1746,
304,
272,
347,
511,
63,
578,
63,
3214,
8,
277,
304,
267,
1249,
275,
1211,
8,
288,
7339,
29,
19,
12,
288,
2653,
29,
5783,
12,
288,
9435,
29,
709,
12,
288,
1499,
534,
6004,
18590,
734,
5309,
10923,
367,
16524,
13,
1772,
22901,
360,
267,
776,
398,
299,
275,
3897,
8,
1162,
29,
589,
9,
267,
702,
299,
14,
5814,
508,
650,
267,
702,
299,
14,
2593,
508,
6891,
267,
702,
299,
14,
4532,
508,
1616,
267,
702,
299,
14,
1328,
508,
283,
6004,
18590,
734,
5309,
10923,
367,
16524,
13,
1772,
22901,
360,
339,
347,
511,
63,
578,
63,
875,
63,
3214,
8,
277,
304,
267,
1249,
275,
1211,
8,
288,
7339,
534,
19,
297,
288,
2653,
534,
5783,
297,
288,
9435,
534,
709,
297,
288,
1499,
534,
6004,
18590,
734,
5309,
10923,
367,
16524,
13,
1772,
22901,
360,
267,
776,
398,
299,
275,
3897,
8,
1162,
29,
589,
9,
267,
702,
299,
14,
5814,
508,
650,
267,
702,
299,
14,
2593,
508,
6891,
267,
702,
299,
14,
4532,
508,
1616,
267,
702,
299,
14,
1328,
508,
283,
6004,
18590,
734,
5309,
10923,
367,
16524,
13,
1772,
22901,
360,
421,
199,
533,
1379,
2988,
8,
2796,
14,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
291,
14,
1650,
275,
28405,
342,
267,
291,
14,
11238,
17,
275,
3371,
360,
521,
14,
4532,
358,
267,
291,
14,
11238,
17,
14,
928,
342,
339,
347,
6766,
8,
277,
304,
267,
291,
14,
11238,
17,
14,
2379,
342,
339,
347,
511,
63,
2573,
63,
14039,
63,
4561,
8,
277,
12,
627,
589,
304,
267,
663,
63,
578,
63,
589,
8,
807,
8,
288,
2505,
534,
2060,
297,
288,
1654,
534,
5967,
297,
288,
922,
534,
2113,
7,
267,
5082,
398,
859,
275,
6953,
8,
288,
1423,
63,
1650,
29,
277,
14,
1650,
14,
2094,
63,
1650,
12,
288,
5171,
63,
1074,
63,
632,
29,
277,
14,
1650,
14,
9823,
63,
1074,
63,
632,
267,
776,
398,
327,
11041,
3102,
370,
3542,
2488,
9661,
315,
314,
859,
370,
5992,
267,
8562,
275,
24118,
8,
578,
29,
578,
9,
267,
8562,
423,
2242,
63,
475,
63,
1782,
275,
4420,
8,
1107,
63,
585,
29,
549,
9,
267,
8562,
423,
1782,
63,
374,
63,
15051,
316,
275,
4420,
8,
1107,
63,
585,
29,
797,
9,
267,
8562,
423,
374,
63,
311,
293,
86,
63,
5720,
63,
265,
63,
1782,
275,
4420,
8,
1107,
63,
585,
29,
797,
9,
267,
8562,
423,
362,
63,
1258,
63,
2105,
275,
4420,
8,
1107,
63,
585,
29,
549,
9,
398,
2058,
275,
8562,
14,
1628,
63,
578,
342,
398,
702,
2058,
459,
2489,
418,
365,
756,
267,
702,
2058,
459,
16691,
418,
508,
378,
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
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
334,
67,
9,
9708,
481,
21,
17138,
3277,
14,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
646,
747,
199,
646,
2022,
199,
646,
4613,
199,
646,
984,
199,
199,
692,
984,
14,
1023,
63,
815,
665,
334,
18,
12,
1520,
304,
272,
4613,
1657,
275,
4613,
14,
1657,
14,
2759,
480,
38,
21,
2622,
4621,
4409,
2018,
2356,
499,
14,
23,
531,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
199,
199,
893,
26,
272,
687,
3555,
14,
3112,
14,
17833,
63,
2573,
492,
3897,
272,
687,
3555,
14,
3112,
14,
17833,
63,
2573,
492,
24118,
272,
687,
3555,
14,
3112,
14,
17833,
63,
2573,
492,
28405,
339,
327,
1010,
2622,
499,
14,
24,
12,
2622,
2896,
492,
3792,
14,
272,
687,
511,
14,
5260,
14,
5819,
492,
2882,
272,
687,
511,
14,
5260,
14,
5819,
14,
1805,
492,
4420,
272,
687,
511,
14,
5260,
14,
5819,
14,
1805,
492,
3371,
339,
687,
511,
14,
5260,
14,
3112,
14,
1208,
492,
663,
63,
578,
63,
589,
199,
2590,
3545,
26,
272,
687,
3242,
14,
3112,
14,
1200,
14,
70,
21,
14,
17833,
63,
2573,
492,
3897,
272,
687,
3242,
14,
3112,
14,
1200,
14,
70,
21,
14,
17833,
63,
2573,
492,
24118,
272,
687,
3242,
14,
3112,
14,
1200,
14,
70,
21,
14,
17833,
63,
2573,
492,
28405,
339,
327,
2622,
499,
14,
24,
8925,
272,
687,
6204,
14,
5819,
492,
2882,
272,
687,
6204,
14,
5819,
14,
1805,
492,
4420,
272,
687,
6204,
14,
5819,
14,
1805,
492,
3371,
339,
687,
6204,
14,
3112,
14,
1208,
492,
663,
63,
578,
63,
589,
421,
199,
5997,
63,
515,
275,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
283,
8769,
358,
199,
5997,
63,
576,
275,
1052,
421,
199,
318,
2248,
63,
5997,
8,
354,
304,
272,
931,
275,
747,
14,
515,
14,
904,
8,
5997,
63,
515,
12,
536,
9,
339,
340,
931,
315,
10949,
63,
576,
26,
267,
372,
10949,
63,
576,
59,
515,
61,
339,
543,
1551,
8,
515,
9,
465,
289,
26,
267,
666,
275,
289,
14,
739,
342,
339,
862,
26,
267,
666,
275,
2022,
14,
3640,
8,
576,
9,
272,
871,
2186,
26,
267,
986,
339,
10949,
63,
576,
59,
515,
61,
275,
666,
272,
372,
666,
421,
199,
533,
1379,
5976,
8,
2796,
14,
1746,
304,
272,
347,
511,
63,
578,
63,
3214,
8,
277,
304,
267,
1249,
275,
1211,
8,
288,
7339,
29,
19,
12,
288,
2653,
29,
5783,
12,
288,
9435,
29,
709,
12,
288,
1499,
534,
6004,
18590,
734,
5309,
10923,
367,
16524,
13,
1772,
22901,
360,
267,
776,
398,
299,
275,
3897,
8,
1162,
29,
589,
9,
267,
702,
299,
14,
5814,
508,
650,
267,
702,
299,
14,
2593,
508,
6891,
267,
702,
299,
14,
4532,
508,
1616,
267,
702,
299,
14,
1328,
508,
283,
6004,
18590,
734,
5309,
10923,
367,
16524,
13,
1772,
22901,
360,
339,
347,
511,
63,
578,
63,
875,
63,
3214,
8,
277,
304,
267,
1249,
275,
1211,
8,
288,
7339,
534,
19,
297,
288,
2653,
534,
5783,
297,
288,
9435,
534,
709,
297,
288,
1499,
534,
6004,
18590,
734,
5309,
10923,
367,
16524,
13,
1772,
22901,
360,
267,
776,
398,
299,
275,
3897,
8,
1162,
29,
589,
9,
267,
702,
299,
14,
5814,
508,
650,
267,
702,
299,
14,
2593,
508,
6891,
267,
702,
299,
14,
4532,
508,
1616,
267,
702,
299,
14,
1328,
508,
283,
6004,
18590,
734,
5309,
10923,
367,
16524,
13,
1772,
22901,
360,
421,
199,
533,
1379,
2988,
8,
2796,
14,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
291,
14,
1650,
275,
28405,
342,
267,
291,
14,
11238,
17,
275,
3371,
360,
521,
14,
4532,
358,
267,
291,
14,
11238,
17,
14,
928,
342,
339,
347,
6766,
8,
277,
304,
267,
291,
14,
11238,
17,
14,
2379,
342,
339,
347,
511,
63,
2573,
63,
14039,
63,
4561,
8,
277,
12,
627,
589,
304,
267,
663,
63,
578,
63,
589,
8,
807,
8,
288,
2505,
534,
2060,
297,
288,
1654,
534,
5967,
297,
288,
922,
534,
2113,
7,
267,
5082,
398,
859,
275,
6953,
8,
288,
1423,
63,
1650,
29,
277,
14,
1650,
14,
2094,
63,
1650,
12,
288,
5171,
63,
1074,
63,
632,
29,
277,
14,
1650,
14,
9823,
63,
1074,
63,
632,
267,
776,
398,
327,
11041,
3102,
370,
3542,
2488,
9661,
315,
314,
859,
370,
5992,
267,
8562,
275,
24118,
8,
578,
29,
578,
9,
267,
8562,
423,
2242,
63,
475,
63,
1782,
275,
4420,
8,
1107,
63,
585,
29,
549,
9,
267,
8562,
423,
1782,
63,
374,
63,
15051,
316,
275,
4420,
8,
1107,
63,
585,
29,
797,
9,
267,
8562,
423,
374,
63,
311,
293,
86,
63,
5720,
63,
265,
63,
1782,
275,
4420,
8,
1107,
63,
585,
29,
797,
9,
267,
8562,
423,
362,
63,
1258,
63,
2105,
275,
4420,
8,
1107,
63,
585,
29,
549,
9,
398,
2058,
275,
8562,
14,
1628,
63,
578,
342,
398,
702,
2058,
459,
2489,
418,
365,
756,
267,
702,
2058,
459,
16691,
418,
508,
378,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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emetry/core/backends/android_command_line_backend.py
|
11
|
3993
|
# Copyright 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import logging
import pipes
import sys
from telemetry.core import util
util.AddDirToPythonPath(util.GetChromiumSrcDir(), 'build', 'android')
from pylib.device import device_errors # pylint: disable=F0401
def _QuoteIfNeeded(arg):
# Properly escape "key=valueA valueB" to "key='valueA valueB'"
# Values without spaces, or that seem to be quoted are left untouched.
# This is required so CommandLine.java can parse valueB correctly rather
# than as a separate switch.
params = arg.split('=', 1)
if len(params) != 2:
return arg
key, values = params
if ' ' not in values:
return arg
if values[0] in '"\'' and values[-1] == values[0]:
return arg
return '%s=%s' % (key, pipes.quote(values))
class SetUpCommandLineFlags(object):
"""A context manager for setting up the android command line flags.
This provides a readable way of using the android command line backend class.
Example usage:
with android_command_line_backend.SetUpCommandLineFlags(
adb, backend_settings, startup_args):
# Something to run while the command line flags are set appropriately.
"""
def __init__(self, adb, backend_settings, startup_args):
self._android_command_line_backend = _AndroidCommandLineBackend(
adb, backend_settings, startup_args)
def __enter__(self):
self._android_command_line_backend.SetUpCommandLineFlags()
def __exit__(self, *args):
self._android_command_line_backend.RestoreCommandLineFlags()
class _AndroidCommandLineBackend(object):
"""The backend for providing command line flags on android.
There are command line flags that Chromium accept in order to enable
particular features or modify otherwise default functionality. To set the
flags for Chrome on Android, specific files on the device must be updated
with the flags to enable. This class provides a wrapper around this
functionality.
"""
def __init__(self, adb, backend_settings, startup_args):
self._adb = adb
self._backend_settings = backend_settings
self._startup_args = startup_args
self._saved_command_line_file_contents = None
@property
def command_line_file(self):
return self._backend_settings.GetCommandLineFile(self._adb.IsUserBuild())
def SetUpCommandLineFlags(self):
args = [self._backend_settings.pseudo_exec_name]
args.extend(self._startup_args)
content = ' '.join(_QuoteIfNeeded(arg) for arg in args)
try:
# Save the current command line to restore later, except if it appears to
# be a Telemetry created one. This is to prevent a common bug where
# --host-resolver-rules borks people's browsers if something goes wrong
# with Telemetry.
self._saved_command_line_file_contents = self._ReadFile()
if '--host-resolver-rules' in self._saved_command_line_file_contents:
self._saved_command_line_file_contents = None
except device_errors.CommandFailedError:
self._saved_command_line_file_contents = None
try:
self._WriteFile(content)
except device_errors.CommandFailedError as exc:
logging.critical(exc)
logging.critical('Cannot set Chrome command line. '
'Fix this by flashing to a userdebug build.')
sys.exit(1)
def RestoreCommandLineFlags(self):
if self._saved_command_line_file_contents is None:
self._RemoveFile()
else:
self._WriteFile(self._saved_command_line_file_contents)
def _ReadFile(self):
return self._adb.device().ReadFile(self.command_line_file, as_root=True)
def _WriteFile(self, contents):
self._adb.device().WriteFile(self.command_line_file, contents, as_root=True)
def _RemoveFile(self):
self._adb.device().RunShellCommand(['rm', '-f', self.command_line_file],
as_root=True, check_return=True)
|
bsd-3-clause
|
[
3,
1898,
6171,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
646,
2050,
199,
646,
20988,
199,
646,
984,
199,
199,
504,
17298,
14,
1018,
492,
4884,
199,
199,
1974,
14,
1123,
3567,
1378,
4718,
2042,
8,
1974,
14,
1002,
29381,
21261,
3567,
1062,
283,
1506,
297,
283,
6238,
358,
199,
504,
29219,
14,
1782,
492,
2243,
63,
2550,
221,
327,
4287,
26,
3507,
29,
38,
28025,
421,
199,
318,
485,
12838,
3917,
21549,
8,
1273,
304,
523,
327,
2165,
529,
590,
4772,
298,
498,
29,
585,
33,
574,
34,
2,
370,
298,
498,
534,
585,
33,
574,
34,
4065,
523,
327,
13468,
1928,
7883,
12,
503,
626,
17021,
370,
506,
10999,
787,
3602,
625,
31854,
14,
523,
327,
961,
365,
1415,
880,
5817,
3049,
14,
6138,
883,
2198,
574,
34,
6657,
7830,
523,
327,
2419,
465,
282,
7396,
6258,
14,
523,
1862,
275,
1680,
14,
1294,
25283,
413,
9,
523,
340,
822,
8,
1162,
9,
1137,
499,
26,
272,
372,
1680,
523,
790,
12,
1338,
275,
1862,
523,
340,
283,
283,
440,
315,
1338,
26,
272,
372,
1680,
523,
340,
1338,
59,
16,
61,
315,
283,
3212,
891,
436,
1338,
1988,
17,
61,
508,
1338,
59,
16,
2189,
272,
372,
1680,
523,
372,
1543,
83,
2458,
83,
7,
450,
334,
498,
12,
20988,
14,
3513,
8,
1459,
430,
421,
199,
533,
2494,
1721,
16926,
6381,
8,
785,
304,
523,
408,
33,
1067,
5256,
367,
4260,
1536,
314,
15516,
1414,
1004,
3285,
14,
819,
961,
6571,
282,
12701,
4340,
402,
1808,
314,
15516,
1414,
1004,
4865,
1021,
14,
523,
5679,
4503,
26,
2541,
543,
15516,
63,
1531,
63,
604,
63,
4620,
14,
19845,
16926,
6381,
8,
881,
28173,
12,
4865,
63,
1751,
12,
14210,
63,
589,
304,
267,
327,
27173,
370,
1255,
1830,
314,
1414,
1004,
3285,
787,
663,
22497,
14,
523,
408,
523,
347,
636,
826,
721,
277,
12,
28173,
12,
4865,
63,
1751,
12,
14210,
63,
589,
304,
272,
291,
423,
6238,
63,
1531,
63,
604,
63,
4620,
275,
485,
20762,
16926,
8447,
8,
267,
28173,
12,
4865,
63,
1751,
12,
14210,
63,
589,
9,
819,
347,
636,
4200,
721,
277,
304,
272,
291,
423,
6238,
63,
1531,
63,
604,
63,
4620,
14,
19845,
16926,
6381,
342,
819,
347,
636,
2224,
721,
277,
12,
627,
589,
304,
272,
291,
423,
6238,
63,
1531,
63,
604,
63,
4620,
14,
21012,
16926,
6381,
342,
421,
199,
533,
485,
20762,
16926,
8447,
8,
785,
304,
523,
408,
1918,
4865,
367,
13070,
1414,
1004,
3285,
641,
15516,
14,
819,
6006,
787,
1414,
1004,
3285,
626,
12051,
4729,
315,
1865,
370,
4756,
523,
6770,
4534,
503,
2811,
4257,
849,
9330,
14,
4005,
663,
314,
523,
3285,
367,
16776,
641,
14694,
12,
2488,
1584,
641,
314,
2243,
1471,
506,
4588,
523,
543,
314,
3285,
370,
4756,
14,
961,
1021,
6571,
282,
4975,
6818,
642,
523,
9330,
14,
523,
408,
819,
347,
636,
826,
721,
277,
12,
28173,
12,
4865,
63,
1751,
12,
14210,
63,
589,
304,
272,
291,
423,
13741,
275,
28173,
272,
291,
423,
4620,
63,
1751,
275,
4865,
63,
1751,
272,
291,
423,
16480,
63,
589,
275,
14210,
63,
589,
272,
291,
423,
8420,
63,
1531,
63,
604,
63,
493,
63,
4407,
275,
488,
819,
768,
1829,
523,
347,
1414,
63,
604,
63,
493,
8,
277,
304,
272,
372,
291,
423,
4620,
63,
1751,
14,
1002,
16926,
1173,
8,
277,
423,
13741,
14,
1831,
1899,
3425,
1012,
819,
347,
2494,
1721,
16926,
6381,
8,
277,
304,
272,
1249,
275,
359,
277,
423,
4620,
63,
1751,
14,
22490,
63,
1628,
63,
354,
61,
272,
1249,
14,
2880,
8,
277,
423,
16480,
63,
589,
9,
272,
1564,
275,
283,
1987,
904,
1547,
12838,
3917,
21549,
8,
1273,
9,
367,
1680,
315,
1249,
9,
339,
862,
26,
489,
327,
11063,
314,
1453,
1414,
1004,
370,
9066,
2945,
12,
871,
340,
652,
11337,
370,
489,
327,
506,
282,
221,
23884,
10987,
2737,
1373,
14,
961,
365,
370,
7981,
282,
2863,
6519,
2382,
489,
327,
1553,
1102,
13,
7717,
13,
4423,
330,
4708,
83,
13135,
1159,
23776,
340,
6020,
13538,
6835,
489,
327,
543,
23884,
10987,
14,
489,
291,
423,
8420,
63,
1531,
63,
604,
63,
493,
63,
4407,
275,
291,
423,
32356,
342,
489,
340,
2850,
1102,
13,
7717,
13,
4423,
7,
315,
291,
423,
8420,
63,
1531,
63,
604,
63,
493,
63,
4407,
26,
267,
291,
423,
8420,
63,
1531,
63,
604,
63,
493,
63,
4407,
275,
488,
272,
871,
2243,
63,
2550,
14,
3110,
4276,
547,
26,
489,
291,
423,
8420,
63,
1531,
63,
604,
63,
493,
63,
4407,
275,
488,
339,
862,
26,
489,
291,
423,
3534,
1173,
8,
1317,
9,
272,
871,
2243,
63,
2550,
14,
3110,
4276,
547,
465,
3178,
26,
489,
2050,
14,
13138,
8,
2804,
9,
489,
2050,
14,
13138,
360,
6612,
663,
16776,
1414,
1004,
14,
283,
2432,
283,
11985,
642,
701,
14775,
316,
370,
282,
922,
1757,
1900,
2659,
489,
984,
14,
2224,
8,
17,
9,
819,
347,
22379,
16926,
6381,
8,
277,
304,
272,
340,
291,
423,
8420,
63,
1531,
63,
604,
63,
493,
63,
4407,
365,
488,
26,
489,
291,
423,
5587,
1173,
342,
272,
587,
26,
489,
291,
423,
3534,
1173,
8,
277,
423,
8420,
63,
1531,
63,
604,
63,
493,
63,
4407,
9,
819,
347,
485,
32356,
8,
277,
304,
272,
372,
291,
423,
13741,
14,
1782,
1252,
32356,
8,
277,
14,
1531,
63,
604,
63,
493,
12,
465,
63,
1231,
29,
549,
9,
819,
347,
485,
3534,
1173,
8,
277,
12,
4072,
304,
272,
291,
423,
13741,
14,
1782,
1252,
3534,
1173,
8,
277,
14,
1531,
63,
604,
63,
493,
12,
4072,
12,
465,
63,
1231,
29,
549,
9,
819,
347,
485,
5587,
1173,
8,
277,
304,
272,
291,
423,
13741,
14,
1782,
1252,
2540,
8529,
3110,
2941,
5682,
297,
2475,
70,
297,
291,
14,
1531,
63,
604,
63,
493,
467,
4318,
465,
63,
1231,
29,
549,
12,
1104,
63,
1107,
29,
549,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
6171,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
646,
2050,
199,
646,
20988,
199,
646,
984,
199,
199,
504,
17298,
14,
1018,
492,
4884,
199,
199,
1974,
14,
1123,
3567,
1378,
4718,
2042,
8,
1974,
14,
1002,
29381,
21261,
3567,
1062,
283,
1506,
297,
283,
6238,
358,
199,
504,
29219,
14,
1782,
492,
2243,
63,
2550,
221,
327,
4287,
26,
3507,
29,
38,
28025,
421,
199,
318,
485,
12838,
3917,
21549,
8,
1273,
304,
523,
327,
2165,
529,
590,
4772,
298,
498,
29,
585,
33,
574,
34,
2,
370,
298,
498,
534,
585,
33,
574,
34,
4065,
523,
327,
13468,
1928,
7883,
12,
503,
626,
17021,
370,
506,
10999,
787,
3602,
625,
31854,
14,
523,
327,
961,
365,
1415,
880,
5817,
3049,
14,
6138,
883,
2198,
574,
34,
6657,
7830,
523,
327,
2419,
465,
282,
7396,
6258,
14,
523,
1862,
275,
1680,
14,
1294,
25283,
413,
9,
523,
340,
822,
8,
1162,
9,
1137,
499,
26,
272,
372,
1680,
523,
790,
12,
1338,
275,
1862,
523,
340,
283,
283,
440,
315,
1338,
26,
272,
372,
1680,
523,
340,
1338,
59,
16,
61,
315,
283,
3212,
891,
436,
1338,
1988,
17,
61,
508,
1338,
59,
16,
2189,
272,
372,
1680,
523,
372,
1543,
83,
2458,
83,
7,
450,
334,
498,
12,
20988,
14,
3513,
8,
1459,
430,
421,
199,
533,
2494,
1721,
16926,
6381,
8,
785,
304,
523,
408,
33,
1067,
5256,
367,
4260,
1536,
314,
15516,
1414,
1004,
3285,
14,
819,
961,
6571,
282,
12701,
4340,
402,
1808,
314,
15516,
1414,
1004,
4865,
1021,
14,
523,
5679,
4503,
26,
2541,
543,
15516,
63,
1531,
63,
604,
63,
4620,
14,
19845,
16926,
6381,
8,
881,
28173,
12,
4865,
63,
1751,
12,
14210,
63,
589,
304,
267,
327,
27173,
370,
1255,
1830,
314,
1414,
1004,
3285,
787,
663,
22497,
14,
523,
408,
523,
347,
636,
826,
721,
277,
12,
28173,
12,
4865,
63,
1751,
12,
14210,
63,
589,
304,
272,
291,
423,
6238,
63,
1531,
63,
604,
63,
4620,
275,
485,
20762,
16926,
8447,
8,
267,
28173,
12,
4865,
63,
1751,
12,
14210,
63,
589,
9,
819,
347,
636,
4200,
721,
277,
304,
272,
291,
423,
6238,
63,
1531,
63,
604,
63,
4620,
14,
19845,
16926,
6381,
342,
819,
347,
636,
2224,
721,
277,
12,
627,
589,
304,
272,
291,
423,
6238,
63,
1531,
63,
604,
63,
4620,
14,
21012,
16926,
6381,
342,
421,
199,
533,
485,
20762,
16926,
8447,
8,
785,
304,
523,
408,
1918,
4865,
367,
13070,
1414,
1004,
3285,
641,
15516,
14,
819,
6006,
787,
1414,
1004,
3285,
626,
12051,
4729,
315,
1865,
370,
4756,
523,
6770,
4534,
503,
2811,
4257,
849,
9330,
14,
4005,
663,
314,
523,
3285,
367,
16776,
641,
14694,
12,
2488,
1584,
641,
314,
2243,
1471,
506,
4588,
523,
543,
314,
3285,
370,
4756,
14,
961,
1021,
6571,
282,
4975,
6818,
642,
523,
9330,
14,
523,
408,
819,
347,
636,
826,
721,
277,
12,
28173,
12,
4865,
63,
1751,
12,
14210,
63,
589,
304,
272,
291,
423,
13741,
275,
28173,
272,
291,
423,
4620,
63,
1751,
275,
4865,
63,
1751,
272,
291,
423,
16480,
63,
589,
275,
14210,
63,
589,
272,
291,
423,
8420,
63,
1531,
63,
604,
63,
493,
63,
4407,
275,
488,
819,
768,
1829,
523,
347,
1414,
63,
604,
63,
493,
8,
277,
304,
272,
372,
291,
423,
4620,
63,
1751,
14,
1002,
16926,
1173,
8,
277,
423,
13741,
14,
1831,
1899,
3425,
1012,
819,
347,
2494,
1721,
16926,
6381,
8,
277,
304,
272,
1249,
275,
359,
277,
423,
4620,
63,
1751,
14,
22490,
63,
1628,
63,
354,
61,
272,
1249,
14,
2880,
8,
277,
423,
16480,
63,
589,
9,
272,
1564,
275,
283,
1987,
904,
1547,
12838,
3917,
21549,
8,
1273,
9,
367,
1680,
315,
1249,
9,
339,
862,
26,
489,
327,
11063,
314,
1453,
1414,
1004,
370,
9066,
2945,
12,
871,
340,
652,
11337,
370,
489,
327,
506,
282,
221,
23884,
10987,
2737,
1373,
14,
961,
365,
370,
7981,
282,
2863,
6519,
2382,
489,
327,
1553,
1102,
13,
7717,
13,
4423,
330,
4708,
83,
13135,
1159,
23776,
340,
6020,
13538,
6835,
489,
327,
543,
23884,
10987,
14,
489,
291,
423,
8420,
63,
1531,
63,
604,
63,
493,
63,
4407,
275,
291,
423,
32356,
342,
489,
340,
2850,
1102,
13,
7717,
13,
4423,
7,
315,
291,
423,
8420,
63,
1531,
63,
604,
63,
493,
63,
4407,
26,
267,
291,
423,
8420,
63,
1531,
63,
604,
63,
493,
63,
4407,
275,
488,
272,
871,
2243,
63,
2550,
14,
3110,
4276,
547,
26,
489,
291,
423,
8420,
63,
1531,
63,
604,
63,
493,
63,
4407,
275,
488,
339,
862,
26,
489,
291,
423,
3534,
1173,
8,
1317,
9,
272,
871,
2243,
63,
2550,
14,
3110,
4276,
547,
465,
3178,
26,
489,
2050,
14,
13138,
8,
2804,
9,
489,
2050,
14,
13138,
360,
6612,
663,
16776,
1414,
1004,
14,
283,
2432,
283,
11985,
642,
701,
14775,
316,
370,
282,
922,
1757,
1900,
2659,
489,
984,
14,
2224,
8,
17,
9,
819,
347,
22379,
16926,
6381,
8,
277,
304,
272,
340,
291,
423,
8420,
63,
1531,
63,
604,
63,
493,
63,
4407,
365,
488,
26,
489,
291,
423,
5587,
1173,
342,
272,
587,
26,
489,
291,
423,
3534,
1173,
8,
277,
423,
8420,
63,
1531,
63,
604,
63,
493,
63,
4407,
9,
819,
347,
485,
32356,
8,
277,
304,
272,
372,
291,
423,
13741,
14,
1782,
1252,
32356,
8,
277,
14,
1531,
63,
604,
63,
493,
12,
465,
63,
1231,
29,
549,
9,
819,
347,
485,
3534,
1173,
8,
277,
12,
4072,
304,
272,
291,
423,
13741,
14,
1782,
1252,
3534,
1173,
8,
277,
14,
1531,
63,
604,
63,
493,
12,
4072,
12,
465,
63,
1231,
29,
549,
9,
819,
347,
485,
5587,
1173,
8,
277,
304,
272,
291,
423,
13741,
14,
1782,
1252,
2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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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
AOKP/external_chromium_org
|
chrome/app/nibs/PRESUBMIT.py
|
126
|
3062
|
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Presubmit script to verify that XIB changes are done with the right version.
See http://dev.chromium.org/developers/design-documents/mac-xib-files for more
information.
"""
import re
# Minimum is Mac OS X 10.8.1 (12B19).
HUMAN_DARWIN_VERSION = '10.8.x, x >= 1'
ALLOWED_DARWIN_VERSION = 12 # Darwin 12 = 10.8.
MINIMUM_DARWIN_RELEASE = 'B' # Release B = 10.8.1.
MINIMUM_IB_VERSION = 2549 # Xcode 4.4.1.
MAXIMUM_IB_VERSION = 3084 # Xcode 4.6.x.
HUMAN_IB_VERSION = '>= 4.4.1, <= 4.6.x'
SYSTEM_VERSION_RE = r'<string key="IBDocument\.SystemVersion">' + \
'([0-9]{,2})([A-Z])([0-9]+)</string>'
IB_VERSION_RE = \
r'<string key="IBDocument\.InterfaceBuilderVersion">([0-9]+)</string>'
def _CheckXIBSystemAndXcodeVersions(input_api, output_api, error_type):
affected_xibs = [x for x in input_api.AffectedFiles()
if x.LocalPath().endswith('.xib')]
incorrect_system_versions = []
incorrect_ib_versions = []
for xib in affected_xibs:
if len(xib.NewContents()) == 0:
continue
system_version = None
ib_version = None
new_contents = xib.NewContents()
if not new_contents:
# Deleting files is always fine.
continue
for line in new_contents:
m = re.search(SYSTEM_VERSION_RE, line)
if m:
system_version = (m.group(1), m.group(2), m.group(3))
m = re.search(IB_VERSION_RE, line)
if m:
ib_version = m.group(1)
if system_version is not None and ib_version is not None:
break
if system_version is None:
incorrect_system_versions.append(xib.LocalPath())
continue
if int(system_version[0]) != ALLOWED_DARWIN_VERSION:
incorrect_system_versions.append(xib.LocalPath())
continue
if system_version[1] < MINIMUM_DARWIN_RELEASE:
incorrect_system_versions.append(xib.LocalPath())
continue
if ib_version is None or int(ib_version) < MINIMUM_IB_VERSION or \
int(ib_version) > MAXIMUM_IB_VERSION:
incorrect_ib_versions.append(xib.LocalPath())
continue
problems = []
if incorrect_system_versions:
problems.append(error_type(
'XIB files need to be saved on Mac OS X ' + HUMAN_DARWIN_VERSION,
items=incorrect_system_versions))
if incorrect_ib_versions:
problems.append(error_type(
'XIB files need to be saved using Xcode version ' + HUMAN_IB_VERSION,
items=incorrect_ib_versions))
return problems
def CheckChangeOnUpload(input_api, output_api):
# Allow uploads to happen even if the presubmit fails, so that contributors
# can ask their reviewer or another person to re-save the XIBs for them.
return _CheckXIBSystemAndXcodeVersions(input_api, output_api,
error_type=output_api.PresubmitPromptWarning)
def CheckChangeOnCommit(input_api, output_api):
return _CheckXIBSystemAndXcodeVersions(input_api, output_api,
error_type=output_api.PresubmitError)
|
bsd-3-clause
|
[
3,
1898,
334,
67,
9,
6029,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
30607,
2884,
370,
4911,
626,
1323,
2100,
4493,
787,
4224,
543,
314,
2451,
1015,
14,
199,
199,
9295,
1455,
921,
2374,
14,
13211,
14,
1308,
15,
23826,
15,
14748,
13,
12233,
15,
3088,
13,
88,
1892,
13,
1725,
367,
1655,
199,
11697,
14,
199,
624,
199,
199,
646,
295,
199,
199,
3,
22466,
365,
10444,
4403,
1323,
1616,
14,
24,
14,
17,
334,
713,
34,
1167,
680,
199,
40,
2639,
879,
63,
36,
689,
7941,
63,
4612,
275,
283,
709,
14,
24,
14,
88,
12,
671,
2356,
413,
7,
199,
17350,
63,
36,
689,
7941,
63,
4612,
275,
3144,
221,
327,
577,
22822,
3144,
275,
1616,
14,
24,
14,
199,
4896,
27078,
63,
36,
689,
7941,
63,
19736,
275,
283,
34,
7,
221,
327,
17646,
699,
275,
1616,
14,
24,
14,
17,
14,
199,
199,
4896,
27078,
63,
2100,
63,
4612,
275,
499,
15419,
221,
327,
10602,
841,
14,
20,
14,
17,
14,
199,
4283,
27078,
63,
2100,
63,
4612,
275,
4233,
1349,
221,
327,
10602,
841,
14,
22,
14,
88,
14,
199,
40,
2639,
879,
63,
2100,
63,
4612,
275,
283,
8119,
841,
14,
20,
14,
17,
12,
2695,
841,
14,
22,
14,
88,
7,
199,
199,
12711,
63,
4612,
63,
907,
275,
519,
7601,
875,
790,
628,
2100,
5564,
4537,
3989,
3353,
15603,
435,
971,
272,
283,
779,
16,
13,
25,
8194,
12,
18,
1552,
779,
33,
13,
58,
566,
779,
16,
13,
25,
11896,
1108,
875,
3524,
199,
199,
2100,
63,
4612,
63,
907,
275,
971,
272,
519,
7601,
875,
790,
628,
2100,
5564,
4537,
4267,
6437,
3353,
1743,
779,
16,
13,
25,
11896,
1108,
875,
3524,
199,
199,
318,
485,
1799,
56,
2100,
3989,
3325,
18442,
21167,
8,
1210,
63,
1246,
12,
1072,
63,
1246,
12,
1125,
63,
466,
304,
523,
16955,
63,
6865,
1533,
275,
359,
88,
367,
671,
315,
1324,
63,
1246,
14,
19256,
6201,
5535,
342,
489,
340,
671,
14,
26453,
1252,
4130,
5175,
88,
1892,
5440,
819,
8927,
63,
2253,
63,
6234,
275,
942,
523,
8927,
63,
1892,
63,
6234,
275,
942,
819,
367,
671,
1892,
315,
16955,
63,
6865,
1533,
26,
272,
340,
822,
8,
88,
1892,
14,
4665,
11383,
1012,
508,
378,
26,
489,
1980,
339,
2656,
63,
1023,
275,
488,
272,
26242,
63,
1023,
275,
488,
339,
892,
63,
4407,
275,
671,
1892,
14,
4665,
11383,
342,
272,
340,
440,
892,
63,
4407,
26,
489,
327,
15920,
1584,
365,
3544,
15701,
14,
489,
1980,
339,
367,
1004,
315,
892,
63,
4407,
26,
489,
333,
275,
295,
14,
1733,
8,
12711,
63,
4612,
63,
907,
12,
1004,
9,
489,
340,
333,
26,
267,
2656,
63,
1023,
275,
334,
77,
14,
923,
8,
17,
395,
333,
14,
923,
8,
18,
395,
333,
14,
923,
8,
19,
430,
2541,
333,
275,
295,
14,
1733,
8,
2100,
63,
4612,
63,
907,
12,
1004,
9,
489,
340,
333,
26,
267,
26242,
63,
1023,
275,
333,
14,
923,
8,
17,
9,
2541,
340,
2656,
63,
1023,
365,
440,
488,
436,
26242,
63,
1023,
365,
440,
488,
26,
267,
2059,
339,
340,
2656,
63,
1023,
365,
488,
26,
489,
8927,
63,
2253,
63,
6234,
14,
740,
8,
88,
1892,
14,
26453,
1012,
489,
1980,
272,
340,
1109,
8,
2253,
63,
1023,
59,
16,
566,
1137,
27805,
1149,
63,
36,
689,
7941,
63,
4612,
26,
489,
8927,
63,
2253,
63,
6234,
14,
740,
8,
88,
1892,
14,
26453,
1012,
489,
1980,
272,
340,
2656,
63,
1023,
59,
17,
61,
665,
15861,
27078,
63,
36,
689,
7941,
63,
19736,
26,
489,
8927,
63,
2253,
63,
6234,
14,
740,
8,
88,
1892,
14,
26453,
1012,
489,
1980,
339,
340,
26242,
63,
1023,
365,
488,
503,
1109,
8,
1892,
63,
1023,
9,
665,
15861,
27078,
63,
2100,
63,
4612,
503,
971,
2126,
1109,
8,
1892,
63,
1023,
9,
690,
9141,
27078,
63,
2100,
63,
4612,
26,
489,
8927,
63,
1892,
63,
6234,
14,
740,
8,
88,
1892,
14,
26453,
1012,
489,
1980,
819,
8826,
275,
942,
523,
340,
8927,
63,
2253,
63,
6234,
26,
272,
8826,
14,
740,
8,
705,
63,
466,
8,
267,
283,
56,
2100,
1584,
1929,
370,
506,
6290,
641,
10444,
4403,
1323,
283,
435,
869,
2639,
879,
63,
36,
689,
7941,
63,
4612,
12,
267,
2974,
29,
15448,
63,
2253,
63,
6234,
430,
523,
340,
8927,
63,
1892,
63,
6234,
26,
272,
8826,
14,
740,
8,
705,
63,
466,
8,
267,
283,
56,
2100,
1584,
1929,
370,
506,
6290,
1808,
10602,
1015,
283,
435,
869,
2639,
879,
63,
2100,
63,
4612,
12,
267,
2974,
29,
15448,
63,
1892,
63,
6234,
430,
523,
372,
8826,
199,
199,
318,
2670,
4001,
3314,
10301,
8,
1210,
63,
1246,
12,
1072,
63,
1246,
304,
523,
327,
9812,
26598,
370,
5992,
2755,
340,
314,
23895,
6918,
12,
880,
626,
8417,
523,
327,
883,
7198,
3932,
11248,
281,
503,
4573,
4954,
370,
295,
13,
2117,
314,
1323,
2100,
83,
367,
3062,
14,
523,
372,
485,
1799,
56,
2100,
3989,
3325,
18442,
21167,
8,
1210,
63,
1246,
12,
1072,
63,
1246,
12,
489,
1125,
63,
466,
29,
1199,
63,
1246,
14,
30607,
20430,
3849,
9,
199,
199,
318,
2670,
4001,
3314,
11421,
8,
1210,
63,
1246,
12,
1072,
63,
1246,
304,
523,
372,
485,
1799,
56,
2100,
3989,
3325,
18442,
21167,
8,
1210,
63,
1246,
12,
1072,
63,
1246,
12,
489,
1125,
63,
466,
29,
1199,
63,
1246,
14,
30607,
547,
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
] |
[
1898,
334,
67,
9,
6029,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
30607,
2884,
370,
4911,
626,
1323,
2100,
4493,
787,
4224,
543,
314,
2451,
1015,
14,
199,
199,
9295,
1455,
921,
2374,
14,
13211,
14,
1308,
15,
23826,
15,
14748,
13,
12233,
15,
3088,
13,
88,
1892,
13,
1725,
367,
1655,
199,
11697,
14,
199,
624,
199,
199,
646,
295,
199,
199,
3,
22466,
365,
10444,
4403,
1323,
1616,
14,
24,
14,
17,
334,
713,
34,
1167,
680,
199,
40,
2639,
879,
63,
36,
689,
7941,
63,
4612,
275,
283,
709,
14,
24,
14,
88,
12,
671,
2356,
413,
7,
199,
17350,
63,
36,
689,
7941,
63,
4612,
275,
3144,
221,
327,
577,
22822,
3144,
275,
1616,
14,
24,
14,
199,
4896,
27078,
63,
36,
689,
7941,
63,
19736,
275,
283,
34,
7,
221,
327,
17646,
699,
275,
1616,
14,
24,
14,
17,
14,
199,
199,
4896,
27078,
63,
2100,
63,
4612,
275,
499,
15419,
221,
327,
10602,
841,
14,
20,
14,
17,
14,
199,
4283,
27078,
63,
2100,
63,
4612,
275,
4233,
1349,
221,
327,
10602,
841,
14,
22,
14,
88,
14,
199,
40,
2639,
879,
63,
2100,
63,
4612,
275,
283,
8119,
841,
14,
20,
14,
17,
12,
2695,
841,
14,
22,
14,
88,
7,
199,
199,
12711,
63,
4612,
63,
907,
275,
519,
7601,
875,
790,
628,
2100,
5564,
4537,
3989,
3353,
15603,
435,
971,
272,
283,
779,
16,
13,
25,
8194,
12,
18,
1552,
779,
33,
13,
58,
566,
779,
16,
13,
25,
11896,
1108,
875,
3524,
199,
199,
2100,
63,
4612,
63,
907,
275,
971,
272,
519,
7601,
875,
790,
628,
2100,
5564,
4537,
4267,
6437,
3353,
1743,
779,
16,
13,
25,
11896,
1108,
875,
3524,
199,
199,
318,
485,
1799,
56,
2100,
3989,
3325,
18442,
21167,
8,
1210,
63,
1246,
12,
1072,
63,
1246,
12,
1125,
63,
466,
304,
523,
16955,
63,
6865,
1533,
275,
359,
88,
367,
671,
315,
1324,
63,
1246,
14,
19256,
6201,
5535,
342,
489,
340,
671,
14,
26453,
1252,
4130,
5175,
88,
1892,
5440,
819,
8927,
63,
2253,
63,
6234,
275,
942,
523,
8927,
63,
1892,
63,
6234,
275,
942,
819,
367,
671,
1892,
315,
16955,
63,
6865,
1533,
26,
272,
340,
822,
8,
88,
1892,
14,
4665,
11383,
1012,
508,
378,
26,
489,
1980,
339,
2656,
63,
1023,
275,
488,
272,
26242,
63,
1023,
275,
488,
339,
892,
63,
4407,
275,
671,
1892,
14,
4665,
11383,
342,
272,
340,
440,
892,
63,
4407,
26,
489,
327,
15920,
1584,
365,
3544,
15701,
14,
489,
1980,
339,
367,
1004,
315,
892,
63,
4407,
26,
489,
333,
275,
295,
14,
1733,
8,
12711,
63,
4612,
63,
907,
12,
1004,
9,
489,
340,
333,
26,
267,
2656,
63,
1023,
275,
334,
77,
14,
923,
8,
17,
395,
333,
14,
923,
8,
18,
395,
333,
14,
923,
8,
19,
430,
2541,
333,
275,
295,
14,
1733,
8,
2100,
63,
4612,
63,
907,
12,
1004,
9,
489,
340,
333,
26,
267,
26242,
63,
1023,
275,
333,
14,
923,
8,
17,
9,
2541,
340,
2656,
63,
1023,
365,
440,
488,
436,
26242,
63,
1023,
365,
440,
488,
26,
267,
2059,
339,
340,
2656,
63,
1023,
365,
488,
26,
489,
8927,
63,
2253,
63,
6234,
14,
740,
8,
88,
1892,
14,
26453,
1012,
489,
1980,
272,
340,
1109,
8,
2253,
63,
1023,
59,
16,
566,
1137,
27805,
1149,
63,
36,
689,
7941,
63,
4612,
26,
489,
8927,
63,
2253,
63,
6234,
14,
740,
8,
88,
1892,
14,
26453,
1012,
489,
1980,
272,
340,
2656,
63,
1023,
59,
17,
61,
665,
15861,
27078,
63,
36,
689,
7941,
63,
19736,
26,
489,
8927,
63,
2253,
63,
6234,
14,
740,
8,
88,
1892,
14,
26453,
1012,
489,
1980,
339,
340,
26242,
63,
1023,
365,
488,
503,
1109,
8,
1892,
63,
1023,
9,
665,
15861,
27078,
63,
2100,
63,
4612,
503,
971,
2126,
1109,
8,
1892,
63,
1023,
9,
690,
9141,
27078,
63,
2100,
63,
4612,
26,
489,
8927,
63,
1892,
63,
6234,
14,
740,
8,
88,
1892,
14,
26453,
1012,
489,
1980,
819,
8826,
275,
942,
523,
340,
8927,
63,
2253,
63,
6234,
26,
272,
8826,
14,
740,
8,
705,
63,
466,
8,
267,
283,
56,
2100,
1584,
1929,
370,
506,
6290,
641,
10444,
4403,
1323,
283,
435,
869,
2639,
879,
63,
36,
689,
7941,
63,
4612,
12,
267,
2974,
29,
15448,
63,
2253,
63,
6234,
430,
523,
340,
8927,
63,
1892,
63,
6234,
26,
272,
8826,
14,
740,
8,
705,
63,
466,
8,
267,
283,
56,
2100,
1584,
1929,
370,
506,
6290,
1808,
10602,
1015,
283,
435,
869,
2639,
879,
63,
2100,
63,
4612,
12,
267,
2974,
29,
15448,
63,
1892,
63,
6234,
430,
523,
372,
8826,
199,
199,
318,
2670,
4001,
3314,
10301,
8,
1210,
63,
1246,
12,
1072,
63,
1246,
304,
523,
327,
9812,
26598,
370,
5992,
2755,
340,
314,
23895,
6918,
12,
880,
626,
8417,
523,
327,
883,
7198,
3932,
11248,
281,
503,
4573,
4954,
370,
295,
13,
2117,
314,
1323,
2100,
83,
367,
3062,
14,
523,
372,
485,
1799,
56,
2100,
3989,
3325,
18442,
21167,
8,
1210,
63,
1246,
12,
1072,
63,
1246,
12,
489,
1125,
63,
466,
29,
1199,
63,
1246,
14,
30607,
20430,
3849,
9,
199,
199,
318,
2670,
4001,
3314,
11421,
8,
1210,
63,
1246,
12,
1072,
63,
1246,
304,
523,
372,
485,
1799,
56,
2100,
3989,
3325,
18442,
21167,
8,
1210,
63,
1246,
12,
1072,
63,
1246,
12,
489,
1125,
63,
466,
29,
1199,
63,
1246,
14,
30607,
547,
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,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
SELYIO/iztlaiptv
|
servers/royalvids.py
|
42
|
2747
|
# -*- coding: iso-8859-1 -*-
#------------------------------------------------------------
# pelisalacarta - XBMC Plugin
# Conector para royalvids
# http://blog.tvalacarta.info/plugin-xbmc/pelisalacarta/
#------------------------------------------------------------
import urlparse,urllib2,urllib,re
import os
from core import scrapertools
from core import logger
from core import config
def get_video_url( page_url , premium = False , user="" , password="", video_password="" ):
logger.info("[royalvids.py] url="+page_url)
# http://www.royalvids.eu/e.php?id=4f1ce3fe5305f&width=670&height=400
page_url = 'http://www.royalvids.eu/e.php?id='+page_url+'&width=670&height=400'
# Lo pide una vez
data = scrapertools.cache_page( page_url)
# Extrae el trozo cifrado
patron ='<param name="flashvars" value="file=(.+?)&'
matches = re.compile(patron,re.DOTALL).findall(data)
#scrapertools.printMatches(matches)
data = ""
if len(matches)>0:
logger.info("[royalvids.py] flashvars=")
else:
logger.info("[royalvids.py] no encuentra flashvars=")
return []
video_urls = []
url = matches[0]+"?start=0"
video_urls.append( ["."+matches[0].rsplit('.',1)[1]+" [royalvids]",url])
for video_url in video_urls:
logger.info("[royalvids.py] %s - %s" % (video_url[0],video_url[1]))
return video_urls
# Encuentra vídeos de este servidor en el texto pasado
def find_videos(text):
encontrados = set()
devuelve = []
# http://www.peliculasaudiolatino.com/show/royalvids.php?url=4f1ce3fe5305f
patronvideos = 'royalvids\.php\?url=([A-Z0-9a-z]+)'
logger.info("[royalvids.py] find_videos #"+patronvideos+"#")
matches = re.compile(patronvideos,re.DOTALL).findall(text)
for match in matches:
titulo = "[royalvids]"
url = match
if url not in encontrados:
logger.info(" url="+url)
devuelve.append( [ titulo , url , 'royalvids' ] )
encontrados.add(url)
else:
logger.info(" url duplicada="+url)
# http://www.royalvids.eu/e.php?id=4f1ce3fe5305f&width=670&height=400
patronvideos = 'http://www.royalvids.eu/e.php\?id=([A-Z0-9a-z]+)'
logger.info("[royalvids.py] find_videos #"+patronvideos+"#")
matches = re.compile(patronvideos,re.DOTALL).findall(text)
for match in matches:
titulo = "[royalvids]"
url = "http://www.royalvids.com/"+match
if url not in encontrados:
logger.info(" url="+url)
devuelve.append( [ titulo , url , 'royalvids' ] )
encontrados.add(url)
else:
logger.info(" url duplicada="+url)
return devuelve
|
gpl-2.0
|
[
3,
1882,
2803,
26,
11601,
13,
4830,
13,
17,
1882,
199,
17807,
4559,
199,
3,
4837,
317,
6327,
645,
29549,
446,
1323,
28994,
11349,
199,
3,
445,
368,
630,
12665,
882,
31876,
86,
1580,
199,
3,
1455,
921,
11486,
14,
84,
637,
645,
29549,
14,
815,
15,
2718,
13,
21382,
15,
321,
317,
6327,
645,
29549,
15,
199,
17807,
4559,
199,
199,
646,
7097,
12,
4078,
18,
12,
4078,
12,
264,
199,
646,
747,
199,
199,
504,
6170,
492,
28348,
199,
504,
6170,
492,
2512,
199,
504,
6170,
492,
1101,
199,
199,
318,
664,
63,
3722,
63,
633,
8,
2034,
63,
633,
2360,
876,
23481,
275,
756,
2360,
922,
9287,
2360,
2505,
8772,
3991,
63,
2060,
9287,
3461,
272,
2512,
14,
815,
10994,
4813,
279,
86,
1580,
14,
647,
61,
1166,
16368,
1606,
63,
633,
9,
2286,
327,
1455,
921,
1544,
14,
4813,
279,
86,
1580,
14,
16913,
15,
69,
14,
8624,
31,
344,
29,
20,
70,
17,
301,
19,
771,
21,
11565,
70,
6,
2063,
29,
21451,
6,
3333,
29,
5303,
272,
2034,
63,
633,
275,
283,
1014,
921,
1544,
14,
4813,
279,
86,
1580,
14,
16913,
15,
69,
14,
8624,
31,
344,
22078,
1606,
63,
633,
4786,
6,
2063,
29,
21451,
6,
3333,
29,
5303,
7,
272,
327,
3835,
299,
2655,
32686,
11199,
90,
272,
666,
275,
28348,
14,
1637,
63,
1606,
8,
2034,
63,
633,
9,
1362,
339,
327,
11177,
69,
579,
22621,
18070,
286,
692,
345,
1117,
272,
272,
32500,
275,
7601,
635,
536,
628,
11331,
2936,
2,
574,
628,
493,
2687,
11198,
9,
6,
7,
272,
4450,
275,
295,
14,
2014,
8,
10853,
2641,
12,
264,
14,
16504,
680,
6452,
8,
576,
9,
272,
327,
12865,
529,
2537,
14,
1361,
12962,
8,
6742,
9,
272,
666,
275,
3087,
272,
340,
822,
8,
6742,
13032,
16,
26,
267,
2512,
14,
815,
10994,
4813,
279,
86,
1580,
14,
647,
61,
14775,
2936,
23758,
272,
587,
26,
267,
2512,
14,
815,
10994,
4813,
279,
86,
1580,
14,
647,
61,
949,
12011,
85,
484,
345,
14775,
2936,
23758,
398,
372,
942,
17635,
3991,
63,
3603,
275,
942,
2286,
1166,
275,
4450,
59,
16,
2807,
14863,
928,
29,
16,
2,
272,
3991,
63,
3603,
14,
740,
8,
359,
1674,
7709,
6742,
59,
16,
1055,
13490,
14078,
17,
2788,
17,
2807,
2,
359,
4813,
279,
86,
1580,
11472,
633,
566,
339,
367,
3991,
63,
633,
315,
3991,
63,
3603,
26,
267,
2512,
14,
815,
10994,
4813,
279,
86,
1580,
14,
647,
61,
450,
83,
446,
450,
83,
2,
450,
334,
3722,
63,
633,
59,
16,
467,
3722,
63,
633,
59,
17,
2459,
339,
372,
3991,
63,
3603,
199,
199,
3,
3447,
15140,
484,
345,
373,
13676,
18808,
477,
325,
1597,
8926,
5017,
269,
655,
579,
1318,
79,
19099,
5129,
199,
318,
2342,
63,
11418,
8,
505,
304,
272,
655,
17926,
18339,
275,
663,
342,
272,
4866,
13086,
432,
275,
942,
339,
327,
1455,
921,
1544,
14,
321,
606,
32646,
23577,
393,
292,
10175,
14,
957,
15,
2384,
15,
4813,
279,
86,
1580,
14,
8624,
31,
633,
29,
20,
70,
17,
301,
19,
771,
21,
11565,
70,
272,
32500,
11418,
221,
275,
283,
4813,
279,
86,
1580,
4537,
8624,
29635,
633,
30982,
33,
13,
58,
16,
13,
25,
65,
13,
90,
29716,
272,
2512,
14,
815,
10994,
4813,
279,
86,
1580,
14,
647,
61,
2342,
63,
11418,
327,
7709,
10853,
2641,
11418,
5207,
3,
531,
272,
4450,
275,
295,
14,
2014,
8,
10853,
2641,
11418,
12,
264,
14,
16504,
680,
6452,
8,
505,
9,
339,
367,
1336,
315,
4450,
26,
267,
3367,
10963,
320,
275,
7369,
4813,
279,
86,
1580,
8480,
267,
1166,
275,
1336,
267,
340,
1166,
440,
315,
655,
17926,
18339,
26,
288,
2512,
14,
815,
480,
221,
1166,
16368,
633,
9,
288,
4866,
13086,
432,
14,
740,
8,
359,
3367,
10963,
320,
2360,
1166,
2360,
283,
4813,
279,
86,
1580,
7,
1622,
776,
288,
655,
17926,
18339,
14,
525,
8,
633,
9,
267,
587,
26,
288,
2512,
14,
815,
480,
221,
1166,
366,
4230,
10641,
16368,
633,
9,
15567,
327,
1455,
921,
1544,
14,
4813,
279,
86,
1580,
14,
16913,
15,
69,
14,
8624,
31,
344,
29,
20,
70,
17,
301,
19,
771,
21,
11565,
70,
6,
2063,
29,
21451,
6,
3333,
29,
5303,
272,
32500,
11418,
221,
275,
283,
1014,
921,
1544,
14,
4813,
279,
86,
1580,
14,
16913,
15,
69,
14,
8624,
29635,
344,
30982,
33,
13,
58,
16,
13,
25,
65,
13,
90,
29716,
272,
2512,
14,
815,
10994,
4813,
279,
86,
1580,
14,
647,
61,
2342,
63,
11418,
327,
7709,
10853,
2641,
11418,
5207,
3,
531,
272,
4450,
275,
295,
14,
2014,
8,
10853,
2641,
11418,
12,
264,
14,
16504,
680,
6452,
8,
505,
9,
339,
367,
1336,
315,
4450,
26,
267,
3367,
10963,
320,
275,
7369,
4813,
279,
86,
1580,
8480,
267,
1166,
275,
298,
1014,
921,
1544,
14,
4813,
279,
86,
1580,
14,
957,
25976,
1431,
267,
340,
1166,
440,
315,
655,
17926,
18339,
26,
288,
2512,
14,
815,
480,
221,
1166,
16368,
633,
9,
288,
4866,
13086,
432,
14,
740,
8,
359,
3367,
10963,
320,
2360,
1166,
2360,
283,
4813,
279,
86,
1580,
7,
1622,
776,
288,
655,
17926,
18339,
14,
525,
8,
633,
9,
267,
587,
26,
288,
2512,
14,
815,
480,
221,
1166,
366,
4230,
10641,
16368,
633,
9,
339,
372,
4866,
13086,
432,
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
] |
[
1882,
2803,
26,
11601,
13,
4830,
13,
17,
1882,
199,
17807,
4559,
199,
3,
4837,
317,
6327,
645,
29549,
446,
1323,
28994,
11349,
199,
3,
445,
368,
630,
12665,
882,
31876,
86,
1580,
199,
3,
1455,
921,
11486,
14,
84,
637,
645,
29549,
14,
815,
15,
2718,
13,
21382,
15,
321,
317,
6327,
645,
29549,
15,
199,
17807,
4559,
199,
199,
646,
7097,
12,
4078,
18,
12,
4078,
12,
264,
199,
646,
747,
199,
199,
504,
6170,
492,
28348,
199,
504,
6170,
492,
2512,
199,
504,
6170,
492,
1101,
199,
199,
318,
664,
63,
3722,
63,
633,
8,
2034,
63,
633,
2360,
876,
23481,
275,
756,
2360,
922,
9287,
2360,
2505,
8772,
3991,
63,
2060,
9287,
3461,
272,
2512,
14,
815,
10994,
4813,
279,
86,
1580,
14,
647,
61,
1166,
16368,
1606,
63,
633,
9,
2286,
327,
1455,
921,
1544,
14,
4813,
279,
86,
1580,
14,
16913,
15,
69,
14,
8624,
31,
344,
29,
20,
70,
17,
301,
19,
771,
21,
11565,
70,
6,
2063,
29,
21451,
6,
3333,
29,
5303,
272,
2034,
63,
633,
275,
283,
1014,
921,
1544,
14,
4813,
279,
86,
1580,
14,
16913,
15,
69,
14,
8624,
31,
344,
22078,
1606,
63,
633,
4786,
6,
2063,
29,
21451,
6,
3333,
29,
5303,
7,
272,
327,
3835,
299,
2655,
32686,
11199,
90,
272,
666,
275,
28348,
14,
1637,
63,
1606,
8,
2034,
63,
633,
9,
1362,
339,
327,
11177,
69,
579,
22621,
18070,
286,
692,
345,
1117,
272,
272,
32500,
275,
7601,
635,
536,
628,
11331,
2936,
2,
574,
628,
493,
2687,
11198,
9,
6,
7,
272,
4450,
275,
295,
14,
2014,
8,
10853,
2641,
12,
264,
14,
16504,
680,
6452,
8,
576,
9,
272,
327,
12865,
529,
2537,
14,
1361,
12962,
8,
6742,
9,
272,
666,
275,
3087,
272,
340,
822,
8,
6742,
13032,
16,
26,
267,
2512,
14,
815,
10994,
4813,
279,
86,
1580,
14,
647,
61,
14775,
2936,
23758,
272,
587,
26,
267,
2512,
14,
815,
10994,
4813,
279,
86,
1580,
14,
647,
61,
949,
12011,
85,
484,
345,
14775,
2936,
23758,
398,
372,
942,
17635,
3991,
63,
3603,
275,
942,
2286,
1166,
275,
4450,
59,
16,
2807,
14863,
928,
29,
16,
2,
272,
3991,
63,
3603,
14,
740,
8,
359,
1674,
7709,
6742,
59,
16,
1055,
13490,
14078,
17,
2788,
17,
2807,
2,
359,
4813,
279,
86,
1580,
11472,
633,
566,
339,
367,
3991,
63,
633,
315,
3991,
63,
3603,
26,
267,
2512,
14,
815,
10994,
4813,
279,
86,
1580,
14,
647,
61,
450,
83,
446,
450,
83,
2,
450,
334,
3722,
63,
633,
59,
16,
467,
3722,
63,
633,
59,
17,
2459,
339,
372,
3991,
63,
3603,
199,
199,
3,
3447,
15140,
484,
345,
373,
13676,
18808,
477,
325,
1597,
8926,
5017,
269,
655,
579,
1318,
79,
19099,
5129,
199,
318,
2342,
63,
11418,
8,
505,
304,
272,
655,
17926,
18339,
275,
663,
342,
272,
4866,
13086,
432,
275,
942,
339,
327,
1455,
921,
1544,
14,
321,
606,
32646,
23577,
393,
292,
10175,
14,
957,
15,
2384,
15,
4813,
279,
86,
1580,
14,
8624,
31,
633,
29,
20,
70,
17,
301,
19,
771,
21,
11565,
70,
272,
32500,
11418,
221,
275,
283,
4813,
279,
86,
1580,
4537,
8624,
29635,
633,
30982,
33,
13,
58,
16,
13,
25,
65,
13,
90,
29716,
272,
2512,
14,
815,
10994,
4813,
279,
86,
1580,
14,
647,
61,
2342,
63,
11418,
327,
7709,
10853,
2641,
11418,
5207,
3,
531,
272,
4450,
275,
295,
14,
2014,
8,
10853,
2641,
11418,
12,
264,
14,
16504,
680,
6452,
8,
505,
9,
339,
367,
1336,
315,
4450,
26,
267,
3367,
10963,
320,
275,
7369,
4813,
279,
86,
1580,
8480,
267,
1166,
275,
1336,
267,
340,
1166,
440,
315,
655,
17926,
18339,
26,
288,
2512,
14,
815,
480,
221,
1166,
16368,
633,
9,
288,
4866,
13086,
432,
14,
740,
8,
359,
3367,
10963,
320,
2360,
1166,
2360,
283,
4813,
279,
86,
1580,
7,
1622,
776,
288,
655,
17926,
18339,
14,
525,
8,
633,
9,
267,
587,
26,
288,
2512,
14,
815,
480,
221,
1166,
366,
4230,
10641,
16368,
633,
9,
15567,
327,
1455,
921,
1544,
14,
4813,
279,
86,
1580,
14,
16913,
15,
69,
14,
8624,
31,
344,
29,
20,
70,
17,
301,
19,
771,
21,
11565,
70,
6,
2063,
29,
21451,
6,
3333,
29,
5303,
272,
32500,
11418,
221,
275,
283,
1014,
921,
1544,
14,
4813,
279,
86,
1580,
14,
16913,
15,
69,
14,
8624,
29635,
344,
30982,
33,
13,
58,
16,
13,
25,
65,
13,
90,
29716,
272,
2512,
14,
815,
10994,
4813,
279,
86,
1580,
14,
647,
61,
2342,
63,
11418,
327,
7709,
10853,
2641,
11418,
5207,
3,
531,
272,
4450,
275,
295,
14,
2014,
8,
10853,
2641,
11418,
12,
264,
14,
16504,
680,
6452,
8,
505,
9,
339,
367,
1336,
315,
4450,
26,
267,
3367,
10963,
320,
275,
7369,
4813,
279,
86,
1580,
8480,
267,
1166,
275,
298,
1014,
921,
1544,
14,
4813,
279,
86,
1580,
14,
957,
25976,
1431,
267,
340,
1166,
440,
315,
655,
17926,
18339,
26,
288,
2512,
14,
815,
480,
221,
1166,
16368,
633,
9,
288,
4866,
13086,
432,
14,
740,
8,
359,
3367,
10963,
320,
2360,
1166,
2360,
283,
4813,
279,
86,
1580,
7,
1622,
776,
288,
655,
17926,
18339,
14,
525,
8,
633,
9,
267,
587,
26,
288,
2512,
14,
815,
480,
221,
1166,
366,
4230,
10641,
16368,
633,
9,
339,
372,
4866,
13086,
432,
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,
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,
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
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
] |
dgladkov/django
|
tests/template_tests/syntax_tests/test_firstof.py
|
177
|
3215
|
from django.template import TemplateSyntaxError
from django.test import SimpleTestCase
from ..utils import setup
class FirstOfTagTests(SimpleTestCase):
@setup({'firstof01': '{% firstof a b c %}'})
def test_firstof01(self):
output = self.engine.render_to_string('firstof01', {'a': 0, 'c': 0, 'b': 0})
self.assertEqual(output, '')
@setup({'firstof02': '{% firstof a b c %}'})
def test_firstof02(self):
output = self.engine.render_to_string('firstof02', {'a': 1, 'c': 0, 'b': 0})
self.assertEqual(output, '1')
@setup({'firstof03': '{% firstof a b c %}'})
def test_firstof03(self):
output = self.engine.render_to_string('firstof03', {'a': 0, 'c': 0, 'b': 2})
self.assertEqual(output, '2')
@setup({'firstof04': '{% firstof a b c %}'})
def test_firstof04(self):
output = self.engine.render_to_string('firstof04', {'a': 0, 'c': 3, 'b': 0})
self.assertEqual(output, '3')
@setup({'firstof05': '{% firstof a b c %}'})
def test_firstof05(self):
output = self.engine.render_to_string('firstof05', {'a': 1, 'c': 3, 'b': 2})
self.assertEqual(output, '1')
@setup({'firstof06': '{% firstof a b c %}'})
def test_firstof06(self):
output = self.engine.render_to_string('firstof06', {'c': 3, 'b': 0})
self.assertEqual(output, '3')
@setup({'firstof07': '{% firstof a b "c" %}'})
def test_firstof07(self):
output = self.engine.render_to_string('firstof07', {'a': 0})
self.assertEqual(output, 'c')
@setup({'firstof08': '{% firstof a b "c and d" %}'})
def test_firstof08(self):
output = self.engine.render_to_string('firstof08', {'a': 0, 'b': 0})
self.assertEqual(output, 'c and d')
@setup({'firstof09': '{% firstof %}'})
def test_firstof09(self):
with self.assertRaises(TemplateSyntaxError):
self.engine.get_template('firstof09')
@setup({'firstof10': '{% firstof a %}'})
def test_firstof10(self):
output = self.engine.render_to_string('firstof10', {'a': '<'})
self.assertEqual(output, '<')
@setup({'firstof11': '{% firstof a b %}'})
def test_firstof11(self):
output = self.engine.render_to_string('firstof11', {'a': '<', 'b': '>'})
self.assertEqual(output, '<')
@setup({'firstof12': '{% firstof a b %}'})
def test_firstof12(self):
output = self.engine.render_to_string('firstof12', {'a': '', 'b': '>'})
self.assertEqual(output, '>')
@setup({'firstof13': '{% autoescape off %}{% firstof a %}{% endautoescape %}'})
def test_firstof13(self):
output = self.engine.render_to_string('firstof13', {'a': '<'})
self.assertEqual(output, '<')
@setup({'firstof14': '{% firstof a|safe b %}'})
def test_firstof14(self):
output = self.engine.render_to_string('firstof14', {'a': '<'})
self.assertEqual(output, '<')
@setup({'firstof15': '{% firstof a b c as myvar %}'})
def test_firstof15(self):
ctx = {'a': 0, 'b': 2, 'c': 3}
output = self.engine.render_to_string('firstof15', ctx)
self.assertEqual(ctx['myvar'], '2')
self.assertEqual(output, '')
|
bsd-3-clause
|
[
504,
1639,
14,
1160,
492,
17762,
199,
504,
1639,
14,
396,
492,
24424,
199,
199,
504,
2508,
1208,
492,
3272,
421,
199,
533,
7758,
3466,
1931,
2925,
8,
17968,
304,
339,
768,
2758,
3252,
2246,
1618,
614,
356,
12100,
1642,
1618,
282,
330,
286,
17776,
272,
347,
511,
63,
2246,
1618,
614,
8,
277,
304,
267,
1072,
275,
291,
14,
3908,
14,
3352,
63,
475,
63,
875,
360,
2246,
1618,
614,
297,
791,
65,
356,
378,
12,
283,
67,
356,
378,
12,
283,
66,
356,
378,
1552,
267,
291,
14,
629,
8,
1199,
12,
4074,
339,
768,
2758,
3252,
2246,
1618,
996,
356,
12100,
1642,
1618,
282,
330,
286,
17776,
272,
347,
511,
63,
2246,
1618,
996,
8,
277,
304,
267,
1072,
275,
291,
14,
3908,
14,
3352,
63,
475,
63,
875,
360,
2246,
1618,
996,
297,
791,
65,
356,
413,
12,
283,
67,
356,
378,
12,
283,
66,
356,
378,
1552,
267,
291,
14,
629,
8,
1199,
12,
283,
17,
358,
339,
768,
2758,
3252,
2246,
1618,
1644,
356,
12100,
1642,
1618,
282,
330,
286,
17776,
272,
347,
511,
63,
2246,
1618,
1644,
8,
277,
304,
267,
1072,
275,
291,
14,
3908,
14,
3352,
63,
475,
63,
875,
360,
2246,
1618,
1644,
297,
791,
65,
356,
378,
12,
283,
67,
356,
378,
12,
283,
66,
356,
499,
1552,
267,
291,
14,
629,
8,
1199,
12,
283,
18,
358,
339,
768,
2758,
3252,
2246,
1618,
966,
356,
12100,
1642,
1618,
282,
330,
286,
17776,
272,
347,
511,
63,
2246,
1618,
966,
8,
277,
304,
267,
1072,
275,
291,
14,
3908,
14,
3352,
63,
475,
63,
875,
360,
2246,
1618,
966,
297,
791,
65,
356,
378,
12,
283,
67,
356,
650,
12,
283,
66,
356,
378,
1552,
267,
291,
14,
629,
8,
1199,
12,
283,
19,
358,
339,
768,
2758,
3252,
2246,
1618,
1717,
356,
12100,
1642,
1618,
282,
330,
286,
17776,
272,
347,
511,
63,
2246,
1618,
1717,
8,
277,
304,
267,
1072,
275,
291,
14,
3908,
14,
3352,
63,
475,
63,
875,
360,
2246,
1618,
1717,
297,
791,
65,
356,
413,
12,
283,
67,
356,
650,
12,
283,
66,
356,
499,
1552,
267,
291,
14,
629,
8,
1199,
12,
283,
17,
358,
339,
768,
2758,
3252,
2246,
1618,
1690,
356,
12100,
1642,
1618,
282,
330,
286,
17776,
272,
347,
511,
63,
2246,
1618,
1690,
8,
277,
304,
267,
1072,
275,
291,
14,
3908,
14,
3352,
63,
475,
63,
875,
360,
2246,
1618,
1690,
297,
791,
67,
356,
650,
12,
283,
66,
356,
378,
1552,
267,
291,
14,
629,
8,
1199,
12,
283,
19,
358,
339,
768,
2758,
3252,
2246,
1618,
1780,
356,
12100,
1642,
1618,
282,
330,
298,
67,
2,
17776,
272,
347,
511,
63,
2246,
1618,
1780,
8,
277,
304,
267,
1072,
275,
291,
14,
3908,
14,
3352,
63,
475,
63,
875,
360,
2246,
1618,
1780,
297,
791,
65,
356,
378,
1552,
267,
291,
14,
629,
8,
1199,
12,
283,
67,
358,
339,
768,
2758,
3252,
2246,
1618,
2036,
356,
12100,
1642,
1618,
282,
330,
298,
67,
436,
366,
2,
17776,
272,
347,
511,
63,
2246,
1618,
2036,
8,
277,
304,
267,
1072,
275,
291,
14,
3908,
14,
3352,
63,
475,
63,
875,
360,
2246,
1618,
2036,
297,
791,
65,
356,
378,
12,
283,
66,
356,
378,
1552,
267,
291,
14,
629,
8,
1199,
12,
283,
67,
436,
366,
358,
339,
768,
2758,
3252,
2246,
1618,
1643,
356,
12100,
1642,
1618,
17776,
272,
347,
511,
63,
2246,
1618,
1643,
8,
277,
304,
267,
543,
291,
14,
1855,
8,
20837,
304,
288,
291,
14,
3908,
14,
362,
63,
1160,
360,
2246,
1618,
1643,
358,
339,
768,
2758,
3252,
2246,
1618,
709,
356,
12100,
1642,
1618,
282,
17776,
272,
347,
511,
63,
2246,
1618,
709,
8,
277,
304,
267,
1072,
275,
291,
14,
3908,
14,
3352,
63,
475,
63,
875,
360,
2246,
1618,
709,
297,
791,
65,
356,
2650,
3071,
267,
291,
14,
629,
8,
1199,
12,
7673,
4116,
10784,
339,
768,
2758,
3252,
2246,
1618,
845,
356,
12100,
1642,
1618,
282,
330,
17776,
272,
347,
511,
63,
2246,
1618,
845,
8,
277,
304,
267,
1072,
275,
291,
14,
3908,
14,
3352,
63,
475,
63,
875,
360,
2246,
1618,
845,
297,
791,
65,
356,
30243,
283,
66,
356,
12696,
3071,
267,
291,
14,
629,
8,
1199,
12,
7673,
4116,
10784,
339,
768,
2758,
3252,
2246,
1618,
713,
356,
12100,
1642,
1618,
282,
330,
17776,
272,
347,
511,
63,
2246,
1618,
713,
8,
277,
304,
267,
1072,
275,
291,
14,
3908,
14,
3352,
63,
475,
63,
875,
360,
2246,
1618,
713,
297,
791,
65,
356,
3260,
283,
66,
356,
12696,
3071,
267,
291,
14,
629,
8,
1199,
12,
7673,
3308,
10784,
339,
768,
2758,
3252,
2246,
1618,
969,
356,
12100,
19102,
2331,
12760,
1642,
1618,
282,
12760,
1284,
15818,
17776,
272,
347,
511,
63,
2246,
1618,
969,
8,
277,
304,
267,
1072,
275,
291,
14,
3908,
14,
3352,
63,
475,
63,
875,
360,
2246,
1618,
969,
297,
791,
65,
356,
2650,
3071,
267,
291,
14,
629,
8,
1199,
12,
2650,
358,
339,
768,
2758,
3252,
2246,
1618,
1079,
356,
12100,
1642,
1618,
282,
92,
3489,
330,
17776,
272,
347,
511,
63,
2246,
1618,
1079,
8,
277,
304,
267,
1072,
275,
291,
14,
3908,
14,
3352,
63,
475,
63,
875,
360,
2246,
1618,
1079,
297,
791,
65,
356,
2650,
3071,
267,
291,
14,
629,
8,
1199,
12,
2650,
358,
339,
768,
2758,
3252,
2246,
1618,
1046,
356,
12100,
1642,
1618,
282,
330,
286,
465,
3002,
1391,
17776,
272,
347,
511,
63,
2246,
1618,
1046,
8,
277,
304,
267,
4027,
275,
791,
65,
356,
378,
12,
283,
66,
356,
499,
12,
283,
67,
356,
650,
93,
267,
1072,
275,
291,
14,
3908,
14,
3352,
63,
475,
63,
875,
360,
2246,
1618,
1046,
297,
4027,
9,
267,
291,
14,
629,
8,
3799,
459,
1662,
1391,
995,
283,
18,
358,
267,
291,
14,
629,
8,
1199,
12,
4074,
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
] |
[
1639,
14,
1160,
492,
17762,
199,
504,
1639,
14,
396,
492,
24424,
199,
199,
504,
2508,
1208,
492,
3272,
421,
199,
533,
7758,
3466,
1931,
2925,
8,
17968,
304,
339,
768,
2758,
3252,
2246,
1618,
614,
356,
12100,
1642,
1618,
282,
330,
286,
17776,
272,
347,
511,
63,
2246,
1618,
614,
8,
277,
304,
267,
1072,
275,
291,
14,
3908,
14,
3352,
63,
475,
63,
875,
360,
2246,
1618,
614,
297,
791,
65,
356,
378,
12,
283,
67,
356,
378,
12,
283,
66,
356,
378,
1552,
267,
291,
14,
629,
8,
1199,
12,
4074,
339,
768,
2758,
3252,
2246,
1618,
996,
356,
12100,
1642,
1618,
282,
330,
286,
17776,
272,
347,
511,
63,
2246,
1618,
996,
8,
277,
304,
267,
1072,
275,
291,
14,
3908,
14,
3352,
63,
475,
63,
875,
360,
2246,
1618,
996,
297,
791,
65,
356,
413,
12,
283,
67,
356,
378,
12,
283,
66,
356,
378,
1552,
267,
291,
14,
629,
8,
1199,
12,
283,
17,
358,
339,
768,
2758,
3252,
2246,
1618,
1644,
356,
12100,
1642,
1618,
282,
330,
286,
17776,
272,
347,
511,
63,
2246,
1618,
1644,
8,
277,
304,
267,
1072,
275,
291,
14,
3908,
14,
3352,
63,
475,
63,
875,
360,
2246,
1618,
1644,
297,
791,
65,
356,
378,
12,
283,
67,
356,
378,
12,
283,
66,
356,
499,
1552,
267,
291,
14,
629,
8,
1199,
12,
283,
18,
358,
339,
768,
2758,
3252,
2246,
1618,
966,
356,
12100,
1642,
1618,
282,
330,
286,
17776,
272,
347,
511,
63,
2246,
1618,
966,
8,
277,
304,
267,
1072,
275,
291,
14,
3908,
14,
3352,
63,
475,
63,
875,
360,
2246,
1618,
966,
297,
791,
65,
356,
378,
12,
283,
67,
356,
650,
12,
283,
66,
356,
378,
1552,
267,
291,
14,
629,
8,
1199,
12,
283,
19,
358,
339,
768,
2758,
3252,
2246,
1618,
1717,
356,
12100,
1642,
1618,
282,
330,
286,
17776,
272,
347,
511,
63,
2246,
1618,
1717,
8,
277,
304,
267,
1072,
275,
291,
14,
3908,
14,
3352,
63,
475,
63,
875,
360,
2246,
1618,
1717,
297,
791,
65,
356,
413,
12,
283,
67,
356,
650,
12,
283,
66,
356,
499,
1552,
267,
291,
14,
629,
8,
1199,
12,
283,
17,
358,
339,
768,
2758,
3252,
2246,
1618,
1690,
356,
12100,
1642,
1618,
282,
330,
286,
17776,
272,
347,
511,
63,
2246,
1618,
1690,
8,
277,
304,
267,
1072,
275,
291,
14,
3908,
14,
3352,
63,
475,
63,
875,
360,
2246,
1618,
1690,
297,
791,
67,
356,
650,
12,
283,
66,
356,
378,
1552,
267,
291,
14,
629,
8,
1199,
12,
283,
19,
358,
339,
768,
2758,
3252,
2246,
1618,
1780,
356,
12100,
1642,
1618,
282,
330,
298,
67,
2,
17776,
272,
347,
511,
63,
2246,
1618,
1780,
8,
277,
304,
267,
1072,
275,
291,
14,
3908,
14,
3352,
63,
475,
63,
875,
360,
2246,
1618,
1780,
297,
791,
65,
356,
378,
1552,
267,
291,
14,
629,
8,
1199,
12,
283,
67,
358,
339,
768,
2758,
3252,
2246,
1618,
2036,
356,
12100,
1642,
1618,
282,
330,
298,
67,
436,
366,
2,
17776,
272,
347,
511,
63,
2246,
1618,
2036,
8,
277,
304,
267,
1072,
275,
291,
14,
3908,
14,
3352,
63,
475,
63,
875,
360,
2246,
1618,
2036,
297,
791,
65,
356,
378,
12,
283,
66,
356,
378,
1552,
267,
291,
14,
629,
8,
1199,
12,
283,
67,
436,
366,
358,
339,
768,
2758,
3252,
2246,
1618,
1643,
356,
12100,
1642,
1618,
17776,
272,
347,
511,
63,
2246,
1618,
1643,
8,
277,
304,
267,
543,
291,
14,
1855,
8,
20837,
304,
288,
291,
14,
3908,
14,
362,
63,
1160,
360,
2246,
1618,
1643,
358,
339,
768,
2758,
3252,
2246,
1618,
709,
356,
12100,
1642,
1618,
282,
17776,
272,
347,
511,
63,
2246,
1618,
709,
8,
277,
304,
267,
1072,
275,
291,
14,
3908,
14,
3352,
63,
475,
63,
875,
360,
2246,
1618,
709,
297,
791,
65,
356,
2650,
3071,
267,
291,
14,
629,
8,
1199,
12,
7673,
4116,
10784,
339,
768,
2758,
3252,
2246,
1618,
845,
356,
12100,
1642,
1618,
282,
330,
17776,
272,
347,
511,
63,
2246,
1618,
845,
8,
277,
304,
267,
1072,
275,
291,
14,
3908,
14,
3352,
63,
475,
63,
875,
360,
2246,
1618,
845,
297,
791,
65,
356,
30243,
283,
66,
356,
12696,
3071,
267,
291,
14,
629,
8,
1199,
12,
7673,
4116,
10784,
339,
768,
2758,
3252,
2246,
1618,
713,
356,
12100,
1642,
1618,
282,
330,
17776,
272,
347,
511,
63,
2246,
1618,
713,
8,
277,
304,
267,
1072,
275,
291,
14,
3908,
14,
3352,
63,
475,
63,
875,
360,
2246,
1618,
713,
297,
791,
65,
356,
3260,
283,
66,
356,
12696,
3071,
267,
291,
14,
629,
8,
1199,
12,
7673,
3308,
10784,
339,
768,
2758,
3252,
2246,
1618,
969,
356,
12100,
19102,
2331,
12760,
1642,
1618,
282,
12760,
1284,
15818,
17776,
272,
347,
511,
63,
2246,
1618,
969,
8,
277,
304,
267,
1072,
275,
291,
14,
3908,
14,
3352,
63,
475,
63,
875,
360,
2246,
1618,
969,
297,
791,
65,
356,
2650,
3071,
267,
291,
14,
629,
8,
1199,
12,
2650,
358,
339,
768,
2758,
3252,
2246,
1618,
1079,
356,
12100,
1642,
1618,
282,
92,
3489,
330,
17776,
272,
347,
511,
63,
2246,
1618,
1079,
8,
277,
304,
267,
1072,
275,
291,
14,
3908,
14,
3352,
63,
475,
63,
875,
360,
2246,
1618,
1079,
297,
791,
65,
356,
2650,
3071,
267,
291,
14,
629,
8,
1199,
12,
2650,
358,
339,
768,
2758,
3252,
2246,
1618,
1046,
356,
12100,
1642,
1618,
282,
330,
286,
465,
3002,
1391,
17776,
272,
347,
511,
63,
2246,
1618,
1046,
8,
277,
304,
267,
4027,
275,
791,
65,
356,
378,
12,
283,
66,
356,
499,
12,
283,
67,
356,
650,
93,
267,
1072,
275,
291,
14,
3908,
14,
3352,
63,
475,
63,
875,
360,
2246,
1618,
1046,
297,
4027,
9,
267,
291,
14,
629,
8,
3799,
459,
1662,
1391,
995,
283,
18,
358,
267,
291,
14,
629,
8,
1199,
12,
4074,
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,
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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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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
markflyhigh/incubator-beam
|
sdks/python/apache_beam/io/source_test_utils.py
|
1
|
26317
|
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""Helper functions and test harnesses for source implementations.
This module contains helper functions and test harnesses for checking
correctness of source (a subclass of ``iobase.BoundedSource``) and range
tracker (a subclass of``iobase.RangeTracker``) implementations.
Contains a few lightweight utilities (e.g. reading items from a source such as
``readFromSource()``, as well as heavyweight property testing and stress
testing harnesses that help getting a large amount of test coverage with few
code.
Most notable ones are:
* ``assertSourcesEqualReferenceSource()`` helps testing that the data read by
the union of sources produced by ``BoundedSource.split()`` is the same as data
read by the original source.
* If your source implements dynamic work rebalancing, use the
``assertSplitAtFraction()`` family of functions - they test behavior of
``RangeTracker.try_split()``, in particular, that various consistency
properties are respected and the total set of data read by the source is
preserved when splits happen. Use ``assertSplitAtFractionBehavior()`` to test
individual cases of ``RangeTracker.try_split()`` and use
``assertSplitAtFractionExhaustive()`` as a heavy-weight stress test including
concurrency. We strongly recommend to use both.
For example usages, see the unit tests of modules such as
* apache_beam.io.source_test_utils_test.py
* apache_beam.io.avroio_test.py
"""
from __future__ import absolute_import
from __future__ import division
import logging
import threading
import weakref
from builtins import next
from builtins import object
from builtins import range
from collections import namedtuple
from multiprocessing.pool import ThreadPool
from apache_beam.io import iobase
from apache_beam.testing.util import equal_to
__all__ = ['read_from_source',
'assert_sources_equal_reference_source',
'assert_reentrant_reads_succeed',
'assert_split_at_fraction_behavior',
'assert_split_at_fraction_binary',
'assert_split_at_fraction_exhaustive',
'assert_split_at_fraction_fails',
'assert_split_at_fraction_succeeds_and_consistent']
class ExpectedSplitOutcome(object):
MUST_SUCCEED_AND_BE_CONSISTENT = 1
MUST_FAIL = 2
MUST_BE_CONSISTENT_IF_SUCCEEDS = 3
SplitAtFractionResult = namedtuple(
'SplitAtFractionResult', 'num_primary_items num_residual_items')
SplitFractionStatistics = namedtuple(
'SplitFractionStatistics',
'successful_fractions non_trivial_fractions')
def read_from_source(source, start_position=None, stop_position=None):
"""Reads elements from the given ```BoundedSource```.
Only reads elements within the given position range.
Args:
source (~apache_beam.io.iobase.BoundedSource):
:class:`~apache_beam.io.iobase.BoundedSource` implementation.
start_position (int): start position for reading.
stop_position (int): stop position for reading.
Returns:
List[str]: the set of values read from the sources.
"""
values = []
range_tracker = source.get_range_tracker(start_position, stop_position)
assert isinstance(range_tracker, iobase.RangeTracker)
reader = source.read(range_tracker)
for value in reader:
values.append(value)
return values
def _ThreadPool(threads):
# ThreadPool crashes in old versions of Python (< 2.7.5) if created from a
# child thread. (http://bugs.python.org/issue10015)
if not hasattr(threading.current_thread(), '_children'):
threading.current_thread()._children = weakref.WeakKeyDictionary()
return ThreadPool(threads)
def assert_sources_equal_reference_source(reference_source_info, sources_info):
"""Tests if a reference source is equal to a given set of sources.
Given a reference source (a :class:`~apache_beam.io.iobase.BoundedSource`
and a position range) and a list of sources, assert that the union of the
records read from the list of sources is equal to the records read from the
reference source.
Args:
reference_source_info\
(Tuple[~apache_beam.io.iobase.BoundedSource, int, int]):
a three-tuple that gives the reference
:class:`~apache_beam.io.iobase.BoundedSource`, position to start
reading at, and position to stop reading at.
sources_info\
(Iterable[Tuple[~apache_beam.io.iobase.BoundedSource, int, int]]):
a set of sources. Each source is a three-tuple that is of the same
format described above.
Raises:
~exceptions.ValueError: if the set of data produced by the reference source
and the given set of sources are not equivalent.
"""
if not (isinstance(reference_source_info, tuple) and
len(reference_source_info) == 3 and
isinstance(reference_source_info[0], iobase.BoundedSource)):
raise ValueError('reference_source_info must a three-tuple where first'
'item of the tuple gives a '
'iobase.BoundedSource. Received: %r'
% reference_source_info)
reference_records = read_from_source(
*reference_source_info)
source_records = []
for source_info in sources_info:
assert isinstance(source_info, tuple)
assert len(source_info) == 3
if not (isinstance(source_info, tuple) and
len(source_info) == 3 and
isinstance(source_info[0], iobase.BoundedSource)):
raise ValueError('source_info must a three tuple where first'
'item of the tuple gives a '
'iobase.BoundedSource. Received: %r'
% source_info)
if (type(reference_source_info[0].default_output_coder()) !=
type(source_info[0].default_output_coder())):
raise ValueError(
'Reference source %r and the source %r must use the same coder. '
'They are using %r and %r respectively instead.'
% (reference_source_info[0], source_info[0],
type(reference_source_info[0].default_output_coder()),
type(source_info[0].default_output_coder())))
source_records.extend(read_from_source(*source_info))
if len(reference_records) != len(source_records):
raise ValueError(
'Reference source must produce the same number of records as the '
'list of sources. Number of records were %d and %d instead.'
% (len(reference_records), len(source_records)))
if equal_to(reference_records)(source_records):
raise ValueError(
'Reference source and provided list of sources must produce the '
'same set of records.')
def assert_reentrant_reads_succeed(source_info):
"""Tests if a given source can be read in a reentrant manner.
Assume that given source produces the set of values ``{v1, v2, v3, ... vn}``.
For ``i`` in range ``[1, n-1]`` this method performs a reentrant read after
reading ``i`` elements and verifies that both the original and reentrant read
produce the expected set of values.
Args:
source_info (Tuple[~apache_beam.io.iobase.BoundedSource, int, int]):
a three-tuple that gives the reference
:class:`~apache_beam.io.iobase.BoundedSource`, position to start reading
at, and a position to stop reading at.
Raises:
~exceptions.ValueError: if source is too trivial or reentrant read result
in an incorrect read.
"""
source, start_position, stop_position = source_info
assert isinstance(source, iobase.BoundedSource)
expected_values = [val for val in source.read(source.get_range_tracker(
start_position, stop_position))]
if len(expected_values) < 2:
raise ValueError('Source is too trivial since it produces only %d '
'values. Please give a source that reads at least 2 '
'values.' % len(expected_values))
for i in range(1, len(expected_values) - 1):
read_iter = source.read(source.get_range_tracker(
start_position, stop_position))
original_read = []
for _ in range(i):
original_read.append(next(read_iter))
# Reentrant read
reentrant_read = [val for val in source.read(
source.get_range_tracker(start_position, stop_position))]
# Continuing original read.
for val in read_iter:
original_read.append(val)
if equal_to(original_read)(expected_values):
raise ValueError('Source did not produce expected values when '
'performing a reentrant read after reading %d values. '
'Expected %r received %r.'
% (i, expected_values, original_read))
if equal_to(reentrant_read)(expected_values):
raise ValueError('A reentrant read of source after reading %d values '
'did not produce expected values. Expected %r '
'received %r.'
% (i, expected_values, reentrant_read))
def assert_split_at_fraction_behavior(source, num_items_to_read_before_split,
split_fraction, expected_outcome):
"""Verifies the behaviour of splitting a source at a given fraction.
Asserts that splitting a :class:`~apache_beam.io.iobase.BoundedSource` either
fails after reading **num_items_to_read_before_split** items, or succeeds in
a way that is consistent according to
:func:`assert_split_at_fraction_succeeds_and_consistent()`.
Args:
source (~apache_beam.io.iobase.BoundedSource): the source to perform
dynamic splitting on.
num_items_to_read_before_split (int): number of items to read before
splitting.
split_fraction (float): fraction to split at.
expected_outcome (int): a value from
:class:`~apache_beam.io.source_test_utils.ExpectedSplitOutcome`.
Returns:
Tuple[int, int]: a tuple that gives the number of items produced by reading
the two ranges produced after dynamic splitting. If splitting did not
occur, the first value of the tuple will represent the full set of records
read by the source while the second value of the tuple will be ``-1``.
"""
assert isinstance(source, iobase.BoundedSource)
expected_items = read_from_source(source, None, None)
return _assert_split_at_fraction_behavior(
source, expected_items, num_items_to_read_before_split, split_fraction,
expected_outcome)
def _assert_split_at_fraction_behavior(
source, expected_items, num_items_to_read_before_split,
split_fraction, expected_outcome, start_position=None, stop_position=None):
range_tracker = source.get_range_tracker(start_position, stop_position)
assert isinstance(range_tracker, iobase.RangeTracker)
current_items = []
reader = source.read(range_tracker)
# Reading 'num_items_to_read_before_split' items.
reader_iter = iter(reader)
for _ in range(num_items_to_read_before_split):
current_items.append(next(reader_iter))
suggested_split_position = range_tracker.position_at_fraction(
split_fraction)
stop_position_before_split = range_tracker.stop_position()
split_result = range_tracker.try_split(suggested_split_position)
if split_result is not None:
if len(split_result) != 2:
raise ValueError('Split result must be a tuple that contains split '
'position and split fraction. Received: %r' %
(split_result,))
if range_tracker.stop_position() != split_result[0]:
raise ValueError('After a successful split, the stop position of the '
'RangeTracker must be the same as the returned split '
'position. Observed %r and %r which are different.'
% (range_tracker.stop_position() % (split_result[0],)))
if split_fraction < 0 or split_fraction > 1:
raise ValueError('Split fraction must be within the range [0,1]',
'Observed split fraction was %r.' % (split_result[1],))
stop_position_after_split = range_tracker.stop_position()
if split_result and stop_position_after_split == stop_position_before_split:
raise ValueError('Stop position %r did not change after a successful '
'split of source %r at fraction %r.' %
(stop_position_before_split, source, split_fraction))
if expected_outcome == ExpectedSplitOutcome.MUST_SUCCEED_AND_BE_CONSISTENT:
if not split_result:
raise ValueError('Expected split of source %r at fraction %r to be '
'successful after reading %d elements. But '
'the split failed.' %
(source, split_fraction, num_items_to_read_before_split))
elif expected_outcome == ExpectedSplitOutcome.MUST_FAIL:
if split_result:
raise ValueError('Expected split of source %r at fraction %r after '
'reading %d elements to fail. But splitting '
'succeeded with result %r.' %
(source, split_fraction, num_items_to_read_before_split,
split_result))
elif (expected_outcome !=
ExpectedSplitOutcome.MUST_BE_CONSISTENT_IF_SUCCEEDS):
raise ValueError('Unknown type of expected outcome: %r' %
expected_outcome)
current_items.extend([value for value in reader_iter])
residual_range = (
split_result[0], stop_position_before_split) if split_result else None
return _verify_single_split_fraction_result(
source, expected_items, current_items,
split_result,
(range_tracker.start_position(), range_tracker.stop_position()),
residual_range, split_fraction)
def _range_to_str(start, stop):
return '[' + (str(start) + ',' + str(stop) + ')')
def _verify_single_split_fraction_result(
source, expected_items, current_items, split_successful, primary_range,
residual_range, split_fraction):
assert primary_range
primary_items = read_from_source(source, *primary_range)
if not split_successful:
# For unsuccessful splits, residual_range should be None.
assert not residual_range
residual_items = (
read_from_source(source, *residual_range)
if split_successful else [])
total_items = primary_items + residual_items
if current_items != primary_items:
raise ValueError('Current source %r and a source created using the '
'range of the primary source %r determined '
'by performing dynamic work rebalancing at fraction '
'%r produced different values. Expected '
'these sources to produce the same list of values.'
% (source,
_range_to_str(*primary_range),
split_fraction)
)
if expected_items != total_items:
raise ValueError('Items obtained by reading the source %r for primary '
'and residual ranges %s and %s did not produce the '
'expected list of values.'
% (source,
_range_to_str(*primary_range),
_range_to_str(*residual_range)))
result = (len(primary_items),
len(residual_items) if split_successful else -1)
return result
def assert_split_at_fraction_succeeds_and_consistent(
source, num_items_to_read_before_split, split_fraction):
"""Verifies some consistency properties of dynamic work rebalancing.
Equivalent to the following pseudocode:::
original_range_tracker = source.getRangeTracker(None, None)
original_reader = source.read(original_range_tracker)
items_before_split = read N items from original_reader
suggested_split_position = original_range_tracker.position_for_fraction(
split_fraction)
original_stop_position - original_range_tracker.stop_position()
split_result = range_tracker.try_split()
split_position, split_fraction = split_result
primary_range_tracker = source.get_range_tracker(
original_range_tracker.start_position(), split_position)
residual_range_tracker = source.get_range_tracker(split_position,
original_stop_position)
assert that: items when reading source.read(primary_range_tracker) ==
items_before_split + items from continuing to read 'original_reader'
assert that: items when reading source.read(original_range_tracker) =
items when reading source.read(primary_range_tracker) + items when reading
source.read(residual_range_tracker)
Args:
source: source to perform dynamic work rebalancing on.
num_items_to_read_before_split: number of items to read before splitting.
split_fraction: fraction to split at.
"""
assert_split_at_fraction_behavior(
source, num_items_to_read_before_split, split_fraction,
ExpectedSplitOutcome.MUST_SUCCEED_AND_BE_CONSISTENT)
def assert_split_at_fraction_fails(source, num_items_to_read_before_split,
split_fraction):
"""Asserts that dynamic work rebalancing at a given fraction fails.
Asserts that trying to perform dynamic splitting after reading
'num_items_to_read_before_split' items from the source fails.
Args:
source: source to perform dynamic splitting on.
num_items_to_read_before_split: number of items to read before splitting.
split_fraction: fraction to split at.
"""
assert_split_at_fraction_behavior(
source, num_items_to_read_before_split, split_fraction,
ExpectedSplitOutcome.MUST_FAIL)
def assert_split_at_fraction_binary(
source, expected_items, num_items_to_read_before_split, left_fraction,
left_result, right_fraction, right_result, stats, start_position=None,
stop_position=None):
"""Performs dynamic work rebalancing for fractions within a given range.
Asserts that given a start position, a source can be split at every
interesting fraction (halfway between two fractions that differ by at
least one item) and the results are consistent if a split succeeds.
Args:
source: source to perform dynamic splitting on.
expected_items: total set of items expected when reading the source.
num_items_to_read_before_split: number of items to read before splitting.
left_fraction: left fraction for binary splitting.
left_result: result received by splitting at left fraction.
right_fraction: right fraction for binary splitting.
right_result: result received by splitting at right fraction.
stats: a ``SplitFractionStatistics`` for storing results.
"""
assert right_fraction > left_fraction
if right_fraction - left_fraction < 0.001:
# This prevents infinite recursion.
return
middle_fraction = (left_fraction + right_fraction) / 2
if left_result is None:
left_result = _assert_split_at_fraction_behavior(
source, expected_items, num_items_to_read_before_split, left_fraction,
ExpectedSplitOutcome.MUST_BE_CONSISTENT_IF_SUCCEEDS)
if right_result is None:
right_result = _assert_split_at_fraction_behavior(
source, expected_items, num_items_to_read_before_split,
right_fraction, ExpectedSplitOutcome.MUST_BE_CONSISTENT_IF_SUCCEEDS)
middle_result = _assert_split_at_fraction_behavior(
source, expected_items, num_items_to_read_before_split, middle_fraction,
ExpectedSplitOutcome.MUST_BE_CONSISTENT_IF_SUCCEEDS)
if middle_result[1] != -1:
stats.successful_fractions.append(middle_fraction)
if middle_result[1] > 0:
stats.non_trivial_fractions.append(middle_fraction)
# Two split results are equivalent if primary and residual ranges of them
# produce the same number of records (simply checking the size of primary
# enough since the total number of records is constant).
if left_result[0] != middle_result[0]:
assert_split_at_fraction_binary(
source, expected_items, num_items_to_read_before_split, left_fraction,
left_result, middle_fraction, middle_result, stats)
# We special case right_fraction=1.0 since that could fail due to being out
# of range. (even if a dynamic split fails at 'middle_fraction' and at
# fraction 1.0, there might be fractions in range ('middle_fraction', 1.0)
# where dynamic splitting succeeds).
if right_fraction == 1.0 or middle_result[0] != right_result[0]:
assert_split_at_fraction_binary(
source, expected_items, num_items_to_read_before_split,
middle_fraction, middle_result, right_fraction, right_result, stats)
MAX_CONCURRENT_SPLITTING_TRIALS_PER_ITEM = 100
MAX_CONCURRENT_SPLITTING_TRIALS_TOTAL = 1000
def assert_split_at_fraction_exhaustive(
source, start_position=None, stop_position=None,
perform_multi_threaded_test=True):
"""Performs and tests dynamic work rebalancing exhaustively.
Asserts that for each possible start position, a source can be split at
every interesting fraction (halfway between two fractions that differ by at
least one item) and the results are consistent if a split succeeds.
Verifies multi threaded splitting as well.
Args:
source (~apache_beam.io.iobase.BoundedSource): the source to perform
dynamic splitting on.
perform_multi_threaded_test (bool): if :data:`True` performs a
multi-threaded test, otherwise this test is skipped.
Raises:
~exceptions.ValueError: if the exhaustive splitting test fails.
"""
expected_items = read_from_source(source, start_position, stop_position)
if not expected_items:
raise ValueError('Source %r is empty.' % source)
if len(expected_items) == 1:
raise ValueError('Source %r only reads a single item.' % source)
all_non_trivial_fractions = []
any_successful_fractions = False
any_non_trivial_fractions = False
for i in range(len(expected_items)):
stats = SplitFractionStatistics([], [])
assert_split_at_fraction_binary(
source, expected_items, i, 0.0, None, 1.0, None, stats)
if stats.successful_fractions:
any_successful_fractions = True
if stats.non_trivial_fractions:
any_non_trivial_fractions = True
all_non_trivial_fractions.append(stats.non_trivial_fractions)
if not any_successful_fractions:
raise ValueError('SplitAtFraction test completed vacuously: no '
'successful split fractions found')
if not any_non_trivial_fractions:
raise ValueError(
'SplitAtFraction test completed vacuously: no non-trivial split '
'fractions found')
if not perform_multi_threaded_test:
return
num_total_trials = 0
for i in range(len(expected_items)):
non_trivial_fractions = [2.0] # 2.0 is larger than any valid fraction.
non_trivial_fractions.extend(all_non_trivial_fractions[i])
min_non_trivial_fraction = min(non_trivial_fractions)
if min_non_trivial_fraction == 2.0:
# This will not happen all the time. Otherwise previous test will fail
# due to vacuousness.
continue
num_trials = 0
have_success = False
have_failure = False
thread_pool = _ThreadPool(2)
try:
while True:
num_trials += 1
if (num_trials >
MAX_CONCURRENT_SPLITTING_TRIALS_PER_ITEM):
logging.warn(
'After %d concurrent splitting trials at item #%d, observed '
'only %s, giving up on this item',
num_trials,
i,
'success' if have_success else 'failure'
)
break
if _assert_split_at_fraction_concurrent(
source, expected_items, i, min_non_trivial_fraction, thread_pool):
have_success = True
else:
have_failure = True
if have_success and have_failure:
logging.info('%d trials to observe both success and failure of '
'concurrent splitting at item #%d', num_trials, i)
break
finally:
thread_pool.close()
num_total_trials += num_trials
if num_total_trials > MAX_CONCURRENT_SPLITTING_TRIALS_TOTAL:
logging.warn('After %d total concurrent splitting trials, considered '
'only %d items, giving up.', num_total_trials, i)
break
logging.info('%d total concurrent splitting trials for %d items',
num_total_trials, len(expected_items))
def _assert_split_at_fraction_concurrent(
source, expected_items, num_items_to_read_before_splitting,
split_fraction, thread_pool=None):
range_tracker = source.get_range_tracker(None, None)
stop_position_before_split = range_tracker.stop_position()
reader = source.read(range_tracker)
reader_iter = iter(reader)
current_items = []
for _ in range(num_items_to_read_before_splitting):
current_items.append(next(reader_iter))
def read_or_split(test_params):
if test_params[0]:
return [val for val in test_params[1]]
else:
position = test_params[1].position_at_fraction(test_params[2])
result = test_params[1].try_split(position)
return result
inputs = []
pool = thread_pool if thread_pool else _ThreadPool(2)
try:
inputs.append([True, reader_iter])
inputs.append([False, range_tracker, split_fraction])
results = pool.map(read_or_split, inputs)
finally:
if not thread_pool:
pool.close()
current_items.extend(results[0])
primary_range = (
range_tracker.start_position(), range_tracker.stop_position())
split_result = results[1]
residual_range = (
split_result[0], stop_position_before_split) if split_result else None
res = _verify_single_split_fraction_result(
source, expected_items, current_items, split_result,
primary_range, residual_range, split_fraction)
return res[1] > 0
|
apache-2.0
|
[
3,
199,
3,
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
503,
1655,
199,
3,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
1854,
543,
199,
3,
642,
1736,
367,
4722,
2556,
12602,
4248,
12715,
14,
199,
3,
710,
14857,
12378,
642,
570,
370,
2047,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
199,
3,
334,
1589,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
199,
3,
314,
844,
14,
221,
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,
3,
199,
199,
624,
4433,
3423,
436,
511,
394,
1060,
397,
874,
367,
1350,
12591,
14,
199,
199,
2765,
859,
3509,
5922,
3423,
436,
511,
394,
1060,
397,
874,
367,
7907,
199,
4525,
4171,
402,
1350,
334,
65,
5516,
402,
1124,
2308,
1095,
14,
8781,
2980,
16580,
436,
1425,
199,
8877,
334,
65,
5516,
402,
1040,
2308,
1095,
14,
4709,
13652,
16580,
12591,
14,
199,
199,
6906,
282,
9284,
10540,
3463,
15841,
334,
69,
14,
71,
14,
7664,
2974,
687,
282,
1350,
4066,
465,
199,
1040,
739,
2532,
2980,
22524,
465,
5521,
465,
946,
22421,
3463,
3324,
5343,
436,
31692,
199,
4776,
394,
1060,
397,
874,
626,
1720,
10232,
282,
7031,
5982,
402,
511,
11745,
543,
9284,
199,
600,
14,
199,
199,
24625,
440,
461,
7869,
787,
26,
199,
10,
1124,
479,
13959,
591,
5083,
2980,
8497,
22577,
5343,
626,
314,
666,
1586,
701,
199,
1589,
13629,
402,
5274,
13584,
701,
1124,
8781,
2980,
14,
1294,
8497,
365,
314,
2011,
465,
666,
199,
739,
701,
314,
3379,
1350,
14,
199,
10,
982,
2195,
1350,
9031,
8336,
1736,
295,
30260,
12,
675,
314,
199,
1040,
479,
8862,
1271,
27217,
8497,
9614,
402,
3423,
446,
2985,
511,
5953,
402,
199,
1040,
4709,
13652,
14,
893,
63,
1294,
22524,
315,
6770,
12,
626,
7750,
17754,
199,
3282,
787,
522,
1043,
436,
314,
3141,
663,
402,
666,
1586,
701,
314,
1350,
365,
199,
32104,
1380,
19115,
5992,
14,
3645,
1124,
479,
8862,
1271,
27217,
25361,
8497,
370,
511,
199,
23001,
5560,
402,
1124,
4709,
13652,
14,
893,
63,
1294,
8497,
436,
675,
199,
1040,
479,
8862,
1271,
27217,
920,
2411,
833,
1912,
8497,
465,
282,
946,
22421,
13,
3463,
31692,
511,
5893,
199,
27518,
14,
2136,
30390,
27747,
370,
675,
3865,
14,
199,
199,
1858,
2893,
4503,
83,
12,
1937,
314,
4137,
2295,
402,
4621,
4066,
465,
199,
627,
17098,
63,
14529,
14,
2308,
14,
1365,
63,
396,
63,
1208,
63,
396,
14,
647,
199,
627,
17098,
63,
14529,
14,
2308,
14,
1214,
293,
2308,
63,
396,
14,
647,
199,
624,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
199,
646,
2050,
199,
646,
5796,
199,
646,
13852,
199,
504,
12963,
492,
2163,
199,
504,
12963,
492,
909,
199,
504,
12963,
492,
1425,
199,
504,
5055,
492,
12863,
199,
504,
12866,
14,
2293,
492,
11086,
5453,
199,
199,
504,
17098,
63,
14529,
14,
2308,
492,
5890,
1095,
199,
504,
17098,
63,
14529,
14,
4776,
14,
1974,
492,
4472,
63,
475,
199,
199,
363,
452,
363,
275,
788,
739,
63,
504,
63,
1365,
297,
1779,
283,
479,
63,
4553,
63,
1452,
63,
4443,
63,
1365,
297,
1779,
283,
479,
63,
3441,
454,
867,
63,
15656,
63,
26622,
297,
1779,
283,
479,
63,
1294,
63,
292,
63,
13054,
63,
17537,
297,
1779,
283,
479,
63,
1294,
63,
292,
63,
13054,
63,
3008,
297,
1779,
283,
479,
63,
1294,
63,
292,
63,
13054,
63,
476,
2411,
833,
1912,
297,
1779,
283,
479,
63,
1294,
63,
292,
63,
13054,
63,
15762,
297,
1779,
283,
479,
63,
1294,
63,
292,
63,
13054,
63,
14301,
5923,
63,
460,
63,
15478,
418,
421,
199,
533,
13796,
8862,
2204,
4352,
8,
785,
304,
523,
18095,
63,
6195,
8890,
63,
3649,
63,
6773,
63,
1864,
29367,
1309,
275,
413,
523,
18095,
63,
8784,
275,
499,
523,
18095,
63,
6773,
63,
1864,
29367,
1309,
63,
4656,
63,
6195,
8890,
51,
275,
650,
421,
199,
8862,
1271,
27217,
2889,
275,
12863,
8,
272,
283,
8862,
1271,
27217,
2889,
297,
283,
1507,
63,
3327,
63,
1744,
1967,
63,
20161,
63,
1744,
358,
199,
199,
8862,
27217,
20750,
275,
12863,
8,
272,
283,
8862,
27217,
20750,
297,
272,
283,
18157,
63,
21844,
2452,
2222,
63,
23844,
63,
21844,
2452,
358,
421,
199,
318,
1586,
63,
504,
63,
1365,
8,
1365,
12,
1343,
63,
3124,
29,
403,
12,
3631,
63,
3124,
29,
403,
304,
523,
408,
23614,
4008,
687,
314,
1627,
10841,
8781,
2980,
1040,
2313,
819,
5972,
11597,
4008,
4453,
314,
1627,
3421,
1425,
14,
523,
3033,
26,
272,
1350,
31742,
3796,
63,
14529,
14,
2308,
14,
2308,
1095,
14,
8781,
2980,
304,
489,
520,
533,
6054,
3796,
63,
14529,
14,
2308,
14,
2308,
1095,
14,
8781,
2980,
64,
4514,
14,
272,
1343,
63,
3124,
334,
442,
304,
1343,
3421,
367,
7664,
14,
272,
3631,
63,
3124,
334,
442,
304,
3631,
3421,
367,
7664,
14,
819,
1803,
26,
272,
3820,
59,
495,
2189,
314,
663,
402,
1338,
1586,
687,
314,
5274,
14,
523,
408,
523,
1338,
275,
942,
523,
1425,
63,
8877,
275,
1350,
14,
362,
63,
1842,
63,
8877,
8,
928,
63,
3124,
12,
3631,
63,
3124,
9,
523,
702,
1228,
8,
1842,
63,
8877,
12,
5890,
1095,
14,
4709,
13652,
9,
523,
7002,
275,
1350,
14,
739,
8,
1842,
63,
8877,
9,
523,
367,
574,
315,
7002,
26,
272,
1338,
14,
740,
8,
585,
9,
819,
372,
1338,
421,
199,
318,
485,
4436,
5453,
8,
6962,
304,
523,
327,
11086,
5453,
2467,
9030,
315,
2269,
5459,
402,
2018,
8642,
499,
14,
23,
14,
21,
9,
340,
2737,
687,
282,
523,
327,
1982,
2462
] |
[
199,
3,
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
503,
1655,
199,
3,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
1854,
543,
199,
3,
642,
1736,
367,
4722,
2556,
12602,
4248,
12715,
14,
199,
3,
710,
14857,
12378,
642,
570,
370,
2047,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
199,
3,
334,
1589,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
199,
3,
314,
844,
14,
221,
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,
3,
199,
199,
624,
4433,
3423,
436,
511,
394,
1060,
397,
874,
367,
1350,
12591,
14,
199,
199,
2765,
859,
3509,
5922,
3423,
436,
511,
394,
1060,
397,
874,
367,
7907,
199,
4525,
4171,
402,
1350,
334,
65,
5516,
402,
1124,
2308,
1095,
14,
8781,
2980,
16580,
436,
1425,
199,
8877,
334,
65,
5516,
402,
1040,
2308,
1095,
14,
4709,
13652,
16580,
12591,
14,
199,
199,
6906,
282,
9284,
10540,
3463,
15841,
334,
69,
14,
71,
14,
7664,
2974,
687,
282,
1350,
4066,
465,
199,
1040,
739,
2532,
2980,
22524,
465,
5521,
465,
946,
22421,
3463,
3324,
5343,
436,
31692,
199,
4776,
394,
1060,
397,
874,
626,
1720,
10232,
282,
7031,
5982,
402,
511,
11745,
543,
9284,
199,
600,
14,
199,
199,
24625,
440,
461,
7869,
787,
26,
199,
10,
1124,
479,
13959,
591,
5083,
2980,
8497,
22577,
5343,
626,
314,
666,
1586,
701,
199,
1589,
13629,
402,
5274,
13584,
701,
1124,
8781,
2980,
14,
1294,
8497,
365,
314,
2011,
465,
666,
199,
739,
701,
314,
3379,
1350,
14,
199,
10,
982,
2195,
1350,
9031,
8336,
1736,
295,
30260,
12,
675,
314,
199,
1040,
479,
8862,
1271,
27217,
8497,
9614,
402,
3423,
446,
2985,
511,
5953,
402,
199,
1040,
4709,
13652,
14,
893,
63,
1294,
22524,
315,
6770,
12,
626,
7750,
17754,
199,
3282,
787,
522,
1043,
436,
314,
3141,
663,
402,
666,
1586,
701,
314,
1350,
365,
199,
32104,
1380,
19115,
5992,
14,
3645,
1124,
479,
8862,
1271,
27217,
25361,
8497,
370,
511,
199,
23001,
5560,
402,
1124,
4709,
13652,
14,
893,
63,
1294,
8497,
436,
675,
199,
1040,
479,
8862,
1271,
27217,
920,
2411,
833,
1912,
8497,
465,
282,
946,
22421,
13,
3463,
31692,
511,
5893,
199,
27518,
14,
2136,
30390,
27747,
370,
675,
3865,
14,
199,
199,
1858,
2893,
4503,
83,
12,
1937,
314,
4137,
2295,
402,
4621,
4066,
465,
199,
627,
17098,
63,
14529,
14,
2308,
14,
1365,
63,
396,
63,
1208,
63,
396,
14,
647,
199,
627,
17098,
63,
14529,
14,
2308,
14,
1214,
293,
2308,
63,
396,
14,
647,
199,
624,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
199,
646,
2050,
199,
646,
5796,
199,
646,
13852,
199,
504,
12963,
492,
2163,
199,
504,
12963,
492,
909,
199,
504,
12963,
492,
1425,
199,
504,
5055,
492,
12863,
199,
504,
12866,
14,
2293,
492,
11086,
5453,
199,
199,
504,
17098,
63,
14529,
14,
2308,
492,
5890,
1095,
199,
504,
17098,
63,
14529,
14,
4776,
14,
1974,
492,
4472,
63,
475,
199,
199,
363,
452,
363,
275,
788,
739,
63,
504,
63,
1365,
297,
1779,
283,
479,
63,
4553,
63,
1452,
63,
4443,
63,
1365,
297,
1779,
283,
479,
63,
3441,
454,
867,
63,
15656,
63,
26622,
297,
1779,
283,
479,
63,
1294,
63,
292,
63,
13054,
63,
17537,
297,
1779,
283,
479,
63,
1294,
63,
292,
63,
13054,
63,
3008,
297,
1779,
283,
479,
63,
1294,
63,
292,
63,
13054,
63,
476,
2411,
833,
1912,
297,
1779,
283,
479,
63,
1294,
63,
292,
63,
13054,
63,
15762,
297,
1779,
283,
479,
63,
1294,
63,
292,
63,
13054,
63,
14301,
5923,
63,
460,
63,
15478,
418,
421,
199,
533,
13796,
8862,
2204,
4352,
8,
785,
304,
523,
18095,
63,
6195,
8890,
63,
3649,
63,
6773,
63,
1864,
29367,
1309,
275,
413,
523,
18095,
63,
8784,
275,
499,
523,
18095,
63,
6773,
63,
1864,
29367,
1309,
63,
4656,
63,
6195,
8890,
51,
275,
650,
421,
199,
8862,
1271,
27217,
2889,
275,
12863,
8,
272,
283,
8862,
1271,
27217,
2889,
297,
283,
1507,
63,
3327,
63,
1744,
1967,
63,
20161,
63,
1744,
358,
199,
199,
8862,
27217,
20750,
275,
12863,
8,
272,
283,
8862,
27217,
20750,
297,
272,
283,
18157,
63,
21844,
2452,
2222,
63,
23844,
63,
21844,
2452,
358,
421,
199,
318,
1586,
63,
504,
63,
1365,
8,
1365,
12,
1343,
63,
3124,
29,
403,
12,
3631,
63,
3124,
29,
403,
304,
523,
408,
23614,
4008,
687,
314,
1627,
10841,
8781,
2980,
1040,
2313,
819,
5972,
11597,
4008,
4453,
314,
1627,
3421,
1425,
14,
523,
3033,
26,
272,
1350,
31742,
3796,
63,
14529,
14,
2308,
14,
2308,
1095,
14,
8781,
2980,
304,
489,
520,
533,
6054,
3796,
63,
14529,
14,
2308,
14,
2308,
1095,
14,
8781,
2980,
64,
4514,
14,
272,
1343,
63,
3124,
334,
442,
304,
1343,
3421,
367,
7664,
14,
272,
3631,
63,
3124,
334,
442,
304,
3631,
3421,
367,
7664,
14,
819,
1803,
26,
272,
3820,
59,
495,
2189,
314,
663,
402,
1338,
1586,
687,
314,
5274,
14,
523,
408,
523,
1338,
275,
942,
523,
1425,
63,
8877,
275,
1350,
14,
362,
63,
1842,
63,
8877,
8,
928,
63,
3124,
12,
3631,
63,
3124,
9,
523,
702,
1228,
8,
1842,
63,
8877,
12,
5890,
1095,
14,
4709,
13652,
9,
523,
7002,
275,
1350,
14,
739,
8,
1842,
63,
8877,
9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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
] |
DavidAndreev/indico
|
indico/modules/events/contributions/models/references.py
|
2
|
2079
|
# This file is part of Indico.
# Copyright (C) 2002 - 2016 European Organization for Nuclear Research (CERN).
#
# Indico 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.
#
# Indico 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 Indico; if not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
from indico.core.db import db
from indico.modules.events.models.references import ReferenceModelBase
from indico.util.string import format_repr, return_ascii
class ContributionReference(ReferenceModelBase):
__tablename__ = 'contribution_references'
__table_args__ = {'schema': 'events'}
reference_backref_name = 'contribution_references'
contribution_id = db.Column(
db.Integer,
db.ForeignKey('events.contributions.id'),
nullable=False,
index=True
)
# relationship backrefs:
# - contribution (Contribution.references)
@return_ascii
def __repr__(self):
return format_repr(self, 'id', 'contribution_id', 'reference_type_id', _text=self.value)
class SubContributionReference(ReferenceModelBase):
__tablename__ = 'subcontribution_references'
__table_args__ = {'schema': 'events'}
reference_backref_name = 'subcontribution_references'
subcontribution_id = db.Column(
db.Integer,
db.ForeignKey('events.subcontributions.id'),
nullable=False,
index=True
)
# relationship backrefs:
# - subcontribution (SubContribution.references)
@return_ascii
def __repr__(self):
return format_repr(self, 'id', 'subcontribution_id', 'reference_type_id', _text=self.value)
|
gpl-3.0
|
[
3,
961,
570,
365,
1777,
402,
1010,
27347,
14,
199,
3,
1898,
334,
35,
9,
14790,
446,
7800,
31615,
290,
18863,
367,
653,
947,
4025,
26993,
334,
35,
14482,
680,
199,
3,
199,
3,
1010,
27347,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
650,
402,
314,
199,
3,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
1010,
27347,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
199,
3,
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,
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,
1010,
27347,
27,
340,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
2539,
331,
14,
1018,
14,
697,
492,
1592,
199,
504,
2539,
331,
14,
3112,
14,
4368,
14,
992,
14,
12635,
492,
10944,
1685,
1563,
199,
504,
2539,
331,
14,
1974,
14,
875,
492,
1475,
63,
2722,
12,
372,
63,
4371,
421,
199,
533,
1448,
15980,
5083,
8,
5083,
1685,
1563,
304,
272,
636,
10983,
363,
275,
283,
388,
15980,
63,
12635,
7,
272,
636,
1224,
63,
589,
363,
275,
791,
3629,
356,
283,
4368,
936,
272,
3659,
63,
894,
1121,
63,
354,
275,
283,
388,
15980,
63,
12635,
7,
339,
406,
15980,
63,
344,
275,
1592,
14,
4547,
8,
267,
1592,
14,
2674,
12,
267,
1592,
14,
3190,
360,
4368,
14,
388,
26675,
14,
344,
659,
267,
7854,
29,
797,
12,
267,
1478,
29,
549,
272,
776,
339,
327,
8931,
1771,
7655,
26,
272,
327,
446,
406,
15980,
334,
714,
15980,
14,
12635,
9,
339,
768,
1107,
63,
4371,
272,
347,
636,
2722,
721,
277,
304,
267,
372,
1475,
63,
2722,
8,
277,
12,
283,
344,
297,
283,
388,
15980,
63,
344,
297,
283,
4443,
63,
466,
63,
344,
297,
485,
505,
29,
277,
14,
585,
9,
421,
199,
533,
4804,
714,
15980,
5083,
8,
5083,
1685,
1563,
304,
272,
636,
10983,
363,
275,
283,
954,
388,
15980,
63,
12635,
7,
272,
636,
1224,
63,
589,
363,
275,
791,
3629,
356,
283,
4368,
936,
272,
3659,
63,
894,
1121,
63,
354,
275,
283,
954,
388,
15980,
63,
12635,
7,
339,
1007,
388,
15980,
63,
344,
275,
1592,
14,
4547,
8,
267,
1592,
14,
2674,
12,
267,
1592,
14,
3190,
360,
4368,
14,
954,
388,
26675,
14,
344,
659,
267,
7854,
29,
797,
12,
267,
1478,
29,
549,
272,
776,
339,
327,
8931,
1771,
7655,
26,
272,
327,
446,
1007,
388,
15980,
334,
2610,
714,
15980,
14,
12635,
9,
339,
768,
1107,
63,
4371,
272,
347,
636,
2722,
721,
277,
304,
267,
372,
1475,
63,
2722,
8,
277,
12,
283,
344,
297,
283,
954,
388,
15980,
63,
344,
297,
283,
4443,
63,
466,
63,
344,
297,
485,
505,
29,
277,
14,
585,
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
] |
[
961,
570,
365,
1777,
402,
1010,
27347,
14,
199,
3,
1898,
334,
35,
9,
14790,
446,
7800,
31615,
290,
18863,
367,
653,
947,
4025,
26993,
334,
35,
14482,
680,
199,
3,
199,
3,
1010,
27347,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
650,
402,
314,
199,
3,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
1010,
27347,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
199,
3,
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,
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,
1010,
27347,
27,
340,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
2539,
331,
14,
1018,
14,
697,
492,
1592,
199,
504,
2539,
331,
14,
3112,
14,
4368,
14,
992,
14,
12635,
492,
10944,
1685,
1563,
199,
504,
2539,
331,
14,
1974,
14,
875,
492,
1475,
63,
2722,
12,
372,
63,
4371,
421,
199,
533,
1448,
15980,
5083,
8,
5083,
1685,
1563,
304,
272,
636,
10983,
363,
275,
283,
388,
15980,
63,
12635,
7,
272,
636,
1224,
63,
589,
363,
275,
791,
3629,
356,
283,
4368,
936,
272,
3659,
63,
894,
1121,
63,
354,
275,
283,
388,
15980,
63,
12635,
7,
339,
406,
15980,
63,
344,
275,
1592,
14,
4547,
8,
267,
1592,
14,
2674,
12,
267,
1592,
14,
3190,
360,
4368,
14,
388,
26675,
14,
344,
659,
267,
7854,
29,
797,
12,
267,
1478,
29,
549,
272,
776,
339,
327,
8931,
1771,
7655,
26,
272,
327,
446,
406,
15980,
334,
714,
15980,
14,
12635,
9,
339,
768,
1107,
63,
4371,
272,
347,
636,
2722,
721,
277,
304,
267,
372,
1475,
63,
2722,
8,
277,
12,
283,
344,
297,
283,
388,
15980,
63,
344,
297,
283,
4443,
63,
466,
63,
344,
297,
485,
505,
29,
277,
14,
585,
9,
421,
199,
533,
4804,
714,
15980,
5083,
8,
5083,
1685,
1563,
304,
272,
636,
10983,
363,
275,
283,
954,
388,
15980,
63,
12635,
7,
272,
636,
1224,
63,
589,
363,
275,
791,
3629,
356,
283,
4368,
936,
272,
3659,
63,
894,
1121,
63,
354,
275,
283,
954,
388,
15980,
63,
12635,
7,
339,
1007,
388,
15980,
63,
344,
275,
1592,
14,
4547,
8,
267,
1592,
14,
2674,
12,
267,
1592,
14,
3190,
360,
4368,
14,
954,
388,
26675,
14,
344,
659,
267,
7854,
29,
797,
12,
267,
1478,
29,
549,
272,
776,
339,
327,
8931,
1771,
7655,
26,
272,
327,
446,
1007,
388,
15980,
334,
2610,
714,
15980,
14,
12635,
9,
339,
768,
1107,
63,
4371,
272,
347,
636,
2722,
721,
277,
304,
267,
372,
1475,
63,
2722,
8,
277,
12,
283,
344,
297,
283,
954,
388,
15980,
63,
344,
297,
283,
4443,
63,
466,
63,
344,
297,
485,
505,
29,
277,
14,
585,
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,
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,
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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
] |
abushaa/solar_project
|
solar_main.py
|
10
|
5906
|
# coding: utf-8
# license: GPLv3
import tkinter
from tkinter.filedialog import *
from solar_vis import *
from solar_model import *
from solar_input import *
perform_execution = False
"""Флаг цикличности выполнения расчёта"""
physical_time = 0
"""Физическое время от начала расчёта.
Тип: float"""
displayed_time = None
"""Отображаемое на экране время.
Тип: переменная tkinter"""
time_step = None
"""Шаг по времени при моделировании.
Тип: float"""
space_objects = []
"""Список космических объектов."""
def execution():
"""Функция исполнения -- выполняется циклически, вызывая обработку всех небесных тел,
а также обновляя их положение на экране.
Цикличность выполнения зависит от значения глобальной переменной perform_execution.
При perform_execution == True функция запрашивает вызов самой себя по таймеру через от 1 мс до 100 мс.
"""
global physical_time
global displayed_time
recalculate_space_objects_positions(space_objects, time_step.get())
for body in space_objects:
update_object_position(space, body)
physical_time += time_step.get()
displayed_time.set("%.1f" % physical_time + " seconds gone")
if perform_execution:
space.after(101 - int(time_speed.get()), execution)
def start_execution():
"""Обработчик события нажатия на кнопку Start.
Запускает циклическое исполнение функции execution.
"""
global perform_execution
perform_execution = True
start_button['text'] = "Pause"
start_button['command'] = stop_execution
execution()
print('Started execution...')
def stop_execution():
"""Обработчик события нажатия на кнопку Start.
Останавливает циклическое исполнение функции execution.
"""
global perform_execution
perform_execution = False
start_button['text'] = "Start"
start_button['command'] = start_execution
print('Paused execution.')
def open_file_dialog():
"""Открывает диалоговое окно выбора имени файла и вызывает
функцию считывания параметров системы небесных тел из данного файла.
Считанные объекты сохраняются в глобальный список space_objects
"""
global space_objects
global perform_execution
perform_execution = False
for obj in space_objects:
space.delete(obj.image) # удаление старых изображений планет
in_filename = askopenfilename(filetypes=(("Text file", ".txt"),))
space_objects = read_space_objects_data_from_file(in_filename)
max_distance = max([max(abs(obj.x), abs(obj.y)) for obj in space_objects])
calculate_scale_factor(max_distance)
for obj in space_objects:
if obj.type == 'star':
create_star_image(space, obj)
elif obj.type == 'planet':
create_planet_image(space, obj)
else:
raise AssertionError()
def save_file_dialog():
"""Открывает диалоговое окно выбора имени файла и вызывает
функцию считывания параметров системы небесных тел из данного файла.
Считанные объекты сохраняются в глобальный список space_objects
"""
out_filename = asksaveasfilename(filetypes=(("Text file", ".txt"),))
write_space_objects_data_to_file(out_filename, space_objects)
def main():
"""Главная функция главного модуля.
Создаёт объекты графического дизайна библиотеки tkinter: окно, холст, фрейм с кнопками, кнопки.
"""
global physical_time
global displayed_time
global time_step
global time_speed
global space
global start_button
print('Modelling started!')
physical_time = 0
root = tkinter.Tk()
# космическое пространство отображается на холсте типа Canvas
space = tkinter.Canvas(root, width=window_width, height=window_height, bg="black")
space.pack(side=tkinter.TOP)
# нижняя панель с кнопками
frame = tkinter.Frame(root)
frame.pack(side=tkinter.BOTTOM)
start_button = tkinter.Button(frame, text="Start", command=start_execution, width=6)
start_button.pack(side=tkinter.LEFT)
time_step = tkinter.DoubleVar()
time_step.set(1)
time_step_entry = tkinter.Entry(frame, textvariable=time_step)
time_step_entry.pack(side=tkinter.LEFT)
time_speed = tkinter.DoubleVar()
scale = tkinter.Scale(frame, variable=time_speed, orient=tkinter.HORIZONTAL)
scale.pack(side=tkinter.LEFT)
load_file_button = tkinter.Button(frame, text="Open file...", command=open_file_dialog)
load_file_button.pack(side=tkinter.LEFT)
save_file_button = tkinter.Button(frame, text="Save to file...", command=save_file_dialog)
save_file_button.pack(side=tkinter.LEFT)
displayed_time = tkinter.StringVar()
displayed_time.set(str(physical_time) + " seconds gone")
time_label = tkinter.Label(frame, textvariable=displayed_time, width=30)
time_label.pack(side=tkinter.RIGHT)
root.mainloop()
print('Modelling finished!')
if __name__ == "__main__":
main()
|
gpl-3.0
|
[
3,
2803,
26,
2774,
13,
24,
199,
3,
4190,
26,
14629,
86,
19,
199,
199,
646,
22171,
199,
504,
22171,
14,
493,
7196,
492,
627,
199,
504,
8597,
285,
63,
5068,
492,
627,
199,
504,
8597,
285,
63,
1238,
492,
627,
199,
504,
8597,
285,
63,
1210,
492,
627,
199,
199,
15795,
63,
9416,
275,
756,
199,
624,
141,
98,
10356,
13111,
112,
221,
25827,
6500,
11487,
10356,
6500,
19277,
7592,
5806,
18261,
6500,
22213,
17445,
23645,
26927,
7592,
18624,
6500,
14978,
221,
7753,
5657,
8474,
19277,
142,
240,
7413,
5657,
624,
199,
199,
15020,
63,
521,
275,
378,
199,
624,
141,
98,
16863,
116,
6500,
19277,
6286,
8474,
11487,
5806,
6286,
22213,
7753,
15578,
121,
14978,
221,
5806,
7413,
24917,
5657,
19277,
30638,
5657,
221,
7753,
5657,
8474,
19277,
142,
240,
7413,
5657,
14,
199,
141,
96,
16863,
124,
26,
2069,
624,
199,
199,
22283,
63,
521,
275,
488,
199,
624,
141,
253,
7413,
8381,
110,
7753,
13111,
115,
5657,
15578,
121,
5806,
6286,
24917,
5657,
221,
142,
236,
11487,
7753,
21674,
6286,
22213,
7753,
15578,
121,
14978,
14,
199,
141,
96,
16863,
124,
26,
19820,
21273,
15578,
121,
18624,
7592,
5657,
14978,
22171,
624,
199,
199,
521,
63,
2926,
275,
488,
199,
624,
141,
102,
13111,
112,
19820,
5806,
22213,
7753,
15578,
121,
18624,
6500,
19820,
7753,
6500,
7038,
121,
28711,
30598,
6500,
7753,
21267,
21674,
6500,
6500,
14,
199,
141,
96,
16863,
124,
26,
2069,
624,
199,
199,
2638,
63,
1462,
275,
942,
199,
624,
141,
95,
23645,
6500,
8474,
8381,
119,
31999,
5806,
8474,
23000,
6500,
19277,
6286,
8474,
11487,
6500,
25969,
221,
8381,
110,
142,
233,
6286,
11487,
7413,
21267,
1041,
421,
199,
318,
6451,
837,
272,
408,
141,
98,
12195,
7592,
11487,
25827,
6500,
14978,
221,
6500,
8474,
23645,
26927,
7592,
18624,
6500,
14978,
1553,
22213,
17445,
23645,
26927,
7592,
14978,
30160,
8474,
14978,
221,
25827,
6500,
11487,
10356,
6500,
19277,
6286,
8474,
11487,
6500,
12,
22213,
17445,
31027,
17445,
19630,
5657,
14978,
221,
8381,
110,
7753,
13111,
110,
5806,
7413,
11487,
12195,
22213,
8474,
6286,
25969,
24917,
15578,
110,
6286,
8474,
7592,
17445,
25969,
221,
7413,
30598,
12,
272,
221,
5657,
221,
7413,
5657,
11487,
141,
115,
6286,
221,
8381,
110,
7592,
21267,
10356,
14978,
14978,
221,
6500,
25969,
19820,
26927,
8381,
115,
18624,
6500,
6286,
24917,
5657,
221,
142,
236,
11487,
7753,
21674,
6286,
14,
272,
7038,
100,
6500,
11487,
10356,
6500,
19277,
7592,
5806,
18261,
16961,
22213,
17445,
23645,
26927,
7592,
18624,
6500,
14978,
7038,
116,
13111,
111,
6500,
8474,
30019,
221,
5806,
7413,
7038,
116,
7592,
5657,
19277,
18624,
6500,
14978,
7038,
112,
10356,
8381,
110,
30638,
16961,
7592,
8381,
118,
19820,
21273,
15578,
121,
18624,
7592,
8381,
118,
5147,
63,
9416,
14,
272,
7038,
254,
7753,
6500,
5147,
63,
9416,
508,
715,
221,
31815,
12195,
7592,
11487,
25827,
6500,
14978,
7038,
116,
13111,
124,
7753,
5657,
27202,
16863,
111,
5657,
30160,
22213,
17445,
31027,
21267,
24071,
13111,
121,
8381,
118,
24071,
15578,
110,
14978,
19820,
5806,
221,
7413,
13111,
118,
23000,
21273,
12195,
221,
19277,
21273,
15578,
116,
221,
5806,
7413,
413,
7038,
121,
8474,
29562,
5806,
2948,
7038,
121,
8474,
14,
272,
408,
272,
2288,
14095,
63,
521,
272,
2288,
9080,
63,
521,
272,
295,
12063,
63,
2638,
63,
1462,
63,
12658,
8,
2638,
63,
1462,
12,
900,
63,
2926,
14,
362,
1012,
272,
367,
2396,
315,
4601,
63,
1462,
26,
267,
1678,
63,
785,
63,
3124,
8,
2638,
12,
2396,
9,
272,
14095,
63,
521,
847,
900,
63,
2926,
14,
362,
342,
272,
9080,
63,
521,
14,
409,
3647,
14,
17,
70,
2,
450,
14095,
63,
521,
435,
298,
4696,
21737,
531,
339,
340,
5147,
63,
9416,
26,
267,
4601,
14,
4399,
8,
4893,
446,
1109,
8,
521,
63,
7625,
14,
362,
4000,
6451,
9,
421,
199,
318,
1343,
63,
9416,
837,
272,
408,
141,
253,
141,
110,
7753,
13111,
110,
5806,
7413,
19277,
6500,
11487,
24071,
8381,
110,
17445,
7413,
6500,
14978,
24917,
13111,
115,
24219,
6500,
14978,
24917,
5657,
31999,
7592,
8381,
124,
11487,
12195,
7707,
14,
272,
7038,
246,
13111,
124,
12195,
8474,
29352,
30160,
221,
25827,
6500,
11487,
10356,
6500,
19277,
6286,
8474,
11487,
5806,
6286,
221,
6500,
8474,
23645,
26927,
7592,
18624,
6500,
6286,
221,
31815,
12195,
7592,
11487,
25827,
6500,
6500,
6451,
14,
272,
408,
272,
2288,
5147,
63,
9416,
272,
5147,
63,
9416,
275,
715,
272,
1343,
63,
3887,
459,
505,
418,
275,
298,
30851,
2,
272,
1343,
63,
3887,
459,
1531,
418,
275,
3631,
63,
9416,
339,
6451,
342,
272,
870,
360,
21031,
6451,
15103,
421,
199,
318,
3631,
63,
9416,
837,
272,
408,
141,
253,
141,
110,
7753,
13111,
110,
5806,
7413,
19277,
6500,
11487,
24071,
8381,
110,
17445,
7413,
6500,
14978,
24917,
13111,
115,
24219,
6500,
14978,
24917,
5657,
31999,
7592,
8381,
124,
11487,
12195,
7707,
14,
272,
7038,
253,
18261,
21674,
13111,
111,
10356,
16863,
111,
5657,
30160,
221,
25827,
6500,
11487,
10356,
6500,
19277,
6286,
8474,
11487,
5806,
6286,
221,
6500,
8474,
23645,
26927,
7592,
18624,
6500,
6286,
221,
31815,
12195,
7592,
11487,
25827,
6500,
6500,
6451,
14,
272,
408,
272,
2288,
5147,
63,
9416,
272,
5147,
63,
9416,
275,
756,
272,
1343,
63,
3887,
459,
505,
418,
275,
298,
3162,
2,
272,
1343,
63,
3887,
459,
1531,
418,
275,
1343,
63,
9416,
272,
870,
360,
4232,
2972,
6451,
2659,
421,
199,
318,
1551,
63,
493,
63,
7196,
837,
272,
408,
141,
253,
7413,
11487,
7753,
17445,
19630,
5657,
30160,
29562,
6500,
30638,
8381,
112,
21267,
5806,
6286,
221,
8381,
119,
7592,
5806,
22213,
17445,
141,
110,
26438,
5657,
221,
16863,
121,
18624,
6500,
221,
31815,
13111,
118,
10356,
5657,
221,
6500,
22213,
17445,
31027,
17445,
19630,
5657,
30160,
272,
221,
31815,
12195,
7592,
11487,
25827,
6500,
31235,
24071,
19277,
30019,
17445,
19630,
21674,
6500,
14978,
19820,
27559,
13111,
121,
30160,
7753,
21267,
24071,
6500,
18261,
15578,
121,
17445,
24917,
15578,
110,
6286,
8474,
7592,
17445,
25969,
221,
7413,
30598,
221,
16863,
116,
29562,
21674,
7592,
8381,
112,
5806,
221,
31815,
13111,
118,
10356,
5657,
14,
272,
7038,
95,
19277,
30019,
21674,
7592,
17445,
6286,
221,
8381,
110,
142,
233,
6286,
11487,
7413,
17445,
24071,
5806,
25969,
7753,
21674
] |
[
2803,
26,
2774,
13,
24,
199,
3,
4190,
26,
14629,
86,
19,
199,
199,
646,
22171,
199,
504,
22171,
14,
493,
7196,
492,
627,
199,
504,
8597,
285,
63,
5068,
492,
627,
199,
504,
8597,
285,
63,
1238,
492,
627,
199,
504,
8597,
285,
63,
1210,
492,
627,
199,
199,
15795,
63,
9416,
275,
756,
199,
624,
141,
98,
10356,
13111,
112,
221,
25827,
6500,
11487,
10356,
6500,
19277,
7592,
5806,
18261,
6500,
22213,
17445,
23645,
26927,
7592,
18624,
6500,
14978,
221,
7753,
5657,
8474,
19277,
142,
240,
7413,
5657,
624,
199,
199,
15020,
63,
521,
275,
378,
199,
624,
141,
98,
16863,
116,
6500,
19277,
6286,
8474,
11487,
5806,
6286,
22213,
7753,
15578,
121,
14978,
221,
5806,
7413,
24917,
5657,
19277,
30638,
5657,
221,
7753,
5657,
8474,
19277,
142,
240,
7413,
5657,
14,
199,
141,
96,
16863,
124,
26,
2069,
624,
199,
199,
22283,
63,
521,
275,
488,
199,
624,
141,
253,
7413,
8381,
110,
7753,
13111,
115,
5657,
15578,
121,
5806,
6286,
24917,
5657,
221,
142,
236,
11487,
7753,
21674,
6286,
22213,
7753,
15578,
121,
14978,
14,
199,
141,
96,
16863,
124,
26,
19820,
21273,
15578,
121,
18624,
7592,
5657,
14978,
22171,
624,
199,
199,
521,
63,
2926,
275,
488,
199,
624,
141,
102,
13111,
112,
19820,
5806,
22213,
7753,
15578,
121,
18624,
6500,
19820,
7753,
6500,
7038,
121,
28711,
30598,
6500,
7753,
21267,
21674,
6500,
6500,
14,
199,
141,
96,
16863,
124,
26,
2069,
624,
199,
199,
2638,
63,
1462,
275,
942,
199,
624,
141,
95,
23645,
6500,
8474,
8381,
119,
31999,
5806,
8474,
23000,
6500,
19277,
6286,
8474,
11487,
6500,
25969,
221,
8381,
110,
142,
233,
6286,
11487,
7413,
21267,
1041,
421,
199,
318,
6451,
837,
272,
408,
141,
98,
12195,
7592,
11487,
25827,
6500,
14978,
221,
6500,
8474,
23645,
26927,
7592,
18624,
6500,
14978,
1553,
22213,
17445,
23645,
26927,
7592,
14978,
30160,
8474,
14978,
221,
25827,
6500,
11487,
10356,
6500,
19277,
6286,
8474,
11487,
6500,
12,
22213,
17445,
31027,
17445,
19630,
5657,
14978,
221,
8381,
110,
7753,
13111,
110,
5806,
7413,
11487,
12195,
22213,
8474,
6286,
25969,
24917,
15578,
110,
6286,
8474,
7592,
17445,
25969,
221,
7413,
30598,
12,
272,
221,
5657,
221,
7413,
5657,
11487,
141,
115,
6286,
221,
8381,
110,
7592,
21267,
10356,
14978,
14978,
221,
6500,
25969,
19820,
26927,
8381,
115,
18624,
6500,
6286,
24917,
5657,
221,
142,
236,
11487,
7753,
21674,
6286,
14,
272,
7038,
100,
6500,
11487,
10356,
6500,
19277,
7592,
5806,
18261,
16961,
22213,
17445,
23645,
26927,
7592,
18624,
6500,
14978,
7038,
116,
13111,
111,
6500,
8474,
30019,
221,
5806,
7413,
7038,
116,
7592,
5657,
19277,
18624,
6500,
14978,
7038,
112,
10356,
8381,
110,
30638,
16961,
7592,
8381,
118,
19820,
21273,
15578,
121,
18624,
7592,
8381,
118,
5147,
63,
9416,
14,
272,
7038,
254,
7753,
6500,
5147,
63,
9416,
508,
715,
221,
31815,
12195,
7592,
11487,
25827,
6500,
14978,
7038,
116,
13111,
124,
7753,
5657,
27202,
16863,
111,
5657,
30160,
22213,
17445,
31027,
21267,
24071,
13111,
121,
8381,
118,
24071,
15578,
110,
14978,
19820,
5806,
221,
7413,
13111,
118,
23000,
21273,
12195,
221,
19277,
21273,
15578,
116,
221,
5806,
7413,
413,
7038,
121,
8474,
29562,
5806,
2948,
7038,
121,
8474,
14,
272,
408,
272,
2288,
14095,
63,
521,
272,
2288,
9080,
63,
521,
272,
295,
12063,
63,
2638,
63,
1462,
63,
12658,
8,
2638,
63,
1462,
12,
900,
63,
2926,
14,
362,
1012,
272,
367,
2396,
315,
4601,
63,
1462,
26,
267,
1678,
63,
785,
63,
3124,
8,
2638,
12,
2396,
9,
272,
14095,
63,
521,
847,
900,
63,
2926,
14,
362,
342,
272,
9080,
63,
521,
14,
409,
3647,
14,
17,
70,
2,
450,
14095,
63,
521,
435,
298,
4696,
21737,
531,
339,
340,
5147,
63,
9416,
26,
267,
4601,
14,
4399,
8,
4893,
446,
1109,
8,
521,
63,
7625,
14,
362,
4000,
6451,
9,
421,
199,
318,
1343,
63,
9416,
837,
272,
408,
141,
253,
141,
110,
7753,
13111,
110,
5806,
7413,
19277,
6500,
11487,
24071,
8381,
110,
17445,
7413,
6500,
14978,
24917,
13111,
115,
24219,
6500,
14978,
24917,
5657,
31999,
7592,
8381,
124,
11487,
12195,
7707,
14,
272,
7038,
246,
13111,
124,
12195,
8474,
29352,
30160,
221,
25827,
6500,
11487,
10356,
6500,
19277,
6286,
8474,
11487,
5806,
6286,
221,
6500,
8474,
23645,
26927,
7592,
18624,
6500,
6286,
221,
31815,
12195,
7592,
11487,
25827,
6500,
6500,
6451,
14,
272,
408,
272,
2288,
5147,
63,
9416,
272,
5147,
63,
9416,
275,
715,
272,
1343,
63,
3887,
459,
505,
418,
275,
298,
30851,
2,
272,
1343,
63,
3887,
459,
1531,
418,
275,
3631,
63,
9416,
339,
6451,
342,
272,
870,
360,
21031,
6451,
15103,
421,
199,
318,
3631,
63,
9416,
837,
272,
408,
141,
253,
141,
110,
7753,
13111,
110,
5806,
7413,
19277,
6500,
11487,
24071,
8381,
110,
17445,
7413,
6500,
14978,
24917,
13111,
115,
24219,
6500,
14978,
24917,
5657,
31999,
7592,
8381,
124,
11487,
12195,
7707,
14,
272,
7038,
253,
18261,
21674,
13111,
111,
10356,
16863,
111,
5657,
30160,
221,
25827,
6500,
11487,
10356,
6500,
19277,
6286,
8474,
11487,
5806,
6286,
221,
6500,
8474,
23645,
26927,
7592,
18624,
6500,
6286,
221,
31815,
12195,
7592,
11487,
25827,
6500,
6500,
6451,
14,
272,
408,
272,
2288,
5147,
63,
9416,
272,
5147,
63,
9416,
275,
756,
272,
1343,
63,
3887,
459,
505,
418,
275,
298,
3162,
2,
272,
1343,
63,
3887,
459,
1531,
418,
275,
1343,
63,
9416,
272,
870,
360,
4232,
2972,
6451,
2659,
421,
199,
318,
1551,
63,
493,
63,
7196,
837,
272,
408,
141,
253,
7413,
11487,
7753,
17445,
19630,
5657,
30160,
29562,
6500,
30638,
8381,
112,
21267,
5806,
6286,
221,
8381,
119,
7592,
5806,
22213,
17445,
141,
110,
26438,
5657,
221,
16863,
121,
18624,
6500,
221,
31815,
13111,
118,
10356,
5657,
221,
6500,
22213,
17445,
31027,
17445,
19630,
5657,
30160,
272,
221,
31815,
12195,
7592,
11487,
25827,
6500,
31235,
24071,
19277,
30019,
17445,
19630,
21674,
6500,
14978,
19820,
27559,
13111,
121,
30160,
7753,
21267,
24071,
6500,
18261,
15578,
121,
17445,
24917,
15578,
110,
6286,
8474,
7592,
17445,
25969,
221,
7413,
30598,
221,
16863,
116,
29562,
21674,
7592,
8381,
112,
5806,
221,
31815,
13111,
118,
10356,
5657,
14,
272,
7038,
95,
19277,
30019,
21674,
7592,
17445,
6286,
221,
8381,
110,
142,
233,
6286,
11487,
7413,
17445,
24071,
5806,
25969,
7753,
21674,
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,
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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
] |
tudorvio/tempest
|
tempest/api/compute/floating_ips/test_list_floating_ips_negative.py
|
17
|
1687
|
# Copyright 2012 OpenStack Foundation
# 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 uuid
from tempest_lib import exceptions as lib_exc
from tempest.api.compute import base
from tempest.common.utils import data_utils
from tempest import config
from tempest import test
CONF = config.CONF
class FloatingIPDetailsNegativeTestJSON(base.BaseV2ComputeTest):
@classmethod
def setup_clients(cls):
super(FloatingIPDetailsNegativeTestJSON, cls).setup_clients()
cls.client = cls.floating_ips_client
@test.attr(type=['negative'])
@test.idempotent_id('7ab18834-4a4b-4f28-a2c5-440579866695')
@test.services('network')
def test_get_nonexistent_floating_ip_details(self):
# Negative test:Should not be able to GET the details
# of non-existent floating IP
# Creating a non-existent floatingIP id
if CONF.service_available.neutron:
non_exist_id = str(uuid.uuid4())
else:
non_exist_id = data_utils.rand_int_id(start=999)
self.assertRaises(lib_exc.NotFound,
self.client.show_floating_ip, non_exist_id)
|
apache-2.0
|
[
3,
1898,
6029,
14260,
2752,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
646,
5377,
199,
199,
504,
24076,
63,
773,
492,
4967,
465,
1973,
63,
2804,
199,
199,
504,
24076,
14,
1246,
14,
3357,
492,
1300,
199,
504,
24076,
14,
2330,
14,
1208,
492,
666,
63,
1208,
199,
504,
24076,
492,
1101,
199,
504,
24076,
492,
511,
199,
199,
3103,
275,
1101,
14,
3103,
421,
199,
533,
27729,
1772,
11347,
15562,
774,
6243,
8,
1095,
14,
1563,
54,
18,
8564,
774,
304,
339,
768,
3744,
272,
347,
3272,
63,
14555,
8,
1886,
304,
267,
1613,
8,
17895,
1772,
11347,
15562,
774,
6243,
12,
843,
680,
2758,
63,
14555,
342,
267,
843,
14,
1258,
275,
843,
14,
7774,
63,
6142,
63,
1258,
339,
768,
396,
14,
962,
8,
466,
2968,
7371,
1105,
272,
768,
396,
14,
21307,
63,
344,
360,
23,
371,
11501,
1082,
13,
20,
65,
20,
66,
13,
20,
70,
1651,
13,
65,
18,
67,
21,
13,
14162,
14003,
1184,
1272,
2720,
358,
272,
768,
396,
14,
5950,
360,
1200,
358,
272,
347,
511,
63,
362,
63,
21573,
63,
7774,
63,
711,
63,
5087,
8,
277,
304,
267,
327,
32548,
511,
26,
11408,
440,
506,
7688,
370,
9576,
314,
2436,
267,
327,
402,
2222,
13,
15025,
8402,
3531,
267,
327,
20507,
282,
2222,
13,
15025,
8402,
1772,
1305,
267,
340,
6392,
14,
1364,
63,
4561,
14,
10271,
26,
288,
2222,
63,
4494,
63,
344,
275,
620,
8,
2580,
14,
2580,
20,
1012,
267,
587,
26,
288,
2222,
63,
4494,
63,
344,
275,
666,
63,
1208,
14,
3759,
63,
442,
63,
344,
8,
928,
29,
5637,
9,
267,
291,
14,
1855,
8,
773,
63,
2804,
14,
4667,
12,
2079,
291,
14,
1258,
14,
2384,
63,
7774,
63,
711,
12,
2222,
63,
4494,
63,
344,
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
] |
[
1898,
6029,
14260,
2752,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
646,
5377,
199,
199,
504,
24076,
63,
773,
492,
4967,
465,
1973,
63,
2804,
199,
199,
504,
24076,
14,
1246,
14,
3357,
492,
1300,
199,
504,
24076,
14,
2330,
14,
1208,
492,
666,
63,
1208,
199,
504,
24076,
492,
1101,
199,
504,
24076,
492,
511,
199,
199,
3103,
275,
1101,
14,
3103,
421,
199,
533,
27729,
1772,
11347,
15562,
774,
6243,
8,
1095,
14,
1563,
54,
18,
8564,
774,
304,
339,
768,
3744,
272,
347,
3272,
63,
14555,
8,
1886,
304,
267,
1613,
8,
17895,
1772,
11347,
15562,
774,
6243,
12,
843,
680,
2758,
63,
14555,
342,
267,
843,
14,
1258,
275,
843,
14,
7774,
63,
6142,
63,
1258,
339,
768,
396,
14,
962,
8,
466,
2968,
7371,
1105,
272,
768,
396,
14,
21307,
63,
344,
360,
23,
371,
11501,
1082,
13,
20,
65,
20,
66,
13,
20,
70,
1651,
13,
65,
18,
67,
21,
13,
14162,
14003,
1184,
1272,
2720,
358,
272,
768,
396,
14,
5950,
360,
1200,
358,
272,
347,
511,
63,
362,
63,
21573,
63,
7774,
63,
711,
63,
5087,
8,
277,
304,
267,
327,
32548,
511,
26,
11408,
440,
506,
7688,
370,
9576,
314,
2436,
267,
327,
402,
2222,
13,
15025,
8402,
3531,
267,
327,
20507,
282,
2222,
13,
15025,
8402,
1772,
1305,
267,
340,
6392,
14,
1364,
63,
4561,
14,
10271,
26,
288,
2222,
63,
4494,
63,
344,
275,
620,
8,
2580,
14,
2580,
20,
1012,
267,
587,
26,
288,
2222,
63,
4494,
63,
344,
275,
666,
63,
1208,
14,
3759,
63,
442,
63,
344,
8,
928,
29,
5637,
9,
267,
291,
14,
1855,
8,
773,
63,
2804,
14,
4667,
12,
2079,
291,
14,
1258,
14,
2384,
63,
7774,
63,
711,
12,
2222,
63,
4494,
63,
344,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
alikins/ansible
|
lib/ansible/modules/cloud/cloudstack/cs_instance_nic_secondaryip.py
|
94
|
8006
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# (c) 2017, René Moser <mail@renemoser.net>
#
# 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: cs_instance_nic_secondaryip
short_description: Manages secondary IPs of an instance on Apache CloudStack based clouds.
description:
- Add and remove secondary IPs to and from a NIC of an instance.
version_added: "2.4"
author: "René Moser (@resmo)"
options:
vm:
description:
- Name of instance.
required: true
aliases: [ name ]
network:
description:
- Name of the network.
- Required to find the NIC if instance has multiple networks assigned.
vm_guest_ip:
description:
- Secondary IP address to be added to the instance nic.
- If not set, the API always returns a new IP address and idempotency is not given.
aliases: [ secondary_ip ]
vpc:
description:
- Name of the VPC the C(vm) is related to.
domain:
description:
- Domain the instance is related to.
account:
description:
- Account the instance is related to.
project:
description:
- Name of the project the instance is deployed in.
zone:
description:
- Name of the zone in which the instance is deployed in.
- If not set, default zone is used.
state:
description:
- State of the ipaddress.
default: present
choices: [ present, absent ]
poll_async:
description:
- Poll async jobs until job has finished.
default: true
extends_documentation_fragment: cloudstack
'''
EXAMPLES = '''
- name: Assign a specific IP to the default NIC of the VM
local_action:
module: cs_instance_nic_secondaryip
vm: customer_xy
vm_guest_ip: 10.10.10.10
# Note: If vm_guest_ip is not set, you will get a new IP address on every run.
- name: Assign an IP to the default NIC of the VM
local_action:
module: cs_instance_nic_secondaryip
vm: customer_xy
- name: Remove a specific IP from the default NIC
local_action:
module: cs_instance_nic_secondaryip
vm: customer_xy
vm_guest_ip: 10.10.10.10
state: absent
'''
RETURN = '''
---
id:
description: UUID of the NIC.
returned: success
type: string
sample: 87b1e0ce-4e01-11e4-bb66-0050569e64b8
vm:
description: Name of the VM.
returned: success
type: string
sample: web-01
ip_address:
description: Primary IP of the NIC.
returned: success
type: string
sample: 10.10.10.10
netmask:
description: Netmask of the NIC.
returned: success
type: string
sample: 255.255.255.0
mac_address:
description: MAC address of the NIC.
returned: success
type: string
sample: 02:00:33:31:00:e4
vm_guest_ip:
description: Secondary IP of the NIC.
returned: success
type: string
sample: 10.10.10.10
network:
description: Name of the network if not default.
returned: success
type: string
sample: sync network
domain:
description: Domain the VM is related to.
returned: success
type: string
sample: example domain
account:
description: Account the VM is related to.
returned: success
type: string
sample: example account
project:
description: Name of project the VM is related to.
returned: success
type: string
sample: Production
'''
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.cloudstack import (
AnsibleCloudStack,
cs_argument_spec,
cs_required_together
)
class AnsibleCloudStackInstanceNicSecondaryIp(AnsibleCloudStack):
def __init__(self, module):
super(AnsibleCloudStackInstanceNicSecondaryIp, self).__init__(module)
self.vm_guest_ip = self.module.params.get('vm_guest_ip')
self.nic = None
self.returns = {
'ipaddress': 'ip_address',
'macaddress': 'mac_address',
'netmask': 'netmask',
}
def get_nic(self):
if self.nic:
return self.nic
args = {
'virtualmachineid': self.get_vm(key='id'),
'networkid': self.get_network(key='id'),
}
nics = self.query_api('listNics', **args)
if nics:
self.nic = nics['nic'][0]
return self.nic
self.fail_json(msg="NIC for VM %s in network %s not found" % (self.get_vm(key='name'), self.get_network(key='name')))
def get_secondary_ip(self):
nic = self.get_nic()
if self.vm_guest_ip:
secondary_ips = nic.get('secondaryip') or []
for secondary_ip in secondary_ips:
if secondary_ip['ipaddress'] == self.vm_guest_ip:
return secondary_ip
return None
def present_nic_ip(self):
nic = self.get_nic()
if not self.get_secondary_ip():
self.result['changed'] = True
args = {
'nicid': nic['id'],
'ipaddress': self.vm_guest_ip,
}
if not self.module.check_mode:
res = self.query_api('addIpToNic', **args)
poll_async = self.module.params.get('poll_async')
if poll_async:
nic = self.poll_job(res, 'nicsecondaryip')
# Save result for RETURNS
self.vm_guest_ip = nic['ipaddress']
return nic
def absent_nic_ip(self):
nic = self.get_nic()
secondary_ip = self.get_secondary_ip()
if secondary_ip:
self.result['changed'] = True
if not self.module.check_mode:
res = self.query_api('removeIpFromNic', id=secondary_ip['id'])
poll_async = self.module.params.get('poll_async')
if poll_async:
self.poll_job(res, 'nicsecondaryip')
return nic
def get_result(self, nic):
super(AnsibleCloudStackInstanceNicSecondaryIp, self).get_result(nic)
if nic and not self.module.params.get('network'):
self.module.params['network'] = nic.get('networkid')
self.result['network'] = self.get_network(key='name')
self.result['vm'] = self.get_vm(key='name')
self.result['vm_guest_ip'] = self.vm_guest_ip
return self.result
def main():
argument_spec = cs_argument_spec()
argument_spec.update(dict(
vm=dict(required=True, aliases=['name']),
vm_guest_ip=dict(aliases=['secondary_ip']),
network=dict(),
vpc=dict(),
state=dict(choices=['present', 'absent'], default='present'),
domain=dict(),
account=dict(),
project=dict(),
zone=dict(),
poll_async=dict(type='bool', default=True),
))
module = AnsibleModule(
argument_spec=argument_spec,
required_together=cs_required_together(),
supports_check_mode=True,
required_if=([
('state', 'absent', ['vm_guest_ip'])
])
)
acs_instance_nic_secondaryip = AnsibleCloudStackInstanceNicSecondaryIp(module)
state = module.params.get('state')
if state == 'absent':
nic = acs_instance_nic_secondaryip.absent_nic_ip()
else:
nic = acs_instance_nic_secondaryip.present_nic_ip()
result = acs_instance_nic_secondaryip.get_result(nic)
module.exit_json(**result)
if __name__ == '__main__':
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
334,
67,
9,
9708,
12,
10055,
5741,
3930,
332,
665,
1198,
32,
264,
685,
573,
332,
14,
846,
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,
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,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
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,
1449,
199,
2595,
199,
578,
26,
7117,
63,
842,
63,
12165,
63,
12371,
711,
199,
3612,
63,
1802,
26,
21612,
13851,
30657,
402,
376,
1256,
641,
3668,
8142,
4851,
4079,
2463,
14577,
14,
199,
1802,
26,
272,
446,
2654,
436,
2813,
13851,
30657,
370,
436,
687,
282,
31265,
402,
376,
1256,
14,
199,
1023,
63,
3270,
26,
298,
18,
14,
20,
2,
199,
2502,
26,
298,
5349,
5741,
3930,
332,
8593,
470,
573,
2924,
199,
1419,
26,
523,
4169,
26,
272,
1369,
26,
489,
446,
2812,
402,
1256,
14,
272,
1415,
26,
2549,
272,
5481,
26,
359,
536,
1622,
523,
2784,
26,
272,
1369,
26,
489,
446,
2812,
402,
314,
2784,
14,
489,
446,
11105,
370,
2342,
314,
31265,
340,
1256,
965,
3663,
11759,
7943,
14,
523,
4169,
63,
10409,
63,
711,
26,
272,
1369,
26,
489,
446,
16707,
695,
3531,
2287,
370,
506,
3483,
370,
314,
1256,
14304,
14,
489,
446,
982,
440,
663,
12,
314,
3261,
3544,
2529,
282,
892,
3531,
2287,
436,
9979,
9613,
9447,
365,
440,
1627,
14,
272,
5481,
26,
359,
13851,
63,
711,
1622,
523,
12830,
26,
272,
1369,
26,
489,
446,
2812,
402,
314,
19209,
314,
445,
8,
2611,
9,
365,
4048,
370,
14,
523,
2881,
26,
272,
1369,
26,
489,
446,
14061,
314,
1256,
365,
4048,
370,
14,
523,
2933,
26,
272,
1369,
26,
489,
446,
9973,
314,
1256,
365,
4048,
370,
14,
523,
2199,
26,
272,
1369,
26,
489,
446,
2812,
402,
314,
2199,
314,
1256,
365,
26181,
315,
14,
523,
5718,
26,
272,
1369,
26,
489,
446,
2812,
402,
314,
5718,
315,
1314,
314,
1256,
365,
26181,
315,
14,
489,
446,
982,
440,
663,
12,
849,
5718,
365,
1202,
14,
523,
1174,
26,
272,
1369,
26,
489,
446,
8511,
402,
314,
20617,
14,
272,
849,
26,
3451,
272,
3415,
26,
359,
3451,
12,
9552,
1622,
523,
11271,
63,
4146,
26,
272,
1369,
26,
489,
446,
25306,
5316,
9643,
5133,
3906,
965,
9158,
14,
272,
849,
26,
2549,
199,
11036,
63,
9970,
63,
7677,
26,
8002,
2340,
199,
2344,
199,
199,
8918,
275,
1449,
199,
13,
536,
26,
16927,
282,
2488,
3531,
370,
314,
849,
31265,
402,
314,
7525,
523,
2257,
63,
1287,
26,
272,
859,
26,
7117,
63,
842,
63,
12165,
63,
12371,
711,
272,
4169,
26,
15229,
63,
1702,
272,
4169,
63,
10409,
63,
711,
26,
1616,
14,
709,
14,
709,
14,
709,
199,
199,
3,
3390,
26,
982,
4169,
63,
10409,
63,
711,
365,
440,
663,
12,
1265,
911,
664,
282,
892,
3531,
2287,
641,
4036,
1255,
14,
199,
13,
536,
26,
16927,
376,
3531,
370,
314,
849,
31265,
402,
314,
7525,
523,
2257,
63,
1287,
26,
272,
859,
26,
7117,
63,
842,
63,
12165,
63,
12371,
711,
272,
4169,
26,
15229,
63,
1702,
199,
199,
13,
536,
26,
5852,
282,
2488,
3531,
687,
314,
849,
31265,
523,
2257,
63,
1287,
26,
272,
859,
26,
7117,
63,
842,
63,
12165,
63,
12371,
711,
272,
4169,
26,
15229,
63,
1702,
272,
4169,
63,
10409,
63,
711,
26,
1616,
14,
709,
14,
709,
14,
709,
272,
1174,
26,
9552,
199,
2344,
199,
199,
9677,
275,
1449,
199,
2595,
199,
344,
26,
523,
1369,
26,
11134,
402,
314,
31265,
14,
523,
2138,
26,
3182,
523,
730,
26,
1059,
523,
2690,
26,
10513,
66,
17,
69,
16,
301,
13,
20,
69,
614,
13,
845,
69,
20,
13,
2501,
1272,
13,
25426,
15143,
69,
772,
66,
24,
199,
2611,
26,
523,
1369,
26,
2812,
402,
314,
7525,
14,
523,
2138,
26,
3182,
523,
730,
26,
1059,
523,
2690,
26,
3330,
13,
614,
199,
711,
63,
1562,
26,
523,
1369,
26,
26710,
3531,
402,
314,
31265,
14,
523,
2138,
26,
3182,
523,
730,
26,
1059,
523,
2690,
26,
1616,
14,
709,
14,
709,
14,
709,
199,
14588,
26,
523,
1369,
26,
5365,
2629,
402,
314,
31265,
14,
523,
2138,
26,
3182,
523,
730,
26,
1059,
523,
2690,
26,
5450,
14,
2299,
14,
2299,
14,
16,
199,
3088,
63,
1562,
26,
523,
1369,
26,
13347,
2287,
402,
314,
31265,
14,
523,
2138,
26,
3182,
523,
730,
26,
1059,
523,
2690,
26,
12497,
26,
383,
26,
1153,
26,
2192,
26,
383,
26,
69,
20,
199,
2611,
63,
10409,
63,
711,
26,
523,
1369,
26,
16707,
695,
3531,
402,
314,
31265,
14,
523,
2138,
26,
3182,
523,
730,
26,
1059,
523,
2690,
26,
1616,
14,
709,
14,
709,
14,
709,
199,
1200,
26,
523,
1369,
26,
2812,
402,
314,
2784,
340,
440,
849,
14,
523,
2138,
26,
3182,
523,
730,
26,
1059,
523,
2690,
26,
7604,
2784,
199,
2261,
26,
523,
1369,
26,
14061,
314,
7525,
365,
4048,
370,
14,
523,
2138,
26,
3182,
523,
730,
26,
1059,
523,
2690,
26,
2893,
2881,
199,
2048,
26,
523,
1369,
26,
9973,
314,
7525,
365,
4048,
370,
14,
523,
2138,
26,
3182,
523
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
334,
67,
9,
9708,
12,
10055,
5741,
3930,
332,
665,
1198,
32,
264,
685,
573,
332,
14,
846,
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,
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,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
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,
1449,
199,
2595,
199,
578,
26,
7117,
63,
842,
63,
12165,
63,
12371,
711,
199,
3612,
63,
1802,
26,
21612,
13851,
30657,
402,
376,
1256,
641,
3668,
8142,
4851,
4079,
2463,
14577,
14,
199,
1802,
26,
272,
446,
2654,
436,
2813,
13851,
30657,
370,
436,
687,
282,
31265,
402,
376,
1256,
14,
199,
1023,
63,
3270,
26,
298,
18,
14,
20,
2,
199,
2502,
26,
298,
5349,
5741,
3930,
332,
8593,
470,
573,
2924,
199,
1419,
26,
523,
4169,
26,
272,
1369,
26,
489,
446,
2812,
402,
1256,
14,
272,
1415,
26,
2549,
272,
5481,
26,
359,
536,
1622,
523,
2784,
26,
272,
1369,
26,
489,
446,
2812,
402,
314,
2784,
14,
489,
446,
11105,
370,
2342,
314,
31265,
340,
1256,
965,
3663,
11759,
7943,
14,
523,
4169,
63,
10409,
63,
711,
26,
272,
1369,
26,
489,
446,
16707,
695,
3531,
2287,
370,
506,
3483,
370,
314,
1256,
14304,
14,
489,
446,
982,
440,
663,
12,
314,
3261,
3544,
2529,
282,
892,
3531,
2287,
436,
9979,
9613,
9447,
365,
440,
1627,
14,
272,
5481,
26,
359,
13851,
63,
711,
1622,
523,
12830,
26,
272,
1369,
26,
489,
446,
2812,
402,
314,
19209,
314,
445,
8,
2611,
9,
365,
4048,
370,
14,
523,
2881,
26,
272,
1369,
26,
489,
446,
14061,
314,
1256,
365,
4048,
370,
14,
523,
2933,
26,
272,
1369,
26,
489,
446,
9973,
314,
1256,
365,
4048,
370,
14,
523,
2199,
26,
272,
1369,
26,
489,
446,
2812,
402,
314,
2199,
314,
1256,
365,
26181,
315,
14,
523,
5718,
26,
272,
1369,
26,
489,
446,
2812,
402,
314,
5718,
315,
1314,
314,
1256,
365,
26181,
315,
14,
489,
446,
982,
440,
663,
12,
849,
5718,
365,
1202,
14,
523,
1174,
26,
272,
1369,
26,
489,
446,
8511,
402,
314,
20617,
14,
272,
849,
26,
3451,
272,
3415,
26,
359,
3451,
12,
9552,
1622,
523,
11271,
63,
4146,
26,
272,
1369,
26,
489,
446,
25306,
5316,
9643,
5133,
3906,
965,
9158,
14,
272,
849,
26,
2549,
199,
11036,
63,
9970,
63,
7677,
26,
8002,
2340,
199,
2344,
199,
199,
8918,
275,
1449,
199,
13,
536,
26,
16927,
282,
2488,
3531,
370,
314,
849,
31265,
402,
314,
7525,
523,
2257,
63,
1287,
26,
272,
859,
26,
7117,
63,
842,
63,
12165,
63,
12371,
711,
272,
4169,
26,
15229,
63,
1702,
272,
4169,
63,
10409,
63,
711,
26,
1616,
14,
709,
14,
709,
14,
709,
199,
199,
3,
3390,
26,
982,
4169,
63,
10409,
63,
711,
365,
440,
663,
12,
1265,
911,
664,
282,
892,
3531,
2287,
641,
4036,
1255,
14,
199,
13,
536,
26,
16927,
376,
3531,
370,
314,
849,
31265,
402,
314,
7525,
523,
2257,
63,
1287,
26,
272,
859,
26,
7117,
63,
842,
63,
12165,
63,
12371,
711,
272,
4169,
26,
15229,
63,
1702,
199,
199,
13,
536,
26,
5852,
282,
2488,
3531,
687,
314,
849,
31265,
523,
2257,
63,
1287,
26,
272,
859,
26,
7117,
63,
842,
63,
12165,
63,
12371,
711,
272,
4169,
26,
15229,
63,
1702,
272,
4169,
63,
10409,
63,
711,
26,
1616,
14,
709,
14,
709,
14,
709,
272,
1174,
26,
9552,
199,
2344,
199,
199,
9677,
275,
1449,
199,
2595,
199,
344,
26,
523,
1369,
26,
11134,
402,
314,
31265,
14,
523,
2138,
26,
3182,
523,
730,
26,
1059,
523,
2690,
26,
10513,
66,
17,
69,
16,
301,
13,
20,
69,
614,
13,
845,
69,
20,
13,
2501,
1272,
13,
25426,
15143,
69,
772,
66,
24,
199,
2611,
26,
523,
1369,
26,
2812,
402,
314,
7525,
14,
523,
2138,
26,
3182,
523,
730,
26,
1059,
523,
2690,
26,
3330,
13,
614,
199,
711,
63,
1562,
26,
523,
1369,
26,
26710,
3531,
402,
314,
31265,
14,
523,
2138,
26,
3182,
523,
730,
26,
1059,
523,
2690,
26,
1616,
14,
709,
14,
709,
14,
709,
199,
14588,
26,
523,
1369,
26,
5365,
2629,
402,
314,
31265,
14,
523,
2138,
26,
3182,
523,
730,
26,
1059,
523,
2690,
26,
5450,
14,
2299,
14,
2299,
14,
16,
199,
3088,
63,
1562,
26,
523,
1369,
26,
13347,
2287,
402,
314,
31265,
14,
523,
2138,
26,
3182,
523,
730,
26,
1059,
523,
2690,
26,
12497,
26,
383,
26,
1153,
26,
2192,
26,
383,
26,
69,
20,
199,
2611,
63,
10409,
63,
711,
26,
523,
1369,
26,
16707,
695,
3531,
402,
314,
31265,
14,
523,
2138,
26,
3182,
523,
730,
26,
1059,
523,
2690,
26,
1616,
14,
709,
14,
709,
14,
709,
199,
1200,
26,
523,
1369,
26,
2812,
402,
314,
2784,
340,
440,
849,
14,
523,
2138,
26,
3182,
523,
730,
26,
1059,
523,
2690,
26,
7604,
2784,
199,
2261,
26,
523,
1369,
26,
14061,
314,
7525,
365,
4048,
370,
14,
523,
2138,
26,
3182,
523,
730,
26,
1059,
523,
2690,
26,
2893,
2881,
199,
2048,
26,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
diox/zamboni
|
mkt/extensions/validation.py
|
5
|
10727
|
import imghdr
import json
from cStringIO import StringIO
from zipfile import BadZipfile
from django.forms import ValidationError
from django.utils.encoding import smart_unicode
from PIL import Image
from django.utils.translation import ugettext as _
from mkt.api.exceptions import ParseError
from mkt.files.utils import SafeUnzip
from mkt.site.utils import strip_bom
class ExtensionValidator(object):
"""
Firefox OS Add-on validator. If validation fails, will raise an instance of
rest_framework.exceptions.ParseError containing information about the
error.
"""
errors = {
'AUTHOR_NOT_STRING': _(u'The `author` property must be a string.'),
'AUTHOR_TOO_LONG': _(
u'The `author` property cannot be longer than 128 characters.'),
'AUTHOR_TOO_SHORT': _(
u'The `author` property must be at least 1 character'
u' long and can not consist of only whitespace characters.'),
'BAD_CONTENT_TYPE': _(
u'The file sent has an unsupported content-type'),
'DESCRIPTION_NOT_STRING': _(
u'The `description` property must be a string.'),
'DESCRIPTION_TOO_LONG': _(
u'The `description` property cannot be '
u'longer than 132 characters.'),
'ICON_INCORRECT_DIMENSIONS': _(
u'The icon file `%(icon_path)s` is not the specified dimensions '
u'of %(icon_size)s x %(icon_size)s as defined in the manifest.'),
'ICON_DOES_NOT_EXIST': _(
u'The icon file `%(icon_path)s` is referenced in the manifest but'
u' does not exist in the ZIP file.'),
'ICONS_NO_128': _(
u'If defining `icons`, you must include a 128x128 variant.'),
'ICON_NOT_A_VALID_IMAGE_OR_PNG': _(
u'The icon file `%s` is not a valid PNG.'),
'ICON_NOT_SQUARE': _(
u'The icon file `%(icon_path)s` is not square.'),
'ICON_INVALID_SIZE': _(
u'The manifest contains an invalid icon size: %(icon_size)s'),
'INVALID_JSON': _(
u"'manifest.json' in the archive is not a valid JSON"
u" file."),
'INVALID_JSON_ENCODING': _(
u"'manifest.json' in the archive is not encoded in UTF-8."),
'INVALID_ZIP': _(u'The file sent is not a valid ZIP file.'),
'NAME_MISSING': _(u'There is no `name` property in the manifest.'),
'NAME_NOT_STRING': _(u'The `name` property must be a string.'),
'NAME_TOO_LONG': _(
u'The `name` property cannot be longer than 45 '
u'characters.'),
'NAME_TOO_SHORT': _(
u'The `name` property must be at least 1 character'
u' long and can not consist of only whitespace characters.'),
'NO_MANIFEST': _(
u"The archive does not contain a 'manifest.json' "
u"file."),
'VERSION_MISSING': _(
u'There is no `version` property in the manifest.'),
'VERSION_NOT_STRING': _(u'The `version` property must be a string.'),
'VERSION_INVALID': _(
u'The `version` property must be a string'
u' containing one to four dot-separated integers each between'
u' 0 and 65535.'),
}
valid_content_types = (
'application/octet-stream',
'application/zip',
)
def __init__(self, file_obj=None):
self.file_obj = file_obj
self.zipfile = None
def error(self, key, **kwargs):
message = self.errors[key]
if kwargs:
message = self.errors[key] % kwargs
raise ParseError(detail={
'key': key,
'message': message,
'params': kwargs,
})
def validate(self):
"""
Run the full validation suite against the uploaded file:
* Ensure that it is a valid zip file.
* Ensure that it contains a valid manifest.json file.
* Validate the manifest fields against the spec.
Return the manifest contents (as dict).
"""
self.manifest = self.validate_file(self.file_obj)
self.data = self.validate_json(self.manifest)
self.validate_name(self.data)
self.validate_description(self.data)
self.validate_version(self.data)
self.validate_author(self.data)
self.validate_icons(self.data)
return self.data
def validate_file(self, file_obj):
"""
Verify that the upload is a valid zip file that contains a
manifest.json file.
"""
if file_obj.content_type not in self.valid_content_types:
self.error('BAD_CONTENT_TYPE')
try:
self.zipfile = SafeUnzip(file_obj)
try:
# Will throw ValidationError if necessary.
self.zipfile.is_valid()
except ValidationError as e:
raise ParseError(unicode(e))
except (BadZipfile, IOError):
self.error('INVALID_ZIP')
manifest = self.zipfile.extract_path('manifest.json')
except KeyError:
self.error('NO_MANIFEST')
return manifest
def validate_json(self, contents):
"""
Verify that the enclosed manifest.json is a valid and parsable JSON
file.
"""
try:
# We support only UTF-8 encoded manifests.
decoded_data = smart_unicode(strip_bom(contents))
except UnicodeDecodeError:
self.error('INVALID_JSON_ENCODING')
try:
return json.loads(decoded_data)
except ValueError:
self.error('INVALID_JSON')
def validate_name(self, manifest_json):
"""
Ensure that the name property of the manifest exists and is a string
between 1 and 45 characters long.
In addition, even though it's allowed in the spec, we consider the name
invalid (too short) if it contains only whitespace characters.
https://developer.chrome.com/extensions/manifest/name
"""
try:
name = manifest_json['name']
except KeyError:
self.error('NAME_MISSING')
if not isinstance(name, basestring):
self.error('NAME_NOT_STRING')
if len(name.strip()) < 1:
self.error('NAME_TOO_SHORT')
if len(name) > 45:
self.error('NAME_TOO_LONG')
def validate_description(self, manifest_json):
"""
Ensures that, if present, the description property is no longer than
132 characters.
https://developer.chrome.com/extensions/manifest/description
"""
if 'description' in manifest_json:
description = manifest_json['description']
if not isinstance(description, basestring):
self.error('DESCRIPTION_NOT_STRING')
if len(description.strip()) > 132:
self.error('DESCRIPTION_TOO_LONG')
def validate_version(self, manifest_json):
"""
Ensure that the version property of the manifest exists and is a string
containing one to four dot-separated integers, each between 0 and
65535, with no leading zeros."""
try:
version = manifest_json['version']
except KeyError:
self.error('VERSION_MISSING')
if not isinstance(version, basestring):
self.error('VERSION_NOT_STRING')
splitted = version.split('.')
if len(splitted) > 4:
# Too many dots.
self.error('VERSION_INVALID')
for version_component in splitted:
try:
number = int(version_component)
if version_component.startswith('0') and number != 0:
# Leading zeros are forbidden.
self.error('VERSION_INVALID')
if number < 0 or number > 65535:
# All numbers must be between 0 and 65535 inclusive.
self.error('VERSION_INVALID')
except ValueError:
# Not a valid number.
self.error('VERSION_INVALID')
def validate_author(self, manifest_json):
"""
Ensures that, if present, the author property is no longer than
128 characters.
"""
if 'author' in manifest_json:
author = manifest_json['author']
# Author must not be empty/only whitespace if present, since we'll
# use it as link text.
if not isinstance(author, basestring):
self.error('AUTHOR_NOT_STRING')
if len(author.strip()) < 1:
self.error('AUTHOR_TOO_SHORT')
if len(author) > 128:
self.error('AUTHOR_TOO_LONG')
def validate_icons(self, manifest_json):
"""
Validate the `icons` property in the manifest:
* Ensure that, if the icons property is present, a 128px icon is
provided.
* Ensure that each icon size is a valid integer.
* Ensure that each icon file is valid by calling _validate_icon_file().
"""
icons = manifest_json.get('icons', {})
if icons:
if '128' not in icons:
self.error('ICONS_NO_128')
for icon_size, icon_path in icons.iteritems():
try:
icon_size = int(icon_size)
if icon_size <= 0:
raise ValueError
except ValueError:
self.error(
'ICON_INVALID_SIZE', icon_size=unicode(icon_size))
self._validate_icon_file(icon_path, icon_size)
def _validate_icon_file(self, icon_path, icon_size):
"""
Validate a specific icon path referenced in the manifest:
* Ensure that the file exists in the zip.
* Ensure that it is a valid PNG file.
* Ensure that it is square.
* Ensure that it has the claimed dimensions.
"""
try:
icon_contents = self.zipfile.extract_path(icon_path.lstrip('/'))
except KeyError:
self.error('ICON_DOES_NOT_EXIST', icon_path=icon_path)
try:
if imghdr.what(None, icon_contents) != 'png':
raise IOError
image = Image.open(StringIO(icon_contents))
except IOError:
self.error('ICON_NOT_A_VALID_IMAGE_OR_PNG',
icon_path=icon_path)
if image.size[0] != image.size[1]:
self.error('ICON_NOT_SQUARE', icon_path=icon_path)
if icon_size != image.size[0]:
self.error('ICON_INCORRECT_DIMENSIONS',
icon_path=icon_path, icon_size=icon_size)
|
bsd-3-clause
|
[
646,
3416,
3561,
5012,
199,
646,
2022,
199,
504,
15073,
492,
5228,
199,
504,
10392,
492,
8857,
8674,
493,
199,
199,
504,
1639,
14,
3351,
492,
8505,
199,
504,
1639,
14,
1208,
14,
2991,
492,
11179,
63,
2975,
199,
199,
504,
14937,
492,
6047,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
465,
485,
199,
199,
504,
21825,
14,
1246,
14,
3924,
492,
21743,
199,
504,
21825,
14,
1725,
14,
1208,
492,
14969,
1358,
3065,
199,
504,
21825,
14,
2124,
14,
1208,
492,
6202,
63,
16302,
421,
199,
533,
13282,
8640,
8,
785,
304,
272,
408,
272,
24584,
4403,
2654,
13,
265,
11822,
14,
982,
6411,
6918,
12,
911,
746,
376,
1256,
402,
272,
4618,
63,
4857,
14,
3924,
14,
9123,
3035,
2556,
3595,
314,
272,
1125,
14,
272,
408,
272,
2552,
275,
469,
267,
283,
27938,
63,
4609,
63,
5353,
356,
12561,
85,
7,
1918,
658,
2502,
64,
3324,
1471,
506,
282,
1059,
8038,
267,
283,
27938,
63,
30947,
63,
12375,
356,
12561,
288,
399,
7,
1918,
658,
2502,
64,
3324,
3913,
506,
8088,
2419,
7960,
4110,
8038,
267,
283,
27938,
63,
30947,
63,
13003,
356,
12561,
288,
399,
7,
1918,
658,
2502,
64,
3324,
1471,
506,
737,
5210,
413,
4528,
7,
288,
399,
7,
1846,
436,
883,
440,
17568,
402,
1454,
8139,
4110,
8038,
267,
283,
9439,
63,
9663,
63,
2711,
356,
12561,
288,
399,
7,
1918,
570,
4847,
965,
376,
16313,
1564,
13,
466,
659,
267,
283,
17705,
63,
4609,
63,
5353,
356,
12561,
288,
399,
7,
1918,
658,
1802,
64,
3324,
1471,
506,
282,
1059,
8038,
267,
283,
17705,
63,
30947,
63,
12375,
356,
12561,
288,
399,
7,
1918,
658,
1802,
64,
3324,
3913,
506,
283,
288,
399,
7,
5298,
836,
2419,
27207,
4110,
8038,
267,
283,
15903,
63,
568,
31704,
63,
19080,
17427,
356,
12561,
288,
399,
7,
1918,
7016,
570,
658,
2840,
4677,
63,
515,
9,
83,
64,
365,
440,
314,
2013,
7365,
283,
288,
399,
7,
1618,
2818,
4677,
63,
890,
9,
83,
671,
2818,
4677,
63,
890,
9,
83,
465,
3247,
315,
314,
7712,
8038,
267,
283,
15903,
63,
1649,
654,
63,
4609,
63,
13301,
356,
12561,
288,
399,
7,
1918,
7016,
570,
658,
2840,
4677,
63,
515,
9,
83,
64,
365,
11812,
315,
314,
7712,
1325,
7,
288,
399,
7,
1630,
440,
2187,
315,
314,
18402,
570,
8038,
267,
283,
15903,
51,
63,
2826,
63,
3933,
356,
12561,
288,
399,
7,
3917,
12669,
658,
16471,
3559,
1265,
1471,
2387,
282,
7960,
88,
3933,
9854,
8038,
267,
283,
15903,
63,
4609,
63,
33,
63,
5600,
63,
9438,
63,
726,
63,
24454,
356,
12561,
288,
399,
7,
1918,
7016,
570,
18633,
83,
64,
365,
440,
282,
1686,
26951,
8038,
267,
283,
15903,
63,
4609,
63,
51,
14424,
356,
12561,
288,
399,
7,
1918,
7016,
570,
658,
2840,
4677,
63,
515,
9,
83,
64,
365,
440,
12386,
8038,
267,
283,
15903,
63,
9692,
63,
4305,
356,
12561,
288,
399,
7,
1918,
7712,
3509,
376,
3866,
7016,
1568,
26,
2818,
4677,
63,
890,
9,
83,
659,
267,
283,
9692,
63,
6243,
356,
12561,
288,
399,
4507,
6418,
14,
1001,
7,
315,
314,
6359,
365,
440,
282,
1686,
4840,
2,
288,
399,
2,
570,
7651,
267,
283,
9692,
63,
6243,
63,
16314,
356,
12561,
288,
399,
4507,
6418,
14,
1001,
7,
315,
314,
6359,
365,
440,
5737,
315,
9094,
13,
24,
7651,
267,
283,
9692,
63,
16977,
356,
12561,
85,
7,
1918,
570,
4847,
365,
440,
282,
1686,
18402,
570,
8038,
267,
283,
2339,
63,
18701,
356,
12561,
85,
7,
10924,
365,
949,
658,
354,
64,
3324,
315,
314,
7712,
8038,
267,
283,
2339,
63,
4609,
63,
5353,
356,
12561,
85,
7,
1918,
658,
354,
64,
3324,
1471,
506,
282,
1059,
8038,
267,
283,
2339,
63,
30947,
63,
12375,
356,
12561,
288,
399,
7,
1918,
658,
354,
64,
3324,
3913,
506,
8088,
2419,
10416,
283,
288,
399,
7,
16516,
8038,
267,
283,
2339,
63,
30947,
63,
13003,
356,
12561,
288,
399,
7,
1918,
658,
354,
64,
3324,
1471,
506,
737,
5210,
413,
4528,
7,
288,
399,
7,
1846,
436,
883,
440,
17568,
402,
1454,
8139,
4110,
8038,
267,
283,
2826,
63,
24067,
356,
12561,
288,
399,
2,
1918,
6359,
1630,
440,
1395,
282,
283,
6418,
14,
1001,
7,
298,
288,
399,
2,
493,
7651,
267,
283,
4612,
63,
18701,
356,
12561,
288,
399,
7,
10924,
365,
949,
658,
1023,
64,
3324,
315,
314,
7712,
8038,
267,
283,
4612,
63,
4609,
63,
5353,
356,
12561,
85,
7,
1918,
658,
1023,
64,
3324,
1471,
506,
282,
1059,
8038,
267,
283,
4612,
63,
9692,
356,
12561,
288,
399,
7,
1918,
658,
1023,
64,
3324,
1471,
506,
282,
1059,
7,
288,
399,
7,
3035,
1373,
370,
11648,
6308,
13,
12794,
9446,
1924,
3382,
7,
288,
399,
7,
378,
436,
18247,
8038,
272,
789,
272,
1686,
63,
1317,
63,
1313,
275,
334,
267,
283,
3578,
15,
18162,
13,
1745,
297,
267,
283,
3578,
15,
3065,
297,
272,
776,
339,
347,
636,
826,
721,
277,
12,
570,
63,
1113,
29,
403,
304,
267,
291,
14,
493,
63,
1113,
275,
570,
63,
1113,
267,
291,
14,
18717,
275,
488,
339,
347,
1125,
8,
277,
12,
790,
12,
1011,
958,
304,
267,
1245,
275,
291,
14,
2550,
59,
498,
61,
267,
340,
2074,
26,
288,
1245,
275,
291,
14,
2550,
59,
498,
61,
450,
2074,
267,
746,
21743,
8,
5506,
3126,
288,
283,
498,
356,
790,
12,
288,
283,
1188,
356,
1245,
12,
288,
283,
1162,
356,
2074,
12,
267,
3828,
339,
347,
4107,
8,
277,
304,
267,
408,
267,
3378,
314,
2615,
6411,
5241,
6169,
314,
14238,
570,
26,
398,
627,
7523,
626,
652,
365,
282,
1686,
3482,
570,
14,
267,
627,
7523,
626,
652,
3509,
282,
1686,
7712,
14,
1001,
570,
14,
267,
627,
12134,
314,
7712,
1504,
6169,
314,
3158,
14,
398,
1432,
314,
7712,
4072,
334,
305,
1211,
680,
267,
408,
267,
291,
14,
6418,
275,
291,
14,
3502,
63,
493,
8,
277,
14,
493,
63,
1113,
9,
267,
291,
14,
576,
275,
291,
14,
3502,
63,
1001,
8,
277,
14,
6418,
9,
267,
291,
14,
3502,
63,
354,
8,
277,
14,
576,
9,
267,
291,
14,
3502,
63,
1802,
8,
277,
14
] |
[
3416,
3561,
5012,
199,
646,
2022,
199,
504,
15073,
492,
5228,
199,
504,
10392,
492,
8857,
8674,
493,
199,
199,
504,
1639,
14,
3351,
492,
8505,
199,
504,
1639,
14,
1208,
14,
2991,
492,
11179,
63,
2975,
199,
199,
504,
14937,
492,
6047,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
465,
485,
199,
199,
504,
21825,
14,
1246,
14,
3924,
492,
21743,
199,
504,
21825,
14,
1725,
14,
1208,
492,
14969,
1358,
3065,
199,
504,
21825,
14,
2124,
14,
1208,
492,
6202,
63,
16302,
421,
199,
533,
13282,
8640,
8,
785,
304,
272,
408,
272,
24584,
4403,
2654,
13,
265,
11822,
14,
982,
6411,
6918,
12,
911,
746,
376,
1256,
402,
272,
4618,
63,
4857,
14,
3924,
14,
9123,
3035,
2556,
3595,
314,
272,
1125,
14,
272,
408,
272,
2552,
275,
469,
267,
283,
27938,
63,
4609,
63,
5353,
356,
12561,
85,
7,
1918,
658,
2502,
64,
3324,
1471,
506,
282,
1059,
8038,
267,
283,
27938,
63,
30947,
63,
12375,
356,
12561,
288,
399,
7,
1918,
658,
2502,
64,
3324,
3913,
506,
8088,
2419,
7960,
4110,
8038,
267,
283,
27938,
63,
30947,
63,
13003,
356,
12561,
288,
399,
7,
1918,
658,
2502,
64,
3324,
1471,
506,
737,
5210,
413,
4528,
7,
288,
399,
7,
1846,
436,
883,
440,
17568,
402,
1454,
8139,
4110,
8038,
267,
283,
9439,
63,
9663,
63,
2711,
356,
12561,
288,
399,
7,
1918,
570,
4847,
965,
376,
16313,
1564,
13,
466,
659,
267,
283,
17705,
63,
4609,
63,
5353,
356,
12561,
288,
399,
7,
1918,
658,
1802,
64,
3324,
1471,
506,
282,
1059,
8038,
267,
283,
17705,
63,
30947,
63,
12375,
356,
12561,
288,
399,
7,
1918,
658,
1802,
64,
3324,
3913,
506,
283,
288,
399,
7,
5298,
836,
2419,
27207,
4110,
8038,
267,
283,
15903,
63,
568,
31704,
63,
19080,
17427,
356,
12561,
288,
399,
7,
1918,
7016,
570,
658,
2840,
4677,
63,
515,
9,
83,
64,
365,
440,
314,
2013,
7365,
283,
288,
399,
7,
1618,
2818,
4677,
63,
890,
9,
83,
671,
2818,
4677,
63,
890,
9,
83,
465,
3247,
315,
314,
7712,
8038,
267,
283,
15903,
63,
1649,
654,
63,
4609,
63,
13301,
356,
12561,
288,
399,
7,
1918,
7016,
570,
658,
2840,
4677,
63,
515,
9,
83,
64,
365,
11812,
315,
314,
7712,
1325,
7,
288,
399,
7,
1630,
440,
2187,
315,
314,
18402,
570,
8038,
267,
283,
15903,
51,
63,
2826,
63,
3933,
356,
12561,
288,
399,
7,
3917,
12669,
658,
16471,
3559,
1265,
1471,
2387,
282,
7960,
88,
3933,
9854,
8038,
267,
283,
15903,
63,
4609,
63,
33,
63,
5600,
63,
9438,
63,
726,
63,
24454,
356,
12561,
288,
399,
7,
1918,
7016,
570,
18633,
83,
64,
365,
440,
282,
1686,
26951,
8038,
267,
283,
15903,
63,
4609,
63,
51,
14424,
356,
12561,
288,
399,
7,
1918,
7016,
570,
658,
2840,
4677,
63,
515,
9,
83,
64,
365,
440,
12386,
8038,
267,
283,
15903,
63,
9692,
63,
4305,
356,
12561,
288,
399,
7,
1918,
7712,
3509,
376,
3866,
7016,
1568,
26,
2818,
4677,
63,
890,
9,
83,
659,
267,
283,
9692,
63,
6243,
356,
12561,
288,
399,
4507,
6418,
14,
1001,
7,
315,
314,
6359,
365,
440,
282,
1686,
4840,
2,
288,
399,
2,
570,
7651,
267,
283,
9692,
63,
6243,
63,
16314,
356,
12561,
288,
399,
4507,
6418,
14,
1001,
7,
315,
314,
6359,
365,
440,
5737,
315,
9094,
13,
24,
7651,
267,
283,
9692,
63,
16977,
356,
12561,
85,
7,
1918,
570,
4847,
365,
440,
282,
1686,
18402,
570,
8038,
267,
283,
2339,
63,
18701,
356,
12561,
85,
7,
10924,
365,
949,
658,
354,
64,
3324,
315,
314,
7712,
8038,
267,
283,
2339,
63,
4609,
63,
5353,
356,
12561,
85,
7,
1918,
658,
354,
64,
3324,
1471,
506,
282,
1059,
8038,
267,
283,
2339,
63,
30947,
63,
12375,
356,
12561,
288,
399,
7,
1918,
658,
354,
64,
3324,
3913,
506,
8088,
2419,
10416,
283,
288,
399,
7,
16516,
8038,
267,
283,
2339,
63,
30947,
63,
13003,
356,
12561,
288,
399,
7,
1918,
658,
354,
64,
3324,
1471,
506,
737,
5210,
413,
4528,
7,
288,
399,
7,
1846,
436,
883,
440,
17568,
402,
1454,
8139,
4110,
8038,
267,
283,
2826,
63,
24067,
356,
12561,
288,
399,
2,
1918,
6359,
1630,
440,
1395,
282,
283,
6418,
14,
1001,
7,
298,
288,
399,
2,
493,
7651,
267,
283,
4612,
63,
18701,
356,
12561,
288,
399,
7,
10924,
365,
949,
658,
1023,
64,
3324,
315,
314,
7712,
8038,
267,
283,
4612,
63,
4609,
63,
5353,
356,
12561,
85,
7,
1918,
658,
1023,
64,
3324,
1471,
506,
282,
1059,
8038,
267,
283,
4612,
63,
9692,
356,
12561,
288,
399,
7,
1918,
658,
1023,
64,
3324,
1471,
506,
282,
1059,
7,
288,
399,
7,
3035,
1373,
370,
11648,
6308,
13,
12794,
9446,
1924,
3382,
7,
288,
399,
7,
378,
436,
18247,
8038,
272,
789,
272,
1686,
63,
1317,
63,
1313,
275,
334,
267,
283,
3578,
15,
18162,
13,
1745,
297,
267,
283,
3578,
15,
3065,
297,
272,
776,
339,
347,
636,
826,
721,
277,
12,
570,
63,
1113,
29,
403,
304,
267,
291,
14,
493,
63,
1113,
275,
570,
63,
1113,
267,
291,
14,
18717,
275,
488,
339,
347,
1125,
8,
277,
12,
790,
12,
1011,
958,
304,
267,
1245,
275,
291,
14,
2550,
59,
498,
61,
267,
340,
2074,
26,
288,
1245,
275,
291,
14,
2550,
59,
498,
61,
450,
2074,
267,
746,
21743,
8,
5506,
3126,
288,
283,
498,
356,
790,
12,
288,
283,
1188,
356,
1245,
12,
288,
283,
1162,
356,
2074,
12,
267,
3828,
339,
347,
4107,
8,
277,
304,
267,
408,
267,
3378,
314,
2615,
6411,
5241,
6169,
314,
14238,
570,
26,
398,
627,
7523,
626,
652,
365,
282,
1686,
3482,
570,
14,
267,
627,
7523,
626,
652,
3509,
282,
1686,
7712,
14,
1001,
570,
14,
267,
627,
12134,
314,
7712,
1504,
6169,
314,
3158,
14,
398,
1432,
314,
7712,
4072,
334,
305,
1211,
680,
267,
408,
267,
291,
14,
6418,
275,
291,
14,
3502,
63,
493,
8,
277,
14,
493,
63,
1113,
9,
267,
291,
14,
576,
275,
291,
14,
3502,
63,
1001,
8,
277,
14,
6418,
9,
267,
291,
14,
3502,
63,
354,
8,
277,
14,
576,
9,
267,
291,
14,
3502,
63,
1802,
8,
277,
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,
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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
] |
nightjean/Deep-Learning
|
tensorflow/examples/learn/text_classification_character_rnn.py
|
61
|
3350
|
# Copyright 2016 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""This is an example of using recurrent neural networks over characters for DBpedia dataset to predict class from description of an entity.
This model is similar to one described in this paper:
"Character-level Convolutional Networks for Text Classification"
http://arxiv.org/abs/1509.01626
and is somewhat alternative to the Lua code from here:
https://github.com/zhangxiangxiao/Crepe
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import argparse
import sys
import numpy as np
import pandas
from sklearn import metrics
import tensorflow as tf
learn = tf.contrib.learn
FLAGS = None
MAX_DOCUMENT_LENGTH = 100
HIDDEN_SIZE = 20
def char_rnn_model(features, target):
"""Character level recurrent neural network model to predict classes."""
target = tf.one_hot(target, 15, 1, 0)
byte_list = tf.one_hot(features, 256, 1, 0)
byte_list = tf.unstack(byte_list, axis=1)
cell = tf.contrib.rnn.GRUCell(HIDDEN_SIZE)
_, encoding = tf.contrib.rnn.static_rnn(cell, byte_list, dtype=tf.float32)
logits = tf.contrib.layers.fully_connected(encoding, 15, activation_fn=None)
loss = tf.contrib.losses.softmax_cross_entropy(logits, target)
train_op = tf.contrib.layers.optimize_loss(
loss,
tf.contrib.framework.get_global_step(),
optimizer='Adam',
learning_rate=0.01)
return ({
'class': tf.argmax(logits, 1),
'prob': tf.nn.softmax(logits)
}, loss, train_op)
def main(unused_argv):
# Prepare training and testing data
dbpedia = learn.datasets.load_dataset(
'dbpedia', test_with_fake_data=FLAGS.test_with_fake_data)
x_train = pandas.DataFrame(dbpedia.train.data)[1]
y_train = pandas.Series(dbpedia.train.target)
x_test = pandas.DataFrame(dbpedia.test.data)[1]
y_test = pandas.Series(dbpedia.test.target)
# Process vocabulary
char_processor = learn.preprocessing.ByteProcessor(MAX_DOCUMENT_LENGTH)
x_train = np.array(list(char_processor.fit_transform(x_train)))
x_test = np.array(list(char_processor.transform(x_test)))
# Build model
classifier = learn.Estimator(model_fn=char_rnn_model)
# Train and predict
classifier.fit(x_train, y_train, steps=100)
y_predicted = [
p['class'] for p in classifier.predict(
x_test, as_iterable=True)
]
score = metrics.accuracy_score(y_test, y_predicted)
print('Accuracy: {0:f}'.format(score))
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument(
'--test_with_fake_data',
default=False,
help='Test the example code with fake data.',
action='store_true')
FLAGS, unparsed = parser.parse_known_args()
tf.app.run(main=main, argv=[sys.argv[0]] + unparsed)
|
apache-2.0
|
[
3,
221,
1898,
7800,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
221,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
221,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
221,
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,
221,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
221,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
221,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
221,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
221,
4204,
1334,
314,
844,
14,
199,
624,
2765,
365,
376,
2893,
402,
1808,
295,
1818,
1279,
4889,
11759,
1806,
4110,
367,
6249,
321,
2391,
4789,
370,
12610,
1021,
687,
1369,
402,
376,
4642,
14,
199,
199,
2765,
1402,
365,
8545,
370,
1373,
11736,
315,
642,
15220,
26,
2043,
298,
14852,
13,
1896,
19140,
3347,
279,
17138,
367,
4516,
8465,
7789,
2,
2043,
1455,
921,
27290,
14,
1308,
15,
2101,
15,
1046,
1643,
14,
10882,
1479,
199,
199,
460,
365,
30362,
13943,
370,
314,
491,
1458,
1233,
687,
2348,
26,
2043,
4178,
921,
5031,
14,
957,
15,
3951,
621,
6865,
621,
88,
18939,
15,
35,
5028,
199,
624,
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,
7534,
199,
646,
984,
199,
199,
646,
2680,
465,
980,
199,
646,
10634,
199,
504,
6357,
492,
7186,
199,
646,
3228,
465,
2833,
199,
199,
4643,
275,
2833,
14,
2828,
14,
4643,
199,
199,
4831,
275,
488,
199,
199,
4283,
63,
7884,
63,
9127,
275,
2948,
199,
40,
22436,
63,
4305,
275,
3388,
421,
199,
318,
1495,
63,
12845,
63,
1238,
8,
3179,
12,
1347,
304,
523,
408,
14852,
2166,
295,
1818,
1279,
4889,
2784,
1402,
370,
12610,
3992,
1041,
523,
1347,
275,
2833,
14,
368,
63,
8885,
8,
1375,
12,
4114,
12,
413,
12,
378,
9,
523,
3696,
63,
513,
275,
2833,
14,
368,
63,
8885,
8,
3179,
12,
7633,
12,
413,
12,
378,
9,
523,
3696,
63,
513,
275,
2833,
14,
324,
2340,
8,
4414,
63,
513,
12,
3114,
29,
17,
9,
819,
4917,
275,
2833,
14,
2828,
14,
12845,
14,
3975,
53,
8108,
8,
40,
22436,
63,
4305,
9,
523,
5501,
2644,
275,
2833,
14,
2828,
14,
12845,
14,
1986,
63,
12845,
8,
3890,
12,
3696,
63,
513,
12,
2152,
29,
3249,
14,
1609,
708,
9,
819,
11051,
275,
2833,
14,
2828,
14,
4359,
14,
5836,
63,
7113,
8,
2991,
12,
4114,
12,
10361,
63,
2324,
29,
403,
9,
523,
5621,
275,
2833,
14,
2828,
14,
17865,
14,
16395,
63,
7925,
63,
10435,
8,
10492,
12,
1347,
9,
819,
3560,
63,
411,
275,
2833,
14,
2828,
14,
4359,
14,
13416,
63,
4358,
8,
489,
5621,
12,
489,
2833,
14,
2828,
14,
4857,
14,
362,
63,
2966,
63,
2926,
1062,
489,
10736,
534,
32408,
297,
489,
9328,
63,
1866,
29,
16,
14,
614,
9,
819,
372,
11459,
489,
283,
533,
356,
2833,
14,
16383,
8,
10492,
12,
413,
395,
489,
283,
6101,
356,
2833,
14,
4411,
14,
16395,
8,
10492,
9,
523,
1660,
5621,
12,
3560,
63,
411,
9,
421,
199,
318,
2446,
8,
8618,
63,
3020,
304,
523,
327,
17008,
6093,
436,
5343,
666,
523,
1592,
321,
2391,
275,
12537,
14,
12281,
14,
912,
63,
5214,
8,
489,
283,
697,
321,
2391,
297,
511,
63,
1045,
63,
3183,
63,
576,
29,
4831,
14,
396,
63,
1045,
63,
3183,
63,
576,
9,
523,
671,
63,
2834,
275,
10634,
14,
9205,
8,
697,
321,
2391,
14,
2834,
14,
576,
2788,
17,
61,
523,
612,
63,
2834,
275,
10634,
14,
9641,
8,
697,
321,
2391,
14,
2834,
14,
1375,
9,
523,
671,
63,
396,
275,
10634,
14,
9205,
8,
697,
321,
2391,
14,
396,
14,
576,
2788,
17,
61,
523,
612,
63,
396,
275,
10634,
14,
9641,
8,
697,
321,
2391,
14,
396,
14,
1375,
9,
819,
327,
7132,
17515,
523,
1495,
63,
6459,
275,
12537,
14,
21402,
14,
4861,
10438,
8,
4283,
63,
7884,
63,
9127,
9,
523,
671,
63,
2834,
275,
980,
14,
1144,
8,
513,
8,
1560,
63,
6459,
14,
3269,
63,
4711,
8,
88,
63,
2834,
1724,
523,
671,
63,
396,
275,
980,
14,
1144,
8,
513,
8,
1560,
63,
6459,
14,
4711,
8,
88,
63,
396,
1724,
819,
327,
6516,
1402,
523,
12429,
275,
12537,
14,
13183,
8,
1238,
63,
2324,
29,
1560,
63,
12845,
63,
1238,
9,
819,
327,
16732,
436,
12610,
523,
12429,
14,
3269,
8,
88,
63,
2834,
12,
612,
63,
2834,
12,
7124,
29,
1960,
9,
523,
612,
63,
21118,
275,
359,
489,
299,
459,
533,
418,
367,
299,
315,
12429,
14,
6892,
8,
881,
671,
63,
396,
12,
465,
63,
8147,
29,
549,
9,
523,
1622,
523,
5396,
275,
7186,
14,
13374,
63,
3397,
8,
89,
63,
396,
12,
612,
63,
21118,
9,
523,
870,
360,
1945,
7933,
26,
469,
16,
26,
70,
5285,
908,
8,
3397,
430,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
1798,
275,
7534,
14,
10730,
342,
523,
1798,
14,
525,
63,
2094,
8,
489,
2850,
396,
63,
1045,
63,
3183,
63,
576,
297,
489,
849,
29,
797,
12,
489,
1720,
534,
774,
314,
2893,
1233,
543,
4026,
666,
3130,
489,
1595,
534,
1617,
63,
2052,
358,
523,
12846,
12,
31857,
275,
1798,
14,
1122,
63,
3159,
63,
589,
342,
523,
2833,
14,
571,
14,
1065,
8,
973,
29,
973,
12,
9238,
1524,
1274,
14,
3020,
59,
16,
2677,
435,
31857,
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
] |
[
221,
1898,
7800,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
221,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
221,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
221,
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,
221,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
221,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
221,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
221,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
221,
4204,
1334,
314,
844,
14,
199,
624,
2765,
365,
376,
2893,
402,
1808,
295,
1818,
1279,
4889,
11759,
1806,
4110,
367,
6249,
321,
2391,
4789,
370,
12610,
1021,
687,
1369,
402,
376,
4642,
14,
199,
199,
2765,
1402,
365,
8545,
370,
1373,
11736,
315,
642,
15220,
26,
2043,
298,
14852,
13,
1896,
19140,
3347,
279,
17138,
367,
4516,
8465,
7789,
2,
2043,
1455,
921,
27290,
14,
1308,
15,
2101,
15,
1046,
1643,
14,
10882,
1479,
199,
199,
460,
365,
30362,
13943,
370,
314,
491,
1458,
1233,
687,
2348,
26,
2043,
4178,
921,
5031,
14,
957,
15,
3951,
621,
6865,
621,
88,
18939,
15,
35,
5028,
199,
624,
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,
7534,
199,
646,
984,
199,
199,
646,
2680,
465,
980,
199,
646,
10634,
199,
504,
6357,
492,
7186,
199,
646,
3228,
465,
2833,
199,
199,
4643,
275,
2833,
14,
2828,
14,
4643,
199,
199,
4831,
275,
488,
199,
199,
4283,
63,
7884,
63,
9127,
275,
2948,
199,
40,
22436,
63,
4305,
275,
3388,
421,
199,
318,
1495,
63,
12845,
63,
1238,
8,
3179,
12,
1347,
304,
523,
408,
14852,
2166,
295,
1818,
1279,
4889,
2784,
1402,
370,
12610,
3992,
1041,
523,
1347,
275,
2833,
14,
368,
63,
8885,
8,
1375,
12,
4114,
12,
413,
12,
378,
9,
523,
3696,
63,
513,
275,
2833,
14,
368,
63,
8885,
8,
3179,
12,
7633,
12,
413,
12,
378,
9,
523,
3696,
63,
513,
275,
2833,
14,
324,
2340,
8,
4414,
63,
513,
12,
3114,
29,
17,
9,
819,
4917,
275,
2833,
14,
2828,
14,
12845,
14,
3975,
53,
8108,
8,
40,
22436,
63,
4305,
9,
523,
5501,
2644,
275,
2833,
14,
2828,
14,
12845,
14,
1986,
63,
12845,
8,
3890,
12,
3696,
63,
513,
12,
2152,
29,
3249,
14,
1609,
708,
9,
819,
11051,
275,
2833,
14,
2828,
14,
4359,
14,
5836,
63,
7113,
8,
2991,
12,
4114,
12,
10361,
63,
2324,
29,
403,
9,
523,
5621,
275,
2833,
14,
2828,
14,
17865,
14,
16395,
63,
7925,
63,
10435,
8,
10492,
12,
1347,
9,
819,
3560,
63,
411,
275,
2833,
14,
2828,
14,
4359,
14,
13416,
63,
4358,
8,
489,
5621,
12,
489,
2833,
14,
2828,
14,
4857,
14,
362,
63,
2966,
63,
2926,
1062,
489,
10736,
534,
32408,
297,
489,
9328,
63,
1866,
29,
16,
14,
614,
9,
819,
372,
11459,
489,
283,
533,
356,
2833,
14,
16383,
8,
10492,
12,
413,
395,
489,
283,
6101,
356,
2833,
14,
4411,
14,
16395,
8,
10492,
9,
523,
1660,
5621,
12,
3560,
63,
411,
9,
421,
199,
318,
2446,
8,
8618,
63,
3020,
304,
523,
327,
17008,
6093,
436,
5343,
666,
523,
1592,
321,
2391,
275,
12537,
14,
12281,
14,
912,
63,
5214,
8,
489,
283,
697,
321,
2391,
297,
511,
63,
1045,
63,
3183,
63,
576,
29,
4831,
14,
396,
63,
1045,
63,
3183,
63,
576,
9,
523,
671,
63,
2834,
275,
10634,
14,
9205,
8,
697,
321,
2391,
14,
2834,
14,
576,
2788,
17,
61,
523,
612,
63,
2834,
275,
10634,
14,
9641,
8,
697,
321,
2391,
14,
2834,
14,
1375,
9,
523,
671,
63,
396,
275,
10634,
14,
9205,
8,
697,
321,
2391,
14,
396,
14,
576,
2788,
17,
61,
523,
612,
63,
396,
275,
10634,
14,
9641,
8,
697,
321,
2391,
14,
396,
14,
1375,
9,
819,
327,
7132,
17515,
523,
1495,
63,
6459,
275,
12537,
14,
21402,
14,
4861,
10438,
8,
4283,
63,
7884,
63,
9127,
9,
523,
671,
63,
2834,
275,
980,
14,
1144,
8,
513,
8,
1560,
63,
6459,
14,
3269,
63,
4711,
8,
88,
63,
2834,
1724,
523,
671,
63,
396,
275,
980,
14,
1144,
8,
513,
8,
1560,
63,
6459,
14,
4711,
8,
88,
63,
396,
1724,
819,
327,
6516,
1402,
523,
12429,
275,
12537,
14,
13183,
8,
1238,
63,
2324,
29,
1560,
63,
12845,
63,
1238,
9,
819,
327,
16732,
436,
12610,
523,
12429,
14,
3269,
8,
88,
63,
2834,
12,
612,
63,
2834,
12,
7124,
29,
1960,
9,
523,
612,
63,
21118,
275,
359,
489,
299,
459,
533,
418,
367,
299,
315,
12429,
14,
6892,
8,
881,
671,
63,
396,
12,
465,
63,
8147,
29,
549,
9,
523,
1622,
523,
5396,
275,
7186,
14,
13374,
63,
3397,
8,
89,
63,
396,
12,
612,
63,
21118,
9,
523,
870,
360,
1945,
7933,
26,
469,
16,
26,
70,
5285,
908,
8,
3397,
430,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
1798,
275,
7534,
14,
10730,
342,
523,
1798,
14,
525,
63,
2094,
8,
489,
2850,
396,
63,
1045,
63,
3183,
63,
576,
297,
489,
849,
29,
797,
12,
489,
1720,
534,
774,
314,
2893,
1233,
543,
4026,
666,
3130,
489,
1595,
534,
1617,
63,
2052,
358,
523,
12846,
12,
31857,
275,
1798,
14,
1122,
63,
3159,
63,
589,
342,
523,
2833,
14,
571,
14,
1065,
8,
973,
29,
973,
12,
9238,
1524,
1274,
14,
3020,
59,
16,
2677,
435,
31857,
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,
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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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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
AnselZhangGit/fuel-main
|
utils/jenkins/report-exporter/builds.py
|
7
|
3618
|
# Copyright 2015 Mirantis, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from conf import JENKINS
from jenkins import Jenkins
import json
import logging
import urllib2
logger = logging.getLogger(__package__)
J = Jenkins(JENKINS["url"])
def get_test_data(url):
test_url = "/".join([url.rstrip("/"), 'testReport', 'api/json'])
logger.debug("Request test data from {}".format(test_url))
req = urllib2.Request(test_url)
opener = urllib2.build_opener(urllib2.HTTPHandler)
s = opener.open(req).read()
return json.loads(s)
def get_jobs_for_view(view):
"""Return list of jobs from specified view
"""
view_url = "/".join([JENKINS["url"], 'view', view, 'api/json'])
logger.debug("Request view data from {}".format(view_url))
req = urllib2.Request(view_url)
opener = urllib2.build_opener(urllib2.HTTPHandler)
s = opener.open(req).read()
view_data = json.loads(s)
jobs = [job["name"] for job in view_data["jobs"]]
return jobs
class Build():
def __init__(self, name, number):
"""Get build info via Jenkins API, get test info via direct HTTP
request.
If number is 'latest', get latest completed build.
"""
self.name = name
if number == 'latest':
job_info = J.get_job_info(self.name, depth=1)
self.number = job_info["lastCompletedBuild"]["number"]
else:
self.number = int(number)
self.build_data = J.get_build_info(self.name, self.number, depth=1)
self.url = self.build_data["url"]
def test_data(self):
try:
data = get_test_data(self.url)
except Exception as e:
logger.warning("No test data for {0}: {1}".format(
self.url,
e,
))
# If we failed to get any tests for the build, return
# meta test case 'jenkins' with status 'failed'.
data = {
"suites": [
{
"cases": [
{
"className": "jenkins",
"status": "failed"
}
]
}
]
}
return data
def __str__(self):
string = "\n".join([
"{0}: {1}".format(*item) for item in self.build_record()
])
return string
def build_record(self):
"""Return list of pairs.
We cannot use dictionary, because columns are ordered.
"""
data = [
('number', str(self.number)),
('id', self.build_data["id"]),
('description', self.build_data["description"]),
('url', self.build_data["url"]),
]
test_data = self.test_data()
for suite in test_data['suites']:
for case in suite['cases']:
column_id = case['className'].lower().replace("_", "-")
data.append((column_id, case['status'].lower()))
return data
|
apache-2.0
|
[
3,
259,
1898,
6900,
603,
723,
4466,
83,
12,
3277,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
504,
3743,
492,
1603,
742,
43,
10789,
199,
504,
29537,
492,
32516,
199,
646,
2022,
199,
646,
2050,
199,
646,
4011,
18,
199,
199,
2921,
275,
2050,
14,
5572,
3460,
2491,
3368,
199,
42,
275,
32516,
8,
42,
742,
43,
10789,
905,
633,
3135,
421,
199,
318,
664,
63,
396,
63,
576,
8,
633,
304,
272,
511,
63,
633,
275,
3286,
1674,
904,
779,
633,
14,
6735,
4769,
1288,
283,
396,
7457,
297,
283,
1246,
15,
1001,
1105,
272,
2512,
14,
1757,
480,
2017,
511,
666,
687,
8352,
908,
8,
396,
63,
633,
430,
272,
2648,
275,
4011,
18,
14,
2017,
8,
396,
63,
633,
9,
272,
16088,
275,
4011,
18,
14,
1506,
63,
11637,
8,
4078,
18,
14,
2856,
2461,
9,
272,
308,
275,
16088,
14,
1490,
8,
2103,
680,
739,
342,
272,
372,
2022,
14,
3640,
8,
83,
9,
421,
199,
318,
664,
63,
6920,
63,
509,
63,
1345,
8,
1345,
304,
272,
408,
1767,
769,
402,
9643,
687,
2013,
2455,
272,
408,
272,
2455,
63,
633,
275,
3286,
1674,
904,
779,
42,
742,
43,
10789,
905,
633,
2255,
283,
1345,
297,
2455,
12,
283,
1246,
15,
1001,
1105,
272,
2512,
14,
1757,
480,
2017,
2455,
666,
687,
8352,
908,
8,
1345,
63,
633,
430,
272,
2648,
275,
4011,
18,
14,
2017,
8,
1345,
63,
633,
9,
272,
16088,
275,
4011,
18,
14,
1506,
63,
11637,
8,
4078,
18,
14,
2856,
2461,
9,
272,
308,
275,
16088,
14,
1490,
8,
2103,
680,
739,
342,
272,
2455,
63,
576,
275,
2022,
14,
3640,
8,
83,
9,
272,
9643,
275,
359,
2423,
905,
354,
937,
367,
3906,
315,
2455,
63,
576,
905,
6920,
15261,
272,
372,
9643,
421,
199,
533,
6516,
837,
272,
347,
636,
826,
721,
277,
12,
536,
12,
1329,
304,
267,
408,
1002,
1900,
2256,
4799,
32516,
3261,
12,
664,
511,
2256,
4799,
4125,
3101,
267,
1056,
14,
398,
982,
1329,
365,
283,
7410,
297,
664,
8839,
9709,
1900,
14,
267,
408,
398,
291,
14,
354,
275,
536,
398,
340,
1329,
508,
283,
7410,
356,
288,
3906,
63,
815,
275,
1603,
14,
362,
63,
2423,
63,
815,
8,
277,
14,
354,
12,
5818,
29,
17,
9,
288,
291,
14,
1955,
275,
3906,
63,
815,
905,
2019,
19908,
3425,
6611,
1955,
937,
267,
587,
26,
288,
291,
14,
1955,
275,
1109,
8,
1955,
9,
398,
291,
14,
1506,
63,
576,
275,
1603,
14,
362,
63,
1506,
63,
815,
8,
277,
14,
354,
12,
291,
14,
1955,
12,
5818,
29,
17,
9,
267,
291,
14,
633,
275,
291,
14,
1506,
63,
576,
905,
633,
937,
339,
347,
511,
63,
576,
8,
277,
304,
267,
862,
26,
288,
666,
275,
664,
63,
396,
63,
576,
8,
277,
14,
633,
9,
267,
871,
2186,
465,
325,
26,
288,
2512,
14,
3764,
480,
1944,
511,
666,
367,
469,
16,
9160,
469,
17,
5469,
908,
8,
355,
291,
14,
633,
12,
355,
325,
12,
288,
5082,
288,
327,
982,
781,
3405,
370,
664,
1263,
2295,
367,
314,
1900,
12,
372,
288,
327,
3404,
511,
1930,
283,
25622,
7,
543,
2004,
283,
4892,
1370,
288,
666,
275,
469,
355,
298,
27034,
582,
359,
490,
469,
717,
298,
9403,
582,
359,
1169,
469,
1816,
298,
533,
985,
582,
298,
25622,
401,
1816,
298,
1205,
582,
298,
4892,
2,
1169,
789,
717,
1622,
490,
789,
355,
1622,
288,
789,
398,
372,
666,
339,
347,
636,
495,
721,
277,
304,
267,
1059,
275,
1867,
78,
1674,
904,
779,
288,
5310,
16,
9160,
469,
17,
5469,
908,
2031,
1053,
9,
367,
1242,
315,
291,
14,
1506,
63,
3059,
342,
267,
4794,
267,
372,
1059,
339,
347,
1900,
63,
3059,
8,
277,
304,
267,
408,
1767,
769,
402,
6342,
14,
398,
2136,
3913,
675,
2600,
12,
2952,
4362,
787,
7741,
14,
267,
408,
398,
666,
275,
359,
288,
661,
1955,
297,
620,
8,
277,
14,
1955,
1826,
288,
661,
344,
297,
291,
14,
1506,
63,
576,
905,
344,
10252,
288,
661,
1802,
297,
291,
14,
1506,
63,
576,
905,
1802,
10252,
288,
661,
633,
297,
291,
14,
1506,
63,
576,
905,
633,
10252,
267,
1622,
398,
511,
63,
576,
275,
291,
14,
396,
63,
576,
342,
267,
367,
5241,
315,
511,
63,
576,
459,
27034,
2565,
288,
367,
1930,
315,
5241,
459,
9403,
2565,
355,
2763,
63,
344,
275,
1930,
459,
533,
985,
2278,
2325,
1252,
1814,
11008,
401,
3905,
531,
355,
666,
14,
740,
1332,
2301,
63,
344,
12,
1930,
459,
1205,
2278,
2325,
4059,
398,
372,
666,
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
] |
[
259,
1898,
6900,
603,
723,
4466,
83,
12,
3277,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
504,
3743,
492,
1603,
742,
43,
10789,
199,
504,
29537,
492,
32516,
199,
646,
2022,
199,
646,
2050,
199,
646,
4011,
18,
199,
199,
2921,
275,
2050,
14,
5572,
3460,
2491,
3368,
199,
42,
275,
32516,
8,
42,
742,
43,
10789,
905,
633,
3135,
421,
199,
318,
664,
63,
396,
63,
576,
8,
633,
304,
272,
511,
63,
633,
275,
3286,
1674,
904,
779,
633,
14,
6735,
4769,
1288,
283,
396,
7457,
297,
283,
1246,
15,
1001,
1105,
272,
2512,
14,
1757,
480,
2017,
511,
666,
687,
8352,
908,
8,
396,
63,
633,
430,
272,
2648,
275,
4011,
18,
14,
2017,
8,
396,
63,
633,
9,
272,
16088,
275,
4011,
18,
14,
1506,
63,
11637,
8,
4078,
18,
14,
2856,
2461,
9,
272,
308,
275,
16088,
14,
1490,
8,
2103,
680,
739,
342,
272,
372,
2022,
14,
3640,
8,
83,
9,
421,
199,
318,
664,
63,
6920,
63,
509,
63,
1345,
8,
1345,
304,
272,
408,
1767,
769,
402,
9643,
687,
2013,
2455,
272,
408,
272,
2455,
63,
633,
275,
3286,
1674,
904,
779,
42,
742,
43,
10789,
905,
633,
2255,
283,
1345,
297,
2455,
12,
283,
1246,
15,
1001,
1105,
272,
2512,
14,
1757,
480,
2017,
2455,
666,
687,
8352,
908,
8,
1345,
63,
633,
430,
272,
2648,
275,
4011,
18,
14,
2017,
8,
1345,
63,
633,
9,
272,
16088,
275,
4011,
18,
14,
1506,
63,
11637,
8,
4078,
18,
14,
2856,
2461,
9,
272,
308,
275,
16088,
14,
1490,
8,
2103,
680,
739,
342,
272,
2455,
63,
576,
275,
2022,
14,
3640,
8,
83,
9,
272,
9643,
275,
359,
2423,
905,
354,
937,
367,
3906,
315,
2455,
63,
576,
905,
6920,
15261,
272,
372,
9643,
421,
199,
533,
6516,
837,
272,
347,
636,
826,
721,
277,
12,
536,
12,
1329,
304,
267,
408,
1002,
1900,
2256,
4799,
32516,
3261,
12,
664,
511,
2256,
4799,
4125,
3101,
267,
1056,
14,
398,
982,
1329,
365,
283,
7410,
297,
664,
8839,
9709,
1900,
14,
267,
408,
398,
291,
14,
354,
275,
536,
398,
340,
1329,
508,
283,
7410,
356,
288,
3906,
63,
815,
275,
1603,
14,
362,
63,
2423,
63,
815,
8,
277,
14,
354,
12,
5818,
29,
17,
9,
288,
291,
14,
1955,
275,
3906,
63,
815,
905,
2019,
19908,
3425,
6611,
1955,
937,
267,
587,
26,
288,
291,
14,
1955,
275,
1109,
8,
1955,
9,
398,
291,
14,
1506,
63,
576,
275,
1603,
14,
362,
63,
1506,
63,
815,
8,
277,
14,
354,
12,
291,
14,
1955,
12,
5818,
29,
17,
9,
267,
291,
14,
633,
275,
291,
14,
1506,
63,
576,
905,
633,
937,
339,
347,
511,
63,
576,
8,
277,
304,
267,
862,
26,
288,
666,
275,
664,
63,
396,
63,
576,
8,
277,
14,
633,
9,
267,
871,
2186,
465,
325,
26,
288,
2512,
14,
3764,
480,
1944,
511,
666,
367,
469,
16,
9160,
469,
17,
5469,
908,
8,
355,
291,
14,
633,
12,
355,
325,
12,
288,
5082,
288,
327,
982,
781,
3405,
370,
664,
1263,
2295,
367,
314,
1900,
12,
372,
288,
327,
3404,
511,
1930,
283,
25622,
7,
543,
2004,
283,
4892,
1370,
288,
666,
275,
469,
355,
298,
27034,
582,
359,
490,
469,
717,
298,
9403,
582,
359,
1169,
469,
1816,
298,
533,
985,
582,
298,
25622,
401,
1816,
298,
1205,
582,
298,
4892,
2,
1169,
789,
717,
1622,
490,
789,
355,
1622,
288,
789,
398,
372,
666,
339,
347,
636,
495,
721,
277,
304,
267,
1059,
275,
1867,
78,
1674,
904,
779,
288,
5310,
16,
9160,
469,
17,
5469,
908,
2031,
1053,
9,
367,
1242,
315,
291,
14,
1506,
63,
3059,
342,
267,
4794,
267,
372,
1059,
339,
347,
1900,
63,
3059,
8,
277,
304,
267,
408,
1767,
769,
402,
6342,
14,
398,
2136,
3913,
675,
2600,
12,
2952,
4362,
787,
7741,
14,
267,
408,
398,
666,
275,
359,
288,
661,
1955,
297,
620,
8,
277,
14,
1955,
1826,
288,
661,
344,
297,
291,
14,
1506,
63,
576,
905,
344,
10252,
288,
661,
1802,
297,
291,
14,
1506,
63,
576,
905,
1802,
10252,
288,
661,
633,
297,
291,
14,
1506,
63,
576,
905,
633,
10252,
267,
1622,
398,
511,
63,
576,
275,
291,
14,
396,
63,
576,
342,
267,
367,
5241,
315,
511,
63,
576,
459,
27034,
2565,
288,
367,
1930,
315,
5241,
459,
9403,
2565,
355,
2763,
63,
344,
275,
1930,
459,
533,
985,
2278,
2325,
1252,
1814,
11008,
401,
3905,
531,
355,
666,
14,
740,
1332,
2301,
63,
344,
12,
1930,
459,
1205,
2278,
2325,
4059,
398,
372,
666,
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,
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,
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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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
nzavagli/UnrealPy
|
UnrealPyEmbed/Development/Python/2015.08.07-Python2710-x64-Source-vs2015/Python27/Source/Pygments-2.0.2/pygments/styles/vim.py
|
135
|
1976
|
# -*- coding: utf-8 -*-
"""
pygments.styles.vim
~~~~~~~~~~~~~~~~~~~
A highlighting style for Pygments, inspired by vim.
:copyright: Copyright 2006-2014 by the Pygments team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
from pygments.style import Style
from pygments.token import Keyword, Name, Comment, String, Error, \
Number, Operator, Generic, Whitespace, Token
class VimStyle(Style):
"""
Styles somewhat like vim 7.0
"""
background_color = "#000000"
highlight_color = "#222222"
default_style = "#cccccc"
styles = {
Token: "#cccccc",
Whitespace: "",
Comment: "#000080",
Comment.Preproc: "",
Comment.Special: "bold #cd0000",
Keyword: "#cdcd00",
Keyword.Declaration: "#00cd00",
Keyword.Namespace: "#cd00cd",
Keyword.Pseudo: "",
Keyword.Type: "#00cd00",
Operator: "#3399cc",
Operator.Word: "#cdcd00",
Name: "",
Name.Class: "#00cdcd",
Name.Builtin: "#cd00cd",
Name.Exception: "bold #666699",
Name.Variable: "#00cdcd",
String: "#cd0000",
Number: "#cd00cd",
Generic.Heading: "bold #000080",
Generic.Subheading: "bold #800080",
Generic.Deleted: "#cd0000",
Generic.Inserted: "#00cd00",
Generic.Error: "#FF0000",
Generic.Emph: "italic",
Generic.Strong: "bold",
Generic.Prompt: "bold #000080",
Generic.Output: "#888",
Generic.Traceback: "#04D",
Error: "border:#FF0000"
}
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
13277,
14,
12955,
14,
16361,
272,
18294,
23597,
339,
437,
22437,
3449,
367,
14493,
12,
315,
8721,
581,
701,
6695,
14,
339,
520,
7307,
26,
1898,
8315,
13,
7280,
701,
314,
14493,
8099,
12,
1937,
10610,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
2436,
14,
199,
624,
199,
199,
504,
13277,
14,
2487,
492,
19442,
199,
504,
13277,
14,
1418,
492,
6431,
12,
2812,
12,
6819,
12,
2624,
12,
4520,
12,
971,
1362,
4860,
12,
11013,
12,
8307,
12,
24403,
12,
8767,
421,
199,
533,
812,
1017,
6609,
8,
6609,
304,
272,
408,
272,
428,
369,
2978,
30362,
2839,
6695,
1520,
14,
16,
272,
408,
339,
8020,
63,
2326,
275,
5426,
3273,
2,
272,
11850,
63,
2326,
275,
5426,
9993,
1081,
2,
272,
849,
63,
2487,
275,
5426,
13720,
2055,
2,
339,
15725,
275,
469,
267,
8767,
26,
9326,
5426,
13720,
2055,
401,
267,
24403,
26,
4483,
4873,
267,
6819,
26,
7861,
5426,
993,
1257,
401,
267,
6819,
14,
19285,
26,
3698,
4873,
267,
6819,
14,
12246,
26,
3698,
298,
9771,
327,
2866,
993,
401,
398,
6431,
26,
7861,
5426,
2866,
2866,
383,
401,
267,
6431,
14,
17737,
26,
755,
5426,
383,
2866,
383,
401,
267,
6431,
14,
8814,
26,
260,
5426,
2866,
383,
2866,
401,
267,
6431,
14,
23414,
26,
3322,
4873,
267,
6431,
14,
804,
26,
4519,
5426,
383,
2866,
383,
401,
398,
11013,
26,
8295,
5426,
1153,
1020,
2055,
401,
267,
11013,
14,
10155,
26,
3777,
5426,
2866,
2866,
383,
401,
398,
2812,
26,
10473,
4873,
267,
2812,
14,
2543,
26,
4483,
5426,
383,
2866,
2866,
401,
267,
2812,
14,
12306,
26,
4519,
5426,
2866,
383,
2866,
401,
267,
2812,
14,
1726,
26,
3322,
298,
9771,
327,
6997,
1020,
401,
267,
2812,
14,
2773,
26,
3777,
5426,
383,
2866,
2866,
401,
398,
2624,
26,
8540,
5426,
2866,
993,
401,
267,
4860,
26,
8540,
5426,
2866,
383,
2866,
401,
398,
8307,
14,
23818,
26,
3698,
298,
9771,
327,
993,
1257,
401,
267,
8307,
14,
2610,
13983,
26,
263,
298,
9771,
327,
15214,
1257,
401,
267,
8307,
14,
17735,
26,
3698,
5426,
2866,
993,
401,
267,
8307,
14,
607,
9449,
26,
3515,
5426,
383,
2866,
383,
401,
267,
8307,
14,
547,
26,
3777,
5426,
1665,
993,
401,
267,
8307,
14,
37,
311,
72,
26,
4519,
298,
21843,
401,
267,
8307,
14,
2848,
951,
26,
3322,
298,
9771,
401,
267,
8307,
14,
20430,
26,
3322,
298,
9771,
327,
993,
1257,
401,
267,
8307,
14,
2959,
26,
3322,
5426,
13997,
401,
267,
8307,
14,
15905,
26,
260,
5426,
966,
36,
401,
398,
4520,
26,
9326,
298,
8665,
15596,
1665,
993,
2,
272,
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
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
13277,
14,
12955,
14,
16361,
272,
18294,
23597,
339,
437,
22437,
3449,
367,
14493,
12,
315,
8721,
581,
701,
6695,
14,
339,
520,
7307,
26,
1898,
8315,
13,
7280,
701,
314,
14493,
8099,
12,
1937,
10610,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
2436,
14,
199,
624,
199,
199,
504,
13277,
14,
2487,
492,
19442,
199,
504,
13277,
14,
1418,
492,
6431,
12,
2812,
12,
6819,
12,
2624,
12,
4520,
12,
971,
1362,
4860,
12,
11013,
12,
8307,
12,
24403,
12,
8767,
421,
199,
533,
812,
1017,
6609,
8,
6609,
304,
272,
408,
272,
428,
369,
2978,
30362,
2839,
6695,
1520,
14,
16,
272,
408,
339,
8020,
63,
2326,
275,
5426,
3273,
2,
272,
11850,
63,
2326,
275,
5426,
9993,
1081,
2,
272,
849,
63,
2487,
275,
5426,
13720,
2055,
2,
339,
15725,
275,
469,
267,
8767,
26,
9326,
5426,
13720,
2055,
401,
267,
24403,
26,
4483,
4873,
267,
6819,
26,
7861,
5426,
993,
1257,
401,
267,
6819,
14,
19285,
26,
3698,
4873,
267,
6819,
14,
12246,
26,
3698,
298,
9771,
327,
2866,
993,
401,
398,
6431,
26,
7861,
5426,
2866,
2866,
383,
401,
267,
6431,
14,
17737,
26,
755,
5426,
383,
2866,
383,
401,
267,
6431,
14,
8814,
26,
260,
5426,
2866,
383,
2866,
401,
267,
6431,
14,
23414,
26,
3322,
4873,
267,
6431,
14,
804,
26,
4519,
5426,
383,
2866,
383,
401,
398,
11013,
26,
8295,
5426,
1153,
1020,
2055,
401,
267,
11013,
14,
10155,
26,
3777,
5426,
2866,
2866,
383,
401,
398,
2812,
26,
10473,
4873,
267,
2812,
14,
2543,
26,
4483,
5426,
383,
2866,
2866,
401,
267,
2812,
14,
12306,
26,
4519,
5426,
2866,
383,
2866,
401,
267,
2812,
14,
1726,
26,
3322,
298,
9771,
327,
6997,
1020,
401,
267,
2812,
14,
2773,
26,
3777,
5426,
383,
2866,
2866,
401,
398,
2624,
26,
8540,
5426,
2866,
993,
401,
267,
4860,
26,
8540,
5426,
2866,
383,
2866,
401,
398,
8307,
14,
23818,
26,
3698,
298,
9771,
327,
993,
1257,
401,
267,
8307,
14,
2610,
13983,
26,
263,
298,
9771,
327,
15214,
1257,
401,
267,
8307,
14,
17735,
26,
3698,
5426,
2866,
993,
401,
267,
8307,
14,
607,
9449,
26,
3515,
5426,
383,
2866,
383,
401,
267,
8307,
14,
547,
26,
3777,
5426,
1665,
993,
401,
267,
8307,
14,
37,
311,
72,
26,
4519,
298,
21843,
401,
267,
8307,
14,
2848,
951,
26,
3322,
298,
9771,
401,
267,
8307,
14,
20430,
26,
3322,
298,
9771,
327,
993,
1257,
401,
267,
8307,
14,
2959,
26,
3322,
5426,
13997,
401,
267,
8307,
14,
15905,
26,
260,
5426,
966,
36,
401,
398,
4520,
26,
9326,
298,
8665,
15596,
1665,
993,
2,
272,
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,
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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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
40123148/2015cdbg11_0420
|
static/Brython3.1.1-20150328-091302/Lib/sre_parse.py
|
630
|
29657
|
#
# Secret Labs' Regular Expression Engine
#
# convert re-style regular expression to sre pattern
#
# Copyright (c) 1998-2001 by Secret Labs AB. All rights reserved.
#
# See the sre.py file for information on usage and redistribution.
#
"""Internal support module for sre"""
# XXX: show string offset and offending character for all errors
import sys
from sre_constants import *
from _sre import MAXREPEAT
SPECIAL_CHARS = ".\\[{()*+?^$|"
REPEAT_CHARS = "*+?{"
DIGITS = set("0123456789")
OCTDIGITS = set("01234567")
HEXDIGITS = set("0123456789abcdefABCDEF")
WHITESPACE = set(" \t\n\r\v\f")
ESCAPES = {
r"\a": (LITERAL, ord("\a")),
r"\b": (LITERAL, ord("\b")),
r"\f": (LITERAL, ord("\f")),
r"\n": (LITERAL, ord("\n")),
r"\r": (LITERAL, ord("\r")),
r"\t": (LITERAL, ord("\t")),
r"\v": (LITERAL, ord("\v")),
r"\\": (LITERAL, ord("\\"))
}
CATEGORIES = {
r"\A": (AT, AT_BEGINNING_STRING), # start of string
r"\b": (AT, AT_BOUNDARY),
r"\B": (AT, AT_NON_BOUNDARY),
r"\d": (IN, [(CATEGORY, CATEGORY_DIGIT)]),
r"\D": (IN, [(CATEGORY, CATEGORY_NOT_DIGIT)]),
r"\s": (IN, [(CATEGORY, CATEGORY_SPACE)]),
r"\S": (IN, [(CATEGORY, CATEGORY_NOT_SPACE)]),
r"\w": (IN, [(CATEGORY, CATEGORY_WORD)]),
r"\W": (IN, [(CATEGORY, CATEGORY_NOT_WORD)]),
r"\Z": (AT, AT_END_STRING), # end of string
}
FLAGS = {
# standard flags
"i": SRE_FLAG_IGNORECASE,
"L": SRE_FLAG_LOCALE,
"m": SRE_FLAG_MULTILINE,
"s": SRE_FLAG_DOTALL,
"x": SRE_FLAG_VERBOSE,
# extensions
"a": SRE_FLAG_ASCII,
"t": SRE_FLAG_TEMPLATE,
"u": SRE_FLAG_UNICODE,
}
class Pattern:
# master pattern object. keeps track of global attributes
def __init__(self):
self.flags = 0
self.open = []
self.groups = 1
self.groupdict = {}
def opengroup(self, name=None):
gid = self.groups
self.groups = gid + 1
if name is not None:
ogid = self.groupdict.get(name, None)
if ogid is not None:
raise error("redefinition of group name %s as group %d; "
"was group %d" % (repr(name), gid, ogid))
self.groupdict[name] = gid
self.open.append(gid)
return gid
def closegroup(self, gid):
self.open.remove(gid)
def checkgroup(self, gid):
return gid < self.groups and gid not in self.open
class SubPattern:
# a subpattern, in intermediate form
def __init__(self, pattern, data=None):
self.pattern = pattern
if data is None:
data = []
self.data = data
self.width = None
def __iter__(self):
return iter(self.data)
def dump(self, level=0):
nl = 1
seqtypes = (tuple, list)
for op, av in self.data:
print(level*" " + op, end=' '); nl = 0
if op == "in":
# member sublanguage
print(); nl = 1
for op, a in av:
print((level+1)*" " + op, a)
elif op == "branch":
print(); nl = 1
i = 0
for a in av[1]:
if i > 0:
print(level*" " + "or")
a.dump(level+1); nl = 1
i = i + 1
elif isinstance(av, seqtypes):
for a in av:
if isinstance(a, SubPattern):
if not nl: print()
a.dump(level+1); nl = 1
else:
print(a, end=' ') ; nl = 0
else:
print(av, end=' ') ; nl = 0
if not nl: print()
def __repr__(self):
return repr(self.data)
def __len__(self):
return len(self.data)
def __delitem__(self, index):
del self.data[index]
def __getitem__(self, index):
if isinstance(index, slice):
return SubPattern(self.pattern, self.data[index])
return self.data[index]
def __setitem__(self, index, code):
self.data[index] = code
def insert(self, index, code):
self.data.insert(index, code)
def append(self, code):
self.data.append(code)
def getwidth(self):
# determine the width (min, max) for this subpattern
if self.width:
return self.width
lo = hi = 0
UNITCODES = (ANY, RANGE, IN, LITERAL, NOT_LITERAL, CATEGORY)
REPEATCODES = (MIN_REPEAT, MAX_REPEAT)
for op, av in self.data:
if op is BRANCH:
i = sys.maxsize
j = 0
for av in av[1]:
l, h = av.getwidth()
i = min(i, l)
j = max(j, h)
lo = lo + i
hi = hi + j
elif op is CALL:
i, j = av.getwidth()
lo = lo + i
hi = hi + j
elif op is SUBPATTERN:
i, j = av[1].getwidth()
lo = lo + i
hi = hi + j
elif op in REPEATCODES:
i, j = av[2].getwidth()
lo = lo + int(i) * av[0]
hi = hi + int(j) * av[1]
elif op in UNITCODES:
lo = lo + 1
hi = hi + 1
elif op == SUCCESS:
break
self.width = int(min(lo, sys.maxsize)), int(min(hi, sys.maxsize))
return self.width
class Tokenizer:
def __init__(self, string):
self.istext = isinstance(string, str)
self.string = string
self.index = 0
self.__next()
def __next(self):
if self.index >= len(self.string):
self.next = None
return
char = self.string[self.index:self.index+1]
# Special case for the str8, since indexing returns a integer
# XXX This is only needed for test_bug_926075 in test_re.py
if char and not self.istext:
char = chr(char[0])
if char == "\\":
try:
c = self.string[self.index + 1]
except IndexError:
raise error("bogus escape (end of line)")
if not self.istext:
c = chr(c)
char = char + c
self.index = self.index + len(char)
self.next = char
def match(self, char, skip=1):
if char == self.next:
if skip:
self.__next()
return 1
return 0
def get(self):
this = self.next
self.__next()
return this
def getwhile(self, n, charset):
result = ''
for _ in range(n):
c = self.next
if c not in charset:
break
result += c
self.__next()
return result
def tell(self):
return self.index, self.next
def seek(self, index):
self.index, self.next = index
def isident(char):
return "a" <= char <= "z" or "A" <= char <= "Z" or char == "_"
def isdigit(char):
return "0" <= char <= "9"
def isname(name):
# check that group name is a valid string
if not isident(name[0]):
return False
for char in name[1:]:
if not isident(char) and not isdigit(char):
return False
return True
def _class_escape(source, escape):
# handle escape code inside character class
code = ESCAPES.get(escape)
if code:
return code
code = CATEGORIES.get(escape)
if code and code[0] == IN:
return code
try:
c = escape[1:2]
if c == "x":
# hexadecimal escape (exactly two digits)
escape += source.getwhile(2, HEXDIGITS)
if len(escape) != 4:
raise ValueError
return LITERAL, int(escape[2:], 16) & 0xff
elif c == "u" and source.istext:
# unicode escape (exactly four digits)
escape += source.getwhile(4, HEXDIGITS)
if len(escape) != 6:
raise ValueError
return LITERAL, int(escape[2:], 16)
elif c == "U" and source.istext:
# unicode escape (exactly eight digits)
escape += source.getwhile(8, HEXDIGITS)
if len(escape) != 10:
raise ValueError
c = int(escape[2:], 16)
chr(c) # raise ValueError for invalid code
return LITERAL, c
elif c in OCTDIGITS:
# octal escape (up to three digits)
escape += source.getwhile(2, OCTDIGITS)
return LITERAL, int(escape[1:], 8) & 0xff
elif c in DIGITS:
raise ValueError
if len(escape) == 2:
return LITERAL, ord(escape[1])
except ValueError:
pass
raise error("bogus escape: %s" % repr(escape))
def _escape(source, escape, state):
# handle escape code in expression
code = CATEGORIES.get(escape)
if code:
return code
code = ESCAPES.get(escape)
if code:
return code
try:
c = escape[1:2]
if c == "x":
# hexadecimal escape
escape += source.getwhile(2, HEXDIGITS)
if len(escape) != 4:
raise ValueError
return LITERAL, int(escape[2:], 16) & 0xff
elif c == "u" and source.istext:
# unicode escape (exactly four digits)
escape += source.getwhile(4, HEXDIGITS)
if len(escape) != 6:
raise ValueError
return LITERAL, int(escape[2:], 16)
elif c == "U" and source.istext:
# unicode escape (exactly eight digits)
escape += source.getwhile(8, HEXDIGITS)
if len(escape) != 10:
raise ValueError
c = int(escape[2:], 16)
chr(c) # raise ValueError for invalid code
return LITERAL, c
elif c == "0":
# octal escape
escape += source.getwhile(2, OCTDIGITS)
return LITERAL, int(escape[1:], 8) & 0xff
elif c in DIGITS:
# octal escape *or* decimal group reference (sigh)
if source.next in DIGITS:
escape = escape + source.get()
if (escape[1] in OCTDIGITS and escape[2] in OCTDIGITS and
source.next in OCTDIGITS):
# got three octal digits; this is an octal escape
escape = escape + source.get()
return LITERAL, int(escape[1:], 8) & 0xff
# not an octal escape, so this is a group reference
group = int(escape[1:])
if group < state.groups:
if not state.checkgroup(group):
raise error("cannot refer to open group")
return GROUPREF, group
raise ValueError
if len(escape) == 2:
return LITERAL, ord(escape[1])
except ValueError:
pass
raise error("bogus escape: %s" % repr(escape))
def _parse_sub(source, state, nested=1):
# parse an alternation: a|b|c
items = []
itemsappend = items.append
sourcematch = source.match
while 1:
itemsappend(_parse(source, state))
if sourcematch("|"):
continue
if not nested:
break
if not source.next or sourcematch(")", 0):
break
else:
raise error("pattern not properly closed")
if len(items) == 1:
return items[0]
subpattern = SubPattern(state)
subpatternappend = subpattern.append
# check if all items share a common prefix
while 1:
prefix = None
for item in items:
if not item:
break
if prefix is None:
prefix = item[0]
elif item[0] != prefix:
break
else:
# all subitems start with a common "prefix".
# move it out of the branch
for item in items:
del item[0]
subpatternappend(prefix)
continue # check next one
break
# check if the branch can be replaced by a character set
for item in items:
if len(item) != 1 or item[0][0] != LITERAL:
break
else:
# we can store this as a character set instead of a
# branch (the compiler may optimize this even more)
set = []
setappend = set.append
for item in items:
setappend(item[0])
subpatternappend((IN, set))
return subpattern
subpattern.append((BRANCH, (None, items)))
return subpattern
def _parse_sub_cond(source, state, condgroup):
item_yes = _parse(source, state)
if source.match("|"):
item_no = _parse(source, state)
if source.match("|"):
raise error("conditional backref with more than two branches")
else:
item_no = None
if source.next and not source.match(")", 0):
raise error("pattern not properly closed")
subpattern = SubPattern(state)
subpattern.append((GROUPREF_EXISTS, (condgroup, item_yes, item_no)))
return subpattern
_PATTERNENDERS = set("|)")
_ASSERTCHARS = set("=!<")
_LOOKBEHINDASSERTCHARS = set("=!")
_REPEATCODES = set([MIN_REPEAT, MAX_REPEAT])
def _parse(source, state):
# parse a simple pattern
subpattern = SubPattern(state)
# precompute constants into local variables
subpatternappend = subpattern.append
sourceget = source.get
sourcematch = source.match
_len = len
PATTERNENDERS = _PATTERNENDERS
ASSERTCHARS = _ASSERTCHARS
LOOKBEHINDASSERTCHARS = _LOOKBEHINDASSERTCHARS
REPEATCODES = _REPEATCODES
while 1:
if source.next in PATTERNENDERS:
break # end of subpattern
this = sourceget()
if this is None:
break # end of pattern
if state.flags & SRE_FLAG_VERBOSE:
# skip whitespace and comments
if this in WHITESPACE:
continue
if this == "#":
while 1:
this = sourceget()
if this in (None, "\n"):
break
continue
if this and this[0] not in SPECIAL_CHARS:
subpatternappend((LITERAL, ord(this)))
elif this == "[":
# character set
set = []
setappend = set.append
## if sourcematch(":"):
## pass # handle character classes
if sourcematch("^"):
setappend((NEGATE, None))
# check remaining characters
start = set[:]
while 1:
this = sourceget()
if this == "]" and set != start:
break
elif this and this[0] == "\\":
code1 = _class_escape(source, this)
elif this:
code1 = LITERAL, ord(this)
else:
raise error("unexpected end of regular expression")
if sourcematch("-"):
# potential range
this = sourceget()
if this == "]":
if code1[0] is IN:
code1 = code1[1][0]
setappend(code1)
setappend((LITERAL, ord("-")))
break
elif this:
if this[0] == "\\":
code2 = _class_escape(source, this)
else:
code2 = LITERAL, ord(this)
if code1[0] != LITERAL or code2[0] != LITERAL:
raise error("bad character range")
lo = code1[1]
hi = code2[1]
if hi < lo:
raise error("bad character range")
setappend((RANGE, (lo, hi)))
else:
raise error("unexpected end of regular expression")
else:
if code1[0] is IN:
code1 = code1[1][0]
setappend(code1)
# XXX: <fl> should move set optimization to compiler!
if _len(set)==1 and set[0][0] is LITERAL:
subpatternappend(set[0]) # optimization
elif _len(set)==2 and set[0][0] is NEGATE and set[1][0] is LITERAL:
subpatternappend((NOT_LITERAL, set[1][1])) # optimization
else:
# XXX: <fl> should add charmap optimization here
subpatternappend((IN, set))
elif this and this[0] in REPEAT_CHARS:
# repeat previous item
if this == "?":
min, max = 0, 1
elif this == "*":
min, max = 0, MAXREPEAT
elif this == "+":
min, max = 1, MAXREPEAT
elif this == "{":
if source.next == "}":
subpatternappend((LITERAL, ord(this)))
continue
here = source.tell()
min, max = 0, MAXREPEAT
lo = hi = ""
while source.next in DIGITS:
lo = lo + source.get()
if sourcematch(","):
while source.next in DIGITS:
hi = hi + sourceget()
else:
hi = lo
if not sourcematch("}"):
subpatternappend((LITERAL, ord(this)))
source.seek(here)
continue
if lo:
min = int(lo)
if min >= MAXREPEAT:
raise OverflowError("the repetition number is too large")
if hi:
max = int(hi)
if max >= MAXREPEAT:
raise OverflowError("the repetition number is too large")
if max < min:
raise error("bad repeat interval")
else:
raise error("not supported")
# figure out which item to repeat
if subpattern:
item = subpattern[-1:]
else:
item = None
if not item or (_len(item) == 1 and item[0][0] == AT):
raise error("nothing to repeat")
if item[0][0] in REPEATCODES:
raise error("multiple repeat")
if sourcematch("?"):
subpattern[-1] = (MIN_REPEAT, (min, max, item))
else:
subpattern[-1] = (MAX_REPEAT, (min, max, item))
elif this == ".":
subpatternappend((ANY, None))
elif this == "(":
group = 1
name = None
condgroup = None
if sourcematch("?"):
group = 0
# options
if sourcematch("P"):
# python extensions
if sourcematch("<"):
# named group: skip forward to end of name
name = ""
while 1:
char = sourceget()
if char is None:
raise error("unterminated name")
if char == ">":
break
name = name + char
group = 1
if not name:
raise error("missing group name")
if not isname(name):
raise error("bad character in group name")
elif sourcematch("="):
# named backreference
name = ""
while 1:
char = sourceget()
if char is None:
raise error("unterminated name")
if char == ")":
break
name = name + char
if not name:
raise error("missing group name")
if not isname(name):
raise error("bad character in group name")
gid = state.groupdict.get(name)
if gid is None:
raise error("unknown group name")
subpatternappend((GROUPREF, gid))
continue
else:
char = sourceget()
if char is None:
raise error("unexpected end of pattern")
raise error("unknown specifier: ?P%s" % char)
elif sourcematch(":"):
# non-capturing group
group = 2
elif sourcematch("#"):
# comment
while 1:
if source.next is None or source.next == ")":
break
sourceget()
if not sourcematch(")"):
raise error("unbalanced parenthesis")
continue
elif source.next in ASSERTCHARS:
# lookahead assertions
char = sourceget()
dir = 1
if char == "<":
if source.next not in LOOKBEHINDASSERTCHARS:
raise error("syntax error")
dir = -1 # lookbehind
char = sourceget()
p = _parse_sub(source, state)
if not sourcematch(")"):
raise error("unbalanced parenthesis")
if char == "=":
subpatternappend((ASSERT, (dir, p)))
else:
subpatternappend((ASSERT_NOT, (dir, p)))
continue
elif sourcematch("("):
# conditional backreference group
condname = ""
while 1:
char = sourceget()
if char is None:
raise error("unterminated name")
if char == ")":
break
condname = condname + char
group = 2
if not condname:
raise error("missing group name")
if isname(condname):
condgroup = state.groupdict.get(condname)
if condgroup is None:
raise error("unknown group name")
else:
try:
condgroup = int(condname)
except ValueError:
raise error("bad character in group name")
else:
# flags
if not source.next in FLAGS:
raise error("unexpected end of pattern")
while source.next in FLAGS:
state.flags = state.flags | FLAGS[sourceget()]
if group:
# parse group contents
if group == 2:
# anonymous group
group = None
else:
group = state.opengroup(name)
if condgroup:
p = _parse_sub_cond(source, state, condgroup)
else:
p = _parse_sub(source, state)
if not sourcematch(")"):
raise error("unbalanced parenthesis")
if group is not None:
state.closegroup(group)
subpatternappend((SUBPATTERN, (group, p)))
else:
while 1:
char = sourceget()
if char is None:
raise error("unexpected end of pattern")
if char == ")":
break
raise error("unknown extension")
elif this == "^":
subpatternappend((AT, AT_BEGINNING))
elif this == "$":
subpattern.append((AT, AT_END))
elif this and this[0] == "\\":
code = _escape(source, this, state)
subpatternappend(code)
else:
raise error("parser error")
return subpattern
def fix_flags(src, flags):
# Check and fix flags according to the type of pattern (str or bytes)
if isinstance(src, str):
if not flags & SRE_FLAG_ASCII:
flags |= SRE_FLAG_UNICODE
elif flags & SRE_FLAG_UNICODE:
raise ValueError("ASCII and UNICODE flags are incompatible")
else:
if flags & SRE_FLAG_UNICODE:
raise ValueError("can't use UNICODE flag with a bytes pattern")
return flags
def parse(str, flags=0, pattern=None):
# parse 're' pattern into list of (opcode, argument) tuples
source = Tokenizer(str)
if pattern is None:
pattern = Pattern()
pattern.flags = flags
pattern.str = str
p = _parse_sub(source, pattern, 0)
p.pattern.flags = fix_flags(str, p.pattern.flags)
tail = source.get()
if tail == ")":
raise error("unbalanced parenthesis")
elif tail:
raise error("bogus characters at end of regular expression")
if flags & SRE_FLAG_DEBUG:
p.dump()
if not (flags & SRE_FLAG_VERBOSE) and p.pattern.flags & SRE_FLAG_VERBOSE:
# the VERBOSE flag was switched on inside the pattern. to be
# on the safe side, we'll parse the whole thing again...
return parse(str, p.pattern.flags)
return p
def parse_template(source, pattern):
# parse 're' replacement string into list of literals and
# group references
s = Tokenizer(source)
sget = s.get
p = []
a = p.append
def literal(literal, p=p, pappend=a):
if p and p[-1][0] is LITERAL:
p[-1] = LITERAL, p[-1][1] + literal
else:
pappend((LITERAL, literal))
sep = source[:0]
if isinstance(sep, str):
makechar = chr
else:
makechar = chr
while 1:
this = sget()
if this is None:
break # end of replacement string
if this and this[0] == "\\":
# group
c = this[1:2]
if c == "g":
name = ""
if s.match("<"):
while 1:
char = sget()
if char is None:
raise error("unterminated group name")
if char == ">":
break
name = name + char
if not name:
raise error("missing group name")
try:
index = int(name)
if index < 0:
raise error("negative group number")
except ValueError:
if not isname(name):
raise error("bad character in group name")
try:
index = pattern.groupindex[name]
except KeyError:
raise IndexError("unknown group name")
a((MARK, index))
elif c == "0":
if s.next in OCTDIGITS:
this = this + sget()
if s.next in OCTDIGITS:
this = this + sget()
literal(makechar(int(this[1:], 8) & 0xff))
elif c in DIGITS:
isoctal = False
if s.next in DIGITS:
this = this + sget()
if (c in OCTDIGITS and this[2] in OCTDIGITS and
s.next in OCTDIGITS):
this = this + sget()
isoctal = True
literal(makechar(int(this[1:], 8) & 0xff))
if not isoctal:
a((MARK, int(this[1:])))
else:
try:
this = makechar(ESCAPES[this][1])
except KeyError:
pass
literal(this)
else:
literal(this)
# convert template to groups and literals lists
i = 0
groups = []
groupsappend = groups.append
literals = [None] * len(p)
if isinstance(source, str):
encode = lambda x: x
else:
# The tokenizer implicitly decodes bytes objects as latin-1, we must
# therefore re-encode the final representation.
encode = lambda x: x.encode('latin-1')
for c, s in p:
if c is MARK:
groupsappend((i, s))
# literal[i] is already None
else:
literals[i] = encode(s)
i = i + 1
return groups, literals
def expand_template(template, match):
g = match.group
sep = match.string[:0]
groups, literals = template
literals = literals[:]
try:
for index, group in groups:
literals[index] = s = g(group)
if s is None:
raise error("unmatched group")
except IndexError:
raise error("invalid group reference")
return sep.join(literals)
|
gpl-2.0
|
[
3,
199,
3,
23580,
491,
2101,
7,
18528,
22013,
12580,
199,
3,
199,
3,
3957,
295,
13,
2487,
5578,
3965,
370,
25877,
3851,
199,
3,
199,
3,
1898,
334,
67,
9,
19960,
13,
8339,
701,
23580,
491,
2101,
14840,
14,
221,
2900,
4481,
4644,
14,
199,
3,
199,
3,
1666,
314,
25877,
14,
647,
570,
367,
2556,
641,
4503,
436,
295,
4972,
14,
199,
3,
199,
199,
624,
8405,
2291,
859,
367,
25877,
624,
199,
199,
3,
5787,
26,
2498,
1059,
3268,
436,
2331,
3219,
4528,
367,
1006,
2552,
199,
199,
646,
984,
199,
199,
504,
25877,
63,
5559,
492,
627,
199,
504,
485,
31026,
492,
9141,
23851,
199,
199,
25748,
63,
16326,
275,
3680,
1103,
59,
91,
25608,
23778,
62,
4,
25576,
199,
23851,
63,
16326,
275,
8969,
23778,
6641,
199,
199,
22855,
5930,
275,
663,
480,
11371,
531,
199,
199,
47,
1028,
22855,
5930,
275,
663,
480,
9461,
5308,
531,
199,
21377,
22855,
5930,
275,
663,
480,
11371,
10678,
18820,
531,
199,
199,
20620,
275,
663,
480,
971,
84,
60,
78,
60,
82,
60,
86,
60,
70,
531,
199,
199,
654,
8549,
654,
275,
469,
272,
519,
3212,
65,
582,
334,
21692,
12,
6206,
4582,
65,
8150,
272,
519,
3212,
66,
582,
334,
21692,
12,
6206,
4582,
66,
8150,
272,
519,
3212,
70,
582,
334,
21692,
12,
6206,
4582,
70,
8150,
272,
519,
3212,
78,
582,
334,
21692,
12,
6206,
4582,
78,
8150,
272,
519,
3212,
82,
582,
334,
21692,
12,
6206,
4582,
82,
8150,
272,
519,
3212,
84,
582,
334,
21692,
12,
6206,
4582,
84,
8150,
272,
519,
3212,
86,
582,
334,
21692,
12,
6206,
4582,
86,
8150,
272,
519,
22996,
582,
334,
21692,
12,
6206,
23236,
2237,
199,
93,
199,
199,
35,
12649,
28743,
275,
469,
272,
519,
3212,
33,
582,
334,
619,
12,
15059,
63,
15947,
6024,
63,
5353,
395,
327,
1343,
402,
1059,
272,
519,
3212,
66,
582,
334,
619,
12,
15059,
63,
21489,
395,
272,
519,
3212,
34,
582,
334,
619,
12,
15059,
63,
13887,
63,
21489,
395,
272,
519,
3212,
68,
582,
334,
568,
12,
3842,
22690,
12,
24004,
63,
36,
6995,
16636,
272,
519,
3212,
36,
582,
334,
568,
12,
3842,
22690,
12,
24004,
63,
4609,
63,
36,
6995,
16636,
272,
519,
3212,
83,
582,
334,
568,
12,
3842,
22690,
12,
24004,
63,
11658,
16636,
272,
519,
3212,
51,
582,
334,
568,
12,
3842,
22690,
12,
24004,
63,
4609,
63,
11658,
16636,
272,
519,
3212,
87,
582,
334,
568,
12,
3842,
22690,
12,
24004,
63,
5172,
16636,
272,
519,
3212,
55,
582,
334,
568,
12,
3842,
22690,
12,
24004,
63,
4609,
63,
5172,
16636,
272,
519,
3212,
58,
582,
334,
619,
12,
15059,
63,
3902,
63,
5353,
395,
327,
1284,
402,
1059,
199,
93,
199,
199,
4831,
275,
469,
272,
327,
4465,
3285,
272,
298,
73,
582,
26421,
63,
3719,
63,
15434,
12,
272,
298,
44,
582,
26421,
63,
3719,
63,
20828,
12,
272,
298,
77,
582,
26421,
63,
3719,
63,
16661,
12,
272,
298,
83,
582,
26421,
63,
3719,
63,
16504,
12,
272,
298,
88,
582,
26421,
63,
3719,
63,
16075,
12,
272,
327,
5478,
272,
298,
65,
582,
26421,
63,
3719,
63,
12292,
12,
272,
298,
84,
582,
26421,
63,
3719,
63,
7433,
12,
272,
298,
85,
582,
26421,
63,
3719,
63,
12819,
12,
199,
93,
199,
199,
533,
27019,
26,
272,
327,
5288,
3851,
909,
14,
221,
18578,
4426,
402,
2288,
3004,
272,
347,
636,
826,
721,
277,
304,
267,
291,
14,
2469,
275,
378,
267,
291,
14,
1490,
275,
942,
267,
291,
14,
2634,
275,
413,
267,
291,
14,
20567,
275,
1052,
272,
347,
1551,
923,
8,
277,
12,
536,
29,
403,
304,
267,
15122,
275,
291,
14,
2634,
267,
291,
14,
2634,
275,
15122,
435,
413,
267,
340,
536,
365,
440,
488,
26,
288,
312,
8787,
275,
291,
14,
20567,
14,
362,
8,
354,
12,
488,
9,
288,
340,
312,
8787,
365,
440,
488,
26,
355,
746,
1125,
480,
264,
7463,
402,
1572,
536,
450,
83,
465,
1572,
450,
68,
27,
298,
1169,
298,
10274,
1572,
450,
68,
2,
450,
334,
2722,
8,
354,
395,
15122,
12,
221,
312,
8787,
430,
288,
291,
14,
20567,
59,
354,
61,
275,
15122,
267,
291,
14,
1490,
14,
740,
8,
8787,
9,
267,
372,
15122,
272,
347,
4002,
923,
8,
277,
12,
15122,
304,
267,
291,
14,
1490,
14,
2168,
8,
8787,
9,
272,
347,
1104,
923,
8,
277,
12,
15122,
304,
267,
372,
15122,
665,
291,
14,
2634,
436,
15122,
440,
315,
291,
14,
1490,
199,
199,
533,
4804,
9959,
26,
272,
327,
282,
30179,
12,
315,
13197,
1824,
272,
347,
636,
826,
721,
277,
12,
3851,
12,
666,
29,
403,
304,
267,
291,
14,
3401,
275,
3851,
267,
340,
666,
365,
488,
26,
288,
666,
275,
942,
267,
291,
14,
576,
275,
666,
267,
291,
14,
2063,
275,
488,
272,
347,
636,
1661,
721,
277,
304,
267,
372,
2740,
8,
277,
14,
576,
9,
339,
347,
5461,
8,
277,
12,
2166,
29,
16,
304,
267,
12992,
275,
413,
267,
5412,
1313,
275,
334,
2960,
12,
769,
9,
267,
367,
1687,
12,
2289,
315,
291,
14,
576,
26,
288,
870,
8,
1896,
12469,
221,
298,
435,
1687,
12,
1284,
534,
283,
2736,
12992,
275,
378,
288,
340,
1687,
508,
298,
262,
582,
355,
327,
3653,
1007,
3671,
355,
870,
7303,
12992,
275,
413,
355,
367,
1687,
12,
282,
315,
2289,
26,
490,
870,
1332,
1896,
11,
17,
3342,
2,
221,
298,
435,
1687,
12,
282,
9,
288,
916,
1687,
508,
298,
4694,
582,
355,
870,
7303,
12992,
275,
413,
355,
284,
275,
378,
355,
367,
282,
315,
2289,
59,
17,
2189,
490,
340,
284,
690,
378,
26,
717,
870,
8,
1896,
12469,
221,
298,
435,
298,
269,
531,
490,
282,
14,
2724,
8,
1896,
11,
17,
2736,
12992,
275,
413,
490,
284,
275,
284,
435,
413,
288,
916,
1228,
8,
1214,
12,
5412,
1313,
304,
355,
367,
282,
315,
2289,
26,
490,
340,
1228,
8,
65,
12,
4804,
9959,
304,
717,
340,
440,
12992,
26,
870,
342,
717,
282,
14,
2724,
8,
1896,
11,
17,
2736,
12992,
275,
413,
490,
587,
26,
717,
870,
8,
65,
12,
1284,
534,
5320,
8700,
12992
] |
[
199,
3,
23580,
491,
2101,
7,
18528,
22013,
12580,
199,
3,
199,
3,
3957,
295,
13,
2487,
5578,
3965,
370,
25877,
3851,
199,
3,
199,
3,
1898,
334,
67,
9,
19960,
13,
8339,
701,
23580,
491,
2101,
14840,
14,
221,
2900,
4481,
4644,
14,
199,
3,
199,
3,
1666,
314,
25877,
14,
647,
570,
367,
2556,
641,
4503,
436,
295,
4972,
14,
199,
3,
199,
199,
624,
8405,
2291,
859,
367,
25877,
624,
199,
199,
3,
5787,
26,
2498,
1059,
3268,
436,
2331,
3219,
4528,
367,
1006,
2552,
199,
199,
646,
984,
199,
199,
504,
25877,
63,
5559,
492,
627,
199,
504,
485,
31026,
492,
9141,
23851,
199,
199,
25748,
63,
16326,
275,
3680,
1103,
59,
91,
25608,
23778,
62,
4,
25576,
199,
23851,
63,
16326,
275,
8969,
23778,
6641,
199,
199,
22855,
5930,
275,
663,
480,
11371,
531,
199,
199,
47,
1028,
22855,
5930,
275,
663,
480,
9461,
5308,
531,
199,
21377,
22855,
5930,
275,
663,
480,
11371,
10678,
18820,
531,
199,
199,
20620,
275,
663,
480,
971,
84,
60,
78,
60,
82,
60,
86,
60,
70,
531,
199,
199,
654,
8549,
654,
275,
469,
272,
519,
3212,
65,
582,
334,
21692,
12,
6206,
4582,
65,
8150,
272,
519,
3212,
66,
582,
334,
21692,
12,
6206,
4582,
66,
8150,
272,
519,
3212,
70,
582,
334,
21692,
12,
6206,
4582,
70,
8150,
272,
519,
3212,
78,
582,
334,
21692,
12,
6206,
4582,
78,
8150,
272,
519,
3212,
82,
582,
334,
21692,
12,
6206,
4582,
82,
8150,
272,
519,
3212,
84,
582,
334,
21692,
12,
6206,
4582,
84,
8150,
272,
519,
3212,
86,
582,
334,
21692,
12,
6206,
4582,
86,
8150,
272,
519,
22996,
582,
334,
21692,
12,
6206,
23236,
2237,
199,
93,
199,
199,
35,
12649,
28743,
275,
469,
272,
519,
3212,
33,
582,
334,
619,
12,
15059,
63,
15947,
6024,
63,
5353,
395,
327,
1343,
402,
1059,
272,
519,
3212,
66,
582,
334,
619,
12,
15059,
63,
21489,
395,
272,
519,
3212,
34,
582,
334,
619,
12,
15059,
63,
13887,
63,
21489,
395,
272,
519,
3212,
68,
582,
334,
568,
12,
3842,
22690,
12,
24004,
63,
36,
6995,
16636,
272,
519,
3212,
36,
582,
334,
568,
12,
3842,
22690,
12,
24004,
63,
4609,
63,
36,
6995,
16636,
272,
519,
3212,
83,
582,
334,
568,
12,
3842,
22690,
12,
24004,
63,
11658,
16636,
272,
519,
3212,
51,
582,
334,
568,
12,
3842,
22690,
12,
24004,
63,
4609,
63,
11658,
16636,
272,
519,
3212,
87,
582,
334,
568,
12,
3842,
22690,
12,
24004,
63,
5172,
16636,
272,
519,
3212,
55,
582,
334,
568,
12,
3842,
22690,
12,
24004,
63,
4609,
63,
5172,
16636,
272,
519,
3212,
58,
582,
334,
619,
12,
15059,
63,
3902,
63,
5353,
395,
327,
1284,
402,
1059,
199,
93,
199,
199,
4831,
275,
469,
272,
327,
4465,
3285,
272,
298,
73,
582,
26421,
63,
3719,
63,
15434,
12,
272,
298,
44,
582,
26421,
63,
3719,
63,
20828,
12,
272,
298,
77,
582,
26421,
63,
3719,
63,
16661,
12,
272,
298,
83,
582,
26421,
63,
3719,
63,
16504,
12,
272,
298,
88,
582,
26421,
63,
3719,
63,
16075,
12,
272,
327,
5478,
272,
298,
65,
582,
26421,
63,
3719,
63,
12292,
12,
272,
298,
84,
582,
26421,
63,
3719,
63,
7433,
12,
272,
298,
85,
582,
26421,
63,
3719,
63,
12819,
12,
199,
93,
199,
199,
533,
27019,
26,
272,
327,
5288,
3851,
909,
14,
221,
18578,
4426,
402,
2288,
3004,
272,
347,
636,
826,
721,
277,
304,
267,
291,
14,
2469,
275,
378,
267,
291,
14,
1490,
275,
942,
267,
291,
14,
2634,
275,
413,
267,
291,
14,
20567,
275,
1052,
272,
347,
1551,
923,
8,
277,
12,
536,
29,
403,
304,
267,
15122,
275,
291,
14,
2634,
267,
291,
14,
2634,
275,
15122,
435,
413,
267,
340,
536,
365,
440,
488,
26,
288,
312,
8787,
275,
291,
14,
20567,
14,
362,
8,
354,
12,
488,
9,
288,
340,
312,
8787,
365,
440,
488,
26,
355,
746,
1125,
480,
264,
7463,
402,
1572,
536,
450,
83,
465,
1572,
450,
68,
27,
298,
1169,
298,
10274,
1572,
450,
68,
2,
450,
334,
2722,
8,
354,
395,
15122,
12,
221,
312,
8787,
430,
288,
291,
14,
20567,
59,
354,
61,
275,
15122,
267,
291,
14,
1490,
14,
740,
8,
8787,
9,
267,
372,
15122,
272,
347,
4002,
923,
8,
277,
12,
15122,
304,
267,
291,
14,
1490,
14,
2168,
8,
8787,
9,
272,
347,
1104,
923,
8,
277,
12,
15122,
304,
267,
372,
15122,
665,
291,
14,
2634,
436,
15122,
440,
315,
291,
14,
1490,
199,
199,
533,
4804,
9959,
26,
272,
327,
282,
30179,
12,
315,
13197,
1824,
272,
347,
636,
826,
721,
277,
12,
3851,
12,
666,
29,
403,
304,
267,
291,
14,
3401,
275,
3851,
267,
340,
666,
365,
488,
26,
288,
666,
275,
942,
267,
291,
14,
576,
275,
666,
267,
291,
14,
2063,
275,
488,
272,
347,
636,
1661,
721,
277,
304,
267,
372,
2740,
8,
277,
14,
576,
9,
339,
347,
5461,
8,
277,
12,
2166,
29,
16,
304,
267,
12992,
275,
413,
267,
5412,
1313,
275,
334,
2960,
12,
769,
9,
267,
367,
1687,
12,
2289,
315,
291,
14,
576,
26,
288,
870,
8,
1896,
12469,
221,
298,
435,
1687,
12,
1284,
534,
283,
2736,
12992,
275,
378,
288,
340,
1687,
508,
298,
262,
582,
355,
327,
3653,
1007,
3671,
355,
870,
7303,
12992,
275,
413,
355,
367,
1687,
12,
282,
315,
2289,
26,
490,
870,
1332,
1896,
11,
17,
3342,
2,
221,
298,
435,
1687,
12,
282,
9,
288,
916,
1687,
508,
298,
4694,
582,
355,
870,
7303,
12992,
275,
413,
355,
284,
275,
378,
355,
367,
282,
315,
2289,
59,
17,
2189,
490,
340,
284,
690,
378,
26,
717,
870,
8,
1896,
12469,
221,
298,
435,
298,
269,
531,
490,
282,
14,
2724,
8,
1896,
11,
17,
2736,
12992,
275,
413,
490,
284,
275,
284,
435,
413,
288,
916,
1228,
8,
1214,
12,
5412,
1313,
304,
355,
367,
282,
315,
2289,
26,
490,
340,
1228,
8,
65,
12,
4804,
9959,
304,
717,
340,
440,
12992,
26,
870,
342,
717,
282,
14,
2724,
8,
1896,
11,
17,
2736,
12992,
275,
413,
490,
587,
26,
717,
870,
8,
65,
12,
1284,
534,
5320,
8700,
12992,
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,
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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
] |
devaha/archagent
|
node_modules/grunt-plugin/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/xcode.py
|
126
|
54475
|
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import filecmp
import gyp.common
import gyp.xcodeproj_file
import errno
import os
import sys
import posixpath
import re
import shutil
import subprocess
import tempfile
# Project files generated by this module will use _intermediate_var as a
# custom Xcode setting whose value is a DerivedSources-like directory that's
# project-specific and configuration-specific. The normal choice,
# DERIVED_FILE_DIR, is target-specific, which is thought to be too restrictive
# as it is likely that multiple targets within a single project file will want
# to access the same set of generated files. The other option,
# PROJECT_DERIVED_FILE_DIR, is unsuitable because while it is project-specific,
# it is not configuration-specific. INTERMEDIATE_DIR is defined as
# $(PROJECT_DERIVED_FILE_DIR)/$(CONFIGURATION).
_intermediate_var = 'INTERMEDIATE_DIR'
# SHARED_INTERMEDIATE_DIR is the same, except that it is shared among all
# targets that share the same BUILT_PRODUCTS_DIR.
_shared_intermediate_var = 'SHARED_INTERMEDIATE_DIR'
_library_search_paths_var = 'LIBRARY_SEARCH_PATHS'
generator_default_variables = {
'EXECUTABLE_PREFIX': '',
'EXECUTABLE_SUFFIX': '',
'STATIC_LIB_PREFIX': 'lib',
'SHARED_LIB_PREFIX': 'lib',
'STATIC_LIB_SUFFIX': '.a',
'SHARED_LIB_SUFFIX': '.dylib',
# INTERMEDIATE_DIR is a place for targets to build up intermediate products.
# It is specific to each build environment. It is only guaranteed to exist
# and be constant within the context of a project, corresponding to a single
# input file. Some build environments may allow their intermediate directory
# to be shared on a wider scale, but this is not guaranteed.
'INTERMEDIATE_DIR': '$(%s)' % _intermediate_var,
'OS': 'mac',
'PRODUCT_DIR': '$(BUILT_PRODUCTS_DIR)',
'LIB_DIR': '$(BUILT_PRODUCTS_DIR)',
'RULE_INPUT_ROOT': '$(INPUT_FILE_BASE)',
'RULE_INPUT_EXT': '$(INPUT_FILE_SUFFIX)',
'RULE_INPUT_NAME': '$(INPUT_FILE_NAME)',
'RULE_INPUT_PATH': '$(INPUT_FILE_PATH)',
'RULE_INPUT_DIRNAME': '$(INPUT_FILE_DIRNAME)',
'SHARED_INTERMEDIATE_DIR': '$(%s)' % _shared_intermediate_var,
'CONFIGURATION_NAME': '$(CONFIGURATION)',
}
# The Xcode-specific sections that hold paths.
generator_additional_path_sections = [
'mac_bundle_resources',
'mac_framework_headers',
'mac_framework_private_headers',
# 'mac_framework_dirs', input already handles _dirs endings.
]
# The Xcode-specific keys that exist on targets and aren't moved down to
# configurations.
generator_additional_non_configuration_keys = [
'mac_bundle',
'mac_bundle_resources',
'mac_framework_headers',
'mac_framework_private_headers',
'xcode_create_dependents_test_runner',
]
# We want to let any rules apply to files that are resources also.
generator_extra_sources_for_rules = [
'mac_bundle_resources',
'mac_framework_headers',
'mac_framework_private_headers',
]
# Xcode's standard set of library directories, which don't need to be duplicated
# in LIBRARY_SEARCH_PATHS. This list is not exhaustive, but that's okay.
xcode_standard_library_dirs = frozenset([
'$(SDKROOT)/usr/lib',
'$(SDKROOT)/usr/local/lib',
])
def CreateXCConfigurationList(configuration_names):
xccl = gyp.xcodeproj_file.XCConfigurationList({'buildConfigurations': []})
if len(configuration_names) == 0:
configuration_names = ['Default']
for configuration_name in configuration_names:
xcbc = gyp.xcodeproj_file.XCBuildConfiguration({
'name': configuration_name})
xccl.AppendProperty('buildConfigurations', xcbc)
xccl.SetProperty('defaultConfigurationName', configuration_names[0])
return xccl
class XcodeProject(object):
def __init__(self, gyp_path, path, build_file_dict):
self.gyp_path = gyp_path
self.path = path
self.project = gyp.xcodeproj_file.PBXProject(path=path)
projectDirPath = gyp.common.RelativePath(
os.path.dirname(os.path.abspath(self.gyp_path)),
os.path.dirname(path) or '.')
self.project.SetProperty('projectDirPath', projectDirPath)
self.project_file = \
gyp.xcodeproj_file.XCProjectFile({'rootObject': self.project})
self.build_file_dict = build_file_dict
# TODO(mark): add destructor that cleans up self.path if created_dir is
# True and things didn't complete successfully. Or do something even
# better with "try"?
self.created_dir = False
try:
os.makedirs(self.path)
self.created_dir = True
except OSError, e:
if e.errno != errno.EEXIST:
raise
def Finalize1(self, xcode_targets, serialize_all_tests):
# Collect a list of all of the build configuration names used by the
# various targets in the file. It is very heavily advised to keep each
# target in an entire project (even across multiple project files) using
# the same set of configuration names.
configurations = []
for xct in self.project.GetProperty('targets'):
xccl = xct.GetProperty('buildConfigurationList')
xcbcs = xccl.GetProperty('buildConfigurations')
for xcbc in xcbcs:
name = xcbc.GetProperty('name')
if name not in configurations:
configurations.append(name)
# Replace the XCConfigurationList attached to the PBXProject object with
# a new one specifying all of the configuration names used by the various
# targets.
try:
xccl = CreateXCConfigurationList(configurations)
self.project.SetProperty('buildConfigurationList', xccl)
except:
sys.stderr.write("Problem with gyp file %s\n" % self.gyp_path)
raise
# The need for this setting is explained above where _intermediate_var is
# defined. The comments below about wanting to avoid project-wide build
# settings apply here too, but this needs to be set on a project-wide basis
# so that files relative to the _intermediate_var setting can be displayed
# properly in the Xcode UI.
#
# Note that for configuration-relative files such as anything relative to
# _intermediate_var, for the purposes of UI tree view display, Xcode will
# only resolve the configuration name once, when the project file is
# opened. If the active build configuration is changed, the project file
# must be closed and reopened if it is desired for the tree view to update.
# This is filed as Apple radar 6588391.
xccl.SetBuildSetting(_intermediate_var,
'$(PROJECT_DERIVED_FILE_DIR)/$(CONFIGURATION)')
xccl.SetBuildSetting(_shared_intermediate_var,
'$(SYMROOT)/DerivedSources/$(CONFIGURATION)')
# Set user-specified project-wide build settings and config files. This
# is intended to be used very sparingly. Really, almost everything should
# go into target-specific build settings sections. The project-wide
# settings are only intended to be used in cases where Xcode attempts to
# resolve variable references in a project context as opposed to a target
# context, such as when resolving sourceTree references while building up
# the tree tree view for UI display.
# Any values set globally are applied to all configurations, then any
# per-configuration values are applied.
for xck, xcv in self.build_file_dict.get('xcode_settings', {}).iteritems():
xccl.SetBuildSetting(xck, xcv)
if 'xcode_config_file' in self.build_file_dict:
config_ref = self.project.AddOrGetFileInRootGroup(
self.build_file_dict['xcode_config_file'])
xccl.SetBaseConfiguration(config_ref)
build_file_configurations = self.build_file_dict.get('configurations', {})
if build_file_configurations:
for config_name in configurations:
build_file_configuration_named = \
build_file_configurations.get(config_name, {})
if build_file_configuration_named:
xcc = xccl.ConfigurationNamed(config_name)
for xck, xcv in build_file_configuration_named.get('xcode_settings',
{}).iteritems():
xcc.SetBuildSetting(xck, xcv)
if 'xcode_config_file' in build_file_configuration_named:
config_ref = self.project.AddOrGetFileInRootGroup(
build_file_configurations[config_name]['xcode_config_file'])
xcc.SetBaseConfiguration(config_ref)
# Sort the targets based on how they appeared in the input.
# TODO(mark): Like a lot of other things here, this assumes internal
# knowledge of PBXProject - in this case, of its "targets" property.
# ordinary_targets are ordinary targets that are already in the project
# file. run_test_targets are the targets that run unittests and should be
# used for the Run All Tests target. support_targets are the action/rule
# targets used by GYP file targets, just kept for the assert check.
ordinary_targets = []
run_test_targets = []
support_targets = []
# targets is full list of targets in the project.
targets = []
# does the it define it's own "all"?
has_custom_all = False
# targets_for_all is the list of ordinary_targets that should be listed
# in this project's "All" target. It includes each non_runtest_target
# that does not have suppress_wildcard set.
targets_for_all = []
for target in self.build_file_dict['targets']:
target_name = target['target_name']
toolset = target['toolset']
qualified_target = gyp.common.QualifiedTarget(self.gyp_path, target_name,
toolset)
xcode_target = xcode_targets[qualified_target]
# Make sure that the target being added to the sorted list is already in
# the unsorted list.
assert xcode_target in self.project._properties['targets']
targets.append(xcode_target)
ordinary_targets.append(xcode_target)
if xcode_target.support_target:
support_targets.append(xcode_target.support_target)
targets.append(xcode_target.support_target)
if not int(target.get('suppress_wildcard', False)):
targets_for_all.append(xcode_target)
if target_name.lower() == 'all':
has_custom_all = True;
# If this target has a 'run_as' attribute, add its target to the
# targets, and add it to the test targets.
if target.get('run_as'):
# Make a target to run something. It should have one
# dependency, the parent xcode target.
xccl = CreateXCConfigurationList(configurations)
run_target = gyp.xcodeproj_file.PBXAggregateTarget({
'name': 'Run ' + target_name,
'productName': xcode_target.GetProperty('productName'),
'buildConfigurationList': xccl,
},
parent=self.project)
run_target.AddDependency(xcode_target)
command = target['run_as']
script = ''
if command.get('working_directory'):
script = script + 'cd "%s"\n' % \
gyp.xcodeproj_file.ConvertVariablesToShellSyntax(
command.get('working_directory'))
if command.get('environment'):
script = script + "\n".join(
['export %s="%s"' %
(key, gyp.xcodeproj_file.ConvertVariablesToShellSyntax(val))
for (key, val) in command.get('environment').iteritems()]) + "\n"
# Some test end up using sockets, files on disk, etc. and can get
# confused if more then one test runs at a time. The generator
# flag 'xcode_serialize_all_test_runs' controls the forcing of all
# tests serially. It defaults to True. To get serial runs this
# little bit of python does the same as the linux flock utility to
# make sure only one runs at a time.
command_prefix = ''
if serialize_all_tests:
command_prefix = \
"""python -c "import fcntl, subprocess, sys
file = open('$TMPDIR/GYP_serialize_test_runs', 'a')
fcntl.flock(file.fileno(), fcntl.LOCK_EX)
sys.exit(subprocess.call(sys.argv[1:]))" """
# If we were unable to exec for some reason, we want to exit
# with an error, and fixup variable references to be shell
# syntax instead of xcode syntax.
script = script + 'exec ' + command_prefix + '%s\nexit 1\n' % \
gyp.xcodeproj_file.ConvertVariablesToShellSyntax(
gyp.common.EncodePOSIXShellList(command.get('action')))
ssbp = gyp.xcodeproj_file.PBXShellScriptBuildPhase({
'shellScript': script,
'showEnvVarsInLog': 0,
})
run_target.AppendProperty('buildPhases', ssbp)
# Add the run target to the project file.
targets.append(run_target)
run_test_targets.append(run_target)
xcode_target.test_runner = run_target
# Make sure that the list of targets being replaced is the same length as
# the one replacing it, but allow for the added test runner targets.
assert len(self.project._properties['targets']) == \
len(ordinary_targets) + len(support_targets)
self.project._properties['targets'] = targets
# Get rid of unnecessary levels of depth in groups like the Source group.
self.project.RootGroupsTakeOverOnlyChildren(True)
# Sort the groups nicely. Do this after sorting the targets, because the
# Products group is sorted based on the order of the targets.
self.project.SortGroups()
# Create an "All" target if there's more than one target in this project
# file and the project didn't define its own "All" target. Put a generated
# "All" target first so that people opening up the project for the first
# time will build everything by default.
if len(targets_for_all) > 1 and not has_custom_all:
xccl = CreateXCConfigurationList(configurations)
all_target = gyp.xcodeproj_file.PBXAggregateTarget(
{
'buildConfigurationList': xccl,
'name': 'All',
},
parent=self.project)
for target in targets_for_all:
all_target.AddDependency(target)
# TODO(mark): This is evil because it relies on internal knowledge of
# PBXProject._properties. It's important to get the "All" target first,
# though.
self.project._properties['targets'].insert(0, all_target)
# The same, but for run_test_targets.
if len(run_test_targets) > 1:
xccl = CreateXCConfigurationList(configurations)
run_all_tests_target = gyp.xcodeproj_file.PBXAggregateTarget(
{
'buildConfigurationList': xccl,
'name': 'Run All Tests',
},
parent=self.project)
for run_test_target in run_test_targets:
run_all_tests_target.AddDependency(run_test_target)
# Insert after the "All" target, which must exist if there is more than
# one run_test_target.
self.project._properties['targets'].insert(1, run_all_tests_target)
def Finalize2(self, xcode_targets, xcode_target_to_target_dict):
# Finalize2 needs to happen in a separate step because the process of
# updating references to other projects depends on the ordering of targets
# within remote project files. Finalize1 is responsible for sorting duty,
# and once all project files are sorted, Finalize2 can come in and update
# these references.
# To support making a "test runner" target that will run all the tests
# that are direct dependents of any given target, we look for
# xcode_create_dependents_test_runner being set on an Aggregate target,
# and generate a second target that will run the tests runners found under
# the marked target.
for bf_tgt in self.build_file_dict['targets']:
if int(bf_tgt.get('xcode_create_dependents_test_runner', 0)):
tgt_name = bf_tgt['target_name']
toolset = bf_tgt['toolset']
qualified_target = gyp.common.QualifiedTarget(self.gyp_path,
tgt_name, toolset)
xcode_target = xcode_targets[qualified_target]
if isinstance(xcode_target, gyp.xcodeproj_file.PBXAggregateTarget):
# Collect all the run test targets.
all_run_tests = []
pbxtds = xcode_target.GetProperty('dependencies')
for pbxtd in pbxtds:
pbxcip = pbxtd.GetProperty('targetProxy')
dependency_xct = pbxcip.GetProperty('remoteGlobalIDString')
if hasattr(dependency_xct, 'test_runner'):
all_run_tests.append(dependency_xct.test_runner)
# Directly depend on all the runners as they depend on the target
# that builds them.
if len(all_run_tests) > 0:
run_all_target = gyp.xcodeproj_file.PBXAggregateTarget({
'name': 'Run %s Tests' % tgt_name,
'productName': tgt_name,
},
parent=self.project)
for run_test_target in all_run_tests:
run_all_target.AddDependency(run_test_target)
# Insert the test runner after the related target.
idx = self.project._properties['targets'].index(xcode_target)
self.project._properties['targets'].insert(idx + 1, run_all_target)
# Update all references to other projects, to make sure that the lists of
# remote products are complete. Otherwise, Xcode will fill them in when
# it opens the project file, which will result in unnecessary diffs.
# TODO(mark): This is evil because it relies on internal knowledge of
# PBXProject._other_pbxprojects.
for other_pbxproject in self.project._other_pbxprojects.keys():
self.project.AddOrGetProjectReference(other_pbxproject)
self.project.SortRemoteProductReferences()
# Give everything an ID.
self.project_file.ComputeIDs()
# Make sure that no two objects in the project file have the same ID. If
# multiple objects wind up with the same ID, upon loading the file, Xcode
# will only recognize one object (the last one in the file?) and the
# results are unpredictable.
self.project_file.EnsureNoIDCollisions()
def Write(self):
# Write the project file to a temporary location first. Xcode watches for
# changes to the project file and presents a UI sheet offering to reload
# the project when it does change. However, in some cases, especially when
# multiple projects are open or when Xcode is busy, things don't work so
# seamlessly. Sometimes, Xcode is able to detect that a project file has
# changed but can't unload it because something else is referencing it.
# To mitigate this problem, and to avoid even having Xcode present the UI
# sheet when an open project is rewritten for inconsequential changes, the
# project file is written to a temporary file in the xcodeproj directory
# first. The new temporary file is then compared to the existing project
# file, if any. If they differ, the new file replaces the old; otherwise,
# the new project file is simply deleted. Xcode properly detects a file
# being renamed over an open project file as a change and so it remains
# able to present the "project file changed" sheet under this system.
# Writing to a temporary file first also avoids the possible problem of
# Xcode rereading an incomplete project file.
(output_fd, new_pbxproj_path) = \
tempfile.mkstemp(suffix='.tmp', prefix='project.pbxproj.gyp.',
dir=self.path)
try:
output_file = os.fdopen(output_fd, 'wb')
self.project_file.Print(output_file)
output_file.close()
pbxproj_path = os.path.join(self.path, 'project.pbxproj')
same = False
try:
same = filecmp.cmp(pbxproj_path, new_pbxproj_path, False)
except OSError, e:
if e.errno != errno.ENOENT:
raise
if same:
# The new file is identical to the old one, just get rid of the new
# one.
os.unlink(new_pbxproj_path)
else:
# The new file is different from the old one, or there is no old one.
# Rename the new file to the permanent name.
#
# tempfile.mkstemp uses an overly restrictive mode, resulting in a
# file that can only be read by the owner, regardless of the umask.
# There's no reason to not respect the umask here, which means that
# an extra hoop is required to fetch it and reset the new file's mode.
#
# No way to get the umask without setting a new one? Set a safe one
# and then set it back to the old value.
umask = os.umask(077)
os.umask(umask)
os.chmod(new_pbxproj_path, 0666 & ~umask)
os.rename(new_pbxproj_path, pbxproj_path)
except Exception:
# Don't leave turds behind. In fact, if this code was responsible for
# creating the xcodeproj directory, get rid of that too.
os.unlink(new_pbxproj_path)
if self.created_dir:
shutil.rmtree(self.path, True)
raise
cached_xcode_version = None
def InstalledXcodeVersion():
"""Fetches the installed version of Xcode, returns empty string if it is
unable to figure it out."""
global cached_xcode_version
if not cached_xcode_version is None:
return cached_xcode_version
# Default to an empty string
cached_xcode_version = ''
# Collect the xcodebuild's version information.
try:
import subprocess
cmd = ['/usr/bin/xcodebuild', '-version']
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE)
xcodebuild_version_info = proc.communicate()[0]
# Any error, return empty string
if proc.returncode:
xcodebuild_version_info = ''
except OSError:
# We failed to launch the tool
xcodebuild_version_info = ''
# Pull out the Xcode version itself.
match_line = re.search('^Xcode (.*)$', xcodebuild_version_info, re.MULTILINE)
if match_line:
cached_xcode_version = match_line.group(1)
# Done!
return cached_xcode_version
def AddSourceToTarget(source, type, pbxp, xct):
# TODO(mark): Perhaps source_extensions and library_extensions can be made a
# little bit fancier.
source_extensions = ['c', 'cc', 'cpp', 'cxx', 'm', 'mm', 's']
# .o is conceptually more of a "source" than a "library," but Xcode thinks
# of "sources" as things to compile and "libraries" (or "frameworks") as
# things to link with. Adding an object file to an Xcode target's frameworks
# phase works properly.
library_extensions = ['a', 'dylib', 'framework', 'o']
basename = posixpath.basename(source)
(root, ext) = posixpath.splitext(basename)
if ext:
ext = ext[1:].lower()
if ext in source_extensions and type != 'none':
xct.SourcesPhase().AddFile(source)
elif ext in library_extensions and type != 'none':
xct.FrameworksPhase().AddFile(source)
else:
# Files that aren't added to a sources or frameworks build phase can still
# go into the project file, just not as part of a build phase.
pbxp.AddOrGetFileInRootGroup(source)
def AddResourceToTarget(resource, pbxp, xct):
# TODO(mark): Combine with AddSourceToTarget above? Or just inline this call
# where it's used.
xct.ResourcesPhase().AddFile(resource)
def AddHeaderToTarget(header, pbxp, xct, is_public):
# TODO(mark): Combine with AddSourceToTarget above? Or just inline this call
# where it's used.
settings = '{ATTRIBUTES = (%s, ); }' % ('Private', 'Public')[is_public]
xct.HeadersPhase().AddFile(header, settings)
_xcode_variable_re = re.compile('(\$\((.*?)\))')
def ExpandXcodeVariables(string, expansions):
"""Expands Xcode-style $(VARIABLES) in string per the expansions dict.
In some rare cases, it is appropriate to expand Xcode variables when a
project file is generated. For any substring $(VAR) in string, if VAR is a
key in the expansions dict, $(VAR) will be replaced with expansions[VAR].
Any $(VAR) substring in string for which VAR is not a key in the expansions
dict will remain in the returned string.
"""
matches = _xcode_variable_re.findall(string)
if matches == None:
return string
matches.reverse()
for match in matches:
(to_replace, variable) = match
if not variable in expansions:
continue
replacement = expansions[variable]
string = re.sub(re.escape(to_replace), replacement, string)
return string
def EscapeXCodeArgument(s):
"""We must escape the arguments that we give to XCode so that it knows not to
split on spaces and to respect backslash and quote literals."""
s = s.replace('\\', '\\\\')
s = s.replace('"', '\\"')
return '"' + s + '"'
def PerformBuild(data, configurations, params):
options = params['options']
for build_file, build_file_dict in data.iteritems():
(build_file_root, build_file_ext) = os.path.splitext(build_file)
if build_file_ext != '.gyp':
continue
xcodeproj_path = build_file_root + options.suffix + '.xcodeproj'
if options.generator_output:
xcodeproj_path = os.path.join(options.generator_output, xcodeproj_path)
for config in configurations:
arguments = ['xcodebuild', '-project', xcodeproj_path]
arguments += ['-configuration', config]
print "Building [%s]: %s" % (config, arguments)
subprocess.check_call(arguments)
def GenerateOutput(target_list, target_dicts, data, params):
options = params['options']
generator_flags = params.get('generator_flags', {})
parallel_builds = generator_flags.get('xcode_parallel_builds', True)
serialize_all_tests = \
generator_flags.get('xcode_serialize_all_test_runs', True)
project_version = generator_flags.get('xcode_project_version', None)
skip_excluded_files = \
not generator_flags.get('xcode_list_excluded_files', True)
xcode_projects = {}
for build_file, build_file_dict in data.iteritems():
(build_file_root, build_file_ext) = os.path.splitext(build_file)
if build_file_ext != '.gyp':
continue
xcodeproj_path = build_file_root + options.suffix + '.xcodeproj'
if options.generator_output:
xcodeproj_path = os.path.join(options.generator_output, xcodeproj_path)
xcp = XcodeProject(build_file, xcodeproj_path, build_file_dict)
xcode_projects[build_file] = xcp
pbxp = xcp.project
if parallel_builds:
pbxp.SetProperty('attributes',
{'BuildIndependentTargetsInParallel': 'YES'})
if project_version:
xcp.project_file.SetXcodeVersion(project_version)
# Add gyp/gypi files to project
if not generator_flags.get('standalone'):
main_group = pbxp.GetProperty('mainGroup')
build_group = gyp.xcodeproj_file.PBXGroup({'name': 'Build'})
main_group.AppendChild(build_group)
for included_file in build_file_dict['included_files']:
build_group.AddOrGetFileByPath(included_file, False)
xcode_targets = {}
xcode_target_to_target_dict = {}
for qualified_target in target_list:
[build_file, target_name, toolset] = \
gyp.common.ParseQualifiedTarget(qualified_target)
spec = target_dicts[qualified_target]
if spec['toolset'] != 'target':
raise Exception(
'Multiple toolsets not supported in xcode build (target %s)' %
qualified_target)
configuration_names = [spec['default_configuration']]
for configuration_name in sorted(spec['configurations'].keys()):
if configuration_name not in configuration_names:
configuration_names.append(configuration_name)
xcp = xcode_projects[build_file]
pbxp = xcp.project
# Set up the configurations for the target according to the list of names
# supplied.
xccl = CreateXCConfigurationList(configuration_names)
# Create an XCTarget subclass object for the target. The type with
# "+bundle" appended will be used if the target has "mac_bundle" set.
# loadable_modules not in a mac_bundle are mapped to
# com.googlecode.gyp.xcode.bundle, a pseudo-type that xcode.py interprets
# to create a single-file mh_bundle.
_types = {
'executable': 'com.apple.product-type.tool',
'loadable_module': 'com.googlecode.gyp.xcode.bundle',
'shared_library': 'com.apple.product-type.library.dynamic',
'static_library': 'com.apple.product-type.library.static',
'executable+bundle': 'com.apple.product-type.application',
'loadable_module+bundle': 'com.apple.product-type.bundle',
'shared_library+bundle': 'com.apple.product-type.framework',
}
target_properties = {
'buildConfigurationList': xccl,
'name': target_name,
}
type = spec['type']
is_bundle = int(spec.get('mac_bundle', 0))
if type != 'none':
type_bundle_key = type
if is_bundle:
type_bundle_key += '+bundle'
xctarget_type = gyp.xcodeproj_file.PBXNativeTarget
try:
target_properties['productType'] = _types[type_bundle_key]
except KeyError, e:
gyp.common.ExceptionAppend(e, "-- unknown product type while "
"writing target %s" % target_name)
raise
else:
xctarget_type = gyp.xcodeproj_file.PBXAggregateTarget
assert not is_bundle, (
'mac_bundle targets cannot have type none (target "%s")' %
target_name)
target_product_name = spec.get('product_name')
if target_product_name is not None:
target_properties['productName'] = target_product_name
xct = xctarget_type(target_properties, parent=pbxp,
force_outdir=spec.get('product_dir'),
force_prefix=spec.get('product_prefix'),
force_extension=spec.get('product_extension'))
pbxp.AppendProperty('targets', xct)
xcode_targets[qualified_target] = xct
xcode_target_to_target_dict[xct] = spec
spec_actions = spec.get('actions', [])
spec_rules = spec.get('rules', [])
# Xcode has some "issues" with checking dependencies for the "Compile
# sources" step with any source files/headers generated by actions/rules.
# To work around this, if a target is building anything directly (not
# type "none"), then a second target is used to run the GYP actions/rules
# and is made a dependency of this target. This way the work is done
# before the dependency checks for what should be recompiled.
support_xct = None
if type != 'none' and (spec_actions or spec_rules):
support_xccl = CreateXCConfigurationList(configuration_names);
support_target_properties = {
'buildConfigurationList': support_xccl,
'name': target_name + ' Support',
}
if target_product_name:
support_target_properties['productName'] = \
target_product_name + ' Support'
support_xct = \
gyp.xcodeproj_file.PBXAggregateTarget(support_target_properties,
parent=pbxp)
pbxp.AppendProperty('targets', support_xct)
xct.AddDependency(support_xct)
# Hang the support target off the main target so it can be tested/found
# by the generator during Finalize.
xct.support_target = support_xct
prebuild_index = 0
# Add custom shell script phases for "actions" sections.
for action in spec_actions:
# There's no need to write anything into the script to ensure that the
# output directories already exist, because Xcode will look at the
# declared outputs and automatically ensure that they exist for us.
# Do we have a message to print when this action runs?
message = action.get('message')
if message:
message = 'echo note: ' + gyp.common.EncodePOSIXShellArgument(message)
else:
message = ''
# Turn the list into a string that can be passed to a shell.
action_string = gyp.common.EncodePOSIXShellList(action['action'])
# Convert Xcode-type variable references to sh-compatible environment
# variable references.
message_sh = gyp.xcodeproj_file.ConvertVariablesToShellSyntax(message)
action_string_sh = gyp.xcodeproj_file.ConvertVariablesToShellSyntax(
action_string)
script = ''
# Include the optional message
if message_sh:
script += message_sh + '\n'
# Be sure the script runs in exec, and that if exec fails, the script
# exits signalling an error.
script += 'exec ' + action_string_sh + '\nexit 1\n'
ssbp = gyp.xcodeproj_file.PBXShellScriptBuildPhase({
'inputPaths': action['inputs'],
'name': 'Action "' + action['action_name'] + '"',
'outputPaths': action['outputs'],
'shellScript': script,
'showEnvVarsInLog': 0,
})
if support_xct:
support_xct.AppendProperty('buildPhases', ssbp)
else:
# TODO(mark): this assumes too much knowledge of the internals of
# xcodeproj_file; some of these smarts should move into xcodeproj_file
# itself.
xct._properties['buildPhases'].insert(prebuild_index, ssbp)
prebuild_index = prebuild_index + 1
# TODO(mark): Should verify that at most one of these is specified.
if int(action.get('process_outputs_as_sources', False)):
for output in action['outputs']:
AddSourceToTarget(output, type, pbxp, xct)
if int(action.get('process_outputs_as_mac_bundle_resources', False)):
for output in action['outputs']:
AddResourceToTarget(output, pbxp, xct)
# tgt_mac_bundle_resources holds the list of bundle resources so
# the rule processing can check against it.
if is_bundle:
tgt_mac_bundle_resources = spec.get('mac_bundle_resources', [])
else:
tgt_mac_bundle_resources = []
# Add custom shell script phases driving "make" for "rules" sections.
#
# Xcode's built-in rule support is almost powerful enough to use directly,
# but there are a few significant deficiencies that render them unusable.
# There are workarounds for some of its inadequacies, but in aggregate,
# the workarounds added complexity to the generator, and some workarounds
# actually require input files to be crafted more carefully than I'd like.
# Consequently, until Xcode rules are made more capable, "rules" input
# sections will be handled in Xcode output by shell script build phases
# performed prior to the compilation phase.
#
# The following problems with Xcode rules were found. The numbers are
# Apple radar IDs. I hope that these shortcomings are addressed, I really
# liked having the rules handled directly in Xcode during the period that
# I was prototyping this.
#
# 6588600 Xcode compiles custom script rule outputs too soon, compilation
# fails. This occurs when rule outputs from distinct inputs are
# interdependent. The only workaround is to put rules and their
# inputs in a separate target from the one that compiles the rule
# outputs. This requires input file cooperation and it means that
# process_outputs_as_sources is unusable.
# 6584932 Need to declare that custom rule outputs should be excluded from
# compilation. A possible workaround is to lie to Xcode about a
# rule's output, giving it a dummy file it doesn't know how to
# compile. The rule action script would need to touch the dummy.
# 6584839 I need a way to declare additional inputs to a custom rule.
# A possible workaround is a shell script phase prior to
# compilation that touches a rule's primary input files if any
# would-be additional inputs are newer than the output. Modifying
# the source tree - even just modification times - feels dirty.
# 6564240 Xcode "custom script" build rules always dump all environment
# variables. This is a low-prioroty problem and is not a
# show-stopper.
rules_by_ext = {}
for rule in spec_rules:
rules_by_ext[rule['extension']] = rule
# First, some definitions:
#
# A "rule source" is a file that was listed in a target's "sources"
# list and will have a rule applied to it on the basis of matching the
# rule's "extensions" attribute. Rule sources are direct inputs to
# rules.
#
# Rule definitions may specify additional inputs in their "inputs"
# attribute. These additional inputs are used for dependency tracking
# purposes.
#
# A "concrete output" is a rule output with input-dependent variables
# resolved. For example, given a rule with:
# 'extension': 'ext', 'outputs': ['$(INPUT_FILE_BASE).cc'],
# if the target's "sources" list contained "one.ext" and "two.ext",
# the "concrete output" for rule input "two.ext" would be "two.cc". If
# a rule specifies multiple outputs, each input file that the rule is
# applied to will have the same number of concrete outputs.
#
# If any concrete outputs are outdated or missing relative to their
# corresponding rule_source or to any specified additional input, the
# rule action must be performed to generate the concrete outputs.
# concrete_outputs_by_rule_source will have an item at the same index
# as the rule['rule_sources'] that it corresponds to. Each item is a
# list of all of the concrete outputs for the rule_source.
concrete_outputs_by_rule_source = []
# concrete_outputs_all is a flat list of all concrete outputs that this
# rule is able to produce, given the known set of input files
# (rule_sources) that apply to it.
concrete_outputs_all = []
# messages & actions are keyed by the same indices as rule['rule_sources']
# and concrete_outputs_by_rule_source. They contain the message and
# action to perform after resolving input-dependent variables. The
# message is optional, in which case None is stored for each rule source.
messages = []
actions = []
for rule_source in rule.get('rule_sources', []):
rule_source_dirname, rule_source_basename = \
posixpath.split(rule_source)
(rule_source_root, rule_source_ext) = \
posixpath.splitext(rule_source_basename)
# These are the same variable names that Xcode uses for its own native
# rule support. Because Xcode's rule engine is not being used, they
# need to be expanded as they are written to the makefile.
rule_input_dict = {
'INPUT_FILE_BASE': rule_source_root,
'INPUT_FILE_SUFFIX': rule_source_ext,
'INPUT_FILE_NAME': rule_source_basename,
'INPUT_FILE_PATH': rule_source,
'INPUT_FILE_DIRNAME': rule_source_dirname,
}
concrete_outputs_for_this_rule_source = []
for output in rule.get('outputs', []):
# Fortunately, Xcode and make both use $(VAR) format for their
# variables, so the expansion is the only transformation necessary.
# Any remaning $(VAR)-type variables in the string can be given
# directly to make, which will pick up the correct settings from
# what Xcode puts into the environment.
concrete_output = ExpandXcodeVariables(output, rule_input_dict)
concrete_outputs_for_this_rule_source.append(concrete_output)
# Add all concrete outputs to the project.
pbxp.AddOrGetFileInRootGroup(concrete_output)
concrete_outputs_by_rule_source.append( \
concrete_outputs_for_this_rule_source)
concrete_outputs_all.extend(concrete_outputs_for_this_rule_source)
# TODO(mark): Should verify that at most one of these is specified.
if int(rule.get('process_outputs_as_sources', False)):
for output in concrete_outputs_for_this_rule_source:
AddSourceToTarget(output, type, pbxp, xct)
# If the file came from the mac_bundle_resources list or if the rule
# is marked to process outputs as bundle resource, do so.
was_mac_bundle_resource = rule_source in tgt_mac_bundle_resources
if was_mac_bundle_resource or \
int(rule.get('process_outputs_as_mac_bundle_resources', False)):
for output in concrete_outputs_for_this_rule_source:
AddResourceToTarget(output, pbxp, xct)
# Do we have a message to print when this rule runs?
message = rule.get('message')
if message:
message = gyp.common.EncodePOSIXShellArgument(message)
message = ExpandXcodeVariables(message, rule_input_dict)
messages.append(message)
# Turn the list into a string that can be passed to a shell.
action_string = gyp.common.EncodePOSIXShellList(rule['action'])
action = ExpandXcodeVariables(action_string, rule_input_dict)
actions.append(action)
if len(concrete_outputs_all) > 0:
# TODO(mark): There's a possibilty for collision here. Consider
# target "t" rule "A_r" and target "t_A" rule "r".
makefile_name = '%s.make' % re.sub(
'[^a-zA-Z0-9_]', '_' , '%s_%s' % (target_name, rule['rule_name']))
makefile_path = os.path.join(xcode_projects[build_file].path,
makefile_name)
# TODO(mark): try/close? Write to a temporary file and swap it only
# if it's got changes?
makefile = open(makefile_path, 'wb')
# make will build the first target in the makefile by default. By
# convention, it's called "all". List all (or at least one)
# concrete output for each rule source as a prerequisite of the "all"
# target.
makefile.write('all: \\\n')
for concrete_output_index in \
xrange(0, len(concrete_outputs_by_rule_source)):
# Only list the first (index [0]) concrete output of each input
# in the "all" target. Otherwise, a parallel make (-j > 1) would
# attempt to process each input multiple times simultaneously.
# Otherwise, "all" could just contain the entire list of
# concrete_outputs_all.
concrete_output = \
concrete_outputs_by_rule_source[concrete_output_index][0]
if concrete_output_index == len(concrete_outputs_by_rule_source) - 1:
eol = ''
else:
eol = ' \\'
makefile.write(' %s%s\n' % (concrete_output, eol))
for (rule_source, concrete_outputs, message, action) in \
zip(rule['rule_sources'], concrete_outputs_by_rule_source,
messages, actions):
makefile.write('\n')
# Add a rule that declares it can build each concrete output of a
# rule source. Collect the names of the directories that are
# required.
concrete_output_dirs = []
for concrete_output_index in xrange(0, len(concrete_outputs)):
concrete_output = concrete_outputs[concrete_output_index]
if concrete_output_index == 0:
bol = ''
else:
bol = ' '
makefile.write('%s%s \\\n' % (bol, concrete_output))
concrete_output_dir = posixpath.dirname(concrete_output)
if (concrete_output_dir and
concrete_output_dir not in concrete_output_dirs):
concrete_output_dirs.append(concrete_output_dir)
makefile.write(' : \\\n')
# The prerequisites for this rule are the rule source itself and
# the set of additional rule inputs, if any.
prerequisites = [rule_source]
prerequisites.extend(rule.get('inputs', []))
for prerequisite_index in xrange(0, len(prerequisites)):
prerequisite = prerequisites[prerequisite_index]
if prerequisite_index == len(prerequisites) - 1:
eol = ''
else:
eol = ' \\'
makefile.write(' %s%s\n' % (prerequisite, eol))
# Make sure that output directories exist before executing the rule
# action.
if len(concrete_output_dirs) > 0:
makefile.write('\t@mkdir -p "%s"\n' %
'" "'.join(concrete_output_dirs))
# The rule message and action have already had the necessary variable
# substitutions performed.
if message:
# Mark it with note: so Xcode picks it up in build output.
makefile.write('\t@echo note: %s\n' % message)
makefile.write('\t%s\n' % action)
makefile.close()
# It might be nice to ensure that needed output directories exist
# here rather than in each target in the Makefile, but that wouldn't
# work if there ever was a concrete output that had an input-dependent
# variable anywhere other than in the leaf position.
# Don't declare any inputPaths or outputPaths. If they're present,
# Xcode will provide a slight optimization by only running the script
# phase if any output is missing or outdated relative to any input.
# Unfortunately, it will also assume that all outputs are touched by
# the script, and if the outputs serve as files in a compilation
# phase, they will be unconditionally rebuilt. Since make might not
# rebuild everything that could be declared here as an output, this
# extra compilation activity is unnecessary. With inputPaths and
# outputPaths not supplied, make will always be called, but it knows
# enough to not do anything when everything is up-to-date.
# To help speed things up, pass -j COUNT to make so it does some work
# in parallel. Don't use ncpus because Xcode will build ncpus targets
# in parallel and if each target happens to have a rules step, there
# would be ncpus^2 things going. With a machine that has 2 quad-core
# Xeons, a build can quickly run out of processes based on
# scheduling/other tasks, and randomly failing builds are no good.
script = \
"""JOB_COUNT="$(/usr/sbin/sysctl -n hw.ncpu)"
if [ "${JOB_COUNT}" -gt 4 ]; then
JOB_COUNT=4
fi
exec "${DEVELOPER_BIN_DIR}/make" -f "${PROJECT_FILE_PATH}/%s" -j "${JOB_COUNT}"
exit 1
""" % makefile_name
ssbp = gyp.xcodeproj_file.PBXShellScriptBuildPhase({
'name': 'Rule "' + rule['rule_name'] + '"',
'shellScript': script,
'showEnvVarsInLog': 0,
})
if support_xct:
support_xct.AppendProperty('buildPhases', ssbp)
else:
# TODO(mark): this assumes too much knowledge of the internals of
# xcodeproj_file; some of these smarts should move into xcodeproj_file
# itself.
xct._properties['buildPhases'].insert(prebuild_index, ssbp)
prebuild_index = prebuild_index + 1
# Extra rule inputs also go into the project file. Concrete outputs were
# already added when they were computed.
groups = ['inputs', 'inputs_excluded']
if skip_excluded_files:
groups = [x for x in groups if not x.endswith('_excluded')]
for group in groups:
for item in rule.get(group, []):
pbxp.AddOrGetFileInRootGroup(item)
# Add "sources".
for source in spec.get('sources', []):
(source_root, source_extension) = posixpath.splitext(source)
if source_extension[1:] not in rules_by_ext:
# AddSourceToTarget will add the file to a root group if it's not
# already there.
AddSourceToTarget(source, type, pbxp, xct)
else:
pbxp.AddOrGetFileInRootGroup(source)
# Add "mac_bundle_resources" and "mac_framework_private_headers" if
# it's a bundle of any type.
if is_bundle:
for resource in tgt_mac_bundle_resources:
(resource_root, resource_extension) = posixpath.splitext(resource)
if resource_extension[1:] not in rules_by_ext:
AddResourceToTarget(resource, pbxp, xct)
else:
pbxp.AddOrGetFileInRootGroup(resource)
for header in spec.get('mac_framework_private_headers', []):
AddHeaderToTarget(header, pbxp, xct, False)
# Add "mac_framework_headers". These can be valid for both frameworks
# and static libraries.
if is_bundle or type == 'static_library':
for header in spec.get('mac_framework_headers', []):
AddHeaderToTarget(header, pbxp, xct, True)
# Add "copies".
for copy_group in spec.get('copies', []):
pbxcp = gyp.xcodeproj_file.PBXCopyFilesBuildPhase({
'name': 'Copy to ' + copy_group['destination']
},
parent=xct)
dest = copy_group['destination']
if dest[0] not in ('/', '$'):
# Relative paths are relative to $(SRCROOT).
dest = '$(SRCROOT)/' + dest
pbxcp.SetDestination(dest)
# TODO(mark): The usual comment about this knowing too much about
# gyp.xcodeproj_file internals applies.
xct._properties['buildPhases'].insert(prebuild_index, pbxcp)
for file in copy_group['files']:
pbxcp.AddFile(file)
# Excluded files can also go into the project file.
if not skip_excluded_files:
for key in ['sources', 'mac_bundle_resources', 'mac_framework_headers',
'mac_framework_private_headers']:
excluded_key = key + '_excluded'
for item in spec.get(excluded_key, []):
pbxp.AddOrGetFileInRootGroup(item)
# So can "inputs" and "outputs" sections of "actions" groups.
groups = ['inputs', 'inputs_excluded', 'outputs', 'outputs_excluded']
if skip_excluded_files:
groups = [x for x in groups if not x.endswith('_excluded')]
for action in spec.get('actions', []):
for group in groups:
for item in action.get(group, []):
# Exclude anything in BUILT_PRODUCTS_DIR. They're products, not
# sources.
if not item.startswith('$(BUILT_PRODUCTS_DIR)/'):
pbxp.AddOrGetFileInRootGroup(item)
for postbuild in spec.get('postbuilds', []):
action_string_sh = gyp.common.EncodePOSIXShellList(postbuild['action'])
script = 'exec ' + action_string_sh + '\nexit 1\n'
# Make the postbuild step depend on the output of ld or ar from this
# target. Apparently putting the script step after the link step isn't
# sufficient to ensure proper ordering in all cases. With an input
# declared but no outputs, the script step should run every time, as
# desired.
ssbp = gyp.xcodeproj_file.PBXShellScriptBuildPhase({
'inputPaths': ['$(BUILT_PRODUCTS_DIR)/$(EXECUTABLE_PATH)'],
'name': 'Postbuild "' + postbuild['postbuild_name'] + '"',
'shellScript': script,
'showEnvVarsInLog': 0,
})
xct.AppendProperty('buildPhases', ssbp)
# Add dependencies before libraries, because adding a dependency may imply
# adding a library. It's preferable to keep dependencies listed first
# during a link phase so that they can override symbols that would
# otherwise be provided by libraries, which will usually include system
# libraries. On some systems, ld is finicky and even requires the
# libraries to be ordered in such a way that unresolved symbols in
# earlier-listed libraries may only be resolved by later-listed libraries.
# The Mac linker doesn't work that way, but other platforms do, and so
# their linker invocations need to be constructed in this way. There's
# no compelling reason for Xcode's linker invocations to differ.
if 'dependencies' in spec:
for dependency in spec['dependencies']:
xct.AddDependency(xcode_targets[dependency])
# The support project also gets the dependencies (in case they are
# needed for the actions/rules to work).
if support_xct:
support_xct.AddDependency(xcode_targets[dependency])
if 'libraries' in spec:
for library in spec['libraries']:
xct.FrameworksPhase().AddFile(library)
# Add the library's directory to LIBRARY_SEARCH_PATHS if necessary.
# I wish Xcode handled this automatically.
library_dir = posixpath.dirname(library)
if library_dir not in xcode_standard_library_dirs and (
not xct.HasBuildSetting(_library_search_paths_var) or
library_dir not in xct.GetBuildSetting(_library_search_paths_var)):
xct.AppendBuildSetting(_library_search_paths_var, library_dir)
for configuration_name in configuration_names:
configuration = spec['configurations'][configuration_name]
xcbc = xct.ConfigurationNamed(configuration_name)
for include_dir in configuration.get('mac_framework_dirs', []):
xcbc.AppendBuildSetting('FRAMEWORK_SEARCH_PATHS', include_dir)
for include_dir in configuration.get('include_dirs', []):
xcbc.AppendBuildSetting('HEADER_SEARCH_PATHS', include_dir)
if 'defines' in configuration:
for define in configuration['defines']:
set_define = EscapeXCodeArgument(define)
xcbc.AppendBuildSetting('GCC_PREPROCESSOR_DEFINITIONS', set_define)
if 'xcode_settings' in configuration:
for xck, xcv in configuration['xcode_settings'].iteritems():
xcbc.SetBuildSetting(xck, xcv)
if 'xcode_config_file' in configuration:
config_ref = pbxp.AddOrGetFileInRootGroup(
configuration['xcode_config_file'])
xcbc.SetBaseConfiguration(config_ref)
build_files = []
for build_file, build_file_dict in data.iteritems():
if build_file.endswith('.gyp'):
build_files.append(build_file)
for build_file in build_files:
xcode_projects[build_file].Finalize1(xcode_targets, serialize_all_tests)
for build_file in build_files:
xcode_projects[build_file].Finalize2(xcode_targets,
xcode_target_to_target_dict)
for build_file in build_files:
xcode_projects[build_file].Write()
|
gpl-2.0
|
[
3,
1898,
334,
67,
9,
6029,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
646,
570,
5730,
199,
646,
4902,
14,
2330,
199,
646,
4902,
14,
29286,
63,
493,
199,
646,
7554,
199,
646,
747,
199,
646,
984,
199,
646,
15454,
199,
646,
295,
199,
646,
5145,
199,
646,
3873,
199,
646,
5549,
421,
199,
3,
7290,
1584,
4046,
701,
642,
859,
911,
675,
485,
15940,
63,
1391,
465,
282,
199,
3,
3537,
10602,
4260,
7447,
574,
365,
282,
27731,
13959,
13,
2930,
2082,
626,
1159,
199,
3,
2199,
13,
6100,
436,
2897,
13,
6100,
14,
221,
710,
3293,
7141,
12,
199,
3,
577,
540,
30487,
63,
3817,
63,
3022,
12,
365,
1347,
13,
6100,
12,
1314,
365,
32463,
370,
506,
4634,
7213,
6648,
199,
3,
465,
652,
365,
12060,
626,
3663,
4545,
4453,
282,
2849,
2199,
570,
911,
2934,
199,
3,
370,
2879,
314,
2011,
663,
402,
4046,
1584,
14,
221,
710,
1163,
945,
12,
199,
3,
21915,
63,
11733,
30487,
63,
3817,
63,
3022,
12,
365,
625,
83,
10020,
2952,
1830,
652,
365,
2199,
13,
6100,
12,
199,
3,
652,
365,
440,
2897,
13,
6100,
14,
221,
8729,
19464,
63,
3022,
365,
3247,
465,
199,
3,
7714,
10797,
63,
11733,
30487,
63,
3817,
63,
3022,
2447,
6629,
22212,
680,
199,
63,
15940,
63,
1391,
275,
283,
23227,
63,
3022,
7,
199,
199,
3,
4410,
689,
1149,
63,
23227,
63,
3022,
365,
314,
2011,
12,
871,
626,
652,
365,
5709,
16885,
1006,
199,
3,
4545,
626,
8663,
314,
2011,
16331,
1193,
52,
63,
14853,
51,
63,
3022,
14,
199,
63,
5555,
63,
15940,
63,
1391,
275,
283,
13772,
63,
23227,
63,
3022,
7,
199,
199,
63,
4342,
63,
1733,
63,
3771,
63,
1391,
275,
283,
16983,
63,
15962,
63,
20202,
7,
199,
199,
4679,
63,
885,
63,
3669,
275,
469,
523,
283,
21623,
63,
6351,
356,
3260,
523,
283,
21623,
63,
12273,
356,
3260,
523,
283,
10449,
63,
5617,
63,
6351,
356,
283,
773,
297,
523,
283,
13772,
63,
5617,
63,
6351,
356,
283,
773,
297,
523,
283,
10449,
63,
5617,
63,
12273,
356,
1987,
65,
297,
523,
283,
13772,
63,
5617,
63,
12273,
356,
1987,
22305,
297,
523,
327,
8729,
19464,
63,
3022,
365,
282,
4192,
367,
4545,
370,
1900,
1536,
13197,
7585,
14,
523,
327,
2779,
365,
2488,
370,
1924,
1900,
3734,
14,
221,
2779,
365,
1454,
17334,
370,
2187,
523,
327,
436,
506,
4413,
4453,
314,
1067,
402,
282,
2199,
12,
5226,
370,
282,
2849,
523,
327,
1324,
570,
14,
221,
6601,
1900,
22196,
1443,
2040,
3932,
13197,
2082,
523,
327,
370,
506,
5709,
641,
282,
26038,
424,
4666,
12,
1325,
642,
365,
440,
17334,
14,
523,
283,
23227,
63,
3022,
356,
4505,
4042,
83,
3171,
450,
485,
15940,
63,
1391,
12,
523,
283,
3100,
356,
283,
3088,
297,
523,
283,
14853,
63,
3022,
356,
9774,
18637,
52,
63,
14853,
51,
63,
3022,
3196,
523,
283,
5617,
63,
3022,
356,
9774,
18637,
52,
63,
14853,
51,
63,
3022,
3196,
523,
283,
13578,
63,
7321,
63,
5441,
356,
9774,
7321,
63,
3817,
63,
5825,
3196,
523,
283,
13578,
63,
7321,
63,
2472,
356,
9774,
7321,
63,
3817,
63,
12273,
3196,
523,
283,
13578,
63,
7321,
63,
2339,
356,
9774,
7321,
63,
3817,
63,
2339,
3196,
523,
283,
13578,
63,
7321,
63,
3243,
356,
9774,
7321,
63,
3817,
63,
3243,
3196,
523,
283,
13578,
63,
7321,
63,
3022,
2339,
356,
9774,
7321,
63,
3817,
63,
3022,
2339,
3196,
523,
283,
13772,
63,
23227,
63,
3022,
356,
4505,
4042,
83,
3171,
450,
485,
5555,
63,
15940,
63,
1391,
12,
523,
283,
22212,
63,
2339,
356,
9774,
22212,
3196,
199,
93,
199,
199,
3,
710,
10602,
13,
6100,
10189,
626,
10266,
3792,
14,
199,
4679,
63,
8460,
63,
515,
63,
7786,
275,
359,
523,
283,
3088,
63,
6469,
63,
4435,
297,
523,
283,
3088,
63,
4857,
63,
2139,
297,
523,
283,
3088,
63,
4857,
63,
4239,
63,
2139,
297,
523,
327,
283,
3088,
63,
4857,
63,
3220,
297,
1324,
2575,
10022,
485,
3220,
1284,
780,
14,
199,
61,
199,
199,
3,
710,
10602,
13,
6100,
2883,
626,
2187,
641,
4545,
436,
10621,
1133,
12155,
3224,
370,
199,
3,
13422,
14,
199,
4679,
63,
8460,
63,
2865,
63,
4758,
63,
1612,
275,
359,
523,
283,
3088,
63,
6469,
297,
523,
283,
3088,
63,
6469,
63,
4435,
297,
523,
283,
3088,
63,
4857,
63,
2139,
297,
523,
283,
3088,
63,
4857,
63,
4239,
63,
2139,
297,
523,
283,
8701,
63,
981,
63,
32333,
63,
396,
63,
5933,
297,
199,
61,
199,
199,
3,
2136,
2934,
370,
4691,
1263,
4713,
4838,
370,
1584,
626,
787,
5944,
2597,
14,
199,
4679,
63,
2911,
63,
4553,
63,
509,
63,
4423,
275,
359,
523,
283,
3088,
63,
6469,
63,
4435,
297,
523,
283,
3088,
63,
4857,
63,
2139,
297,
523,
283,
3088,
63,
4857,
63,
4239,
63,
2139,
297,
199,
61,
199,
199,
3,
10602,
1159,
4465,
663,
402,
3555,
6602,
12,
1314,
2793,
1133,
1929,
370,
506,
21747,
199,
3,
315,
25764,
50,
4392,
63,
15962,
63,
20202,
14,
961,
769,
365,
440,
21354,
833,
1912,
12,
1325,
626,
1159,
5849,
14,
199,
8701,
63,
6807,
63,
4342,
63,
3220,
275,
9522,
779,
523,
9774,
14939,
5441,
2447,
2647,
15,
773,
297,
523,
9774,
14939,
5441,
2447,
2647,
15,
1832,
15,
773,
297,
199,
566,
199,
199,
318,
2790,
20770,
26454,
8,
4758,
63,
1247,
304,
523,
20399,
429,
275,
4902,
14,
29286,
63,
493,
14,
20770,
26454,
3252,
1506,
25808,
356,
942,
1552,
523,
340,
822,
8,
4758,
63,
1247,
9,
508,
378,
26,
272,
2897,
63,
1247,
275,
788,
2698,
418,
523,
367,
2897,
63,
354,
315,
2897,
63,
1247,
26,
272,
671,
19279,
275,
4902,
14,
29286,
63,
493,
14,
20770,
3425,
5688,
2561,
267,
283,
354,
356,
2897,
63,
354,
1552,
272,
20399,
429,
14,
8310,
3697,
360,
1506,
25808,
297,
671,
19279,
9,
523,
20399,
429,
14,
1084,
3697,
360,
885,
5688,
985,
297,
2897,
63,
1247,
59,
16,
566,
523,
372,
20399,
429,
421,
199,
533
] |
[
1898,
334,
67,
9,
6029,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
646,
570,
5730,
199,
646,
4902,
14,
2330,
199,
646,
4902,
14,
29286,
63,
493,
199,
646,
7554,
199,
646,
747,
199,
646,
984,
199,
646,
15454,
199,
646,
295,
199,
646,
5145,
199,
646,
3873,
199,
646,
5549,
421,
199,
3,
7290,
1584,
4046,
701,
642,
859,
911,
675,
485,
15940,
63,
1391,
465,
282,
199,
3,
3537,
10602,
4260,
7447,
574,
365,
282,
27731,
13959,
13,
2930,
2082,
626,
1159,
199,
3,
2199,
13,
6100,
436,
2897,
13,
6100,
14,
221,
710,
3293,
7141,
12,
199,
3,
577,
540,
30487,
63,
3817,
63,
3022,
12,
365,
1347,
13,
6100,
12,
1314,
365,
32463,
370,
506,
4634,
7213,
6648,
199,
3,
465,
652,
365,
12060,
626,
3663,
4545,
4453,
282,
2849,
2199,
570,
911,
2934,
199,
3,
370,
2879,
314,
2011,
663,
402,
4046,
1584,
14,
221,
710,
1163,
945,
12,
199,
3,
21915,
63,
11733,
30487,
63,
3817,
63,
3022,
12,
365,
625,
83,
10020,
2952,
1830,
652,
365,
2199,
13,
6100,
12,
199,
3,
652,
365,
440,
2897,
13,
6100,
14,
221,
8729,
19464,
63,
3022,
365,
3247,
465,
199,
3,
7714,
10797,
63,
11733,
30487,
63,
3817,
63,
3022,
2447,
6629,
22212,
680,
199,
63,
15940,
63,
1391,
275,
283,
23227,
63,
3022,
7,
199,
199,
3,
4410,
689,
1149,
63,
23227,
63,
3022,
365,
314,
2011,
12,
871,
626,
652,
365,
5709,
16885,
1006,
199,
3,
4545,
626,
8663,
314,
2011,
16331,
1193,
52,
63,
14853,
51,
63,
3022,
14,
199,
63,
5555,
63,
15940,
63,
1391,
275,
283,
13772,
63,
23227,
63,
3022,
7,
199,
199,
63,
4342,
63,
1733,
63,
3771,
63,
1391,
275,
283,
16983,
63,
15962,
63,
20202,
7,
199,
199,
4679,
63,
885,
63,
3669,
275,
469,
523,
283,
21623,
63,
6351,
356,
3260,
523,
283,
21623,
63,
12273,
356,
3260,
523,
283,
10449,
63,
5617,
63,
6351,
356,
283,
773,
297,
523,
283,
13772,
63,
5617,
63,
6351,
356,
283,
773,
297,
523,
283,
10449,
63,
5617,
63,
12273,
356,
1987,
65,
297,
523,
283,
13772,
63,
5617,
63,
12273,
356,
1987,
22305,
297,
523,
327,
8729,
19464,
63,
3022,
365,
282,
4192,
367,
4545,
370,
1900,
1536,
13197,
7585,
14,
523,
327,
2779,
365,
2488,
370,
1924,
1900,
3734,
14,
221,
2779,
365,
1454,
17334,
370,
2187,
523,
327,
436,
506,
4413,
4453,
314,
1067,
402,
282,
2199,
12,
5226,
370,
282,
2849,
523,
327,
1324,
570,
14,
221,
6601,
1900,
22196,
1443,
2040,
3932,
13197,
2082,
523,
327,
370,
506,
5709,
641,
282,
26038,
424,
4666,
12,
1325,
642,
365,
440,
17334,
14,
523,
283,
23227,
63,
3022,
356,
4505,
4042,
83,
3171,
450,
485,
15940,
63,
1391,
12,
523,
283,
3100,
356,
283,
3088,
297,
523,
283,
14853,
63,
3022,
356,
9774,
18637,
52,
63,
14853,
51,
63,
3022,
3196,
523,
283,
5617,
63,
3022,
356,
9774,
18637,
52,
63,
14853,
51,
63,
3022,
3196,
523,
283,
13578,
63,
7321,
63,
5441,
356,
9774,
7321,
63,
3817,
63,
5825,
3196,
523,
283,
13578,
63,
7321,
63,
2472,
356,
9774,
7321,
63,
3817,
63,
12273,
3196,
523,
283,
13578,
63,
7321,
63,
2339,
356,
9774,
7321,
63,
3817,
63,
2339,
3196,
523,
283,
13578,
63,
7321,
63,
3243,
356,
9774,
7321,
63,
3817,
63,
3243,
3196,
523,
283,
13578,
63,
7321,
63,
3022,
2339,
356,
9774,
7321,
63,
3817,
63,
3022,
2339,
3196,
523,
283,
13772,
63,
23227,
63,
3022,
356,
4505,
4042,
83,
3171,
450,
485,
5555,
63,
15940,
63,
1391,
12,
523,
283,
22212,
63,
2339,
356,
9774,
22212,
3196,
199,
93,
199,
199,
3,
710,
10602,
13,
6100,
10189,
626,
10266,
3792,
14,
199,
4679,
63,
8460,
63,
515,
63,
7786,
275,
359,
523,
283,
3088,
63,
6469,
63,
4435,
297,
523,
283,
3088,
63,
4857,
63,
2139,
297,
523,
283,
3088,
63,
4857,
63,
4239,
63,
2139,
297,
523,
327,
283,
3088,
63,
4857,
63,
3220,
297,
1324,
2575,
10022,
485,
3220,
1284,
780,
14,
199,
61,
199,
199,
3,
710,
10602,
13,
6100,
2883,
626,
2187,
641,
4545,
436,
10621,
1133,
12155,
3224,
370,
199,
3,
13422,
14,
199,
4679,
63,
8460,
63,
2865,
63,
4758,
63,
1612,
275,
359,
523,
283,
3088,
63,
6469,
297,
523,
283,
3088,
63,
6469,
63,
4435,
297,
523,
283,
3088,
63,
4857,
63,
2139,
297,
523,
283,
3088,
63,
4857,
63,
4239,
63,
2139,
297,
523,
283,
8701,
63,
981,
63,
32333,
63,
396,
63,
5933,
297,
199,
61,
199,
199,
3,
2136,
2934,
370,
4691,
1263,
4713,
4838,
370,
1584,
626,
787,
5944,
2597,
14,
199,
4679,
63,
2911,
63,
4553,
63,
509,
63,
4423,
275,
359,
523,
283,
3088,
63,
6469,
63,
4435,
297,
523,
283,
3088,
63,
4857,
63,
2139,
297,
523,
283,
3088,
63,
4857,
63,
4239,
63,
2139,
297,
199,
61,
199,
199,
3,
10602,
1159,
4465,
663,
402,
3555,
6602,
12,
1314,
2793,
1133,
1929,
370,
506,
21747,
199,
3,
315,
25764,
50,
4392,
63,
15962,
63,
20202,
14,
961,
769,
365,
440,
21354,
833,
1912,
12,
1325,
626,
1159,
5849,
14,
199,
8701,
63,
6807,
63,
4342,
63,
3220,
275,
9522,
779,
523,
9774,
14939,
5441,
2447,
2647,
15,
773,
297,
523,
9774,
14939,
5441,
2447,
2647,
15,
1832,
15,
773,
297,
199,
566,
199,
199,
318,
2790,
20770,
26454,
8,
4758,
63,
1247,
304,
523,
20399,
429,
275,
4902,
14,
29286,
63,
493,
14,
20770,
26454,
3252,
1506,
25808,
356,
942,
1552,
523,
340,
822,
8,
4758,
63,
1247,
9,
508,
378,
26,
272,
2897,
63,
1247,
275,
788,
2698,
418,
523,
367,
2897,
63,
354,
315,
2897,
63,
1247,
26,
272,
671,
19279,
275,
4902,
14,
29286,
63,
493,
14,
20770,
3425,
5688,
2561,
267,
283,
354,
356,
2897,
63,
354,
1552,
272,
20399,
429,
14,
8310,
3697,
360,
1506,
25808,
297,
671,
19279,
9,
523,
20399,
429,
14,
1084,
3697,
360,
885,
5688,
985,
297,
2897,
63,
1247,
59,
16,
566,
523,
372,
20399,
429,
421,
199,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,
1,
1,
1
] |
Letractively/aha-gae
|
aha/modelcontroller/tests/test_crudhander.py
|
1
|
1715
|
# -*- coding: utf-8 -*-
from unittest import TestCase
import logging
log = logging.getLogger(__name__)
from nose.tools import *
from aha.modelcontroller.formcontrol import FormControl, handle_state, validate
FC = FormControl
class TestCRUDControllerMixIn(TestCase):
def test_subclass(self):
"""
Test for subclassing CRUDControllerMixIn
"""
from coregae.controller.crudcontrollers import (
CRUDControllerMixIn, CRUDControllerMetaClass)
class TestKlass(CRUDControllerMixIn):
EDIT_FC = FormControl()
ADD_FC = FormControl()
@EDIT_FC.handle_state(FC.SUCCESS)
def edit_data(self):
return "FOO"
@EDIT_FC.handle_validate(FC.INITIAL)
def edit_validate(self):
pass
@ADD_FC.handle_state(FC.INITIAL)
def add_form(self):
return "FOO"
assert_true(hasattr(TestKlass, 'EDIT_FC'))
assert_true(hasattr(TestKlass, 'ADD_FC'))
assert_not_equal(TestKlass.EDIT_FC, CRUDControllerMixIn.EDIT_FC)
efc = TestKlass.EDIT_FC
efc2 = CRUDControllerMixIn.EDIT_FC
assert_equal(efc.get_processor(FC.INITIAL),
efc2.get_processor(FC.INITIAL))
assert_not_equal(efc.get_processor(FC.SUCCESS),
efc2.get_processor(FC.SUCCESS))
assert_not_equal(efc.get_validator(FC.INITIAL),
efc2.get_validator(FC.INITIAL))
afc = TestKlass.ADD_FC
afc2 = CRUDControllerMixIn.ADD_FC
assert_not_equal(afc.get_processor(FC.INITIAL),
afc2.get_processor(FC.INITIAL))
|
bsd-3-clause
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
504,
2882,
492,
7640,
199,
646,
2050,
199,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
504,
11354,
14,
2537,
492,
627,
199,
199,
504,
282,
2411,
14,
1238,
5538,
14,
964,
2785,
492,
8204,
3717,
12,
2429,
63,
929,
12,
4107,
199,
4161,
275,
8204,
3717,
199,
199,
533,
1379,
2944,
3383,
7506,
26527,
8,
1746,
304,
339,
347,
511,
63,
6083,
8,
277,
304,
267,
408,
267,
1379,
367,
24572,
17101,
3383,
7506,
26527,
267,
408,
267,
687,
512,
1135,
3624,
14,
5538,
14,
28941,
20531,
492,
334,
490,
17101,
3383,
7506,
26527,
12,
17101,
3383,
7506,
3396,
2543,
9,
398,
1021,
1379,
43,
4297,
8,
2944,
3383,
7506,
26527,
304,
288,
24981,
63,
4161,
275,
8204,
3717,
342,
288,
21380,
63,
4161,
275,
8204,
3717,
342,
953,
768,
17929,
63,
4161,
14,
2479,
63,
929,
8,
4161,
14,
12779,
9,
288,
347,
5283,
63,
576,
8,
277,
304,
355,
372,
298,
13046,
2,
953,
768,
17929,
63,
4161,
14,
2479,
63,
3502,
8,
4161,
14,
13768,
9,
288,
347,
5283,
63,
3502,
8,
277,
304,
355,
986,
953,
768,
9732,
63,
4161,
14,
2479,
63,
929,
8,
4161,
14,
13768,
9,
288,
347,
1050,
63,
964,
8,
277,
304,
355,
372,
298,
13046,
2,
7318,
702,
63,
2052,
8,
11161,
8,
774,
43,
4297,
12,
283,
17929,
63,
4161,
1333,
267,
702,
63,
2052,
8,
11161,
8,
774,
43,
4297,
12,
283,
9732,
63,
4161,
1333,
267,
702,
63,
1397,
63,
1452,
8,
774,
43,
4297,
14,
17929,
63,
4161,
12,
17101,
3383,
7506,
26527,
14,
17929,
63,
4161,
9,
7318,
325,
3003,
275,
1379,
43,
4297,
14,
17929,
63,
4161,
267,
325,
3003,
18,
275,
17101,
3383,
7506,
26527,
14,
17929,
63,
4161,
398,
702,
63,
1452,
8,
2829,
67,
14,
362,
63,
6459,
8,
4161,
14,
13768,
395,
2151,
325,
3003,
18,
14,
362,
63,
6459,
8,
4161,
14,
13768,
430,
398,
702,
63,
1397,
63,
1452,
8,
2829,
67,
14,
362,
63,
6459,
8,
4161,
14,
12779,
395,
586,
325,
3003,
18,
14,
362,
63,
6459,
8,
4161,
14,
12779,
430,
398,
702,
63,
1397,
63,
1452,
8,
2829,
67,
14,
362,
63,
11034,
8,
4161,
14,
13768,
395,
586,
325,
3003,
18,
14,
362,
63,
11034,
8,
4161,
14,
13768,
430,
398,
282,
3003,
275,
1379,
43,
4297,
14,
9732,
63,
4161,
267,
282,
3003,
18,
275,
17101,
3383,
7506,
26527,
14,
9732,
63,
4161,
398,
702,
63,
1397,
63,
1452,
8,
2756,
67,
14,
362,
63,
6459,
8,
4161,
14,
13768,
395,
586,
282,
3003,
18,
14,
362,
63,
6459,
8,
4161,
14,
13768,
430,
4388,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
2882,
492,
7640,
199,
646,
2050,
199,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
504,
11354,
14,
2537,
492,
627,
199,
199,
504,
282,
2411,
14,
1238,
5538,
14,
964,
2785,
492,
8204,
3717,
12,
2429,
63,
929,
12,
4107,
199,
4161,
275,
8204,
3717,
199,
199,
533,
1379,
2944,
3383,
7506,
26527,
8,
1746,
304,
339,
347,
511,
63,
6083,
8,
277,
304,
267,
408,
267,
1379,
367,
24572,
17101,
3383,
7506,
26527,
267,
408,
267,
687,
512,
1135,
3624,
14,
5538,
14,
28941,
20531,
492,
334,
490,
17101,
3383,
7506,
26527,
12,
17101,
3383,
7506,
3396,
2543,
9,
398,
1021,
1379,
43,
4297,
8,
2944,
3383,
7506,
26527,
304,
288,
24981,
63,
4161,
275,
8204,
3717,
342,
288,
21380,
63,
4161,
275,
8204,
3717,
342,
953,
768,
17929,
63,
4161,
14,
2479,
63,
929,
8,
4161,
14,
12779,
9,
288,
347,
5283,
63,
576,
8,
277,
304,
355,
372,
298,
13046,
2,
953,
768,
17929,
63,
4161,
14,
2479,
63,
3502,
8,
4161,
14,
13768,
9,
288,
347,
5283,
63,
3502,
8,
277,
304,
355,
986,
953,
768,
9732,
63,
4161,
14,
2479,
63,
929,
8,
4161,
14,
13768,
9,
288,
347,
1050,
63,
964,
8,
277,
304,
355,
372,
298,
13046,
2,
7318,
702,
63,
2052,
8,
11161,
8,
774,
43,
4297,
12,
283,
17929,
63,
4161,
1333,
267,
702,
63,
2052,
8,
11161,
8,
774,
43,
4297,
12,
283,
9732,
63,
4161,
1333,
267,
702,
63,
1397,
63,
1452,
8,
774,
43,
4297,
14,
17929,
63,
4161,
12,
17101,
3383,
7506,
26527,
14,
17929,
63,
4161,
9,
7318,
325,
3003,
275,
1379,
43,
4297,
14,
17929,
63,
4161,
267,
325,
3003,
18,
275,
17101,
3383,
7506,
26527,
14,
17929,
63,
4161,
398,
702,
63,
1452,
8,
2829,
67,
14,
362,
63,
6459,
8,
4161,
14,
13768,
395,
2151,
325,
3003,
18,
14,
362,
63,
6459,
8,
4161,
14,
13768,
430,
398,
702,
63,
1397,
63,
1452,
8,
2829,
67,
14,
362,
63,
6459,
8,
4161,
14,
12779,
395,
586,
325,
3003,
18,
14,
362,
63,
6459,
8,
4161,
14,
12779,
430,
398,
702,
63,
1397,
63,
1452,
8,
2829,
67,
14,
362,
63,
11034,
8,
4161,
14,
13768,
395,
586,
325,
3003,
18,
14,
362,
63,
11034,
8,
4161,
14,
13768,
430,
398,
282,
3003,
275,
1379,
43,
4297,
14,
9732,
63,
4161,
267,
282,
3003,
18,
275,
17101,
3383,
7506,
26527,
14,
9732,
63,
4161,
398,
702,
63,
1397,
63,
1452,
8,
2756,
67,
14,
362,
63,
6459,
8,
4161,
14,
13768,
395,
586,
282,
3003,
18,
14,
362,
63,
6459,
8,
4161,
14,
13768,
430,
4388,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
EmreAtes/spack
|
var/spack/repos/builtin/packages/texlive/package.py
|
1
|
3446
|
##############################################################################
# Copyright (c) 2013-2018, Lawrence Livermore National Security, LLC.
# Produced at the Lawrence Livermore National Laboratory.
#
# This file is part of Spack.
# Created by Todd Gamblin, tgamblin@llnl.gov, All rights reserved.
# LLNL-CODE-647188
#
# For details, see https://github.com/spack/spack
# Please also see the NOTICE and LICENSE files for our notice and the LGPL.
#
# This program 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) version 2.1, February 1999.
#
# 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 terms and
# conditions of the GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
##############################################################################
from spack import *
import os
class Texlive(Package):
"""TeX Live is a free software distribution for the TeX typesetting
system. Heads up, it's is not a reproducible installation."""
homepage = "http://www.tug.org/texlive"
# Install from specific site because the texlive mirrors do not
# all update in synchrony.
#
# BEWARE: TexLive updates their installs frequently (probably why
# they call it *Live*...). There is no good way to provide a
# repeatable install of the package.
#
# We're now pulling the installation bits from tug.org's repo of
# historic bits. This means that the checksum for the installer
# itself is stable. Don't let that fool you though, it's still
# installing TeX **LIVE** from e.g. ctan.math.... below, which is
# not reproducible.
version('live', '8f8fc301514c08a89a2e97197369c648',
url='ftp://tug.org/historic/systems/texlive/2017/install-tl-unx.tar.gz')
# There does not seem to be a complete list of schemes.
# Examples include:
# full scheme (everything)
# medium scheme (small + more packages and languages)
# small scheme (basic + xetex, metapost, a few languages)
# basic scheme (plain and latex)
# minimal scheme (plain only)
# See:
# https://www.tug.org/texlive/doc/texlive-en/texlive-en.html#x1-25025r6
variant(
'scheme',
default='small',
values=('minimal', 'basic', 'small', 'medium', 'full'),
description='Package subset to install'
)
depends_on('perl', type='build')
def install(self, spec, prefix):
# Using texlive's mirror system leads to mysterious problems,
# in lieu of being able to specify a repository as a variant, hardwire
# a particular (slow, but central) one for now.
_repository = 'http://ctan.math.washington.edu/tex-archive/systems/texlive/tlnet/'
env = os.environ
env['TEXLIVE_INSTALL_PREFIX'] = prefix
perl = which('perl')
scheme = spec.variants['scheme'].value
perl('./install-tl', '-scheme', scheme,
'-repository', _repository,
'-portable', '-profile', '/dev/null')
|
lgpl-2.1
|
[
4605,
199,
3,
1898,
334,
67,
9,
6171,
13,
12682,
12,
7964,
29590,
491,
4380,
6878,
20548,
13863,
12,
20376,
14,
199,
3,
2165,
16584,
737,
314,
7964,
29590,
491,
4380,
6878,
20548,
16871,
31671,
14,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
428,
1389,
14,
199,
3,
18208,
701,
377,
16216,
598,
11020,
472,
12,
22387,
11020,
472,
32,
914,
7530,
14,
16294,
12,
2900,
4481,
4644,
14,
199,
3,
491,
44,
14176,
13,
6012,
13,
8557,
11501,
199,
3,
199,
3,
2104,
2436,
12,
1937,
4178,
921,
5031,
14,
957,
15,
83,
1389,
15,
83,
1389,
199,
3,
7754,
2597,
1937,
314,
12840,
436,
5113,
1584,
367,
4154,
4245,
436,
314,
32426,
14,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
844,
334,
305,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
9,
1015,
499,
14,
17,
12,
21141,
26709,
21300,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
199,
3,
2428,
1821,
3408,
27,
1928,
2755,
314,
5292,
3408,
1634,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
1666,
314,
2895,
436,
199,
3,
3704,
402,
314,
1664,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
15673,
13,
13421,
8217,
199,
4605,
199,
504,
308,
1389,
492,
627,
199,
646,
747,
421,
199,
533,
20566,
6442,
8,
8599,
304,
272,
408,
12589,
24683,
365,
282,
2867,
2032,
4084,
367,
314,
5773,
56,
730,
6031,
2126,
2656,
14,
221,
5311,
9402,
1536,
12,
652,
1159,
365,
440,
282,
295,
496,
2033,
559,
830,
12096,
1041,
339,
26586,
275,
298,
1014,
921,
1544,
14,
84,
1518,
14,
1308,
15,
3858,
6442,
2,
339,
327,
13276,
687,
2488,
4770,
2952,
314,
14709,
6442,
15216,
83,
886,
440,
272,
327,
1006,
1678,
315,
15354,
89,
14,
272,
327,
272,
327,
6262,
3695,
26,
20566,
17458,
7029,
3932,
25801,
28914,
590,
334,
6101,
6665,
10842,
272,
327,
2985,
1240,
652,
627,
17458,
10,
1396,
680,
221,
6006,
365,
949,
6954,
4340,
370,
5647,
282,
272,
327,
11982,
461,
3907,
402,
314,
2559,
14,
272,
327,
272,
327,
2136,
3984,
3063,
10299,
316,
314,
12096,
5821,
687,
307,
1518,
14,
1308,
1159,
3831,
402,
272,
327,
13612,
269,
530,
5821,
14,
221,
961,
4910,
626,
314,
9040,
367,
314,
18535,
272,
327,
6337,
365,
17830,
14,
221,
7529,
1133,
4691,
626,
7090,
393,
1265,
10617,
12,
652,
1159,
5139,
272,
327,
22200,
5773,
56,
1011,
31541,
538,
687,
325,
14,
71,
14,
9428,
290,
14,
3442,
4496,
5084,
12,
1314,
365,
272,
327,
440,
295,
496,
2033,
559,
830,
14,
272,
1015,
360,
6442,
297,
283,
24,
70,
24,
3003,
8507,
24098,
67,
2036,
65,
1407,
65,
18,
69,
2576,
11165,
11939,
67,
10552,
297,
288,
1166,
534,
8915,
921,
84,
1518,
14,
1308,
15,
11141,
269,
530,
15,
19135,
15,
3858,
6442,
15,
10680,
15,
3174,
13,
5019,
13,
324,
88,
14,
5369,
14,
6838,
358,
339,
327,
6006,
1630,
440,
17021,
370,
506,
282,
4890,
769,
402,
21149,
14,
272,
327,
6058,
2387,
26,
272,
327,
257,
2615,
5687,
334,
14287,
2127,
9,
272,
327,
257,
21576,
5687,
334,
7241,
435,
1655,
6117,
436,
10815,
9,
272,
327,
257,
7425,
5687,
334,
4316,
435,
671,
69,
3858,
12,
7647,
439,
941,
12,
282,
9284,
10815,
9,
272,
327,
257,
5678,
5687,
334,
6104,
436,
15571,
9,
272,
327,
257,
13460,
5687,
334,
6104,
1454,
9,
272,
327,
1666,
26,
272,
327,
4178,
921,
1544,
14,
84,
1518,
14,
1308,
15,
3858,
6442,
15,
1301,
15,
3858,
6442,
13,
287,
15,
3858,
6442,
13,
287,
14,
1360,
3,
88,
17,
13,
7991,
821,
82,
22,
272,
9854,
8,
267,
283,
5512,
297,
267,
849,
534,
7241,
297,
267,
1338,
7782,
21508,
297,
283,
4316,
297,
283,
7241,
297,
283,
14345,
297,
283,
2861,
659,
267,
1369,
534,
8599,
10026,
370,
3907,
7,
272,
776,
339,
8350,
63,
265,
360,
22805,
297,
730,
534,
1506,
358,
339,
347,
3907,
8,
277,
12,
3158,
12,
2403,
304,
267,
327,
11719,
14709,
6442,
1159,
15216,
2656,
27401,
370,
333,
588,
6236,
1785,
8826,
12,
267,
327,
315,
1212,
16913,
402,
3769,
7688,
370,
4165,
282,
7611,
465,
282,
9854,
12,
7508,
11239,
267,
327,
282,
6770,
334,
14362,
12,
1325,
18796,
9,
1373,
367,
3063,
14,
267,
485,
8421,
275,
283,
1014,
921,
22315,
14,
3442,
14,
87,
1119,
31673,
14,
8654,
15,
3858,
13,
6404,
15,
19135,
15,
3858,
6442,
15,
5019,
846,
4805,
267,
2589,
275,
747,
14,
2314,
267,
2589,
459,
52,
1438,
31541,
63,
16811,
63,
6351,
418,
275,
2403,
267,
1126,
76,
275,
1314,
360,
22805,
358,
267,
5687,
275,
3158,
14,
15680,
459,
5512,
2278,
585,
267,
1126,
76,
17371,
3174,
13,
5019,
297,
2475,
5512,
297,
5687,
12,
1467,
2475,
8421,
297,
485,
8421,
12,
1467,
2475,
719,
461,
297,
2475,
2913,
297,
1994,
2374,
15,
2307,
358,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
3,
1898,
334,
67,
9,
6171,
13,
12682,
12,
7964,
29590,
491,
4380,
6878,
20548,
13863,
12,
20376,
14,
199,
3,
2165,
16584,
737,
314,
7964,
29590,
491,
4380,
6878,
20548,
16871,
31671,
14,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
428,
1389,
14,
199,
3,
18208,
701,
377,
16216,
598,
11020,
472,
12,
22387,
11020,
472,
32,
914,
7530,
14,
16294,
12,
2900,
4481,
4644,
14,
199,
3,
491,
44,
14176,
13,
6012,
13,
8557,
11501,
199,
3,
199,
3,
2104,
2436,
12,
1937,
4178,
921,
5031,
14,
957,
15,
83,
1389,
15,
83,
1389,
199,
3,
7754,
2597,
1937,
314,
12840,
436,
5113,
1584,
367,
4154,
4245,
436,
314,
32426,
14,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
844,
334,
305,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
9,
1015,
499,
14,
17,
12,
21141,
26709,
21300,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
199,
3,
2428,
1821,
3408,
27,
1928,
2755,
314,
5292,
3408,
1634,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
1666,
314,
2895,
436,
199,
3,
3704,
402,
314,
1664,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
15673,
13,
13421,
8217,
199,
4605,
199,
504,
308,
1389,
492,
627,
199,
646,
747,
421,
199,
533,
20566,
6442,
8,
8599,
304,
272,
408,
12589,
24683,
365,
282,
2867,
2032,
4084,
367,
314,
5773,
56,
730,
6031,
2126,
2656,
14,
221,
5311,
9402,
1536,
12,
652,
1159,
365,
440,
282,
295,
496,
2033,
559,
830,
12096,
1041,
339,
26586,
275,
298,
1014,
921,
1544,
14,
84,
1518,
14,
1308,
15,
3858,
6442,
2,
339,
327,
13276,
687,
2488,
4770,
2952,
314,
14709,
6442,
15216,
83,
886,
440,
272,
327,
1006,
1678,
315,
15354,
89,
14,
272,
327,
272,
327,
6262,
3695,
26,
20566,
17458,
7029,
3932,
25801,
28914,
590,
334,
6101,
6665,
10842,
272,
327,
2985,
1240,
652,
627,
17458,
10,
1396,
680,
221,
6006,
365,
949,
6954,
4340,
370,
5647,
282,
272,
327,
11982,
461,
3907,
402,
314,
2559,
14,
272,
327,
272,
327,
2136,
3984,
3063,
10299,
316,
314,
12096,
5821,
687,
307,
1518,
14,
1308,
1159,
3831,
402,
272,
327,
13612,
269,
530,
5821,
14,
221,
961,
4910,
626,
314,
9040,
367,
314,
18535,
272,
327,
6337,
365,
17830,
14,
221,
7529,
1133,
4691,
626,
7090,
393,
1265,
10617,
12,
652,
1159,
5139,
272,
327,
22200,
5773,
56,
1011,
31541,
538,
687,
325,
14,
71,
14,
9428,
290,
14,
3442,
4496,
5084,
12,
1314,
365,
272,
327,
440,
295,
496,
2033,
559,
830,
14,
272,
1015,
360,
6442,
297,
283,
24,
70,
24,
3003,
8507,
24098,
67,
2036,
65,
1407,
65,
18,
69,
2576,
11165,
11939,
67,
10552,
297,
288,
1166,
534,
8915,
921,
84,
1518,
14,
1308,
15,
11141,
269,
530,
15,
19135,
15,
3858,
6442,
15,
10680,
15,
3174,
13,
5019,
13,
324,
88,
14,
5369,
14,
6838,
358,
339,
327,
6006,
1630,
440,
17021,
370,
506,
282,
4890,
769,
402,
21149,
14,
272,
327,
6058,
2387,
26,
272,
327,
257,
2615,
5687,
334,
14287,
2127,
9,
272,
327,
257,
21576,
5687,
334,
7241,
435,
1655,
6117,
436,
10815,
9,
272,
327,
257,
7425,
5687,
334,
4316,
435,
671,
69,
3858,
12,
7647,
439,
941,
12,
282,
9284,
10815,
9,
272,
327,
257,
5678,
5687,
334,
6104,
436,
15571,
9,
272,
327,
257,
13460,
5687,
334,
6104,
1454,
9,
272,
327,
1666,
26,
272,
327,
4178,
921,
1544,
14,
84,
1518,
14,
1308,
15,
3858,
6442,
15,
1301,
15,
3858,
6442,
13,
287,
15,
3858,
6442,
13,
287,
14,
1360,
3,
88,
17,
13,
7991,
821,
82,
22,
272,
9854,
8,
267,
283,
5512,
297,
267,
849,
534,
7241,
297,
267,
1338,
7782,
21508,
297,
283,
4316,
297,
283,
7241,
297,
283,
14345,
297,
283,
2861,
659,
267,
1369,
534,
8599,
10026,
370,
3907,
7,
272,
776,
339,
8350,
63,
265,
360,
22805,
297,
730,
534,
1506,
358,
339,
347,
3907,
8,
277,
12,
3158,
12,
2403,
304,
267,
327,
11719,
14709,
6442,
1159,
15216,
2656,
27401,
370,
333,
588,
6236,
1785,
8826,
12,
267,
327,
315,
1212,
16913,
402,
3769,
7688,
370,
4165,
282,
7611,
465,
282,
9854,
12,
7508,
11239,
267,
327,
282,
6770,
334,
14362,
12,
1325,
18796,
9,
1373,
367,
3063,
14,
267,
485,
8421,
275,
283,
1014,
921,
22315,
14,
3442,
14,
87,
1119,
31673,
14,
8654,
15,
3858,
13,
6404,
15,
19135,
15,
3858,
6442,
15,
5019,
846,
4805,
267,
2589,
275,
747,
14,
2314,
267,
2589,
459,
52,
1438,
31541,
63,
16811,
63,
6351,
418,
275,
2403,
267,
1126,
76,
275,
1314,
360,
22805,
358,
267,
5687,
275,
3158,
14,
15680,
459,
5512,
2278,
585,
267,
1126,
76,
17371,
3174,
13,
5019,
297,
2475,
5512,
297,
5687,
12,
1467,
2475,
8421,
297,
485,
8421,
12,
1467,
2475,
719,
461,
297,
2475,
2913,
297,
1994,
2374,
15,
2307,
358,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
amyvmiwei/kbengine
|
kbe/res/scripts/common/Lib/site-packages/setuptools/tests/test_dist_info.py
|
452
|
2615
|
"""Test .dist-info style distributions.
"""
import os
import shutil
import tempfile
import unittest
import textwrap
try:
import ast
except:
pass
import pkg_resources
from setuptools.tests.py26compat import skipIf
def DALS(s):
"dedent and left-strip"
return textwrap.dedent(s).lstrip()
class TestDistInfo(unittest.TestCase):
def test_distinfo(self):
dists = {}
for d in pkg_resources.find_distributions(self.tmpdir):
dists[d.project_name] = d
assert len(dists) == 2, dists
unversioned = dists['UnversionedDistribution']
versioned = dists['VersionedDistribution']
assert versioned.version == '2.718' # from filename
assert unversioned.version == '0.3' # from METADATA
@skipIf('ast' not in globals(),
"ast is used to test conditional dependencies (Python >= 2.6)")
def test_conditional_dependencies(self):
requires = [pkg_resources.Requirement.parse('splort==4'),
pkg_resources.Requirement.parse('quux>=1.1')]
for d in pkg_resources.find_distributions(self.tmpdir):
self.assertEqual(d.requires(), requires[:1])
self.assertEqual(d.requires(extras=('baz',)), requires)
self.assertEqual(d.extras, ['baz'])
def setUp(self):
self.tmpdir = tempfile.mkdtemp()
versioned = os.path.join(self.tmpdir,
'VersionedDistribution-2.718.dist-info')
os.mkdir(versioned)
metadata_file = open(os.path.join(versioned, 'METADATA'), 'w+')
try:
metadata_file.write(DALS(
"""
Metadata-Version: 1.2
Name: VersionedDistribution
Requires-Dist: splort (4)
Provides-Extra: baz
Requires-Dist: quux (>=1.1); extra == 'baz'
"""))
finally:
metadata_file.close()
unversioned = os.path.join(self.tmpdir,
'UnversionedDistribution.dist-info')
os.mkdir(unversioned)
metadata_file = open(os.path.join(unversioned, 'METADATA'), 'w+')
try:
metadata_file.write(DALS(
"""
Metadata-Version: 1.2
Name: UnversionedDistribution
Version: 0.3
Requires-Dist: splort (==4)
Provides-Extra: baz
Requires-Dist: quux (>=1.1); extra == 'baz'
"""))
finally:
metadata_file.close()
def tearDown(self):
shutil.rmtree(self.tmpdir)
|
lgpl-3.0
|
[
624,
774,
1275,
2686,
13,
815,
3449,
10208,
14,
199,
624,
199,
646,
747,
199,
646,
5145,
199,
646,
5549,
199,
646,
2882,
199,
646,
13390,
199,
199,
893,
26,
272,
492,
6073,
199,
2590,
26,
272,
986,
199,
199,
646,
5496,
63,
4435,
199,
199,
504,
9116,
14,
2219,
14,
647,
1479,
5819,
492,
3372,
3917,
199,
199,
318,
577,
748,
51,
8,
83,
304,
272,
298,
14674,
436,
3602,
13,
1913,
2,
272,
372,
13390,
14,
14674,
8,
83,
680,
10124,
342,
199,
199,
533,
1379,
12012,
2354,
8,
2796,
14,
1746,
304,
339,
347,
511,
63,
2686,
815,
8,
277,
304,
267,
23697,
275,
1052,
267,
367,
366,
315,
5496,
63,
4435,
14,
1623,
63,
5613,
8,
277,
14,
8616,
304,
288,
23697,
59,
68,
14,
1715,
63,
354,
61,
275,
366,
398,
702,
822,
8,
18552,
9,
508,
499,
12,
23697,
398,
625,
24155,
275,
23697,
459,
1358,
24155,
8580,
418,
267,
31792,
275,
23697,
459,
3673,
12308,
8580,
418,
398,
702,
31792,
14,
1023,
508,
283,
18,
14,
26948,
7,
327,
687,
1788,
267,
702,
625,
24155,
14,
1023,
508,
283,
16,
14,
19,
7,
327,
687,
19357,
8071,
339,
768,
15118,
360,
1810,
7,
440,
315,
7992,
1062,
267,
298,
1810,
365,
1202,
370,
511,
12303,
5124,
334,
4718,
2356,
499,
14,
22,
6320,
272,
347,
511,
63,
14353,
63,
5714,
8,
277,
304,
267,
5074,
275,
359,
4600,
63,
4435,
14,
17947,
14,
1122,
360,
15276,
361,
389,
20,
659,
490,
5496,
63,
4435,
14,
17947,
14,
1122,
360,
32050,
8119,
17,
14,
17,
5440,
398,
367,
366,
315,
5496,
63,
4435,
14,
1623,
63,
5613,
8,
277,
14,
8616,
304,
288,
291,
14,
629,
8,
68,
14,
6537,
1062,
5074,
1491,
17,
566,
288,
291,
14,
629,
8,
68,
14,
6537,
8,
9975,
7782,
6185,
16256,
5074,
9,
288,
291,
14,
629,
8,
68,
14,
9975,
12,
788,
6185,
1105,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
8616,
275,
5549,
14,
11983,
342,
267,
31792,
275,
747,
14,
515,
14,
904,
8,
277,
14,
8616,
12,
639,
283,
3673,
12308,
8580,
13,
18,
14,
26948,
14,
2686,
13,
815,
358,
267,
747,
14,
8215,
8,
24155,
9,
267,
3341,
63,
493,
275,
1551,
8,
736,
14,
515,
14,
904,
8,
24155,
12,
283,
8314,
659,
283,
87,
13854,
267,
862,
26,
288,
3341,
63,
493,
14,
952,
8,
10741,
51,
8,
355,
408,
355,
16160,
13,
3353,
26,
413,
14,
18,
355,
2812,
26,
5444,
12308,
8580,
355,
15127,
13,
12012,
26,
23168,
361,
334,
20,
9,
355,
21552,
13,
7426,
26,
15507,
355,
15127,
13,
12012,
26,
2173,
2521,
334,
8119,
17,
14,
17,
2736,
2402,
508,
283,
6185,
7,
355,
24072,
267,
3753,
26,
288,
3341,
63,
493,
14,
1600,
342,
267,
625,
24155,
275,
747,
14,
515,
14,
904,
8,
277,
14,
8616,
12,
3521,
283,
1358,
24155,
8580,
14,
2686,
13,
815,
358,
267,
747,
14,
8215,
8,
324,
24155,
9,
267,
3341,
63,
493,
275,
1551,
8,
736,
14,
515,
14,
904,
8,
324,
24155,
12,
283,
8314,
659,
283,
87,
13854,
267,
862,
26,
288,
3341,
63,
493,
14,
952,
8,
10741,
51,
8,
355,
408,
355,
16160,
13,
3353,
26,
413,
14,
18,
355,
2812,
26,
1910,
24155,
8580,
355,
3394,
26,
378,
14,
19,
355,
15127,
13,
12012,
26,
23168,
361,
334,
389,
20,
9,
355,
21552,
13,
7426,
26,
15507,
355,
15127,
13,
12012,
26,
2173,
2521,
334,
8119,
17,
14,
17,
2736,
2402,
508,
283,
6185,
7,
355,
24072,
267,
3753,
26,
288,
3341,
63,
493,
14,
1600,
342,
339,
347,
6766,
8,
277,
304,
267,
5145,
14,
9242,
8,
277,
14,
8616,
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
] |
[
774,
1275,
2686,
13,
815,
3449,
10208,
14,
199,
624,
199,
646,
747,
199,
646,
5145,
199,
646,
5549,
199,
646,
2882,
199,
646,
13390,
199,
199,
893,
26,
272,
492,
6073,
199,
2590,
26,
272,
986,
199,
199,
646,
5496,
63,
4435,
199,
199,
504,
9116,
14,
2219,
14,
647,
1479,
5819,
492,
3372,
3917,
199,
199,
318,
577,
748,
51,
8,
83,
304,
272,
298,
14674,
436,
3602,
13,
1913,
2,
272,
372,
13390,
14,
14674,
8,
83,
680,
10124,
342,
199,
199,
533,
1379,
12012,
2354,
8,
2796,
14,
1746,
304,
339,
347,
511,
63,
2686,
815,
8,
277,
304,
267,
23697,
275,
1052,
267,
367,
366,
315,
5496,
63,
4435,
14,
1623,
63,
5613,
8,
277,
14,
8616,
304,
288,
23697,
59,
68,
14,
1715,
63,
354,
61,
275,
366,
398,
702,
822,
8,
18552,
9,
508,
499,
12,
23697,
398,
625,
24155,
275,
23697,
459,
1358,
24155,
8580,
418,
267,
31792,
275,
23697,
459,
3673,
12308,
8580,
418,
398,
702,
31792,
14,
1023,
508,
283,
18,
14,
26948,
7,
327,
687,
1788,
267,
702,
625,
24155,
14,
1023,
508,
283,
16,
14,
19,
7,
327,
687,
19357,
8071,
339,
768,
15118,
360,
1810,
7,
440,
315,
7992,
1062,
267,
298,
1810,
365,
1202,
370,
511,
12303,
5124,
334,
4718,
2356,
499,
14,
22,
6320,
272,
347,
511,
63,
14353,
63,
5714,
8,
277,
304,
267,
5074,
275,
359,
4600,
63,
4435,
14,
17947,
14,
1122,
360,
15276,
361,
389,
20,
659,
490,
5496,
63,
4435,
14,
17947,
14,
1122,
360,
32050,
8119,
17,
14,
17,
5440,
398,
367,
366,
315,
5496,
63,
4435,
14,
1623,
63,
5613,
8,
277,
14,
8616,
304,
288,
291,
14,
629,
8,
68,
14,
6537,
1062,
5074,
1491,
17,
566,
288,
291,
14,
629,
8,
68,
14,
6537,
8,
9975,
7782,
6185,
16256,
5074,
9,
288,
291,
14,
629,
8,
68,
14,
9975,
12,
788,
6185,
1105,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
8616,
275,
5549,
14,
11983,
342,
267,
31792,
275,
747,
14,
515,
14,
904,
8,
277,
14,
8616,
12,
639,
283,
3673,
12308,
8580,
13,
18,
14,
26948,
14,
2686,
13,
815,
358,
267,
747,
14,
8215,
8,
24155,
9,
267,
3341,
63,
493,
275,
1551,
8,
736,
14,
515,
14,
904,
8,
24155,
12,
283,
8314,
659,
283,
87,
13854,
267,
862,
26,
288,
3341,
63,
493,
14,
952,
8,
10741,
51,
8,
355,
408,
355,
16160,
13,
3353,
26,
413,
14,
18,
355,
2812,
26,
5444,
12308,
8580,
355,
15127,
13,
12012,
26,
23168,
361,
334,
20,
9,
355,
21552,
13,
7426,
26,
15507,
355,
15127,
13,
12012,
26,
2173,
2521,
334,
8119,
17,
14,
17,
2736,
2402,
508,
283,
6185,
7,
355,
24072,
267,
3753,
26,
288,
3341,
63,
493,
14,
1600,
342,
267,
625,
24155,
275,
747,
14,
515,
14,
904,
8,
277,
14,
8616,
12,
3521,
283,
1358,
24155,
8580,
14,
2686,
13,
815,
358,
267,
747,
14,
8215,
8,
324,
24155,
9,
267,
3341,
63,
493,
275,
1551,
8,
736,
14,
515,
14,
904,
8,
324,
24155,
12,
283,
8314,
659,
283,
87,
13854,
267,
862,
26,
288,
3341,
63,
493,
14,
952,
8,
10741,
51,
8,
355,
408,
355,
16160,
13,
3353,
26,
413,
14,
18,
355,
2812,
26,
1910,
24155,
8580,
355,
3394,
26,
378,
14,
19,
355,
15127,
13,
12012,
26,
23168,
361,
334,
389,
20,
9,
355,
21552,
13,
7426,
26,
15507,
355,
15127,
13,
12012,
26,
2173,
2521,
334,
8119,
17,
14,
17,
2736,
2402,
508,
283,
6185,
7,
355,
24072,
267,
3753,
26,
288,
3341,
63,
493,
14,
1600,
342,
339,
347,
6766,
8,
277,
304,
267,
5145,
14,
9242,
8,
277,
14,
8616,
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,
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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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
] |
damdam-s/OpenUpgrade
|
addons/event/report/report_event_registration.py
|
310
|
4079
|
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp import models, fields
from openerp import tools
class report_event_registration(models.Model):
"""Events Analysis"""
_name = "report.event.registration"
_order = 'event_date desc'
_auto = False
event_date = fields.Datetime('Event Date', readonly=True)
event_id = fields.Many2one('event.event', 'Event', required=True)
draft_state = fields.Integer(' # No of Draft Registrations')
confirm_state = fields.Integer(' # No of Confirmed Registrations')
seats_max = fields.Integer('Max Seats')
nbevent = fields.Integer('Number of Events')
nbregistration = fields.Integer('Number of Registrations')
event_type = fields.Many2one('event.type', 'Event Type')
registration_state = fields.Selection([('draft', 'Draft'), ('confirm', 'Confirmed'), ('done', 'Attended'), ('cancel', 'Cancelled')], 'Registration State', readonly=True, required=True)
event_state = fields.Selection([('draft', 'Draft'), ('confirm', 'Confirmed'), ('done', 'Done'), ('cancel', 'Cancelled')], 'Event State', readonly=True, required=True)
user_id = fields.Many2one('res.users', 'Event Responsible', readonly=True)
user_id_registration = fields.Many2one('res.users', 'Register', readonly=True)
name_registration = fields.Char('Participant / Contact Name', readonly=True)
company_id = fields.Many2one('res.company', 'Company', readonly=True)
def init(self, cr):
"""Initialize the sql view for the event registration """
tools.drop_view_if_exists(cr, 'report_event_registration')
# TOFIX this request won't select events that have no registration
cr.execute(""" CREATE VIEW report_event_registration AS (
SELECT
e.id::varchar || '/' || coalesce(r.id::varchar,'') AS id,
e.id AS event_id,
e.user_id AS user_id,
r.user_id AS user_id_registration,
r.name AS name_registration,
e.company_id AS company_id,
e.date_begin AS event_date,
count(r.id) AS nbevent,
sum(r.nb_register) AS nbregistration,
CASE WHEN r.state IN ('draft') THEN r.nb_register ELSE 0 END AS draft_state,
CASE WHEN r.state IN ('open','done') THEN r.nb_register ELSE 0 END AS confirm_state,
e.type AS event_type,
e.seats_max AS seats_max,
e.state AS event_state,
r.state AS registration_state
FROM
event_event e
LEFT JOIN event_registration r ON (e.id=r.event_id)
GROUP BY
event_id,
user_id_registration,
r.id,
registration_state,
r.nb_register,
event_type,
e.id,
e.date_begin,
e.user_id,
event_state,
e.company_id,
e.seats_max,
name_registration
)
""")
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
504,
5166,
492,
1709,
12,
1504,
199,
504,
5166,
492,
7249,
421,
199,
533,
3622,
63,
1430,
63,
8054,
8,
992,
14,
1685,
304,
272,
408,
11770,
21916,
624,
272,
485,
354,
275,
298,
3070,
14,
1430,
14,
8054,
2,
272,
485,
1648,
275,
283,
1430,
63,
602,
4328,
7,
272,
485,
2495,
275,
756,
339,
1566,
63,
602,
275,
1504,
14,
19636,
360,
2390,
6148,
297,
6863,
29,
549,
9,
272,
1566,
63,
344,
275,
1504,
14,
4089,
18,
368,
360,
1430,
14,
1430,
297,
283,
2390,
297,
1415,
29,
549,
9,
272,
11872,
63,
929,
275,
1504,
14,
2674,
360,
327,
3091,
402,
28090,
5044,
631,
3801,
358,
272,
12679,
63,
929,
275,
1504,
14,
2674,
360,
327,
3091,
402,
1448,
11451,
5044,
631,
3801,
358,
272,
542,
1956,
63,
988,
275,
1504,
14,
2674,
360,
4261,
3240,
1956,
358,
272,
302,
1235,
782,
275,
1504,
14,
2674,
360,
3259,
402,
27982,
358,
272,
8526,
8054,
275,
1504,
14,
2674,
360,
3259,
402,
5044,
631,
3801,
358,
272,
1566,
63,
466,
275,
1504,
14,
4089,
18,
368,
360,
1430,
14,
466,
297,
283,
2390,
2434,
358,
272,
10991,
63,
929,
275,
1504,
14,
7713,
8318,
7185,
297,
283,
18332,
659,
661,
9548,
297,
283,
714,
11451,
659,
661,
4456,
297,
283,
1271,
6943,
659,
661,
6406,
297,
283,
22127,
2665,
283,
11757,
8511,
297,
6863,
29,
549,
12,
1415,
29,
549,
9,
272,
1566,
63,
929,
275,
1504,
14,
7713,
8318,
7185,
297,
283,
18332,
659,
661,
9548,
297,
283,
714,
11451,
659,
661,
4456,
297,
283,
10759,
659,
661,
6406,
297,
283,
22127,
2665,
283,
2390,
8511,
297,
6863,
29,
549,
12,
1415,
29,
549,
9,
272,
922,
63,
344,
275,
1504,
14,
4089,
18,
368,
360,
470,
14,
3707,
297,
283,
2390,
3591,
678,
1164,
297,
6863,
29,
549,
9,
272,
922,
63,
344,
63,
8054,
275,
1504,
14,
4089,
18,
368,
360,
470,
14,
3707,
297,
283,
7099,
297,
6863,
29,
549,
9,
272,
536,
63,
8054,
275,
1504,
14,
1610,
360,
1262,
16448,
1182,
18684,
2812,
297,
6863,
29,
549,
9,
272,
7233,
63,
344,
275,
1504,
14,
4089,
18,
368,
360,
470,
14,
4627,
297,
283,
16063,
297,
6863,
29,
549,
9,
339,
347,
4205,
8,
277,
12,
2467,
304,
267,
408,
9345,
314,
3875,
2455,
367,
314,
1566,
10991,
408,
267,
7249,
14,
4824,
63,
1345,
63,
692,
63,
2444,
8,
1556,
12,
283,
3070,
63,
1430,
63,
8054,
358,
398,
327,
2296,
5192,
642,
1056,
7859,
1133,
3504,
4474,
626,
1172,
949,
10991,
267,
2467,
14,
2526,
4852,
16999,
30359,
3622,
63,
1430,
63,
8054,
4319,
334,
288,
10468,
355,
325,
14,
344,
447,
25545,
12208,
7324,
12208,
512,
29944,
8,
82,
14,
344,
447,
25545,
2584,
358,
4319,
1305,
12,
355,
325,
14,
344,
4319,
1566,
63,
344,
12,
355,
325,
14,
751,
63,
344,
4319,
922,
63,
344,
12,
355,
519,
14,
751,
63,
344,
4319,
922,
63,
344,
63,
8054,
12,
355,
519,
14,
354,
4319,
536,
63,
8054,
12,
355,
325,
14,
4627,
63,
344,
4319,
7233,
63,
344,
12,
355,
325,
14,
602,
63,
5037,
4319,
1566,
63,
602,
12,
355,
2338,
8,
82,
14,
344,
9,
4319,
302,
1235,
782,
12,
355,
3089,
8,
82,
14,
4994,
63,
2683,
9,
4319,
8526,
8054,
12,
355,
7240,
899,
27802,
519,
14,
929,
1621,
661,
7185,
358,
27299,
519,
14,
4994,
63,
2683,
22325,
899,
378,
7729,
4319,
11872,
63,
929,
12,
355,
7240,
899,
27802,
519,
14,
929,
1621,
661,
1490,
1673,
4456,
358,
27299,
519,
14,
4994,
63,
2683,
22325,
899,
378,
7729,
4319,
12679,
63,
929,
12,
355,
325,
14,
466,
4319,
1566,
63,
466,
12,
355,
325,
14,
261,
1956,
63,
988,
4319,
542,
1956,
63,
988,
12,
355,
325,
14,
929,
4319,
1566,
63,
929,
12,
355,
519,
14,
929,
4319,
10991,
63,
929,
288,
4442,
355,
1566,
63,
1430,
325,
355,
6578,
10593,
1566,
63,
8054,
519,
5258,
334,
69,
14,
344,
29,
82,
14,
1430,
63,
344,
9,
953,
15443,
6515,
355,
1566,
63,
344,
12,
355,
922,
63,
344,
63,
8054,
12,
355,
519,
14,
344,
12,
355,
10991,
63,
929,
12,
355,
519,
14,
4994,
63,
2683,
12,
355,
1566,
63,
466,
12,
355,
325,
14,
344,
12,
355,
325,
14,
602,
63,
5037,
12,
355,
325,
14,
751,
63,
344,
12,
355,
1566,
63,
929,
12,
355,
325,
14,
4627,
63,
344,
12,
355,
325,
14,
261,
1956,
63,
988,
12,
355,
536,
63,
8054,
267,
776,
267,
7857,
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
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
504,
5166,
492,
1709,
12,
1504,
199,
504,
5166,
492,
7249,
421,
199,
533,
3622,
63,
1430,
63,
8054,
8,
992,
14,
1685,
304,
272,
408,
11770,
21916,
624,
272,
485,
354,
275,
298,
3070,
14,
1430,
14,
8054,
2,
272,
485,
1648,
275,
283,
1430,
63,
602,
4328,
7,
272,
485,
2495,
275,
756,
339,
1566,
63,
602,
275,
1504,
14,
19636,
360,
2390,
6148,
297,
6863,
29,
549,
9,
272,
1566,
63,
344,
275,
1504,
14,
4089,
18,
368,
360,
1430,
14,
1430,
297,
283,
2390,
297,
1415,
29,
549,
9,
272,
11872,
63,
929,
275,
1504,
14,
2674,
360,
327,
3091,
402,
28090,
5044,
631,
3801,
358,
272,
12679,
63,
929,
275,
1504,
14,
2674,
360,
327,
3091,
402,
1448,
11451,
5044,
631,
3801,
358,
272,
542,
1956,
63,
988,
275,
1504,
14,
2674,
360,
4261,
3240,
1956,
358,
272,
302,
1235,
782,
275,
1504,
14,
2674,
360,
3259,
402,
27982,
358,
272,
8526,
8054,
275,
1504,
14,
2674,
360,
3259,
402,
5044,
631,
3801,
358,
272,
1566,
63,
466,
275,
1504,
14,
4089,
18,
368,
360,
1430,
14,
466,
297,
283,
2390,
2434,
358,
272,
10991,
63,
929,
275,
1504,
14,
7713,
8318,
7185,
297,
283,
18332,
659,
661,
9548,
297,
283,
714,
11451,
659,
661,
4456,
297,
283,
1271,
6943,
659,
661,
6406,
297,
283,
22127,
2665,
283,
11757,
8511,
297,
6863,
29,
549,
12,
1415,
29,
549,
9,
272,
1566,
63,
929,
275,
1504,
14,
7713,
8318,
7185,
297,
283,
18332,
659,
661,
9548,
297,
283,
714,
11451,
659,
661,
4456,
297,
283,
10759,
659,
661,
6406,
297,
283,
22127,
2665,
283,
2390,
8511,
297,
6863,
29,
549,
12,
1415,
29,
549,
9,
272,
922,
63,
344,
275,
1504,
14,
4089,
18,
368,
360,
470,
14,
3707,
297,
283,
2390,
3591,
678,
1164,
297,
6863,
29,
549,
9,
272,
922,
63,
344,
63,
8054,
275,
1504,
14,
4089,
18,
368,
360,
470,
14,
3707,
297,
283,
7099,
297,
6863,
29,
549,
9,
272,
536,
63,
8054,
275,
1504,
14,
1610,
360,
1262,
16448,
1182,
18684,
2812,
297,
6863,
29,
549,
9,
272,
7233,
63,
344,
275,
1504,
14,
4089,
18,
368,
360,
470,
14,
4627,
297,
283,
16063,
297,
6863,
29,
549,
9,
339,
347,
4205,
8,
277,
12,
2467,
304,
267,
408,
9345,
314,
3875,
2455,
367,
314,
1566,
10991,
408,
267,
7249,
14,
4824,
63,
1345,
63,
692,
63,
2444,
8,
1556,
12,
283,
3070,
63,
1430,
63,
8054,
358,
398,
327,
2296,
5192,
642,
1056,
7859,
1133,
3504,
4474,
626,
1172,
949,
10991,
267,
2467,
14,
2526,
4852,
16999,
30359,
3622,
63,
1430,
63,
8054,
4319,
334,
288,
10468,
355,
325,
14,
344,
447,
25545,
12208,
7324,
12208,
512,
29944,
8,
82,
14,
344,
447,
25545,
2584,
358,
4319,
1305,
12,
355,
325,
14,
344,
4319,
1566,
63,
344,
12,
355,
325,
14,
751,
63,
344,
4319,
922,
63,
344,
12,
355,
519,
14,
751,
63,
344,
4319,
922,
63,
344,
63,
8054,
12,
355,
519,
14,
354,
4319,
536,
63,
8054,
12,
355,
325,
14,
4627,
63,
344,
4319,
7233,
63,
344,
12,
355,
325,
14,
602,
63,
5037,
4319,
1566,
63,
602,
12,
355,
2338,
8,
82,
14,
344,
9,
4319,
302,
1235,
782,
12,
355,
3089,
8,
82,
14,
4994,
63,
2683,
9,
4319,
8526,
8054,
12,
355,
7240,
899,
27802,
519,
14,
929,
1621,
661,
7185,
358,
27299,
519,
14,
4994,
63,
2683,
22325,
899,
378,
7729,
4319,
11872,
63,
929,
12,
355,
7240,
899,
27802,
519,
14,
929,
1621,
661,
1490,
1673,
4456,
358,
27299,
519,
14,
4994,
63,
2683,
22325,
899,
378,
7729,
4319,
12679,
63,
929,
12,
355,
325,
14,
466,
4319,
1566,
63,
466,
12,
355,
325,
14,
261,
1956,
63,
988,
4319,
542,
1956,
63,
988,
12,
355,
325,
14,
929,
4319,
1566,
63,
929,
12,
355,
519,
14,
929,
4319,
10991,
63,
929,
288,
4442,
355,
1566,
63,
1430,
325,
355,
6578,
10593,
1566,
63,
8054,
519,
5258,
334,
69,
14,
344,
29,
82,
14,
1430,
63,
344,
9,
953,
15443,
6515,
355,
1566,
63,
344,
12,
355,
922,
63,
344,
63,
8054,
12,
355,
519,
14,
344,
12,
355,
10991,
63,
929,
12,
355,
519,
14,
4994,
63,
2683,
12,
355,
1566,
63,
466,
12,
355,
325,
14,
344,
12,
355,
325,
14,
602,
63,
5037,
12,
355,
325,
14,
751,
63,
344,
12,
355,
1566,
63,
929,
12,
355,
325,
14,
4627,
63,
344,
12,
355,
325,
14,
261,
1956,
63,
988,
12,
355,
536,
63,
8054,
267,
776,
267,
7857,
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,
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,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# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
# * Neither the name of Google Inc. nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""gen_gtest_pred_impl.py v0.1
Generates the implementation of Google Test predicate assertions and
accompanying tests.
Usage:
gen_gtest_pred_impl.py MAX_ARITY
where MAX_ARITY is a positive integer.
The command generates the implementation of up-to MAX_ARITY-ary
predicate assertions, and writes it to file gtest_pred_impl.h in the
directory where the script is. It also generates the accompanying
unit test in file gtest_pred_impl_unittest.cc.
"""
__author__ = 'wan@google.com (Zhanyong Wan)'
import os
import sys
import time
# Where this script is.
SCRIPT_DIR = os.path.dirname(sys.argv[0])
# Where to store the generated header.
HEADER = os.path.join(SCRIPT_DIR, '../include/gtest/gtest_pred_impl.h')
# Where to store the generated unit test.
UNIT_TEST = os.path.join(SCRIPT_DIR, '../test/gtest_pred_impl_unittest.cc')
def HeaderPreamble(n):
"""Returns the preamble for the header file.
Args:
n: the maximum arity of the predicate macros to be generated.
"""
# A map that defines the values used in the preamble template.
DEFS = {
'today' : time.strftime('%m/%d/%Y'),
'year' : time.strftime('%Y'),
'command' : '%s %s' % (os.path.basename(sys.argv[0]), n),
'n' : n
}
return (
"""// Copyright 2006, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// This file is AUTOMATICALLY GENERATED on %(today)s by command
// '%(command)s'. DO NOT EDIT BY HAND!
//
// Implements a family of generic predicate assertion macros.
#ifndef GTEST_INCLUDE_GTEST_GTEST_PRED_IMPL_H_
#define GTEST_INCLUDE_GTEST_GTEST_PRED_IMPL_H_
#include "gtest/gtest.h"
namespace testing {
// This header implements a family of generic predicate assertion
// macros:
//
// ASSERT_PRED_FORMAT1(pred_format, v1)
// ASSERT_PRED_FORMAT2(pred_format, v1, v2)
// ...
//
// where pred_format is a function or functor that takes n (in the
// case of ASSERT_PRED_FORMATn) values and their source expression
// text, and returns a testing::AssertionResult. See the definition
// of ASSERT_EQ in gtest.h for an example.
//
// If you don't care about formatting, you can use the more
// restrictive version:
//
// ASSERT_PRED1(pred, v1)
// ASSERT_PRED2(pred, v1, v2)
// ...
//
// where pred is an n-ary function or functor that returns bool,
// and the values v1, v2, ..., must support the << operator for
// streaming to std::ostream.
//
// We also define the EXPECT_* variations.
//
// For now we only support predicates whose arity is at most %(n)s.
// Please email googletestframework@googlegroups.com if you need
// support for higher arities.
// GTEST_ASSERT_ is the basic statement to which all of the assertions
// in this file reduce. Don't use this in your code.
#define GTEST_ASSERT_(expression, on_failure) \\
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \\
if (const ::testing::AssertionResult gtest_ar = (expression)) \\
; \\
else \\
on_failure(gtest_ar.failure_message())
""" % DEFS)
def Arity(n):
"""Returns the English name of the given arity."""
if n < 0:
return None
elif n <= 3:
return ['nullary', 'unary', 'binary', 'ternary'][n]
else:
return '%s-ary' % n
def Title(word):
"""Returns the given word in title case. The difference between
this and string's title() method is that Title('4-ary') is '4-ary'
while '4-ary'.title() is '4-Ary'."""
return word[0].upper() + word[1:]
def OneTo(n):
"""Returns the list [1, 2, 3, ..., n]."""
return range(1, n + 1)
def Iter(n, format, sep=''):
"""Given a positive integer n, a format string that contains 0 or
more '%s' format specs, and optionally a separator string, returns
the join of n strings, each formatted with the format string on an
iterator ranged from 1 to n.
Example:
Iter(3, 'v%s', sep=', ') returns 'v1, v2, v3'.
"""
# How many '%s' specs are in format?
spec_count = len(format.split('%s')) - 1
return sep.join([format % (spec_count * (i,)) for i in OneTo(n)])
def ImplementationForArity(n):
"""Returns the implementation of n-ary predicate assertions."""
# A map the defines the values used in the implementation template.
DEFS = {
'n' : str(n),
'vs' : Iter(n, 'v%s', sep=', '),
'vts' : Iter(n, '#v%s', sep=', '),
'arity' : Arity(n),
'Arity' : Title(Arity(n))
}
impl = """
// Helper function for implementing {EXPECT|ASSERT}_PRED%(n)s. Don't use
// this in your code.
template <typename Pred""" % DEFS
impl += Iter(n, """,
typename T%s""")
impl += """>
AssertionResult AssertPred%(n)sHelper(const char* pred_text""" % DEFS
impl += Iter(n, """,
const char* e%s""")
impl += """,
Pred pred"""
impl += Iter(n, """,
const T%s& v%s""")
impl += """) {
if (pred(%(vs)s)) return AssertionSuccess();
""" % DEFS
impl += ' return AssertionFailure() << pred_text << "("'
impl += Iter(n, """
<< e%s""", sep=' << ", "')
impl += ' << ") evaluates to false, where"'
impl += Iter(n, """
<< "\\n" << e%s << " evaluates to " << v%s""")
impl += """;
}
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT%(n)s.
// Don't use this in your code.
#define GTEST_PRED_FORMAT%(n)s_(pred_format, %(vs)s, on_failure)\\
GTEST_ASSERT_(pred_format(%(vts)s, %(vs)s), \\
on_failure)
// Internal macro for implementing {EXPECT|ASSERT}_PRED%(n)s. Don't use
// this in your code.
#define GTEST_PRED%(n)s_(pred, %(vs)s, on_failure)\\
GTEST_ASSERT_(::testing::AssertPred%(n)sHelper(#pred""" % DEFS
impl += Iter(n, """, \\
#v%s""")
impl += """, \\
pred"""
impl += Iter(n, """, \\
v%s""")
impl += """), on_failure)
// %(Arity)s predicate assertion macros.
#define EXPECT_PRED_FORMAT%(n)s(pred_format, %(vs)s) \\
GTEST_PRED_FORMAT%(n)s_(pred_format, %(vs)s, GTEST_NONFATAL_FAILURE_)
#define EXPECT_PRED%(n)s(pred, %(vs)s) \\
GTEST_PRED%(n)s_(pred, %(vs)s, GTEST_NONFATAL_FAILURE_)
#define ASSERT_PRED_FORMAT%(n)s(pred_format, %(vs)s) \\
GTEST_PRED_FORMAT%(n)s_(pred_format, %(vs)s, GTEST_FATAL_FAILURE_)
#define ASSERT_PRED%(n)s(pred, %(vs)s) \\
GTEST_PRED%(n)s_(pred, %(vs)s, GTEST_FATAL_FAILURE_)
""" % DEFS
return impl
def HeaderPostamble():
"""Returns the postamble for the header file."""
return """
} // namespace testing
#endif // GTEST_INCLUDE_GTEST_GTEST_PRED_IMPL_H_
"""
def GenerateFile(path, content):
"""Given a file path and a content string
overwrites it with the given content.
"""
print 'Updating file %s . . .' % path
f = file(path, 'w+')
print >>f, content,
f.close()
print 'File %s has been updated.' % path
def GenerateHeader(n):
"""Given the maximum arity n, updates the header file that implements
the predicate assertions.
"""
GenerateFile(HEADER,
HeaderPreamble(n)
+ ''.join([ImplementationForArity(i) for i in OneTo(n)])
+ HeaderPostamble())
def UnitTestPreamble():
"""Returns the preamble for the unit test file."""
# A map that defines the values used in the preamble template.
DEFS = {
'today' : time.strftime('%m/%d/%Y'),
'year' : time.strftime('%Y'),
'command' : '%s %s' % (os.path.basename(sys.argv[0]), sys.argv[1]),
}
return (
"""// Copyright 2006, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// This file is AUTOMATICALLY GENERATED on %(today)s by command
// '%(command)s'. DO NOT EDIT BY HAND!
// Regression test for gtest_pred_impl.h
//
// This file is generated by a script and quite long. If you intend to
// learn how Google Test works by reading its unit tests, read
// gtest_unittest.cc instead.
//
// This is intended as a regression test for the Google Test predicate
// assertions. We compile it as part of the gtest_unittest target
// only to keep the implementation tidy and compact, as it is quite
// involved to set up the stage for testing Google Test using Google
// Test itself.
//
// Currently, gtest_unittest takes ~11 seconds to run in the testing
// daemon. In the future, if it grows too large and needs much more
// time to finish, we should consider separating this file into a
// stand-alone regression test.
#include <iostream>
#include "gtest/gtest.h"
#include "gtest/gtest-spi.h"
// A user-defined data type.
struct Bool {
explicit Bool(int val) : value(val != 0) {}
bool operator>(int n) const { return value > Bool(n).value; }
Bool operator+(const Bool& rhs) const { return Bool(value + rhs.value); }
bool operator==(const Bool& rhs) const { return value == rhs.value; }
bool value;
};
// Enables Bool to be used in assertions.
std::ostream& operator<<(std::ostream& os, const Bool& x) {
return os << (x.value ? "true" : "false");
}
""" % DEFS)
def TestsForArity(n):
"""Returns the tests for n-ary predicate assertions."""
# A map that defines the values used in the template for the tests.
DEFS = {
'n' : n,
'es' : Iter(n, 'e%s', sep=', '),
'vs' : Iter(n, 'v%s', sep=', '),
'vts' : Iter(n, '#v%s', sep=', '),
'tvs' : Iter(n, 'T%s v%s', sep=', '),
'int_vs' : Iter(n, 'int v%s', sep=', '),
'Bool_vs' : Iter(n, 'Bool v%s', sep=', '),
'types' : Iter(n, 'typename T%s', sep=', '),
'v_sum' : Iter(n, 'v%s', sep=' + '),
'arity' : Arity(n),
'Arity' : Title(Arity(n)),
}
tests = (
"""// Sample functions/functors for testing %(arity)s predicate assertions.
// A %(arity)s predicate function.
template <%(types)s>
bool PredFunction%(n)s(%(tvs)s) {
return %(v_sum)s > 0;
}
// The following two functions are needed to circumvent a bug in
// gcc 2.95.3, which sometimes has problem with the above template
// function.
bool PredFunction%(n)sInt(%(int_vs)s) {
return %(v_sum)s > 0;
}
bool PredFunction%(n)sBool(%(Bool_vs)s) {
return %(v_sum)s > 0;
}
""" % DEFS)
tests += """
// A %(arity)s predicate functor.
struct PredFunctor%(n)s {
template <%(types)s>
bool operator()(""" % DEFS
tests += Iter(n, 'const T%s& v%s', sep=""",
""")
tests += """) {
return %(v_sum)s > 0;
}
};
""" % DEFS
tests += """
// A %(arity)s predicate-formatter function.
template <%(types)s>
testing::AssertionResult PredFormatFunction%(n)s(""" % DEFS
tests += Iter(n, 'const char* e%s', sep=""",
""")
tests += Iter(n, """,
const T%s& v%s""")
tests += """) {
if (PredFunction%(n)s(%(vs)s))
return testing::AssertionSuccess();
return testing::AssertionFailure()
<< """ % DEFS
tests += Iter(n, 'e%s', sep=' << " + " << ')
tests += """
<< " is expected to be positive, but evaluates to "
<< %(v_sum)s << ".";
}
""" % DEFS
tests += """
// A %(arity)s predicate-formatter functor.
struct PredFormatFunctor%(n)s {
template <%(types)s>
testing::AssertionResult operator()(""" % DEFS
tests += Iter(n, 'const char* e%s', sep=""",
""")
tests += Iter(n, """,
const T%s& v%s""")
tests += """) const {
return PredFormatFunction%(n)s(%(es)s, %(vs)s);
}
};
""" % DEFS
tests += """
// Tests for {EXPECT|ASSERT}_PRED_FORMAT%(n)s.
class Predicate%(n)sTest : public testing::Test {
protected:
virtual void SetUp() {
expected_to_finish_ = true;
finished_ = false;""" % DEFS
tests += """
""" + Iter(n, 'n%s_ = ') + """0;
}
"""
tests += """
virtual void TearDown() {
// Verifies that each of the predicate's arguments was evaluated
// exactly once."""
tests += ''.join(["""
EXPECT_EQ(1, n%s_) <<
"The predicate assertion didn't evaluate argument %s "
"exactly once.";""" % (i, i + 1) for i in OneTo(n)])
tests += """
// Verifies that the control flow in the test function is expected.
if (expected_to_finish_ && !finished_) {
FAIL() << "The predicate assertion unexpactedly aborted the test.";
} else if (!expected_to_finish_ && finished_) {
FAIL() << "The failed predicate assertion didn't abort the test "
"as expected.";
}
}
// true iff the test function is expected to run to finish.
static bool expected_to_finish_;
// true iff the test function did run to finish.
static bool finished_;
""" % DEFS
tests += Iter(n, """
static int n%s_;""")
tests += """
};
bool Predicate%(n)sTest::expected_to_finish_;
bool Predicate%(n)sTest::finished_;
""" % DEFS
tests += Iter(n, """int Predicate%%(n)sTest::n%s_;
""") % DEFS
tests += """
typedef Predicate%(n)sTest EXPECT_PRED_FORMAT%(n)sTest;
typedef Predicate%(n)sTest ASSERT_PRED_FORMAT%(n)sTest;
typedef Predicate%(n)sTest EXPECT_PRED%(n)sTest;
typedef Predicate%(n)sTest ASSERT_PRED%(n)sTest;
""" % DEFS
def GenTest(use_format, use_assert, expect_failure,
use_functor, use_user_type):
"""Returns the test for a predicate assertion macro.
Args:
use_format: true iff the assertion is a *_PRED_FORMAT*.
use_assert: true iff the assertion is a ASSERT_*.
expect_failure: true iff the assertion is expected to fail.
use_functor: true iff the first argument of the assertion is
a functor (as opposed to a function)
use_user_type: true iff the predicate functor/function takes
argument(s) of a user-defined type.
Example:
GenTest(1, 0, 0, 1, 0) returns a test that tests the behavior
of a successful EXPECT_PRED_FORMATn() that takes a functor
whose arguments have built-in types."""
if use_assert:
assrt = 'ASSERT' # 'assert' is reserved, so we cannot use
# that identifier here.
else:
assrt = 'EXPECT'
assertion = assrt + '_PRED'
if use_format:
pred_format = 'PredFormat'
assertion += '_FORMAT'
else:
pred_format = 'Pred'
assertion += '%(n)s' % DEFS
if use_functor:
pred_format_type = 'functor'
pred_format += 'Functor%(n)s()'
else:
pred_format_type = 'function'
pred_format += 'Function%(n)s'
if not use_format:
if use_user_type:
pred_format += 'Bool'
else:
pred_format += 'Int'
test_name = pred_format_type.title()
if use_user_type:
arg_type = 'user-defined type (Bool)'
test_name += 'OnUserType'
if expect_failure:
arg = 'Bool(n%s_++)'
else:
arg = 'Bool(++n%s_)'
else:
arg_type = 'built-in type (int)'
test_name += 'OnBuiltInType'
if expect_failure:
arg = 'n%s_++'
else:
arg = '++n%s_'
if expect_failure:
successful_or_failed = 'failed'
expected_or_not = 'expected.'
test_name += 'Failure'
else:
successful_or_failed = 'successful'
expected_or_not = 'UNEXPECTED!'
test_name += 'Success'
# A map that defines the values used in the test template.
defs = DEFS.copy()
defs.update({
'assert' : assrt,
'assertion' : assertion,
'test_name' : test_name,
'pf_type' : pred_format_type,
'pf' : pred_format,
'arg_type' : arg_type,
'arg' : arg,
'successful' : successful_or_failed,
'expected' : expected_or_not,
})
test = """
// Tests a %(successful)s %(assertion)s where the
// predicate-formatter is a %(pf_type)s on a %(arg_type)s.
TEST_F(%(assertion)sTest, %(test_name)s) {""" % defs
indent = (len(assertion) + 3)*' '
extra_indent = ''
if expect_failure:
extra_indent = ' '
if use_assert:
test += """
expected_to_finish_ = false;
EXPECT_FATAL_FAILURE({ // NOLINT"""
else:
test += """
EXPECT_NONFATAL_FAILURE({ // NOLINT"""
test += '\n' + extra_indent + """ %(assertion)s(%(pf)s""" % defs
test = test % defs
test += Iter(n, ',\n' + indent + extra_indent + '%(arg)s' % defs)
test += ');\n' + extra_indent + ' finished_ = true;\n'
if expect_failure:
test += ' }, "");\n'
test += '}\n'
return test
# Generates tests for all 2**6 = 64 combinations.
tests += ''.join([GenTest(use_format, use_assert, expect_failure,
use_functor, use_user_type)
for use_format in [0, 1]
for use_assert in [0, 1]
for expect_failure in [0, 1]
for use_functor in [0, 1]
for use_user_type in [0, 1]
])
return tests
def UnitTestPostamble():
"""Returns the postamble for the tests."""
return ''
def GenerateUnitTest(n):
"""Returns the tests for up-to n-ary predicate assertions."""
GenerateFile(UNIT_TEST,
UnitTestPreamble()
+ ''.join([TestsForArity(i) for i in OneTo(n)])
+ UnitTestPostamble())
def _Main():
"""The entry point of the script. Generates the header file and its
unit test."""
if len(sys.argv) != 2:
print __doc__
print 'Author: ' + __author__
sys.exit(1)
n = int(sys.argv[1])
GenerateHeader(n)
GenerateUnitTest(n)
if __name__ == '__main__':
_Main()
|
gpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
8315,
12,
4475,
3277,
14,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
199,
3,
199,
3,
258,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
258,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
199,
3,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
199,
3,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
3,
4084,
14,
199,
3,
258,
627,
11443,
314,
536,
402,
4475,
3277,
14,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
624,
2268,
63,
8385,
63,
5991,
63,
5472,
14,
647,
373,
16,
14,
17,
199,
199,
20551,
314,
4514,
402,
4475,
1379,
11944,
22835,
436,
199,
645,
4627,
316,
2295,
14,
199,
199,
7692,
26,
819,
3805,
63,
8385,
63,
5991,
63,
5472,
14,
647,
9141,
63,
689,
1922,
199,
199,
4509,
9141,
63,
689,
1922,
365,
282,
7317,
3000,
14,
199,
199,
1918,
1414,
12821,
314,
4514,
402,
1536,
13,
475,
9141,
63,
689,
1922,
13,
695,
199,
14463,
22835,
12,
436,
14511,
652,
370,
570,
9088,
63,
5991,
63,
5472,
14,
72,
315,
314,
199,
3619,
2382,
314,
2884,
365,
14,
221,
2779,
2597,
12821,
314,
23073,
199,
3248,
511,
315,
570,
9088,
63,
5991,
63,
5472,
63,
2796,
14,
2055,
14,
199,
624,
199,
199,
363,
2502,
363,
275,
283,
20444,
32,
3098,
14,
957,
334,
12674,
1629,
951,
644,
290,
3171,
199,
199,
646,
747,
199,
646,
984,
199,
646,
900,
199,
199,
3,
17685,
642,
2884,
365,
14,
199,
10484,
63,
3022,
275,
747,
14,
515,
14,
3475,
8,
1274,
14,
3020,
59,
16,
566,
199,
199,
3,
17685,
370,
3877,
314,
4046,
1406,
14,
199,
7311,
275,
747,
14,
515,
14,
904,
8,
10484,
63,
3022,
12,
20644,
2613,
15,
8385,
15,
8385,
63,
5991,
63,
5472,
14,
72,
358,
199,
199,
3,
17685,
370,
3877,
314,
4046,
4137,
511,
14,
199,
15505,
63,
2864,
275,
747,
14,
515,
14,
904,
8,
10484,
63,
3022,
12,
20644,
396,
15,
8385,
63,
5991,
63,
5472,
63,
2796,
14,
2055,
358,
421,
199,
318,
10240,
29423,
8,
78,
304,
523,
408,
3407,
314,
19789,
367,
314,
1406,
570,
14,
819,
3033,
26,
272,
302,
26,
221,
314,
5696,
14554,
369,
402,
314,
11944,
16954,
370,
506,
4046,
14,
523,
408,
819,
327,
437,
2341,
626,
7890,
314,
1338,
1202,
315,
314,
19789,
1978,
14,
523,
28259,
275,
469,
272,
283,
8136,
7,
520,
900,
14,
6205,
3508,
77,
3149,
68,
3149,
57,
659,
272,
283,
3403,
7,
520,
900,
14,
6205,
3508,
57,
659,
272,
283,
1531,
7,
520,
1543,
83,
450,
83,
7,
450,
334,
736,
14,
515,
14,
4846,
8,
1274,
14,
3020,
59,
16,
2522,
302,
395,
272,
283,
78,
7,
520,
302,
272,
789,
819,
372,
334,
199,
624,
501,
1898,
8315,
12,
4475,
3277,
14,
199,
501,
2900,
4481,
4644,
14,
199,
501,
199,
501,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
501,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
501,
7647,
26,
199,
501,
199,
501,
258,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
501,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
501,
258,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
199,
501,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
199,
501,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
501,
4084,
14,
199,
501,
258,
627,
11443,
314,
536,
402,
4475,
3277,
14,
6590,
314,
1561,
402,
2399,
199,
501,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
501,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
501,
199,
501,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
501,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
501,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
501,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
501,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
501,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
501,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
501,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
501,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
501,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
501,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
8315,
12,
4475,
3277,
14,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
199,
3,
199,
3,
258,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
258,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
199,
3,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
199,
3,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
3,
4084,
14,
199,
3,
258,
627,
11443,
314,
536,
402,
4475,
3277,
14,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
624,
2268,
63,
8385,
63,
5991,
63,
5472,
14,
647,
373,
16,
14,
17,
199,
199,
20551,
314,
4514,
402,
4475,
1379,
11944,
22835,
436,
199,
645,
4627,
316,
2295,
14,
199,
199,
7692,
26,
819,
3805,
63,
8385,
63,
5991,
63,
5472,
14,
647,
9141,
63,
689,
1922,
199,
199,
4509,
9141,
63,
689,
1922,
365,
282,
7317,
3000,
14,
199,
199,
1918,
1414,
12821,
314,
4514,
402,
1536,
13,
475,
9141,
63,
689,
1922,
13,
695,
199,
14463,
22835,
12,
436,
14511,
652,
370,
570,
9088,
63,
5991,
63,
5472,
14,
72,
315,
314,
199,
3619,
2382,
314,
2884,
365,
14,
221,
2779,
2597,
12821,
314,
23073,
199,
3248,
511,
315,
570,
9088,
63,
5991,
63,
5472,
63,
2796,
14,
2055,
14,
199,
624,
199,
199,
363,
2502,
363,
275,
283,
20444,
32,
3098,
14,
957,
334,
12674,
1629,
951,
644,
290,
3171,
199,
199,
646,
747,
199,
646,
984,
199,
646,
900,
199,
199,
3,
17685,
642,
2884,
365,
14,
199,
10484,
63,
3022,
275,
747,
14,
515,
14,
3475,
8,
1274,
14,
3020,
59,
16,
566,
199,
199,
3,
17685,
370,
3877,
314,
4046,
1406,
14,
199,
7311,
275,
747,
14,
515,
14,
904,
8,
10484,
63,
3022,
12,
20644,
2613,
15,
8385,
15,
8385,
63,
5991,
63,
5472,
14,
72,
358,
199,
199,
3,
17685,
370,
3877,
314,
4046,
4137,
511,
14,
199,
15505,
63,
2864,
275,
747,
14,
515,
14,
904,
8,
10484,
63,
3022,
12,
20644,
396,
15,
8385,
63,
5991,
63,
5472,
63,
2796,
14,
2055,
358,
421,
199,
318,
10240,
29423,
8,
78,
304,
523,
408,
3407,
314,
19789,
367,
314,
1406,
570,
14,
819,
3033,
26,
272,
302,
26,
221,
314,
5696,
14554,
369,
402,
314,
11944,
16954,
370,
506,
4046,
14,
523,
408,
819,
327,
437,
2341,
626,
7890,
314,
1338,
1202,
315,
314,
19789,
1978,
14,
523,
28259,
275,
469,
272,
283,
8136,
7,
520,
900,
14,
6205,
3508,
77,
3149,
68,
3149,
57,
659,
272,
283,
3403,
7,
520,
900,
14,
6205,
3508,
57,
659,
272,
283,
1531,
7,
520,
1543,
83,
450,
83,
7,
450,
334,
736,
14,
515,
14,
4846,
8,
1274,
14,
3020,
59,
16,
2522,
302,
395,
272,
283,
78,
7,
520,
302,
272,
789,
819,
372,
334,
199,
624,
501,
1898,
8315,
12,
4475,
3277,
14,
199,
501,
2900,
4481,
4644,
14,
199,
501,
199,
501,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
501,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
501,
7647,
26,
199,
501,
199,
501,
258,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
501,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
501,
258,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
199,
501,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
199,
501,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
501,
4084,
14,
199,
501,
258,
627,
11443,
314,
536,
402,
4475,
3277,
14,
6590,
314,
1561,
402,
2399,
199,
501,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
501,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
501,
199,
501,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
501,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
501,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
501,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
501,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
501,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
501,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
501,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
501,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
501,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
501,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
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,
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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
] |
junzis/py-adsb-decoder
|
pyModeS/extra/aero.py
|
1
|
5201
|
"""
Functions for aeronautics in this module
- physical quantities always in SI units
- lat,lon,course and heading in degrees
International Standard Atmosphere
::
p,rho,T = atmos(H) # atmos as function of geopotential altitude H [m]
a = vsound(H) # speed of sound [m/s] as function of H[m]
p = pressure(H) # calls atmos but retruns only pressure [Pa]
T = temperature(H) # calculates temperature [K]
rho = density(H) # calls atmos but retruns only pressure [Pa]
Speed conversion at altitude H[m] in ISA
::
Mach = tas2mach(Vtas,H) # true airspeed (Vtas) to mach number conversion
Vtas = mach2tas(Mach,H) # true airspeed (Vtas) to mach number conversion
Vtas = eas2tas(Veas,H) # equivalent airspeed to true airspeed, H in [m]
Veas = tas2eas(Vtas,H) # true airspeed to equivent airspeed, H in [m]
Vtas = cas2tas(Vcas,H) # Vcas to Vtas conversion both m/s, H in [m]
Vcas = tas2cas(Vtas,H) # Vtas to Vcas conversion both m/s, H in [m]
Vcas = mach2cas(Mach,H) # Mach to Vcas conversion Vcas in m/s, H in [m]
Mach = cas2mach(Vcas,H) # Vcas to mach copnversion Vcas in m/s, H in [m]
"""
import numpy as np
"""Aero and geo Constants """
kts = 0.514444 # knot -> m/s
ft = 0.3048 # ft -> m
fpm = 0.00508 # ft/min -> m/s
inch = 0.0254 # inch -> m
sqft = 0.09290304 # 1 square foot
nm = 1852. # nautical mile -> m
lbs = 0.453592 # pound -> kg
g0 = 9.80665 # m/s2, Sea level gravity constant
R = 287.05287 # m2/(s2 x K), gas constant, sea level ISA
p0 = 101325. # Pa, air pressure, sea level ISA
rho0 = 1.225 # kg/m3, air density, sea level ISA
T0 = 288.15 # K, temperature, sea level ISA
gamma = 1.40 # cp/cv for air
gamma1 = 0.2 # (gamma-1)/2 for air
gamma2 = 3.5 # gamma/(gamma-1) for air
beta = -0.0065 # [K/m] ISA temp gradient below tropopause
r_earth = 6371000. # m, average earth radius
a0 = 340.293988 # m/s, sea level speed of sound ISA, sqrt(gamma*R*T0)
def atmos(H):
# H in metres
T = np.maximum(288.15 - 0.0065 * H, 216.65)
rhotrop = 1.225 * (T / 288.15)**4.256848030018761
dhstrat = np.maximum(0., H - 11000.0)
rho = rhotrop * np.exp(-dhstrat / 6341.552161)
p = rho * R * T
return p, rho, T
def temperature(H):
p, r, T = atmos(H)
return T
def pressure(H):
p, r, T = atmos(H)
return p
def density(H):
p, r, T = atmos(H)
return r
def vsound(H):
"""Speed of sound"""
T = temperature(H)
a = np.sqrt(gamma * R * T)
return a
def distance(lat1, lon1, lat2, lon2, H=0):
"""
Compute spherical distance from spherical coordinates.
For two locations in spherical coordinates
(1, theta, phi) and (1, theta', phi')
cosine( arc length ) =
sin phi sin phi' cos(theta-theta') + cos phi cos phi'
distance = rho * arc length
"""
# phi = 90 - latitude
phi1 = np.radians(90.0 - lat1)
phi2 = np.radians(90.0 - lat2)
# theta = longitude
theta1 = np.radians(lon1)
theta2 = np.radians(lon2)
cos = np.sin(phi1) * np.sin(phi2) * np.cos(theta1 - theta2) + np.cos(phi1) * np.cos(phi2)
cos = np.where(cos>1, 1, cos)
arc = np.arccos(cos)
dist = arc * (r_earth + H) # meters, radius of earth
return dist
def bearing(lat1, lon1, lat2, lon2):
lat1 = np.radians(lat1)
lon1 = np.radians(lon1)
lat2 = np.radians(lat2)
lon2 = np.radians(lon2)
x = np.sin(lon2-lon1) * np.cos(lat2)
y = np.cos(lat1) * np.sin(lat2) \
- np.sin(lat1) * np.cos(lat2) * np.cos(lon2-lon1)
initial_bearing = np.arctan2(x, y)
initial_bearing = np.degrees(initial_bearing)
bearing = (initial_bearing + 360) % 360
return bearing
# -----------------------------------------------------
# Speed conversions, altitude H all in meters
# -----------------------------------------------------
def tas2mach(Vtas, H):
"""True Airspeed to Mach number"""
a = vsound(H)
Mach = Vtas/a
return Mach
def mach2tas(Mach, H):
"""Mach number to True Airspeed"""
a = vsound(H)
Vtas = Mach*a
return Vtas
def eas2tas(Veas, H):
"""Equivalent Airspeed to True Airspeed"""
rho = density(H)
Vtas = Veas * np.sqrt(rho0/rho)
return Vtas
def tas2eas(Vtas, H):
"""True Airspeed to Equivalent Airspeed"""
rho = density(H)
Veas = Vtas * np.sqrt(rho/rho0)
return Veas
def cas2tas(Vcas, H):
"""Calibrated Airspeed to True Airspeed"""
p, rho, T = atmos(H)
qdyn = p0*((1.+rho0*Vcas*Vcas/(7.*p0))**3.5-1.)
Vtas = np.sqrt(7.*p/rho*((1.+qdyn/p)**(2./7.)-1.))
return Vtas
def tas2cas(Vtas, H):
"""True Airspeed to Calibrated Airspeed"""
p, rho, T = atmos(H)
qdyn = p*((1.+rho*Vtas*Vtas/(7.*p))**3.5-1.)
Vcas = np.sqrt(7.*p0/rho0*((qdyn/p0+1.)**(2./7.)-1.))
return Vcas
def mach2cas(Mach, H):
"""Mach number to Calibrated Airspeed"""
Vtas = mach2tas(Mach, H)
Vcas = tas2cas(Vtas, H)
return Vcas
def cas2mach(Vcas, H):
"""Calibrated Airspeed to Mach number"""
Vtas = cas2tas(Vcas, H)
Mach = tas2mach(Vtas, H)
return Mach
|
mit
|
[
624,
199,
13967,
367,
282,
281,
265,
3844,
7769,
315,
642,
859,
199,
199,
13,
14095,
13621,
1417,
3544,
315,
428,
41,
6204,
199,
13,
8396,
12,
5298,
12,
1972,
436,
16631,
315,
14358,
199,
199,
30886,
9739,
2854,
573,
14980,
199,
447,
339,
299,
12,
10412,
12,
52,
275,
737,
16908,
8,
40,
9,
259,
327,
737,
16908,
465,
805,
402,
2312,
27826,
9443,
29534,
869,
359,
77,
61,
272,
282,
275,
8118,
1034,
8,
40,
9,
260,
327,
8112,
402,
20453,
359,
77,
15,
83,
61,
465,
805,
402,
869,
59,
77,
61,
272,
299,
275,
25471,
8,
40,
9,
755,
327,
4882,
737,
16908,
1325,
295,
454,
324,
83,
1454,
25471,
359,
4232,
61,
272,
377,
275,
14843,
8,
40,
9,
259,
327,
6966,
2335,
14843,
359,
43,
61,
272,
17908,
275,
13650,
8,
40,
9,
420,
327,
4882,
737,
16908,
1325,
295,
454,
324,
83,
1454,
25471,
359,
4232,
61,
199,
199,
15146,
8603,
737,
29534,
869,
59,
77,
61,
315,
2281,
33,
199,
447,
339,
30611,
275,
307,
305,
18,
14121,
8,
54,
15520,
12,
40,
9,
259,
327,
2549,
12321,
7625,
334,
54,
15520,
9,
370,
14401,
1329,
8603,
272,
812,
15520,
275,
14401,
18,
15520,
8,
45,
1225,
12,
40,
9,
259,
327,
2549,
12321,
7625,
334,
54,
15520,
9,
370,
14401,
1329,
8603,
272,
812,
15520,
275,
9600,
18,
15520,
8,
15169,
305,
12,
40,
9,
258,
327,
7353,
12321,
7625,
370,
2549,
12321,
7625,
12,
869,
315,
359,
77,
61,
272,
25777,
305,
275,
307,
305,
18,
69,
305,
8,
54,
15520,
12,
40,
9,
258,
327,
2549,
12321,
7625,
370,
325,
783,
782,
12321,
7625,
12,
869,
315,
359,
77,
61,
272,
812,
15520,
275,
14984,
18,
15520,
8,
54,
9765,
12,
40,
9,
258,
327,
812,
9765,
221,
370,
812,
15520,
8603,
3865,
333,
15,
83,
12,
869,
315,
359,
77,
61,
272,
812,
9765,
275,
307,
305,
18,
9765,
8,
54,
15520,
12,
40,
9,
258,
327,
812,
15520,
370,
812,
9765,
8603,
3865,
333,
15,
83,
12,
869,
315,
359,
77,
61,
272,
812,
9765,
275,
14401,
18,
9765,
8,
45,
1225,
12,
40,
9,
259,
327,
30611,
370,
812,
9765,
8603,
812,
9765,
315,
333,
15,
83,
12,
869,
315,
359,
77,
61,
272,
30611,
257,
275,
14984,
18,
14121,
8,
54,
9765,
12,
40,
9,
221,
327,
812,
9765,
370,
14401,
4870,
78,
1023,
812,
9765,
315,
333,
15,
83,
12,
869,
315,
359,
77,
61,
199,
199,
624,
199,
199,
646,
2680,
465,
980,
199,
199,
624,
33,
3478,
436,
8509,
22296,
408,
199,
75,
1086,
275,
378,
14,
24098,
18078,
420,
327,
1022,
1397,
1035,
333,
15,
83,
199,
856,
275,
378,
14,
8533,
24,
260,
327,
18133,
1035,
333,
199,
3997,
77,
275,
378,
14,
383,
14585,
755,
327,
18133,
15,
827,
1035,
333,
15,
83,
199,
28494,
275,
378,
14,
16,
8306,
755,
327,
315,
335,
1035,
333,
199,
3526,
856,
275,
378,
14,
1643,
1398,
1644,
966,
257,
327,
413,
12386,
18913,
199,
10756,
275,
413,
22719,
14,
3515,
327,
302,
3844,
3294,
333,
441,
1035,
333,
199,
76,
1533,
275,
378,
14,
2322,
1276,
2942,
420,
327,
299,
1034,
1035,
31746,
199,
71,
16,
275,
1749,
14,
1257,
16373,
263,
327,
333,
15,
83,
18,
12,
3240,
65,
2166,
1999,
18936,
4413,
199,
50,
275,
499,
1555,
14,
1717,
11884,
755,
327,
333,
18,
7985,
83,
18,
671,
1804,
395,
486,
305,
4413,
12,
29894,
2166,
2281,
33,
199,
80,
16,
275,
14313,
13288,
14,
263,
327,
10164,
12,
12321,
25471,
12,
29894,
2166,
2281,
33,
199,
10412,
16,
275,
413,
14,
10932,
263,
327,
31746,
15,
77,
19,
12,
12321,
13650,
12,
29894,
2166,
2281,
33,
199,
52,
16,
275,
32558,
14,
1046,
260,
327,
1804,
12,
14843,
12,
29894,
2166,
2281,
33,
199,
7325,
275,
413,
14,
2167,
263,
327,
7667,
15,
5107,
367,
12321,
199,
7325,
17,
275,
378,
14,
18,
263,
327,
334,
7325,
13,
17,
2447,
18,
367,
12321,
199,
7325,
18,
275,
650,
14,
21,
263,
327,
10169,
7985,
7325,
13,
17,
9,
367,
12321,
199,
5683,
275,
446,
16,
14,
27004,
420,
327,
359,
43,
15,
77,
61,
2281,
33,
2388,
6709,
5084,
22621,
555,
11241,
199,
82,
63,
2210,
273,
275,
1227,
1401,
5279,
14,
221,
327,
333,
12,
8095,
8413,
273,
9362,
199,
65,
16,
275,
650,
2167,
14,
1398,
1355,
1299,
258,
327,
333,
15,
83,
12,
29894,
2166,
8112,
402,
20453,
2281,
33,
12,
7452,
8,
7325,
10,
50,
10,
52,
16,
9,
421,
199,
318,
737,
16908,
8,
40,
304,
272,
327,
869,
315,
7647,
470,
272,
377,
275,
980,
14,
11555,
8,
10740,
14,
1046,
446,
378,
14,
27004,
627,
869,
12,
30630,
14,
2182,
9,
272,
519,
8885,
2675,
275,
413,
14,
10932,
627,
334,
52,
1182,
32558,
14,
1046,
6422,
20,
14,
3912,
1349,
1257,
5863,
1085,
26648,
272,
31387,
495,
292,
275,
980,
14,
11555,
8,
16,
2020,
869,
446,
4119,
1493,
14,
16,
9,
272,
17908,
275,
519,
8885,
2675,
627,
980,
14,
1474,
2801,
7821,
495,
292,
1182,
1227,
15590,
14,
1229,
9669,
17,
9,
272,
299,
275,
17908,
627,
820,
627,
377,
272,
372,
299,
12,
17908,
12,
377,
421,
199,
318,
14843,
8,
40,
304,
272,
299,
12,
519,
12,
377,
275,
737,
16908,
8,
40,
9,
272,
372,
377,
421,
199,
318,
25471,
8,
40,
304,
272,
299,
12,
519,
12,
377,
275,
737,
16908,
8,
40,
9,
272,
372,
299,
421,
199,
318,
13650,
8,
40,
304,
272,
299,
12,
519,
12,
377,
275,
737,
16908,
8,
40,
9,
272,
372,
519,
421,
199,
318,
8118,
1034,
8,
40,
304,
272,
408,
15146,
402,
20453,
624,
272,
377,
275,
14843,
8,
40,
9,
272,
282,
275,
980,
14,
5079,
8,
7325,
627,
820,
627,
377,
9,
272,
372,
282,
421,
199,
318,
6033,
8,
4452,
17,
12,
6132,
17,
12,
8396,
18,
12,
6132,
18,
12,
869,
29,
16,
304,
272,
408,
272,
8354,
308,
27058,
6033,
687,
308,
27058,
8983,
14,
339,
2104,
2877,
9918,
315,
308,
27058,
8983,
272,
334,
17,
12,
12724,
12,
14524,
9,
436,
334,
17
] |
[
199,
13967,
367,
282,
281,
265,
3844,
7769,
315,
642,
859,
199,
199,
13,
14095,
13621,
1417,
3544,
315,
428,
41,
6204,
199,
13,
8396,
12,
5298,
12,
1972,
436,
16631,
315,
14358,
199,
199,
30886,
9739,
2854,
573,
14980,
199,
447,
339,
299,
12,
10412,
12,
52,
275,
737,
16908,
8,
40,
9,
259,
327,
737,
16908,
465,
805,
402,
2312,
27826,
9443,
29534,
869,
359,
77,
61,
272,
282,
275,
8118,
1034,
8,
40,
9,
260,
327,
8112,
402,
20453,
359,
77,
15,
83,
61,
465,
805,
402,
869,
59,
77,
61,
272,
299,
275,
25471,
8,
40,
9,
755,
327,
4882,
737,
16908,
1325,
295,
454,
324,
83,
1454,
25471,
359,
4232,
61,
272,
377,
275,
14843,
8,
40,
9,
259,
327,
6966,
2335,
14843,
359,
43,
61,
272,
17908,
275,
13650,
8,
40,
9,
420,
327,
4882,
737,
16908,
1325,
295,
454,
324,
83,
1454,
25471,
359,
4232,
61,
199,
199,
15146,
8603,
737,
29534,
869,
59,
77,
61,
315,
2281,
33,
199,
447,
339,
30611,
275,
307,
305,
18,
14121,
8,
54,
15520,
12,
40,
9,
259,
327,
2549,
12321,
7625,
334,
54,
15520,
9,
370,
14401,
1329,
8603,
272,
812,
15520,
275,
14401,
18,
15520,
8,
45,
1225,
12,
40,
9,
259,
327,
2549,
12321,
7625,
334,
54,
15520,
9,
370,
14401,
1329,
8603,
272,
812,
15520,
275,
9600,
18,
15520,
8,
15169,
305,
12,
40,
9,
258,
327,
7353,
12321,
7625,
370,
2549,
12321,
7625,
12,
869,
315,
359,
77,
61,
272,
25777,
305,
275,
307,
305,
18,
69,
305,
8,
54,
15520,
12,
40,
9,
258,
327,
2549,
12321,
7625,
370,
325,
783,
782,
12321,
7625,
12,
869,
315,
359,
77,
61,
272,
812,
15520,
275,
14984,
18,
15520,
8,
54,
9765,
12,
40,
9,
258,
327,
812,
9765,
221,
370,
812,
15520,
8603,
3865,
333,
15,
83,
12,
869,
315,
359,
77,
61,
272,
812,
9765,
275,
307,
305,
18,
9765,
8,
54,
15520,
12,
40,
9,
258,
327,
812,
15520,
370,
812,
9765,
8603,
3865,
333,
15,
83,
12,
869,
315,
359,
77,
61,
272,
812,
9765,
275,
14401,
18,
9765,
8,
45,
1225,
12,
40,
9,
259,
327,
30611,
370,
812,
9765,
8603,
812,
9765,
315,
333,
15,
83,
12,
869,
315,
359,
77,
61,
272,
30611,
257,
275,
14984,
18,
14121,
8,
54,
9765,
12,
40,
9,
221,
327,
812,
9765,
370,
14401,
4870,
78,
1023,
812,
9765,
315,
333,
15,
83,
12,
869,
315,
359,
77,
61,
199,
199,
624,
199,
199,
646,
2680,
465,
980,
199,
199,
624,
33,
3478,
436,
8509,
22296,
408,
199,
75,
1086,
275,
378,
14,
24098,
18078,
420,
327,
1022,
1397,
1035,
333,
15,
83,
199,
856,
275,
378,
14,
8533,
24,
260,
327,
18133,
1035,
333,
199,
3997,
77,
275,
378,
14,
383,
14585,
755,
327,
18133,
15,
827,
1035,
333,
15,
83,
199,
28494,
275,
378,
14,
16,
8306,
755,
327,
315,
335,
1035,
333,
199,
3526,
856,
275,
378,
14,
1643,
1398,
1644,
966,
257,
327,
413,
12386,
18913,
199,
10756,
275,
413,
22719,
14,
3515,
327,
302,
3844,
3294,
333,
441,
1035,
333,
199,
76,
1533,
275,
378,
14,
2322,
1276,
2942,
420,
327,
299,
1034,
1035,
31746,
199,
71,
16,
275,
1749,
14,
1257,
16373,
263,
327,
333,
15,
83,
18,
12,
3240,
65,
2166,
1999,
18936,
4413,
199,
50,
275,
499,
1555,
14,
1717,
11884,
755,
327,
333,
18,
7985,
83,
18,
671,
1804,
395,
486,
305,
4413,
12,
29894,
2166,
2281,
33,
199,
80,
16,
275,
14313,
13288,
14,
263,
327,
10164,
12,
12321,
25471,
12,
29894,
2166,
2281,
33,
199,
10412,
16,
275,
413,
14,
10932,
263,
327,
31746,
15,
77,
19,
12,
12321,
13650,
12,
29894,
2166,
2281,
33,
199,
52,
16,
275,
32558,
14,
1046,
260,
327,
1804,
12,
14843,
12,
29894,
2166,
2281,
33,
199,
7325,
275,
413,
14,
2167,
263,
327,
7667,
15,
5107,
367,
12321,
199,
7325,
17,
275,
378,
14,
18,
263,
327,
334,
7325,
13,
17,
2447,
18,
367,
12321,
199,
7325,
18,
275,
650,
14,
21,
263,
327,
10169,
7985,
7325,
13,
17,
9,
367,
12321,
199,
5683,
275,
446,
16,
14,
27004,
420,
327,
359,
43,
15,
77,
61,
2281,
33,
2388,
6709,
5084,
22621,
555,
11241,
199,
82,
63,
2210,
273,
275,
1227,
1401,
5279,
14,
221,
327,
333,
12,
8095,
8413,
273,
9362,
199,
65,
16,
275,
650,
2167,
14,
1398,
1355,
1299,
258,
327,
333,
15,
83,
12,
29894,
2166,
8112,
402,
20453,
2281,
33,
12,
7452,
8,
7325,
10,
50,
10,
52,
16,
9,
421,
199,
318,
737,
16908,
8,
40,
304,
272,
327,
869,
315,
7647,
470,
272,
377,
275,
980,
14,
11555,
8,
10740,
14,
1046,
446,
378,
14,
27004,
627,
869,
12,
30630,
14,
2182,
9,
272,
519,
8885,
2675,
275,
413,
14,
10932,
627,
334,
52,
1182,
32558,
14,
1046,
6422,
20,
14,
3912,
1349,
1257,
5863,
1085,
26648,
272,
31387,
495,
292,
275,
980,
14,
11555,
8,
16,
2020,
869,
446,
4119,
1493,
14,
16,
9,
272,
17908,
275,
519,
8885,
2675,
627,
980,
14,
1474,
2801,
7821,
495,
292,
1182,
1227,
15590,
14,
1229,
9669,
17,
9,
272,
299,
275,
17908,
627,
820,
627,
377,
272,
372,
299,
12,
17908,
12,
377,
421,
199,
318,
14843,
8,
40,
304,
272,
299,
12,
519,
12,
377,
275,
737,
16908,
8,
40,
9,
272,
372,
377,
421,
199,
318,
25471,
8,
40,
304,
272,
299,
12,
519,
12,
377,
275,
737,
16908,
8,
40,
9,
272,
372,
299,
421,
199,
318,
13650,
8,
40,
304,
272,
299,
12,
519,
12,
377,
275,
737,
16908,
8,
40,
9,
272,
372,
519,
421,
199,
318,
8118,
1034,
8,
40,
304,
272,
408,
15146,
402,
20453,
624,
272,
377,
275,
14843,
8,
40,
9,
272,
282,
275,
980,
14,
5079,
8,
7325,
627,
820,
627,
377,
9,
272,
372,
282,
421,
199,
318,
6033,
8,
4452,
17,
12,
6132,
17,
12,
8396,
18,
12,
6132,
18,
12,
869,
29,
16,
304,
272,
408,
272,
8354,
308,
27058,
6033,
687,
308,
27058,
8983,
14,
339,
2104,
2877,
9918,
315,
308,
27058,
8983,
272,
334,
17,
12,
12724,
12,
14524,
9,
436,
334,
17,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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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
] |
sencha/chromium-spacewalk
|
chrome/common/extensions/docs/server2/permissions_data_source.py
|
9
|
3650
|
# Copyright 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
from itertools import ifilter
from operator import itemgetter
from data_source import DataSource
from extensions_paths import PRIVATE_TEMPLATES
from future import Future
from platform_util import GetPlatforms
def _ListifyPermissions(permissions):
'''Filter out any permissions that do not have a description or with a name
that ends with Private then sort permissions features by name into a list.
'''
def filter_permissions(perm):
return 'description' in perm and not perm['name'].endswith('Private')
return sorted(
ifilter(filter_permissions, permissions.itervalues()),
key=itemgetter('name'))
def _AddDependencyDescriptions(permissions, api_features):
'''Use |api_features| to determine the dependencies APIs have on permissions.
Add descriptions to |permissions| based on those dependencies.
'''
for name, permission in permissions.iteritems():
# Don't overwrite the description created by expanding a partial template.
if 'partial' in permission:
continue
has_deps = False
if name in api_features:
for dependency in api_features[name].get('dependencies', ()):
if dependency.startswith('permission:'):
has_deps = True
if has_deps:
permission['partial'] = 'permissions/generic_description.html'
class PermissionsDataSource(DataSource):
'''Load and format permissions features to be used by templates.
'''
def __init__(self, server_instance, request):
self._platform_bundle = server_instance.platform_bundle
self._object_store = server_instance.object_store_creator.Create(
PermissionsDataSource)
self._template_cache = server_instance.compiled_fs_factory.ForTemplates(
server_instance.host_file_system_provider.GetTrunk())
def _CreatePermissionsDataForPlatform(self, platform):
features_bundle = self._platform_bundle.GetFeaturesBundle(platform)
api_features_future = features_bundle.GetAPIFeatures()
permission_features_future = features_bundle.GetPermissionFeatures()
def resolve():
api_features = api_features_future.Get()
permission_features = permission_features_future.Get()
_AddDependencyDescriptions(permission_features, api_features)
# Turn partial templates into descriptions, ensure anchors are set.
for permission in permission_features.values():
if not 'anchor' in permission:
permission['anchor'] = permission['name']
if 'partial' in permission:
permission['description'] = self._template_cache.GetFromFile(
PRIVATE_TEMPLATES + permission['partial']).Get()
del permission['partial']
return _ListifyPermissions(permission_features)
return Future(callback=resolve)
def _CreatePermissionsData(self):
permissions_data_futures = dict(
(platform, self._CreatePermissionsDataForPlatform(platform))
for platform in GetPlatforms())
def resolve():
return dict(('declare_' + platform, future.Get())
for platform, future in permissions_data_futures.iteritems())
return Future(callback=resolve)
def _GetCachedPermissionsData(self):
data = self._object_store.Get('permissions_data').Get()
if data is None:
data = self._CreatePermissionsData().Get()
self._object_store.Set('permissions_data', data)
return data
def Cron(self):
return self._CreatePermissionsData()
def get(self, key):
return self._GetCachedPermissionsData().get(key)
|
bsd-3-clause
|
[
3,
1898,
6171,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
504,
7975,
492,
284,
1541,
199,
504,
4182,
492,
1242,
7416,
199,
199,
504,
666,
63,
1365,
492,
24300,
199,
504,
5478,
63,
3771,
492,
28644,
1951,
63,
25437,
199,
504,
6466,
492,
20799,
199,
504,
4298,
63,
1974,
492,
2372,
3714,
8560,
421,
199,
318,
485,
1296,
2021,
17004,
8,
6060,
304,
523,
1449,
4131,
734,
1263,
3443,
626,
886,
440,
1172,
282,
1369,
503,
543,
282,
536,
523,
626,
11187,
543,
18551,
2066,
4069,
3443,
4534,
701,
536,
1901,
282,
769,
14,
523,
1449,
523,
347,
2457,
63,
6060,
8,
8220,
304,
272,
372,
283,
1802,
7,
315,
10869,
436,
440,
10869,
459,
354,
2278,
4130,
360,
12185,
358,
819,
372,
3355,
8,
489,
284,
1541,
8,
1541,
63,
6060,
12,
3443,
14,
13012,
4000,
489,
790,
29,
20832,
360,
354,
1333,
421,
199,
318,
485,
1123,
14403,
5831,
83,
8,
6060,
12,
2986,
63,
3179,
304,
523,
1449,
6119,
1204,
1246,
63,
3179,
92,
370,
6705,
314,
5124,
15913,
1172,
641,
3443,
14,
523,
2654,
18714,
370,
1204,
6060,
92,
4079,
641,
5204,
5124,
14,
523,
1449,
523,
367,
536,
12,
4983,
315,
3443,
14,
4611,
837,
272,
327,
7529,
1133,
8970,
314,
1369,
2737,
701,
6544,
316,
282,
7417,
1978,
14,
272,
340,
283,
6672,
7,
315,
4983,
26,
489,
1980,
339,
965,
63,
5846,
275,
756,
272,
340,
536,
315,
2986,
63,
3179,
26,
489,
367,
5936,
315,
2986,
63,
3179,
59,
354,
1055,
362,
360,
5714,
297,
334,
2298,
267,
340,
5936,
14,
2460,
360,
5693,
23117,
881,
965,
63,
5846,
275,
715,
339,
340,
965,
63,
5846,
26,
489,
4983,
459,
6672,
418,
275,
283,
6060,
15,
6767,
63,
1802,
14,
1360,
7,
199,
199,
533,
28260,
16693,
8,
16693,
304,
523,
1449,
6200,
436,
1475,
3443,
4534,
370,
506,
1202,
701,
7009,
14,
523,
1449,
523,
347,
636,
826,
721,
277,
12,
1654,
63,
842,
12,
1056,
304,
272,
291,
423,
3246,
63,
6469,
275,
1654,
63,
842,
14,
3246,
63,
6469,
272,
291,
423,
785,
63,
1617,
275,
1654,
63,
842,
14,
785,
63,
1617,
63,
9986,
14,
2499,
8,
267,
28260,
16693,
9,
272,
291,
423,
1160,
63,
1637,
275,
1654,
63,
842,
14,
8427,
63,
2319,
63,
3702,
14,
1858,
17969,
8,
267,
1654,
63,
842,
14,
1102,
63,
493,
63,
2253,
63,
3780,
14,
1002,
20460,
75,
1012,
819,
347,
485,
2499,
17004,
1451,
1858,
10397,
8,
277,
12,
4298,
304,
272,
4534,
63,
6469,
275,
291,
423,
3246,
63,
6469,
14,
1002,
10807,
12320,
8,
3246,
9,
272,
2986,
63,
3179,
63,
2443,
275,
4534,
63,
6469,
14,
1002,
3735,
10807,
342,
272,
4983,
63,
3179,
63,
2443,
275,
4534,
63,
6469,
14,
1002,
7980,
10807,
342,
339,
347,
7512,
837,
489,
2986,
63,
3179,
275,
2986,
63,
3179,
63,
2443,
14,
1002,
342,
489,
4983,
63,
3179,
275,
4983,
63,
3179,
63,
2443,
14,
1002,
342,
489,
485,
1123,
14403,
5831,
83,
8,
5693,
63,
3179,
12,
2986,
63,
3179,
9,
2541,
327,
16147,
7417,
7009,
1901,
18714,
12,
4868,
32682,
787,
663,
14,
489,
367,
4983,
315,
4983,
63,
3179,
14,
1459,
837,
267,
340,
440,
283,
11498,
7,
315,
4983,
26,
881,
4983,
459,
11498,
418,
275,
4983,
459,
354,
418,
267,
340,
283,
6672,
7,
315,
4983,
26,
881,
4983,
459,
1802,
418,
275,
291,
423,
1160,
63,
1637,
14,
1002,
26637,
8,
1598,
28644,
1951,
63,
25437,
435,
4983,
459,
6672,
13227,
1002,
342,
881,
2150,
4983,
459,
6672,
418,
2541,
372,
485,
1296,
2021,
17004,
8,
5693,
63,
3179,
9,
272,
372,
20799,
8,
3058,
29,
6983,
9,
819,
347,
485,
2499,
17004,
1451,
8,
277,
304,
272,
3443,
63,
576,
63,
25513,
275,
1211,
8,
267,
334,
3246,
12,
291,
423,
2499,
17004,
1451,
1858,
10397,
8,
3246,
430,
267,
367,
4298,
315,
2372,
3714,
8560,
1012,
339,
347,
7512,
837,
489,
372,
1211,
4725,
16536,
8650,
435,
4298,
12,
6466,
14,
1002,
1012,
2116,
367,
4298,
12,
6466,
315,
3443,
63,
576,
63,
25513,
14,
4611,
1012,
272,
372,
20799,
8,
3058,
29,
6983,
9,
819,
347,
485,
1002,
16138,
17004,
1451,
8,
277,
304,
272,
666,
275,
291,
423,
785,
63,
1617,
14,
1002,
360,
6060,
63,
576,
1959,
1002,
342,
272,
340,
666,
365,
488,
26,
489,
666,
275,
291,
423,
2499,
17004,
1451,
1252,
1002,
342,
489,
291,
423,
785,
63,
1617,
14,
1084,
360,
6060,
63,
576,
297,
666,
9,
272,
372,
666,
819,
347,
445,
2641,
8,
277,
304,
272,
372,
291,
423,
2499,
17004,
1451,
342,
819,
347,
664,
8,
277,
12,
790,
304,
272,
372,
291,
423,
1002,
16138,
17004,
1451,
1252,
362,
8,
498,
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
] |
[
1898,
6171,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
504,
7975,
492,
284,
1541,
199,
504,
4182,
492,
1242,
7416,
199,
199,
504,
666,
63,
1365,
492,
24300,
199,
504,
5478,
63,
3771,
492,
28644,
1951,
63,
25437,
199,
504,
6466,
492,
20799,
199,
504,
4298,
63,
1974,
492,
2372,
3714,
8560,
421,
199,
318,
485,
1296,
2021,
17004,
8,
6060,
304,
523,
1449,
4131,
734,
1263,
3443,
626,
886,
440,
1172,
282,
1369,
503,
543,
282,
536,
523,
626,
11187,
543,
18551,
2066,
4069,
3443,
4534,
701,
536,
1901,
282,
769,
14,
523,
1449,
523,
347,
2457,
63,
6060,
8,
8220,
304,
272,
372,
283,
1802,
7,
315,
10869,
436,
440,
10869,
459,
354,
2278,
4130,
360,
12185,
358,
819,
372,
3355,
8,
489,
284,
1541,
8,
1541,
63,
6060,
12,
3443,
14,
13012,
4000,
489,
790,
29,
20832,
360,
354,
1333,
421,
199,
318,
485,
1123,
14403,
5831,
83,
8,
6060,
12,
2986,
63,
3179,
304,
523,
1449,
6119,
1204,
1246,
63,
3179,
92,
370,
6705,
314,
5124,
15913,
1172,
641,
3443,
14,
523,
2654,
18714,
370,
1204,
6060,
92,
4079,
641,
5204,
5124,
14,
523,
1449,
523,
367,
536,
12,
4983,
315,
3443,
14,
4611,
837,
272,
327,
7529,
1133,
8970,
314,
1369,
2737,
701,
6544,
316,
282,
7417,
1978,
14,
272,
340,
283,
6672,
7,
315,
4983,
26,
489,
1980,
339,
965,
63,
5846,
275,
756,
272,
340,
536,
315,
2986,
63,
3179,
26,
489,
367,
5936,
315,
2986,
63,
3179,
59,
354,
1055,
362,
360,
5714,
297,
334,
2298,
267,
340,
5936,
14,
2460,
360,
5693,
23117,
881,
965,
63,
5846,
275,
715,
339,
340,
965,
63,
5846,
26,
489,
4983,
459,
6672,
418,
275,
283,
6060,
15,
6767,
63,
1802,
14,
1360,
7,
199,
199,
533,
28260,
16693,
8,
16693,
304,
523,
1449,
6200,
436,
1475,
3443,
4534,
370,
506,
1202,
701,
7009,
14,
523,
1449,
523,
347,
636,
826,
721,
277,
12,
1654,
63,
842,
12,
1056,
304,
272,
291,
423,
3246,
63,
6469,
275,
1654,
63,
842,
14,
3246,
63,
6469,
272,
291,
423,
785,
63,
1617,
275,
1654,
63,
842,
14,
785,
63,
1617,
63,
9986,
14,
2499,
8,
267,
28260,
16693,
9,
272,
291,
423,
1160,
63,
1637,
275,
1654,
63,
842,
14,
8427,
63,
2319,
63,
3702,
14,
1858,
17969,
8,
267,
1654,
63,
842,
14,
1102,
63,
493,
63,
2253,
63,
3780,
14,
1002,
20460,
75,
1012,
819,
347,
485,
2499,
17004,
1451,
1858,
10397,
8,
277,
12,
4298,
304,
272,
4534,
63,
6469,
275,
291,
423,
3246,
63,
6469,
14,
1002,
10807,
12320,
8,
3246,
9,
272,
2986,
63,
3179,
63,
2443,
275,
4534,
63,
6469,
14,
1002,
3735,
10807,
342,
272,
4983,
63,
3179,
63,
2443,
275,
4534,
63,
6469,
14,
1002,
7980,
10807,
342,
339,
347,
7512,
837,
489,
2986,
63,
3179,
275,
2986,
63,
3179,
63,
2443,
14,
1002,
342,
489,
4983,
63,
3179,
275,
4983,
63,
3179,
63,
2443,
14,
1002,
342,
489,
485,
1123,
14403,
5831,
83,
8,
5693,
63,
3179,
12,
2986,
63,
3179,
9,
2541,
327,
16147,
7417,
7009,
1901,
18714,
12,
4868,
32682,
787,
663,
14,
489,
367,
4983,
315,
4983,
63,
3179,
14,
1459,
837,
267,
340,
440,
283,
11498,
7,
315,
4983,
26,
881,
4983,
459,
11498,
418,
275,
4983,
459,
354,
418,
267,
340,
283,
6672,
7,
315,
4983,
26,
881,
4983,
459,
1802,
418,
275,
291,
423,
1160,
63,
1637,
14,
1002,
26637,
8,
1598,
28644,
1951,
63,
25437,
435,
4983,
459,
6672,
13227,
1002,
342,
881,
2150,
4983,
459,
6672,
418,
2541,
372,
485,
1296,
2021,
17004,
8,
5693,
63,
3179,
9,
272,
372,
20799,
8,
3058,
29,
6983,
9,
819,
347,
485,
2499,
17004,
1451,
8,
277,
304,
272,
3443,
63,
576,
63,
25513,
275,
1211,
8,
267,
334,
3246,
12,
291,
423,
2499,
17004,
1451,
1858,
10397,
8,
3246,
430,
267,
367,
4298,
315,
2372,
3714,
8560,
1012,
339,
347,
7512,
837,
489,
372,
1211,
4725,
16536,
8650,
435,
4298,
12,
6466,
14,
1002,
1012,
2116,
367,
4298,
12,
6466,
315,
3443,
63,
576,
63,
25513,
14,
4611,
1012,
272,
372,
20799,
8,
3058,
29,
6983,
9,
819,
347,
485,
1002,
16138,
17004,
1451,
8,
277,
304,
272,
666,
275,
291,
423,
785,
63,
1617,
14,
1002,
360,
6060,
63,
576,
1959,
1002,
342,
272,
340,
666,
365,
488,
26,
489,
666,
275,
291,
423,
2499,
17004,
1451,
1252,
1002,
342,
489,
291,
423,
785,
63,
1617,
14,
1084,
360,
6060,
63,
576,
297,
666,
9,
272,
372,
666,
819,
347,
445,
2641,
8,
277,
304,
272,
372,
291,
423,
2499,
17004,
1451,
342,
819,
347,
664,
8,
277,
12,
790,
304,
272,
372,
291,
423,
1002,
16138,
17004,
1451,
1252,
362,
8,
498,
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,
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,
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