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
|
|---|---|---|---|---|---|---|---|---|
Jorge-Rodriguez/ansible
|
test/units/modules/network/nos/test_nos_facts.py
|
30
|
2127
|
#
# (c) 2018 Extreme Networks 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/>.
#
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from units.compat.mock import patch
from ansible.modules.network.nos import nos_facts
from units.modules.utils import set_module_args
from .nos_module import TestNosModule, load_fixture
class TestNosFactsModule(TestNosModule):
module = nos_facts
def setUp(self):
super(TestNosFactsModule, self).setUp()
self.mock_run_commands = patch('ansible.modules.network.nos.nos_facts.run_commands')
self.run_commands = self.mock_run_commands.start()
def tearDown(self):
super(TestNosFactsModule, self).tearDown()
self.mock_run_commands.stop()
def load_fixtures(self, commands=None):
def load_from_file(*args, **kwargs):
commands = args[1]
output = list()
for command in commands:
filename = str(command).split(' | ')[0].replace(' ', '_')
output.append(load_fixture('nos_facts_%s' % filename))
return output
self.run_commands.side_effect = load_from_file
def test_nos_facts(self):
set_module_args(dict(gather_subset='default'))
result = self.execute_module()
self.assertEqual(
result['ansible_facts']['ansible_net_model'], 'BR-VDX6740'
)
self.assertEqual(
result['ansible_facts']['ansible_net_serialnum'], 'CPL2541K01E'
)
|
gpl-3.0
|
[
3,
199,
3,
334,
67,
9,
14894,
7255,
17817,
17138,
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,
3,
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,
12712,
492,
302,
736,
63,
5047,
199,
504,
6204,
14,
3112,
14,
1208,
492,
663,
63,
578,
63,
589,
199,
504,
1275,
12712,
63,
578,
492,
1379,
46,
736,
2377,
12,
2248,
63,
5997,
421,
199,
533,
1379,
46,
736,
25821,
2377,
8,
774,
46,
736,
2377,
304,
339,
859,
275,
302,
736,
63,
5047,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
774,
46,
736,
25821,
2377,
12,
291,
680,
5996,
342,
267,
291,
14,
1805,
63,
1065,
63,
4405,
275,
3371,
360,
4853,
14,
3112,
14,
1200,
14,
12712,
14,
12712,
63,
5047,
14,
1065,
63,
4405,
358,
267,
291,
14,
1065,
63,
4405,
275,
291,
14,
1805,
63,
1065,
63,
4405,
14,
928,
342,
339,
347,
6766,
8,
277,
304,
267,
1613,
8,
774,
46,
736,
25821,
2377,
12,
291,
680,
12336,
342,
267,
291,
14,
1805,
63,
1065,
63,
4405,
14,
2379,
342,
339,
347,
2248,
63,
8769,
8,
277,
12,
3718,
29,
403,
304,
267,
347,
2248,
63,
504,
63,
493,
2031,
589,
12,
1011,
958,
304,
288,
3718,
275,
1249,
59,
17,
61,
288,
1072,
275,
769,
342,
953,
367,
1414,
315,
3718,
26,
355,
1788,
275,
620,
8,
1531,
680,
1294,
360,
1204,
27618,
16,
1055,
1814,
360,
1656,
18962,
355,
1072,
14,
740,
8,
912,
63,
5997,
360,
12712,
63,
5047,
4970,
83,
7,
450,
1788,
430,
288,
372,
1072,
398,
291,
14,
1065,
63,
4405,
14,
2441,
63,
5881,
275,
2248,
63,
504,
63,
493,
339,
347,
511,
63,
12712,
63,
5047,
8,
277,
304,
267,
663,
63,
578,
63,
589,
8,
807,
8,
13737,
63,
9401,
534,
885,
1333,
267,
754,
275,
291,
14,
2526,
63,
578,
342,
267,
291,
14,
629,
8,
288,
754,
459,
4853,
63,
5047,
2545,
4853,
63,
846,
63,
1238,
995,
283,
7184,
13,
54,
19596,
10393,
16,
7,
267,
776,
267,
291,
14,
629,
8,
288,
754,
459,
4853,
63,
5047,
2545,
4853,
63,
846,
63,
2171,
1507,
995,
283,
35,
2749,
821,
2953,
43,
614,
37,
7,
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
] |
[
199,
3,
334,
67,
9,
14894,
7255,
17817,
17138,
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,
3,
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,
12712,
492,
302,
736,
63,
5047,
199,
504,
6204,
14,
3112,
14,
1208,
492,
663,
63,
578,
63,
589,
199,
504,
1275,
12712,
63,
578,
492,
1379,
46,
736,
2377,
12,
2248,
63,
5997,
421,
199,
533,
1379,
46,
736,
25821,
2377,
8,
774,
46,
736,
2377,
304,
339,
859,
275,
302,
736,
63,
5047,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
774,
46,
736,
25821,
2377,
12,
291,
680,
5996,
342,
267,
291,
14,
1805,
63,
1065,
63,
4405,
275,
3371,
360,
4853,
14,
3112,
14,
1200,
14,
12712,
14,
12712,
63,
5047,
14,
1065,
63,
4405,
358,
267,
291,
14,
1065,
63,
4405,
275,
291,
14,
1805,
63,
1065,
63,
4405,
14,
928,
342,
339,
347,
6766,
8,
277,
304,
267,
1613,
8,
774,
46,
736,
25821,
2377,
12,
291,
680,
12336,
342,
267,
291,
14,
1805,
63,
1065,
63,
4405,
14,
2379,
342,
339,
347,
2248,
63,
8769,
8,
277,
12,
3718,
29,
403,
304,
267,
347,
2248,
63,
504,
63,
493,
2031,
589,
12,
1011,
958,
304,
288,
3718,
275,
1249,
59,
17,
61,
288,
1072,
275,
769,
342,
953,
367,
1414,
315,
3718,
26,
355,
1788,
275,
620,
8,
1531,
680,
1294,
360,
1204,
27618,
16,
1055,
1814,
360,
1656,
18962,
355,
1072,
14,
740,
8,
912,
63,
5997,
360,
12712,
63,
5047,
4970,
83,
7,
450,
1788,
430,
288,
372,
1072,
398,
291,
14,
1065,
63,
4405,
14,
2441,
63,
5881,
275,
2248,
63,
504,
63,
493,
339,
347,
511,
63,
12712,
63,
5047,
8,
277,
304,
267,
663,
63,
578,
63,
589,
8,
807,
8,
13737,
63,
9401,
534,
885,
1333,
267,
754,
275,
291,
14,
2526,
63,
578,
342,
267,
291,
14,
629,
8,
288,
754,
459,
4853,
63,
5047,
2545,
4853,
63,
846,
63,
1238,
995,
283,
7184,
13,
54,
19596,
10393,
16,
7,
267,
776,
267,
291,
14,
629,
8,
288,
754,
459,
4853,
63,
5047,
2545,
4853,
63,
846,
63,
2171,
1507,
995,
283,
35,
2749,
821,
2953,
43,
614,
37,
7,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
nisse3000/pymatgen
|
pymatgen/analysis/tests/test_transition_state.py
|
4
|
3285
|
# coding: utf-8
# Copyright (c) Pymatgen Development Team.
# Distributed under the terms of the MIT License.
from __future__ import division, unicode_literals
import os
import unittest
import warnings
from pymatgen.util.testing import PymatgenTest
from pymatgen.analysis.transition_state import NEBAnalysis
import json
from pymatgen.analysis.transition_state import combine_neb_plots
"""
TODO: Modify unittest doc.
"""
__author__ = "David Waroquiers"
__copyright__ = "Copyright 2016, The Materials Project"
__version__ = "0.1"
__maintainer__ = "Shyam Dwaraknath"
__email__ = "shyamd@lbl.gov"
__date__ = "2/5/16"
test_dir = os.path.join(os.path.dirname(__file__), "..", "..", "..",
'test_files', 'neb_analysis')
class NEBAnalysisTest(PymatgenTest):
def setUp(self):
warnings.simplefilter("ignore")
def tearDown(self):
warnings.resetwarnings()
def runTest(self):
neb_analysis1 = NEBAnalysis.from_dir(os.path.join
(test_dir, 'neb1', 'neb'))
neb_analysis1_from_dict = NEBAnalysis.from_dict(neb_analysis1.as_dict())
json_data = json.dumps(neb_analysis1.as_dict())
neb_dict = json.loads(json_data)
neb_analysis1_from_json_data = NEBAnalysis.from_dict(neb_dict)
self.assertArrayAlmostEqual(neb_analysis1.energies[0], -255.97992669000001)
self.assertArrayAlmostEqual(neb_analysis1.energies[3], -255.84261996000001)
self.assertArrayAlmostEqual(neb_analysis1.r, neb_analysis1_from_dict.r)
self.assertArrayAlmostEqual(neb_analysis1.energies, neb_analysis1_from_dict.energies)
self.assertArrayAlmostEqual(neb_analysis1.forces, neb_analysis1_from_dict.forces)
self.assertEqual(neb_analysis1.structures, neb_analysis1_from_dict.structures)
self.assertArrayAlmostEqual(neb_analysis1.r, neb_analysis1_from_json_data.r)
self.assertArrayAlmostEqual(neb_analysis1.energies, neb_analysis1_from_json_data.energies)
self.assertArrayAlmostEqual(neb_analysis1.forces, neb_analysis1_from_json_data.forces)
self.assertEqual(neb_analysis1.structures, neb_analysis1_from_json_data.structures)
self.assertArrayAlmostEqual(neb_analysis1.get_extrema()[1][0], (0.50023335723480078, 325.20043063935128))
neb_analysis1.setup_spline(spline_options={'saddle_point': 'zero_slope'})
self.assertArrayAlmostEqual(neb_analysis1.get_extrema()[1][0], (0.50023335723480078, 325.20003984140203))
with open(os.path.join(test_dir, 'neb2', 'neb_analysis2.json'),
'r') as f:
neb_analysis2_dict = json.load(f)
neb_analysis2 = NEBAnalysis.from_dict(neb_analysis2_dict)
self.assertArrayAlmostEqual(neb_analysis2.get_extrema()[1][0], (0.37255257367467326, 562.40825334519991))
neb_analysis2.setup_spline(spline_options={'saddle_point': 'zero_slope'})
self.assertArrayAlmostEqual(neb_analysis2.get_extrema()[1][0], (0.30371133723478794, 528.46229631648691))
def test_combine_neb_plots(self):
neb_dir = os.path.join(test_dir, 'neb1', 'neb')
neb_analysis = NEBAnalysis.from_dir(neb_dir)
combine_neb_plots([neb_analysis, neb_analysis])
if __name__ == '__main__':
unittest.main()
|
mit
|
[
3,
2803,
26,
2774,
13,
24,
199,
3,
1898,
334,
67,
9,
1611,
30649,
15290,
11682,
14,
199,
3,
17484,
1334,
314,
2895,
402,
314,
10697,
844,
14,
199,
199,
504,
636,
2443,
363,
492,
4629,
12,
2649,
63,
5955,
199,
199,
646,
747,
199,
646,
2882,
199,
646,
3598,
199,
504,
1134,
30649,
14,
1974,
14,
4776,
492,
1611,
30649,
774,
199,
504,
1134,
30649,
14,
10466,
14,
14143,
63,
929,
492,
7110,
34,
13182,
199,
646,
2022,
199,
504,
1134,
30649,
14,
10466,
14,
14143,
63,
929,
492,
13323,
63,
685,
66,
63,
13701,
199,
199,
624,
199,
11768,
26,
22520,
2882,
1382,
14,
199,
624,
199,
199,
363,
2502,
363,
275,
298,
36,
17204,
644,
285,
79,
783,
1192,
2,
199,
363,
7307,
363,
275,
298,
7384,
7800,
12,
710,
26570,
83,
7290,
2,
199,
363,
1023,
363,
275,
298,
16,
14,
17,
2,
199,
363,
26665,
363,
275,
298,
2662,
89,
455,
577,
3281,
1151,
78,
1619,
2,
199,
363,
2123,
363,
275,
298,
609,
89,
21778,
32,
18842,
14,
16294,
2,
199,
363,
602,
363,
275,
298,
18,
15,
21,
15,
975,
2,
421,
199,
396,
63,
694,
275,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
21777,
401,
21777,
401,
21777,
401,
717,
283,
396,
63,
1725,
297,
283,
685,
66,
63,
10466,
358,
421,
199,
533,
7110,
34,
13182,
774,
8,
2713,
30649,
774,
304,
339,
347,
3613,
8,
277,
304,
267,
3598,
14,
18815,
480,
4247,
531,
339,
347,
6766,
8,
277,
304,
267,
3598,
14,
3958,
5451,
342,
339,
347,
29779,
8,
277,
304,
267,
1279,
66,
63,
10466,
17,
275,
7110,
34,
13182,
14,
504,
63,
694,
8,
736,
14,
515,
14,
904,
6163,
334,
396,
63,
694,
12,
283,
685,
66,
17,
297,
283,
685,
66,
1333,
267,
1279,
66,
63,
10466,
17,
63,
504,
63,
807,
275,
7110,
34,
13182,
14,
504,
63,
807,
8,
685,
66,
63,
10466,
17,
14,
305,
63,
807,
1012,
267,
2022,
63,
576,
275,
2022,
14,
4180,
8,
685,
66,
63,
10466,
17,
14,
305,
63,
807,
1012,
398,
1279,
66,
63,
807,
275,
2022,
14,
3640,
8,
1001,
63,
576,
9,
267,
1279,
66,
63,
10466,
17,
63,
504,
63,
1001,
63,
576,
275,
7110,
34,
13182,
14,
504,
63,
807,
8,
685,
66,
63,
807,
9,
398,
291,
14,
479,
3836,
7331,
8,
685,
66,
63,
10466,
17,
14,
29607,
59,
16,
467,
446,
2299,
14,
2576,
1020,
9969,
25,
19983,
9,
267,
291,
14,
479,
3836,
7331,
8,
685,
66,
63,
10466,
17,
14,
29607,
59,
19,
467,
446,
2299,
14,
1349,
1479,
7155,
22,
19983,
9,
267,
291,
14,
479,
3836,
7331,
8,
685,
66,
63,
10466,
17,
14,
82,
12,
1279,
66,
63,
10466,
17,
63,
504,
63,
807,
14,
82,
9,
267,
291,
14,
479,
3836,
7331,
8,
685,
66,
63,
10466,
17,
14,
29607,
12,
1279,
66,
63,
10466,
17,
63,
504,
63,
807,
14,
29607,
9,
267,
291,
14,
479,
3836,
7331,
8,
685,
66,
63,
10466,
17,
14,
509,
823,
12,
1279,
66,
63,
10466,
17,
63,
504,
63,
807,
14,
509,
823,
9,
267,
291,
14,
629,
8,
685,
66,
63,
10466,
17,
14,
13547,
12,
1279,
66,
63,
10466,
17,
63,
504,
63,
807,
14,
13547,
9,
398,
291,
14,
479,
3836,
7331,
8,
685,
66,
63,
10466,
17,
14,
82,
12,
1279,
66,
63,
10466,
17,
63,
504,
63,
1001,
63,
576,
14,
82,
9,
267,
291,
14,
479,
3836,
7331,
8,
685,
66,
63,
10466,
17,
14,
29607,
12,
1279,
66,
63,
10466,
17,
63,
504,
63,
1001,
63,
576,
14,
29607,
9,
267,
291,
14,
479,
3836,
7331,
8,
685,
66,
63,
10466,
17,
14,
509,
823,
12,
1279,
66,
63,
10466,
17,
63,
504,
63,
1001,
63,
576,
14,
509,
823,
9,
267,
291,
14,
629,
8,
685,
66,
63,
10466,
17,
14,
13547,
12,
1279,
66,
63,
10466,
17,
63,
504,
63,
1001,
63,
576,
14,
13547,
9,
398,
291,
14,
479,
3836,
7331,
8,
685,
66,
63,
10466,
17,
14,
362,
63,
832,
264,
391,
3430,
17,
1527,
16,
467,
334,
16,
14,
5783,
10034,
1276,
2819,
1082,
6718,
2277,
12,
650,
821,
14,
15431,
11363,
1355,
1276,
3933,
430,
398,
1279,
66,
63,
10466,
17,
14,
2758,
63,
27066,
8,
27066,
63,
1419,
3713,
83,
20101,
63,
1403,
356,
283,
4262,
63,
25278,
3071,
267,
291,
14,
479,
3836,
7331,
8,
685,
66,
63,
10466,
17,
14,
362,
63,
832,
264,
391,
3430,
17,
1527,
16,
467,
334,
16,
14,
5783,
10034,
1276,
2819,
1082,
6718,
2277,
12,
650,
821,
14,
8269,
1355,
1349,
29840,
1644,
430,
267,
543,
1551,
8,
736,
14,
515,
14,
904,
8,
396,
63,
694,
12,
283,
685,
66,
18,
297,
283,
685,
66,
63,
10466,
18,
14,
1001,
659,
2116,
283,
82,
358,
465,
289,
26,
288,
1279,
66,
63,
10466,
18,
63,
807,
275,
2022,
14,
912,
8,
70,
9,
267,
1279,
66,
63,
10466,
18,
275,
7110,
34,
13182,
14,
504,
63,
807,
8,
685,
66,
63,
10466,
18,
63,
807,
9,
267,
291,
14,
479,
3836,
7331,
8,
685,
66,
63,
10466,
18,
14,
362,
63,
832,
264,
391,
3430,
17,
1527,
16,
467,
334,
16,
14,
1401,
2299,
11551,
1344,
1342,
1822,
8342,
12,
959,
2789,
14,
26132,
3781,
1082,
2869,
1020,
3328,
430,
398,
1279,
66,
63,
10466,
18,
14,
2758,
63,
27066,
8,
27066,
63,
1419,
3713,
83,
20101,
63,
1403,
356,
283,
4262,
63,
25278,
3071,
267,
291,
14,
479,
3836,
7331,
8,
685,
66,
63,
10466,
18,
14,
362,
63,
832,
264,
391,
3430,
17,
1527,
16,
467,
334,
16,
14,
1216,
1401,
845,
1153,
2819,
12532,
1555,
2635,
12,
959,
1651,
14,
2466,
1081,
2534,
2192,
772,
1184,
3328,
430,
339,
347,
511,
63,
13307,
63,
685,
66,
63,
13701,
8,
277,
304,
267,
1279,
66,
63,
694,
275,
747,
14,
515,
14,
904,
8,
396,
63,
694,
12,
283,
685,
66,
17,
297,
283,
685,
66,
358,
267,
1279,
66,
63,
10466,
275,
7110,
34,
13182,
14,
504,
63,
694,
8,
685,
66,
63,
694,
9
] |
[
2803,
26,
2774,
13,
24,
199,
3,
1898,
334,
67,
9,
1611,
30649,
15290,
11682,
14,
199,
3,
17484,
1334,
314,
2895,
402,
314,
10697,
844,
14,
199,
199,
504,
636,
2443,
363,
492,
4629,
12,
2649,
63,
5955,
199,
199,
646,
747,
199,
646,
2882,
199,
646,
3598,
199,
504,
1134,
30649,
14,
1974,
14,
4776,
492,
1611,
30649,
774,
199,
504,
1134,
30649,
14,
10466,
14,
14143,
63,
929,
492,
7110,
34,
13182,
199,
646,
2022,
199,
504,
1134,
30649,
14,
10466,
14,
14143,
63,
929,
492,
13323,
63,
685,
66,
63,
13701,
199,
199,
624,
199,
11768,
26,
22520,
2882,
1382,
14,
199,
624,
199,
199,
363,
2502,
363,
275,
298,
36,
17204,
644,
285,
79,
783,
1192,
2,
199,
363,
7307,
363,
275,
298,
7384,
7800,
12,
710,
26570,
83,
7290,
2,
199,
363,
1023,
363,
275,
298,
16,
14,
17,
2,
199,
363,
26665,
363,
275,
298,
2662,
89,
455,
577,
3281,
1151,
78,
1619,
2,
199,
363,
2123,
363,
275,
298,
609,
89,
21778,
32,
18842,
14,
16294,
2,
199,
363,
602,
363,
275,
298,
18,
15,
21,
15,
975,
2,
421,
199,
396,
63,
694,
275,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
21777,
401,
21777,
401,
21777,
401,
717,
283,
396,
63,
1725,
297,
283,
685,
66,
63,
10466,
358,
421,
199,
533,
7110,
34,
13182,
774,
8,
2713,
30649,
774,
304,
339,
347,
3613,
8,
277,
304,
267,
3598,
14,
18815,
480,
4247,
531,
339,
347,
6766,
8,
277,
304,
267,
3598,
14,
3958,
5451,
342,
339,
347,
29779,
8,
277,
304,
267,
1279,
66,
63,
10466,
17,
275,
7110,
34,
13182,
14,
504,
63,
694,
8,
736,
14,
515,
14,
904,
6163,
334,
396,
63,
694,
12,
283,
685,
66,
17,
297,
283,
685,
66,
1333,
267,
1279,
66,
63,
10466,
17,
63,
504,
63,
807,
275,
7110,
34,
13182,
14,
504,
63,
807,
8,
685,
66,
63,
10466,
17,
14,
305,
63,
807,
1012,
267,
2022,
63,
576,
275,
2022,
14,
4180,
8,
685,
66,
63,
10466,
17,
14,
305,
63,
807,
1012,
398,
1279,
66,
63,
807,
275,
2022,
14,
3640,
8,
1001,
63,
576,
9,
267,
1279,
66,
63,
10466,
17,
63,
504,
63,
1001,
63,
576,
275,
7110,
34,
13182,
14,
504,
63,
807,
8,
685,
66,
63,
807,
9,
398,
291,
14,
479,
3836,
7331,
8,
685,
66,
63,
10466,
17,
14,
29607,
59,
16,
467,
446,
2299,
14,
2576,
1020,
9969,
25,
19983,
9,
267,
291,
14,
479,
3836,
7331,
8,
685,
66,
63,
10466,
17,
14,
29607,
59,
19,
467,
446,
2299,
14,
1349,
1479,
7155,
22,
19983,
9,
267,
291,
14,
479,
3836,
7331,
8,
685,
66,
63,
10466,
17,
14,
82,
12,
1279,
66,
63,
10466,
17,
63,
504,
63,
807,
14,
82,
9,
267,
291,
14,
479,
3836,
7331,
8,
685,
66,
63,
10466,
17,
14,
29607,
12,
1279,
66,
63,
10466,
17,
63,
504,
63,
807,
14,
29607,
9,
267,
291,
14,
479,
3836,
7331,
8,
685,
66,
63,
10466,
17,
14,
509,
823,
12,
1279,
66,
63,
10466,
17,
63,
504,
63,
807,
14,
509,
823,
9,
267,
291,
14,
629,
8,
685,
66,
63,
10466,
17,
14,
13547,
12,
1279,
66,
63,
10466,
17,
63,
504,
63,
807,
14,
13547,
9,
398,
291,
14,
479,
3836,
7331,
8,
685,
66,
63,
10466,
17,
14,
82,
12,
1279,
66,
63,
10466,
17,
63,
504,
63,
1001,
63,
576,
14,
82,
9,
267,
291,
14,
479,
3836,
7331,
8,
685,
66,
63,
10466,
17,
14,
29607,
12,
1279,
66,
63,
10466,
17,
63,
504,
63,
1001,
63,
576,
14,
29607,
9,
267,
291,
14,
479,
3836,
7331,
8,
685,
66,
63,
10466,
17,
14,
509,
823,
12,
1279,
66,
63,
10466,
17,
63,
504,
63,
1001,
63,
576,
14,
509,
823,
9,
267,
291,
14,
629,
8,
685,
66,
63,
10466,
17,
14,
13547,
12,
1279,
66,
63,
10466,
17,
63,
504,
63,
1001,
63,
576,
14,
13547,
9,
398,
291,
14,
479,
3836,
7331,
8,
685,
66,
63,
10466,
17,
14,
362,
63,
832,
264,
391,
3430,
17,
1527,
16,
467,
334,
16,
14,
5783,
10034,
1276,
2819,
1082,
6718,
2277,
12,
650,
821,
14,
15431,
11363,
1355,
1276,
3933,
430,
398,
1279,
66,
63,
10466,
17,
14,
2758,
63,
27066,
8,
27066,
63,
1419,
3713,
83,
20101,
63,
1403,
356,
283,
4262,
63,
25278,
3071,
267,
291,
14,
479,
3836,
7331,
8,
685,
66,
63,
10466,
17,
14,
362,
63,
832,
264,
391,
3430,
17,
1527,
16,
467,
334,
16,
14,
5783,
10034,
1276,
2819,
1082,
6718,
2277,
12,
650,
821,
14,
8269,
1355,
1349,
29840,
1644,
430,
267,
543,
1551,
8,
736,
14,
515,
14,
904,
8,
396,
63,
694,
12,
283,
685,
66,
18,
297,
283,
685,
66,
63,
10466,
18,
14,
1001,
659,
2116,
283,
82,
358,
465,
289,
26,
288,
1279,
66,
63,
10466,
18,
63,
807,
275,
2022,
14,
912,
8,
70,
9,
267,
1279,
66,
63,
10466,
18,
275,
7110,
34,
13182,
14,
504,
63,
807,
8,
685,
66,
63,
10466,
18,
63,
807,
9,
267,
291,
14,
479,
3836,
7331,
8,
685,
66,
63,
10466,
18,
14,
362,
63,
832,
264,
391,
3430,
17,
1527,
16,
467,
334,
16,
14,
1401,
2299,
11551,
1344,
1342,
1822,
8342,
12,
959,
2789,
14,
26132,
3781,
1082,
2869,
1020,
3328,
430,
398,
1279,
66,
63,
10466,
18,
14,
2758,
63,
27066,
8,
27066,
63,
1419,
3713,
83,
20101,
63,
1403,
356,
283,
4262,
63,
25278,
3071,
267,
291,
14,
479,
3836,
7331,
8,
685,
66,
63,
10466,
18,
14,
362,
63,
832,
264,
391,
3430,
17,
1527,
16,
467,
334,
16,
14,
1216,
1401,
845,
1153,
2819,
12532,
1555,
2635,
12,
959,
1651,
14,
2466,
1081,
2534,
2192,
772,
1184,
3328,
430,
339,
347,
511,
63,
13307,
63,
685,
66,
63,
13701,
8,
277,
304,
267,
1279,
66,
63,
694,
275,
747,
14,
515,
14,
904,
8,
396,
63,
694,
12,
283,
685,
66,
17,
297,
283,
685,
66,
358,
267,
1279,
66,
63,
10466,
275,
7110,
34,
13182,
14,
504,
63,
694,
8,
685,
66,
63,
694,
9,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
osmanbaskaya/formality-classifier-cnn
|
build_model.py
|
2
|
1627
|
import sys
import data
import codecs
import cPickle
import os
from model import create_logistic_model, create_regression_model, train_model
fn = sys.argv[1]
model_output_dir = sys.argv[2]
problem_type = sys.argv[3]
use_pretrained_embeddings = True if sys.argv[4].lower() == 'true' else False
print >> sys.stderr, fn, model_output_dir, problem_type, use_pretrained_embeddings
assert problem_type in ('regression', 'classification'), "Problem type should be either regression or classification"
maxlen = 25 # maximum length for each sentence.
max_features = 25000 # length of the vocabulary.
batch_size = 32
nb_epoch = 4
additional_num_words = 2 # "UNK" and "PADDING"
(X_train, y_train), (_, _), word_idx = data.read(fn, 0.0, maxlen, max_features, problem_type)
print >> sys.stderr, 'X_train shape:', X_train.shape
max_features = min(max_features, len(word_idx) + additional_num_words)
if problem_type == 'regression':
model = create_regression_model(maxlen, max_features, word_idx, use_pretrained_embeddings)
else:
model = create_logistic_model(maxlen, max_features, word_idx, use_pretrained_embeddings)
train_model(model, X_train, y_train, batch_size, nb_epoch)
model.save_weights(os.path.join(model_output_dir, 'weights.h5'), overwrite=True)
print >> sys.stderr, "Weights are written"
cPickle.dump(word_idx, codecs.open(os.path.join(model_output_dir, 'word_idx.json'), 'w', encoding='utf8'))
print >> sys.stderr, "word_idx dict is written"
architecture = model.to_json()
open(os.path.join(model_output_dir, 'architecture.json'), 'w').write(architecture)
print >> sys.stderr, "Architecture is written"
|
mit
|
[
646,
984,
199,
646,
666,
199,
646,
6010,
199,
646,
17572,
199,
646,
747,
199,
504,
1402,
492,
1218,
63,
23452,
63,
1238,
12,
1218,
63,
12513,
63,
1238,
12,
3560,
63,
1238,
421,
199,
2324,
275,
984,
14,
3020,
59,
17,
61,
199,
1238,
63,
1199,
63,
694,
275,
984,
14,
3020,
59,
18,
61,
199,
6462,
63,
466,
275,
984,
14,
3020,
59,
19,
61,
199,
1180,
63,
657,
23782,
63,
32719,
275,
715,
340,
984,
14,
3020,
59,
20,
1055,
2325,
342,
508,
283,
2052,
7,
587,
756,
199,
199,
1361,
4331,
984,
14,
3083,
12,
4325,
12,
1402,
63,
1199,
63,
694,
12,
5160,
63,
466,
12,
675,
63,
657,
23782,
63,
32719,
199,
199,
479,
5160,
63,
466,
315,
661,
12513,
297,
283,
14368,
659,
298,
16467,
730,
1077,
506,
1902,
10864,
503,
12505,
2,
199,
199,
29078,
275,
5661,
221,
327,
5696,
2582,
367,
1924,
14537,
14,
199,
988,
63,
3179,
275,
5661,
1493,
221,
327,
2582,
402,
314,
17515,
14,
199,
2912,
63,
890,
275,
4337,
199,
4994,
63,
7367,
275,
841,
199,
8460,
63,
1507,
63,
3148,
275,
499,
221,
327,
298,
8019,
2,
436,
298,
48,
9732,
1206,
2,
421,
199,
8,
56,
63,
2834,
12,
612,
63,
2834,
395,
27017,
485,
395,
4349,
63,
2996,
275,
666,
14,
739,
8,
2324,
12,
378,
14,
16,
12,
21037,
12,
1390,
63,
3179,
12,
5160,
63,
466,
9,
199,
1361,
4331,
984,
14,
3083,
12,
283,
56,
63,
2834,
2215,
6536,
1323,
63,
2834,
14,
1392,
199,
199,
988,
63,
3179,
275,
1748,
8,
988,
63,
3179,
12,
822,
8,
1027,
63,
2996,
9,
435,
4722,
63,
1507,
63,
3148,
9,
199,
199,
692,
5160,
63,
466,
508,
283,
12513,
356,
272,
1402,
275,
1218,
63,
12513,
63,
1238,
8,
29078,
12,
1390,
63,
3179,
12,
4349,
63,
2996,
12,
675,
63,
657,
23782,
63,
32719,
9,
199,
2836,
26,
272,
1402,
275,
1218,
63,
23452,
63,
1238,
8,
29078,
12,
1390,
63,
3179,
12,
4349,
63,
2996,
12,
675,
63,
657,
23782,
63,
32719,
9,
199,
199,
2834,
63,
1238,
8,
1238,
12,
1323,
63,
2834,
12,
612,
63,
2834,
12,
3522,
63,
890,
12,
8526,
63,
7367,
9,
199,
1238,
14,
2117,
63,
4916,
8,
736,
14,
515,
14,
904,
8,
1238,
63,
1199,
63,
694,
12,
283,
4916,
14,
72,
21,
659,
8970,
29,
549,
9,
199,
1361,
4331,
984,
14,
3083,
12,
298,
23885,
787,
5313,
2,
199,
199,
67,
12755,
14,
2724,
8,
1027,
63,
2996,
12,
6010,
14,
1490,
8,
736,
14,
515,
14,
904,
8,
1238,
63,
1199,
63,
694,
12,
283,
1027,
63,
2996,
14,
1001,
659,
283,
87,
297,
2644,
534,
1624,
24,
1333,
199,
1361,
4331,
984,
14,
3083,
12,
298,
1027,
63,
2996,
1211,
365,
5313,
2,
199,
199,
19134,
275,
1402,
14,
475,
63,
1001,
342,
199,
1490,
8,
736,
14,
515,
14,
904,
8,
1238,
63,
1199,
63,
694,
12,
283,
19134,
14,
1001,
659,
283,
87,
1959,
952,
8,
19134,
9,
199,
1361,
4331,
984,
14,
3083,
12,
298,
8438,
10497,
365,
5313,
2,
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
] |
[
984,
199,
646,
666,
199,
646,
6010,
199,
646,
17572,
199,
646,
747,
199,
504,
1402,
492,
1218,
63,
23452,
63,
1238,
12,
1218,
63,
12513,
63,
1238,
12,
3560,
63,
1238,
421,
199,
2324,
275,
984,
14,
3020,
59,
17,
61,
199,
1238,
63,
1199,
63,
694,
275,
984,
14,
3020,
59,
18,
61,
199,
6462,
63,
466,
275,
984,
14,
3020,
59,
19,
61,
199,
1180,
63,
657,
23782,
63,
32719,
275,
715,
340,
984,
14,
3020,
59,
20,
1055,
2325,
342,
508,
283,
2052,
7,
587,
756,
199,
199,
1361,
4331,
984,
14,
3083,
12,
4325,
12,
1402,
63,
1199,
63,
694,
12,
5160,
63,
466,
12,
675,
63,
657,
23782,
63,
32719,
199,
199,
479,
5160,
63,
466,
315,
661,
12513,
297,
283,
14368,
659,
298,
16467,
730,
1077,
506,
1902,
10864,
503,
12505,
2,
199,
199,
29078,
275,
5661,
221,
327,
5696,
2582,
367,
1924,
14537,
14,
199,
988,
63,
3179,
275,
5661,
1493,
221,
327,
2582,
402,
314,
17515,
14,
199,
2912,
63,
890,
275,
4337,
199,
4994,
63,
7367,
275,
841,
199,
8460,
63,
1507,
63,
3148,
275,
499,
221,
327,
298,
8019,
2,
436,
298,
48,
9732,
1206,
2,
421,
199,
8,
56,
63,
2834,
12,
612,
63,
2834,
395,
27017,
485,
395,
4349,
63,
2996,
275,
666,
14,
739,
8,
2324,
12,
378,
14,
16,
12,
21037,
12,
1390,
63,
3179,
12,
5160,
63,
466,
9,
199,
1361,
4331,
984,
14,
3083,
12,
283,
56,
63,
2834,
2215,
6536,
1323,
63,
2834,
14,
1392,
199,
199,
988,
63,
3179,
275,
1748,
8,
988,
63,
3179,
12,
822,
8,
1027,
63,
2996,
9,
435,
4722,
63,
1507,
63,
3148,
9,
199,
199,
692,
5160,
63,
466,
508,
283,
12513,
356,
272,
1402,
275,
1218,
63,
12513,
63,
1238,
8,
29078,
12,
1390,
63,
3179,
12,
4349,
63,
2996,
12,
675,
63,
657,
23782,
63,
32719,
9,
199,
2836,
26,
272,
1402,
275,
1218,
63,
23452,
63,
1238,
8,
29078,
12,
1390,
63,
3179,
12,
4349,
63,
2996,
12,
675,
63,
657,
23782,
63,
32719,
9,
199,
199,
2834,
63,
1238,
8,
1238,
12,
1323,
63,
2834,
12,
612,
63,
2834,
12,
3522,
63,
890,
12,
8526,
63,
7367,
9,
199,
1238,
14,
2117,
63,
4916,
8,
736,
14,
515,
14,
904,
8,
1238,
63,
1199,
63,
694,
12,
283,
4916,
14,
72,
21,
659,
8970,
29,
549,
9,
199,
1361,
4331,
984,
14,
3083,
12,
298,
23885,
787,
5313,
2,
199,
199,
67,
12755,
14,
2724,
8,
1027,
63,
2996,
12,
6010,
14,
1490,
8,
736,
14,
515,
14,
904,
8,
1238,
63,
1199,
63,
694,
12,
283,
1027,
63,
2996,
14,
1001,
659,
283,
87,
297,
2644,
534,
1624,
24,
1333,
199,
1361,
4331,
984,
14,
3083,
12,
298,
1027,
63,
2996,
1211,
365,
5313,
2,
199,
199,
19134,
275,
1402,
14,
475,
63,
1001,
342,
199,
1490,
8,
736,
14,
515,
14,
904,
8,
1238,
63,
1199,
63,
694,
12,
283,
19134,
14,
1001,
659,
283,
87,
1959,
952,
8,
19134,
9,
199,
1361,
4331,
984,
14,
3083,
12,
298,
8438,
10497,
365,
5313,
2,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
a1d3s/linux-bpi
|
tools/perf/scripts/python/netdev-times.py
|
1544
|
15191
|
# Display a process of packets and processed time.
# It helps us to investigate networking or network device.
#
# options
# tx: show only tx chart
# rx: show only rx chart
# dev=: show only thing related to specified device
# debug: work with debug mode. It shows buffer status.
import os
import sys
sys.path.append(os.environ['PERF_EXEC_PATH'] + \
'/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
from perf_trace_context import *
from Core import *
from Util import *
all_event_list = []; # insert all tracepoint event related with this script
irq_dic = {}; # key is cpu and value is a list which stacks irqs
# which raise NET_RX softirq
net_rx_dic = {}; # key is cpu and value include time of NET_RX softirq-entry
# and a list which stacks receive
receive_hunk_list = []; # a list which include a sequence of receive events
rx_skb_list = []; # received packet list for matching
# skb_copy_datagram_iovec
buffer_budget = 65536; # the budget of rx_skb_list, tx_queue_list and
# tx_xmit_list
of_count_rx_skb_list = 0; # overflow count
tx_queue_list = []; # list of packets which pass through dev_queue_xmit
of_count_tx_queue_list = 0; # overflow count
tx_xmit_list = []; # list of packets which pass through dev_hard_start_xmit
of_count_tx_xmit_list = 0; # overflow count
tx_free_list = []; # list of packets which is freed
# options
show_tx = 0;
show_rx = 0;
dev = 0; # store a name of device specified by option "dev="
debug = 0;
# indices of event_info tuple
EINFO_IDX_NAME= 0
EINFO_IDX_CONTEXT=1
EINFO_IDX_CPU= 2
EINFO_IDX_TIME= 3
EINFO_IDX_PID= 4
EINFO_IDX_COMM= 5
# Calculate a time interval(msec) from src(nsec) to dst(nsec)
def diff_msec(src, dst):
return (dst - src) / 1000000.0
# Display a process of transmitting a packet
def print_transmit(hunk):
if dev != 0 and hunk['dev'].find(dev) < 0:
return
print "%7s %5d %6d.%06dsec %12.3fmsec %12.3fmsec" % \
(hunk['dev'], hunk['len'],
nsecs_secs(hunk['queue_t']),
nsecs_nsecs(hunk['queue_t'])/1000,
diff_msec(hunk['queue_t'], hunk['xmit_t']),
diff_msec(hunk['xmit_t'], hunk['free_t']))
# Format for displaying rx packet processing
PF_IRQ_ENTRY= " irq_entry(+%.3fmsec irq=%d:%s)"
PF_SOFT_ENTRY=" softirq_entry(+%.3fmsec)"
PF_NAPI_POLL= " napi_poll_exit(+%.3fmsec %s)"
PF_JOINT= " |"
PF_WJOINT= " | |"
PF_NET_RECV= " |---netif_receive_skb(+%.3fmsec skb=%x len=%d)"
PF_NET_RX= " |---netif_rx(+%.3fmsec skb=%x)"
PF_CPY_DGRAM= " | skb_copy_datagram_iovec(+%.3fmsec %d:%s)"
PF_KFREE_SKB= " | kfree_skb(+%.3fmsec location=%x)"
PF_CONS_SKB= " | consume_skb(+%.3fmsec)"
# Display a process of received packets and interrputs associated with
# a NET_RX softirq
def print_receive(hunk):
show_hunk = 0
irq_list = hunk['irq_list']
cpu = irq_list[0]['cpu']
base_t = irq_list[0]['irq_ent_t']
# check if this hunk should be showed
if dev != 0:
for i in range(len(irq_list)):
if irq_list[i]['name'].find(dev) >= 0:
show_hunk = 1
break
else:
show_hunk = 1
if show_hunk == 0:
return
print "%d.%06dsec cpu=%d" % \
(nsecs_secs(base_t), nsecs_nsecs(base_t)/1000, cpu)
for i in range(len(irq_list)):
print PF_IRQ_ENTRY % \
(diff_msec(base_t, irq_list[i]['irq_ent_t']),
irq_list[i]['irq'], irq_list[i]['name'])
print PF_JOINT
irq_event_list = irq_list[i]['event_list']
for j in range(len(irq_event_list)):
irq_event = irq_event_list[j]
if irq_event['event'] == 'netif_rx':
print PF_NET_RX % \
(diff_msec(base_t, irq_event['time']),
irq_event['skbaddr'])
print PF_JOINT
print PF_SOFT_ENTRY % \
diff_msec(base_t, hunk['sirq_ent_t'])
print PF_JOINT
event_list = hunk['event_list']
for i in range(len(event_list)):
event = event_list[i]
if event['event_name'] == 'napi_poll':
print PF_NAPI_POLL % \
(diff_msec(base_t, event['event_t']), event['dev'])
if i == len(event_list) - 1:
print ""
else:
print PF_JOINT
else:
print PF_NET_RECV % \
(diff_msec(base_t, event['event_t']), event['skbaddr'],
event['len'])
if 'comm' in event.keys():
print PF_WJOINT
print PF_CPY_DGRAM % \
(diff_msec(base_t, event['comm_t']),
event['pid'], event['comm'])
elif 'handle' in event.keys():
print PF_WJOINT
if event['handle'] == "kfree_skb":
print PF_KFREE_SKB % \
(diff_msec(base_t,
event['comm_t']),
event['location'])
elif event['handle'] == "consume_skb":
print PF_CONS_SKB % \
diff_msec(base_t,
event['comm_t'])
print PF_JOINT
def trace_begin():
global show_tx
global show_rx
global dev
global debug
for i in range(len(sys.argv)):
if i == 0:
continue
arg = sys.argv[i]
if arg == 'tx':
show_tx = 1
elif arg =='rx':
show_rx = 1
elif arg.find('dev=',0, 4) >= 0:
dev = arg[4:]
elif arg == 'debug':
debug = 1
if show_tx == 0 and show_rx == 0:
show_tx = 1
show_rx = 1
def trace_end():
# order all events in time
all_event_list.sort(lambda a,b :cmp(a[EINFO_IDX_TIME],
b[EINFO_IDX_TIME]))
# process all events
for i in range(len(all_event_list)):
event_info = all_event_list[i]
name = event_info[EINFO_IDX_NAME]
if name == 'irq__softirq_exit':
handle_irq_softirq_exit(event_info)
elif name == 'irq__softirq_entry':
handle_irq_softirq_entry(event_info)
elif name == 'irq__softirq_raise':
handle_irq_softirq_raise(event_info)
elif name == 'irq__irq_handler_entry':
handle_irq_handler_entry(event_info)
elif name == 'irq__irq_handler_exit':
handle_irq_handler_exit(event_info)
elif name == 'napi__napi_poll':
handle_napi_poll(event_info)
elif name == 'net__netif_receive_skb':
handle_netif_receive_skb(event_info)
elif name == 'net__netif_rx':
handle_netif_rx(event_info)
elif name == 'skb__skb_copy_datagram_iovec':
handle_skb_copy_datagram_iovec(event_info)
elif name == 'net__net_dev_queue':
handle_net_dev_queue(event_info)
elif name == 'net__net_dev_xmit':
handle_net_dev_xmit(event_info)
elif name == 'skb__kfree_skb':
handle_kfree_skb(event_info)
elif name == 'skb__consume_skb':
handle_consume_skb(event_info)
# display receive hunks
if show_rx:
for i in range(len(receive_hunk_list)):
print_receive(receive_hunk_list[i])
# display transmit hunks
if show_tx:
print " dev len Qdisc " \
" netdevice free"
for i in range(len(tx_free_list)):
print_transmit(tx_free_list[i])
if debug:
print "debug buffer status"
print "----------------------------"
print "xmit Qdisc:remain:%d overflow:%d" % \
(len(tx_queue_list), of_count_tx_queue_list)
print "xmit netdevice:remain:%d overflow:%d" % \
(len(tx_xmit_list), of_count_tx_xmit_list)
print "receive:remain:%d overflow:%d" % \
(len(rx_skb_list), of_count_rx_skb_list)
# called from perf, when it finds a correspoinding event
def irq__softirq_entry(name, context, cpu, sec, nsec, pid, comm, callchain, vec):
if symbol_str("irq__softirq_entry", "vec", vec) != "NET_RX":
return
event_info = (name, context, cpu, nsecs(sec, nsec), pid, comm, vec)
all_event_list.append(event_info)
def irq__softirq_exit(name, context, cpu, sec, nsec, pid, comm, callchain, vec):
if symbol_str("irq__softirq_entry", "vec", vec) != "NET_RX":
return
event_info = (name, context, cpu, nsecs(sec, nsec), pid, comm, vec)
all_event_list.append(event_info)
def irq__softirq_raise(name, context, cpu, sec, nsec, pid, comm, callchain, vec):
if symbol_str("irq__softirq_entry", "vec", vec) != "NET_RX":
return
event_info = (name, context, cpu, nsecs(sec, nsec), pid, comm, vec)
all_event_list.append(event_info)
def irq__irq_handler_entry(name, context, cpu, sec, nsec, pid, comm,
callchain, irq, irq_name):
event_info = (name, context, cpu, nsecs(sec, nsec), pid, comm,
irq, irq_name)
all_event_list.append(event_info)
def irq__irq_handler_exit(name, context, cpu, sec, nsec, pid, comm, callchain, irq, ret):
event_info = (name, context, cpu, nsecs(sec, nsec), pid, comm, irq, ret)
all_event_list.append(event_info)
def napi__napi_poll(name, context, cpu, sec, nsec, pid, comm, callchain, napi, dev_name):
event_info = (name, context, cpu, nsecs(sec, nsec), pid, comm,
napi, dev_name)
all_event_list.append(event_info)
def net__netif_receive_skb(name, context, cpu, sec, nsec, pid, comm, callchain, skbaddr,
skblen, dev_name):
event_info = (name, context, cpu, nsecs(sec, nsec), pid, comm,
skbaddr, skblen, dev_name)
all_event_list.append(event_info)
def net__netif_rx(name, context, cpu, sec, nsec, pid, comm, callchain, skbaddr,
skblen, dev_name):
event_info = (name, context, cpu, nsecs(sec, nsec), pid, comm,
skbaddr, skblen, dev_name)
all_event_list.append(event_info)
def net__net_dev_queue(name, context, cpu, sec, nsec, pid, comm, callchain,
skbaddr, skblen, dev_name):
event_info = (name, context, cpu, nsecs(sec, nsec), pid, comm,
skbaddr, skblen, dev_name)
all_event_list.append(event_info)
def net__net_dev_xmit(name, context, cpu, sec, nsec, pid, comm, callchain,
skbaddr, skblen, rc, dev_name):
event_info = (name, context, cpu, nsecs(sec, nsec), pid, comm,
skbaddr, skblen, rc ,dev_name)
all_event_list.append(event_info)
def skb__kfree_skb(name, context, cpu, sec, nsec, pid, comm, callchain,
skbaddr, protocol, location):
event_info = (name, context, cpu, nsecs(sec, nsec), pid, comm,
skbaddr, protocol, location)
all_event_list.append(event_info)
def skb__consume_skb(name, context, cpu, sec, nsec, pid, comm, callchain, skbaddr):
event_info = (name, context, cpu, nsecs(sec, nsec), pid, comm,
skbaddr)
all_event_list.append(event_info)
def skb__skb_copy_datagram_iovec(name, context, cpu, sec, nsec, pid, comm, callchain,
skbaddr, skblen):
event_info = (name, context, cpu, nsecs(sec, nsec), pid, comm,
skbaddr, skblen)
all_event_list.append(event_info)
def handle_irq_handler_entry(event_info):
(name, context, cpu, time, pid, comm, irq, irq_name) = event_info
if cpu not in irq_dic.keys():
irq_dic[cpu] = []
irq_record = {'irq':irq, 'name':irq_name, 'cpu':cpu, 'irq_ent_t':time}
irq_dic[cpu].append(irq_record)
def handle_irq_handler_exit(event_info):
(name, context, cpu, time, pid, comm, irq, ret) = event_info
if cpu not in irq_dic.keys():
return
irq_record = irq_dic[cpu].pop()
if irq != irq_record['irq']:
return
irq_record.update({'irq_ext_t':time})
# if an irq doesn't include NET_RX softirq, drop.
if 'event_list' in irq_record.keys():
irq_dic[cpu].append(irq_record)
def handle_irq_softirq_raise(event_info):
(name, context, cpu, time, pid, comm, vec) = event_info
if cpu not in irq_dic.keys() \
or len(irq_dic[cpu]) == 0:
return
irq_record = irq_dic[cpu].pop()
if 'event_list' in irq_record.keys():
irq_event_list = irq_record['event_list']
else:
irq_event_list = []
irq_event_list.append({'time':time, 'event':'sirq_raise'})
irq_record.update({'event_list':irq_event_list})
irq_dic[cpu].append(irq_record)
def handle_irq_softirq_entry(event_info):
(name, context, cpu, time, pid, comm, vec) = event_info
net_rx_dic[cpu] = {'sirq_ent_t':time, 'event_list':[]}
def handle_irq_softirq_exit(event_info):
(name, context, cpu, time, pid, comm, vec) = event_info
irq_list = []
event_list = 0
if cpu in irq_dic.keys():
irq_list = irq_dic[cpu]
del irq_dic[cpu]
if cpu in net_rx_dic.keys():
sirq_ent_t = net_rx_dic[cpu]['sirq_ent_t']
event_list = net_rx_dic[cpu]['event_list']
del net_rx_dic[cpu]
if irq_list == [] or event_list == 0:
return
rec_data = {'sirq_ent_t':sirq_ent_t, 'sirq_ext_t':time,
'irq_list':irq_list, 'event_list':event_list}
# merge information realted to a NET_RX softirq
receive_hunk_list.append(rec_data)
def handle_napi_poll(event_info):
(name, context, cpu, time, pid, comm, napi, dev_name) = event_info
if cpu in net_rx_dic.keys():
event_list = net_rx_dic[cpu]['event_list']
rec_data = {'event_name':'napi_poll',
'dev':dev_name, 'event_t':time}
event_list.append(rec_data)
def handle_netif_rx(event_info):
(name, context, cpu, time, pid, comm,
skbaddr, skblen, dev_name) = event_info
if cpu not in irq_dic.keys() \
or len(irq_dic[cpu]) == 0:
return
irq_record = irq_dic[cpu].pop()
if 'event_list' in irq_record.keys():
irq_event_list = irq_record['event_list']
else:
irq_event_list = []
irq_event_list.append({'time':time, 'event':'netif_rx',
'skbaddr':skbaddr, 'skblen':skblen, 'dev_name':dev_name})
irq_record.update({'event_list':irq_event_list})
irq_dic[cpu].append(irq_record)
def handle_netif_receive_skb(event_info):
global of_count_rx_skb_list
(name, context, cpu, time, pid, comm,
skbaddr, skblen, dev_name) = event_info
if cpu in net_rx_dic.keys():
rec_data = {'event_name':'netif_receive_skb',
'event_t':time, 'skbaddr':skbaddr, 'len':skblen}
event_list = net_rx_dic[cpu]['event_list']
event_list.append(rec_data)
rx_skb_list.insert(0, rec_data)
if len(rx_skb_list) > buffer_budget:
rx_skb_list.pop()
of_count_rx_skb_list += 1
def handle_net_dev_queue(event_info):
global of_count_tx_queue_list
(name, context, cpu, time, pid, comm,
skbaddr, skblen, dev_name) = event_info
skb = {'dev':dev_name, 'skbaddr':skbaddr, 'len':skblen, 'queue_t':time}
tx_queue_list.insert(0, skb)
if len(tx_queue_list) > buffer_budget:
tx_queue_list.pop()
of_count_tx_queue_list += 1
def handle_net_dev_xmit(event_info):
global of_count_tx_xmit_list
(name, context, cpu, time, pid, comm,
skbaddr, skblen, rc, dev_name) = event_info
if rc == 0: # NETDEV_TX_OK
for i in range(len(tx_queue_list)):
skb = tx_queue_list[i]
if skb['skbaddr'] == skbaddr:
skb['xmit_t'] = time
tx_xmit_list.insert(0, skb)
del tx_queue_list[i]
if len(tx_xmit_list) > buffer_budget:
tx_xmit_list.pop()
of_count_tx_xmit_list += 1
return
def handle_kfree_skb(event_info):
(name, context, cpu, time, pid, comm,
skbaddr, protocol, location) = event_info
for i in range(len(tx_queue_list)):
skb = tx_queue_list[i]
if skb['skbaddr'] == skbaddr:
del tx_queue_list[i]
return
for i in range(len(tx_xmit_list)):
skb = tx_xmit_list[i]
if skb['skbaddr'] == skbaddr:
skb['free_t'] = time
tx_free_list.append(skb)
del tx_xmit_list[i]
return
for i in range(len(rx_skb_list)):
rec_data = rx_skb_list[i]
if rec_data['skbaddr'] == skbaddr:
rec_data.update({'handle':"kfree_skb",
'comm':comm, 'pid':pid, 'comm_t':time})
del rx_skb_list[i]
return
def handle_consume_skb(event_info):
(name, context, cpu, time, pid, comm, skbaddr) = event_info
for i in range(len(tx_xmit_list)):
skb = tx_xmit_list[i]
if skb['skbaddr'] == skbaddr:
skb['free_t'] = time
tx_free_list.append(skb)
del tx_xmit_list[i]
return
def handle_skb_copy_datagram_iovec(event_info):
(name, context, cpu, time, pid, comm, skbaddr, skblen) = event_info
for i in range(len(rx_skb_list)):
rec_data = rx_skb_list[i]
if skbaddr == rec_data['skbaddr']:
rec_data.update({'handle':"skb_copy_datagram_iovec",
'comm':comm, 'pid':pid, 'comm_t':time})
del rx_skb_list[i]
return
|
gpl-2.0
|
[
3,
12175,
282,
2112,
402,
14593,
436,
7686,
900,
14,
199,
3,
2779,
22577,
2739,
370,
315,
27174,
323,
2784,
316,
503,
2784,
2243,
14,
199,
3,
199,
3,
1511,
199,
3,
4773,
26,
2498,
1454,
4773,
10943,
199,
3,
12951,
26,
2498,
1454,
12951,
10943,
199,
3,
4866,
29,
26,
2498,
1454,
8377,
4048,
370,
2013,
2243,
199,
3,
3105,
26,
1736,
543,
3105,
818,
14,
2779,
13703,
3335,
2004,
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,
8582,
63,
3446,
63,
1100,
492,
627,
199,
504,
11672,
492,
627,
199,
504,
21248,
492,
627,
199,
199,
452,
63,
1430,
63,
513,
275,
22750,
327,
5518,
1006,
3307,
1403,
1566,
4048,
543,
642,
2884,
199,
7277,
63,
5000,
275,
27978,
327,
790,
365,
5033,
436,
574,
365,
282,
769,
1314,
26733,
10476,
83,
1598,
327,
1314,
746,
18340,
63,
15361,
880,
15493,
199,
846,
63,
6872,
63,
5000,
275,
27978,
327,
790,
365,
5033,
436,
574,
2387,
900,
402,
18340,
63,
15361,
880,
15493,
13,
2373,
686,
327,
436,
282,
769,
1314,
26733,
9128,
199,
9391,
63,
17428,
63,
513,
275,
22750,
327,
282,
769,
1314,
2387,
282,
3414,
402,
9128,
4474,
199,
6872,
63,
6852,
63,
513,
275,
22750,
327,
3086,
3644,
769,
367,
4877,
686,
755,
327,
11448,
63,
1574,
63,
25443,
63,
30463,
199,
199,
2738,
63,
16501,
275,
25980,
27,
327,
314,
1032,
14080,
402,
12951,
63,
6852,
63,
513,
12,
4773,
63,
1825,
63,
513,
436,
686,
755,
327,
4773,
63,
14217,
63,
513,
199,
1618,
63,
835,
63,
6872,
63,
6852,
63,
513,
275,
378,
27,
327,
15784,
2338,
199,
199,
2347,
63,
1825,
63,
513,
275,
22750,
327,
769,
402,
14593,
1314,
986,
4012,
4866,
63,
1825,
63,
14217,
199,
1618,
63,
835,
63,
2347,
63,
1825,
63,
513,
275,
378,
27,
327,
15784,
2338,
199,
199,
2347,
63,
14217,
63,
513,
275,
22750,
221,
327,
769,
402,
14593,
1314,
986,
4012,
4866,
63,
8726,
63,
928,
63,
14217,
199,
1618,
63,
835,
63,
2347,
63,
14217,
63,
513,
275,
378,
27,
327,
15784,
2338,
199,
199,
2347,
63,
4624,
63,
513,
275,
22750,
221,
327,
769,
402,
14593,
1314,
365,
23694,
199,
199,
3,
1511,
199,
2384,
63,
2347,
275,
378,
27,
199,
2384,
63,
6872,
275,
378,
27,
199,
2374,
275,
378,
27,
327,
3877,
282,
536,
402,
2243,
2013,
701,
945,
298,
2374,
628,
199,
1757,
275,
378,
27,
199,
199,
3,
4918,
402,
1566,
63,
815,
2008,
199,
26556,
63,
20037,
63,
2339,
29,
257,
378,
199,
26556,
63,
20037,
63,
9059,
29,
17,
199,
26556,
63,
20037,
63,
11011,
29,
259,
499,
199,
26556,
63,
20037,
63,
4961,
29,
257,
650,
199,
26556,
63,
20037,
63,
16098,
29,
259,
841,
199,
26556,
63,
20037,
63,
5378,
29,
257,
959,
199,
199,
3,
12707,
282,
900,
6252,
8,
19764,
9,
687,
2928,
8,
78,
3321,
9,
370,
5042,
8,
78,
3321,
9,
199,
318,
3915,
63,
19764,
8,
2164,
12,
5042,
304,
199,
198,
1107,
334,
5119,
446,
2928,
9,
1182,
19492,
14,
16,
199,
199,
3,
12175,
282,
2112,
402,
27754,
1337,
282,
3644,
199,
318,
870,
63,
31399,
8,
17428,
304,
199,
198,
692,
4866,
1137,
378,
436,
19988,
459,
2374,
2278,
1623,
8,
2374,
9,
665,
378,
26,
507,
198,
1107,
199,
198,
1361,
2071,
23,
83,
450,
21,
68,
450,
22,
68,
4111,
1690,
68,
3321,
450,
713,
14,
19,
25154,
420,
450,
713,
14,
19,
25154,
2,
450,
971,
507,
198,
8,
17428,
459,
2374,
995,
19988,
459,
552,
995,
507,
198,
9618,
63,
4855,
8,
17428,
459,
1825,
63,
84,
3815,
507,
198,
9618,
63,
9618,
8,
17428,
459,
1825,
63,
84,
1105,
15,
5279,
12,
507,
198,
3028,
63,
19764,
8,
17428,
459,
1825,
63,
84,
995,
19988,
459,
14217,
63,
84,
3815,
507,
198,
3028,
63,
19764,
8,
17428,
459,
14217,
63,
84,
995,
19988,
459,
4624,
63,
84,
5156,
199,
199,
3,
9701,
367,
20589,
12951,
3644,
6661,
199,
10966,
63,
3927,
49,
63,
7285,
29,
298,
221,
10476,
63,
2373,
28643,
19,
25154,
10476,
2458,
68,
2689,
83,
2924,
199,
10966,
63,
26999,
63,
7285,
628,
221,
880,
15493,
63,
2373,
28643,
19,
25154,
2924,
199,
10966,
63,
46,
3735,
63,
16428,
29,
298,
221,
302,
1246,
63,
6843,
63,
2224,
28643,
19,
25154,
450,
83,
2924,
199,
10966,
63,
24931,
29,
258,
298,
260,
1204,
2,
199,
10966,
63,
55,
24931,
29,
259,
298,
260,
1204,
3322,
1204,
2,
199,
10966,
63,
7278,
63,
9481,
54,
29,
221,
298,
260,
1204,
2595,
20869,
63,
9391,
63,
6852,
28643,
19,
25154,
11448,
2458,
88,
822,
2458,
68,
2924,
199,
10966,
63,
7278,
63,
15361,
29,
259,
298,
260,
1204,
2595,
20869,
63,
6872,
28643,
19,
25154,
11448,
2458,
88,
2924,
199,
10966,
63,
2890,
57,
63,
25351,
29,
298,
260,
1204,
420,
11448,
63,
1574,
63,
25443,
63,
30463,
28643,
19,
25154,
450,
68,
2689,
83,
2924,
199,
10966,
63,
17706,
5271,
63,
8656,
34,
29,
298,
260,
1204,
420,
1022,
4624,
63,
6852,
28643,
19,
25154,
2909,
2458,
88,
2924,
199,
10966,
63,
1864,
51,
63,
8656,
34,
29,
221,
298,
260,
1204,
420,
9451,
63,
6852,
28643,
19,
25154,
2924,
199,
199,
3,
12175,
282,
2112,
402,
3086,
14593,
436,
1640,
82,
524,
83,
4568,
543,
199,
3,
282,
18340,
63,
15361,
880,
15493,
199,
318,
870,
63,
9391,
8,
17428,
304,
199,
198,
2384,
63,
17428,
275,
378,
199,
198,
7277,
63,
513,
275,
19988,
459,
7277,
63,
513,
418,
199,
198,
3541,
275,
10476,
63,
513,
59,
16,
2733,
3541,
418,
199,
198,
1095,
63,
84,
275,
10476,
63,
513,
59,
16,
2733,
7277,
63,
484,
63,
84,
418,
199,
198,
3,
1104,
340,
642,
19988,
1077,
506,
2498,
379,
199,
198,
692,
4866,
1137,
378,
26,
507,
198,
509,
284,
315,
1425,
8,
552,
8,
7277,
63,
513,
2298,
686,
198,
692,
10476,
63,
513
] |
[
12175,
282,
2112,
402,
14593,
436,
7686,
900,
14,
199,
3,
2779,
22577,
2739,
370,
315,
27174,
323,
2784,
316,
503,
2784,
2243,
14,
199,
3,
199,
3,
1511,
199,
3,
4773,
26,
2498,
1454,
4773,
10943,
199,
3,
12951,
26,
2498,
1454,
12951,
10943,
199,
3,
4866,
29,
26,
2498,
1454,
8377,
4048,
370,
2013,
2243,
199,
3,
3105,
26,
1736,
543,
3105,
818,
14,
2779,
13703,
3335,
2004,
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,
8582,
63,
3446,
63,
1100,
492,
627,
199,
504,
11672,
492,
627,
199,
504,
21248,
492,
627,
199,
199,
452,
63,
1430,
63,
513,
275,
22750,
327,
5518,
1006,
3307,
1403,
1566,
4048,
543,
642,
2884,
199,
7277,
63,
5000,
275,
27978,
327,
790,
365,
5033,
436,
574,
365,
282,
769,
1314,
26733,
10476,
83,
1598,
327,
1314,
746,
18340,
63,
15361,
880,
15493,
199,
846,
63,
6872,
63,
5000,
275,
27978,
327,
790,
365,
5033,
436,
574,
2387,
900,
402,
18340,
63,
15361,
880,
15493,
13,
2373,
686,
327,
436,
282,
769,
1314,
26733,
9128,
199,
9391,
63,
17428,
63,
513,
275,
22750,
327,
282,
769,
1314,
2387,
282,
3414,
402,
9128,
4474,
199,
6872,
63,
6852,
63,
513,
275,
22750,
327,
3086,
3644,
769,
367,
4877,
686,
755,
327,
11448,
63,
1574,
63,
25443,
63,
30463,
199,
199,
2738,
63,
16501,
275,
25980,
27,
327,
314,
1032,
14080,
402,
12951,
63,
6852,
63,
513,
12,
4773,
63,
1825,
63,
513,
436,
686,
755,
327,
4773,
63,
14217,
63,
513,
199,
1618,
63,
835,
63,
6872,
63,
6852,
63,
513,
275,
378,
27,
327,
15784,
2338,
199,
199,
2347,
63,
1825,
63,
513,
275,
22750,
327,
769,
402,
14593,
1314,
986,
4012,
4866,
63,
1825,
63,
14217,
199,
1618,
63,
835,
63,
2347,
63,
1825,
63,
513,
275,
378,
27,
327,
15784,
2338,
199,
199,
2347,
63,
14217,
63,
513,
275,
22750,
221,
327,
769,
402,
14593,
1314,
986,
4012,
4866,
63,
8726,
63,
928,
63,
14217,
199,
1618,
63,
835,
63,
2347,
63,
14217,
63,
513,
275,
378,
27,
327,
15784,
2338,
199,
199,
2347,
63,
4624,
63,
513,
275,
22750,
221,
327,
769,
402,
14593,
1314,
365,
23694,
199,
199,
3,
1511,
199,
2384,
63,
2347,
275,
378,
27,
199,
2384,
63,
6872,
275,
378,
27,
199,
2374,
275,
378,
27,
327,
3877,
282,
536,
402,
2243,
2013,
701,
945,
298,
2374,
628,
199,
1757,
275,
378,
27,
199,
199,
3,
4918,
402,
1566,
63,
815,
2008,
199,
26556,
63,
20037,
63,
2339,
29,
257,
378,
199,
26556,
63,
20037,
63,
9059,
29,
17,
199,
26556,
63,
20037,
63,
11011,
29,
259,
499,
199,
26556,
63,
20037,
63,
4961,
29,
257,
650,
199,
26556,
63,
20037,
63,
16098,
29,
259,
841,
199,
26556,
63,
20037,
63,
5378,
29,
257,
959,
199,
199,
3,
12707,
282,
900,
6252,
8,
19764,
9,
687,
2928,
8,
78,
3321,
9,
370,
5042,
8,
78,
3321,
9,
199,
318,
3915,
63,
19764,
8,
2164,
12,
5042,
304,
199,
198,
1107,
334,
5119,
446,
2928,
9,
1182,
19492,
14,
16,
199,
199,
3,
12175,
282,
2112,
402,
27754,
1337,
282,
3644,
199,
318,
870,
63,
31399,
8,
17428,
304,
199,
198,
692,
4866,
1137,
378,
436,
19988,
459,
2374,
2278,
1623,
8,
2374,
9,
665,
378,
26,
507,
198,
1107,
199,
198,
1361,
2071,
23,
83,
450,
21,
68,
450,
22,
68,
4111,
1690,
68,
3321,
450,
713,
14,
19,
25154,
420,
450,
713,
14,
19,
25154,
2,
450,
971,
507,
198,
8,
17428,
459,
2374,
995,
19988,
459,
552,
995,
507,
198,
9618,
63,
4855,
8,
17428,
459,
1825,
63,
84,
3815,
507,
198,
9618,
63,
9618,
8,
17428,
459,
1825,
63,
84,
1105,
15,
5279,
12,
507,
198,
3028,
63,
19764,
8,
17428,
459,
1825,
63,
84,
995,
19988,
459,
14217,
63,
84,
3815,
507,
198,
3028,
63,
19764,
8,
17428,
459,
14217,
63,
84,
995,
19988,
459,
4624,
63,
84,
5156,
199,
199,
3,
9701,
367,
20589,
12951,
3644,
6661,
199,
10966,
63,
3927,
49,
63,
7285,
29,
298,
221,
10476,
63,
2373,
28643,
19,
25154,
10476,
2458,
68,
2689,
83,
2924,
199,
10966,
63,
26999,
63,
7285,
628,
221,
880,
15493,
63,
2373,
28643,
19,
25154,
2924,
199,
10966,
63,
46,
3735,
63,
16428,
29,
298,
221,
302,
1246,
63,
6843,
63,
2224,
28643,
19,
25154,
450,
83,
2924,
199,
10966,
63,
24931,
29,
258,
298,
260,
1204,
2,
199,
10966,
63,
55,
24931,
29,
259,
298,
260,
1204,
3322,
1204,
2,
199,
10966,
63,
7278,
63,
9481,
54,
29,
221,
298,
260,
1204,
2595,
20869,
63,
9391,
63,
6852,
28643,
19,
25154,
11448,
2458,
88,
822,
2458,
68,
2924,
199,
10966,
63,
7278,
63,
15361,
29,
259,
298,
260,
1204,
2595,
20869,
63,
6872,
28643,
19,
25154,
11448,
2458,
88,
2924,
199,
10966,
63,
2890,
57,
63,
25351,
29,
298,
260,
1204,
420,
11448,
63,
1574,
63,
25443,
63,
30463,
28643,
19,
25154,
450,
68,
2689,
83,
2924,
199,
10966,
63,
17706,
5271,
63,
8656,
34,
29,
298,
260,
1204,
420,
1022,
4624,
63,
6852,
28643,
19,
25154,
2909,
2458,
88,
2924,
199,
10966,
63,
1864,
51,
63,
8656,
34,
29,
221,
298,
260,
1204,
420,
9451,
63,
6852,
28643,
19,
25154,
2924,
199,
199,
3,
12175,
282,
2112,
402,
3086,
14593,
436,
1640,
82,
524,
83,
4568,
543,
199,
3,
282,
18340,
63,
15361,
880,
15493,
199,
318,
870,
63,
9391,
8,
17428,
304,
199,
198,
2384,
63,
17428,
275,
378,
199,
198,
7277,
63,
513,
275,
19988,
459,
7277,
63,
513,
418,
199,
198,
3541,
275,
10476,
63,
513,
59,
16,
2733,
3541,
418,
199,
198,
1095,
63,
84,
275,
10476,
63,
513,
59,
16,
2733,
7277,
63,
484,
63,
84,
418,
199,
198,
3,
1104,
340,
642,
19988,
1077,
506,
2498,
379,
199,
198,
692,
4866,
1137,
378,
26,
507,
198,
509,
284,
315,
1425,
8,
552,
8,
7277,
63,
513,
2298,
686,
198,
692,
10476,
63,
513,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
sadanandb/pmt
|
src/context/client/create_set_asset.py
|
6
|
2651
|
###########################################################
#
# Copyright (c) 2005, Southpaw Technology
# All Rights Reserved
#
# PROPRIETARY INFORMATION. This software is proprietary to
# Southpaw Technology, and is not to be reproduced, transmitted,
# or disclosed in any way without written permission.
#
#
#
import re, sys, cStringIO, xmlrpclib
from common import *
import checkin, load
def create(set_name, cat_name, context):
'''update a node in the session'''
info = TacticInfo.get()
ticket = info.get_ticket()
server = info.get_xmlrpc_server()
app = info.get_app()
# get all of the top level assets
selected = app.mel("ls -sl -as")
if not selected:
raise TacticException('At least 1 asset (top node) needs to be selected in the session!')
xml, asset_code = server.create_set(ticket, set_name, cat_name, selected)
builder = info.get_builder()
builder.execute(xml)
if asset_code:
# checkin_set and upload the files
checkin.checkin_set(set_name, asset_code)
# publish the set
snapshot_code = server.checkin_set(ticket, asset_code, context)
# update tacticNodeInfo
#context = "publish"
load.update(snapshot_code, asset_code, set_name, context)
'''
#OLD CODE
class CreateSetAsset:
def __init__(my, set_code):
my.set_code = set_code
my.info = TacticInfo.get()
my.ticket = my.info.get_ticket()
def execute(my):
# get all of the top level assets
selected = mel("ls -sl -as")
for instance in selected:
print instance
# export the node
mel("select %s" % instance)
path = mel("file -rename %s" % instance )
mel("file -f -es -type mayaAscii")
# for some reason file -rename always returns .mb extension?!?
p = re.compile(r'\.mb$')
path = p.sub('.ma', path)
my.upload(path)
mel("select %s" % " ".join(selected) )
# now create all of the assets through xmlrpc
server = my.info.get_xmlrpc_server()
asset_codes = server.create_assets(my.ticket, my.set_code, selected)
# rename nodes
count = 0
for instance in selected:
mel("rename %s %s" % (instance, asset_codes[count]) )
count += 1
def upload(my, from_path):
my.info.upload(from_path)
if __name__ == '__main__':
executable = sys.argv[0]
args = sys.argv[1:]
set_code = args[0]
cmd = CreateSetAsset(set_code)
cmd.execute()
'''
|
epl-1.0
|
[
26207,
5680,
199,
3,
199,
3,
1898,
334,
67,
9,
11811,
12,
23150,
387,
87,
21580,
199,
3,
9326,
2900,
5924,
5702,
199,
3,
199,
3,
3611,
20076,
775,
4392,
1621,
18623,
14,
221,
961,
2032,
365,
557,
1359,
386,
695,
370,
199,
3,
23150,
387,
87,
21580,
12,
436,
365,
440,
370,
506,
9172,
68,
12,
29818,
12,
199,
3,
503,
4339,
320,
939,
315,
1263,
4340,
1928,
5313,
4983,
14,
199,
3,
199,
3,
199,
3,
199,
199,
646,
295,
12,
984,
12,
15073,
12,
19122,
199,
199,
504,
2863,
492,
627,
199,
646,
1104,
262,
12,
2248,
421,
199,
318,
1218,
8,
409,
63,
354,
12,
6230,
63,
354,
12,
1067,
304,
272,
1449,
873,
282,
1031,
315,
314,
2351,
2344,
272,
2256,
275,
377,
27296,
2354,
14,
362,
342,
272,
12052,
275,
2256,
14,
362,
63,
9201,
342,
272,
1654,
275,
2256,
14,
362,
63,
17596,
63,
1000,
342,
272,
272,
1145,
275,
2256,
14,
362,
63,
571,
342,
272,
327,
664,
1006,
402,
314,
2746,
2166,
17202,
272,
4895,
275,
1145,
14,
26908,
480,
478,
446,
2482,
446,
305,
531,
272,
272,
340,
440,
4895,
26,
267,
746,
377,
27296,
1726,
360,
1271,
5210,
413,
8977,
334,
2119,
1031,
9,
4839,
370,
506,
4895,
315,
314,
2351,
10916,
272,
2748,
12,
8977,
63,
600,
275,
1654,
14,
981,
63,
409,
8,
9201,
12,
663,
63,
354,
12,
6230,
63,
354,
12,
4895,
9,
272,
6545,
275,
2256,
14,
362,
63,
5649,
342,
272,
6545,
14,
2526,
8,
1652,
9,
339,
340,
8977,
63,
600,
26,
267,
327,
1104,
262,
63,
409,
436,
5802,
314,
1584,
4960,
1104,
262,
14,
1074,
262,
63,
409,
8,
409,
63,
354,
12,
8977,
63,
600,
9,
2728,
327,
2780,
314,
663,
267,
5740,
63,
600,
275,
1654,
14,
1074,
262,
63,
409,
8,
9201,
12,
8977,
63,
600,
12,
1067,
9,
398,
327,
1678,
307,
27296,
1716,
2354,
267,
327,
1100,
275,
298,
4763,
2,
267,
2248,
14,
873,
8,
4753,
63,
600,
12,
8977,
63,
600,
12,
663,
63,
354,
12,
1067,
9,
221,
26339,
199,
2344,
199,
3,
5104,
22547,
259,
199,
533,
2790,
1084,
19979,
26,
339,
347,
636,
826,
721,
1662,
12,
663,
63,
600,
304,
267,
3002,
14,
409,
63,
600,
275,
663,
63,
600,
267,
3002,
14,
815,
275,
377,
27296,
2354,
14,
362,
342,
267,
3002,
14,
9201,
275,
3002,
14,
815,
14,
362,
63,
9201,
342,
5493,
347,
5341,
8,
1662,
304,
398,
327,
664,
1006,
402,
314,
2746,
2166,
17202,
267,
4895,
275,
562,
76,
480,
478,
446,
2482,
446,
305,
531,
398,
367,
1256,
315,
4895,
26,
288,
870,
1256,
953,
327,
4843,
314,
1031,
288,
562,
76,
480,
2416,
450,
83,
2,
450,
1256,
9,
288,
931,
275,
562,
76,
480,
493,
446,
8165,
450,
83,
2,
450,
1256,
776,
288,
562,
76,
480,
493,
446,
70,
446,
397,
446,
466,
1443,
65,
11129,
531,
953,
327,
367,
2005,
4499,
570,
446,
8165,
3544,
2529,
1275,
887,
3329,
31,
1,
31,
288,
299,
275,
295,
14,
2014,
8,
82,
1154,
14,
887,
9988,
288,
931,
275,
299,
14,
954,
5175,
391,
297,
931,
9,
953,
3002,
14,
5064,
8,
515,
9,
2728,
562,
76,
480,
2416,
450,
83,
2,
450,
298,
3680,
904,
8,
5511,
9,
776,
398,
327,
3063,
1218,
1006,
402,
314,
17202,
4012,
15432,
267,
1654,
275,
3002,
14,
815,
14,
362,
63,
17596,
63,
1000,
342,
267,
8977,
63,
6021,
275,
1654,
14,
981,
63,
12186,
8,
1662,
14,
9201,
12,
3002,
14,
409,
63,
600,
12,
4895,
9,
398,
327,
11441,
3380,
267,
2338,
275,
378,
267,
367,
1256,
315,
4895,
26,
288,
562,
76,
480,
8165,
450,
83,
450,
83,
2,
450,
334,
842,
12,
8977,
63,
6021,
59,
835,
566,
776,
288,
2338,
847,
413,
2378,
347,
5802,
8,
1662,
12,
687,
63,
515,
304,
267,
3002,
14,
815,
14,
5064,
8,
504,
63,
515,
9,
4388,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
7286,
275,
984,
14,
3020,
59,
16,
61,
272,
1249,
275,
984,
14,
3020,
59,
17,
2938,
339,
663,
63,
600,
275,
1249,
59,
16,
61,
339,
2088,
275,
2790,
1084,
19979,
8,
409,
63,
600,
9,
272,
2088,
14,
2526,
342,
199,
199,
2344,
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
] |
[
5680,
199,
3,
199,
3,
1898,
334,
67,
9,
11811,
12,
23150,
387,
87,
21580,
199,
3,
9326,
2900,
5924,
5702,
199,
3,
199,
3,
3611,
20076,
775,
4392,
1621,
18623,
14,
221,
961,
2032,
365,
557,
1359,
386,
695,
370,
199,
3,
23150,
387,
87,
21580,
12,
436,
365,
440,
370,
506,
9172,
68,
12,
29818,
12,
199,
3,
503,
4339,
320,
939,
315,
1263,
4340,
1928,
5313,
4983,
14,
199,
3,
199,
3,
199,
3,
199,
199,
646,
295,
12,
984,
12,
15073,
12,
19122,
199,
199,
504,
2863,
492,
627,
199,
646,
1104,
262,
12,
2248,
421,
199,
318,
1218,
8,
409,
63,
354,
12,
6230,
63,
354,
12,
1067,
304,
272,
1449,
873,
282,
1031,
315,
314,
2351,
2344,
272,
2256,
275,
377,
27296,
2354,
14,
362,
342,
272,
12052,
275,
2256,
14,
362,
63,
9201,
342,
272,
1654,
275,
2256,
14,
362,
63,
17596,
63,
1000,
342,
272,
272,
1145,
275,
2256,
14,
362,
63,
571,
342,
272,
327,
664,
1006,
402,
314,
2746,
2166,
17202,
272,
4895,
275,
1145,
14,
26908,
480,
478,
446,
2482,
446,
305,
531,
272,
272,
340,
440,
4895,
26,
267,
746,
377,
27296,
1726,
360,
1271,
5210,
413,
8977,
334,
2119,
1031,
9,
4839,
370,
506,
4895,
315,
314,
2351,
10916,
272,
2748,
12,
8977,
63,
600,
275,
1654,
14,
981,
63,
409,
8,
9201,
12,
663,
63,
354,
12,
6230,
63,
354,
12,
4895,
9,
272,
6545,
275,
2256,
14,
362,
63,
5649,
342,
272,
6545,
14,
2526,
8,
1652,
9,
339,
340,
8977,
63,
600,
26,
267,
327,
1104,
262,
63,
409,
436,
5802,
314,
1584,
4960,
1104,
262,
14,
1074,
262,
63,
409,
8,
409,
63,
354,
12,
8977,
63,
600,
9,
2728,
327,
2780,
314,
663,
267,
5740,
63,
600,
275,
1654,
14,
1074,
262,
63,
409,
8,
9201,
12,
8977,
63,
600,
12,
1067,
9,
398,
327,
1678,
307,
27296,
1716,
2354,
267,
327,
1100,
275,
298,
4763,
2,
267,
2248,
14,
873,
8,
4753,
63,
600,
12,
8977,
63,
600,
12,
663,
63,
354,
12,
1067,
9,
221,
26339,
199,
2344,
199,
3,
5104,
22547,
259,
199,
533,
2790,
1084,
19979,
26,
339,
347,
636,
826,
721,
1662,
12,
663,
63,
600,
304,
267,
3002,
14,
409,
63,
600,
275,
663,
63,
600,
267,
3002,
14,
815,
275,
377,
27296,
2354,
14,
362,
342,
267,
3002,
14,
9201,
275,
3002,
14,
815,
14,
362,
63,
9201,
342,
5493,
347,
5341,
8,
1662,
304,
398,
327,
664,
1006,
402,
314,
2746,
2166,
17202,
267,
4895,
275,
562,
76,
480,
478,
446,
2482,
446,
305,
531,
398,
367,
1256,
315,
4895,
26,
288,
870,
1256,
953,
327,
4843,
314,
1031,
288,
562,
76,
480,
2416,
450,
83,
2,
450,
1256,
9,
288,
931,
275,
562,
76,
480,
493,
446,
8165,
450,
83,
2,
450,
1256,
776,
288,
562,
76,
480,
493,
446,
70,
446,
397,
446,
466,
1443,
65,
11129,
531,
953,
327,
367,
2005,
4499,
570,
446,
8165,
3544,
2529,
1275,
887,
3329,
31,
1,
31,
288,
299,
275,
295,
14,
2014,
8,
82,
1154,
14,
887,
9988,
288,
931,
275,
299,
14,
954,
5175,
391,
297,
931,
9,
953,
3002,
14,
5064,
8,
515,
9,
2728,
562,
76,
480,
2416,
450,
83,
2,
450,
298,
3680,
904,
8,
5511,
9,
776,
398,
327,
3063,
1218,
1006,
402,
314,
17202,
4012,
15432,
267,
1654,
275,
3002,
14,
815,
14,
362,
63,
17596,
63,
1000,
342,
267,
8977,
63,
6021,
275,
1654,
14,
981,
63,
12186,
8,
1662,
14,
9201,
12,
3002,
14,
409,
63,
600,
12,
4895,
9,
398,
327,
11441,
3380,
267,
2338,
275,
378,
267,
367,
1256,
315,
4895,
26,
288,
562,
76,
480,
8165,
450,
83,
450,
83,
2,
450,
334,
842,
12,
8977,
63,
6021,
59,
835,
566,
776,
288,
2338,
847,
413,
2378,
347,
5802,
8,
1662,
12,
687,
63,
515,
304,
267,
3002,
14,
815,
14,
5064,
8,
504,
63,
515,
9,
4388,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
7286,
275,
984,
14,
3020,
59,
16,
61,
272,
1249,
275,
984,
14,
3020,
59,
17,
2938,
339,
663,
63,
600,
275,
1249,
59,
16,
61,
339,
2088,
275,
2790,
1084,
19979,
8,
409,
63,
600,
9,
272,
2088,
14,
2526,
342,
199,
199,
2344,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
chirilo/phantomjs
|
src/qt/qtwebkit/Source/ThirdParty/gtest/scripts/gen_gtest_pred_impl.py
|
294
|
21993
|
#!/usr/bin/env python
#
# 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.
"""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_
// Makes sure this header is not included before gtest.h.
#ifndef GTEST_INCLUDE_GTEST_GTEST_H_
#error Do not include gtest_pred_impl.h directly. Include gtest.h instead.
#endif // GTEST_INCLUDE_GTEST_GTEST_H_
// 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();
Message msg;
""" % DEFS
impl += ' msg << pred_text << "("'
impl += Iter(n, """
<< e%s""", sep=' << ", "')
impl += ' << ") evaluates to false, where"'
impl += Iter(n, """
<< "\\n" << e%s << " evaluates to " << v%s""")
impl += """;
return AssertionFailure(msg);
}
// 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 """
#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();
testing::Message msg;
msg << """ % DEFS
tests += Iter(n, 'e%s', sep=' << " + " << ')
tests += """
<< " is expected to be positive, but evaluates to "
<< %(v_sum)s << ".";
return testing::AssertionFailure(msg);
}
""" % 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()
|
bsd-3-clause
|
[
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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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
] |
Tesla-Redux/android_external_skia
|
tools/skpdiff/generate_pmetric_tables.py
|
179
|
4156
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
from __future__ import print_function
from math import *
COPYRIGHT = '''/*
* Copyright 2013 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/'''
HELP = '// To regenerate SkPMetricUtil_generated.h, simply run ./generate_pmetric_tables.py'
# From Barten SPIE 1989
def contrast_sensitivity(cycles_per_degree, luminance):
a = 440.0 * pow(1.0 + 0.7 / luminance, -0.2)
b = 0.3 * pow(1 + 100.0 / luminance, 0.15)
return a * cycles_per_degree * exp(-b * cycles_per_degree) * sqrt(1.0 + 0.06 * exp(b * cycles_per_degree))
# From Ward Larson Siggraph 1997
def threshold_vs_intensity(adaptation_luminance):
log_lum = float('-inf') # Works in Python 2.6+
try:
log_lum = log10(adaptation_luminance)
except ValueError:
pass
x = 0.0
if log_lum < -3.94:
x = -2.86
elif log_lum < -1.44:
x = pow(0.405 * log_lum + 1.6, 2.18) - 2.86
elif log_lum < -0.0184:
x = log_lum - 0.395
elif log_lum < 1.9:
x = pow(0.249 * log_lum + 0.65, 2.7) - 0.72
else:
x = log_lum - 1.255
return pow(10.0, x)
# From Daly 1993
def visual_mask(contrast):
x = pow(392.498 * contrast, 0.7)
x = pow(0.0153 * x, 4.0)
return pow(1.0 + x, 0.25)
# float gCubeRootTable[]
CUBE_ROOT_ACCESS_FUNCTION = '''
static float get_cube_root(float value) {
SkASSERT(value >= 0.0f);
SkASSERT(value * 1023.0f < 1024.0f);
return gCubeRootTable[(int)(value * 1023.0f)];
}
'''
def generate_cube_root_table(stream):
print('static float gCubeRootTable[] = {', end='', file=stream)
for i in range(1024):
if i % 6 == 0:
print('\n ', end='', file=stream)
print("%.10f" % pow(i / 1024.0, 1.0 / 3.0), end='f,', file=stream)
print('\n};', end='', file=stream)
print(CUBE_ROOT_ACCESS_FUNCTION, file=stream)
# float gGammaTable[]
GAMMA_ACCESS_FUNCTION = '''
static float get_gamma(unsigned char value) {
return gGammaTable[value];
}
'''
def generate_gamma_table(stream):
print('static float gGammaTable[] = {', end='', file=stream)
for i in range(256):
if i % 6 == 0:
print('\n ', end='', file=stream)
print("%.10f" % pow(i / 255.0, 2.2), end='f,', file=stream)
print('\n};', end='', file=stream)
print(GAMMA_ACCESS_FUNCTION, file=stream)
# float gTVITable[]
TVI_ACCESS_FUNCTION = '''
static float get_threshold_vs_intensity(float value) {
SkASSERT(value >= 0.0f);
SkASSERT(value < 100.0f);
return gTVITable[(int)(value * 100.0f)];
}
'''
def generate_tvi_table(stream):
print('static float gTVITable[] = {', end='', file=stream)
for i in range(10000):
if i % 6 == 0:
print('\n ', end='', file=stream)
print("%.10f" % threshold_vs_intensity(i / 100.0), end='f,', file=stream)
print('\n};', end='', file=stream)
print(TVI_ACCESS_FUNCTION, file=stream)
# float gVisualMaskTable[]
VISUAL_MASK_DOMAIN = 4000
VISUAL_MASK_ACCESS_FUNCTION = '''
static float get_visual_mask(float value) {{
SkASSERT(value >= 0.0f);
SkASSERT(value < {}.0f);
return gVisualMaskTable[(int)value];
}}'''
def generate_visual_mask_table(stream):
print('static float gVisualMaskTable[] = {', end='', file=stream)
for i in range(VISUAL_MASK_DOMAIN):
if i % 6 == 0:
print('\n ', end='', file=stream)
print("%.10f" % visual_mask(i), end='f,', file=stream)
print('\n};', end='', file=stream)
print(VISUAL_MASK_ACCESS_FUNCTION.format(VISUAL_MASK_DOMAIN), file=stream)
def generate_lookup_tables(stream):
print(COPYRIGHT, file=stream)
print(HELP, file=stream)
print('namespace SkPMetricUtil {', file=stream)
generate_cube_root_table(stream)
generate_gamma_table(stream)
generate_tvi_table(stream)
generate_visual_mask_table(stream)
print('}', file=stream)
def main():
pmetric_util_out = open('SkPMetricUtil_generated.h', 'wb')
generate_lookup_tables(pmetric_util_out)
pmetric_util_out.close()
if __name__ == '__main__':
main()
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
504,
3473,
492,
627,
421,
199,
32324,
5716,
275,
1449,
6331,
199,
627,
1898,
6171,
4475,
3277,
14,
199,
627,
199,
627,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
627,
1911,
315,
314,
5113,
570,
14,
199,
11589,
2344,
421,
199,
17930,
275,
18290,
4005,
30943,
29201,
48,
11119,
9562,
63,
10176,
14,
72,
12,
9329,
1255,
16605,
4208,
63,
80,
5165,
63,
5987,
14,
647,
7,
421,
199,
3,
11606,
12377,
724,
428,
2252,
37,
5851,
1407,
199,
318,
30347,
63,
2464,
20635,
8,
23356,
63,
529,
63,
10956,
12,
634,
453,
262,
554,
304,
272,
282,
275,
841,
2167,
14,
16,
627,
13131,
8,
17,
14,
16,
435,
378,
14,
23,
1182,
634,
453,
262,
554,
12,
446,
16,
14,
18,
9,
272,
330,
275,
378,
14,
19,
627,
13131,
8,
17,
435,
2948,
14,
16,
1182,
634,
453,
262,
554,
12,
378,
14,
1046,
9,
272,
372,
282,
627,
19001,
63,
529,
63,
10956,
627,
1437,
2801,
66,
627,
19001,
63,
529,
63,
10956,
9,
627,
7452,
8,
17,
14,
16,
435,
378,
14,
1690,
627,
1437,
8,
66,
627,
19001,
63,
529,
63,
10956,
430,
421,
199,
3,
11606,
644,
1005,
491,
285,
834,
14625,
2180,
9013,
23,
199,
318,
8765,
63,
3122,
63,
27203,
8,
19609,
425,
63,
25065,
262,
554,
304,
272,
943,
63,
25065,
275,
2069,
3654,
4904,
358,
327,
28099,
315,
2018,
499,
14,
22,
11,
272,
862,
26,
267,
943,
63,
25065,
275,
943,
709,
8,
19609,
425,
63,
25065,
262,
554,
9,
272,
871,
1722,
26,
267,
986,
339,
671,
275,
378,
14,
16,
339,
340,
943,
63,
25065,
665,
446,
19,
14,
2635,
26,
267,
671,
275,
446,
18,
14,
1184,
339,
916,
943,
63,
25065,
665,
446,
17,
14,
1602,
26,
267,
671,
275,
13131,
8,
16,
14,
15770,
627,
943,
63,
25065,
435,
413,
14,
22,
12,
499,
14,
1085,
9,
446,
499,
14,
1184,
339,
916,
943,
63,
25065,
665,
446,
16,
14,
614,
1349,
26,
267,
671,
275,
943,
63,
25065,
446,
378,
14,
14099,
339,
916,
943,
63,
25065,
665,
413,
14,
25,
26,
267,
671,
275,
13131,
8,
16,
14,
11032,
627,
943,
63,
25065,
435,
378,
14,
2182,
12,
499,
14,
23,
9,
446,
378,
14,
2819,
339,
587,
26,
267,
671,
275,
943,
63,
25065,
446,
413,
14,
2299,
339,
372,
13131,
8,
709,
14,
16,
12,
671,
9,
421,
199,
3,
11606,
577,
2618,
9013,
19,
199,
318,
13104,
63,
2629,
8,
17926,
270,
304,
272,
671,
275,
13131,
8,
14042,
14,
20537,
627,
30347,
12,
378,
14,
23,
9,
272,
671,
275,
13131,
8,
16,
14,
614,
2481,
627,
671,
12,
841,
14,
16,
9,
272,
372,
13131,
8,
17,
14,
16,
435,
671,
12,
378,
14,
821,
9,
421,
199,
3,
2069,
486,
25043,
6405,
3186,
8607,
199,
35,
21857,
63,
5441,
63,
11074,
63,
15476,
275,
1449,
199,
1986,
2069,
664,
63,
11477,
63,
1231,
8,
1609,
574,
9,
469,
272,
29201,
24790,
8,
585,
2356,
378,
14,
16,
70,
2736,
272,
29201,
24790,
8,
585,
627,
12996,
19,
14,
16,
70,
665,
6619,
14,
16,
70,
2736,
272,
372,
486,
25043,
6405,
3186,
7528,
442,
5130,
585,
627,
12996,
19,
14,
16,
70,
1874,
27,
199,
93,
199,
2344,
199,
318,
3550,
63,
11477,
63,
1231,
63,
1224,
8,
1745,
304,
272,
870,
360,
1986,
2069,
486,
25043,
6405,
3186,
8607,
275,
469,
297,
1284,
4581,
570,
29,
1745,
9,
272,
367,
284,
315,
1425,
8,
7727,
304,
267,
340,
284,
450,
1227,
508,
378,
26,
288,
870,
2258,
78,
259,
1656,
1284,
4581,
570,
29,
1745,
9,
267,
870,
3647,
14,
709,
70,
2,
450,
13131,
8,
73,
1182,
6619,
14,
16,
12,
413,
14,
16,
1182,
650,
14,
16,
395,
1284,
534,
70,
12,
297,
570,
29,
1745,
9,
272,
870,
2258,
78,
93,
10805,
1284,
4581,
570,
29,
1745,
9,
272,
870,
8,
35,
21857,
63,
5441,
63,
11074,
63,
15476,
12,
570,
29,
1745,
9,
421,
199,
3,
2069,
486,
15091,
3186,
8607,
199,
39,
1156,
2054,
63,
11074,
63,
15476,
275,
1449,
199,
1986,
2069,
664,
63,
7325,
8,
2244,
1495,
574,
9,
469,
272,
372,
486,
15091,
3186,
59,
585,
11566,
199,
93,
199,
2344,
199,
318,
3550,
63,
7325,
63,
1224,
8,
1745,
304,
272,
870,
360,
1986,
2069,
486,
15091,
3186,
8607,
275,
469,
297,
1284,
4581,
570,
29,
1745,
9,
272,
367,
284,
315,
1425,
8,
3912,
304,
267,
340,
284,
450,
1227,
508,
378,
26,
288,
870,
2258,
78,
259,
1656,
1284,
4581,
570,
29,
1745,
9,
267,
870,
3647,
14,
709,
70,
2,
450,
13131,
8,
73,
1182,
5450,
14,
16,
12,
499,
14,
18,
395,
1284,
534,
70,
12,
297,
570,
29,
1745,
9,
272,
870,
2258,
78,
93,
10805,
1284,
4581,
570,
29,
1745,
9,
272,
870,
8,
39,
1156,
2054,
63,
11074,
63,
15476,
12,
570,
29,
1745,
9,
421,
199,
3,
2069,
486,
12764,
649,
461,
8607,
199,
12764,
41,
63,
11074,
63,
15476,
275,
1449,
199,
1986,
2069,
664,
63,
7227,
63,
3122,
63,
27203,
8,
1609,
574,
9,
469,
272,
29201,
24790,
8,
585,
2356,
378,
14,
16,
70,
2736,
272,
29201,
24790,
8,
585,
665,
2948,
14,
16,
70,
2736,
272,
372,
486,
12764,
649,
461,
7528,
442,
5130,
585,
627,
2948,
14,
16,
70,
1874,
27,
199,
93,
199,
2344,
199,
318,
3550,
63,
84,
433,
63,
1224,
8,
1745,
304,
272,
870,
360,
1986,
2069,
486,
12764,
649,
461,
8607,
275,
469,
297,
1284,
4581,
570,
29,
1745,
9,
272,
367,
284,
315,
1425,
8,
9943,
304,
267,
340,
284,
450,
1227,
508,
378,
26,
288,
870,
2258,
78,
259,
1656,
1284,
4581,
570,
29,
1745,
9,
267,
870,
3647,
14,
709,
70,
2,
450,
8765,
63,
3122,
63,
27203,
8,
73,
1182,
2948,
14,
16,
395,
1284,
534,
70,
12,
297,
570,
29,
1745,
9,
272,
870,
2258,
78,
93,
10805,
1284,
4581
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
504,
3473,
492,
627,
421,
199,
32324,
5716,
275,
1449,
6331,
199,
627,
1898,
6171,
4475,
3277,
14,
199,
627,
199,
627,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
627,
1911,
315,
314,
5113,
570,
14,
199,
11589,
2344,
421,
199,
17930,
275,
18290,
4005,
30943,
29201,
48,
11119,
9562,
63,
10176,
14,
72,
12,
9329,
1255,
16605,
4208,
63,
80,
5165,
63,
5987,
14,
647,
7,
421,
199,
3,
11606,
12377,
724,
428,
2252,
37,
5851,
1407,
199,
318,
30347,
63,
2464,
20635,
8,
23356,
63,
529,
63,
10956,
12,
634,
453,
262,
554,
304,
272,
282,
275,
841,
2167,
14,
16,
627,
13131,
8,
17,
14,
16,
435,
378,
14,
23,
1182,
634,
453,
262,
554,
12,
446,
16,
14,
18,
9,
272,
330,
275,
378,
14,
19,
627,
13131,
8,
17,
435,
2948,
14,
16,
1182,
634,
453,
262,
554,
12,
378,
14,
1046,
9,
272,
372,
282,
627,
19001,
63,
529,
63,
10956,
627,
1437,
2801,
66,
627,
19001,
63,
529,
63,
10956,
9,
627,
7452,
8,
17,
14,
16,
435,
378,
14,
1690,
627,
1437,
8,
66,
627,
19001,
63,
529,
63,
10956,
430,
421,
199,
3,
11606,
644,
1005,
491,
285,
834,
14625,
2180,
9013,
23,
199,
318,
8765,
63,
3122,
63,
27203,
8,
19609,
425,
63,
25065,
262,
554,
304,
272,
943,
63,
25065,
275,
2069,
3654,
4904,
358,
327,
28099,
315,
2018,
499,
14,
22,
11,
272,
862,
26,
267,
943,
63,
25065,
275,
943,
709,
8,
19609,
425,
63,
25065,
262,
554,
9,
272,
871,
1722,
26,
267,
986,
339,
671,
275,
378,
14,
16,
339,
340,
943,
63,
25065,
665,
446,
19,
14,
2635,
26,
267,
671,
275,
446,
18,
14,
1184,
339,
916,
943,
63,
25065,
665,
446,
17,
14,
1602,
26,
267,
671,
275,
13131,
8,
16,
14,
15770,
627,
943,
63,
25065,
435,
413,
14,
22,
12,
499,
14,
1085,
9,
446,
499,
14,
1184,
339,
916,
943,
63,
25065,
665,
446,
16,
14,
614,
1349,
26,
267,
671,
275,
943,
63,
25065,
446,
378,
14,
14099,
339,
916,
943,
63,
25065,
665,
413,
14,
25,
26,
267,
671,
275,
13131,
8,
16,
14,
11032,
627,
943,
63,
25065,
435,
378,
14,
2182,
12,
499,
14,
23,
9,
446,
378,
14,
2819,
339,
587,
26,
267,
671,
275,
943,
63,
25065,
446,
413,
14,
2299,
339,
372,
13131,
8,
709,
14,
16,
12,
671,
9,
421,
199,
3,
11606,
577,
2618,
9013,
19,
199,
318,
13104,
63,
2629,
8,
17926,
270,
304,
272,
671,
275,
13131,
8,
14042,
14,
20537,
627,
30347,
12,
378,
14,
23,
9,
272,
671,
275,
13131,
8,
16,
14,
614,
2481,
627,
671,
12,
841,
14,
16,
9,
272,
372,
13131,
8,
17,
14,
16,
435,
671,
12,
378,
14,
821,
9,
421,
199,
3,
2069,
486,
25043,
6405,
3186,
8607,
199,
35,
21857,
63,
5441,
63,
11074,
63,
15476,
275,
1449,
199,
1986,
2069,
664,
63,
11477,
63,
1231,
8,
1609,
574,
9,
469,
272,
29201,
24790,
8,
585,
2356,
378,
14,
16,
70,
2736,
272,
29201,
24790,
8,
585,
627,
12996,
19,
14,
16,
70,
665,
6619,
14,
16,
70,
2736,
272,
372,
486,
25043,
6405,
3186,
7528,
442,
5130,
585,
627,
12996,
19,
14,
16,
70,
1874,
27,
199,
93,
199,
2344,
199,
318,
3550,
63,
11477,
63,
1231,
63,
1224,
8,
1745,
304,
272,
870,
360,
1986,
2069,
486,
25043,
6405,
3186,
8607,
275,
469,
297,
1284,
4581,
570,
29,
1745,
9,
272,
367,
284,
315,
1425,
8,
7727,
304,
267,
340,
284,
450,
1227,
508,
378,
26,
288,
870,
2258,
78,
259,
1656,
1284,
4581,
570,
29,
1745,
9,
267,
870,
3647,
14,
709,
70,
2,
450,
13131,
8,
73,
1182,
6619,
14,
16,
12,
413,
14,
16,
1182,
650,
14,
16,
395,
1284,
534,
70,
12,
297,
570,
29,
1745,
9,
272,
870,
2258,
78,
93,
10805,
1284,
4581,
570,
29,
1745,
9,
272,
870,
8,
35,
21857,
63,
5441,
63,
11074,
63,
15476,
12,
570,
29,
1745,
9,
421,
199,
3,
2069,
486,
15091,
3186,
8607,
199,
39,
1156,
2054,
63,
11074,
63,
15476,
275,
1449,
199,
1986,
2069,
664,
63,
7325,
8,
2244,
1495,
574,
9,
469,
272,
372,
486,
15091,
3186,
59,
585,
11566,
199,
93,
199,
2344,
199,
318,
3550,
63,
7325,
63,
1224,
8,
1745,
304,
272,
870,
360,
1986,
2069,
486,
15091,
3186,
8607,
275,
469,
297,
1284,
4581,
570,
29,
1745,
9,
272,
367,
284,
315,
1425,
8,
3912,
304,
267,
340,
284,
450,
1227,
508,
378,
26,
288,
870,
2258,
78,
259,
1656,
1284,
4581,
570,
29,
1745,
9,
267,
870,
3647,
14,
709,
70,
2,
450,
13131,
8,
73,
1182,
5450,
14,
16,
12,
499,
14,
18,
395,
1284,
534,
70,
12,
297,
570,
29,
1745,
9,
272,
870,
2258,
78,
93,
10805,
1284,
4581,
570,
29,
1745,
9,
272,
870,
8,
39,
1156,
2054,
63,
11074,
63,
15476,
12,
570,
29,
1745,
9,
421,
199,
3,
2069,
486,
12764,
649,
461,
8607,
199,
12764,
41,
63,
11074,
63,
15476,
275,
1449,
199,
1986,
2069,
664,
63,
7227,
63,
3122,
63,
27203,
8,
1609,
574,
9,
469,
272,
29201,
24790,
8,
585,
2356,
378,
14,
16,
70,
2736,
272,
29201,
24790,
8,
585,
665,
2948,
14,
16,
70,
2736,
272,
372,
486,
12764,
649,
461,
7528,
442,
5130,
585,
627,
2948,
14,
16,
70,
1874,
27,
199,
93,
199,
2344,
199,
318,
3550,
63,
84,
433,
63,
1224,
8,
1745,
304,
272,
870,
360,
1986,
2069,
486,
12764,
649,
461,
8607,
275,
469,
297,
1284,
4581,
570,
29,
1745,
9,
272,
367,
284,
315,
1425,
8,
9943,
304,
267,
340,
284,
450,
1227,
508,
378,
26,
288,
870,
2258,
78,
259,
1656,
1284,
4581,
570,
29,
1745,
9,
267,
870,
3647,
14,
709,
70,
2,
450,
8765,
63,
3122,
63,
27203,
8,
73,
1182,
2948,
14,
16,
395,
1284,
534,
70,
12,
297,
570,
29,
1745,
9,
272,
870,
2258,
78,
93,
10805,
1284,
4581,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
vmindru/ansible
|
lib/ansible/modules/cloud/vmware/vmware_host_package_facts.py
|
47
|
4254
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright: (c) 2018, Abhijeet Kasurde <akasurde@redhat.com>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
ANSIBLE_METADATA = {
'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'community'
}
DOCUMENTATION = r'''
---
module: vmware_host_package_facts
short_description: Gathers facts about available packages on an ESXi host
description:
- This module can be used to gather facts about available packages and their status on an ESXi host.
version_added: '2.5'
author:
- Abhijeet Kasurde (@Akasurde)
notes:
- Tested on vSphere 6.5
requirements:
- python >= 2.6
- PyVmomi
options:
cluster_name:
description:
- Name of the cluster.
- Package facts about each ESXi server will be returned for given cluster.
- If C(esxi_hostname) is not given, this parameter is required.
esxi_hostname:
description:
- ESXi hostname.
- Package facts about this ESXi server will be returned.
- If C(cluster_name) is not given, this parameter is required.
extends_documentation_fragment: vmware.documentation
'''
EXAMPLES = r'''
- name: Gather facts about all ESXi Host in given Cluster
vmware_host_package_facts:
hostname: '{{ vcenter_hostname }}'
username: '{{ vcenter_username }}'
password: '{{ vcenter_password }}'
cluster_name: cluster_name
delegate_to: localhost
register: cluster_host_packages
- name: Gather facts about ESXi Host
vmware_host_package_facts:
hostname: '{{ vcenter_hostname }}'
username: '{{ vcenter_username }}'
password: '{{ vcenter_password }}'
esxi_hostname: '{{ esxi_hostname }}'
delegate_to: localhost
register: host_packages
'''
RETURN = r'''
hosts_package_facts:
description:
- dict with hostname as key and dict with package facts as value
returned: hosts_package_facts
type: dict
sample: { "hosts_package_facts": { "localhost.localdomain": []}}
'''
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.vmware import vmware_argument_spec, PyVmomi
class VmwarePackageManager(PyVmomi):
def __init__(self, module):
super(VmwarePackageManager, self).__init__(module)
cluster_name = self.params.get('cluster_name', None)
esxi_host_name = self.params.get('esxi_hostname', None)
self.hosts = self.get_all_host_objs(cluster_name=cluster_name, esxi_host_name=esxi_host_name)
def gather_package_facts(self):
hosts_facts = {}
for host in self.hosts:
host_package_facts = []
host_pkg_mgr = host.configManager.imageConfigManager
if host_pkg_mgr:
pkgs = host_pkg_mgr.FetchSoftwarePackages()
for pkg in pkgs:
host_package_facts.append(dict(name=pkg.name,
version=pkg.version,
vendor=pkg.vendor,
summary=pkg.summary,
description=pkg.description,
acceptance_level=pkg.acceptanceLevel,
maintenance_mode_required=pkg.maintenanceModeRequired,
creation_date=pkg.creationDate,
)
)
hosts_facts[host.name] = host_package_facts
return hosts_facts
def main():
argument_spec = vmware_argument_spec()
argument_spec.update(
cluster_name=dict(type='str', required=False),
esxi_hostname=dict(type='str', required=False),
)
module = AnsibleModule(
argument_spec=argument_spec,
required_one_of=[
['cluster_name', 'esxi_hostname'],
]
)
vmware_host_package_config = VmwarePackageManager(module)
module.exit_json(changed=False, hosts_package_facts=vmware_host_package_config.gather_package_facts())
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,
1898,
26,
334,
67,
9,
14894,
12,
8351,
5812,
6532,
386,
1804,
305,
300,
271,
665,
1151,
305,
300,
271,
32,
17164,
14,
957,
30,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
363,
6577,
363,
275,
730,
199,
199,
8490,
63,
8314,
275,
469,
272,
283,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
272,
283,
1205,
356,
788,
7780,
995,
272,
283,
4946,
63,
991,
356,
283,
9387,
7,
199,
93,
199,
199,
8948,
275,
519,
2344,
199,
2595,
199,
578,
26,
19365,
63,
1102,
63,
2491,
63,
5047,
199,
3612,
63,
1802,
26,
19634,
83,
9036,
3595,
2808,
6117,
641,
376,
10427,
14828,
1591,
199,
1802,
26,
199,
13,
961,
859,
883,
506,
1202,
370,
13082,
9036,
3595,
2808,
6117,
436,
3932,
2004,
641,
376,
10427,
14828,
1591,
14,
199,
1023,
63,
3270,
26,
283,
18,
14,
21,
7,
199,
2502,
26,
199,
13,
8351,
5812,
6532,
386,
1804,
305,
300,
271,
8593,
33,
75,
305,
300,
271,
9,
199,
5983,
26,
199,
13,
30568,
641,
373,
22385,
1227,
14,
21,
199,
7538,
26,
199,
13,
2366,
2356,
499,
14,
22,
199,
13,
1611,
54,
28603,
199,
1419,
26,
523,
4350,
63,
354,
26,
272,
1369,
26,
272,
446,
2812,
402,
314,
4350,
14,
272,
446,
15665,
9036,
3595,
1924,
10427,
14828,
1654,
911,
506,
2138,
367,
1627,
4350,
14,
272,
446,
982,
445,
8,
397,
6865,
63,
4269,
9,
365,
440,
1627,
12,
642,
2725,
365,
1415,
14,
523,
9455,
6865,
63,
4269,
26,
272,
1369,
26,
272,
446,
10427,
14828,
6246,
14,
272,
446,
15665,
9036,
3595,
642,
10427,
14828,
1654,
911,
506,
2138,
14,
272,
446,
982,
445,
8,
4201,
63,
354,
9,
365,
440,
1627,
12,
642,
2725,
365,
1415,
14,
199,
11036,
63,
9970,
63,
7677,
26,
19365,
14,
9970,
199,
2344,
199,
199,
8918,
275,
519,
2344,
199,
13,
536,
26,
19634,
9036,
3595,
1006,
10427,
14828,
10891,
315,
1627,
16454,
523,
19365,
63,
1102,
63,
2491,
63,
5047,
26,
272,
6246,
26,
11400,
27127,
63,
4269,
16339,
272,
3434,
26,
11400,
27127,
63,
2473,
16339,
272,
2505,
26,
11400,
27127,
63,
2060,
16339,
272,
4350,
63,
354,
26,
4350,
63,
354,
523,
13080,
63,
475,
26,
11667,
523,
2274,
26,
4350,
63,
1102,
63,
5154,
199,
199,
13,
536,
26,
19634,
9036,
3595,
10427,
14828,
10891,
523,
19365,
63,
1102,
63,
2491,
63,
5047,
26,
272,
6246,
26,
11400,
27127,
63,
4269,
16339,
272,
3434,
26,
11400,
27127,
63,
2473,
16339,
272,
2505,
26,
11400,
27127,
63,
2060,
16339,
272,
9455,
6865,
63,
4269,
26,
11400,
9455,
6865,
63,
4269,
16339,
523,
13080,
63,
475,
26,
11667,
523,
2274,
26,
1591,
63,
5154,
199,
2344,
199,
199,
9677,
275,
519,
2344,
199,
5146,
63,
2491,
63,
5047,
26,
272,
1369,
26,
272,
446,
1211,
543,
6246,
465,
790,
436,
1211,
543,
2559,
9036,
465,
574,
272,
2138,
26,
7057,
63,
2491,
63,
5047,
272,
730,
26,
1211,
272,
2690,
26,
469,
298,
5146,
63,
2491,
63,
5047,
582,
469,
298,
5967,
14,
1832,
2261,
582,
942,
4863,
199,
2344,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
199,
504,
3242,
14,
578,
63,
1208,
14,
18970,
492,
19365,
63,
2094,
63,
1650,
12,
1611,
54,
28603,
421,
199,
533,
812,
77,
1068,
8599,
2988,
8,
2713,
54,
28603,
304,
272,
347,
636,
826,
721,
277,
12,
859,
304,
267,
1613,
8,
17402,
1068,
8599,
2988,
12,
291,
2843,
826,
721,
578,
9,
267,
4350,
63,
354,
275,
291,
14,
1162,
14,
362,
360,
4201,
63,
354,
297,
488,
9,
267,
9455,
6865,
63,
1102,
63,
354,
275,
291,
14,
1162,
14,
362,
360,
397,
6865,
63,
4269,
297,
488,
9,
267,
291,
14,
5146,
275,
291,
14,
362,
63,
452,
63,
1102,
63,
8718,
8,
4201,
63,
354,
29,
4201,
63,
354,
12,
9455,
6865,
63,
1102,
63,
354,
29,
397,
6865,
63,
1102,
63,
354,
9,
339,
347,
13082,
63,
2491,
63,
5047,
8,
277,
304,
267,
7057,
63,
5047,
275,
1052,
267,
367,
1591,
315,
291,
14,
5146,
26,
288,
1591,
63,
2491,
63,
5047,
275,
942,
288,
1591,
63,
4600,
63,
7755,
275,
1591,
14,
888,
2988,
14,
1569,
2028,
2988,
288,
340,
1591,
63,
4600,
63,
7755,
26,
355,
24162,
275,
1591,
63,
4600,
63,
7755,
14,
11135,
10337,
25135,
342,
355,
367,
5496,
315,
24162,
26,
490,
1591,
63,
2491,
63,
5047,
14,
740,
8,
807,
8,
354,
29,
4600,
14,
354,
12,
8962,
1015,
29,
4600,
14,
1023,
12,
8962,
20868,
29,
4600,
14,
9884,
12,
8962,
6212,
29,
4600,
14,
4705,
12,
8962,
1369,
29,
4600,
14,
1802,
12,
8962,
4729,
554,
63,
1896,
29,
4600,
14,
28519,
4670,
12,
8962,
21964,
63,
632,
63,
2427,
29,
4600,
14,
19725,
1385,
8030,
12,
8962,
7143,
63,
602,
29,
4600,
14,
8782,
2506,
12,
8962,
776,
6343,
776,
288,
7057,
63,
5047,
59,
1102,
14,
354,
61,
275,
1591,
63,
2491,
63,
5047,
267,
372,
7057,
63,
5047,
421,
199,
318,
2446,
837,
272,
1423,
63,
1650,
275,
19365,
63,
2094,
63,
1650,
342,
272,
1423,
63,
1650,
14,
873,
8,
267,
4350,
63,
354,
29,
807,
8,
466,
534,
495,
297,
1415,
29,
797,
395,
267,
9455,
6865,
63,
4269,
29,
807,
8,
466,
534,
495,
297,
1415,
29,
797,
395,
272,
776,
339,
859,
275,
6953,
8,
267,
1423,
63,
1650,
29,
2094,
63,
1650,
12,
267,
1415,
63,
368,
63,
1618,
1524,
288,
788,
4201,
63,
354,
297,
283,
397,
6865,
63,
4269,
995,
267,
1622,
272,
776,
339,
19365,
63,
1102,
63,
2491,
63,
888,
275,
812,
77,
1068,
8599,
2988,
8,
578,
9,
272,
859,
14,
2224,
63,
1001,
8,
2489,
29,
797,
12,
7057,
63,
2491,
63,
5047,
29,
18970,
63,
1102,
63,
2491,
63,
888,
14
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
1898,
26,
334,
67,
9,
14894,
12,
8351,
5812,
6532,
386,
1804,
305,
300,
271,
665,
1151,
305,
300,
271,
32,
17164,
14,
957,
30,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
363,
6577,
363,
275,
730,
199,
199,
8490,
63,
8314,
275,
469,
272,
283,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
272,
283,
1205,
356,
788,
7780,
995,
272,
283,
4946,
63,
991,
356,
283,
9387,
7,
199,
93,
199,
199,
8948,
275,
519,
2344,
199,
2595,
199,
578,
26,
19365,
63,
1102,
63,
2491,
63,
5047,
199,
3612,
63,
1802,
26,
19634,
83,
9036,
3595,
2808,
6117,
641,
376,
10427,
14828,
1591,
199,
1802,
26,
199,
13,
961,
859,
883,
506,
1202,
370,
13082,
9036,
3595,
2808,
6117,
436,
3932,
2004,
641,
376,
10427,
14828,
1591,
14,
199,
1023,
63,
3270,
26,
283,
18,
14,
21,
7,
199,
2502,
26,
199,
13,
8351,
5812,
6532,
386,
1804,
305,
300,
271,
8593,
33,
75,
305,
300,
271,
9,
199,
5983,
26,
199,
13,
30568,
641,
373,
22385,
1227,
14,
21,
199,
7538,
26,
199,
13,
2366,
2356,
499,
14,
22,
199,
13,
1611,
54,
28603,
199,
1419,
26,
523,
4350,
63,
354,
26,
272,
1369,
26,
272,
446,
2812,
402,
314,
4350,
14,
272,
446,
15665,
9036,
3595,
1924,
10427,
14828,
1654,
911,
506,
2138,
367,
1627,
4350,
14,
272,
446,
982,
445,
8,
397,
6865,
63,
4269,
9,
365,
440,
1627,
12,
642,
2725,
365,
1415,
14,
523,
9455,
6865,
63,
4269,
26,
272,
1369,
26,
272,
446,
10427,
14828,
6246,
14,
272,
446,
15665,
9036,
3595,
642,
10427,
14828,
1654,
911,
506,
2138,
14,
272,
446,
982,
445,
8,
4201,
63,
354,
9,
365,
440,
1627,
12,
642,
2725,
365,
1415,
14,
199,
11036,
63,
9970,
63,
7677,
26,
19365,
14,
9970,
199,
2344,
199,
199,
8918,
275,
519,
2344,
199,
13,
536,
26,
19634,
9036,
3595,
1006,
10427,
14828,
10891,
315,
1627,
16454,
523,
19365,
63,
1102,
63,
2491,
63,
5047,
26,
272,
6246,
26,
11400,
27127,
63,
4269,
16339,
272,
3434,
26,
11400,
27127,
63,
2473,
16339,
272,
2505,
26,
11400,
27127,
63,
2060,
16339,
272,
4350,
63,
354,
26,
4350,
63,
354,
523,
13080,
63,
475,
26,
11667,
523,
2274,
26,
4350,
63,
1102,
63,
5154,
199,
199,
13,
536,
26,
19634,
9036,
3595,
10427,
14828,
10891,
523,
19365,
63,
1102,
63,
2491,
63,
5047,
26,
272,
6246,
26,
11400,
27127,
63,
4269,
16339,
272,
3434,
26,
11400,
27127,
63,
2473,
16339,
272,
2505,
26,
11400,
27127,
63,
2060,
16339,
272,
9455,
6865,
63,
4269,
26,
11400,
9455,
6865,
63,
4269,
16339,
523,
13080,
63,
475,
26,
11667,
523,
2274,
26,
1591,
63,
5154,
199,
2344,
199,
199,
9677,
275,
519,
2344,
199,
5146,
63,
2491,
63,
5047,
26,
272,
1369,
26,
272,
446,
1211,
543,
6246,
465,
790,
436,
1211,
543,
2559,
9036,
465,
574,
272,
2138,
26,
7057,
63,
2491,
63,
5047,
272,
730,
26,
1211,
272,
2690,
26,
469,
298,
5146,
63,
2491,
63,
5047,
582,
469,
298,
5967,
14,
1832,
2261,
582,
942,
4863,
199,
2344,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
199,
504,
3242,
14,
578,
63,
1208,
14,
18970,
492,
19365,
63,
2094,
63,
1650,
12,
1611,
54,
28603,
421,
199,
533,
812,
77,
1068,
8599,
2988,
8,
2713,
54,
28603,
304,
272,
347,
636,
826,
721,
277,
12,
859,
304,
267,
1613,
8,
17402,
1068,
8599,
2988,
12,
291,
2843,
826,
721,
578,
9,
267,
4350,
63,
354,
275,
291,
14,
1162,
14,
362,
360,
4201,
63,
354,
297,
488,
9,
267,
9455,
6865,
63,
1102,
63,
354,
275,
291,
14,
1162,
14,
362,
360,
397,
6865,
63,
4269,
297,
488,
9,
267,
291,
14,
5146,
275,
291,
14,
362,
63,
452,
63,
1102,
63,
8718,
8,
4201,
63,
354,
29,
4201,
63,
354,
12,
9455,
6865,
63,
1102,
63,
354,
29,
397,
6865,
63,
1102,
63,
354,
9,
339,
347,
13082,
63,
2491,
63,
5047,
8,
277,
304,
267,
7057,
63,
5047,
275,
1052,
267,
367,
1591,
315,
291,
14,
5146,
26,
288,
1591,
63,
2491,
63,
5047,
275,
942,
288,
1591,
63,
4600,
63,
7755,
275,
1591,
14,
888,
2988,
14,
1569,
2028,
2988,
288,
340,
1591,
63,
4600,
63,
7755,
26,
355,
24162,
275,
1591,
63,
4600,
63,
7755,
14,
11135,
10337,
25135,
342,
355,
367,
5496,
315,
24162,
26,
490,
1591,
63,
2491,
63,
5047,
14,
740,
8,
807,
8,
354,
29,
4600,
14,
354,
12,
8962,
1015,
29,
4600,
14,
1023,
12,
8962,
20868,
29,
4600,
14,
9884,
12,
8962,
6212,
29,
4600,
14,
4705,
12,
8962,
1369,
29,
4600,
14,
1802,
12,
8962,
4729,
554,
63,
1896,
29,
4600,
14,
28519,
4670,
12,
8962,
21964,
63,
632,
63,
2427,
29,
4600,
14,
19725,
1385,
8030,
12,
8962,
7143,
63,
602,
29,
4600,
14,
8782,
2506,
12,
8962,
776,
6343,
776,
288,
7057,
63,
5047,
59,
1102,
14,
354,
61,
275,
1591,
63,
2491,
63,
5047,
267,
372,
7057,
63,
5047,
421,
199,
318,
2446,
837,
272,
1423,
63,
1650,
275,
19365,
63,
2094,
63,
1650,
342,
272,
1423,
63,
1650,
14,
873,
8,
267,
4350,
63,
354,
29,
807,
8,
466,
534,
495,
297,
1415,
29,
797,
395,
267,
9455,
6865,
63,
4269,
29,
807,
8,
466,
534,
495,
297,
1415,
29,
797,
395,
272,
776,
339,
859,
275,
6953,
8,
267,
1423,
63,
1650,
29,
2094,
63,
1650,
12,
267,
1415,
63,
368,
63,
1618,
1524,
288,
788,
4201,
63,
354,
297,
283,
397,
6865,
63,
4269,
995,
267,
1622,
272,
776,
339,
19365,
63,
1102,
63,
2491,
63,
888,
275,
812,
77,
1068,
8599,
2988,
8,
578,
9,
272,
859,
14,
2224,
63,
1001,
8,
2489,
29,
797,
12,
7057,
63,
2491,
63,
5047,
29,
18970,
63,
1102,
63,
2491,
63,
888,
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,
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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
] |
remoteur/ospurge
|
ospurge/ospurge.py
|
2
|
34513
|
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
#
# This software is released under the MIT License.
#
# Copyright (c) 2014 Cloudwatt
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
import argparse
import logging
import os
import sys
import time
import ceilometerclient.exc
from ceilometerclient.v2 import client as ceilometer_client
import cinderclient.exceptions
from cinderclient.v1 import client as cinder_client
import glanceclient.exc
from glanceclient.v1 import client as glance_client
from heatclient import client as heat_client
import heatclient.openstack.common.apiclient.exceptions
from keystoneclient.apiclient import exceptions as api_exceptions
import keystoneclient.openstack.common.apiclient.exceptions
from keystoneclient.v2_0 import client as keystone_client
import neutronclient.common.exceptions
from neutronclient.v2_0 import client as neutron_client
import novaclient.exceptions
from novaclient.v1_1 import client as nova_client
import requests
from swiftclient import client as swift_client
RETRIES = 10 # Retry a delete operation 10 times before exiting
TIMEOUT = 5 # 5 seconds timeout between retries
class ResourceNotEnabled(Exception):
pass
class EndpointNotFound(Exception):
pass
class InvalidEndpoint(Exception):
pass
class NoSuchProject(Exception):
ERROR_CODE = 2
AUTHENTICATION_FAILED_ERROR_CODE = 3
class DeletionFailed(Exception):
ERROR_CODE = 4
CONNECTION_ERROR_CODE = 5
NOT_AUTHORIZED = 6
# Available resources classes.
# The order of the Openstack resources in the subsequent list
# corresponds to the order in which ospurge will delete the
# resources. This order takes into account inter-resources
# dependencies, and tries to minimize the overall time duration of the
# purge operation.
RESOURCES_CLASSES = ['CinderSnapshots',
'CinderBackups',
'NovaServers',
'NeutronFloatingIps',
'NeutronFireWall',
'NeutronFireWallPolicy',
'NeutronFireWallRule',
'NeutronLbMembers',
'NeutronLbVip',
'NeutronLbHealthMonitor',
'NeutronLbPool',
'NeutronMeteringLabel',
'NeutronInterfaces',
'NeutronRouters',
'NeutronPorts',
'NeutronNetworks',
'NeutronSecgroups',
'GlanceImages',
'SwiftObjects',
'SwiftContainers',
'CinderVolumes',
'CeilometerAlarms',
'HeatStacks']
# Decorators
def retry(service_name):
def factory(func):
"""Decorator allowing to retry in case of failure."""
def wrapper(*args, **kwargs):
n = 0
while True:
try:
return func(*args, **kwargs)
except Exception as e:
if getattr(e, 'http_status', False) == 404:
# Sometimes a resource can be deleted manually by
# someone else while ospurge is running and listed it.
# If this happens, We raise a Warning.
logging.warning(
"Can not delete the resource because it does not"
" exist : %s" % e
)
# No need to retry deleting an non existing resource
break
else:
if n == RETRIES:
raise DeletionFailed(service_name)
n += 1
logging.info("* Deletion failed - "
"Retrying in {} seconds - "
"Retry count {}".format(TIMEOUT, n))
time.sleep(TIMEOUT)
return wrapper
return factory
# Classes
class Session(object):
"""A Session stores information that can be used by the different Openstack Clients.
The most important data is:
* self.token - The Openstack token to be used accross services;
* self.catalog - Allowing to retrieve services' endpoints.
"""
def __init__(self, username, password, project_id, auth_url,
endpoint_type="publicURL", region_name=None, insecure=False):
client = keystone_client.Client(
username=username, password=password, tenant_id=project_id,
auth_url=auth_url, region_name=region_name, insecure=insecure)
# Storing username, password, project_id and auth_url for
# use by clients libraries that cannot use an existing token.
self.username = username
self.password = password
self.project_id = project_id
self.auth_url = auth_url
self.region_name = region_name
self.insecure = insecure
# Session variables to be used by clients when possible
self.token = client.auth_token
self.user_id = client.user_id
self.project_name = client.project_name
self.endpoint_type = endpoint_type
self.catalog = client.service_catalog.get_endpoints()
def get_endpoint(self, service_type):
try:
return self.catalog[service_type][0][self.endpoint_type]
except (KeyError, IndexError):
# Endpoint could not be found
raise EndpointNotFound(service_type)
class Resources(object):
"""Abstract base class for all resources to be removed."""
def __init__(self, session):
self.session = session
def list(self):
pass
def delete(self, resource):
"""Displays informational message about a resource deletion."""
logging.info("* Deleting {}.".format(self.resource_str(resource)))
def purge(self):
"""Delete all resources."""
# Purging is displayed and done only if self.list succeeds
resources = self.list()
c_name = self.__class__.__name__
logging.info("* Purging {}".format(c_name))
for resource in resources:
retry(c_name)(self.delete)(resource)
def dump(self):
"""Display all available resources."""
# Resources type and resources are displayed only if self.list succeeds
resources = self.list()
c_name = self.__class__.__name__
print("* Resources type: {}".format(c_name))
for resource in resources:
print(self.resource_str(resource))
print("")
class SwiftResources(Resources):
def __init__(self, session):
super(SwiftResources, self).__init__(session)
self.endpoint = self.session.get_endpoint("object-store")
self.token = self.session.token
conn = swift_client.HTTPConnection(self.endpoint, insecure=self.session.insecure)
self.http_conn = conn.parsed_url, conn
# This method is used to retrieve Objects as well as Containers.
def list_containers(self):
containers = swift_client.get_account(self.endpoint, self.token, http_conn=self.http_conn)[1]
return (cont['name'] for cont in containers)
class SwiftObjects(SwiftResources):
def list(self):
swift_objects = []
for cont in self.list_containers():
objs = [{'container': cont, 'name': obj['name']} for obj in
swift_client.get_container(self.endpoint, self.token, cont, http_conn=self.http_conn)[1]]
swift_objects.extend(objs)
return swift_objects
def delete(self, obj):
super(SwiftObjects, self).delete(obj)
swift_client.delete_object(self.endpoint, token=self.token, http_conn=self.http_conn,
container=obj['container'], name=obj['name'])
def resource_str(self, obj):
return "object {} in container {}".format(obj['name'], obj['container'])
class SwiftContainers(SwiftResources):
def list(self):
return self.list_containers()
def delete(self, container):
"""Container must be empty for deletion to succeed."""
super(SwiftContainers, self).delete(container)
swift_client.delete_container(self.endpoint, self.token, container, http_conn=self.http_conn)
def resource_str(self, obj):
return "container {}".format(obj)
class CinderResources(Resources):
def __init__(self, session):
super(CinderResources, self).__init__(session)
# Cinder client library can't use an existing token. When
# using this library, we have to reauthenticate.
self.client = cinder_client.Client(
session.username, session.password,
session.project_name, session.auth_url, session.insecure,
endpoint_type=session.endpoint_type,
region_name=session.region_name)
class CinderSnapshots(CinderResources):
def list(self):
return self.client.volume_snapshots.list()
def delete(self, snap):
super(CinderSnapshots, self).delete(snap)
self.client.volume_snapshots.delete(snap)
def resource_str(self, snap):
return "snapshot {} (id {})".format(snap.display_name, snap.id)
class CinderVolumes(CinderResources):
def list(self):
return self.client.volumes.list()
def delete(self, vol):
"""Snapshots created from the volume must be deleted first."""
super(CinderVolumes, self).delete(vol)
self.client.volumes.delete(vol)
def resource_str(self, vol):
return "volume {} (id {})".format(vol.display_name, vol.id)
class CinderBackups(CinderResources):
def list(self):
return self.client.backups.list()
def delete(self, backup):
super(CinderBackups, self).delete(backup)
self.client.backups.delete(backup)
def resource_str(self, backup):
return "backup {} (id {}) of volume {}".format(backup.name, backup.id, backup.volume_id)
class NeutronResources(Resources):
def __init__(self, session):
super(NeutronResources, self).__init__(session)
self.client = neutron_client.Client(
username=session.username, password=session.password,
tenant_id=session.project_id, auth_url=session.auth_url,
endpoint_type=session.endpoint_type,
region_name=session.region_name, insecure=session.insecure)
self.project_id = session.project_id
# This method is used for routers and interfaces removal
def list_routers(self):
return filter(self._owned_resource, self.client.list_routers()['routers'])
def _owned_resource(self, res):
# Only considering resources owned by project
return res['tenant_id'] == self.project_id
class NeutronRouters(NeutronResources):
def list(self):
return self.list_routers()
def delete(self, router):
"""Interfaces must be deleted first."""
super(NeutronRouters, self).delete(router)
# Remove router gateway prior to remove the router itself
self.client.remove_gateway_router(router['id'])
self.client.delete_router(router['id'])
def resource_str(self, router):
return "router {} (id {})".format(router['name'], router['id'])
class NeutronInterfaces(NeutronResources):
def list(self):
# Only considering "router_interface" ports
# (not gateways, neither unbound ports)
all_ports = [port for port in self.client.list_ports()['ports']
if port["device_owner"] == "network:router_interface"]
return filter(self._owned_resource, all_ports)
def delete(self, interface):
super(NeutronInterfaces, self).delete(interface)
self.client.remove_interface_router(interface['device_id'],
{'port_id': interface['id']})
def resource_str(self, interface):
return "interface {} (id {})".format(interface['name'],
interface['id'])
class NeutronPorts(NeutronResources):
# When created, unbound ports' device_owner are "". device_owner
# is of the form" compute:*" if it has been bound to some vm in
# the past.
def list(self):
all_ports = [port for port in self.client.list_ports()['ports']
if port["device_owner"] == ""
or port["device_owner"].startswith("compute:")]
return filter(self._owned_resource, all_ports)
def delete(self, port):
super(NeutronPorts, self).delete(port)
self.client.delete_port(port['id'])
def resource_str(self, port):
return "port {} (id {})".format(port['name'], port['id'])
class NeutronNetworks(NeutronResources):
def list(self):
return filter(self._owned_resource,
self.client.list_networks()['networks'])
def delete(self, net):
"""Delete a Neutron network
Interfaces connected to the network must be deleted first.
Implying there must not be any VM on the network.
"""
super(NeutronNetworks, self).delete(net)
self.client.delete_network(net['id'])
def resource_str(self, net):
return "network {} (id {})".format(net['name'], net['id'])
class NeutronSecgroups(NeutronResources):
def list(self):
# filtering out default security group (cannot be removed)
def secgroup_filter(secgroup):
if secgroup['name'] == 'default':
return False
return self._owned_resource(secgroup)
try:
sgs = self.client.list_security_groups()['security_groups']
return filter(secgroup_filter, sgs)
except neutronclient.common.exceptions.NeutronClientException as err:
if getattr(err, "status_code", None) == 404:
raise ResourceNotEnabled
raise
def delete(self, secgroup):
"""VMs using the security group should be deleted first."""
super(NeutronSecgroups, self).delete(secgroup)
self.client.delete_security_group(secgroup['id'])
def resource_str(self, secgroup):
return "security group {} (id {})".format(
secgroup['name'], secgroup['id'])
class NeutronFloatingIps(NeutronResources):
def list(self):
return filter(self._owned_resource,
self.client.list_floatingips()['floatingips'])
def delete(self, floating_ip):
super(NeutronFloatingIps, self).delete(floating_ip)
self.client.delete_floatingip(floating_ip['id'])
def resource_str(self, floating_ip):
return "floating ip {} (id {})".format(
floating_ip['floating_ip_address'], floating_ip['id'])
class NeutronLbMembers(NeutronResources):
def list(self):
return filter(self._owned_resource, self.client.list_members()['members'])
def delete(self, member):
super(NeutronLbMembers, self).delete(member)
self.client.delete_member(member['id'])
def resource_str(self, member):
return "lb-member {} (id {})".format(member['address'], member['id'])
class NeutronLbPool(NeutronResources):
def list(self):
return filter(self._owned_resource, self.client.list_pools()['pools'])
def delete(self, pool):
super(NeutronLbPool, self).delete(pool)
self.client.delete_pool(pool['id'])
def resource_str(self, pool):
return "lb-pool {} (id {})".format(pool['name'], pool['id'])
class NeutronLbVip(NeutronResources):
def list(self):
return filter(self._owned_resource, self.client.list_vips()['vips'])
def delete(self, vip):
super(NeutronLbVip, self).delete(vip)
self.client.delete_vip(vip['id'])
def resource_str(self, vip):
return "lb-vip {} (id {})".format(vip['name'], vip['id'])
class NeutronLbHealthMonitor(NeutronResources):
def list(self):
return filter(self._owned_resource, self.client.list_health_monitors()['health_monitors'])
def delete(self, health_monitor):
super(NeutronLbHealthMonitor, self).delete(health_monitor)
self.client.delete_health_monitor(health_monitor['id'])
def resource_str(self, health_monitor):
return "lb-health_monotor type {} (id {})".format(health_monitor['type'], health_monitor['id'])
class NeutronMeteringLabel(NeutronResources):
def list(self):
return filter(self._owned_resource, self.client.list_metering_labels()['metering_labels'])
def delete(self, metering_label):
super(NeutronMeteringLabel, self).delete(metering_label)
self.client.delete_metering_label(metering_label['id'])
def resource_str(self, metering_label):
return "meter-label {} (id {})".format(metering_label['name'], metering_label['id'])
class NeutronFireWallPolicy(NeutronResources):
def list(self):
return filter(self._owned_resource, self.client.list_firewall_policies()['firewall_policies'])
def delete(self, firewall_policy):
super(NeutronFireWallPolicy, self).delete(firewall_policy)
self.client.delete_firewall_policy(firewall_policy['id'])
def resource_str(self, firewall_policy):
return "Firewall policy {} (id {})".format(firewall_policy['name'], firewall_policy['id'])
class NeutronFireWallRule(NeutronResources):
def list(self):
return filter(self._owned_resource, self.client.list_firewall_rules()['firewall_rules'])
def delete(self, firewall_rule):
super(NeutronFireWallRule, self).delete(firewall_rule)
self.client.delete_firewall_rule(firewall_rule['id'])
def resource_str(self, firewall_rule):
return "Firewall rule {} (id {})".format(firewall_rule['name'], firewall_rule['id'])
class NeutronFireWall(NeutronResources):
def list(self):
return filter(self._owned_resource, self.client.list_firewalls()['firewalls'])
def delete(self, firewall):
super(NeutronFireWall, self).delete(firewall)
self.client.delete_firewall(firewall['id'])
def resource_str(self, firewall):
return "Firewall {} (id {})".format(firewall['name'], firewall['id'])
class NovaServers(Resources):
def __init__(self, session):
super(NovaServers, self).__init__(session)
self.client = nova_client.Client(
session.username, session.password,
session.project_name, auth_url=session.auth_url,
endpoint_type=session.endpoint_type,
region_name=session.region_name, insecure=session.insecure)
self.project_id = session.project_id
"""Manage nova resources"""
def list(self):
return self.client.servers.list()
def delete(self, server):
super(NovaServers, self).delete(server)
self.client.servers.delete(server)
def resource_str(self, server):
return "server {} (id {})".format(server.name, server.id)
class GlanceImages(Resources):
def __init__(self, session):
self.client = glance_client.Client(
endpoint=session.get_endpoint("image"),
token=session.token, insecure=session.insecure)
self.project_id = session.project_id
def list(self):
return filter(self._owned_resource, self.client.images.list())
def delete(self, image):
super(GlanceImages, self).delete(image)
self.client.images.delete(image.id)
def resource_str(self, image):
return "image {} (id {})".format(image.name, image.id)
def _owned_resource(self, res):
# Only considering resources owned by project
return res.owner == self.project_id
class HeatStacks(Resources):
def __init__(self, session):
self.client = heat_client.Client(
"1",
endpoint=session.get_endpoint("orchestration"),
token=session.token, insecure=session.insecure)
self.project_id = session.project_id
def list(self):
return self.client.stacks.list()
def delete(self, stack):
super(HeatStacks, self).delete(stack)
if stack.stack_status == "DELETE_FAILED":
self.client.stacks.abandon(stack.id)
else:
self.client.stacks.delete(stack.id)
def resource_str(self, stack):
return "stack {})".format(stack.id)
class CeilometerAlarms(Resources):
def __init__(self, session):
# Ceilometer Client needs a method that returns the token
def get_token():
return session.token
self.client = ceilometer_client.Client(
endpoint=session.get_endpoint("metering"),
token=get_token, insecure=session.insecure)
self.project_id = session.project_id
def list(self):
query = [{'field': 'project_id',
'op': 'eq',
'value': self.project_id}]
return self.client.alarms.list(q=query)
def delete(self, alarm):
super(CeilometerAlarms, self).delete(alarm)
self.client.alarms.delete(alarm.alarm_id)
def resource_str(self, alarm):
return "alarm {}".format(alarm.name)
class KeystoneManager(object):
"""Manages Keystone queries."""
def __init__(self, username, password, project, auth_url, insecure, **kwargs):
self.client = keystone_client.Client(
username=username, password=password,
tenant_name=project, auth_url=auth_url,
insecure=insecure, **kwargs)
self.admin_role_id = None
self.tenant_info = None
def get_project_id(self, project_name_or_id=None):
"""Get a project by its id
Returns:
* ID of current project if called without parameter,
* ID of project given as parameter if one is given.
"""
if project_name_or_id is None:
return self.client.tenant_id
try:
self.tenant_info = self.client.tenants.get(project_name_or_id)
# If it doesn't raise an 404, project_name_or_id is
# already the project's id
project_id = project_name_or_id
except api_exceptions.NotFound:
try:
# Can raise api_exceptions.Forbidden:
tenants = self.client.tenants.list()
project_id = filter(
lambda x: x.name == project_name_or_id, tenants)[0].id
except IndexError:
raise NoSuchProject(project_name_or_id)
if not self.tenant_info:
self.tenant_info = self.client.tenants.get(project_id)
return project_id
def enable_project(self, project_id):
logging.info("* Enabling project {}.".format(project_id))
self.tenant_info = self.client.tenants.update(project_id, enabled=True)
def disable_project(self, project_id):
logging.info("* Disabling project {}.".format(project_id))
self.tenant_info = self.client.tenants.update(project_id, enabled=False)
def get_admin_role_id(self):
if not self.admin_role_id:
roles = self.client.roles.list()
self.admin_role_id = filter(lambda x: x.name == "admin", roles)[0].id
return self.admin_role_id
def become_project_admin(self, project_id):
user_id = self.client.user_id
admin_role_id = self.get_admin_role_id()
logging.info("* Granting role admin to user {} on project {}.".format(
user_id, project_id))
return self.client.roles.add_user_role(user_id, admin_role_id, project_id)
def undo_become_project_admin(self, project_id):
user_id = self.client.user_id
admin_role_id = self.get_admin_role_id()
logging.info("* Removing role admin to user {} on project {}.".format(
user_id, project_id))
return self.client.roles.remove_user_role(user_id, admin_role_id, project_id)
def delete_project(self, project_id):
logging.info("* Deleting project {}.".format(project_id))
self.client.tenants.delete(project_id)
def perform_on_project(admin_name, password, project, auth_url,
endpoint_type='publicURL', region_name=None,
action='dump', insecure=False):
"""Perform provided action on all resources of project.
action can be: 'purge' or 'dump'
"""
session = Session(admin_name, password, project, auth_url,
endpoint_type, region_name, insecure)
error = None
for rc in RESOURCES_CLASSES:
try:
resources = globals()[rc](session)
res_actions = {'purge': resources.purge,
'dump': resources.dump}
res_actions[action]()
except (EndpointNotFound,
keystoneclient.openstack.common.apiclient.exceptions.EndpointNotFound,
neutronclient.common.exceptions.EndpointNotFound,
cinderclient.exceptions.EndpointNotFound,
novaclient.exceptions.EndpointNotFound,
heatclient.openstack.common.apiclient.exceptions.EndpointNotFound,
ResourceNotEnabled):
# If service is not in Keystone's services catalog, ignoring it
pass
except requests.exceptions.MissingSchema as e:
logging.warning(
'Some resources may not have been deleted, "{!s}" is '
'improperly configured and returned: {!r}\n'.format(rc, e))
except (ceilometerclient.exc.InvalidEndpoint, glanceclient.exc.InvalidEndpoint) as e:
logging.warning(
"Unable to connect to {} endpoint : {}".format(rc, e.message))
error = InvalidEndpoint(rc)
except (neutronclient.common.exceptions.NeutronClientException):
# If service is not configured, ignoring it
pass
if error:
raise error
# From Russell Heilling
# http://stackoverflow.com/questions/10551117/setting-options-from-environment-variables-when-using-argparse
class EnvDefault(argparse.Action):
def __init__(self, envvar, required=True, default=None, **kwargs):
# Overriding default with environment variable if available
if envvar in os.environ:
default = os.environ[envvar]
if required and default:
required = False
super(EnvDefault, self).__init__(default=default, required=required,
**kwargs)
def __call__(self, parser, namespace, values, option_string=None):
setattr(namespace, self.dest, values)
def parse_args():
desc = "Purge resources from an Openstack project."
parser = argparse.ArgumentParser(description=desc)
parser.add_argument("--verbose", action="store_true",
help="Makes output verbose")
parser.add_argument("--dry-run", action="store_true",
help="List project's resources")
parser.add_argument("--dont-delete-project", action="store_true",
help="Executes cleanup script without removing the project. "
"Warning: all project resources will still be deleted.")
parser.add_argument("--region-name", action=EnvDefault, required=False,
envvar='OS_REGION_NAME', default=None,
help="Region to use. Defaults to env[OS_REGION_NAME] "
"or None")
parser.add_argument("--endpoint-type", action=EnvDefault,
envvar='OS_ENDPOINT_TYPE', default="publicURL",
help="Endpoint type to use. Defaults to "
"env[OS_ENDPOINT_TYPE] or publicURL")
parser.add_argument("--username", action=EnvDefault,
envvar='OS_USERNAME', required=True,
help="If --own-project is set : a user name with access to the "
"project being purged. If --cleanup-project is set : "
"a user name with admin role in project specified in --admin-project. "
"Defaults to env[OS_USERNAME]")
parser.add_argument("--password", action=EnvDefault,
envvar='OS_PASSWORD', required=True,
help="The user's password. Defaults "
"to env[OS_PASSWORD].")
parser.add_argument("--admin-project", action=EnvDefault,
envvar='OS_TENANT_NAME', required=True,
help="Project name used for authentication. This project "
"will be purged if --own-project is set. "
"Defaults to env[OS_TENANT_NAME].")
parser.add_argument("--auth-url", action=EnvDefault,
envvar='OS_AUTH_URL', required=True,
help="Authentication URL. Defaults to "
"env[OS_AUTH_URL].")
parser.add_argument("--cleanup-project", required=False, default=None,
help="ID or Name of project to purge. Not required "
"if --own-project has been set. Using --cleanup-project "
"requires to authenticate with admin credentials.")
parser.add_argument("--own-project", action="store_true",
help="Delete resources of the project used to "
"authenticate. Useful if you don't have the "
"admin credentials of the platform.")
parser.add_argument("--insecure", action="store_true",
help="Explicitly allow all OpenStack clients to perform "
"insecure SSL (https) requests. The server's "
"certificate will not be verified against any "
"certificate authorities. This option should be "
"used with caution.")
args = parser.parse_args()
if not (args.cleanup_project or args.own_project):
parser.error('Either --cleanup-project '
'or --own-project has to be set')
if args.cleanup_project and args.own_project:
parser.error('Both --cleanup-project '
'and --own-project can not be set')
return args
def main():
args = parse_args()
if args.verbose:
logging.basicConfig(level=logging.INFO)
else:
# Set default log level to Warning
logging.basicConfig(level=logging.WARNING)
try:
keystone_manager = KeystoneManager(args.username, args.password,
args.admin_project, args.auth_url,
args.insecure, region_name=args.region_name)
except api_exceptions.Unauthorized as exc:
print("Authentication failed: {}".format(str(exc)))
sys.exit(AUTHENTICATION_FAILED_ERROR_CODE)
remove_admin_role_after_purge = False
disable_project_after_purge = False
try:
cleanup_project_id = keystone_manager.get_project_id(
args.cleanup_project)
if not args.own_project:
try:
keystone_manager.become_project_admin(cleanup_project_id)
except api_exceptions.Conflict:
# user was already admin on the target project.
pass
else:
remove_admin_role_after_purge = True
# If the project was enabled before the purge, do not disable it after the purge
disable_project_after_purge = not keystone_manager.tenant_info.enabled
if disable_project_after_purge:
# The project is currently disabled so we need to enable it
# in order to delete resources of the project
keystone_manager.enable_project(cleanup_project_id)
except api_exceptions.Forbidden as exc:
print("Not authorized: {}".format(str(exc)))
sys.exit(NOT_AUTHORIZED)
except NoSuchProject as exc:
print("Project {} doesn't exist".format(str(exc)))
sys.exit(NoSuchProject.ERROR_CODE)
# Proper cleanup
try:
action = "dump" if args.dry_run else "purge"
perform_on_project(args.username, args.password, cleanup_project_id,
args.auth_url, args.endpoint_type, args.region_name,
action, args.insecure)
except requests.exceptions.ConnectionError as exc:
print("Connection error: {}".format(str(exc)))
sys.exit(CONNECTION_ERROR_CODE)
except (DeletionFailed, InvalidEndpoint) as exc:
print("Deletion of {} failed".format(str(exc)))
print("*Warning* Some resources may not have been cleaned up")
sys.exit(DeletionFailed.ERROR_CODE)
if (not args.dry_run) and (not args.dont_delete_project) and (not args.own_project):
keystone_manager.delete_project(cleanup_project_id)
else:
# Project is not deleted, we may want to disable the project
# this must happen before we remove the admin role
if disable_project_after_purge:
keystone_manager.disable_project(cleanup_project_id)
# We may also want to remove ourself from the purged project
if remove_admin_role_after_purge:
keystone_manager.undo_become_project_admin(cleanup_project_id)
sys.exit(0)
if __name__ == "__main__":
main()
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2644,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
961,
2032,
365,
14286,
1334,
314,
10697,
844,
14,
199,
3,
199,
3,
1898,
334,
67,
9,
6927,
8142,
87,
6796,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
1331,
199,
3,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
298,
10337,
1288,
370,
7962,
199,
3,
315,
314,
2290,
1928,
10588,
12,
5893,
1928,
12305,
314,
4481,
199,
3,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
11207,
12,
13473,
12,
436,
15,
269,
12743,
199,
3,
6866,
402,
314,
2290,
12,
436,
370,
11291,
12103,
370,
12676,
314,
2290,
365,
199,
3,
13985,
370,
886,
880,
12,
5420,
370,
314,
2569,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
315,
1006,
199,
3,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
1549,
199,
3,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
3169,
12,
199,
3,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
7000,
2334,
199,
3,
10610,
1549,
5877,
8164,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
199,
3,
5603,
12,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
199,
3,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
2334,
199,
3,
4141,
14,
199,
199,
646,
7534,
199,
646,
2050,
199,
646,
747,
199,
646,
984,
199,
646,
900,
199,
199,
646,
10142,
25617,
1258,
14,
2804,
199,
504,
10142,
25617,
1258,
14,
86,
18,
492,
1890,
465,
10142,
25617,
63,
1258,
199,
646,
13069,
1258,
14,
3924,
199,
504,
13069,
1258,
14,
86,
17,
492,
1890,
465,
13069,
63,
1258,
199,
646,
21785,
1258,
14,
2804,
199,
504,
21785,
1258,
14,
86,
17,
492,
1890,
465,
21785,
63,
1258,
199,
504,
20408,
1258,
492,
1890,
465,
20408,
63,
1258,
199,
646,
20408,
1258,
14,
8512,
14,
2330,
14,
25661,
14,
3924,
199,
504,
19395,
1258,
14,
25661,
492,
4967,
465,
2986,
63,
3924,
199,
646,
19395,
1258,
14,
8512,
14,
2330,
14,
25661,
14,
3924,
199,
504,
19395,
1258,
14,
86,
18,
63,
16,
492,
1890,
465,
19395,
63,
1258,
199,
646,
8224,
1258,
14,
2330,
14,
3924,
199,
504,
8224,
1258,
14,
86,
18,
63,
16,
492,
1890,
465,
8224,
63,
1258,
199,
646,
949,
15367,
864,
14,
3924,
199,
504,
949,
15367,
864,
14,
86,
17,
63,
17,
492,
1890,
465,
5913,
63,
1258,
199,
646,
4145,
199,
504,
16275,
1258,
492,
1890,
465,
16275,
63,
1258,
199,
199,
32528,
275,
1616,
221,
327,
20506,
282,
3145,
3439,
1616,
5431,
2544,
24234,
199,
8899,
275,
959,
257,
327,
959,
4696,
2653,
3382,
10086,
421,
199,
533,
7337,
1763,
6589,
8,
1726,
304,
272,
986,
421,
199,
533,
9599,
1403,
4667,
8,
1726,
304,
272,
986,
421,
199,
533,
6378,
11442,
8,
1726,
304,
272,
986,
421,
199,
533,
23798,
4761,
8,
1726,
304,
272,
12539,
63,
6012,
275,
499,
199,
199,
29599,
63,
12299,
63,
3170,
63,
6012,
275,
650,
421,
199,
533,
12035,
296,
4276,
8,
1726,
304,
272,
12539,
63,
6012,
275,
841,
199,
199,
18389,
63,
3170,
63,
6012,
275,
959,
199,
199,
4609,
63,
25303,
1149,
275,
1227,
421,
199,
3,
23840,
5944,
3992,
14,
199,
3,
710,
1865,
402,
314,
3232,
2340,
5944,
315,
314,
13372,
769,
199,
3,
13718,
370,
314,
1865,
315,
1314,
312,
681,
300,
303,
911,
3145,
314,
199,
3,
5944,
14,
961,
1865,
6181,
1901,
2933,
1640,
13,
4435,
199,
3,
5124,
12,
436,
11275,
370,
24720,
314,
20347,
900,
7373,
402,
314,
199,
3,
18503,
3439,
14,
199,
199,
3830,
11237,
16734,
63,
13748,
275,
788,
35,
5755,
12038,
83,
297,
2151,
283,
35,
5755,
4540,
15203,
297,
2151,
283,
19884,
23637,
297,
2151,
283,
20915,
17895,
41,
1190,
297,
2151,
283,
20915,
13081,
18018,
297,
2151,
283,
20915,
13081,
18018,
4845,
297,
2151,
283,
20915,
13081,
18018,
5065,
297,
2151,
283,
20915,
44,
66,
23056,
297,
2151,
283,
20915,
44,
66,
54,
711,
297,
2151,
283,
20915,
44,
66,
18850,
13189,
297,
2151,
283,
20915,
44,
66,
5453,
297,
2151,
283,
20915,
27937,
316,
4314,
297,
2151,
283,
20915,
18680,
297,
2151,
283,
20915,
5407,
878,
297,
2151,
283,
20915,
25573,
297,
2151,
283,
20915,
30551,
297,
2151,
283,
20915,
4933,
2634,
297,
2151,
283,
17541,
554,
18882,
297,
2151,
283,
10941,
2949,
11188,
297,
2151,
283,
10941,
2949,
31266,
1192,
297,
2151,
283,
35,
5755,
32480,
297,
2151,
283,
24417,
25617,
2439,
25005,
297,
2151,
283,
30770,
4851,
83,
418,
421,
199,
3,
13966,
269,
2750,
199,
199,
318,
7269,
8,
1364,
63,
354,
304,
272,
347,
6434,
8,
1532,
304,
267,
408,
14946,
17266,
370,
7269,
315,
1930,
402,
5988,
1041,
267,
347,
4975,
2031,
589,
12,
1011,
958,
304,
288,
302,
275,
378,
288,
1830,
715,
26,
355,
862,
26,
490,
372,
2562,
2031,
589,
12,
1011,
958,
9,
355,
871,
2186,
465,
325,
26,
490,
340,
2519,
8,
69,
12,
283,
1014,
63,
1205,
297,
756,
9,
508,
7901,
26,
717,
327,
30094,
282,
2073,
883,
506,
5463,
10250,
701,
717,
327,
17122,
587,
1830,
312,
681,
300,
303,
365,
3879,
436,
10532,
652,
14,
717,
327,
982,
642,
10986,
12,
2136,
746,
282,
15902,
14,
717,
2050,
14,
3764,
8,
1169,
298,
6049,
440,
3145,
314,
2073,
2952,
652,
1630,
440,
2,
1169,
298,
2187,
520,
450,
83,
2,
450,
325,
717,
776,
717,
327,
3091,
1929,
370,
7269,
13794,
376,
2222,
3411,
2073,
717,
2059,
490,
587,
26,
717,
340,
302,
508,
17409,
23359,
26,
1169,
746,
12035,
296,
4276,
8,
1364,
63,
354,
9,
717,
302,
847,
413,
717,
2050,
14,
815,
23124,
12035,
296,
3405,
446,
298,
3660,
298,
12989,
316,
315,
1052,
4696,
446,
298,
3660,
298,
12989,
2338,
8352,
908,
8,
8899,
12,
302,
430,
717,
900,
14,
4532,
8,
8899,
9
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2644,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
961,
2032,
365,
14286,
1334,
314,
10697,
844,
14,
199,
3,
199,
3,
1898,
334,
67,
9,
6927,
8142,
87,
6796,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
1331,
199,
3,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
298,
10337,
1288,
370,
7962,
199,
3,
315,
314,
2290,
1928,
10588,
12,
5893,
1928,
12305,
314,
4481,
199,
3,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
11207,
12,
13473,
12,
436,
15,
269,
12743,
199,
3,
6866,
402,
314,
2290,
12,
436,
370,
11291,
12103,
370,
12676,
314,
2290,
365,
199,
3,
13985,
370,
886,
880,
12,
5420,
370,
314,
2569,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
315,
1006,
199,
3,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
1549,
199,
3,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
3169,
12,
199,
3,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
7000,
2334,
199,
3,
10610,
1549,
5877,
8164,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
199,
3,
5603,
12,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
199,
3,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
2334,
199,
3,
4141,
14,
199,
199,
646,
7534,
199,
646,
2050,
199,
646,
747,
199,
646,
984,
199,
646,
900,
199,
199,
646,
10142,
25617,
1258,
14,
2804,
199,
504,
10142,
25617,
1258,
14,
86,
18,
492,
1890,
465,
10142,
25617,
63,
1258,
199,
646,
13069,
1258,
14,
3924,
199,
504,
13069,
1258,
14,
86,
17,
492,
1890,
465,
13069,
63,
1258,
199,
646,
21785,
1258,
14,
2804,
199,
504,
21785,
1258,
14,
86,
17,
492,
1890,
465,
21785,
63,
1258,
199,
504,
20408,
1258,
492,
1890,
465,
20408,
63,
1258,
199,
646,
20408,
1258,
14,
8512,
14,
2330,
14,
25661,
14,
3924,
199,
504,
19395,
1258,
14,
25661,
492,
4967,
465,
2986,
63,
3924,
199,
646,
19395,
1258,
14,
8512,
14,
2330,
14,
25661,
14,
3924,
199,
504,
19395,
1258,
14,
86,
18,
63,
16,
492,
1890,
465,
19395,
63,
1258,
199,
646,
8224,
1258,
14,
2330,
14,
3924,
199,
504,
8224,
1258,
14,
86,
18,
63,
16,
492,
1890,
465,
8224,
63,
1258,
199,
646,
949,
15367,
864,
14,
3924,
199,
504,
949,
15367,
864,
14,
86,
17,
63,
17,
492,
1890,
465,
5913,
63,
1258,
199,
646,
4145,
199,
504,
16275,
1258,
492,
1890,
465,
16275,
63,
1258,
199,
199,
32528,
275,
1616,
221,
327,
20506,
282,
3145,
3439,
1616,
5431,
2544,
24234,
199,
8899,
275,
959,
257,
327,
959,
4696,
2653,
3382,
10086,
421,
199,
533,
7337,
1763,
6589,
8,
1726,
304,
272,
986,
421,
199,
533,
9599,
1403,
4667,
8,
1726,
304,
272,
986,
421,
199,
533,
6378,
11442,
8,
1726,
304,
272,
986,
421,
199,
533,
23798,
4761,
8,
1726,
304,
272,
12539,
63,
6012,
275,
499,
199,
199,
29599,
63,
12299,
63,
3170,
63,
6012,
275,
650,
421,
199,
533,
12035,
296,
4276,
8,
1726,
304,
272,
12539,
63,
6012,
275,
841,
199,
199,
18389,
63,
3170,
63,
6012,
275,
959,
199,
199,
4609,
63,
25303,
1149,
275,
1227,
421,
199,
3,
23840,
5944,
3992,
14,
199,
3,
710,
1865,
402,
314,
3232,
2340,
5944,
315,
314,
13372,
769,
199,
3,
13718,
370,
314,
1865,
315,
1314,
312,
681,
300,
303,
911,
3145,
314,
199,
3,
5944,
14,
961,
1865,
6181,
1901,
2933,
1640,
13,
4435,
199,
3,
5124,
12,
436,
11275,
370,
24720,
314,
20347,
900,
7373,
402,
314,
199,
3,
18503,
3439,
14,
199,
199,
3830,
11237,
16734,
63,
13748,
275,
788,
35,
5755,
12038,
83,
297,
2151,
283,
35,
5755,
4540,
15203,
297,
2151,
283,
19884,
23637,
297,
2151,
283,
20915,
17895,
41,
1190,
297,
2151,
283,
20915,
13081,
18018,
297,
2151,
283,
20915,
13081,
18018,
4845,
297,
2151,
283,
20915,
13081,
18018,
5065,
297,
2151,
283,
20915,
44,
66,
23056,
297,
2151,
283,
20915,
44,
66,
54,
711,
297,
2151,
283,
20915,
44,
66,
18850,
13189,
297,
2151,
283,
20915,
44,
66,
5453,
297,
2151,
283,
20915,
27937,
316,
4314,
297,
2151,
283,
20915,
18680,
297,
2151,
283,
20915,
5407,
878,
297,
2151,
283,
20915,
25573,
297,
2151,
283,
20915,
30551,
297,
2151,
283,
20915,
4933,
2634,
297,
2151,
283,
17541,
554,
18882,
297,
2151,
283,
10941,
2949,
11188,
297,
2151,
283,
10941,
2949,
31266,
1192,
297,
2151,
283,
35,
5755,
32480,
297,
2151,
283,
24417,
25617,
2439,
25005,
297,
2151,
283,
30770,
4851,
83,
418,
421,
199,
3,
13966,
269,
2750,
199,
199,
318,
7269,
8,
1364,
63,
354,
304,
272,
347,
6434,
8,
1532,
304,
267,
408,
14946,
17266,
370,
7269,
315,
1930,
402,
5988,
1041,
267,
347,
4975,
2031,
589,
12,
1011,
958,
304,
288,
302,
275,
378,
288,
1830,
715,
26,
355,
862,
26,
490,
372,
2562,
2031,
589,
12,
1011,
958,
9,
355,
871,
2186,
465,
325,
26,
490,
340,
2519,
8,
69,
12,
283,
1014,
63,
1205,
297,
756,
9,
508,
7901,
26,
717,
327,
30094,
282,
2073,
883,
506,
5463,
10250,
701,
717,
327,
17122,
587,
1830,
312,
681,
300,
303,
365,
3879,
436,
10532,
652,
14,
717,
327,
982,
642,
10986,
12,
2136,
746,
282,
15902,
14,
717,
2050,
14,
3764,
8,
1169,
298,
6049,
440,
3145,
314,
2073,
2952,
652,
1630,
440,
2,
1169,
298,
2187,
520,
450,
83,
2,
450,
325,
717,
776,
717,
327,
3091,
1929,
370,
7269,
13794,
376,
2222,
3411,
2073,
717,
2059,
490,
587,
26,
717,
340,
302,
508,
17409,
23359,
26,
1169,
746,
12035,
296,
4276,
8,
1364,
63,
354,
9,
717,
302,
847,
413,
717,
2050,
14,
815,
23124,
12035,
296,
3405,
446,
298,
3660,
298,
12989,
316,
315,
1052,
4696,
446,
298,
3660,
298,
12989,
2338,
8352,
908,
8,
8899,
12,
302,
430,
717,
900,
14,
4532,
8,
8899,
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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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
] |
samklr/mesos-cli
|
tests/integration/test_completion.py
|
2
|
2442
|
# 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 absolute_import, print_function
import os
import sys
import mock
import mesos.cli.cmds.completion
from .. import utils
def generate_env(line):
env = {
"COMP_LINE": line,
"COMP_POINT": len(line)
}
env.update(os.environ)
return env
# There are some side effects in completion. To test completers, make sure you
# use different commands. Otherwise, you'll get what appears to be random
# failures.
@mock.patch("mesos.cli.cmds.completion.EXIT", sys.exit)
class TestCompletion(utils.MockState):
@mock.patch("os.environ", generate_env("mesos "))
@mock.patch("mesos.cli.cli.cmds", lambda **kwargs: ["help"])
def test_cmds(self):
mesos.cli.cmds.completion.main()
assert "help" in self.stdout
@mock.patch("os.environ", generate_env("mesos cat "))
def test_task(self):
self.assertRaises(SystemExit, mesos.cli.cmds.completion.main)
assert "app-15" in self.stdout
assert "app-215" in self.stdout
reload(mesos.cli.cmds.cat)
@mock.patch("os.environ", generate_env("mesos state 2"))
def test_slave(self):
self.assertRaises(SystemExit, mesos.cli.cmds.completion.main)
assert len(self.stdout.split("\n")) == 2
reload(mesos.cli.cmds.state)
@mock.patch("os.environ", generate_env("mesos ls app-215 Twisted-14.0.0/"))
@mock.patch("mesos.cli.slave.MesosSlave.file_list", utils.file_list)
def test_file(self):
self.assertRaises(SystemExit, mesos.cli.cmds.completion.main)
assert "twisted/" in self.stdout
assert "NEWS" in self.stdout
reload(mesos.cli.cmds.ls)
|
apache-2.0
|
[
3,
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
199,
3,
503,
1655,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
199,
3,
1854,
543,
642,
1736,
367,
4722,
2556,
199,
3,
12602,
4248,
12715,
14,
221,
710,
14857,
12378,
642,
570,
199,
3,
370,
1265,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
199,
3,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
199,
3,
543,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
421,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
870,
63,
1593,
199,
199,
646,
747,
199,
646,
984,
199,
199,
646,
1683,
199,
199,
646,
26560,
736,
14,
2764,
14,
12975,
14,
13207,
199,
199,
504,
2508,
492,
3778,
421,
199,
318,
3550,
63,
1813,
8,
604,
304,
272,
2589,
275,
469,
267,
298,
6790,
63,
6174,
582,
1004,
12,
267,
298,
6790,
63,
7217,
582,
822,
8,
604,
9,
272,
789,
272,
2589,
14,
873,
8,
736,
14,
2314,
9,
272,
372,
2589,
421,
199,
3,
6006,
787,
2005,
5366,
22414,
315,
13659,
14,
4005,
511,
2831,
878,
12,
1852,
3238,
1265,
199,
3,
675,
3365,
3718,
14,
6630,
12,
1265,
7171,
664,
4052,
11337,
370,
506,
2196,
199,
3,
9081,
14,
199,
32,
1805,
14,
2068,
480,
6415,
736,
14,
2764,
14,
12975,
14,
13207,
14,
17219,
401,
984,
14,
2224,
9,
199,
533,
1379,
19741,
8,
1208,
14,
3346,
2223,
304,
339,
768,
1805,
14,
2068,
480,
736,
14,
2314,
401,
3550,
63,
1813,
480,
6415,
736,
26725,
272,
768,
1805,
14,
2068,
480,
6415,
736,
14,
2764,
14,
2764,
14,
12975,
401,
2400,
1011,
958,
26,
2097,
3437,
3135,
272,
347,
511,
63,
12975,
8,
277,
304,
267,
26560,
736,
14,
2764,
14,
12975,
14,
13207,
14,
973,
342,
398,
702,
298,
3437,
2,
315,
291,
14,
2703,
339,
768,
1805,
14,
2068,
480,
736,
14,
2314,
401,
3550,
63,
1813,
480,
6415,
736,
6230,
26725,
272,
347,
511,
63,
1765,
8,
277,
304,
267,
291,
14,
1855,
8,
24738,
12,
26560,
736,
14,
2764,
14,
12975,
14,
13207,
14,
973,
9,
398,
702,
298,
571,
13,
1046,
2,
315,
291,
14,
2703,
267,
702,
298,
571,
13,
7842,
2,
315,
291,
14,
2703,
398,
13101,
8,
6415,
736,
14,
2764,
14,
12975,
14,
3385,
9,
339,
768,
1805,
14,
2068,
480,
736,
14,
2314,
401,
3550,
63,
1813,
480,
6415,
736,
1174,
499,
2237,
272,
347,
511,
63,
12384,
8,
277,
304,
267,
291,
14,
1855,
8,
24738,
12,
26560,
736,
14,
2764,
14,
12975,
14,
13207,
14,
973,
9,
398,
702,
822,
8,
277,
14,
2703,
14,
1294,
4582,
78,
2237,
508,
499,
398,
13101,
8,
6415,
736,
14,
2764,
14,
12975,
14,
929,
9,
339,
768,
1805,
14,
2068,
480,
736,
14,
2314,
401,
3550,
63,
1813,
480,
6415,
736,
9100,
1145,
13,
7842,
17078,
13,
1079,
14,
16,
14,
16,
15,
2237,
272,
768,
1805,
14,
2068,
480,
6415,
736,
14,
2764,
14,
12384,
14,
45,
397,
736,
28950,
14,
493,
63,
513,
401,
3778,
14,
493,
63,
513,
9,
272,
347,
511,
63,
493,
8,
277,
304,
267,
291,
14,
1855,
8,
24738,
12,
26560,
736,
14,
2764,
14,
12975,
14,
13207,
14,
973,
9,
398,
702,
298,
12145,
6687,
315,
291,
14,
2703,
267,
702,
298,
6388,
5035,
2,
315,
291,
14,
2703,
398,
13101,
8,
6415,
736,
14,
2764,
14,
12975,
14,
478,
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
] |
[
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
199,
3,
503,
1655,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
199,
3,
1854,
543,
642,
1736,
367,
4722,
2556,
199,
3,
12602,
4248,
12715,
14,
221,
710,
14857,
12378,
642,
570,
199,
3,
370,
1265,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
199,
3,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
199,
3,
543,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
421,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
870,
63,
1593,
199,
199,
646,
747,
199,
646,
984,
199,
199,
646,
1683,
199,
199,
646,
26560,
736,
14,
2764,
14,
12975,
14,
13207,
199,
199,
504,
2508,
492,
3778,
421,
199,
318,
3550,
63,
1813,
8,
604,
304,
272,
2589,
275,
469,
267,
298,
6790,
63,
6174,
582,
1004,
12,
267,
298,
6790,
63,
7217,
582,
822,
8,
604,
9,
272,
789,
272,
2589,
14,
873,
8,
736,
14,
2314,
9,
272,
372,
2589,
421,
199,
3,
6006,
787,
2005,
5366,
22414,
315,
13659,
14,
4005,
511,
2831,
878,
12,
1852,
3238,
1265,
199,
3,
675,
3365,
3718,
14,
6630,
12,
1265,
7171,
664,
4052,
11337,
370,
506,
2196,
199,
3,
9081,
14,
199,
32,
1805,
14,
2068,
480,
6415,
736,
14,
2764,
14,
12975,
14,
13207,
14,
17219,
401,
984,
14,
2224,
9,
199,
533,
1379,
19741,
8,
1208,
14,
3346,
2223,
304,
339,
768,
1805,
14,
2068,
480,
736,
14,
2314,
401,
3550,
63,
1813,
480,
6415,
736,
26725,
272,
768,
1805,
14,
2068,
480,
6415,
736,
14,
2764,
14,
2764,
14,
12975,
401,
2400,
1011,
958,
26,
2097,
3437,
3135,
272,
347,
511,
63,
12975,
8,
277,
304,
267,
26560,
736,
14,
2764,
14,
12975,
14,
13207,
14,
973,
342,
398,
702,
298,
3437,
2,
315,
291,
14,
2703,
339,
768,
1805,
14,
2068,
480,
736,
14,
2314,
401,
3550,
63,
1813,
480,
6415,
736,
6230,
26725,
272,
347,
511,
63,
1765,
8,
277,
304,
267,
291,
14,
1855,
8,
24738,
12,
26560,
736,
14,
2764,
14,
12975,
14,
13207,
14,
973,
9,
398,
702,
298,
571,
13,
1046,
2,
315,
291,
14,
2703,
267,
702,
298,
571,
13,
7842,
2,
315,
291,
14,
2703,
398,
13101,
8,
6415,
736,
14,
2764,
14,
12975,
14,
3385,
9,
339,
768,
1805,
14,
2068,
480,
736,
14,
2314,
401,
3550,
63,
1813,
480,
6415,
736,
1174,
499,
2237,
272,
347,
511,
63,
12384,
8,
277,
304,
267,
291,
14,
1855,
8,
24738,
12,
26560,
736,
14,
2764,
14,
12975,
14,
13207,
14,
973,
9,
398,
702,
822,
8,
277,
14,
2703,
14,
1294,
4582,
78,
2237,
508,
499,
398,
13101,
8,
6415,
736,
14,
2764,
14,
12975,
14,
929,
9,
339,
768,
1805,
14,
2068,
480,
736,
14,
2314,
401,
3550,
63,
1813,
480,
6415,
736,
9100,
1145,
13,
7842,
17078,
13,
1079,
14,
16,
14,
16,
15,
2237,
272,
768,
1805,
14,
2068,
480,
6415,
736,
14,
2764,
14,
12384,
14,
45,
397,
736,
28950,
14,
493,
63,
513,
401,
3778,
14,
493,
63,
513,
9,
272,
347,
511,
63,
493,
8,
277,
304,
267,
291,
14,
1855,
8,
24738,
12,
26560,
736,
14,
2764,
14,
12975,
14,
13207,
14,
973,
9,
398,
702,
298,
12145,
6687,
315,
291,
14,
2703,
267,
702,
298,
6388,
5035,
2,
315,
291,
14,
2703,
398,
13101,
8,
6415,
736,
14,
2764,
14,
12975,
14,
478,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
mnahm5/django-estore
|
Lib/site-packages/awscli/customizations/configure/configure.py
|
1
|
5970
|
# Copyright 2016 Amazon.com, Inc. or its affiliates. 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. A copy of
# the License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file 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 os
import logging
from botocore.exceptions import ProfileNotFound
from awscli.compat import compat_input
from awscli.customizations.commands import BasicCommand
from awscli.customizations.configure.addmodel import AddModelCommand
from awscli.customizations.configure.set import ConfigureSetCommand
from awscli.customizations.configure.get import ConfigureGetCommand
from awscli.customizations.configure.list import ConfigureListCommand
from awscli.customizations.configure.writer import ConfigFileWriter
from . import mask_value
logger = logging.getLogger(__name__)
def register_configure_cmd(cli):
cli.register('building-command-table.main',
ConfigureCommand.add_command)
class InteractivePrompter(object):
def get_value(self, current_value, config_name, prompt_text=''):
if config_name in ('aws_access_key_id', 'aws_secret_access_key'):
current_value = mask_value(current_value)
response = compat_input("%s [%s]: " % (prompt_text, current_value))
if not response:
# If the user hits enter, we return a value of None
# instead of an empty string. That way we can determine
# whether or not a value has changed.
response = None
return response
class ConfigureCommand(BasicCommand):
NAME = 'configure'
DESCRIPTION = BasicCommand.FROM_FILE()
SYNOPSIS = ('aws configure [--profile profile-name]')
EXAMPLES = (
'To create a new configuration::\n'
'\n'
' $ aws configure\n'
' AWS Access Key ID [None]: accesskey\n'
' AWS Secret Access Key [None]: secretkey\n'
' Default region name [None]: us-west-2\n'
' Default output format [None]:\n'
'\n'
'To update just the region name::\n'
'\n'
' $ aws configure\n'
' AWS Access Key ID [****]:\n'
' AWS Secret Access Key [****]:\n'
' Default region name [us-west-1]: us-west-2\n'
' Default output format [None]:\n'
)
SUBCOMMANDS = [
{'name': 'list', 'command_class': ConfigureListCommand},
{'name': 'get', 'command_class': ConfigureGetCommand},
{'name': 'set', 'command_class': ConfigureSetCommand},
{'name': 'add-model', 'command_class': AddModelCommand}
]
# If you want to add new values to prompt, update this list here.
VALUES_TO_PROMPT = [
# (logical_name, config_name, prompt_text)
('aws_access_key_id', "AWS Access Key ID"),
('aws_secret_access_key', "AWS Secret Access Key"),
('region', "Default region name"),
('output', "Default output format"),
]
def __init__(self, session, prompter=None, config_writer=None):
super(ConfigureCommand, self).__init__(session)
if prompter is None:
prompter = InteractivePrompter()
self._prompter = prompter
if config_writer is None:
config_writer = ConfigFileWriter()
self._config_writer = config_writer
def _run_main(self, parsed_args, parsed_globals):
# Called when invoked with no args "aws configure"
new_values = {}
# This is the config from the config file scoped to a specific
# profile.
try:
config = self._session.get_scoped_config()
except ProfileNotFound:
config = {}
for config_name, prompt_text in self.VALUES_TO_PROMPT:
current_value = config.get(config_name)
new_value = self._prompter.get_value(current_value, config_name,
prompt_text)
if new_value is not None and new_value != current_value:
new_values[config_name] = new_value
config_filename = os.path.expanduser(
self._session.get_config_variable('config_file'))
if new_values:
self._write_out_creds_file_values(new_values,
parsed_globals.profile)
if parsed_globals.profile is not None:
new_values['__section__'] = (
'profile %s' % parsed_globals.profile)
self._config_writer.update_config(new_values, config_filename)
def _write_out_creds_file_values(self, new_values, profile_name):
# The access_key/secret_key are now *always* written to the shared
# credentials file (~/.aws/credentials), see aws/aws-cli#847.
# post-conditions: ~/.aws/credentials will have the updated credential
# file values and new_values will have the cred vars removed.
credential_file_values = {}
if 'aws_access_key_id' in new_values:
credential_file_values['aws_access_key_id'] = new_values.pop(
'aws_access_key_id')
if 'aws_secret_access_key' in new_values:
credential_file_values['aws_secret_access_key'] = new_values.pop(
'aws_secret_access_key')
if credential_file_values:
if profile_name is not None:
credential_file_values['__section__'] = profile_name
shared_credentials_filename = os.path.expanduser(
self._session.get_config_variable('credentials_file'))
self._config_writer.update_config(
credential_file_values,
shared_credentials_filename)
|
mit
|
[
3,
1898,
7800,
14347,
14,
957,
12,
3277,
14,
503,
2399,
29172,
2335,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3471,
2047,
199,
3,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
437,
1331,
402,
199,
3,
314,
844,
365,
16180,
737,
199,
3,
199,
3,
258,
1455,
921,
7231,
14,
15144,
14,
957,
15,
3796,
18,
14,
16,
15,
199,
3,
199,
3,
503,
315,
314,
298,
1682,
2,
570,
23073,
642,
570,
14,
961,
570,
365,
199,
3,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
2990,
1549,
4217,
1634,
199,
3,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
844,
367,
314,
2488,
199,
3,
2637,
4210,
3443,
436,
4204,
1334,
314,
844,
14,
199,
646,
747,
199,
646,
2050,
199,
199,
504,
21199,
14,
3924,
492,
14386,
4667,
199,
199,
504,
26936,
551,
317,
14,
5819,
492,
8434,
63,
1210,
199,
504,
26936,
551,
317,
14,
4229,
12270,
14,
4405,
492,
10082,
3110,
199,
504,
26936,
551,
317,
14,
4229,
12270,
14,
6472,
14,
525,
1238,
492,
2654,
1685,
3110,
199,
504,
26936,
551,
317,
14,
4229,
12270,
14,
6472,
14,
409,
492,
15453,
1084,
3110,
199,
504,
26936,
551,
317,
14,
4229,
12270,
14,
6472,
14,
362,
492,
15453,
1002,
3110,
199,
504,
26936,
551,
317,
14,
4229,
12270,
14,
6472,
14,
513,
492,
15453,
1296,
3110,
199,
504,
26936,
551,
317,
14,
4229,
12270,
14,
6472,
14,
5491,
492,
4094,
28199,
199,
199,
504,
1275,
492,
3656,
63,
585,
421,
199,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
318,
2274,
63,
6472,
63,
1760,
8,
2764,
304,
272,
5053,
14,
2683,
360,
17952,
13,
1531,
13,
1224,
14,
973,
297,
326,
15453,
3110,
14,
525,
63,
1531,
9,
421,
199,
533,
1010,
7502,
919,
311,
351,
8,
785,
304,
339,
347,
664,
63,
585,
8,
277,
12,
1453,
63,
585,
12,
1101,
63,
354,
12,
8457,
63,
505,
9280,
267,
340,
1101,
63,
354,
315,
661,
7231,
63,
2732,
63,
498,
63,
344,
297,
283,
7231,
63,
4731,
63,
2732,
63,
498,
735,
288,
1453,
63,
585,
275,
3656,
63,
585,
8,
1818,
63,
585,
9,
267,
1177,
275,
8434,
63,
1210,
3647,
83,
8978,
83,
2189,
298,
450,
334,
7650,
63,
505,
12,
1453,
63,
585,
430,
267,
340,
440,
1177,
26,
288,
327,
982,
314,
922,
19745,
9509,
12,
781,
372,
282,
574,
402,
488,
288,
327,
3140,
402,
376,
2701,
1059,
14,
221,
10314,
4340,
781,
883,
6705,
288,
327,
3775,
503,
440,
282,
574,
965,
2896,
14,
288,
1177,
275,
488,
267,
372,
1177,
421,
199,
533,
15453,
3110,
8,
6845,
3110,
304,
272,
13637,
275,
283,
6472,
7,
272,
17410,
1075,
275,
10082,
3110,
14,
12491,
63,
3817,
342,
272,
10046,
46,
21665,
1311,
275,
661,
7231,
7908,
19344,
2913,
4690,
13,
354,
10374,
272,
3651,
8236,
275,
334,
267,
283,
1378,
1218,
282,
892,
2897,
447,
60,
78,
7,
267,
1557,
78,
7,
267,
283,
259,
2672,
11488,
7908,
60,
78,
7,
267,
283,
259,
10168,
11003,
2606,
2870,
359,
403,
2189,
2879,
498,
60,
78,
7,
267,
283,
259,
10168,
23580,
11003,
2606,
359,
403,
2189,
7565,
498,
60,
78,
7,
267,
283,
259,
3758,
4897,
536,
359,
403,
2189,
2739,
13,
19082,
13,
18,
60,
78,
7,
267,
283,
259,
3758,
1072,
1475,
359,
403,
2189,
60,
78,
7,
267,
1557,
78,
7,
267,
283,
1378,
1678,
2951,
314,
4897,
536,
447,
60,
78,
7,
267,
1557,
78,
7,
267,
283,
259,
2672,
11488,
7908,
60,
78,
7,
267,
283,
259,
10168,
11003,
2606,
2870,
359,
1116,
2189,
60,
78,
7,
267,
283,
259,
10168,
23580,
11003,
2606,
359,
1116,
2189,
60,
78,
7,
267,
283,
259,
3758,
4897,
536,
359,
527,
13,
19082,
13,
17,
2189,
2739,
13,
19082,
13,
18,
60,
78,
7,
267,
283,
259,
3758,
1072,
1475,
359,
403,
2189,
60,
78,
7,
272,
776,
272,
7605,
28442,
275,
359,
267,
791,
354,
356,
283,
513,
297,
283,
1531,
63,
533,
356,
15453,
1296,
3110,
1386,
267,
791,
354,
356,
283,
362,
297,
283,
1531,
63,
533,
356,
15453,
1002,
3110,
1386,
267,
791,
354,
356,
283,
409,
297,
283,
1531,
63,
533,
356,
15453,
1084,
3110,
1386,
267,
791,
354,
356,
283,
525,
13,
1238,
297,
283,
1531,
63,
533,
356,
2654,
1685,
3110,
93,
272,
1622,
339,
327,
982,
1265,
2934,
370,
1050,
892,
1338,
370,
8457,
12,
1678,
642,
769,
2348,
14,
272,
13992,
63,
2566,
63,
2514,
26178,
275,
359,
267,
327,
334,
7954,
63,
354,
12,
1101,
63,
354,
12,
8457,
63,
505,
9,
267,
661,
7231,
63,
2732,
63,
498,
63,
344,
297,
298,
13226,
11003,
2606,
2870,
1288,
267,
661,
7231,
63,
4731,
63,
2732,
63,
498,
297,
298,
13226,
23580,
11003,
2606,
1288,
267,
661,
4551,
297,
298,
2698,
4897,
536,
1288,
267,
661,
1199,
297,
298,
2698,
1072,
1475,
1288,
272,
1622,
339,
347,
636,
826,
721,
277,
12,
2351,
12,
21652,
351,
29,
403,
12,
1101,
63,
5491,
29,
403,
304,
267,
1613,
8,
17324,
3110,
12,
291,
2843,
826,
721,
1730,
9,
267,
340,
21652,
351,
365,
488,
26,
288,
21652,
351,
275,
1010,
7502,
919,
311,
351,
342,
267,
291,
423,
496,
311,
351,
275,
21652,
351,
267,
340,
1101,
63,
5491,
365,
488,
26,
288,
1101,
63,
5491,
275,
4094,
28199,
342,
267,
291,
423,
888,
63,
5491,
275,
1101,
63,
5491,
339,
347,
485,
1065,
63,
973,
8,
277,
12,
4565,
63,
589,
12,
4565,
63,
8473,
304,
267,
327,
12295,
1380,
10302,
543,
949,
1249,
298,
7231,
7908,
2,
267,
892,
63,
1459,
275,
1052,
267,
327,
961,
365,
314,
1101,
687,
314,
1101,
570,
27582,
370,
282,
2488,
267,
327,
4690,
14,
267,
862,
26,
288,
1101,
275,
291,
423,
1730,
14,
362,
63,
23254,
63,
888,
342,
267,
871,
14386,
4667,
26,
288,
1101,
275,
1052,
267,
367,
1101,
63,
354,
12,
8457,
63,
505,
315,
291,
14,
15514,
63,
2566,
63,
2514,
26178,
26,
288,
1453,
63,
585,
275,
1101,
14
] |
[
1898,
7800,
14347,
14,
957,
12,
3277,
14,
503,
2399,
29172,
2335,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3471,
2047,
199,
3,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
437,
1331,
402,
199,
3,
314,
844,
365,
16180,
737,
199,
3,
199,
3,
258,
1455,
921,
7231,
14,
15144,
14,
957,
15,
3796,
18,
14,
16,
15,
199,
3,
199,
3,
503,
315,
314,
298,
1682,
2,
570,
23073,
642,
570,
14,
961,
570,
365,
199,
3,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
2990,
1549,
4217,
1634,
199,
3,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
844,
367,
314,
2488,
199,
3,
2637,
4210,
3443,
436,
4204,
1334,
314,
844,
14,
199,
646,
747,
199,
646,
2050,
199,
199,
504,
21199,
14,
3924,
492,
14386,
4667,
199,
199,
504,
26936,
551,
317,
14,
5819,
492,
8434,
63,
1210,
199,
504,
26936,
551,
317,
14,
4229,
12270,
14,
4405,
492,
10082,
3110,
199,
504,
26936,
551,
317,
14,
4229,
12270,
14,
6472,
14,
525,
1238,
492,
2654,
1685,
3110,
199,
504,
26936,
551,
317,
14,
4229,
12270,
14,
6472,
14,
409,
492,
15453,
1084,
3110,
199,
504,
26936,
551,
317,
14,
4229,
12270,
14,
6472,
14,
362,
492,
15453,
1002,
3110,
199,
504,
26936,
551,
317,
14,
4229,
12270,
14,
6472,
14,
513,
492,
15453,
1296,
3110,
199,
504,
26936,
551,
317,
14,
4229,
12270,
14,
6472,
14,
5491,
492,
4094,
28199,
199,
199,
504,
1275,
492,
3656,
63,
585,
421,
199,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
318,
2274,
63,
6472,
63,
1760,
8,
2764,
304,
272,
5053,
14,
2683,
360,
17952,
13,
1531,
13,
1224,
14,
973,
297,
326,
15453,
3110,
14,
525,
63,
1531,
9,
421,
199,
533,
1010,
7502,
919,
311,
351,
8,
785,
304,
339,
347,
664,
63,
585,
8,
277,
12,
1453,
63,
585,
12,
1101,
63,
354,
12,
8457,
63,
505,
9280,
267,
340,
1101,
63,
354,
315,
661,
7231,
63,
2732,
63,
498,
63,
344,
297,
283,
7231,
63,
4731,
63,
2732,
63,
498,
735,
288,
1453,
63,
585,
275,
3656,
63,
585,
8,
1818,
63,
585,
9,
267,
1177,
275,
8434,
63,
1210,
3647,
83,
8978,
83,
2189,
298,
450,
334,
7650,
63,
505,
12,
1453,
63,
585,
430,
267,
340,
440,
1177,
26,
288,
327,
982,
314,
922,
19745,
9509,
12,
781,
372,
282,
574,
402,
488,
288,
327,
3140,
402,
376,
2701,
1059,
14,
221,
10314,
4340,
781,
883,
6705,
288,
327,
3775,
503,
440,
282,
574,
965,
2896,
14,
288,
1177,
275,
488,
267,
372,
1177,
421,
199,
533,
15453,
3110,
8,
6845,
3110,
304,
272,
13637,
275,
283,
6472,
7,
272,
17410,
1075,
275,
10082,
3110,
14,
12491,
63,
3817,
342,
272,
10046,
46,
21665,
1311,
275,
661,
7231,
7908,
19344,
2913,
4690,
13,
354,
10374,
272,
3651,
8236,
275,
334,
267,
283,
1378,
1218,
282,
892,
2897,
447,
60,
78,
7,
267,
1557,
78,
7,
267,
283,
259,
2672,
11488,
7908,
60,
78,
7,
267,
283,
259,
10168,
11003,
2606,
2870,
359,
403,
2189,
2879,
498,
60,
78,
7,
267,
283,
259,
10168,
23580,
11003,
2606,
359,
403,
2189,
7565,
498,
60,
78,
7,
267,
283,
259,
3758,
4897,
536,
359,
403,
2189,
2739,
13,
19082,
13,
18,
60,
78,
7,
267,
283,
259,
3758,
1072,
1475,
359,
403,
2189,
60,
78,
7,
267,
1557,
78,
7,
267,
283,
1378,
1678,
2951,
314,
4897,
536,
447,
60,
78,
7,
267,
1557,
78,
7,
267,
283,
259,
2672,
11488,
7908,
60,
78,
7,
267,
283,
259,
10168,
11003,
2606,
2870,
359,
1116,
2189,
60,
78,
7,
267,
283,
259,
10168,
23580,
11003,
2606,
359,
1116,
2189,
60,
78,
7,
267,
283,
259,
3758,
4897,
536,
359,
527,
13,
19082,
13,
17,
2189,
2739,
13,
19082,
13,
18,
60,
78,
7,
267,
283,
259,
3758,
1072,
1475,
359,
403,
2189,
60,
78,
7,
272,
776,
272,
7605,
28442,
275,
359,
267,
791,
354,
356,
283,
513,
297,
283,
1531,
63,
533,
356,
15453,
1296,
3110,
1386,
267,
791,
354,
356,
283,
362,
297,
283,
1531,
63,
533,
356,
15453,
1002,
3110,
1386,
267,
791,
354,
356,
283,
409,
297,
283,
1531,
63,
533,
356,
15453,
1084,
3110,
1386,
267,
791,
354,
356,
283,
525,
13,
1238,
297,
283,
1531,
63,
533,
356,
2654,
1685,
3110,
93,
272,
1622,
339,
327,
982,
1265,
2934,
370,
1050,
892,
1338,
370,
8457,
12,
1678,
642,
769,
2348,
14,
272,
13992,
63,
2566,
63,
2514,
26178,
275,
359,
267,
327,
334,
7954,
63,
354,
12,
1101,
63,
354,
12,
8457,
63,
505,
9,
267,
661,
7231,
63,
2732,
63,
498,
63,
344,
297,
298,
13226,
11003,
2606,
2870,
1288,
267,
661,
7231,
63,
4731,
63,
2732,
63,
498,
297,
298,
13226,
23580,
11003,
2606,
1288,
267,
661,
4551,
297,
298,
2698,
4897,
536,
1288,
267,
661,
1199,
297,
298,
2698,
1072,
1475,
1288,
272,
1622,
339,
347,
636,
826,
721,
277,
12,
2351,
12,
21652,
351,
29,
403,
12,
1101,
63,
5491,
29,
403,
304,
267,
1613,
8,
17324,
3110,
12,
291,
2843,
826,
721,
1730,
9,
267,
340,
21652,
351,
365,
488,
26,
288,
21652,
351,
275,
1010,
7502,
919,
311,
351,
342,
267,
291,
423,
496,
311,
351,
275,
21652,
351,
267,
340,
1101,
63,
5491,
365,
488,
26,
288,
1101,
63,
5491,
275,
4094,
28199,
342,
267,
291,
423,
888,
63,
5491,
275,
1101,
63,
5491,
339,
347,
485,
1065,
63,
973,
8,
277,
12,
4565,
63,
589,
12,
4565,
63,
8473,
304,
267,
327,
12295,
1380,
10302,
543,
949,
1249,
298,
7231,
7908,
2,
267,
892,
63,
1459,
275,
1052,
267,
327,
961,
365,
314,
1101,
687,
314,
1101,
570,
27582,
370,
282,
2488,
267,
327,
4690,
14,
267,
862,
26,
288,
1101,
275,
291,
423,
1730,
14,
362,
63,
23254,
63,
888,
342,
267,
871,
14386,
4667,
26,
288,
1101,
275,
1052,
267,
367,
1101,
63,
354,
12,
8457,
63,
505,
315,
291,
14,
15514,
63,
2566,
63,
2514,
26178,
26,
288,
1453,
63,
585,
275,
1101,
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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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
] |
mihirskulkarni/Marathi_entropy
|
vishwakosh_book.py
|
1
|
2497
|
"""This file downloads a particular volume of Marathi Vishwakosh (https://marathivishwakosh.maharashtra.gov.in/) and saves the pages spread across twenty files using a modulo of 20 to the number of Vishkosh page entry.
Run using 'python vishwkosh_book.py volume' from terminal where volume is the Volume of Vishwakosh you want to download, which ranges from 1-20. """
from bs4 import BeautifulSoup
import urllib, collections, codecs, ssl
import numpy as np
import re
import sys
from urlparse import urljoin
vol = str(sys.argv[1])
context = ssl._create_unverified_context()
base_url = 'https://marathivishwakosh.maharashtra.gov.in/khandas/khand'+vol+'/index.php'
for i in range(20):
locals()['f'+str(i)] = codecs.open('vishwakosh_books_'+str(i)+'.txt','a','utf-8')
#f = codecs.open('vishwakosh_books.txt','w','utf-8')
links = []
url1 = 'https://marathivishwakosh.maharashtra.gov.in/khandas/khand'+vol+'/'
html1 = urllib.urlopen(url1,context=context).read()
soup1 = BeautifulSoup(html1)
for link in soup1.findAll('a',href=re.compile('index.php')):
links.append(link['href'])
count = 0
for i in range(len(links)):
print i
print links[i]
#url = "https://marathivishwakosh.maharashtra.gov.in/khandas/khand1/index.php/component/content/article?id="+str(i)
#url = base_url + links[i]
url = urljoin(base_url, links[i])
html = urllib.urlopen(url,context=context).read()
#if html == blank:
# continue
page = str(html)
number = page.find('\xe0\xa4\xaa\xe0\xa5\x82\xe0\xa4\xb0\xe0\xa5\x8d\xe0\xa4\xa3 \xe0\xa4\xa8\xe0\xa5\x8b\xe0\xa4\x82\xe0\xa4\xa6 \xe0\xa4\xaa\xe0\xa4\xb9\xe0\xa4\xbe')
if number != -1:
print 'Using whole page'
page2 = page[number-200:number]
linklist = [i for i in page2.split() if i.startswith('href')][0]
link = [i for i in linklist.split('"') if i.startswith('/khandas')][0]
#url = base_url + link
url = urljoin(base_url, link)
html = urllib.urlopen(url,context=context).read()
h1 = html.find('article-info-term')
if h1 != -1:
h2 = html.find('MVishwakosh')
if h2 != -1:
html = html[h1:h2]
soup = BeautifulSoup(html)
text = soup.get_text()
count += 1
print 'count', count
locals()['f'+str(np.mod(count,20))].write(text)
# else:
# pass
# else:
# pass
#print text
#f.close()
for i in range(20):
locals()['f'+str(i)].close()
|
mit
|
[
624,
2765,
570,
28242,
282,
6770,
3301,
402,
16794,
1619,
73,
812,
2453,
758,
7697,
609,
334,
2859,
921,
4584,
1619,
1003,
2453,
758,
7697,
609,
14,
391,
8210,
305,
517,
345,
14,
16294,
14,
262,
24793,
436,
23050,
314,
6497,
308,
8984,
9371,
8900,
287,
369,
1584,
1808,
282,
27656,
402,
3388,
370,
314,
1329,
402,
812,
2453,
7697,
609,
2034,
2397,
14,
199,
199,
2540,
1808,
283,
1548,
373,
2453,
87,
7697,
609,
63,
2706,
14,
647,
3301,
7,
687,
11167,
2382,
3301,
365,
314,
15018,
402,
812,
2453,
758,
7697,
609,
1265,
2934,
370,
5235,
12,
1314,
12271,
687,
413,
13,
1165,
14,
408,
199,
504,
9922,
20,
492,
17132,
199,
646,
4011,
12,
5055,
12,
6010,
12,
6149,
199,
646,
2680,
465,
980,
199,
646,
295,
199,
646,
984,
199,
504,
7097,
492,
20818,
199,
199,
5650,
275,
620,
8,
1274,
14,
3020,
59,
17,
566,
199,
1100,
275,
6149,
423,
981,
63,
324,
12949,
63,
1100,
342,
199,
1095,
63,
633,
275,
283,
2859,
921,
4584,
1619,
1003,
2453,
758,
7697,
609,
14,
391,
8210,
305,
517,
345,
14,
16294,
14,
262,
15,
75,
6868,
305,
15,
75,
6868,
6828,
5650,
23164,
1080,
14,
8624,
7,
199,
509,
284,
315,
1425,
8,
1165,
304,
272,
9480,
12047,
70,
6828,
495,
8,
73,
1874,
275,
6010,
14,
1490,
360,
86,
2453,
758,
7697,
609,
63,
8858,
20013,
495,
8,
73,
6393,
1370,
2424,
1673,
65,
1673,
1624,
13,
24,
358,
199,
3,
70,
275,
6010,
14,
1490,
360,
86,
2453,
758,
7697,
609,
63,
8858,
14,
2424,
1673,
87,
1673,
1624,
13,
24,
358,
199,
4614,
275,
942,
199,
633,
17,
275,
283,
2859,
921,
4584,
1619,
1003,
2453,
758,
7697,
609,
14,
391,
8210,
305,
517,
345,
14,
16294,
14,
262,
15,
75,
6868,
305,
15,
75,
6868,
6828,
5650,
4786,
4805,
199,
1360,
17,
275,
4011,
14,
10890,
8,
633,
17,
12,
1100,
29,
1100,
680,
739,
342,
199,
9317,
17,
275,
17132,
8,
1360,
17,
9,
199,
199,
509,
2142,
315,
9108,
17,
14,
32651,
360,
65,
297,
6399,
29,
264,
14,
2014,
360,
1080,
14,
8624,
8109,
272,
6220,
14,
740,
8,
1073,
459,
6399,
1105,
199,
835,
275,
378,
199,
509,
284,
315,
1425,
8,
552,
8,
4614,
2298,
272,
870,
284,
272,
870,
6220,
59,
73,
61,
272,
327,
633,
275,
298,
2859,
921,
4584,
1619,
1003,
2453,
758,
7697,
609,
14,
391,
8210,
305,
517,
345,
14,
16294,
14,
262,
15,
75,
6868,
305,
15,
75,
6868,
17,
15,
1080,
14,
8624,
15,
3173,
15,
1317,
15,
6934,
31,
344,
16368,
495,
8,
73,
9,
272,
327,
633,
275,
1300,
63,
633,
435,
6220,
59,
73,
61,
272,
1166,
275,
20818,
8,
1095,
63,
633,
12,
6220,
59,
73,
566,
272,
3517,
275,
4011,
14,
10890,
8,
633,
12,
1100,
29,
1100,
680,
739,
342,
272,
327,
692,
3517,
508,
4596,
26,
272,
327,
259,
1980,
272,
2034,
275,
620,
8,
1360,
9,
272,
1329,
275,
2034,
14,
1623,
2258,
1845,
16,
60,
1800,
20,
60,
10117,
60,
1845,
16,
60,
1800,
21,
60,
88,
2564,
60,
1845,
16,
60,
1800,
20,
60,
1774,
16,
60,
1845,
16,
60,
1800,
21,
60,
88,
24,
68,
60,
1845,
16,
60,
1800,
20,
60,
1800,
19,
971,
1845,
16,
60,
1800,
20,
60,
1800,
24,
60,
1845,
16,
60,
1800,
21,
60,
88,
24,
66,
60,
1845,
16,
60,
1800,
20,
60,
88,
2564,
60,
1845,
16,
60,
1800,
20,
60,
1800,
22,
971,
1845,
16,
60,
1800,
20,
60,
10117,
60,
1845,
16,
60,
1800,
20,
60,
1774,
25,
60,
1845,
16,
60,
1800,
20,
60,
9957,
358,
272,
340,
1329,
1137,
446,
17,
26,
267,
870,
283,
10369,
8852,
2034,
7,
267,
2034,
18,
275,
2034,
59,
1955,
13,
1840,
26,
1955,
61,
267,
2142,
513,
275,
359,
73,
367,
284,
315,
2034,
18,
14,
1294,
342,
340,
284,
14,
2460,
360,
6399,
358,
1527,
16,
61,
267,
2142,
275,
359,
73,
367,
284,
315,
2142,
513,
14,
1294,
25441,
340,
284,
14,
2460,
2336,
75,
6868,
305,
358,
1527,
16,
61,
267,
327,
633,
275,
1300,
63,
633,
435,
2142,
267,
1166,
275,
20818,
8,
1095,
63,
633,
12,
2142,
9,
267,
3517,
275,
4011,
14,
10890,
8,
633,
12,
1100,
29,
1100,
680,
739,
342,
272,
394,
17,
275,
3517,
14,
1623,
360,
6934,
13,
815,
13,
5125,
358,
272,
340,
394,
17,
1137,
446,
17,
26,
267,
394,
18,
275,
3517,
14,
1623,
360,
25875,
2453,
758,
7697,
609,
358,
267,
340,
394,
18,
1137,
446,
17,
26,
288,
3517,
275,
3517,
59,
72,
17,
26,
72,
18,
61,
288,
9108,
275,
17132,
8,
1360,
9,
288,
1318,
275,
9108,
14,
362,
63,
505,
342,
288,
2338,
847,
413,
288,
870,
283,
835,
297,
2338,
288,
9480,
12047,
70,
6828,
495,
8,
1590,
14,
1494,
8,
835,
12,
1165,
430,
1055,
952,
8,
505,
9,
1467,
199,
3,
263,
587,
26,
199,
3,
3322,
986,
199,
3,
259,
587,
26,
199,
3,
263,
986,
267,
327,
1361,
1318,
199,
199,
3,
70,
14,
1600,
342,
199,
509,
284,
315,
1425,
8,
1165,
304,
272,
9480,
12047,
70,
6828,
495,
8,
73,
22509,
1600,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2765,
570,
28242,
282,
6770,
3301,
402,
16794,
1619,
73,
812,
2453,
758,
7697,
609,
334,
2859,
921,
4584,
1619,
1003,
2453,
758,
7697,
609,
14,
391,
8210,
305,
517,
345,
14,
16294,
14,
262,
24793,
436,
23050,
314,
6497,
308,
8984,
9371,
8900,
287,
369,
1584,
1808,
282,
27656,
402,
3388,
370,
314,
1329,
402,
812,
2453,
7697,
609,
2034,
2397,
14,
199,
199,
2540,
1808,
283,
1548,
373,
2453,
87,
7697,
609,
63,
2706,
14,
647,
3301,
7,
687,
11167,
2382,
3301,
365,
314,
15018,
402,
812,
2453,
758,
7697,
609,
1265,
2934,
370,
5235,
12,
1314,
12271,
687,
413,
13,
1165,
14,
408,
199,
504,
9922,
20,
492,
17132,
199,
646,
4011,
12,
5055,
12,
6010,
12,
6149,
199,
646,
2680,
465,
980,
199,
646,
295,
199,
646,
984,
199,
504,
7097,
492,
20818,
199,
199,
5650,
275,
620,
8,
1274,
14,
3020,
59,
17,
566,
199,
1100,
275,
6149,
423,
981,
63,
324,
12949,
63,
1100,
342,
199,
1095,
63,
633,
275,
283,
2859,
921,
4584,
1619,
1003,
2453,
758,
7697,
609,
14,
391,
8210,
305,
517,
345,
14,
16294,
14,
262,
15,
75,
6868,
305,
15,
75,
6868,
6828,
5650,
23164,
1080,
14,
8624,
7,
199,
509,
284,
315,
1425,
8,
1165,
304,
272,
9480,
12047,
70,
6828,
495,
8,
73,
1874,
275,
6010,
14,
1490,
360,
86,
2453,
758,
7697,
609,
63,
8858,
20013,
495,
8,
73,
6393,
1370,
2424,
1673,
65,
1673,
1624,
13,
24,
358,
199,
3,
70,
275,
6010,
14,
1490,
360,
86,
2453,
758,
7697,
609,
63,
8858,
14,
2424,
1673,
87,
1673,
1624,
13,
24,
358,
199,
4614,
275,
942,
199,
633,
17,
275,
283,
2859,
921,
4584,
1619,
1003,
2453,
758,
7697,
609,
14,
391,
8210,
305,
517,
345,
14,
16294,
14,
262,
15,
75,
6868,
305,
15,
75,
6868,
6828,
5650,
4786,
4805,
199,
1360,
17,
275,
4011,
14,
10890,
8,
633,
17,
12,
1100,
29,
1100,
680,
739,
342,
199,
9317,
17,
275,
17132,
8,
1360,
17,
9,
199,
199,
509,
2142,
315,
9108,
17,
14,
32651,
360,
65,
297,
6399,
29,
264,
14,
2014,
360,
1080,
14,
8624,
8109,
272,
6220,
14,
740,
8,
1073,
459,
6399,
1105,
199,
835,
275,
378,
199,
509,
284,
315,
1425,
8,
552,
8,
4614,
2298,
272,
870,
284,
272,
870,
6220,
59,
73,
61,
272,
327,
633,
275,
298,
2859,
921,
4584,
1619,
1003,
2453,
758,
7697,
609,
14,
391,
8210,
305,
517,
345,
14,
16294,
14,
262,
15,
75,
6868,
305,
15,
75,
6868,
17,
15,
1080,
14,
8624,
15,
3173,
15,
1317,
15,
6934,
31,
344,
16368,
495,
8,
73,
9,
272,
327,
633,
275,
1300,
63,
633,
435,
6220,
59,
73,
61,
272,
1166,
275,
20818,
8,
1095,
63,
633,
12,
6220,
59,
73,
566,
272,
3517,
275,
4011,
14,
10890,
8,
633,
12,
1100,
29,
1100,
680,
739,
342,
272,
327,
692,
3517,
508,
4596,
26,
272,
327,
259,
1980,
272,
2034,
275,
620,
8,
1360,
9,
272,
1329,
275,
2034,
14,
1623,
2258,
1845,
16,
60,
1800,
20,
60,
10117,
60,
1845,
16,
60,
1800,
21,
60,
88,
2564,
60,
1845,
16,
60,
1800,
20,
60,
1774,
16,
60,
1845,
16,
60,
1800,
21,
60,
88,
24,
68,
60,
1845,
16,
60,
1800,
20,
60,
1800,
19,
971,
1845,
16,
60,
1800,
20,
60,
1800,
24,
60,
1845,
16,
60,
1800,
21,
60,
88,
24,
66,
60,
1845,
16,
60,
1800,
20,
60,
88,
2564,
60,
1845,
16,
60,
1800,
20,
60,
1800,
22,
971,
1845,
16,
60,
1800,
20,
60,
10117,
60,
1845,
16,
60,
1800,
20,
60,
1774,
25,
60,
1845,
16,
60,
1800,
20,
60,
9957,
358,
272,
340,
1329,
1137,
446,
17,
26,
267,
870,
283,
10369,
8852,
2034,
7,
267,
2034,
18,
275,
2034,
59,
1955,
13,
1840,
26,
1955,
61,
267,
2142,
513,
275,
359,
73,
367,
284,
315,
2034,
18,
14,
1294,
342,
340,
284,
14,
2460,
360,
6399,
358,
1527,
16,
61,
267,
2142,
275,
359,
73,
367,
284,
315,
2142,
513,
14,
1294,
25441,
340,
284,
14,
2460,
2336,
75,
6868,
305,
358,
1527,
16,
61,
267,
327,
633,
275,
1300,
63,
633,
435,
2142,
267,
1166,
275,
20818,
8,
1095,
63,
633,
12,
2142,
9,
267,
3517,
275,
4011,
14,
10890,
8,
633,
12,
1100,
29,
1100,
680,
739,
342,
272,
394,
17,
275,
3517,
14,
1623,
360,
6934,
13,
815,
13,
5125,
358,
272,
340,
394,
17,
1137,
446,
17,
26,
267,
394,
18,
275,
3517,
14,
1623,
360,
25875,
2453,
758,
7697,
609,
358,
267,
340,
394,
18,
1137,
446,
17,
26,
288,
3517,
275,
3517,
59,
72,
17,
26,
72,
18,
61,
288,
9108,
275,
17132,
8,
1360,
9,
288,
1318,
275,
9108,
14,
362,
63,
505,
342,
288,
2338,
847,
413,
288,
870,
283,
835,
297,
2338,
288,
9480,
12047,
70,
6828,
495,
8,
1590,
14,
1494,
8,
835,
12,
1165,
430,
1055,
952,
8,
505,
9,
1467,
199,
3,
263,
587,
26,
199,
3,
3322,
986,
199,
3,
259,
587,
26,
199,
3,
263,
986,
267,
327,
1361,
1318,
199,
199,
3,
70,
14,
1600,
342,
199,
509,
284,
315,
1425,
8,
1165,
304,
272,
9480,
12047,
70,
6828,
495,
8,
73,
22509,
1600,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ProfessorX/Config
|
.PyCharm30/system/python_stubs/-1247972723/gtk/_gtk/Button.py
|
1
|
10341
|
# encoding: utf-8
# module gtk._gtk
# from /usr/lib/python2.7/dist-packages/gtk-2.0/gtk/_gtk.so
# by generator 1.135
# no doc
# imports
import atk as __atk
import gio as __gio
import gobject as __gobject
import gobject._gobject as __gobject__gobject
from Bin import Bin
from Activatable import Activatable
class Button(Bin, Activatable):
"""
Object GtkButton
Signals from GtkButton:
activate ()
pressed ()
released ()
clicked ()
enter ()
leave ()
Properties from GtkButton:
label -> gchararray: Label
Text of the label widget inside the button, if the button contains a label widget
image -> GtkWidget: Image widget
Child widget to appear next to the button text
relief -> GtkReliefStyle: Border relief
The border relief style
use-underline -> gboolean: Use underline
If set, an underline in the text indicates the next character should be used for the mnemonic accelerator key
use-stock -> gboolean: Use stock
If set, the label is used to pick a stock item instead of being displayed
focus-on-click -> gboolean: Focus on click
Whether the button grabs focus when it is clicked with the mouse
xalign -> gfloat: Horizontal alignment for child
Horizontal position of child in available space. 0.0 is left aligned, 1.0 is right aligned
yalign -> gfloat: Vertical alignment for child
Vertical position of child in available space. 0.0 is top aligned, 1.0 is bottom aligned
image-position -> GtkPositionType: Image position
The position of the image relative to the text
Signals from GtkContainer:
add (GtkWidget)
remove (GtkWidget)
check-resize ()
set-focus-child (GtkWidget)
Properties from GtkContainer:
border-width -> guint: Border width
The width of the empty border outside the containers children
resize-mode -> GtkResizeMode: Resize mode
Specify how resize events are handled
child -> GtkWidget: Child
Can be used to add a new child to the container
Signals from GtkWidget:
composited-changed ()
show ()
hide ()
map ()
unmap ()
realize ()
unrealize ()
size-request (GtkRequisition)
size-allocate (GdkRectangle)
state-changed (GtkStateType)
parent-set (GtkWidget)
hierarchy-changed (GtkWidget)
style-set (GtkStyle)
direction-changed (GtkTextDirection)
grab-notify (gboolean)
child-notify (GParam)
mnemonic-activate (gboolean) -> gboolean
grab-focus ()
focus (GtkDirectionType) -> gboolean
move-focus (GtkDirectionType)
event (GdkEvent) -> gboolean
event-after (GdkEvent)
button-press-event (GdkEvent) -> gboolean
button-release-event (GdkEvent) -> gboolean
scroll-event (GdkEvent) -> gboolean
motion-notify-event (GdkEvent) -> gboolean
keynav-failed (GtkDirectionType) -> gboolean
delete-event (GdkEvent) -> gboolean
destroy-event (GdkEvent) -> gboolean
expose-event (GdkEvent) -> gboolean
key-press-event (GdkEvent) -> gboolean
key-release-event (GdkEvent) -> gboolean
enter-notify-event (GdkEvent) -> gboolean
leave-notify-event (GdkEvent) -> gboolean
configure-event (GdkEvent) -> gboolean
focus-in-event (GdkEvent) -> gboolean
focus-out-event (GdkEvent) -> gboolean
map-event (GdkEvent) -> gboolean
unmap-event (GdkEvent) -> gboolean
property-notify-event (GdkEvent) -> gboolean
selection-clear-event (GdkEvent) -> gboolean
selection-request-event (GdkEvent) -> gboolean
selection-notify-event (GdkEvent) -> gboolean
selection-received (GtkSelectionData, guint)
selection-get (GtkSelectionData, guint, guint)
proximity-in-event (GdkEvent) -> gboolean
proximity-out-event (GdkEvent) -> gboolean
drag-leave (GdkDragContext, guint)
drag-begin (GdkDragContext)
drag-end (GdkDragContext)
drag-data-delete (GdkDragContext)
drag-failed (GdkDragContext, GtkDragResult) -> gboolean
drag-motion (GdkDragContext, gint, gint, guint) -> gboolean
drag-drop (GdkDragContext, gint, gint, guint) -> gboolean
drag-data-get (GdkDragContext, GtkSelectionData, guint, guint)
drag-data-received (GdkDragContext, gint, gint, GtkSelectionData, guint, guint)
visibility-notify-event (GdkEvent) -> gboolean
client-event (GdkEvent) -> gboolean
no-expose-event (GdkEvent) -> gboolean
window-state-event (GdkEvent) -> gboolean
damage-event (GdkEvent) -> gboolean
grab-broken-event (GdkEvent) -> gboolean
query-tooltip (gint, gint, gboolean, GtkTooltip) -> gboolean
popup-menu () -> gboolean
show-help (GtkWidgetHelpType) -> gboolean
accel-closures-changed ()
screen-changed (GdkScreen)
can-activate-accel (guint) -> gboolean
Properties from GtkWidget:
name -> gchararray: Widget name
The name of the widget
parent -> GtkContainer: Parent widget
The parent widget of this widget. Must be a Container widget
width-request -> gint: Width request
Override for width request of the widget, or -1 if natural request should be used
height-request -> gint: Height request
Override for height request of the widget, or -1 if natural request should be used
visible -> gboolean: Visible
Whether the widget is visible
sensitive -> gboolean: Sensitive
Whether the widget responds to input
app-paintable -> gboolean: Application paintable
Whether the application will paint directly on the widget
can-focus -> gboolean: Can focus
Whether the widget can accept the input focus
has-focus -> gboolean: Has focus
Whether the widget has the input focus
is-focus -> gboolean: Is focus
Whether the widget is the focus widget within the toplevel
can-default -> gboolean: Can default
Whether the widget can be the default widget
has-default -> gboolean: Has default
Whether the widget is the default widget
receives-default -> gboolean: Receives default
If TRUE, the widget will receive the default action when it is focused
composite-child -> gboolean: Composite child
Whether the widget is part of a composite widget
style -> GtkStyle: Style
The style of the widget, which contains information about how it will look (colors etc)
events -> GdkEventMask: Events
The event mask that decides what kind of GdkEvents this widget gets
extension-events -> GdkExtensionMode: Extension events
The mask that decides what kind of extension events this widget gets
no-show-all -> gboolean: No show all
Whether gtk_widget_show_all() should not affect this widget
has-tooltip -> gboolean: Has tooltip
Whether this widget has a tooltip
tooltip-markup -> gchararray: Tooltip markup
The contents of the tooltip for this widget
tooltip-text -> gchararray: Tooltip Text
The contents of the tooltip for this widget
window -> GdkWindow: Window
The widget's window if it is realized
double-buffered -> gboolean: Double Buffered
Whether or not the widget is double buffered
Signals from GtkObject:
destroy ()
Properties from GtkObject:
user-data -> gpointer: User Data
Anonymous User Data Pointer
Signals from GObject:
notify (GParam)
"""
def clicked(self, *args, **kwargs): # real signature unknown
pass
@classmethod
def do_activate(cls, *args, **kwargs): # real signature unknown
pass
@classmethod
def do_clicked(cls, *args, **kwargs): # real signature unknown
pass
@classmethod
def do_enter(cls, *args, **kwargs): # real signature unknown
pass
@classmethod
def do_leave(cls, *args, **kwargs): # real signature unknown
pass
@classmethod
def do_pressed(cls, *args, **kwargs): # real signature unknown
pass
@classmethod
def do_released(cls, *args, **kwargs): # real signature unknown
pass
def enter(self, *args, **kwargs): # real signature unknown
pass
def get_alignment(self, *args, **kwargs): # real signature unknown
pass
def get_event_window(self, *args, **kwargs): # real signature unknown
pass
def get_focus_on_click(self, *args, **kwargs): # real signature unknown
pass
def get_image(self, *args, **kwargs): # real signature unknown
pass
def get_image_position(self, *args, **kwargs): # real signature unknown
pass
def get_label(self, *args, **kwargs): # real signature unknown
pass
def get_relief(self, *args, **kwargs): # real signature unknown
pass
def get_use_stock(self, *args, **kwargs): # real signature unknown
pass
def get_use_underline(self, *args, **kwargs): # real signature unknown
pass
def leave(self, *args, **kwargs): # real signature unknown
pass
def pressed(self, *args, **kwargs): # real signature unknown
pass
def released(self, *args, **kwargs): # real signature unknown
pass
def set_alignment(self, *args, **kwargs): # real signature unknown
pass
def set_focus_on_click(self, *args, **kwargs): # real signature unknown
pass
def set_image(self, *args, **kwargs): # real signature unknown
pass
def set_image_position(self, *args, **kwargs): # real signature unknown
pass
def set_label(self, *args, **kwargs): # real signature unknown
pass
def set_relief(self, *args, **kwargs): # real signature unknown
pass
def set_use_stock(self, *args, **kwargs): # real signature unknown
pass
def set_use_underline(self, *args, **kwargs): # real signature unknown
pass
def __init__(self, *args, **kwargs): # real signature unknown
pass
def __iter__(self): # real signature unknown; restored from __doc__
""" x.__iter__() <==> iter(x) """
pass
__gtype__ = None # (!) real value is ''
|
gpl-2.0
|
[
3,
2644,
26,
2774,
13,
24,
199,
3,
859,
8116,
423,
12275,
199,
3,
687,
1182,
2647,
15,
773,
15,
1548,
18,
14,
23,
15,
2686,
13,
5154,
15,
12275,
13,
18,
14,
16,
15,
12275,
15607,
12275,
14,
1152,
199,
3,
701,
4306,
413,
14,
8312,
199,
3,
949,
1382,
199,
199,
3,
8925,
199,
646,
737,
75,
465,
636,
292,
75,
199,
646,
486,
2308,
465,
636,
71,
2308,
199,
646,
25595,
465,
636,
71,
785,
199,
646,
25595,
423,
71,
785,
465,
636,
71,
785,
363,
71,
785,
421,
199,
504,
32613,
492,
32613,
199,
199,
504,
21904,
86,
15511,
492,
21904,
86,
15511,
199,
199,
533,
16005,
8,
13394,
12,
21904,
86,
15511,
304,
272,
408,
272,
6935,
11424,
4259,
2286,
6632,
2551,
687,
11424,
4259,
26,
489,
15422,
6248,
489,
25167,
6248,
489,
14286,
6248,
489,
28614,
6248,
489,
9509,
6248,
489,
10137,
6248,
2286,
19329,
687,
11424,
4259,
26,
489,
1768,
1035,
486,
1560,
1144,
26,
10354,
267,
4516,
402,
314,
1768,
3938,
6272,
314,
5528,
12,
340,
314,
5528,
3509,
282,
1768,
3938,
489,
1834,
1035,
11424,
3339,
26,
6047,
3938,
267,
12988,
3938,
370,
7468,
2163,
370,
314,
5528,
1318,
489,
28958,
1035,
11424,
497,
317,
2829,
6609,
26,
699,
1648,
28958,
267,
710,
9162,
28958,
3449,
489,
675,
13,
24396,
1035,
486,
4871,
26,
3645,
25735,
267,
982,
663,
12,
376,
25735,
315,
314,
1318,
9126,
314,
2163,
4528,
1077,
506,
1202,
367,
314,
18250,
16082,
1066,
27139,
790,
489,
675,
13,
6088,
1035,
486,
4871,
26,
3645,
10952,
267,
982,
663,
12,
314,
1768,
365,
1202,
370,
3732,
282,
10952,
1242,
3140,
402,
3769,
9080,
489,
16470,
13,
265,
13,
4891,
1035,
486,
4871,
26,
481,
10763,
641,
8968,
267,
7480,
314,
5528,
1999,
1533,
16470,
1380,
652,
365,
28614,
543,
314,
12817,
489,
671,
5743,
1035,
486,
1609,
26,
869,
7550,
13177,
367,
1982,
267,
869,
7550,
3421,
402,
1982,
315,
2808,
4601,
14,
378,
14,
16,
365,
3602,
22569,
12,
413,
14,
16,
365,
2451,
22569,
489,
612,
5743,
1035,
486,
1609,
26,
5444,
3294,
13177,
367,
1982,
267,
5444,
3294,
3421,
402,
1982,
315,
2808,
4601,
14,
378,
14,
16,
365,
2746,
22569,
12,
413,
14,
16,
365,
9048,
22569,
489,
1834,
13,
3124,
1035,
11424,
5625,
804,
26,
6047,
3421,
267,
710,
3421,
402,
314,
1834,
3847,
370,
314,
1318,
2286,
6632,
2551,
687,
11424,
4076,
26,
489,
1050,
334,
18891,
3339,
9,
489,
2813,
334,
18891,
3339,
9,
489,
1104,
13,
8709,
6248,
489,
663,
13,
12283,
13,
1739,
334,
18891,
3339,
9,
2286,
19329,
687,
11424,
4076,
26,
489,
9162,
13,
2063,
1035,
486,
1635,
26,
699,
1648,
3462,
267,
710,
3462,
402,
314,
2701,
9162,
9682,
314,
15333,
4978,
489,
15210,
13,
632,
1035,
11424,
24559,
1385,
26,
799,
890,
818,
267,
13327,
4212,
15210,
4474,
787,
8860,
489,
1982,
1035,
11424,
3339,
26,
12988,
267,
6855,
506,
1202,
370,
1050,
282,
892,
1982,
370,
314,
3970,
2286,
6632,
2551,
687,
11424,
3339,
26,
489,
11395,
11669,
13,
2489,
6248,
489,
2498,
6248,
489,
13714,
6248,
489,
2341,
6248,
489,
625,
1130,
6248,
489,
3363,
794,
6248,
489,
625,
3093,
794,
6248,
489,
1568,
13,
1069,
334,
18891,
497,
21523,
9,
489,
1568,
13,
12991,
334,
39,
6341,
18127,
9,
489,
1174,
13,
2489,
334,
18891,
2223,
804,
9,
489,
1676,
13,
409,
334,
18891,
3339,
9,
489,
14446,
13,
2489,
334,
18891,
3339,
9,
489,
3449,
13,
409,
334,
18891,
6609,
9,
489,
7581,
13,
2489,
334,
18891,
1872,
17015,
9,
489,
18200,
13,
6814,
334,
71,
4871,
9,
489,
1982,
13,
6814,
334,
39,
4098,
9,
489,
18250,
16082,
13,
8222,
334,
71,
4871,
9,
1035,
486,
4871,
489,
18200,
13,
12283,
6248,
489,
16470,
334,
18891,
17015,
804,
9,
1035,
486,
4871,
489,
4057,
13,
12283,
334,
18891,
17015,
804,
9,
489,
1566,
334,
39,
6341,
2390,
9,
1035,
486,
4871,
489,
1566,
13,
4399,
334,
39,
6341,
2390,
9,
489,
5528,
13,
2915,
13,
1430,
334,
39,
6341,
2390,
9,
1035,
486,
4871,
489,
5528,
13,
3221,
13,
1430,
334,
39,
6341,
2390,
9,
1035,
486,
4871,
489,
13704,
13,
1430,
334,
39,
6341,
2390,
9,
1035,
486,
4871,
489,
25134,
13,
6814,
13,
1430,
334,
39,
6341,
2390,
9,
1035,
486,
4871,
489,
790,
10927,
13,
4892,
334,
18891,
17015,
804,
9,
1035,
486,
4871,
489,
3145,
13,
1430,
334,
39,
6341,
2390,
9,
1035,
486,
4871,
489,
11972,
13,
1430,
334,
39,
6341,
2390,
9,
1035,
486,
4871,
489,
23705,
13,
1430,
334,
39,
6341,
2390,
9,
1035,
486,
4871,
489,
790,
13,
2915,
13,
1430,
334,
39,
6341,
2390,
9,
1035,
486,
4871,
489,
790,
13,
3221,
13,
1430,
334,
39,
6341,
2390,
9,
1035,
486,
4871,
489,
9509,
13,
6814,
13,
1430,
334,
39,
6341,
2390,
9,
1035,
486,
4871,
489,
10137,
13,
6814,
13,
1430,
334,
39,
6341,
2390,
9,
1035,
486,
4871,
489,
7908,
13,
1430,
334,
39,
6341,
2390,
9,
1035,
486,
4871,
489,
16470,
13,
262,
13,
1430,
334,
39,
6341,
2390,
9,
1035,
486,
4871,
489,
16470,
13,
548,
13,
1430,
334,
39,
6341,
2390,
9,
1035,
486,
4871,
489,
2341,
13,
1430,
334,
39,
6341,
2390,
9,
1035,
486,
4871,
489,
625,
1130,
13,
1430,
334,
39,
6341,
2390,
9,
1035,
486,
4871,
489,
3324,
13,
6814,
13,
1430,
334,
39,
6341,
2390,
9,
1035,
486,
4871,
489,
7267,
13,
3584,
13,
1430,
334,
39,
6341,
2390,
9,
1035,
486,
4871,
489,
7267,
13,
1069,
13,
1430,
334,
39,
6341,
2390,
9,
1035,
486,
4871,
489,
7267,
13,
6814,
13,
1430,
334,
39,
6341,
2390,
9,
1035,
486,
4871,
489,
7267,
13,
9226,
334,
18891,
7713,
1451,
12,
486,
1635,
9,
489,
7267,
13,
362,
334,
18891,
7713,
1451,
12,
486,
1635,
12,
486,
1635,
9,
489,
10645,
1017,
1209,
13,
262,
13,
1430,
334,
39,
6341,
2390,
9,
1035,
486,
4871,
489,
10645,
1017,
1209,
13,
548,
13,
1430,
334,
39,
6341,
2390,
9,
1035,
486,
4871,
489,
18981,
13,
12422,
334,
39,
6341,
20287,
2998,
12,
486,
1635,
9,
489,
18981,
13,
5037,
334,
39,
6341,
20287,
2998,
9,
489,
18981
] |
[
2644,
26,
2774,
13,
24,
199,
3,
859,
8116,
423,
12275,
199,
3,
687,
1182,
2647,
15,
773,
15,
1548,
18,
14,
23,
15,
2686,
13,
5154,
15,
12275,
13,
18,
14,
16,
15,
12275,
15607,
12275,
14,
1152,
199,
3,
701,
4306,
413,
14,
8312,
199,
3,
949,
1382,
199,
199,
3,
8925,
199,
646,
737,
75,
465,
636,
292,
75,
199,
646,
486,
2308,
465,
636,
71,
2308,
199,
646,
25595,
465,
636,
71,
785,
199,
646,
25595,
423,
71,
785,
465,
636,
71,
785,
363,
71,
785,
421,
199,
504,
32613,
492,
32613,
199,
199,
504,
21904,
86,
15511,
492,
21904,
86,
15511,
199,
199,
533,
16005,
8,
13394,
12,
21904,
86,
15511,
304,
272,
408,
272,
6935,
11424,
4259,
2286,
6632,
2551,
687,
11424,
4259,
26,
489,
15422,
6248,
489,
25167,
6248,
489,
14286,
6248,
489,
28614,
6248,
489,
9509,
6248,
489,
10137,
6248,
2286,
19329,
687,
11424,
4259,
26,
489,
1768,
1035,
486,
1560,
1144,
26,
10354,
267,
4516,
402,
314,
1768,
3938,
6272,
314,
5528,
12,
340,
314,
5528,
3509,
282,
1768,
3938,
489,
1834,
1035,
11424,
3339,
26,
6047,
3938,
267,
12988,
3938,
370,
7468,
2163,
370,
314,
5528,
1318,
489,
28958,
1035,
11424,
497,
317,
2829,
6609,
26,
699,
1648,
28958,
267,
710,
9162,
28958,
3449,
489,
675,
13,
24396,
1035,
486,
4871,
26,
3645,
25735,
267,
982,
663,
12,
376,
25735,
315,
314,
1318,
9126,
314,
2163,
4528,
1077,
506,
1202,
367,
314,
18250,
16082,
1066,
27139,
790,
489,
675,
13,
6088,
1035,
486,
4871,
26,
3645,
10952,
267,
982,
663,
12,
314,
1768,
365,
1202,
370,
3732,
282,
10952,
1242,
3140,
402,
3769,
9080,
489,
16470,
13,
265,
13,
4891,
1035,
486,
4871,
26,
481,
10763,
641,
8968,
267,
7480,
314,
5528,
1999,
1533,
16470,
1380,
652,
365,
28614,
543,
314,
12817,
489,
671,
5743,
1035,
486,
1609,
26,
869,
7550,
13177,
367,
1982,
267,
869,
7550,
3421,
402,
1982,
315,
2808,
4601,
14,
378,
14,
16,
365,
3602,
22569,
12,
413,
14,
16,
365,
2451,
22569,
489,
612,
5743,
1035,
486,
1609,
26,
5444,
3294,
13177,
367,
1982,
267,
5444,
3294,
3421,
402,
1982,
315,
2808,
4601,
14,
378,
14,
16,
365,
2746,
22569,
12,
413,
14,
16,
365,
9048,
22569,
489,
1834,
13,
3124,
1035,
11424,
5625,
804,
26,
6047,
3421,
267,
710,
3421,
402,
314,
1834,
3847,
370,
314,
1318,
2286,
6632,
2551,
687,
11424,
4076,
26,
489,
1050,
334,
18891,
3339,
9,
489,
2813,
334,
18891,
3339,
9,
489,
1104,
13,
8709,
6248,
489,
663,
13,
12283,
13,
1739,
334,
18891,
3339,
9,
2286,
19329,
687,
11424,
4076,
26,
489,
9162,
13,
2063,
1035,
486,
1635,
26,
699,
1648,
3462,
267,
710,
3462,
402,
314,
2701,
9162,
9682,
314,
15333,
4978,
489,
15210,
13,
632,
1035,
11424,
24559,
1385,
26,
799,
890,
818,
267,
13327,
4212,
15210,
4474,
787,
8860,
489,
1982,
1035,
11424,
3339,
26,
12988,
267,
6855,
506,
1202,
370,
1050,
282,
892,
1982,
370,
314,
3970,
2286,
6632,
2551,
687,
11424,
3339,
26,
489,
11395,
11669,
13,
2489,
6248,
489,
2498,
6248,
489,
13714,
6248,
489,
2341,
6248,
489,
625,
1130,
6248,
489,
3363,
794,
6248,
489,
625,
3093,
794,
6248,
489,
1568,
13,
1069,
334,
18891,
497,
21523,
9,
489,
1568,
13,
12991,
334,
39,
6341,
18127,
9,
489,
1174,
13,
2489,
334,
18891,
2223,
804,
9,
489,
1676,
13,
409,
334,
18891,
3339,
9,
489,
14446,
13,
2489,
334,
18891,
3339,
9,
489,
3449,
13,
409,
334,
18891,
6609,
9,
489,
7581,
13,
2489,
334,
18891,
1872,
17015,
9,
489,
18200,
13,
6814,
334,
71,
4871,
9,
489,
1982,
13,
6814,
334,
39,
4098,
9,
489,
18250,
16082,
13,
8222,
334,
71,
4871,
9,
1035,
486,
4871,
489,
18200,
13,
12283,
6248,
489,
16470,
334,
18891,
17015,
804,
9,
1035,
486,
4871,
489,
4057,
13,
12283,
334,
18891,
17015,
804,
9,
489,
1566,
334,
39,
6341,
2390,
9,
1035,
486,
4871,
489,
1566,
13,
4399,
334,
39,
6341,
2390,
9,
489,
5528,
13,
2915,
13,
1430,
334,
39,
6341,
2390,
9,
1035,
486,
4871,
489,
5528,
13,
3221,
13,
1430,
334,
39,
6341,
2390,
9,
1035,
486,
4871,
489,
13704,
13,
1430,
334,
39,
6341,
2390,
9,
1035,
486,
4871,
489,
25134,
13,
6814,
13,
1430,
334,
39,
6341,
2390,
9,
1035,
486,
4871,
489,
790,
10927,
13,
4892,
334,
18891,
17015,
804,
9,
1035,
486,
4871,
489,
3145,
13,
1430,
334,
39,
6341,
2390,
9,
1035,
486,
4871,
489,
11972,
13,
1430,
334,
39,
6341,
2390,
9,
1035,
486,
4871,
489,
23705,
13,
1430,
334,
39,
6341,
2390,
9,
1035,
486,
4871,
489,
790,
13,
2915,
13,
1430,
334,
39,
6341,
2390,
9,
1035,
486,
4871,
489,
790,
13,
3221,
13,
1430,
334,
39,
6341,
2390,
9,
1035,
486,
4871,
489,
9509,
13,
6814,
13,
1430,
334,
39,
6341,
2390,
9,
1035,
486,
4871,
489,
10137,
13,
6814,
13,
1430,
334,
39,
6341,
2390,
9,
1035,
486,
4871,
489,
7908,
13,
1430,
334,
39,
6341,
2390,
9,
1035,
486,
4871,
489,
16470,
13,
262,
13,
1430,
334,
39,
6341,
2390,
9,
1035,
486,
4871,
489,
16470,
13,
548,
13,
1430,
334,
39,
6341,
2390,
9,
1035,
486,
4871,
489,
2341,
13,
1430,
334,
39,
6341,
2390,
9,
1035,
486,
4871,
489,
625,
1130,
13,
1430,
334,
39,
6341,
2390,
9,
1035,
486,
4871,
489,
3324,
13,
6814,
13,
1430,
334,
39,
6341,
2390,
9,
1035,
486,
4871,
489,
7267,
13,
3584,
13,
1430,
334,
39,
6341,
2390,
9,
1035,
486,
4871,
489,
7267,
13,
1069,
13,
1430,
334,
39,
6341,
2390,
9,
1035,
486,
4871,
489,
7267,
13,
6814,
13,
1430,
334,
39,
6341,
2390,
9,
1035,
486,
4871,
489,
7267,
13,
9226,
334,
18891,
7713,
1451,
12,
486,
1635,
9,
489,
7267,
13,
362,
334,
18891,
7713,
1451,
12,
486,
1635,
12,
486,
1635,
9,
489,
10645,
1017,
1209,
13,
262,
13,
1430,
334,
39,
6341,
2390,
9,
1035,
486,
4871,
489,
10645,
1017,
1209,
13,
548,
13,
1430,
334,
39,
6341,
2390,
9,
1035,
486,
4871,
489,
18981,
13,
12422,
334,
39,
6341,
20287,
2998,
12,
486,
1635,
9,
489,
18981,
13,
5037,
334,
39,
6341,
20287,
2998,
9,
489,
18981,
0
] |
[
1,
1,
1,
1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
tests/wpt/web-platform-tests/tools/pywebsocket/src/test/test_dispatch.py
|
488
|
13127
|
#!/usr/bin/env python
#
# Copyright 2011, Google Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
# * Neither the name of Google Inc. nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""Tests for dispatch module."""
import os
import unittest
import set_sys_path # Update sys.path to locate mod_pywebsocket module.
from mod_pywebsocket import dispatch
from mod_pywebsocket import handshake
from test import mock
_TEST_HANDLERS_DIR = os.path.join(
os.path.split(__file__)[0], 'testdata', 'handlers')
_TEST_HANDLERS_SUB_DIR = os.path.join(_TEST_HANDLERS_DIR, 'sub')
class DispatcherTest(unittest.TestCase):
"""A unittest for dispatch module."""
def test_normalize_path(self):
self.assertEqual(os.path.abspath('/a/b').replace('\\', '/'),
dispatch._normalize_path('/a/b'))
self.assertEqual(os.path.abspath('/a/b').replace('\\', '/'),
dispatch._normalize_path('\\a\\b'))
self.assertEqual(os.path.abspath('/a/b').replace('\\', '/'),
dispatch._normalize_path('/a/c/../b'))
self.assertEqual(os.path.abspath('abc').replace('\\', '/'),
dispatch._normalize_path('abc'))
def test_converter(self):
converter = dispatch._create_path_to_resource_converter('/a/b')
# Python built by MSC inserts a drive name like 'C:\' via realpath().
# Converter Generator expands provided path using realpath() and uses
# the path including a drive name to verify the prefix.
os_root = os.path.realpath('/')
self.assertEqual('/h', converter(os_root + 'a/b/h_wsh.py'))
self.assertEqual('/c/h', converter(os_root + 'a/b/c/h_wsh.py'))
self.assertEqual(None, converter(os_root + 'a/b/h.py'))
self.assertEqual(None, converter('a/b/h_wsh.py'))
converter = dispatch._create_path_to_resource_converter('a/b')
self.assertEqual('/h', converter(dispatch._normalize_path(
'a/b/h_wsh.py')))
converter = dispatch._create_path_to_resource_converter('/a/b///')
self.assertEqual('/h', converter(os_root + 'a/b/h_wsh.py'))
self.assertEqual('/h', converter(dispatch._normalize_path(
'/a/b/../b/h_wsh.py')))
converter = dispatch._create_path_to_resource_converter(
'/a/../a/b/../b/')
self.assertEqual('/h', converter(os_root + 'a/b/h_wsh.py'))
converter = dispatch._create_path_to_resource_converter(r'\a\b')
self.assertEqual('/h', converter(os_root + r'a\b\h_wsh.py'))
self.assertEqual('/h', converter(os_root + r'a/b/h_wsh.py'))
def test_enumerate_handler_file_paths(self):
paths = list(
dispatch._enumerate_handler_file_paths(_TEST_HANDLERS_DIR))
paths.sort()
self.assertEqual(8, len(paths))
expected_paths = [
os.path.join(_TEST_HANDLERS_DIR, 'abort_by_user_wsh.py'),
os.path.join(_TEST_HANDLERS_DIR, 'blank_wsh.py'),
os.path.join(_TEST_HANDLERS_DIR, 'origin_check_wsh.py'),
os.path.join(_TEST_HANDLERS_DIR, 'sub',
'exception_in_transfer_wsh.py'),
os.path.join(_TEST_HANDLERS_DIR, 'sub', 'non_callable_wsh.py'),
os.path.join(_TEST_HANDLERS_DIR, 'sub', 'plain_wsh.py'),
os.path.join(_TEST_HANDLERS_DIR, 'sub',
'wrong_handshake_sig_wsh.py'),
os.path.join(_TEST_HANDLERS_DIR, 'sub',
'wrong_transfer_sig_wsh.py'),
]
for expected, actual in zip(expected_paths, paths):
self.assertEqual(expected, actual)
def test_source_handler_file(self):
self.assertRaises(
dispatch.DispatchException, dispatch._source_handler_file, '')
self.assertRaises(
dispatch.DispatchException, dispatch._source_handler_file, 'def')
self.assertRaises(
dispatch.DispatchException, dispatch._source_handler_file, '1/0')
self.failUnless(dispatch._source_handler_file(
'def web_socket_do_extra_handshake(request):pass\n'
'def web_socket_transfer_data(request):pass\n'))
def test_source_warnings(self):
dispatcher = dispatch.Dispatcher(_TEST_HANDLERS_DIR, None)
warnings = dispatcher.source_warnings()
warnings.sort()
expected_warnings = [
(os.path.realpath(os.path.join(
_TEST_HANDLERS_DIR, 'blank_wsh.py')) +
': web_socket_do_extra_handshake is not defined.'),
(os.path.realpath(os.path.join(
_TEST_HANDLERS_DIR, 'sub', 'non_callable_wsh.py')) +
': web_socket_do_extra_handshake is not callable.'),
(os.path.realpath(os.path.join(
_TEST_HANDLERS_DIR, 'sub', 'wrong_handshake_sig_wsh.py')) +
': web_socket_do_extra_handshake is not defined.'),
(os.path.realpath(os.path.join(
_TEST_HANDLERS_DIR, 'sub', 'wrong_transfer_sig_wsh.py')) +
': web_socket_transfer_data is not defined.'),
]
self.assertEquals(4, len(warnings))
for expected, actual in zip(expected_warnings, warnings):
self.assertEquals(expected, actual)
def test_do_extra_handshake(self):
dispatcher = dispatch.Dispatcher(_TEST_HANDLERS_DIR, None)
request = mock.MockRequest()
request.ws_resource = '/origin_check'
request.ws_origin = 'http://example.com'
dispatcher.do_extra_handshake(request) # Must not raise exception.
request.ws_origin = 'http://bad.example.com'
try:
dispatcher.do_extra_handshake(request)
self.fail('Could not catch HandshakeException with 403 status')
except handshake.HandshakeException, e:
self.assertEquals(403, e.status)
except Exception, e:
self.fail('Unexpected exception: %r' % e)
def test_abort_extra_handshake(self):
dispatcher = dispatch.Dispatcher(_TEST_HANDLERS_DIR, None)
request = mock.MockRequest()
request.ws_resource = '/abort_by_user'
self.assertRaises(handshake.AbortedByUserException,
dispatcher.do_extra_handshake, request)
def test_transfer_data(self):
dispatcher = dispatch.Dispatcher(_TEST_HANDLERS_DIR, None)
request = mock.MockRequest(connection=mock.MockConn('\xff\x00'))
request.ws_resource = '/origin_check'
request.ws_protocol = 'p1'
dispatcher.transfer_data(request)
self.assertEqual('origin_check_wsh.py is called for /origin_check, p1'
'\xff\x00',
request.connection.written_data())
request = mock.MockRequest(connection=mock.MockConn('\xff\x00'))
request.ws_resource = '/sub/plain'
request.ws_protocol = None
dispatcher.transfer_data(request)
self.assertEqual('sub/plain_wsh.py is called for /sub/plain, None'
'\xff\x00',
request.connection.written_data())
request = mock.MockRequest(connection=mock.MockConn('\xff\x00'))
request.ws_resource = '/sub/plain?'
request.ws_protocol = None
dispatcher.transfer_data(request)
self.assertEqual('sub/plain_wsh.py is called for /sub/plain?, None'
'\xff\x00',
request.connection.written_data())
request = mock.MockRequest(connection=mock.MockConn('\xff\x00'))
request.ws_resource = '/sub/plain?q=v'
request.ws_protocol = None
dispatcher.transfer_data(request)
self.assertEqual('sub/plain_wsh.py is called for /sub/plain?q=v, None'
'\xff\x00',
request.connection.written_data())
def test_transfer_data_no_handler(self):
dispatcher = dispatch.Dispatcher(_TEST_HANDLERS_DIR, None)
for resource in ['/blank', '/sub/non_callable',
'/sub/no_wsh_at_the_end', '/does/not/exist']:
request = mock.MockRequest(connection=mock.MockConn(''))
request.ws_resource = resource
request.ws_protocol = 'p2'
try:
dispatcher.transfer_data(request)
self.fail()
except dispatch.DispatchException, e:
self.failUnless(str(e).find('No handler') != -1)
except Exception:
self.fail()
def test_transfer_data_handler_exception(self):
dispatcher = dispatch.Dispatcher(_TEST_HANDLERS_DIR, None)
request = mock.MockRequest(connection=mock.MockConn(''))
request.ws_resource = '/sub/exception_in_transfer'
request.ws_protocol = 'p3'
try:
dispatcher.transfer_data(request)
self.fail()
except Exception, e:
self.failUnless(str(e).find('Intentional') != -1,
'Unexpected exception: %s' % e)
def test_abort_transfer_data(self):
dispatcher = dispatch.Dispatcher(_TEST_HANDLERS_DIR, None)
request = mock.MockRequest()
request.ws_resource = '/abort_by_user'
self.assertRaises(handshake.AbortedByUserException,
dispatcher.transfer_data, request)
def test_scan_dir(self):
disp = dispatch.Dispatcher(_TEST_HANDLERS_DIR, None)
self.assertEqual(4, len(disp._handler_suite_map))
self.failUnless('/origin_check' in disp._handler_suite_map)
self.failUnless(
'/sub/exception_in_transfer' in disp._handler_suite_map)
self.failUnless('/sub/plain' in disp._handler_suite_map)
def test_scan_sub_dir(self):
disp = dispatch.Dispatcher(_TEST_HANDLERS_DIR, _TEST_HANDLERS_SUB_DIR)
self.assertEqual(2, len(disp._handler_suite_map))
self.failIf('/origin_check' in disp._handler_suite_map)
self.failUnless(
'/sub/exception_in_transfer' in disp._handler_suite_map)
self.failUnless('/sub/plain' in disp._handler_suite_map)
def test_scan_sub_dir_as_root(self):
disp = dispatch.Dispatcher(_TEST_HANDLERS_SUB_DIR,
_TEST_HANDLERS_SUB_DIR)
self.assertEqual(2, len(disp._handler_suite_map))
self.failIf('/origin_check' in disp._handler_suite_map)
self.failIf('/sub/exception_in_transfer' in disp._handler_suite_map)
self.failIf('/sub/plain' in disp._handler_suite_map)
self.failUnless('/exception_in_transfer' in disp._handler_suite_map)
self.failUnless('/plain' in disp._handler_suite_map)
def test_scan_dir_must_under_root(self):
dispatch.Dispatcher('a/b', 'a/b/c') # OK
dispatch.Dispatcher('a/b///', 'a/b') # OK
self.assertRaises(dispatch.DispatchException,
dispatch.Dispatcher, 'a/b/c', 'a/b')
def test_resource_path_alias(self):
disp = dispatch.Dispatcher(_TEST_HANDLERS_DIR, None)
disp.add_resource_path_alias('/', '/origin_check')
self.assertEqual(5, len(disp._handler_suite_map))
self.failUnless('/origin_check' in disp._handler_suite_map)
self.failUnless(
'/sub/exception_in_transfer' in disp._handler_suite_map)
self.failUnless('/sub/plain' in disp._handler_suite_map)
self.failUnless('/' in disp._handler_suite_map)
self.assertRaises(dispatch.DispatchException,
disp.add_resource_path_alias, '/alias', '/not-exist')
if __name__ == '__main__':
unittest.main()
# vi:sts=4 sw=4 et
|
mpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
7760,
12,
4475,
3277,
14,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
199,
3,
199,
3,
258,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
258,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
199,
3,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
199,
3,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
3,
4084,
14,
199,
3,
258,
627,
11443,
314,
536,
402,
4475,
3277,
14,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
421,
199,
624,
2925,
367,
7634,
859,
1041,
421,
199,
646,
747,
199,
646,
2882,
199,
199,
646,
663,
63,
1274,
63,
515,
221,
327,
6162,
984,
14,
515,
370,
16592,
3413,
63,
21387,
859,
14,
199,
199,
504,
3413,
63,
21387,
492,
7634,
199,
504,
3413,
63,
21387,
492,
14305,
199,
504,
511,
492,
1683,
421,
199,
63,
2864,
63,
10854,
28778,
63,
3022,
275,
747,
14,
515,
14,
904,
8,
267,
747,
14,
515,
14,
1294,
3460,
493,
363,
2788,
16,
467,
283,
18481,
297,
283,
5586,
358,
199,
199,
63,
2864,
63,
10854,
28778,
63,
6348,
63,
3022,
275,
747,
14,
515,
14,
904,
1547,
2864,
63,
10854,
28778,
63,
3022,
12,
283,
954,
358,
421,
199,
533,
5289,
11238,
774,
8,
2796,
14,
1746,
304,
272,
408,
33,
2882,
367,
7634,
859,
1041,
339,
347,
511,
63,
7721,
63,
515,
8,
277,
304,
267,
291,
14,
629,
8,
736,
14,
515,
14,
4832,
2336,
65,
15,
66,
1959,
1814,
20786,
1994,
659,
586,
7634,
423,
7721,
63,
515,
2336,
65,
15,
66,
1333,
267,
291,
14,
629,
8,
736,
14,
515,
14,
4832,
2336,
65,
15,
66,
1959,
1814,
20786,
1994,
659,
586,
7634,
423,
7721,
63,
515,
11671,
65,
1103,
66,
1333,
267,
291,
14,
629,
8,
736,
14,
515,
14,
4832,
2336,
65,
15,
66,
1959,
1814,
20786,
1994,
659,
586,
7634,
423,
7721,
63,
515,
2336,
65,
15,
67,
15,
5093,
66,
1333,
267,
291,
14,
629,
8,
736,
14,
515,
14,
4832,
360,
3175,
1959,
1814,
20786,
1994,
659,
586,
7634,
423,
7721,
63,
515,
360,
3175,
1333,
339,
347,
511,
63,
11256,
8,
277,
304,
267,
11109,
275,
7634,
423,
981,
63,
515,
63,
475,
63,
1927,
63,
11256,
2336,
65,
15,
66,
358,
267,
327,
2018,
6137,
701,
603,
5153,
28203,
282,
12912,
536,
2839,
283,
35,
3427,
7,
4799,
3363,
515,
1252,
267,
327,
11801,
351,
15042,
1437,
5915,
2741,
931,
1808,
3363,
515,
342,
436,
4440,
267,
327,
314,
931,
5893,
282,
12912,
536,
370,
4911,
314,
2403,
14,
267,
747,
63,
1231,
275,
747,
14,
515,
14,
11091,
7825,
267,
291,
14,
629,
2336,
72,
297,
11109,
8,
736,
63,
1231,
435,
283,
65,
15,
66,
15,
72,
63,
87,
609,
14,
647,
1333,
267,
291,
14,
629,
2336,
67,
15,
72,
297,
11109,
8,
736,
63,
1231,
435,
283,
65,
15,
66,
15,
67,
15,
72,
63,
87,
609,
14,
647,
1333,
267,
291,
14,
629,
8,
403,
12,
11109,
8,
736,
63,
1231,
435,
283,
65,
15,
66,
15,
72,
14,
647,
1333,
267,
291,
14,
629,
8,
403,
12,
11109,
360,
65,
15,
66,
15,
72,
63,
87,
609,
14,
647,
1333,
398,
11109,
275,
7634,
423,
981,
63,
515,
63,
475,
63,
1927,
63,
11256,
360,
65,
15,
66,
358,
267,
291,
14,
629,
2336,
72,
297,
11109,
8,
6052,
423,
7721,
63,
515,
8,
288,
283,
65,
15,
66,
15,
72,
63,
87,
609,
14,
647,
7058,
398,
11109,
275,
7634,
423,
981,
63,
515,
63,
475,
63,
1927,
63,
11256,
2336,
65,
15,
66,
501,
6217,
267,
291,
14,
629,
2336,
72,
297,
11109,
8,
736,
63,
1231,
435,
283,
65,
15,
66,
15,
72,
63,
87,
609,
14,
647,
1333,
267,
291,
14,
629,
2336,
72,
297,
11109,
8,
6052,
423,
7721,
63,
515,
8,
288,
1994,
65,
15,
66,
15,
5093,
66,
15,
72,
63,
87,
609,
14,
647,
7058,
398,
11109,
275,
7634,
423,
981,
63,
515,
63,
475,
63,
1927,
63,
11256,
8,
288,
1994,
65,
15,
5093,
65,
15,
66,
15,
5093,
66,
6217,
267,
291,
14,
629,
2336,
72,
297,
11109,
8,
736,
63,
1231,
435,
283,
65,
15,
66,
15,
72,
63,
87,
609,
14,
647,
1333,
398,
11109,
275,
7634,
423,
981,
63,
515,
63,
475,
63,
1927,
63,
11256,
8,
82,
1154,
65,
60,
66,
358,
267,
291,
14,
629,
2336,
72,
297,
11109,
8,
736,
63,
1231,
435,
519,
7,
65,
60,
66,
60,
72,
63,
87,
609,
14,
647,
1333,
267,
291,
14,
629,
2336,
72,
297,
11109,
8,
736,
63,
1231,
435,
519,
7,
65,
15,
66,
15,
72,
63,
87,
609,
14
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
7760,
12,
4475,
3277,
14,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
199,
3,
199,
3,
258,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
258,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
199,
3,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
199,
3,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
3,
4084,
14,
199,
3,
258,
627,
11443,
314,
536,
402,
4475,
3277,
14,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
421,
199,
624,
2925,
367,
7634,
859,
1041,
421,
199,
646,
747,
199,
646,
2882,
199,
199,
646,
663,
63,
1274,
63,
515,
221,
327,
6162,
984,
14,
515,
370,
16592,
3413,
63,
21387,
859,
14,
199,
199,
504,
3413,
63,
21387,
492,
7634,
199,
504,
3413,
63,
21387,
492,
14305,
199,
504,
511,
492,
1683,
421,
199,
63,
2864,
63,
10854,
28778,
63,
3022,
275,
747,
14,
515,
14,
904,
8,
267,
747,
14,
515,
14,
1294,
3460,
493,
363,
2788,
16,
467,
283,
18481,
297,
283,
5586,
358,
199,
199,
63,
2864,
63,
10854,
28778,
63,
6348,
63,
3022,
275,
747,
14,
515,
14,
904,
1547,
2864,
63,
10854,
28778,
63,
3022,
12,
283,
954,
358,
421,
199,
533,
5289,
11238,
774,
8,
2796,
14,
1746,
304,
272,
408,
33,
2882,
367,
7634,
859,
1041,
339,
347,
511,
63,
7721,
63,
515,
8,
277,
304,
267,
291,
14,
629,
8,
736,
14,
515,
14,
4832,
2336,
65,
15,
66,
1959,
1814,
20786,
1994,
659,
586,
7634,
423,
7721,
63,
515,
2336,
65,
15,
66,
1333,
267,
291,
14,
629,
8,
736,
14,
515,
14,
4832,
2336,
65,
15,
66,
1959,
1814,
20786,
1994,
659,
586,
7634,
423,
7721,
63,
515,
11671,
65,
1103,
66,
1333,
267,
291,
14,
629,
8,
736,
14,
515,
14,
4832,
2336,
65,
15,
66,
1959,
1814,
20786,
1994,
659,
586,
7634,
423,
7721,
63,
515,
2336,
65,
15,
67,
15,
5093,
66,
1333,
267,
291,
14,
629,
8,
736,
14,
515,
14,
4832,
360,
3175,
1959,
1814,
20786,
1994,
659,
586,
7634,
423,
7721,
63,
515,
360,
3175,
1333,
339,
347,
511,
63,
11256,
8,
277,
304,
267,
11109,
275,
7634,
423,
981,
63,
515,
63,
475,
63,
1927,
63,
11256,
2336,
65,
15,
66,
358,
267,
327,
2018,
6137,
701,
603,
5153,
28203,
282,
12912,
536,
2839,
283,
35,
3427,
7,
4799,
3363,
515,
1252,
267,
327,
11801,
351,
15042,
1437,
5915,
2741,
931,
1808,
3363,
515,
342,
436,
4440,
267,
327,
314,
931,
5893,
282,
12912,
536,
370,
4911,
314,
2403,
14,
267,
747,
63,
1231,
275,
747,
14,
515,
14,
11091,
7825,
267,
291,
14,
629,
2336,
72,
297,
11109,
8,
736,
63,
1231,
435,
283,
65,
15,
66,
15,
72,
63,
87,
609,
14,
647,
1333,
267,
291,
14,
629,
2336,
67,
15,
72,
297,
11109,
8,
736,
63,
1231,
435,
283,
65,
15,
66,
15,
67,
15,
72,
63,
87,
609,
14,
647,
1333,
267,
291,
14,
629,
8,
403,
12,
11109,
8,
736,
63,
1231,
435,
283,
65,
15,
66,
15,
72,
14,
647,
1333,
267,
291,
14,
629,
8,
403,
12,
11109,
360,
65,
15,
66,
15,
72,
63,
87,
609,
14,
647,
1333,
398,
11109,
275,
7634,
423,
981,
63,
515,
63,
475,
63,
1927,
63,
11256,
360,
65,
15,
66,
358,
267,
291,
14,
629,
2336,
72,
297,
11109,
8,
6052,
423,
7721,
63,
515,
8,
288,
283,
65,
15,
66,
15,
72,
63,
87,
609,
14,
647,
7058,
398,
11109,
275,
7634,
423,
981,
63,
515,
63,
475,
63,
1927,
63,
11256,
2336,
65,
15,
66,
501,
6217,
267,
291,
14,
629,
2336,
72,
297,
11109,
8,
736,
63,
1231,
435,
283,
65,
15,
66,
15,
72,
63,
87,
609,
14,
647,
1333,
267,
291,
14,
629,
2336,
72,
297,
11109,
8,
6052,
423,
7721,
63,
515,
8,
288,
1994,
65,
15,
66,
15,
5093,
66,
15,
72,
63,
87,
609,
14,
647,
7058,
398,
11109,
275,
7634,
423,
981,
63,
515,
63,
475,
63,
1927,
63,
11256,
8,
288,
1994,
65,
15,
5093,
65,
15,
66,
15,
5093,
66,
6217,
267,
291,
14,
629,
2336,
72,
297,
11109,
8,
736,
63,
1231,
435,
283,
65,
15,
66,
15,
72,
63,
87,
609,
14,
647,
1333,
398,
11109,
275,
7634,
423,
981,
63,
515,
63,
475,
63,
1927,
63,
11256,
8,
82,
1154,
65,
60,
66,
358,
267,
291,
14,
629,
2336,
72,
297,
11109,
8,
736,
63,
1231,
435,
519,
7,
65,
60,
66,
60,
72,
63,
87,
609,
14,
647,
1333,
267,
291,
14,
629,
2336,
72,
297,
11109,
8,
736,
63,
1231,
435,
519,
7,
65,
15,
66,
15,
72,
63,
87,
609,
14,
0
] |
[
1,
1,
1,
1,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client
|
tests/contrib/test_sqlalchemy.py
|
21
|
4827
|
# Copyright 2016 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import datetime
import unittest
import mock
import sqlalchemy
import sqlalchemy.ext.declarative
import sqlalchemy.orm
import oauth2client
import oauth2client.client
import oauth2client.contrib.sqlalchemy
Base = sqlalchemy.ext.declarative.declarative_base()
class DummyModel(Base):
__tablename__ = 'dummy'
id = sqlalchemy.Column(sqlalchemy.Integer, primary_key=True)
# we will query against this, because of ROWID
key = sqlalchemy.Column(sqlalchemy.Integer)
credentials = sqlalchemy.Column(
oauth2client.contrib.sqlalchemy.CredentialsType)
class TestSQLAlchemyStorage(unittest.TestCase):
def setUp(self):
engine = sqlalchemy.create_engine('sqlite://')
Base.metadata.create_all(engine)
self.session = sqlalchemy.orm.sessionmaker(bind=engine)
self.credentials = oauth2client.client.OAuth2Credentials(
access_token='token',
client_id='client_id',
client_secret='client_secret',
refresh_token='refresh_token',
token_expiry=datetime.datetime.utcnow(),
token_uri=oauth2client.GOOGLE_TOKEN_URI,
user_agent='DummyAgent',
)
def tearDown(self):
session = self.session()
session.query(DummyModel).filter_by(key=1).delete()
session.commit()
def compare_credentials(self, result):
self.assertEqual(result.access_token, self.credentials.access_token)
self.assertEqual(result.client_id, self.credentials.client_id)
self.assertEqual(result.client_secret, self.credentials.client_secret)
self.assertEqual(result.refresh_token, self.credentials.refresh_token)
self.assertEqual(result.token_expiry, self.credentials.token_expiry)
self.assertEqual(result.token_uri, self.credentials.token_uri)
self.assertEqual(result.user_agent, self.credentials.user_agent)
@mock.patch('oauth2client.client.OAuth2Credentials.set_store')
def test_get(self, set_store):
session = self.session()
credentials_storage = oauth2client.contrib.sqlalchemy.Storage(
session=session,
model_class=DummyModel,
key_name='key',
key_value=1,
property_name='credentials',
)
# No credentials stored
self.assertIsNone(credentials_storage.get())
# Invalid credentials stored
session.add(DummyModel(
key=1,
credentials=oauth2client.client.Credentials(),
))
session.commit()
bad_credentials = credentials_storage.get()
self.assertIsInstance(bad_credentials, oauth2client.client.Credentials)
set_store.assert_not_called()
# Valid credentials stored
session.query(DummyModel).filter_by(key=1).delete()
session.add(DummyModel(
key=1,
credentials=self.credentials,
))
session.commit()
self.compare_credentials(credentials_storage.get())
set_store.assert_called_with(credentials_storage)
def test_put(self):
session = self.session()
storage = oauth2client.contrib.sqlalchemy.Storage(
session=session,
model_class=DummyModel,
key_name='key',
key_value=1,
property_name='credentials',
)
# Store invalid credentials first to verify overwriting
storage.put(oauth2client.client.Credentials())
storage.put(self.credentials)
session.commit()
entity = session.query(DummyModel).filter_by(key=1).first()
self.compare_credentials(entity.credentials)
def test_delete(self):
session = self.session()
session.add(DummyModel(
key=1,
credentials=self.credentials,
))
session.commit()
query = session.query(DummyModel).filter_by(key=1)
self.assertIsNotNone(query.first())
oauth2client.contrib.sqlalchemy.Storage(
session=session,
model_class=DummyModel,
key_name='key',
key_value=1,
property_name='credentials',
).delete()
session.commit()
self.assertIsNone(query.first())
|
apache-2.0
|
[
3,
1898,
7800,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
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,
646,
2197,
199,
646,
2882,
199,
199,
646,
1683,
199,
646,
8335,
199,
646,
8335,
14,
832,
14,
12164,
1905,
199,
646,
8335,
14,
1025,
199,
199,
646,
9725,
18,
1258,
199,
646,
9725,
18,
1258,
14,
1258,
199,
646,
9725,
18,
1258,
14,
2828,
14,
14536,
199,
199,
1563,
275,
8335,
14,
832,
14,
12164,
1905,
14,
12164,
1905,
63,
1095,
342,
421,
199,
533,
9762,
1685,
8,
1563,
304,
272,
636,
10983,
363,
275,
283,
5869,
7,
339,
1305,
275,
8335,
14,
4547,
8,
14536,
14,
2674,
12,
5062,
63,
498,
29,
549,
9,
272,
327,
781,
911,
1827,
6169,
642,
12,
2952,
402,
9769,
9845,
272,
790,
275,
8335,
14,
4547,
8,
14536,
14,
2674,
9,
272,
6235,
275,
8335,
14,
4547,
8,
267,
9725,
18,
1258,
14,
2828,
14,
14536,
14,
13428,
804,
9,
421,
199,
533,
1379,
4657,
12800,
6408,
8,
2796,
14,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
6869,
275,
8335,
14,
981,
63,
3908,
360,
10659,
921,
358,
267,
3523,
14,
2343,
14,
981,
63,
452,
8,
3908,
9,
398,
291,
14,
1730,
275,
8335,
14,
1025,
14,
1730,
14367,
8,
3409,
29,
3908,
9,
267,
291,
14,
6942,
275,
9725,
18,
1258,
14,
1258,
14,
12906,
18,
13428,
8,
288,
2879,
63,
1418,
534,
1418,
297,
288,
1890,
63,
344,
534,
1258,
63,
344,
297,
288,
1890,
63,
4731,
534,
1258,
63,
4731,
297,
288,
9236,
63,
1418,
534,
6635,
63,
1418,
297,
288,
1526,
63,
16844,
29,
2083,
14,
2083,
14,
10779,
1062,
288,
1526,
63,
2302,
29,
6126,
18,
1258,
14,
24243,
63,
8803,
63,
7639,
12,
288,
922,
63,
4054,
534,
11324,
7788,
297,
267,
776,
339,
347,
6766,
8,
277,
304,
267,
2351,
275,
291,
14,
1730,
342,
267,
2351,
14,
1131,
8,
11324,
1685,
680,
1541,
63,
991,
8,
498,
29,
17,
680,
1807,
342,
267,
2351,
14,
3543,
342,
339,
347,
6540,
63,
6942,
8,
277,
12,
754,
304,
267,
291,
14,
629,
8,
1099,
14,
2732,
63,
1418,
12,
291,
14,
6942,
14,
2732,
63,
1418,
9,
267,
291,
14,
629,
8,
1099,
14,
1258,
63,
344,
12,
291,
14,
6942,
14,
1258,
63,
344,
9,
267,
291,
14,
629,
8,
1099,
14,
1258,
63,
4731,
12,
291,
14,
6942,
14,
1258,
63,
4731,
9,
267,
291,
14,
629,
8,
1099,
14,
6635,
63,
1418,
12,
291,
14,
6942,
14,
6635,
63,
1418,
9,
267,
291,
14,
629,
8,
1099,
14,
1418,
63,
16844,
12,
291,
14,
6942,
14,
1418,
63,
16844,
9,
267,
291,
14,
629,
8,
1099,
14,
1418,
63,
2302,
12,
291,
14,
6942,
14,
1418,
63,
2302,
9,
267,
291,
14,
629,
8,
1099,
14,
751,
63,
4054,
12,
291,
14,
6942,
14,
751,
63,
4054,
9,
339,
768,
1805,
14,
2068,
360,
6126,
18,
1258,
14,
1258,
14,
12906,
18,
13428,
14,
409,
63,
1617,
358,
272,
347,
511,
63,
362,
8,
277,
12,
663,
63,
1617,
304,
267,
2351,
275,
291,
14,
1730,
342,
267,
6235,
63,
3494,
275,
9725,
18,
1258,
14,
2828,
14,
14536,
14,
6408,
8,
288,
2351,
29,
1730,
12,
288,
1402,
63,
533,
29,
11324,
1685,
12,
288,
790,
63,
354,
534,
498,
297,
288,
790,
63,
585,
29,
17,
12,
288,
3324,
63,
354,
534,
6942,
297,
267,
776,
267,
327,
3091,
6235,
5489,
267,
291,
14,
7702,
8,
6942,
63,
3494,
14,
362,
1012,
398,
327,
6378,
6235,
5489,
267,
2351,
14,
525,
8,
11324,
1685,
8,
288,
790,
29,
17,
12,
288,
6235,
29,
6126,
18,
1258,
14,
1258,
14,
13428,
1062,
267,
5082,
267,
2351,
14,
3543,
342,
267,
4875,
63,
6942,
275,
6235,
63,
3494,
14,
362,
342,
267,
291,
14,
6926,
8,
4087,
63,
6942,
12,
9725,
18,
1258,
14,
1258,
14,
13428,
9,
267,
663,
63,
1617,
14,
479,
63,
1397,
63,
3527,
342,
398,
327,
4821,
6235,
5489,
267,
2351,
14,
1131,
8,
11324,
1685,
680,
1541,
63,
991,
8,
498,
29,
17,
680,
1807,
342,
267,
2351,
14,
525,
8,
11324,
1685,
8,
288,
790,
29,
17,
12,
288,
6235,
29,
277,
14,
6942,
12,
267,
5082,
267,
2351,
14,
3543,
342,
398,
291,
14,
5785,
63,
6942,
8,
6942,
63,
3494,
14,
362,
1012,
267,
663,
63,
1617,
14,
479,
63,
3527,
63,
1045,
8,
6942,
63,
3494,
9,
339,
347,
511,
63,
524,
8,
277,
304,
267,
2351,
275,
291,
14,
1730,
342,
267,
4887,
275,
9725,
18,
1258,
14,
2828,
14,
14536,
14,
6408,
8,
288,
2351,
29,
1730,
12,
288,
1402,
63,
533,
29,
11324,
1685,
12,
288,
790,
63,
354,
534,
498,
297,
288,
790,
63,
585,
29,
17,
12,
288,
3324,
63,
354,
534,
6942,
297,
267,
776,
267,
327,
13874,
3866,
6235,
1642,
370,
4911,
32592,
267,
4887,
14,
524,
8,
6126,
18,
1258,
14,
1258,
14,
13428,
1012,
267,
4887,
14,
524,
8,
277,
14,
6942,
9,
267,
2351,
14,
3543,
342,
398,
4642,
275,
2351,
14,
1131,
8,
11324,
1685,
680,
1541,
63,
991,
8,
498,
29,
17,
680,
2246,
342,
267,
291,
14,
5785,
63,
6942,
8,
4502,
14,
6942,
9,
339,
347,
511,
63,
1807,
8,
277,
304,
267,
2351,
275,
291,
14,
1730,
342,
267,
2351,
14,
525,
8,
11324,
1685,
8,
288,
790,
29,
17,
12,
288,
6235,
29,
277
] |
[
1898,
7800,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
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,
646,
2197,
199,
646,
2882,
199,
199,
646,
1683,
199,
646,
8335,
199,
646,
8335,
14,
832,
14,
12164,
1905,
199,
646,
8335,
14,
1025,
199,
199,
646,
9725,
18,
1258,
199,
646,
9725,
18,
1258,
14,
1258,
199,
646,
9725,
18,
1258,
14,
2828,
14,
14536,
199,
199,
1563,
275,
8335,
14,
832,
14,
12164,
1905,
14,
12164,
1905,
63,
1095,
342,
421,
199,
533,
9762,
1685,
8,
1563,
304,
272,
636,
10983,
363,
275,
283,
5869,
7,
339,
1305,
275,
8335,
14,
4547,
8,
14536,
14,
2674,
12,
5062,
63,
498,
29,
549,
9,
272,
327,
781,
911,
1827,
6169,
642,
12,
2952,
402,
9769,
9845,
272,
790,
275,
8335,
14,
4547,
8,
14536,
14,
2674,
9,
272,
6235,
275,
8335,
14,
4547,
8,
267,
9725,
18,
1258,
14,
2828,
14,
14536,
14,
13428,
804,
9,
421,
199,
533,
1379,
4657,
12800,
6408,
8,
2796,
14,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
6869,
275,
8335,
14,
981,
63,
3908,
360,
10659,
921,
358,
267,
3523,
14,
2343,
14,
981,
63,
452,
8,
3908,
9,
398,
291,
14,
1730,
275,
8335,
14,
1025,
14,
1730,
14367,
8,
3409,
29,
3908,
9,
267,
291,
14,
6942,
275,
9725,
18,
1258,
14,
1258,
14,
12906,
18,
13428,
8,
288,
2879,
63,
1418,
534,
1418,
297,
288,
1890,
63,
344,
534,
1258,
63,
344,
297,
288,
1890,
63,
4731,
534,
1258,
63,
4731,
297,
288,
9236,
63,
1418,
534,
6635,
63,
1418,
297,
288,
1526,
63,
16844,
29,
2083,
14,
2083,
14,
10779,
1062,
288,
1526,
63,
2302,
29,
6126,
18,
1258,
14,
24243,
63,
8803,
63,
7639,
12,
288,
922,
63,
4054,
534,
11324,
7788,
297,
267,
776,
339,
347,
6766,
8,
277,
304,
267,
2351,
275,
291,
14,
1730,
342,
267,
2351,
14,
1131,
8,
11324,
1685,
680,
1541,
63,
991,
8,
498,
29,
17,
680,
1807,
342,
267,
2351,
14,
3543,
342,
339,
347,
6540,
63,
6942,
8,
277,
12,
754,
304,
267,
291,
14,
629,
8,
1099,
14,
2732,
63,
1418,
12,
291,
14,
6942,
14,
2732,
63,
1418,
9,
267,
291,
14,
629,
8,
1099,
14,
1258,
63,
344,
12,
291,
14,
6942,
14,
1258,
63,
344,
9,
267,
291,
14,
629,
8,
1099,
14,
1258,
63,
4731,
12,
291,
14,
6942,
14,
1258,
63,
4731,
9,
267,
291,
14,
629,
8,
1099,
14,
6635,
63,
1418,
12,
291,
14,
6942,
14,
6635,
63,
1418,
9,
267,
291,
14,
629,
8,
1099,
14,
1418,
63,
16844,
12,
291,
14,
6942,
14,
1418,
63,
16844,
9,
267,
291,
14,
629,
8,
1099,
14,
1418,
63,
2302,
12,
291,
14,
6942,
14,
1418,
63,
2302,
9,
267,
291,
14,
629,
8,
1099,
14,
751,
63,
4054,
12,
291,
14,
6942,
14,
751,
63,
4054,
9,
339,
768,
1805,
14,
2068,
360,
6126,
18,
1258,
14,
1258,
14,
12906,
18,
13428,
14,
409,
63,
1617,
358,
272,
347,
511,
63,
362,
8,
277,
12,
663,
63,
1617,
304,
267,
2351,
275,
291,
14,
1730,
342,
267,
6235,
63,
3494,
275,
9725,
18,
1258,
14,
2828,
14,
14536,
14,
6408,
8,
288,
2351,
29,
1730,
12,
288,
1402,
63,
533,
29,
11324,
1685,
12,
288,
790,
63,
354,
534,
498,
297,
288,
790,
63,
585,
29,
17,
12,
288,
3324,
63,
354,
534,
6942,
297,
267,
776,
267,
327,
3091,
6235,
5489,
267,
291,
14,
7702,
8,
6942,
63,
3494,
14,
362,
1012,
398,
327,
6378,
6235,
5489,
267,
2351,
14,
525,
8,
11324,
1685,
8,
288,
790,
29,
17,
12,
288,
6235,
29,
6126,
18,
1258,
14,
1258,
14,
13428,
1062,
267,
5082,
267,
2351,
14,
3543,
342,
267,
4875,
63,
6942,
275,
6235,
63,
3494,
14,
362,
342,
267,
291,
14,
6926,
8,
4087,
63,
6942,
12,
9725,
18,
1258,
14,
1258,
14,
13428,
9,
267,
663,
63,
1617,
14,
479,
63,
1397,
63,
3527,
342,
398,
327,
4821,
6235,
5489,
267,
2351,
14,
1131,
8,
11324,
1685,
680,
1541,
63,
991,
8,
498,
29,
17,
680,
1807,
342,
267,
2351,
14,
525,
8,
11324,
1685,
8,
288,
790,
29,
17,
12,
288,
6235,
29,
277,
14,
6942,
12,
267,
5082,
267,
2351,
14,
3543,
342,
398,
291,
14,
5785,
63,
6942,
8,
6942,
63,
3494,
14,
362,
1012,
267,
663,
63,
1617,
14,
479,
63,
3527,
63,
1045,
8,
6942,
63,
3494,
9,
339,
347,
511,
63,
524,
8,
277,
304,
267,
2351,
275,
291,
14,
1730,
342,
267,
4887,
275,
9725,
18,
1258,
14,
2828,
14,
14536,
14,
6408,
8,
288,
2351,
29,
1730,
12,
288,
1402,
63,
533,
29,
11324,
1685,
12,
288,
790,
63,
354,
534,
498,
297,
288,
790,
63,
585,
29,
17,
12,
288,
3324,
63,
354,
534,
6942,
297,
267,
776,
267,
327,
13874,
3866,
6235,
1642,
370,
4911,
32592,
267,
4887,
14,
524,
8,
6126,
18,
1258,
14,
1258,
14,
13428,
1012,
267,
4887,
14,
524,
8,
277,
14,
6942,
9,
267,
2351,
14,
3543,
342,
398,
4642,
275,
2351,
14,
1131,
8,
11324,
1685,
680,
1541,
63,
991,
8,
498,
29,
17,
680,
2246,
342,
267,
291,
14,
5785,
63,
6942,
8,
4502,
14,
6942,
9,
339,
347,
511,
63,
1807,
8,
277,
304,
267,
2351,
275,
291,
14,
1730,
342,
267,
2351,
14,
525,
8,
11324,
1685,
8,
288,
790,
29,
17,
12,
288,
6235,
29,
277,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
notmatthancock/notmatthancock.github.io
|
code/py/region_growing/test_rg_c_nbhds.py
|
1
|
1325
|
import numpy as np
import time
import region_growing_python as rgp
import region_growing as rgc
from mayavi import mlab
nx = 61; ny = 51; nz = 71;
tx = np.linspace(-3,3,nx)
ty = np.linspace(-3,3,ny)
tz = np.linspace(-3,3,nz)
x,y,z = np.meshgrid(tx,ty,tz)
w = x**4 - 5*x**2 + y**4 - 5*y**2 + z**4 - 5*z**2
vol = -np.ones_like(w)
vol[np.logical_and(w >= 5, w<=20)] = 1.
vol[w <= -11] = 1.
seed = (11,45,35) # inner
#seed = (45,38,35) # outer
nbhds = np.array([1,5,10,15,25])
ntrials = 10
times = np.zeros((len(nbhds), 2, ntrials))
for i,n in enumerate(nbhds):
for j in range(ntrials):
print n
print "--------------------------------------------------"
start = time.time()
segpy = rgp.grow(vol, seed, n)
stop = time.time()
times[i,0,j] = stop-start
print("(Python) Ellapsed time: %.3f seconds." % (stop - start))
print("(Python) Errors: %d" % np.logical_xor(w <= -11, segpy).sum())
# segc = np.zeros(vol.shape, dtype=np.int8)
start = time.time()
segc = rgc.grow(vol, seed[0], seed[1], seed[2], n)
stop = time.time()
times[i,1,j] = stop-start
print("(C) Ellapsed time: %.3f seconds." % (stop - start))
print("(C) Errors: %d" % np.logical_xor(w <= -11, segc).sum())
print ""
|
mit
|
[
646,
2680,
465,
980,
199,
646,
900,
199,
646,
4897,
63,
22890,
316,
63,
1548,
465,
519,
4927,
199,
646,
4897,
63,
22890,
316,
465,
519,
9493,
199,
504,
1443,
7194,
492,
333,
5561,
199,
199,
7343,
275,
17017,
27,
25758,
275,
8026,
27,
302,
90,
275,
17245,
27,
199,
199,
2347,
275,
980,
14,
11649,
2801,
19,
12,
19,
12,
7343,
9,
199,
369,
275,
980,
14,
11649,
2801,
19,
12,
19,
12,
9745,
9,
199,
3903,
275,
980,
14,
11649,
2801,
19,
12,
19,
12,
15291,
9,
199,
199,
88,
12,
89,
12,
90,
275,
980,
14,
6480,
3825,
8,
2347,
12,
369,
12,
3903,
9,
199,
199,
87,
275,
671,
538,
20,
446,
959,
10,
88,
538,
18,
435,
612,
538,
20,
446,
959,
10,
89,
538,
18,
435,
1315,
538,
20,
446,
959,
10,
90,
538,
18,
199,
199,
5650,
275,
446,
1590,
14,
4548,
63,
2930,
8,
87,
9,
199,
5650,
59,
1590,
14,
7954,
63,
460,
8,
87,
2356,
959,
12,
336,
12932,
1165,
1874,
275,
413,
14,
199,
5650,
59,
87,
2695,
446,
845,
61,
275,
413,
14,
199,
199,
5176,
275,
334,
845,
12,
2322,
12,
1276,
9,
327,
6506,
199,
3,
5176,
275,
334,
2322,
12,
1703,
12,
1276,
9,
327,
6890,
199,
199,
4994,
72,
795,
275,
980,
14,
1144,
779,
17,
12,
21,
12,
709,
12,
1046,
12,
821,
566,
199,
343,
1383,
83,
275,
1616,
199,
4508,
275,
980,
14,
4250,
1332,
552,
8,
4994,
72,
795,
395,
499,
12,
302,
24684,
430,
199,
199,
509,
284,
12,
78,
315,
3874,
8,
4994,
72,
795,
304,
272,
367,
1335,
315,
1425,
8,
343,
1383,
83,
304,
267,
870,
302,
267,
870,
298,
6489,
306,
2,
267,
1343,
275,
900,
14,
521,
342,
267,
8812,
647,
275,
519,
4927,
14,
22890,
8,
5650,
12,
6347,
12,
302,
9,
267,
3631,
275,
900,
14,
521,
342,
398,
5431,
59,
73,
12,
16,
12,
74,
61,
275,
3631,
13,
928,
398,
870,
18353,
4718,
9,
13096,
9982,
900,
26,
10536,
19,
70,
4696,
2122,
450,
334,
2379,
446,
1343,
430,
267,
870,
18353,
4718,
9,
20456,
26,
450,
68,
2,
450,
980,
14,
7954,
63,
15721,
8,
87,
2695,
446,
845,
12,
8812,
647,
680,
1838,
1012,
199,
199,
3,
263,
8812,
67,
275,
980,
14,
4250,
8,
5650,
14,
1392,
12,
2152,
29,
1590,
14,
442,
24,
9,
267,
1343,
275,
900,
14,
521,
342,
267,
8812,
67,
275,
519,
9493,
14,
22890,
8,
5650,
12,
6347,
59,
16,
467,
6347,
59,
17,
467,
6347,
59,
18,
467,
302,
9,
4960,
3631,
275,
900,
14,
521,
342,
398,
5431,
59,
73,
12,
17,
12,
74,
61,
275,
3631,
13,
928,
398,
870,
18353,
35,
9,
420,
13096,
9982,
900,
26,
10536,
19,
70,
4696,
2122,
450,
334,
2379,
446,
1343,
430,
267,
870,
18353,
35,
9,
420,
20456,
26,
450,
68,
2,
450,
980,
14,
7954,
63,
15721,
8,
87,
2695,
446,
845,
12,
8812,
67,
680,
1838,
1012,
267,
870,
3087,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2680,
465,
980,
199,
646,
900,
199,
646,
4897,
63,
22890,
316,
63,
1548,
465,
519,
4927,
199,
646,
4897,
63,
22890,
316,
465,
519,
9493,
199,
504,
1443,
7194,
492,
333,
5561,
199,
199,
7343,
275,
17017,
27,
25758,
275,
8026,
27,
302,
90,
275,
17245,
27,
199,
199,
2347,
275,
980,
14,
11649,
2801,
19,
12,
19,
12,
7343,
9,
199,
369,
275,
980,
14,
11649,
2801,
19,
12,
19,
12,
9745,
9,
199,
3903,
275,
980,
14,
11649,
2801,
19,
12,
19,
12,
15291,
9,
199,
199,
88,
12,
89,
12,
90,
275,
980,
14,
6480,
3825,
8,
2347,
12,
369,
12,
3903,
9,
199,
199,
87,
275,
671,
538,
20,
446,
959,
10,
88,
538,
18,
435,
612,
538,
20,
446,
959,
10,
89,
538,
18,
435,
1315,
538,
20,
446,
959,
10,
90,
538,
18,
199,
199,
5650,
275,
446,
1590,
14,
4548,
63,
2930,
8,
87,
9,
199,
5650,
59,
1590,
14,
7954,
63,
460,
8,
87,
2356,
959,
12,
336,
12932,
1165,
1874,
275,
413,
14,
199,
5650,
59,
87,
2695,
446,
845,
61,
275,
413,
14,
199,
199,
5176,
275,
334,
845,
12,
2322,
12,
1276,
9,
327,
6506,
199,
3,
5176,
275,
334,
2322,
12,
1703,
12,
1276,
9,
327,
6890,
199,
199,
4994,
72,
795,
275,
980,
14,
1144,
779,
17,
12,
21,
12,
709,
12,
1046,
12,
821,
566,
199,
343,
1383,
83,
275,
1616,
199,
4508,
275,
980,
14,
4250,
1332,
552,
8,
4994,
72,
795,
395,
499,
12,
302,
24684,
430,
199,
199,
509,
284,
12,
78,
315,
3874,
8,
4994,
72,
795,
304,
272,
367,
1335,
315,
1425,
8,
343,
1383,
83,
304,
267,
870,
302,
267,
870,
298,
6489,
306,
2,
267,
1343,
275,
900,
14,
521,
342,
267,
8812,
647,
275,
519,
4927,
14,
22890,
8,
5650,
12,
6347,
12,
302,
9,
267,
3631,
275,
900,
14,
521,
342,
398,
5431,
59,
73,
12,
16,
12,
74,
61,
275,
3631,
13,
928,
398,
870,
18353,
4718,
9,
13096,
9982,
900,
26,
10536,
19,
70,
4696,
2122,
450,
334,
2379,
446,
1343,
430,
267,
870,
18353,
4718,
9,
20456,
26,
450,
68,
2,
450,
980,
14,
7954,
63,
15721,
8,
87,
2695,
446,
845,
12,
8812,
647,
680,
1838,
1012,
199,
199,
3,
263,
8812,
67,
275,
980,
14,
4250,
8,
5650,
14,
1392,
12,
2152,
29,
1590,
14,
442,
24,
9,
267,
1343,
275,
900,
14,
521,
342,
267,
8812,
67,
275,
519,
9493,
14,
22890,
8,
5650,
12,
6347,
59,
16,
467,
6347,
59,
17,
467,
6347,
59,
18,
467,
302,
9,
4960,
3631,
275,
900,
14,
521,
342,
398,
5431,
59,
73,
12,
17,
12,
74,
61,
275,
3631,
13,
928,
398,
870,
18353,
35,
9,
420,
13096,
9982,
900,
26,
10536,
19,
70,
4696,
2122,
450,
334,
2379,
446,
1343,
430,
267,
870,
18353,
35,
9,
420,
20456,
26,
450,
68,
2,
450,
980,
14,
7954,
63,
15721,
8,
87,
2695,
446,
845,
12,
8812,
67,
680,
1838,
1012,
267,
870,
3087,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
wpoely86/vsc-base
|
lib/vsc/utils/docs.py
|
2
|
2359
|
# #
# Copyright 2015-2015 Ghent University
#
# This file is part of vsc-base,
# originally created by the HPC team of Ghent University (http://ugent.be/hpc/en),
# with support of Ghent University (http://ugent.be/hpc),
# the Flemish Supercomputer Centre (VSC) (https://vscentrum.be/nl/en),
# the Hercules foundation (http://www.herculesstichting.be/in_English)
# and the Department of Economy, Science and Innovation (EWI) (http://www.ewi-vlaanderen.be/en).
#
# http://github.com/hpcugent/vsc-base
#
# vsc-base is free software: you can redistribute it and/or modify
# it under the terms of the GNU Library General Public License as
# published by the Free Software Foundation, either version 2 of
# the License, or (at your option) any later version.
#
# vsc-base 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 vsc-base. If not, see <http://www.gnu.org/licenses/>.
# #
"""
Functions for generating rst documentation
@author: Caroline De Brouwer (Ghent University)
"""
INDENT_4SPACES = ' ' * 4
class LengthNotEqualException(ValueError):
pass
def mk_rst_table(titles, columns):
"""
Returns an rst table with given titles and columns (a nested list of string columns for each column)
"""
title_cnt, col_cnt = len(titles), len(columns)
if title_cnt != col_cnt:
msg = "Number of titles/columns should be equal, found %d titles and %d columns" % (title_cnt, col_cnt)
raise LengthNotEqualException, msg
table = []
col_widths = []
tmpl = []
line= []
# figure out column widths
for i, title in enumerate(titles):
width = max(map(len, columns[i] + [title]))
# make line template
tmpl.append('{%s:{c}<%s}' % (i, width))
line = [''] * col_cnt
line_tmpl = INDENT_4SPACES.join(tmpl)
table_line = line_tmpl.format(*line, c='=')
table.append(table_line)
table.append(line_tmpl.format(*titles, c=' '))
table.append(table_line)
for row in map(list, zip(*columns)):
table.append(line_tmpl.format(*row, c=' '))
table.extend([table_line, ''])
return table
|
lgpl-2.1
|
[
3,
327,
199,
3,
1898,
6900,
13,
7806,
598,
72,
484,
15904,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
373,
551,
13,
1095,
12,
199,
3,
20657,
2737,
701,
314,
869,
4222,
8099,
402,
598,
72,
484,
15904,
334,
1014,
921,
1518,
484,
14,
1235,
15,
72,
2352,
15,
287,
395,
199,
3,
543,
2291,
402,
598,
72,
484,
15904,
334,
1014,
921,
1518,
484,
14,
1235,
15,
72,
2352,
395,
199,
3,
314,
481,
274,
1292,
72,
17897,
23805,
30610,
264,
334,
54,
5153,
9,
334,
2859,
921,
86,
10845,
454,
453,
14,
1235,
15,
7530,
15,
287,
395,
199,
3,
314,
18769,
67,
443,
83,
1911,
425,
334,
1014,
921,
1544,
14,
2523,
67,
443,
83,
270,
1158,
1337,
14,
1235,
15,
262,
63,
19410,
9,
199,
3,
436,
314,
1487,
12493,
402,
662,
25129,
89,
12,
27491,
436,
1010,
889,
4255,
334,
37,
18759,
9,
334,
1014,
921,
1544,
14,
546,
73,
13,
86,
416,
290,
271,
828,
14,
1235,
15,
287,
680,
199,
3,
199,
3,
1455,
921,
5031,
14,
957,
15,
72,
2352,
1518,
484,
15,
86,
551,
13,
1095,
199,
3,
199,
3,
373,
551,
13,
1095,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
11243,
1696,
1684,
844,
465,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
499,
402,
199,
3,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
373,
551,
13,
1095,
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,
11243,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
11243,
1696,
1684,
844,
199,
3,
3180,
543,
373,
551,
13,
1095,
14,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
327,
199,
624,
199,
13967,
367,
12999,
23720,
3794,
199,
199,
32,
2502,
26,
14243,
393,
1132,
1487,
699,
7930,
2135,
334,
39,
72,
484,
15904,
9,
199,
624,
199,
199,
29080,
63,
20,
5763,
21287,
275,
283,
283,
627,
841,
421,
199,
533,
19893,
1763,
591,
1726,
8,
3393,
304,
272,
986,
421,
199,
318,
9199,
63,
8332,
63,
1224,
8,
8916,
12,
4362,
304,
272,
408,
272,
1803,
376,
23720,
1817,
543,
1627,
16194,
436,
4362,
334,
65,
6032,
769,
402,
1059,
4362,
367,
1924,
2763,
9,
272,
408,
272,
2538,
63,
6507,
12,
1048,
63,
6507,
275,
822,
8,
8916,
395,
822,
8,
3406,
9,
272,
340,
2538,
63,
6507,
1137,
1048,
63,
6507,
26,
267,
1499,
275,
298,
3259,
402,
16194,
15,
3406,
1077,
506,
4472,
12,
1911,
450,
68,
16194,
436,
450,
68,
4362,
2,
450,
334,
1213,
63,
6507,
12,
1048,
63,
6507,
9,
267,
746,
19893,
1763,
591,
1726,
12,
1499,
272,
1817,
275,
942,
272,
1048,
63,
22209,
275,
942,
272,
9675,
275,
942,
272,
1004,
29,
942,
339,
327,
9658,
734,
2763,
28186,
272,
367,
284,
12,
2538,
315,
3874,
8,
8916,
304,
267,
3462,
275,
1390,
8,
1130,
8,
552,
12,
4362,
59,
73,
61,
435,
359,
1213,
2459,
398,
327,
1852,
1004,
1978,
267,
9675,
14,
740,
24103,
83,
14534,
67,
93,
21110,
83,
6834,
450,
334,
73,
12,
3462,
430,
339,
1004,
275,
24506,
627,
1048,
63,
6507,
272,
1004,
63,
11510,
275,
23632,
1309,
63,
20,
5763,
21287,
14,
904,
8,
11510,
9,
272,
1817,
63,
604,
275,
1004,
63,
11510,
14,
908,
2031,
604,
12,
286,
534,
14619,
339,
1817,
14,
740,
8,
1224,
63,
604,
9,
272,
1817,
14,
740,
8,
604,
63,
11510,
14,
908,
2031,
8916,
12,
286,
534,
20005,
272,
1817,
14,
740,
8,
1224,
63,
604,
9,
339,
367,
1962,
315,
2341,
8,
513,
12,
3482,
2031,
3406,
2298,
267,
1817,
14,
740,
8,
604,
63,
11510,
14,
908,
2031,
1143,
12,
286,
534,
20005,
339,
1817,
14,
2880,
779,
1224,
63,
604,
12,
283,
1105,
339,
372,
1817,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
327,
199,
3,
1898,
6900,
13,
7806,
598,
72,
484,
15904,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
373,
551,
13,
1095,
12,
199,
3,
20657,
2737,
701,
314,
869,
4222,
8099,
402,
598,
72,
484,
15904,
334,
1014,
921,
1518,
484,
14,
1235,
15,
72,
2352,
15,
287,
395,
199,
3,
543,
2291,
402,
598,
72,
484,
15904,
334,
1014,
921,
1518,
484,
14,
1235,
15,
72,
2352,
395,
199,
3,
314,
481,
274,
1292,
72,
17897,
23805,
30610,
264,
334,
54,
5153,
9,
334,
2859,
921,
86,
10845,
454,
453,
14,
1235,
15,
7530,
15,
287,
395,
199,
3,
314,
18769,
67,
443,
83,
1911,
425,
334,
1014,
921,
1544,
14,
2523,
67,
443,
83,
270,
1158,
1337,
14,
1235,
15,
262,
63,
19410,
9,
199,
3,
436,
314,
1487,
12493,
402,
662,
25129,
89,
12,
27491,
436,
1010,
889,
4255,
334,
37,
18759,
9,
334,
1014,
921,
1544,
14,
546,
73,
13,
86,
416,
290,
271,
828,
14,
1235,
15,
287,
680,
199,
3,
199,
3,
1455,
921,
5031,
14,
957,
15,
72,
2352,
1518,
484,
15,
86,
551,
13,
1095,
199,
3,
199,
3,
373,
551,
13,
1095,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
11243,
1696,
1684,
844,
465,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
499,
402,
199,
3,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
373,
551,
13,
1095,
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,
11243,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
11243,
1696,
1684,
844,
199,
3,
3180,
543,
373,
551,
13,
1095,
14,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
327,
199,
624,
199,
13967,
367,
12999,
23720,
3794,
199,
199,
32,
2502,
26,
14243,
393,
1132,
1487,
699,
7930,
2135,
334,
39,
72,
484,
15904,
9,
199,
624,
199,
199,
29080,
63,
20,
5763,
21287,
275,
283,
283,
627,
841,
421,
199,
533,
19893,
1763,
591,
1726,
8,
3393,
304,
272,
986,
421,
199,
318,
9199,
63,
8332,
63,
1224,
8,
8916,
12,
4362,
304,
272,
408,
272,
1803,
376,
23720,
1817,
543,
1627,
16194,
436,
4362,
334,
65,
6032,
769,
402,
1059,
4362,
367,
1924,
2763,
9,
272,
408,
272,
2538,
63,
6507,
12,
1048,
63,
6507,
275,
822,
8,
8916,
395,
822,
8,
3406,
9,
272,
340,
2538,
63,
6507,
1137,
1048,
63,
6507,
26,
267,
1499,
275,
298,
3259,
402,
16194,
15,
3406,
1077,
506,
4472,
12,
1911,
450,
68,
16194,
436,
450,
68,
4362,
2,
450,
334,
1213,
63,
6507,
12,
1048,
63,
6507,
9,
267,
746,
19893,
1763,
591,
1726,
12,
1499,
272,
1817,
275,
942,
272,
1048,
63,
22209,
275,
942,
272,
9675,
275,
942,
272,
1004,
29,
942,
339,
327,
9658,
734,
2763,
28186,
272,
367,
284,
12,
2538,
315,
3874,
8,
8916,
304,
267,
3462,
275,
1390,
8,
1130,
8,
552,
12,
4362,
59,
73,
61,
435,
359,
1213,
2459,
398,
327,
1852,
1004,
1978,
267,
9675,
14,
740,
24103,
83,
14534,
67,
93,
21110,
83,
6834,
450,
334,
73,
12,
3462,
430,
339,
1004,
275,
24506,
627,
1048,
63,
6507,
272,
1004,
63,
11510,
275,
23632,
1309,
63,
20,
5763,
21287,
14,
904,
8,
11510,
9,
272,
1817,
63,
604,
275,
1004,
63,
11510,
14,
908,
2031,
604,
12,
286,
534,
14619,
339,
1817,
14,
740,
8,
1224,
63,
604,
9,
272,
1817,
14,
740,
8,
604,
63,
11510,
14,
908,
2031,
8916,
12,
286,
534,
20005,
272,
1817,
14,
740,
8,
1224,
63,
604,
9,
339,
367,
1962,
315,
2341,
8,
513,
12,
3482,
2031,
3406,
2298,
267,
1817,
14,
740,
8,
604,
63,
11510,
14,
908,
2031,
1143,
12,
286,
534,
20005,
339,
1817,
14,
2880,
779,
1224,
63,
604,
12,
283,
1105,
339,
372,
1817,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
lingcheng99/Algorithm
|
UnorderedList.py
|
1
|
2979
|
"""
Implement Unordered List, or linked list, in python.
The building block is the class Node.
Refer to http://interactivepython.org/runestone/static/pythonds/BasicDS/ImplementinganUnorderedListLinkedLists.html
With added functions append(),index(),insert(),pop()
"""
class Node:
def __init__(self,initdata):
self.data = initdata
self.next = None
def getData(self):
return self.data
def getNext(self):
return self.next
def setData(self,newdata):
self.data = newdata
def setNext(self,newnext):
self.next = newnext
class UnorderedList:
def __init__(self):
self.head = None
def isEmpty(self):
return self.head == None
def add(self,item):
temp = Node(item)
temp.setNext(self.head)
self.head = temp
def size(self):
current = self.head
count = 0
while current != None:
count = count + 1
current = current.getNext()
return count
def search(self,item):
current = self.head
found = False
while current != None and not found:
if current.getData() == item:
found = True
else:
current = current.getNext()
return found
def remove(self,item):
current = self.head
previous = None
found = False
while not found:
if current.getData() == item:
found = True
else:
previous = current
current = current.getNext()
if previous == None:
self.head = current.getNext()
else:
previous.setNext(current.getNext())
def append(self,item):
current=self.head
while current.getNext()!=None:
current=current.getNext()
temp=Node(item)
current.setNext(temp)
def index(self,item):
current=self.head
position=0
while current.getData()!=item and current.getNext()!=None:
current=current.getNext()
position+=1
if current.getData()==item:
return position
else:
return 'Not found'
def insert(self,pos,item):
if pos==0:
self.add(item)
return
current=self.head
location=1
while current.getNext()!=None and location!=pos:
current=current.getNext()
location+=1
temp=Node(item)
after=current.getNext()
current.setNext(temp)
temp.setNext(after)
def pop(self,pos):
current=self.head
if pos==0:
self.head=current.getNext()
return
location=1
while current.getNext()!=None and location!=pos:
current=current.getNext()
location+=1
after=current.getNext().getNext()
current.setNext(after)
|
mit
|
[
624,
199,
26924,
1910,
8235,
3820,
12,
503,
10632,
769,
12,
315,
2366,
14,
199,
1918,
10015,
1853,
365,
314,
1021,
5013,
14,
199,
497,
2412,
370,
1455,
921,
13543,
1548,
14,
1308,
15,
1065,
597,
368,
15,
1986,
15,
1548,
795,
15,
6845,
3177,
15,
26924,
316,
290,
1358,
8235,
1296,
26748,
15116,
14,
1360,
199,
3007,
3483,
3423,
5666,
1062,
1080,
1062,
3176,
1062,
1935,
342,
199,
624,
199,
199,
533,
5013,
26,
272,
347,
636,
826,
721,
277,
12,
826,
576,
304,
267,
291,
14,
576,
275,
4205,
576,
267,
291,
14,
2184,
275,
488,
339,
347,
664,
1451,
8,
277,
304,
267,
372,
291,
14,
576,
339,
347,
664,
5765,
8,
277,
304,
267,
372,
291,
14,
2184,
339,
347,
663,
1451,
8,
277,
12,
1222,
576,
304,
267,
291,
14,
576,
275,
892,
576,
339,
347,
663,
5765,
8,
277,
12,
1222,
2184,
304,
267,
291,
14,
2184,
275,
892,
2184,
27844,
199,
533,
1910,
8235,
1296,
26,
339,
347,
636,
826,
721,
277,
304,
267,
291,
14,
2993,
275,
488,
339,
347,
365,
4699,
8,
277,
304,
267,
372,
291,
14,
2993,
508,
488,
339,
347,
1050,
8,
277,
12,
1053,
304,
267,
2388,
275,
5013,
8,
1053,
9,
267,
2388,
14,
409,
5765,
8,
277,
14,
2993,
9,
267,
291,
14,
2993,
275,
2388,
339,
347,
1568,
8,
277,
304,
267,
1453,
275,
291,
14,
2993,
267,
2338,
275,
378,
267,
1830,
1453,
1137,
488,
26,
288,
2338,
275,
2338,
435,
413,
288,
1453,
275,
1453,
14,
362,
5765,
342,
267,
372,
2338,
339,
347,
2754,
8,
277,
12,
1053,
304,
267,
1453,
275,
291,
14,
2993,
267,
1911,
275,
756,
267,
1830,
1453,
1137,
488,
436,
440,
1911,
26,
288,
340,
1453,
14,
29276,
342,
508,
1242,
26,
355,
1911,
275,
715,
288,
587,
26,
355,
1453,
275,
1453,
14,
362,
5765,
342,
267,
372,
1911,
339,
347,
2813,
8,
277,
12,
1053,
304,
267,
1453,
275,
291,
14,
2993,
267,
4136,
275,
488,
267,
1911,
275,
756,
267,
1830,
440,
1911,
26,
288,
340,
1453,
14,
29276,
342,
508,
1242,
26,
355,
1911,
275,
715,
288,
587,
26,
355,
4136,
275,
1453,
355,
1453,
275,
1453,
14,
362,
5765,
342,
267,
340,
4136,
508,
488,
26,
288,
291,
14,
2993,
275,
1453,
14,
362,
5765,
342,
267,
587,
26,
288,
4136,
14,
409,
5765,
8,
1818,
14,
362,
5765,
1012,
15567,
347,
5666,
8,
277,
12,
1053,
304,
267,
1453,
29,
277,
14,
2993,
267,
1830,
1453,
14,
362,
5765,
342,
1111,
403,
26,
288,
1453,
29,
1818,
14,
362,
5765,
342,
267,
2388,
29,
1716,
8,
1053,
9,
267,
1453,
14,
409,
5765,
8,
808,
9,
5493,
347,
1478,
8,
277,
12,
1053,
304,
267,
1453,
29,
277,
14,
2993,
267,
3421,
29,
16,
267,
1830,
1453,
14,
29276,
342,
1111,
1053,
436,
1453,
14,
362,
5765,
342,
1111,
403,
26,
288,
1453,
29,
1818,
14,
362,
5765,
342,
288,
3421,
10365,
17,
267,
340,
1453,
14,
29276,
342,
389,
1053,
26,
288,
372,
3421,
267,
587,
26,
288,
372,
283,
1763,
1911,
7,
5493,
347,
5518,
8,
277,
12,
1712,
12,
1053,
304,
267,
340,
2086,
389,
16,
26,
288,
291,
14,
525,
8,
1053,
9,
288,
372,
267,
1453,
29,
277,
14,
2993,
267,
2909,
29,
17,
267,
1830,
1453,
14,
362,
5765,
342,
1111,
403,
436,
2909,
1111,
1712,
26,
288,
1453,
29,
1818,
14,
362,
5765,
342,
288,
2909,
10365,
17,
267,
2388,
29,
1716,
8,
1053,
9,
267,
2410,
29,
1818,
14,
362,
5765,
342,
267,
1453,
14,
409,
5765,
8,
808,
9,
267,
2388,
14,
409,
5765,
8,
4399,
9,
5493,
347,
4560,
8,
277,
12,
1712,
304,
267,
1453,
29,
277,
14,
2993,
267,
340,
2086,
389,
16,
26,
288,
291,
14,
2993,
29,
1818,
14,
362,
5765,
342,
288,
372,
18418,
2909,
29,
17,
267,
1830,
1453,
14,
362,
5765,
342,
1111,
403,
436,
2909,
1111,
1712,
26,
288,
1453,
29,
1818,
14,
362,
5765,
342,
288,
2909,
10365,
17,
267,
2410,
29,
1818,
14,
362,
5765,
1252,
362,
5765,
342,
267,
1453,
14,
409,
5765,
8,
4399,
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
] |
[
199,
26924,
1910,
8235,
3820,
12,
503,
10632,
769,
12,
315,
2366,
14,
199,
1918,
10015,
1853,
365,
314,
1021,
5013,
14,
199,
497,
2412,
370,
1455,
921,
13543,
1548,
14,
1308,
15,
1065,
597,
368,
15,
1986,
15,
1548,
795,
15,
6845,
3177,
15,
26924,
316,
290,
1358,
8235,
1296,
26748,
15116,
14,
1360,
199,
3007,
3483,
3423,
5666,
1062,
1080,
1062,
3176,
1062,
1935,
342,
199,
624,
199,
199,
533,
5013,
26,
272,
347,
636,
826,
721,
277,
12,
826,
576,
304,
267,
291,
14,
576,
275,
4205,
576,
267,
291,
14,
2184,
275,
488,
339,
347,
664,
1451,
8,
277,
304,
267,
372,
291,
14,
576,
339,
347,
664,
5765,
8,
277,
304,
267,
372,
291,
14,
2184,
339,
347,
663,
1451,
8,
277,
12,
1222,
576,
304,
267,
291,
14,
576,
275,
892,
576,
339,
347,
663,
5765,
8,
277,
12,
1222,
2184,
304,
267,
291,
14,
2184,
275,
892,
2184,
27844,
199,
533,
1910,
8235,
1296,
26,
339,
347,
636,
826,
721,
277,
304,
267,
291,
14,
2993,
275,
488,
339,
347,
365,
4699,
8,
277,
304,
267,
372,
291,
14,
2993,
508,
488,
339,
347,
1050,
8,
277,
12,
1053,
304,
267,
2388,
275,
5013,
8,
1053,
9,
267,
2388,
14,
409,
5765,
8,
277,
14,
2993,
9,
267,
291,
14,
2993,
275,
2388,
339,
347,
1568,
8,
277,
304,
267,
1453,
275,
291,
14,
2993,
267,
2338,
275,
378,
267,
1830,
1453,
1137,
488,
26,
288,
2338,
275,
2338,
435,
413,
288,
1453,
275,
1453,
14,
362,
5765,
342,
267,
372,
2338,
339,
347,
2754,
8,
277,
12,
1053,
304,
267,
1453,
275,
291,
14,
2993,
267,
1911,
275,
756,
267,
1830,
1453,
1137,
488,
436,
440,
1911,
26,
288,
340,
1453,
14,
29276,
342,
508,
1242,
26,
355,
1911,
275,
715,
288,
587,
26,
355,
1453,
275,
1453,
14,
362,
5765,
342,
267,
372,
1911,
339,
347,
2813,
8,
277,
12,
1053,
304,
267,
1453,
275,
291,
14,
2993,
267,
4136,
275,
488,
267,
1911,
275,
756,
267,
1830,
440,
1911,
26,
288,
340,
1453,
14,
29276,
342,
508,
1242,
26,
355,
1911,
275,
715,
288,
587,
26,
355,
4136,
275,
1453,
355,
1453,
275,
1453,
14,
362,
5765,
342,
267,
340,
4136,
508,
488,
26,
288,
291,
14,
2993,
275,
1453,
14,
362,
5765,
342,
267,
587,
26,
288,
4136,
14,
409,
5765,
8,
1818,
14,
362,
5765,
1012,
15567,
347,
5666,
8,
277,
12,
1053,
304,
267,
1453,
29,
277,
14,
2993,
267,
1830,
1453,
14,
362,
5765,
342,
1111,
403,
26,
288,
1453,
29,
1818,
14,
362,
5765,
342,
267,
2388,
29,
1716,
8,
1053,
9,
267,
1453,
14,
409,
5765,
8,
808,
9,
5493,
347,
1478,
8,
277,
12,
1053,
304,
267,
1453,
29,
277,
14,
2993,
267,
3421,
29,
16,
267,
1830,
1453,
14,
29276,
342,
1111,
1053,
436,
1453,
14,
362,
5765,
342,
1111,
403,
26,
288,
1453,
29,
1818,
14,
362,
5765,
342,
288,
3421,
10365,
17,
267,
340,
1453,
14,
29276,
342,
389,
1053,
26,
288,
372,
3421,
267,
587,
26,
288,
372,
283,
1763,
1911,
7,
5493,
347,
5518,
8,
277,
12,
1712,
12,
1053,
304,
267,
340,
2086,
389,
16,
26,
288,
291,
14,
525,
8,
1053,
9,
288,
372,
267,
1453,
29,
277,
14,
2993,
267,
2909,
29,
17,
267,
1830,
1453,
14,
362,
5765,
342,
1111,
403,
436,
2909,
1111,
1712,
26,
288,
1453,
29,
1818,
14,
362,
5765,
342,
288,
2909,
10365,
17,
267,
2388,
29,
1716,
8,
1053,
9,
267,
2410,
29,
1818,
14,
362,
5765,
342,
267,
1453,
14,
409,
5765,
8,
808,
9,
267,
2388,
14,
409,
5765,
8,
4399,
9,
5493,
347,
4560,
8,
277,
12,
1712,
304,
267,
1453,
29,
277,
14,
2993,
267,
340,
2086,
389,
16,
26,
288,
291,
14,
2993,
29,
1818,
14,
362,
5765,
342,
288,
372,
18418,
2909,
29,
17,
267,
1830,
1453,
14,
362,
5765,
342,
1111,
403,
436,
2909,
1111,
1712,
26,
288,
1453,
29,
1818,
14,
362,
5765,
342,
288,
2909,
10365,
17,
267,
2410,
29,
1818,
14,
362,
5765,
1252,
362,
5765,
342,
267,
1453,
14,
409,
5765,
8,
4399,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
gangadhar-kadam/lgnlvefrape
|
frappe/core/report/permitted_documents_for_user/permitted_documents_for_user.py
|
32
|
1678
|
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
# MIT License. See license.txt
from __future__ import unicode_literals
import frappe
from frappe import _, throw
import frappe.utils.user
from frappe.permissions import check_admin_or_system_manager
from frappe.model.db_schema import type_map
def execute(filters=None):
user, doctype = filters.get("user"), filters.get("doctype")
validate(user, doctype)
columns, fields = get_columns_and_fields(doctype)
data = frappe.get_list(doctype, fields=fields, as_list=True, user=user)
return columns, data
def validate(user, doctype):
# check if current user is System Manager
check_admin_or_system_manager()
if not user:
throw(_("Please specify user"))
if not doctype:
throw(_("Please specify doctype"))
def get_columns_and_fields(doctype):
columns = ["Name:Link/{}:200".format(doctype)]
fields = ["name"]
for df in frappe.get_meta(doctype).fields:
if df.in_list_view and df.fieldtype in type_map:
fields.append(df.fieldname)
fieldtype = "Link/{}".format(df.options) if df.fieldtype=="Link" else df.fieldtype
columns.append("{label}:{fieldtype}:{width}".format(label=df.label, fieldtype=fieldtype, width=df.width or 100))
return columns, fields
def query_doctypes(doctype, txt, searchfield, start, page_len, filters):
user = filters.get("user")
user_obj = frappe.utils.user.User(user)
user_obj.build_permissions()
can_read = user_obj.can_read
single_doctypes = [d[0] for d in frappe.db.get_values("DocType", {"issingle": 1})]
out = []
for dt in can_read:
if txt.lower().replace("%", "") in dt.lower() and dt not in single_doctypes:
out.append([dt])
return out
|
mit
|
[
3,
1898,
334,
67,
9,
6171,
12,
6001,
8144,
19215,
29053,
14,
12126,
14,
436,
23212,
199,
3,
10697,
844,
14,
1666,
4190,
14,
2424,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
646,
6950,
199,
504,
6950,
492,
5501,
7978,
199,
646,
6950,
14,
1208,
14,
751,
199,
504,
6950,
14,
6060,
492,
1104,
63,
2113,
63,
269,
63,
2253,
63,
2609,
199,
504,
6950,
14,
1238,
14,
697,
63,
3629,
492,
730,
63,
1130,
199,
199,
318,
5341,
8,
4273,
29,
403,
304,
199,
198,
751,
12,
13265,
275,
4766,
14,
362,
480,
751,
1288,
4766,
14,
362,
480,
6356,
531,
199,
198,
3502,
8,
751,
12,
13265,
9,
421,
198,
3406,
12,
1504,
275,
664,
63,
3406,
63,
460,
63,
955,
8,
6356,
9,
199,
198,
576,
275,
6950,
14,
362,
63,
513,
8,
6356,
12,
1504,
29,
955,
12,
465,
63,
513,
29,
549,
12,
922,
29,
751,
9,
421,
198,
1107,
4362,
12,
666,
199,
199,
318,
4107,
8,
751,
12,
13265,
304,
199,
198,
3,
1104,
340,
1453,
922,
365,
6187,
13537,
199,
198,
1074,
63,
2113,
63,
269,
63,
2253,
63,
2609,
342,
421,
198,
692,
440,
922,
26,
507,
198,
11964,
6115,
8254,
4165,
922,
2237,
421,
198,
692,
440,
13265,
26,
507,
198,
11964,
6115,
8254,
4165,
13265,
2237,
199,
199,
318,
664,
63,
3406,
63,
460,
63,
955,
8,
6356,
304,
199,
198,
3406,
275,
2097,
985,
26,
3834,
14698,
26,
1840,
1674,
908,
8,
6356,
1874,
199,
198,
955,
275,
2097,
354,
937,
199,
198,
509,
4051,
315,
6950,
14,
362,
63,
2024,
8,
6356,
680,
955,
26,
507,
198,
692,
4051,
14,
262,
63,
513,
63,
1345,
436,
4051,
14,
698,
466,
315,
730,
63,
1130,
26,
686,
198,
955,
14,
740,
8,
1587,
14,
13646,
9,
686,
198,
698,
466,
275,
298,
3834,
15,
13536,
908,
8,
1587,
14,
1419,
9,
340,
4051,
14,
698,
466,
11800,
3834,
2,
587,
4051,
14,
698,
466,
686,
198,
3406,
14,
740,
13076,
1302,
16495,
698,
466,
16495,
2063,
5469,
908,
8,
1302,
29,
1587,
14,
1302,
12,
901,
466,
29,
698,
466,
12,
3462,
29,
1587,
14,
2063,
503,
2948,
430,
421,
198,
1107,
4362,
12,
1504,
199,
199,
318,
1827,
63,
6356,
83,
8,
6356,
12,
9444,
12,
2754,
698,
12,
1343,
12,
2034,
63,
552,
12,
4766,
304,
199,
198,
751,
275,
4766,
14,
362,
480,
751,
531,
199,
198,
751,
63,
1113,
275,
6950,
14,
1208,
14,
751,
14,
1899,
8,
751,
9,
199,
198,
751,
63,
1113,
14,
1506,
63,
6060,
342,
199,
198,
2425,
63,
739,
275,
922,
63,
1113,
14,
2425,
63,
739,
421,
198,
4780,
63,
6356,
83,
275,
359,
68,
59,
16,
61,
367,
366,
315,
6950,
14,
697,
14,
362,
63,
1459,
480,
3768,
804,
401,
2420,
374,
4780,
582,
413,
1552,
61,
421,
198,
548,
275,
942,
199,
198,
509,
4487,
315,
883,
63,
739,
26,
507,
198,
692,
9444,
14,
2325,
1252,
1814,
3647,
401,
6899,
315,
4487,
14,
2325,
342,
436,
4487,
440,
315,
2849,
63,
6356,
83,
26,
686,
198,
548,
14,
740,
779,
3583,
566,
421,
198,
1107,
734,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
334,
67,
9,
6171,
12,
6001,
8144,
19215,
29053,
14,
12126,
14,
436,
23212,
199,
3,
10697,
844,
14,
1666,
4190,
14,
2424,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
646,
6950,
199,
504,
6950,
492,
5501,
7978,
199,
646,
6950,
14,
1208,
14,
751,
199,
504,
6950,
14,
6060,
492,
1104,
63,
2113,
63,
269,
63,
2253,
63,
2609,
199,
504,
6950,
14,
1238,
14,
697,
63,
3629,
492,
730,
63,
1130,
199,
199,
318,
5341,
8,
4273,
29,
403,
304,
199,
198,
751,
12,
13265,
275,
4766,
14,
362,
480,
751,
1288,
4766,
14,
362,
480,
6356,
531,
199,
198,
3502,
8,
751,
12,
13265,
9,
421,
198,
3406,
12,
1504,
275,
664,
63,
3406,
63,
460,
63,
955,
8,
6356,
9,
199,
198,
576,
275,
6950,
14,
362,
63,
513,
8,
6356,
12,
1504,
29,
955,
12,
465,
63,
513,
29,
549,
12,
922,
29,
751,
9,
421,
198,
1107,
4362,
12,
666,
199,
199,
318,
4107,
8,
751,
12,
13265,
304,
199,
198,
3,
1104,
340,
1453,
922,
365,
6187,
13537,
199,
198,
1074,
63,
2113,
63,
269,
63,
2253,
63,
2609,
342,
421,
198,
692,
440,
922,
26,
507,
198,
11964,
6115,
8254,
4165,
922,
2237,
421,
198,
692,
440,
13265,
26,
507,
198,
11964,
6115,
8254,
4165,
13265,
2237,
199,
199,
318,
664,
63,
3406,
63,
460,
63,
955,
8,
6356,
304,
199,
198,
3406,
275,
2097,
985,
26,
3834,
14698,
26,
1840,
1674,
908,
8,
6356,
1874,
199,
198,
955,
275,
2097,
354,
937,
199,
198,
509,
4051,
315,
6950,
14,
362,
63,
2024,
8,
6356,
680,
955,
26,
507,
198,
692,
4051,
14,
262,
63,
513,
63,
1345,
436,
4051,
14,
698,
466,
315,
730,
63,
1130,
26,
686,
198,
955,
14,
740,
8,
1587,
14,
13646,
9,
686,
198,
698,
466,
275,
298,
3834,
15,
13536,
908,
8,
1587,
14,
1419,
9,
340,
4051,
14,
698,
466,
11800,
3834,
2,
587,
4051,
14,
698,
466,
686,
198,
3406,
14,
740,
13076,
1302,
16495,
698,
466,
16495,
2063,
5469,
908,
8,
1302,
29,
1587,
14,
1302,
12,
901,
466,
29,
698,
466,
12,
3462,
29,
1587,
14,
2063,
503,
2948,
430,
421,
198,
1107,
4362,
12,
1504,
199,
199,
318,
1827,
63,
6356,
83,
8,
6356,
12,
9444,
12,
2754,
698,
12,
1343,
12,
2034,
63,
552,
12,
4766,
304,
199,
198,
751,
275,
4766,
14,
362,
480,
751,
531,
199,
198,
751,
63,
1113,
275,
6950,
14,
1208,
14,
751,
14,
1899,
8,
751,
9,
199,
198,
751,
63,
1113,
14,
1506,
63,
6060,
342,
199,
198,
2425,
63,
739,
275,
922,
63,
1113,
14,
2425,
63,
739,
421,
198,
4780,
63,
6356,
83,
275,
359,
68,
59,
16,
61,
367,
366,
315,
6950,
14,
697,
14,
362,
63,
1459,
480,
3768,
804,
401,
2420,
374,
4780,
582,
413,
1552,
61,
421,
198,
548,
275,
942,
199,
198,
509,
4487,
315,
883,
63,
739,
26,
507,
198,
692,
9444,
14,
2325,
1252,
1814,
3647,
401,
6899,
315,
4487,
14,
2325,
342,
436,
4487,
440,
315,
2849,
63,
6356,
83,
26,
686,
198,
548,
14,
740,
779,
3583,
566,
421,
198,
1107,
734,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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
] |
orgito/ansible
|
lib/ansible/module_utils/common/dict_transformations.py
|
27
|
5003
|
# -*- coding: utf-8 -*-
# Copyright: (c) 2018, 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
import re
from copy import deepcopy
def camel_dict_to_snake_dict(camel_dict, reversible=False, ignore_list=()):
"""
reversible allows two way conversion of a camelized dict
such that snake_dict_to_camel_dict(camel_dict_to_snake_dict(x)) == x
This is achieved through mapping e.g. HTTPEndpoint to h_t_t_p_endpoint
where the default would be simply http_endpoint, which gets turned into
HttpEndpoint if recamelized.
ignore_list is used to avoid converting a sub-tree of a dict. This is
particularly important for tags, where keys are case-sensitive. We convert
the 'Tags' key but nothing below.
"""
def value_is_list(camel_list):
checked_list = []
for item in camel_list:
if isinstance(item, dict):
checked_list.append(camel_dict_to_snake_dict(item, reversible))
elif isinstance(item, list):
checked_list.append(value_is_list(item))
else:
checked_list.append(item)
return checked_list
snake_dict = {}
for k, v in camel_dict.items():
if isinstance(v, dict) and k not in ignore_list:
snake_dict[_camel_to_snake(k, reversible=reversible)] = camel_dict_to_snake_dict(v, reversible)
elif isinstance(v, list) and k not in ignore_list:
snake_dict[_camel_to_snake(k, reversible=reversible)] = value_is_list(v)
else:
snake_dict[_camel_to_snake(k, reversible=reversible)] = v
return snake_dict
def snake_dict_to_camel_dict(snake_dict, capitalize_first=False):
"""
Perhaps unexpectedly, snake_dict_to_camel_dict returns dromedaryCase
rather than true CamelCase. Passing capitalize_first=True returns
CamelCase. The default remains False as that was the original implementation
"""
def camelize(complex_type, capitalize_first=False):
if complex_type is None:
return
new_type = type(complex_type)()
if isinstance(complex_type, dict):
for key in complex_type:
new_type[_snake_to_camel(key, capitalize_first)] = camelize(complex_type[key], capitalize_first)
elif isinstance(complex_type, list):
for i in range(len(complex_type)):
new_type.append(camelize(complex_type[i], capitalize_first))
else:
return complex_type
return new_type
return camelize(snake_dict, capitalize_first)
def _snake_to_camel(snake, capitalize_first=False):
if capitalize_first:
return ''.join(x.capitalize() or '_' for x in snake.split('_'))
else:
return snake.split('_')[0] + ''.join(x.capitalize() or '_' for x in snake.split('_')[1:])
def _camel_to_snake(name, reversible=False):
def prepend_underscore_and_lower(m):
return '_' + m.group(0).lower()
import re
if reversible:
upper_pattern = r'[A-Z]'
else:
# Cope with pluralized abbreviations such as TargetGroupARNs
# that would otherwise be rendered target_group_ar_ns
upper_pattern = r'[A-Z]{3,}s$'
s1 = re.sub(upper_pattern, prepend_underscore_and_lower, name)
# Handle when there was nothing before the plural_pattern
if s1.startswith("_") and not name.startswith("_"):
s1 = s1[1:]
if reversible:
return s1
# Remainder of solution seems to be https://stackoverflow.com/a/1176023
first_cap_pattern = r'(.)([A-Z][a-z]+)'
all_cap_pattern = r'([a-z0-9])([A-Z]+)'
s2 = re.sub(first_cap_pattern, r'\1_\2', s1)
return re.sub(all_cap_pattern, r'\1_\2', s2).lower()
def dict_merge(a, b):
'''recursively merges dicts. not just simple a['key'] = b['key'], if
both a and b have a key whose value is a dict then dict_merge is called
on both values and the result stored in the returned dictionary.'''
if not isinstance(b, dict):
return b
result = deepcopy(a)
for k, v in b.items():
if k in result and isinstance(result[k], dict):
result[k] = dict_merge(result[k], v)
else:
result[k] = deepcopy(v)
return result
def recursive_diff(dict1, dict2):
left = dict((k, v) for (k, v) in dict1.items() if k not in dict2)
right = dict((k, v) for (k, v) in dict2.items() if k not in dict1)
for k in (set(dict1.keys()) & set(dict2.keys())):
if isinstance(dict1[k], dict) and isinstance(dict2[k], dict):
result = recursive_diff(dict1[k], dict2[k])
if result:
left[k] = result[0]
right[k] = result[1]
elif dict1[k] != dict2[k]:
left[k] = dict1[k]
right[k] = dict2[k]
if left or right:
return left, right
else:
return None
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
1898,
26,
334,
67,
9,
14894,
12,
2622,
7290,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
363,
6577,
363,
275,
730,
421,
199,
646,
295,
199,
504,
1331,
492,
14800,
421,
199,
318,
31129,
63,
807,
63,
475,
63,
21415,
63,
807,
8,
22997,
63,
807,
12,
29465,
1164,
29,
797,
12,
3686,
63,
513,
23603,
272,
408,
272,
29465,
1164,
6127,
2877,
4340,
8603,
402,
282,
20382,
317,
7068,
1211,
272,
4066,
626,
6895,
1728,
63,
807,
63,
475,
63,
22997,
63,
807,
8,
22997,
63,
807,
63,
475,
63,
21415,
63,
807,
8,
88,
430,
508,
671,
339,
961,
365,
22175,
1354,
4012,
4412,
325,
14,
71,
14,
869,
1481,
1510,
977,
1403,
370,
394,
63,
84,
63,
84,
63,
80,
63,
6520,
272,
2382,
314,
849,
3955,
506,
9329,
1455,
63,
6520,
12,
1314,
7545,
19136,
1901,
272,
4760,
11442,
340,
6488,
313,
317,
7068,
14,
339,
3686,
63,
513,
365,
1202,
370,
5126,
13806,
282,
1007,
13,
2350,
402,
282,
1211,
14,
961,
365,
272,
6770,
590,
11012,
367,
3762,
12,
2382,
2883,
787,
1930,
13,
7361,
14,
2136,
3957,
272,
314,
283,
9440,
7,
790,
1325,
6548,
5084,
14,
272,
408,
339,
347,
574,
63,
374,
63,
513,
8,
22997,
63,
513,
304,
398,
7923,
63,
513,
275,
942,
267,
367,
1242,
315,
31129,
63,
513,
26,
288,
340,
1228,
8,
1053,
12,
1211,
304,
355,
7923,
63,
513,
14,
740,
8,
22997,
63,
807,
63,
475,
63,
21415,
63,
807,
8,
1053,
12,
29465,
1164,
430,
288,
916,
1228,
8,
1053,
12,
769,
304,
355,
7923,
63,
513,
14,
740,
8,
585,
63,
374,
63,
513,
8,
1053,
430,
288,
587,
26,
355,
7923,
63,
513,
14,
740,
8,
1053,
9,
398,
372,
7923,
63,
513,
339,
6895,
1728,
63,
807,
275,
1052,
272,
367,
1022,
12,
373,
315,
31129,
63,
807,
14,
1744,
837,
267,
340,
1228,
8,
86,
12,
1211,
9,
436,
1022,
440,
315,
3686,
63,
513,
26,
288,
6895,
1728,
63,
807,
13040,
22997,
63,
475,
63,
21415,
8,
75,
12,
29465,
1164,
29,
264,
422,
1164,
1874,
275,
31129,
63,
807,
63,
475,
63,
21415,
63,
807,
8,
86,
12,
29465,
1164,
9,
267,
916,
1228,
8,
86,
12,
769,
9,
436,
1022,
440,
315,
3686,
63,
513,
26,
288,
6895,
1728,
63,
807,
13040,
22997,
63,
475,
63,
21415,
8,
75,
12,
29465,
1164,
29,
264,
422,
1164,
1874,
275,
574,
63,
374,
63,
513,
8,
86,
9,
267,
587,
26,
288,
6895,
1728,
63,
807,
13040,
22997,
63,
475,
63,
21415,
8,
75,
12,
29465,
1164,
29,
264,
422,
1164,
1874,
275,
373,
339,
372,
6895,
1728,
63,
807,
421,
199,
318,
6895,
1728,
63,
807,
63,
475,
63,
22997,
63,
807,
8,
21415,
63,
807,
12,
17094,
794,
63,
2246,
29,
797,
304,
272,
408,
272,
3492,
17396,
10537,
590,
12,
6895,
1728,
63,
807,
63,
475,
63,
22997,
63,
807,
2529,
366,
293,
3594,
695,
1538,
272,
7830,
2419,
2549,
445,
14868,
1538,
14,
31755,
17094,
794,
63,
2246,
29,
549,
2529,
272,
445,
14868,
1538,
14,
710,
849,
25803,
756,
465,
626,
1990,
314,
3379,
4514,
272,
408,
339,
347,
20382,
13559,
8,
5254,
63,
466,
12,
17094,
794,
63,
2246,
29,
797,
304,
267,
340,
6114,
63,
466,
365,
488,
26,
288,
372,
267,
892,
63,
466,
275,
730,
8,
5254,
63,
466,
16315,
267,
340,
1228,
8,
5254,
63,
466,
12,
1211,
304,
288,
367,
790,
315,
6114,
63,
466,
26,
355,
892,
63,
466,
13040,
21415,
63,
475,
63,
22997,
8,
498,
12,
17094,
794,
63,
2246,
1874,
275,
20382,
13559,
8,
5254,
63,
466,
59,
498,
467,
17094,
794,
63,
2246,
9,
267,
916,
1228,
8,
5254,
63,
466,
12,
769,
304,
288,
367,
284,
315,
1425,
8,
552,
8,
5254,
63,
466,
2298,
355,
892,
63,
466,
14,
740,
8,
27467,
13559,
8,
5254,
63,
466,
59,
73,
467,
17094,
794,
63,
2246,
430,
267,
587,
26,
288,
372,
6114,
63,
466,
267,
372,
892,
63,
466,
339,
372,
20382,
13559,
8,
21415,
63,
807,
12,
17094,
794,
63,
2246,
9,
421,
199,
318,
485,
21415,
63,
475,
63,
22997,
8,
21415,
12,
17094,
794,
63,
2246,
29,
797,
304,
272,
340,
17094,
794,
63,
2246,
26,
267,
372,
6522,
904,
8,
88,
14,
18351,
342,
503,
14135,
367,
671,
315,
6895,
1728,
14,
1294,
6412,
1333,
272,
587,
26,
267,
372,
6895,
1728,
14,
1294,
6412,
5832,
16,
61,
435,
6522,
904,
8,
88,
14,
18351,
342,
503,
14135,
367,
671,
315,
6895,
1728,
14,
1294,
6412,
5832,
17,
5728,
421,
199,
318,
485,
22997,
63,
475,
63,
21415,
8,
354,
12,
29465,
1164,
29,
797,
304,
339,
347,
18213,
63,
21831,
63,
460,
63,
2325,
8,
77,
304,
267,
372,
14135,
435,
333,
14,
923,
8,
16,
680,
2325,
342,
339,
492,
295,
272,
340,
29465,
1164,
26,
267,
7008,
63,
3401,
275,
519,
3894,
33,
13,
58,
6616,
272,
587,
26,
267,
327,
1849,
321,
543,
11718,
1759,
2236,
23988,
1298,
4066,
465,
10256,
2448,
689,
2438,
267,
327,
626,
3955,
4257,
506,
8018,
1347,
63,
923,
63,
285,
63,
561,
267,
7008,
63,
3401,
275,
519,
3894,
33,
13,
58,
8194,
19,
28209,
83,
12913,
339,
308,
17,
275,
295,
14,
954,
8,
4142,
63,
3401,
12,
18213,
63,
21831,
63,
460,
63,
2325,
12,
536,
9,
272,
327,
8690,
1380,
2337,
1990,
6548,
2544,
314,
11718,
63,
3401,
272,
340,
308,
17,
14,
2460,
11008,
531,
436,
440,
536,
14,
2460,
11008,
2349,
267,
308,
17,
275,
308,
17,
59,
17,
2938,
272,
340,
29465,
1164,
26,
267,
372,
308,
17,
339,
327,
799,
973,
424,
402,
8744,
12237,
370,
506,
4178,
921,
23153,
14,
957,
15,
65,
15,
31989,
16771,
272,
1642,
63,
2874,
63,
3401,
275,
519,
6774,
4959,
779,
33,
13
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
1898,
26,
334,
67,
9,
14894,
12,
2622,
7290,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
363,
6577,
363,
275,
730,
421,
199,
646,
295,
199,
504,
1331,
492,
14800,
421,
199,
318,
31129,
63,
807,
63,
475,
63,
21415,
63,
807,
8,
22997,
63,
807,
12,
29465,
1164,
29,
797,
12,
3686,
63,
513,
23603,
272,
408,
272,
29465,
1164,
6127,
2877,
4340,
8603,
402,
282,
20382,
317,
7068,
1211,
272,
4066,
626,
6895,
1728,
63,
807,
63,
475,
63,
22997,
63,
807,
8,
22997,
63,
807,
63,
475,
63,
21415,
63,
807,
8,
88,
430,
508,
671,
339,
961,
365,
22175,
1354,
4012,
4412,
325,
14,
71,
14,
869,
1481,
1510,
977,
1403,
370,
394,
63,
84,
63,
84,
63,
80,
63,
6520,
272,
2382,
314,
849,
3955,
506,
9329,
1455,
63,
6520,
12,
1314,
7545,
19136,
1901,
272,
4760,
11442,
340,
6488,
313,
317,
7068,
14,
339,
3686,
63,
513,
365,
1202,
370,
5126,
13806,
282,
1007,
13,
2350,
402,
282,
1211,
14,
961,
365,
272,
6770,
590,
11012,
367,
3762,
12,
2382,
2883,
787,
1930,
13,
7361,
14,
2136,
3957,
272,
314,
283,
9440,
7,
790,
1325,
6548,
5084,
14,
272,
408,
339,
347,
574,
63,
374,
63,
513,
8,
22997,
63,
513,
304,
398,
7923,
63,
513,
275,
942,
267,
367,
1242,
315,
31129,
63,
513,
26,
288,
340,
1228,
8,
1053,
12,
1211,
304,
355,
7923,
63,
513,
14,
740,
8,
22997,
63,
807,
63,
475,
63,
21415,
63,
807,
8,
1053,
12,
29465,
1164,
430,
288,
916,
1228,
8,
1053,
12,
769,
304,
355,
7923,
63,
513,
14,
740,
8,
585,
63,
374,
63,
513,
8,
1053,
430,
288,
587,
26,
355,
7923,
63,
513,
14,
740,
8,
1053,
9,
398,
372,
7923,
63,
513,
339,
6895,
1728,
63,
807,
275,
1052,
272,
367,
1022,
12,
373,
315,
31129,
63,
807,
14,
1744,
837,
267,
340,
1228,
8,
86,
12,
1211,
9,
436,
1022,
440,
315,
3686,
63,
513,
26,
288,
6895,
1728,
63,
807,
13040,
22997,
63,
475,
63,
21415,
8,
75,
12,
29465,
1164,
29,
264,
422,
1164,
1874,
275,
31129,
63,
807,
63,
475,
63,
21415,
63,
807,
8,
86,
12,
29465,
1164,
9,
267,
916,
1228,
8,
86,
12,
769,
9,
436,
1022,
440,
315,
3686,
63,
513,
26,
288,
6895,
1728,
63,
807,
13040,
22997,
63,
475,
63,
21415,
8,
75,
12,
29465,
1164,
29,
264,
422,
1164,
1874,
275,
574,
63,
374,
63,
513,
8,
86,
9,
267,
587,
26,
288,
6895,
1728,
63,
807,
13040,
22997,
63,
475,
63,
21415,
8,
75,
12,
29465,
1164,
29,
264,
422,
1164,
1874,
275,
373,
339,
372,
6895,
1728,
63,
807,
421,
199,
318,
6895,
1728,
63,
807,
63,
475,
63,
22997,
63,
807,
8,
21415,
63,
807,
12,
17094,
794,
63,
2246,
29,
797,
304,
272,
408,
272,
3492,
17396,
10537,
590,
12,
6895,
1728,
63,
807,
63,
475,
63,
22997,
63,
807,
2529,
366,
293,
3594,
695,
1538,
272,
7830,
2419,
2549,
445,
14868,
1538,
14,
31755,
17094,
794,
63,
2246,
29,
549,
2529,
272,
445,
14868,
1538,
14,
710,
849,
25803,
756,
465,
626,
1990,
314,
3379,
4514,
272,
408,
339,
347,
20382,
13559,
8,
5254,
63,
466,
12,
17094,
794,
63,
2246,
29,
797,
304,
267,
340,
6114,
63,
466,
365,
488,
26,
288,
372,
267,
892,
63,
466,
275,
730,
8,
5254,
63,
466,
16315,
267,
340,
1228,
8,
5254,
63,
466,
12,
1211,
304,
288,
367,
790,
315,
6114,
63,
466,
26,
355,
892,
63,
466,
13040,
21415,
63,
475,
63,
22997,
8,
498,
12,
17094,
794,
63,
2246,
1874,
275,
20382,
13559,
8,
5254,
63,
466,
59,
498,
467,
17094,
794,
63,
2246,
9,
267,
916,
1228,
8,
5254,
63,
466,
12,
769,
304,
288,
367,
284,
315,
1425,
8,
552,
8,
5254,
63,
466,
2298,
355,
892,
63,
466,
14,
740,
8,
27467,
13559,
8,
5254,
63,
466,
59,
73,
467,
17094,
794,
63,
2246,
430,
267,
587,
26,
288,
372,
6114,
63,
466,
267,
372,
892,
63,
466,
339,
372,
20382,
13559,
8,
21415,
63,
807,
12,
17094,
794,
63,
2246,
9,
421,
199,
318,
485,
21415,
63,
475,
63,
22997,
8,
21415,
12,
17094,
794,
63,
2246,
29,
797,
304,
272,
340,
17094,
794,
63,
2246,
26,
267,
372,
6522,
904,
8,
88,
14,
18351,
342,
503,
14135,
367,
671,
315,
6895,
1728,
14,
1294,
6412,
1333,
272,
587,
26,
267,
372,
6895,
1728,
14,
1294,
6412,
5832,
16,
61,
435,
6522,
904,
8,
88,
14,
18351,
342,
503,
14135,
367,
671,
315,
6895,
1728,
14,
1294,
6412,
5832,
17,
5728,
421,
199,
318,
485,
22997,
63,
475,
63,
21415,
8,
354,
12,
29465,
1164,
29,
797,
304,
339,
347,
18213,
63,
21831,
63,
460,
63,
2325,
8,
77,
304,
267,
372,
14135,
435,
333,
14,
923,
8,
16,
680,
2325,
342,
339,
492,
295,
272,
340,
29465,
1164,
26,
267,
7008,
63,
3401,
275,
519,
3894,
33,
13,
58,
6616,
272,
587,
26,
267,
327,
1849,
321,
543,
11718,
1759,
2236,
23988,
1298,
4066,
465,
10256,
2448,
689,
2438,
267,
327,
626,
3955,
4257,
506,
8018,
1347,
63,
923,
63,
285,
63,
561,
267,
7008,
63,
3401,
275,
519,
3894,
33,
13,
58,
8194,
19,
28209,
83,
12913,
339,
308,
17,
275,
295,
14,
954,
8,
4142,
63,
3401,
12,
18213,
63,
21831,
63,
460,
63,
2325,
12,
536,
9,
272,
327,
8690,
1380,
2337,
1990,
6548,
2544,
314,
11718,
63,
3401,
272,
340,
308,
17,
14,
2460,
11008,
531,
436,
440,
536,
14,
2460,
11008,
2349,
267,
308,
17,
275,
308,
17,
59,
17,
2938,
272,
340,
29465,
1164,
26,
267,
372,
308,
17,
339,
327,
799,
973,
424,
402,
8744,
12237,
370,
506,
4178,
921,
23153,
14,
957,
15,
65,
15,
31989,
16771,
272,
1642,
63,
2874,
63,
3401,
275,
519,
6774,
4959,
779,
33,
13,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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
# Copyright (c) 2009 Advanced Micro Devices, 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 the copyright holders nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# Authors: Ron Dreslinski
# Brad Beckmann
import m5
from m5.objects import *
from m5.defines import buildEnv
from m5.util import addToPath
import os, optparse, sys
# Get paths we might need. It's expected this file is in m5/configs/example.
config_path = os.path.dirname(os.path.abspath(__file__))
config_root = os.path.dirname(config_path)
m5_root = os.path.dirname(config_root)
addToPath(config_root+'/configs/common')
addToPath(config_root+'/configs/ruby')
addToPath(config_root+'/configs/topologies')
import Ruby
import Options
parser = optparse.OptionParser()
Options.addCommonOptions(parser)
# Add the ruby specific and protocol specific options
Ruby.define_options(parser)
(options, args) = parser.parse_args()
#
# Set the default cache size and associativity to be very small to encourage
# races between requests and writebacks.
#
options.l1d_size="256B"
options.l1i_size="256B"
options.l2_size="512B"
options.l3_size="1kB"
options.l1d_assoc=2
options.l1i_assoc=2
options.l2_assoc=2
options.l3_assoc=2
# Turn on flush check for the hammer protocol
check_flush = False
if buildEnv['PROTOCOL'] == 'MOESI_hammer':
check_flush = True
#
# create the tester and system, including ruby
#
tester = RubyTester(check_flush = check_flush, checks_to_complete = 100,
wakeup_frequency = 10, num_cpus = options.num_cpus)
system = System(tester = tester, physmem = SimpleMemory())
Ruby.create_system(options, system)
assert(options.num_cpus == len(system.ruby._cpu_ruby_ports))
#
# The tester is most effective when randomization is turned on and
# artifical delay is randomly inserted on messages
#
system.ruby.randomization = True
for ruby_port in system.ruby._cpu_ruby_ports:
#
# Tie the ruby tester ports to the ruby cpu read and write ports
#
if ruby_port.support_data_reqs:
tester.cpuDataPort = ruby_port.slave
if ruby_port.support_inst_reqs:
tester.cpuInstPort = ruby_port.slave
#
# Tell the sequencer this is the ruby tester so that it
# copies the subblock back to the checker
#
ruby_port.using_ruby_tester = True
#
# Ruby doesn't need the backing image of memory when running with
# the tester.
#
ruby_port.access_phys_mem = False
# -----------------------
# run simulation
# -----------------------
root = Root(full_system = False, system = system )
root.system.mem_mode = 'timing'
# Not much point in this being higher than the L1 latency
m5.ticks.setGlobalFrequency('1ns')
|
bsd-3-clause
|
[
3,
1898,
334,
67,
9,
8315,
13,
9488,
710,
5044,
24871,
402,
710,
15904,
402,
603,
1158,
528,
290,
199,
3,
1898,
334,
67,
9,
8937,
32445,
27022,
12272,
83,
12,
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,
26771,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
27,
199,
3,
26771,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
199,
3,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
27,
199,
3,
15564,
314,
536,
402,
314,
4248,
31976,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
3,
199,
3,
6642,
26,
32472,
577,
470,
472,
10728,
199,
3,
3515,
699,
9525,
6423,
346,
20059,
199,
199,
646,
333,
21,
199,
504,
333,
21,
14,
1462,
492,
627,
199,
504,
333,
21,
14,
14334,
492,
1900,
7744,
199,
504,
333,
21,
14,
1974,
492,
1050,
1378,
2042,
199,
646,
747,
12,
8691,
12,
984,
199,
199,
3,
2372,
3792,
781,
5594,
1929,
14,
221,
2779,
1159,
1420,
642,
570,
365,
315,
333,
21,
15,
7532,
15,
2694,
14,
199,
888,
63,
515,
275,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
3460,
493,
8964,
199,
888,
63,
1231,
275,
747,
14,
515,
14,
3475,
8,
888,
63,
515,
9,
199,
77,
21,
63,
1231,
275,
747,
14,
515,
14,
3475,
8,
888,
63,
1231,
9,
199,
525,
1378,
2042,
8,
888,
63,
1231,
23164,
7532,
15,
2330,
358,
199,
525,
1378,
2042,
8,
888,
63,
1231,
23164,
7532,
15,
21952,
358,
199,
525,
1378,
2042,
8,
888,
63,
1231,
23164,
7532,
15,
16851,
15241,
358,
199,
199,
646,
820,
10972,
199,
646,
8394,
199,
199,
2087,
275,
8691,
14,
14553,
342,
199,
4558,
14,
525,
7844,
4558,
8,
2087,
9,
199,
199,
3,
2654,
314,
31855,
2488,
436,
4113,
2488,
1511,
199,
50,
10972,
14,
4640,
63,
1419,
8,
2087,
9,
199,
199,
8,
1419,
12,
1249,
9,
275,
1798,
14,
1122,
63,
589,
342,
199,
199,
3,
199,
3,
2494,
314,
849,
2581,
1568,
436,
4035,
2159,
18936,
370,
506,
7437,
7425,
370,
655,
25715,
474,
199,
3,
660,
823,
3382,
4145,
436,
2218,
894,
83,
14,
199,
3,
199,
1419,
14,
76,
17,
68,
63,
890,
628,
3912,
34,
2,
199,
1419,
14,
76,
17,
73,
63,
890,
628,
3912,
34,
2,
199,
1419,
14,
76,
18,
63,
890,
628,
7736,
34,
2,
199,
1419,
14,
76,
19,
63,
890,
628,
17,
75,
34,
2,
199,
1419,
14,
76,
17,
68,
63,
16824,
29,
18,
199,
1419,
14,
76,
17,
73,
63,
16824,
29,
18,
199,
1419,
14,
76,
18,
63,
16824,
29,
18,
199,
1419,
14,
76,
19,
63,
16824,
29,
18,
199,
199,
3,
16147,
641,
8976,
1104,
367,
314,
24868,
2626,
4113,
199,
1074,
63,
4939,
275,
756,
199,
692,
1900,
7744,
459,
9583,
418,
508,
283,
2679,
654,
41,
63,
10670,
2626,
356,
272,
1104,
63,
4939,
275,
715,
199,
199,
3,
199,
3,
1218,
314,
17570,
436,
2656,
12,
5893,
31855,
199,
3,
199,
8234,
275,
820,
10972,
22403,
8,
1074,
63,
4939,
275,
1104,
63,
4939,
12,
5920,
63,
475,
63,
4883,
275,
2948,
12,
490,
21560,
384,
63,
11132,
275,
1616,
12,
1967,
63,
8896,
275,
1511,
14,
1507,
63,
8896,
9,
199,
199,
2253,
275,
6187,
8,
8234,
275,
17570,
12,
3945,
588,
5286,
275,
5870,
8628,
1012,
199,
199,
50,
10972,
14,
981,
63,
2253,
8,
1419,
12,
2656,
9,
199,
199,
479,
8,
1419,
14,
1507,
63,
8896,
508,
822,
8,
2253,
14,
21952,
423,
3541,
63,
21952,
63,
5203,
430,
199,
199,
3,
199,
3,
710,
17570,
365,
4750,
15826,
1380,
2196,
2072,
365,
19136,
641,
436,
199,
3,
601,
1428,
915,
7339,
365,
19311,
11788,
641,
3788,
199,
3,
199,
2253,
14,
21952,
14,
2355,
2072,
275,
715,
199,
199,
509,
31855,
63,
719,
315,
2656,
14,
21952,
423,
3541,
63,
21952,
63,
5203,
26,
272,
327,
272,
327,
377,
1873,
314,
31855,
17570,
8873,
370,
314,
31855,
5033,
1586,
436,
2218,
8873,
272,
327,
272,
340,
31855,
63,
719,
14,
4058,
63,
576,
63,
12720,
26,
268,
17570,
14,
3541,
1451,
4313,
275,
31855,
63,
719,
14,
12384,
272,
340,
31855,
63,
719,
14,
4058,
63,
3615,
63,
12720,
26,
268,
17570,
14,
3541,
10083,
4313,
275,
31855,
63,
719,
14,
12384,
339,
327,
272,
327,
30528,
314,
542,
1514,
2247,
642,
365,
314,
31855,
17570,
880,
626,
652,
272,
327,
6866,
314,
1007,
1457,
1771,
370,
314,
7739,
272,
327,
272,
31855,
63,
719,
14,
4941,
63,
21952,
63,
8234,
275,
715,
339,
327,
272,
327,
820,
10972,
3181,
1133,
1929,
314,
21094,
1834,
402,
4402,
1380,
3879,
543,
272,
327,
314,
17570,
14,
272,
327,
272
] |
[
1898,
334,
67,
9,
8315,
13,
9488,
710,
5044,
24871,
402,
710,
15904,
402,
603,
1158,
528,
290,
199,
3,
1898,
334,
67,
9,
8937,
32445,
27022,
12272,
83,
12,
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,
26771,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
27,
199,
3,
26771,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
199,
3,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
27,
199,
3,
15564,
314,
536,
402,
314,
4248,
31976,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
3,
199,
3,
6642,
26,
32472,
577,
470,
472,
10728,
199,
3,
3515,
699,
9525,
6423,
346,
20059,
199,
199,
646,
333,
21,
199,
504,
333,
21,
14,
1462,
492,
627,
199,
504,
333,
21,
14,
14334,
492,
1900,
7744,
199,
504,
333,
21,
14,
1974,
492,
1050,
1378,
2042,
199,
646,
747,
12,
8691,
12,
984,
199,
199,
3,
2372,
3792,
781,
5594,
1929,
14,
221,
2779,
1159,
1420,
642,
570,
365,
315,
333,
21,
15,
7532,
15,
2694,
14,
199,
888,
63,
515,
275,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
3460,
493,
8964,
199,
888,
63,
1231,
275,
747,
14,
515,
14,
3475,
8,
888,
63,
515,
9,
199,
77,
21,
63,
1231,
275,
747,
14,
515,
14,
3475,
8,
888,
63,
1231,
9,
199,
525,
1378,
2042,
8,
888,
63,
1231,
23164,
7532,
15,
2330,
358,
199,
525,
1378,
2042,
8,
888,
63,
1231,
23164,
7532,
15,
21952,
358,
199,
525,
1378,
2042,
8,
888,
63,
1231,
23164,
7532,
15,
16851,
15241,
358,
199,
199,
646,
820,
10972,
199,
646,
8394,
199,
199,
2087,
275,
8691,
14,
14553,
342,
199,
4558,
14,
525,
7844,
4558,
8,
2087,
9,
199,
199,
3,
2654,
314,
31855,
2488,
436,
4113,
2488,
1511,
199,
50,
10972,
14,
4640,
63,
1419,
8,
2087,
9,
199,
199,
8,
1419,
12,
1249,
9,
275,
1798,
14,
1122,
63,
589,
342,
199,
199,
3,
199,
3,
2494,
314,
849,
2581,
1568,
436,
4035,
2159,
18936,
370,
506,
7437,
7425,
370,
655,
25715,
474,
199,
3,
660,
823,
3382,
4145,
436,
2218,
894,
83,
14,
199,
3,
199,
1419,
14,
76,
17,
68,
63,
890,
628,
3912,
34,
2,
199,
1419,
14,
76,
17,
73,
63,
890,
628,
3912,
34,
2,
199,
1419,
14,
76,
18,
63,
890,
628,
7736,
34,
2,
199,
1419,
14,
76,
19,
63,
890,
628,
17,
75,
34,
2,
199,
1419,
14,
76,
17,
68,
63,
16824,
29,
18,
199,
1419,
14,
76,
17,
73,
63,
16824,
29,
18,
199,
1419,
14,
76,
18,
63,
16824,
29,
18,
199,
1419,
14,
76,
19,
63,
16824,
29,
18,
199,
199,
3,
16147,
641,
8976,
1104,
367,
314,
24868,
2626,
4113,
199,
1074,
63,
4939,
275,
756,
199,
692,
1900,
7744,
459,
9583,
418,
508,
283,
2679,
654,
41,
63,
10670,
2626,
356,
272,
1104,
63,
4939,
275,
715,
199,
199,
3,
199,
3,
1218,
314,
17570,
436,
2656,
12,
5893,
31855,
199,
3,
199,
8234,
275,
820,
10972,
22403,
8,
1074,
63,
4939,
275,
1104,
63,
4939,
12,
5920,
63,
475,
63,
4883,
275,
2948,
12,
490,
21560,
384,
63,
11132,
275,
1616,
12,
1967,
63,
8896,
275,
1511,
14,
1507,
63,
8896,
9,
199,
199,
2253,
275,
6187,
8,
8234,
275,
17570,
12,
3945,
588,
5286,
275,
5870,
8628,
1012,
199,
199,
50,
10972,
14,
981,
63,
2253,
8,
1419,
12,
2656,
9,
199,
199,
479,
8,
1419,
14,
1507,
63,
8896,
508,
822,
8,
2253,
14,
21952,
423,
3541,
63,
21952,
63,
5203,
430,
199,
199,
3,
199,
3,
710,
17570,
365,
4750,
15826,
1380,
2196,
2072,
365,
19136,
641,
436,
199,
3,
601,
1428,
915,
7339,
365,
19311,
11788,
641,
3788,
199,
3,
199,
2253,
14,
21952,
14,
2355,
2072,
275,
715,
199,
199,
509,
31855,
63,
719,
315,
2656,
14,
21952,
423,
3541,
63,
21952,
63,
5203,
26,
272,
327,
272,
327,
377,
1873,
314,
31855,
17570,
8873,
370,
314,
31855,
5033,
1586,
436,
2218,
8873,
272,
327,
272,
340,
31855,
63,
719,
14,
4058,
63,
576,
63,
12720,
26,
268,
17570,
14,
3541,
1451,
4313,
275,
31855,
63,
719,
14,
12384,
272,
340,
31855,
63,
719,
14,
4058,
63,
3615,
63,
12720,
26,
268,
17570,
14,
3541,
10083,
4313,
275,
31855,
63,
719,
14,
12384,
339,
327,
272,
327,
30528,
314,
542,
1514,
2247,
642,
365,
314,
31855,
17570,
880,
626,
652,
272,
327,
6866,
314,
1007,
1457,
1771,
370,
314,
7739,
272,
327,
272,
31855,
63,
719,
14,
4941,
63,
21952,
63,
8234,
275,
715,
339,
327,
272,
327,
820,
10972,
3181,
1133,
1929,
314,
21094,
1834,
402,
4402,
1380,
3879,
543,
272,
327,
314,
17570,
14,
272,
327,
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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
JasonDean-1/Script-Python-WebServer
|
www/transwarp/db.py
|
16
|
13973
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = 'Michael Liao'
'''
Database operation module.
'''
import time, uuid, functools, threading, logging
# Dict object:
class Dict(dict):
'''
Simple dict but support access as x.y style.
>>> d1 = Dict()
>>> d1['x'] = 100
>>> d1.x
100
>>> d1.y = 200
>>> d1['y']
200
>>> d2 = Dict(a=1, b=2, c='3')
>>> d2.c
'3'
>>> d2['empty']
Traceback (most recent call last):
...
KeyError: 'empty'
>>> d2.empty
Traceback (most recent call last):
...
AttributeError: 'Dict' object has no attribute 'empty'
>>> d3 = Dict(('a', 'b', 'c'), (1, 2, 3))
>>> d3.a
1
>>> d3.b
2
>>> d3.c
3
'''
def __init__(self, names=(), values=(), **kw):
super(Dict, self).__init__(**kw)
for k, v in zip(names, values):
self[k] = v
def __getattr__(self, key):
try:
return self[key]
except KeyError:
raise AttributeError(r"'Dict' object has no attribute '%s'" % key)
def __setattr__(self, key, value):
self[key] = value
def next_id(t=None):
'''
Return next id as 50-char string.
Args:
t: unix timestamp, default to None and using time.time().
'''
if t is None:
t = time.time()
return '%015d%s000' % (int(t * 1000), uuid.uuid4().hex)
def _profiling(start, sql=''):
t = time.time() - start
if t > 0.1:
logging.warning('[PROFILING] [DB] %s: %s' % (t, sql))
else:
logging.info('[PROFILING] [DB] %s: %s' % (t, sql))
class DBError(Exception):
pass
class MultiColumnsError(DBError):
pass
class _LasyConnection(object):
def __init__(self):
self.connection = None
def cursor(self):
if self.connection is None:
connection = engine.connect()
logging.info('open connection <%s>...' % hex(id(connection)))
self.connection = connection
return self.connection.cursor()
def commit(self):
self.connection.commit()
def rollback(self):
self.connection.rollback()
def cleanup(self):
if self.connection:
connection = self.connection
self.connection = None
logging.info('close connection <%s>...' % hex(id(connection)))
connection.close()
class _DbCtx(threading.local):
'''
Thread local object that holds connection info.
'''
def __init__(self):
self.connection = None
self.transactions = 0
def is_init(self):
return not self.connection is None
def init(self):
logging.info('open lazy connection...')
self.connection = _LasyConnection()
self.transactions = 0
def cleanup(self):
self.connection.cleanup()
self.connection = None
def cursor(self):
'''
Return cursor
'''
return self.connection.cursor()
# thread-local db context:
_db_ctx = _DbCtx()
# global engine object:
engine = None
class _Engine(object):
def __init__(self, connect):
self._connect = connect
def connect(self):
return self._connect()
def create_engine(user, password, database, host='127.0.0.1', port=3306, **kw):
import mysql.connector
global engine
if engine is not None:
raise DBError('Engine is already initialized.')
params = dict(user=user, password=password, database=database, host=host, port=port)
defaults = dict(use_unicode=True, charset='utf8', collation='utf8_general_ci', autocommit=False)
for k, v in defaults.iteritems():
params[k] = kw.pop(k, v)
params.update(kw)
params['buffered'] = True
engine = _Engine(lambda: mysql.connector.connect(**params))
# test connection...
logging.info('Init mysql engine <%s> ok.' % hex(id(engine)))
class _ConnectionCtx(object):
'''
_ConnectionCtx object that can open and close connection context. _ConnectionCtx object can be nested and only the most
outer connection has effect.
with connection():
pass
with connection():
pass
'''
def __enter__(self):
global _db_ctx
self.should_cleanup = False
if not _db_ctx.is_init():
_db_ctx.init()
self.should_cleanup = True
return self
def __exit__(self, exctype, excvalue, traceback):
global _db_ctx
if self.should_cleanup:
_db_ctx.cleanup()
def connection():
'''
Return _ConnectionCtx object that can be used by 'with' statement:
with connection():
pass
'''
return _ConnectionCtx()
def with_connection(func):
'''
Decorator for reuse connection.
@with_connection
def foo(*args, **kw):
f1()
f2()
f3()
'''
@functools.wraps(func)
def _wrapper(*args, **kw):
with _ConnectionCtx():
return func(*args, **kw)
return _wrapper
class _TransactionCtx(object):
'''
_TransactionCtx object that can handle transactions.
with _TransactionCtx():
pass
'''
def __enter__(self):
global _db_ctx
self.should_close_conn = False
if not _db_ctx.is_init():
# needs open a connection first:
_db_ctx.init()
self.should_close_conn = True
_db_ctx.transactions = _db_ctx.transactions + 1
logging.info('begin transaction...' if _db_ctx.transactions==1 else 'join current transaction...')
return self
def __exit__(self, exctype, excvalue, traceback):
global _db_ctx
_db_ctx.transactions = _db_ctx.transactions - 1
try:
if _db_ctx.transactions==0:
if exctype is None:
self.commit()
else:
self.rollback()
finally:
if self.should_close_conn:
_db_ctx.cleanup()
def commit(self):
global _db_ctx
logging.info('commit transaction...')
try:
_db_ctx.connection.commit()
logging.info('commit ok.')
except:
logging.warning('commit failed. try rollback...')
_db_ctx.connection.rollback()
logging.warning('rollback ok.')
raise
def rollback(self):
global _db_ctx
logging.warning('rollback transaction...')
_db_ctx.connection.rollback()
logging.info('rollback ok.')
def transaction():
'''
Create a transaction object so can use with statement:
with transaction():
pass
>>> def update_profile(id, name, rollback):
... u = dict(id=id, name=name, email='%s@test.org' % name, passwd=name, last_modified=time.time())
... insert('user', **u)
... r = update('update user set passwd=? where id=?', name.upper(), id)
... if rollback:
... raise StandardError('will cause rollback...')
>>> with transaction():
... update_profile(900301, 'Python', False)
>>> select_one('select * from user where id=?', 900301).name
u'Python'
>>> with transaction():
... update_profile(900302, 'Ruby', True)
Traceback (most recent call last):
...
StandardError: will cause rollback...
>>> select('select * from user where id=?', 900302)
[]
'''
return _TransactionCtx()
def with_transaction(func):
'''
A decorator that makes function around transaction.
>>> @with_transaction
... def update_profile(id, name, rollback):
... u = dict(id=id, name=name, email='%s@test.org' % name, passwd=name, last_modified=time.time())
... insert('user', **u)
... r = update('update user set passwd=? where id=?', name.upper(), id)
... if rollback:
... raise StandardError('will cause rollback...')
>>> update_profile(8080, 'Julia', False)
>>> select_one('select * from user where id=?', 8080).passwd
u'JULIA'
>>> update_profile(9090, 'Robert', True)
Traceback (most recent call last):
...
StandardError: will cause rollback...
>>> select('select * from user where id=?', 9090)
[]
'''
@functools.wraps(func)
def _wrapper(*args, **kw):
_start = time.time()
with _TransactionCtx():
return func(*args, **kw)
_profiling(_start)
return _wrapper
def _select(sql, first, *args):
' execute select SQL and return unique result or list results.'
global _db_ctx
cursor = None
sql = sql.replace('?', '%s')
logging.info('SQL: %s, ARGS: %s' % (sql, args))
try:
cursor = _db_ctx.connection.cursor()
cursor.execute(sql, args)
if cursor.description:
names = [x[0] for x in cursor.description]
if first:
values = cursor.fetchone()
if not values:
return None
return Dict(names, values)
return [Dict(names, x) for x in cursor.fetchall()]
finally:
if cursor:
cursor.close()
@with_connection
def select_one(sql, *args):
'''
Execute select SQL and expected one result.
If no result found, return None.
If multiple results found, the first one returned.
>>> u1 = dict(id=100, name='Alice', email='alice@test.org', passwd='ABC-12345', last_modified=time.time())
>>> u2 = dict(id=101, name='Sarah', email='sarah@test.org', passwd='ABC-12345', last_modified=time.time())
>>> insert('user', **u1)
1
>>> insert('user', **u2)
1
>>> u = select_one('select * from user where id=?', 100)
>>> u.name
u'Alice'
>>> select_one('select * from user where email=?', 'abc@email.com')
>>> u2 = select_one('select * from user where passwd=? order by email', 'ABC-12345')
>>> u2.name
u'Alice'
'''
return _select(sql, True, *args)
@with_connection
def select_int(sql, *args):
'''
Execute select SQL and expected one int and only one int result.
>>> n = update('delete from user')
>>> u1 = dict(id=96900, name='Ada', email='ada@test.org', passwd='A-12345', last_modified=time.time())
>>> u2 = dict(id=96901, name='Adam', email='adam@test.org', passwd='A-12345', last_modified=time.time())
>>> insert('user', **u1)
1
>>> insert('user', **u2)
1
>>> select_int('select count(*) from user')
2
>>> select_int('select count(*) from user where email=?', 'ada@test.org')
1
>>> select_int('select count(*) from user where email=?', 'notexist@test.org')
0
>>> select_int('select id from user where email=?', 'ada@test.org')
96900
>>> select_int('select id, name from user where email=?', 'ada@test.org')
Traceback (most recent call last):
...
MultiColumnsError: Expect only one column.
'''
d = _select(sql, True, *args)
if len(d)!=1:
raise MultiColumnsError('Expect only one column.')
return d.values()[0]
@with_connection
def select(sql, *args):
'''
Execute select SQL and return list or empty list if no result.
>>> u1 = dict(id=200, name='Wall.E', email='wall.e@test.org', passwd='back-to-earth', last_modified=time.time())
>>> u2 = dict(id=201, name='Eva', email='eva@test.org', passwd='back-to-earth', last_modified=time.time())
>>> insert('user', **u1)
1
>>> insert('user', **u2)
1
>>> L = select('select * from user where id=?', 900900900)
>>> L
[]
>>> L = select('select * from user where id=?', 200)
>>> L[0].email
u'wall.e@test.org'
>>> L = select('select * from user where passwd=? order by id desc', 'back-to-earth')
>>> L[0].name
u'Eva'
>>> L[1].name
u'Wall.E'
'''
return _select(sql, False, *args)
@with_connection
def _update(sql, *args):
global _db_ctx
cursor = None
sql = sql.replace('?', '%s')
logging.info('SQL: %s, ARGS: %s' % (sql, args))
try:
cursor = _db_ctx.connection.cursor()
cursor.execute(sql, args)
r = cursor.rowcount
if _db_ctx.transactions==0:
# no transaction enviroment:
logging.info('auto commit')
_db_ctx.connection.commit()
return r
finally:
if cursor:
cursor.close()
def insert(table, **kw):
'''
Execute insert SQL.
>>> u1 = dict(id=2000, name='Bob', email='bob@test.org', passwd='bobobob', last_modified=time.time())
>>> insert('user', **u1)
1
>>> u2 = select_one('select * from user where id=?', 2000)
>>> u2.name
u'Bob'
>>> insert('user', **u2)
Traceback (most recent call last):
...
IntegrityError: 1062 (23000): Duplicate entry '2000' for key 'PRIMARY'
'''
cols, args = zip(*kw.iteritems())
sql = 'insert into `%s` (%s) values (%s)' % (table, ','.join(['`%s`' % col for col in cols]), ','.join(['?' for i in range(len(cols))]))
return _update(sql, *args)
def update(sql, *args):
r'''
Execute update SQL.
>>> u1 = dict(id=1000, name='Michael', email='michael@test.org', passwd='123456', last_modified=time.time())
>>> insert('user', **u1)
1
>>> u2 = select_one('select * from user where id=?', 1000)
>>> u2.email
u'michael@test.org'
>>> u2.passwd
u'123456'
>>> update('update user set email=?, passwd=? where id=?', 'michael@example.org', '654321', 1000)
1
>>> u3 = select_one('select * from user where id=?', 1000)
>>> u3.email
u'michael@example.org'
>>> u3.passwd
u'654321'
>>> update('update user set passwd=? where id=?', '***', '123\' or id=\'456')
0
'''
return _update(sql, *args)
if __name__=='__main__':
logging.basicConfig(level=logging.DEBUG)
create_engine('www-data', 'www-data', 'test')
update('drop table if exists user')
update('create table user (id int primary key, name text, email text, passwd text, last_modified real)')
import doctest
doctest.testmod()
|
gpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
363,
2502,
363,
275,
283,
45,
11781,
491,
18939,
7,
199,
199,
2344,
199,
7243,
3439,
859,
14,
199,
2344,
199,
199,
646,
900,
12,
5377,
12,
9143,
12,
5796,
12,
2050,
199,
199,
3,
7448,
909,
26,
199,
199,
533,
7448,
8,
807,
304,
272,
1449,
272,
5870,
1211,
1325,
2291,
2879,
465,
671,
14,
89,
3449,
14,
339,
1306,
366,
17,
275,
7448,
342,
272,
1306,
366,
17,
459,
88,
418,
275,
2948,
272,
1306,
366,
17,
14,
88,
272,
2948,
272,
1306,
366,
17,
14,
89,
275,
1926,
272,
1306,
366,
17,
459,
89,
418,
272,
1926,
272,
1306,
366,
18,
275,
7448,
8,
65,
29,
17,
12,
330,
29,
18,
12,
286,
534,
19,
358,
272,
1306,
366,
18,
14,
67,
272,
283,
19,
7,
272,
1306,
366,
18,
459,
1667,
418,
272,
15273,
334,
2786,
8058,
1240,
2061,
304,
267,
2263,
272,
4067,
26,
283,
1667,
7,
272,
1306,
366,
18,
14,
1667,
272,
15273,
334,
2786,
8058,
1240,
2061,
304,
267,
2263,
272,
4281,
26,
283,
2141,
7,
909,
965,
949,
2225,
283,
1667,
7,
272,
1306,
366,
19,
275,
7448,
4725,
65,
297,
283,
66,
297,
283,
67,
659,
334,
17,
12,
499,
12,
650,
430,
272,
1306,
366,
19,
14,
65,
272,
413,
272,
1306,
366,
19,
14,
66,
272,
499,
272,
1306,
366,
19,
14,
67,
272,
650,
272,
1449,
272,
347,
636,
826,
721,
277,
12,
1561,
16729,
1338,
16729,
1011,
829,
304,
267,
1613,
8,
2141,
12,
291,
2843,
826,
14155,
829,
9,
267,
367,
1022,
12,
373,
315,
3482,
8,
1247,
12,
1338,
304,
288,
291,
59,
75,
61,
275,
373,
339,
347,
636,
5675,
721,
277,
12,
790,
304,
267,
862,
26,
288,
372,
291,
59,
498,
61,
267,
871,
4067,
26,
288,
746,
4281,
8,
82,
4507,
2141,
7,
909,
965,
949,
2225,
1543,
83,
4065,
450,
790,
9,
339,
347,
636,
10202,
721,
277,
12,
790,
12,
574,
304,
267,
291,
59,
498,
61,
275,
574,
199,
199,
318,
2163,
63,
344,
8,
84,
29,
403,
304,
272,
1449,
272,
1432,
2163,
1305,
465,
5238,
13,
1560,
1059,
14,
339,
3033,
26,
267,
307,
26,
16572,
4913,
12,
849,
370,
488,
436,
1808,
900,
14,
521,
1252,
272,
1449,
272,
340,
307,
365,
488,
26,
267,
307,
275,
900,
14,
521,
342,
272,
372,
1543,
11164,
68,
5,
83,
1493,
7,
450,
334,
442,
8,
84,
627,
5198,
395,
5377,
14,
2580,
20,
1252,
4097,
9,
199,
199,
318,
485,
496,
19294,
8,
928,
12,
3875,
9280,
272,
307,
275,
900,
14,
521,
342,
446,
1343,
272,
340,
307,
690,
378,
14,
17,
26,
267,
2050,
14,
3764,
11894,
2514,
5110,
1206,
61,
359,
2846,
61,
450,
83,
26,
450,
83,
7,
450,
334,
84,
12,
3875,
430,
272,
587,
26,
267,
2050,
14,
815,
11894,
2514,
5110,
1206,
61,
359,
2846,
61,
450,
83,
26,
450,
83,
7,
450,
334,
84,
12,
3875,
430,
199,
199,
533,
6249,
547,
8,
1726,
304,
272,
986,
199,
199,
533,
6879,
15086,
547,
8,
2846,
547,
304,
272,
986,
199,
199,
533,
485,
44,
5660,
3225,
8,
785,
304,
339,
347,
636,
826,
721,
277,
304,
267,
291,
14,
2105,
275,
488,
339,
347,
3920,
8,
277,
304,
267,
340,
291,
14,
2105,
365,
488,
26,
288,
1950,
275,
6869,
14,
2242,
342,
288,
2050,
14,
815,
360,
1490,
1950,
21808,
83,
30,
13698,
450,
6318,
8,
344,
8,
2105,
1724,
288,
291,
14,
2105,
275,
1950,
267,
372,
291,
14,
2105,
14,
3937,
342,
339,
347,
5532,
8,
277,
304,
267,
291,
14,
2105,
14,
3543,
342,
339,
347,
16475,
8,
277,
304,
267,
291,
14,
2105,
14,
10437,
342,
339,
347,
9058,
8,
277,
304,
267,
340,
291,
14,
2105,
26,
288,
1950,
275,
291,
14,
2105,
288,
291,
14,
2105,
275,
488,
288,
2050,
14,
815,
360,
1600,
1950,
21808,
83,
30,
13698,
450,
6318,
8,
344,
8,
2105,
1724,
288,
1950,
14,
1600,
342,
199,
199,
533,
485,
8882,
35,
2347,
8,
12562,
14,
1832,
304,
272,
1449,
272,
11086,
2257,
909,
626,
15164,
1950,
2256,
14,
272,
1449,
272,
347,
636,
826,
721,
277,
304,
267,
291,
14,
2105,
275,
488,
267,
291,
14,
13754,
275,
378,
339,
347,
365,
63,
826,
8,
277,
304,
267,
372,
440,
291,
14,
2105,
365,
488,
339,
347,
4205,
8,
277,
304,
267,
2050,
14,
815,
360,
1490,
9617,
1950,
15103,
267,
291,
14,
2105,
275,
485,
44,
5660,
3225,
342,
267,
291,
14,
13754,
275,
378,
339,
347,
9058,
8,
277,
304,
267,
291,
14,
2105,
14,
7661,
342,
267,
291,
14,
2105,
275,
488,
339,
347,
3920,
8,
277,
304,
267,
1449,
267,
1432,
3920,
267,
1449,
267,
372,
291,
14,
2105,
14,
3937,
342,
199,
199,
3,
2462,
13,
1832,
1592,
1067,
26,
199,
63,
697,
63,
3799,
275,
485,
8882,
35,
2347,
342,
199,
199,
3,
2288,
6869,
909,
26,
199,
3908,
275,
488,
199,
199,
533,
485,
8524,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
4907,
304,
267,
291,
423,
2242,
275,
4907,
339,
347,
4907,
8,
277,
304,
267,
372,
291,
423,
2242,
342,
199,
199,
318,
1218,
63,
3908,
8,
751,
12,
2505,
12,
3050,
12,
1591,
534,
4195,
14,
16,
14,
16,
14,
17,
297,
1844,
29,
1153,
1690,
12,
1011,
829,
304,
272,
492,
12896,
14,
11815,
272,
2288,
6869,
272,
340,
6869,
365,
440,
488,
26,
267,
746,
6249,
547,
360,
8524,
365,
2575,
10038,
2659,
272,
1862,
275,
1211,
8,
751,
29,
751,
12,
2505,
29,
2060,
12,
3050,
29,
4659,
12,
1591,
29,
1102,
12,
1844,
29,
719,
9,
272,
4243,
275,
1211,
8,
1180,
63,
2975,
29,
549,
12,
5960,
534,
1624,
24,
297,
1048,
2212,
534,
1624,
24,
63,
10706,
63,
559,
297,
24845,
29,
797,
9,
272,
367,
1022,
12,
373,
315,
4243,
14,
4611,
837,
267,
1862,
59,
75,
61,
275,
4775,
14,
1935,
8,
75,
12,
373,
9,
272,
1862,
14,
873,
8,
829,
9,
272,
1862,
459,
17605,
418,
275
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
363,
2502,
363,
275,
283,
45,
11781,
491,
18939,
7,
199,
199,
2344,
199,
7243,
3439,
859,
14,
199,
2344,
199,
199,
646,
900,
12,
5377,
12,
9143,
12,
5796,
12,
2050,
199,
199,
3,
7448,
909,
26,
199,
199,
533,
7448,
8,
807,
304,
272,
1449,
272,
5870,
1211,
1325,
2291,
2879,
465,
671,
14,
89,
3449,
14,
339,
1306,
366,
17,
275,
7448,
342,
272,
1306,
366,
17,
459,
88,
418,
275,
2948,
272,
1306,
366,
17,
14,
88,
272,
2948,
272,
1306,
366,
17,
14,
89,
275,
1926,
272,
1306,
366,
17,
459,
89,
418,
272,
1926,
272,
1306,
366,
18,
275,
7448,
8,
65,
29,
17,
12,
330,
29,
18,
12,
286,
534,
19,
358,
272,
1306,
366,
18,
14,
67,
272,
283,
19,
7,
272,
1306,
366,
18,
459,
1667,
418,
272,
15273,
334,
2786,
8058,
1240,
2061,
304,
267,
2263,
272,
4067,
26,
283,
1667,
7,
272,
1306,
366,
18,
14,
1667,
272,
15273,
334,
2786,
8058,
1240,
2061,
304,
267,
2263,
272,
4281,
26,
283,
2141,
7,
909,
965,
949,
2225,
283,
1667,
7,
272,
1306,
366,
19,
275,
7448,
4725,
65,
297,
283,
66,
297,
283,
67,
659,
334,
17,
12,
499,
12,
650,
430,
272,
1306,
366,
19,
14,
65,
272,
413,
272,
1306,
366,
19,
14,
66,
272,
499,
272,
1306,
366,
19,
14,
67,
272,
650,
272,
1449,
272,
347,
636,
826,
721,
277,
12,
1561,
16729,
1338,
16729,
1011,
829,
304,
267,
1613,
8,
2141,
12,
291,
2843,
826,
14155,
829,
9,
267,
367,
1022,
12,
373,
315,
3482,
8,
1247,
12,
1338,
304,
288,
291,
59,
75,
61,
275,
373,
339,
347,
636,
5675,
721,
277,
12,
790,
304,
267,
862,
26,
288,
372,
291,
59,
498,
61,
267,
871,
4067,
26,
288,
746,
4281,
8,
82,
4507,
2141,
7,
909,
965,
949,
2225,
1543,
83,
4065,
450,
790,
9,
339,
347,
636,
10202,
721,
277,
12,
790,
12,
574,
304,
267,
291,
59,
498,
61,
275,
574,
199,
199,
318,
2163,
63,
344,
8,
84,
29,
403,
304,
272,
1449,
272,
1432,
2163,
1305,
465,
5238,
13,
1560,
1059,
14,
339,
3033,
26,
267,
307,
26,
16572,
4913,
12,
849,
370,
488,
436,
1808,
900,
14,
521,
1252,
272,
1449,
272,
340,
307,
365,
488,
26,
267,
307,
275,
900,
14,
521,
342,
272,
372,
1543,
11164,
68,
5,
83,
1493,
7,
450,
334,
442,
8,
84,
627,
5198,
395,
5377,
14,
2580,
20,
1252,
4097,
9,
199,
199,
318,
485,
496,
19294,
8,
928,
12,
3875,
9280,
272,
307,
275,
900,
14,
521,
342,
446,
1343,
272,
340,
307,
690,
378,
14,
17,
26,
267,
2050,
14,
3764,
11894,
2514,
5110,
1206,
61,
359,
2846,
61,
450,
83,
26,
450,
83,
7,
450,
334,
84,
12,
3875,
430,
272,
587,
26,
267,
2050,
14,
815,
11894,
2514,
5110,
1206,
61,
359,
2846,
61,
450,
83,
26,
450,
83,
7,
450,
334,
84,
12,
3875,
430,
199,
199,
533,
6249,
547,
8,
1726,
304,
272,
986,
199,
199,
533,
6879,
15086,
547,
8,
2846,
547,
304,
272,
986,
199,
199,
533,
485,
44,
5660,
3225,
8,
785,
304,
339,
347,
636,
826,
721,
277,
304,
267,
291,
14,
2105,
275,
488,
339,
347,
3920,
8,
277,
304,
267,
340,
291,
14,
2105,
365,
488,
26,
288,
1950,
275,
6869,
14,
2242,
342,
288,
2050,
14,
815,
360,
1490,
1950,
21808,
83,
30,
13698,
450,
6318,
8,
344,
8,
2105,
1724,
288,
291,
14,
2105,
275,
1950,
267,
372,
291,
14,
2105,
14,
3937,
342,
339,
347,
5532,
8,
277,
304,
267,
291,
14,
2105,
14,
3543,
342,
339,
347,
16475,
8,
277,
304,
267,
291,
14,
2105,
14,
10437,
342,
339,
347,
9058,
8,
277,
304,
267,
340,
291,
14,
2105,
26,
288,
1950,
275,
291,
14,
2105,
288,
291,
14,
2105,
275,
488,
288,
2050,
14,
815,
360,
1600,
1950,
21808,
83,
30,
13698,
450,
6318,
8,
344,
8,
2105,
1724,
288,
1950,
14,
1600,
342,
199,
199,
533,
485,
8882,
35,
2347,
8,
12562,
14,
1832,
304,
272,
1449,
272,
11086,
2257,
909,
626,
15164,
1950,
2256,
14,
272,
1449,
272,
347,
636,
826,
721,
277,
304,
267,
291,
14,
2105,
275,
488,
267,
291,
14,
13754,
275,
378,
339,
347,
365,
63,
826,
8,
277,
304,
267,
372,
440,
291,
14,
2105,
365,
488,
339,
347,
4205,
8,
277,
304,
267,
2050,
14,
815,
360,
1490,
9617,
1950,
15103,
267,
291,
14,
2105,
275,
485,
44,
5660,
3225,
342,
267,
291,
14,
13754,
275,
378,
339,
347,
9058,
8,
277,
304,
267,
291,
14,
2105,
14,
7661,
342,
267,
291,
14,
2105,
275,
488,
339,
347,
3920,
8,
277,
304,
267,
1449,
267,
1432,
3920,
267,
1449,
267,
372,
291,
14,
2105,
14,
3937,
342,
199,
199,
3,
2462,
13,
1832,
1592,
1067,
26,
199,
63,
697,
63,
3799,
275,
485,
8882,
35,
2347,
342,
199,
199,
3,
2288,
6869,
909,
26,
199,
3908,
275,
488,
199,
199,
533,
485,
8524,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
4907,
304,
267,
291,
423,
2242,
275,
4907,
339,
347,
4907,
8,
277,
304,
267,
372,
291,
423,
2242,
342,
199,
199,
318,
1218,
63,
3908,
8,
751,
12,
2505,
12,
3050,
12,
1591,
534,
4195,
14,
16,
14,
16,
14,
17,
297,
1844,
29,
1153,
1690,
12,
1011,
829,
304,
272,
492,
12896,
14,
11815,
272,
2288,
6869,
272,
340,
6869,
365,
440,
488,
26,
267,
746,
6249,
547,
360,
8524,
365,
2575,
10038,
2659,
272,
1862,
275,
1211,
8,
751,
29,
751,
12,
2505,
29,
2060,
12,
3050,
29,
4659,
12,
1591,
29,
1102,
12,
1844,
29,
719,
9,
272,
4243,
275,
1211,
8,
1180,
63,
2975,
29,
549,
12,
5960,
534,
1624,
24,
297,
1048,
2212,
534,
1624,
24,
63,
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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
CopeX/odoo
|
addons/point_of_sale/account_bank_statement.py
|
313
|
2159
|
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2008 PC Solutions (<http://pcsol.be>). All Rights Reserved
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp.osv import fields, osv
class account_journal(osv.osv):
_inherit = 'account.journal'
_columns = {
'journal_user': fields.boolean('PoS Payment Method', help="Check this box if this journal define a payment method that can be used in point of sales."),
'amount_authorized_diff' : fields.float('Amount Authorized Difference', help="This field depicts the maximum difference allowed between the ending balance and the theorical cash when closing a session, for non-POS managers. If this maximum is reached, the user will have an error message at the closing of his session saying that he needs to contact his manager."),
'self_checkout_payment_method' : fields.boolean('Self Checkout Payment Method'), #FIXME : this field is obsolete
}
_defaults = {
'self_checkout_payment_method' : False,
}
class account_cash_statement(osv.osv):
_inherit = 'account.bank.statement'
_columns = {
'pos_session_id' : fields.many2one('pos.session', copy=False),
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
9300,
510,
35,
17991,
8653,
8642,
1014,
921,
80,
1259,
393,
14,
1235,
10121,
2900,
5924,
5702,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
504,
5166,
14,
4795,
492,
1504,
12,
9506,
199,
199,
533,
2933,
63,
7067,
8,
4795,
14,
4795,
304,
272,
485,
6486,
275,
283,
2048,
14,
7067,
7,
272,
485,
3406,
275,
469,
267,
283,
7067,
63,
751,
356,
1504,
14,
4871,
360,
1575,
51,
25523,
9075,
297,
1720,
628,
1799,
642,
5689,
340,
642,
9605,
5627,
282,
11628,
1083,
626,
883,
506,
1202,
315,
2376,
402,
21702,
7651,
398,
283,
4606,
63,
11497,
63,
3028,
7,
520,
1504,
14,
1609,
360,
18785,
6529,
1759,
18029,
4646,
297,
1720,
628,
2765,
901,
477,
1038,
3021,
314,
5696,
8865,
4370,
3382,
314,
13401,
14094,
436,
314,
314,
10611,
286,
1119,
1380,
11261,
282,
2351,
12,
367,
2222,
13,
9263,
19680,
14,
982,
642,
5696,
365,
13075,
12,
314,
922,
911,
1172,
376,
1125,
1245,
737,
314,
11261,
402,
17049,
2351,
14722,
316,
626,
946,
4839,
370,
8966,
17049,
5256,
7651,
267,
283,
277,
63,
12891,
63,
7948,
63,
765,
7,
520,
1504,
14,
4871,
360,
12887,
2670,
548,
25523,
9075,
659,
327,
31779,
520,
642,
901,
365,
24985,
272,
789,
272,
485,
4322,
275,
469,
267,
283,
277,
63,
12891,
63,
7948,
63,
765,
7,
520,
756,
12,
272,
789,
421,
199,
533,
2933,
63,
20084,
63,
6242,
8,
4795,
14,
4795,
304,
272,
485,
6486,
275,
283,
2048,
14,
9860,
14,
6242,
7,
272,
485,
3406,
275,
469,
267,
283,
1712,
63,
1730,
63,
344,
7,
520,
1504,
14,
3479,
18,
368,
360,
1712,
14,
1730,
297,
1331,
29,
797,
395,
272,
789,
421,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
9300,
510,
35,
17991,
8653,
8642,
1014,
921,
80,
1259,
393,
14,
1235,
10121,
2900,
5924,
5702,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
504,
5166,
14,
4795,
492,
1504,
12,
9506,
199,
199,
533,
2933,
63,
7067,
8,
4795,
14,
4795,
304,
272,
485,
6486,
275,
283,
2048,
14,
7067,
7,
272,
485,
3406,
275,
469,
267,
283,
7067,
63,
751,
356,
1504,
14,
4871,
360,
1575,
51,
25523,
9075,
297,
1720,
628,
1799,
642,
5689,
340,
642,
9605,
5627,
282,
11628,
1083,
626,
883,
506,
1202,
315,
2376,
402,
21702,
7651,
398,
283,
4606,
63,
11497,
63,
3028,
7,
520,
1504,
14,
1609,
360,
18785,
6529,
1759,
18029,
4646,
297,
1720,
628,
2765,
901,
477,
1038,
3021,
314,
5696,
8865,
4370,
3382,
314,
13401,
14094,
436,
314,
314,
10611,
286,
1119,
1380,
11261,
282,
2351,
12,
367,
2222,
13,
9263,
19680,
14,
982,
642,
5696,
365,
13075,
12,
314,
922,
911,
1172,
376,
1125,
1245,
737,
314,
11261,
402,
17049,
2351,
14722,
316,
626,
946,
4839,
370,
8966,
17049,
5256,
7651,
267,
283,
277,
63,
12891,
63,
7948,
63,
765,
7,
520,
1504,
14,
4871,
360,
12887,
2670,
548,
25523,
9075,
659,
327,
31779,
520,
642,
901,
365,
24985,
272,
789,
272,
485,
4322,
275,
469,
267,
283,
277,
63,
12891,
63,
7948,
63,
765,
7,
520,
756,
12,
272,
789,
421,
199,
533,
2933,
63,
20084,
63,
6242,
8,
4795,
14,
4795,
304,
272,
485,
6486,
275,
283,
2048,
14,
9860,
14,
6242,
7,
272,
485,
3406,
275,
469,
267,
283,
1712,
63,
1730,
63,
344,
7,
520,
1504,
14,
3479,
18,
368,
360,
1712,
14,
1730,
297,
1331,
29,
797,
395,
272,
789,
421,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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
] |
avneesh91/django
|
tests/admin_docs/models.py
|
244
|
1941
|
"""
Models for testing various aspects of the djang.contrib.admindocs app
"""
from django.db import models
class Company(models.Model):
name = models.CharField(max_length=200)
class Group(models.Model):
name = models.CharField(max_length=200)
class Family(models.Model):
last_name = models.CharField(max_length=200)
class Person(models.Model):
"""
Stores information about a person, related to :model:`myapp.Company`.
**Notes**
Use ``save_changes()`` when saving this object.
``company``
Field storing :model:`myapp.Company` where the person works.
(DESCRIPTION)
.. raw:: html
:file: admin_docs/evilfile.txt
.. include:: admin_docs/evilfile.txt
"""
first_name = models.CharField(max_length=200, help_text="The person's first name")
last_name = models.CharField(max_length=200, help_text="The person's last name")
company = models.ForeignKey(Company, models.CASCADE, help_text="place of work")
family = models.ForeignKey(Family, models.SET_NULL, related_name='+', null=True)
groups = models.ManyToManyField(Group, help_text="has membership")
def _get_full_name(self):
return "%s %s" % (self.first_name, self.last_name)
def rename_company(self, new_name):
self.company.name = new_name
self.company.save()
return new_name
def dummy_function(self, baz, rox, *some_args, **some_kwargs):
return some_kwargs
def suffix_company_name(self, suffix='ltd'):
return self.company.name + suffix
def add_image(self):
pass
def delete_image(self):
pass
def save_changes(self):
pass
def set_status(self):
pass
def get_full_name(self):
"""
Get the full name of the person
"""
return self._get_full_name()
def get_status_count(self):
return 0
def get_groups_list(self):
return []
|
bsd-3-clause
|
[
624,
199,
20474,
367,
5343,
7750,
17435,
83,
402,
314,
366,
851,
14,
2828,
14,
14464,
688,
14851,
1145,
199,
624,
199,
199,
504,
1639,
14,
697,
492,
1709,
421,
199,
533,
15878,
8,
992,
14,
1685,
304,
272,
536,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1840,
9,
421,
199,
533,
5611,
8,
992,
14,
1685,
304,
272,
536,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1840,
9,
421,
199,
533,
481,
4632,
8,
992,
14,
1685,
304,
272,
2061,
63,
354,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1840,
9,
421,
199,
533,
8028,
8,
992,
14,
1685,
304,
272,
408,
272,
31299,
2556,
3595,
282,
4954,
12,
4048,
370,
520,
1238,
1705,
1662,
571,
14,
16063,
2313,
339,
1011,
18685,
538,
339,
3645,
1124,
2117,
63,
6627,
8497,
1380,
13369,
642,
909,
14,
339,
1124,
4627,
1040,
267,
5024,
16915,
520,
1238,
1705,
1662,
571,
14,
16063,
64,
2382,
314,
4954,
5419,
14,
339,
334,
17705,
9,
339,
2508,
3066,
447,
3517,
267,
520,
493,
26,
4628,
63,
4757,
15,
69,
433,
12059,
14,
2424,
339,
2508,
2387,
447,
4628,
63,
4757,
15,
69,
433,
12059,
14,
2424,
272,
408,
272,
1642,
63,
354,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1840,
12,
1720,
63,
505,
628,
1918,
4954,
1159,
1642,
536,
531,
272,
2061,
63,
354,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1840,
12,
1720,
63,
505,
628,
1918,
4954,
1159,
2061,
536,
531,
272,
7233,
275,
1709,
14,
3190,
8,
16063,
12,
1709,
14,
10855,
12,
1720,
63,
505,
628,
2778,
402,
1736,
531,
272,
9614,
275,
1709,
14,
3190,
8,
16345,
12,
1709,
14,
3597,
63,
8084,
12,
4048,
63,
354,
534,
7386,
2973,
29,
549,
9,
272,
4652,
275,
1709,
14,
7624,
8,
2448,
12,
1720,
63,
505,
628,
1989,
14616,
531,
339,
347,
485,
362,
63,
2861,
63,
354,
8,
277,
304,
267,
372,
2071,
83,
450,
83,
2,
450,
334,
277,
14,
2246,
63,
354,
12,
291,
14,
2019,
63,
354,
9,
339,
347,
11441,
63,
4627,
8,
277,
12,
892,
63,
354,
304,
267,
291,
14,
4627,
14,
354,
275,
892,
63,
354,
267,
291,
14,
4627,
14,
2117,
342,
267,
372,
892,
63,
354,
339,
347,
7283,
63,
1593,
8,
277,
12,
15507,
12,
882,
88,
12,
627,
3972,
63,
589,
12,
1011,
3972,
63,
958,
304,
267,
372,
2005,
63,
958,
339,
347,
4739,
63,
4627,
63,
354,
8,
277,
12,
4739,
534,
76,
2076,
735,
267,
372,
291,
14,
4627,
14,
354,
435,
4739,
339,
347,
1050,
63,
1569,
8,
277,
304,
267,
986,
339,
347,
3145,
63,
1569,
8,
277,
304,
267,
986,
339,
347,
3354,
63,
6627,
8,
277,
304,
267,
986,
339,
347,
663,
63,
1205,
8,
277,
304,
267,
986,
339,
347,
664,
63,
2861,
63,
354,
8,
277,
304,
267,
408,
267,
2372,
314,
2615,
536,
402,
314,
4954,
267,
408,
267,
372,
291,
423,
362,
63,
2861,
63,
354,
342,
339,
347,
664,
63,
1205,
63,
835,
8,
277,
304,
267,
372,
378,
339,
347,
664,
63,
2634,
63,
513,
8,
277,
304,
267,
372,
942,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
20474,
367,
5343,
7750,
17435,
83,
402,
314,
366,
851,
14,
2828,
14,
14464,
688,
14851,
1145,
199,
624,
199,
199,
504,
1639,
14,
697,
492,
1709,
421,
199,
533,
15878,
8,
992,
14,
1685,
304,
272,
536,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1840,
9,
421,
199,
533,
5611,
8,
992,
14,
1685,
304,
272,
536,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1840,
9,
421,
199,
533,
481,
4632,
8,
992,
14,
1685,
304,
272,
2061,
63,
354,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1840,
9,
421,
199,
533,
8028,
8,
992,
14,
1685,
304,
272,
408,
272,
31299,
2556,
3595,
282,
4954,
12,
4048,
370,
520,
1238,
1705,
1662,
571,
14,
16063,
2313,
339,
1011,
18685,
538,
339,
3645,
1124,
2117,
63,
6627,
8497,
1380,
13369,
642,
909,
14,
339,
1124,
4627,
1040,
267,
5024,
16915,
520,
1238,
1705,
1662,
571,
14,
16063,
64,
2382,
314,
4954,
5419,
14,
339,
334,
17705,
9,
339,
2508,
3066,
447,
3517,
267,
520,
493,
26,
4628,
63,
4757,
15,
69,
433,
12059,
14,
2424,
339,
2508,
2387,
447,
4628,
63,
4757,
15,
69,
433,
12059,
14,
2424,
272,
408,
272,
1642,
63,
354,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1840,
12,
1720,
63,
505,
628,
1918,
4954,
1159,
1642,
536,
531,
272,
2061,
63,
354,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1840,
12,
1720,
63,
505,
628,
1918,
4954,
1159,
2061,
536,
531,
272,
7233,
275,
1709,
14,
3190,
8,
16063,
12,
1709,
14,
10855,
12,
1720,
63,
505,
628,
2778,
402,
1736,
531,
272,
9614,
275,
1709,
14,
3190,
8,
16345,
12,
1709,
14,
3597,
63,
8084,
12,
4048,
63,
354,
534,
7386,
2973,
29,
549,
9,
272,
4652,
275,
1709,
14,
7624,
8,
2448,
12,
1720,
63,
505,
628,
1989,
14616,
531,
339,
347,
485,
362,
63,
2861,
63,
354,
8,
277,
304,
267,
372,
2071,
83,
450,
83,
2,
450,
334,
277,
14,
2246,
63,
354,
12,
291,
14,
2019,
63,
354,
9,
339,
347,
11441,
63,
4627,
8,
277,
12,
892,
63,
354,
304,
267,
291,
14,
4627,
14,
354,
275,
892,
63,
354,
267,
291,
14,
4627,
14,
2117,
342,
267,
372,
892,
63,
354,
339,
347,
7283,
63,
1593,
8,
277,
12,
15507,
12,
882,
88,
12,
627,
3972,
63,
589,
12,
1011,
3972,
63,
958,
304,
267,
372,
2005,
63,
958,
339,
347,
4739,
63,
4627,
63,
354,
8,
277,
12,
4739,
534,
76,
2076,
735,
267,
372,
291,
14,
4627,
14,
354,
435,
4739,
339,
347,
1050,
63,
1569,
8,
277,
304,
267,
986,
339,
347,
3145,
63,
1569,
8,
277,
304,
267,
986,
339,
347,
3354,
63,
6627,
8,
277,
304,
267,
986,
339,
347,
663,
63,
1205,
8,
277,
304,
267,
986,
339,
347,
664,
63,
2861,
63,
354,
8,
277,
304,
267,
408,
267,
2372,
314,
2615,
536,
402,
314,
4954,
267,
408,
267,
372,
291,
423,
362,
63,
2861,
63,
354,
342,
339,
347,
664,
63,
1205,
63,
835,
8,
277,
304,
267,
372,
378,
339,
347,
664,
63,
2634,
63,
513,
8,
277,
304,
267,
372,
942,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
JioCloud/nova
|
nova/tests/unit/virt/libvirt/test_dmcrypt.py
|
47
|
2461
|
# Copyright (c) 2014 The Johns Hopkins University/Applied Physics Laboratory
# 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 os
from nova import test
from nova import utils
from nova.virt.libvirt import dmcrypt
class LibvirtDmcryptTestCase(test.NoDBTestCase):
def setUp(self):
super(LibvirtDmcryptTestCase, self).setUp()
self.CIPHER = 'cipher'
self.KEY_SIZE = 256
self.NAME = 'disk'
self.TARGET = dmcrypt.volume_name(self.NAME)
self.PATH = '/dev/nova-lvm/instance_disk'
self.KEY = range(0, self.KEY_SIZE)
self.KEY_STR = ''.join(["%02x" % x for x in range(0, self.KEY_SIZE)])
self.executes = []
self.kwargs = {}
def fake_execute(*cmd, **kwargs):
self.executes.append(cmd)
self.kwargs = kwargs
return None, None
def fake_listdir(path):
return [self.TARGET, '/dev/mapper/disk']
self.stubs.Set(utils, 'execute', fake_execute)
self.stubs.Set(os, 'listdir', fake_listdir)
def test_create_volume(self):
expected_commands = [('cryptsetup',
'create',
self.TARGET,
self.PATH,
'--cipher=' + self.CIPHER,
'--key-size=' + str(self.KEY_SIZE),
'--key-file=-')]
dmcrypt.create_volume(self.TARGET, self.PATH, self.CIPHER,
self.KEY_SIZE, self.KEY)
self.assertEqual(expected_commands, self.executes)
self.assertEqual(self.KEY_STR, self.kwargs['process_input'])
def test_delete_volume(self):
expected_commands = [('cryptsetup', 'remove', self.TARGET)]
dmcrypt.delete_volume(self.TARGET)
self.assertEqual(expected_commands, self.executes)
def test_list_volumes(self):
encrypted_volumes = dmcrypt.list_volumes()
self.assertEqual([self.TARGET], encrypted_volumes)
|
apache-2.0
|
[
3,
1898,
334,
67,
9,
6927,
710,
7135,
25338,
869,
411,
75,
3617,
15904,
15,
2640,
1857,
24309,
17378,
16871,
31671,
199,
3,
2900,
5924,
5702,
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,
747,
199,
199,
504,
5913,
492,
511,
199,
504,
5913,
492,
3778,
199,
504,
5913,
14,
4549,
14,
11877,
492,
17547,
4997,
421,
199,
533,
8003,
4549,
36,
77,
4997,
1746,
8,
396,
14,
32437,
304,
272,
347,
3613,
8,
277,
304,
267,
1613,
8,
14407,
36,
77,
4997,
1746,
12,
291,
680,
5996,
342,
398,
291,
14,
35,
1772,
3452,
275,
283,
9231,
7,
267,
291,
14,
3078,
63,
4305,
275,
7633,
267,
291,
14,
2339,
275,
283,
4032,
7,
267,
291,
14,
9268,
275,
17547,
4997,
14,
2405,
63,
354,
8,
277,
14,
2339,
9,
267,
291,
14,
3243,
275,
1994,
2374,
15,
6765,
13,
31283,
15,
842,
63,
4032,
7,
267,
291,
14,
3078,
275,
1425,
8,
16,
12,
291,
14,
3078,
63,
4305,
9,
267,
291,
14,
3078,
63,
3027,
275,
6522,
904,
30387,
996,
88,
2,
450,
671,
367,
671,
315,
1425,
8,
16,
12,
291,
14,
3078,
63,
4305,
3948,
398,
291,
14,
1628,
3862,
275,
942,
267,
291,
14,
958,
275,
1052,
398,
347,
4026,
63,
2526,
2031,
1760,
12,
1011,
958,
304,
288,
291,
14,
1628,
3862,
14,
740,
8,
1760,
9,
288,
291,
14,
958,
275,
2074,
288,
372,
488,
12,
488,
398,
347,
4026,
63,
7374,
8,
515,
304,
288,
372,
359,
277,
14,
9268,
12,
1994,
2374,
15,
7153,
15,
4032,
418,
398,
291,
14,
8957,
14,
1084,
8,
1208,
12,
283,
2526,
297,
4026,
63,
2526,
9,
267,
291,
14,
8957,
14,
1084,
8,
736,
12,
283,
7374,
297,
4026,
63,
7374,
9,
339,
347,
511,
63,
981,
63,
2405,
8,
277,
304,
267,
1420,
63,
4405,
275,
4274,
4997,
2758,
297,
2049,
283,
981,
297,
2049,
291,
14,
9268,
12,
2049,
291,
14,
3243,
12,
2049,
2850,
9231,
534,
435,
291,
14,
35,
1772,
3452,
12,
2049,
2850,
498,
13,
890,
534,
435,
620,
8,
277,
14,
3078,
63,
4305,
395,
2049,
2850,
498,
13,
493,
4022,
5440,
267,
17547,
4997,
14,
981,
63,
2405,
8,
277,
14,
9268,
12,
291,
14,
3243,
12,
291,
14,
35,
1772,
3452,
12,
288,
291,
14,
3078,
63,
4305,
12,
291,
14,
3078,
9,
398,
291,
14,
629,
8,
2062,
63,
4405,
12,
291,
14,
1628,
3862,
9,
267,
291,
14,
629,
8,
277,
14,
3078,
63,
3027,
12,
291,
14,
958,
459,
1412,
63,
1210,
1105,
339,
347,
511,
63,
1807,
63,
2405,
8,
277,
304,
267,
1420,
63,
4405,
275,
4274,
4997,
2758,
297,
283,
2168,
297,
291,
14,
9268,
1874,
267,
17547,
4997,
14,
1807,
63,
2405,
8,
277,
14,
9268,
9,
398,
291,
14,
629,
8,
2062,
63,
4405,
12,
291,
14,
1628,
3862,
9,
339,
347,
511,
63,
513,
63,
8838,
8,
277,
304,
267,
14862,
63,
8838,
275,
17547,
4997,
14,
513,
63,
8838,
342,
398,
291,
14,
629,
779,
277,
14,
9268,
467,
14862,
63,
8838,
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
] |
[
1898,
334,
67,
9,
6927,
710,
7135,
25338,
869,
411,
75,
3617,
15904,
15,
2640,
1857,
24309,
17378,
16871,
31671,
199,
3,
2900,
5924,
5702,
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,
747,
199,
199,
504,
5913,
492,
511,
199,
504,
5913,
492,
3778,
199,
504,
5913,
14,
4549,
14,
11877,
492,
17547,
4997,
421,
199,
533,
8003,
4549,
36,
77,
4997,
1746,
8,
396,
14,
32437,
304,
272,
347,
3613,
8,
277,
304,
267,
1613,
8,
14407,
36,
77,
4997,
1746,
12,
291,
680,
5996,
342,
398,
291,
14,
35,
1772,
3452,
275,
283,
9231,
7,
267,
291,
14,
3078,
63,
4305,
275,
7633,
267,
291,
14,
2339,
275,
283,
4032,
7,
267,
291,
14,
9268,
275,
17547,
4997,
14,
2405,
63,
354,
8,
277,
14,
2339,
9,
267,
291,
14,
3243,
275,
1994,
2374,
15,
6765,
13,
31283,
15,
842,
63,
4032,
7,
267,
291,
14,
3078,
275,
1425,
8,
16,
12,
291,
14,
3078,
63,
4305,
9,
267,
291,
14,
3078,
63,
3027,
275,
6522,
904,
30387,
996,
88,
2,
450,
671,
367,
671,
315,
1425,
8,
16,
12,
291,
14,
3078,
63,
4305,
3948,
398,
291,
14,
1628,
3862,
275,
942,
267,
291,
14,
958,
275,
1052,
398,
347,
4026,
63,
2526,
2031,
1760,
12,
1011,
958,
304,
288,
291,
14,
1628,
3862,
14,
740,
8,
1760,
9,
288,
291,
14,
958,
275,
2074,
288,
372,
488,
12,
488,
398,
347,
4026,
63,
7374,
8,
515,
304,
288,
372,
359,
277,
14,
9268,
12,
1994,
2374,
15,
7153,
15,
4032,
418,
398,
291,
14,
8957,
14,
1084,
8,
1208,
12,
283,
2526,
297,
4026,
63,
2526,
9,
267,
291,
14,
8957,
14,
1084,
8,
736,
12,
283,
7374,
297,
4026,
63,
7374,
9,
339,
347,
511,
63,
981,
63,
2405,
8,
277,
304,
267,
1420,
63,
4405,
275,
4274,
4997,
2758,
297,
2049,
283,
981,
297,
2049,
291,
14,
9268,
12,
2049,
291,
14,
3243,
12,
2049,
2850,
9231,
534,
435,
291,
14,
35,
1772,
3452,
12,
2049,
2850,
498,
13,
890,
534,
435,
620,
8,
277,
14,
3078,
63,
4305,
395,
2049,
2850,
498,
13,
493,
4022,
5440,
267,
17547,
4997,
14,
981,
63,
2405,
8,
277,
14,
9268,
12,
291,
14,
3243,
12,
291,
14,
35,
1772,
3452,
12,
288,
291,
14,
3078,
63,
4305,
12,
291,
14,
3078,
9,
398,
291,
14,
629,
8,
2062,
63,
4405,
12,
291,
14,
1628,
3862,
9,
267,
291,
14,
629,
8,
277,
14,
3078,
63,
3027,
12,
291,
14,
958,
459,
1412,
63,
1210,
1105,
339,
347,
511,
63,
1807,
63,
2405,
8,
277,
304,
267,
1420,
63,
4405,
275,
4274,
4997,
2758,
297,
283,
2168,
297,
291,
14,
9268,
1874,
267,
17547,
4997,
14,
1807,
63,
2405,
8,
277,
14,
9268,
9,
398,
291,
14,
629,
8,
2062,
63,
4405,
12,
291,
14,
1628,
3862,
9,
339,
347,
511,
63,
513,
63,
8838,
8,
277,
304,
267,
14862,
63,
8838,
275,
17547,
4997,
14,
513,
63,
8838,
342,
398,
291,
14,
629,
779,
277,
14,
9268,
467,
14862,
63,
8838,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
nicklhy/mxnet
|
python/mxnet/registry.py
|
28
|
4653
|
# 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.
# coding: utf-8
# pylint: disable=no-member
"""Registry for serializable objects."""
from __future__ import absolute_import
import json
import warnings
from .base import string_types
_REGISTRY = {}
def get_register_func(base_class, nickname):
"""Get registrator function.
Parameters
----------
base_class : type
base class for classes that will be reigstered
nickname : str
nickname of base_class for logging
Returns
-------
a registrator function
"""
if base_class not in _REGISTRY:
_REGISTRY[base_class] = {}
registry = _REGISTRY[base_class]
def register(klass, name=None):
"""Register functions"""
assert issubclass(klass, base_class), \
"Can only register subclass of %s"%base_class.__name__
if name is None:
name = klass.__name__.lower()
if name in registry:
warnings.warn(
"\033[91mNew %s %s.%s registered with name %s is"
"overriding existing %s %s.%s\033[0m"%(
nickname, klass.__module__, klass.__name__, name,
nickname, registry[name].__module__, registry[name].__name__),
UserWarning, stacklevel=2)
registry[name] = klass
return klass
register.__doc__ = "Register %s to the %s factory"%(nickname, nickname)
return register
def get_alias_func(base_class, nickname):
"""Get registrator function that allow aliases.
Parameters
----------
base_class : type
base class for classes that will be reigstered
nickname : str
nickname of base_class for logging
Returns
-------
a registrator function
"""
register = get_register_func(base_class, nickname)
def alias(*aliases):
"""alias registrator"""
def reg(klass):
"""registrator function"""
for name in aliases:
register(klass, name)
return klass
return reg
return alias
def get_create_func(base_class, nickname):
"""Get creator function
Parameters
----------
base_class : type
base class for classes that will be reigstered
nickname : str
nickname of base_class for logging
Returns
-------
a creator function
"""
if base_class not in _REGISTRY:
_REGISTRY[base_class] = {}
registry = _REGISTRY[base_class]
def create(*args, **kwargs):
"""Create instance from config"""
if len(args):
name = args[0]
args = args[1:]
else:
name = kwargs.pop(nickname)
if isinstance(name, base_class):
assert len(args) == 0 and len(kwargs) == 0, \
"%s is already an instance. Additional arguments are invalid"%(nickname)
return name
if isinstance(name, dict):
return create(**name)
assert isinstance(name, string_types), "%s must be of string type"%nickname
if name.startswith('['):
assert not args and not kwargs
name, kwargs = json.loads(name)
return create(name, **kwargs)
elif name.startswith('{'):
assert not args and not kwargs
kwargs = json.loads(name)
return create(**kwargs)
name = name.lower()
assert name in registry, \
"%s is not registered. Please register with %s.register first"%(
str(name), nickname)
return registry[name](*args, **kwargs)
create.__doc__ = """Create a %s instance from config.
Parameters
----------
%s : str or %s instance
class name of desired instance. If is a instance,
it will be returned directly.
**kwargs : dict
arguments to be passed to constructor"""%(nickname, nickname, base_class.__name__)
return create
|
apache-2.0
|
[
3,
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
199,
3,
503,
1655,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
199,
3,
1854,
543,
642,
1736,
367,
4722,
2556,
199,
3,
12602,
4248,
12715,
14,
221,
710,
14857,
12378,
642,
570,
199,
3,
370,
1265,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
199,
3,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
199,
3,
543,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
257,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
199,
3,
2032,
1854,
1334,
314,
844,
365,
1854,
641,
376,
199,
3,
298,
1179,
2281,
2,
4207,
12,
2428,
2990,
1549,
4217,
1634,
1821,
199,
3,
3826,
12,
1902,
4056,
503,
2478,
14,
221,
1666,
314,
844,
367,
314,
199,
3,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
199,
3,
2803,
26,
2774,
13,
24,
199,
3,
4287,
26,
3507,
29,
889,
13,
1114,
199,
199,
624,
10899,
367,
31244,
2251,
1041,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
646,
2022,
199,
646,
3598,
199,
199,
504,
1275,
1095,
492,
1059,
63,
1313,
199,
199,
63,
25304,
57,
275,
1052,
421,
199,
318,
664,
63,
2683,
63,
1532,
8,
1095,
63,
533,
12,
24332,
304,
272,
408,
1002,
1295,
14710,
805,
14,
339,
3897,
272,
4143,
272,
1300,
63,
533,
520,
730,
267,
1300,
1021,
367,
3992,
626,
911,
506,
295,
73,
458,
3014,
272,
24332,
520,
620,
267,
24332,
402,
1300,
63,
533,
367,
2050,
339,
1803,
272,
5514,
272,
282,
1295,
14710,
805,
272,
408,
272,
340,
1300,
63,
533,
440,
315,
485,
25304,
57,
26,
267,
485,
25304,
57,
59,
1095,
63,
533,
61,
275,
1052,
272,
7086,
275,
485,
25304,
57,
59,
1095,
63,
533,
61,
339,
347,
2274,
8,
11645,
12,
536,
29,
403,
304,
267,
408,
7099,
3423,
624,
267,
702,
11602,
8,
11645,
12,
1300,
63,
533,
395,
971,
288,
298,
6049,
1454,
2274,
5516,
402,
450,
83,
6808,
1095,
63,
533,
855,
354,
363,
267,
340,
536,
365,
488,
26,
288,
536,
275,
8531,
855,
354,
4343,
2325,
342,
267,
340,
536,
315,
7086,
26,
288,
3598,
14,
4050,
8,
355,
1867,
8762,
59,
3328,
77,
4665,
450,
83,
450,
83,
4111,
83,
7264,
543,
536,
450,
83,
365,
2,
355,
298,
1883,
15526,
3411,
450,
83,
450,
83,
4111,
83,
60,
8762,
59,
16,
77,
14007,
490,
24332,
12,
8531,
855,
578,
3108,
8531,
855,
354,
3108,
536,
12,
490,
24332,
12,
7086,
59,
354,
17979,
578,
3108,
7086,
59,
354,
17979,
354,
10139,
355,
2876,
3849,
12,
13232,
29,
18,
9,
267,
7086,
59,
354,
61,
275,
8531,
267,
372,
8531,
339,
2274,
855,
1301,
363,
275,
298,
7099,
450,
83,
370,
314,
450,
83,
6434,
14007,
18544,
12,
24332,
9,
272,
372,
2274,
421,
199,
318,
664,
63,
3620,
63,
1532,
8,
1095,
63,
533,
12,
24332,
304,
272,
408,
1002,
1295,
14710,
805,
626,
2040,
5481,
14,
339,
3897,
272,
4143,
272,
1300,
63,
533,
520,
730,
267,
1300,
1021,
367,
3992,
626,
911,
506,
295,
73,
458,
3014,
272,
24332,
520,
620,
267,
24332,
402,
1300,
63,
533,
367,
2050,
339,
1803,
272,
5514,
272,
282,
1295,
14710,
805,
272,
408,
272,
2274,
275,
664,
63,
2683,
63,
1532,
8,
1095,
63,
533,
12,
24332,
9,
339,
347,
5162,
2031,
8602,
304,
267,
408,
3620,
1295,
14710,
624,
267,
347,
1295,
8,
11645,
304,
288,
408,
1135,
14710,
805,
624,
288,
367,
536,
315,
5481,
26,
355,
2274,
8,
11645,
12,
536,
9,
288,
372,
8531,
267,
372,
1295,
272,
372,
5162,
421,
199,
318,
664,
63,
981,
63,
1532,
8,
1095,
63,
533,
12,
24332,
304,
272,
408,
1002,
14875,
805,
339,
3897,
272,
4143,
272,
1300,
63,
533,
520,
730,
267,
1300,
1021,
367,
3992,
626,
911,
506,
295,
73,
458,
3014,
272,
24332,
520,
620,
267,
24332,
402,
1300,
63,
533,
367,
2050,
339,
1803,
272,
5514,
272,
282,
14875,
805,
272,
408,
272,
340,
1300,
63,
533,
440,
315,
485,
25304,
57,
26,
267,
485,
25304,
57,
59,
1095,
63,
533,
61,
275,
1052,
272,
7086,
275,
485,
25304,
57,
59,
1095,
63,
533,
61,
339,
347,
1218,
2031,
589,
12,
1011,
958,
304,
267,
408,
2499,
1256,
687,
1101,
624,
267,
340,
822,
8,
589,
304,
288,
536,
275,
1249,
59,
16,
61,
288,
1249,
275,
1249,
59,
17,
2938,
267,
587,
26,
288,
536,
275,
2074,
14,
1935,
8,
18544,
9,
398,
340,
1228,
8,
354,
12,
1300,
63,
533,
304,
288,
702,
822,
8,
589,
9,
508,
378,
436,
822,
8,
958,
9,
508,
378,
12,
971,
355,
2071,
83,
365,
2575,
376,
1256,
14,
10961,
2368,
787,
3866,
14007,
18544,
9,
288,
372,
536,
398,
340,
1228,
8,
354,
12,
1211,
304,
288,
372,
1218,
3682,
354,
9,
398,
702,
1228,
8,
354,
12,
1059,
63,
1313,
395,
2071,
83,
1471,
506,
402,
1059,
730,
6808,
18544,
398,
340,
536,
14,
2460,
360,
459,
304,
288,
702,
440,
1249,
436,
440,
2074,
288,
536,
12,
2074,
275,
2022,
14,
3640,
8,
354,
9,
288,
372,
1218,
8,
354,
12,
1011,
958,
9,
267,
916,
536,
14,
2460,
11117,
735,
288,
702,
440,
1249,
436,
440,
2074,
288,
2074,
275,
2022,
14,
3640,
8,
354,
9,
288,
372,
1218,
3682,
958,
9,
398,
536,
275,
536,
14,
2325,
342,
267,
702,
536,
315,
7086,
12,
971,
288,
2071,
83,
365,
440,
7264,
14,
7754,
2274,
543,
450,
83,
14,
2683,
1642,
14007,
355,
620,
8,
354,
395,
24332,
9,
267,
372,
7086,
59,
354,
61,
2031,
589,
12,
1011,
958,
9,
339,
1218,
855,
1301,
363,
275,
408,
2499,
282,
450,
83,
1256,
687,
1101,
14,
199,
199,
5976,
199,
9460,
199,
5,
83,
520,
620,
503,
450,
83,
1256,
272,
1021,
536,
402,
6387,
1256,
14,
982,
365,
282,
1256,
12,
272,
652,
911,
506,
2138
] |
[
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
199,
3,
503,
1655,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
199,
3,
1854,
543,
642,
1736,
367,
4722,
2556,
199,
3,
12602,
4248,
12715,
14,
221,
710,
14857,
12378,
642,
570,
199,
3,
370,
1265,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
199,
3,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
199,
3,
543,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
257,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
199,
3,
2032,
1854,
1334,
314,
844,
365,
1854,
641,
376,
199,
3,
298,
1179,
2281,
2,
4207,
12,
2428,
2990,
1549,
4217,
1634,
1821,
199,
3,
3826,
12,
1902,
4056,
503,
2478,
14,
221,
1666,
314,
844,
367,
314,
199,
3,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
199,
3,
2803,
26,
2774,
13,
24,
199,
3,
4287,
26,
3507,
29,
889,
13,
1114,
199,
199,
624,
10899,
367,
31244,
2251,
1041,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
646,
2022,
199,
646,
3598,
199,
199,
504,
1275,
1095,
492,
1059,
63,
1313,
199,
199,
63,
25304,
57,
275,
1052,
421,
199,
318,
664,
63,
2683,
63,
1532,
8,
1095,
63,
533,
12,
24332,
304,
272,
408,
1002,
1295,
14710,
805,
14,
339,
3897,
272,
4143,
272,
1300,
63,
533,
520,
730,
267,
1300,
1021,
367,
3992,
626,
911,
506,
295,
73,
458,
3014,
272,
24332,
520,
620,
267,
24332,
402,
1300,
63,
533,
367,
2050,
339,
1803,
272,
5514,
272,
282,
1295,
14710,
805,
272,
408,
272,
340,
1300,
63,
533,
440,
315,
485,
25304,
57,
26,
267,
485,
25304,
57,
59,
1095,
63,
533,
61,
275,
1052,
272,
7086,
275,
485,
25304,
57,
59,
1095,
63,
533,
61,
339,
347,
2274,
8,
11645,
12,
536,
29,
403,
304,
267,
408,
7099,
3423,
624,
267,
702,
11602,
8,
11645,
12,
1300,
63,
533,
395,
971,
288,
298,
6049,
1454,
2274,
5516,
402,
450,
83,
6808,
1095,
63,
533,
855,
354,
363,
267,
340,
536,
365,
488,
26,
288,
536,
275,
8531,
855,
354,
4343,
2325,
342,
267,
340,
536,
315,
7086,
26,
288,
3598,
14,
4050,
8,
355,
1867,
8762,
59,
3328,
77,
4665,
450,
83,
450,
83,
4111,
83,
7264,
543,
536,
450,
83,
365,
2,
355,
298,
1883,
15526,
3411,
450,
83,
450,
83,
4111,
83,
60,
8762,
59,
16,
77,
14007,
490,
24332,
12,
8531,
855,
578,
3108,
8531,
855,
354,
3108,
536,
12,
490,
24332,
12,
7086,
59,
354,
17979,
578,
3108,
7086,
59,
354,
17979,
354,
10139,
355,
2876,
3849,
12,
13232,
29,
18,
9,
267,
7086,
59,
354,
61,
275,
8531,
267,
372,
8531,
339,
2274,
855,
1301,
363,
275,
298,
7099,
450,
83,
370,
314,
450,
83,
6434,
14007,
18544,
12,
24332,
9,
272,
372,
2274,
421,
199,
318,
664,
63,
3620,
63,
1532,
8,
1095,
63,
533,
12,
24332,
304,
272,
408,
1002,
1295,
14710,
805,
626,
2040,
5481,
14,
339,
3897,
272,
4143,
272,
1300,
63,
533,
520,
730,
267,
1300,
1021,
367,
3992,
626,
911,
506,
295,
73,
458,
3014,
272,
24332,
520,
620,
267,
24332,
402,
1300,
63,
533,
367,
2050,
339,
1803,
272,
5514,
272,
282,
1295,
14710,
805,
272,
408,
272,
2274,
275,
664,
63,
2683,
63,
1532,
8,
1095,
63,
533,
12,
24332,
9,
339,
347,
5162,
2031,
8602,
304,
267,
408,
3620,
1295,
14710,
624,
267,
347,
1295,
8,
11645,
304,
288,
408,
1135,
14710,
805,
624,
288,
367,
536,
315,
5481,
26,
355,
2274,
8,
11645,
12,
536,
9,
288,
372,
8531,
267,
372,
1295,
272,
372,
5162,
421,
199,
318,
664,
63,
981,
63,
1532,
8,
1095,
63,
533,
12,
24332,
304,
272,
408,
1002,
14875,
805,
339,
3897,
272,
4143,
272,
1300,
63,
533,
520,
730,
267,
1300,
1021,
367,
3992,
626,
911,
506,
295,
73,
458,
3014,
272,
24332,
520,
620,
267,
24332,
402,
1300,
63,
533,
367,
2050,
339,
1803,
272,
5514,
272,
282,
14875,
805,
272,
408,
272,
340,
1300,
63,
533,
440,
315,
485,
25304,
57,
26,
267,
485,
25304,
57,
59,
1095,
63,
533,
61,
275,
1052,
272,
7086,
275,
485,
25304,
57,
59,
1095,
63,
533,
61,
339,
347,
1218,
2031,
589,
12,
1011,
958,
304,
267,
408,
2499,
1256,
687,
1101,
624,
267,
340,
822,
8,
589,
304,
288,
536,
275,
1249,
59,
16,
61,
288,
1249,
275,
1249,
59,
17,
2938,
267,
587,
26,
288,
536,
275,
2074,
14,
1935,
8,
18544,
9,
398,
340,
1228,
8,
354,
12,
1300,
63,
533,
304,
288,
702,
822,
8,
589,
9,
508,
378,
436,
822,
8,
958,
9,
508,
378,
12,
971,
355,
2071,
83,
365,
2575,
376,
1256,
14,
10961,
2368,
787,
3866,
14007,
18544,
9,
288,
372,
536,
398,
340,
1228,
8,
354,
12,
1211,
304,
288,
372,
1218,
3682,
354,
9,
398,
702,
1228,
8,
354,
12,
1059,
63,
1313,
395,
2071,
83,
1471,
506,
402,
1059,
730,
6808,
18544,
398,
340,
536,
14,
2460,
360,
459,
304,
288,
702,
440,
1249,
436,
440,
2074,
288,
536,
12,
2074,
275,
2022,
14,
3640,
8,
354,
9,
288,
372,
1218,
8,
354,
12,
1011,
958,
9,
267,
916,
536,
14,
2460,
11117,
735,
288,
702,
440,
1249,
436,
440,
2074,
288,
2074,
275,
2022,
14,
3640,
8,
354,
9,
288,
372,
1218,
3682,
958,
9,
398,
536,
275,
536,
14,
2325,
342,
267,
702,
536,
315,
7086,
12,
971,
288,
2071,
83,
365,
440,
7264,
14,
7754,
2274,
543,
450,
83,
14,
2683,
1642,
14007,
355,
620,
8,
354,
395,
24332,
9,
267,
372,
7086,
59,
354,
61,
2031,
589,
12,
1011,
958,
9,
339,
1218,
855,
1301,
363,
275,
408,
2499,
282,
450,
83,
1256,
687,
1101,
14,
199,
199,
5976,
199,
9460,
199,
5,
83,
520,
620,
503,
450,
83,
1256,
272,
1021,
536,
402,
6387,
1256,
14,
982,
365,
282,
1256,
12,
272,
652,
911,
506,
2138,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
lrowe/experimental.cssselect
|
src/experimental/cssselect.py
|
1
|
32885
|
# Copyright (c) 2004 Ian Bicking. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
#
# 3. Neither the name of Ian Bicking 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 IAN BICKING 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.
"""CSS Selectors based on XPath.
This module supports selecting XML/HTML tags based on CSS selectors.
See the `CSSSelector` class for details.
"""
import re
from lxml import etree
__all__ = ['SelectorSyntaxError', 'ExpressionError',
'CSSSelector']
try:
_basestring = basestring
except NameError:
_basestring = str
class SelectorSyntaxError(SyntaxError):
pass
class ExpressionError(RuntimeError):
pass
class CSSSelector(etree.XPath):
"""A CSS selector.
Usage::
>>> from lxml import etree, cssselect
>>> select = cssselect.CSSSelector("a tag > child")
>>> root = etree.XML("<a><b><c/><tag><child>TEXT</child></tag></b></a>")
>>> [ el.tag for el in select(root) ]
['child']
To use CSS namespaces, you need to pass a prefix-to-namespace
mapping as ``namespaces`` keyword argument::
>>> rdfns = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'
>>> select_ns = cssselect.CSSSelector('root > rdf|Description',
... namespaces={'rdf': rdfns})
>>> rdf = etree.XML((
... '<root xmlns:rdf="%s">'
... '<rdf:Description>blah</rdf:Description>'
... '</root>') % rdfns)
>>> [(el.tag, el.text) for el in select_ns(rdf)]
[('{http://www.w3.org/1999/02/22-rdf-syntax-ns#}Description', 'blah')]
"""
def __init__(self, css, namespaces=None):
path = css_to_xpath(css)
etree.XPath.__init__(self, path, namespaces=namespaces)
self.css = css
def __repr__(self):
return '<%s %s for %r>' % (
self.__class__.__name__,
hex(abs(id(self)))[2:],
self.css)
##############################
## Token objects:
try:
_unicode = unicode
_unichr = unichr
except NameError:
# Python 3
_unicode = str
_unichr = chr
class _UniToken(_unicode):
def __new__(cls, contents, pos):
obj = _unicode.__new__(cls, contents)
obj.pos = pos
return obj
def __repr__(self):
return '%s(%s, %r)' % (
self.__class__.__name__,
_unicode.__repr__(self),
self.pos)
class Symbol(_UniToken):
pass
class String(_UniToken):
pass
class Token(_UniToken):
pass
############################################################
## Parsing
############################################################
##############################
## Syntax objects:
class Class(object):
"""
Represents selector.class_name
"""
def __init__(self, selector, class_name):
self.selector = selector
self.class_name = class_name
def __repr__(self):
return '%s[%r.%s]' % (
self.__class__.__name__,
self.selector,
self.class_name)
def xpath(self):
sel_xpath = self.selector.xpath()
sel_xpath.add_condition(
"@class and contains(concat(' ', normalize-space(@class), ' '), %s)" % xpath_literal(' '+self.class_name+' '))
return sel_xpath
class Function(object):
"""
Represents selector:name(expr)
"""
unsupported = [
'target', 'lang', 'enabled', 'disabled',]
def __init__(self, selector, type, name, expr):
self.selector = selector
self.type = type
self.name = name
self.expr = expr
def __repr__(self):
return '%s[%r%s%s(%r)]' % (
self.__class__.__name__,
self.selector,
self.type, self.name, self.expr)
def xpath(self):
sel_path = self.selector.xpath()
if self.name in self.unsupported:
raise ExpressionError(
"The pseudo-class %r is not supported" % self.name)
method = '_xpath_' + self.name.replace('-', '_')
if not hasattr(self, method):
raise ExpressionError(
"The pseudo-class %r is unknown" % self.name)
method = getattr(self, method)
return method(sel_path, self.expr)
def _xpath_nth_child(self, xpath, expr, last=False,
add_name_test=True):
a, b = parse_series(expr)
if not a and not b and not last:
# a=0 means nothing is returned...
xpath.add_condition('false() and position() = 0')
return xpath
if add_name_test:
xpath.add_name_test()
xpath.add_star_prefix()
if a == 0:
if last:
b = 'last() - %s' % b
xpath.add_condition('position() = %s' % b)
return xpath
if last:
# FIXME: I'm not sure if this is right
a = -a
b = -b
if b > 0:
b_neg = str(-b)
else:
b_neg = '+%s' % (-b)
if a != 1:
expr = ['(position() %s) mod %s = 0' % (b_neg, a)]
else:
expr = []
if b >= 0:
expr.append('position() >= %s' % b)
elif b < 0 and last:
expr.append('position() < (last() %s)' % b)
expr = ' and '.join(expr)
if expr:
xpath.add_condition(expr)
return xpath
# FIXME: handle an+b, odd, even
# an+b means every-a, plus b, e.g., 2n+1 means odd
# 0n+b means b
# n+0 means a=1, i.e., all elements
# an means every a elements, i.e., 2n means even
# -n means -1n
# -1n+6 means elements 6 and previous
def _xpath_nth_last_child(self, xpath, expr):
return self._xpath_nth_child(xpath, expr, last=True)
def _xpath_nth_of_type(self, xpath, expr):
if xpath.element == '*':
raise NotImplementedError(
"*:nth-of-type() is not implemented")
return self._xpath_nth_child(xpath, expr, add_name_test=False)
def _xpath_nth_last_of_type(self, xpath, expr):
return self._xpath_nth_child(xpath, expr, last=True, add_name_test=False)
def _xpath_contains(self, xpath, expr):
# text content, minus tags, must contain expr
# this selector was removed from the CSS3 spec
# case sensitive for speed, matching jQuery's implementation
if isinstance(expr, Element):
expr = expr._format_element()
xpath.add_condition('contains(string(.), %s)'
% xpath_literal(expr))
return xpath
def _xpath_not(self, xpath, expr):
# everything for which not expr applies
expr = expr.xpath()
cond = expr.condition
# FIXME: should I do something about element_path?
xpath.add_condition('not(%s)' % cond)
return xpath
class Pseudo(object):
"""
Represents selector:ident
"""
unsupported = ['indeterminate', 'first-line', 'first-letter',
'selection', 'before', 'after', 'link', 'visited',
'active', 'focus', 'hover']
def __init__(self, element, type, ident):
self.element = element
assert type in (':', '::')
self.type = type
self.ident = ident
def __repr__(self):
return '%s[%r%s%s]' % (
self.__class__.__name__,
self.element,
self.type, self.ident)
def xpath(self):
el_xpath = self.element.xpath()
if self.ident in self.unsupported:
raise ExpressionError(
"The pseudo-class %r is unsupported" % self.ident)
method = '_xpath_' + self.ident.replace('-', '_')
if not hasattr(self, method):
raise ExpressionError(
"The pseudo-class %r is unknown" % self.ident)
method = getattr(self, method)
el_xpath = method(el_xpath)
return el_xpath
def _xpath_checked(self, xpath):
# FIXME: is this really all the elements?
xpath.add_condition("(@selected or @checked) and (name(.) = 'input' or name(.) = 'option')")
return xpath
def _xpath_root(self, xpath):
xpath.add_condition("not(parent::*)")
return xpath
def _xpath_first_child(self, xpath):
xpath.add_star_prefix()
xpath.add_name_test()
xpath.add_condition('position() = 1')
return xpath
def _xpath_last_child(self, xpath):
xpath.add_star_prefix()
xpath.add_name_test()
xpath.add_condition('position() = last()')
return xpath
def _xpath_first_of_type(self, xpath):
if xpath.element == '*':
raise NotImplementedError(
"*:first-of-type is not implemented")
xpath.add_star_prefix()
xpath.add_condition('position() = 1')
return xpath
def _xpath_last_of_type(self, xpath):
if xpath.element == '*':
raise NotImplementedError(
"*:last-of-type is not implemented")
xpath.add_star_prefix()
xpath.add_condition('position() = last()')
return xpath
def _xpath_only_child(self, xpath):
xpath.add_name_test()
xpath.add_star_prefix()
xpath.add_condition('last() = 1')
return xpath
def _xpath_only_of_type(self, xpath):
if xpath.element == '*':
raise NotImplementedError(
"*:only-of-type is not implemented")
xpath.add_condition('last() = 1')
return xpath
def _xpath_empty(self, xpath):
xpath.add_condition("not(*) and not(normalize-space())")
return xpath
class Attrib(object):
"""
Represents selector[namespace|attrib operator value]
"""
def __init__(self, selector, namespace, attrib, operator, value):
self.selector = selector
self.namespace = namespace
self.attrib = attrib
self.operator = operator
self.value = value
def __repr__(self):
if self.operator == 'exists':
return '%s[%r[%s]]' % (
self.__class__.__name__,
self.selector,
self._format_attrib())
else:
return '%s[%r[%s %s %r]]' % (
self.__class__.__name__,
self.selector,
self._format_attrib(),
self.operator,
self.value)
def _format_attrib(self):
if self.namespace == '*':
return self.attrib
else:
return '%s|%s' % (self.namespace, self.attrib)
def _xpath_attrib(self):
# FIXME: if attrib is *?
if self.namespace == '*':
return '@' + self.attrib
else:
return '@%s:%s' % (self.namespace, self.attrib)
def xpath(self):
path = self.selector.xpath()
attrib = self._xpath_attrib()
value = self.value
if self.operator == 'exists':
assert not value
path.add_condition(attrib)
elif self.operator == '=':
path.add_condition('%s = %s' % (attrib,
xpath_literal(value)))
elif self.operator == '!=':
# FIXME: this seems like a weird hack...
if value:
path.add_condition('not(%s) or %s != %s'
% (attrib, attrib, xpath_literal(value)))
else:
path.add_condition('%s != %s'
% (attrib, xpath_literal(value)))
#path.add_condition('%s != %s' % (attrib, xpath_literal(value)))
elif self.operator == '~=':
path.add_condition("%s and contains(concat(' ', normalize-space(%s), ' '), %s)" % (attrib, attrib, xpath_literal(' '+value+' ')))
elif self.operator == '|=':
# Weird, but true...
path.add_condition('%s and (%s = %s or starts-with(%s, %s))' % (
attrib,
attrib, xpath_literal(value),
attrib, xpath_literal(value + '-')))
elif self.operator == '^=':
path.add_condition('%s and starts-with(%s, %s)' % (
attrib, attrib, xpath_literal(value)))
elif self.operator == '$=':
# Oddly there is a starts-with in XPath 1.0, but not ends-with
path.add_condition('%s and substring(%s, string-length(%s)-%s) = %s'
% (attrib, attrib, attrib, len(value)-1, xpath_literal(value)))
elif self.operator == '*=':
# Attribute selectors are case sensitive
path.add_condition('%s and contains(%s, %s)' % (
attrib, attrib, xpath_literal(value)))
else:
assert 0, ("Unknown operator: %r" % self.operator)
return path
class Element(object):
"""
Represents namespace|element
"""
def __init__(self, namespace, element):
self.namespace = namespace
self.element = element
def __repr__(self):
return '%s[%s]' % (
self.__class__.__name__,
self._format_element())
def _format_element(self):
if self.namespace == '*':
return self.element
else:
return '%s|%s' % (self.namespace, self.element)
def xpath(self):
if self.namespace == '*':
el = self.element.lower()
else:
# FIXME: Should we lowercase here?
el = '%s:%s' % (self.namespace, self.element)
return XPathExpr(element=el)
class Hash(object):
"""
Represents selector#id
"""
def __init__(self, selector, id):
self.selector = selector
self.id = id
def __repr__(self):
return '%s[%r#%s]' % (
self.__class__.__name__,
self.selector, self.id)
def xpath(self):
path = self.selector.xpath()
path.add_condition('@id = %s' % xpath_literal(self.id))
return path
class Or(object):
def __init__(self, items):
self.items = items
def __repr__(self):
return '%s(%r)' % (
self.__class__.__name__,
self.items)
def xpath(self):
paths = [item.xpath() for item in self.items]
return XPathExprOr(paths)
class CombinedSelector(object):
_method_mapping = {
' ': 'descendant',
'>': 'child',
'+': 'direct_adjacent',
'~': 'indirect_adjacent',
}
def __init__(self, selector, combinator, subselector):
assert selector is not None
self.selector = selector
self.combinator = combinator
self.subselector = subselector
def __repr__(self):
if self.combinator == ' ':
comb = '<followed>'
else:
comb = self.combinator
return '%s[%r %s %r]' % (
self.__class__.__name__,
self.selector,
comb,
self.subselector)
def xpath(self):
if self.combinator not in self._method_mapping:
raise ExpressionError(
"Unknown combinator: %r" % self.combinator)
method = '_xpath_' + self._method_mapping[self.combinator]
method = getattr(self, method)
path = self.selector.xpath()
return method(path, self.subselector)
def _xpath_descendant(self, xpath, sub):
# when sub is a descendant in any way of xpath
xpath.join('//', sub.xpath())
return xpath
def _xpath_child(self, xpath, sub):
# when sub is an immediate child of xpath
xpath.join('/', sub.xpath())
return xpath
def _xpath_direct_adjacent(self, xpath, sub):
# when sub immediately follows xpath
xpath.join('/following-sibling::', sub.xpath())
xpath.add_name_test()
xpath.add_condition('position() = 1')
return xpath
def _xpath_indirect_adjacent(self, xpath, sub):
# when sub comes somewhere after xpath as a sibling
xpath.join('/following-sibling::', sub.xpath())
return xpath
##############################
## XPathExpr objects:
_el_re = re.compile(r'^\w+\s*$', re.UNICODE)
_id_re = re.compile(r'^(\w*)#(\w+)\s*$', re.UNICODE)
_class_re = re.compile(r'^(\w*)\.(\w+)\s*$', re.UNICODE)
def css_to_xpath(css_expr, prefix='descendant-or-self::'):
if isinstance(css_expr, _basestring):
match = _el_re.search(css_expr)
if match is not None:
return '%s%s' % (prefix, match.group(0).strip())
match = _id_re.search(css_expr)
if match is not None:
return "%s%s[@id = '%s']" % (
prefix, match.group(1) or '*', match.group(2))
match = _class_re.search(css_expr)
if match is not None:
return "%s%s[@class and contains(concat(' ', normalize-space(@class), ' '), ' %s ')]" % (
prefix, match.group(1) or '*', match.group(2))
css_expr = parse(css_expr)
expr = css_expr.xpath()
assert expr is not None, (
"Got None for xpath expression from %s" % repr(css_expr))
if prefix:
expr.add_prefix(prefix)
return _unicode(expr)
class XPathExpr(object):
def __init__(self, prefix=None, path=None, element='*', condition=None,
star_prefix=False):
self.prefix = prefix
self.path = path
self.element = element
self.condition = condition
self.star_prefix = star_prefix
def __str__(self):
path = ''
if self.prefix is not None:
path += _unicode(self.prefix)
if self.path is not None:
path += _unicode(self.path)
path += _unicode(self.element)
if self.condition:
path += '[%s]' % self.condition
return path
def __repr__(self):
return '%s[%s]' % (
self.__class__.__name__, self)
def add_condition(self, condition):
if self.condition:
self.condition = '%s and (%s)' % (self.condition, condition)
else:
self.condition = condition
def add_path(self, part):
if self.path is None:
self.path = self.element
else:
self.path += self.element
self.element = part
def add_prefix(self, prefix):
if self.prefix:
self.prefix = prefix + self.prefix
else:
self.prefix = prefix
def add_name_test(self):
if self.element == '*':
# We weren't doing a test anyway
return
self.add_condition("name() = %s" % xpath_literal(self.element))
self.element = '*'
def add_star_prefix(self):
"""
Adds a /* prefix if there is no prefix. This is when you need
to keep context's constrained to a single parent.
"""
if self.path:
self.path += '*/'
else:
self.path = '*/'
self.star_prefix = True
def join(self, combiner, other):
prefix = _unicode(self)
prefix += combiner
path = (other.prefix or '') + (other.path or '')
# We don't need a star prefix if we are joining to this other
# prefix; so we'll get rid of it
if other.star_prefix and path == '*/':
path = ''
self.prefix = prefix
self.path = path
self.element = other.element
self.condition = other.condition
class XPathExprOr(XPathExpr):
"""
Represents |'d expressions. Note that unfortunately it isn't
the union, it's the sum, so duplicate elements will appear.
"""
def __init__(self, items, prefix=None):
for item in items:
assert item is not None
self.items = items
self.prefix = prefix
def __str__(self):
prefix = self.prefix or ''
return ' | '.join(["%s%s" % (prefix,i) for i in self.items])
split_at_single_quotes = re.compile("('+)").split
def xpath_literal(s):
if isinstance(s, Element):
# This is probably a symbol that looks like an expression...
s = s._format_element()
else:
s = _unicode(s)
if "'" not in s:
s = "'%s'" % s
elif '"' not in s:
s = '"%s"' % s
else:
s = "concat(%s)" % ','.join([
(("'" in part) and '"%s"' or "'%s'") % part
for part in split_at_single_quotes(s) if part
])
return s
##############################
## Parsing functions
def parse(string):
stream = TokenStream(tokenize(string))
stream.source = string
try:
return parse_selector_group(stream)
except SelectorSyntaxError:
import sys
e = sys.exc_info()[1]
message = "%s at %s -> %r" % (
e, stream.used, stream.peek())
e.msg = message
if sys.version_info < (2,6):
e.message = message
e.args = tuple([message])
raise
def parse_selector_group(stream):
result = []
while 1:
result.append(parse_selector(stream))
if stream.peek() == ',':
stream.next()
# Ignore optional whitespace after a group separator
while stream.peek() == ' ':
stream.next()
else:
break
if len(result) == 1:
return result[0]
else:
return Or(result)
def parse_selector(stream):
result = parse_simple_selector(stream)
while 1:
peek = stream.peek()
if peek == ',' or peek is None:
return result
elif peek in ('+', '>', '~'):
# A combinator
combinator = stream.next()
# Ignore optional whitespace after a combinator
while stream.peek() == ' ':
stream.next()
else:
combinator = ' '
consumed = len(stream.used)
next_selector = parse_simple_selector(stream)
if consumed == len(stream.used):
raise SelectorSyntaxError(
"Expected selector, got '%s'" % stream.peek())
result = CombinedSelector(result, combinator, next_selector)
return result
def parse_simple_selector(stream):
peek = stream.peek()
if peek != '*' and not isinstance(peek, Symbol):
element = namespace = '*'
else:
next = stream.next()
if next != '*' and not isinstance(next, Symbol):
raise SelectorSyntaxError(
"Expected symbol, got '%s'" % next)
if stream.peek() == '|':
namespace = next
stream.next()
element = stream.next()
if element != '*' and not isinstance(next, Symbol):
raise SelectorSyntaxError(
"Expected symbol, got '%s'" % next)
else:
namespace = '*'
element = next
result = Element(namespace, element)
has_hash = False
while 1:
peek = stream.peek()
if peek == '#':
if has_hash:
# You can't have two hashes
# (FIXME: is there some more general rule I'm missing?)
break
stream.next()
result = Hash(result, stream.next())
has_hash = True
continue
elif peek == '.':
stream.next()
result = Class(result, stream.next())
continue
elif peek == '[':
stream.next()
result = parse_attrib(result, stream)
next = stream.next()
if not next == ']':
raise SelectorSyntaxError(
"] expected, got '%s'" % next)
continue
elif peek == ':' or peek == '::':
type = stream.next()
ident = stream.next()
if not isinstance(ident, Symbol):
raise SelectorSyntaxError(
"Expected symbol, got '%s'" % ident)
if stream.peek() == '(':
stream.next()
peek = stream.peek()
if isinstance(peek, String):
selector = stream.next()
elif isinstance(peek, Symbol) and is_int(peek):
selector = int(stream.next())
else:
# FIXME: parse_simple_selector, or selector, or...?
selector = parse_simple_selector(stream)
next = stream.next()
if not next == ')':
raise SelectorSyntaxError(
"Expected ')', got '%s' and '%s'"
% (next, selector))
result = Function(result, type, ident, selector)
else:
result = Pseudo(result, type, ident)
continue
else:
if peek == ' ':
stream.next()
break
# FIXME: not sure what "negation" is
return result
def is_int(v):
try:
int(v)
except ValueError:
return False
else:
return True
def parse_attrib(selector, stream):
attrib = stream.next()
if stream.peek() == '|':
namespace = attrib
stream.next()
attrib = stream.next()
else:
namespace = '*'
if stream.peek() == ']':
return Attrib(selector, namespace, attrib, 'exists', None)
op = stream.next()
if not op in ('^=', '$=', '*=', '=', '~=', '|=', '!='):
raise SelectorSyntaxError(
"Operator expected, got '%s'" % op)
value = stream.next()
if not isinstance(value, (Symbol, String)):
raise SelectorSyntaxError(
"Expected string or symbol, got '%s'" % value)
return Attrib(selector, namespace, attrib, op, value)
def parse_series(s):
"""
Parses things like '1n+2', or 'an+b' generally, returning (a, b)
"""
if isinstance(s, Element):
s = s._format_element()
if not s or s == '*':
# Happens when there's nothing, which the CSS parser thinks of as *
return (0, 0)
if isinstance(s, int):
# Happens when you just get a number
return (0, s)
if s == 'odd':
return (2, 1)
elif s == 'even':
return (2, 0)
elif s == 'n':
return (1, 0)
if 'n' not in s:
# Just a b
return (0, int(s))
a, b = s.split('n', 1)
if not a:
a = 1
elif a == '-' or a == '+':
a = int(a+'1')
else:
a = int(a)
if not b:
b = 0
elif b == '-' or b == '+':
b = int(b+'1')
else:
b = int(b)
return (a, b)
############################################################
## Tokenizing
############################################################
_match_whitespace = re.compile(r'\s+', re.UNICODE).match
_replace_comments = re.compile(r'/\*.*?\*/', re.DOTALL).sub
_match_count_number = re.compile(r'[+-]?\d*n(?:[+-]\d+)?').match
def tokenize(s):
pos = 0
s = _replace_comments('', s)
while 1:
match = _match_whitespace(s, pos=pos)
if match:
preceding_whitespace_pos = pos
pos = match.end()
else:
preceding_whitespace_pos = 0
if pos >= len(s):
return
match = _match_count_number(s, pos=pos)
if match and match.group() != 'n':
sym = s[pos:match.end()]
yield Symbol(sym, pos)
pos = match.end()
continue
c = s[pos]
c2 = s[pos:pos+2]
if c2 in ('~=', '|=', '^=', '$=', '*=', '::', '!='):
if c2 == '::' and preceding_whitespace_pos > 0:
yield Token(' ', preceding_whitespace_pos)
yield Token(c2, pos)
pos += 2
continue
if c in '>+~,.*=[]()|:#':
if c in ':.#[' and preceding_whitespace_pos > 0:
yield Token(' ', preceding_whitespace_pos)
yield Token(c, pos)
pos += 1
continue
if c == '"' or c == "'":
# Quoted string
old_pos = pos
sym, pos = tokenize_escaped_string(s, pos)
yield String(sym, old_pos)
continue
old_pos = pos
sym, pos = tokenize_symbol(s, pos)
yield Symbol(sym, old_pos)
continue
split_at_string_escapes = re.compile(r'(\\(?:%s))'
% '|'.join(['[A-Fa-f0-9]{1,6}(?:\r\n|\s)?',
'[^A-Fa-f0-9]'])).split
def unescape_string_literal(literal):
substrings = []
for substring in split_at_string_escapes(literal):
if not substring:
continue
elif '\\' in substring:
if substring[0] == '\\' and len(substring) > 1:
substring = substring[1:]
if substring[0] in '0123456789ABCDEFabcdef':
# int() correctly ignores the potentially trailing whitespace
substring = _unichr(int(substring, 16))
else:
raise SelectorSyntaxError(
"Invalid escape sequence %r in string %r"
% (substring.split('\\')[1], literal))
substrings.append(substring)
return ''.join(substrings)
def tokenize_escaped_string(s, pos):
quote = s[pos]
assert quote in ('"', "'")
pos = pos+1
start = pos
while 1:
next = s.find(quote, pos)
if next == -1:
raise SelectorSyntaxError(
"Expected closing %s for string in: %r"
% (quote, s[start:]))
result = s[start:next]
if result.endswith('\\'):
# next quote character is escaped
pos = next+1
continue
if '\\' in result:
result = unescape_string_literal(result)
return result, next+1
_illegal_symbol = re.compile(r'[^\w\\-]', re.UNICODE)
def tokenize_symbol(s, pos):
start = pos
match = _illegal_symbol.search(s, pos=pos)
if not match:
# Goes to end of s
return s[start:], len(s)
if match.start() == pos:
assert 0, (
"Unexpected symbol: %r at %s" % (s[pos], pos))
if not match:
result = s[start:]
pos = len(s)
else:
result = s[start:match.start()]
pos = match.start()
try:
result = result.encode('ASCII', 'backslashreplace').decode('unicode_escape')
except UnicodeDecodeError:
import sys
e = sys.exc_info()[1]
raise SelectorSyntaxError(
"Bad symbol %r: %s" % (result, e))
return result, pos
class TokenStream(object):
def __init__(self, tokens, source=None):
self.used = []
self.tokens = iter(tokens)
self.source = source
self.peeked = None
self._peeking = False
try:
self.next_token = self.tokens.next
except AttributeError:
# Python 3
self.next_token = self.tokens.__next__
def next(self):
if self._peeking:
self._peeking = False
self.used.append(self.peeked)
return self.peeked
else:
try:
next = self.next_token()
self.used.append(next)
return next
except StopIteration:
return None
def __iter__(self):
return iter(self.next, None)
def peek(self):
if not self._peeking:
try:
self.peeked = self.next_token()
except StopIteration:
return None
self._peeking = True
return self.peeked
|
bsd-3-clause
|
[
3,
1898,
334,
67,
9,
8353,
473,
290,
699,
2000,
316,
14,
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,
413,
14,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
199,
3,
499,
14,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
199,
3,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
3,
4084,
14,
199,
3,
199,
3,
650,
14,
11443,
314,
536,
402,
473,
290,
699,
2000,
316,
6590,
314,
1561,
402,
2399,
8417,
1443,
199,
3,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
642,
2032,
199,
3,
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,
473,
879,
699,
13884,
1206,
1549,
199,
3,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
8820,
12,
199,
3,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
5471,
2296,
12,
199,
3,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
7126,
12,
1549,
199,
3,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
9815,
1634,
199,
3,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
334,
6446,
199,
3,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
1634,
5749,
199,
3,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
421,
199,
624,
14391,
3240,
3283,
83,
4079,
641,
1323,
2042,
14,
199,
199,
2765,
859,
5171,
30090,
4692,
15,
4943,
3762,
4079,
641,
15750,
9759,
83,
14,
199,
9295,
314,
658,
14391,
11212,
64,
1021,
367,
2436,
14,
199,
624,
199,
199,
646,
295,
199,
504,
14490,
492,
7559,
199,
199,
363,
452,
363,
275,
788,
11212,
9294,
297,
283,
9093,
547,
297,
1779,
283,
14391,
11212,
418,
199,
199,
893,
26,
272,
485,
17628,
275,
7116,
199,
2590,
12746,
26,
272,
485,
17628,
275,
620,
199,
199,
533,
3240,
3283,
9294,
8,
9294,
304,
272,
986,
199,
199,
533,
22013,
547,
8,
13281,
304,
272,
986,
199,
199,
533,
15750,
11212,
8,
9464,
14,
27645,
304,
272,
408,
33,
15750,
9759,
14,
339,
11028,
447,
398,
1306,
687,
14490,
492,
7559,
12,
11431,
2416,
267,
1306,
3504,
275,
11431,
2416,
14,
14391,
11212,
480,
65,
1947,
690,
1982,
531,
398,
1306,
1738,
275,
7559,
14,
4317,
6757,
65,
2535,
66,
2535,
67,
31022,
1450,
2535,
1739,
30,
3876,
1108,
1739,
2957,
1450,
2957,
66,
2957,
65,
9579,
267,
1306,
359,
579,
14,
1450,
367,
579,
315,
3504,
8,
1231,
9,
1622,
267,
788,
1739,
418,
2286,
4005,
675,
15750,
10747,
12,
1265,
1929,
370,
986,
282,
2403,
13,
475,
13,
3251,
272,
4412,
465,
1124,
9247,
1040,
4252,
1423,
447,
13857,
1306,
18148,
561,
275,
283,
1014,
921,
1544,
14,
87,
19,
14,
1308,
15,
16278,
15,
996,
15,
1081,
13,
17120,
13,
7093,
13,
561,
19367,
267,
1306,
3504,
63,
561,
275,
11431,
2416,
14,
14391,
11212,
360,
1231,
690,
18148,
92,
5831,
297,
267,
2263,
15530,
10747,
3713,
17120,
356,
18148,
561,
1552,
398,
1306,
18148,
275,
7559,
14,
4317,
1332,
267,
2263,
258,
2650,
1231,
9604,
26,
17120,
5961,
83,
15603,
267,
2263,
755,
2650,
17120,
26,
5831,
30,
12702,
1108,
17120,
26,
5831,
3524,
267,
2263,
258,
11936,
1231,
5971,
450,
18148,
561,
9,
267,
1306,
3842,
352,
14,
1450,
12,
579,
14,
505,
9,
367,
579,
315,
3504,
63,
561,
8,
17120,
1874,
267,
4274,
91,
1014,
921,
1544,
14,
87,
19,
14,
1308,
15,
16278,
15,
996,
15,
1081,
13,
17120,
13,
7093,
13,
561,
3,
93,
5831,
297,
283,
12702,
5440,
272,
408,
272,
347,
636,
826,
721,
277,
12,
11431,
12,
10747,
29,
403,
304,
267,
931,
275,
11431,
63,
475,
63,
8006,
8,
3919,
9,
267,
7559,
14,
27645,
855,
826,
721,
277,
12,
931,
12,
10747,
29,
9247,
9,
267,
291,
14,
3919,
275,
11431,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
18342,
83,
450,
83,
367,
450,
82,
3524,
450,
334,
288,
291,
855,
533,
4914,
354,
3108,
288,
6318,
8,
2101,
8,
344,
8,
277,
1724,
59,
18,
8429,
288,
291,
14,
3919,
9,
199,
199,
6565,
3726,
199,
309,
8767,
2251,
26,
199,
199,
893,
26,
272,
485,
2975,
275,
2649,
272,
485,
324,
15257,
275,
17742,
199,
2590,
12746,
26,
272,
327,
2018,
650,
272,
485,
2975,
275,
620,
272,
485,
324,
15257,
275,
8678,
199,
199,
533,
485,
27921,
3264,
1547,
2975,
304,
272,
347,
636,
1222,
721,
1886,
12,
4072,
12,
2086,
304,
267,
1559,
275,
485,
2975,
855,
1222,
721,
1886,
12,
4072,
9,
267,
1559,
14,
1712,
275,
2086,
267,
372,
1559,
5493,
347,
636,
2722,
721,
277,
304,
267,
372,
1543,
83,
4042,
83,
12,
450,
82,
3171,
450,
334,
288,
291,
855,
533,
4914,
354,
3108,
288,
485,
2975,
855,
2722,
721,
277,
395,
288,
291,
14,
1712,
9,
199,
199,
533,
10080,
1547,
27921,
3264,
304,
272,
986,
199,
199,
533,
2624,
1547,
27921,
3264,
304,
272,
986,
199,
199,
533,
8767,
1547,
27921,
3264,
304,
272,
986,
199,
199,
26207,
381,
199,
309,
28747,
199,
26207,
381,
199,
199,
6565,
3726,
199,
309,
18377,
2251,
26,
199,
199,
533,
8089,
8,
785,
304,
272,
408,
272,
21591,
9759,
14,
533,
63,
354,
272,
408,
339,
347,
636,
826,
721,
277,
12,
9759,
12,
1021,
63,
354,
304,
267,
291,
14,
6662,
275,
9759,
267,
291,
14,
533,
63,
354,
275,
1021,
63,
354,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
1543,
83,
9722,
82,
4111
] |
[
1898,
334,
67,
9,
8353,
473,
290,
699,
2000,
316,
14,
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,
413,
14,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
199,
3,
499,
14,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
199,
3,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
3,
4084,
14,
199,
3,
199,
3,
650,
14,
11443,
314,
536,
402,
473,
290,
699,
2000,
316,
6590,
314,
1561,
402,
2399,
8417,
1443,
199,
3,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
642,
2032,
199,
3,
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,
473,
879,
699,
13884,
1206,
1549,
199,
3,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
8820,
12,
199,
3,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
5471,
2296,
12,
199,
3,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
7126,
12,
1549,
199,
3,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
9815,
1634,
199,
3,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
334,
6446,
199,
3,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
1634,
5749,
199,
3,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
421,
199,
624,
14391,
3240,
3283,
83,
4079,
641,
1323,
2042,
14,
199,
199,
2765,
859,
5171,
30090,
4692,
15,
4943,
3762,
4079,
641,
15750,
9759,
83,
14,
199,
9295,
314,
658,
14391,
11212,
64,
1021,
367,
2436,
14,
199,
624,
199,
199,
646,
295,
199,
504,
14490,
492,
7559,
199,
199,
363,
452,
363,
275,
788,
11212,
9294,
297,
283,
9093,
547,
297,
1779,
283,
14391,
11212,
418,
199,
199,
893,
26,
272,
485,
17628,
275,
7116,
199,
2590,
12746,
26,
272,
485,
17628,
275,
620,
199,
199,
533,
3240,
3283,
9294,
8,
9294,
304,
272,
986,
199,
199,
533,
22013,
547,
8,
13281,
304,
272,
986,
199,
199,
533,
15750,
11212,
8,
9464,
14,
27645,
304,
272,
408,
33,
15750,
9759,
14,
339,
11028,
447,
398,
1306,
687,
14490,
492,
7559,
12,
11431,
2416,
267,
1306,
3504,
275,
11431,
2416,
14,
14391,
11212,
480,
65,
1947,
690,
1982,
531,
398,
1306,
1738,
275,
7559,
14,
4317,
6757,
65,
2535,
66,
2535,
67,
31022,
1450,
2535,
1739,
30,
3876,
1108,
1739,
2957,
1450,
2957,
66,
2957,
65,
9579,
267,
1306,
359,
579,
14,
1450,
367,
579,
315,
3504,
8,
1231,
9,
1622,
267,
788,
1739,
418,
2286,
4005,
675,
15750,
10747,
12,
1265,
1929,
370,
986,
282,
2403,
13,
475,
13,
3251,
272,
4412,
465,
1124,
9247,
1040,
4252,
1423,
447,
13857,
1306,
18148,
561,
275,
283,
1014,
921,
1544,
14,
87,
19,
14,
1308,
15,
16278,
15,
996,
15,
1081,
13,
17120,
13,
7093,
13,
561,
19367,
267,
1306,
3504,
63,
561,
275,
11431,
2416,
14,
14391,
11212,
360,
1231,
690,
18148,
92,
5831,
297,
267,
2263,
15530,
10747,
3713,
17120,
356,
18148,
561,
1552,
398,
1306,
18148,
275,
7559,
14,
4317,
1332,
267,
2263,
258,
2650,
1231,
9604,
26,
17120,
5961,
83,
15603,
267,
2263,
755,
2650,
17120,
26,
5831,
30,
12702,
1108,
17120,
26,
5831,
3524,
267,
2263,
258,
11936,
1231,
5971,
450,
18148,
561,
9,
267,
1306,
3842,
352,
14,
1450,
12,
579,
14,
505,
9,
367,
579,
315,
3504,
63,
561,
8,
17120,
1874,
267,
4274,
91,
1014,
921,
1544,
14,
87,
19,
14,
1308,
15,
16278,
15,
996,
15,
1081,
13,
17120,
13,
7093,
13,
561,
3,
93,
5831,
297,
283,
12702,
5440,
272,
408,
272,
347,
636,
826,
721,
277,
12,
11431,
12,
10747,
29,
403,
304,
267,
931,
275,
11431,
63,
475,
63,
8006,
8,
3919,
9,
267,
7559,
14,
27645,
855,
826,
721,
277,
12,
931,
12,
10747,
29,
9247,
9,
267,
291,
14,
3919,
275,
11431,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
18342,
83,
450,
83,
367,
450,
82,
3524,
450,
334,
288,
291,
855,
533,
4914,
354,
3108,
288,
6318,
8,
2101,
8,
344,
8,
277,
1724,
59,
18,
8429,
288,
291,
14,
3919,
9,
199,
199,
6565,
3726,
199,
309,
8767,
2251,
26,
199,
199,
893,
26,
272,
485,
2975,
275,
2649,
272,
485,
324,
15257,
275,
17742,
199,
2590,
12746,
26,
272,
327,
2018,
650,
272,
485,
2975,
275,
620,
272,
485,
324,
15257,
275,
8678,
199,
199,
533,
485,
27921,
3264,
1547,
2975,
304,
272,
347,
636,
1222,
721,
1886,
12,
4072,
12,
2086,
304,
267,
1559,
275,
485,
2975,
855,
1222,
721,
1886,
12,
4072,
9,
267,
1559,
14,
1712,
275,
2086,
267,
372,
1559,
5493,
347,
636,
2722,
721,
277,
304,
267,
372,
1543,
83,
4042,
83,
12,
450,
82,
3171,
450,
334,
288,
291,
855,
533,
4914,
354,
3108,
288,
485,
2975,
855,
2722,
721,
277,
395,
288,
291,
14,
1712,
9,
199,
199,
533,
10080,
1547,
27921,
3264,
304,
272,
986,
199,
199,
533,
2624,
1547,
27921,
3264,
304,
272,
986,
199,
199,
533,
8767,
1547,
27921,
3264,
304,
272,
986,
199,
199,
26207,
381,
199,
309,
28747,
199,
26207,
381,
199,
199,
6565,
3726,
199,
309,
18377,
2251,
26,
199,
199,
533,
8089,
8,
785,
304,
272,
408,
272,
21591,
9759,
14,
533,
63,
354,
272,
408,
339,
347,
636,
826,
721,
277,
12,
9759,
12,
1021,
63,
354,
304,
267,
291,
14,
6662,
275,
9759,
267,
291,
14,
533,
63,
354,
275,
1021,
63,
354,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
1543,
83,
9722,
82,
4111,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
comradealain/project_SM
|
simulation.py
|
1
|
2956
|
import random
def generateTBA(rda):
if rda == 0:
return 4
elif rda >= 1 and rda <= 25:
return 1
elif rda >= 26 and rda <= 65:
return 2
elif rda >= 66 and rda <= 85:
return 3
else:
return 4
def ward_1_service_time(rds):
if rds == 0:
return 6
elif rds >= 1 and rds <= 20:
return 4
elif rds >= 21 and rds <= 45:
return 5
elif rds >= 46 and rds <= 75:
return 3
else:
return 6
def ward_2_service_time(rds):
if rds == 0:
return 5
elif rds >= 1 and rds <= 30:
return 7
elif rds >= 31 and rds <= 58:
return 6
elif rds >= 59 and rds <= 83:
return 8
else:
return 5
def ward_3_service_time(rds):
if rds == 0:
return 9
elif rds >= 1 and rds <= 35:
return 7
elif rds >= 36 and rds <= 60:
return 10
elif rds >= 61 and rds <= 80:
return 8
else:
return 9
cta = 0
rds = round(random.uniform(0,100))
ward_1_tsb = 0
ward_1_st = ward_1_service_time(rds)
ward_1_tse = ward_1_tsb + ward_1_st
ward_1_tst = ward_1_st
ward_2_tse = -1
ward_3_tse = -1
ward_2_tst = 0
ward_3_tst = 0
total_time_queue = 0
for i in range(2,101):
rda = round(random.uniform(0,100))
cta = cta + generateTBA(rda)
rds = round(random.uniform(0,100))
if cta >= ward_1_tse:
ward_1_tsb = cta
ward_1_st = ward_1_service_time(rds)
ward_1_tse = ward_1_tsb + ward_1_st
ward_1_tst = ward_1_tst + ward_1_st
else:
if cta >= ward_2_tse or ward_2_tse == -1:
ward_2_tsb = cta
ward_2_st = ward_2_service_time(rds)
ward_2_tse = ward_2_tsb + ward_2_st
ward_2_tst = ward_2_tst + ward_2_st
else:
if cta >= ward_3_tse or ward_3_tse == -1:
ward_3_tsb = cta
ward_3_st = ward_3_service_time(rds)
ward_3_tse = ward_3_tsb + ward_3_st
ward_3_tst = ward_3_tst + ward_3_st
else:
w = min(ward_1_tse,ward_2_tse,ward_3_tse)
if w == ward_1_tse:
total_time_queue = total_time_queue + ward_1_tse - cta
ward_1_tsb = ward_1_tse
ward_1_st = ward_1_service_time(rds)
ward_1_tse = ward_1_tsb + ward_1_st
ward_1_tst = ward_1_tst + ward_1_st
elif w == ward_2_tse:
total_time_queue = total_time_queue + ward_2_tse - cta
ward_2_tsb = ward_2_tse
ward_2_st = ward_2_service_time(rds)
ward_2_tse = ward_2_tsb + ward_2_st
ward_2_tst = ward_2_tst + ward_2_st
else:
total_time_queue = total_time_queue + ward_3_tse - cta
ward_3_tsb = ward_3_tse
ward_3_st = ward_3_service_time(rds)
ward_3_tse = ward_3_tsb + ward_3_st
ward_3_tst = ward_3_tst + ward_3_st
total_time_system = ward_1_tst + ward_2_tst + ward_3_tst + total_time_queue
avg_time_system = total_time_system / 100
avg_delay = total_time_queue / 100
print("Total time in queue: " + str(total_time_queue))
print("Average delay: " + str(avg_delay))
print("Total time in system: " + str(total_time_system))
print("Average time in system: " + str(avg_time_system))
|
apache-2.0
|
[
646,
2196,
199,
199,
318,
3550,
52,
4134,
8,
82,
983,
304,
199,
198,
692,
519,
983,
508,
378,
26,
507,
198,
1107,
841,
8299,
198,
4164,
519,
983,
2356,
413,
436,
519,
983,
2695,
5661,
26,
6722,
372,
413,
8299,
198,
4164,
519,
983,
2356,
7875,
436,
519,
983,
2695,
11738,
26,
507,
198,
1107,
499,
421,
198,
4164,
519,
983,
2356,
14157,
436,
519,
983,
2695,
16412,
26,
507,
198,
1107,
650,
421,
198,
2836,
26,
507,
198,
1107,
841,
199,
199,
318,
336,
1005,
63,
17,
63,
1364,
63,
521,
8,
23098,
304,
199,
198,
692,
519,
795,
508,
378,
26,
507,
198,
1107,
1227,
8299,
198,
4164,
519,
795,
2356,
413,
436,
519,
795,
2695,
3388,
26,
6722,
372,
841,
8299,
198,
4164,
519,
795,
2356,
7829,
436,
519,
795,
2695,
10416,
26,
507,
198,
1107,
959,
421,
198,
4164,
519,
795,
2356,
12426,
436,
519,
795,
2695,
13098,
26,
507,
198,
1107,
650,
421,
198,
2836,
26,
507,
198,
1107,
1227,
199,
199,
318,
336,
1005,
63,
18,
63,
1364,
63,
521,
8,
23098,
304,
199,
198,
692,
519,
795,
508,
378,
26,
507,
198,
1107,
959,
8299,
198,
4164,
519,
795,
2356,
413,
436,
519,
795,
2695,
4233,
26,
6722,
372,
1520,
8299,
198,
4164,
519,
795,
2356,
7105,
436,
519,
795,
2695,
13713,
26,
507,
198,
1107,
1227,
421,
198,
4164,
519,
795,
2356,
8155,
436,
519,
795,
2695,
20582,
26,
507,
198,
1107,
1695,
421,
198,
2836,
26,
507,
198,
1107,
959,
199,
199,
318,
336,
1005,
63,
19,
63,
1364,
63,
521,
8,
23098,
304,
199,
198,
692,
519,
795,
508,
378,
26,
507,
198,
1107,
1749,
8299,
198,
4164,
519,
795,
2356,
413,
436,
519,
795,
2695,
8685,
26,
6722,
372,
1520,
8299,
198,
4164,
519,
795,
2356,
8780,
436,
519,
795,
2695,
5212,
26,
507,
198,
1107,
1616,
421,
198,
4164,
519,
795,
2356,
17017,
436,
519,
795,
2695,
5939,
26,
507,
198,
1107,
1695,
421,
198,
2836,
26,
507,
198,
1107,
1749,
421,
199,
319,
65,
275,
378,
199,
23098,
275,
6168,
8,
2355,
14,
8830,
8,
16,
12,
1960,
430,
199,
199,
3079,
63,
17,
63,
1086,
66,
275,
378,
199,
3079,
63,
17,
63,
270,
275,
336,
1005,
63,
17,
63,
1364,
63,
521,
8,
23098,
9,
199,
3079,
63,
17,
63,
84,
261,
275,
336,
1005,
63,
17,
63,
1086,
66,
435,
336,
1005,
63,
17,
63,
270,
199,
3079,
63,
17,
63,
84,
270,
275,
336,
1005,
63,
17,
63,
270,
4388,
199,
3079,
63,
18,
63,
84,
261,
275,
446,
17,
199,
3079,
63,
19,
63,
84,
261,
275,
446,
17,
199,
199,
3079,
63,
18,
63,
84,
270,
275,
378,
199,
3079,
63,
19,
63,
84,
270,
275,
378,
199,
199,
2923,
63,
521,
63,
1825,
275,
378,
199,
199,
509,
284,
315,
1425,
8,
18,
12,
4893,
304,
199,
198,
82,
983,
275,
6168,
8,
2355,
14,
8830,
8,
16,
12,
1960,
430,
199,
198,
319,
65,
275,
286,
502,
435,
3550,
52,
4134,
8,
82,
983,
9,
199,
198,
23098,
275,
6168,
8,
2355,
14,
8830,
8,
16,
12,
1960,
430,
421,
198,
692,
286,
502,
2356,
336,
1005,
63,
17,
63,
84,
261,
26,
507,
198,
3079,
63,
17,
63,
1086,
66,
275,
286,
502,
507,
198,
3079,
63,
17,
63,
270,
275,
336,
1005,
63,
17,
63,
1364,
63,
521,
8,
23098,
9,
507,
198,
3079,
63,
17,
63,
84,
261,
275,
336,
1005,
63,
17,
63,
1086,
66,
435,
336,
1005,
63,
17,
63,
270,
507,
198,
3079,
63,
17,
63,
84,
270,
275,
336,
1005,
63,
17,
63,
84,
270,
435,
336,
1005,
63,
17,
63,
270,
421,
198,
2836,
26,
507,
198,
692,
286,
502,
2356,
336,
1005,
63,
18,
63,
84,
261,
503,
336,
1005,
63,
18,
63,
84,
261,
508,
446,
17,
26,
686,
198,
3079,
63,
18,
63,
1086,
66,
275,
286,
502,
686,
198,
3079,
63,
18,
63,
270,
275,
336,
1005,
63,
18,
63,
1364,
63,
521,
8,
23098,
9,
686,
198,
3079,
63,
18,
63,
84,
261,
275,
336,
1005,
63,
18,
63,
1086,
66,
435,
336,
1005,
63,
18,
63,
270,
686,
198,
3079,
63,
18,
63,
84,
270,
275,
336,
1005,
63,
18,
63,
84,
270,
435,
336,
1005,
63,
18,
63,
270,
507,
198,
2836,
26,
686,
198,
692,
286,
502,
2356,
336,
1005,
63,
19,
63,
84,
261,
503,
336,
1005,
63,
19,
63,
84,
261,
508,
446,
17,
26,
1585,
198,
3079,
63,
19,
63,
1086,
66,
275,
286,
502,
1585,
198,
3079,
63,
19,
63,
270,
275,
336,
1005,
63,
19,
63,
1364,
63,
521,
8,
23098,
9,
1585,
198,
3079,
63,
19,
63,
84,
261,
275,
336,
1005,
63,
19,
63,
1086,
66,
435,
336,
1005,
63,
19,
63,
270,
1585,
198,
3079,
63,
19,
63,
84,
270,
275,
336,
1005,
63,
19,
63,
84,
270,
435,
336,
1005,
63,
19,
63,
270,
6319,
198,
2836,
26,
24449,
336,
275,
1748,
8,
3079,
63,
17,
63,
84,
261,
12,
3079,
63,
18,
63,
84,
261,
12,
3079,
63,
19,
63,
84,
261,
9,
326,
24449,
340,
336,
508,
336,
1005,
63,
17,
63,
84,
261,
26,
1585,
258,
198,
2923,
63,
521,
63,
1825,
275,
3141,
63,
521,
63,
1825,
435,
336,
1005,
63,
17,
63,
84,
261,
446,
286,
502,
28932,
258,
198,
3079,
63,
17,
63,
1086,
66,
275,
336,
1005,
63,
17,
63,
84,
261,
1585,
258,
198,
3079,
63,
17,
63,
270,
275,
336,
1005,
63,
17,
63,
1364,
63,
521,
8,
23098,
9,
1585,
258,
198,
3079,
63,
17,
63,
84,
261,
275,
336,
1005,
63,
17,
63,
1086,
66,
435,
336,
1005,
63,
17,
63,
270,
1585,
258,
198,
3079,
63,
17,
63,
84,
270,
275,
336,
1005,
63,
17,
63,
84,
270,
435,
336,
1005,
63,
17,
63,
270,
16737,
259,
916,
336,
508,
336,
1005,
63,
18,
63,
84,
261,
26,
1585,
258,
198,
2923,
63,
521,
63,
1825,
275,
3141,
63,
521,
63,
1825,
435,
336,
1005,
63,
18,
63,
84,
261,
446,
286,
502,
1585,
258,
198,
3079,
63,
18,
63,
1086,
66,
275,
336,
1005
] |
[
2196,
199,
199,
318,
3550,
52,
4134,
8,
82,
983,
304,
199,
198,
692,
519,
983,
508,
378,
26,
507,
198,
1107,
841,
8299,
198,
4164,
519,
983,
2356,
413,
436,
519,
983,
2695,
5661,
26,
6722,
372,
413,
8299,
198,
4164,
519,
983,
2356,
7875,
436,
519,
983,
2695,
11738,
26,
507,
198,
1107,
499,
421,
198,
4164,
519,
983,
2356,
14157,
436,
519,
983,
2695,
16412,
26,
507,
198,
1107,
650,
421,
198,
2836,
26,
507,
198,
1107,
841,
199,
199,
318,
336,
1005,
63,
17,
63,
1364,
63,
521,
8,
23098,
304,
199,
198,
692,
519,
795,
508,
378,
26,
507,
198,
1107,
1227,
8299,
198,
4164,
519,
795,
2356,
413,
436,
519,
795,
2695,
3388,
26,
6722,
372,
841,
8299,
198,
4164,
519,
795,
2356,
7829,
436,
519,
795,
2695,
10416,
26,
507,
198,
1107,
959,
421,
198,
4164,
519,
795,
2356,
12426,
436,
519,
795,
2695,
13098,
26,
507,
198,
1107,
650,
421,
198,
2836,
26,
507,
198,
1107,
1227,
199,
199,
318,
336,
1005,
63,
18,
63,
1364,
63,
521,
8,
23098,
304,
199,
198,
692,
519,
795,
508,
378,
26,
507,
198,
1107,
959,
8299,
198,
4164,
519,
795,
2356,
413,
436,
519,
795,
2695,
4233,
26,
6722,
372,
1520,
8299,
198,
4164,
519,
795,
2356,
7105,
436,
519,
795,
2695,
13713,
26,
507,
198,
1107,
1227,
421,
198,
4164,
519,
795,
2356,
8155,
436,
519,
795,
2695,
20582,
26,
507,
198,
1107,
1695,
421,
198,
2836,
26,
507,
198,
1107,
959,
199,
199,
318,
336,
1005,
63,
19,
63,
1364,
63,
521,
8,
23098,
304,
199,
198,
692,
519,
795,
508,
378,
26,
507,
198,
1107,
1749,
8299,
198,
4164,
519,
795,
2356,
413,
436,
519,
795,
2695,
8685,
26,
6722,
372,
1520,
8299,
198,
4164,
519,
795,
2356,
8780,
436,
519,
795,
2695,
5212,
26,
507,
198,
1107,
1616,
421,
198,
4164,
519,
795,
2356,
17017,
436,
519,
795,
2695,
5939,
26,
507,
198,
1107,
1695,
421,
198,
2836,
26,
507,
198,
1107,
1749,
421,
199,
319,
65,
275,
378,
199,
23098,
275,
6168,
8,
2355,
14,
8830,
8,
16,
12,
1960,
430,
199,
199,
3079,
63,
17,
63,
1086,
66,
275,
378,
199,
3079,
63,
17,
63,
270,
275,
336,
1005,
63,
17,
63,
1364,
63,
521,
8,
23098,
9,
199,
3079,
63,
17,
63,
84,
261,
275,
336,
1005,
63,
17,
63,
1086,
66,
435,
336,
1005,
63,
17,
63,
270,
199,
3079,
63,
17,
63,
84,
270,
275,
336,
1005,
63,
17,
63,
270,
4388,
199,
3079,
63,
18,
63,
84,
261,
275,
446,
17,
199,
3079,
63,
19,
63,
84,
261,
275,
446,
17,
199,
199,
3079,
63,
18,
63,
84,
270,
275,
378,
199,
3079,
63,
19,
63,
84,
270,
275,
378,
199,
199,
2923,
63,
521,
63,
1825,
275,
378,
199,
199,
509,
284,
315,
1425,
8,
18,
12,
4893,
304,
199,
198,
82,
983,
275,
6168,
8,
2355,
14,
8830,
8,
16,
12,
1960,
430,
199,
198,
319,
65,
275,
286,
502,
435,
3550,
52,
4134,
8,
82,
983,
9,
199,
198,
23098,
275,
6168,
8,
2355,
14,
8830,
8,
16,
12,
1960,
430,
421,
198,
692,
286,
502,
2356,
336,
1005,
63,
17,
63,
84,
261,
26,
507,
198,
3079,
63,
17,
63,
1086,
66,
275,
286,
502,
507,
198,
3079,
63,
17,
63,
270,
275,
336,
1005,
63,
17,
63,
1364,
63,
521,
8,
23098,
9,
507,
198,
3079,
63,
17,
63,
84,
261,
275,
336,
1005,
63,
17,
63,
1086,
66,
435,
336,
1005,
63,
17,
63,
270,
507,
198,
3079,
63,
17,
63,
84,
270,
275,
336,
1005,
63,
17,
63,
84,
270,
435,
336,
1005,
63,
17,
63,
270,
421,
198,
2836,
26,
507,
198,
692,
286,
502,
2356,
336,
1005,
63,
18,
63,
84,
261,
503,
336,
1005,
63,
18,
63,
84,
261,
508,
446,
17,
26,
686,
198,
3079,
63,
18,
63,
1086,
66,
275,
286,
502,
686,
198,
3079,
63,
18,
63,
270,
275,
336,
1005,
63,
18,
63,
1364,
63,
521,
8,
23098,
9,
686,
198,
3079,
63,
18,
63,
84,
261,
275,
336,
1005,
63,
18,
63,
1086,
66,
435,
336,
1005,
63,
18,
63,
270,
686,
198,
3079,
63,
18,
63,
84,
270,
275,
336,
1005,
63,
18,
63,
84,
270,
435,
336,
1005,
63,
18,
63,
270,
507,
198,
2836,
26,
686,
198,
692,
286,
502,
2356,
336,
1005,
63,
19,
63,
84,
261,
503,
336,
1005,
63,
19,
63,
84,
261,
508,
446,
17,
26,
1585,
198,
3079,
63,
19,
63,
1086,
66,
275,
286,
502,
1585,
198,
3079,
63,
19,
63,
270,
275,
336,
1005,
63,
19,
63,
1364,
63,
521,
8,
23098,
9,
1585,
198,
3079,
63,
19,
63,
84,
261,
275,
336,
1005,
63,
19,
63,
1086,
66,
435,
336,
1005,
63,
19,
63,
270,
1585,
198,
3079,
63,
19,
63,
84,
270,
275,
336,
1005,
63,
19,
63,
84,
270,
435,
336,
1005,
63,
19,
63,
270,
6319,
198,
2836,
26,
24449,
336,
275,
1748,
8,
3079,
63,
17,
63,
84,
261,
12,
3079,
63,
18,
63,
84,
261,
12,
3079,
63,
19,
63,
84,
261,
9,
326,
24449,
340,
336,
508,
336,
1005,
63,
17,
63,
84,
261,
26,
1585,
258,
198,
2923,
63,
521,
63,
1825,
275,
3141,
63,
521,
63,
1825,
435,
336,
1005,
63,
17,
63,
84,
261,
446,
286,
502,
28932,
258,
198,
3079,
63,
17,
63,
1086,
66,
275,
336,
1005,
63,
17,
63,
84,
261,
1585,
258,
198,
3079,
63,
17,
63,
270,
275,
336,
1005,
63,
17,
63,
1364,
63,
521,
8,
23098,
9,
1585,
258,
198,
3079,
63,
17,
63,
84,
261,
275,
336,
1005,
63,
17,
63,
1086,
66,
435,
336,
1005,
63,
17,
63,
270,
1585,
258,
198,
3079,
63,
17,
63,
84,
270,
275,
336,
1005,
63,
17,
63,
84,
270,
435,
336,
1005,
63,
17,
63,
270,
16737,
259,
916,
336,
508,
336,
1005,
63,
18,
63,
84,
261,
26,
1585,
258,
198,
2923,
63,
521,
63,
1825,
275,
3141,
63,
521,
63,
1825,
435,
336,
1005,
63,
18,
63,
84,
261,
446,
286,
502,
1585,
258,
198,
3079,
63,
18,
63,
1086,
66,
275,
336,
1005,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
cschenck/blender_sim
|
fluid_sim_deps/blender-2.69/2.69/scripts/addons/add_mesh_extra_objects/add_mesh_polysphere.py
|
1
|
3014
|
# ##### BEGIN GPL LICENSE BLOCK #####
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####
'''
bl_info = {
"name": "Add PolySphere",
"author": "Andy Davies (metalliandy)",
"version": (0,1,6),
"blender": (2, 62, 0),
"location": "View3D > Add > Mesh > PolySphere",
"description": "Adds a PolySphere (all quads) for sculpting",
"warning": "",
"wiki_url": "http://wiki.blender.org/index.php/Extensions:2.5/Py/"\
"Scripts/Add_Mesh/Add_PolySphere",
"tracker_url": "",
"category": "Add Mesh"}
'''
import bpy
def Add_PolySphere():
#Add Cube to scene
bpy.ops.mesh.primitive_cube_add()
#Changes name of Cube to PolySphere adds the variable cube
cube = bpy.context.object
cube.name = "PolySphere"
#Positions Cube primitive to scene centre
bpy.context.active_object.location = [0, 0, 0]
#Adds Subsurf Modifier
bpy.ops.object.modifier_add(type='SUBSURF')
#Selects Subsurf Modifier for editing
subsurf = cube.modifiers['Subsurf']
#Changes Subsurf levels
subsurf.levels = 3
#Applys Subsurf Modifier
bpy.ops.object.modifier_apply(apply_as='DATA', modifier="Subsurf")
#Adds smooth shading
bpy.ops.object.shade_smooth()
#Change to Editmode
bpy.ops.object.editmode_toggle()
#Selects cube in Editmode
#bpy.ops.mesh.select_all(action='TOGGLE')
#Adds transform "To Sphere"
bpy.ops.transform.tosphere(value=1)
#Change to Objectmode
bpy.ops.object.editmode_toggle()
#Scales Object to 2.0 Units
bpy.ops.transform.resize(value=(1.15525, 1.15525, 1.15525), constraint_axis=(False, False, False), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1, snap=False, snap_target='CLOSEST', snap_point=(0, 0, 0), snap_align=False, snap_normal=(0, 0, 0), release_confirm=False)
#Applys location, rotation and scale data
bpy.ops.object.transform_apply(location=True, rotation=True, scale=True)
#makes PolySphere an operator
class AddPolySphere(bpy.types.Operator):
bl_idname = "mesh.primitive_polysphere_add"
bl_label = "Add PolySphere"
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
Add_PolySphere()
return {'FINISHED'}
|
gpl-3.0
|
[
3,
22906,
16427,
14629,
5113,
8068,
22906,
199,
3,
199,
3,
221,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
221,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
199,
3,
221,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
199,
3,
221,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
221,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
221,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
221,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
221,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
221,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
221,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
2752,
12,
199,
3,
221,
3277,
2020,
8026,
11236,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
11315,
13,
10067,
12,
8217,
14,
199,
3,
199,
3,
22906,
7729,
14629,
5113,
8068,
22906,
199,
2344,
199,
3345,
63,
815,
275,
469,
272,
298,
354,
582,
298,
1123,
16869,
22385,
401,
272,
298,
2502,
582,
298,
3325,
89,
577,
7194,
397,
334,
22420,
317,
460,
89,
4186,
9622,
272,
298,
1023,
582,
334,
16,
12,
17,
12,
22,
395,
272,
298,
66,
24912,
582,
334,
18,
12,
16202,
12,
378,
395,
272,
298,
1985,
582,
298,
2768,
19,
36,
690,
2654,
690,
603,
10613,
690,
16869,
22385,
401,
272,
298,
1802,
582,
298,
14995,
282,
16869,
22385,
334,
452,
2173,
9402,
9,
367,
308,
3119,
541,
316,
401,
272,
298,
3764,
582,
4873,
272,
298,
6797,
63,
633,
582,
298,
1014,
921,
6797,
14,
66,
24912,
14,
1308,
15,
1080,
14,
8624,
15,
10597,
26,
18,
14,
21,
15,
2713,
15,
3212,
267,
298,
25681,
15,
1123,
63,
12241,
15,
1123,
63,
12747,
22385,
401,
272,
298,
8877,
63,
633,
582,
4873,
272,
298,
3710,
582,
298,
1123,
603,
10613,
3570,
199,
2344,
258,
199,
199,
646,
20575,
199,
199,
318,
2654,
63,
12747,
22385,
837,
272,
327,
1123,
445,
3375,
370,
13856,
272,
20575,
14,
1483,
14,
6480,
14,
16161,
63,
11477,
63,
525,
342,
339,
327,
13907,
536,
402,
445,
3375,
370,
16869,
22385,
9584,
314,
1750,
15681,
272,
15681,
275,
20575,
14,
1100,
14,
785,
272,
15681,
14,
354,
275,
298,
12747,
22385,
2,
339,
327,
32650,
445,
3375,
18944,
370,
13856,
13345,
264,
272,
20575,
14,
1100,
14,
2682,
63,
785,
14,
1985,
275,
359,
16,
12,
378,
12,
378,
61,
339,
327,
14995,
4804,
21579,
12972,
3895,
272,
20575,
14,
1483,
14,
785,
14,
18156,
63,
525,
8,
466,
534,
6348,
51,
1230,
38,
358,
339,
327,
5446,
83,
4804,
21579,
12972,
3895,
367,
20401,
272,
1007,
21579,
275,
15681,
14,
17431,
459,
2610,
21579,
418,
339,
327,
13907,
4804,
21579,
11106,
272,
1007,
21579,
14,
11402,
275,
650,
257,
339,
327,
2640,
76,
588,
4804,
21579,
12972,
3895,
272,
20575,
14,
1483,
14,
785,
14,
18156,
63,
4998,
8,
4998,
63,
305,
534,
3998,
297,
17880,
628,
2610,
21579,
531,
339,
327,
14995,
19608,
1033,
5384,
272,
20575,
14,
1483,
14,
785,
14,
31170,
63,
19169,
342,
339,
327,
4001,
370,
16407,
632,
272,
20575,
14,
1483,
14,
785,
14,
3773,
632,
63,
13396,
342,
339,
327,
5446,
83,
15681,
315,
16407,
632,
272,
327,
66,
647,
14,
1483,
14,
6480,
14,
2416,
63,
452,
8,
1287,
534,
2566,
2916,
906,
358,
339,
327,
14995,
5793,
298,
1378,
8360,
1681,
2,
272,
20575,
14,
1483,
14,
4711,
14,
475,
14980,
8,
585,
29,
17,
9,
339,
327,
4001,
370,
6935,
632,
272,
20575,
14,
1483,
14,
785,
14,
3773,
632,
63,
13396,
342,
2286,
327,
9944,
83,
6935,
370,
499,
14,
16,
1910,
1405,
272,
20575,
14,
1483,
14,
4711,
14,
8709,
8,
585,
2687,
17,
14,
11520,
821,
12,
413,
14,
11520,
821,
12,
413,
14,
11520,
821,
395,
5828,
63,
3127,
2687,
797,
12,
756,
12,
756,
395,
5828,
63,
17001,
534,
13808,
297,
15216,
29,
797,
12,
24382,
279,
534,
16205,
297,
24382,
279,
63,
3773,
63,
70,
279,
320,
556,
534,
51,
2679,
22949,
297,
24382,
279,
63,
890,
29,
17,
12,
13639,
29,
797,
12,
13639,
63,
1375,
534,
10353,
51,
1719,
297,
13639,
63,
1403,
2687,
16,
12,
378,
12,
378,
395,
13639,
63,
5743,
29,
797,
12,
13639,
63,
3302,
2687,
16,
12,
378,
12,
378,
395,
4683,
63,
9548,
29,
797,
9,
2286,
327,
2640,
76,
588,
2909,
12,
13038,
436,
4666,
666,
272,
20575,
14,
1483,
14,
785,
14,
4711,
63,
4998,
8,
1985,
29,
549,
12,
13038,
29,
549,
12,
4666,
29,
549,
9,
199,
199,
3,
391,
9246,
16869,
22385,
376,
4182,
199,
533,
2654,
12747,
22385,
8,
66,
647,
14,
1313,
14,
7961,
304,
2286,
6826,
63,
344,
354,
275,
298,
6480,
14,
16161,
63,
15743,
80,
1681,
63,
525,
2,
272,
6826,
63,
1302,
275,
298,
1123,
16869,
22385,
2,
272,
6826,
63,
1419,
275,
791,
23986,
297,
283,
1734,
1649,
936,
339,
347,
5341,
8,
277,
12,
1067,
304,
267,
2654,
63,
12747,
22385,
342,
267,
372,
791,
17383,
20450,
936,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
22906,
16427,
14629,
5113,
8068,
22906,
199,
3,
199,
3,
221,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
221,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
199,
3,
221,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
199,
3,
221,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
221,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
221,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
221,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
221,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
221,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
221,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
2752,
12,
199,
3,
221,
3277,
2020,
8026,
11236,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
11315,
13,
10067,
12,
8217,
14,
199,
3,
199,
3,
22906,
7729,
14629,
5113,
8068,
22906,
199,
2344,
199,
3345,
63,
815,
275,
469,
272,
298,
354,
582,
298,
1123,
16869,
22385,
401,
272,
298,
2502,
582,
298,
3325,
89,
577,
7194,
397,
334,
22420,
317,
460,
89,
4186,
9622,
272,
298,
1023,
582,
334,
16,
12,
17,
12,
22,
395,
272,
298,
66,
24912,
582,
334,
18,
12,
16202,
12,
378,
395,
272,
298,
1985,
582,
298,
2768,
19,
36,
690,
2654,
690,
603,
10613,
690,
16869,
22385,
401,
272,
298,
1802,
582,
298,
14995,
282,
16869,
22385,
334,
452,
2173,
9402,
9,
367,
308,
3119,
541,
316,
401,
272,
298,
3764,
582,
4873,
272,
298,
6797,
63,
633,
582,
298,
1014,
921,
6797,
14,
66,
24912,
14,
1308,
15,
1080,
14,
8624,
15,
10597,
26,
18,
14,
21,
15,
2713,
15,
3212,
267,
298,
25681,
15,
1123,
63,
12241,
15,
1123,
63,
12747,
22385,
401,
272,
298,
8877,
63,
633,
582,
4873,
272,
298,
3710,
582,
298,
1123,
603,
10613,
3570,
199,
2344,
258,
199,
199,
646,
20575,
199,
199,
318,
2654,
63,
12747,
22385,
837,
272,
327,
1123,
445,
3375,
370,
13856,
272,
20575,
14,
1483,
14,
6480,
14,
16161,
63,
11477,
63,
525,
342,
339,
327,
13907,
536,
402,
445,
3375,
370,
16869,
22385,
9584,
314,
1750,
15681,
272,
15681,
275,
20575,
14,
1100,
14,
785,
272,
15681,
14,
354,
275,
298,
12747,
22385,
2,
339,
327,
32650,
445,
3375,
18944,
370,
13856,
13345,
264,
272,
20575,
14,
1100,
14,
2682,
63,
785,
14,
1985,
275,
359,
16,
12,
378,
12,
378,
61,
339,
327,
14995,
4804,
21579,
12972,
3895,
272,
20575,
14,
1483,
14,
785,
14,
18156,
63,
525,
8,
466,
534,
6348,
51,
1230,
38,
358,
339,
327,
5446,
83,
4804,
21579,
12972,
3895,
367,
20401,
272,
1007,
21579,
275,
15681,
14,
17431,
459,
2610,
21579,
418,
339,
327,
13907,
4804,
21579,
11106,
272,
1007,
21579,
14,
11402,
275,
650,
257,
339,
327,
2640,
76,
588,
4804,
21579,
12972,
3895,
272,
20575,
14,
1483,
14,
785,
14,
18156,
63,
4998,
8,
4998,
63,
305,
534,
3998,
297,
17880,
628,
2610,
21579,
531,
339,
327,
14995,
19608,
1033,
5384,
272,
20575,
14,
1483,
14,
785,
14,
31170,
63,
19169,
342,
339,
327,
4001,
370,
16407,
632,
272,
20575,
14,
1483,
14,
785,
14,
3773,
632,
63,
13396,
342,
339,
327,
5446,
83,
15681,
315,
16407,
632,
272,
327,
66,
647,
14,
1483,
14,
6480,
14,
2416,
63,
452,
8,
1287,
534,
2566,
2916,
906,
358,
339,
327,
14995,
5793,
298,
1378,
8360,
1681,
2,
272,
20575,
14,
1483,
14,
4711,
14,
475,
14980,
8,
585,
29,
17,
9,
339,
327,
4001,
370,
6935,
632,
272,
20575,
14,
1483,
14,
785,
14,
3773,
632,
63,
13396,
342,
2286,
327,
9944,
83,
6935,
370,
499,
14,
16,
1910,
1405,
272,
20575,
14,
1483,
14,
4711,
14,
8709,
8,
585,
2687,
17,
14,
11520,
821,
12,
413,
14,
11520,
821,
12,
413,
14,
11520,
821,
395,
5828,
63,
3127,
2687,
797,
12,
756,
12,
756,
395,
5828,
63,
17001,
534,
13808,
297,
15216,
29,
797,
12,
24382,
279,
534,
16205,
297,
24382,
279,
63,
3773,
63,
70,
279,
320,
556,
534,
51,
2679,
22949,
297,
24382,
279,
63,
890,
29,
17,
12,
13639,
29,
797,
12,
13639,
63,
1375,
534,
10353,
51,
1719,
297,
13639,
63,
1403,
2687,
16,
12,
378,
12,
378,
395,
13639,
63,
5743,
29,
797,
12,
13639,
63,
3302,
2687,
16,
12,
378,
12,
378,
395,
4683,
63,
9548,
29,
797,
9,
2286,
327,
2640,
76,
588,
2909,
12,
13038,
436,
4666,
666,
272,
20575,
14,
1483,
14,
785,
14,
4711,
63,
4998,
8,
1985,
29,
549,
12,
13038,
29,
549,
12,
4666,
29,
549,
9,
199,
199,
3,
391,
9246,
16869,
22385,
376,
4182,
199,
533,
2654,
12747,
22385,
8,
66,
647,
14,
1313,
14,
7961,
304,
2286,
6826,
63,
344,
354,
275,
298,
6480,
14,
16161,
63,
15743,
80,
1681,
63,
525,
2,
272,
6826,
63,
1302,
275,
298,
1123,
16869,
22385,
2,
272,
6826,
63,
1419,
275,
791,
23986,
297,
283,
1734,
1649,
936,
339,
347,
5341,
8,
277,
12,
1067,
304,
267,
2654,
63,
12747,
22385,
342,
267,
372,
791,
17383,
20450,
936,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
OptiPop/external_chromium_org
|
tools/deep_memory_profiler/accumulate.py
|
100
|
9536
|
#!/usr/bin/env python
# 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.
# A script to accumulate values from the 'dmprof cat' command into CSV or else.
#
# Usage:
# ./accumulate.py -f <format> -t <template-name> < input.json > output
#
# <format> is one of "csv", "json", and "tree". If "csv" or "json" is given,
# accumulate.py dumps a similar file to "dmprof csv|json". If "tree" is given,
# accumulate.py dumps a human-readable breakdown tree.
#
# <template-name> is a label in templates.json.
import datetime
import json
import logging
import optparse
import sys
from lib.ordered_dict import OrderedDict
LOGGER = logging.getLogger('dmprof-accumulate')
def visit_in_template(template, snapshot, depth):
"""Visits all categories via a given template.
This function is not used. It's a sample function to traverse a template.
"""
world = template[0]
breakdown = template[1]
rules = template[2]
for rule, _ in snapshot[world]['breakdown'][breakdown].iteritems():
print (' ' * depth) + rule
if rule in rules:
visit_in_template(rules[rule], snapshot, depth + 1)
def accumulate(template, snapshot, units_dict, target_units):
"""Accumulates units in a JSON |snapshot| with applying a given |template|.
Args:
template: A template tree included in a dmprof cat JSON file.
snapshot: A snapshot in a dmprof cat JSON file.
units_dict: A dict of units in worlds.
target_units: A list of unit ids which are a target of this accumulation.
"""
world = template[0]
breakdown = template[1]
rules = template[2]
remainder_units = target_units.copy()
category_tree = OrderedDict()
total = 0
for rule, match in snapshot[world]['breakdown'][breakdown].iteritems():
if 'hidden' in match and match['hidden']:
continue
matched_units = set(match['units']).intersection(target_units)
subtotal = 0
for unit_id in matched_units:
subtotal += units_dict[world][unit_id]
total += subtotal
remainder_units = remainder_units.difference(matched_units)
if rule not in rules:
# A category matched with |rule| is a leaf of the breakdown tree.
# It is NOT broken down more.
category_tree[rule] = subtotal
continue
# A category matched with |rule| is broken down more.
subtemplate = rules[rule]
subworld = subtemplate[0]
subbreakdown = subtemplate[1]
if subworld == world:
# Break down in the same world: consider units.
category_tree[rule], accounted_total, subremainder_units = accumulate(
subtemplate, snapshot, units_dict, matched_units)
subremainder_total = 0
if subremainder_units:
for unit_id in subremainder_units:
subremainder_total += units_dict[world][unit_id]
category_tree[rule][None] = subremainder_total
if subtotal != accounted_total + subremainder_total:
print >> sys.stderr, (
'WARNING: Sum of %s:%s is different from %s by %d bytes.' % (
subworld, subbreakdown, rule,
subtotal - (accounted_total + subremainder_total)))
else:
# Break down in a different world: consider only the total size.
category_tree[rule], accounted_total, _ = accumulate(
subtemplate, snapshot, units_dict, set(units_dict[subworld].keys()))
if subtotal >= accounted_total:
category_tree[rule][None] = subtotal - accounted_total
else:
print >> sys.stderr, (
'WARNING: Sum of %s:%s is larger than %s by %d bytes.' % (
subworld, subbreakdown, rule, accounted_total - subtotal))
print >> sys.stderr, (
'WARNING: Assuming remainder of %s is 0.' % rule)
category_tree[rule][None] = 0
return category_tree, total, remainder_units
def flatten(category_tree, header=''):
"""Flattens a category tree into a flat list."""
result = []
for rule, sub in category_tree.iteritems():
if not rule:
rule = 'remaining'
if header:
flattened_rule = header + '>' + rule
else:
flattened_rule = rule
if isinstance(sub, dict) or isinstance(sub, OrderedDict):
result.extend(flatten(sub, flattened_rule))
else:
result.append((flattened_rule, sub))
return result
def print_category_tree(category_tree, output, depth=0):
"""Prints a category tree in a human-readable format."""
for label in category_tree:
print >> output, (' ' * depth),
if (isinstance(category_tree[label], dict) or
isinstance(category_tree[label], OrderedDict)):
print >> output, '%s:' % label
print_category_tree(category_tree[label], output, depth + 1)
else:
print >> output, '%s: %d' % (label, category_tree[label])
def flatten_all_category_trees(category_trees):
flattened_labels = set()
flattened_table = []
for category_tree in category_trees:
flattened = OrderedDict()
for label, subtotal in flatten(category_tree):
flattened_labels.add(label)
flattened[label] = subtotal
flattened_table.append(flattened)
return flattened_labels, flattened_table
def output_csv(output, category_trees, data, first_time, output_exponent):
flattened_labels, flattened_table = flatten_all_category_trees(category_trees)
sorted_flattened_labels = sorted(flattened_labels)
print >> output, ','.join(['second'] + sorted_flattened_labels)
for index, row in enumerate(flattened_table):
values = [str(data['snapshots'][index]['time'] - first_time)]
for label in sorted_flattened_labels:
if label in row:
divisor = 1
if output_exponent.upper() == 'K':
divisor = 1024.0
elif output_exponent.upper() == 'M':
divisor = 1024.0 * 1024.0
values.append(str(row[label] / divisor))
else:
values.append('0')
print >> output, ','.join(values)
def output_json(output, category_trees, data, first_time, template_label):
flattened_labels, flattened_table = flatten_all_category_trees(category_trees)
json_snapshots = []
for index, row in enumerate(flattened_table):
row_with_meta = row.copy()
row_with_meta['second'] = data['snapshots'][index]['time'] - first_time
row_with_meta['dump_time'] = datetime.datetime.fromtimestamp(
data['snapshots'][index]['time']).strftime('%Y-%m-%d %H:%M:%S')
json_snapshots.append(row_with_meta)
json_root = {
'version': 'JSON_DEEP_2',
'policies': {
template_label: {
'legends': sorted(flattened_labels),
'snapshots': json_snapshots
}
}
}
json.dump(json_root, output, indent=2, sort_keys=True)
def output_tree(output, category_trees):
for index, category_tree in enumerate(category_trees):
print >> output, '< Snapshot #%d >' % index
print_category_tree(category_tree, output, 1)
print >> output, ''
def do_main(cat_input, output, template_label, output_format, output_exponent):
"""Does the main work: accumulate for every snapshot and print a result."""
if output_format not in ['csv', 'json', 'tree']:
raise NotImplementedError('The output format \"%s\" is not implemented.' %
output_format)
if output_exponent.upper() not in ['B', 'K', 'M']:
raise NotImplementedError('The exponent \"%s\" is not implemented.' %
output_exponent)
data = json.loads(cat_input.read(), object_pairs_hook=OrderedDict)
templates = data['templates']
if not template_label:
template_label = data['default_template']
if template_label not in templates:
LOGGER.error('A template \'%s\' is not found.' % template_label)
return
template = templates[template_label]
category_trees = []
first_time = None
for snapshot in data['snapshots']:
if not first_time:
first_time = snapshot['time']
units = {}
for world_name in snapshot['worlds']:
world_units = {}
for unit_id, sizes in snapshot['worlds'][world_name]['units'].iteritems():
world_units[int(unit_id)] = sizes[0]
units[world_name] = world_units
category_tree, _, _ = accumulate(
template, snapshot['worlds'], units, set(units[template[0]].keys()))
category_trees.append(category_tree)
if output_format == 'csv':
output_csv(output, category_trees, data, first_time, output_exponent)
elif output_format == 'json':
output_json(output, category_trees, data, first_time, template_label)
elif output_format == 'tree':
output_tree(output, category_trees)
def main():
LOGGER.setLevel(logging.DEBUG)
handler = logging.StreamHandler()
handler.setLevel(logging.INFO)
formatter = logging.Formatter('%(message)s')
handler.setFormatter(formatter)
LOGGER.addHandler(handler)
parser = optparse.OptionParser()
parser.add_option('-t', '--template', dest='template',
metavar='TEMPLATE',
help='Apply TEMPLATE to list up.')
parser.add_option('-f', '--format', dest='format', default='csv',
help='Specify the output format: csv, json or tree.')
parser.add_option('-e', '--exponent', dest='exponent', default='M',
help='Specify B (bytes), K (kilobytes) or M (megabytes).')
options, _ = parser.parse_args(sys.argv)
do_main(sys.stdin, sys.stdout,
options.template, options.format, options.exponent)
if __name__ == '__main__':
sys.exit(main())
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
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,
3,
437,
2884,
370,
30535,
1338,
687,
314,
283,
10930,
293,
70,
6230,
7,
1414,
1901,
14689,
503,
587,
14,
199,
3,
199,
3,
11028,
26,
199,
3,
257,
16605,
13223,
5434,
14,
647,
446,
70,
665,
908,
30,
446,
84,
665,
1160,
13,
354,
30,
665,
1324,
14,
1001,
690,
1072,
199,
3,
199,
3,
665,
908,
30,
365,
1373,
402,
298,
4737,
401,
298,
1001,
401,
436,
298,
2350,
1674,
982,
298,
4737,
2,
503,
298,
1001,
2,
365,
1627,
12,
199,
3,
30535,
14,
647,
16864,
282,
8545,
570,
370,
298,
10930,
293,
70,
7392,
92,
1001,
1674,
982,
298,
2350,
2,
365,
1627,
12,
199,
3,
30535,
14,
647,
16864,
282,
11779,
13,
11875,
2059,
2110,
3123,
14,
199,
3,
199,
3,
665,
1160,
13,
354,
30,
365,
282,
1768,
315,
7009,
14,
1001,
14,
199,
199,
646,
2197,
199,
646,
2022,
199,
646,
2050,
199,
646,
8691,
199,
646,
984,
199,
199,
504,
1973,
14,
8235,
63,
807,
492,
8773,
421,
199,
10186,
275,
2050,
14,
5572,
360,
10930,
293,
70,
13,
13223,
5434,
358,
421,
199,
318,
5684,
63,
262,
63,
1160,
8,
1160,
12,
5740,
12,
5818,
304,
523,
408,
2201,
30066,
1006,
9695,
4799,
282,
1627,
1978,
14,
819,
961,
805,
365,
440,
1202,
14,
2779,
1159,
282,
2690,
805,
370,
24749,
282,
1978,
14,
523,
408,
523,
6701,
275,
1978,
59,
16,
61,
523,
2059,
2110,
275,
1978,
59,
17,
61,
523,
4713,
275,
1978,
59,
18,
61,
819,
367,
2332,
12,
485,
315,
5740,
59,
7617,
2733,
4785,
2110,
3488,
4785,
2110,
1055,
4611,
837,
272,
870,
661,
221,
283,
627,
5818,
9,
435,
2332,
272,
340,
2332,
315,
4713,
26,
489,
5684,
63,
262,
63,
1160,
8,
4423,
59,
2200,
467,
5740,
12,
5818,
435,
413,
9,
421,
199,
318,
30535,
8,
1160,
12,
5740,
12,
6204,
63,
807,
12,
1347,
63,
5260,
304,
523,
408,
23384,
15409,
6204,
315,
282,
4840,
1204,
4753,
92,
543,
18876,
282,
1627,
1204,
1160,
18257,
819,
3033,
26,
489,
1978,
26,
437,
1978,
3123,
5120,
315,
282,
14605,
293,
70,
6230,
4840,
570,
14,
489,
5740,
26,
437,
5740,
315,
282,
14605,
293,
70,
6230,
4840,
570,
14,
489,
6204,
63,
807,
26,
437,
1211,
402,
6204,
315,
1319,
76,
795,
14,
489,
1347,
63,
5260,
26,
437,
769,
402,
4137,
2762,
1314,
787,
282,
1347,
402,
642,
11162,
5332,
14,
523,
408,
523,
6701,
275,
1978,
59,
16,
61,
523,
2059,
2110,
275,
1978,
59,
17,
61,
523,
4713,
275,
1978,
59,
18,
61,
819,
15748,
63,
5260,
275,
1347,
63,
5260,
14,
1574,
342,
523,
4637,
63,
2350,
275,
8773,
342,
523,
3141,
275,
378,
819,
367,
2332,
12,
1336,
315,
5740,
59,
7617,
2733,
4785,
2110,
3488,
4785,
2110,
1055,
4611,
837,
272,
340,
283,
5642,
7,
315,
1336,
436,
1336,
459,
5642,
2565,
489,
1980,
272,
7838,
63,
5260,
275,
663,
8,
1431,
459,
5260,
13227,
12569,
8,
1375,
63,
5260,
9,
272,
1007,
2923,
275,
378,
272,
367,
4137,
63,
344,
315,
7838,
63,
5260,
26,
489,
1007,
2923,
847,
6204,
63,
807,
59,
7617,
1527,
3248,
63,
344,
61,
272,
3141,
847,
1007,
2923,
272,
15748,
63,
5260,
275,
15748,
63,
5260,
14,
9196,
8,
10151,
63,
5260,
9,
272,
340,
2332,
440,
315,
4713,
26,
489,
327,
437,
4637,
7838,
543,
1204,
2200,
92,
365,
282,
11747,
402,
314,
2059,
2110,
3123,
14,
489,
327,
2779,
365,
2845,
10529,
3224,
1655,
14,
489,
4637,
63,
2350,
59,
2200,
61,
275,
1007,
2923,
489,
1980,
339,
327,
437,
4637,
7838,
543,
1204,
2200,
92,
365,
10529,
3224,
1655,
14,
272,
1007,
1160,
275,
4713,
59,
2200,
61,
272,
1007,
7617,
275,
1007,
1160,
59,
16,
61,
272,
1007,
4785,
2110,
275,
1007,
1160,
59,
17,
61,
339,
340,
1007,
7617,
508,
6701,
26,
489,
327,
22535,
3224,
315,
314,
2011,
6701,
26,
11201,
6204,
14,
489,
4637,
63,
2350,
59,
2200,
467,
1066,
3094,
471,
63,
2923,
12,
1007,
23850,
63,
5260,
275,
30535,
8,
881,
1007,
1160,
12,
5740,
12,
6204,
63,
807,
12,
7838,
63,
5260,
9,
489,
1007,
23850,
63,
2923,
275,
378,
489,
340,
1007,
23850,
63,
5260,
26,
267,
367,
4137,
63,
344,
315,
1007,
23850,
63,
5260,
26,
881,
1007,
23850,
63,
2923,
847,
6204,
63,
807,
59,
7617,
1527,
3248,
63,
344,
61,
267,
4637,
63,
2350,
59,
2200,
1527,
403,
61,
275,
1007,
23850,
63,
2923,
489,
340,
1007,
2923,
1137,
1066,
3094,
471,
63,
2923,
435,
1007,
23850,
63,
2923,
26,
267,
870,
4331,
984,
14,
3083,
12,
334,
288,
283,
9171,
26,
12094,
402,
450,
83,
2689,
83,
365,
3365,
687,
450,
83,
701,
450,
68,
2783,
3530,
450,
334,
355,
1007,
7617,
12,
1007,
4785,
2110,
12,
2332,
12,
355,
1007,
2923,
446,
334,
645,
3094,
471,
63,
2923,
435,
1007,
23850,
63,
2923,
1724,
272,
587,
26,
489,
327,
22535,
3224,
315,
282,
3365,
6701,
26,
11201,
1454,
314,
3141,
1568,
14,
489,
4637,
63,
2350,
59,
2200,
467,
1066,
3094,
471,
63,
2923,
12,
485,
275,
30535,
8,
881,
1007,
1160,
12,
5740,
12,
6204,
63,
807,
12,
663,
8,
5260,
63,
807,
59,
954,
7617,
1055,
1612,
4059,
489,
340,
1007,
2923,
2356,
1066,
3094,
471,
63,
2923,
26,
267,
4637,
63,
2350,
59,
2200,
1527,
403,
61,
275,
1007,
2923,
446,
1066,
3094,
471,
63,
2923,
489,
587,
26,
267,
870,
4331,
984,
14,
3083,
12,
334,
288,
283,
9171,
26,
12094,
402,
450,
83,
2689,
83,
365,
12142,
2419,
450,
83,
701,
450,
68,
2783,
3530,
450,
334,
355,
1007,
7617,
12,
1007,
4785,
2110,
12,
2332,
12,
1066,
3094,
471,
63,
2923,
446,
1007,
2923,
430,
267,
870,
4331,
984,
14,
3083,
12,
334,
288,
283,
9171,
26,
257,
10829,
12848,
15748,
402,
450,
83,
365,
378,
3530,
450,
2332,
9,
267,
4637,
63,
2350,
59
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
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,
3,
437,
2884,
370,
30535,
1338,
687,
314,
283,
10930,
293,
70,
6230,
7,
1414,
1901,
14689,
503,
587,
14,
199,
3,
199,
3,
11028,
26,
199,
3,
257,
16605,
13223,
5434,
14,
647,
446,
70,
665,
908,
30,
446,
84,
665,
1160,
13,
354,
30,
665,
1324,
14,
1001,
690,
1072,
199,
3,
199,
3,
665,
908,
30,
365,
1373,
402,
298,
4737,
401,
298,
1001,
401,
436,
298,
2350,
1674,
982,
298,
4737,
2,
503,
298,
1001,
2,
365,
1627,
12,
199,
3,
30535,
14,
647,
16864,
282,
8545,
570,
370,
298,
10930,
293,
70,
7392,
92,
1001,
1674,
982,
298,
2350,
2,
365,
1627,
12,
199,
3,
30535,
14,
647,
16864,
282,
11779,
13,
11875,
2059,
2110,
3123,
14,
199,
3,
199,
3,
665,
1160,
13,
354,
30,
365,
282,
1768,
315,
7009,
14,
1001,
14,
199,
199,
646,
2197,
199,
646,
2022,
199,
646,
2050,
199,
646,
8691,
199,
646,
984,
199,
199,
504,
1973,
14,
8235,
63,
807,
492,
8773,
421,
199,
10186,
275,
2050,
14,
5572,
360,
10930,
293,
70,
13,
13223,
5434,
358,
421,
199,
318,
5684,
63,
262,
63,
1160,
8,
1160,
12,
5740,
12,
5818,
304,
523,
408,
2201,
30066,
1006,
9695,
4799,
282,
1627,
1978,
14,
819,
961,
805,
365,
440,
1202,
14,
2779,
1159,
282,
2690,
805,
370,
24749,
282,
1978,
14,
523,
408,
523,
6701,
275,
1978,
59,
16,
61,
523,
2059,
2110,
275,
1978,
59,
17,
61,
523,
4713,
275,
1978,
59,
18,
61,
819,
367,
2332,
12,
485,
315,
5740,
59,
7617,
2733,
4785,
2110,
3488,
4785,
2110,
1055,
4611,
837,
272,
870,
661,
221,
283,
627,
5818,
9,
435,
2332,
272,
340,
2332,
315,
4713,
26,
489,
5684,
63,
262,
63,
1160,
8,
4423,
59,
2200,
467,
5740,
12,
5818,
435,
413,
9,
421,
199,
318,
30535,
8,
1160,
12,
5740,
12,
6204,
63,
807,
12,
1347,
63,
5260,
304,
523,
408,
23384,
15409,
6204,
315,
282,
4840,
1204,
4753,
92,
543,
18876,
282,
1627,
1204,
1160,
18257,
819,
3033,
26,
489,
1978,
26,
437,
1978,
3123,
5120,
315,
282,
14605,
293,
70,
6230,
4840,
570,
14,
489,
5740,
26,
437,
5740,
315,
282,
14605,
293,
70,
6230,
4840,
570,
14,
489,
6204,
63,
807,
26,
437,
1211,
402,
6204,
315,
1319,
76,
795,
14,
489,
1347,
63,
5260,
26,
437,
769,
402,
4137,
2762,
1314,
787,
282,
1347,
402,
642,
11162,
5332,
14,
523,
408,
523,
6701,
275,
1978,
59,
16,
61,
523,
2059,
2110,
275,
1978,
59,
17,
61,
523,
4713,
275,
1978,
59,
18,
61,
819,
15748,
63,
5260,
275,
1347,
63,
5260,
14,
1574,
342,
523,
4637,
63,
2350,
275,
8773,
342,
523,
3141,
275,
378,
819,
367,
2332,
12,
1336,
315,
5740,
59,
7617,
2733,
4785,
2110,
3488,
4785,
2110,
1055,
4611,
837,
272,
340,
283,
5642,
7,
315,
1336,
436,
1336,
459,
5642,
2565,
489,
1980,
272,
7838,
63,
5260,
275,
663,
8,
1431,
459,
5260,
13227,
12569,
8,
1375,
63,
5260,
9,
272,
1007,
2923,
275,
378,
272,
367,
4137,
63,
344,
315,
7838,
63,
5260,
26,
489,
1007,
2923,
847,
6204,
63,
807,
59,
7617,
1527,
3248,
63,
344,
61,
272,
3141,
847,
1007,
2923,
272,
15748,
63,
5260,
275,
15748,
63,
5260,
14,
9196,
8,
10151,
63,
5260,
9,
272,
340,
2332,
440,
315,
4713,
26,
489,
327,
437,
4637,
7838,
543,
1204,
2200,
92,
365,
282,
11747,
402,
314,
2059,
2110,
3123,
14,
489,
327,
2779,
365,
2845,
10529,
3224,
1655,
14,
489,
4637,
63,
2350,
59,
2200,
61,
275,
1007,
2923,
489,
1980,
339,
327,
437,
4637,
7838,
543,
1204,
2200,
92,
365,
10529,
3224,
1655,
14,
272,
1007,
1160,
275,
4713,
59,
2200,
61,
272,
1007,
7617,
275,
1007,
1160,
59,
16,
61,
272,
1007,
4785,
2110,
275,
1007,
1160,
59,
17,
61,
339,
340,
1007,
7617,
508,
6701,
26,
489,
327,
22535,
3224,
315,
314,
2011,
6701,
26,
11201,
6204,
14,
489,
4637,
63,
2350,
59,
2200,
467,
1066,
3094,
471,
63,
2923,
12,
1007,
23850,
63,
5260,
275,
30535,
8,
881,
1007,
1160,
12,
5740,
12,
6204,
63,
807,
12,
7838,
63,
5260,
9,
489,
1007,
23850,
63,
2923,
275,
378,
489,
340,
1007,
23850,
63,
5260,
26,
267,
367,
4137,
63,
344,
315,
1007,
23850,
63,
5260,
26,
881,
1007,
23850,
63,
2923,
847,
6204,
63,
807,
59,
7617,
1527,
3248,
63,
344,
61,
267,
4637,
63,
2350,
59,
2200,
1527,
403,
61,
275,
1007,
23850,
63,
2923,
489,
340,
1007,
2923,
1137,
1066,
3094,
471,
63,
2923,
435,
1007,
23850,
63,
2923,
26,
267,
870,
4331,
984,
14,
3083,
12,
334,
288,
283,
9171,
26,
12094,
402,
450,
83,
2689,
83,
365,
3365,
687,
450,
83,
701,
450,
68,
2783,
3530,
450,
334,
355,
1007,
7617,
12,
1007,
4785,
2110,
12,
2332,
12,
355,
1007,
2923,
446,
334,
645,
3094,
471,
63,
2923,
435,
1007,
23850,
63,
2923,
1724,
272,
587,
26,
489,
327,
22535,
3224,
315,
282,
3365,
6701,
26,
11201,
1454,
314,
3141,
1568,
14,
489,
4637,
63,
2350,
59,
2200,
467,
1066,
3094,
471,
63,
2923,
12,
485,
275,
30535,
8,
881,
1007,
1160,
12,
5740,
12,
6204,
63,
807,
12,
663,
8,
5260,
63,
807,
59,
954,
7617,
1055,
1612,
4059,
489,
340,
1007,
2923,
2356,
1066,
3094,
471,
63,
2923,
26,
267,
4637,
63,
2350,
59,
2200,
1527,
403,
61,
275,
1007,
2923,
446,
1066,
3094,
471,
63,
2923,
489,
587,
26,
267,
870,
4331,
984,
14,
3083,
12,
334,
288,
283,
9171,
26,
12094,
402,
450,
83,
2689,
83,
365,
12142,
2419,
450,
83,
701,
450,
68,
2783,
3530,
450,
334,
355,
1007,
7617,
12,
1007,
4785,
2110,
12,
2332,
12,
1066,
3094,
471,
63,
2923,
446,
1007,
2923,
430,
267,
870,
4331,
984,
14,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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
] |
jumpstarter-io/glance
|
glance/api/v2/model/metadef_tag.py
|
20
|
1139
|
# Copyright (c) 2014 Hewlett-Packard Development Company, L.P.
#
# 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 wsme
from wsme import types
from glance.common import wsme_utils
class MetadefTag(types.Base, wsme_utils.WSMEModelTransformer):
name = wsme.wsattr(types.text, mandatory=True)
# Not using datetime since time format has to be
# in oslo_utils.timeutils.isotime() format
created_at = wsme.wsattr(types.text, mandatory=False)
updated_at = wsme.wsattr(types.text, mandatory=False)
class MetadefTags(types.Base, wsme_utils.WSMEModelTransformer):
tags = wsme.wsattr([MetadefTag], mandatory=False)
|
apache-2.0
|
[
3,
1898,
334,
67,
9,
6927,
27849,
13,
29471,
15290,
15878,
12,
491,
14,
48,
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,
199,
3,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
646,
10900,
278,
199,
504,
10900,
278,
492,
2943,
199,
199,
504,
21785,
14,
2330,
492,
10900,
278,
63,
1208,
421,
199,
533,
6288,
318,
1931,
8,
1313,
14,
1563,
12,
10900,
278,
63,
1208,
14,
5035,
3635,
1685,
19761,
304,
339,
536,
275,
10900,
278,
14,
3569,
962,
8,
1313,
14,
505,
12,
15230,
29,
549,
9,
339,
327,
2832,
1808,
2197,
3967,
900,
1475,
965,
370,
506,
272,
327,
315,
11258,
63,
1208,
14,
521,
1208,
14,
4595,
521,
342,
1475,
272,
2737,
63,
292,
275,
10900,
278,
14,
3569,
962,
8,
1313,
14,
505,
12,
15230,
29,
797,
9,
272,
4588,
63,
292,
275,
10900,
278,
14,
3569,
962,
8,
1313,
14,
505,
12,
15230,
29,
797,
9,
421,
199,
533,
6288,
318,
9440,
8,
1313,
14,
1563,
12,
10900,
278,
63,
1208,
14,
5035,
3635,
1685,
19761,
304,
339,
3762,
275,
10900,
278,
14,
3569,
962,
779,
3396,
318,
1931,
467,
15230,
29,
797,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
334,
67,
9,
6927,
27849,
13,
29471,
15290,
15878,
12,
491,
14,
48,
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,
199,
3,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
646,
10900,
278,
199,
504,
10900,
278,
492,
2943,
199,
199,
504,
21785,
14,
2330,
492,
10900,
278,
63,
1208,
421,
199,
533,
6288,
318,
1931,
8,
1313,
14,
1563,
12,
10900,
278,
63,
1208,
14,
5035,
3635,
1685,
19761,
304,
339,
536,
275,
10900,
278,
14,
3569,
962,
8,
1313,
14,
505,
12,
15230,
29,
549,
9,
339,
327,
2832,
1808,
2197,
3967,
900,
1475,
965,
370,
506,
272,
327,
315,
11258,
63,
1208,
14,
521,
1208,
14,
4595,
521,
342,
1475,
272,
2737,
63,
292,
275,
10900,
278,
14,
3569,
962,
8,
1313,
14,
505,
12,
15230,
29,
797,
9,
272,
4588,
63,
292,
275,
10900,
278,
14,
3569,
962,
8,
1313,
14,
505,
12,
15230,
29,
797,
9,
421,
199,
533,
6288,
318,
9440,
8,
1313,
14,
1563,
12,
10900,
278,
63,
1208,
14,
5035,
3635,
1685,
19761,
304,
339,
3762,
275,
10900,
278,
14,
3569,
962,
779,
3396,
318,
1931,
467,
15230,
29,
797,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ocadotechnology/boto
|
boto/s3/cors.py
|
240
|
8941
|
# Copyright (c) 2012 Mitch Garnaat http://garnaat.org/
# Copyright (c) 2012 Amazon.com, Inc. or its affiliates. All Rights Reserved
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish, dis-
# tribute, sublicense, and/or sell copies of the Software, and to permit
# persons to whom the Software is furnished to do so, subject to the fol-
# lowing conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
#
class CORSRule(object):
"""
CORS rule for a bucket.
:ivar id: A unique identifier for the rule. The ID value can be
up to 255 characters long. The IDs help you find a rule in
the configuration.
:ivar allowed_methods: An HTTP method that you want to allow the
origin to execute. Each CORSRule must identify at least one
origin and one method. Valid values are:
GET|PUT|HEAD|POST|DELETE
:ivar allowed_origin: An origin that you want to allow cross-domain
requests from. This can contain at most one * wild character.
Each CORSRule must identify at least one origin and one method.
The origin value can include at most one '*' wild character.
For example, "http://*.example.com". You can also specify
only * as the origin value allowing all origins cross-domain access.
:ivar allowed_header: Specifies which headers are allowed in a
pre-flight OPTIONS request via the
Access-Control-Request-Headers header. Each header name
specified in the Access-Control-Request-Headers header must
have a corresponding entry in the rule. Amazon S3 will send
only the allowed headers in a response that were requested.
This can contain at most one * wild character.
:ivar max_age_seconds: The time in seconds that your browser is to
cache the preflight response for the specified resource.
:ivar expose_header: One or more headers in the response that you
want customers to be able to access from their applications
(for example, from a JavaScript XMLHttpRequest object). You
add one ExposeHeader element in the rule for each header.
"""
def __init__(self, allowed_method=None, allowed_origin=None,
id=None, allowed_header=None, max_age_seconds=None,
expose_header=None):
if allowed_method is None:
allowed_method = []
self.allowed_method = allowed_method
if allowed_origin is None:
allowed_origin = []
self.allowed_origin = allowed_origin
self.id = id
if allowed_header is None:
allowed_header = []
self.allowed_header = allowed_header
self.max_age_seconds = max_age_seconds
if expose_header is None:
expose_header = []
self.expose_header = expose_header
def __repr__(self):
return '<Rule: %s>' % self.id
def startElement(self, name, attrs, connection):
return None
def endElement(self, name, value, connection):
if name == 'ID':
self.id = value
elif name == 'AllowedMethod':
self.allowed_method.append(value)
elif name == 'AllowedOrigin':
self.allowed_origin.append(value)
elif name == 'AllowedHeader':
self.allowed_header.append(value)
elif name == 'MaxAgeSeconds':
self.max_age_seconds = int(value)
elif name == 'ExposeHeader':
self.expose_header.append(value)
else:
setattr(self, name, value)
def to_xml(self):
s = '<CORSRule>'
for allowed_method in self.allowed_method:
s += '<AllowedMethod>%s</AllowedMethod>' % allowed_method
for allowed_origin in self.allowed_origin:
s += '<AllowedOrigin>%s</AllowedOrigin>' % allowed_origin
for allowed_header in self.allowed_header:
s += '<AllowedHeader>%s</AllowedHeader>' % allowed_header
for expose_header in self.expose_header:
s += '<ExposeHeader>%s</ExposeHeader>' % expose_header
if self.max_age_seconds:
s += '<MaxAgeSeconds>%d</MaxAgeSeconds>' % self.max_age_seconds
if self.id:
s += '<ID>%s</ID>' % self.id
s += '</CORSRule>'
return s
class CORSConfiguration(list):
"""
A container for the rules associated with a CORS configuration.
"""
def startElement(self, name, attrs, connection):
if name == 'CORSRule':
rule = CORSRule()
self.append(rule)
return rule
return None
def endElement(self, name, value, connection):
setattr(self, name, value)
def to_xml(self):
"""
Returns a string containing the XML version of the Lifecycle
configuration as defined by S3.
"""
s = '<CORSConfiguration>'
for rule in self:
s += rule.to_xml()
s += '</CORSConfiguration>'
return s
def add_rule(self, allowed_method, allowed_origin,
id=None, allowed_header=None, max_age_seconds=None,
expose_header=None):
"""
Add a rule to this CORS configuration. This only adds
the rule to the local copy. To install the new rule(s) on
the bucket, you need to pass this CORS config object
to the set_cors method of the Bucket object.
:type allowed_methods: list of str
:param allowed_methods: An HTTP method that you want to allow the
origin to execute. Each CORSRule must identify at least one
origin and one method. Valid values are:
GET|PUT|HEAD|POST|DELETE
:type allowed_origin: list of str
:param allowed_origin: An origin that you want to allow cross-domain
requests from. This can contain at most one * wild character.
Each CORSRule must identify at least one origin and one method.
The origin value can include at most one '*' wild character.
For example, "http://*.example.com". You can also specify
only * as the origin value allowing all origins
cross-domain access.
:type id: str
:param id: A unique identifier for the rule. The ID value can be
up to 255 characters long. The IDs help you find a rule in
the configuration.
:type allowed_header: list of str
:param allowed_header: Specifies which headers are allowed in a
pre-flight OPTIONS request via the
Access-Control-Request-Headers header. Each header name
specified in the Access-Control-Request-Headers header must
have a corresponding entry in the rule. Amazon S3 will send
only the allowed headers in a response that were requested.
This can contain at most one * wild character.
:type max_age_seconds: int
:param max_age_seconds: The time in seconds that your browser is to
cache the preflight response for the specified resource.
:type expose_header: list of str
:param expose_header: One or more headers in the response that you
want customers to be able to access from their applications
(for example, from a JavaScript XMLHttpRequest object). You
add one ExposeHeader element in the rule for each header.
"""
if not isinstance(allowed_method, (list, tuple)):
allowed_method = [allowed_method]
if not isinstance(allowed_origin, (list, tuple)):
allowed_origin = [allowed_origin]
if not isinstance(allowed_origin, (list, tuple)):
if allowed_origin is None:
allowed_origin = []
else:
allowed_origin = [allowed_origin]
if not isinstance(expose_header, (list, tuple)):
if expose_header is None:
expose_header = []
else:
expose_header = [expose_header]
rule = CORSRule(allowed_method, allowed_origin, id, allowed_header,
max_age_seconds, expose_header)
self.append(rule)
|
mit
|
[
3,
1898,
334,
67,
9,
6029,
603,
9414,
598,
26272,
1455,
921,
71,
26272,
14,
1308,
15,
199,
3,
1898,
334,
67,
9,
6029,
14347,
14,
957,
12,
3277,
14,
503,
2399,
29172,
2335,
14,
221,
2900,
5924,
5702,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
199,
3,
1331,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
199,
3,
298,
10337,
1288,
370,
7962,
315,
314,
2290,
1928,
10588,
12,
5893,
199,
3,
1928,
12305,
314,
4481,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
2153,
13,
199,
3,
28420,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
314,
2290,
12,
436,
370,
11291,
199,
3,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
880,
12,
5420,
370,
314,
1699,
13,
199,
3,
28486,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
199,
3,
315,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
199,
3,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
28471,
13,
199,
3,
28463,
12,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
199,
3,
7000,
2334,
17632,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
199,
3,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
199,
3,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
199,
3,
1621,
2334,
4141,
14,
199,
3,
421,
199,
533,
445,
4149,
5065,
8,
785,
304,
272,
408,
272,
445,
4149,
2332,
367,
282,
5315,
14,
339,
520,
7725,
1305,
26,
437,
3747,
5148,
367,
314,
2332,
14,
221,
710,
2870,
574,
883,
506,
267,
1536,
370,
5450,
4110,
1846,
14,
221,
710,
11449,
1720,
1265,
2342,
282,
2332,
315,
267,
314,
2897,
14,
339,
520,
7725,
4370,
63,
2474,
26,
1626,
3101,
1083,
626,
1265,
2934,
370,
2040,
314,
267,
6330,
370,
5341,
14,
221,
7048,
445,
4149,
5065,
1471,
10405,
737,
5210,
1373,
267,
6330,
436,
1373,
1083,
14,
4821,
1338,
787,
26,
267,
9576,
92,
4013,
92,
5211,
92,
4030,
92,
7014,
339,
520,
7725,
4370,
63,
6493,
26,
1626,
6330,
626,
1265,
2934,
370,
2040,
8059,
13,
2261,
267,
4145,
687,
14,
961,
883,
1395,
737,
4750,
1373,
627,
336,
668,
4528,
14,
267,
7048,
445,
4149,
5065,
1471,
10405,
737,
5210,
1373,
6330,
436,
1373,
1083,
14,
267,
710,
6330,
574,
883,
2387,
737,
4750,
1373,
13626,
336,
668,
4528,
14,
267,
2104,
2893,
12,
298,
1014,
921,
4856,
2694,
14,
957,
1674,
2047,
883,
2597,
4165,
267,
1454,
627,
465,
314,
6330,
574,
17266,
1006,
2306,
3617,
8059,
13,
2261,
2879,
14,
339,
520,
7725,
4370,
63,
1291,
26,
11015,
1314,
2323,
787,
4370,
315,
282,
267,
876,
13,
28807,
23860,
1056,
4799,
314,
267,
11003,
13,
3717,
13,
2017,
13,
9883,
1406,
14,
7048,
1406,
536,
267,
2013,
315,
314,
11003,
13,
3717,
13,
2017,
13,
9883,
1406,
1471,
267,
1172,
282,
5226,
2397,
315,
314,
2332,
14,
14347,
428,
19,
911,
3222,
267,
1454,
314,
4370,
2323,
315,
282,
1177,
626,
4898,
5839,
14,
267,
961,
883,
1395,
737,
4750,
1373,
627,
336,
668,
4528,
14,
339,
520,
7725,
1390,
63,
474,
63,
4515,
26,
710,
900,
315,
4696,
626,
2195,
7042,
365,
370,
267,
2581,
314,
20491,
4040,
1177,
367,
314,
2013,
2073,
14,
339,
520,
7725,
23705,
63,
1291,
26,
7309,
503,
1655,
2323,
315,
314,
1177,
626,
1265,
267,
2934,
286,
28078,
370,
506,
7688,
370,
2879,
687,
3932,
13103,
267,
334,
509,
2893,
12,
687,
282,
15250,
4692,
10441,
909,
680,
221,
2047,
267,
1050,
1373,
1316,
4070,
2567,
1819,
315,
314,
2332,
367,
1924,
1406,
14,
267,
408,
339,
347,
636,
826,
721,
277,
12,
4370,
63,
765,
29,
403,
12,
4370,
63,
6493,
29,
403,
12,
326,
1305,
29,
403,
12,
4370,
63,
1291,
29,
403,
12,
1390,
63,
474,
63,
4515,
29,
403,
12,
326,
23705,
63,
1291,
29,
403,
304,
267,
340,
4370,
63,
765,
365,
488,
26,
288,
4370,
63,
765,
275,
942,
267,
291,
14,
6541,
63,
765,
275,
4370,
63,
765,
267,
340,
4370,
63,
6493,
365,
488,
26,
288,
4370,
63,
6493,
275,
942,
267,
291,
14,
6541,
63,
6493,
275,
4370,
63,
6493,
267,
291,
14,
344,
275,
1305,
267,
340,
4370,
63,
1291,
365,
488,
26,
288,
4370,
63,
1291,
275,
942,
267,
291,
14,
6541,
63,
1291,
275,
4370,
63,
1291,
267,
291,
14,
988,
63,
474,
63,
4515,
275,
1390,
63,
474,
63,
4515,
267,
340,
23705,
63,
1291,
365,
488,
26,
288,
23705,
63,
1291,
275,
942,
267,
291,
14,
20586,
63,
1291,
275,
23705,
63,
1291,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
2650,
5065,
26,
450,
83,
3524,
450,
291,
14,
344,
339,
347,
26325,
8,
277,
12,
536,
12,
3290,
12,
1950,
304,
267,
372,
488,
339,
347,
28920,
8,
277,
12,
536,
12,
574,
12,
1950,
304,
267,
340,
536,
508,
283,
998,
356,
288,
291,
14,
344,
275,
574,
267,
916,
536,
508,
283,
16070,
3767,
356,
288,
291,
14,
6541,
63,
765,
14,
740,
8,
585,
9,
267,
916,
536,
508,
283,
16070,
12834,
356,
288,
291,
14,
6541,
63,
6493,
14,
740,
8,
585,
9,
267,
916,
536,
508,
283,
16070,
2567,
356,
288,
291,
14,
6541,
63,
1291,
14,
740,
8,
585,
9,
267,
916,
536,
508,
283,
4261,
20480,
13165,
356,
288,
291,
14,
988,
63,
474,
63,
4515,
275,
1109,
8,
585,
9,
267,
916,
536,
508,
283,
920,
4070,
2567,
356,
288,
291,
14,
20586,
63,
1291,
14,
740,
8,
585,
9,
267,
587,
26,
288,
5371,
8,
277,
12,
536,
12,
574,
9,
339,
347,
370,
63,
1652,
8,
277,
304,
267,
308,
275,
2650,
35,
4149,
5065,
3524,
267,
367,
4370,
63,
765,
315,
291,
14,
6541,
63,
765,
26,
288,
308,
847,
2650,
16070,
3767,
6598,
83,
1108,
16070,
3767,
3524,
450,
4370,
63,
765
] |
[
1898,
334,
67,
9,
6029,
603,
9414,
598,
26272,
1455,
921,
71,
26272,
14,
1308,
15,
199,
3,
1898,
334,
67,
9,
6029,
14347,
14,
957,
12,
3277,
14,
503,
2399,
29172,
2335,
14,
221,
2900,
5924,
5702,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
199,
3,
1331,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
199,
3,
298,
10337,
1288,
370,
7962,
315,
314,
2290,
1928,
10588,
12,
5893,
199,
3,
1928,
12305,
314,
4481,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
2153,
13,
199,
3,
28420,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
314,
2290,
12,
436,
370,
11291,
199,
3,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
880,
12,
5420,
370,
314,
1699,
13,
199,
3,
28486,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
199,
3,
315,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
199,
3,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
28471,
13,
199,
3,
28463,
12,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
199,
3,
7000,
2334,
17632,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
199,
3,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
199,
3,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
199,
3,
1621,
2334,
4141,
14,
199,
3,
421,
199,
533,
445,
4149,
5065,
8,
785,
304,
272,
408,
272,
445,
4149,
2332,
367,
282,
5315,
14,
339,
520,
7725,
1305,
26,
437,
3747,
5148,
367,
314,
2332,
14,
221,
710,
2870,
574,
883,
506,
267,
1536,
370,
5450,
4110,
1846,
14,
221,
710,
11449,
1720,
1265,
2342,
282,
2332,
315,
267,
314,
2897,
14,
339,
520,
7725,
4370,
63,
2474,
26,
1626,
3101,
1083,
626,
1265,
2934,
370,
2040,
314,
267,
6330,
370,
5341,
14,
221,
7048,
445,
4149,
5065,
1471,
10405,
737,
5210,
1373,
267,
6330,
436,
1373,
1083,
14,
4821,
1338,
787,
26,
267,
9576,
92,
4013,
92,
5211,
92,
4030,
92,
7014,
339,
520,
7725,
4370,
63,
6493,
26,
1626,
6330,
626,
1265,
2934,
370,
2040,
8059,
13,
2261,
267,
4145,
687,
14,
961,
883,
1395,
737,
4750,
1373,
627,
336,
668,
4528,
14,
267,
7048,
445,
4149,
5065,
1471,
10405,
737,
5210,
1373,
6330,
436,
1373,
1083,
14,
267,
710,
6330,
574,
883,
2387,
737,
4750,
1373,
13626,
336,
668,
4528,
14,
267,
2104,
2893,
12,
298,
1014,
921,
4856,
2694,
14,
957,
1674,
2047,
883,
2597,
4165,
267,
1454,
627,
465,
314,
6330,
574,
17266,
1006,
2306,
3617,
8059,
13,
2261,
2879,
14,
339,
520,
7725,
4370,
63,
1291,
26,
11015,
1314,
2323,
787,
4370,
315,
282,
267,
876,
13,
28807,
23860,
1056,
4799,
314,
267,
11003,
13,
3717,
13,
2017,
13,
9883,
1406,
14,
7048,
1406,
536,
267,
2013,
315,
314,
11003,
13,
3717,
13,
2017,
13,
9883,
1406,
1471,
267,
1172,
282,
5226,
2397,
315,
314,
2332,
14,
14347,
428,
19,
911,
3222,
267,
1454,
314,
4370,
2323,
315,
282,
1177,
626,
4898,
5839,
14,
267,
961,
883,
1395,
737,
4750,
1373,
627,
336,
668,
4528,
14,
339,
520,
7725,
1390,
63,
474,
63,
4515,
26,
710,
900,
315,
4696,
626,
2195,
7042,
365,
370,
267,
2581,
314,
20491,
4040,
1177,
367,
314,
2013,
2073,
14,
339,
520,
7725,
23705,
63,
1291,
26,
7309,
503,
1655,
2323,
315,
314,
1177,
626,
1265,
267,
2934,
286,
28078,
370,
506,
7688,
370,
2879,
687,
3932,
13103,
267,
334,
509,
2893,
12,
687,
282,
15250,
4692,
10441,
909,
680,
221,
2047,
267,
1050,
1373,
1316,
4070,
2567,
1819,
315,
314,
2332,
367,
1924,
1406,
14,
267,
408,
339,
347,
636,
826,
721,
277,
12,
4370,
63,
765,
29,
403,
12,
4370,
63,
6493,
29,
403,
12,
326,
1305,
29,
403,
12,
4370,
63,
1291,
29,
403,
12,
1390,
63,
474,
63,
4515,
29,
403,
12,
326,
23705,
63,
1291,
29,
403,
304,
267,
340,
4370,
63,
765,
365,
488,
26,
288,
4370,
63,
765,
275,
942,
267,
291,
14,
6541,
63,
765,
275,
4370,
63,
765,
267,
340,
4370,
63,
6493,
365,
488,
26,
288,
4370,
63,
6493,
275,
942,
267,
291,
14,
6541,
63,
6493,
275,
4370,
63,
6493,
267,
291,
14,
344,
275,
1305,
267,
340,
4370,
63,
1291,
365,
488,
26,
288,
4370,
63,
1291,
275,
942,
267,
291,
14,
6541,
63,
1291,
275,
4370,
63,
1291,
267,
291,
14,
988,
63,
474,
63,
4515,
275,
1390,
63,
474,
63,
4515,
267,
340,
23705,
63,
1291,
365,
488,
26,
288,
23705,
63,
1291,
275,
942,
267,
291,
14,
20586,
63,
1291,
275,
23705,
63,
1291,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
2650,
5065,
26,
450,
83,
3524,
450,
291,
14,
344,
339,
347,
26325,
8,
277,
12,
536,
12,
3290,
12,
1950,
304,
267,
372,
488,
339,
347,
28920,
8,
277,
12,
536,
12,
574,
12,
1950,
304,
267,
340,
536,
508,
283,
998,
356,
288,
291,
14,
344,
275,
574,
267,
916,
536,
508,
283,
16070,
3767,
356,
288,
291,
14,
6541,
63,
765,
14,
740,
8,
585,
9,
267,
916,
536,
508,
283,
16070,
12834,
356,
288,
291,
14,
6541,
63,
6493,
14,
740,
8,
585,
9,
267,
916,
536,
508,
283,
16070,
2567,
356,
288,
291,
14,
6541,
63,
1291,
14,
740,
8,
585,
9,
267,
916,
536,
508,
283,
4261,
20480,
13165,
356,
288,
291,
14,
988,
63,
474,
63,
4515,
275,
1109,
8,
585,
9,
267,
916,
536,
508,
283,
920,
4070,
2567,
356,
288,
291,
14,
20586,
63,
1291,
14,
740,
8,
585,
9,
267,
587,
26,
288,
5371,
8,
277,
12,
536,
12,
574,
9,
339,
347,
370,
63,
1652,
8,
277,
304,
267,
308,
275,
2650,
35,
4149,
5065,
3524,
267,
367,
4370,
63,
765,
315,
291,
14,
6541,
63,
765,
26,
288,
308,
847,
2650,
16070,
3767,
6598,
83,
1108,
16070,
3767,
3524,
450,
4370,
63,
765,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
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anagrams_in_a_string.py
|
1
|
1819
|
'''
Given a string s and a non-empty string p, find all the start indices of p's anagrams in s.
Strings consists of lowercase English letters only and the length of both strings s and p will not be larger than 20,100.
The order of output does not matter.
Example 1:
Input:
s: "cbaebabacd" p: "abc"
Output:
[0, 6]
Explanation:
The substring with start index = 0 is "cba", which is an anagram of "abc".
The substring with start index = 6 is "bac", which is an anagram of "abc".
Example 2:
Input:
s: "abab" p: "ab"
Output:
[0, 1, 2]
Explanation:
The substring with start index = 0 is "ab", which is an anagram of "ab".
The substring with start index = 1 is "ba", which is an anagram of "ab".
The substring with start index = 2 is "ab", which is an anagram of "ab".
'''
class Solution(object):
def findAnagrams(self, s, p):
"""
:type s: str
:type p: str
:rtype: List[int]
"""
import collections
w_hash = collections.defaultdict(int)
p_hash = collections.defaultdict(int)
for char in p:
p_hash[char] += 1
p_size = len(p)
s_size = len(s)
output = list()
start = 0
end = 0
if s_size < p_size:
return output
while end < p_size:
w_hash[s[end]] += 1
end += 1
while end < s_size:
if w_hash == p_hash:
output.append(start)
w_hash[s[start]] -=1
if w_hash[s[start]] == 0:
del w_hash[s[start]]
start += 1
w_hash[s[end]] += 1
end += 1
if w_hash == p_hash:
output.append(start)
return output
solution = Solution()
print solution.findAnagrams("abab", "ab")
print solution.findAnagrams("cbaebabacd", "abc")
|
bsd-3-clause
|
[
2344,
199,
13735,
282,
1059,
308,
436,
282,
2222,
13,
1667,
1059,
299,
12,
2342,
1006,
314,
1343,
4918,
402,
299,
1159,
376,
643,
345,
706,
315,
308,
14,
199,
199,
12672,
18581,
402,
12141,
20144,
14435,
1454,
436,
314,
2582,
402,
3865,
3326,
308,
436,
299,
911,
440,
506,
12142,
2419,
3388,
12,
1960,
14,
199,
199,
1918,
1865,
402,
1072,
1630,
440,
17247,
14,
199,
199,
9846,
413,
26,
199,
199,
3205,
26,
199,
83,
26,
298,
28995,
2871,
371,
645,
68,
2,
299,
26,
298,
3175,
2,
199,
199,
2959,
26,
199,
59,
16,
12,
1227,
61,
199,
199,
920,
10304,
26,
199,
1918,
20597,
543,
1343,
1478,
275,
378,
365,
298,
28995,
401,
1314,
365,
376,
376,
32208,
402,
298,
3175,
1674,
199,
1918,
20597,
543,
1343,
1478,
275,
1227,
365,
298,
28150,
401,
1314,
365,
376,
376,
32208,
402,
298,
3175,
1674,
199,
9846,
499,
26,
199,
199,
3205,
26,
199,
83,
26,
298,
371,
371,
2,
299,
26,
298,
371,
2,
199,
199,
2959,
26,
199,
59,
16,
12,
413,
12,
499,
61,
199,
199,
920,
10304,
26,
199,
1918,
20597,
543,
1343,
1478,
275,
378,
365,
298,
371,
401,
1314,
365,
376,
376,
32208,
402,
298,
371,
1674,
199,
1918,
20597,
543,
1343,
1478,
275,
413,
365,
298,
2470,
401,
1314,
365,
376,
376,
32208,
402,
298,
371,
1674,
199,
1918,
20597,
543,
1343,
1478,
275,
499,
365,
298,
371,
401,
1314,
365,
376,
376,
32208,
402,
298,
371,
1674,
199,
2344,
199,
199,
533,
9274,
8,
785,
304,
272,
347,
2342,
2493,
643,
345,
706,
8,
277,
12,
308,
12,
299,
304,
267,
408,
267,
520,
466,
308,
26,
620,
267,
520,
466,
299,
26,
620,
267,
520,
4500,
26,
3820,
59,
442,
61,
267,
408,
267,
492,
5055,
267,
336,
63,
2227,
275,
5055,
14,
21501,
8,
442,
9,
267,
299,
63,
2227,
275,
5055,
14,
21501,
8,
442,
9,
267,
367,
1495,
315,
299,
26,
288,
299,
63,
2227,
59,
1560,
61,
847,
413,
267,
299,
63,
890,
275,
822,
8,
80,
9,
267,
308,
63,
890,
275,
822,
8,
83,
9,
267,
1072,
275,
769,
342,
267,
1343,
275,
378,
267,
1284,
275,
378,
267,
340,
308,
63,
890,
665,
299,
63,
890,
26,
288,
372,
1072,
267,
1830,
1284,
665,
299,
63,
890,
26,
288,
336,
63,
2227,
59,
83,
59,
500,
2677,
847,
413,
288,
1284,
847,
413,
267,
1830,
1284,
665,
308,
63,
890,
26,
288,
340,
336,
63,
2227,
508,
299,
63,
2227,
26,
355,
1072,
14,
740,
8,
928,
9,
288,
336,
63,
2227,
59,
83,
59,
928,
2677,
4862,
17,
288,
340,
336,
63,
2227,
59,
83,
59,
928,
2677,
508,
378,
26,
355,
2150,
336,
63,
2227,
59,
83,
59,
928,
2677,
288,
1343,
847,
413,
288,
336,
63,
2227,
59,
83,
59,
500,
2677,
847,
413,
288,
1284,
847,
413,
267,
340,
336,
63,
2227,
508,
299,
63,
2227,
26,
288,
1072,
14,
740,
8,
928,
9,
267,
372,
1072,
199,
199,
14458,
275,
9274,
342,
199,
1361,
8744,
14,
1623,
2493,
643,
345,
706,
480,
371,
371,
401,
298,
371,
531,
199,
1361,
8744,
14,
1623,
2493,
643,
345,
706,
480,
28995,
2871,
371,
645,
68,
401,
298,
3175,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
13735,
282,
1059,
308,
436,
282,
2222,
13,
1667,
1059,
299,
12,
2342,
1006,
314,
1343,
4918,
402,
299,
1159,
376,
643,
345,
706,
315,
308,
14,
199,
199,
12672,
18581,
402,
12141,
20144,
14435,
1454,
436,
314,
2582,
402,
3865,
3326,
308,
436,
299,
911,
440,
506,
12142,
2419,
3388,
12,
1960,
14,
199,
199,
1918,
1865,
402,
1072,
1630,
440,
17247,
14,
199,
199,
9846,
413,
26,
199,
199,
3205,
26,
199,
83,
26,
298,
28995,
2871,
371,
645,
68,
2,
299,
26,
298,
3175,
2,
199,
199,
2959,
26,
199,
59,
16,
12,
1227,
61,
199,
199,
920,
10304,
26,
199,
1918,
20597,
543,
1343,
1478,
275,
378,
365,
298,
28995,
401,
1314,
365,
376,
376,
32208,
402,
298,
3175,
1674,
199,
1918,
20597,
543,
1343,
1478,
275,
1227,
365,
298,
28150,
401,
1314,
365,
376,
376,
32208,
402,
298,
3175,
1674,
199,
9846,
499,
26,
199,
199,
3205,
26,
199,
83,
26,
298,
371,
371,
2,
299,
26,
298,
371,
2,
199,
199,
2959,
26,
199,
59,
16,
12,
413,
12,
499,
61,
199,
199,
920,
10304,
26,
199,
1918,
20597,
543,
1343,
1478,
275,
378,
365,
298,
371,
401,
1314,
365,
376,
376,
32208,
402,
298,
371,
1674,
199,
1918,
20597,
543,
1343,
1478,
275,
413,
365,
298,
2470,
401,
1314,
365,
376,
376,
32208,
402,
298,
371,
1674,
199,
1918,
20597,
543,
1343,
1478,
275,
499,
365,
298,
371,
401,
1314,
365,
376,
376,
32208,
402,
298,
371,
1674,
199,
2344,
199,
199,
533,
9274,
8,
785,
304,
272,
347,
2342,
2493,
643,
345,
706,
8,
277,
12,
308,
12,
299,
304,
267,
408,
267,
520,
466,
308,
26,
620,
267,
520,
466,
299,
26,
620,
267,
520,
4500,
26,
3820,
59,
442,
61,
267,
408,
267,
492,
5055,
267,
336,
63,
2227,
275,
5055,
14,
21501,
8,
442,
9,
267,
299,
63,
2227,
275,
5055,
14,
21501,
8,
442,
9,
267,
367,
1495,
315,
299,
26,
288,
299,
63,
2227,
59,
1560,
61,
847,
413,
267,
299,
63,
890,
275,
822,
8,
80,
9,
267,
308,
63,
890,
275,
822,
8,
83,
9,
267,
1072,
275,
769,
342,
267,
1343,
275,
378,
267,
1284,
275,
378,
267,
340,
308,
63,
890,
665,
299,
63,
890,
26,
288,
372,
1072,
267,
1830,
1284,
665,
299,
63,
890,
26,
288,
336,
63,
2227,
59,
83,
59,
500,
2677,
847,
413,
288,
1284,
847,
413,
267,
1830,
1284,
665,
308,
63,
890,
26,
288,
340,
336,
63,
2227,
508,
299,
63,
2227,
26,
355,
1072,
14,
740,
8,
928,
9,
288,
336,
63,
2227,
59,
83,
59,
928,
2677,
4862,
17,
288,
340,
336,
63,
2227,
59,
83,
59,
928,
2677,
508,
378,
26,
355,
2150,
336,
63,
2227,
59,
83,
59,
928,
2677,
288,
1343,
847,
413,
288,
336,
63,
2227,
59,
83,
59,
500,
2677,
847,
413,
288,
1284,
847,
413,
267,
340,
336,
63,
2227,
508,
299,
63,
2227,
26,
288,
1072,
14,
740,
8,
928,
9,
267,
372,
1072,
199,
199,
14458,
275,
9274,
342,
199,
1361,
8744,
14,
1623,
2493,
643,
345,
706,
480,
371,
371,
401,
298,
371,
531,
199,
1361,
8744,
14,
1623,
2493,
643,
345,
706,
480,
28995,
2871,
371,
645,
68,
401,
298,
3175,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
mrb/letsencrypt
|
letsencrypt/plugins/null.py
|
17
|
1439
|
"""Null plugin."""
import logging
import zope.component
import zope.interface
from letsencrypt import interfaces
from letsencrypt.plugins import common
logger = logging.getLogger(__name__)
class Installer(common.Plugin):
"""Null installer."""
zope.interface.implements(interfaces.IInstaller)
zope.interface.classProvides(interfaces.IPluginFactory)
description = "Null Installer"
hidden = True
# pylint: disable=missing-docstring,no-self-use
def prepare(self):
pass # pragma: no cover
def more_info(self):
return "Installer that doesn't do anything (for testing)."
def get_all_names(self):
return []
def deploy_cert(self, domain, cert_path, key_path,
chain_path=None, fullchain_path=None):
pass # pragma: no cover
def enhance(self, domain, enhancement, options=None):
pass # pragma: no cover
def supported_enhancements(self):
return []
def get_all_certs_keys(self):
return []
def save(self, title=None, temporary=False):
pass # pragma: no cover
def rollback_checkpoints(self, rollback=1):
pass # pragma: no cover
def recovery_routine(self):
pass # pragma: no cover
def view_config_changes(self):
pass # pragma: no cover
def config_test(self):
pass # pragma: no cover
def restart(self):
pass # pragma: no cover
|
apache-2.0
|
[
624,
8849,
3589,
1041,
199,
646,
2050,
199,
199,
646,
20110,
14,
3173,
199,
646,
20110,
14,
3266,
199,
199,
504,
4691,
31561,
492,
8386,
199,
504,
4691,
31561,
14,
5265,
492,
2863,
421,
199,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
14089,
9230,
8,
2330,
14,
5061,
304,
272,
408,
8849,
18535,
1041,
272,
20110,
14,
3266,
14,
24900,
8,
7436,
14,
41,
27598,
9,
272,
20110,
14,
3266,
14,
533,
17473,
8,
7436,
14,
1772,
76,
1632,
2927,
9,
339,
1369,
275,
298,
8849,
14089,
9230,
2,
272,
8752,
275,
715,
339,
327,
4287,
26,
3507,
29,
4752,
13,
12485,
12,
889,
13,
277,
13,
1180,
339,
347,
9275,
8,
277,
304,
267,
986,
221,
327,
11942,
26,
949,
8486,
339,
347,
1655,
63,
815,
8,
277,
304,
267,
372,
298,
27598,
626,
3181,
1133,
886,
7003,
334,
509,
5343,
17617,
339,
347,
664,
63,
452,
63,
1247,
8,
277,
304,
267,
372,
942,
339,
347,
12287,
63,
4736,
8,
277,
12,
2881,
12,
6250,
63,
515,
12,
790,
63,
515,
12,
490,
6036,
63,
515,
29,
403,
12,
2615,
4429,
63,
515,
29,
403,
304,
267,
986,
221,
327,
11942,
26,
949,
8486,
339,
347,
655,
14666,
8,
277,
12,
2881,
12,
655,
14666,
434,
12,
1511,
29,
403,
304,
267,
986,
221,
327,
11942,
26,
949,
8486,
339,
347,
3748,
63,
287,
14666,
1470,
8,
277,
304,
267,
372,
942,
339,
347,
664,
63,
452,
63,
8356,
63,
1612,
8,
277,
304,
267,
372,
942,
339,
347,
3354,
8,
277,
12,
2538,
29,
403,
12,
7937,
29,
797,
304,
267,
986,
221,
327,
11942,
26,
949,
8486,
339,
347,
16475,
63,
32475,
8,
277,
12,
16475,
29,
17,
304,
267,
986,
221,
327,
11942,
26,
949,
8486,
339,
347,
24201,
63,
17765,
8,
277,
304,
267,
986,
221,
327,
11942,
26,
949,
8486,
339,
347,
2455,
63,
888,
63,
6627,
8,
277,
304,
267,
986,
221,
327,
11942,
26,
949,
8486,
339,
347,
1101,
63,
396,
8,
277,
304,
267,
986,
221,
327,
11942,
26,
949,
8486,
339,
347,
11004,
8,
277,
304,
267,
986,
221,
327,
11942,
26,
949,
8486,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
8849,
3589,
1041,
199,
646,
2050,
199,
199,
646,
20110,
14,
3173,
199,
646,
20110,
14,
3266,
199,
199,
504,
4691,
31561,
492,
8386,
199,
504,
4691,
31561,
14,
5265,
492,
2863,
421,
199,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
14089,
9230,
8,
2330,
14,
5061,
304,
272,
408,
8849,
18535,
1041,
272,
20110,
14,
3266,
14,
24900,
8,
7436,
14,
41,
27598,
9,
272,
20110,
14,
3266,
14,
533,
17473,
8,
7436,
14,
1772,
76,
1632,
2927,
9,
339,
1369,
275,
298,
8849,
14089,
9230,
2,
272,
8752,
275,
715,
339,
327,
4287,
26,
3507,
29,
4752,
13,
12485,
12,
889,
13,
277,
13,
1180,
339,
347,
9275,
8,
277,
304,
267,
986,
221,
327,
11942,
26,
949,
8486,
339,
347,
1655,
63,
815,
8,
277,
304,
267,
372,
298,
27598,
626,
3181,
1133,
886,
7003,
334,
509,
5343,
17617,
339,
347,
664,
63,
452,
63,
1247,
8,
277,
304,
267,
372,
942,
339,
347,
12287,
63,
4736,
8,
277,
12,
2881,
12,
6250,
63,
515,
12,
790,
63,
515,
12,
490,
6036,
63,
515,
29,
403,
12,
2615,
4429,
63,
515,
29,
403,
304,
267,
986,
221,
327,
11942,
26,
949,
8486,
339,
347,
655,
14666,
8,
277,
12,
2881,
12,
655,
14666,
434,
12,
1511,
29,
403,
304,
267,
986,
221,
327,
11942,
26,
949,
8486,
339,
347,
3748,
63,
287,
14666,
1470,
8,
277,
304,
267,
372,
942,
339,
347,
664,
63,
452,
63,
8356,
63,
1612,
8,
277,
304,
267,
372,
942,
339,
347,
3354,
8,
277,
12,
2538,
29,
403,
12,
7937,
29,
797,
304,
267,
986,
221,
327,
11942,
26,
949,
8486,
339,
347,
16475,
63,
32475,
8,
277,
12,
16475,
29,
17,
304,
267,
986,
221,
327,
11942,
26,
949,
8486,
339,
347,
24201,
63,
17765,
8,
277,
304,
267,
986,
221,
327,
11942,
26,
949,
8486,
339,
347,
2455,
63,
888,
63,
6627,
8,
277,
304,
267,
986,
221,
327,
11942,
26,
949,
8486,
339,
347,
1101,
63,
396,
8,
277,
304,
267,
986,
221,
327,
11942,
26,
949,
8486,
339,
347,
11004,
8,
277,
304,
267,
986,
221,
327,
11942,
26,
949,
8486,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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y import array, dtype, int32
# set input attribute as continuous i.e. 2
feattypes = array([2],dtype=int32)
parameter_list = [[500,50,15,0.2,feattypes]]
def regression_chaidtree_modular(num_train=500,num_test=50,x_range=15,noise_var=0.2,ft=feattypes):
try:
from modshogun import RealFeatures, RegressionLabels, CSVFile, CHAIDTree, PT_REGRESSION
from numpy import random
except ImportError:
print("Could not import Shogun and/or numpy modules")
return
random.seed(1)
# form training dataset : y=x with noise
X_train=random.rand(1,num_train)*x_range;
Y_train=X_train+random.randn(num_train)*noise_var
# form test dataset
X_test=array([[float(i)/num_test*x_range for i in range(num_test)]])
# wrap features and labels into Shogun objects
feats_train=RealFeatures(X_train)
feats_test=RealFeatures(X_test)
train_labels=RegressionLabels(Y_train[0])
# CHAID Tree formation
c=CHAIDTree(2,feattypes,50)
c.set_labels(train_labels)
c.train(feats_train)
# Regress on test data
output=c.apply_regression(feats_test).get_labels()
return c,output
if __name__=='__main__':
print('CHAIDTree')
regression_chaidtree_modular(*parameter_list[0])
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
504,
2680,
492,
1625,
12,
2152,
12,
1109,
708,
199,
199,
3,
663,
1324,
2225,
465,
19922,
284,
14,
69,
14,
499,
199,
11873,
1313,
275,
1625,
779,
18,
467,
2271,
29,
442,
708,
9,
199,
199,
5329,
63,
513,
275,
3474,
5783,
12,
1400,
12,
1046,
12,
16,
14,
18,
12,
11873,
1313,
2677,
199,
199,
318,
10864,
63,
9518,
344,
2350,
63,
1494,
2238,
8,
1507,
63,
2834,
29,
5783,
12,
1507,
63,
396,
29,
1400,
12,
88,
63,
1842,
29,
1046,
12,
11838,
63,
1391,
29,
16,
14,
18,
12,
856,
29,
11873,
1313,
304,
199,
198,
893,
26,
507,
198,
504,
3413,
13927,
17924,
492,
14849,
10807,
12,
13262,
14016,
12,
14689,
1173,
12,
445,
6294,
998,
3987,
12,
510,
52,
63,
907,
3975,
9577,
507,
198,
504,
2680,
492,
2196,
199,
198,
2590,
3545,
26,
507,
198,
1361,
480,
6531,
440,
492,
428,
526,
17924,
436,
15,
269,
2680,
4621,
531,
507,
198,
1107,
421,
198,
2355,
14,
5176,
8,
17,
9,
421,
198,
3,
1824,
6093,
4789,
520,
612,
29,
88,
543,
11145,
199,
198,
56,
63,
2834,
29,
2355,
14,
3759,
8,
17,
12,
1507,
63,
2834,
3342,
88,
63,
1842,
27,
199,
198,
57,
63,
2834,
29,
56,
63,
2834,
11,
2355,
14,
10843,
8,
1507,
63,
2834,
3342,
11838,
63,
1391,
421,
198,
3,
1824,
511,
4789,
199,
198,
56,
63,
396,
29,
1144,
4038,
1609,
8,
73,
2447,
1507,
63,
396,
10,
88,
63,
1842,
367,
284,
315,
1425,
8,
1507,
63,
396,
1874,
566,
421,
198,
3,
4816,
4534,
436,
3628,
1901,
428,
526,
17924,
2251,
199,
198,
29255,
63,
2834,
29,
10099,
10807,
8,
56,
63,
2834,
9,
199,
198,
29255,
63,
396,
29,
10099,
10807,
8,
56,
63,
396,
9,
199,
198,
2834,
63,
3512,
29,
13013,
14016,
8,
57,
63,
2834,
59,
16,
566,
421,
198,
3,
445,
6294,
998,
12178,
367,
1615,
199,
198,
67,
29,
26363,
998,
3987,
8,
18,
12,
11873,
1313,
12,
1400,
9,
199,
198,
67,
14,
409,
63,
3512,
8,
2834,
63,
3512,
9,
199,
198,
67,
14,
2834,
8,
29255,
63,
2834,
9,
421,
198,
3,
799,
3313,
641,
511,
666,
199,
198,
1199,
29,
67,
14,
4998,
63,
12513,
8,
29255,
63,
396,
680,
362,
63,
3512,
342,
421,
198,
1107,
286,
12,
1199,
199,
199,
692,
636,
354,
363,
6803,
363,
973,
3706,
199,
198,
1361,
360,
26363,
998,
3987,
358,
199,
198,
12513,
63,
9518,
344,
2350,
63,
1494,
2238,
2031,
5329,
63,
513,
59,
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
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
504,
2680,
492,
1625,
12,
2152,
12,
1109,
708,
199,
199,
3,
663,
1324,
2225,
465,
19922,
284,
14,
69,
14,
499,
199,
11873,
1313,
275,
1625,
779,
18,
467,
2271,
29,
442,
708,
9,
199,
199,
5329,
63,
513,
275,
3474,
5783,
12,
1400,
12,
1046,
12,
16,
14,
18,
12,
11873,
1313,
2677,
199,
199,
318,
10864,
63,
9518,
344,
2350,
63,
1494,
2238,
8,
1507,
63,
2834,
29,
5783,
12,
1507,
63,
396,
29,
1400,
12,
88,
63,
1842,
29,
1046,
12,
11838,
63,
1391,
29,
16,
14,
18,
12,
856,
29,
11873,
1313,
304,
199,
198,
893,
26,
507,
198,
504,
3413,
13927,
17924,
492,
14849,
10807,
12,
13262,
14016,
12,
14689,
1173,
12,
445,
6294,
998,
3987,
12,
510,
52,
63,
907,
3975,
9577,
507,
198,
504,
2680,
492,
2196,
199,
198,
2590,
3545,
26,
507,
198,
1361,
480,
6531,
440,
492,
428,
526,
17924,
436,
15,
269,
2680,
4621,
531,
507,
198,
1107,
421,
198,
2355,
14,
5176,
8,
17,
9,
421,
198,
3,
1824,
6093,
4789,
520,
612,
29,
88,
543,
11145,
199,
198,
56,
63,
2834,
29,
2355,
14,
3759,
8,
17,
12,
1507,
63,
2834,
3342,
88,
63,
1842,
27,
199,
198,
57,
63,
2834,
29,
56,
63,
2834,
11,
2355,
14,
10843,
8,
1507,
63,
2834,
3342,
11838,
63,
1391,
421,
198,
3,
1824,
511,
4789,
199,
198,
56,
63,
396,
29,
1144,
4038,
1609,
8,
73,
2447,
1507,
63,
396,
10,
88,
63,
1842,
367,
284,
315,
1425,
8,
1507,
63,
396,
1874,
566,
421,
198,
3,
4816,
4534,
436,
3628,
1901,
428,
526,
17924,
2251,
199,
198,
29255,
63,
2834,
29,
10099,
10807,
8,
56,
63,
2834,
9,
199,
198,
29255,
63,
396,
29,
10099,
10807,
8,
56,
63,
396,
9,
199,
198,
2834,
63,
3512,
29,
13013,
14016,
8,
57,
63,
2834,
59,
16,
566,
421,
198,
3,
445,
6294,
998,
12178,
367,
1615,
199,
198,
67,
29,
26363,
998,
3987,
8,
18,
12,
11873,
1313,
12,
1400,
9,
199,
198,
67,
14,
409,
63,
3512,
8,
2834,
63,
3512,
9,
199,
198,
67,
14,
2834,
8,
29255,
63,
2834,
9,
421,
198,
3,
799,
3313,
641,
511,
666,
199,
198,
1199,
29,
67,
14,
4998,
63,
12513,
8,
29255,
63,
396,
680,
362,
63,
3512,
342,
421,
198,
1107,
286,
12,
1199,
199,
199,
692,
636,
354,
363,
6803,
363,
973,
3706,
199,
198,
1361,
360,
26363,
998,
3987,
358,
199,
198,
12513,
63,
9518,
344,
2350,
63,
1494,
2238,
2031,
5329,
63,
513,
59,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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/python/EST_Wave.py
|
2
|
7329
|
# This file was automatically generated by SWIG (http://www.swig.org).
# Version 1.3.40
#
# Do not make changes to this file unless you know what you are doing--modify
# the SWIG interface file instead.
# This file is compatible with both classic and new-style classes.
from sys import version_info
if version_info >= (2,6,0):
def swig_import_helper():
from os.path import dirname
import imp
fp = None
try:
fp, pathname, description = imp.find_module('_EST_Wave', [dirname(__file__)])
except ImportError:
import _EST_Wave
return _EST_Wave
if fp is not None:
try:
_mod = imp.load_module('_EST_Wave', fp, pathname, description)
finally:
fp.close()
return _mod
_EST_Wave = swig_import_helper()
del swig_import_helper
else:
import _EST_Wave
del version_info
try:
_swig_property = property
except NameError:
pass # Python < 2.2 doesn't have 'property'.
def _swig_setattr_nondynamic(self,class_type,name,value,static=1):
if (name == "thisown"): return self.this.own(value)
if (name == "this"):
if type(value).__name__ == 'SwigPyObject':
self.__dict__[name] = value
return
method = class_type.__swig_setmethods__.get(name,None)
if method: return method(self,value)
if (not static) or hasattr(self,name):
self.__dict__[name] = value
else:
raise AttributeError("You cannot add attributes to %s" % self)
def _swig_setattr(self,class_type,name,value):
return _swig_setattr_nondynamic(self,class_type,name,value,0)
def _swig_getattr(self,class_type,name):
if (name == "thisown"): return self.this.own()
method = class_type.__swig_getmethods__.get(name,None)
if method: return method(self)
raise AttributeError(name)
def _swig_repr(self):
try: strthis = "proxy of " + self.this.__repr__()
except: strthis = ""
return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,)
try:
_object = object
_newclass = 1
except AttributeError:
class _object : pass
_newclass = 0
read_ok = _EST_Wave.read_ok
read_format_error = _EST_Wave.read_format_error
read_not_found_error = _EST_Wave.read_not_found_error
read_error = _EST_Wave.read_error
write_ok = _EST_Wave.write_ok
write_fail = _EST_Wave.write_fail
write_error = _EST_Wave.write_error
write_partial = _EST_Wave.write_partial
connect_ok = _EST_Wave.connect_ok
connect_not_found_error = _EST_Wave.connect_not_found_error
connect_not_allowed_error = _EST_Wave.connect_not_allowed_error
connect_system_error = _EST_Wave.connect_system_error
connect_error = _EST_Wave.connect_error
class EST_Wave(_object):
__swig_setmethods__ = {}
__setattr__ = lambda self, name, value: _swig_setattr(self, EST_Wave, name, value)
__swig_getmethods__ = {}
__getattr__ = lambda self, name: _swig_getattr(self, EST_Wave, name)
__repr__ = _swig_repr
__swig_getmethods__["default_sample_rate"] = _EST_Wave.EST_Wave_default_sample_rate_get
if _newclass:default_sample_rate = _swig_property(_EST_Wave.EST_Wave_default_sample_rate_get)
def __init__(self, *args):
this = _EST_Wave.new_EST_Wave(*args)
try: self.this.append(this)
except: self.this = this
__swig_destroy__ = _EST_Wave.delete_EST_Wave
__del__ = lambda self : None;
def a(self, *args): return _EST_Wave.EST_Wave_a(self, *args)
def a_safe(self, *args): return _EST_Wave.EST_Wave_a_safe(self, *args)
def set_a(self, *args): return _EST_Wave.EST_Wave_set_a(self, *args)
def t(self, *args): return _EST_Wave.EST_Wave_t(self, *args)
def num_samples(self): return _EST_Wave.EST_Wave_num_samples(self)
def num_channels(self): return _EST_Wave.EST_Wave_num_channels(self)
def sample_rate(self): return _EST_Wave.EST_Wave_sample_rate(self)
def set_sample_rate(self, *args): return _EST_Wave.EST_Wave_set_sample_rate(self, *args)
def length(self): return _EST_Wave.EST_Wave_length(self)
def end(self): return _EST_Wave.EST_Wave_end(self)
def have_left_context(self, *args): return _EST_Wave.EST_Wave_have_left_context(self, *args)
def sample_type(self): return _EST_Wave.EST_Wave_sample_type(self)
def set_sample_type(self, *args): return _EST_Wave.EST_Wave_set_sample_type(self, *args)
def file_type(self): return _EST_Wave.EST_Wave_file_type(self)
def set_file_type(self, *args): return _EST_Wave.EST_Wave_set_file_type(self, *args)
def name(self): return _EST_Wave.EST_Wave_name(self)
def set_name(self, *args): return _EST_Wave.EST_Wave_set_name(self, *args)
def resize(self, *args): return _EST_Wave.EST_Wave_resize(self, *args)
def resample(self, *args): return _EST_Wave.EST_Wave_resample(self, *args)
def rescale(self, *args): return _EST_Wave.EST_Wave_rescale(self, *args)
def clear(self): return _EST_Wave.EST_Wave_clear(self)
def copy(self, *args): return _EST_Wave.EST_Wave_copy(self, *args)
def fill(self, *args): return _EST_Wave.EST_Wave_fill(self, *args)
def empty(self, *args): return _EST_Wave.EST_Wave_empty(self, *args)
def load(self, *args): return _EST_Wave.EST_Wave_load(self, *args)
def load_file(self, *args): return _EST_Wave.EST_Wave_load_file(self, *args)
def save(self, *args): return _EST_Wave.EST_Wave_save(self, *args)
def save_file(self, *args): return _EST_Wave.EST_Wave_save_file(self, *args)
def integrity(self): return _EST_Wave.EST_Wave_integrity(self)
def info(self): return _EST_Wave.EST_Wave_info(self)
def play(self): return _EST_Wave.EST_Wave_play(self)
EST_Wave_swigregister = _EST_Wave.EST_Wave_swigregister
EST_Wave_swigregister(EST_Wave)
def wave_extract_channel(*args):
return _EST_Wave.wave_extract_channel(*args)
wave_extract_channel = _EST_Wave.wave_extract_channel
def wave_combine_channels(*args):
return _EST_Wave.wave_combine_channels(*args)
wave_combine_channels = _EST_Wave.wave_combine_channels
def wave_subwave(*args):
return _EST_Wave.wave_subwave(*args)
wave_subwave = _EST_Wave.wave_subwave
def wave_divide(*args):
return _EST_Wave.wave_divide(*args)
wave_divide = _EST_Wave.wave_divide
def wave_extract(*args):
return _EST_Wave.wave_extract(*args)
wave_extract = _EST_Wave.wave_extract
def add_waves(*args):
return _EST_Wave.add_waves(*args)
add_waves = _EST_Wave.add_waves
def difference(*args):
return _EST_Wave.difference(*args)
difference = _EST_Wave.difference
def error(*args):
return _EST_Wave.error(*args)
error = _EST_Wave.error
def absolute(*args):
return _EST_Wave.absolute(*args)
absolute = _EST_Wave.absolute
def wave_info(*args):
return _EST_Wave.wave_info(*args)
wave_info = _EST_Wave.wave_info
def invert(*args):
return _EST_Wave.invert(*args)
invert = _EST_Wave.invert
def differentiate(*args):
return _EST_Wave.differentiate(*args)
differentiate = _EST_Wave.differentiate
def reverse(*args):
return _EST_Wave.reverse(*args)
reverse = _EST_Wave.reverse
def rms_error(*args):
return _EST_Wave.rms_error(*args)
rms_error = _EST_Wave.rms_error
def abs_error(*args):
return _EST_Wave.abs_error(*args)
abs_error = _EST_Wave.abs_error
def correlation(*args):
return _EST_Wave.correlation(*args)
correlation = _EST_Wave.correlation
|
lgpl-3.0
|
[
3,
961,
570,
1990,
5847,
4046,
701,
26480,
334,
1014,
921,
1544,
14,
9676,
14,
1308,
680,
199,
3,
3394,
413,
14,
19,
14,
2167,
199,
3,
199,
3,
4226,
440,
1852,
4493,
370,
642,
570,
7444,
1265,
5715,
4052,
1265,
787,
9689,
306,
8951,
199,
3,
314,
26480,
3217,
570,
3140,
14,
199,
3,
961,
570,
365,
9025,
543,
3865,
31205,
436,
892,
13,
2487,
3992,
14,
199,
199,
504,
984,
492,
1015,
63,
815,
199,
692,
1015,
63,
815,
2356,
334,
18,
12,
22,
12,
16,
304,
272,
347,
30057,
63,
646,
63,
3676,
837,
267,
687,
747,
14,
515,
492,
9017,
267,
492,
1742,
267,
4090,
275,
488,
267,
862,
26,
288,
4090,
12,
11776,
12,
1369,
275,
1742,
14,
1623,
63,
578,
6412,
1719,
63,
21393,
297,
359,
3475,
3460,
493,
3368,
566,
267,
871,
3545,
26,
288,
492,
485,
1719,
63,
21393,
288,
372,
485,
1719,
63,
21393,
267,
340,
4090,
365,
440,
488,
26,
288,
862,
26,
355,
485,
1494,
275,
1742,
14,
912,
63,
578,
6412,
1719,
63,
21393,
297,
4090,
12,
11776,
12,
1369,
9,
288,
3753,
26,
355,
4090,
14,
1600,
342,
288,
372,
485,
1494,
272,
485,
1719,
63,
21393,
275,
30057,
63,
646,
63,
3676,
342,
272,
2150,
30057,
63,
646,
63,
3676,
199,
2836,
26,
272,
492,
485,
1719,
63,
21393,
199,
2264,
1015,
63,
815,
199,
893,
26,
272,
485,
9676,
63,
1829,
275,
3324,
199,
2590,
12746,
26,
272,
986,
327,
2018,
665,
499,
14,
18,
3181,
1133,
1172,
283,
1829,
1370,
199,
318,
485,
9676,
63,
10202,
63,
2865,
7764,
8,
277,
12,
533,
63,
466,
12,
354,
12,
585,
12,
1986,
29,
17,
304,
272,
340,
334,
354,
508,
298,
3749,
944,
2349,
372,
291,
14,
3749,
14,
944,
8,
585,
9,
272,
340,
334,
354,
508,
298,
3749,
2349,
267,
340,
730,
8,
585,
2843,
354,
363,
508,
283,
10941,
528,
19999,
356,
288,
291,
855,
807,
12298,
354,
61,
275,
574,
288,
372,
272,
1083,
275,
1021,
63,
466,
855,
9676,
63,
409,
2474,
4343,
362,
8,
354,
12,
403,
9,
272,
340,
1083,
26,
372,
1083,
8,
277,
12,
585,
9,
272,
340,
334,
1397,
2955,
9,
503,
2688,
8,
277,
12,
354,
304,
267,
291,
855,
807,
12298,
354,
61,
275,
574,
272,
587,
26,
267,
746,
4281,
480,
5556,
3913,
1050,
3004,
370,
450,
83,
2,
450,
291,
9,
199,
199,
318,
485,
9676,
63,
10202,
8,
277,
12,
533,
63,
466,
12,
354,
12,
585,
304,
272,
372,
485,
9676,
63,
10202,
63,
2865,
7764,
8,
277,
12,
533,
63,
466,
12,
354,
12,
585,
12,
16,
9,
199,
199,
318,
485,
9676,
63,
5675,
8,
277,
12,
533,
63,
466,
12,
354,
304,
272,
340,
334,
354,
508,
298,
3749,
944,
2349,
372,
291,
14,
3749,
14,
944,
342,
272,
1083,
275,
1021,
63,
466,
855,
9676,
63,
362,
2474,
4343,
362,
8,
354,
12,
403,
9,
272,
340,
1083,
26,
372,
1083,
8,
277,
9,
272,
746,
4281,
8,
354,
9,
199,
199,
318,
485,
9676,
63,
2722,
8,
277,
304,
272,
862,
26,
620,
3749,
275,
298,
3280,
402,
298,
435,
291,
14,
3749,
855,
2722,
4533,
272,
871,
26,
620,
3749,
275,
3087,
272,
372,
23054,
83,
4111,
83,
27,
450,
83,
690,
2,
450,
334,
277,
855,
533,
4914,
578,
3108,
291,
855,
533,
4914,
354,
3108,
620,
3749,
4258,
199,
199,
893,
26,
272,
485,
785,
275,
909,
272,
485,
1222,
533,
275,
413,
199,
2590,
4281,
26,
272,
1021,
485,
785,
520,
986,
272,
485,
1222,
533,
275,
378,
421,
199,
739,
63,
745,
275,
485,
1719,
63,
21393,
14,
739,
63,
745,
199,
739,
63,
908,
63,
705,
275,
485,
1719,
63,
21393,
14,
739,
63,
908,
63,
705,
199,
739,
63,
1397,
63,
4214,
63,
705,
275,
485,
1719,
63,
21393,
14,
739,
63,
1397,
63,
4214,
63,
705,
199,
739,
63,
705,
275,
485,
1719,
63,
21393,
14,
739,
63,
705,
199,
952,
63,
745,
275,
485,
1719,
63,
21393,
14,
952,
63,
745,
199,
952,
63,
1633,
275,
485,
1719,
63,
21393,
14,
952,
63,
1633,
199,
952,
63,
705,
275,
485,
1719,
63,
21393,
14,
952,
63,
705,
199,
952,
63,
6672,
275,
485,
1719,
63,
21393,
14,
952,
63,
6672,
199,
2242,
63,
745,
275,
485,
1719,
63,
21393,
14,
2242,
63,
745,
199,
2242,
63,
1397,
63,
4214,
63,
705,
275,
485,
1719,
63,
21393,
14,
2242,
63,
1397,
63,
4214,
63,
705,
199,
2242,
63,
1397,
63,
6541,
63,
705,
275,
485,
1719,
63,
21393,
14,
2242,
63,
1397,
63,
6541,
63,
705,
199,
2242,
63,
2253,
63,
705,
275,
485,
1719,
63,
21393,
14,
2242,
63,
2253,
63,
705,
199,
2242,
63,
705,
275,
485,
1719,
63,
21393,
14,
2242,
63,
705,
199,
533,
221,
1719,
63,
21393,
1547,
785,
304,
272,
636,
9676,
63,
409,
2474,
363,
275,
1052,
272,
636,
10202,
363,
275,
2400,
291,
12,
536,
12,
574,
26,
485,
9676,
63,
10202,
8,
277,
12,
221,
1719,
63,
21393,
12,
536,
12,
574,
9,
272,
636,
9676,
63,
362,
2474,
363,
275,
1052,
272,
636,
5675,
363,
275,
2400,
291,
12,
536,
26,
485,
9676,
63,
5675,
8,
277,
12,
221,
1719,
63,
21393,
12,
536,
9,
272,
636,
2722,
363,
275,
485,
9676,
63,
2722,
272,
636,
9676,
63,
362,
2474,
363,
905,
885,
63,
3271,
63,
1866,
937,
275,
485,
1719,
63,
21393,
14,
1719,
63,
21393,
63,
885,
63,
3271,
63,
1866,
63,
362,
272,
340,
485,
1222,
533,
26,
885,
63,
3271,
63,
1866,
275,
485,
9676,
63,
1829,
1547,
1719,
63,
21393,
14,
1719,
63,
21393,
63,
885,
63,
3271,
63,
1866,
63,
362,
9,
272,
347,
636,
826,
721,
277,
12,
627,
589,
304,
4960,
642,
275,
485,
1719,
63,
21393,
14,
1222,
63,
1719,
63,
21393,
2031,
589,
9,
267,
862,
26,
291,
14,
3749,
14,
740,
8,
3749,
9,
267,
871,
26,
291,
14,
3749,
275,
642,
272,
636,
9676,
63,
7237,
363,
275,
485,
1719,
63,
21393,
14,
1807,
63,
1719,
63,
21393,
272,
636,
2264,
363,
275,
2400,
291,
520,
488,
27
] |
[
961,
570,
1990,
5847,
4046,
701,
26480,
334,
1014,
921,
1544,
14,
9676,
14,
1308,
680,
199,
3,
3394,
413,
14,
19,
14,
2167,
199,
3,
199,
3,
4226,
440,
1852,
4493,
370,
642,
570,
7444,
1265,
5715,
4052,
1265,
787,
9689,
306,
8951,
199,
3,
314,
26480,
3217,
570,
3140,
14,
199,
3,
961,
570,
365,
9025,
543,
3865,
31205,
436,
892,
13,
2487,
3992,
14,
199,
199,
504,
984,
492,
1015,
63,
815,
199,
692,
1015,
63,
815,
2356,
334,
18,
12,
22,
12,
16,
304,
272,
347,
30057,
63,
646,
63,
3676,
837,
267,
687,
747,
14,
515,
492,
9017,
267,
492,
1742,
267,
4090,
275,
488,
267,
862,
26,
288,
4090,
12,
11776,
12,
1369,
275,
1742,
14,
1623,
63,
578,
6412,
1719,
63,
21393,
297,
359,
3475,
3460,
493,
3368,
566,
267,
871,
3545,
26,
288,
492,
485,
1719,
63,
21393,
288,
372,
485,
1719,
63,
21393,
267,
340,
4090,
365,
440,
488,
26,
288,
862,
26,
355,
485,
1494,
275,
1742,
14,
912,
63,
578,
6412,
1719,
63,
21393,
297,
4090,
12,
11776,
12,
1369,
9,
288,
3753,
26,
355,
4090,
14,
1600,
342,
288,
372,
485,
1494,
272,
485,
1719,
63,
21393,
275,
30057,
63,
646,
63,
3676,
342,
272,
2150,
30057,
63,
646,
63,
3676,
199,
2836,
26,
272,
492,
485,
1719,
63,
21393,
199,
2264,
1015,
63,
815,
199,
893,
26,
272,
485,
9676,
63,
1829,
275,
3324,
199,
2590,
12746,
26,
272,
986,
327,
2018,
665,
499,
14,
18,
3181,
1133,
1172,
283,
1829,
1370,
199,
318,
485,
9676,
63,
10202,
63,
2865,
7764,
8,
277,
12,
533,
63,
466,
12,
354,
12,
585,
12,
1986,
29,
17,
304,
272,
340,
334,
354,
508,
298,
3749,
944,
2349,
372,
291,
14,
3749,
14,
944,
8,
585,
9,
272,
340,
334,
354,
508,
298,
3749,
2349,
267,
340,
730,
8,
585,
2843,
354,
363,
508,
283,
10941,
528,
19999,
356,
288,
291,
855,
807,
12298,
354,
61,
275,
574,
288,
372,
272,
1083,
275,
1021,
63,
466,
855,
9676,
63,
409,
2474,
4343,
362,
8,
354,
12,
403,
9,
272,
340,
1083,
26,
372,
1083,
8,
277,
12,
585,
9,
272,
340,
334,
1397,
2955,
9,
503,
2688,
8,
277,
12,
354,
304,
267,
291,
855,
807,
12298,
354,
61,
275,
574,
272,
587,
26,
267,
746,
4281,
480,
5556,
3913,
1050,
3004,
370,
450,
83,
2,
450,
291,
9,
199,
199,
318,
485,
9676,
63,
10202,
8,
277,
12,
533,
63,
466,
12,
354,
12,
585,
304,
272,
372,
485,
9676,
63,
10202,
63,
2865,
7764,
8,
277,
12,
533,
63,
466,
12,
354,
12,
585,
12,
16,
9,
199,
199,
318,
485,
9676,
63,
5675,
8,
277,
12,
533,
63,
466,
12,
354,
304,
272,
340,
334,
354,
508,
298,
3749,
944,
2349,
372,
291,
14,
3749,
14,
944,
342,
272,
1083,
275,
1021,
63,
466,
855,
9676,
63,
362,
2474,
4343,
362,
8,
354,
12,
403,
9,
272,
340,
1083,
26,
372,
1083,
8,
277,
9,
272,
746,
4281,
8,
354,
9,
199,
199,
318,
485,
9676,
63,
2722,
8,
277,
304,
272,
862,
26,
620,
3749,
275,
298,
3280,
402,
298,
435,
291,
14,
3749,
855,
2722,
4533,
272,
871,
26,
620,
3749,
275,
3087,
272,
372,
23054,
83,
4111,
83,
27,
450,
83,
690,
2,
450,
334,
277,
855,
533,
4914,
578,
3108,
291,
855,
533,
4914,
354,
3108,
620,
3749,
4258,
199,
199,
893,
26,
272,
485,
785,
275,
909,
272,
485,
1222,
533,
275,
413,
199,
2590,
4281,
26,
272,
1021,
485,
785,
520,
986,
272,
485,
1222,
533,
275,
378,
421,
199,
739,
63,
745,
275,
485,
1719,
63,
21393,
14,
739,
63,
745,
199,
739,
63,
908,
63,
705,
275,
485,
1719,
63,
21393,
14,
739,
63,
908,
63,
705,
199,
739,
63,
1397,
63,
4214,
63,
705,
275,
485,
1719,
63,
21393,
14,
739,
63,
1397,
63,
4214,
63,
705,
199,
739,
63,
705,
275,
485,
1719,
63,
21393,
14,
739,
63,
705,
199,
952,
63,
745,
275,
485,
1719,
63,
21393,
14,
952,
63,
745,
199,
952,
63,
1633,
275,
485,
1719,
63,
21393,
14,
952,
63,
1633,
199,
952,
63,
705,
275,
485,
1719,
63,
21393,
14,
952,
63,
705,
199,
952,
63,
6672,
275,
485,
1719,
63,
21393,
14,
952,
63,
6672,
199,
2242,
63,
745,
275,
485,
1719,
63,
21393,
14,
2242,
63,
745,
199,
2242,
63,
1397,
63,
4214,
63,
705,
275,
485,
1719,
63,
21393,
14,
2242,
63,
1397,
63,
4214,
63,
705,
199,
2242,
63,
1397,
63,
6541,
63,
705,
275,
485,
1719,
63,
21393,
14,
2242,
63,
1397,
63,
6541,
63,
705,
199,
2242,
63,
2253,
63,
705,
275,
485,
1719,
63,
21393,
14,
2242,
63,
2253,
63,
705,
199,
2242,
63,
705,
275,
485,
1719,
63,
21393,
14,
2242,
63,
705,
199,
533,
221,
1719,
63,
21393,
1547,
785,
304,
272,
636,
9676,
63,
409,
2474,
363,
275,
1052,
272,
636,
10202,
363,
275,
2400,
291,
12,
536,
12,
574,
26,
485,
9676,
63,
10202,
8,
277,
12,
221,
1719,
63,
21393,
12,
536,
12,
574,
9,
272,
636,
9676,
63,
362,
2474,
363,
275,
1052,
272,
636,
5675,
363,
275,
2400,
291,
12,
536,
26,
485,
9676,
63,
5675,
8,
277,
12,
221,
1719,
63,
21393,
12,
536,
9,
272,
636,
2722,
363,
275,
485,
9676,
63,
2722,
272,
636,
9676,
63,
362,
2474,
363,
905,
885,
63,
3271,
63,
1866,
937,
275,
485,
1719,
63,
21393,
14,
1719,
63,
21393,
63,
885,
63,
3271,
63,
1866,
63,
362,
272,
340,
485,
1222,
533,
26,
885,
63,
3271,
63,
1866,
275,
485,
9676,
63,
1829,
1547,
1719,
63,
21393,
14,
1719,
63,
21393,
63,
885,
63,
3271,
63,
1866,
63,
362,
9,
272,
347,
636,
826,
721,
277,
12,
627,
589,
304,
4960,
642,
275,
485,
1719,
63,
21393,
14,
1222,
63,
1719,
63,
21393,
2031,
589,
9,
267,
862,
26,
291,
14,
3749,
14,
740,
8,
3749,
9,
267,
871,
26,
291,
14,
3749,
275,
642,
272,
636,
9676,
63,
7237,
363,
275,
485,
1719,
63,
21393,
14,
1807,
63,
1719,
63,
21393,
272,
636,
2264,
363,
275,
2400,
291,
520,
488,
27,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
kiyukuta/chainer
|
chainer/datasets/dict_dataset.py
|
7
|
1331
|
import six
class DictDataset(object):
"""Dataset of a dictionary of datasets.
It combines multiple datasets into one dataset. Each example is represented
by a dictionary mapping a key to an example of the corresponding dataset.
Args:
datasets: Underlying datasets. The keys are used as the keys of each
example. All datasets must have the same length.
"""
def __init__(self, **datasets):
if not datasets:
raise ValueError('no datasets are given')
length = None
for key, dataset in six.iteritems(datasets):
if length is None:
length = len(dataset)
elif length != len(dataset):
raise ValueError(
'dataset length conflicts at "{}"'.format(key))
self._datasets = datasets
self._length = length
def __getitem__(self, index):
batches = {key: dataset[index]
for key, dataset in six.iteritems(self._datasets)}
if isinstance(index, slice):
length = len(six.itervalues(batches).next())
return [{key: batch[i] for key, batch in six.iteritems(batches)}
for i in six.moves.range(length)]
else:
return batches
def __len__(self):
return self._length
|
mit
|
[
646,
3816,
421,
199,
533,
7448,
9271,
8,
785,
304,
339,
408,
9271,
402,
282,
2600,
402,
13148,
14,
339,
2779,
5300,
3746,
3663,
13148,
1901,
1373,
4789,
14,
7048,
2893,
365,
11159,
272,
701,
282,
2600,
4412,
282,
790,
370,
376,
2893,
402,
314,
5226,
4789,
14,
339,
3033,
26,
267,
13148,
26,
25010,
6670,
13148,
14,
710,
2883,
787,
1202,
465,
314,
2883,
402,
1924,
288,
2893,
14,
2900,
13148,
1471,
1172,
314,
2011,
2582,
14,
339,
408,
339,
347,
636,
826,
721,
277,
12,
1011,
12281,
304,
267,
340,
440,
13148,
26,
288,
746,
1722,
360,
889,
13148,
787,
1627,
358,
267,
2582,
275,
488,
267,
367,
790,
12,
4789,
315,
3816,
14,
4611,
8,
12281,
304,
288,
340,
2582,
365,
488,
26,
355,
2582,
275,
822,
8,
5214,
9,
288,
916,
2582,
1137,
822,
8,
5214,
304,
355,
746,
1722,
8,
490,
283,
5214,
2582,
18511,
737,
28168,
1370,
908,
8,
498,
430,
267,
291,
423,
12281,
275,
13148,
267,
291,
423,
1267,
275,
2582,
339,
347,
636,
6095,
721,
277,
12,
1478,
304,
267,
19593,
275,
469,
498,
26,
4789,
59,
1080,
61,
673,
367,
790,
12,
4789,
315,
3816,
14,
4611,
8,
277,
423,
12281,
6769,
267,
340,
1228,
8,
1080,
12,
6014,
304,
288,
2582,
275,
822,
8,
4174,
14,
13012,
8,
14896,
680,
2184,
1012,
288,
372,
8910,
498,
26,
3522,
59,
73,
61,
367,
790,
12,
3522,
315,
3816,
14,
4611,
8,
14896,
6769,
490,
367,
284,
315,
3816,
14,
4912,
14,
1842,
8,
1267,
1874,
267,
587,
26,
288,
372,
19593,
339,
347,
636,
552,
721,
277,
304,
267,
372,
291,
423,
1267,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
3816,
421,
199,
533,
7448,
9271,
8,
785,
304,
339,
408,
9271,
402,
282,
2600,
402,
13148,
14,
339,
2779,
5300,
3746,
3663,
13148,
1901,
1373,
4789,
14,
7048,
2893,
365,
11159,
272,
701,
282,
2600,
4412,
282,
790,
370,
376,
2893,
402,
314,
5226,
4789,
14,
339,
3033,
26,
267,
13148,
26,
25010,
6670,
13148,
14,
710,
2883,
787,
1202,
465,
314,
2883,
402,
1924,
288,
2893,
14,
2900,
13148,
1471,
1172,
314,
2011,
2582,
14,
339,
408,
339,
347,
636,
826,
721,
277,
12,
1011,
12281,
304,
267,
340,
440,
13148,
26,
288,
746,
1722,
360,
889,
13148,
787,
1627,
358,
267,
2582,
275,
488,
267,
367,
790,
12,
4789,
315,
3816,
14,
4611,
8,
12281,
304,
288,
340,
2582,
365,
488,
26,
355,
2582,
275,
822,
8,
5214,
9,
288,
916,
2582,
1137,
822,
8,
5214,
304,
355,
746,
1722,
8,
490,
283,
5214,
2582,
18511,
737,
28168,
1370,
908,
8,
498,
430,
267,
291,
423,
12281,
275,
13148,
267,
291,
423,
1267,
275,
2582,
339,
347,
636,
6095,
721,
277,
12,
1478,
304,
267,
19593,
275,
469,
498,
26,
4789,
59,
1080,
61,
673,
367,
790,
12,
4789,
315,
3816,
14,
4611,
8,
277,
423,
12281,
6769,
267,
340,
1228,
8,
1080,
12,
6014,
304,
288,
2582,
275,
822,
8,
4174,
14,
13012,
8,
14896,
680,
2184,
1012,
288,
372,
8910,
498,
26,
3522,
59,
73,
61,
367,
790,
12,
3522,
315,
3816,
14,
4611,
8,
14896,
6769,
490,
367,
284,
315,
3816,
14,
4912,
14,
1842,
8,
1267,
1874,
267,
587,
26,
288,
372,
19593,
339,
347,
636,
552,
721,
277,
304,
267,
372,
291,
423,
1267,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
Vvucinic/Wander
|
venv_2_7/lib/python2.7/site-packages/pip/_vendor/lockfile/__init__.py
|
475
|
9162
|
"""
lockfile.py - Platform-independent advisory file locks.
Requires Python 2.5 unless you apply 2.4.diff
Locking is done on a per-thread basis instead of a per-process basis.
Usage:
>>> lock = LockFile('somefile')
>>> try:
... lock.acquire()
... except AlreadyLocked:
... print 'somefile', 'is locked already.'
... except LockFailed:
... print 'somefile', 'can\\'t be locked.'
... else:
... print 'got lock'
got lock
>>> print lock.is_locked()
True
>>> lock.release()
>>> lock = LockFile('somefile')
>>> print lock.is_locked()
False
>>> with lock:
... print lock.is_locked()
True
>>> print lock.is_locked()
False
>>> lock = LockFile('somefile')
>>> # It is okay to lock twice from the same thread...
>>> with lock:
... lock.acquire()
...
>>> # Though no counter is kept, so you can't unlock multiple times...
>>> print lock.is_locked()
False
Exceptions:
Error - base class for other exceptions
LockError - base class for all locking exceptions
AlreadyLocked - Another thread or process already holds the lock
LockFailed - Lock failed for some other reason
UnlockError - base class for all unlocking exceptions
AlreadyUnlocked - File was not locked.
NotMyLock - File was locked but not by the current thread/process
"""
from __future__ import absolute_import
import sys
import socket
import os
import threading
import time
import urllib
import warnings
import functools
# Work with PEP8 and non-PEP8 versions of threading module.
if not hasattr(threading, "current_thread"):
threading.current_thread = threading.currentThread
if not hasattr(threading.Thread, "get_name"):
threading.Thread.get_name = threading.Thread.getName
__all__ = ['Error', 'LockError', 'LockTimeout', 'AlreadyLocked',
'LockFailed', 'UnlockError', 'NotLocked', 'NotMyLock',
'LinkLockFile', 'MkdirLockFile', 'SQLiteLockFile',
'LockBase', 'locked']
class Error(Exception):
"""
Base class for other exceptions.
>>> try:
... raise Error
... except Exception:
... pass
"""
pass
class LockError(Error):
"""
Base class for error arising from attempts to acquire the lock.
>>> try:
... raise LockError
... except Error:
... pass
"""
pass
class LockTimeout(LockError):
"""Raised when lock creation fails within a user-defined period of time.
>>> try:
... raise LockTimeout
... except LockError:
... pass
"""
pass
class AlreadyLocked(LockError):
"""Some other thread/process is locking the file.
>>> try:
... raise AlreadyLocked
... except LockError:
... pass
"""
pass
class LockFailed(LockError):
"""Lock file creation failed for some other reason.
>>> try:
... raise LockFailed
... except LockError:
... pass
"""
pass
class UnlockError(Error):
"""
Base class for errors arising from attempts to release the lock.
>>> try:
... raise UnlockError
... except Error:
... pass
"""
pass
class NotLocked(UnlockError):
"""Raised when an attempt is made to unlock an unlocked file.
>>> try:
... raise NotLocked
... except UnlockError:
... pass
"""
pass
class NotMyLock(UnlockError):
"""Raised when an attempt is made to unlock a file someone else locked.
>>> try:
... raise NotMyLock
... except UnlockError:
... pass
"""
pass
class LockBase:
"""Base class for platform-specific lock classes."""
def __init__(self, path, threaded=True, timeout=None):
"""
>>> lock = LockBase('somefile')
>>> lock = LockBase('somefile', threaded=False)
"""
self.path = path
self.lock_file = os.path.abspath(path) + ".lock"
self.hostname = socket.gethostname()
self.pid = os.getpid()
if threaded:
t = threading.current_thread()
# Thread objects in Python 2.4 and earlier do not have ident
# attrs. Worm around that.
ident = getattr(t, "ident", hash(t))
self.tname = "-%x" % (ident & 0xffffffff)
else:
self.tname = ""
dirname = os.path.dirname(self.lock_file)
# unique name is mostly about the current process, but must
# also contain the path -- otherwise, two adjacent locked
# files conflict (one file gets locked, creating lock-file and
# unique file, the other one gets locked, creating lock-file
# and overwriting the already existing lock-file, then one
# gets unlocked, deleting both lock-file and unique file,
# finally the last lock errors out upon releasing.
self.unique_name = os.path.join(dirname,
"%s%s.%s%s" % (self.hostname,
self.tname,
self.pid,
hash(self.path)))
self.timeout = timeout
def acquire(self, timeout=None):
"""
Acquire the lock.
* If timeout is omitted (or None), wait forever trying to lock the
file.
* If timeout > 0, try to acquire the lock for that many seconds. If
the lock period expires and the file is still locked, raise
LockTimeout.
* If timeout <= 0, raise AlreadyLocked immediately if the file is
already locked.
"""
raise NotImplemented("implement in subclass")
def release(self):
"""
Release the lock.
If the file is not locked, raise NotLocked.
"""
raise NotImplemented("implement in subclass")
def is_locked(self):
"""
Tell whether or not the file is locked.
"""
raise NotImplemented("implement in subclass")
def i_am_locking(self):
"""
Return True if this object is locking the file.
"""
raise NotImplemented("implement in subclass")
def break_lock(self):
"""
Remove a lock. Useful if a locking thread failed to unlock.
"""
raise NotImplemented("implement in subclass")
def __enter__(self):
"""
Context manager support.
"""
self.acquire()
return self
def __exit__(self, *_exc):
"""
Context manager support.
"""
self.release()
def __repr__(self):
return "<%s: %r -- %r>" % (self.__class__.__name__, self.unique_name,
self.path)
def _fl_helper(cls, mod, *args, **kwds):
warnings.warn("Import from %s module instead of lockfile package" % mod,
DeprecationWarning, stacklevel=2)
# This is a bit funky, but it's only for awhile. The way the unit tests
# are constructed this function winds up as an unbound method, so it
# actually takes three args, not two. We want to toss out self.
if not isinstance(args[0], str):
# We are testing, avoid the first arg
args = args[1:]
if len(args) == 1 and not kwds:
kwds["threaded"] = True
return cls(*args, **kwds)
def LinkFileLock(*args, **kwds):
"""Factory function provided for backwards compatibility.
Do not use in new code. Instead, import LinkLockFile from the
lockfile.linklockfile module.
"""
from . import linklockfile
return _fl_helper(linklockfile.LinkLockFile, "lockfile.linklockfile",
*args, **kwds)
def MkdirFileLock(*args, **kwds):
"""Factory function provided for backwards compatibility.
Do not use in new code. Instead, import MkdirLockFile from the
lockfile.mkdirlockfile module.
"""
from . import mkdirlockfile
return _fl_helper(mkdirlockfile.MkdirLockFile, "lockfile.mkdirlockfile",
*args, **kwds)
def SQLiteFileLock(*args, **kwds):
"""Factory function provided for backwards compatibility.
Do not use in new code. Instead, import SQLiteLockFile from the
lockfile.mkdirlockfile module.
"""
from . import sqlitelockfile
return _fl_helper(sqlitelockfile.SQLiteLockFile, "lockfile.sqlitelockfile",
*args, **kwds)
def locked(path, timeout=None):
"""Decorator which enables locks for decorated function.
Arguments:
- path: path for lockfile.
- timeout (optional): Timeout for acquiring lock.
Usage:
@locked('/var/run/myname', timeout=0)
def myname(...):
...
"""
def decor(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
lock = FileLock(path, timeout=timeout)
lock.acquire()
try:
return func(*args, **kwargs)
finally:
lock.release()
return wrapper
return decor
if hasattr(os, "link"):
from . import linklockfile as _llf
LockFile = _llf.LinkLockFile
else:
from . import mkdirlockfile as _mlf
LockFile = _mlf.MkdirLockFile
FileLock = LockFile
|
artistic-2.0
|
[
624,
199,
26204,
14,
647,
446,
16078,
13,
26083,
1503,
5068,
1089,
570,
23340,
14,
199,
199,
18153,
2018,
499,
14,
21,
7444,
1265,
4838,
499,
14,
20,
14,
3028,
199,
6432,
316,
365,
4224,
641,
282,
1126,
13,
2671,
5597,
3140,
402,
282,
1126,
13,
1412,
5597,
14,
199,
199,
7692,
26,
199,
199,
6071,
4650,
275,
15536,
1173,
360,
3972,
493,
358,
199,
6071,
862,
26,
199,
1396,
258,
4650,
14,
8174,
342,
199,
1396,
871,
21086,
22408,
26,
199,
1396,
258,
870,
283,
3972,
493,
297,
283,
374,
14233,
2575,
3530,
199,
1396,
871,
15536,
4276,
26,
199,
1396,
258,
870,
283,
3972,
493,
297,
283,
2425,
1103,
7,
84,
506,
14233,
3530,
199,
1396,
587,
26,
199,
1396,
258,
870,
283,
7808,
4650,
7,
199,
7808,
4650,
199,
6071,
870,
4650,
14,
374,
63,
9325,
342,
199,
549,
199,
6071,
4650,
14,
3221,
342,
199,
199,
6071,
4650,
275,
15536,
1173,
360,
3972,
493,
358,
199,
6071,
870,
4650,
14,
374,
63,
9325,
342,
199,
797,
199,
6071,
543,
4650,
26,
199,
1396,
259,
870,
4650,
14,
374,
63,
9325,
342,
199,
549,
199,
6071,
870,
4650,
14,
374,
63,
9325,
342,
199,
797,
199,
199,
6071,
4650,
275,
15536,
1173,
360,
3972,
493,
358,
199,
6071,
327,
2779,
365,
5849,
370,
4650,
13373,
687,
314,
2011,
2462,
1396,
199,
6071,
543,
4650,
26,
199,
1396,
258,
4650,
14,
8174,
342,
199,
1396,
199,
6071,
327,
18049,
3080,
949,
7055,
365,
16204,
12,
880,
1265,
883,
1133,
28451,
3663,
5431,
1396,
199,
6071,
870,
4650,
14,
374,
63,
9325,
342,
199,
797,
199,
199,
16836,
26,
339,
4520,
446,
1300,
1021,
367,
1163,
4967,
267,
15536,
547,
446,
1300,
1021,
367,
1006,
27267,
4967,
288,
21086,
22408,
446,
22604,
2462,
503,
2112,
2575,
15164,
314,
4650,
288,
15536,
4276,
446,
15536,
3405,
367,
2005,
1163,
4499,
267,
1910,
831,
547,
446,
1300,
1021,
367,
1006,
625,
24056,
4967,
288,
21086,
1358,
9325,
446,
3814,
1990,
440,
14233,
14,
288,
2832,
5713,
6432,
446,
3814,
1990,
14233,
1325,
440,
701,
314,
1453,
2462,
15,
1412,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
646,
984,
199,
646,
2838,
199,
646,
747,
199,
646,
5796,
199,
646,
900,
199,
646,
4011,
199,
646,
3598,
199,
646,
9143,
199,
199,
3,
9361,
543,
13663,
24,
436,
2222,
13,
25633,
24,
5459,
402,
5796,
859,
14,
199,
692,
440,
2688,
8,
12562,
12,
298,
1818,
63,
2671,
2349,
272,
5796,
14,
1818,
63,
2671,
275,
5796,
14,
1818,
4436,
199,
692,
440,
2688,
8,
12562,
14,
4436,
12,
298,
362,
63,
354,
2349,
272,
5796,
14,
4436,
14,
362,
63,
354,
275,
5796,
14,
4436,
14,
16405,
199,
199,
363,
452,
363,
275,
788,
547,
297,
283,
6432,
547,
297,
283,
6432,
6372,
297,
283,
16760,
22408,
297,
1779,
283,
6432,
4276,
297,
283,
1358,
831,
547,
297,
283,
1763,
22408,
297,
283,
1763,
5713,
6432,
297,
1779,
283,
3834,
6432,
1173,
297,
283,
31506,
694,
6432,
1173,
297,
283,
4657,
1175,
6432,
1173,
297,
1779,
283,
6432,
1563,
297,
283,
9325,
418,
199,
199,
533,
4520,
8,
1726,
304,
272,
408,
272,
3523,
1021,
367,
1163,
4967,
14,
339,
1306,
862,
26,
272,
2263,
257,
746,
4520,
272,
2263,
871,
2186,
26,
272,
2263,
257,
986,
272,
408,
272,
986,
199,
199,
533,
15536,
547,
8,
547,
304,
272,
408,
272,
3523,
1021,
367,
1125,
14554,
1044,
687,
12454,
370,
16919,
314,
4650,
14,
339,
1306,
862,
26,
272,
2263,
257,
746,
15536,
547,
272,
2263,
871,
4520,
26,
272,
2263,
257,
986,
272,
408,
272,
986,
199,
199,
533,
15536,
6372,
8,
6432,
547,
304,
272,
408,
16894,
1380,
4650,
7143,
6918,
4453,
282,
922,
13,
4037,
6247,
402,
900,
14,
339,
1306,
862,
26,
272,
2263,
257,
746,
15536,
6372,
272,
2263,
871,
15536,
547,
26,
272,
2263,
257,
986,
272,
408,
272,
986,
199,
199,
533,
21086,
22408,
8,
6432,
547,
304,
272,
408,
7700,
1163,
2462,
15,
1412,
365,
27267,
314,
570,
14,
339,
1306,
862,
26,
272,
2263,
257,
746,
21086,
22408,
272,
2263,
871,
15536,
547,
26,
272,
2263,
257,
986,
272,
408,
272,
986,
199,
199,
533,
15536,
4276,
8,
6432,
547,
304,
272,
408,
6432,
570,
7143,
3405,
367,
2005,
1163,
4499,
14,
339,
1306,
862,
26,
272,
2263,
257,
746,
15536,
4276,
272,
2263,
871,
15536,
547,
26,
272,
2263,
257,
986,
272,
408,
272,
986,
199,
199,
533,
1910,
831,
547,
8,
547,
304,
272,
408,
272,
3523,
1021,
367,
2552,
14554,
1044,
687,
12454,
370,
4683,
314,
4650,
14,
339,
1306,
862,
26,
272,
2263,
257,
746,
1910,
831,
547,
272,
2263,
871,
4520,
26,
272,
2263,
257,
986,
272,
408,
272,
986,
199,
199,
533,
2832,
22408,
8,
1358,
831,
547,
304,
272,
408,
16894,
1380,
376,
7427,
365,
6326,
370,
28451,
376,
625,
9325,
570,
14,
339,
1306,
862,
26,
272,
2263,
257,
746,
2832,
22408,
272,
2263,
871,
1910,
831,
547,
26,
272,
2263,
257,
986,
272,
408,
272,
986,
199,
199,
533,
2832,
5713,
6432,
8,
1358,
831,
547,
304,
272,
408,
16894,
1380,
376,
7427,
365,
6326,
370,
28451,
282,
570,
17122,
587,
14233,
14,
339,
1306,
862,
26,
272,
2263,
257,
746,
2832,
5713,
6432,
272,
2263,
871,
1910,
831,
547,
26,
272,
2263,
257,
986,
272,
408,
272,
986,
199,
199,
533,
15536,
1563,
26,
272,
408,
1563,
1021,
367,
4298,
13,
6100,
4650,
3992,
1041,
272,
347,
636,
826,
721,
277,
12,
931,
12,
25396,
29,
549,
12,
2653,
29,
403,
304,
267,
408,
267,
1306,
4650,
275,
15536,
1563,
360,
3972,
493,
358,
267,
1306,
4650,
275,
15536,
1563,
360,
3972,
493,
297,
25396,
29,
797,
9,
267,
408,
267,
291,
14,
515,
275,
931,
267,
291,
14,
831,
63,
493,
275,
747,
14,
515,
14,
4832,
8,
515,
9,
435,
3680,
831,
2,
267,
291,
14,
4269,
275,
2838,
14,
29789,
342,
267,
291,
14,
3150,
275,
747,
14,
17829,
342,
267,
340,
25396,
26,
288,
307,
275,
5796,
14,
1818,
63,
2671,
342,
288,
327,
11086,
2251,
315,
2018,
499,
14,
20,
436,
14119,
886
] |
[
199,
26204,
14,
647,
446,
16078,
13,
26083,
1503,
5068,
1089,
570,
23340,
14,
199,
199,
18153,
2018,
499,
14,
21,
7444,
1265,
4838,
499,
14,
20,
14,
3028,
199,
6432,
316,
365,
4224,
641,
282,
1126,
13,
2671,
5597,
3140,
402,
282,
1126,
13,
1412,
5597,
14,
199,
199,
7692,
26,
199,
199,
6071,
4650,
275,
15536,
1173,
360,
3972,
493,
358,
199,
6071,
862,
26,
199,
1396,
258,
4650,
14,
8174,
342,
199,
1396,
871,
21086,
22408,
26,
199,
1396,
258,
870,
283,
3972,
493,
297,
283,
374,
14233,
2575,
3530,
199,
1396,
871,
15536,
4276,
26,
199,
1396,
258,
870,
283,
3972,
493,
297,
283,
2425,
1103,
7,
84,
506,
14233,
3530,
199,
1396,
587,
26,
199,
1396,
258,
870,
283,
7808,
4650,
7,
199,
7808,
4650,
199,
6071,
870,
4650,
14,
374,
63,
9325,
342,
199,
549,
199,
6071,
4650,
14,
3221,
342,
199,
199,
6071,
4650,
275,
15536,
1173,
360,
3972,
493,
358,
199,
6071,
870,
4650,
14,
374,
63,
9325,
342,
199,
797,
199,
6071,
543,
4650,
26,
199,
1396,
259,
870,
4650,
14,
374,
63,
9325,
342,
199,
549,
199,
6071,
870,
4650,
14,
374,
63,
9325,
342,
199,
797,
199,
199,
6071,
4650,
275,
15536,
1173,
360,
3972,
493,
358,
199,
6071,
327,
2779,
365,
5849,
370,
4650,
13373,
687,
314,
2011,
2462,
1396,
199,
6071,
543,
4650,
26,
199,
1396,
258,
4650,
14,
8174,
342,
199,
1396,
199,
6071,
327,
18049,
3080,
949,
7055,
365,
16204,
12,
880,
1265,
883,
1133,
28451,
3663,
5431,
1396,
199,
6071,
870,
4650,
14,
374,
63,
9325,
342,
199,
797,
199,
199,
16836,
26,
339,
4520,
446,
1300,
1021,
367,
1163,
4967,
267,
15536,
547,
446,
1300,
1021,
367,
1006,
27267,
4967,
288,
21086,
22408,
446,
22604,
2462,
503,
2112,
2575,
15164,
314,
4650,
288,
15536,
4276,
446,
15536,
3405,
367,
2005,
1163,
4499,
267,
1910,
831,
547,
446,
1300,
1021,
367,
1006,
625,
24056,
4967,
288,
21086,
1358,
9325,
446,
3814,
1990,
440,
14233,
14,
288,
2832,
5713,
6432,
446,
3814,
1990,
14233,
1325,
440,
701,
314,
1453,
2462,
15,
1412,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
646,
984,
199,
646,
2838,
199,
646,
747,
199,
646,
5796,
199,
646,
900,
199,
646,
4011,
199,
646,
3598,
199,
646,
9143,
199,
199,
3,
9361,
543,
13663,
24,
436,
2222,
13,
25633,
24,
5459,
402,
5796,
859,
14,
199,
692,
440,
2688,
8,
12562,
12,
298,
1818,
63,
2671,
2349,
272,
5796,
14,
1818,
63,
2671,
275,
5796,
14,
1818,
4436,
199,
692,
440,
2688,
8,
12562,
14,
4436,
12,
298,
362,
63,
354,
2349,
272,
5796,
14,
4436,
14,
362,
63,
354,
275,
5796,
14,
4436,
14,
16405,
199,
199,
363,
452,
363,
275,
788,
547,
297,
283,
6432,
547,
297,
283,
6432,
6372,
297,
283,
16760,
22408,
297,
1779,
283,
6432,
4276,
297,
283,
1358,
831,
547,
297,
283,
1763,
22408,
297,
283,
1763,
5713,
6432,
297,
1779,
283,
3834,
6432,
1173,
297,
283,
31506,
694,
6432,
1173,
297,
283,
4657,
1175,
6432,
1173,
297,
1779,
283,
6432,
1563,
297,
283,
9325,
418,
199,
199,
533,
4520,
8,
1726,
304,
272,
408,
272,
3523,
1021,
367,
1163,
4967,
14,
339,
1306,
862,
26,
272,
2263,
257,
746,
4520,
272,
2263,
871,
2186,
26,
272,
2263,
257,
986,
272,
408,
272,
986,
199,
199,
533,
15536,
547,
8,
547,
304,
272,
408,
272,
3523,
1021,
367,
1125,
14554,
1044,
687,
12454,
370,
16919,
314,
4650,
14,
339,
1306,
862,
26,
272,
2263,
257,
746,
15536,
547,
272,
2263,
871,
4520,
26,
272,
2263,
257,
986,
272,
408,
272,
986,
199,
199,
533,
15536,
6372,
8,
6432,
547,
304,
272,
408,
16894,
1380,
4650,
7143,
6918,
4453,
282,
922,
13,
4037,
6247,
402,
900,
14,
339,
1306,
862,
26,
272,
2263,
257,
746,
15536,
6372,
272,
2263,
871,
15536,
547,
26,
272,
2263,
257,
986,
272,
408,
272,
986,
199,
199,
533,
21086,
22408,
8,
6432,
547,
304,
272,
408,
7700,
1163,
2462,
15,
1412,
365,
27267,
314,
570,
14,
339,
1306,
862,
26,
272,
2263,
257,
746,
21086,
22408,
272,
2263,
871,
15536,
547,
26,
272,
2263,
257,
986,
272,
408,
272,
986,
199,
199,
533,
15536,
4276,
8,
6432,
547,
304,
272,
408,
6432,
570,
7143,
3405,
367,
2005,
1163,
4499,
14,
339,
1306,
862,
26,
272,
2263,
257,
746,
15536,
4276,
272,
2263,
871,
15536,
547,
26,
272,
2263,
257,
986,
272,
408,
272,
986,
199,
199,
533,
1910,
831,
547,
8,
547,
304,
272,
408,
272,
3523,
1021,
367,
2552,
14554,
1044,
687,
12454,
370,
4683,
314,
4650,
14,
339,
1306,
862,
26,
272,
2263,
257,
746,
1910,
831,
547,
272,
2263,
871,
4520,
26,
272,
2263,
257,
986,
272,
408,
272,
986,
199,
199,
533,
2832,
22408,
8,
1358,
831,
547,
304,
272,
408,
16894,
1380,
376,
7427,
365,
6326,
370,
28451,
376,
625,
9325,
570,
14,
339,
1306,
862,
26,
272,
2263,
257,
746,
2832,
22408,
272,
2263,
871,
1910,
831,
547,
26,
272,
2263,
257,
986,
272,
408,
272,
986,
199,
199,
533,
2832,
5713,
6432,
8,
1358,
831,
547,
304,
272,
408,
16894,
1380,
376,
7427,
365,
6326,
370,
28451,
282,
570,
17122,
587,
14233,
14,
339,
1306,
862,
26,
272,
2263,
257,
746,
2832,
5713,
6432,
272,
2263,
871,
1910,
831,
547,
26,
272,
2263,
257,
986,
272,
408,
272,
986,
199,
199,
533,
15536,
1563,
26,
272,
408,
1563,
1021,
367,
4298,
13,
6100,
4650,
3992,
1041,
272,
347,
636,
826,
721,
277,
12,
931,
12,
25396,
29,
549,
12,
2653,
29,
403,
304,
267,
408,
267,
1306,
4650,
275,
15536,
1563,
360,
3972,
493,
358,
267,
1306,
4650,
275,
15536,
1563,
360,
3972,
493,
297,
25396,
29,
797,
9,
267,
408,
267,
291,
14,
515,
275,
931,
267,
291,
14,
831,
63,
493,
275,
747,
14,
515,
14,
4832,
8,
515,
9,
435,
3680,
831,
2,
267,
291,
14,
4269,
275,
2838,
14,
29789,
342,
267,
291,
14,
3150,
275,
747,
14,
17829,
342,
267,
340,
25396,
26,
288,
307,
275,
5796,
14,
1818,
63,
2671,
342,
288,
327,
11086,
2251,
315,
2018,
499,
14,
20,
436,
14119,
886,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
redhat-openstack/django
|
django/conf/locale/sl/formats.py
|
200
|
2120
|
# -*- encoding: utf-8 -*-
# This file is distributed under the same license as the Django package.
#
from __future__ import unicode_literals
# The *_FORMAT strings use the Django date format syntax,
# see http://docs.djangoproject.com/en/dev/ref/templates/builtins/#date
DATE_FORMAT = 'd. F Y'
TIME_FORMAT = 'H:i:s'
DATETIME_FORMAT = 'j. F Y. H:i'
YEAR_MONTH_FORMAT = 'F Y'
MONTH_DAY_FORMAT = 'j. F'
SHORT_DATE_FORMAT = 'j. M. Y'
SHORT_DATETIME_FORMAT = 'j.n.Y. H:i'
FIRST_DAY_OF_WEEK = 0
# The *_INPUT_FORMATS strings use the Python strftime format syntax,
# see http://docs.python.org/library/datetime.html#strftime-strptime-behavior
DATE_INPUT_FORMATS = (
'%d.%m.%Y', '%d.%m.%y', # '25.10.2006', '25.10.06'
'%d-%m-%Y', # '25-10-2006'
'%d. %m. %Y', '%d. %m. %y', # '25. 10. 2006', '25. 10. 06'
)
DATETIME_INPUT_FORMATS = (
'%d.%m.%Y %H:%M:%S', # '25.10.2006 14:30:59'
'%d.%m.%Y %H:%M:%S.%f', # '25.10.2006 14:30:59.000200'
'%d.%m.%Y %H:%M', # '25.10.2006 14:30'
'%d.%m.%Y', # '25.10.2006'
'%d.%m.%y %H:%M:%S', # '25.10.06 14:30:59'
'%d.%m.%y %H:%M:%S.%f', # '25.10.06 14:30:59.000200'
'%d.%m.%y %H:%M', # '25.10.06 14:30'
'%d.%m.%y', # '25.10.06'
'%d-%m-%Y %H:%M:%S', # '25-10-2006 14:30:59'
'%d-%m-%Y %H:%M:%S.%f', # '25-10-2006 14:30:59.000200'
'%d-%m-%Y %H:%M', # '25-10-2006 14:30'
'%d-%m-%Y', # '25-10-2006'
'%d. %m. %Y %H:%M:%S', # '25. 10. 2006 14:30:59'
'%d. %m. %Y %H:%M:%S.%f', # '25. 10. 2006 14:30:59.000200'
'%d. %m. %Y %H:%M', # '25. 10. 2006 14:30'
'%d. %m. %Y', # '25. 10. 2006'
'%d. %m. %y %H:%M:%S', # '25. 10. 06 14:30:59'
'%d. %m. %y %H:%M:%S.%f', # '25. 10. 06 14:30:59.000200'
'%d. %m. %y %H:%M', # '25. 10. 06 14:30'
'%d. %m. %y', # '25. 10. 06'
)
DECIMAL_SEPARATOR = ','
THOUSAND_SEPARATOR = '.'
NUMBER_GROUPING = 3
|
bsd-3-clause
|
[
3,
1882,
2644,
26,
2774,
13,
24,
1882,
199,
3,
961,
570,
365,
1854,
1334,
314,
2011,
4190,
465,
314,
5634,
2559,
14,
199,
3,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
3,
710,
20841,
4807,
3326,
675,
314,
5634,
1434,
1475,
6302,
12,
199,
3,
1937,
1455,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
2374,
15,
1121,
15,
5876,
15,
10372,
12645,
602,
199,
5390,
63,
4807,
275,
283,
68,
14,
481,
1488,
7,
199,
4961,
63,
4807,
275,
283,
40,
26,
73,
26,
83,
7,
199,
12488,
63,
4807,
275,
283,
74,
14,
481,
1488,
14,
869,
26,
73,
7,
199,
19216,
63,
16413,
63,
4807,
275,
283,
38,
1488,
7,
199,
16413,
63,
11655,
63,
4807,
275,
283,
74,
14,
481,
7,
199,
13003,
63,
5390,
63,
4807,
275,
283,
74,
14,
603,
14,
1488,
7,
199,
13003,
63,
12488,
63,
4807,
275,
283,
74,
14,
78,
14,
57,
14,
869,
26,
73,
7,
199,
12903,
63,
11655,
63,
3359,
63,
24929,
275,
378,
199,
199,
3,
710,
20841,
7321,
63,
14019,
3326,
675,
314,
2018,
14053,
1475,
6302,
12,
199,
3,
1937,
1455,
921,
4757,
14,
1548,
14,
1308,
15,
4342,
15,
2083,
14,
1360,
3,
6205,
13,
9866,
13,
17537,
199,
5390,
63,
7321,
63,
14019,
275,
334,
272,
1543,
68,
4111,
77,
4111,
57,
297,
1543,
68,
4111,
77,
4111,
89,
297,
260,
327,
283,
821,
14,
709,
14,
7968,
297,
283,
821,
14,
709,
14,
1690,
7,
272,
1543,
68,
3295,
77,
3295,
57,
297,
9326,
327,
283,
821,
13,
709,
13,
7968,
7,
272,
1543,
68,
14,
450,
77,
14,
450,
57,
297,
1543,
68,
14,
450,
77,
14,
450,
89,
297,
258,
327,
283,
821,
14,
1616,
14,
8315,
297,
283,
821,
14,
1616,
14,
24293,
7,
199,
9,
199,
199,
12488,
63,
7321,
63,
14019,
275,
334,
272,
1543,
68,
4111,
77,
4111,
57,
450,
40,
2689,
45,
2689,
51,
297,
3322,
327,
283,
821,
14,
709,
14,
7968,
4329,
26,
1216,
26,
1427,
7,
272,
1543,
68,
4111,
77,
4111,
57,
450,
40,
2689,
45,
2689,
51,
4111,
70,
297,
260,
327,
283,
821,
14,
709,
14,
7968,
4329,
26,
1216,
26,
1427,
14,
25080,
7,
272,
1543,
68,
4111,
77,
4111,
57,
450,
40,
2689,
45,
297,
5185,
327,
283,
821,
14,
709,
14,
7968,
4329,
26,
1216,
7,
272,
1543,
68,
4111,
77,
4111,
57,
297,
9326,
327,
283,
821,
14,
709,
14,
7968,
7,
272,
1543,
68,
4111,
77,
4111,
89,
450,
40,
2689,
45,
2689,
51,
297,
3322,
327,
283,
821,
14,
709,
14,
1690,
4329,
26,
1216,
26,
1427,
7,
272,
1543,
68,
4111,
77,
4111,
89,
450,
40,
2689,
45,
2689,
51,
4111,
70,
297,
260,
327,
283,
821,
14,
709,
14,
1690,
4329,
26,
1216,
26,
1427,
14,
25080,
7,
272,
1543,
68,
4111,
77,
4111,
89,
450,
40,
2689,
45,
297,
4483,
327,
283,
821,
14,
709,
14,
1690,
4329,
26,
1216,
7,
272,
1543,
68,
4111,
77,
4111,
89,
297,
9326,
327,
283,
821,
14,
709,
14,
1690,
7,
272,
1543,
68,
3295,
77,
3295,
57,
450,
40,
2689,
45,
2689,
51,
297,
3322,
327,
283,
821,
13,
709,
13,
7968,
4329,
26,
1216,
26,
1427,
7,
272,
1543,
68,
3295,
77,
3295,
57,
450,
40,
2689,
45,
2689,
51,
4111,
70,
297,
260,
327,
283,
821,
13,
709,
13,
7968,
4329,
26,
1216,
26,
1427,
14,
25080,
7,
272,
1543,
68,
3295,
77,
3295,
57,
450,
40,
2689,
45,
297,
5185,
327,
283,
821,
13,
709,
13,
7968,
4329,
26,
1216,
7,
272,
1543,
68,
3295,
77,
3295,
57,
297,
9326,
327,
283,
821,
13,
709,
13,
7968,
7,
272,
1543,
68,
14,
450,
77,
14,
450,
57,
450,
40,
2689,
45,
2689,
51,
297,
3515,
327,
283,
821,
14,
1616,
14,
8315,
4329,
26,
1216,
26,
1427,
7,
272,
1543,
68,
14,
450,
77,
14,
450,
57,
450,
40,
2689,
45,
2689,
51,
4111,
70,
297,
755,
327,
283,
821,
14,
1616,
14,
8315,
4329,
26,
1216,
26,
1427,
14,
25080,
7,
272,
1543,
68,
14,
450,
77,
14,
450,
57,
450,
40,
2689,
45,
297,
3777,
327,
283,
821,
14,
1616,
14,
8315,
4329,
26,
1216,
7,
272,
1543,
68,
14,
450,
77,
14,
450,
57,
297,
7861,
327,
283,
821,
14,
1616,
14,
8315,
7,
272,
1543,
68,
14,
450,
77,
14,
450,
89,
450,
40,
2689,
45,
2689,
51,
297,
3515,
327,
283,
821,
14,
1616,
14,
24293,
4329,
26,
1216,
26,
1427,
7,
272,
1543,
68,
14,
450,
77,
14,
450,
89,
450,
40,
2689,
45,
2689,
51,
4111,
70,
297,
755,
327,
283,
821,
14,
1616,
14,
24293,
4329,
26,
1216,
26,
1427,
14,
25080,
7,
272,
1543,
68,
14,
450,
77,
14,
450,
89,
450,
40,
2689,
45,
297,
3777,
327,
283,
821,
14,
1616,
14,
24293,
4329,
26,
1216,
7,
272,
1543,
68,
14,
450,
77,
14,
450,
89,
297,
7861,
327,
283,
821,
14,
1616,
14,
24293,
7,
199,
9,
199,
199,
23925,
63,
15828,
275,
13647,
199,
28714,
63,
15828,
275,
7815,
199,
9190,
63,
7823,
1206,
275,
650,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2644,
26,
2774,
13,
24,
1882,
199,
3,
961,
570,
365,
1854,
1334,
314,
2011,
4190,
465,
314,
5634,
2559,
14,
199,
3,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
3,
710,
20841,
4807,
3326,
675,
314,
5634,
1434,
1475,
6302,
12,
199,
3,
1937,
1455,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
2374,
15,
1121,
15,
5876,
15,
10372,
12645,
602,
199,
5390,
63,
4807,
275,
283,
68,
14,
481,
1488,
7,
199,
4961,
63,
4807,
275,
283,
40,
26,
73,
26,
83,
7,
199,
12488,
63,
4807,
275,
283,
74,
14,
481,
1488,
14,
869,
26,
73,
7,
199,
19216,
63,
16413,
63,
4807,
275,
283,
38,
1488,
7,
199,
16413,
63,
11655,
63,
4807,
275,
283,
74,
14,
481,
7,
199,
13003,
63,
5390,
63,
4807,
275,
283,
74,
14,
603,
14,
1488,
7,
199,
13003,
63,
12488,
63,
4807,
275,
283,
74,
14,
78,
14,
57,
14,
869,
26,
73,
7,
199,
12903,
63,
11655,
63,
3359,
63,
24929,
275,
378,
199,
199,
3,
710,
20841,
7321,
63,
14019,
3326,
675,
314,
2018,
14053,
1475,
6302,
12,
199,
3,
1937,
1455,
921,
4757,
14,
1548,
14,
1308,
15,
4342,
15,
2083,
14,
1360,
3,
6205,
13,
9866,
13,
17537,
199,
5390,
63,
7321,
63,
14019,
275,
334,
272,
1543,
68,
4111,
77,
4111,
57,
297,
1543,
68,
4111,
77,
4111,
89,
297,
260,
327,
283,
821,
14,
709,
14,
7968,
297,
283,
821,
14,
709,
14,
1690,
7,
272,
1543,
68,
3295,
77,
3295,
57,
297,
9326,
327,
283,
821,
13,
709,
13,
7968,
7,
272,
1543,
68,
14,
450,
77,
14,
450,
57,
297,
1543,
68,
14,
450,
77,
14,
450,
89,
297,
258,
327,
283,
821,
14,
1616,
14,
8315,
297,
283,
821,
14,
1616,
14,
24293,
7,
199,
9,
199,
199,
12488,
63,
7321,
63,
14019,
275,
334,
272,
1543,
68,
4111,
77,
4111,
57,
450,
40,
2689,
45,
2689,
51,
297,
3322,
327,
283,
821,
14,
709,
14,
7968,
4329,
26,
1216,
26,
1427,
7,
272,
1543,
68,
4111,
77,
4111,
57,
450,
40,
2689,
45,
2689,
51,
4111,
70,
297,
260,
327,
283,
821,
14,
709,
14,
7968,
4329,
26,
1216,
26,
1427,
14,
25080,
7,
272,
1543,
68,
4111,
77,
4111,
57,
450,
40,
2689,
45,
297,
5185,
327,
283,
821,
14,
709,
14,
7968,
4329,
26,
1216,
7,
272,
1543,
68,
4111,
77,
4111,
57,
297,
9326,
327,
283,
821,
14,
709,
14,
7968,
7,
272,
1543,
68,
4111,
77,
4111,
89,
450,
40,
2689,
45,
2689,
51,
297,
3322,
327,
283,
821,
14,
709,
14,
1690,
4329,
26,
1216,
26,
1427,
7,
272,
1543,
68,
4111,
77,
4111,
89,
450,
40,
2689,
45,
2689,
51,
4111,
70,
297,
260,
327,
283,
821,
14,
709,
14,
1690,
4329,
26,
1216,
26,
1427,
14,
25080,
7,
272,
1543,
68,
4111,
77,
4111,
89,
450,
40,
2689,
45,
297,
4483,
327,
283,
821,
14,
709,
14,
1690,
4329,
26,
1216,
7,
272,
1543,
68,
4111,
77,
4111,
89,
297,
9326,
327,
283,
821,
14,
709,
14,
1690,
7,
272,
1543,
68,
3295,
77,
3295,
57,
450,
40,
2689,
45,
2689,
51,
297,
3322,
327,
283,
821,
13,
709,
13,
7968,
4329,
26,
1216,
26,
1427,
7,
272,
1543,
68,
3295,
77,
3295,
57,
450,
40,
2689,
45,
2689,
51,
4111,
70,
297,
260,
327,
283,
821,
13,
709,
13,
7968,
4329,
26,
1216,
26,
1427,
14,
25080,
7,
272,
1543,
68,
3295,
77,
3295,
57,
450,
40,
2689,
45,
297,
5185,
327,
283,
821,
13,
709,
13,
7968,
4329,
26,
1216,
7,
272,
1543,
68,
3295,
77,
3295,
57,
297,
9326,
327,
283,
821,
13,
709,
13,
7968,
7,
272,
1543,
68,
14,
450,
77,
14,
450,
57,
450,
40,
2689,
45,
2689,
51,
297,
3515,
327,
283,
821,
14,
1616,
14,
8315,
4329,
26,
1216,
26,
1427,
7,
272,
1543,
68,
14,
450,
77,
14,
450,
57,
450,
40,
2689,
45,
2689,
51,
4111,
70,
297,
755,
327,
283,
821,
14,
1616,
14,
8315,
4329,
26,
1216,
26,
1427,
14,
25080,
7,
272,
1543,
68,
14,
450,
77,
14,
450,
57,
450,
40,
2689,
45,
297,
3777,
327,
283,
821,
14,
1616,
14,
8315,
4329,
26,
1216,
7,
272,
1543,
68,
14,
450,
77,
14,
450,
57,
297,
7861,
327,
283,
821,
14,
1616,
14,
8315,
7,
272,
1543,
68,
14,
450,
77,
14,
450,
89,
450,
40,
2689,
45,
2689,
51,
297,
3515,
327,
283,
821,
14,
1616,
14,
24293,
4329,
26,
1216,
26,
1427,
7,
272,
1543,
68,
14,
450,
77,
14,
450,
89,
450,
40,
2689,
45,
2689,
51,
4111,
70,
297,
755,
327,
283,
821,
14,
1616,
14,
24293,
4329,
26,
1216,
26,
1427,
14,
25080,
7,
272,
1543,
68,
14,
450,
77,
14,
450,
89,
450,
40,
2689,
45,
297,
3777,
327,
283,
821,
14,
1616,
14,
24293,
4329,
26,
1216,
7,
272,
1543,
68,
14,
450,
77,
14,
450,
89,
297,
7861,
327,
283,
821,
14,
1616,
14,
24293,
7,
199,
9,
199,
199,
23925,
63,
15828,
275,
13647,
199,
28714,
63,
15828,
275,
7815,
199,
9190,
63,
7823,
1206,
275,
650,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
jaredks/euler
|
011/011.py
|
1
|
2013
|
from operator import mul
grid = '''
08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08
49 49 99 40 17 81 18 57 60 87 17 40 98 43 69 48 04 56 62 00
81 49 31 73 55 79 14 29 93 71 40 67 53 88 30 03 49 13 36 65
52 70 95 23 04 60 11 42 69 24 68 56 01 32 56 71 37 02 36 91
22 31 16 71 51 67 63 89 41 92 36 54 22 40 40 28 66 33 13 80
24 47 32 60 99 03 45 02 44 75 33 53 78 36 84 20 35 17 12 50
32 98 81 28 64 23 67 10 26 38 40 67 59 54 70 66 18 38 64 70
67 26 20 68 02 62 12 20 95 63 94 39 63 08 40 91 66 49 94 21
24 55 58 05 66 73 99 26 97 17 78 78 96 83 14 88 34 89 63 72
21 36 23 09 75 00 76 44 20 45 35 14 00 61 33 97 34 31 33 95
78 17 53 28 22 75 31 67 15 94 03 80 04 62 16 14 09 53 56 92
16 39 05 42 96 35 31 47 55 58 88 24 00 17 54 24 36 29 85 57
86 56 00 48 35 71 89 07 05 44 44 37 44 60 21 58 51 54 17 58
19 80 81 68 05 94 47 69 28 73 92 13 86 52 17 77 04 89 55 40
04 52 08 83 97 35 99 16 07 97 57 32 16 26 26 79 33 27 98 66
88 36 68 87 57 62 20 72 03 46 33 67 46 55 12 32 63 93 53 69
04 42 16 73 38 25 39 11 24 94 72 18 08 46 29 32 40 62 76 36
20 69 36 41 72 30 23 88 34 62 99 69 82 67 59 85 74 04 36 16
20 73 35 29 78 31 90 01 74 31 49 71 48 86 81 16 23 57 05 54
01 70 54 71 83 51 54 69 16 92 33 48 61 43 52 01 89 19 67 48
'''
grid = [map(int, l.split()) for l in grid.strip().split('\n')]
if __name__ == "__main__":
n = 4
s = 20
m = 0
# HORIZONTAL
for i in xrange(s):
for j in xrange(s-n+1):
m = max(m, reduce(mul, (grid[i][j+k] for k in xrange(n))))
# VERTICAL
for i in xrange(s-n+1):
for j in xrange(s):
m = max(m, reduce(mul, (grid[i+k][j] for k in xrange(n))))
# DIAGONAL (TOP-LEFT, BOTTOM-RIGHT)
for i in xrange(s-n+1):
for j in xrange(s-n+1):
m = max(m, reduce(mul, (grid[i+k][j+k] for k in xrange(n))))
# DIAGONAL (TOP-RIGHT, BOTTOM-LEFT)
for i in xrange(n-1, s):
for j in xrange(s-n+1):
m = max(m, reduce(mul, (grid[i-k][j+k] for k in xrange(n))))
print m
|
bsd-3-clause
|
[
504,
4182,
492,
19207,
199,
199,
3825,
275,
1449,
199,
2036,
12497,
6928,
15997,
10448,
4114,
8733,
6335,
8733,
13098,
28527,
22528,
24937,
14679,
14589,
3144,
5238,
8375,
21358,
19363,
199,
1887,
12260,
8806,
6335,
5557,
19071,
6155,
12699,
5212,
10513,
5557,
6335,
16096,
11851,
14610,
9615,
28527,
12001,
16202,
8733,
199,
2835,
12260,
7105,
18525,
12766,
13734,
4329,
7349,
18969,
17245,
6335,
13296,
13564,
10523,
4233,
30569,
12260,
4944,
8780,
11738,
199,
2528,
10045,
16102,
6546,
28527,
5212,
4119,
5685,
14610,
5504,
10851,
12001,
17163,
4337,
12001,
17245,
6877,
12497,
8780,
21358,
199,
1081,
7105,
3193,
17245,
8026,
13296,
13668,
17838,
13385,
20140,
8780,
13470,
6928,
6335,
6335,
7294,
14157,
9404,
4944,
5939,
199,
1194,
10954,
4337,
5212,
8806,
30569,
10416,
12497,
10868,
13098,
9404,
13564,
14679,
8780,
8264,
3388,
8685,
5557,
3144,
5238,
199,
708,
16096,
19071,
7294,
5049,
6546,
13296,
1616,
7875,
10448,
6335,
13296,
8155,
13470,
10045,
14157,
6155,
10448,
5049,
10045,
199,
1822,
7875,
3388,
10851,
12497,
16202,
3144,
3388,
16102,
13668,
18729,
10551,
13668,
19363,
6335,
21358,
14157,
12260,
18729,
7829,
199,
1194,
12766,
13713,
22528,
14157,
18525,
8806,
7875,
15997,
5557,
14679,
14679,
15580,
20582,
4329,
10523,
8177,
17838,
13668,
15323,
199,
2025,
8780,
6546,
21798,
13098,
8733,
14646,
10868,
3388,
10416,
8685,
4329,
8733,
17017,
9404,
15997,
8177,
7105,
9404,
16102,
199,
2277,
5557,
13564,
7294,
6928,
13098,
7105,
13296,
4114,
18729,
30569,
5939,
28527,
16202,
3193,
4329,
21798,
13564,
12001,
20140,
199,
975,
10551,
22528,
5685,
15580,
8685,
7105,
10954,
12766,
13713,
10523,
5504,
8733,
5557,
13470,
5504,
8780,
7349,
16412,
12699,
199,
1184,
12001,
8733,
9615,
8685,
17245,
17838,
24937,
22528,
10868,
10868,
6877,
10868,
5212,
7829,
13713,
8026,
13470,
5557,
13713,
199,
1167,
5939,
19071,
10851,
22528,
18729,
10954,
14610,
7294,
18525,
20140,
4944,
10300,
14589,
5557,
8375,
28527,
17838,
12766,
6335,
199,
966,
14589,
19363,
20582,
15997,
8685,
8806,
3193,
24937,
15997,
12699,
4337,
3193,
7875,
7875,
13734,
9404,
8087,
16096,
14157,
199,
1299,
8780,
10851,
10513,
12699,
16202,
3388,
15323,
30569,
12426,
9404,
13296,
12426,
12766,
3144,
4337,
13668,
18969,
13564,
14610,
199,
966,
5685,
3193,
18525,
10448,
5661,
10551,
4119,
5504,
18729,
15323,
6155,
19363,
12426,
7349,
4337,
6335,
16202,
14646,
8780,
199,
1165,
14610,
8780,
13385,
15323,
4233,
6546,
10523,
8177,
16202,
8806,
14610,
18051,
13296,
8155,
16412,
9720,
28527,
8780,
3193,
199,
1165,
18525,
8685,
7349,
14679,
7105,
9137,
17163,
9720,
7105,
12260,
17245,
9615,
10300,
19071,
3193,
6546,
12699,
22528,
13470,
199,
614,
10045,
13470,
17245,
20582,
8026,
13470,
14610,
3193,
20140,
9404,
9615,
17017,
11851,
14589,
17163,
17838,
5851,
13296,
9615,
199,
2344,
199,
3825,
275,
359,
1130,
8,
442,
12,
634,
14,
1294,
1012,
367,
634,
315,
6068,
14,
1913,
1252,
1294,
2258,
78,
5440,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
302,
275,
841,
272,
308,
275,
3388,
272,
333,
275,
378,
339,
327,
8724,
272,
367,
284,
315,
4945,
8,
83,
304,
267,
367,
1335,
315,
4945,
8,
83,
13,
78,
11,
17,
304,
288,
333,
275,
1390,
8,
77,
12,
7114,
8,
3703,
12,
334,
3825,
59,
73,
1527,
74,
11,
75,
61,
367,
1022,
315,
4945,
8,
78,
7845,
339,
327,
8267,
272,
367,
284,
315,
4945,
8,
83,
13,
78,
11,
17,
304,
267,
367,
1335,
315,
4945,
8,
83,
304,
288,
333,
275,
1390,
8,
77,
12,
7114,
8,
3703,
12,
334,
3825,
59,
73,
11,
75,
1527,
74,
61,
367,
1022,
315,
4945,
8,
78,
7845,
339,
327,
5266,
1254,
615,
748,
334,
11422,
13,
9894,
12,
699,
1387,
19731,
13,
12811,
9,
272,
367,
284,
315,
4945,
8,
83,
13,
78,
11,
17,
304,
267,
367,
1335,
315,
4945,
8,
83,
13,
78,
11,
17,
304,
288,
333,
275,
1390,
8,
77,
12,
7114,
8,
3703,
12,
334,
3825,
59,
73,
11,
75,
1527,
74,
11,
75,
61,
367,
1022,
315,
4945,
8,
78,
7845,
339,
327,
5266,
1254,
615,
748,
334,
11422,
13,
12811,
12,
699,
1387,
19731,
13,
9894,
9,
272,
367,
284,
315,
4945,
8,
78,
13,
17,
12,
308,
304,
267,
367,
1335,
315,
4945,
8,
83,
13,
78,
11,
17,
304,
288,
333,
275,
1390,
8,
77,
12,
7114,
8,
3703,
12,
334,
3825,
59,
73,
13,
75,
1527,
74,
11,
75,
61,
367,
1022,
315,
4945,
8,
78,
7845,
339,
870,
333,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
4182,
492,
19207,
199,
199,
3825,
275,
1449,
199,
2036,
12497,
6928,
15997,
10448,
4114,
8733,
6335,
8733,
13098,
28527,
22528,
24937,
14679,
14589,
3144,
5238,
8375,
21358,
19363,
199,
1887,
12260,
8806,
6335,
5557,
19071,
6155,
12699,
5212,
10513,
5557,
6335,
16096,
11851,
14610,
9615,
28527,
12001,
16202,
8733,
199,
2835,
12260,
7105,
18525,
12766,
13734,
4329,
7349,
18969,
17245,
6335,
13296,
13564,
10523,
4233,
30569,
12260,
4944,
8780,
11738,
199,
2528,
10045,
16102,
6546,
28527,
5212,
4119,
5685,
14610,
5504,
10851,
12001,
17163,
4337,
12001,
17245,
6877,
12497,
8780,
21358,
199,
1081,
7105,
3193,
17245,
8026,
13296,
13668,
17838,
13385,
20140,
8780,
13470,
6928,
6335,
6335,
7294,
14157,
9404,
4944,
5939,
199,
1194,
10954,
4337,
5212,
8806,
30569,
10416,
12497,
10868,
13098,
9404,
13564,
14679,
8780,
8264,
3388,
8685,
5557,
3144,
5238,
199,
708,
16096,
19071,
7294,
5049,
6546,
13296,
1616,
7875,
10448,
6335,
13296,
8155,
13470,
10045,
14157,
6155,
10448,
5049,
10045,
199,
1822,
7875,
3388,
10851,
12497,
16202,
3144,
3388,
16102,
13668,
18729,
10551,
13668,
19363,
6335,
21358,
14157,
12260,
18729,
7829,
199,
1194,
12766,
13713,
22528,
14157,
18525,
8806,
7875,
15997,
5557,
14679,
14679,
15580,
20582,
4329,
10523,
8177,
17838,
13668,
15323,
199,
2025,
8780,
6546,
21798,
13098,
8733,
14646,
10868,
3388,
10416,
8685,
4329,
8733,
17017,
9404,
15997,
8177,
7105,
9404,
16102,
199,
2277,
5557,
13564,
7294,
6928,
13098,
7105,
13296,
4114,
18729,
30569,
5939,
28527,
16202,
3193,
4329,
21798,
13564,
12001,
20140,
199,
975,
10551,
22528,
5685,
15580,
8685,
7105,
10954,
12766,
13713,
10523,
5504,
8733,
5557,
13470,
5504,
8780,
7349,
16412,
12699,
199,
1184,
12001,
8733,
9615,
8685,
17245,
17838,
24937,
22528,
10868,
10868,
6877,
10868,
5212,
7829,
13713,
8026,
13470,
5557,
13713,
199,
1167,
5939,
19071,
10851,
22528,
18729,
10954,
14610,
7294,
18525,
20140,
4944,
10300,
14589,
5557,
8375,
28527,
17838,
12766,
6335,
199,
966,
14589,
19363,
20582,
15997,
8685,
8806,
3193,
24937,
15997,
12699,
4337,
3193,
7875,
7875,
13734,
9404,
8087,
16096,
14157,
199,
1299,
8780,
10851,
10513,
12699,
16202,
3388,
15323,
30569,
12426,
9404,
13296,
12426,
12766,
3144,
4337,
13668,
18969,
13564,
14610,
199,
966,
5685,
3193,
18525,
10448,
5661,
10551,
4119,
5504,
18729,
15323,
6155,
19363,
12426,
7349,
4337,
6335,
16202,
14646,
8780,
199,
1165,
14610,
8780,
13385,
15323,
4233,
6546,
10523,
8177,
16202,
8806,
14610,
18051,
13296,
8155,
16412,
9720,
28527,
8780,
3193,
199,
1165,
18525,
8685,
7349,
14679,
7105,
9137,
17163,
9720,
7105,
12260,
17245,
9615,
10300,
19071,
3193,
6546,
12699,
22528,
13470,
199,
614,
10045,
13470,
17245,
20582,
8026,
13470,
14610,
3193,
20140,
9404,
9615,
17017,
11851,
14589,
17163,
17838,
5851,
13296,
9615,
199,
2344,
199,
3825,
275,
359,
1130,
8,
442,
12,
634,
14,
1294,
1012,
367,
634,
315,
6068,
14,
1913,
1252,
1294,
2258,
78,
5440,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
302,
275,
841,
272,
308,
275,
3388,
272,
333,
275,
378,
339,
327,
8724,
272,
367,
284,
315,
4945,
8,
83,
304,
267,
367,
1335,
315,
4945,
8,
83,
13,
78,
11,
17,
304,
288,
333,
275,
1390,
8,
77,
12,
7114,
8,
3703,
12,
334,
3825,
59,
73,
1527,
74,
11,
75,
61,
367,
1022,
315,
4945,
8,
78,
7845,
339,
327,
8267,
272,
367,
284,
315,
4945,
8,
83,
13,
78,
11,
17,
304,
267,
367,
1335,
315,
4945,
8,
83,
304,
288,
333,
275,
1390,
8,
77,
12,
7114,
8,
3703,
12,
334,
3825,
59,
73,
11,
75,
1527,
74,
61,
367,
1022,
315,
4945,
8,
78,
7845,
339,
327,
5266,
1254,
615,
748,
334,
11422,
13,
9894,
12,
699,
1387,
19731,
13,
12811,
9,
272,
367,
284,
315,
4945,
8,
83,
13,
78,
11,
17,
304,
267,
367,
1335,
315,
4945,
8,
83,
13,
78,
11,
17,
304,
288,
333,
275,
1390,
8,
77,
12,
7114,
8,
3703,
12,
334,
3825,
59,
73,
11,
75,
1527,
74,
11,
75,
61,
367,
1022,
315,
4945,
8,
78,
7845,
339,
327,
5266,
1254,
615,
748,
334,
11422,
13,
12811,
12,
699,
1387,
19731,
13,
9894,
9,
272,
367,
284,
315,
4945,
8,
78,
13,
17,
12,
308,
304,
267,
367,
1335,
315,
4945,
8,
83,
13,
78,
11,
17,
304,
288,
333,
275,
1390,
8,
77,
12,
7114,
8,
3703,
12,
334,
3825,
59,
73,
13,
75,
1527,
74,
11,
75,
61,
367,
1022,
315,
4945,
8,
78,
7845,
339,
870,
333,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
batxes/4c2vhic
|
SHH_WT_models/SHH_WT_models_final_output_0.1_-0.1_11000/SHH_WT_models26485.py
|
4
|
17581
|
import _surface
import chimera
try:
import chimera.runCommand
except:
pass
from VolumePath import markerset as ms
try:
from VolumePath import Marker_Set, Link
new_marker_set=Marker_Set
except:
from VolumePath import volume_path_dialog
d= volume_path_dialog(True)
new_marker_set= d.new_marker_set
marker_sets={}
surf_sets={}
if "particle_0 geometry" not in marker_sets:
s=new_marker_set('particle_0 geometry')
marker_sets["particle_0 geometry"]=s
s= marker_sets["particle_0 geometry"]
mark=s.place_marker((5963.78, 9495.23, 10964.4), (0.7, 0.7, 0.7), 890.203)
if "particle_1 geometry" not in marker_sets:
s=new_marker_set('particle_1 geometry')
marker_sets["particle_1 geometry"]=s
s= marker_sets["particle_1 geometry"]
mark=s.place_marker((6143.39, 8942.29, 9375.15), (0.7, 0.7, 0.7), 792.956)
if "particle_2 geometry" not in marker_sets:
s=new_marker_set('particle_2 geometry')
marker_sets["particle_2 geometry"]=s
s= marker_sets["particle_2 geometry"]
mark=s.place_marker((4695.21, 8667.07, 8154.84), (0.7, 0.7, 0.7), 856.786)
if "particle_3 geometry" not in marker_sets:
s=new_marker_set('particle_3 geometry')
marker_sets["particle_3 geometry"]=s
s= marker_sets["particle_3 geometry"]
mark=s.place_marker((4153.72, 10399.4, 9633.64), (0.7, 0.7, 0.7), 963.679)
if "particle_4 geometry" not in marker_sets:
s=new_marker_set('particle_4 geometry')
marker_sets["particle_4 geometry"]=s
s= marker_sets["particle_4 geometry"]
mark=s.place_marker((2666.22, 10179.4, 9428.64), (0.7, 0.7, 0.7), 761.442)
if "particle_5 geometry" not in marker_sets:
s=new_marker_set('particle_5 geometry')
marker_sets["particle_5 geometry"]=s
s= marker_sets["particle_5 geometry"]
mark=s.place_marker((1931.24, 8366.64, 7897.94), (0.7, 0.7, 0.7), 961.183)
if "particle_6 geometry" not in marker_sets:
s=new_marker_set('particle_6 geometry')
marker_sets["particle_6 geometry"]=s
s= marker_sets["particle_6 geometry"]
mark=s.place_marker((1464.66, 6804.33, 7467.3), (0.7, 0.7, 0.7), 753.151)
if "particle_7 geometry" not in marker_sets:
s=new_marker_set('particle_7 geometry')
marker_sets["particle_7 geometry"]=s
s= marker_sets["particle_7 geometry"]
mark=s.place_marker((1078.77, 7461.67, 8066.38), (1, 0.7, 0), 1098.07)
if "particle_8 geometry" not in marker_sets:
s=new_marker_set('particle_8 geometry')
marker_sets["particle_8 geometry"]=s
s= marker_sets["particle_8 geometry"]
mark=s.place_marker((2039.59, 5155.99, 6912.7), (0.7, 0.7, 0.7), 1010.42)
if "particle_9 geometry" not in marker_sets:
s=new_marker_set('particle_9 geometry')
marker_sets["particle_9 geometry"]=s
s= marker_sets["particle_9 geometry"]
mark=s.place_marker((1843.94, 3708.08, 7791.24), (1, 0.7, 0), 821.043)
if "particle_10 geometry" not in marker_sets:
s=new_marker_set('particle_10 geometry')
marker_sets["particle_10 geometry"]=s
s= marker_sets["particle_10 geometry"]
mark=s.place_marker((2842.19, 2781.71, 6500.63), (0.7, 0.7, 0.7), 873.876)
if "particle_11 geometry" not in marker_sets:
s=new_marker_set('particle_11 geometry')
marker_sets["particle_11 geometry"]=s
s= marker_sets["particle_11 geometry"]
mark=s.place_marker((4123.1, 3361.43, 7049.51), (0.7, 0.7, 0.7), 625.532)
if "particle_12 geometry" not in marker_sets:
s=new_marker_set('particle_12 geometry')
marker_sets["particle_12 geometry"]=s
s= marker_sets["particle_12 geometry"]
mark=s.place_marker((5657.24, 3552.18, 6977.22), (0.7, 0.7, 0.7), 880.474)
if "particle_13 geometry" not in marker_sets:
s=new_marker_set('particle_13 geometry')
marker_sets["particle_13 geometry"]=s
s= marker_sets["particle_13 geometry"]
mark=s.place_marker((5476.74, 4240.79, 8359.34), (0.7, 0.7, 0.7), 659.161)
if "particle_14 geometry" not in marker_sets:
s=new_marker_set('particle_14 geometry')
marker_sets["particle_14 geometry"]=s
s= marker_sets["particle_14 geometry"]
mark=s.place_marker((7411.23, 3889.99, 9519.66), (0.7, 0.7, 0.7), 831.745)
if "particle_15 geometry" not in marker_sets:
s=new_marker_set('particle_15 geometry')
marker_sets["particle_15 geometry"]=s
s= marker_sets["particle_15 geometry"]
mark=s.place_marker((10219.4, 5085.65, 9117.87), (0.7, 0.7, 0.7), 803.065)
if "particle_16 geometry" not in marker_sets:
s=new_marker_set('particle_16 geometry')
marker_sets["particle_16 geometry"]=s
s= marker_sets["particle_16 geometry"]
mark=s.place_marker((9897.06, 6295.88, 7627.35), (0.7, 0.7, 0.7), 610.262)
if "particle_17 geometry" not in marker_sets:
s=new_marker_set('particle_17 geometry')
marker_sets["particle_17 geometry"]=s
s= marker_sets["particle_17 geometry"]
mark=s.place_marker((9925.73, 5114.77, 6940.38), (0.7, 0.7, 0.7), 741.265)
if "particle_18 geometry" not in marker_sets:
s=new_marker_set('particle_18 geometry')
marker_sets["particle_18 geometry"]=s
s= marker_sets["particle_18 geometry"]
mark=s.place_marker((8425.02, 4379.43, 6970.81), (0.7, 0.7, 0.7), 748.625)
if "particle_19 geometry" not in marker_sets:
s=new_marker_set('particle_19 geometry')
marker_sets["particle_19 geometry"]=s
s= marker_sets["particle_19 geometry"]
mark=s.place_marker((8029.83, 2991.75, 7260.46), (0.7, 0.7, 0.7), 677.181)
if "particle_20 geometry" not in marker_sets:
s=new_marker_set('particle_20 geometry')
marker_sets["particle_20 geometry"]=s
s= marker_sets["particle_20 geometry"]
mark=s.place_marker((5951.3, 3796.04, 6289.92), (0.7, 0.7, 0.7), 616.015)
if "particle_21 geometry" not in marker_sets:
s=new_marker_set('particle_21 geometry')
marker_sets["particle_21 geometry"]=s
s= marker_sets["particle_21 geometry"]
mark=s.place_marker((7957.21, 3600.33, 6641.35), (0.7, 0.7, 0.7), 653.154)
if "particle_22 geometry" not in marker_sets:
s=new_marker_set('particle_22 geometry')
marker_sets["particle_22 geometry"]=s
s= marker_sets["particle_22 geometry"]
mark=s.place_marker((8140.19, 4126.99, 6096.32), (0.7, 0.7, 0.7), 595.33)
if "particle_23 geometry" not in marker_sets:
s=new_marker_set('particle_23 geometry')
marker_sets["particle_23 geometry"]=s
s= marker_sets["particle_23 geometry"]
mark=s.place_marker((9147.4, 4373.5, 5415.01), (0.7, 0.7, 0.7), 627.901)
if "particle_24 geometry" not in marker_sets:
s=new_marker_set('particle_24 geometry')
marker_sets["particle_24 geometry"]=s
s= marker_sets["particle_24 geometry"]
mark=s.place_marker((9507.63, 5298.75, 6384.18), (0.7, 0.7, 0.7), 663.941)
if "particle_25 geometry" not in marker_sets:
s=new_marker_set('particle_25 geometry')
marker_sets["particle_25 geometry"]=s
s= marker_sets["particle_25 geometry"]
mark=s.place_marker((10749.5, 5707.74, 7303.62), (0.7, 0.7, 0.7), 663.899)
if "particle_26 geometry" not in marker_sets:
s=new_marker_set('particle_26 geometry')
marker_sets["particle_26 geometry"]=s
s= marker_sets["particle_26 geometry"]
mark=s.place_marker((9428.5, 4939.22, 6938.06), (0.7, 0.7, 0.7), 644.694)
if "particle_27 geometry" not in marker_sets:
s=new_marker_set('particle_27 geometry')
marker_sets["particle_27 geometry"]=s
s= marker_sets["particle_27 geometry"]
mark=s.place_marker((7223.76, 4997.86, 7158.44), (0.7, 0.7, 0.7), 896.802)
if "particle_28 geometry" not in marker_sets:
s=new_marker_set('particle_28 geometry')
marker_sets["particle_28 geometry"]=s
s= marker_sets["particle_28 geometry"]
mark=s.place_marker((7281.52, 4269.62, 6065.9), (0.7, 0.7, 0.7), 576.38)
if "particle_29 geometry" not in marker_sets:
s=new_marker_set('particle_29 geometry')
marker_sets["particle_29 geometry"]=s
s= marker_sets["particle_29 geometry"]
mark=s.place_marker((6240.74, 3577.17, 5689.64), (0.7, 0.7, 0.7), 635.092)
if "particle_30 geometry" not in marker_sets:
s=new_marker_set('particle_30 geometry')
marker_sets["particle_30 geometry"]=s
s= marker_sets["particle_30 geometry"]
mark=s.place_marker((6519.02, 4271.11, 5060.68), (0.7, 0.7, 0.7), 651.505)
if "particle_31 geometry" not in marker_sets:
s=new_marker_set('particle_31 geometry')
marker_sets["particle_31 geometry"]=s
s= marker_sets["particle_31 geometry"]
mark=s.place_marker((5384.08, 3544.98, 6240.88), (0.7, 0.7, 0.7), 718.042)
if "particle_32 geometry" not in marker_sets:
s=new_marker_set('particle_32 geometry')
marker_sets["particle_32 geometry"]=s
s= marker_sets["particle_32 geometry"]
mark=s.place_marker((6832.31, 2963.47, 5550.58), (0.7, 0.7, 0.7), 726.714)
if "particle_33 geometry" not in marker_sets:
s=new_marker_set('particle_33 geometry')
marker_sets["particle_33 geometry"]=s
s= marker_sets["particle_33 geometry"]
mark=s.place_marker((7719.21, 4172.89, 5336.81), (0.7, 0.7, 0.7), 673.585)
if "particle_34 geometry" not in marker_sets:
s=new_marker_set('particle_34 geometry')
marker_sets["particle_34 geometry"]=s
s= marker_sets["particle_34 geometry"]
mark=s.place_marker((8593.07, 4410.01, 6309.83), (0.7, 0.7, 0.7), 598.418)
if "particle_35 geometry" not in marker_sets:
s=new_marker_set('particle_35 geometry')
marker_sets["particle_35 geometry"]=s
s= marker_sets["particle_35 geometry"]
mark=s.place_marker((9600.92, 4235.46, 7257.21), (0.7, 0.7, 0.7), 693.382)
if "particle_36 geometry" not in marker_sets:
s=new_marker_set('particle_36 geometry')
marker_sets["particle_36 geometry"]=s
s= marker_sets["particle_36 geometry"]
mark=s.place_marker((7261.14, 4254.98, 6484.12), (0.7, 0.7, 0.7), 804.038)
if "particle_37 geometry" not in marker_sets:
s=new_marker_set('particle_37 geometry')
marker_sets["particle_37 geometry"]=s
s= marker_sets["particle_37 geometry"]
mark=s.place_marker((9059.41, 4053.18, 5940.46), (0.7, 0.7, 0.7), 816.178)
if "particle_38 geometry" not in marker_sets:
s=new_marker_set('particle_38 geometry')
marker_sets["particle_38 geometry"]=s
s= marker_sets["particle_38 geometry"]
mark=s.place_marker((8555.71, 5301.11, 6099.13), (0.7, 0.7, 0.7), 776.628)
if "particle_39 geometry" not in marker_sets:
s=new_marker_set('particle_39 geometry')
marker_sets["particle_39 geometry"]=s
s= marker_sets["particle_39 geometry"]
mark=s.place_marker((8991.82, 3826.7, 5849.34), (0.7, 0.7, 0.7), 750.656)
if "particle_40 geometry" not in marker_sets:
s=new_marker_set('particle_40 geometry')
marker_sets["particle_40 geometry"]=s
s= marker_sets["particle_40 geometry"]
mark=s.place_marker((7563.14, 3873.99, 5074.14), (0.7, 0.7, 0.7), 709.625)
if "particle_41 geometry" not in marker_sets:
s=new_marker_set('particle_41 geometry')
marker_sets["particle_41 geometry"]=s
s= marker_sets["particle_41 geometry"]
mark=s.place_marker((6543.97, 2386.07, 4844.48), (0.7, 0.7, 0.7), 927.681)
if "particle_42 geometry" not in marker_sets:
s=new_marker_set('particle_42 geometry')
marker_sets["particle_42 geometry"]=s
s= marker_sets["particle_42 geometry"]
mark=s.place_marker((9142.15, 2025.38, 4197.04), (0.7, 0.7, 0.7), 1088.21)
if "particle_43 geometry" not in marker_sets:
s=new_marker_set('particle_43 geometry')
marker_sets["particle_43 geometry"]=s
s= marker_sets["particle_43 geometry"]
mark=s.place_marker((7348.59, 1971.75, 4655.23), (0.7, 0.7, 0.7), 736.147)
if "particle_44 geometry" not in marker_sets:
s=new_marker_set('particle_44 geometry')
marker_sets["particle_44 geometry"]=s
s= marker_sets["particle_44 geometry"]
mark=s.place_marker((7831.14, 3367.81, 5135.72), (0.7, 0.7, 0.7), 861.101)
if "particle_45 geometry" not in marker_sets:
s=new_marker_set('particle_45 geometry')
marker_sets["particle_45 geometry"]=s
s= marker_sets["particle_45 geometry"]
mark=s.place_marker((5920.06, 3975.09, 4676.61), (0.7, 0.7, 0.7), 924.213)
if "particle_46 geometry" not in marker_sets:
s=new_marker_set('particle_46 geometry')
marker_sets["particle_46 geometry"]=s
s= marker_sets["particle_46 geometry"]
mark=s.place_marker((6371.79, 4701, 2870.69), (0.7, 0.7, 0.7), 881.828)
if "particle_47 geometry" not in marker_sets:
s=new_marker_set('particle_47 geometry')
marker_sets["particle_47 geometry"]=s
s= marker_sets["particle_47 geometry"]
mark=s.place_marker((7297.06, 3112.25, 1937.05), (0.7, 0.7, 0.7), 927.681)
if "particle_48 geometry" not in marker_sets:
s=new_marker_set('particle_48 geometry')
marker_sets["particle_48 geometry"]=s
s= marker_sets["particle_48 geometry"]
mark=s.place_marker((5713.25, 4206.32, 1914.88), (0.7, 0.7, 0.7), 831.576)
if "particle_49 geometry" not in marker_sets:
s=new_marker_set('particle_49 geometry')
marker_sets["particle_49 geometry"]=s
s= marker_sets["particle_49 geometry"]
mark=s.place_marker((4335.65, 5025.11, 2899.42), (0.7, 0.7, 0.7), 859.494)
if "particle_50 geometry" not in marker_sets:
s=new_marker_set('particle_50 geometry')
marker_sets["particle_50 geometry"]=s
s= marker_sets["particle_50 geometry"]
mark=s.place_marker((4129.88, 4211.21, 2106.06), (0.7, 0.7, 0.7), 704.845)
if "particle_51 geometry" not in marker_sets:
s=new_marker_set('particle_51 geometry')
marker_sets["particle_51 geometry"]=s
s= marker_sets["particle_51 geometry"]
mark=s.place_marker((3804.45, 4560.97, 3750.74), (0.7, 0.7, 0.7), 804.461)
if "particle_52 geometry" not in marker_sets:
s=new_marker_set('particle_52 geometry')
marker_sets["particle_52 geometry"]=s
s= marker_sets["particle_52 geometry"]
mark=s.place_marker((3603.17, 5215.54, 5363.19), (0.7, 0.7, 0.7), 934.111)
if "particle_53 geometry" not in marker_sets:
s=new_marker_set('particle_53 geometry')
marker_sets["particle_53 geometry"]=s
s= marker_sets["particle_53 geometry"]
mark=s.place_marker((2107.24, 4872.4, 5501.58), (0.7, 0.7, 0.7), 988.339)
if "particle_54 geometry" not in marker_sets:
s=new_marker_set('particle_54 geometry')
marker_sets["particle_54 geometry"]=s
s= marker_sets["particle_54 geometry"]
mark=s.place_marker((1979.21, 4625.06, 4774.39), (1, 0.7, 0), 803.7)
if "particle_55 geometry" not in marker_sets:
s=new_marker_set('particle_55 geometry')
marker_sets["particle_55 geometry"]=s
s= marker_sets["particle_55 geometry"]
mark=s.place_marker((3594.25, 5355.89, 3693.32), (0.7, 0.7, 0.7), 812.118)
if "particle_56 geometry" not in marker_sets:
s=new_marker_set('particle_56 geometry')
marker_sets["particle_56 geometry"]=s
s= marker_sets["particle_56 geometry"]
mark=s.place_marker((3474.89, 7519.5, 3775.86), (0.7, 0.7, 0.7), 1177.93)
if "particle_57 geometry" not in marker_sets:
s=new_marker_set('particle_57 geometry')
marker_sets["particle_57 geometry"]=s
s= marker_sets["particle_57 geometry"]
mark=s.place_marker((4551.27, 9455.26, 2546.55), (0.7, 0.7, 0.7), 1038.21)
if "particle_58 geometry" not in marker_sets:
s=new_marker_set('particle_58 geometry')
marker_sets["particle_58 geometry"]=s
s= marker_sets["particle_58 geometry"]
mark=s.place_marker((4859.36, 9836.4, 2242.84), (1, 0.7, 0), 758.016)
if "particle_59 geometry" not in marker_sets:
s=new_marker_set('particle_59 geometry')
marker_sets["particle_59 geometry"]=s
s= marker_sets["particle_59 geometry"]
mark=s.place_marker((4436.49, 10348, 2745.17), (0.7, 0.7, 0.7), 824.046)
if "particle_60 geometry" not in marker_sets:
s=new_marker_set('particle_60 geometry')
marker_sets["particle_60 geometry"]=s
s= marker_sets["particle_60 geometry"]
mark=s.place_marker((4596.59, 9184.44, 2489.66), (0.7, 0.7, 0.7), 793.379)
if "particle_61 geometry" not in marker_sets:
s=new_marker_set('particle_61 geometry')
marker_sets["particle_61 geometry"]=s
s= marker_sets["particle_61 geometry"]
mark=s.place_marker((3690.39, 9673.29, 1789.05), (0.7, 0.7, 0.7), 1011.56)
if "particle_62 geometry" not in marker_sets:
s=new_marker_set('particle_62 geometry')
marker_sets["particle_62 geometry"]=s
s= marker_sets["particle_62 geometry"]
mark=s.place_marker((3977.3, 8378.07, 3169.41), (0.7, 0.7, 0.7), 1097.01)
if "particle_63 geometry" not in marker_sets:
s=new_marker_set('particle_63 geometry')
marker_sets["particle_63 geometry"]=s
s= marker_sets["particle_63 geometry"]
mark=s.place_marker((3145.72, 9961.52, 2416.25), (0.7, 0.7, 0.7), 851.626)
if "particle_64 geometry" not in marker_sets:
s=new_marker_set('particle_64 geometry')
marker_sets["particle_64 geometry"]=s
s= marker_sets["particle_64 geometry"]
mark=s.place_marker((2843.46, 11529.6, 1194.94), (0.7, 0.7, 0.7), 869.434)
if "particle_65 geometry" not in marker_sets:
s=new_marker_set('particle_65 geometry')
marker_sets["particle_65 geometry"]=s
s= marker_sets["particle_65 geometry"]
mark=s.place_marker((2541.46, 9897.35, 436.09), (0.7, 0.7, 0.7), 818.463)
if "particle_66 geometry" not in marker_sets:
s=new_marker_set('particle_66 geometry')
marker_sets["particle_66 geometry"]=s
s= marker_sets["particle_66 geometry"]
mark=s.place_marker((3735.17, 10464.5, -589.245), (0.7, 0.7, 0.7), 759.539)
if "particle_67 geometry" not in marker_sets:
s=new_marker_set('particle_67 geometry')
marker_sets["particle_67 geometry"]=s
s= marker_sets["particle_67 geometry"]
mark=s.place_marker((3440.54, 9018.19, 1385.84), (0.7, 0.7, 0.7), 1088.59)
if "particle_68 geometry" not in marker_sets:
s=new_marker_set('particle_68 geometry')
marker_sets["particle_68 geometry"]=s
s= marker_sets["particle_68 geometry"]
mark=s.place_marker((3761.03, 10854.2, 656.695), (0.7, 0.7, 0.7), 822.312)
if "particle_69 geometry" not in marker_sets:
s=new_marker_set('particle_69 geometry')
marker_sets["particle_69 geometry"]=s
s= marker_sets["particle_69 geometry"]
mark=s.place_marker((4728.33, 10477.5, -701.656), (0.7, 0.7, 0.7), 749.81)
if "particle_70 geometry" not in marker_sets:
s=new_marker_set('particle_70 geometry')
marker_sets["particle_70 geometry"]=s
s= marker_sets["particle_70 geometry"]
mark=s.place_marker((5199.29, 9150.39, -1.5525), (0.7, 0.7, 0.7), 764.488)
for k in surf_sets.keys():
chimera.openModels.add([surf_sets[k]])
|
gpl-3.0
|
[
646,
485,
10992,
199,
646,
682,
1036,
345,
199,
893,
26,
523,
492,
682,
1036,
345,
14,
1065,
3110,
199,
2590,
26,
523,
986,
199,
504,
15018,
2042,
492,
3608,
409,
465,
6605,
199,
893,
26,
523,
687,
15018,
2042,
492,
26903,
63,
1084,
12,
10967,
523,
892,
63,
4211,
63,
409,
29,
12825,
63,
1084,
199,
2590,
26,
523,
687,
15018,
2042,
492,
3301,
63,
515,
63,
7196,
523,
366,
29,
3301,
63,
515,
63,
7196,
8,
549,
9,
523,
892,
63,
4211,
63,
409,
29,
366,
14,
1222,
63,
4211,
63,
409,
199,
4211,
63,
2193,
7622,
199,
21579,
63,
2193,
7622,
199,
692,
298,
3829,
63,
16,
3400,
2,
440,
315,
3608,
63,
2193,
26,
523,
308,
29,
1222,
63,
4211,
63,
409,
360,
3829,
63,
16,
3400,
358,
523,
3608,
63,
2193,
905,
3829,
63,
16,
3400,
8713,
83,
199,
83,
29,
3608,
63,
2193,
905,
3829,
63,
16,
3400,
937,
199,
1657,
29,
83,
14,
2778,
63,
4211,
1332,
1427,
2766,
14,
2277,
12,
1749,
20384,
14,
1789,
12,
24058,
772,
14,
20,
395,
334,
16,
14,
23,
12,
378,
14,
23,
12,
378,
14,
23,
395,
221,
13173,
14,
11341,
9,
199,
692,
298,
3829,
63,
17,
3400,
2,
440,
315,
3608,
63,
2193,
26,
523,
308,
29,
1222,
63,
4211,
63,
409,
360,
3829,
63,
17,
3400,
358,
523,
3608,
63,
2193,
905,
3829,
63,
17,
3400,
8713,
83,
199,
83,
29,
3608,
63,
2193,
905,
3829,
63,
17,
3400,
937,
199,
1657,
29,
83,
14,
2778,
63,
4211,
1332,
22,
12289,
14,
1355,
12,
17838,
2260,
14,
1398,
12,
1749,
9946,
14,
1046,
395,
334,
16,
14,
23,
12,
378,
14,
23,
12,
378,
14,
23,
395,
1520,
2942,
14,
31980,
9,
199,
692,
298,
3829,
63,
18,
3400,
2,
440,
315,
3608,
63,
2193,
26,
523,
308,
29,
1222,
63,
4211,
63,
409,
360,
3829,
63,
18,
3400,
358,
523,
3608,
63,
2193,
905,
3829,
63,
18,
3400,
8713,
83,
199,
83,
29,
3608,
63,
2193,
905,
3829,
63,
18,
3400,
937,
199,
1657,
29,
83,
14,
2778,
63,
4211,
1332,
16112,
21,
14,
2025,
12,
10300,
1822,
14,
1780,
12,
1695,
10478,
14,
1349,
395,
334,
16,
14,
23,
12,
378,
14,
23,
12,
378,
14,
23,
395,
1695,
1367,
14,
23,
1184,
9,
199,
692,
298,
3829,
63,
19,
3400,
2,
440,
315,
3608,
63,
2193,
26,
523,
308,
29,
1222,
63,
4211,
63,
409,
360,
3829,
63,
19,
3400,
358,
523,
3608,
63,
2193,
905,
3829,
63,
19,
3400,
8713,
83,
199,
83,
29,
3608,
63,
2193,
905,
3829,
63,
19,
3400,
937,
199,
1657,
29,
83,
14,
2778,
63,
4211,
1332,
20,
12034,
14,
2819,
12,
1616,
10936,
14,
20,
12,
15580,
1153,
14,
772,
395,
334,
16,
14,
23,
12,
378,
14,
23,
12,
378,
14,
23,
395,
1749,
2766,
14,
18450,
9,
199,
692,
298,
3829,
63,
20,
3400,
2,
440,
315,
3608,
63,
2193,
26,
523,
308,
29,
1222,
63,
4211,
63,
409,
360,
3829,
63,
20,
3400,
358,
523,
3608,
63,
2193,
905,
3829,
63,
20,
3400,
8713,
83,
199,
83,
29,
3608,
63,
2193,
905,
3829,
63,
20,
3400,
937,
199,
1657,
29,
83,
14,
2778,
63,
4211,
1332,
9969,
22,
14,
1081,
12,
14313,
1965,
14,
20,
12,
18729,
1651,
14,
772,
395,
334,
16,
14,
23,
12,
378,
14,
23,
12,
378,
14,
23,
395,
1520,
2976,
14,
24338,
9,
199,
692,
298,
3829,
63,
21,
3400,
2,
440,
315,
3608,
63,
2193,
26,
523,
308,
29,
1222,
63,
4211,
63,
409,
360,
3829,
63,
21,
3400,
358,
523,
3608,
63,
2193,
905,
3829,
63,
21,
3400,
8713,
83,
199,
83,
29,
3608,
63,
2193,
905,
3829,
63,
21,
3400,
937,
199,
1657,
29,
83,
14,
2778,
63,
4211,
1332,
1167,
2192,
14,
1194,
12,
1695,
11065,
14,
772,
12,
1520,
8483,
14,
2635,
395,
334,
16,
14,
23,
12,
378,
14,
23,
12,
378,
14,
23,
395,
1749,
2976,
14,
12363,
9,
199,
692,
298,
3829,
63,
22,
3400,
2,
440,
315,
3608,
63,
2193,
26,
523,
308,
29,
1222,
63,
4211,
63,
409,
360,
3829,
63,
22,
3400,
358,
523,
3608,
63,
2193,
905,
3829,
63,
22,
3400,
8713,
83,
199,
83,
29,
3608,
63,
2193,
905,
3829,
63,
22,
3400,
937,
199,
1657,
29,
83,
14,
2778,
63,
4211,
1332,
1079,
772,
14,
1272,
12,
10851,
966,
14,
1153,
12,
9720,
1822,
14,
19,
395,
334,
16,
14,
23,
12,
378,
14,
23,
12,
378,
14,
23,
395,
1520,
2481,
14,
12768,
9,
199,
692,
298,
3829,
63,
23,
3400,
2,
440,
315,
3608,
63,
2193,
26,
523,
308,
29,
1222,
63,
4211,
63,
409,
360,
3829,
63,
23,
3400,
358,
523,
3608,
63,
2193,
905,
3829,
63,
23,
3400,
8713,
83,
199,
83,
29,
3608,
63,
2193,
905,
3829,
63,
23,
3400,
937,
199,
1657,
29,
83,
14,
2778,
63,
4211,
1332,
709,
2277,
14,
1138,
12,
9720,
2976,
14,
1822,
12,
5939,
1272,
14,
1703,
395,
334,
17,
12,
378,
14,
23,
12,
378,
395,
1616,
2905,
14,
1780,
9,
199,
692,
298,
3829,
63,
24,
3400,
2,
440,
315,
3608,
63,
2193,
26,
523,
308,
29,
1222,
63,
4211,
63,
409,
360,
3829,
63,
24,
3400,
358,
523,
3608,
63,
2193,
905,
3829,
63,
24,
3400,
8713,
83,
199,
83,
29,
3608,
63,
2193,
905,
3829,
63,
24,
3400,
937,
199,
1657,
29,
83,
14,
2778,
63,
4211,
1332,
1165,
1355,
14,
1427,
12,
959,
11520,
14,
1020,
12,
14610,
713,
14,
23,
395,
334,
16,
14,
23,
12,
378,
14,
23,
12,
378,
14,
23,
395,
413,
9523,
14,
2260,
9,
199,
692,
298,
3829,
63,
25,
3400,
2,
440,
315,
3608,
63,
2193,
26,
523,
308,
29,
1222,
63,
4211,
63,
409,
360,
3829,
63,
25,
3400,
358,
523,
3608,
63,
2193,
905,
3829,
63,
25,
3400,
8713,
83,
199,
83,
29,
3608,
63,
2193,
905,
3829,
63,
25,
3400,
937,
199,
1657,
29,
83,
14,
2778,
63,
4211,
1332,
1085,
2824,
14,
2635,
12,
6877,
2036,
14,
2036,
12,
8375,
3328,
14,
1194,
395,
334,
17,
12,
378,
14,
23,
12,
378,
395,
1695,
2025
] |
[
485,
10992,
199,
646,
682,
1036,
345,
199,
893,
26,
523,
492,
682,
1036,
345,
14,
1065,
3110,
199,
2590,
26,
523,
986,
199,
504,
15018,
2042,
492,
3608,
409,
465,
6605,
199,
893,
26,
523,
687,
15018,
2042,
492,
26903,
63,
1084,
12,
10967,
523,
892,
63,
4211,
63,
409,
29,
12825,
63,
1084,
199,
2590,
26,
523,
687,
15018,
2042,
492,
3301,
63,
515,
63,
7196,
523,
366,
29,
3301,
63,
515,
63,
7196,
8,
549,
9,
523,
892,
63,
4211,
63,
409,
29,
366,
14,
1222,
63,
4211,
63,
409,
199,
4211,
63,
2193,
7622,
199,
21579,
63,
2193,
7622,
199,
692,
298,
3829,
63,
16,
3400,
2,
440,
315,
3608,
63,
2193,
26,
523,
308,
29,
1222,
63,
4211,
63,
409,
360,
3829,
63,
16,
3400,
358,
523,
3608,
63,
2193,
905,
3829,
63,
16,
3400,
8713,
83,
199,
83,
29,
3608,
63,
2193,
905,
3829,
63,
16,
3400,
937,
199,
1657,
29,
83,
14,
2778,
63,
4211,
1332,
1427,
2766,
14,
2277,
12,
1749,
20384,
14,
1789,
12,
24058,
772,
14,
20,
395,
334,
16,
14,
23,
12,
378,
14,
23,
12,
378,
14,
23,
395,
221,
13173,
14,
11341,
9,
199,
692,
298,
3829,
63,
17,
3400,
2,
440,
315,
3608,
63,
2193,
26,
523,
308,
29,
1222,
63,
4211,
63,
409,
360,
3829,
63,
17,
3400,
358,
523,
3608,
63,
2193,
905,
3829,
63,
17,
3400,
8713,
83,
199,
83,
29,
3608,
63,
2193,
905,
3829,
63,
17,
3400,
937,
199,
1657,
29,
83,
14,
2778,
63,
4211,
1332,
22,
12289,
14,
1355,
12,
17838,
2260,
14,
1398,
12,
1749,
9946,
14,
1046,
395,
334,
16,
14,
23,
12,
378,
14,
23,
12,
378,
14,
23,
395,
1520,
2942,
14,
31980,
9,
199,
692,
298,
3829,
63,
18,
3400,
2,
440,
315,
3608,
63,
2193,
26,
523,
308,
29,
1222,
63,
4211,
63,
409,
360,
3829,
63,
18,
3400,
358,
523,
3608,
63,
2193,
905,
3829,
63,
18,
3400,
8713,
83,
199,
83,
29,
3608,
63,
2193,
905,
3829,
63,
18,
3400,
937,
199,
1657,
29,
83,
14,
2778,
63,
4211,
1332,
16112,
21,
14,
2025,
12,
10300,
1822,
14,
1780,
12,
1695,
10478,
14,
1349,
395,
334,
16,
14,
23,
12,
378,
14,
23,
12,
378,
14,
23,
395,
1695,
1367,
14,
23,
1184,
9,
199,
692,
298,
3829,
63,
19,
3400,
2,
440,
315,
3608,
63,
2193,
26,
523,
308,
29,
1222,
63,
4211,
63,
409,
360,
3829,
63,
19,
3400,
358,
523,
3608,
63,
2193,
905,
3829,
63,
19,
3400,
8713,
83,
199,
83,
29,
3608,
63,
2193,
905,
3829,
63,
19,
3400,
937,
199,
1657,
29,
83,
14,
2778,
63,
4211,
1332,
20,
12034,
14,
2819,
12,
1616,
10936,
14,
20,
12,
15580,
1153,
14,
772,
395,
334,
16,
14,
23,
12,
378,
14,
23,
12,
378,
14,
23,
395,
1749,
2766,
14,
18450,
9,
199,
692,
298,
3829,
63,
20,
3400,
2,
440,
315,
3608,
63,
2193,
26,
523,
308,
29,
1222,
63,
4211,
63,
409,
360,
3829,
63,
20,
3400,
358,
523,
3608,
63,
2193,
905,
3829,
63,
20,
3400,
8713,
83,
199,
83,
29,
3608,
63,
2193,
905,
3829,
63,
20,
3400,
937,
199,
1657,
29,
83,
14,
2778,
63,
4211,
1332,
9969,
22,
14,
1081,
12,
14313,
1965,
14,
20,
12,
18729,
1651,
14,
772,
395,
334,
16,
14,
23,
12,
378,
14,
23,
12,
378,
14,
23,
395,
1520,
2976,
14,
24338,
9,
199,
692,
298,
3829,
63,
21,
3400,
2,
440,
315,
3608,
63,
2193,
26,
523,
308,
29,
1222,
63,
4211,
63,
409,
360,
3829,
63,
21,
3400,
358,
523,
3608,
63,
2193,
905,
3829,
63,
21,
3400,
8713,
83,
199,
83,
29,
3608,
63,
2193,
905,
3829,
63,
21,
3400,
937,
199,
1657,
29,
83,
14,
2778,
63,
4211,
1332,
1167,
2192,
14,
1194,
12,
1695,
11065,
14,
772,
12,
1520,
8483,
14,
2635,
395,
334,
16,
14,
23,
12,
378,
14,
23,
12,
378,
14,
23,
395,
1749,
2976,
14,
12363,
9,
199,
692,
298,
3829,
63,
22,
3400,
2,
440,
315,
3608,
63,
2193,
26,
523,
308,
29,
1222,
63,
4211,
63,
409,
360,
3829,
63,
22,
3400,
358,
523,
3608,
63,
2193,
905,
3829,
63,
22,
3400,
8713,
83,
199,
83,
29,
3608,
63,
2193,
905,
3829,
63,
22,
3400,
937,
199,
1657,
29,
83,
14,
2778,
63,
4211,
1332,
1079,
772,
14,
1272,
12,
10851,
966,
14,
1153,
12,
9720,
1822,
14,
19,
395,
334,
16,
14,
23,
12,
378,
14,
23,
12,
378,
14,
23,
395,
1520,
2481,
14,
12768,
9,
199,
692,
298,
3829,
63,
23,
3400,
2,
440,
315,
3608,
63,
2193,
26,
523,
308,
29,
1222,
63,
4211,
63,
409,
360,
3829,
63,
23,
3400,
358,
523,
3608,
63,
2193,
905,
3829,
63,
23,
3400,
8713,
83,
199,
83,
29,
3608,
63,
2193,
905,
3829,
63,
23,
3400,
937,
199,
1657,
29,
83,
14,
2778,
63,
4211,
1332,
709,
2277,
14,
1138,
12,
9720,
2976,
14,
1822,
12,
5939,
1272,
14,
1703,
395,
334,
17,
12,
378,
14,
23,
12,
378,
395,
1616,
2905,
14,
1780,
9,
199,
692,
298,
3829,
63,
24,
3400,
2,
440,
315,
3608,
63,
2193,
26,
523,
308,
29,
1222,
63,
4211,
63,
409,
360,
3829,
63,
24,
3400,
358,
523,
3608,
63,
2193,
905,
3829,
63,
24,
3400,
8713,
83,
199,
83,
29,
3608,
63,
2193,
905,
3829,
63,
24,
3400,
937,
199,
1657,
29,
83,
14,
2778,
63,
4211,
1332,
1165,
1355,
14,
1427,
12,
959,
11520,
14,
1020,
12,
14610,
713,
14,
23,
395,
334,
16,
14,
23,
12,
378,
14,
23,
12,
378,
14,
23,
395,
413,
9523,
14,
2260,
9,
199,
692,
298,
3829,
63,
25,
3400,
2,
440,
315,
3608,
63,
2193,
26,
523,
308,
29,
1222,
63,
4211,
63,
409,
360,
3829,
63,
25,
3400,
358,
523,
3608,
63,
2193,
905,
3829,
63,
25,
3400,
8713,
83,
199,
83,
29,
3608,
63,
2193,
905,
3829,
63,
25,
3400,
937,
199,
1657,
29,
83,
14,
2778,
63,
4211,
1332,
1085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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
] |
vladnicoara/SDLive-Blog
|
documentor/libraries/Sphinx-1.1.3-py3.2/sphinx/util/texescape.py
|
2
|
2680
|
# -*- coding: utf-8 -*-
"""
sphinx.util.texescape
~~~~~~~~~~~~~~~~~~~~~
TeX escaping helper.
:copyright: Copyright 2007-2011 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
tex_replacements = [
# map TeX special chars
('$', r'\$'),
('%', r'\%'),
('&', r'\&'),
('#', r'\#'),
('_', r'\_'),
('{', r'\{'),
('}', r'\}'),
('[', r'{[}'),
(']', r'{]}'),
('`', r'{}`'),
('\\',r'\textbackslash{}'),
('~', r'\textasciitilde{}'),
('<', r'\textless{}'),
('>', r'\textgreater{}'),
('^', r'\textasciicircum{}'),
# map special Unicode characters to TeX commands
('¶', r'\P{}'),
('§', r'\S{}'),
('€', r'\texteuro{}'),
('∞', r'\(\infty\)'),
('±', r'\(\pm\)'),
('→', r'\(\rightarrow\)'),
('‣', r'\(\rightarrow\)'),
# used to separate -- in options
('', r'{}'),
# map some special Unicode characters to similar ASCII ones
('─', r'-'),
('⎽', r'\_'),
('╲', r'\textbackslash{}'),
('|', r'\textbar{}'),
('│', r'\textbar{}'),
('ℯ', r'e'),
('ⅈ', r'i'),
('₁', r'1'),
('₂', r'2'),
# map Greek alphabet
('α', r'\(\alpha\)'),
('β', r'\(\beta\)'),
('γ', r'\(\gamma\)'),
('δ', r'\(\delta\)'),
('ε', r'\(\epsilon\)'),
('ζ', r'\(\zeta\)'),
('η', r'\(\eta\)'),
('θ', r'\(\theta\)'),
('ι', r'\(\iota\)'),
('κ', r'\(\kappa\)'),
('λ', r'\(\lambda\)'),
('μ', r'\(\mu\)'),
('ν', r'\(\nu\)'),
('ξ', r'\(\xi\)'),
('ο', r'o'),
('π', r'\(\pi\)'),
('ρ', r'\(\rho\)'),
('σ', r'\(\sigma\)'),
('τ', r'\(\tau\)'),
('υ', '\\(\\upsilon\\)'),
('φ', r'\(\phi\)'),
('χ', r'\(\chi\)'),
('ψ', r'\(\psi\)'),
('ω', r'\(\omega\)'),
('Α', r'A'),
('Β', r'B'),
('Γ', r'\(\Gamma\)'),
('Δ', r'\(\Delta\)'),
('Ε', r'E'),
('Ζ', r'Z'),
('Η', r'H'),
('Θ', r'\(\Theta\)'),
('Ι', r'I'),
('Κ', r'K'),
('Λ', r'\(\Lambda\)'),
('Μ', r'M'),
('Ν', r'N'),
('Ξ', r'\(\Xi\)'),
('Ο', r'O'),
('Π', r'\(\Pi\)'),
('Ρ', r'P'),
('Σ', r'\(\Sigma\)'),
('Τ', r'T'),
('Υ', '\\(\\Upsilon\\)'),
('Φ', r'\(\Phi\)'),
('Χ', r'X'),
('Ψ', r'\(\Psi\)'),
('Ω', r'\(\Omega\)'),
('Ω', r'\(\Omega\)'),
]
tex_escape_map = {}
tex_replace_map = {}
tex_hl_escape_map_new = {}
def init():
for a, b in tex_replacements:
tex_escape_map[ord(a)] = b
tex_replace_map[ord(a)] = '_'
for a, b in tex_replacements:
if a in '[]{}\\': continue
tex_hl_escape_map_new[ord(a)] = b
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
15882,
14,
1974,
14,
3858,
3765,
272,
18294,
2878,
94,
339,
5773,
56,
21375,
5922,
14,
339,
520,
7307,
26,
1898,
10219,
13,
8128,
701,
314,
10229,
8099,
12,
1937,
10610,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
2436,
14,
199,
624,
199,
199,
3858,
63,
1814,
1470,
275,
359,
272,
327,
2341,
5773,
56,
4539,
8365,
272,
661,
4268,
519,
1154,
26712,
272,
16651,
297,
519,
1154,
5,
659,
272,
661,
16749,
519,
1154,
6,
659,
272,
22870,
297,
519,
1154,
3,
659,
272,
12331,
297,
519,
1154,
63,
659,
272,
661,
27824,
519,
1154,
91,
659,
272,
661,
7293,
519,
1154,
93,
659,
272,
23734,
297,
519,
16019,
59,
93,
659,
272,
334,
418,
297,
519,
16019,
9420,
659,
272,
661,
30880,
519,
7,
2440,
64,
659,
272,
661,
1103,
297,
82,
1154,
505,
21509,
2440,
659,
272,
661,
94,
297,
519,
1154,
505,
4371,
16488,
2440,
659,
272,
19990,
297,
519,
1154,
505,
2003,
2440,
659,
272,
661,
4206,
519,
1154,
505,
13154,
2440,
659,
272,
661,
62,
297,
519,
1154,
505,
305,
559,
530,
5958,
453,
2440,
659,
272,
327,
2341,
4539,
6140,
4110,
370,
5773,
56,
3718,
272,
661,
127,
115,
297,
519,
1154,
48,
2440,
659,
272,
661,
127,
101,
297,
519,
1154,
51,
2440,
659,
272,
661,
28268,
106,
297,
519,
1154,
3858,
266,
9129,
2440,
659,
272,
661,
159,
231,
253,
297,
519,
1154,
2961,
4904,
369,
60,
11218,
272,
661,
127,
110,
297,
519,
1154,
2961,
7073,
60,
11218,
272,
661,
159,
229,
241,
297,
519,
1154,
2961,
1019,
7691,
60,
11218,
272,
661,
8477,
97,
297,
519,
1154,
2961,
1019,
7691,
60,
11218,
272,
327,
1202,
370,
7396,
1553,
315,
1511,
272,
661,
172,
120,
124,
297,
519,
7,
2440,
659,
272,
327,
2341,
2005,
4539,
6140,
4110,
370,
8545,
10485,
7869,
272,
661,
19961,
297,
519,
12418,
659,
272,
661,
159,
237,
122,
297,
519,
1154,
63,
659,
272,
661,
19298,
111,
297,
519,
1154,
505,
21509,
2440,
659,
272,
661,
26320,
519,
1154,
505,
1700,
2440,
659,
272,
661,
15038,
225,
297,
519,
1154,
505,
1700,
2440,
659,
272,
661,
159,
227,
108,
297,
519,
7,
69,
659,
272,
661,
159,
228,
231,
297,
519,
7,
73,
659,
272,
661,
28268,
224,
297,
519,
7,
17,
659,
272,
661,
28268,
225,
297,
519,
7,
18,
659,
272,
327,
2341,
598,
14291,
27230,
272,
661,
13500,
297,
519,
1154,
2961,
4468,
60,
11218,
272,
661,
139,
111,
297,
519,
1154,
2961,
5683,
60,
11218,
272,
661,
28916,
297,
519,
1154,
2961,
7325,
60,
11218,
272,
661,
139,
113,
297,
519,
1154,
2961,
3136,
60,
11218,
272,
661,
15339,
297,
519,
1154,
2961,
15761,
60,
11218,
272,
661,
139,
115,
297,
519,
1154,
2961,
90,
1841,
60,
11218,
272,
661,
21694,
297,
519,
1154,
2961,
1841,
60,
11218,
272,
661,
139,
117,
297,
519,
1154,
2961,
9337,
60,
11218,
272,
661,
16426,
297,
519,
1154,
2961,
73,
12041,
60,
11218,
272,
661,
26839,
297,
519,
1154,
2961,
31918,
60,
11218,
272,
661,
28085,
297,
519,
1154,
2961,
2734,
60,
11218,
272,
661,
24461,
297,
519,
1154,
2961,
6553,
60,
11218,
272,
661,
17444,
297,
519,
1154,
2961,
4850,
60,
11218,
272,
661,
139,
123,
297,
519,
1154,
2961,
6865,
60,
11218,
272,
661,
15407,
297,
519,
7,
79,
659,
272,
661,
22955,
297,
519,
1154,
2961,
1038,
60,
11218,
272,
661,
18346,
297,
519,
1154,
2961,
10412,
60,
11218,
272,
661,
20136,
297,
519,
1154,
2961,
9412,
60,
11218,
272,
661,
17123,
297,
519,
1154,
2961,
16656,
60,
11218,
272,
661,
27630,
297,
6468,
27910,
384,
8746,
1103,
11218,
272,
661,
140,
229,
297,
519,
1154,
2961,
10909,
60,
11218,
272,
661,
140,
230,
297,
519,
1154,
2961,
13175,
60,
11218,
272,
661,
140,
231,
297,
519,
1154,
2961,
18645,
60,
11218,
272,
661,
140,
232,
297,
519,
1154,
2961,
23524,
60,
11218,
272,
661,
139,
240,
297,
519,
7,
33,
659,
272,
661,
139,
241,
297,
519,
7,
34,
659,
272,
661,
139,
242,
297,
519,
1154,
2961,
15091,
60,
11218,
272,
661,
139,
243,
297,
519,
1154,
2961,
13411,
60,
11218,
272,
661,
139,
244,
297,
519,
7,
37,
659,
272,
661,
139,
245,
297,
519,
7,
58,
659,
272,
661,
139,
246,
297,
519,
7,
40,
659,
272,
661,
139,
247,
297,
519,
1154,
2961,
2719,
1841,
60,
11218,
272,
661,
139,
248,
297,
519,
7,
41,
659,
272,
661,
139,
249,
297,
519,
7,
43,
659,
272,
661,
139,
250,
297,
519,
1154,
2961,
21350,
60,
11218,
272,
661,
139,
251,
297,
519,
7,
45,
659,
272,
661,
139,
252,
297,
519,
7,
46,
659,
272,
661,
139,
253,
297,
519,
1154,
2961,
14828,
60,
11218,
272,
661,
139,
254,
297,
519,
7,
47,
659,
272,
661,
139,
255,
297,
519,
1154,
2961,
10542,
60,
11218,
272,
661,
139,
95,
297,
519,
7,
48,
659,
272,
661,
139,
97,
297,
519,
1154,
2961,
23394,
60,
11218,
272,
661,
139,
98,
297,
519,
7,
52,
659,
272,
661,
139,
99,
297,
6468,
27910,
1721,
8746,
1103,
11218,
272,
661,
139,
100,
297,
519,
1154,
2961,
5663,
73,
60,
11218,
272,
661,
139,
101,
297,
519,
7,
56,
659,
272,
661,
139,
102,
297,
519,
1154,
2961,
48,
338,
60,
11218,
272,
661,
139,
103,
297,
519,
1154,
2961,
47,
29073,
60,
11218,
272,
661,
159,
227,
100,
297,
519,
1154,
2961,
47,
29073,
60,
11218,
199,
61,
199,
199,
3858,
63,
3765,
63,
1130,
275,
1052,
199,
3858,
63,
1814,
63,
1130,
275,
1052,
199,
3858,
63,
15544,
63,
3765,
63,
1130,
63,
1222,
275,
1052,
199,
199,
318,
4205,
837,
272,
367,
282,
12,
330,
315,
14709,
63,
1814,
1470,
26,
267,
14709,
63,
3765,
63,
1130,
59,
2181,
8,
65,
1874,
275,
330,
267,
14709,
63,
1814,
63,
1130,
59,
2181,
8,
65,
1874,
275,
14135,
339,
367,
282,
12,
330,
315,
14709,
63,
1814,
1470,
26,
267,
340,
282,
315,
6730,
61,
2440,
1103,
356,
1980,
267,
14709,
63,
15544,
63,
3765,
63,
1130,
63,
1222,
59,
2181,
8,
65,
1874,
275,
330,
199
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
15882,
14,
1974,
14,
3858,
3765,
272,
18294,
2878,
94,
339,
5773,
56,
21375,
5922,
14,
339,
520,
7307,
26,
1898,
10219,
13,
8128,
701,
314,
10229,
8099,
12,
1937,
10610,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
2436,
14,
199,
624,
199,
199,
3858,
63,
1814,
1470,
275,
359,
272,
327,
2341,
5773,
56,
4539,
8365,
272,
661,
4268,
519,
1154,
26712,
272,
16651,
297,
519,
1154,
5,
659,
272,
661,
16749,
519,
1154,
6,
659,
272,
22870,
297,
519,
1154,
3,
659,
272,
12331,
297,
519,
1154,
63,
659,
272,
661,
27824,
519,
1154,
91,
659,
272,
661,
7293,
519,
1154,
93,
659,
272,
23734,
297,
519,
16019,
59,
93,
659,
272,
334,
418,
297,
519,
16019,
9420,
659,
272,
661,
30880,
519,
7,
2440,
64,
659,
272,
661,
1103,
297,
82,
1154,
505,
21509,
2440,
659,
272,
661,
94,
297,
519,
1154,
505,
4371,
16488,
2440,
659,
272,
19990,
297,
519,
1154,
505,
2003,
2440,
659,
272,
661,
4206,
519,
1154,
505,
13154,
2440,
659,
272,
661,
62,
297,
519,
1154,
505,
305,
559,
530,
5958,
453,
2440,
659,
272,
327,
2341,
4539,
6140,
4110,
370,
5773,
56,
3718,
272,
661,
127,
115,
297,
519,
1154,
48,
2440,
659,
272,
661,
127,
101,
297,
519,
1154,
51,
2440,
659,
272,
661,
28268,
106,
297,
519,
1154,
3858,
266,
9129,
2440,
659,
272,
661,
159,
231,
253,
297,
519,
1154,
2961,
4904,
369,
60,
11218,
272,
661,
127,
110,
297,
519,
1154,
2961,
7073,
60,
11218,
272,
661,
159,
229,
241,
297,
519,
1154,
2961,
1019,
7691,
60,
11218,
272,
661,
8477,
97,
297,
519,
1154,
2961,
1019,
7691,
60,
11218,
272,
327,
1202,
370,
7396,
1553,
315,
1511,
272,
661,
172,
120,
124,
297,
519,
7,
2440,
659,
272,
327,
2341,
2005,
4539,
6140,
4110,
370,
8545,
10485,
7869,
272,
661,
19961,
297,
519,
12418,
659,
272,
661,
159,
237,
122,
297,
519,
1154,
63,
659,
272,
661,
19298,
111,
297,
519,
1154,
505,
21509,
2440,
659,
272,
661,
26320,
519,
1154,
505,
1700,
2440,
659,
272,
661,
15038,
225,
297,
519,
1154,
505,
1700,
2440,
659,
272,
661,
159,
227,
108,
297,
519,
7,
69,
659,
272,
661,
159,
228,
231,
297,
519,
7,
73,
659,
272,
661,
28268,
224,
297,
519,
7,
17,
659,
272,
661,
28268,
225,
297,
519,
7,
18,
659,
272,
327,
2341,
598,
14291,
27230,
272,
661,
13500,
297,
519,
1154,
2961,
4468,
60,
11218,
272,
661,
139,
111,
297,
519,
1154,
2961,
5683,
60,
11218,
272,
661,
28916,
297,
519,
1154,
2961,
7325,
60,
11218,
272,
661,
139,
113,
297,
519,
1154,
2961,
3136,
60,
11218,
272,
661,
15339,
297,
519,
1154,
2961,
15761,
60,
11218,
272,
661,
139,
115,
297,
519,
1154,
2961,
90,
1841,
60,
11218,
272,
661,
21694,
297,
519,
1154,
2961,
1841,
60,
11218,
272,
661,
139,
117,
297,
519,
1154,
2961,
9337,
60,
11218,
272,
661,
16426,
297,
519,
1154,
2961,
73,
12041,
60,
11218,
272,
661,
26839,
297,
519,
1154,
2961,
31918,
60,
11218,
272,
661,
28085,
297,
519,
1154,
2961,
2734,
60,
11218,
272,
661,
24461,
297,
519,
1154,
2961,
6553,
60,
11218,
272,
661,
17444,
297,
519,
1154,
2961,
4850,
60,
11218,
272,
661,
139,
123,
297,
519,
1154,
2961,
6865,
60,
11218,
272,
661,
15407,
297,
519,
7,
79,
659,
272,
661,
22955,
297,
519,
1154,
2961,
1038,
60,
11218,
272,
661,
18346,
297,
519,
1154,
2961,
10412,
60,
11218,
272,
661,
20136,
297,
519,
1154,
2961,
9412,
60,
11218,
272,
661,
17123,
297,
519,
1154,
2961,
16656,
60,
11218,
272,
661,
27630,
297,
6468,
27910,
384,
8746,
1103,
11218,
272,
661,
140,
229,
297,
519,
1154,
2961,
10909,
60,
11218,
272,
661,
140,
230,
297,
519,
1154,
2961,
13175,
60,
11218,
272,
661,
140,
231,
297,
519,
1154,
2961,
18645,
60,
11218,
272,
661,
140,
232,
297,
519,
1154,
2961,
23524,
60,
11218,
272,
661,
139,
240,
297,
519,
7,
33,
659,
272,
661,
139,
241,
297,
519,
7,
34,
659,
272,
661,
139,
242,
297,
519,
1154,
2961,
15091,
60,
11218,
272,
661,
139,
243,
297,
519,
1154,
2961,
13411,
60,
11218,
272,
661,
139,
244,
297,
519,
7,
37,
659,
272,
661,
139,
245,
297,
519,
7,
58,
659,
272,
661,
139,
246,
297,
519,
7,
40,
659,
272,
661,
139,
247,
297,
519,
1154,
2961,
2719,
1841,
60,
11218,
272,
661,
139,
248,
297,
519,
7,
41,
659,
272,
661,
139,
249,
297,
519,
7,
43,
659,
272,
661,
139,
250,
297,
519,
1154,
2961,
21350,
60,
11218,
272,
661,
139,
251,
297,
519,
7,
45,
659,
272,
661,
139,
252,
297,
519,
7,
46,
659,
272,
661,
139,
253,
297,
519,
1154,
2961,
14828,
60,
11218,
272,
661,
139,
254,
297,
519,
7,
47,
659,
272,
661,
139,
255,
297,
519,
1154,
2961,
10542,
60,
11218,
272,
661,
139,
95,
297,
519,
7,
48,
659,
272,
661,
139,
97,
297,
519,
1154,
2961,
23394,
60,
11218,
272,
661,
139,
98,
297,
519,
7,
52,
659,
272,
661,
139,
99,
297,
6468,
27910,
1721,
8746,
1103,
11218,
272,
661,
139,
100,
297,
519,
1154,
2961,
5663,
73,
60,
11218,
272,
661,
139,
101,
297,
519,
7,
56,
659,
272,
661,
139,
102,
297,
519,
1154,
2961,
48,
338,
60,
11218,
272,
661,
139,
103,
297,
519,
1154,
2961,
47,
29073,
60,
11218,
272,
661,
159,
227,
100,
297,
519,
1154,
2961,
47,
29073,
60,
11218,
199,
61,
199,
199,
3858,
63,
3765,
63,
1130,
275,
1052,
199,
3858,
63,
1814,
63,
1130,
275,
1052,
199,
3858,
63,
15544,
63,
3765,
63,
1130,
63,
1222,
275,
1052,
199,
199,
318,
4205,
837,
272,
367,
282,
12,
330,
315,
14709,
63,
1814,
1470,
26,
267,
14709,
63,
3765,
63,
1130,
59,
2181,
8,
65,
1874,
275,
330,
267,
14709,
63,
1814,
63,
1130,
59,
2181,
8,
65,
1874,
275,
14135,
339,
367,
282,
12,
330,
315,
14709,
63,
1814,
1470,
26,
267,
340,
282,
315,
6730,
61,
2440,
1103,
356,
1980,
267,
14709,
63,
15544,
63,
3765,
63,
1130,
63,
1222,
59,
2181,
8,
65,
1874,
275,
330,
199,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
XiaosongWei/chromium-crosswalk
|
content/browser/devtools/protocol/devtools_protocol_handler_generator.py
|
6
|
25134
|
#!/usr/bin/env python
# Copyright 2014 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 sys
import string
import json
blink_protocol_path = sys.argv[1]
browser_protocol_path = sys.argv[2]
output_cc_path = sys.argv[3]
output_h_path = sys.argv[4]
header = """\
// Copyright 2014 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.
// THIS FILE IS AUTOGENERATED. DO NOT EDIT.
// Generated by
// content/public/browser/devtools_protocol_handler_generator.py from
// third_party/WebKit/Source/devtools/protocol.json and
// content/browser/devtools/browser_protocol.json
"""
template_h = string.Template(header + """\
#ifndef CONTENT_BROWSER_DEVTOOLS_PROTOCOL_DEVTOOLS_PROTOCOL_DISPATCHER_H_
#define CONTENT_BROWSER_DEVTOOLS_PROTOCOL_DEVTOOLS_PROTOCOL_DISPATCHER_H_
#include <utility>
#include "content/browser/devtools/protocol/devtools_protocol_client.h"
namespace content {
class DevToolsProtocolDispatcher;
namespace devtools {
extern const char kProtocolVersion[];
bool IsSupportedProtocolVersion(const std::string& version);
template<typename T>
base::Value* CreateValue(const T& param) {
return new base::FundamentalValue(param);
}
template<class T>
base::Value* CreateValue(scoped_ptr<T>& param) {
return param.release();
}
template<class T>
base::Value* CreateValue(scoped_refptr<T> param) {
return param->ToValue().release();
}
template<typename T>
base::Value* CreateValue(const std::vector<T> param) {
base::ListValue* result = new base::ListValue();
for (auto& item : param) {
result->Append(CreateValue(item));
}
return result;
}
template<>
base::Value* CreateValue(const std::string& param);
${types}\
} // namespace devtools
class DevToolsProtocolDispatcher {
public:
using CommandHandler =
base::Callback<bool(DevToolsCommandId,
scoped_ptr<base::DictionaryValue>)>;
explicit DevToolsProtocolDispatcher(DevToolsProtocolDelegate* notifier);
~DevToolsProtocolDispatcher();
CommandHandler FindCommandHandler(const std::string& method);
${setters}\
private:
using Response = DevToolsProtocolClient::Response;
using CommandHandlers = std::map<std::string, CommandHandler>;
${methods}\
DevToolsProtocolDelegate* notifier_;
DevToolsProtocolClient client_;
CommandHandlers command_handlers_;
${fields}\
};
} // namespace content
#endif // CONTENT_BROWSER_DEVTOOLS_PROTOCOL_DEVTOOLS_PROTOCOL_DISPATCHER_H_
""")
tmpl_typedef = string.Template("""\
namespace ${domain} {
typedef ${param_type} ${declared_name};
} // namespace ${domain}
""")
tmpl_struct = string.Template("""\
namespace ${domain} {
template<int MASK>
struct ${declared_name}Builder
: base::RefCounted<${declared_name}Builder<MASK>> {
public:
enum {
kAllSet = 0,
${fields_enum}\
};
${methods}\
static scoped_refptr<${declared_name}Builder<kNoneSet>> Create() {
return new ${declared_name}Builder<kNoneSet>();
}
scoped_ptr<base::DictionaryValue> ToValue() {
static_assert(MASK == kAllSet, "required properties missing");
return make_scoped_ptr(dict_->DeepCopy());
}
private:
friend struct ${declared_name}Builder<0>;
friend class base::RefCounted<${declared_name}Builder<MASK>>;
~${declared_name}Builder() {}
${declared_name}Builder() : dict_(new base::DictionaryValue()) {
}
template<class T> T* ThisAs() {
static_assert(sizeof(*this) == sizeof(T), "cannot cast");
return reinterpret_cast<T*>(this);
}
scoped_ptr<base::DictionaryValue> dict_;
};
typedef ${declared_name}Builder<0> ${declared_name};
} // namespace ${domain}
""")
tmpl_builder_setter_req = string.Template("""\
scoped_refptr<${declared_name}Builder<MASK & ~k${Param}>>
set_${param}(${pass_type} ${param}) {
static_assert(MASK & k${Param}, "already set");
dict_->Set("${proto_param}", CreateValue(${param}));
return ThisAs<${declared_name}Builder<MASK & ~k${Param}>>();
}
""")
tmpl_builder_setter_opt = string.Template("""\
scoped_refptr<${declared_name}Builder<MASK>>
set_${param}(${pass_type} ${param}) {
dict_->Set("${proto_param}", CreateValue(${param}));
return this;
}
""")
tmpl_builder_enum = string.Template("""\
k${Param} = 1 << ${ordinal},
""")
tmpl_builder_none_set = string.Template("""\
kNoneSet = ${all_fields}
""")
tmpl_named_enum = string.Template("""\
namespace ${domain} {
${values}\
} // namespace ${domain}
""")
tmpl_inline_enum = string.Template("""\
namespace ${domain} {
namespace ${subdomain} {
${values}\
} // namespace ${subdomain}
} // namespace ${domain}
""")
tmpl_enum_value = string.Template("""\
extern const char k${Enum}${Value}[];
""")
tmpl_enum_value_def = string.Template("""\
const char k${Enum}${Value}[] = "${value}";
""")
tmpl_handler = string.Template("""\
namespace ${domain} {
class ${Domain}Handler;
} // namespace domain
""")
tmpl_client = string.Template("""\
namespace ${domain} {
class Client : public DevToolsProtocolClient {
public:
explicit Client(DevToolsProtocolDelegate* notifier);
~Client() override;
${methods}\
};
} // namespace ${domain}
""")
tmpl_event = string.Template("""\
void ${Command}(
scoped_refptr<${Command}Params> params);
""")
tmpl_response = string.Template("""\
void Send${Command}Response(
DevToolsCommandId command_id,
scoped_refptr<${Command}Response> params);
""")
tmpl_setter = string.Template("""\
void Set${Domain}Handler(
devtools::${domain}::${Domain}Handler* ${domain}_handler);
""")
tmpl_callback = string.Template("""\
bool On${Domain}${Command}(
DevToolsCommandId command_id,
scoped_ptr<base::DictionaryValue> params);
""")
tmpl_field = string.Template("""\
devtools::${domain}::${Domain}Handler* ${domain}_handler_;
""")
template_cc = string.Template(header + """\
#include "base/bind.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
${includes}\
namespace content {
DevToolsProtocolDispatcher::DevToolsProtocolDispatcher(
DevToolsProtocolDelegate* notifier)
: notifier_(notifier),
client_(notifier),
${fields_init} {
}
DevToolsProtocolDispatcher::~DevToolsProtocolDispatcher() {
}
DevToolsProtocolDispatcher::CommandHandler
DevToolsProtocolDispatcher::FindCommandHandler(const std::string& method) {
CommandHandlers::iterator it = command_handlers_.find(method);
return it == command_handlers_.end() ? CommandHandler() : it->second;
}
${methods}\
namespace devtools {
const char kProtocolVersion[] = "${major}.${minor}";
bool IsSupportedProtocolVersion(const std::string& version) {
std::vector<base::StringPiece> tokens = base::SplitStringPiece(
version, ".", base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
int major, minor;
return tokens.size() == 2 &&
base::StringToInt(tokens[0], &major) && major == ${major} &&
base::StringToInt(tokens[1], &minor) && minor <= ${minor};
}
template<>
base::Value* CreateValue(const std::string& param) {
return new base::StringValue(param);
}
${types}\
} // namespace devtools
} // namespace content
""")
tmpl_include = string.Template("""\
#include "content/browser/devtools/protocol/${domain}_handler.h"
""")
tmpl_field_init = string.Template("${domain}_handler_(nullptr)")
tmpl_setter_impl = string.Template("""\
void DevToolsProtocolDispatcher::Set${Domain}Handler(
devtools::${domain}::${Domain}Handler* ${domain}_handler) {
DCHECK(!${domain}_handler_);
${domain}_handler_ = ${domain}_handler;
${initializations}\
}
""")
tmpl_register = string.Template("""\
command_handlers_["${Domain}.${command}"] =
base::Bind(
&DevToolsProtocolDispatcher::On${TargetDomain}${Command},
base::Unretained(this));
""")
tmpl_init_client = string.Template("""\
${domain}_handler_->SetClient(make_scoped_ptr(
new devtools::${domain}::Client(notifier_)));
""")
tmpl_callback_impl = string.Template("""\
bool DevToolsProtocolDispatcher::On${Domain}${Command}(
DevToolsCommandId command_id,
scoped_ptr<base::DictionaryValue> params) {
${prep}\
Response response = ${domain}_handler_->${Command}(${args});
scoped_ptr<base::DictionaryValue> protocol_response;
if (client_.SendError(command_id, response))
return true;
if (response.IsFallThrough())
return false;
scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue());
${wrap}\
client_.SendSuccess(command_id, std::move(result));
return true;
}
""")
tmpl_wrap = string.Template("""\
result->Set("${proto_param}", devtools::CreateValue(out_${param}));
""")
tmpl_callback_async_impl = string.Template("""\
bool DevToolsProtocolDispatcher::On${Domain}${Command}(
DevToolsCommandId command_id,
scoped_ptr<base::DictionaryValue> params) {
${prep}\
Response response = ${domain}_handler_->${Command}(${args});
if (client_.SendError(command_id, response))
return true;
return !response.IsFallThrough();
}
""")
tmpl_prep_req = string.Template("""\
${raw_type} in_${param}${init};
if (!params || !params->Get${Type}("${proto_param}", &in_${param})) {
client_.SendError(command_id, Response::InvalidParams("${proto_param}"));
return true;
}
""")
tmpl_prep_req_list = string.Template("""\
base::ListValue* list_${param} = nullptr;
if (!params || !params->GetList("${proto_param}", &list_${param})) {
client_.SendError(command_id, Response::InvalidParams("${proto_param}"));
return true;
}
std::vector<${item_type}> in_${param};
for (base::ListValue::const_iterator it =
list_${param}->begin(); it != list_${param}->end(); ++it) {
${item_raw_type} item;
if (!(*it)->GetAs${ItemType}(&item)) {
client_.SendError(command_id, Response::InvalidParams("${proto_param}"));
return true;
}
in_${param}.push_back(${item_pass});
}
""")
tmpl_prep_opt = string.Template("""\
${raw_type} in_${param}${init};
bool ${param}_found = params && params->Get${Type}(
"${proto_param}",
&in_${param});
""")
tmpl_prep_output = string.Template("""\
${param_type} out_${param}${init};
""")
tmpl_arg_name = string.Template("in_${param}")
tmpl_arg_req = string.Template("${param_pass}")
tmpl_arg_opt = string.Template(
"${param}_found ? ${param_pass} : nullptr")
tmpl_object_pass = string.Template(
"make_scoped_ptr<base::DictionaryValue>(${name}->DeepCopy())")
tmpl_client_impl = string.Template("""\
namespace ${domain} {
Client::Client(DevToolsProtocolDelegate* notifier)
: DevToolsProtocolClient(notifier) {
}
Client::~Client() {
}
${methods}\
} // namespace ${domain}
""")
tmpl_event_impl = string.Template("""\
void Client::${Command}(
scoped_refptr<${Command}Params> params) {
SendNotification("${Domain}.${command}",
params->ToValue());
}
""")
tmpl_response_impl = string.Template("""\
void Client::Send${Command}Response(
DevToolsCommandId command_id,
scoped_refptr<${Command}Response> params) {
SendSuccess(command_id, params->ToValue());
}
""")
tmpl_typename = string.Template("devtools::${domain}::${declared_name}")
def Capitalize(s):
return s[:1].upper() + s[1:]
def Uncamelcase(s):
result = ""
for i, c in enumerate(s):
if c.isupper():
if (i > 0) and ((i < len(s)-1) and s[i+1].islower() or s[i-1].islower()):
result += "_"
result += c.lower()
else:
result += c
return result
types = {}
blink_protocol = json.loads(open(blink_protocol_path, "r").read())
browser_protocol = json.loads(open(browser_protocol_path, "r").read())
type_decls = []
type_impls = []
handler_methods = []
handler_method_impls = []
domain_maps = []
redirects = {}
all_domains = blink_protocol["domains"] + browser_protocol["domains"]
for json_domain in all_domains:
if "types" in json_domain:
for json_type in json_domain["types"]:
types["%s.%s" % (json_domain["domain"], json_type["id"])] = json_type
def DeclareStruct(json_properties, mapping):
methods = []
fields_enum = []
enum_items = []
req_fields_num = 0
for json_prop in json_properties:
prop_map = mapping.copy()
prop_map["proto_param"] = json_prop["name"]
prop_map["param"] = Uncamelcase(json_prop["name"])
prop_map["Param"] = Capitalize(json_prop["name"])
prop_map["subdomain"] = Uncamelcase(prop_map["declared_name"])
del prop_map["declared_name"]
ResolveType(json_prop, prop_map)
prop_map["declared_name"] = mapping["declared_name"]
if json_prop.get("optional"):
methods.append(tmpl_builder_setter_opt.substitute(prop_map))
else:
methods.append(tmpl_builder_setter_req.substitute(prop_map))
enum_items.append("k%s" % prop_map["Param"]);
fields_enum.append(tmpl_builder_enum.substitute(prop_map,
ordinal = req_fields_num))
req_fields_num += 1
all_fields = "kAllSet"
if len(enum_items) > 0:
all_fields = " | ".join(enum_items)
fields_enum.append(tmpl_builder_none_set.substitute(mapping,
all_fields = all_fields))
type_decls.append(tmpl_struct.substitute(mapping,
methods = "\n".join(methods),
fields_enum = "".join(fields_enum)))
def DeclareEnum(json, mapping):
values = []
value_defs = []
tmpl_enum = tmpl_inline_enum
if "declared_name" in mapping:
mapping["Enum"] = mapping["declared_name"]
tmpl_enum = tmpl_named_enum
else:
mapping["Enum"] = Capitalize(mapping["proto_param"])
for enum_value in json["enum"]:
values.append(tmpl_enum_value.substitute(mapping,
Value = Capitalize(enum_value)))
value_defs.append(tmpl_enum_value_def.substitute(mapping,
value = enum_value,
Value = Capitalize(enum_value)))
type_decls.append(tmpl_enum.substitute(mapping,
values = "".join(values)))
type_impls.append(tmpl_enum.substitute(mapping,
values = "".join(value_defs)))
def ResolveRef(json, mapping):
dot_pos = json["$ref"].find(".")
if dot_pos == -1:
domain_name = mapping["Domain"]
type_name = json["$ref"]
else:
domain_name = json["$ref"][:dot_pos]
type_name = json["$ref"][dot_pos + 1:]
json_type = types["%s.%s" % (domain_name, type_name)]
mapping["declared_name"] = Capitalize(type_name)
mapping["Domain"] = domain_name
mapping["domain"] = Uncamelcase(domain_name)
mapping["param_type"] = tmpl_typename.substitute(mapping)
ResolveType(json_type, mapping)
if not "___type_declared" in json_type:
json_type["___type_declared"] = True;
if (json_type.get("type") == "object") and ("properties" in json_type):
DeclareStruct(json_type["properties"], mapping)
else:
if ("enum" in json_type):
DeclareEnum(json_type, mapping)
type_decls.append(tmpl_typedef.substitute(mapping))
def ResolveArray(json, mapping):
items_map = mapping.copy()
ResolveType(json["items"], items_map)
if items_map["Type"] == "List":
# TODO(dgozman) Implement this.
raise Exception("Nested arrays are not implemented")
mapping["param_type"] = "std::vector<%s>" % items_map["param_type"]
mapping["Type"] = "List"
mapping["pass_type"] = "const %s&" % mapping["param_type"]
mapping["storage_type"] = "std::vector<%s>" % items_map["storage_type"]
mapping["raw_type"] = mapping["storage_type"]
mapping["prep_req"] = tmpl_prep_req_list.substitute(mapping,
item_type = items_map["storage_type"],
item_init = items_map["init"],
item_raw_type = items_map["raw_type"],
item_pass = items_map["pass_template"].substitute(name="item", opt=""),
ItemType = items_map["Type"])
mapping["arg_out"] = "&out_%s" % mapping["param"]
def ResolveObject(json, mapping):
mapping["Type"] = "Dictionary"
mapping["storage_type"] = "scoped_ptr<base::DictionaryValue>"
mapping["raw_type"] = "base::DictionaryValue*"
mapping["pass_template"] = tmpl_object_pass
if "properties" in json:
if not "declared_name" in mapping:
mapping["declared_name"] = ("%s%s" %
(mapping["Command"], Capitalize(mapping["proto_param"])))
mapping["param_type"] = ("scoped_refptr<%s>" %
tmpl_typename.substitute(mapping))
DeclareStruct(json["properties"], mapping)
else:
mapping["param_type"] = ("scoped_refptr<%s>" %
tmpl_typename.substitute(mapping))
mapping["pass_type"] = mapping["param_type"]
mapping["arg_out"] = "&out_%s" % mapping["param"]
else:
mapping["param_type"] = "base::DictionaryValue"
mapping["pass_type"] = "scoped_ptr<base::DictionaryValue>"
mapping["arg_out"] = "out_%s.get()" % mapping["param"]
mapping["prep_req"] = tmpl_prep_req.substitute(mapping)
def ResolvePrimitive(json, mapping):
jsonrpc_type = json["type"]
if jsonrpc_type == "boolean":
mapping["param_type"] = "bool"
mapping["Type"] = "Boolean"
mapping["init"] = " = false"
elif jsonrpc_type == "integer":
mapping["param_type"] = "int"
mapping["Type"] = "Integer"
mapping["init"] = " = 0"
elif jsonrpc_type == "number":
mapping["param_type"] = "double"
mapping["Type"] = "Double"
mapping["init"] = " = 0.0"
elif jsonrpc_type == "string":
mapping["param_type"] = "std::string"
mapping["pass_type"] = "const std::string&"
mapping["Type"] = "String"
if "enum" in json and not "declared_name" in mapping:
if not "subdomain" in mapping:
mapping["subdomain"] = Uncamelcase(mapping["command"])
DeclareEnum(json, mapping)
else:
raise Exception("Unknown type: %s" % json_type)
mapping["storage_type"] = mapping["param_type"]
mapping["raw_type"] = mapping["param_type"]
mapping["prep_req"] = tmpl_prep_req.substitute(mapping)
if jsonrpc_type != "string":
mapping["pass_type"] = mapping["param_type"]
mapping["arg_out"] = "&out_%s" % mapping["param"]
def ResolveType(json, mapping):
mapping["init"] = ""
mapping["pass_template"] = string.Template("${opt}${name}")
if "$ref" in json:
ResolveRef(json, mapping)
elif "type" in json:
jsonrpc_type = json["type"]
if jsonrpc_type == "array":
ResolveArray(json, mapping)
elif jsonrpc_type == "object":
ResolveObject(json, mapping)
else:
ResolvePrimitive(json, mapping)
else:
raise Exception("Unknown type at %s.%s %s" %
(mapping["Domain"], mapping["command"], mapping["proto_param"]))
setters = []
fields = []
includes = []
fields_init = []
for json_domain in all_domains:
domain_map = {}
domain_map["Domain"] = json_domain["domain"]
domain_map["domain"] = Uncamelcase(json_domain["domain"])
initializations = []
client_methods = []
client_method_impls = []
domain_empty = True
domain_needs_client = False
if "commands" in json_domain:
for json_command in json_domain["commands"]:
if (not ("handlers" in json_command) or
not ("browser" in json_command["handlers"])):
continue
domain_empty = False
command_map = domain_map.copy()
command_map["command"] = json_command["name"]
command_map["Command"] = Capitalize(json_command["name"])
if "redirect" in json_command:
redirect_domain = json_command["redirect"]
if not (redirect_domain in redirects):
redirects[redirect_domain] = []
command_map["TargetDomain"] = redirect_domain
redirects[redirect_domain].append(tmpl_register.substitute(command_map))
continue
command_map["TargetDomain"] = command_map["Domain"]
prep = []
args = []
if "parameters" in json_command:
for json_param in json_command["parameters"]:
param_map = command_map.copy()
param_map["proto_param"] = json_param["name"]
param_map["param"] = Uncamelcase(json_param["name"])
ResolveType(json_param, param_map)
if json_param.get("optional"):
if param_map["Type"] in ["List"]:
# TODO(vkuzkokov) Implement transformation of base::ListValue
# to std::vector and base::DictonaryValue to struct.
raise Exception(
"Optional array parameters are not implemented")
prep.append(tmpl_prep_opt.substitute(param_map))
param_pass = param_map["pass_template"].substitute(
name=tmpl_arg_name.substitute(param_map),
opt="&")
args.append(
tmpl_arg_opt.substitute(param_map, param_pass=param_pass))
else:
prep.append(param_map["prep_req"])
param_pass = param_map["pass_template"].substitute(
name=tmpl_arg_name.substitute(param_map),
opt="")
args.append(
tmpl_arg_req.substitute(param_map, param_pass=param_pass))
if json_command.get("async"):
domain_needs_client = True
json_returns = []
if "returns" in json_command:
json_returns = json_command["returns"]
command_map["declared_name"] = "%sResponse" % command_map["Command"]
DeclareStruct(json_returns, command_map)
# TODO(vkuzkokov) Pass async callback instance similar to how
# InspectorBackendDispatcher does it. This, however, can work
# only if Blink and Chrome are in the same repo.
args.insert(0, "command_id")
handler_method_impls.append(
tmpl_callback_async_impl.substitute(command_map,
prep = "".join(prep),
args = "\n " + ",\n ".join(args)))
client_methods.append(tmpl_response.substitute(command_map))
client_method_impls.append(tmpl_response_impl.substitute(command_map))
else:
wrap = []
if "returns" in json_command:
for json_param in json_command["returns"]:
param_map = command_map.copy()
param_map["proto_param"] = json_param["name"]
param_map["param"] = Uncamelcase(json_param["name"])
if json_param.get("optional"):
# TODO(vkuzkokov) Implement Optional<T> for value types.
raise Exception("Optional return values are not implemented")
ResolveType(json_param, param_map)
prep.append(tmpl_prep_output.substitute(param_map))
args.append(param_map["arg_out"])
wrap.append(tmpl_wrap.substitute(param_map))
args_str = ""
if len(args) > 0:
args_str = "\n " + ",\n ".join(args)
handler_method_impls.append(tmpl_callback_impl.substitute(command_map,
prep = "".join(prep),
args = args_str,
wrap = "".join(wrap)))
initializations.append(tmpl_register.substitute(command_map))
handler_methods.append(tmpl_callback.substitute(command_map))
if "events" in json_domain:
for json_event in json_domain["events"]:
if (not ("handlers" in json_event) or
not ("browser" in json_event["handlers"])):
continue
domain_empty = False
domain_needs_client = True
event_map = domain_map.copy()
event_map["command"] = json_event["name"]
event_map["Command"] = Capitalize(json_event["name"])
json_parameters = []
if "parameters" in json_event:
json_parameters = json_event["parameters"]
event_map["declared_name"] = "%sParams" % event_map["Command"]
DeclareStruct(json_parameters, event_map);
client_methods.append(tmpl_event.substitute(event_map))
client_method_impls.append(tmpl_event_impl.substitute(event_map))
if domain_empty:
continue
type_decls.append(tmpl_handler.substitute(domain_map))
setters.append(tmpl_setter.substitute(domain_map))
fields.append(tmpl_field.substitute(domain_map))
includes.append(tmpl_include.substitute(domain_map))
fields_init.append(tmpl_field_init.substitute(domain_map))
if domain_needs_client:
type_decls.append(tmpl_client.substitute(domain_map,
methods = "".join(client_methods)))
initializations.append(tmpl_init_client.substitute(domain_map))
type_impls.append(tmpl_client_impl.substitute(domain_map,
methods = "\n".join(client_method_impls)))
domain_map["initializations"] = "".join(initializations)
domain_maps.append(domain_map)
for domain_map in domain_maps:
domain = domain_map["Domain"]
if domain in redirects:
domain_map["initializations"] += "".join(redirects[domain])
handler_method_impls.append(tmpl_setter_impl.substitute(domain_map))
output_h_file = open(output_h_path, "w")
output_cc_file = open(output_cc_path, "w")
output_h_file.write(template_h.substitute({},
types = "\n".join(type_decls),
setters = "".join(setters),
methods = "".join(handler_methods),
fields = "".join(fields)))
output_h_file.close()
output_cc_file.write(template_cc.substitute({},
major = blink_protocol["version"]["major"],
minor = blink_protocol["version"]["minor"],
includes = "".join(sorted(includes)),
fields_init = ",\n ".join(fields_init),
methods = "\n".join(handler_method_impls),
types = "\n".join(type_impls)))
output_cc_file.close()
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1898,
6927,
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,
984,
199,
646,
1059,
199,
646,
2022,
199,
199,
24042,
63,
3922,
63,
515,
275,
984,
14,
3020,
59,
17,
61,
199,
5750,
63,
3922,
63,
515,
275,
984,
14,
3020,
59,
18,
61,
199,
1199,
63,
2055,
63,
515,
275,
984,
14,
3020,
59,
19,
61,
199,
1199,
63,
72,
63,
515,
275,
984,
14,
3020,
59,
20,
61,
199,
199,
1291,
275,
9638,
199,
501,
1898,
6927,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
501,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
501,
1911,
315,
314,
5113,
570,
14,
199,
199,
501,
5749,
13024,
2281,
25420,
12795,
6989,
14,
3506,
2845,
24981,
14,
199,
501,
17065,
701,
199,
501,
221,
1564,
15,
3455,
15,
5750,
15,
32355,
63,
3922,
63,
2232,
63,
4679,
14,
647,
687,
199,
501,
221,
10919,
63,
7522,
15,
21666,
15,
2980,
15,
32355,
15,
3922,
14,
1001,
436,
199,
501,
221,
1564,
15,
5750,
15,
32355,
15,
5750,
63,
3922,
14,
1001,
199,
624,
199,
199,
1160,
63,
72,
275,
1059,
14,
4231,
8,
1291,
435,
9638,
199,
199,
3,
27708,
29417,
63,
31956,
3279,
63,
13260,
20261,
63,
9583,
63,
13260,
20261,
63,
9583,
63,
32550,
540,
63,
40,
63,
199,
3,
4640,
29417,
63,
31956,
3279,
63,
13260,
20261,
63,
9583,
63,
13260,
20261,
63,
9583,
63,
32550,
540,
63,
40,
63,
199,
199,
3,
2613,
665,
16877,
30,
199,
199,
3,
2613,
298,
1317,
15,
5750,
15,
32355,
15,
3922,
15,
32355,
63,
3922,
63,
1258,
14,
72,
2,
199,
199,
3251,
1564,
469,
199,
199,
533,
29314,
11654,
3658,
15461,
27,
199,
199,
3251,
4866,
2537,
469,
199,
199,
18587,
950,
1495,
1022,
3658,
3353,
8607,
27,
199,
199,
2245,
6596,
10682,
3658,
3353,
8,
1297,
2418,
447,
875,
6,
1015,
2736,
199,
199,
1160,
28,
18596,
377,
30,
199,
1095,
447,
1110,
10,
2790,
1110,
8,
1297,
377,
6,
1215,
9,
469,
523,
372,
892,
1300,
447,
32197,
14040,
279,
1110,
8,
635,
2736,
199,
93,
199,
199,
1160,
28,
533,
377,
30,
199,
1095,
447,
1110,
10,
2790,
1110,
8,
23254,
63,
4695,
28,
52,
18181,
1215,
9,
469,
523,
372,
1215,
14,
3221,
7303,
199,
93,
199,
199,
1160,
28,
533,
377,
30,
199,
1095,
447,
1110,
10,
2790,
1110,
8,
23254,
63,
1121,
4695,
28,
52,
30,
1215,
9,
469,
523,
372,
1215,
5118,
1378,
1110,
1252,
3221,
7303,
199,
93,
199,
199,
1160,
28,
18596,
377,
30,
199,
1095,
447,
1110,
10,
2790,
1110,
8,
1297,
2418,
447,
4106,
28,
52,
30,
1215,
9,
469,
523,
1300,
447,
1296,
1110,
10,
754,
275,
892,
1300,
447,
1296,
1110,
7303,
523,
367,
334,
2495,
6,
1242,
520,
1215,
9,
469,
272,
754,
5118,
8310,
8,
2499,
1110,
8,
1053,
16674,
523,
789,
523,
372,
754,
27,
199,
93,
199,
199,
1160,
16137,
199,
1095,
447,
1110,
10,
2790,
1110,
8,
1297,
2418,
447,
875,
6,
1215,
2736,
199,
199,
10545,
1313,
4988,
199,
199,
93,
221,
5001,
3231,
4866,
2537,
199,
199,
533,
29314,
11654,
3658,
15461,
469,
199,
4575,
26,
523,
1808,
5817,
2461,
275,
489,
1300,
447,
2806,
28,
2245,
8,
12680,
11654,
3110,
1304,
12,
2079,
27582,
63,
4695,
28,
1095,
447,
11728,
1110,
30,
13032,
27,
819,
5027,
29314,
11654,
3658,
15461,
8,
12680,
11654,
3658,
21553,
10,
30154,
2736,
523,
6146,
12680,
11654,
3658,
15461,
7303,
819,
5817,
2461,
6668,
3110,
2461,
8,
1297,
2418,
447,
875,
6,
1083,
2736,
199,
199,
10545,
409,
878,
4988,
421,
5726,
26,
523,
1808,
7232,
275,
29314,
11654,
3658,
3041,
447,
2364,
27,
523,
1808,
5817,
25096,
275,
2418,
447,
1130,
28,
1516,
447,
875,
12,
5817,
2461,
30,
27,
199,
199,
10545,
2474,
4988,
819,
29314,
11654,
3658,
21553,
10,
30154,
63,
27,
523,
29314,
11654,
3658,
3041,
1890,
63,
27,
523,
5817,
25096,
1414,
63,
5586,
63,
27,
199,
10545,
955,
4988,
199,
12084,
199,
199,
93,
221,
5001,
3231,
1564,
199,
199,
3,
13739,
221,
5001,
29417,
63,
31956,
3279,
63,
13260,
20261,
63,
9583,
63,
13260,
20261,
63,
9583,
63,
32550,
540,
63,
40,
63,
199,
6141,
199,
199,
11510,
63,
9594,
275,
1059,
14,
4231,
21723,
199,
3251,
10839,
2261,
93,
469,
199,
9594,
10839,
635,
63,
466,
93,
10839,
13545,
63,
354,
12084,
199,
93,
221,
5001,
3231,
10839,
2261,
93,
199,
6141,
199,
199,
11510,
63,
1820,
275,
1059,
14,
4231,
21723,
199,
3251,
10839,
2261,
93,
469,
199,
1160,
28,
442,
603,
7946,
30,
199,
1820,
10839,
13545,
63,
354,
93,
6437,
272,
520,
1300,
447,
2891,
967,
16325,
28,
10545,
13545,
63,
354,
93,
6437,
28,
12880,
1140,
469,
199,
4575,
26,
523,
4952,
469,
272,
1022,
2422,
1084,
275,
378,
12,
199,
10545,
955,
63,
4869,
4988,
523,
16735,
199,
199,
10545,
2474,
4988,
819,
2955,
27582,
63,
1121,
4695,
28,
10545,
13545,
63,
354,
93,
6437,
28,
75,
403,
1084,
1140,
2790,
342,
469,
272,
372,
892,
10839,
13545,
63,
354,
93,
6437,
28,
75,
403,
1084,
30,
7303,
523,
789,
819,
27582,
63,
4695,
28,
1095,
447,
11728,
1110,
30,
4005,
1110,
342,
469,
272,
2955,
63,
479,
8,
12880,
508,
1022,
2422,
1084,
12,
298,
2427,
4382,
4124,
3547,
272,
372,
1852,
63,
23254,
63,
4695,
8,
807,
63,
5118,
27753,
5116,
30910,
523,
789,
421,
5726,
26,
523,
32506,
2702,
10839,
13545,
63,
354,
93,
6437,
28,
16,
30,
27,
523,
32506,
1021,
1300,
447,
2891,
967,
16325,
28,
10545,
13545,
63,
354,
93,
6437,
28,
12880,
1140,
27,
523,
6146,
10545,
13545,
63,
354,
93,
6437,
342,
1052,
819,
10839,
13545,
63,
354,
93,
6437,
342,
520,
1211,
2531,
1222,
1300,
447,
11728,
1110,
1012,
469,
523,
789,
819,
1978,
28,
533,
377,
30,
377,
10,
961,
2822,
342,
469,
272,
2955,
63,
479,
8,
12590,
2031,
3749,
9,
508,
13855,
8
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1898,
6927,
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,
984,
199,
646,
1059,
199,
646,
2022,
199,
199,
24042,
63,
3922,
63,
515,
275,
984,
14,
3020,
59,
17,
61,
199,
5750,
63,
3922,
63,
515,
275,
984,
14,
3020,
59,
18,
61,
199,
1199,
63,
2055,
63,
515,
275,
984,
14,
3020,
59,
19,
61,
199,
1199,
63,
72,
63,
515,
275,
984,
14,
3020,
59,
20,
61,
199,
199,
1291,
275,
9638,
199,
501,
1898,
6927,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
501,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
501,
1911,
315,
314,
5113,
570,
14,
199,
199,
501,
5749,
13024,
2281,
25420,
12795,
6989,
14,
3506,
2845,
24981,
14,
199,
501,
17065,
701,
199,
501,
221,
1564,
15,
3455,
15,
5750,
15,
32355,
63,
3922,
63,
2232,
63,
4679,
14,
647,
687,
199,
501,
221,
10919,
63,
7522,
15,
21666,
15,
2980,
15,
32355,
15,
3922,
14,
1001,
436,
199,
501,
221,
1564,
15,
5750,
15,
32355,
15,
5750,
63,
3922,
14,
1001,
199,
624,
199,
199,
1160,
63,
72,
275,
1059,
14,
4231,
8,
1291,
435,
9638,
199,
199,
3,
27708,
29417,
63,
31956,
3279,
63,
13260,
20261,
63,
9583,
63,
13260,
20261,
63,
9583,
63,
32550,
540,
63,
40,
63,
199,
3,
4640,
29417,
63,
31956,
3279,
63,
13260,
20261,
63,
9583,
63,
13260,
20261,
63,
9583,
63,
32550,
540,
63,
40,
63,
199,
199,
3,
2613,
665,
16877,
30,
199,
199,
3,
2613,
298,
1317,
15,
5750,
15,
32355,
15,
3922,
15,
32355,
63,
3922,
63,
1258,
14,
72,
2,
199,
199,
3251,
1564,
469,
199,
199,
533,
29314,
11654,
3658,
15461,
27,
199,
199,
3251,
4866,
2537,
469,
199,
199,
18587,
950,
1495,
1022,
3658,
3353,
8607,
27,
199,
199,
2245,
6596,
10682,
3658,
3353,
8,
1297,
2418,
447,
875,
6,
1015,
2736,
199,
199,
1160,
28,
18596,
377,
30,
199,
1095,
447,
1110,
10,
2790,
1110,
8,
1297,
377,
6,
1215,
9,
469,
523,
372,
892,
1300,
447,
32197,
14040,
279,
1110,
8,
635,
2736,
199,
93,
199,
199,
1160,
28,
533,
377,
30,
199,
1095,
447,
1110,
10,
2790,
1110,
8,
23254,
63,
4695,
28,
52,
18181,
1215,
9,
469,
523,
372,
1215,
14,
3221,
7303,
199,
93,
199,
199,
1160,
28,
533,
377,
30,
199,
1095,
447,
1110,
10,
2790,
1110,
8,
23254,
63,
1121,
4695,
28,
52,
30,
1215,
9,
469,
523,
372,
1215,
5118,
1378,
1110,
1252,
3221,
7303,
199,
93,
199,
199,
1160,
28,
18596,
377,
30,
199,
1095,
447,
1110,
10,
2790,
1110,
8,
1297,
2418,
447,
4106,
28,
52,
30,
1215,
9,
469,
523,
1300,
447,
1296,
1110,
10,
754,
275,
892,
1300,
447,
1296,
1110,
7303,
523,
367,
334,
2495,
6,
1242,
520,
1215,
9,
469,
272,
754,
5118,
8310,
8,
2499,
1110,
8,
1053,
16674,
523,
789,
523,
372,
754,
27,
199,
93,
199,
199,
1160,
16137,
199,
1095,
447,
1110,
10,
2790,
1110,
8,
1297,
2418,
447,
875,
6,
1215,
2736,
199,
199,
10545,
1313,
4988,
199,
199,
93,
221,
5001,
3231,
4866,
2537,
199,
199,
533,
29314,
11654,
3658,
15461,
469,
199,
4575,
26,
523,
1808,
5817,
2461,
275,
489,
1300,
447,
2806,
28,
2245,
8,
12680,
11654,
3110,
1304,
12,
2079,
27582,
63,
4695,
28,
1095,
447,
11728,
1110,
30,
13032,
27,
819,
5027,
29314,
11654,
3658,
15461,
8,
12680,
11654,
3658,
21553,
10,
30154,
2736,
523,
6146,
12680,
11654,
3658,
15461,
7303,
819,
5817,
2461,
6668,
3110,
2461,
8,
1297,
2418,
447,
875,
6,
1083,
2736,
199,
199,
10545,
409,
878,
4988,
421,
5726,
26,
523,
1808,
7232,
275,
29314,
11654,
3658,
3041,
447,
2364,
27,
523,
1808,
5817,
25096,
275,
2418,
447,
1130,
28,
1516,
447,
875,
12,
5817,
2461,
30,
27,
199,
199,
10545,
2474,
4988,
819,
29314,
11654,
3658,
21553,
10,
30154,
63,
27,
523,
29314,
11654,
3658,
3041,
1890,
63,
27,
523,
5817,
25096,
1414,
63,
5586,
63,
27,
199,
10545,
955,
4988,
199,
12084,
199,
199,
93,
221,
5001,
3231,
1564,
199,
199,
3,
13739,
221,
5001,
29417,
63,
31956,
3279,
63,
13260,
20261,
63,
9583,
63,
13260,
20261,
63,
9583,
63,
32550,
540,
63,
40,
63,
199,
6141,
199,
199,
11510,
63,
9594,
275,
1059,
14,
4231,
21723,
199,
3251,
10839,
2261,
93,
469,
199,
9594,
10839,
635,
63,
466,
93,
10839,
13545,
63,
354,
12084,
199,
93,
221,
5001,
3231,
10839,
2261,
93,
199,
6141,
199,
199,
11510,
63,
1820,
275,
1059,
14,
4231,
21723,
199,
3251,
10839,
2261,
93,
469,
199,
1160,
28,
442,
603,
7946,
30,
199,
1820,
10839,
13545,
63,
354,
93,
6437,
272,
520,
1300,
447,
2891,
967,
16325,
28,
10545,
13545,
63,
354,
93,
6437,
28,
12880,
1140,
469,
199,
4575,
26,
523,
4952,
469,
272,
1022,
2422,
1084,
275,
378,
12,
199,
10545,
955,
63,
4869,
4988,
523,
16735,
199,
199,
10545,
2474,
4988,
819,
2955,
27582,
63,
1121,
4695,
28,
10545,
13545,
63,
354,
93,
6437,
28,
75,
403,
1084,
1140,
2790,
342,
469,
272,
372,
892,
10839,
13545,
63,
354,
93,
6437,
28,
75,
403,
1084,
30,
7303,
523,
789,
819,
27582,
63,
4695,
28,
1095,
447,
11728,
1110,
30,
4005,
1110,
342,
469,
272,
2955,
63,
479,
8,
12880,
508,
1022,
2422,
1084,
12,
298,
2427,
4382,
4124,
3547,
272,
372,
1852,
63,
23254,
63,
4695,
8,
807,
63,
5118,
27753,
5116,
30910,
523,
789,
421,
5726,
26,
523,
32506,
2702,
10839,
13545,
63,
354,
93,
6437,
28,
16,
30,
27,
523,
32506,
1021,
1300,
447,
2891,
967,
16325,
28,
10545,
13545,
63,
354,
93,
6437,
28,
12880,
1140,
27,
523,
6146,
10545,
13545,
63,
354,
93,
6437,
342,
1052,
819,
10839,
13545,
63,
354,
93,
6437,
342,
520,
1211,
2531,
1222,
1300,
447,
11728,
1110,
1012,
469,
523,
789,
819,
1978,
28,
533,
377,
30,
377,
10,
961,
2822,
342,
469,
272,
2955,
63,
479,
8,
12590,
2031,
3749,
9,
508,
13855,
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,
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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
] |
scottdangelo/RemoveVolumeMangerLocks
|
cinder/api/views/types.py
|
28
|
1450
|
# Copyright 2012 Red Hat, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from cinder.api import common
class ViewBuilder(common.ViewBuilder):
def show(self, request, volume_type, brief=False):
"""Trim away extraneous volume type attributes."""
trimmed = dict(id=volume_type.get('id'),
name=volume_type.get('name'),
is_public=volume_type.get('is_public'),
extra_specs=volume_type.get('extra_specs'),
description=volume_type.get('description'))
return trimmed if brief else dict(volume_type=trimmed)
def index(self, request, volume_types):
"""Index over trimmed volume types."""
volume_types_list = [self.show(request, volume_type, True)
for volume_type in volume_types]
return dict(volume_types=volume_types_list)
|
apache-2.0
|
[
3,
1898,
6029,
9572,
13002,
12,
3277,
14,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
504,
13069,
14,
1246,
492,
2863,
421,
199,
533,
10935,
6437,
8,
2330,
14,
2768,
6437,
304,
339,
347,
2498,
8,
277,
12,
1056,
12,
3301,
63,
466,
12,
29226,
29,
797,
304,
267,
408,
31081,
13437,
1599,
26364,
1785,
3301,
730,
3004,
1041,
267,
24196,
275,
1211,
8,
344,
29,
2405,
63,
466,
14,
362,
360,
344,
659,
2432,
536,
29,
2405,
63,
466,
14,
362,
360,
354,
659,
2432,
365,
63,
3455,
29,
2405,
63,
466,
14,
362,
360,
374,
63,
3455,
659,
2432,
2402,
63,
7273,
29,
2405,
63,
466,
14,
362,
360,
2911,
63,
7273,
659,
2432,
1369,
29,
2405,
63,
466,
14,
362,
360,
1802,
1333,
267,
372,
24196,
340,
29226,
587,
1211,
8,
2405,
63,
466,
29,
12263,
3594,
9,
339,
347,
1478,
8,
277,
12,
1056,
12,
3301,
63,
1313,
304,
267,
408,
2681,
1806,
24196,
3301,
2943,
1041,
267,
3301,
63,
1313,
63,
513,
275,
359,
277,
14,
2384,
8,
1069,
12,
3301,
63,
466,
12,
715,
9,
2490,
367,
3301,
63,
466,
315,
3301,
63,
1313,
61,
267,
372,
1211,
8,
2405,
63,
1313,
29,
2405,
63,
1313,
63,
513,
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
] |
[
1898,
6029,
9572,
13002,
12,
3277,
14,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
504,
13069,
14,
1246,
492,
2863,
421,
199,
533,
10935,
6437,
8,
2330,
14,
2768,
6437,
304,
339,
347,
2498,
8,
277,
12,
1056,
12,
3301,
63,
466,
12,
29226,
29,
797,
304,
267,
408,
31081,
13437,
1599,
26364,
1785,
3301,
730,
3004,
1041,
267,
24196,
275,
1211,
8,
344,
29,
2405,
63,
466,
14,
362,
360,
344,
659,
2432,
536,
29,
2405,
63,
466,
14,
362,
360,
354,
659,
2432,
365,
63,
3455,
29,
2405,
63,
466,
14,
362,
360,
374,
63,
3455,
659,
2432,
2402,
63,
7273,
29,
2405,
63,
466,
14,
362,
360,
2911,
63,
7273,
659,
2432,
1369,
29,
2405,
63,
466,
14,
362,
360,
1802,
1333,
267,
372,
24196,
340,
29226,
587,
1211,
8,
2405,
63,
466,
29,
12263,
3594,
9,
339,
347,
1478,
8,
277,
12,
1056,
12,
3301,
63,
1313,
304,
267,
408,
2681,
1806,
24196,
3301,
2943,
1041,
267,
3301,
63,
1313,
63,
513,
275,
359,
277,
14,
2384,
8,
1069,
12,
3301,
63,
466,
12,
715,
9,
2490,
367,
3301,
63,
466,
315,
3301,
63,
1313,
61,
267,
372,
1211,
8,
2405,
63,
1313,
29,
2405,
63,
1313,
63,
513,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
kenorb-contrib/BitTorrent
|
twisted/internet/gtk2reactor.py
|
2
|
9930
|
# Copyright (c) 2001-2004 Twisted Matrix Laboratories.
# See LICENSE for details.
"""
This module provides support for Twisted to interact with the glib/gtk2 mainloop.
In order to use this support, simply do the following::
| from twisted.internet import gtk2reactor
| gtk2reactor.install()
Then use twisted.internet APIs as usual. The other methods here are not
intended to be called directly.
When installing the reactor, you can choose whether to use the glib
event loop or the GTK+ event loop which is based on it but adds GUI
integration.
API Stability: stable
Maintainer: U{Itamar Shtull-Trauring<mailto:twisted@itamarst.org>}
"""
__all__ = ['install']
# System Imports
import sys
from zope.interface import implements
try:
if not hasattr(sys, 'frozen'):
# Don't want to check this for py2exe
import pygtk
pygtk.require('2.0')
except (ImportError, AttributeError):
pass # maybe we're using pygtk before this hack existed.
import gobject
if hasattr(gobject, "threads_init"):
# recent versions of python-gtk expose this. python-gtk=2.4.1
# (wrapping glib-2.4.7) does. python-gtk=2.0.0 (wrapping
# glib-2.2.3) does not.
gobject.threads_init()
# Twisted Imports
from twisted.python import log, threadable, runtime, failure, components
from twisted.internet.interfaces import IReactorFDSet
# Sibling Imports
from twisted.internet import main, posixbase, error, selectreactor
reads = {}
writes = {}
hasReader = reads.has_key
hasWriter = writes.has_key
# the next callback
_simtag = None
POLL_DISCONNECTED = gobject.IO_HUP | gobject.IO_ERR | gobject.IO_NVAL
# glib's iochannel sources won't tell us about any events that we haven't
# asked for, even if those events aren't sensible inputs to the poll()
# call.
INFLAGS = gobject.IO_IN | POLL_DISCONNECTED
OUTFLAGS = gobject.IO_OUT | POLL_DISCONNECTED
def _our_mainquit():
# XXX: gtk.main_quit() (which is used for crash()) raises an exception if
# gtk.main_level() == 0; however, all the tests freeze if we use this
# function to stop the reactor. what gives? (I believe this may have been
# a stupid mistake where I forgot to import gtk here... I will remove this
# comment if the tests pass)
import gtk
if gtk.main_level():
gtk.main_quit()
class Gtk2Reactor(posixbase.PosixReactorBase):
"""GTK+-2 event loop reactor.
"""
implements(IReactorFDSet)
def __init__(self, useGtk=True):
self.context = gobject.main_context_default()
self.loop = gobject.MainLoop()
posixbase.PosixReactorBase.__init__(self)
# pre 2.3.91 the glib iteration and mainloop functions didn't release
# global interpreter lock, thus breaking thread and signal support.
if (hasattr(gobject, "pygtk_version") and gobject.pygtk_version >= (2, 3, 91)
and not useGtk):
self.__pending = self.context.pending
self.__iteration = self.context.iteration
self.__crash = self.loop.quit
self.__run = self.loop.run
else:
import gtk
self.__pending = gtk.events_pending
self.__iteration = gtk.main_iteration
self.__crash = _our_mainquit
self.__run = gtk.main
# The input_add function in pygtk1 checks for objects with a
# 'fileno' method and, if present, uses the result of that method
# as the input source. The pygtk2 input_add does not do this. The
# function below replicates the pygtk1 functionality.
# In addition, pygtk maps gtk.input_add to _gobject.io_add_watch, and
# g_io_add_watch() takes different condition bitfields than
# gtk_input_add(). We use g_io_add_watch() here in case pygtk fixes this
# bug.
def input_add(self, source, condition, callback):
if hasattr(source, 'fileno'):
# handle python objects
def wrapper(source, condition, real_s=source, real_cb=callback):
return real_cb(real_s, condition)
return gobject.io_add_watch(source.fileno(), condition, wrapper)
else:
return gobject.io_add_watch(source, condition, callback)
def addReader(self, reader):
if not hasReader(reader):
reads[reader] = self.input_add(reader, INFLAGS, self.callback)
def addWriter(self, writer):
if not hasWriter(writer):
writes[writer] = self.input_add(writer, OUTFLAGS, self.callback)
def removeAll(self):
return self._removeAll(reads, writes)
def removeReader(self, reader):
if hasReader(reader):
gobject.source_remove(reads[reader])
del reads[reader]
def removeWriter(self, writer):
if hasWriter(writer):
gobject.source_remove(writes[writer])
del writes[writer]
doIterationTimer = None
def doIterationTimeout(self, *args):
self.doIterationTimer = None
return 0 # auto-remove
def doIteration(self, delay):
# flush some pending events, return if there was something to do
# don't use the usual "while self.context.pending(): self.context.iteration()"
# idiom because lots of IO (in particular test_tcp's
# ProperlyCloseFilesTestCase) can keep us from ever exiting.
log.msg(channel='system', event='iteration', reactor=self)
if self.__pending():
self.__iteration(0)
return
# nothing to do, must delay
if delay == 0:
return # shouldn't delay, so just return
self.doIterationTimer = gobject.timeout_add(int(delay * 1000),
self.doIterationTimeout)
# This will either wake up from IO or from a timeout.
self.__iteration(1) # block
# note: with the .simulate timer below, delays > 0.1 will always be
# woken up by the .simulate timer
if self.doIterationTimer:
# if woken by IO, need to cancel the timer
gobject.source_remove(self.doIterationTimer)
self.doIterationTimer = None
def crash(self):
self.__crash()
def run(self, installSignalHandlers=1):
self.startRunning(installSignalHandlers=installSignalHandlers)
gobject.timeout_add(0, self.simulate)
self.__run()
def _doReadOrWrite(self, source, condition, faildict={
error.ConnectionDone: failure.Failure(error.ConnectionDone()),
error.ConnectionLost: failure.Failure(error.ConnectionLost()),
}):
why = None
didRead = None
if condition & POLL_DISCONNECTED and \
not (condition & gobject.IO_IN):
why = main.CONNECTION_LOST
else:
try:
if condition & gobject.IO_IN:
why = source.doRead()
didRead = source.doRead
if not why and condition & gobject.IO_OUT:
# if doRead caused connectionLost, don't call doWrite
# if doRead is doWrite, don't call it again.
if not source.disconnected and source.doWrite != didRead:
why = source.doWrite()
didRead = source.doWrite # if failed it was in write
except:
why = sys.exc_info()[1]
log.msg('Error In %s' % source)
log.deferr()
if why:
self._disconnectSelectable(source, why, didRead == source.doRead)
def callback(self, source, condition):
log.callWithLogger(source, self._doReadOrWrite, source, condition)
self.simulate() # fire Twisted timers
return 1 # 1=don't auto-remove the source
def simulate(self):
"""Run simulation loops and reschedule callbacks.
"""
global _simtag
if _simtag is not None:
gobject.source_remove(_simtag)
self.runUntilCurrent()
timeout = min(self.timeout(), 0.1)
if timeout is None:
timeout = 0.1
# grumble
_simtag = gobject.timeout_add(int(timeout * 1010), self.simulate)
class PortableGtkReactor(selectreactor.SelectReactor):
"""Reactor that works on Windows.
input_add is not supported on GTK+ for Win32, apparently.
"""
def crash(self):
import gtk
# mainquit is deprecated in newer versions
if hasattr(gtk, 'main_quit'):
gtk.main_quit()
else:
gtk.mainquit()
def run(self, installSignalHandlers=1):
import gtk
self.startRunning(installSignalHandlers=installSignalHandlers)
self.simulate()
# mainloop is deprecated in newer versions
if hasattr(gtk, 'main'):
gtk.main()
else:
gtk.mainloop()
def simulate(self):
"""Run simulation loops and reschedule callbacks.
"""
global _simtag
if _simtag is not None:
gobject.source_remove(_simtag)
self.iterate()
timeout = min(self.timeout(), 0.1)
if timeout is None:
timeout = 0.1
# grumble
_simtag = gobject.timeout_add(int(timeout * 1010), self.simulate)
def install(useGtk=True):
"""Configure the twisted mainloop to be run inside the gtk mainloop.
@param useGtk: should glib rather than GTK+ event loop be
used (this will be slightly faster but does not support GUI).
"""
reactor = Gtk2Reactor(useGtk)
from twisted.internet.main import installReactor
installReactor(reactor)
return reactor
def portableInstall(useGtk=True):
"""Configure the twisted mainloop to be run inside the gtk mainloop.
"""
reactor = PortableGtkReactor()
from twisted.internet.main import installReactor
installReactor(reactor)
return reactor
if runtime.platform.getType() != 'posix':
install = portableInstall
|
gpl-3.0
|
[
3,
1898,
334,
67,
9,
12521,
13,
15431,
17078,
8449,
26640,
14,
199,
3,
1666,
5113,
367,
2436,
14,
421,
199,
624,
199,
2765,
859,
6571,
2291,
367,
17078,
370,
17232,
543,
314,
486,
773,
15,
12275,
18,
2446,
3813,
14,
199,
199,
607,
1865,
370,
675,
642,
2291,
12,
9329,
886,
314,
2569,
447,
339,
1204,
221,
687,
7390,
14,
4901,
492,
8116,
18,
13544,
272,
1204,
221,
8116,
18,
13544,
14,
3174,
342,
199,
199,
28226,
675,
7390,
14,
4901,
15913,
465,
20195,
14,
221,
710,
1163,
3102,
2348,
787,
440,
199,
262,
6943,
370,
506,
2797,
5370,
14,
199,
199,
11423,
22200,
314,
9655,
12,
1265,
883,
11496,
3775,
370,
675,
314,
486,
773,
199,
1430,
4438,
503,
314,
598,
15263,
11,
1566,
4438,
1314,
365,
4079,
641,
652,
1325,
9584,
17160,
199,
15092,
14,
199,
199,
3735,
1933,
3616,
26,
17830,
199,
199,
11903,
8368,
281,
26,
738,
91,
7940,
455,
285,
428,
517,
979,
13,
2437,
4039,
28,
26206,
26,
12145,
32,
390,
455,
285,
270,
14,
1308,
23307,
199,
624,
199,
199,
363,
452,
363,
275,
788,
3174,
418,
199,
199,
3,
6187,
24339,
199,
646,
984,
199,
504,
20110,
14,
3266,
492,
9031,
199,
893,
26,
272,
340,
440,
2688,
8,
1274,
12,
283,
11202,
735,
267,
327,
7529,
1133,
2934,
370,
1104,
642,
367,
1134,
18,
5803,
267,
492,
1134,
12275,
267,
1134,
12275,
14,
4365,
360,
18,
14,
16,
358,
199,
2590,
334,
17825,
12,
4281,
304,
272,
986,
327,
11703,
781,
3984,
1808,
1134,
12275,
2544,
642,
11176,
30482,
14,
199,
646,
25595,
199,
692,
2688,
8,
71,
785,
12,
298,
6962,
63,
826,
2349,
272,
327,
8058,
5459,
402,
2366,
13,
12275,
23705,
642,
14,
2366,
13,
12275,
29,
18,
14,
20,
14,
17,
272,
327,
334,
87,
15521,
486,
773,
13,
18,
14,
20,
14,
23,
9,
1630,
14,
2366,
13,
12275,
29,
18,
14,
16,
14,
16,
334,
87,
15521,
272,
327,
486,
773,
13,
18,
14,
18,
14,
19,
9,
1630,
440,
14,
272,
25595,
14,
6962,
63,
826,
342,
199,
199,
3,
17078,
24339,
199,
504,
7390,
14,
1548,
492,
943,
12,
2462,
461,
12,
8836,
12,
5988,
12,
7323,
199,
504,
7390,
14,
4901,
14,
7436,
492,
473,
15860,
7902,
1084,
199,
199,
3,
428,
12654,
24339,
199,
504,
7390,
14,
4901,
492,
2446,
12,
10694,
1095,
12,
1125,
12,
3504,
13544,
199,
199,
15656,
275,
1052,
199,
16334,
275,
1052,
199,
1989,
5929,
275,
11597,
14,
1989,
63,
498,
199,
1989,
6261,
275,
14511,
14,
1989,
63,
498,
199,
199,
3,
314,
2163,
3233,
199,
63,
5206,
1450,
275,
488,
199,
16428,
63,
6178,
14657,
1149,
275,
25595,
14,
2090,
63,
40,
2160,
1204,
25595,
14,
2090,
63,
2666,
1204,
25595,
14,
2090,
63,
46,
3204,
199,
199,
3,
486,
773,
1159,
5890,
2775,
5274,
7859,
1133,
11480,
2739,
3595,
1263,
4474,
626,
781,
19051,
1133,
199,
3,
20864,
367,
12,
2755,
340,
5204,
4474,
10621,
1133,
27962,
4153,
370,
314,
11271,
342,
199,
3,
1240,
14,
199,
568,
4831,
275,
25595,
14,
2090,
63,
568,
1204,
25480,
44,
63,
6178,
14657,
1149,
199,
1877,
4831,
275,
25595,
14,
2090,
63,
1877,
1204,
25480,
44,
63,
6178,
14657,
1149,
199,
199,
318,
485,
567,
63,
973,
10589,
837,
272,
327,
5787,
26,
8116,
14,
973,
63,
10589,
342,
334,
6777,
365,
1202,
367,
12420,
1012,
6534,
376,
1919,
340,
272,
327,
8116,
14,
973,
63,
1896,
342,
508,
378,
27,
13432,
12,
1006,
314,
2295,
22778,
340,
781,
675,
642,
272,
327,
805,
370,
3631,
314,
9655,
14,
221,
4052,
10557,
31,
221,
334,
41,
506,
317,
4754,
642,
1443,
1172,
2757,
272,
327,
282,
410,
31596,
27572,
1728,
2382,
473,
367,
7808,
370,
492,
8116,
2348,
1396,
473,
911,
2813,
642,
272,
327,
3721,
340,
314,
2295,
986,
9,
272,
492,
8116,
272,
340,
8116,
14,
973,
63,
1896,
837,
267,
8116,
14,
973,
63,
10589,
342,
199,
199,
533,
11424,
18,
15860,
8,
9228,
1095,
14,
1575,
4174,
15860,
1563,
304,
272,
408,
8391,
43,
16341,
18,
1566,
4438,
9655,
14,
272,
408,
339,
9031,
8,
30861,
7902,
1084,
9,
339,
347,
636,
826,
721,
277,
12,
675,
18891,
29,
549,
304,
267,
291,
14,
1100,
275,
25595,
14,
973,
63,
1100,
63,
885,
342,
267,
291,
14,
3813,
275,
25595,
14,
6756,
7382,
342,
267,
10694,
1095,
14,
1575,
4174,
15860,
1563,
855,
826,
721,
277,
9,
267,
327,
876,
499,
14,
19,
14,
3328,
314,
486,
773,
8494,
436,
2446,
3813,
3423,
9980,
1133,
4683,
267,
327,
2288,
12693,
4650,
12,
12850,
27485,
2462,
436,
4673,
2291,
14,
267,
340,
334,
11161,
8,
71,
785,
12,
298,
647,
12275,
63,
1023,
531,
436,
25595,
14,
647,
12275,
63,
1023,
2356,
334,
18,
12,
650,
12,
21358,
9,
288,
436,
440,
675,
18891,
304,
288,
291,
855,
6455,
275,
291,
14,
1100,
14,
6455,
288,
291,
855,
12575,
275,
291,
14,
1100,
14,
12575,
288,
291,
855,
14807,
275,
291,
14,
3813,
14,
10589,
288,
291,
855,
1065,
275,
291,
14,
3813,
14,
1065,
267,
587,
26,
288,
492,
8116,
288,
291,
855,
6455,
275,
8116,
14,
4368,
63,
6455,
288,
291,
855,
12575,
275,
8116,
14,
973,
63,
12575,
288,
291,
855,
14807,
275,
485,
567,
63,
973,
10589,
288,
291,
855,
1065,
275,
8116,
14,
973,
339,
327,
710,
1324,
63,
525,
805,
315,
1134,
12275,
17,
5920,
367,
2251,
543,
282,
272,
327,
283,
9843,
7,
1083,
436,
12,
340,
3451,
12,
4440,
314,
754,
402,
626,
1083,
272,
327,
465,
314,
1324,
1350,
14,
710,
1134,
12275,
18,
1324,
63,
525,
1630,
440,
886,
642,
14,
710,
272,
327,
805,
5084,
1833,
606,
2335,
314,
1134,
12275,
17,
9330,
14,
339,
327,
1010,
10234,
12,
1134,
12275,
9033,
8116,
14,
1210,
63,
525,
370,
485,
71,
785,
14,
2308,
63,
525,
63,
6821,
12,
436,
272,
327,
486,
63,
2308,
63,
525,
63,
6821,
342,
6181,
3365,
5558,
4546,
955,
2419,
272,
327,
8116,
63,
1210,
63,
525,
1252,
2136,
675,
486,
63,
2308,
63,
525,
63,
6821,
342,
2348,
315,
1930,
1134,
12275,
25079,
642,
272,
327,
6519,
14
] |
[
1898,
334,
67,
9,
12521,
13,
15431,
17078,
8449,
26640,
14,
199,
3,
1666,
5113,
367,
2436,
14,
421,
199,
624,
199,
2765,
859,
6571,
2291,
367,
17078,
370,
17232,
543,
314,
486,
773,
15,
12275,
18,
2446,
3813,
14,
199,
199,
607,
1865,
370,
675,
642,
2291,
12,
9329,
886,
314,
2569,
447,
339,
1204,
221,
687,
7390,
14,
4901,
492,
8116,
18,
13544,
272,
1204,
221,
8116,
18,
13544,
14,
3174,
342,
199,
199,
28226,
675,
7390,
14,
4901,
15913,
465,
20195,
14,
221,
710,
1163,
3102,
2348,
787,
440,
199,
262,
6943,
370,
506,
2797,
5370,
14,
199,
199,
11423,
22200,
314,
9655,
12,
1265,
883,
11496,
3775,
370,
675,
314,
486,
773,
199,
1430,
4438,
503,
314,
598,
15263,
11,
1566,
4438,
1314,
365,
4079,
641,
652,
1325,
9584,
17160,
199,
15092,
14,
199,
199,
3735,
1933,
3616,
26,
17830,
199,
199,
11903,
8368,
281,
26,
738,
91,
7940,
455,
285,
428,
517,
979,
13,
2437,
4039,
28,
26206,
26,
12145,
32,
390,
455,
285,
270,
14,
1308,
23307,
199,
624,
199,
199,
363,
452,
363,
275,
788,
3174,
418,
199,
199,
3,
6187,
24339,
199,
646,
984,
199,
504,
20110,
14,
3266,
492,
9031,
199,
893,
26,
272,
340,
440,
2688,
8,
1274,
12,
283,
11202,
735,
267,
327,
7529,
1133,
2934,
370,
1104,
642,
367,
1134,
18,
5803,
267,
492,
1134,
12275,
267,
1134,
12275,
14,
4365,
360,
18,
14,
16,
358,
199,
2590,
334,
17825,
12,
4281,
304,
272,
986,
327,
11703,
781,
3984,
1808,
1134,
12275,
2544,
642,
11176,
30482,
14,
199,
646,
25595,
199,
692,
2688,
8,
71,
785,
12,
298,
6962,
63,
826,
2349,
272,
327,
8058,
5459,
402,
2366,
13,
12275,
23705,
642,
14,
2366,
13,
12275,
29,
18,
14,
20,
14,
17,
272,
327,
334,
87,
15521,
486,
773,
13,
18,
14,
20,
14,
23,
9,
1630,
14,
2366,
13,
12275,
29,
18,
14,
16,
14,
16,
334,
87,
15521,
272,
327,
486,
773,
13,
18,
14,
18,
14,
19,
9,
1630,
440,
14,
272,
25595,
14,
6962,
63,
826,
342,
199,
199,
3,
17078,
24339,
199,
504,
7390,
14,
1548,
492,
943,
12,
2462,
461,
12,
8836,
12,
5988,
12,
7323,
199,
504,
7390,
14,
4901,
14,
7436,
492,
473,
15860,
7902,
1084,
199,
199,
3,
428,
12654,
24339,
199,
504,
7390,
14,
4901,
492,
2446,
12,
10694,
1095,
12,
1125,
12,
3504,
13544,
199,
199,
15656,
275,
1052,
199,
16334,
275,
1052,
199,
1989,
5929,
275,
11597,
14,
1989,
63,
498,
199,
1989,
6261,
275,
14511,
14,
1989,
63,
498,
199,
199,
3,
314,
2163,
3233,
199,
63,
5206,
1450,
275,
488,
199,
16428,
63,
6178,
14657,
1149,
275,
25595,
14,
2090,
63,
40,
2160,
1204,
25595,
14,
2090,
63,
2666,
1204,
25595,
14,
2090,
63,
46,
3204,
199,
199,
3,
486,
773,
1159,
5890,
2775,
5274,
7859,
1133,
11480,
2739,
3595,
1263,
4474,
626,
781,
19051,
1133,
199,
3,
20864,
367,
12,
2755,
340,
5204,
4474,
10621,
1133,
27962,
4153,
370,
314,
11271,
342,
199,
3,
1240,
14,
199,
568,
4831,
275,
25595,
14,
2090,
63,
568,
1204,
25480,
44,
63,
6178,
14657,
1149,
199,
1877,
4831,
275,
25595,
14,
2090,
63,
1877,
1204,
25480,
44,
63,
6178,
14657,
1149,
199,
199,
318,
485,
567,
63,
973,
10589,
837,
272,
327,
5787,
26,
8116,
14,
973,
63,
10589,
342,
334,
6777,
365,
1202,
367,
12420,
1012,
6534,
376,
1919,
340,
272,
327,
8116,
14,
973,
63,
1896,
342,
508,
378,
27,
13432,
12,
1006,
314,
2295,
22778,
340,
781,
675,
642,
272,
327,
805,
370,
3631,
314,
9655,
14,
221,
4052,
10557,
31,
221,
334,
41,
506,
317,
4754,
642,
1443,
1172,
2757,
272,
327,
282,
410,
31596,
27572,
1728,
2382,
473,
367,
7808,
370,
492,
8116,
2348,
1396,
473,
911,
2813,
642,
272,
327,
3721,
340,
314,
2295,
986,
9,
272,
492,
8116,
272,
340,
8116,
14,
973,
63,
1896,
837,
267,
8116,
14,
973,
63,
10589,
342,
199,
199,
533,
11424,
18,
15860,
8,
9228,
1095,
14,
1575,
4174,
15860,
1563,
304,
272,
408,
8391,
43,
16341,
18,
1566,
4438,
9655,
14,
272,
408,
339,
9031,
8,
30861,
7902,
1084,
9,
339,
347,
636,
826,
721,
277,
12,
675,
18891,
29,
549,
304,
267,
291,
14,
1100,
275,
25595,
14,
973,
63,
1100,
63,
885,
342,
267,
291,
14,
3813,
275,
25595,
14,
6756,
7382,
342,
267,
10694,
1095,
14,
1575,
4174,
15860,
1563,
855,
826,
721,
277,
9,
267,
327,
876,
499,
14,
19,
14,
3328,
314,
486,
773,
8494,
436,
2446,
3813,
3423,
9980,
1133,
4683,
267,
327,
2288,
12693,
4650,
12,
12850,
27485,
2462,
436,
4673,
2291,
14,
267,
340,
334,
11161,
8,
71,
785,
12,
298,
647,
12275,
63,
1023,
531,
436,
25595,
14,
647,
12275,
63,
1023,
2356,
334,
18,
12,
650,
12,
21358,
9,
288,
436,
440,
675,
18891,
304,
288,
291,
855,
6455,
275,
291,
14,
1100,
14,
6455,
288,
291,
855,
12575,
275,
291,
14,
1100,
14,
12575,
288,
291,
855,
14807,
275,
291,
14,
3813,
14,
10589,
288,
291,
855,
1065,
275,
291,
14,
3813,
14,
1065,
267,
587,
26,
288,
492,
8116,
288,
291,
855,
6455,
275,
8116,
14,
4368,
63,
6455,
288,
291,
855,
12575,
275,
8116,
14,
973,
63,
12575,
288,
291,
855,
14807,
275,
485,
567,
63,
973,
10589,
288,
291,
855,
1065,
275,
8116,
14,
973,
339,
327,
710,
1324,
63,
525,
805,
315,
1134,
12275,
17,
5920,
367,
2251,
543,
282,
272,
327,
283,
9843,
7,
1083,
436,
12,
340,
3451,
12,
4440,
314,
754,
402,
626,
1083,
272,
327,
465,
314,
1324,
1350,
14,
710,
1134,
12275,
18,
1324,
63,
525,
1630,
440,
886,
642,
14,
710,
272,
327,
805,
5084,
1833,
606,
2335,
314,
1134,
12275,
17,
9330,
14,
339,
327,
1010,
10234,
12,
1134,
12275,
9033,
8116,
14,
1210,
63,
525,
370,
485,
71,
785,
14,
2308,
63,
525,
63,
6821,
12,
436,
272,
327,
486,
63,
2308,
63,
525,
63,
6821,
342,
6181,
3365,
5558,
4546,
955,
2419,
272,
327,
8116,
63,
1210,
63,
525,
1252,
2136,
675,
486,
63,
2308,
63,
525,
63,
6821,
342,
2348,
315,
1930,
1134,
12275,
25079,
642,
272,
327,
6519,
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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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
] |
espressopp/espressopp
|
src/analysis/Energy.py
|
1
|
3336
|
# Copyright (C) 2012,2013,2016
# Max Planck Institute for Polymer Research
# Copyright (C) 2008,2009,2010,2011
# Max-Planck-Institute for Polymer Research & Fraunhofer SCAI
#
# This file is part of ESPResSo++.
#
# ESPResSo++ 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.
#
# ESPResSo++ is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
r"""
**************************
espressopp.analysis.Energy
**************************
.. function:: espressopp.analysis.EnergyPot(system, per_atom)
:param system:
:param per_atom: (default: False)
:type system:
:type per_atom:
.. function:: espressopp.analysis.EnergyPot.compute()
:rtype:
.. function:: espressopp.analysis.EnergyKin(system, per_atom)
:param system:
:param per_atom: (default: False)
:type system:
:type per_atom:
.. function:: espressopp.analysis.EnergyKin.compute()
:rtype:
.. function:: espressopp.analysis.EnergyTot(system, per_atom)
:param system:
:param per_atom: (default: False)
:type system:
:type per_atom:
.. function:: espressopp.analysis.EnergyTot.compute()
:rtype:
"""
import espressopp
class EnergyPot():
def __init__(self, system, per_atom=False):
self.system = system
self.per_atom = per_atom
def compute(self):
EPot = 0.0
for k in range(self.system.getNumberOfInteractions()):
EPot += self.system.getInteraction(k).computeEnergy()
if self.per_atom:
NPart = espressopp.analysis.NPart(self.system).compute()
return EPot / NPart
else:
return EPot
class EnergyKin():
def __init__(self, system, per_atom=False):
self.system = system
self.per_atom = per_atom
def compute(self):
NPart = espressopp.analysis.NPart(self.system).compute()
T = espressopp.analysis.Temperature(self.system).compute()
EKin = (3.0/2.0) * NPart * T
if self.per_atom:
return EKin / NPart
else:
return EKin
class EnergyTot():
def __init__(self, system, per_atom=False):
self.system = system
self.per_atom = per_atom
def compute(self):
NPart = espressopp.analysis.NPart(self.system).compute()
T = espressopp.analysis.Temperature(self.system).compute()
EKin = (3.0/2.0) * NPart * T
EPot = 0.0
for k in range(self.system.getNumberOfInteractions()):
EPot += self.system.getInteraction(k).computeEnergy()
if self.per_atom:
return (EPot + EKin) / NPart
else:
return (EPot + EKin)
|
gpl-3.0
|
[
3,
221,
1898,
334,
35,
9,
6029,
12,
6965,
12,
9261,
199,
3,
420,
8228,
32427,
346,
1010,
25585,
367,
16869,
2626,
26993,
199,
3,
221,
1898,
334,
35,
9,
9079,
12,
8664,
12,
6542,
12,
8128,
199,
3,
420,
8228,
13,
13375,
346,
13,
607,
25585,
367,
16869,
2626,
26993,
1253,
481,
345,
324,
526,
2412,
428,
3263,
41,
199,
3,
199,
3,
221,
961,
570,
365,
1777,
402,
31334,
1322,
5158,
4176,
14,
199,
3,
199,
3,
221,
31334,
1322,
5158,
4176,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
221,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
221,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
221,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
221,
31334,
1322,
5158,
4176,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
221,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
221,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
221,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
221,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
221,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
421,
199,
82,
624,
199,
30948,
538,
199,
397,
2915,
26740,
14,
10466,
14,
9900,
199,
30948,
538,
421,
199,
703,
805,
447,
9455,
2915,
26740,
14,
10466,
14,
9900,
48,
357,
8,
2253,
12,
1126,
63,
4188,
9,
2234,
520,
635,
2656,
26,
355,
520,
635,
1126,
63,
4188,
26,
334,
885,
26,
756,
9,
355,
520,
466,
2656,
26,
355,
520,
466,
1126,
63,
4188,
26,
199,
199,
703,
805,
447,
9455,
2915,
26740,
14,
10466,
14,
9900,
48,
357,
14,
3357,
342,
2234,
520,
4500,
26,
199,
199,
703,
805,
447,
9455,
2915,
26740,
14,
10466,
14,
9900,
43,
262,
8,
2253,
12,
1126,
63,
4188,
9,
2234,
520,
635,
2656,
26,
355,
520,
635,
1126,
63,
4188,
26,
334,
885,
26,
756,
9,
355,
520,
466,
2656,
26,
355,
520,
466,
1126,
63,
4188,
26,
199,
199,
703,
805,
447,
9455,
2915,
26740,
14,
10466,
14,
9900,
43,
262,
14,
3357,
342,
2234,
520,
4500,
26,
199,
199,
703,
805,
447,
9455,
2915,
26740,
14,
10466,
14,
9900,
52,
357,
8,
2253,
12,
1126,
63,
4188,
9,
2234,
520,
635,
2656,
26,
355,
520,
635,
1126,
63,
4188,
26,
334,
885,
26,
756,
9,
355,
520,
466,
2656,
26,
355,
520,
466,
1126,
63,
4188,
26,
199,
199,
703,
805,
447,
9455,
2915,
26740,
14,
10466,
14,
9900,
52,
357,
14,
3357,
342,
2234,
520,
4500,
26,
199,
624,
199,
646,
9455,
2915,
26740,
199,
199,
533,
662,
1372,
4312,
48,
357,
837,
339,
347,
636,
826,
721,
277,
12,
2656,
12,
1126,
63,
4188,
29,
797,
304,
267,
291,
14,
2253,
257,
275,
2656,
267,
291,
14,
529,
63,
4188,
275,
1126,
63,
4188,
339,
347,
4526,
8,
277,
304,
267,
31922,
357,
275,
378,
14,
16,
267,
367,
1022,
315,
1425,
8,
277,
14,
2253,
14,
362,
16030,
607,
22990,
5109,
288,
31922,
357,
847,
291,
14,
2253,
14,
362,
31900,
8,
75,
680,
3357,
9900,
342,
267,
340,
291,
14,
529,
63,
4188,
26,
288,
653,
8416,
221,
275,
9455,
2915,
26740,
14,
10466,
14,
46,
8416,
8,
277,
14,
2253,
680,
3357,
342,
288,
372,
31922,
357,
1182,
653,
8416,
267,
587,
26,
288,
372,
31922,
357,
199,
199,
533,
662,
1372,
4312,
43,
262,
837,
339,
347,
636,
826,
721,
277,
12,
2656,
12,
1126,
63,
4188,
29,
797,
304,
267,
291,
14,
2253,
257,
275,
2656,
267,
291,
14,
529,
63,
4188,
275,
1126,
63,
4188,
339,
347,
4526,
8,
277,
304,
267,
653,
8416,
221,
275,
9455,
2915,
26740,
14,
10466,
14,
46,
8416,
8,
277,
14,
2253,
680,
3357,
342,
267,
377,
420,
275,
9455,
2915,
26740,
14,
10466,
14,
27409,
8,
277,
14,
2253,
680,
3357,
342,
267,
662,
43,
262,
257,
275,
334,
19,
14,
16,
15,
18,
14,
16,
9,
627,
653,
8416,
627,
377,
267,
340,
291,
14,
529,
63,
4188,
26,
288,
372,
662,
43,
262,
1182,
653,
8416,
267,
587,
26,
288,
372,
662,
43,
262,
199,
199,
533,
662,
1372,
4312,
52,
357,
837,
339,
347,
636,
826,
721,
277,
12,
2656,
12,
1126,
63,
4188,
29,
797,
304,
267,
291,
14,
2253,
257,
275,
2656,
267,
291,
14,
529,
63,
4188,
275,
1126,
63,
4188,
339,
347,
4526,
8,
277,
304,
267,
653,
8416,
221,
275,
9455,
2915,
26740,
14,
10466,
14,
46,
8416,
8,
277,
14,
2253,
680,
3357,
342,
267,
377,
420,
275,
9455,
2915,
26740,
14,
10466,
14,
27409,
8,
277,
14,
2253,
680,
3357,
342,
267,
662,
43,
262,
257,
275,
334,
19,
14,
16,
15,
18,
14,
16,
9,
627,
653,
8416,
627,
377,
267,
31922,
357,
257,
275,
378,
14,
16,
267,
367,
1022,
315,
1425,
8,
277,
14,
2253,
14,
362,
16030,
607,
22990,
5109,
288,
31922,
357,
847,
291,
14,
2253,
14,
362,
31900,
8,
75,
680,
3357,
9900,
342,
267,
340,
291,
14,
529,
63,
4188,
26,
288,
372,
334,
6102,
357,
435,
662,
43,
262,
9,
1182,
653,
8416,
267,
587,
26,
288,
372,
334,
6102,
357,
435,
662,
43,
262,
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
] |
[
221,
1898,
334,
35,
9,
6029,
12,
6965,
12,
9261,
199,
3,
420,
8228,
32427,
346,
1010,
25585,
367,
16869,
2626,
26993,
199,
3,
221,
1898,
334,
35,
9,
9079,
12,
8664,
12,
6542,
12,
8128,
199,
3,
420,
8228,
13,
13375,
346,
13,
607,
25585,
367,
16869,
2626,
26993,
1253,
481,
345,
324,
526,
2412,
428,
3263,
41,
199,
3,
199,
3,
221,
961,
570,
365,
1777,
402,
31334,
1322,
5158,
4176,
14,
199,
3,
199,
3,
221,
31334,
1322,
5158,
4176,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
221,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
221,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
221,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
221,
31334,
1322,
5158,
4176,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
221,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
221,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
221,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
221,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
221,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
421,
199,
82,
624,
199,
30948,
538,
199,
397,
2915,
26740,
14,
10466,
14,
9900,
199,
30948,
538,
421,
199,
703,
805,
447,
9455,
2915,
26740,
14,
10466,
14,
9900,
48,
357,
8,
2253,
12,
1126,
63,
4188,
9,
2234,
520,
635,
2656,
26,
355,
520,
635,
1126,
63,
4188,
26,
334,
885,
26,
756,
9,
355,
520,
466,
2656,
26,
355,
520,
466,
1126,
63,
4188,
26,
199,
199,
703,
805,
447,
9455,
2915,
26740,
14,
10466,
14,
9900,
48,
357,
14,
3357,
342,
2234,
520,
4500,
26,
199,
199,
703,
805,
447,
9455,
2915,
26740,
14,
10466,
14,
9900,
43,
262,
8,
2253,
12,
1126,
63,
4188,
9,
2234,
520,
635,
2656,
26,
355,
520,
635,
1126,
63,
4188,
26,
334,
885,
26,
756,
9,
355,
520,
466,
2656,
26,
355,
520,
466,
1126,
63,
4188,
26,
199,
199,
703,
805,
447,
9455,
2915,
26740,
14,
10466,
14,
9900,
43,
262,
14,
3357,
342,
2234,
520,
4500,
26,
199,
199,
703,
805,
447,
9455,
2915,
26740,
14,
10466,
14,
9900,
52,
357,
8,
2253,
12,
1126,
63,
4188,
9,
2234,
520,
635,
2656,
26,
355,
520,
635,
1126,
63,
4188,
26,
334,
885,
26,
756,
9,
355,
520,
466,
2656,
26,
355,
520,
466,
1126,
63,
4188,
26,
199,
199,
703,
805,
447,
9455,
2915,
26740,
14,
10466,
14,
9900,
52,
357,
14,
3357,
342,
2234,
520,
4500,
26,
199,
624,
199,
646,
9455,
2915,
26740,
199,
199,
533,
662,
1372,
4312,
48,
357,
837,
339,
347,
636,
826,
721,
277,
12,
2656,
12,
1126,
63,
4188,
29,
797,
304,
267,
291,
14,
2253,
257,
275,
2656,
267,
291,
14,
529,
63,
4188,
275,
1126,
63,
4188,
339,
347,
4526,
8,
277,
304,
267,
31922,
357,
275,
378,
14,
16,
267,
367,
1022,
315,
1425,
8,
277,
14,
2253,
14,
362,
16030,
607,
22990,
5109,
288,
31922,
357,
847,
291,
14,
2253,
14,
362,
31900,
8,
75,
680,
3357,
9900,
342,
267,
340,
291,
14,
529,
63,
4188,
26,
288,
653,
8416,
221,
275,
9455,
2915,
26740,
14,
10466,
14,
46,
8416,
8,
277,
14,
2253,
680,
3357,
342,
288,
372,
31922,
357,
1182,
653,
8416,
267,
587,
26,
288,
372,
31922,
357,
199,
199,
533,
662,
1372,
4312,
43,
262,
837,
339,
347,
636,
826,
721,
277,
12,
2656,
12,
1126,
63,
4188,
29,
797,
304,
267,
291,
14,
2253,
257,
275,
2656,
267,
291,
14,
529,
63,
4188,
275,
1126,
63,
4188,
339,
347,
4526,
8,
277,
304,
267,
653,
8416,
221,
275,
9455,
2915,
26740,
14,
10466,
14,
46,
8416,
8,
277,
14,
2253,
680,
3357,
342,
267,
377,
420,
275,
9455,
2915,
26740,
14,
10466,
14,
27409,
8,
277,
14,
2253,
680,
3357,
342,
267,
662,
43,
262,
257,
275,
334,
19,
14,
16,
15,
18,
14,
16,
9,
627,
653,
8416,
627,
377,
267,
340,
291,
14,
529,
63,
4188,
26,
288,
372,
662,
43,
262,
1182,
653,
8416,
267,
587,
26,
288,
372,
662,
43,
262,
199,
199,
533,
662,
1372,
4312,
52,
357,
837,
339,
347,
636,
826,
721,
277,
12,
2656,
12,
1126,
63,
4188,
29,
797,
304,
267,
291,
14,
2253,
257,
275,
2656,
267,
291,
14,
529,
63,
4188,
275,
1126,
63,
4188,
339,
347,
4526,
8,
277,
304,
267,
653,
8416,
221,
275,
9455,
2915,
26740,
14,
10466,
14,
46,
8416,
8,
277,
14,
2253,
680,
3357,
342,
267,
377,
420,
275,
9455,
2915,
26740,
14,
10466,
14,
27409,
8,
277,
14,
2253,
680,
3357,
342,
267,
662,
43,
262,
257,
275,
334,
19,
14,
16,
15,
18,
14,
16,
9,
627,
653,
8416,
627,
377,
267,
31922,
357,
257,
275,
378,
14,
16,
267,
367,
1022,
315,
1425,
8,
277,
14,
2253,
14,
362,
16030,
607,
22990,
5109,
288,
31922,
357,
847,
291,
14,
2253,
14,
362,
31900,
8,
75,
680,
3357,
9900,
342,
267,
340,
291,
14,
529,
63,
4188,
26,
288,
372,
334,
6102,
357,
435,
662,
43,
262,
9,
1182,
653,
8416,
267,
587,
26,
288,
372,
334,
6102,
357,
435,
662,
43,
262,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
kidaa30/spacewalk
|
client/rhel/rhnlib/rhn/rpclib.py
|
3
|
23949
|
#
# This module contains all the RPC-related functions the RHN code uses
#
# Copyright (c) 2005--2015 Red Hat, Inc.
#
# This software is licensed to you under the GNU General Public License,
# version 2 (GPLv2). There is NO WARRANTY for this software, express or
# implied, including the implied warranties of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
# along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
#
# Red Hat trademarks are not licensed under GPLv2. No permission is
# granted to use or replicate Red Hat trademarks that are incorporated
# in this software or its documentation.
#
__version__ = "$Revision$"
import transports
import urllib
import socket
import re
import sys
from types import ListType, TupleType, StringType, UnicodeType, DictType, DictionaryType
from UserDictCase import UserDictCase
import xmlrpclib
# Redirection handling
MAX_REDIRECTIONS = 5
def check_ipv6(n):
""" Returns true if n is IPv6 address, false otherwise. """
try:
socket.inet_pton(socket.AF_INET6, n)
return True
except:
return False
def split_host(hoststring):
""" Function used to split host information in an URL per RFC 2396
handle full hostname like user:passwd@host:port
"""
l = hoststring.split('@', 1)
host = None
port = None
user = None
passwd = None
if len(l) == 2:
hostport = l[1]
# userinfo present
userinfo = l[0].split(':', 1)
user = userinfo[0]
if len(userinfo) == 2:
passwd = userinfo[1]
else:
hostport = l[0]
# Now parse hostport
if hostport[0] == '[':
# IPv6 with port
host, port = re.split('(?<=\]):', ip_port, 1)
host = host.lstrip('[').rstrip(']')
elif check_ipv6(hostport):
# just IPv6
host = hostport
else:
# IPv4
arr = hostport.split(':', 1)
host = arr[0]
if len(arr) == 2:
port = arr[1]
return (host, port, user, passwd)
def get_proxy_info(proxy):
if proxy == None:
raise ValueError("Host string cannot be null")
arr = proxy.split('://', 1)
if len(arr) == 2:
# scheme found, strip it
proxy = arr[1]
return split_host(proxy)
class MalformedURIError(IOError):
pass
# Originaly taken from xmlrpclib.ServerProxy, now changed most of the code
class Server:
"""uri [,options] -> a logical connection to an XML-RPC server
uri is the connection point on the server, given as
scheme://host/target.
The standard implementation always supports the "http" scheme. If
SSL socket support is available (Python 2.0), it also supports
"https".
If the target part and the slash preceding it are both omitted,
"/RPC2" is assumed.
The following options can be given as keyword arguments:
transport: a transport factory
encoding: the request encoding (default is UTF-8)
verbose: verbosity level
proxy: use an HTTP proxy
username: username for authenticated HTTP proxy
password: password for authenticated HTTP proxy
All 8-bit strings passed to the server proxy are assumed to use
the given encoding.
"""
# Default factories
_transport_class = transports.Transport
_transport_class_https = transports.SafeTransport
_transport_class_proxy = transports.ProxyTransport
_transport_class_https_proxy = transports.SafeProxyTransport
def __init__(self, uri, transport=None, encoding=None, verbose=0,
proxy=None, username=None, password=None, refreshCallback=None,
progressCallback=None, timeout=None):
# establish a "logical" server connection
#
# First parse the proxy information if available
#
if proxy != None:
(ph, pp, pu, pw) = get_proxy_info(proxy)
if pp is not None:
proxy = "%s:%s" % (ph, pp)
else:
proxy = ph
# username and password will override whatever was passed in the
# URL
if pu is not None and username is None:
username = pu
if pw is not None and password is None:
password = pw
self._uri = uri
self._refreshCallback = None
self._progressCallback = None
self._bufferSize = None
self._proxy = proxy
self._username = username
self._password = password
self._timeout = timeout
if len(__version__.split()) > 1:
self.rpc_version = __version__.split()[1]
else:
self.rpc_version = __version__
self._reset_host_handler_and_type()
if transport is None:
self._allow_redirect = 1
transport = self.default_transport(self._type, proxy, username,
password, timeout)
else:
#
# dont allow redirect on unknow transports, that should be
# set up independantly
#
self._allow_redirect = 0
self._redirected = None
self.use_handler_path = 1
self._transport = transport
self._trusted_cert_files = []
self._lang = None
self._encoding = encoding
self._verbose = verbose
self.set_refresh_callback(refreshCallback)
self.set_progress_callback(progressCallback)
# referer, which redirect us to new handler
self.send_handler=None
self._headers = UserDictCase()
def default_transport(self, type, proxy=None, username=None, password=None,
timeout=None):
if proxy:
if type == 'https':
transport = self._transport_class_https_proxy(proxy,
proxyUsername=username, proxyPassword=password, timeout=timeout)
else:
transport = self._transport_class_proxy(proxy,
proxyUsername=username, proxyPassword=password, timeout=timeout)
else:
if type == 'https':
transport = self._transport_class_https(timeout=timeout)
else:
transport = self._transport_class(timeout=timeout)
return transport
def allow_redirect(self, allow):
self._allow_redirect = allow
def redirected(self):
if not self._allow_redirect:
return None
return self._redirected
def set_refresh_callback(self, refreshCallback):
self._refreshCallback = refreshCallback
self._transport.set_refresh_callback(refreshCallback)
def set_buffer_size(self, bufferSize):
self._bufferSize = bufferSize
self._transport.set_buffer_size(bufferSize)
def set_progress_callback(self, progressCallback, bufferSize=16384):
self._progressCallback = progressCallback
self._transport.set_progress_callback(progressCallback, bufferSize)
def _req_body(self, params, methodname):
return xmlrpclib.dumps(params, methodname, encoding=self._encoding)
def get_response_headers(self):
if self._transport:
return self._transport.headers_in
return None
def get_response_status(self):
if self._transport:
return self._transport.response_status
return None
def get_response_reason(self):
if self._transport:
return self._transport.response_reason
return None
def get_content_range(self):
"""Returns a dictionary with three values:
length: the total length of the entity-body (can be None)
first_byte_pos: the position of the first byte (zero based)
last_byte_pos: the position of the last byte (zero based)
The range is inclusive; that is, a response 8-9/102 means two bytes
"""
headers = self.get_response_headers()
if not headers:
return None
content_range = headers.get('Content-Range')
if not content_range:
return None
arr = filter(None, content_range.split())
assert arr[0] == "bytes"
assert len(arr) == 2
arr = arr[1].split('/')
assert len(arr) == 2
brange, total_len = arr
if total_len == '*':
# Per RFC, the server is allowed to use * if the length of the
# entity-body is unknown or difficult to determine
total_len = None
else:
total_len = int(total_len)
start, end = brange.split('-')
result = {
'length' : total_len,
'first_byte_pos' : int(start),
'last_byte_pos' : int(end),
}
return result
def accept_ranges(self):
headers = self.get_response_headers()
if not headers:
return None
if headers.has_key('Accept-Ranges'):
return headers['Accept-Ranges']
return None
def _reset_host_handler_and_type(self):
""" Reset the attributes:
self._host, self._handler, self._type
according the value of self._uri.
"""
# get the url
type, uri = urllib.splittype(self._uri)
if type is None:
raise MalformedURIError("missing protocol in uri")
# with a real uri passed in, uri will now contain "//hostname..." so we
# need at least 3 chars for it to maybe be ok...
if len(uri) < 3 or uri[0:2] != "//":
raise MalformedURIError
if type != None:
self._type = type.lower()
else:
self._type = type
if self._type not in ("http", "https"):
raise IOError("unsupported XML-RPC protocol")
self._host, self._handler = urllib.splithost(uri)
if not self._handler:
self._handler = "/RPC2"
def _strip_characters(self, *args):
""" Strip characters, which are not allowed according:
http://www.w3.org/TR/2006/REC-xml-20060816/#charsets
From spec:
Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF] /* any Unicode character, excluding the surrogate blocks, FFFE, and FFFF. */
"""
regexp = r'[\x00-\x09]|[\x0b-\x0c]|[\x0e-\x1f]'
result=[]
for item in args:
item_type = type(item)
if item_type == StringType or item_type == UnicodeType:
item = re.sub(regexp, '', item)
elif item_type == TupleType:
item = tuple(map(self._strip_characters, item))
elif item_type == ListType:
item = map(self._strip_characters, item)
elif item_type == DictType or item_type == DictionaryType:
item = dict([(self._strip_characters(name, val)) for name, val in item.iteritems()])
# else: some object - should take care of himself
# numbers - are safe
result.append(item)
if len(result) == 1:
return result[0]
else:
return tuple(result)
def _request(self, methodname, params):
""" Call a method on the remote server
we can handle redirections. """
# the loop is used to handle redirections
redirect_response = 0
retry = 0
self._reset_host_handler_and_type()
while 1:
if retry >= MAX_REDIRECTIONS:
raise InvalidRedirectionError(
"Unable to fetch requested Package")
# Clear the transport headers first
self._transport.clear_headers()
for k, v in self._headers.items():
self._transport.set_header(k, v)
self._transport.add_header("X-Info",
'RPC Processor (C) Red Hat, Inc (version %s)' %
self.rpc_version)
# identify the capability set of this client to the server
self._transport.set_header("X-Client-Version", 1)
if self._allow_redirect:
# Advertise that we follow redirects
#changing the version from 1 to 2 to support backward compatibility
self._transport.add_header("X-RHN-Transport-Capability",
"follow-redirects=3")
if redirect_response:
self._transport.add_header('X-RHN-Redirect', '0')
if self.send_handler:
self._transport.add_header('X-RHN-Path', self.send_handler)
request = self._req_body(self._strip_characters(params), methodname)
try:
response = self._transport.request(self._host, \
self._handler, request, verbose=self._verbose)
save_response = self._transport.response_status
except xmlrpclib.ProtocolError:
if self.use_handler_path:
raise
else:
save_response = sys.exc_info()[1].errcode
self._redirected = None
retry += 1
if save_response == 200:
# exit redirects loop and return response
break
elif save_response not in (301, 302):
# Retry pkg fetch
self.use_handler_path = 1
continue
# rest of loop is run only if we are redirected (301, 302)
self._redirected = self._transport.redirected()
self.use_handler_path = 0
redirect_response = 1
if not self._allow_redirect:
raise InvalidRedirectionError("Redirects not allowed")
if self._verbose:
print("%s redirected to %s" % (self._uri, self._redirected))
typ, uri = urllib.splittype(self._redirected)
if typ != None:
typ = typ.lower()
if typ not in ("http", "https"):
raise InvalidRedirectionError(
"Redirected to unsupported protocol %s" % typ)
#
# We forbid HTTPS -> HTTP for security reasons
# Note that HTTP -> HTTPS -> HTTP is allowed (because we compare
# the protocol for the redirect with the original one)
#
if self._type == "https" and typ == "http":
raise InvalidRedirectionError(
"HTTPS redirected to HTTP is not supported")
self._host, self._handler = urllib.splithost(uri)
if not self._handler:
self._handler = "/RPC2"
# Create a new transport for the redirected service and
# set up the parameters on the new transport
del self._transport
self._transport = self.default_transport(typ, self._proxy,
self._username, self._password, self._timeout)
self.set_progress_callback(self._progressCallback)
self.set_refresh_callback(self._refreshCallback)
self.set_buffer_size(self._bufferSize)
self.setlang(self._lang)
if self._trusted_cert_files != [] and \
hasattr(self._transport, "add_trusted_cert"):
for certfile in self._trusted_cert_files:
self._transport.add_trusted_cert(certfile)
# Then restart the loop to try the new entry point.
if isinstance(response, transports.File):
# Just return the file
return response
# an XML-RPC encoded data structure
if isinstance(response, TupleType) and len(response) == 1:
response = response[0]
return response
def __repr__(self):
return (
"<%s for %s%s>" %
(self.__class__.__name__, self._host, self._handler)
)
__str__ = __repr__
def __getattr__(self, name):
# magic method dispatcher
return _Method(self._request, name)
# note: to call a remote object with an non-standard name, use
# result getattr(server, "strange-python-name")(args)
def set_transport_flags(self, transfer=0, encoding=0, **kwargs):
if not self._transport:
# Nothing to do
return
kwargs.update({
'transfer' : transfer,
'encoding' : encoding,
})
apply(self._transport.set_transport_flags, (), kwargs)
def get_transport_flags(self):
if not self._transport:
# Nothing to do
return {}
return self._transport.get_transport_flags()
def reset_transport_flags(self):
# Does nothing
pass
# Allow user-defined additional headers.
def set_header(self, name, arg):
if type(arg) in [ type([]), type(()) ]:
# Multivalued header
self._headers[name] = map(str, arg)
else:
self._headers[name] = str(arg)
def add_header(self, name, arg):
if self._headers.has_key(name):
vlist = self._headers[name]
if not isinstance(vlist, ListType):
vlist = [ vlist ]
else:
vlist = self._headers[name] = []
vlist.append(str(arg))
# Sets the i18n options
def setlang(self, lang):
self._lang = lang
if self._transport and hasattr(self._transport, "setlang"):
self._transport.setlang(lang)
# Sets the CA chain to be used
def use_CA_chain(self, ca_chain = None):
raise NotImplementedError("This method is deprecated")
def add_trusted_cert(self, certfile):
self._trusted_cert_files.append(certfile)
if self._transport and hasattr(self._transport, "add_trusted_cert"):
self._transport.add_trusted_cert(certfile)
def close(self):
if self._transport:
self._transport.close()
self._transport = None
# RHN GET server
class GETServer(Server):
def __init__(self, uri, transport=None, proxy=None, username=None,
password=None, client_version=2, headers={}, refreshCallback=None,
progressCallback=None, timeout=None):
Server.__init__(self, uri,
proxy=proxy,
username=username,
password=password,
transport=transport,
refreshCallback=refreshCallback,
progressCallback=progressCallback,
timeout=timeout)
self._client_version = client_version
self._headers = headers
# Back up the original handler, since we mangle it
self._orig_handler = self._handler
# Download resumption
self.set_range(offset=None, amount=None)
def _req_body(self, params, methodname):
if not params or len(params) < 1:
raise Exception("Required parameter channel not found")
# Strip the multiple / from the handler
h_comps = filter(lambda x: x != '', self._orig_handler.split('/'))
# Set the handler we are going to request
hndl = h_comps + ["$RHN", params[0], methodname] + list(params[1:])
self._handler = '/' + '/'.join(hndl)
#save the constructed handler in case of redirect
self.send_handler = self._handler
# Add headers
#override the handler to replace /XMLRPC with pkg path
if self._redirected and not self.use_handler_path:
self._handler = self._new_req_body()
for h, v in self._headers.items():
self._transport.set_header(h, v)
if self._offset is not None:
if self._offset >= 0:
brange = str(self._offset) + '-'
if self._amount is not None:
brange = brange + str(self._offset + self._amount - 1)
else:
# The last bytes
# amount is ignored in this case
brange = '-' + str(-self._offset)
self._transport.set_header('Range', "bytes=" + brange)
# Flag that we allow for partial content
self._transport.set_transport_flags(allow_partial_content=1)
# GET requests have empty body
return ""
def _new_req_body(self):
type, tmpuri = urllib.splittype(self._redirected)
site, handler = urllib.splithost(tmpuri)
return handler
def set_range(self, offset=None, amount=None):
if offset is not None:
try:
offset = int(offset)
except ValueError:
# Error
raise RangeError("Invalid value `%s' for offset" % offset, None, sys.exc_info()[2])
if amount is not None:
try:
amount = int(amount)
except ValueError:
# Error
raise RangeError("Invalid value `%s' for amount" % amount, None, sys.exc_info()[2])
if amount <= 0:
raise RangeError("Invalid value `%s' for amount" % amount)
self._amount = amount
self._offset = offset
def reset_transport_flags(self):
self._transport.set_transport_flags(allow_partial_content=0)
def __getattr__(self, name):
# magic method dispatcher
return SlicingMethod(self._request, name)
def default_transport(self, type, proxy=None, username=None, password=None,
timeout=None):
ret = Server.default_transport(self, type, proxy=proxy, username=username, password=password, timeout=timeout)
ret.set_method("GET")
return ret
class RangeError(Exception):
pass
class InvalidRedirectionError(Exception):
pass
def getHeaderValues(headers, name):
import mimetools
if not isinstance(headers, mimetools.Message):
if headers.has_key(name):
return [headers[name]]
return []
return map(lambda x: x.split(':', 1)[1].strip(),
headers.getallmatchingheaders(name))
class _Method:
""" some magic to bind an XML-RPC method to an RPC server.
supports "nested" methods (e.g. examples.getStateName)
"""
def __init__(self, send, name):
self._send = send
self._name = name
def __getattr__(self, name):
return _Method(self._send, "%s.%s" % (self._name, name))
def __call__(self, *args):
return self._send(self._name, args)
def __repr__(self):
return (
"<%s %s (%s)>" %
(self.__class__.__name__, self._name, self._send)
)
__str__ = __repr__
class SlicingMethod(_Method):
"""
A "slicing method" allows for byte range requests
"""
def __init__(self, send, name):
_Method.__init__(self, send, name)
self._offset = None
def __getattr__(self, name):
return SlicingMethod(self._send, "%s.%s" % (self._name, name))
def __call__(self, *args, **kwargs):
self._offset = kwargs.get('offset')
self._amount = kwargs.get('amount')
# im_self is a pointer to self, so we can modify the class underneath
try:
self._send.im_self.set_range(offset=self._offset,
amount=self._amount)
except AttributeError:
pass
result = self._send(self._name, args)
# Reset "sticky" transport flags
try:
self._send.im_self.reset_transport_flags()
except AttributeError:
pass
return result
def reportError(headers):
""" Reports the error from the headers. """
errcode = 0
errmsg = ""
s = "X-RHN-Fault-Code"
if headers.has_key(s):
errcode = int(headers[s])
s = "X-RHN-Fault-String"
if headers.has_key(s):
_sList = getHeaderValues(headers, s)
if _sList:
_s = ''.join(_sList)
import base64
errmsg = "%s" % base64.decodestring(_s)
return errcode, errmsg
|
gpl-2.0
|
[
3,
199,
3,
961,
859,
3509,
1006,
314,
11785,
13,
2407,
3423,
314,
820,
23084,
1233,
4440,
199,
3,
199,
3,
1898,
334,
67,
9,
11811,
306,
7806,
9572,
13002,
12,
3277,
14,
199,
3,
199,
3,
961,
2032,
365,
18233,
370,
1265,
1334,
314,
1664,
1696,
1684,
844,
12,
199,
3,
1015,
499,
334,
28863,
18,
680,
6006,
365,
4825,
3408,
367,
642,
2032,
12,
4056,
503,
199,
3,
2478,
12,
5893,
314,
2478,
3712,
1417,
402,
3169,
503,
3092,
199,
3,
2381,
437,
3115,
3104,
14,
2047,
1077,
1172,
3086,
282,
1331,
402,
14629,
86,
18,
199,
3,
3180,
543,
642,
2032,
27,
340,
440,
12,
1937,
199,
3,
1455,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
1753,
13,
2383,
15,
11692,
13,
18,
14,
16,
14,
2424,
14,
199,
3,
199,
3,
9572,
13002,
21032,
10375,
787,
440,
18233,
1334,
14629,
86,
18,
14,
3091,
4983,
365,
199,
3,
10009,
370,
675,
503,
29738,
9572,
13002,
21032,
10375,
626,
787,
30147,
972,
199,
3,
315,
642,
2032,
503,
2399,
3794,
14,
199,
3,
199,
199,
363,
1023,
363,
275,
7880,
12714,
17351,
199,
199,
646,
7773,
83,
199,
646,
4011,
199,
646,
2838,
199,
646,
295,
199,
646,
984,
199,
199,
504,
2943,
492,
3820,
804,
12,
11634,
804,
12,
32654,
12,
6140,
804,
12,
7448,
804,
12,
11932,
804,
199,
199,
504,
32241,
1538,
492,
32241,
1538,
199,
199,
646,
19122,
199,
199,
3,
799,
6874,
7252,
199,
199,
4283,
63,
19747,
2823,
275,
959,
199,
199,
318,
1104,
63,
4774,
22,
8,
78,
304,
272,
408,
1803,
2549,
340,
302,
365,
6509,
22,
2287,
12,
3055,
4257,
14,
408,
272,
862,
26,
267,
2838,
14,
10811,
63,
541,
265,
8,
3450,
14,
5699,
63,
11367,
22,
12,
302,
9,
267,
372,
715,
272,
871,
26,
267,
372,
756,
199,
199,
318,
3715,
63,
1102,
8,
1102,
875,
304,
272,
408,
6801,
1202,
370,
3715,
1591,
2556,
315,
376,
2851,
1126,
7329,
499,
13443,
267,
2429,
2615,
6246,
2839,
922,
26,
12671,
32,
1102,
26,
719,
272,
408,
272,
634,
275,
1591,
875,
14,
1294,
16591,
297,
413,
9,
272,
1591,
275,
488,
272,
1844,
275,
488,
272,
922,
275,
488,
272,
15081,
275,
488,
339,
340,
822,
8,
76,
9,
508,
499,
26,
267,
1591,
719,
275,
634,
59,
17,
61,
267,
327,
922,
815,
3451,
267,
922,
815,
275,
634,
59,
16,
1055,
1294,
16451,
413,
9,
267,
922,
275,
922,
815,
59,
16,
61,
267,
340,
822,
8,
751,
815,
9,
508,
499,
26,
288,
15081,
275,
922,
815,
59,
17,
61,
272,
587,
26,
267,
1591,
719,
275,
634,
59,
16,
61,
339,
327,
7356,
2198,
1591,
719,
272,
340,
1591,
719,
59,
16,
61,
508,
6730,
356,
267,
327,
6509,
22,
543,
1844,
267,
1591,
12,
1844,
275,
295,
14,
1294,
28353,
28,
9529,
4682,
297,
3384,
63,
719,
12,
413,
9,
267,
1591,
275,
1591,
14,
10124,
11894,
1959,
6735,
360,
10374,
272,
916,
1104,
63,
4774,
22,
8,
1102,
719,
304,
267,
327,
2951,
6509,
22,
267,
1591,
275,
1591,
719,
272,
587,
26,
267,
327,
6509,
20,
267,
7953,
275,
1591,
719,
14,
1294,
16451,
413,
9,
267,
1591,
275,
7953,
59,
16,
61,
267,
340,
822,
8,
5250,
9,
508,
499,
26,
288,
1844,
275,
7953,
59,
17,
61,
339,
372,
334,
1102,
12,
1844,
12,
922,
12,
15081,
9,
199,
199,
318,
664,
63,
3280,
63,
815,
8,
3280,
304,
272,
340,
4566,
508,
488,
26,
267,
746,
1722,
480,
4965,
1059,
3913,
506,
2973,
531,
339,
7953,
275,
4566,
14,
1294,
6176,
501,
297,
413,
9,
272,
340,
822,
8,
5250,
9,
508,
499,
26,
267,
327,
5687,
1911,
12,
6202,
652,
267,
4566,
275,
7953,
59,
17,
61,
339,
372,
3715,
63,
1102,
8,
3280,
9,
421,
199,
533,
603,
24012,
7639,
547,
8,
13760,
304,
272,
986,
421,
199,
3,
31534,
2618,
9394,
687,
19122,
14,
3120,
4936,
12,
3063,
2896,
4750,
402,
314,
1233,
199,
533,
7146,
26,
272,
408,
2302,
359,
12,
1419,
61,
1035,
282,
11461,
1950,
370,
376,
4692,
13,
8171,
1654,
339,
5108,
365,
314,
1950,
2376,
641,
314,
1654,
12,
1627,
465,
272,
5687,
921,
1102,
15,
1375,
14,
339,
710,
4465,
4514,
3544,
5171,
314,
298,
1014,
2,
5687,
14,
221,
982,
272,
7799,
2838,
2291,
365,
2808,
334,
4718,
499,
14,
16,
395,
652,
2597,
5171,
272,
298,
2859,
1674,
339,
982,
314,
1347,
1777,
436,
314,
14457,
22627,
652,
787,
3865,
11684,
12,
272,
3286,
8171,
18,
2,
365,
10826,
14,
339,
710,
2569,
1511,
883,
506,
1627,
465,
4252,
2368,
26,
398,
7773,
26,
282,
7773,
6434,
267,
2644,
26,
314,
1056,
2644,
334,
885,
365,
9094,
13,
24,
9,
267,
3376,
26,
8661,
2166,
267,
4566,
26,
675,
376,
3101,
4566,
267,
3434,
26,
3434,
367,
15082,
3101,
4566,
267,
2505,
26,
2505,
367,
15082,
3101,
4566,
339,
2900,
1695,
13,
2075,
3326,
3032,
370,
314,
1654,
4566,
787,
10826,
370,
675,
272,
314,
1627,
2644,
14,
272,
408,
339,
327,
3758,
22115,
272,
485,
5545,
63,
533,
275,
7773,
83,
14,
7836,
272,
485,
5545,
63,
533,
63,
2859,
275,
7773,
83,
14,
11090,
7836,
272,
485,
5545,
63,
533,
63,
3280,
275,
7773,
83,
14,
4936,
7836,
272,
485,
5545,
63,
533,
63,
2859,
63,
3280,
275,
7773,
83,
14,
11090,
4936,
7836,
272,
347,
636,
826,
721,
277,
12,
5108,
12,
7773,
29,
403,
12,
2644,
29,
403,
12,
3376,
29,
16,
12,
267,
4566,
29,
403,
12,
3434,
29,
403,
12,
2505,
29,
403,
12,
9236,
2806,
29,
403,
12,
267,
6696,
2806,
29,
403,
12,
2653,
29,
403,
304,
267,
327,
16873,
282,
298,
7954,
2,
1654,
1950,
398,
327,
267,
327,
7758,
2198,
314,
4566,
2556,
340,
2808,
267,
327,
267,
340,
4566,
1137,
488,
26,
288,
334,
838,
12,
11618,
12,
18848,
12,
19206,
9,
275,
664,
63,
3280,
63,
815,
8,
3280,
9,
953,
340,
11618,
365,
440,
488,
26,
355,
4566,
275,
2071,
83,
2689,
83,
2,
450,
334,
838,
12,
11618,
9,
288,
587,
26,
355,
4566,
275,
3945,
953,
327,
3434,
436,
2505
] |
[
199,
3,
961,
859,
3509,
1006,
314,
11785,
13,
2407,
3423,
314,
820,
23084,
1233,
4440,
199,
3,
199,
3,
1898,
334,
67,
9,
11811,
306,
7806,
9572,
13002,
12,
3277,
14,
199,
3,
199,
3,
961,
2032,
365,
18233,
370,
1265,
1334,
314,
1664,
1696,
1684,
844,
12,
199,
3,
1015,
499,
334,
28863,
18,
680,
6006,
365,
4825,
3408,
367,
642,
2032,
12,
4056,
503,
199,
3,
2478,
12,
5893,
314,
2478,
3712,
1417,
402,
3169,
503,
3092,
199,
3,
2381,
437,
3115,
3104,
14,
2047,
1077,
1172,
3086,
282,
1331,
402,
14629,
86,
18,
199,
3,
3180,
543,
642,
2032,
27,
340,
440,
12,
1937,
199,
3,
1455,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
1753,
13,
2383,
15,
11692,
13,
18,
14,
16,
14,
2424,
14,
199,
3,
199,
3,
9572,
13002,
21032,
10375,
787,
440,
18233,
1334,
14629,
86,
18,
14,
3091,
4983,
365,
199,
3,
10009,
370,
675,
503,
29738,
9572,
13002,
21032,
10375,
626,
787,
30147,
972,
199,
3,
315,
642,
2032,
503,
2399,
3794,
14,
199,
3,
199,
199,
363,
1023,
363,
275,
7880,
12714,
17351,
199,
199,
646,
7773,
83,
199,
646,
4011,
199,
646,
2838,
199,
646,
295,
199,
646,
984,
199,
199,
504,
2943,
492,
3820,
804,
12,
11634,
804,
12,
32654,
12,
6140,
804,
12,
7448,
804,
12,
11932,
804,
199,
199,
504,
32241,
1538,
492,
32241,
1538,
199,
199,
646,
19122,
199,
199,
3,
799,
6874,
7252,
199,
199,
4283,
63,
19747,
2823,
275,
959,
199,
199,
318,
1104,
63,
4774,
22,
8,
78,
304,
272,
408,
1803,
2549,
340,
302,
365,
6509,
22,
2287,
12,
3055,
4257,
14,
408,
272,
862,
26,
267,
2838,
14,
10811,
63,
541,
265,
8,
3450,
14,
5699,
63,
11367,
22,
12,
302,
9,
267,
372,
715,
272,
871,
26,
267,
372,
756,
199,
199,
318,
3715,
63,
1102,
8,
1102,
875,
304,
272,
408,
6801,
1202,
370,
3715,
1591,
2556,
315,
376,
2851,
1126,
7329,
499,
13443,
267,
2429,
2615,
6246,
2839,
922,
26,
12671,
32,
1102,
26,
719,
272,
408,
272,
634,
275,
1591,
875,
14,
1294,
16591,
297,
413,
9,
272,
1591,
275,
488,
272,
1844,
275,
488,
272,
922,
275,
488,
272,
15081,
275,
488,
339,
340,
822,
8,
76,
9,
508,
499,
26,
267,
1591,
719,
275,
634,
59,
17,
61,
267,
327,
922,
815,
3451,
267,
922,
815,
275,
634,
59,
16,
1055,
1294,
16451,
413,
9,
267,
922,
275,
922,
815,
59,
16,
61,
267,
340,
822,
8,
751,
815,
9,
508,
499,
26,
288,
15081,
275,
922,
815,
59,
17,
61,
272,
587,
26,
267,
1591,
719,
275,
634,
59,
16,
61,
339,
327,
7356,
2198,
1591,
719,
272,
340,
1591,
719,
59,
16,
61,
508,
6730,
356,
267,
327,
6509,
22,
543,
1844,
267,
1591,
12,
1844,
275,
295,
14,
1294,
28353,
28,
9529,
4682,
297,
3384,
63,
719,
12,
413,
9,
267,
1591,
275,
1591,
14,
10124,
11894,
1959,
6735,
360,
10374,
272,
916,
1104,
63,
4774,
22,
8,
1102,
719,
304,
267,
327,
2951,
6509,
22,
267,
1591,
275,
1591,
719,
272,
587,
26,
267,
327,
6509,
20,
267,
7953,
275,
1591,
719,
14,
1294,
16451,
413,
9,
267,
1591,
275,
7953,
59,
16,
61,
267,
340,
822,
8,
5250,
9,
508,
499,
26,
288,
1844,
275,
7953,
59,
17,
61,
339,
372,
334,
1102,
12,
1844,
12,
922,
12,
15081,
9,
199,
199,
318,
664,
63,
3280,
63,
815,
8,
3280,
304,
272,
340,
4566,
508,
488,
26,
267,
746,
1722,
480,
4965,
1059,
3913,
506,
2973,
531,
339,
7953,
275,
4566,
14,
1294,
6176,
501,
297,
413,
9,
272,
340,
822,
8,
5250,
9,
508,
499,
26,
267,
327,
5687,
1911,
12,
6202,
652,
267,
4566,
275,
7953,
59,
17,
61,
339,
372,
3715,
63,
1102,
8,
3280,
9,
421,
199,
533,
603,
24012,
7639,
547,
8,
13760,
304,
272,
986,
421,
199,
3,
31534,
2618,
9394,
687,
19122,
14,
3120,
4936,
12,
3063,
2896,
4750,
402,
314,
1233,
199,
533,
7146,
26,
272,
408,
2302,
359,
12,
1419,
61,
1035,
282,
11461,
1950,
370,
376,
4692,
13,
8171,
1654,
339,
5108,
365,
314,
1950,
2376,
641,
314,
1654,
12,
1627,
465,
272,
5687,
921,
1102,
15,
1375,
14,
339,
710,
4465,
4514,
3544,
5171,
314,
298,
1014,
2,
5687,
14,
221,
982,
272,
7799,
2838,
2291,
365,
2808,
334,
4718,
499,
14,
16,
395,
652,
2597,
5171,
272,
298,
2859,
1674,
339,
982,
314,
1347,
1777,
436,
314,
14457,
22627,
652,
787,
3865,
11684,
12,
272,
3286,
8171,
18,
2,
365,
10826,
14,
339,
710,
2569,
1511,
883,
506,
1627,
465,
4252,
2368,
26,
398,
7773,
26,
282,
7773,
6434,
267,
2644,
26,
314,
1056,
2644,
334,
885,
365,
9094,
13,
24,
9,
267,
3376,
26,
8661,
2166,
267,
4566,
26,
675,
376,
3101,
4566,
267,
3434,
26,
3434,
367,
15082,
3101,
4566,
267,
2505,
26,
2505,
367,
15082,
3101,
4566,
339,
2900,
1695,
13,
2075,
3326,
3032,
370,
314,
1654,
4566,
787,
10826,
370,
675,
272,
314,
1627,
2644,
14,
272,
408,
339,
327,
3758,
22115,
272,
485,
5545,
63,
533,
275,
7773,
83,
14,
7836,
272,
485,
5545,
63,
533,
63,
2859,
275,
7773,
83,
14,
11090,
7836,
272,
485,
5545,
63,
533,
63,
3280,
275,
7773,
83,
14,
4936,
7836,
272,
485,
5545,
63,
533,
63,
2859,
63,
3280,
275,
7773,
83,
14,
11090,
4936,
7836,
272,
347,
636,
826,
721,
277,
12,
5108,
12,
7773,
29,
403,
12,
2644,
29,
403,
12,
3376,
29,
16,
12,
267,
4566,
29,
403,
12,
3434,
29,
403,
12,
2505,
29,
403,
12,
9236,
2806,
29,
403,
12,
267,
6696,
2806,
29,
403,
12,
2653,
29,
403,
304,
267,
327,
16873,
282,
298,
7954,
2,
1654,
1950,
398,
327,
267,
327,
7758,
2198,
314,
4566,
2556,
340,
2808,
267,
327,
267,
340,
4566,
1137,
488,
26,
288,
334,
838,
12,
11618,
12,
18848,
12,
19206,
9,
275,
664,
63,
3280,
63,
815,
8,
3280,
9,
953,
340,
11618,
365,
440,
488,
26,
355,
4566,
275,
2071,
83,
2689,
83,
2,
450,
334,
838,
12,
11618,
9,
288,
587,
26,
355,
4566,
275,
3945,
953,
327,
3434,
436,
2505,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
RyanChinSang/ECNG3020-ORSS4SCVI
|
BETA/TestCode/OpenCV/APP-HaarCasObjDet.py
|
1
|
1432
|
import cv2
import winsound
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
eye_cascade = cv2.CascadeClassifier('haarcascade_eye.xml')
cap = cv2.VideoCapture(0)
while 1:
ret, img = cap.read()
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray, 1.3, 5)
for (x, y, w, h) in faces:
cv2.rectangle(img, (x, y), (x + w, y + h), (255, 0, 0), 2)
roi_gray = gray[y:y + h, x:x + w]
roi_color = img[y:y + h, x:x + w]
eyes = eye_cascade.detectMultiScale3(roi_gray, outputRejectLevels=True)
# eyes = eye_cascade.detectMultiScale2(roi_gray)
# print(eyes[1], len(eyes[1]))
# print(eyes[2], len(eyes[2]))
s = 0
a = 0
for i in eyes[2]:
s = s + i[0]
a = s/len(eyes[2])
if a < 0.25:
frequency = 1500 # Set Frequency To 2500 Hertz
duration = 1000 # Set Duration To 1000 ms == 1 second
winsound.Beep(frequency, duration)
for (ex, ey, ew, eh) in eyes[0]:
# advance_frame(roi_color, img, eyes[0])
cv2.rectangle(roi_color, (ex, ey), (ex + ew, ey + eh), (0, 255, 0), 2)
# print(rectList)
# cv2.groupRectangles(rectList, 3, 0.2)
cv2.imshow('img', img)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
|
gpl-3.0
|
[
646,
6277,
18,
199,
646,
29431,
1034,
199,
199,
1409,
63,
15377,
275,
6277,
18,
14,
35,
305,
9490,
8508,
360,
2411,
285,
15377,
63,
70,
2641,
502,
276,
7984,
63,
885,
14,
1652,
358,
199,
15240,
63,
15377,
275,
6277,
18,
14,
35,
305,
9490,
8508,
360,
2411,
285,
15377,
63,
15240,
14,
1652,
358,
199,
199,
2874,
275,
6277,
18,
14,
9166,
16640,
8,
16,
9,
199,
199,
6710,
413,
26,
272,
2203,
12,
6050,
275,
4021,
14,
739,
342,
272,
21977,
275,
6277,
18,
14,
5107,
84,
4117,
8,
4060,
12,
6277,
18,
14,
7134,
63,
34,
3975,
18,
18583,
57,
9,
272,
21143,
275,
8870,
63,
15377,
14,
13552,
3947,
9944,
8,
12150,
12,
413,
14,
19,
12,
959,
9,
272,
367,
334,
88,
12,
612,
12,
336,
12,
394,
9,
315,
21143,
26,
267,
6277,
18,
14,
19954,
8,
4060,
12,
334,
88,
12,
612,
395,
334,
88,
435,
336,
12,
612,
435,
394,
395,
334,
2299,
12,
378,
12,
378,
395,
499,
9,
267,
30240,
63,
12150,
275,
21977,
59,
89,
26,
89,
435,
394,
12,
671,
26,
88,
435,
336,
61,
267,
30240,
63,
2326,
275,
6050,
59,
89,
26,
89,
435,
394,
12,
671,
26,
88,
435,
336,
61,
267,
325,
5066,
275,
25892,
63,
15377,
14,
13552,
3947,
9944,
19,
8,
20581,
63,
12150,
12,
1072,
497,
963,
4670,
83,
29,
549,
9,
267,
327,
325,
5066,
275,
25892,
63,
15377,
14,
13552,
3947,
9944,
18,
8,
20581,
63,
12150,
9,
267,
327,
870,
8,
69,
5066,
59,
17,
467,
822,
8,
69,
5066,
59,
17,
2459,
267,
327,
870,
8,
69,
5066,
59,
18,
467,
822,
8,
69,
5066,
59,
18,
2459,
267,
308,
275,
378,
267,
282,
275,
378,
267,
367,
284,
315,
325,
5066,
59,
18,
2189,
288,
308,
275,
308,
435,
284,
59,
16,
61,
288,
282,
275,
308,
15,
552,
8,
69,
5066,
59,
18,
566,
288,
340,
282,
665,
378,
14,
821,
26,
355,
9857,
275,
24970,
221,
327,
2494,
481,
6056,
4005,
5661,
383,
18769,
3903,
355,
7373,
275,
5198,
221,
327,
2494,
31836,
4005,
5198,
6605,
508,
413,
3499,
355,
29431,
1034,
14,
34,
7840,
8,
11132,
12,
7373,
9,
398,
367,
334,
476,
12,
325,
89,
12,
325,
87,
12,
325,
72,
9,
315,
325,
5066,
59,
16,
2189,
288,
327,
18695,
63,
1943,
8,
20581,
63,
2326,
12,
6050,
12,
325,
5066,
59,
16,
566,
288,
6277,
18,
14,
19954,
8,
20581,
63,
2326,
12,
334,
476,
12,
325,
89,
395,
334,
476,
435,
325,
87,
12,
325,
89,
435,
325,
72,
395,
334,
16,
12,
5450,
12,
378,
395,
499,
9,
288,
327,
870,
8,
1201,
1296,
9,
288,
327,
6277,
18,
14,
923,
8252,
13162,
8,
1201,
1296,
12,
650,
12,
378,
14,
18,
9,
272,
6277,
18,
14,
20413,
360,
4060,
297,
6050,
9,
339,
340,
6277,
18,
14,
2573,
1197,
8,
17,
9,
1253,
378,
9039,
508,
6206,
360,
81,
735,
267,
2059,
199,
199,
2874,
14,
3221,
342,
199,
5107,
18,
14,
7237,
2422,
8647,
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
] |
[
6277,
18,
199,
646,
29431,
1034,
199,
199,
1409,
63,
15377,
275,
6277,
18,
14,
35,
305,
9490,
8508,
360,
2411,
285,
15377,
63,
70,
2641,
502,
276,
7984,
63,
885,
14,
1652,
358,
199,
15240,
63,
15377,
275,
6277,
18,
14,
35,
305,
9490,
8508,
360,
2411,
285,
15377,
63,
15240,
14,
1652,
358,
199,
199,
2874,
275,
6277,
18,
14,
9166,
16640,
8,
16,
9,
199,
199,
6710,
413,
26,
272,
2203,
12,
6050,
275,
4021,
14,
739,
342,
272,
21977,
275,
6277,
18,
14,
5107,
84,
4117,
8,
4060,
12,
6277,
18,
14,
7134,
63,
34,
3975,
18,
18583,
57,
9,
272,
21143,
275,
8870,
63,
15377,
14,
13552,
3947,
9944,
8,
12150,
12,
413,
14,
19,
12,
959,
9,
272,
367,
334,
88,
12,
612,
12,
336,
12,
394,
9,
315,
21143,
26,
267,
6277,
18,
14,
19954,
8,
4060,
12,
334,
88,
12,
612,
395,
334,
88,
435,
336,
12,
612,
435,
394,
395,
334,
2299,
12,
378,
12,
378,
395,
499,
9,
267,
30240,
63,
12150,
275,
21977,
59,
89,
26,
89,
435,
394,
12,
671,
26,
88,
435,
336,
61,
267,
30240,
63,
2326,
275,
6050,
59,
89,
26,
89,
435,
394,
12,
671,
26,
88,
435,
336,
61,
267,
325,
5066,
275,
25892,
63,
15377,
14,
13552,
3947,
9944,
19,
8,
20581,
63,
12150,
12,
1072,
497,
963,
4670,
83,
29,
549,
9,
267,
327,
325,
5066,
275,
25892,
63,
15377,
14,
13552,
3947,
9944,
18,
8,
20581,
63,
12150,
9,
267,
327,
870,
8,
69,
5066,
59,
17,
467,
822,
8,
69,
5066,
59,
17,
2459,
267,
327,
870,
8,
69,
5066,
59,
18,
467,
822,
8,
69,
5066,
59,
18,
2459,
267,
308,
275,
378,
267,
282,
275,
378,
267,
367,
284,
315,
325,
5066,
59,
18,
2189,
288,
308,
275,
308,
435,
284,
59,
16,
61,
288,
282,
275,
308,
15,
552,
8,
69,
5066,
59,
18,
566,
288,
340,
282,
665,
378,
14,
821,
26,
355,
9857,
275,
24970,
221,
327,
2494,
481,
6056,
4005,
5661,
383,
18769,
3903,
355,
7373,
275,
5198,
221,
327,
2494,
31836,
4005,
5198,
6605,
508,
413,
3499,
355,
29431,
1034,
14,
34,
7840,
8,
11132,
12,
7373,
9,
398,
367,
334,
476,
12,
325,
89,
12,
325,
87,
12,
325,
72,
9,
315,
325,
5066,
59,
16,
2189,
288,
327,
18695,
63,
1943,
8,
20581,
63,
2326,
12,
6050,
12,
325,
5066,
59,
16,
566,
288,
6277,
18,
14,
19954,
8,
20581,
63,
2326,
12,
334,
476,
12,
325,
89,
395,
334,
476,
435,
325,
87,
12,
325,
89,
435,
325,
72,
395,
334,
16,
12,
5450,
12,
378,
395,
499,
9,
288,
327,
870,
8,
1201,
1296,
9,
288,
327,
6277,
18,
14,
923,
8252,
13162,
8,
1201,
1296,
12,
650,
12,
378,
14,
18,
9,
272,
6277,
18,
14,
20413,
360,
4060,
297,
6050,
9,
339,
340,
6277,
18,
14,
2573,
1197,
8,
17,
9,
1253,
378,
9039,
508,
6206,
360,
81,
735,
267,
2059,
199,
199,
2874,
14,
3221,
342,
199,
5107,
18,
14,
7237,
2422,
8647,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
wangxiangyu/horizon
|
horizon/test/tests/middleware.py
|
61
|
2400
|
# 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 time
from django.conf import settings
from django.http import HttpResponseRedirect # noqa
from horizon import exceptions
from horizon import middleware
from horizon.test import helpers as test
class MiddlewareTests(test.TestCase):
def test_redirect_login_fail_to_login(self):
url = settings.LOGIN_URL
request = self.factory.post(url)
mw = middleware.HorizonMiddleware()
resp = mw.process_exception(request, exceptions.NotAuthorized())
resp.client = self.client
self.assertRedirects(resp, url)
def test_session_timeout(self):
requested_url = '/project/instances/'
request = self.factory.get(requested_url)
try:
timeout = settings.SESSION_TIMEOUT
except AttributeError:
timeout = 1800
request.session['last_activity'] = int(time.time()) - (timeout + 10)
mw = middleware.HorizonMiddleware()
resp = mw.process_request(request)
self.assertEqual(302, resp.status_code)
self.assertEqual(requested_url, resp.get('Location'))
def test_process_response_redirect_on_ajax_request(self):
url = settings.LOGIN_URL
mw = middleware.HorizonMiddleware()
request = self.factory.post(url,
HTTP_X_REQUESTED_WITH='XMLHttpRequest')
request.META['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'
request.horizon = {'async_messages':
[('error', 'error_msg', 'extra_tag')]}
response = HttpResponseRedirect(url)
response.client = self.client
resp = mw.process_response(request, response)
self.assertEqual(200, resp.status_code)
self.assertEqual(url, resp['X-Horizon-Location'])
|
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,
900,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
199,
504,
1639,
14,
1014,
492,
14935,
221,
327,
8151,
199,
199,
504,
21726,
492,
4967,
199,
504,
21726,
492,
10816,
199,
504,
21726,
14,
396,
492,
10897,
465,
511,
421,
199,
533,
603,
3551,
2925,
8,
396,
14,
1746,
304,
272,
347,
511,
63,
4876,
63,
2886,
63,
1633,
63,
475,
63,
2886,
8,
277,
304,
267,
1166,
275,
2202,
14,
17208,
63,
2632,
267,
1056,
275,
291,
14,
3702,
14,
1932,
8,
633,
9,
398,
23530,
275,
10816,
14,
40,
11925,
6608,
342,
267,
3085,
275,
23530,
14,
1412,
63,
1971,
8,
1069,
12,
4967,
14,
1763,
29284,
1012,
267,
3085,
14,
1258,
275,
291,
14,
1258,
398,
291,
14,
17466,
8,
4518,
12,
1166,
9,
339,
347,
511,
63,
1730,
63,
2593,
8,
277,
304,
267,
5839,
63,
633,
275,
1994,
1715,
15,
5990,
4805,
267,
1056,
275,
291,
14,
3702,
14,
362,
8,
11151,
63,
633,
9,
267,
862,
26,
288,
2653,
275,
2202,
14,
12763,
63,
8899,
267,
871,
4281,
26,
288,
2653,
275,
6155,
383,
267,
1056,
14,
1730,
459,
2019,
63,
8240,
418,
275,
1109,
8,
521,
14,
521,
1012,
446,
334,
2593,
435,
1616,
9,
267,
23530,
275,
10816,
14,
40,
11925,
6608,
342,
267,
3085,
275,
23530,
14,
1412,
63,
1069,
8,
1069,
9,
267,
291,
14,
629,
8,
8551,
12,
3085,
14,
1205,
63,
600,
9,
267,
291,
14,
629,
8,
11151,
63,
633,
12,
3085,
14,
362,
360,
6592,
1333,
339,
347,
511,
63,
1412,
63,
1310,
63,
4876,
63,
265,
63,
12774,
63,
1069,
8,
277,
304,
267,
1166,
275,
2202,
14,
17208,
63,
2632,
267,
23530,
275,
10816,
14,
40,
11925,
6608,
342,
398,
1056,
275,
291,
14,
3702,
14,
1932,
8,
633,
12,
2511,
3101,
63,
56,
63,
6780,
1149,
63,
9139,
534,
4317,
10441,
358,
267,
1056,
14,
10614,
459,
2856,
63,
56,
63,
6780,
1149,
63,
9139,
418,
275,
283,
4317,
10441,
7,
267,
1056,
14,
16561,
275,
791,
4146,
63,
3431,
356,
2574,
4274,
705,
297,
283,
705,
63,
1328,
297,
283,
2911,
63,
1450,
5440,
93,
398,
1177,
275,
14935,
8,
633,
9,
267,
1177,
14,
1258,
275,
291,
14,
1258,
398,
3085,
275,
23530,
14,
1412,
63,
1310,
8,
1069,
12,
1177,
9,
267,
291,
14,
629,
8,
1840,
12,
3085,
14,
1205,
63,
600,
9,
267,
291,
14,
629,
8,
633,
12,
3085,
459,
56,
13,
40,
11925,
13,
6592,
1105,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
900,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
199,
504,
1639,
14,
1014,
492,
14935,
221,
327,
8151,
199,
199,
504,
21726,
492,
4967,
199,
504,
21726,
492,
10816,
199,
504,
21726,
14,
396,
492,
10897,
465,
511,
421,
199,
533,
603,
3551,
2925,
8,
396,
14,
1746,
304,
272,
347,
511,
63,
4876,
63,
2886,
63,
1633,
63,
475,
63,
2886,
8,
277,
304,
267,
1166,
275,
2202,
14,
17208,
63,
2632,
267,
1056,
275,
291,
14,
3702,
14,
1932,
8,
633,
9,
398,
23530,
275,
10816,
14,
40,
11925,
6608,
342,
267,
3085,
275,
23530,
14,
1412,
63,
1971,
8,
1069,
12,
4967,
14,
1763,
29284,
1012,
267,
3085,
14,
1258,
275,
291,
14,
1258,
398,
291,
14,
17466,
8,
4518,
12,
1166,
9,
339,
347,
511,
63,
1730,
63,
2593,
8,
277,
304,
267,
5839,
63,
633,
275,
1994,
1715,
15,
5990,
4805,
267,
1056,
275,
291,
14,
3702,
14,
362,
8,
11151,
63,
633,
9,
267,
862,
26,
288,
2653,
275,
2202,
14,
12763,
63,
8899,
267,
871,
4281,
26,
288,
2653,
275,
6155,
383,
267,
1056,
14,
1730,
459,
2019,
63,
8240,
418,
275,
1109,
8,
521,
14,
521,
1012,
446,
334,
2593,
435,
1616,
9,
267,
23530,
275,
10816,
14,
40,
11925,
6608,
342,
267,
3085,
275,
23530,
14,
1412,
63,
1069,
8,
1069,
9,
267,
291,
14,
629,
8,
8551,
12,
3085,
14,
1205,
63,
600,
9,
267,
291,
14,
629,
8,
11151,
63,
633,
12,
3085,
14,
362,
360,
6592,
1333,
339,
347,
511,
63,
1412,
63,
1310,
63,
4876,
63,
265,
63,
12774,
63,
1069,
8,
277,
304,
267,
1166,
275,
2202,
14,
17208,
63,
2632,
267,
23530,
275,
10816,
14,
40,
11925,
6608,
342,
398,
1056,
275,
291,
14,
3702,
14,
1932,
8,
633,
12,
2511,
3101,
63,
56,
63,
6780,
1149,
63,
9139,
534,
4317,
10441,
358,
267,
1056,
14,
10614,
459,
2856,
63,
56,
63,
6780,
1149,
63,
9139,
418,
275,
283,
4317,
10441,
7,
267,
1056,
14,
16561,
275,
791,
4146,
63,
3431,
356,
2574,
4274,
705,
297,
283,
705,
63,
1328,
297,
283,
2911,
63,
1450,
5440,
93,
398,
1177,
275,
14935,
8,
633,
9,
267,
1177,
14,
1258,
275,
291,
14,
1258,
398,
3085,
275,
23530,
14,
1412,
63,
1310,
8,
1069,
12,
1177,
9,
267,
291,
14,
629,
8,
1840,
12,
3085,
14,
1205,
63,
600,
9,
267,
291,
14,
629,
8,
633,
12,
3085,
459,
56,
13,
40,
11925,
13,
6592,
1105,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
bulislaw/mbed-os
|
tools/test/targets/target_test.py
|
17
|
1446
|
#!/usr/bin/env python
"""
mbed
Copyright (c) 2017-2017 ARM Limited
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
import sys
from os.path import join, abspath, dirname
import unittest
# Be sure that the tools directory is in the search path
ROOT = abspath(join(dirname(__file__), "..", "..", ".."))
sys.path.insert(0, ROOT)
from tools.targets import TARGETS
from tools.arm_pack_manager import Cache
class TestTargets(unittest.TestCase):
def test_device_name(self):
"""Assert device name is in a pack"""
cache = Cache(True, True)
named_targets = (target for target in TARGETS if
hasattr(target, "device_name"))
for target in named_targets:
self.assertTrue(target.device_name in cache.index,
"Target %s contains invalid device_name %s" %
(target.name, target.device_name))
if __name__ == '__main__':
unittest.main()
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
624,
199,
333,
6123,
199,
1898,
334,
67,
9,
9708,
13,
10680,
27155,
23954,
421,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
10813,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
421,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
4204,
1334,
314,
844,
14,
199,
624,
199,
199,
646,
984,
199,
504,
747,
14,
515,
492,
4263,
12,
19529,
12,
9017,
199,
646,
2882,
199,
199,
3,
6423,
3238,
626,
314,
7249,
2082,
365,
315,
314,
2754,
931,
199,
5441,
275,
19529,
8,
904,
8,
3475,
3460,
493,
10139,
21777,
401,
21777,
401,
21777,
2237,
199,
1274,
14,
515,
14,
3176,
8,
16,
12,
16547,
9,
199,
199,
504,
7249,
14,
4684,
492,
26134,
51,
199,
504,
7249,
14,
5362,
63,
1389,
63,
2609,
492,
11977,
199,
199,
533,
1379,
14126,
8,
2796,
14,
1746,
304,
339,
347,
511,
63,
1782,
63,
354,
8,
277,
304,
267,
408,
9699,
2243,
536,
365,
315,
282,
1706,
624,
267,
2581,
275,
11977,
8,
549,
12,
715,
9,
267,
4310,
63,
4684,
275,
334,
1375,
367,
1347,
315,
26134,
51,
340,
586,
2688,
8,
1375,
12,
298,
1782,
63,
354,
2237,
267,
367,
1347,
315,
4310,
63,
4684,
26,
288,
291,
14,
1815,
8,
1375,
14,
1782,
63,
354,
315,
2581,
14,
1080,
12,
1169,
298,
4277,
450,
83,
3509,
3866,
2243,
63,
354,
450,
83,
2,
450,
1169,
334,
1375,
14,
354,
12,
1347,
14,
1782,
63,
354,
430,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
2882,
14,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
624,
199,
333,
6123,
199,
1898,
334,
67,
9,
9708,
13,
10680,
27155,
23954,
421,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
10813,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
421,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
4204,
1334,
314,
844,
14,
199,
624,
199,
199,
646,
984,
199,
504,
747,
14,
515,
492,
4263,
12,
19529,
12,
9017,
199,
646,
2882,
199,
199,
3,
6423,
3238,
626,
314,
7249,
2082,
365,
315,
314,
2754,
931,
199,
5441,
275,
19529,
8,
904,
8,
3475,
3460,
493,
10139,
21777,
401,
21777,
401,
21777,
2237,
199,
1274,
14,
515,
14,
3176,
8,
16,
12,
16547,
9,
199,
199,
504,
7249,
14,
4684,
492,
26134,
51,
199,
504,
7249,
14,
5362,
63,
1389,
63,
2609,
492,
11977,
199,
199,
533,
1379,
14126,
8,
2796,
14,
1746,
304,
339,
347,
511,
63,
1782,
63,
354,
8,
277,
304,
267,
408,
9699,
2243,
536,
365,
315,
282,
1706,
624,
267,
2581,
275,
11977,
8,
549,
12,
715,
9,
267,
4310,
63,
4684,
275,
334,
1375,
367,
1347,
315,
26134,
51,
340,
586,
2688,
8,
1375,
12,
298,
1782,
63,
354,
2237,
267,
367,
1347,
315,
4310,
63,
4684,
26,
288,
291,
14,
1815,
8,
1375,
14,
1782,
63,
354,
315,
2581,
14,
1080,
12,
1169,
298,
4277,
450,
83,
3509,
3866,
2243,
63,
354,
450,
83,
2,
450,
1169,
334,
1375,
14,
354,
12,
1347,
14,
1782,
63,
354,
430,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
2882,
14,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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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
] |
thenewguy/wagtail
|
wagtail/wagtailsearch/views/queries.py
|
6
|
1771
|
from django.shortcuts import render
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.contrib.auth.decorators import permission_required
from wagtail.wagtailadmin.modal_workflow import render_modal_workflow
from wagtail.wagtailadmin.forms import SearchForm
from wagtail.wagtailsearch import models
from wagtail.wagtailsearch.utils import normalise_query_string
@permission_required('wagtailadmin.access_admin')
def chooser(request, get_results=False):
# Get most popular queries
queries = models.Query.get_most_popular()
# If searching, filter results by query string
query_string = None
if 'q' in request.GET:
searchform = SearchForm(request.GET)
if searchform.is_valid():
query_string = searchform.cleaned_data['q']
queries = queries.filter(query_string__icontains=normalise_query_string(query_string))
else:
searchform = SearchForm()
# Pagination
p = request.GET.get('p', 1)
paginator = Paginator(queries, 10)
try:
queries = paginator.page(p)
except PageNotAnInteger:
queries = paginator.page(1)
except EmptyPage:
queries = paginator.page(paginator.num_pages)
# Render
if get_results:
return render(request, "wagtailsearch/queries/chooser/results.html", {
'queries': queries,
'query_string': query_string,
})
else:
return render_modal_workflow(request, 'wagtailsearch/queries/chooser/chooser.html', 'wagtailsearch/queries/chooser/chooser.js', {
'queries': queries,
'searchform': searchform,
'query_string': query_string,
})
def chooserresults(request):
return chooser(request, get_results=True)
|
bsd-3-clause
|
[
504,
1639,
14,
17469,
492,
3795,
199,
504,
1639,
14,
1018,
14,
22073,
492,
28006,
8566,
12,
9630,
3276,
12,
10331,
1763,
2493,
2674,
199,
504,
1639,
14,
2828,
14,
1178,
14,
11582,
492,
4983,
63,
2427,
199,
199,
504,
7328,
14,
30874,
14,
17713,
63,
8856,
492,
3795,
63,
17713,
63,
8856,
199,
504,
7328,
14,
30874,
14,
3351,
492,
8730,
2821,
199,
199,
504,
7328,
14,
17296,
1733,
492,
1709,
199,
504,
7328,
14,
17296,
1733,
14,
1208,
492,
3293,
572,
63,
1131,
63,
875,
421,
199,
32,
5693,
63,
2427,
360,
30874,
14,
2732,
63,
2113,
358,
199,
318,
2468,
13041,
8,
1069,
12,
664,
63,
2604,
29,
797,
304,
272,
327,
2372,
4750,
4560,
2238,
9212,
272,
9212,
275,
1709,
14,
3227,
14,
362,
63,
2786,
63,
1935,
2238,
342,
339,
327,
982,
18112,
12,
2457,
2058,
701,
1827,
1059,
272,
1827,
63,
875,
275,
488,
272,
340,
283,
81,
7,
315,
1056,
14,
2970,
26,
267,
2754,
964,
275,
8730,
2821,
8,
1069,
14,
2970,
9,
267,
340,
2754,
964,
14,
374,
63,
1078,
837,
288,
1827,
63,
875,
275,
2754,
964,
14,
8275,
63,
576,
459,
81,
418,
288,
9212,
275,
9212,
14,
1541,
8,
1131,
63,
875,
363,
30314,
29,
3302,
572,
63,
1131,
63,
875,
8,
1131,
63,
875,
430,
272,
587,
26,
267,
2754,
964,
275,
8730,
2821,
342,
339,
327,
28006,
3155,
272,
299,
275,
1056,
14,
2970,
14,
362,
360,
80,
297,
413,
9,
339,
21398,
275,
28006,
8566,
8,
10590,
12,
1616,
9,
272,
862,
26,
267,
9212,
275,
21398,
14,
1606,
8,
80,
9,
272,
871,
10331,
1763,
2493,
2674,
26,
267,
9212,
275,
21398,
14,
1606,
8,
17,
9,
272,
871,
9630,
3276,
26,
267,
9212,
275,
21398,
14,
1606,
8,
22073,
14,
1507,
63,
5856,
9,
339,
327,
17769,
272,
340,
664,
63,
2604,
26,
267,
372,
3795,
8,
1069,
12,
298,
17296,
1733,
15,
10590,
15,
31123,
15,
2604,
14,
1360,
401,
469,
288,
283,
10590,
356,
9212,
12,
288,
283,
1131,
63,
875,
356,
1827,
63,
875,
12,
267,
3828,
272,
587,
26,
267,
372,
3795,
63,
17713,
63,
8856,
8,
1069,
12,
283,
17296,
1733,
15,
10590,
15,
31123,
15,
31123,
14,
1360,
297,
283,
17296,
1733,
15,
10590,
15,
31123,
15,
31123,
14,
3596,
297,
469,
288,
283,
10590,
356,
9212,
12,
288,
283,
1733,
964,
356,
2754,
964,
12,
288,
283,
1131,
63,
875,
356,
1827,
63,
875,
12,
267,
3828,
421,
199,
318,
2468,
13041,
2604,
8,
1069,
304,
272,
372,
2468,
13041,
8,
1069,
12,
664,
63,
2604,
29,
549,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
1018,
14,
22073,
492,
28006,
8566,
12,
9630,
3276,
12,
10331,
1763,
2493,
2674,
199,
504,
1639,
14,
2828,
14,
1178,
14,
11582,
492,
4983,
63,
2427,
199,
199,
504,
7328,
14,
30874,
14,
17713,
63,
8856,
492,
3795,
63,
17713,
63,
8856,
199,
504,
7328,
14,
30874,
14,
3351,
492,
8730,
2821,
199,
199,
504,
7328,
14,
17296,
1733,
492,
1709,
199,
504,
7328,
14,
17296,
1733,
14,
1208,
492,
3293,
572,
63,
1131,
63,
875,
421,
199,
32,
5693,
63,
2427,
360,
30874,
14,
2732,
63,
2113,
358,
199,
318,
2468,
13041,
8,
1069,
12,
664,
63,
2604,
29,
797,
304,
272,
327,
2372,
4750,
4560,
2238,
9212,
272,
9212,
275,
1709,
14,
3227,
14,
362,
63,
2786,
63,
1935,
2238,
342,
339,
327,
982,
18112,
12,
2457,
2058,
701,
1827,
1059,
272,
1827,
63,
875,
275,
488,
272,
340,
283,
81,
7,
315,
1056,
14,
2970,
26,
267,
2754,
964,
275,
8730,
2821,
8,
1069,
14,
2970,
9,
267,
340,
2754,
964,
14,
374,
63,
1078,
837,
288,
1827,
63,
875,
275,
2754,
964,
14,
8275,
63,
576,
459,
81,
418,
288,
9212,
275,
9212,
14,
1541,
8,
1131,
63,
875,
363,
30314,
29,
3302,
572,
63,
1131,
63,
875,
8,
1131,
63,
875,
430,
272,
587,
26,
267,
2754,
964,
275,
8730,
2821,
342,
339,
327,
28006,
3155,
272,
299,
275,
1056,
14,
2970,
14,
362,
360,
80,
297,
413,
9,
339,
21398,
275,
28006,
8566,
8,
10590,
12,
1616,
9,
272,
862,
26,
267,
9212,
275,
21398,
14,
1606,
8,
80,
9,
272,
871,
10331,
1763,
2493,
2674,
26,
267,
9212,
275,
21398,
14,
1606,
8,
17,
9,
272,
871,
9630,
3276,
26,
267,
9212,
275,
21398,
14,
1606,
8,
22073,
14,
1507,
63,
5856,
9,
339,
327,
17769,
272,
340,
664,
63,
2604,
26,
267,
372,
3795,
8,
1069,
12,
298,
17296,
1733,
15,
10590,
15,
31123,
15,
2604,
14,
1360,
401,
469,
288,
283,
10590,
356,
9212,
12,
288,
283,
1131,
63,
875,
356,
1827,
63,
875,
12,
267,
3828,
272,
587,
26,
267,
372,
3795,
63,
17713,
63,
8856,
8,
1069,
12,
283,
17296,
1733,
15,
10590,
15,
31123,
15,
31123,
14,
1360,
297,
283,
17296,
1733,
15,
10590,
15,
31123,
15,
31123,
14,
3596,
297,
469,
288,
283,
10590,
356,
9212,
12,
288,
283,
1733,
964,
356,
2754,
964,
12,
288,
283,
1131,
63,
875,
356,
1827,
63,
875,
12,
267,
3828,
421,
199,
318,
2468,
13041,
2604,
8,
1069,
304,
272,
372,
2468,
13041,
8,
1069,
12,
664,
63,
2604,
29,
549,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
ludmilamarian/invenio
|
invenio/utils/memoise.py
|
18
|
1488
|
# -*- coding: utf-8 -*-
#
# This file is part of Invenio.
# Copyright (C) 2013 CERN.
#
# Invenio is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# Invenio 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 Invenio; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
"""
Memoisation utilities.
"""
import functools
class Memoise:
"""
Basic memoisation helper.
Usage: fun = Memoise(fun)
"""
def __init__(self, function):
"""Initialise."""
self.memo = {}
self.function = function
def __call__(self, *args):
"""Run and eventually memoise."""
if args not in self.memo:
self.memo[args] = self.function(*args)
return self.memo[args]
def memoize(obj):
cache = obj.cache = {}
@functools.wraps(obj)
def memoizer(*args, **kwargs):
key = str(args) + str(kwargs)
if key not in cache:
cache[key] = obj(*args, **kwargs)
return cache[key]
return memoizer
|
gpl-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
12235,
14,
199,
3,
1898,
334,
35,
9,
6171,
24354,
14,
199,
3,
199,
3,
12235,
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,
499,
402,
314,
199,
3,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
12235,
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,
12235,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
2752,
12,
3277,
2020,
199,
3,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
15673,
13,
13421,
12,
8217,
14,
199,
199,
624,
199,
1352,
573,
19914,
15841,
14,
199,
624,
199,
646,
9143,
421,
199,
533,
3194,
573,
572,
26,
272,
408,
272,
10082,
11955,
19914,
5922,
14,
272,
11028,
26,
9627,
275,
3194,
573,
572,
8,
7036,
9,
272,
408,
339,
347,
636,
826,
721,
277,
12,
805,
304,
267,
408,
5733,
572,
1041,
267,
291,
14,
11979,
275,
1052,
267,
291,
14,
1593,
275,
805,
339,
347,
636,
1250,
721,
277,
12,
627,
589,
304,
267,
408,
2540,
436,
21356,
11955,
572,
1041,
267,
340,
1249,
440,
315,
291,
14,
11979,
26,
288,
291,
14,
11979,
59,
589,
61,
275,
291,
14,
1593,
2031,
589,
9,
267,
372,
291,
14,
11979,
59,
589,
61,
421,
199,
318,
11955,
794,
8,
1113,
304,
272,
2581,
275,
1559,
14,
1637,
275,
1052,
272,
768,
17869,
14,
13582,
8,
1113,
9,
272,
347,
11955,
1793,
2031,
589,
12,
1011,
958,
304,
267,
790,
275,
620,
8,
589,
9,
435,
620,
8,
958,
9,
267,
340,
790,
440,
315,
2581,
26,
288,
2581,
59,
498,
61,
275,
1559,
2031,
589,
12,
1011,
958,
9,
267,
372,
2581,
59,
498,
61,
272,
372,
11955,
1793,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
961,
570,
365,
1777,
402,
12235,
14,
199,
3,
1898,
334,
35,
9,
6171,
24354,
14,
199,
3,
199,
3,
12235,
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,
499,
402,
314,
199,
3,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
12235,
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,
12235,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
2752,
12,
3277,
2020,
199,
3,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
15673,
13,
13421,
12,
8217,
14,
199,
199,
624,
199,
1352,
573,
19914,
15841,
14,
199,
624,
199,
646,
9143,
421,
199,
533,
3194,
573,
572,
26,
272,
408,
272,
10082,
11955,
19914,
5922,
14,
272,
11028,
26,
9627,
275,
3194,
573,
572,
8,
7036,
9,
272,
408,
339,
347,
636,
826,
721,
277,
12,
805,
304,
267,
408,
5733,
572,
1041,
267,
291,
14,
11979,
275,
1052,
267,
291,
14,
1593,
275,
805,
339,
347,
636,
1250,
721,
277,
12,
627,
589,
304,
267,
408,
2540,
436,
21356,
11955,
572,
1041,
267,
340,
1249,
440,
315,
291,
14,
11979,
26,
288,
291,
14,
11979,
59,
589,
61,
275,
291,
14,
1593,
2031,
589,
9,
267,
372,
291,
14,
11979,
59,
589,
61,
421,
199,
318,
11955,
794,
8,
1113,
304,
272,
2581,
275,
1559,
14,
1637,
275,
1052,
272,
768,
17869,
14,
13582,
8,
1113,
9,
272,
347,
11955,
1793,
2031,
589,
12,
1011,
958,
304,
267,
790,
275,
620,
8,
589,
9,
435,
620,
8,
958,
9,
267,
340,
790,
440,
315,
2581,
26,
288,
2581,
59,
498,
61,
275,
1559,
2031,
589,
12,
1011,
958,
9,
267,
372,
2581,
59,
498,
61,
272,
372,
11955,
1793,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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
] |
instantchow/home-assistant
|
tests/components/sensor/test_template.py
|
2
|
3987
|
"""The test for the Template sensor platform."""
import homeassistant.components.sensor as sensor
from tests.common import get_test_home_assistant
class TestTemplateSensor:
"""Test the Template sensor."""
def setup_method(self, method):
"""Setup things to be run when tests are started."""
self.hass = get_test_home_assistant()
def teardown_method(self, method):
"""Stop everything that was started."""
self.hass.stop()
def test_template(self):
"""Test template."""
assert sensor.setup(self.hass, {
'sensor': {
'platform': 'template',
'sensors': {
'test_template_sensor': {
'value_template':
"It {{ states.sensor.test_state.state }}."
}
}
}
})
state = self.hass.states.get('sensor.test_template_sensor')
assert state.state == 'It .'
self.hass.states.set('sensor.test_state', 'Works')
self.hass.pool.block_till_done()
state = self.hass.states.get('sensor.test_template_sensor')
assert state.state == 'It Works.'
def test_template_syntax_error(self):
"""Test templating syntax error."""
assert sensor.setup(self.hass, {
'sensor': {
'platform': 'template',
'sensors': {
'test_template_sensor': {
'value_template':
"{% if rubbish %}"
}
}
}
})
self.hass.states.set('sensor.test_state', 'Works')
self.hass.pool.block_till_done()
state = self.hass.states.get('sensor.test_template_sensor')
assert state.state == 'error'
def test_template_attribute_missing(self):
"""Test missing attribute template."""
assert sensor.setup(self.hass, {
'sensor': {
'platform': 'template',
'sensors': {
'test_template_sensor': {
'value_template':
"It {{ states.sensor.test_state.attributes.missing }}."
}
}
}
})
state = self.hass.states.get('sensor.test_template_sensor')
assert state.state == 'error'
def test_invalid_name_does_not_create(self):
"""Test invalid name."""
assert sensor.setup(self.hass, {
'sensor': {
'platform': 'template',
'sensors': {
'test INVALID sensor': {
'value_template':
"{{ states.sensor.test_state.state }}"
}
}
}
})
assert self.hass.states.all() == []
def test_invalid_sensor_does_not_create(self):
"""Test invalid sensor."""
assert sensor.setup(self.hass, {
'sensor': {
'platform': 'template',
'sensors': {
'test_template_sensor': 'invalid'
}
}
})
assert self.hass.states.all() == []
def test_no_sensors_does_not_create(self):
"""Test no sensors."""
assert sensor.setup(self.hass, {
'sensor': {
'platform': 'template'
}
})
assert self.hass.states.all() == []
def test_missing_template_does_not_create(self):
"""Test missing template."""
assert sensor.setup(self.hass, {
'sensor': {
'platform': 'template',
'sensors': {
'test_template_sensor': {
'not_value_template':
"{{ states.sensor.test_state.state }}"
}
}
}
})
assert self.hass.states.all() == []
|
mit
|
[
624,
1918,
511,
367,
314,
5458,
8778,
4298,
1041,
199,
646,
8846,
14,
4608,
14,
8956,
465,
8778,
199,
199,
504,
2295,
14,
2330,
492,
664,
63,
396,
63,
4219,
63,
7310,
421,
199,
533,
1379,
4231,
10160,
26,
272,
408,
774,
314,
5458,
8778,
1041,
339,
347,
3272,
63,
765,
8,
277,
12,
1083,
304,
267,
408,
8555,
7645,
370,
506,
1255,
1380,
2295,
787,
8239,
1041,
267,
291,
14,
5387,
275,
664,
63,
396,
63,
4219,
63,
7310,
342,
339,
347,
17558,
63,
765,
8,
277,
12,
1083,
304,
267,
408,
6293,
8137,
626,
1990,
8239,
1041,
267,
291,
14,
5387,
14,
2379,
342,
339,
347,
511,
63,
1160,
8,
277,
304,
267,
408,
774,
1978,
1041,
267,
702,
8778,
14,
2758,
8,
277,
14,
5387,
12,
469,
288,
283,
8956,
356,
469,
355,
283,
3246,
356,
283,
1160,
297,
355,
283,
22675,
356,
469,
490,
283,
396,
63,
1160,
63,
8956,
356,
469,
717,
283,
585,
63,
1160,
356,
1169,
298,
7940,
8448,
6363,
14,
8956,
14,
396,
63,
929,
14,
929,
3586,
2122,
490,
789,
355,
789,
288,
789,
267,
3828,
398,
1174,
275,
291,
14,
5387,
14,
4981,
14,
362,
360,
8956,
14,
396,
63,
1160,
63,
8956,
358,
267,
702,
1174,
14,
929,
508,
283,
7940,
1275,
7,
398,
291,
14,
5387,
14,
4981,
14,
409,
360,
8956,
14,
396,
63,
929,
297,
283,
25348,
358,
267,
291,
14,
5387,
14,
2293,
14,
1457,
63,
12587,
63,
4456,
342,
267,
1174,
275,
291,
14,
5387,
14,
4981,
14,
362,
360,
8956,
14,
396,
63,
1160,
63,
8956,
358,
267,
702,
1174,
14,
929,
508,
283,
7940,
28099,
3530,
339,
347,
511,
63,
1160,
63,
7093,
63,
705,
8,
277,
304,
267,
408,
774,
2388,
24615,
6302,
1125,
1041,
267,
702,
8778,
14,
2758,
8,
277,
14,
5387,
12,
469,
288,
283,
8956,
356,
469,
355,
283,
3246,
356,
283,
1160,
297,
355,
283,
22675,
356,
469,
490,
283,
396,
63,
1160,
63,
8956,
356,
469,
717,
283,
585,
63,
1160,
356,
1169,
22704,
340,
519,
9256,
2453,
3674,
2,
490,
789,
355,
789,
288,
789,
267,
3828,
398,
291,
14,
5387,
14,
4981,
14,
409,
360,
8956,
14,
396,
63,
929,
297,
283,
25348,
358,
267,
291,
14,
5387,
14,
2293,
14,
1457,
63,
12587,
63,
4456,
342,
267,
1174,
275,
291,
14,
5387,
14,
4981,
14,
362,
360,
8956,
14,
396,
63,
1160,
63,
8956,
358,
267,
702,
1174,
14,
929,
508,
283,
705,
7,
339,
347,
511,
63,
1160,
63,
3215,
63,
4752,
8,
277,
304,
267,
408,
774,
4124,
2225,
1978,
1041,
267,
702,
8778,
14,
2758,
8,
277,
14,
5387,
12,
469,
288,
283,
8956,
356,
469,
355,
283,
3246,
356,
283,
1160,
297,
355,
283,
22675,
356,
469,
490,
283,
396,
63,
1160,
63,
8956,
356,
469,
717,
283,
585,
63,
1160,
356,
717,
298,
7940,
8448,
6363,
14,
8956,
14,
396,
63,
929,
14,
2987,
14,
4752,
3586,
2122,
490,
789,
355,
789,
288,
789,
267,
3828,
398,
1174,
275,
291,
14,
5387,
14,
4981,
14,
362,
360,
8956,
14,
396,
63,
1160,
63,
8956,
358,
267,
702,
1174,
14,
929,
508,
283,
705,
7,
339,
347,
511,
63,
3197,
63,
354,
63,
9105,
63,
1397,
63,
981,
8,
277,
304,
267,
408,
774,
3866,
536,
1041,
267,
702,
8778,
14,
2758,
8,
277,
14,
5387,
12,
469,
288,
283,
8956,
356,
469,
355,
283,
3246,
356,
283,
1160,
297,
355,
283,
22675,
356,
469,
490,
283,
396,
29901,
8778,
356,
469,
717,
283,
585,
63,
1160,
356,
1169,
7370,
6363,
14,
8956,
14,
396,
63,
929,
14,
929,
7820,
490,
789,
355,
789,
288,
789,
267,
3828,
267,
702,
291,
14,
5387,
14,
4981,
14,
452,
342,
508,
942,
339,
347,
511,
63,
3197,
63,
8956,
63,
9105,
63,
1397,
63,
981,
8,
277,
304,
267,
408,
774,
3866,
8778,
1041,
267,
702,
8778,
14,
2758,
8,
277,
14,
5387,
12,
469,
288,
283,
8956,
356,
469,
355,
283,
3246,
356,
283,
1160,
297,
355,
283,
22675,
356,
469,
490,
283,
396,
63,
1160,
63,
8956,
356,
283,
3197,
7,
355,
789,
288,
789,
267,
3828,
267,
702,
291,
14,
5387,
14,
4981,
14,
452,
342,
508,
942,
339,
347,
511,
63,
889,
63,
22675,
63,
9105,
63,
1397,
63,
981,
8,
277,
304,
267,
408,
774,
949,
19678,
1041,
267,
702,
8778,
14,
2758,
8,
277,
14,
5387,
12,
469,
288,
283,
8956,
356,
469,
355,
283,
3246,
356,
283,
1160,
7,
288,
789,
267,
3828,
267,
702,
291,
14,
5387,
14,
4981,
14,
452,
342,
508,
942,
339,
347,
511,
63,
4752,
63,
1160,
63,
9105,
63,
1397,
63,
981,
8,
277,
304,
267,
408,
774,
4124,
1978,
1041,
267,
702,
8778,
14,
2758,
8,
277,
14,
5387,
12,
469,
288,
283,
8956,
356,
469,
355,
283,
3246,
356,
283,
1160,
297,
355,
283,
22675,
356,
469,
490,
283,
396,
63,
1160,
63,
8956,
356,
469,
717,
283,
1397,
63,
585,
63,
1160,
356,
1169,
7370,
6363,
14,
8956,
14,
396,
63,
929,
14,
929,
7820,
490,
789,
355,
789,
288,
789,
267,
3828,
267,
702,
291,
14,
5387,
14,
4981,
14,
452,
342,
508,
942,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1918,
511,
367,
314,
5458,
8778,
4298,
1041,
199,
646,
8846,
14,
4608,
14,
8956,
465,
8778,
199,
199,
504,
2295,
14,
2330,
492,
664,
63,
396,
63,
4219,
63,
7310,
421,
199,
533,
1379,
4231,
10160,
26,
272,
408,
774,
314,
5458,
8778,
1041,
339,
347,
3272,
63,
765,
8,
277,
12,
1083,
304,
267,
408,
8555,
7645,
370,
506,
1255,
1380,
2295,
787,
8239,
1041,
267,
291,
14,
5387,
275,
664,
63,
396,
63,
4219,
63,
7310,
342,
339,
347,
17558,
63,
765,
8,
277,
12,
1083,
304,
267,
408,
6293,
8137,
626,
1990,
8239,
1041,
267,
291,
14,
5387,
14,
2379,
342,
339,
347,
511,
63,
1160,
8,
277,
304,
267,
408,
774,
1978,
1041,
267,
702,
8778,
14,
2758,
8,
277,
14,
5387,
12,
469,
288,
283,
8956,
356,
469,
355,
283,
3246,
356,
283,
1160,
297,
355,
283,
22675,
356,
469,
490,
283,
396,
63,
1160,
63,
8956,
356,
469,
717,
283,
585,
63,
1160,
356,
1169,
298,
7940,
8448,
6363,
14,
8956,
14,
396,
63,
929,
14,
929,
3586,
2122,
490,
789,
355,
789,
288,
789,
267,
3828,
398,
1174,
275,
291,
14,
5387,
14,
4981,
14,
362,
360,
8956,
14,
396,
63,
1160,
63,
8956,
358,
267,
702,
1174,
14,
929,
508,
283,
7940,
1275,
7,
398,
291,
14,
5387,
14,
4981,
14,
409,
360,
8956,
14,
396,
63,
929,
297,
283,
25348,
358,
267,
291,
14,
5387,
14,
2293,
14,
1457,
63,
12587,
63,
4456,
342,
267,
1174,
275,
291,
14,
5387,
14,
4981,
14,
362,
360,
8956,
14,
396,
63,
1160,
63,
8956,
358,
267,
702,
1174,
14,
929,
508,
283,
7940,
28099,
3530,
339,
347,
511,
63,
1160,
63,
7093,
63,
705,
8,
277,
304,
267,
408,
774,
2388,
24615,
6302,
1125,
1041,
267,
702,
8778,
14,
2758,
8,
277,
14,
5387,
12,
469,
288,
283,
8956,
356,
469,
355,
283,
3246,
356,
283,
1160,
297,
355,
283,
22675,
356,
469,
490,
283,
396,
63,
1160,
63,
8956,
356,
469,
717,
283,
585,
63,
1160,
356,
1169,
22704,
340,
519,
9256,
2453,
3674,
2,
490,
789,
355,
789,
288,
789,
267,
3828,
398,
291,
14,
5387,
14,
4981,
14,
409,
360,
8956,
14,
396,
63,
929,
297,
283,
25348,
358,
267,
291,
14,
5387,
14,
2293,
14,
1457,
63,
12587,
63,
4456,
342,
267,
1174,
275,
291,
14,
5387,
14,
4981,
14,
362,
360,
8956,
14,
396,
63,
1160,
63,
8956,
358,
267,
702,
1174,
14,
929,
508,
283,
705,
7,
339,
347,
511,
63,
1160,
63,
3215,
63,
4752,
8,
277,
304,
267,
408,
774,
4124,
2225,
1978,
1041,
267,
702,
8778,
14,
2758,
8,
277,
14,
5387,
12,
469,
288,
283,
8956,
356,
469,
355,
283,
3246,
356,
283,
1160,
297,
355,
283,
22675,
356,
469,
490,
283,
396,
63,
1160,
63,
8956,
356,
469,
717,
283,
585,
63,
1160,
356,
717,
298,
7940,
8448,
6363,
14,
8956,
14,
396,
63,
929,
14,
2987,
14,
4752,
3586,
2122,
490,
789,
355,
789,
288,
789,
267,
3828,
398,
1174,
275,
291,
14,
5387,
14,
4981,
14,
362,
360,
8956,
14,
396,
63,
1160,
63,
8956,
358,
267,
702,
1174,
14,
929,
508,
283,
705,
7,
339,
347,
511,
63,
3197,
63,
354,
63,
9105,
63,
1397,
63,
981,
8,
277,
304,
267,
408,
774,
3866,
536,
1041,
267,
702,
8778,
14,
2758,
8,
277,
14,
5387,
12,
469,
288,
283,
8956,
356,
469,
355,
283,
3246,
356,
283,
1160,
297,
355,
283,
22675,
356,
469,
490,
283,
396,
29901,
8778,
356,
469,
717,
283,
585,
63,
1160,
356,
1169,
7370,
6363,
14,
8956,
14,
396,
63,
929,
14,
929,
7820,
490,
789,
355,
789,
288,
789,
267,
3828,
267,
702,
291,
14,
5387,
14,
4981,
14,
452,
342,
508,
942,
339,
347,
511,
63,
3197,
63,
8956,
63,
9105,
63,
1397,
63,
981,
8,
277,
304,
267,
408,
774,
3866,
8778,
1041,
267,
702,
8778,
14,
2758,
8,
277,
14,
5387,
12,
469,
288,
283,
8956,
356,
469,
355,
283,
3246,
356,
283,
1160,
297,
355,
283,
22675,
356,
469,
490,
283,
396,
63,
1160,
63,
8956,
356,
283,
3197,
7,
355,
789,
288,
789,
267,
3828,
267,
702,
291,
14,
5387,
14,
4981,
14,
452,
342,
508,
942,
339,
347,
511,
63,
889,
63,
22675,
63,
9105,
63,
1397,
63,
981,
8,
277,
304,
267,
408,
774,
949,
19678,
1041,
267,
702,
8778,
14,
2758,
8,
277,
14,
5387,
12,
469,
288,
283,
8956,
356,
469,
355,
283,
3246,
356,
283,
1160,
7,
288,
789,
267,
3828,
267,
702,
291,
14,
5387,
14,
4981,
14,
452,
342,
508,
942,
339,
347,
511,
63,
4752,
63,
1160,
63,
9105,
63,
1397,
63,
981,
8,
277,
304,
267,
408,
774,
4124,
1978,
1041,
267,
702,
8778,
14,
2758,
8,
277,
14,
5387,
12,
469,
288,
283,
8956,
356,
469,
355,
283,
3246,
356,
283,
1160,
297,
355,
283,
22675,
356,
469,
490,
283,
396,
63,
1160,
63,
8956,
356,
469,
717,
283,
1397,
63,
585,
63,
1160,
356,
1169,
7370,
6363,
14,
8956,
14,
396,
63,
929,
14,
929,
7820,
490,
789,
355,
789,
288,
789,
267,
3828,
267,
702,
291,
14,
5387,
14,
4981,
14,
452,
342,
508,
942,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
JWarmenhoven/seaborn
|
seaborn/external/six.py
|
1
|
22856
|
"""Utilities for writing code that runs on Python 2 and 3"""
# Copyright (c) 2010-2014 Benjamin Peterson
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
import operator
import sys
import types
__author__ = "Benjamin Peterson <benjamin@python.org>"
__version__ = "1.5.2"
# Useful for very coarse version differentiation.
PY2 = sys.version_info[0] == 2
PY3 = sys.version_info[0] == 3
if PY3:
string_types = str,
integer_types = int,
class_types = type,
text_type = str
binary_type = bytes
MAXSIZE = sys.maxsize
else:
string_types = basestring,
integer_types = (int, long)
class_types = (type, types.ClassType)
text_type = unicode
binary_type = str
if sys.platform.startswith("java"):
# Jython always uses 32 bits.
MAXSIZE = int((1 << 31) - 1)
else:
# It's possible to have sizeof(long) != sizeof(Py_ssize_t).
class X(object):
def __len__(self):
return 1 << 31
try:
len(X())
except OverflowError:
# 32-bit
MAXSIZE = int((1 << 31) - 1)
else:
# 64-bit
MAXSIZE = int((1 << 63) - 1)
del X
def _add_doc(func, doc):
"""Add documentation to a function."""
func.__doc__ = doc
def _import_module(name):
"""Import module, returning the module after the last dot."""
__import__(name)
return sys.modules[name]
class _LazyDescr(object):
def __init__(self, name):
self.name = name
def __get__(self, obj, tp):
result = self._resolve()
setattr(obj, self.name, result) # Invokes __set__.
# This is a bit ugly, but it avoids running this again.
delattr(obj.__class__, self.name)
return result
class MovedModule(_LazyDescr):
def __init__(self, name, old, new=None):
super(MovedModule, self).__init__(name)
if PY3:
if new is None:
new = name
self.mod = new
else:
self.mod = old
def _resolve(self):
return _import_module(self.mod)
def __getattr__(self, attr):
# Hack around the Django autoreloader. The reloader tries to get
# __file__ or __name__ of every module in sys.modules. This doesn't work
# well if this MovedModule is for an module that is unavailable on this
# machine (like winreg on Unix systems). Thus, we pretend __file__ and
# __name__ don't exist if the module hasn't been loaded yet. See issues
# #51 and #53.
if attr in ("__file__", "__name__") and self.mod not in sys.modules:
raise AttributeError
_module = self._resolve()
value = getattr(_module, attr)
setattr(self, attr, value)
return value
class _LazyModule(types.ModuleType):
def __init__(self, name):
super(_LazyModule, self).__init__(name)
self.__doc__ = self.__class__.__doc__
def __dir__(self):
attrs = ["__doc__", "__name__"]
attrs += [attr.name for attr in self._moved_attributes]
return attrs
# Subclasses should override this
_moved_attributes = []
class MovedAttribute(_LazyDescr):
def __init__(self, name, old_mod, new_mod, old_attr=None, new_attr=None):
super(MovedAttribute, self).__init__(name)
if PY3:
if new_mod is None:
new_mod = name
self.mod = new_mod
if new_attr is None:
if old_attr is None:
new_attr = name
else:
new_attr = old_attr
self.attr = new_attr
else:
self.mod = old_mod
if old_attr is None:
old_attr = name
self.attr = old_attr
def _resolve(self):
module = _import_module(self.mod)
return getattr(module, self.attr)
class _MovedItems(_LazyModule):
"""Lazy loading of moved objects"""
_moved_attributes = [
MovedAttribute("cStringIO", "cStringIO", "io", "StringIO"),
MovedAttribute("filter", "itertools", "builtins", "ifilter", "filter"),
MovedAttribute("filterfalse", "itertools", "itertools", "ifilterfalse", "filterfalse"),
MovedAttribute("input", "__builtin__", "builtins", "raw_input", "input"),
MovedAttribute("map", "itertools", "builtins", "imap", "map"),
MovedAttribute("range", "__builtin__", "builtins", "xrange", "range"),
MovedAttribute("reload_module", "__builtin__", "imp", "reload"),
MovedAttribute("reduce", "__builtin__", "functools"),
MovedAttribute("StringIO", "StringIO", "io"),
MovedAttribute("UserString", "UserString", "collections"),
MovedAttribute("xrange", "__builtin__", "builtins", "xrange", "range"),
MovedAttribute("zip", "itertools", "builtins", "izip", "zip"),
MovedAttribute("zip_longest", "itertools", "itertools", "izip_longest", "zip_longest"),
MovedModule("builtins", "__builtin__"),
MovedModule("configparser", "ConfigParser"),
MovedModule("copyreg", "copy_reg"),
MovedModule("dbm_gnu", "gdbm", "dbm.gnu"),
MovedModule("http_cookiejar", "cookielib", "http.cookiejar"),
MovedModule("http_cookies", "Cookie", "http.cookies"),
MovedModule("html_entities", "htmlentitydefs", "html.entities"),
MovedModule("html_parser", "HTMLParser", "html.parser"),
MovedModule("http_client", "httplib", "http.client"),
MovedModule("email_mime_multipart", "email.MIMEMultipart", "email.mime.multipart"),
MovedModule("email_mime_text", "email.MIMEText", "email.mime.text"),
MovedModule("email_mime_base", "email.MIMEBase", "email.mime.base"),
MovedModule("BaseHTTPServer", "BaseHTTPServer", "http.server"),
MovedModule("CGIHTTPServer", "CGIHTTPServer", "http.server"),
MovedModule("SimpleHTTPServer", "SimpleHTTPServer", "http.server"),
MovedModule("cPickle", "cPickle", "pickle"),
MovedModule("queue", "Queue"),
MovedModule("reprlib", "repr"),
MovedModule("socketserver", "SocketServer"),
MovedModule("_thread", "thread", "_thread"),
MovedModule("tkinter", "Tkinter"),
MovedModule("tkinter_dialog", "Dialog", "tkinter.dialog"),
MovedModule("tkinter_filedialog", "FileDialog", "tkinter.filedialog"),
MovedModule("tkinter_scrolledtext", "ScrolledText", "tkinter.scrolledtext"),
MovedModule("tkinter_simpledialog", "SimpleDialog", "tkinter.simpledialog"),
MovedModule("tkinter_tix", "Tix", "tkinter.tix"),
MovedModule("tkinter_ttk", "ttk", "tkinter.ttk"),
MovedModule("tkinter_constants", "Tkconstants", "tkinter.constants"),
MovedModule("tkinter_dnd", "Tkdnd", "tkinter.dnd"),
MovedModule("tkinter_colorchooser", "tkColorChooser",
"tkinter.colorchooser"),
MovedModule("tkinter_commondialog", "tkCommonDialog",
"tkinter.commondialog"),
MovedModule("tkinter_tkfiledialog", "tkFileDialog", "tkinter.filedialog"),
MovedModule("tkinter_font", "tkFont", "tkinter.font"),
MovedModule("tkinter_messagebox", "tkMessageBox", "tkinter.messagebox"),
MovedModule("tkinter_tksimpledialog", "tkSimpleDialog",
"tkinter.simpledialog"),
MovedModule("urllib_parse", __name__ + ".moves.urllib_parse", "urllib.parse"),
MovedModule("urllib_error", __name__ + ".moves.urllib_error", "urllib.error"),
MovedModule("urllib", __name__ + ".moves.urllib", __name__ + ".moves.urllib"),
MovedModule("urllib_robotparser", "robotparser", "urllib.robotparser"),
MovedModule("xmlrpc_client", "xmlrpclib", "xmlrpc.client"),
MovedModule("winreg", "_winreg"),
]
for attr in _moved_attributes:
setattr(_MovedItems, attr.name, attr)
if isinstance(attr, MovedModule):
sys.modules[__name__ + ".moves." + attr.name] = attr
del attr
_MovedItems._moved_attributes = _moved_attributes
moves = sys.modules[__name__ + ".moves"] = _MovedItems(__name__ + ".moves")
class Module_six_moves_urllib_parse(_LazyModule):
"""Lazy loading of moved objects in six.moves.urllib_parse"""
_urllib_parse_moved_attributes = [
MovedAttribute("ParseResult", "urlparse", "urllib.parse"),
MovedAttribute("parse_qs", "urlparse", "urllib.parse"),
MovedAttribute("parse_qsl", "urlparse", "urllib.parse"),
MovedAttribute("urldefrag", "urlparse", "urllib.parse"),
MovedAttribute("urljoin", "urlparse", "urllib.parse"),
MovedAttribute("urlparse", "urlparse", "urllib.parse"),
MovedAttribute("urlsplit", "urlparse", "urllib.parse"),
MovedAttribute("urlunparse", "urlparse", "urllib.parse"),
MovedAttribute("urlunsplit", "urlparse", "urllib.parse"),
MovedAttribute("quote", "urllib", "urllib.parse"),
MovedAttribute("quote_plus", "urllib", "urllib.parse"),
MovedAttribute("unquote", "urllib", "urllib.parse"),
MovedAttribute("unquote_plus", "urllib", "urllib.parse"),
MovedAttribute("urlencode", "urllib", "urllib.parse"),
]
for attr in _urllib_parse_moved_attributes:
setattr(Module_six_moves_urllib_parse, attr.name, attr)
del attr
Module_six_moves_urllib_parse._moved_attributes = _urllib_parse_moved_attributes
sys.modules[__name__ + ".moves.urllib_parse"] = sys.modules[__name__ + ".moves.urllib.parse"] = Module_six_moves_urllib_parse(__name__ + ".moves.urllib_parse")
class Module_six_moves_urllib_error(_LazyModule):
"""Lazy loading of moved objects in six.moves.urllib_error"""
_urllib_error_moved_attributes = [
MovedAttribute("URLError", "urllib2", "urllib.error"),
MovedAttribute("HTTPError", "urllib2", "urllib.error"),
MovedAttribute("ContentTooShortError", "urllib", "urllib.error"),
]
for attr in _urllib_error_moved_attributes:
setattr(Module_six_moves_urllib_error, attr.name, attr)
del attr
Module_six_moves_urllib_error._moved_attributes = _urllib_error_moved_attributes
sys.modules[__name__ + ".moves.urllib_error"] = sys.modules[__name__ + ".moves.urllib.error"] = Module_six_moves_urllib_error(__name__ + ".moves.urllib.error")
class Module_six_moves_urllib_request(_LazyModule):
"""Lazy loading of moved objects in six.moves.urllib_request"""
_urllib_request_moved_attributes = [
MovedAttribute("urlopen", "urllib2", "urllib.request"),
MovedAttribute("install_opener", "urllib2", "urllib.request"),
MovedAttribute("build_opener", "urllib2", "urllib.request"),
MovedAttribute("pathname2url", "urllib", "urllib.request"),
MovedAttribute("url2pathname", "urllib", "urllib.request"),
MovedAttribute("getproxies", "urllib", "urllib.request"),
MovedAttribute("Request", "urllib2", "urllib.request"),
MovedAttribute("OpenerDirector", "urllib2", "urllib.request"),
MovedAttribute("HTTPDefaultErrorHandler", "urllib2", "urllib.request"),
MovedAttribute("HTTPRedirectHandler", "urllib2", "urllib.request"),
MovedAttribute("HTTPCookieProcessor", "urllib2", "urllib.request"),
MovedAttribute("ProxyHandler", "urllib2", "urllib.request"),
MovedAttribute("BaseHandler", "urllib2", "urllib.request"),
MovedAttribute("HTTPPasswordMgr", "urllib2", "urllib.request"),
MovedAttribute("HTTPPasswordMgrWithDefaultRealm", "urllib2", "urllib.request"),
MovedAttribute("AbstractBasicAuthHandler", "urllib2", "urllib.request"),
MovedAttribute("HTTPBasicAuthHandler", "urllib2", "urllib.request"),
MovedAttribute("ProxyBasicAuthHandler", "urllib2", "urllib.request"),
MovedAttribute("AbstractDigestAuthHandler", "urllib2", "urllib.request"),
MovedAttribute("HTTPDigestAuthHandler", "urllib2", "urllib.request"),
MovedAttribute("ProxyDigestAuthHandler", "urllib2", "urllib.request"),
MovedAttribute("HTTPHandler", "urllib2", "urllib.request"),
MovedAttribute("HTTPSHandler", "urllib2", "urllib.request"),
MovedAttribute("FileHandler", "urllib2", "urllib.request"),
MovedAttribute("FTPHandler", "urllib2", "urllib.request"),
MovedAttribute("CacheFTPHandler", "urllib2", "urllib.request"),
MovedAttribute("UnknownHandler", "urllib2", "urllib.request"),
MovedAttribute("HTTPErrorProcessor", "urllib2", "urllib.request"),
MovedAttribute("urlretrieve", "urllib", "urllib.request"),
MovedAttribute("urlcleanup", "urllib", "urllib.request"),
MovedAttribute("URLopener", "urllib", "urllib.request"),
MovedAttribute("FancyURLopener", "urllib", "urllib.request"),
MovedAttribute("proxy_bypass", "urllib", "urllib.request"),
]
for attr in _urllib_request_moved_attributes:
setattr(Module_six_moves_urllib_request, attr.name, attr)
del attr
Module_six_moves_urllib_request._moved_attributes = _urllib_request_moved_attributes
sys.modules[__name__ + ".moves.urllib_request"] = sys.modules[__name__ + ".moves.urllib.request"] = Module_six_moves_urllib_request(__name__ + ".moves.urllib.request")
class Module_six_moves_urllib_response(_LazyModule):
"""Lazy loading of moved objects in six.moves.urllib_response"""
_urllib_response_moved_attributes = [
MovedAttribute("addbase", "urllib", "urllib.response"),
MovedAttribute("addclosehook", "urllib", "urllib.response"),
MovedAttribute("addinfo", "urllib", "urllib.response"),
MovedAttribute("addinfourl", "urllib", "urllib.response"),
]
for attr in _urllib_response_moved_attributes:
setattr(Module_six_moves_urllib_response, attr.name, attr)
del attr
Module_six_moves_urllib_response._moved_attributes = _urllib_response_moved_attributes
sys.modules[__name__ + ".moves.urllib_response"] = sys.modules[__name__ + ".moves.urllib.response"] = Module_six_moves_urllib_response(__name__ + ".moves.urllib.response")
class Module_six_moves_urllib_robotparser(_LazyModule):
"""Lazy loading of moved objects in six.moves.urllib_robotparser"""
_urllib_robotparser_moved_attributes = [
MovedAttribute("RobotFileParser", "robotparser", "urllib.robotparser"),
]
for attr in _urllib_robotparser_moved_attributes:
setattr(Module_six_moves_urllib_robotparser, attr.name, attr)
del attr
Module_six_moves_urllib_robotparser._moved_attributes = _urllib_robotparser_moved_attributes
sys.modules[__name__ + ".moves.urllib_robotparser"] = sys.modules[__name__ + ".moves.urllib.robotparser"] = Module_six_moves_urllib_robotparser(__name__ + ".moves.urllib.robotparser")
class Module_six_moves_urllib(types.ModuleType):
"""Create a six.moves.urllib namespace that resembles the Python 3 namespace"""
parse = sys.modules[__name__ + ".moves.urllib_parse"]
error = sys.modules[__name__ + ".moves.urllib_error"]
request = sys.modules[__name__ + ".moves.urllib_request"]
response = sys.modules[__name__ + ".moves.urllib_response"]
robotparser = sys.modules[__name__ + ".moves.urllib_robotparser"]
def __dir__(self):
return ['parse', 'error', 'request', 'response', 'robotparser']
sys.modules[__name__ + ".moves.urllib"] = Module_six_moves_urllib(__name__ + ".moves.urllib")
def add_move(move):
"""Add an item to six.moves."""
setattr(_MovedItems, move.name, move)
def remove_move(name):
"""Remove item from six.moves."""
try:
delattr(_MovedItems, name)
except AttributeError:
try:
del moves.__dict__[name]
except KeyError:
raise AttributeError("no such move, %r" % (name,))
if PY3:
_meth_func = "__func__"
_meth_self = "__self__"
_func_closure = "__closure__"
_func_code = "__code__"
_func_defaults = "__defaults__"
_func_globals = "__globals__"
_iterkeys = "keys"
_itervalues = "values"
_iteritems = "items"
_iterlists = "lists"
else:
_meth_func = "im_func"
_meth_self = "im_self"
_func_closure = "func_closure"
_func_code = "func_code"
_func_defaults = "func_defaults"
_func_globals = "func_globals"
_iterkeys = "iterkeys"
_itervalues = "itervalues"
_iteritems = "iteritems"
_iterlists = "iterlists"
try:
advance_iterator = next
except NameError:
def advance_iterator(it):
return next(it)
next = advance_iterator
try:
callable = callable
except NameError:
def callable(obj):
return any("__call__" in klass.__dict__ for klass in type(obj).__mro__)
if PY3:
def get_unbound_function(unbound):
return unbound
create_bound_method = types.MethodType
Iterator = object
else:
def get_unbound_function(unbound):
return unbound.im_func
def create_bound_method(func, obj):
return types.MethodType(func, obj, obj.__class__)
class Iterator(object):
def next(self):
return type(self).__next__(self)
callable = callable
_add_doc(get_unbound_function,
"""Get the function out of a possibly unbound function""")
get_method_function = operator.attrgetter(_meth_func)
get_method_self = operator.attrgetter(_meth_self)
get_function_closure = operator.attrgetter(_func_closure)
get_function_code = operator.attrgetter(_func_code)
get_function_defaults = operator.attrgetter(_func_defaults)
get_function_globals = operator.attrgetter(_func_globals)
def iterkeys(d, **kw):
"""Return an iterator over the keys of a dictionary."""
return iter(getattr(d, _iterkeys)(**kw))
def itervalues(d, **kw):
"""Return an iterator over the values of a dictionary."""
return iter(getattr(d, _itervalues)(**kw))
def iteritems(d, **kw):
"""Return an iterator over the (key, value) pairs of a dictionary."""
return iter(getattr(d, _iteritems)(**kw))
def iterlists(d, **kw):
"""Return an iterator over the (key, [values]) pairs of a dictionary."""
return iter(getattr(d, _iterlists)(**kw))
if PY3:
def b(s):
return s.encode("latin-1")
def u(s):
return s
unichr = chr
if sys.version_info[1] <= 1:
def int2byte(i):
return bytes((i,))
else:
# This is about 2x faster than the implementation above on 3.2+
int2byte = operator.methodcaller("to_bytes", 1, "big")
byte2int = operator.itemgetter(0)
indexbytes = operator.getitem
iterbytes = iter
import io
StringIO = io.StringIO
BytesIO = io.BytesIO
else:
def b(s):
return s
# Workaround for standalone backslash
def u(s):
return unicode(s.replace(r'\\', r'\\\\'), "unicode_escape")
unichr = unichr
int2byte = chr
def byte2int(bs):
return ord(bs[0])
def indexbytes(buf, i):
return ord(buf[i])
def iterbytes(buf):
return (ord(byte) for byte in buf)
import StringIO
StringIO = BytesIO = StringIO.StringIO
_add_doc(b, """Byte literal""")
_add_doc(u, """Text literal""")
if PY3:
exec_ = getattr(moves.builtins, "exec")
def reraise(tp, value, tb=None):
if value.__traceback__ is not tb:
raise value.with_traceback(tb)
raise value
else:
def exec_(_code_, _globs_=None, _locs_=None):
"""Execute code in a namespace."""
if _globs_ is None:
frame = sys._getframe(1)
_globs_ = frame.f_globals
if _locs_ is None:
_locs_ = frame.f_locals
del frame
elif _locs_ is None:
_locs_ = _globs_
exec("""exec _code_ in _globs_, _locs_""")
exec_("""def reraise(tp, value, tb=None):
raise tp, value, tb
""")
print_ = getattr(moves.builtins, "print", None)
if print_ is None:
def print_(*args, **kwargs):
"""The new-style print function for Python 2.4 and 2.5."""
fp = kwargs.pop("file", sys.stdout)
if fp is None:
return
def write(data):
if not isinstance(data, basestring):
data = str(data)
# If the file has an encoding, encode unicode with it.
if (isinstance(fp, file) and
isinstance(data, unicode) and
fp.encoding is not None):
errors = getattr(fp, "errors", None)
if errors is None:
errors = "strict"
data = data.encode(fp.encoding, errors)
fp.write(data)
want_unicode = False
sep = kwargs.pop("sep", None)
if sep is not None:
if isinstance(sep, unicode):
want_unicode = True
elif not isinstance(sep, str):
raise TypeError("sep must be None or a string")
end = kwargs.pop("end", None)
if end is not None:
if isinstance(end, unicode):
want_unicode = True
elif not isinstance(end, str):
raise TypeError("end must be None or a string")
if kwargs:
raise TypeError("invalid keyword arguments to print()")
if not want_unicode:
for arg in args:
if isinstance(arg, unicode):
want_unicode = True
break
if want_unicode:
newline = unicode("\n")
space = unicode(" ")
else:
newline = "\n"
space = " "
if sep is None:
sep = space
if end is None:
end = newline
for i, arg in enumerate(args):
if i:
write(sep)
write(arg)
write(end)
_add_doc(reraise, """Reraise an exception.""")
def with_metaclass(meta, *bases):
"""Create a base class with a metaclass."""
return meta("NewBase", bases, {})
def add_metaclass(metaclass):
"""Class decorator for creating a class with a metaclass."""
def wrapper(cls):
orig_vars = cls.__dict__.copy()
orig_vars.pop('__dict__', None)
orig_vars.pop('__weakref__', None)
slots = orig_vars.get('__slots__')
if slots is not None:
if isinstance(slots, str):
slots = [slots]
for slots_var in slots:
orig_vars.pop(slots_var)
return metaclass(cls.__name__, cls.__bases__, orig_vars)
return wrapper
|
bsd-3-clause
|
[
624,
22905,
367,
3575,
1233,
626,
7858,
641,
2018,
499,
436,
650,
624,
199,
199,
3,
1898,
334,
67,
9,
7129,
13,
7280,
26844,
16997,
262,
22912,
834,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
1331,
199,
3,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
298,
10337,
1288,
370,
7962,
199,
3,
315,
314,
2290,
1928,
10588,
12,
5893,
1928,
12305,
314,
4481,
199,
3,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
11207,
12,
13473,
12,
436,
15,
269,
12743,
199,
3,
6866,
402,
314,
2290,
12,
436,
370,
11291,
12103,
370,
12676,
314,
2290,
365,
199,
3,
13985,
370,
886,
880,
12,
5420,
370,
314,
2569,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
315,
1006,
199,
3,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
1549,
199,
3,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
3169,
12,
199,
3,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
7000,
2334,
199,
3,
10610,
1549,
5877,
8164,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
199,
3,
5603,
12,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
199,
3,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
2334,
199,
3,
4141,
14,
199,
199,
646,
4182,
199,
646,
984,
199,
646,
2943,
199,
199,
363,
2502,
363,
275,
298,
31231,
16997,
262,
22912,
834,
665,
18486,
16997,
262,
32,
1548,
14,
1308,
4335,
199,
363,
1023,
363,
275,
298,
17,
14,
21,
14,
18,
2,
421,
199,
3,
18491,
367,
7437,
512,
30672,
1015,
26796,
425,
14,
199,
4521,
18,
275,
984,
14,
1023,
63,
815,
59,
16,
61,
508,
499,
199,
4521,
19,
275,
984,
14,
1023,
63,
815,
59,
16,
61,
508,
650,
199,
199,
692,
7843,
19,
26,
272,
1059,
63,
1313,
275,
620,
12,
272,
3000,
63,
1313,
275,
1109,
12,
272,
1021,
63,
1313,
275,
730,
12,
272,
1318,
63,
466,
275,
620,
272,
3366,
63,
466,
275,
2783,
339,
9141,
4305,
275,
984,
14,
13634,
199,
2836,
26,
272,
1059,
63,
1313,
275,
7116,
12,
272,
3000,
63,
1313,
275,
334,
442,
12,
1846,
9,
272,
1021,
63,
1313,
275,
334,
466,
12,
2943,
14,
31165,
9,
272,
1318,
63,
466,
275,
2649,
272,
3366,
63,
466,
275,
620,
339,
340,
984,
14,
3246,
14,
2460,
480,
6138,
2349,
267,
327,
25333,
3544,
4440,
4337,
5821,
14,
267,
9141,
4305,
275,
1109,
1332,
17,
5213,
7105,
9,
446,
413,
9,
272,
587,
26,
267,
327,
2779,
1159,
3962,
370,
1172,
13855,
8,
2809,
9,
1137,
13855,
8,
2713,
63,
30104,
63,
84,
680,
267,
1021,
1323,
8,
785,
304,
288,
347,
636,
552,
721,
277,
304,
355,
372,
413,
5213,
7105,
267,
862,
26,
288,
822,
8,
56,
1012,
267,
871,
23870,
26,
288,
327,
4337,
13,
2075,
288,
9141,
4305,
275,
1109,
1332,
17,
5213,
7105,
9,
446,
413,
9,
267,
587,
26,
288,
327,
5049,
13,
2075,
288,
9141,
4305,
275,
1109,
1332,
17,
5213,
13668,
9,
446,
413,
9,
267,
2150,
1323,
421,
199,
318,
485,
525,
63,
1301,
8,
1532,
12,
1382,
304,
272,
408,
1123,
3794,
370,
282,
805,
1041,
272,
2562,
855,
1301,
363,
275,
1382,
421,
199,
318,
485,
646,
63,
578,
8,
354,
304,
272,
408,
6295,
859,
12,
8152,
314,
859,
2410,
314,
2061,
6308,
1041,
272,
636,
646,
721,
354,
9,
272,
372,
984,
14,
3112,
59,
354,
61,
421,
199,
533,
485,
14269,
28782,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
536,
304,
267,
291,
14,
354,
275,
536,
339,
347,
636,
362,
721,
277,
12,
1559,
12,
9253,
304,
267,
754,
275,
291,
423,
6983,
342,
267,
5371,
8,
1113,
12,
291,
14,
354,
12,
754,
9,
327,
30110,
22652,
636,
409,
4343,
267,
327,
961,
365,
282,
4546,
23761,
12,
1325,
652,
23674,
3879,
642,
4020,
14,
267,
24358,
8,
1113,
855,
533,
3108,
291,
14,
354,
9,
267,
372,
754,
421,
199,
533,
11147,
1547,
14269,
28782,
304,
339,
347,
636,
826,
721,
277,
12,
536,
12,
2269,
12,
892,
29,
403,
304,
267,
1613,
8,
20774,
2377,
12,
291,
2843,
826,
721,
354,
9,
267,
340,
7843,
19,
26,
288,
340,
892,
365,
488,
26,
355,
892,
275,
536,
288,
291,
14,
1494,
275,
892,
267,
587,
26,
288,
291,
14,
1494,
275,
2269,
339,
347,
485,
6983,
8,
277,
304,
267,
372,
485,
646,
63,
578,
8,
277,
14,
1494,
9,
339,
347,
636,
5675,
721,
277,
12,
1921,
304,
267,
327,
30802,
6818,
314,
5634,
28589,
3422,
14,
710,
295,
3422,
11275,
370,
664,
267,
327,
636,
493,
363,
503,
636,
354,
363,
402,
4036,
859,
315,
984,
14,
3112,
14,
961,
3181,
1133,
1736,
267,
327,
5521,
340,
642,
11147,
365,
367,
376,
859,
626,
365,
18735,
641,
642,
267,
327,
6844,
334,
2930,
30748,
641,
13074,
10460,
680,
20227,
12,
781,
27830,
636,
493,
363,
436,
267,
327,
636,
354,
363,
2793,
1133,
2187,
340,
314,
859,
18699,
1133,
2757,
6511,
5966,
14,
1666,
10876,
267,
327,
327,
2869,
436,
327,
2481,
14,
267,
340,
1921,
315,
1689,
363,
493,
13915,
4396,
354,
18617,
436,
291,
14,
1494,
440,
315,
984,
14,
3112,
26,
288,
746,
4281,
267,
485,
578,
275,
291,
423,
6983,
342,
267,
574,
275,
2519,
1547,
578,
12,
1921,
9,
267,
5371,
8,
277,
12,
1921,
12,
574,
9,
267,
372,
574,
421,
199,
533,
485,
14269,
2377,
8,
1313,
14,
21820,
304,
339,
347,
636,
826,
721,
277,
12,
536,
304,
267,
1613,
1547,
14269,
2377,
12,
291,
2843,
826,
721,
354,
9,
267,
291,
855,
1301,
363,
275,
291,
855,
533,
4914,
1301,
363,
339,
347,
636,
694,
721,
277,
304,
267,
3290,
275,
2097,
363,
1301,
13915,
4396,
354,
363,
937,
267,
3290,
847,
359,
962,
14,
354,
367,
1921,
315,
291,
423,
3539
] |
[
22905,
367,
3575,
1233,
626,
7858,
641,
2018,
499,
436,
650,
624,
199,
199,
3,
1898,
334,
67,
9,
7129,
13,
7280,
26844,
16997,
262,
22912,
834,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
1331,
199,
3,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
298,
10337,
1288,
370,
7962,
199,
3,
315,
314,
2290,
1928,
10588,
12,
5893,
1928,
12305,
314,
4481,
199,
3,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
11207,
12,
13473,
12,
436,
15,
269,
12743,
199,
3,
6866,
402,
314,
2290,
12,
436,
370,
11291,
12103,
370,
12676,
314,
2290,
365,
199,
3,
13985,
370,
886,
880,
12,
5420,
370,
314,
2569,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
315,
1006,
199,
3,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
1549,
199,
3,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
3169,
12,
199,
3,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
7000,
2334,
199,
3,
10610,
1549,
5877,
8164,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
199,
3,
5603,
12,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
199,
3,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
2334,
199,
3,
4141,
14,
199,
199,
646,
4182,
199,
646,
984,
199,
646,
2943,
199,
199,
363,
2502,
363,
275,
298,
31231,
16997,
262,
22912,
834,
665,
18486,
16997,
262,
32,
1548,
14,
1308,
4335,
199,
363,
1023,
363,
275,
298,
17,
14,
21,
14,
18,
2,
421,
199,
3,
18491,
367,
7437,
512,
30672,
1015,
26796,
425,
14,
199,
4521,
18,
275,
984,
14,
1023,
63,
815,
59,
16,
61,
508,
499,
199,
4521,
19,
275,
984,
14,
1023,
63,
815,
59,
16,
61,
508,
650,
199,
199,
692,
7843,
19,
26,
272,
1059,
63,
1313,
275,
620,
12,
272,
3000,
63,
1313,
275,
1109,
12,
272,
1021,
63,
1313,
275,
730,
12,
272,
1318,
63,
466,
275,
620,
272,
3366,
63,
466,
275,
2783,
339,
9141,
4305,
275,
984,
14,
13634,
199,
2836,
26,
272,
1059,
63,
1313,
275,
7116,
12,
272,
3000,
63,
1313,
275,
334,
442,
12,
1846,
9,
272,
1021,
63,
1313,
275,
334,
466,
12,
2943,
14,
31165,
9,
272,
1318,
63,
466,
275,
2649,
272,
3366,
63,
466,
275,
620,
339,
340,
984,
14,
3246,
14,
2460,
480,
6138,
2349,
267,
327,
25333,
3544,
4440,
4337,
5821,
14,
267,
9141,
4305,
275,
1109,
1332,
17,
5213,
7105,
9,
446,
413,
9,
272,
587,
26,
267,
327,
2779,
1159,
3962,
370,
1172,
13855,
8,
2809,
9,
1137,
13855,
8,
2713,
63,
30104,
63,
84,
680,
267,
1021,
1323,
8,
785,
304,
288,
347,
636,
552,
721,
277,
304,
355,
372,
413,
5213,
7105,
267,
862,
26,
288,
822,
8,
56,
1012,
267,
871,
23870,
26,
288,
327,
4337,
13,
2075,
288,
9141,
4305,
275,
1109,
1332,
17,
5213,
7105,
9,
446,
413,
9,
267,
587,
26,
288,
327,
5049,
13,
2075,
288,
9141,
4305,
275,
1109,
1332,
17,
5213,
13668,
9,
446,
413,
9,
267,
2150,
1323,
421,
199,
318,
485,
525,
63,
1301,
8,
1532,
12,
1382,
304,
272,
408,
1123,
3794,
370,
282,
805,
1041,
272,
2562,
855,
1301,
363,
275,
1382,
421,
199,
318,
485,
646,
63,
578,
8,
354,
304,
272,
408,
6295,
859,
12,
8152,
314,
859,
2410,
314,
2061,
6308,
1041,
272,
636,
646,
721,
354,
9,
272,
372,
984,
14,
3112,
59,
354,
61,
421,
199,
533,
485,
14269,
28782,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
536,
304,
267,
291,
14,
354,
275,
536,
339,
347,
636,
362,
721,
277,
12,
1559,
12,
9253,
304,
267,
754,
275,
291,
423,
6983,
342,
267,
5371,
8,
1113,
12,
291,
14,
354,
12,
754,
9,
327,
30110,
22652,
636,
409,
4343,
267,
327,
961,
365,
282,
4546,
23761,
12,
1325,
652,
23674,
3879,
642,
4020,
14,
267,
24358,
8,
1113,
855,
533,
3108,
291,
14,
354,
9,
267,
372,
754,
421,
199,
533,
11147,
1547,
14269,
28782,
304,
339,
347,
636,
826,
721,
277,
12,
536,
12,
2269,
12,
892,
29,
403,
304,
267,
1613,
8,
20774,
2377,
12,
291,
2843,
826,
721,
354,
9,
267,
340,
7843,
19,
26,
288,
340,
892,
365,
488,
26,
355,
892,
275,
536,
288,
291,
14,
1494,
275,
892,
267,
587,
26,
288,
291,
14,
1494,
275,
2269,
339,
347,
485,
6983,
8,
277,
304,
267,
372,
485,
646,
63,
578,
8,
277,
14,
1494,
9,
339,
347,
636,
5675,
721,
277,
12,
1921,
304,
267,
327,
30802,
6818,
314,
5634,
28589,
3422,
14,
710,
295,
3422,
11275,
370,
664,
267,
327,
636,
493,
363,
503,
636,
354,
363,
402,
4036,
859,
315,
984,
14,
3112,
14,
961,
3181,
1133,
1736,
267,
327,
5521,
340,
642,
11147,
365,
367,
376,
859,
626,
365,
18735,
641,
642,
267,
327,
6844,
334,
2930,
30748,
641,
13074,
10460,
680,
20227,
12,
781,
27830,
636,
493,
363,
436,
267,
327,
636,
354,
363,
2793,
1133,
2187,
340,
314,
859,
18699,
1133,
2757,
6511,
5966,
14,
1666,
10876,
267,
327,
327,
2869,
436,
327,
2481,
14,
267,
340,
1921,
315,
1689,
363,
493,
13915,
4396,
354,
18617,
436,
291,
14,
1494,
440,
315,
984,
14,
3112,
26,
288,
746,
4281,
267,
485,
578,
275,
291,
423,
6983,
342,
267,
574,
275,
2519,
1547,
578,
12,
1921,
9,
267,
5371,
8,
277,
12,
1921,
12,
574,
9,
267,
372,
574,
421,
199,
533,
485,
14269,
2377,
8,
1313,
14,
21820,
304,
339,
347,
636,
826,
721,
277,
12,
536,
304,
267,
1613,
1547,
14269,
2377,
12,
291,
2843,
826,
721,
354,
9,
267,
291,
855,
1301,
363,
275,
291,
855,
533,
4914,
1301,
363,
339,
347,
636,
694,
721,
277,
304,
267,
3290,
275,
2097,
363,
1301,
13915,
4396,
354,
363,
937,
267,
3290,
847,
359,
962,
14,
354,
367,
1921,
315,
291,
423,
3539,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
mrunge/horizon
|
openstack_dashboard/dashboards/project/access_and_security/tabs.py
|
7
|
5158
|
# Copyright 2012 United States Government as represented by the
# Administrator of the National Aeronautics and Space Administration.
# All Rights Reserved.
#
# Copyright 2012 Nebula, Inc.
# Copyright 2012 OpenStack Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from django.utils.translation import ugettext_lazy as _
from horizon import exceptions
from horizon import tabs
from neutronclient.common import exceptions as neutron_exc
from openstack_dashboard.api import keystone
from openstack_dashboard.api import network
from openstack_dashboard.api import nova
from openstack_dashboard.dashboards.project.access_and_security.\
api_access.tables import EndpointsTable
from openstack_dashboard.dashboards.project.access_and_security.\
floating_ips.tables import FloatingIPsTable
from openstack_dashboard.dashboards.project.access_and_security.\
keypairs.tables import KeypairsTable
from openstack_dashboard.dashboards.project.access_and_security.\
security_groups.tables import SecurityGroupsTable
class SecurityGroupsTab(tabs.TableTab):
table_classes = (SecurityGroupsTable,)
name = _("Security Groups")
slug = "security_groups_tab"
template_name = "horizon/common/_detail_table.html"
permissions = ('openstack.services.compute',)
def get_security_groups_data(self):
try:
security_groups = network.security_group_list(self.request)
except neutron_exc.ConnectionFailed:
security_groups = []
exceptions.handle(self.request)
except Exception:
security_groups = []
exceptions.handle(self.request,
_('Unable to retrieve security groups.'))
return security_groups
class KeypairsTab(tabs.TableTab):
table_classes = (KeypairsTable,)
name = _("Key Pairs")
slug = "keypairs_tab"
template_name = "horizon/common/_detail_table.html"
permissions = ('openstack.services.compute',)
def get_keypairs_data(self):
try:
keypairs = nova.keypair_list(self.request)
except Exception:
keypairs = []
exceptions.handle(self.request,
_('Unable to retrieve key pair list.'))
return keypairs
class FloatingIPsTab(tabs.TableTab):
table_classes = (FloatingIPsTable,)
name = _("Floating IPs")
slug = "floating_ips_tab"
template_name = "horizon/common/_detail_table.html"
permissions = ('openstack.services.compute',)
def get_floating_ips_data(self):
try:
floating_ips = network.tenant_floating_ip_list(self.request)
except neutron_exc.ConnectionFailed:
floating_ips = []
exceptions.handle(self.request)
except Exception:
floating_ips = []
exceptions.handle(self.request,
_('Unable to retrieve floating IP addresses.'))
try:
floating_ip_pools = network.floating_ip_pools_list(self.request)
except neutron_exc.ConnectionFailed:
floating_ip_pools = []
exceptions.handle(self.request)
except Exception:
floating_ip_pools = []
exceptions.handle(self.request,
_('Unable to retrieve floating IP pools.'))
pool_dict = dict([(obj.id, obj.name) for obj in floating_ip_pools])
instances = []
try:
instances, has_more = nova.server_list(self.request)
except Exception:
exceptions.handle(self.request,
_('Unable to retrieve instance list.'))
instances_dict = dict([(obj.id, obj.name) for obj in instances])
for ip in floating_ips:
ip.instance_name = instances_dict.get(ip.instance_id)
ip.pool_name = pool_dict.get(ip.pool, ip.pool)
return floating_ips
def allowed(self, request):
return network.floating_ip_supported(request)
class APIAccessTab(tabs.TableTab):
table_classes = (EndpointsTable,)
name = _("API Access")
slug = "api_access_tab"
template_name = "horizon/common/_detail_table.html"
def get_endpoints_data(self):
services = []
for i, service in enumerate(self.request.user.service_catalog):
service['id'] = i
services.append(
keystone.Service(service, self.request.user.services_region))
return services
class AccessAndSecurityTabs(tabs.TabGroup):
slug = "access_security_tabs"
tabs = (SecurityGroupsTab, KeypairsTab, FloatingIPsTab, APIAccessTab)
sticky = True
|
apache-2.0
|
[
3,
1898,
6029,
1910,
5703,
24230,
598,
27639,
465,
11159,
701,
314,
199,
3,
30660,
402,
314,
20548,
437,
281,
265,
3844,
7769,
436,
19326,
9516,
4633,
14,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
1898,
6029,
653,
2871,
7586,
12,
3277,
14,
199,
3,
1898,
6029,
14260,
2752,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
485,
199,
199,
504,
21726,
492,
4967,
199,
504,
21726,
492,
12187,
199,
199,
504,
8224,
1258,
14,
2330,
492,
4967,
465,
8224,
63,
2804,
199,
199,
504,
13869,
63,
9743,
14,
1246,
492,
19395,
199,
504,
13869,
63,
9743,
14,
1246,
492,
2784,
199,
504,
13869,
63,
9743,
14,
1246,
492,
5913,
199,
199,
504,
13869,
63,
9743,
14,
30424,
14,
1715,
14,
2732,
63,
460,
63,
4416,
3134,
272,
2986,
63,
2732,
14,
5987,
492,
9599,
3438,
3186,
199,
504,
13869,
63,
9743,
14,
30424,
14,
1715,
14,
2732,
63,
460,
63,
4416,
3134,
272,
8402,
63,
6142,
14,
5987,
492,
27729,
1772,
83,
3186,
199,
504,
13869,
63,
9743,
14,
30424,
14,
1715,
14,
2732,
63,
460,
63,
4416,
3134,
272,
790,
7322,
14,
5987,
492,
2606,
7322,
3186,
199,
504,
13869,
63,
9743,
14,
30424,
14,
1715,
14,
2732,
63,
460,
63,
4416,
3134,
272,
6391,
63,
2634,
14,
5987,
492,
13863,
10177,
3186,
421,
199,
533,
13863,
10177,
7690,
8,
8741,
14,
3186,
7690,
304,
272,
1817,
63,
2888,
275,
334,
7676,
10177,
3186,
4258,
272,
536,
275,
3824,
7676,
25031,
531,
272,
8889,
275,
298,
4416,
63,
2634,
63,
2902,
2,
272,
1978,
63,
354,
275,
298,
16561,
15,
2330,
15607,
5506,
63,
1224,
14,
1360,
2,
272,
3443,
275,
661,
8512,
14,
5950,
14,
3357,
9538,
339,
347,
664,
63,
4416,
63,
2634,
63,
576,
8,
277,
304,
267,
862,
26,
288,
6391,
63,
2634,
275,
2784,
14,
4416,
63,
923,
63,
513,
8,
277,
14,
1069,
9,
267,
871,
8224,
63,
2804,
14,
3225,
4276,
26,
288,
6391,
63,
2634,
275,
942,
288,
4967,
14,
2479,
8,
277,
14,
1069,
9,
267,
871,
2186,
26,
288,
6391,
63,
2634,
275,
942,
288,
4967,
14,
2479,
8,
277,
14,
1069,
12,
2892,
4018,
6005,
370,
8044,
6391,
4652,
12459,
267,
372,
6391,
63,
2634,
421,
199,
533,
2606,
7322,
7690,
8,
8741,
14,
3186,
7690,
304,
272,
1817,
63,
2888,
275,
334,
1197,
7322,
3186,
4258,
272,
536,
275,
3824,
1197,
510,
8387,
83,
531,
272,
8889,
275,
298,
30825,
63,
2902,
2,
272,
1978,
63,
354,
275,
298,
16561,
15,
2330,
15607,
5506,
63,
1224,
14,
1360,
2,
272,
3443,
275,
661,
8512,
14,
5950,
14,
3357,
9538,
339,
347,
664,
63,
30825,
63,
576,
8,
277,
304,
267,
862,
26,
288,
790,
7322,
275,
5913,
14,
19263,
63,
513,
8,
277,
14,
1069,
9,
267,
871,
2186,
26,
288,
790,
7322,
275,
942,
288,
4967,
14,
2479,
8,
277,
14,
1069,
12,
2892,
4018,
6005,
370,
8044,
790,
4092,
769,
12459,
267,
372,
790,
7322,
421,
199,
533,
27729,
1772,
83,
7690,
8,
8741,
14,
3186,
7690,
304,
272,
1817,
63,
2888,
275,
334,
17895,
1772,
83,
3186,
4258,
272,
536,
275,
3824,
17895,
30657,
531,
272,
8889,
275,
298,
7774,
63,
6142,
63,
2902,
2,
272,
1978,
63,
354,
275,
298,
16561,
15,
2330,
15607,
5506,
63,
1224,
14,
1360,
2,
272,
3443,
275,
661,
8512,
14,
5950,
14,
3357,
9538,
339,
347,
664,
63,
7774,
63,
6142,
63,
576,
8,
277,
304,
267,
862,
26,
288,
8402,
63,
6142,
275,
2784,
14,
4647,
63,
7774,
63,
711,
63,
513,
8,
277,
14,
1069,
9,
267,
871,
8224,
63,
2804,
14,
3225,
4276,
26,
288,
8402,
63,
6142,
275,
942,
288,
4967,
14,
2479,
8,
277,
14,
1069,
9,
267,
871,
2186,
26,
288,
8402,
63,
6142,
275,
942,
288,
4967,
14,
2479,
8,
277,
14,
1069,
12,
2892,
4018,
6005,
370,
8044,
8402,
3531,
7149,
12459,
398,
862,
26,
288,
8402,
63,
711,
63,
12406,
275,
2784,
14,
7774,
63,
711,
63,
12406,
63,
513,
8,
277,
14,
1069,
9,
267,
871,
8224,
63,
2804,
14,
3225,
4276,
26,
288,
8402,
63,
711,
63,
12406,
275,
942,
288,
4967,
14,
2479,
8,
277,
14,
1069,
9,
267,
871,
2186,
26,
288,
8402,
63,
711,
63,
12406,
275,
942,
288,
4967,
14,
2479,
8,
277,
14,
1069,
12,
2490,
4018,
6005,
370,
8044,
8402,
3531,
20092,
12459,
267,
4203,
63,
807,
275,
1211,
7694,
1113,
14,
344,
12,
1559,
14,
354,
9,
367,
1559,
315,
8402,
63,
711,
63,
12406,
566,
398,
4454,
275,
942,
267,
862,
26,
288,
4454,
12,
965,
63,
6878,
275,
5913,
14,
1000,
63,
513,
8,
277,
14,
1069,
9,
267,
871,
2186,
26,
288,
4967,
14,
2479,
8,
277,
14,
1069,
12,
717,
4018,
6005,
370,
8044,
1256,
769,
12459,
398,
4454,
63,
807,
275,
1211,
7694,
1113,
14,
344,
12,
1559,
14,
354,
9,
367,
1559,
315,
4454,
566,
398,
367,
3384,
315,
8402,
63,
6142,
26,
288,
3384,
14,
842,
63,
354,
275,
4454,
63,
807,
14,
362,
8,
711,
14,
842,
63,
344,
9,
288,
3384,
14,
2293,
63,
354,
275,
4203,
63,
807,
14,
362,
8,
711,
14,
2293,
12,
3384,
14,
2293,
9,
398,
372,
8402,
63,
6142,
339,
347,
4370,
8,
277,
12,
1056,
304,
267,
372,
2784
] |
[
1898,
6029,
1910,
5703,
24230,
598,
27639,
465,
11159,
701,
314,
199,
3,
30660,
402,
314,
20548,
437,
281,
265,
3844,
7769,
436,
19326,
9516,
4633,
14,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
1898,
6029,
653,
2871,
7586,
12,
3277,
14,
199,
3,
1898,
6029,
14260,
2752,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
485,
199,
199,
504,
21726,
492,
4967,
199,
504,
21726,
492,
12187,
199,
199,
504,
8224,
1258,
14,
2330,
492,
4967,
465,
8224,
63,
2804,
199,
199,
504,
13869,
63,
9743,
14,
1246,
492,
19395,
199,
504,
13869,
63,
9743,
14,
1246,
492,
2784,
199,
504,
13869,
63,
9743,
14,
1246,
492,
5913,
199,
199,
504,
13869,
63,
9743,
14,
30424,
14,
1715,
14,
2732,
63,
460,
63,
4416,
3134,
272,
2986,
63,
2732,
14,
5987,
492,
9599,
3438,
3186,
199,
504,
13869,
63,
9743,
14,
30424,
14,
1715,
14,
2732,
63,
460,
63,
4416,
3134,
272,
8402,
63,
6142,
14,
5987,
492,
27729,
1772,
83,
3186,
199,
504,
13869,
63,
9743,
14,
30424,
14,
1715,
14,
2732,
63,
460,
63,
4416,
3134,
272,
790,
7322,
14,
5987,
492,
2606,
7322,
3186,
199,
504,
13869,
63,
9743,
14,
30424,
14,
1715,
14,
2732,
63,
460,
63,
4416,
3134,
272,
6391,
63,
2634,
14,
5987,
492,
13863,
10177,
3186,
421,
199,
533,
13863,
10177,
7690,
8,
8741,
14,
3186,
7690,
304,
272,
1817,
63,
2888,
275,
334,
7676,
10177,
3186,
4258,
272,
536,
275,
3824,
7676,
25031,
531,
272,
8889,
275,
298,
4416,
63,
2634,
63,
2902,
2,
272,
1978,
63,
354,
275,
298,
16561,
15,
2330,
15607,
5506,
63,
1224,
14,
1360,
2,
272,
3443,
275,
661,
8512,
14,
5950,
14,
3357,
9538,
339,
347,
664,
63,
4416,
63,
2634,
63,
576,
8,
277,
304,
267,
862,
26,
288,
6391,
63,
2634,
275,
2784,
14,
4416,
63,
923,
63,
513,
8,
277,
14,
1069,
9,
267,
871,
8224,
63,
2804,
14,
3225,
4276,
26,
288,
6391,
63,
2634,
275,
942,
288,
4967,
14,
2479,
8,
277,
14,
1069,
9,
267,
871,
2186,
26,
288,
6391,
63,
2634,
275,
942,
288,
4967,
14,
2479,
8,
277,
14,
1069,
12,
2892,
4018,
6005,
370,
8044,
6391,
4652,
12459,
267,
372,
6391,
63,
2634,
421,
199,
533,
2606,
7322,
7690,
8,
8741,
14,
3186,
7690,
304,
272,
1817,
63,
2888,
275,
334,
1197,
7322,
3186,
4258,
272,
536,
275,
3824,
1197,
510,
8387,
83,
531,
272,
8889,
275,
298,
30825,
63,
2902,
2,
272,
1978,
63,
354,
275,
298,
16561,
15,
2330,
15607,
5506,
63,
1224,
14,
1360,
2,
272,
3443,
275,
661,
8512,
14,
5950,
14,
3357,
9538,
339,
347,
664,
63,
30825,
63,
576,
8,
277,
304,
267,
862,
26,
288,
790,
7322,
275,
5913,
14,
19263,
63,
513,
8,
277,
14,
1069,
9,
267,
871,
2186,
26,
288,
790,
7322,
275,
942,
288,
4967,
14,
2479,
8,
277,
14,
1069,
12,
2892,
4018,
6005,
370,
8044,
790,
4092,
769,
12459,
267,
372,
790,
7322,
421,
199,
533,
27729,
1772,
83,
7690,
8,
8741,
14,
3186,
7690,
304,
272,
1817,
63,
2888,
275,
334,
17895,
1772,
83,
3186,
4258,
272,
536,
275,
3824,
17895,
30657,
531,
272,
8889,
275,
298,
7774,
63,
6142,
63,
2902,
2,
272,
1978,
63,
354,
275,
298,
16561,
15,
2330,
15607,
5506,
63,
1224,
14,
1360,
2,
272,
3443,
275,
661,
8512,
14,
5950,
14,
3357,
9538,
339,
347,
664,
63,
7774,
63,
6142,
63,
576,
8,
277,
304,
267,
862,
26,
288,
8402,
63,
6142,
275,
2784,
14,
4647,
63,
7774,
63,
711,
63,
513,
8,
277,
14,
1069,
9,
267,
871,
8224,
63,
2804,
14,
3225,
4276,
26,
288,
8402,
63,
6142,
275,
942,
288,
4967,
14,
2479,
8,
277,
14,
1069,
9,
267,
871,
2186,
26,
288,
8402,
63,
6142,
275,
942,
288,
4967,
14,
2479,
8,
277,
14,
1069,
12,
2892,
4018,
6005,
370,
8044,
8402,
3531,
7149,
12459,
398,
862,
26,
288,
8402,
63,
711,
63,
12406,
275,
2784,
14,
7774,
63,
711,
63,
12406,
63,
513,
8,
277,
14,
1069,
9,
267,
871,
8224,
63,
2804,
14,
3225,
4276,
26,
288,
8402,
63,
711,
63,
12406,
275,
942,
288,
4967,
14,
2479,
8,
277,
14,
1069,
9,
267,
871,
2186,
26,
288,
8402,
63,
711,
63,
12406,
275,
942,
288,
4967,
14,
2479,
8,
277,
14,
1069,
12,
2490,
4018,
6005,
370,
8044,
8402,
3531,
20092,
12459,
267,
4203,
63,
807,
275,
1211,
7694,
1113,
14,
344,
12,
1559,
14,
354,
9,
367,
1559,
315,
8402,
63,
711,
63,
12406,
566,
398,
4454,
275,
942,
267,
862,
26,
288,
4454,
12,
965,
63,
6878,
275,
5913,
14,
1000,
63,
513,
8,
277,
14,
1069,
9,
267,
871,
2186,
26,
288,
4967,
14,
2479,
8,
277,
14,
1069,
12,
717,
4018,
6005,
370,
8044,
1256,
769,
12459,
398,
4454,
63,
807,
275,
1211,
7694,
1113,
14,
344,
12,
1559,
14,
354,
9,
367,
1559,
315,
4454,
566,
398,
367,
3384,
315,
8402,
63,
6142,
26,
288,
3384,
14,
842,
63,
354,
275,
4454,
63,
807,
14,
362,
8,
711,
14,
842,
63,
344,
9,
288,
3384,
14,
2293,
63,
354,
275,
4203,
63,
807,
14,
362,
8,
711,
14,
2293,
12,
3384,
14,
2293,
9,
398,
372,
8402,
63,
6142,
339,
347,
4370,
8,
277,
12,
1056,
304,
267,
372,
2784,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
from rebulk import Rebulk, Rule, CustomRule, POST_PROCESS, PRE_PROCESS, AppendMatch, RemoveMatch
from guessit.rules.common.words import iter_words
from .common.formatters import cleanup
from .common.comparators import marker_sorted
from .common.date import valid_year
class EnlargeGroupMatches(CustomRule):
"""
Enlarge matches that are starting and/or ending group to include brackets in their span.
:param matches:
:type matches:
:return:
:rtype:
"""
priority = PRE_PROCESS
def when(self, matches, context):
starting = []
ending = []
for group in matches.markers.named('group'):
for match in matches.starting(group.start + 1):
starting.append(match)
for match in matches.ending(group.end - 1):
ending.append(match)
if starting or ending:
return starting, ending
def then(self, matches, when_response, context):
starting, ending = when_response
for match in starting:
matches.remove(match)
match.start -= 1
match.raw_start += 1
matches.append(match)
for match in ending:
matches.remove(match)
match.end += 1
match.raw_end -= 1
matches.append(match)
class EquivalentHoles(Rule):
"""
Creates equivalent matches for holes that have same values than existing (case insensitive)
"""
priority = POST_PROCESS
consequence = AppendMatch
def when(self, matches, context):
new_matches = []
for filepath in marker_sorted(matches.markers.named('path'), matches):
holes = matches.holes(start=filepath.start, end=filepath.end, formatter=cleanup)
for name in matches.names:
for hole in list(holes):
for current_match in matches.named(name):
if isinstance(current_match.value, six.string_types) and \
hole.value.lower() == current_match.value.lower():
if 'equivalent-ignore' in current_match.tags:
continue
new_value = _preferred_string(hole.value, current_match.value)
if hole.value != new_value:
hole.value = new_value
if current_match.value != new_value:
current_match.value = new_value
hole.name = name
hole.tags = ['equivalent']
new_matches.append(hole)
if hole in holes:
holes.remove(hole)
return new_matches
class RemoveAmbiguous(Rule):
"""
If multiple match are found with same name and different values, keep the one in the most valuable filepart.
Also keep others match with same name and values than those kept ones.
"""
priority = POST_PROCESS
consequence = RemoveMatch
def when(self, matches, context):
fileparts = marker_sorted(matches.markers.named('path'), matches)
previous_fileparts_names = set()
values = defaultdict(list)
to_remove = []
for filepart in fileparts:
filepart_matches = matches.range(filepart.start, filepart.end)
filepart_names = set()
for match in filepart_matches:
filepart_names.add(match.name)
if match.name in previous_fileparts_names:
if match.value not in values[match.name]:
to_remove.append(match)
else:
if match.value not in values[match.name]:
values[match.name].append(match.value)
previous_fileparts_names.update(filepart_names)
return to_remove
def _preferred_string(value1, value2): # pylint:disable=too-many-return-statements
"""
Retrieves preferred title from both values.
:param value1:
:type value1: str
:param value2:
:type value2: str
:return: The preferred title
:rtype: str
"""
if value1 == value2:
return value1
if value1.istitle() and not value2.istitle():
return value1
if not value1.isupper() and value2.isupper():
return value1
if not value1.isupper() and value1[0].isupper() and not value2[0].isupper():
return value1
if _count_title_words(value1) > _count_title_words(value2):
return value1
return value2
def _count_title_words(value):
"""
Count only many words are titles in value.
:param value:
:type value:
:return:
:rtype:
"""
ret = 0
for word in iter_words(value):
if word.value.istitle():
ret += 1
return ret
class SeasonYear(Rule):
"""
If a season is a valid year and no year was found, create an match with year.
"""
priority = POST_PROCESS
consequence = AppendMatch
def when(self, matches, context):
ret = []
if not matches.named('year'):
for season in matches.named('season'):
if valid_year(season.value):
year = copy.copy(season)
year.name = 'year'
ret.append(year)
return ret
class Processors(CustomRule):
"""
Empty rule for ordering post_processing properly.
"""
priority = POST_PROCESS
def when(self, matches, context):
pass
def then(self, matches, when_response, context): # pragma: no cover
pass
def processors():
"""
Builder for rebulk object.
:return: Created Rebulk object
:rtype: Rebulk
"""
return Rebulk().rules(EnlargeGroupMatches, EquivalentHoles, RemoveAmbiguous, SeasonYear, Processors)
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
199,
3498,
1384,
199,
624,
199,
504,
5055,
492,
10018,
199,
646,
1331,
199,
199,
646,
3816,
199,
199,
504,
295,
9377,
492,
799,
9377,
12,
11949,
12,
8388,
5065,
12,
8761,
63,
10494,
12,
19924,
63,
10494,
12,
18726,
4486,
12,
5852,
4486,
199,
504,
19977,
2221,
14,
4423,
14,
2330,
14,
3148,
492,
2740,
63,
3148,
199,
504,
1275,
2330,
14,
24270,
492,
9058,
199,
504,
1275,
2330,
14,
863,
285,
2750,
492,
3608,
63,
5917,
199,
504,
1275,
2330,
14,
602,
492,
1686,
63,
3403,
421,
199,
533,
3447,
9629,
2448,
12962,
8,
7223,
5065,
304,
272,
408,
272,
3447,
9629,
4450,
626,
787,
6617,
436,
15,
269,
13401,
1572,
370,
2387,
21873,
315,
3932,
13598,
14,
272,
520,
635,
4450,
26,
272,
520,
466,
4450,
26,
272,
520,
1107,
26,
272,
520,
4500,
26,
272,
408,
272,
7464,
275,
19924,
63,
10494,
339,
347,
1380,
8,
277,
12,
4450,
12,
1067,
304,
267,
6617,
275,
942,
267,
13401,
275,
942,
398,
367,
1572,
315,
4450,
14,
16835,
14,
4579,
360,
923,
735,
288,
367,
1336,
315,
4450,
14,
15769,
8,
923,
14,
928,
435,
413,
304,
355,
6617,
14,
740,
8,
1431,
9,
953,
367,
1336,
315,
4450,
14,
3219,
8,
923,
14,
500,
446,
413,
304,
355,
13401,
14,
740,
8,
1431,
9,
398,
340,
6617,
503,
13401,
26,
288,
372,
6617,
12,
13401,
339,
347,
2066,
8,
277,
12,
4450,
12,
1380,
63,
1310,
12,
1067,
304,
267,
6617,
12,
13401,
275,
1380,
63,
1310,
267,
367,
1336,
315,
6617,
26,
288,
4450,
14,
2168,
8,
1431,
9,
288,
1336,
14,
928,
4862,
413,
288,
1336,
14,
1773,
63,
928,
847,
413,
288,
4450,
14,
740,
8,
1431,
9,
398,
367,
1336,
315,
13401,
26,
288,
4450,
14,
2168,
8,
1431,
9,
288,
1336,
14,
500,
847,
413,
288,
1336,
14,
1773,
63,
500,
4862,
413,
288,
4450,
14,
740,
8,
1431,
9,
421,
199,
533,
24228,
17810,
2978,
8,
5065,
304,
272,
408,
272,
10560,
7353,
4450,
367,
2636,
2978,
626,
1172,
2011,
1338,
2419,
3411,
334,
2546,
27845,
9,
272,
408,
272,
7464,
275,
8761,
63,
10494,
272,
406,
4041,
275,
18726,
4486,
339,
347,
1380,
8,
277,
12,
4450,
12,
1067,
304,
267,
892,
63,
6742,
275,
942,
398,
367,
9911,
315,
3608,
63,
5917,
8,
6742,
14,
16835,
14,
4579,
360,
515,
659,
4450,
304,
288,
2636,
2978,
275,
4450,
14,
31110,
8,
928,
29,
7218,
14,
928,
12,
1284,
29,
7218,
14,
500,
12,
9698,
29,
7661,
9,
288,
367,
536,
315,
4450,
14,
1247,
26,
355,
367,
2636,
274,
315,
769,
8,
31110,
304,
490,
367,
1453,
63,
1431,
315,
4450,
14,
4579,
8,
354,
304,
717,
340,
1228,
8,
1818,
63,
1431,
14,
585,
12,
3816,
14,
875,
63,
1313,
9,
436,
971,
3147,
2636,
274,
14,
585,
14,
2325,
342,
508,
1453,
63,
1431,
14,
585,
14,
2325,
837,
1169,
340,
283,
24179,
13,
4247,
7,
315,
1453,
63,
1431,
14,
2969,
26,
1816,
1980,
1169,
892,
63,
585,
275,
485,
17477,
63,
875,
8,
16668,
14,
585,
12,
1453,
63,
1431,
14,
585,
9,
1169,
340,
2636,
274,
14,
585,
1137,
892,
63,
585,
26,
1816,
2636,
274,
14,
585,
275,
892,
63,
585,
1169,
340,
1453,
63,
1431,
14,
585,
1137,
892,
63,
585,
26,
1816,
1453,
63,
1431,
14,
585,
275,
892,
63,
585,
1169,
2636,
274,
14,
354,
275,
536,
1169,
2636,
274,
14,
2969,
275,
788,
24179,
418,
1169,
892,
63,
6742,
14,
740,
8,
16668,
9,
1169,
340,
2636,
274,
315,
2636,
2978,
26,
1816,
2636,
2978,
14,
2168,
8,
16668,
9,
398,
372,
892,
63,
6742,
421,
199,
533,
5852,
29209,
20357,
8,
5065,
304,
272,
408,
272,
982,
3663,
1336,
787,
1911,
543,
2011,
536,
436,
3365,
1338,
12,
4215,
314,
1373,
315,
314,
4750,
1139,
85,
461,
570,
2064,
14,
272,
6121,
4215,
11789,
1336,
543,
2011,
536,
436,
1338,
2419,
5204,
16204,
7869,
14,
272,
408,
272,
7464,
275,
8761,
63,
10494,
272,
406,
4041,
275,
5852,
4486,
339,
347,
1380,
8,
277,
12,
4450,
12,
1067,
304,
267,
570,
4181,
275,
3608,
63,
5917,
8,
6742,
14,
16835,
14,
4579,
360,
515,
659,
4450,
9,
398,
4136,
63,
493,
4181,
63,
1247,
275,
663,
342,
267,
1338,
275,
10018,
8,
513,
9,
398,
370,
63,
2168,
275,
942,
267,
367,
570,
2064,
315,
570,
4181,
26,
288,
570,
2064,
63,
6742,
275,
4450,
14,
1842,
8,
493,
2064,
14,
928,
12,
570,
2064,
14,
500,
9,
953,
570,
2064,
63,
1247,
275,
663,
342,
288,
367,
1336,
315,
570,
2064,
63,
6742,
26,
355,
570,
2064,
63,
1247,
14,
525,
8,
1431,
14,
354,
9,
355,
340,
1336,
14,
354,
315,
4136,
63,
493,
4181,
63,
1247,
26,
490,
340,
1336,
14,
585,
440,
315,
1338,
59,
1431,
14,
354,
2189,
717,
370,
63,
2168,
14,
740,
8,
1431,
9,
355,
587,
26,
490,
340,
1336,
14,
585,
440,
315,
1338,
59,
1431,
14,
354,
2189,
717,
1338,
59,
1431,
14,
354,
1055,
740,
8,
1431,
14,
585,
9,
953,
4136,
63,
493,
4181,
63,
1247,
14,
873,
8,
493,
2064,
63,
1247,
9,
398,
372,
370,
63,
2168,
421,
199,
318,
485,
17477,
63,
875,
8,
585,
17,
12,
574,
18,
304,
221,
327,
4287,
26,
5993,
29,
7354,
13,
3479,
13,
1107,
13,
15384,
272,
408,
272,
27940,
14388,
2538,
687,
3865,
1338,
14,
272,
520,
635,
574,
17,
26,
272,
520,
466,
574,
17,
26,
620,
272,
520,
635,
574,
18,
26,
272,
520,
466,
574,
18,
26,
620,
272,
520,
1107,
26,
710,
14388,
2538,
272,
520,
4500,
26,
620,
272,
408,
272,
340,
574,
17,
508,
574,
18,
26,
267,
372,
574,
17,
272,
340,
574,
17,
14,
631,
5776,
342,
436,
440,
574,
18,
14,
631,
5776,
837,
267,
372,
574,
17,
272,
340,
440,
574,
17,
14,
374,
4142,
342,
436,
574,
18,
14,
374,
4142,
837,
267,
372,
574,
17,
272,
340,
440,
574,
17,
14,
374,
4142,
342,
436,
574,
17,
59
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
199,
3498,
1384,
199,
624,
199,
504,
5055,
492,
10018,
199,
646,
1331,
199,
199,
646,
3816,
199,
199,
504,
295,
9377,
492,
799,
9377,
12,
11949,
12,
8388,
5065,
12,
8761,
63,
10494,
12,
19924,
63,
10494,
12,
18726,
4486,
12,
5852,
4486,
199,
504,
19977,
2221,
14,
4423,
14,
2330,
14,
3148,
492,
2740,
63,
3148,
199,
504,
1275,
2330,
14,
24270,
492,
9058,
199,
504,
1275,
2330,
14,
863,
285,
2750,
492,
3608,
63,
5917,
199,
504,
1275,
2330,
14,
602,
492,
1686,
63,
3403,
421,
199,
533,
3447,
9629,
2448,
12962,
8,
7223,
5065,
304,
272,
408,
272,
3447,
9629,
4450,
626,
787,
6617,
436,
15,
269,
13401,
1572,
370,
2387,
21873,
315,
3932,
13598,
14,
272,
520,
635,
4450,
26,
272,
520,
466,
4450,
26,
272,
520,
1107,
26,
272,
520,
4500,
26,
272,
408,
272,
7464,
275,
19924,
63,
10494,
339,
347,
1380,
8,
277,
12,
4450,
12,
1067,
304,
267,
6617,
275,
942,
267,
13401,
275,
942,
398,
367,
1572,
315,
4450,
14,
16835,
14,
4579,
360,
923,
735,
288,
367,
1336,
315,
4450,
14,
15769,
8,
923,
14,
928,
435,
413,
304,
355,
6617,
14,
740,
8,
1431,
9,
953,
367,
1336,
315,
4450,
14,
3219,
8,
923,
14,
500,
446,
413,
304,
355,
13401,
14,
740,
8,
1431,
9,
398,
340,
6617,
503,
13401,
26,
288,
372,
6617,
12,
13401,
339,
347,
2066,
8,
277,
12,
4450,
12,
1380,
63,
1310,
12,
1067,
304,
267,
6617,
12,
13401,
275,
1380,
63,
1310,
267,
367,
1336,
315,
6617,
26,
288,
4450,
14,
2168,
8,
1431,
9,
288,
1336,
14,
928,
4862,
413,
288,
1336,
14,
1773,
63,
928,
847,
413,
288,
4450,
14,
740,
8,
1431,
9,
398,
367,
1336,
315,
13401,
26,
288,
4450,
14,
2168,
8,
1431,
9,
288,
1336,
14,
500,
847,
413,
288,
1336,
14,
1773,
63,
500,
4862,
413,
288,
4450,
14,
740,
8,
1431,
9,
421,
199,
533,
24228,
17810,
2978,
8,
5065,
304,
272,
408,
272,
10560,
7353,
4450,
367,
2636,
2978,
626,
1172,
2011,
1338,
2419,
3411,
334,
2546,
27845,
9,
272,
408,
272,
7464,
275,
8761,
63,
10494,
272,
406,
4041,
275,
18726,
4486,
339,
347,
1380,
8,
277,
12,
4450,
12,
1067,
304,
267,
892,
63,
6742,
275,
942,
398,
367,
9911,
315,
3608,
63,
5917,
8,
6742,
14,
16835,
14,
4579,
360,
515,
659,
4450,
304,
288,
2636,
2978,
275,
4450,
14,
31110,
8,
928,
29,
7218,
14,
928,
12,
1284,
29,
7218,
14,
500,
12,
9698,
29,
7661,
9,
288,
367,
536,
315,
4450,
14,
1247,
26,
355,
367,
2636,
274,
315,
769,
8,
31110,
304,
490,
367,
1453,
63,
1431,
315,
4450,
14,
4579,
8,
354,
304,
717,
340,
1228,
8,
1818,
63,
1431,
14,
585,
12,
3816,
14,
875,
63,
1313,
9,
436,
971,
3147,
2636,
274,
14,
585,
14,
2325,
342,
508,
1453,
63,
1431,
14,
585,
14,
2325,
837,
1169,
340,
283,
24179,
13,
4247,
7,
315,
1453,
63,
1431,
14,
2969,
26,
1816,
1980,
1169,
892,
63,
585,
275,
485,
17477,
63,
875,
8,
16668,
14,
585,
12,
1453,
63,
1431,
14,
585,
9,
1169,
340,
2636,
274,
14,
585,
1137,
892,
63,
585,
26,
1816,
2636,
274,
14,
585,
275,
892,
63,
585,
1169,
340,
1453,
63,
1431,
14,
585,
1137,
892,
63,
585,
26,
1816,
1453,
63,
1431,
14,
585,
275,
892,
63,
585,
1169,
2636,
274,
14,
354,
275,
536,
1169,
2636,
274,
14,
2969,
275,
788,
24179,
418,
1169,
892,
63,
6742,
14,
740,
8,
16668,
9,
1169,
340,
2636,
274,
315,
2636,
2978,
26,
1816,
2636,
2978,
14,
2168,
8,
16668,
9,
398,
372,
892,
63,
6742,
421,
199,
533,
5852,
29209,
20357,
8,
5065,
304,
272,
408,
272,
982,
3663,
1336,
787,
1911,
543,
2011,
536,
436,
3365,
1338,
12,
4215,
314,
1373,
315,
314,
4750,
1139,
85,
461,
570,
2064,
14,
272,
6121,
4215,
11789,
1336,
543,
2011,
536,
436,
1338,
2419,
5204,
16204,
7869,
14,
272,
408,
272,
7464,
275,
8761,
63,
10494,
272,
406,
4041,
275,
5852,
4486,
339,
347,
1380,
8,
277,
12,
4450,
12,
1067,
304,
267,
570,
4181,
275,
3608,
63,
5917,
8,
6742,
14,
16835,
14,
4579,
360,
515,
659,
4450,
9,
398,
4136,
63,
493,
4181,
63,
1247,
275,
663,
342,
267,
1338,
275,
10018,
8,
513,
9,
398,
370,
63,
2168,
275,
942,
267,
367,
570,
2064,
315,
570,
4181,
26,
288,
570,
2064,
63,
6742,
275,
4450,
14,
1842,
8,
493,
2064,
14,
928,
12,
570,
2064,
14,
500,
9,
953,
570,
2064,
63,
1247,
275,
663,
342,
288,
367,
1336,
315,
570,
2064,
63,
6742,
26,
355,
570,
2064,
63,
1247,
14,
525,
8,
1431,
14,
354,
9,
355,
340,
1336,
14,
354,
315,
4136,
63,
493,
4181,
63,
1247,
26,
490,
340,
1336,
14,
585,
440,
315,
1338,
59,
1431,
14,
354,
2189,
717,
370,
63,
2168,
14,
740,
8,
1431,
9,
355,
587,
26,
490,
340,
1336,
14,
585,
440,
315,
1338,
59,
1431,
14,
354,
2189,
717,
1338,
59,
1431,
14,
354,
1055,
740,
8,
1431,
14,
585,
9,
953,
4136,
63,
493,
4181,
63,
1247,
14,
873,
8,
493,
2064,
63,
1247,
9,
398,
372,
370,
63,
2168,
421,
199,
318,
485,
17477,
63,
875,
8,
585,
17,
12,
574,
18,
304,
221,
327,
4287,
26,
5993,
29,
7354,
13,
3479,
13,
1107,
13,
15384,
272,
408,
272,
27940,
14388,
2538,
687,
3865,
1338,
14,
272,
520,
635,
574,
17,
26,
272,
520,
466,
574,
17,
26,
620,
272,
520,
635,
574,
18,
26,
272,
520,
466,
574,
18,
26,
620,
272,
520,
1107,
26,
710,
14388,
2538,
272,
520,
4500,
26,
620,
272,
408,
272,
340,
574,
17,
508,
574,
18,
26,
267,
372,
574,
17,
272,
340,
574,
17,
14,
631,
5776,
342,
436,
440,
574,
18,
14,
631,
5776,
837,
267,
372,
574,
17,
272,
340,
440,
574,
17,
14,
374,
4142,
342,
436,
574,
18,
14,
374,
4142,
837,
267,
372,
574,
17,
272,
340,
440,
574,
17,
14,
374,
4142,
342,
436,
574,
17,
59,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Azure/azure-sdk-for-python
|
tools/azure-devtools/src/azure_devtools/scenario_tests/base.py
|
1
|
8281
|
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
from __future__ import print_function
import unittest
import os
import inspect
import tempfile
import shutil
import logging
import threading
import six
import vcr
from .config import TestConfig
from .const import ENV_TEST_DIAGNOSE
from .utilities import create_random_name, _decompress_response_body
from .decorators import live_only
class IntegrationTestBase(unittest.TestCase):
def __init__(self, method_name):
super(IntegrationTestBase, self).__init__(method_name)
self.diagnose = os.environ.get(ENV_TEST_DIAGNOSE, None) == "True"
self.logger = logging.getLogger("azure_devtools.scenario_tests")
def create_random_name(self, prefix, length): # pylint: disable=no-self-use
return create_random_name(prefix=prefix, length=length)
def create_temp_file(self, size_kb, full_random=False):
""" Create a temporary file for testing. The test harness will delete the file during tearing down. """
fd, path = tempfile.mkstemp()
os.close(fd)
self.addCleanup(lambda: os.remove(path))
with open(path, mode="r+b") as f:
if full_random:
chunk = os.urandom(1024)
else:
chunk = bytearray([0] * 1024)
for _ in range(size_kb):
f.write(chunk)
return path
def create_temp_dir(self):
"""
Create a temporary directory for testing. The test harness will delete the directory during tearing down.
"""
temp_dir = tempfile.mkdtemp()
self.addCleanup(lambda: shutil.rmtree(temp_dir, ignore_errors=True))
return temp_dir
@classmethod
def set_env(cls, key, val):
os.environ[key] = val
@classmethod
def pop_env(cls, key):
return os.environ.pop(key, None)
@live_only()
class LiveTest(IntegrationTestBase):
pass
class ReplayableTest(IntegrationTestBase): # pylint: disable=too-many-instance-attributes
FILTER_HEADERS = [
"authorization",
"client-request-id",
"retry-after",
"x-ms-client-request-id",
"x-ms-correlation-request-id",
"x-ms-ratelimit-remaining-subscription-reads",
"x-ms-request-id",
"x-ms-routing-request-id",
"x-ms-gateway-service-instanceid",
"x-ms-ratelimit-remaining-tenant-reads",
"x-ms-served-by",
"x-ms-authorization-auxiliary",
]
def __init__(
self, # pylint: disable=too-many-arguments
method_name,
config_file=None,
recording_dir=None,
recording_name=None,
recording_processors=None,
replay_processors=None,
recording_patches=None,
replay_patches=None,
match_body=False,
custom_request_matchers=None,
):
super(ReplayableTest, self).__init__(method_name)
self.recording_processors = recording_processors or []
self.replay_processors = replay_processors or []
self.recording_patches = recording_patches or []
self.replay_patches = replay_patches or []
self.config = TestConfig(config_file=config_file)
self.disable_recording = False
test_file_path = inspect.getfile(self.__class__)
recording_dir = recording_dir or os.path.join(os.path.dirname(test_file_path), "recordings")
self.is_live = self.config.record_mode
self.vcr = vcr.VCR(
cassette_library_dir=recording_dir,
before_record_request=self._process_request_recording,
before_record_response=self._process_response_recording,
decode_compressed_response=True,
record_mode="once" if not self.is_live else "all",
filter_headers=self.FILTER_HEADERS,
)
self.vcr.register_matcher("query", self._custom_request_query_matcher)
if match_body:
self.vcr.match_on += ("body",)
for matcher in custom_request_matchers or []:
self.vcr.register_matcher(matcher.__name__, matcher)
self.vcr.match_on += (matcher.__name__,)
self.recording_file = os.path.join(recording_dir, "{}.yaml".format(recording_name or method_name))
if self.is_live and os.path.exists(self.recording_file):
os.remove(self.recording_file)
self.in_recording = self.is_live or not os.path.exists(self.recording_file)
self.test_resources_count = 0
self.original_env = os.environ.copy()
def setUp(self):
super(ReplayableTest, self).setUp()
if self.is_live and os.environ.get("AZURE_SKIP_LIVE_RECORDING", "").lower() == "true":
return
# set up cassette
cm = self.vcr.use_cassette(self.recording_file)
self.cassette = cm.__enter__()
self.addCleanup(cm.__exit__)
# set up mock patches
if self.in_recording:
for patch in self.recording_patches:
patch(self)
else:
for patch in self.replay_patches:
patch(self)
def tearDown(self):
os.environ = self.original_env
# Autorest.Python 2.x
assert not [
t for t in threading.enumerate() if t.name.startswith("AzureOperationPoller")
], "You need to call 'result' or 'wait' on all AzureOperationPoller you have created"
# Autorest.Python 3.x
assert not [
t for t in threading.enumerate() if t.name.startswith("LROPoller")
], "You need to call 'result' or 'wait' on all LROPoller you have created"
def _process_request_recording(self, request):
if self.disable_recording:
return None
if self.in_recording:
for processor in self.recording_processors:
request = processor.process_request(request)
if not request:
break
else:
for processor in self.replay_processors:
request = processor.process_request(request)
if not request:
break
return request
def _process_response_recording(self, response):
from .utilities import is_text_payload
if self.in_recording:
# make header name lower case and filter unwanted headers
headers = {}
for key in response["headers"]:
if key.lower() not in self.FILTER_HEADERS:
headers[key.lower()] = response["headers"][key]
response["headers"] = headers
body = response["body"]["string"]
response = _decompress_response_body(response)
if is_text_payload(response) and body and not isinstance(body, six.string_types):
try:
response["body"]["string"] = body.decode("utf-8")
except UnicodeDecodeError:
pass
for processor in self.recording_processors:
response = processor.process_response(response)
if not response:
break
else:
for processor in self.replay_processors:
response = processor.process_response(response)
if not response:
break
return response
@classmethod
def _custom_request_query_matcher(cls, r1, r2):
""" Ensure method, path, and query parameters match. """
from six.moves.urllib_parse import urlparse, parse_qs # pylint: disable=import-error,relative-import
url1 = urlparse(r1.uri)
url2 = urlparse(r2.uri)
q1 = parse_qs(url1.query)
q2 = parse_qs(url2.query)
shared_keys = set(q1.keys()).intersection(set(q2.keys()))
if len(shared_keys) != len(q1) or len(shared_keys) != len(q2):
return False
for key in shared_keys:
if q1[key][0].lower() != q2[key][0].lower():
return False
return True
|
mit
|
[
3,
5620,
777,
4559,
199,
3,
1898,
334,
67,
9,
15332,
11098,
14,
2900,
4481,
4644,
14,
199,
3,
3909,
1334,
314,
10697,
844,
14,
1666,
844,
14,
2424,
315,
314,
2199,
1738,
367,
4190,
2556,
14,
199,
3,
5620,
777,
4559,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
646,
2882,
199,
646,
747,
199,
646,
6485,
199,
646,
5549,
199,
646,
5145,
199,
646,
2050,
199,
646,
5796,
199,
646,
3816,
199,
646,
373,
1556,
199,
199,
504,
1275,
888,
492,
1379,
2028,
199,
504,
1275,
1297,
492,
5070,
54,
63,
2864,
63,
1914,
1254,
2826,
899,
199,
504,
1275,
16355,
492,
1218,
63,
2355,
63,
354,
12,
485,
14954,
63,
1310,
63,
2030,
199,
504,
1275,
11582,
492,
12166,
63,
2118,
421,
199,
533,
27561,
14440,
8,
2796,
14,
1746,
304,
272,
347,
636,
826,
721,
277,
12,
1083,
63,
354,
304,
267,
1613,
8,
20405,
14440,
12,
291,
2843,
826,
721,
765,
63,
354,
9,
267,
291,
14,
6706,
21085,
275,
747,
14,
2314,
14,
362,
8,
9984,
63,
2864,
63,
1914,
1254,
2826,
899,
12,
488,
9,
508,
298,
549,
2,
267,
291,
14,
2921,
275,
2050,
14,
5572,
480,
9078,
63,
32355,
14,
13444,
63,
2219,
531,
339,
347,
1218,
63,
2355,
63,
354,
8,
277,
12,
2403,
12,
2582,
304,
221,
327,
4287,
26,
3507,
29,
889,
13,
277,
13,
1180,
267,
372,
1218,
63,
2355,
63,
354,
8,
1861,
29,
1861,
12,
2582,
29,
1267,
9,
339,
347,
1218,
63,
808,
63,
493,
8,
277,
12,
1568,
63,
7862,
12,
2615,
63,
2355,
29,
797,
304,
267,
408,
2790,
282,
7937,
570,
367,
5343,
14,
710,
511,
20458,
911,
3145,
314,
570,
5309,
1565,
9332,
3224,
14,
408,
267,
6111,
12,
931,
275,
5549,
14,
17721,
342,
267,
747,
14,
1600,
8,
2592,
9,
267,
291,
14,
12808,
8,
2734,
26,
747,
14,
2168,
8,
515,
430,
398,
543,
1551,
8,
515,
12,
818,
628,
82,
11,
66,
531,
465,
289,
26,
288,
340,
2615,
63,
2355,
26,
355,
3728,
275,
747,
14,
22776,
8,
7727,
9,
288,
587,
26,
355,
3728,
275,
11640,
779,
16,
61,
627,
6619,
9,
288,
367,
485,
315,
1425,
8,
890,
63,
7862,
304,
355,
289,
14,
952,
8,
4604,
9,
398,
372,
931,
339,
347,
1218,
63,
808,
63,
694,
8,
277,
304,
267,
408,
267,
2790,
282,
7937,
2082,
367,
5343,
14,
710,
511,
20458,
911,
3145,
314,
2082,
5309,
1565,
9332,
3224,
14,
267,
408,
267,
2388,
63,
694,
275,
5549,
14,
11983,
342,
267,
291,
14,
12808,
8,
2734,
26,
5145,
14,
9242,
8,
808,
63,
694,
12,
3686,
63,
2550,
29,
549,
430,
398,
372,
2388,
63,
694,
339,
768,
3744,
272,
347,
663,
63,
1813,
8,
1886,
12,
790,
12,
1139,
304,
267,
747,
14,
2314,
59,
498,
61,
275,
1139,
339,
768,
3744,
272,
347,
4560,
63,
1813,
8,
1886,
12,
790,
304,
267,
372,
747,
14,
2314,
14,
1935,
8,
498,
12,
488,
9,
421,
199,
32,
6442,
63,
2118,
342,
199,
533,
24683,
774,
8,
20405,
14440,
304,
272,
986,
421,
199,
533,
799,
2802,
461,
774,
8,
20405,
14440,
304,
221,
327,
4287,
26,
3507,
29,
7354,
13,
3479,
13,
842,
13,
2987,
272,
23244,
63,
21178,
275,
359,
267,
298,
15846,
401,
267,
298,
1258,
13,
1069,
13,
344,
401,
267,
298,
7154,
13,
4399,
401,
267,
298,
88,
13,
706,
13,
1258,
13,
1069,
13,
344,
401,
267,
298,
88,
13,
706,
13,
26487,
13,
1069,
13,
344,
401,
267,
298,
88,
13,
706,
13,
1866,
3097,
13,
11266,
13,
6645,
13,
15656,
401,
267,
298,
88,
13,
706,
13,
1069,
13,
344,
401,
267,
298,
88,
13,
706,
13,
9492,
13,
1069,
13,
344,
401,
267,
298,
88,
13,
706,
13,
7019,
13,
1364,
13,
842,
344,
401,
267,
298,
88,
13,
706,
13,
1866,
3097,
13,
11266,
13,
4647,
13,
15656,
401,
267,
298,
88,
13,
706,
13,
2485,
13,
991,
401,
267,
298,
88,
13,
706,
13,
15846,
13,
10962,
20524,
401,
272,
1622,
339,
347,
636,
826,
721,
267,
291,
12,
221,
327,
4287,
26,
3507,
29,
7354,
13,
3479,
13,
4958,
267,
1083,
63,
354,
12,
267,
1101,
63,
493,
29,
403,
12,
267,
20952,
63,
694,
29,
403,
12,
267,
20952,
63,
354,
29,
403,
12,
267,
20952,
63,
10547,
29,
403,
12,
267,
24331,
63,
10547,
29,
403,
12,
267,
20952,
63,
11350,
29,
403,
12,
267,
24331,
63,
11350,
29,
403,
12,
267,
1336,
63,
2030,
29,
797,
12,
267,
3537,
63,
1069,
63,
1431,
1192,
29,
403,
12,
272,
3461,
267,
1613,
8,
11657,
461,
774,
12,
291,
2843,
826,
721,
765,
63,
354,
9,
398,
291,
14,
24616,
63,
10547,
275,
20952,
63,
10547,
503,
942,
267,
291,
14,
19540,
63,
10547,
275,
24331,
63,
10547,
503,
942,
398,
291,
14,
24616,
63,
11350,
275,
20952,
63,
11350,
503,
942,
267,
291,
14,
19540,
63,
11350,
275,
24331,
63,
11350,
503,
942,
398,
291,
14,
888,
275,
1379,
2028,
8,
888,
63,
493,
29,
888,
63,
493,
9,
398,
291,
14,
5993,
63,
24616,
275,
756,
398,
511,
63,
493,
63,
515,
275,
6485,
14,
23462,
8,
277,
855,
533,
3368,
267,
20952,
63,
694,
275,
20952,
63,
694,
503,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
8,
396,
63,
493,
63,
515,
395,
298,
3059,
780,
531,
267,
291,
14,
374,
63,
6442,
275,
291,
14,
888,
14,
3059,
63,
632,
398,
291,
14,
86,
1556,
275,
373,
1556,
14,
54,
2944,
8,
288,
286,
6562,
266,
63,
4342,
63,
694,
29,
24616,
63,
694,
12,
288,
2544,
63,
3059,
63,
1069,
29,
277,
423,
1412,
63,
1069,
63,
24616,
12,
288,
2544,
63,
3059,
63,
1310,
29,
277,
423,
1412,
63,
1310,
63,
24616,
12,
288,
4849,
63,
10895,
63,
1310,
29,
549,
12,
288,
2777,
63,
632,
628,
5089,
2,
340,
440,
291,
14,
374,
63,
6442,
587,
298,
452,
401,
288,
2457,
63,
2139,
29,
277,
14,
9905,
63,
21178,
12,
267,
776,
267,
291,
14,
86,
1556,
14,
2683,
63,
16135,
480,
1131,
401,
291,
423
] |
[
5620,
777,
4559,
199,
3,
1898,
334,
67,
9,
15332,
11098,
14,
2900,
4481,
4644,
14,
199,
3,
3909,
1334,
314,
10697,
844,
14,
1666,
844,
14,
2424,
315,
314,
2199,
1738,
367,
4190,
2556,
14,
199,
3,
5620,
777,
4559,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
646,
2882,
199,
646,
747,
199,
646,
6485,
199,
646,
5549,
199,
646,
5145,
199,
646,
2050,
199,
646,
5796,
199,
646,
3816,
199,
646,
373,
1556,
199,
199,
504,
1275,
888,
492,
1379,
2028,
199,
504,
1275,
1297,
492,
5070,
54,
63,
2864,
63,
1914,
1254,
2826,
899,
199,
504,
1275,
16355,
492,
1218,
63,
2355,
63,
354,
12,
485,
14954,
63,
1310,
63,
2030,
199,
504,
1275,
11582,
492,
12166,
63,
2118,
421,
199,
533,
27561,
14440,
8,
2796,
14,
1746,
304,
272,
347,
636,
826,
721,
277,
12,
1083,
63,
354,
304,
267,
1613,
8,
20405,
14440,
12,
291,
2843,
826,
721,
765,
63,
354,
9,
267,
291,
14,
6706,
21085,
275,
747,
14,
2314,
14,
362,
8,
9984,
63,
2864,
63,
1914,
1254,
2826,
899,
12,
488,
9,
508,
298,
549,
2,
267,
291,
14,
2921,
275,
2050,
14,
5572,
480,
9078,
63,
32355,
14,
13444,
63,
2219,
531,
339,
347,
1218,
63,
2355,
63,
354,
8,
277,
12,
2403,
12,
2582,
304,
221,
327,
4287,
26,
3507,
29,
889,
13,
277,
13,
1180,
267,
372,
1218,
63,
2355,
63,
354,
8,
1861,
29,
1861,
12,
2582,
29,
1267,
9,
339,
347,
1218,
63,
808,
63,
493,
8,
277,
12,
1568,
63,
7862,
12,
2615,
63,
2355,
29,
797,
304,
267,
408,
2790,
282,
7937,
570,
367,
5343,
14,
710,
511,
20458,
911,
3145,
314,
570,
5309,
1565,
9332,
3224,
14,
408,
267,
6111,
12,
931,
275,
5549,
14,
17721,
342,
267,
747,
14,
1600,
8,
2592,
9,
267,
291,
14,
12808,
8,
2734,
26,
747,
14,
2168,
8,
515,
430,
398,
543,
1551,
8,
515,
12,
818,
628,
82,
11,
66,
531,
465,
289,
26,
288,
340,
2615,
63,
2355,
26,
355,
3728,
275,
747,
14,
22776,
8,
7727,
9,
288,
587,
26,
355,
3728,
275,
11640,
779,
16,
61,
627,
6619,
9,
288,
367,
485,
315,
1425,
8,
890,
63,
7862,
304,
355,
289,
14,
952,
8,
4604,
9,
398,
372,
931,
339,
347,
1218,
63,
808,
63,
694,
8,
277,
304,
267,
408,
267,
2790,
282,
7937,
2082,
367,
5343,
14,
710,
511,
20458,
911,
3145,
314,
2082,
5309,
1565,
9332,
3224,
14,
267,
408,
267,
2388,
63,
694,
275,
5549,
14,
11983,
342,
267,
291,
14,
12808,
8,
2734,
26,
5145,
14,
9242,
8,
808,
63,
694,
12,
3686,
63,
2550,
29,
549,
430,
398,
372,
2388,
63,
694,
339,
768,
3744,
272,
347,
663,
63,
1813,
8,
1886,
12,
790,
12,
1139,
304,
267,
747,
14,
2314,
59,
498,
61,
275,
1139,
339,
768,
3744,
272,
347,
4560,
63,
1813,
8,
1886,
12,
790,
304,
267,
372,
747,
14,
2314,
14,
1935,
8,
498,
12,
488,
9,
421,
199,
32,
6442,
63,
2118,
342,
199,
533,
24683,
774,
8,
20405,
14440,
304,
272,
986,
421,
199,
533,
799,
2802,
461,
774,
8,
20405,
14440,
304,
221,
327,
4287,
26,
3507,
29,
7354,
13,
3479,
13,
842,
13,
2987,
272,
23244,
63,
21178,
275,
359,
267,
298,
15846,
401,
267,
298,
1258,
13,
1069,
13,
344,
401,
267,
298,
7154,
13,
4399,
401,
267,
298,
88,
13,
706,
13,
1258,
13,
1069,
13,
344,
401,
267,
298,
88,
13,
706,
13,
26487,
13,
1069,
13,
344,
401,
267,
298,
88,
13,
706,
13,
1866,
3097,
13,
11266,
13,
6645,
13,
15656,
401,
267,
298,
88,
13,
706,
13,
1069,
13,
344,
401,
267,
298,
88,
13,
706,
13,
9492,
13,
1069,
13,
344,
401,
267,
298,
88,
13,
706,
13,
7019,
13,
1364,
13,
842,
344,
401,
267,
298,
88,
13,
706,
13,
1866,
3097,
13,
11266,
13,
4647,
13,
15656,
401,
267,
298,
88,
13,
706,
13,
2485,
13,
991,
401,
267,
298,
88,
13,
706,
13,
15846,
13,
10962,
20524,
401,
272,
1622,
339,
347,
636,
826,
721,
267,
291,
12,
221,
327,
4287,
26,
3507,
29,
7354,
13,
3479,
13,
4958,
267,
1083,
63,
354,
12,
267,
1101,
63,
493,
29,
403,
12,
267,
20952,
63,
694,
29,
403,
12,
267,
20952,
63,
354,
29,
403,
12,
267,
20952,
63,
10547,
29,
403,
12,
267,
24331,
63,
10547,
29,
403,
12,
267,
20952,
63,
11350,
29,
403,
12,
267,
24331,
63,
11350,
29,
403,
12,
267,
1336,
63,
2030,
29,
797,
12,
267,
3537,
63,
1069,
63,
1431,
1192,
29,
403,
12,
272,
3461,
267,
1613,
8,
11657,
461,
774,
12,
291,
2843,
826,
721,
765,
63,
354,
9,
398,
291,
14,
24616,
63,
10547,
275,
20952,
63,
10547,
503,
942,
267,
291,
14,
19540,
63,
10547,
275,
24331,
63,
10547,
503,
942,
398,
291,
14,
24616,
63,
11350,
275,
20952,
63,
11350,
503,
942,
267,
291,
14,
19540,
63,
11350,
275,
24331,
63,
11350,
503,
942,
398,
291,
14,
888,
275,
1379,
2028,
8,
888,
63,
493,
29,
888,
63,
493,
9,
398,
291,
14,
5993,
63,
24616,
275,
756,
398,
511,
63,
493,
63,
515,
275,
6485,
14,
23462,
8,
277,
855,
533,
3368,
267,
20952,
63,
694,
275,
20952,
63,
694,
503,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
8,
396,
63,
493,
63,
515,
395,
298,
3059,
780,
531,
267,
291,
14,
374,
63,
6442,
275,
291,
14,
888,
14,
3059,
63,
632,
398,
291,
14,
86,
1556,
275,
373,
1556,
14,
54,
2944,
8,
288,
286,
6562,
266,
63,
4342,
63,
694,
29,
24616,
63,
694,
12,
288,
2544,
63,
3059,
63,
1069,
29,
277,
423,
1412,
63,
1069,
63,
24616,
12,
288,
2544,
63,
3059,
63,
1310,
29,
277,
423,
1412,
63,
1310,
63,
24616,
12,
288,
4849,
63,
10895,
63,
1310,
29,
549,
12,
288,
2777,
63,
632,
628,
5089,
2,
340,
440,
291,
14,
374,
63,
6442,
587,
298,
452,
401,
288,
2457,
63,
2139,
29,
277,
14,
9905,
63,
21178,
12,
267,
776,
267,
291,
14,
86,
1556,
14,
2683,
63,
16135,
480,
1131,
401,
291,
423,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
linhdh/SnakeRepellerOnMbed50
|
mbed-os/tools/compliance/ioper_test_target_id.py
|
106
|
5090
|
"""
mbed SDK
Copyright (c) 2011-2015 ARM Limited
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Author: Przemyslaw Wirkus <Przemyslaw.Wirkus@arm.com>
"""
from ioper_base import IOperTestCaseBase
class IOperTest_TargetID(IOperTestCaseBase):
""" tests related to target_id value
"""
def __init__(self, scope=None):
IOperTestCaseBase.__init__(self, scope)
self.TARGET_ID_LEN = 24
def test_target_id_format(self, target_id, target_id_name):
# Expected length == 24, eg. "02400203D94B0E7724B7F3CF"
result = []
target_id_len = len(target_id) if target_id else 0
if target_id_len == self.TARGET_ID_LEN:
result.append((self.PASS, "TARGET_ID_LEN", self.scope, "%s '%s' is %d chars long " % (target_id_name, target_id, target_id_len)))
result.append((self.INFO, "FW_VER_STR", self.scope, "%s Version String is %s.%s.%s " % (target_id_name,
target_id[0:4],
target_id[4:8],
target_id[8:24],
)))
else:
result.append((self.ERROR, "TARGET_ID_LEN", self.scope, "%s '%s' is %d chars long. Expected %d chars" % (target_id_name, target_id, target_id_len, self.TARGET_ID_LEN)))
return result
def test_decode_target_id(self, target_id, target_id_name):
result = []
target_id_len = len(target_id) if target_id else 0
if target_id_len >= 4:
result.append((self.INFO, "FW_VEN_CODE", self.scope, "%s Vendor Code is '%s'" % (target_id_name, target_id[0:2])))
result.append((self.INFO, "FW_PLAT_CODE", self.scope, "%s Platform Code is '%s'" % (target_id_name, target_id[2:4])))
result.append((self.INFO, "FW_VER", self.scope, "%s Firmware Version is '%s'" % (target_id_name, target_id[4:8])))
result.append((self.INFO, "FW_HASH_SEC", self.scope, "%s Hash of secret is '%s'" % (target_id_name, target_id[8:24])))
return result
def test(self, param=None):
result = []
if param:
pass
return result
class IOperTest_TargetID_Basic(IOperTest_TargetID):
""" Basic interoperability tests checking TargetID compliance
"""
def __init__(self, scope=None):
IOperTest_TargetID.__init__(self, scope)
def test(self, param=None):
result = []
if param:
result.append((self.PASS, "TARGET_ID", self.scope, "TargetID '%s' found" % param['target_id']))
# Check if target name can be decoded with mbed-ls
if param['platform_name']:
result.append((self.PASS, "TARGET_ID_DECODE", self.scope, "TargetID '%s' decoded as '%s'" % (param['target_id'][0:4], param['platform_name'])))
else:
result.append((self.ERROR, "TARGET_ID_DECODE", self.scope, "TargetID '%s'... not decoded" % (param['target_id'] if param['target_id'] else '')))
# Test for USBID and mbed.htm consistency
if param['target_id_mbed_htm'] == param['target_id_usb_id']:
result.append((self.PASS, "TARGET_ID_MATCH", self.scope, "TargetID (USBID) and TargetID (mbed.htm) match"))
else:
text = "TargetID (USBID) and TargetID (mbed.htm) don't match: '%s' != '%s'" % (param['target_id_usb_id'], param['target_id_mbed_htm'])
result.append((self.WARN, "TARGET_ID_MATCH", self.scope, text))
else:
result.append((self.ERROR, "TARGET_ID", self.scope, "TargetID not found"))
return result
class IOperTest_TargetID_MbedEnabled(IOperTest_TargetID):
""" Basic interoperability tests checking TargetID compliance
"""
def __init__(self, scope=None):
IOperTest_TargetID.__init__(self, scope)
def test(self, param=None):
result = []
if param:
# Target ID tests:
result += self.test_target_id_format(param['target_id_usb_id'], "TargetId (USBID)")
result += self.test_target_id_format(param['target_id_mbed_htm'], "TargetId (mbed.htm)")
# Some extra info about TargetID itself
result += self.test_decode_target_id(param['target_id_usb_id'], "TargetId (USBID)")
result += self.test_decode_target_id(param['target_id_mbed_htm'], "TargetId (mbed.htm)")
return result
|
gpl-2.0
|
[
624,
199,
3665,
15610,
199,
7384,
334,
67,
9,
7760,
13,
7806,
27155,
23954,
199,
199,
31661,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
13297,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
5556,
1443,
3332,
282,
1331,
402,
314,
844,
737,
339,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
199,
5524,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
16832,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
29946,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
9295,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3097,
1298,
1334,
314,
844,
14,
199,
199,
5949,
26,
25716,
806,
23726,
22277,
644,
723,
75,
527,
665,
9779,
806,
23726,
22277,
14,
55,
723,
75,
527,
32,
5362,
14,
957,
30,
199,
199,
624,
199,
199,
504,
284,
2262,
63,
1095,
492,
473,
3632,
1746,
1563,
421,
199,
533,
473,
3632,
774,
63,
4277,
998,
8,
2090,
529,
1746,
1563,
304,
272,
408,
2295,
4048,
370,
1347,
63,
344,
574,
272,
408,
339,
347,
636,
826,
721,
277,
12,
4194,
29,
403,
304,
267,
473,
3632,
1746,
1563,
855,
826,
721,
277,
12,
4194,
9,
267,
291,
14,
9268,
63,
998,
63,
5304,
275,
5504,
339,
347,
511,
63,
1375,
63,
344,
63,
908,
8,
277,
12,
1347,
63,
344,
12,
1347,
63,
344,
63,
354,
304,
267,
327,
13796,
2582,
508,
5504,
12,
11837,
14,
298,
5284,
383,
11341,
36,
2635,
34,
16,
37,
1138,
1194,
34,
23,
38,
19,
5487,
2,
267,
754,
275,
942,
267,
1347,
63,
344,
63,
552,
275,
822,
8,
1375,
63,
344,
9,
340,
1347,
63,
344,
587,
378,
267,
340,
1347,
63,
344,
63,
552,
508,
291,
14,
9268,
63,
998,
63,
5304,
26,
288,
754,
14,
740,
1332,
277,
14,
6909,
12,
298,
9268,
63,
998,
63,
5304,
401,
291,
14,
2645,
12,
2071,
83,
1543,
83,
7,
365,
450,
68,
8365,
1846,
298,
450,
334,
1375,
63,
344,
63,
354,
12,
1347,
63,
344,
12,
1347,
63,
344,
63,
552,
1724,
288,
754,
14,
740,
1332,
277,
14,
4531,
12,
298,
19445,
63,
2111,
63,
3027,
401,
291,
14,
2645,
12,
2071,
83,
3394,
2624,
365,
450,
83,
4111,
83,
4111,
83,
298,
450,
334,
1375,
63,
344,
63,
354,
12,
12268,
420,
1347,
63,
344,
59,
16,
26,
20,
467,
12268,
420,
1347,
63,
344,
59,
20,
26,
24,
467,
12268,
420,
1347,
63,
344,
59,
24,
26,
1194,
467,
12268,
420,
23183,
267,
587,
26,
288,
754,
14,
740,
1332,
277,
14,
3170,
12,
298,
9268,
63,
998,
63,
5304,
401,
291,
14,
2645,
12,
2071,
83,
1543,
83,
7,
365,
450,
68,
8365,
1846,
14,
13796,
450,
68,
8365,
2,
450,
334,
1375,
63,
344,
63,
354,
12,
1347,
63,
344,
12,
1347,
63,
344,
63,
552,
12,
291,
14,
9268,
63,
998,
63,
5304,
1724,
267,
372,
754,
339,
347,
511,
63,
2708,
63,
1375,
63,
344,
8,
277,
12,
1347,
63,
344,
12,
1347,
63,
344,
63,
354,
304,
267,
754,
275,
942,
267,
1347,
63,
344,
63,
552,
275,
822,
8,
1375,
63,
344,
9,
340,
1347,
63,
344,
587,
378,
267,
340,
1347,
63,
344,
63,
552,
2356,
841,
26,
288,
754,
14,
740,
1332,
277,
14,
4531,
12,
298,
19445,
63,
8253,
63,
6012,
401,
291,
14,
2645,
12,
2071,
83,
812,
7454,
5495,
365,
1543,
83,
4065,
450,
334,
1375,
63,
344,
63,
354,
12,
1347,
63,
344,
59,
16,
26,
18,
11845,
288,
754,
14,
740,
1332,
277,
14,
4531,
12,
298,
19445,
63,
2749,
619,
63,
6012,
401,
291,
14,
2645,
12,
2071,
83,
16078,
5495,
365,
1543,
83,
4065,
450,
334,
1375,
63,
344,
63,
354,
12,
1347,
63,
344,
59,
18,
26,
20,
11845,
288,
754,
14,
740,
1332,
277,
14,
4531,
12,
298,
19445,
63,
2111,
401,
291,
14,
2645,
12,
2071,
83,
481,
20678,
3394,
365,
1543,
83,
4065,
450,
334,
1375,
63,
344,
63,
354,
12,
1347,
63,
344,
59,
20,
26,
24,
11845,
288,
754,
14,
740,
1332,
277,
14,
4531,
12,
298,
19445,
63,
14395,
63,
15048,
401,
291,
14,
2645,
12,
2071,
83,
16101,
402,
7565,
365,
1543,
83,
4065,
450,
334,
1375,
63,
344,
63,
354,
12,
1347,
63,
344,
59,
24,
26,
1194,
11845,
267,
372,
754,
339,
347,
511,
8,
277,
12,
1215,
29,
403,
304,
267,
754,
275,
942,
267,
340,
1215,
26,
288,
986,
267,
372,
754,
421,
199,
533,
473,
3632,
774,
63,
4277,
998,
63,
6845,
8,
2090,
529,
774,
63,
4277,
998,
304,
272,
408,
10082,
4661,
9198,
3616,
2295,
7907,
10256,
998,
4151,
272,
408,
339,
347,
636,
826,
721,
277,
12,
4194,
29,
403,
304,
267,
473,
3632,
774,
63,
4277,
998,
855,
826,
721,
277,
12,
4194,
9,
339,
347,
511,
8,
277,
12,
1215,
29,
403,
304,
267,
754,
275,
942,
398,
340,
1215,
26,
288,
754,
14,
740,
1332,
277,
14,
6909,
12,
298,
9268,
63,
998,
401,
291,
14,
2645,
12,
298,
4277,
998,
1543,
83,
7,
1911,
2,
450,
1215,
459,
1375,
63,
344,
5156,
953,
327,
2670,
340,
1347,
536,
883,
506,
11203,
543,
333,
6123,
13,
478,
288,
340,
1215,
459,
3246,
63,
354,
2565,
355,
754,
14,
740,
1332,
277,
14,
6909,
12,
298,
9268,
63,
998,
63,
1093,
6012,
401,
291,
14,
2645,
12,
298,
4277,
998,
1543,
83,
7,
11203,
465,
1543,
83,
4065,
450,
334,
635,
459,
1375,
63,
344,
3488,
16,
26,
20,
467,
1215,
459,
3246,
63,
354,
26991,
288,
587,
26,
355,
754,
14,
740,
1332,
277,
14,
3170,
12,
298,
9268,
63,
998,
63,
1093,
6012,
401,
291,
14,
2645,
12,
298,
4277,
998,
1543,
83,
7,
1396,
440,
11203,
2,
450,
334,
635,
459,
1375,
63,
344,
418,
340,
1215,
459,
1375,
63,
344,
418,
587,
4074,
430,
953,
327,
1379,
367,
28655,
998,
436,
333,
6123,
14,
15575,
17754,
288,
340,
1215,
459,
1375,
63,
344,
63,
3665,
63,
15575
] |
[
199,
3665,
15610,
199,
7384,
334,
67,
9,
7760,
13,
7806,
27155,
23954,
199,
199,
31661,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
13297,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
5556,
1443,
3332,
282,
1331,
402,
314,
844,
737,
339,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
199,
5524,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
16832,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
29946,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
9295,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3097,
1298,
1334,
314,
844,
14,
199,
199,
5949,
26,
25716,
806,
23726,
22277,
644,
723,
75,
527,
665,
9779,
806,
23726,
22277,
14,
55,
723,
75,
527,
32,
5362,
14,
957,
30,
199,
199,
624,
199,
199,
504,
284,
2262,
63,
1095,
492,
473,
3632,
1746,
1563,
421,
199,
533,
473,
3632,
774,
63,
4277,
998,
8,
2090,
529,
1746,
1563,
304,
272,
408,
2295,
4048,
370,
1347,
63,
344,
574,
272,
408,
339,
347,
636,
826,
721,
277,
12,
4194,
29,
403,
304,
267,
473,
3632,
1746,
1563,
855,
826,
721,
277,
12,
4194,
9,
267,
291,
14,
9268,
63,
998,
63,
5304,
275,
5504,
339,
347,
511,
63,
1375,
63,
344,
63,
908,
8,
277,
12,
1347,
63,
344,
12,
1347,
63,
344,
63,
354,
304,
267,
327,
13796,
2582,
508,
5504,
12,
11837,
14,
298,
5284,
383,
11341,
36,
2635,
34,
16,
37,
1138,
1194,
34,
23,
38,
19,
5487,
2,
267,
754,
275,
942,
267,
1347,
63,
344,
63,
552,
275,
822,
8,
1375,
63,
344,
9,
340,
1347,
63,
344,
587,
378,
267,
340,
1347,
63,
344,
63,
552,
508,
291,
14,
9268,
63,
998,
63,
5304,
26,
288,
754,
14,
740,
1332,
277,
14,
6909,
12,
298,
9268,
63,
998,
63,
5304,
401,
291,
14,
2645,
12,
2071,
83,
1543,
83,
7,
365,
450,
68,
8365,
1846,
298,
450,
334,
1375,
63,
344,
63,
354,
12,
1347,
63,
344,
12,
1347,
63,
344,
63,
552,
1724,
288,
754,
14,
740,
1332,
277,
14,
4531,
12,
298,
19445,
63,
2111,
63,
3027,
401,
291,
14,
2645,
12,
2071,
83,
3394,
2624,
365,
450,
83,
4111,
83,
4111,
83,
298,
450,
334,
1375,
63,
344,
63,
354,
12,
12268,
420,
1347,
63,
344,
59,
16,
26,
20,
467,
12268,
420,
1347,
63,
344,
59,
20,
26,
24,
467,
12268,
420,
1347,
63,
344,
59,
24,
26,
1194,
467,
12268,
420,
23183,
267,
587,
26,
288,
754,
14,
740,
1332,
277,
14,
3170,
12,
298,
9268,
63,
998,
63,
5304,
401,
291,
14,
2645,
12,
2071,
83,
1543,
83,
7,
365,
450,
68,
8365,
1846,
14,
13796,
450,
68,
8365,
2,
450,
334,
1375,
63,
344,
63,
354,
12,
1347,
63,
344,
12,
1347,
63,
344,
63,
552,
12,
291,
14,
9268,
63,
998,
63,
5304,
1724,
267,
372,
754,
339,
347,
511,
63,
2708,
63,
1375,
63,
344,
8,
277,
12,
1347,
63,
344,
12,
1347,
63,
344,
63,
354,
304,
267,
754,
275,
942,
267,
1347,
63,
344,
63,
552,
275,
822,
8,
1375,
63,
344,
9,
340,
1347,
63,
344,
587,
378,
267,
340,
1347,
63,
344,
63,
552,
2356,
841,
26,
288,
754,
14,
740,
1332,
277,
14,
4531,
12,
298,
19445,
63,
8253,
63,
6012,
401,
291,
14,
2645,
12,
2071,
83,
812,
7454,
5495,
365,
1543,
83,
4065,
450,
334,
1375,
63,
344,
63,
354,
12,
1347,
63,
344,
59,
16,
26,
18,
11845,
288,
754,
14,
740,
1332,
277,
14,
4531,
12,
298,
19445,
63,
2749,
619,
63,
6012,
401,
291,
14,
2645,
12,
2071,
83,
16078,
5495,
365,
1543,
83,
4065,
450,
334,
1375,
63,
344,
63,
354,
12,
1347,
63,
344,
59,
18,
26,
20,
11845,
288,
754,
14,
740,
1332,
277,
14,
4531,
12,
298,
19445,
63,
2111,
401,
291,
14,
2645,
12,
2071,
83,
481,
20678,
3394,
365,
1543,
83,
4065,
450,
334,
1375,
63,
344,
63,
354,
12,
1347,
63,
344,
59,
20,
26,
24,
11845,
288,
754,
14,
740,
1332,
277,
14,
4531,
12,
298,
19445,
63,
14395,
63,
15048,
401,
291,
14,
2645,
12,
2071,
83,
16101,
402,
7565,
365,
1543,
83,
4065,
450,
334,
1375,
63,
344,
63,
354,
12,
1347,
63,
344,
59,
24,
26,
1194,
11845,
267,
372,
754,
339,
347,
511,
8,
277,
12,
1215,
29,
403,
304,
267,
754,
275,
942,
267,
340,
1215,
26,
288,
986,
267,
372,
754,
421,
199,
533,
473,
3632,
774,
63,
4277,
998,
63,
6845,
8,
2090,
529,
774,
63,
4277,
998,
304,
272,
408,
10082,
4661,
9198,
3616,
2295,
7907,
10256,
998,
4151,
272,
408,
339,
347,
636,
826,
721,
277,
12,
4194,
29,
403,
304,
267,
473,
3632,
774,
63,
4277,
998,
855,
826,
721,
277,
12,
4194,
9,
339,
347,
511,
8,
277,
12,
1215,
29,
403,
304,
267,
754,
275,
942,
398,
340,
1215,
26,
288,
754,
14,
740,
1332,
277,
14,
6909,
12,
298,
9268,
63,
998,
401,
291,
14,
2645,
12,
298,
4277,
998,
1543,
83,
7,
1911,
2,
450,
1215,
459,
1375,
63,
344,
5156,
953,
327,
2670,
340,
1347,
536,
883,
506,
11203,
543,
333,
6123,
13,
478,
288,
340,
1215,
459,
3246,
63,
354,
2565,
355,
754,
14,
740,
1332,
277,
14,
6909,
12,
298,
9268,
63,
998,
63,
1093,
6012,
401,
291,
14,
2645,
12,
298,
4277,
998,
1543,
83,
7,
11203,
465,
1543,
83,
4065,
450,
334,
635,
459,
1375,
63,
344,
3488,
16,
26,
20,
467,
1215,
459,
3246,
63,
354,
26991,
288,
587,
26,
355,
754,
14,
740,
1332,
277,
14,
3170,
12,
298,
9268,
63,
998,
63,
1093,
6012,
401,
291,
14,
2645,
12,
298,
4277,
998,
1543,
83,
7,
1396,
440,
11203,
2,
450,
334,
635,
459,
1375,
63,
344,
418,
340,
1215,
459,
1375,
63,
344,
418,
587,
4074,
430,
953,
327,
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
] |
kevalds51/sympy
|
sympy/matrices/expressions/tests/test_transpose.py
|
71
|
1194
|
from sympy.functions import adjoint, conjugate, transpose
from sympy.matrices.expressions import MatrixSymbol, Adjoint, trace, Transpose
from sympy.matrices import eye, Matrix
from sympy import symbols, S
from sympy import refine, Q
n, m, l, k, p = symbols('n m l k p', integer=True)
A = MatrixSymbol('A', n, m)
B = MatrixSymbol('B', m, l)
C = MatrixSymbol('C', n, n)
def test_transpose():
Sq = MatrixSymbol('Sq', n, n)
assert transpose(A) == Transpose(A)
assert Transpose(A).shape == (m, n)
assert Transpose(A*B).shape == (l, n)
assert transpose(Transpose(A)) == A
assert isinstance(Transpose(Transpose(A)), Transpose)
assert adjoint(Transpose(A)) == Adjoint(Transpose(A))
assert conjugate(Transpose(A)) == Adjoint(A)
assert Transpose(eye(3)).doit() == eye(3)
assert Transpose(S(5)).doit() == S(5)
assert Transpose(Matrix([[1, 2], [3, 4]])).doit() == Matrix([[1, 3], [2, 4]])
assert transpose(trace(Sq)) == trace(Sq)
assert trace(Transpose(Sq)) == trace(Sq)
assert Transpose(Sq)[0, 1] == Sq[1, 0]
assert Transpose(A*B).doit() == Transpose(B) * Transpose(A)
def test_refine():
assert refine(C.T, Q.symmetric(C)) == C
|
bsd-3-clause
|
[
504,
5840,
14,
5777,
492,
24132,
12,
27246,
12,
16992,
199,
504,
5840,
14,
19032,
14,
15264,
492,
8449,
8169,
12,
4431,
10153,
12,
3307,
12,
6266,
4070,
199,
504,
5840,
14,
19032,
492,
25892,
12,
8449,
199,
504,
5840,
492,
6698,
12,
428,
199,
504,
5840,
492,
2984,
1132,
12,
1413,
199,
199,
78,
12,
333,
12,
634,
12,
1022,
12,
299,
275,
6698,
360,
78,
333,
634,
1022,
299,
297,
3000,
29,
549,
9,
199,
33,
275,
8449,
8169,
360,
33,
297,
302,
12,
333,
9,
199,
34,
275,
8449,
8169,
360,
34,
297,
333,
12,
634,
9,
199,
35,
275,
8449,
8169,
360,
35,
297,
302,
12,
302,
9,
421,
199,
318,
511,
63,
10483,
837,
272,
428,
81,
275,
8449,
8169,
360,
24614,
297,
302,
12,
302,
9,
339,
702,
16992,
8,
33,
9,
508,
6266,
4070,
8,
33,
9,
272,
702,
6266,
4070,
8,
33,
680,
1392,
508,
334,
77,
12,
302,
9,
272,
702,
6266,
4070,
8,
33,
10,
34,
680,
1392,
508,
334,
76,
12,
302,
9,
272,
702,
16992,
8,
3188,
4070,
8,
33,
430,
508,
437,
272,
702,
1228,
8,
3188,
4070,
8,
3188,
4070,
8,
33,
1826,
6266,
4070,
9,
339,
702,
24132,
8,
3188,
4070,
8,
33,
430,
508,
4431,
10153,
8,
3188,
4070,
8,
33,
430,
272,
702,
27246,
8,
3188,
4070,
8,
33,
430,
508,
4431,
10153,
8,
33,
9,
339,
702,
6266,
4070,
8,
15240,
8,
19,
4992,
19014,
342,
508,
25892,
8,
19,
9,
339,
702,
6266,
4070,
8,
51,
8,
21,
4992,
19014,
342,
508,
428,
8,
21,
9,
339,
702,
6266,
4070,
8,
6443,
4038,
17,
12,
499,
467,
359,
19,
12,
841,
17723,
14,
19014,
342,
508,
8449,
4038,
17,
12,
650,
467,
359,
18,
12,
841,
3934,
339,
702,
16992,
8,
3446,
8,
24614,
430,
508,
3307,
8,
24614,
9,
272,
702,
3307,
8,
3188,
4070,
8,
24614,
430,
508,
3307,
8,
24614,
9,
339,
702,
6266,
4070,
8,
24614,
2788,
16,
12,
413,
61,
508,
428,
81,
59,
17,
12,
378,
61,
339,
702,
6266,
4070,
8,
33,
10,
34,
680,
19014,
342,
508,
6266,
4070,
8,
34,
9,
627,
6266,
4070,
8,
33,
9,
421,
199,
318,
511,
63,
1121,
1132,
837,
272,
702,
2984,
1132,
8,
35,
14,
52,
12,
1413,
14,
18422,
8,
35,
430,
508,
445,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
5840,
14,
5777,
492,
24132,
12,
27246,
12,
16992,
199,
504,
5840,
14,
19032,
14,
15264,
492,
8449,
8169,
12,
4431,
10153,
12,
3307,
12,
6266,
4070,
199,
504,
5840,
14,
19032,
492,
25892,
12,
8449,
199,
504,
5840,
492,
6698,
12,
428,
199,
504,
5840,
492,
2984,
1132,
12,
1413,
199,
199,
78,
12,
333,
12,
634,
12,
1022,
12,
299,
275,
6698,
360,
78,
333,
634,
1022,
299,
297,
3000,
29,
549,
9,
199,
33,
275,
8449,
8169,
360,
33,
297,
302,
12,
333,
9,
199,
34,
275,
8449,
8169,
360,
34,
297,
333,
12,
634,
9,
199,
35,
275,
8449,
8169,
360,
35,
297,
302,
12,
302,
9,
421,
199,
318,
511,
63,
10483,
837,
272,
428,
81,
275,
8449,
8169,
360,
24614,
297,
302,
12,
302,
9,
339,
702,
16992,
8,
33,
9,
508,
6266,
4070,
8,
33,
9,
272,
702,
6266,
4070,
8,
33,
680,
1392,
508,
334,
77,
12,
302,
9,
272,
702,
6266,
4070,
8,
33,
10,
34,
680,
1392,
508,
334,
76,
12,
302,
9,
272,
702,
16992,
8,
3188,
4070,
8,
33,
430,
508,
437,
272,
702,
1228,
8,
3188,
4070,
8,
3188,
4070,
8,
33,
1826,
6266,
4070,
9,
339,
702,
24132,
8,
3188,
4070,
8,
33,
430,
508,
4431,
10153,
8,
3188,
4070,
8,
33,
430,
272,
702,
27246,
8,
3188,
4070,
8,
33,
430,
508,
4431,
10153,
8,
33,
9,
339,
702,
6266,
4070,
8,
15240,
8,
19,
4992,
19014,
342,
508,
25892,
8,
19,
9,
339,
702,
6266,
4070,
8,
51,
8,
21,
4992,
19014,
342,
508,
428,
8,
21,
9,
339,
702,
6266,
4070,
8,
6443,
4038,
17,
12,
499,
467,
359,
19,
12,
841,
17723,
14,
19014,
342,
508,
8449,
4038,
17,
12,
650,
467,
359,
18,
12,
841,
3934,
339,
702,
16992,
8,
3446,
8,
24614,
430,
508,
3307,
8,
24614,
9,
272,
702,
3307,
8,
3188,
4070,
8,
24614,
430,
508,
3307,
8,
24614,
9,
339,
702,
6266,
4070,
8,
24614,
2788,
16,
12,
413,
61,
508,
428,
81,
59,
17,
12,
378,
61,
339,
702,
6266,
4070,
8,
33,
10,
34,
680,
19014,
342,
508,
6266,
4070,
8,
34,
9,
627,
6266,
4070,
8,
33,
9,
421,
199,
318,
511,
63,
1121,
1132,
837,
272,
702,
2984,
1132,
8,
35,
14,
52,
12,
1413,
14,
18422,
8,
35,
430,
508,
445,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
mezz64/home-assistant
|
tests/components/sleepiq/test_sensor.py
|
5
|
1493
|
"""The tests for SleepIQ sensor platform."""
import homeassistant.components.sleepiq.sensor as sleepiq
from homeassistant.setup import async_setup_component
from tests.async_mock import MagicMock
from tests.components.sleepiq.test_init import mock_responses
CONFIG = {"username": "foo", "password": "bar"}
async def test_setup(hass, requests_mock):
"""Test for successfully setting up the SleepIQ platform."""
mock_responses(requests_mock)
assert await async_setup_component(hass, "sleepiq", {"sleepiq": CONFIG})
device_mock = MagicMock()
sleepiq.setup_platform(hass, CONFIG, device_mock, MagicMock())
devices = device_mock.call_args[0][0]
assert 2 == len(devices)
left_side = devices[1]
assert "SleepNumber ILE Test1 SleepNumber" == left_side.name
assert 40 == left_side.state
right_side = devices[0]
assert "SleepNumber ILE Test2 SleepNumber" == right_side.name
assert 80 == right_side.state
async def test_setup_sigle(hass, requests_mock):
"""Test for successfully setting up the SleepIQ platform."""
mock_responses(requests_mock, single=True)
assert await async_setup_component(hass, "sleepiq", {"sleepiq": CONFIG})
device_mock = MagicMock()
sleepiq.setup_platform(hass, CONFIG, device_mock, MagicMock())
devices = device_mock.call_args[0][0]
assert 1 == len(devices)
right_side = devices[0]
assert "SleepNumber ILE Test1 SleepNumber" == right_side.name
assert 40 == right_side.state
|
apache-2.0
|
[
624,
1918,
2295,
367,
428,
3614,
23559,
8778,
4298,
1041,
199,
646,
8846,
14,
4608,
14,
83,
18387,
1038,
81,
14,
8956,
465,
308,
18387,
1038,
81,
199,
504,
8846,
14,
2758,
492,
5316,
63,
2758,
63,
3173,
199,
199,
504,
2295,
14,
4146,
63,
1805,
492,
10079,
199,
504,
2295,
14,
4608,
14,
83,
18387,
1038,
81,
14,
396,
63,
826,
492,
1683,
63,
10360,
199,
199,
5569,
275,
2420,
2473,
582,
298,
1421,
401,
298,
2060,
582,
298,
1700,
3570,
421,
199,
4146,
347,
511,
63,
2758,
8,
5387,
12,
4145,
63,
1805,
304,
272,
408,
774,
367,
8792,
4260,
1536,
314,
428,
3614,
23559,
4298,
1041,
272,
1683,
63,
10360,
8,
6615,
63,
1805,
9,
339,
702,
5517,
5316,
63,
2758,
63,
3173,
8,
5387,
12,
298,
83,
18387,
1038,
81,
401,
2420,
83,
18387,
1038,
81,
582,
15869,
1552,
339,
2243,
63,
1805,
275,
10079,
342,
272,
308,
18387,
1038,
81,
14,
2758,
63,
3246,
8,
5387,
12,
15869,
12,
2243,
63,
1805,
12,
10079,
1012,
272,
7256,
275,
2243,
63,
1805,
14,
1250,
63,
589,
59,
16,
1527,
16,
61,
272,
702,
499,
508,
822,
8,
6410,
9,
339,
3602,
63,
2441,
275,
7256,
59,
17,
61,
272,
702,
298,
17306,
3259,
473,
906,
1379,
17,
428,
3614,
3259,
2,
508,
3602,
63,
2441,
14,
354,
272,
702,
6335,
508,
3602,
63,
2441,
14,
929,
339,
2451,
63,
2441,
275,
7256,
59,
16,
61,
272,
702,
298,
17306,
3259,
473,
906,
1379,
18,
428,
3614,
3259,
2,
508,
2451,
63,
2441,
14,
354,
272,
702,
5939,
508,
2451,
63,
2441,
14,
929,
421,
199,
4146,
347,
511,
63,
2758,
63,
338,
3845,
8,
5387,
12,
4145,
63,
1805,
304,
272,
408,
774,
367,
8792,
4260,
1536,
314,
428,
3614,
23559,
4298,
1041,
272,
1683,
63,
10360,
8,
6615,
63,
1805,
12,
2849,
29,
549,
9,
339,
702,
5517,
5316,
63,
2758,
63,
3173,
8,
5387,
12,
298,
83,
18387,
1038,
81,
401,
2420,
83,
18387,
1038,
81,
582,
15869,
1552,
339,
2243,
63,
1805,
275,
10079,
342,
272,
308,
18387,
1038,
81,
14,
2758,
63,
3246,
8,
5387,
12,
15869,
12,
2243,
63,
1805,
12,
10079,
1012,
272,
7256,
275,
2243,
63,
1805,
14,
1250,
63,
589,
59,
16,
1527,
16,
61,
272,
702,
413,
508,
822,
8,
6410,
9,
339,
2451,
63,
2441,
275,
7256,
59,
16,
61,
272,
702,
298,
17306,
3259,
473,
906,
1379,
17,
428,
3614,
3259,
2,
508,
2451,
63,
2441,
14,
354,
272,
702,
6335,
508,
2451,
63,
2441,
14,
929,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1918,
2295,
367,
428,
3614,
23559,
8778,
4298,
1041,
199,
646,
8846,
14,
4608,
14,
83,
18387,
1038,
81,
14,
8956,
465,
308,
18387,
1038,
81,
199,
504,
8846,
14,
2758,
492,
5316,
63,
2758,
63,
3173,
199,
199,
504,
2295,
14,
4146,
63,
1805,
492,
10079,
199,
504,
2295,
14,
4608,
14,
83,
18387,
1038,
81,
14,
396,
63,
826,
492,
1683,
63,
10360,
199,
199,
5569,
275,
2420,
2473,
582,
298,
1421,
401,
298,
2060,
582,
298,
1700,
3570,
421,
199,
4146,
347,
511,
63,
2758,
8,
5387,
12,
4145,
63,
1805,
304,
272,
408,
774,
367,
8792,
4260,
1536,
314,
428,
3614,
23559,
4298,
1041,
272,
1683,
63,
10360,
8,
6615,
63,
1805,
9,
339,
702,
5517,
5316,
63,
2758,
63,
3173,
8,
5387,
12,
298,
83,
18387,
1038,
81,
401,
2420,
83,
18387,
1038,
81,
582,
15869,
1552,
339,
2243,
63,
1805,
275,
10079,
342,
272,
308,
18387,
1038,
81,
14,
2758,
63,
3246,
8,
5387,
12,
15869,
12,
2243,
63,
1805,
12,
10079,
1012,
272,
7256,
275,
2243,
63,
1805,
14,
1250,
63,
589,
59,
16,
1527,
16,
61,
272,
702,
499,
508,
822,
8,
6410,
9,
339,
3602,
63,
2441,
275,
7256,
59,
17,
61,
272,
702,
298,
17306,
3259,
473,
906,
1379,
17,
428,
3614,
3259,
2,
508,
3602,
63,
2441,
14,
354,
272,
702,
6335,
508,
3602,
63,
2441,
14,
929,
339,
2451,
63,
2441,
275,
7256,
59,
16,
61,
272,
702,
298,
17306,
3259,
473,
906,
1379,
18,
428,
3614,
3259,
2,
508,
2451,
63,
2441,
14,
354,
272,
702,
5939,
508,
2451,
63,
2441,
14,
929,
421,
199,
4146,
347,
511,
63,
2758,
63,
338,
3845,
8,
5387,
12,
4145,
63,
1805,
304,
272,
408,
774,
367,
8792,
4260,
1536,
314,
428,
3614,
23559,
4298,
1041,
272,
1683,
63,
10360,
8,
6615,
63,
1805,
12,
2849,
29,
549,
9,
339,
702,
5517,
5316,
63,
2758,
63,
3173,
8,
5387,
12,
298,
83,
18387,
1038,
81,
401,
2420,
83,
18387,
1038,
81,
582,
15869,
1552,
339,
2243,
63,
1805,
275,
10079,
342,
272,
308,
18387,
1038,
81,
14,
2758,
63,
3246,
8,
5387,
12,
15869,
12,
2243,
63,
1805,
12,
10079,
1012,
272,
7256,
275,
2243,
63,
1805,
14,
1250,
63,
589,
59,
16,
1527,
16,
61,
272,
702,
413,
508,
822,
8,
6410,
9,
339,
2451,
63,
2441,
275,
7256,
59,
16,
61,
272,
702,
298,
17306,
3259,
473,
906,
1379,
17,
428,
3614,
3259,
2,
508,
2451,
63,
2441,
14,
354,
272,
702,
6335,
508,
2451,
63,
2441,
14,
929,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
welenofsky/python_koans
|
python3/koans/about_proxy_object_project.py
|
82
|
4104
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Project: Create a Proxy Class
#
# In this assignment, create a proxy class (one is started for you
# below). You should be able to initialize the proxy object with any
# object. Any attributes called on the proxy object should be forwarded
# to the target object. As each attribute call is sent, the proxy should
# record the name of the attribute sent.
#
# The proxy class is started for you. You will need to add a method
# missing handler and any other supporting methods. The specification
# of the Proxy class is given in the AboutProxyObjectProject koan.
# Note: This is a bit trickier than its Ruby Koans counterpart, but you
# can do it!
from runner.koan import *
class Proxy:
def __init__(self, target_object):
# WRITE CODE HERE
#initialize '_obj' attribute last. Trust me on this!
self._obj = target_object
# WRITE CODE HERE
# The proxy object should pass the following Koan:
#
class AboutProxyObjectProject(Koan):
def test_proxy_method_returns_wrapped_object(self):
# NOTE: The Television class is defined below
tv = Proxy(Television())
self.assertTrue(isinstance(tv, Proxy))
def test_tv_methods_still_perform_their_function(self):
tv = Proxy(Television())
tv.channel = 10
tv.power()
self.assertEqual(10, tv.channel)
self.assertTrue(tv.is_on())
def test_proxy_records_messages_sent_to_tv(self):
tv = Proxy(Television())
tv.power()
tv.channel = 10
self.assertEqual(['power', 'channel'], tv.messages())
def test_proxy_handles_invalid_messages(self):
tv = Proxy(Television())
ex = None
with self.assertRaises(AttributeError):
tv.no_such_method()
def test_proxy_reports_methods_have_been_called(self):
tv = Proxy(Television())
tv.power()
tv.power()
self.assertTrue(tv.was_called('power'))
self.assertFalse(tv.was_called('channel'))
def test_proxy_counts_method_calls(self):
tv = Proxy(Television())
tv.power()
tv.channel = 48
tv.power()
self.assertEqual(2, tv.number_of_times_called('power'))
self.assertEqual(1, tv.number_of_times_called('channel'))
self.assertEqual(0, tv.number_of_times_called('is_on'))
def test_proxy_can_record_more_than_just_tv_objects(self):
proxy = Proxy("Py Ohio 2010")
result = proxy.upper()
self.assertEqual("PY OHIO 2010", result)
result = proxy.split()
self.assertEqual(["Py", "Ohio", "2010"], result)
self.assertEqual(['upper', 'split'], proxy.messages())
# ====================================================================
# The following code is to support the testing of the Proxy class. No
# changes should be necessary to anything below this comment.
# Example class using in the proxy testing above.
class Television:
def __init__(self):
self._channel = None
self._power = None
@property
def channel(self):
return self._channel
@channel.setter
def channel(self, value):
self._channel = value
def power(self):
if self._power == 'on':
self._power = 'off'
else:
self._power = 'on'
def is_on(self):
return self._power == 'on'
# Tests for the Television class. All of theses tests should pass.
class TelevisionTest(Koan):
def test_it_turns_on(self):
tv = Television()
tv.power()
self.assertTrue(tv.is_on())
def test_it_also_turns_off(self):
tv = Television()
tv.power()
tv.power()
self.assertFalse(tv.is_on())
def test_edge_case_on_off(self):
tv = Television()
tv.power()
tv.power()
tv.power()
self.assertTrue(tv.is_on())
tv.power()
self.assertFalse(tv.is_on())
def test_can_set_the_channel(self):
tv = Television()
tv.channel = 11
self.assertEqual(11, tv.channel)
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
7290,
26,
2790,
282,
12373,
8089,
199,
3,
199,
3,
1010,
642,
9801,
12,
1218,
282,
4566,
1021,
334,
368,
365,
8239,
367,
1265,
199,
3,
5084,
680,
221,
2047,
1077,
506,
7688,
370,
8265,
314,
4566,
909,
543,
1263,
199,
3,
909,
14,
221,
6184,
3004,
2797,
641,
314,
4566,
909,
1077,
506,
24172,
199,
3,
370,
314,
1347,
909,
14,
221,
3709,
1924,
2225,
1240,
365,
4847,
12,
314,
4566,
1077,
199,
3,
2777,
314,
536,
402,
314,
2225,
4847,
14,
199,
3,
199,
3,
710,
4566,
1021,
365,
8239,
367,
1265,
14,
221,
2047,
911,
1929,
370,
1050,
282,
1083,
199,
3,
4124,
3016,
436,
1263,
1163,
21038,
3102,
14,
221,
710,
8929,
199,
3,
402,
314,
12373,
1021,
365,
1627,
315,
314,
25225,
4936,
1692,
4761,
20817,
290,
14,
199,
199,
3,
3390,
26,
961,
365,
282,
4546,
20907,
4446,
2419,
2399,
820,
10972,
1804,
79,
796,
7055,
2064,
12,
1325,
1265,
199,
3,
883,
886,
652,
1,
199,
199,
504,
7876,
14,
7697,
290,
492,
627,
199,
199,
533,
12373,
26,
272,
347,
636,
826,
721,
277,
12,
1347,
63,
785,
304,
267,
327,
32280,
22547,
869,
28106,
398,
327,
8489,
2513,
1113,
7,
2225,
2061,
14,
377,
19622,
562,
641,
642,
1,
267,
291,
423,
1113,
275,
1347,
63,
785,
339,
327,
32280,
22547,
869,
28106,
199,
199,
3,
710,
4566,
909,
1077,
986,
314,
2569,
1804,
79,
290,
26,
199,
3,
199,
533,
25225,
4936,
1692,
4761,
8,
31305,
290,
304,
272,
347,
511,
63,
3280,
63,
765,
63,
5808,
63,
9130,
63,
785,
8,
277,
304,
267,
327,
6944,
26,
710,
23884,
2317,
1021,
365,
3247,
5084,
267,
13466,
275,
12373,
8,
24944,
2317,
1012,
398,
291,
14,
1815,
8,
6074,
8,
6993,
12,
12373,
430,
339,
347,
511,
63,
6993,
63,
2474,
63,
32310,
63,
15795,
63,
1589,
723,
63,
1593,
8,
277,
304,
267,
13466,
275,
12373,
8,
24944,
2317,
1012,
398,
13466,
14,
2775,
275,
1616,
267,
13466,
14,
5652,
342,
398,
291,
14,
629,
8,
709,
12,
13466,
14,
2775,
9,
267,
291,
14,
1815,
8,
6993,
14,
374,
63,
265,
1012,
339,
347,
511,
63,
3280,
63,
6502,
63,
3431,
63,
1150,
63,
475,
63,
6993,
8,
277,
304,
267,
13466,
275,
12373,
8,
24944,
2317,
1012,
398,
13466,
14,
5652,
342,
267,
13466,
14,
2775,
275,
1616,
398,
291,
14,
629,
2941,
5652,
297,
283,
2775,
995,
13466,
14,
3431,
1012,
339,
347,
511,
63,
3280,
63,
16947,
63,
3197,
63,
3431,
8,
277,
304,
267,
13466,
275,
12373,
8,
24944,
2317,
1012,
398,
444,
275,
488,
267,
543,
291,
14,
1855,
8,
10227,
304,
288,
13466,
14,
889,
63,
10180,
63,
765,
342,
2378,
347,
511,
63,
3280,
63,
15629,
63,
2474,
63,
7804,
63,
1235,
287,
63,
3527,
8,
277,
304,
267,
13466,
275,
12373,
8,
24944,
2317,
1012,
398,
13466,
14,
5652,
342,
267,
13466,
14,
5652,
342,
398,
291,
14,
1815,
8,
6993,
14,
10274,
63,
3527,
360,
5652,
1333,
267,
291,
14,
3334,
8,
6993,
14,
10274,
63,
3527,
360,
2775,
1333,
339,
347,
511,
63,
3280,
63,
6851,
63,
765,
63,
5352,
8,
277,
304,
267,
13466,
275,
12373,
8,
24944,
2317,
1012,
398,
13466,
14,
5652,
342,
267,
13466,
14,
2775,
275,
9615,
267,
13466,
14,
5652,
342,
398,
291,
14,
629,
8,
18,
12,
13466,
14,
1955,
63,
1618,
63,
4508,
63,
3527,
360,
5652,
1333,
267,
291,
14,
629,
8,
17,
12,
13466,
14,
1955,
63,
1618,
63,
4508,
63,
3527,
360,
2775,
1333,
267,
291,
14,
629,
8,
16,
12,
13466,
14,
1955,
63,
1618,
63,
4508,
63,
3527,
360,
374,
63,
265,
1333,
339,
347,
511,
63,
3280,
63,
2425,
63,
3059,
63,
6878,
63,
13797,
63,
4764,
63,
6993,
63,
1462,
8,
277,
304,
267,
4566,
275,
12373,
480,
2713,
593,
72,
2308,
7129,
531,
398,
754,
275,
4566,
14,
4142,
342,
398,
291,
14,
629,
480,
4521,
593,
40,
2090,
7129,
401,
754,
9,
398,
754,
275,
4566,
14,
1294,
342,
398,
291,
14,
629,
5234,
2713,
401,
298,
47,
72,
2308,
401,
298,
6542,
2255,
754,
9,
267,
291,
14,
629,
2941,
4142,
297,
283,
1294,
995,
4566,
14,
3431,
1012,
199,
199,
3,
7819,
5918,
199,
3,
710,
2569,
1233,
365,
370,
2291,
314,
5343,
402,
314,
12373,
1021,
14,
221,
3091,
199,
3,
4493,
1077,
506,
5784,
370,
7003,
5084,
642,
3721,
14,
199,
199,
3,
5679,
1021,
1808,
315,
314,
4566,
5343,
3432,
14,
199,
533,
23884,
2317,
26,
272,
347,
636,
826,
721,
277,
304,
267,
291,
423,
2775,
275,
488,
267,
291,
423,
5652,
275,
488,
339,
768,
1829,
272,
347,
3623,
8,
277,
304,
267,
372,
291,
423,
2775,
339,
768,
2775,
14,
8345,
272,
347,
3623,
8,
277,
12,
574,
304,
267,
291,
423,
2775,
275,
574,
339,
347,
7074,
8,
277,
304,
267,
340,
291,
423,
5652,
508,
283,
265,
356,
288,
291,
423,
5652,
275,
283,
1997,
7,
267,
587,
26,
288,
291,
423,
5652,
275,
283,
265,
7,
339,
347,
365,
63,
265,
8,
277,
304,
267,
372,
291,
423,
5652,
508,
283,
265,
7,
199,
199,
3,
6496,
367,
314,
23884,
2317,
1021,
14,
221,
2900,
402,
314,
874,
2295,
1077,
986,
14,
199,
533,
23884,
2317,
774,
8,
31305,
290,
304,
272,
347,
511,
63,
390,
63,
353,
83,
63,
265,
8,
277,
304,
267,
13466,
275,
23884,
2317,
342,
398,
13466,
14,
5652,
342,
267,
291,
14,
1815,
8,
6993,
14,
374,
63,
265,
1012,
339,
347,
511,
63,
390,
63,
12344,
63,
353,
83,
63,
1997,
8,
277,
304,
267,
13466,
275,
23884,
2317,
342,
398,
13466,
14,
5652,
342,
267,
13466,
14,
5652,
342,
398,
291,
14,
3334,
8,
6993,
14,
374,
63,
265,
1012,
339,
347,
511,
63,
5173,
63,
2546,
63,
265,
63,
1997,
8,
277,
304,
267,
13466,
275,
23884,
2317,
342,
398,
13466,
14,
5652,
342,
267,
13466,
14,
5652,
342,
267,
13466,
14,
5652,
342,
398,
291,
14,
1815,
8,
6993,
14,
374,
63,
265,
1012,
398
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
7290,
26,
2790,
282,
12373,
8089,
199,
3,
199,
3,
1010,
642,
9801,
12,
1218,
282,
4566,
1021,
334,
368,
365,
8239,
367,
1265,
199,
3,
5084,
680,
221,
2047,
1077,
506,
7688,
370,
8265,
314,
4566,
909,
543,
1263,
199,
3,
909,
14,
221,
6184,
3004,
2797,
641,
314,
4566,
909,
1077,
506,
24172,
199,
3,
370,
314,
1347,
909,
14,
221,
3709,
1924,
2225,
1240,
365,
4847,
12,
314,
4566,
1077,
199,
3,
2777,
314,
536,
402,
314,
2225,
4847,
14,
199,
3,
199,
3,
710,
4566,
1021,
365,
8239,
367,
1265,
14,
221,
2047,
911,
1929,
370,
1050,
282,
1083,
199,
3,
4124,
3016,
436,
1263,
1163,
21038,
3102,
14,
221,
710,
8929,
199,
3,
402,
314,
12373,
1021,
365,
1627,
315,
314,
25225,
4936,
1692,
4761,
20817,
290,
14,
199,
199,
3,
3390,
26,
961,
365,
282,
4546,
20907,
4446,
2419,
2399,
820,
10972,
1804,
79,
796,
7055,
2064,
12,
1325,
1265,
199,
3,
883,
886,
652,
1,
199,
199,
504,
7876,
14,
7697,
290,
492,
627,
199,
199,
533,
12373,
26,
272,
347,
636,
826,
721,
277,
12,
1347,
63,
785,
304,
267,
327,
32280,
22547,
869,
28106,
398,
327,
8489,
2513,
1113,
7,
2225,
2061,
14,
377,
19622,
562,
641,
642,
1,
267,
291,
423,
1113,
275,
1347,
63,
785,
339,
327,
32280,
22547,
869,
28106,
199,
199,
3,
710,
4566,
909,
1077,
986,
314,
2569,
1804,
79,
290,
26,
199,
3,
199,
533,
25225,
4936,
1692,
4761,
8,
31305,
290,
304,
272,
347,
511,
63,
3280,
63,
765,
63,
5808,
63,
9130,
63,
785,
8,
277,
304,
267,
327,
6944,
26,
710,
23884,
2317,
1021,
365,
3247,
5084,
267,
13466,
275,
12373,
8,
24944,
2317,
1012,
398,
291,
14,
1815,
8,
6074,
8,
6993,
12,
12373,
430,
339,
347,
511,
63,
6993,
63,
2474,
63,
32310,
63,
15795,
63,
1589,
723,
63,
1593,
8,
277,
304,
267,
13466,
275,
12373,
8,
24944,
2317,
1012,
398,
13466,
14,
2775,
275,
1616,
267,
13466,
14,
5652,
342,
398,
291,
14,
629,
8,
709,
12,
13466,
14,
2775,
9,
267,
291,
14,
1815,
8,
6993,
14,
374,
63,
265,
1012,
339,
347,
511,
63,
3280,
63,
6502,
63,
3431,
63,
1150,
63,
475,
63,
6993,
8,
277,
304,
267,
13466,
275,
12373,
8,
24944,
2317,
1012,
398,
13466,
14,
5652,
342,
267,
13466,
14,
2775,
275,
1616,
398,
291,
14,
629,
2941,
5652,
297,
283,
2775,
995,
13466,
14,
3431,
1012,
339,
347,
511,
63,
3280,
63,
16947,
63,
3197,
63,
3431,
8,
277,
304,
267,
13466,
275,
12373,
8,
24944,
2317,
1012,
398,
444,
275,
488,
267,
543,
291,
14,
1855,
8,
10227,
304,
288,
13466,
14,
889,
63,
10180,
63,
765,
342,
2378,
347,
511,
63,
3280,
63,
15629,
63,
2474,
63,
7804,
63,
1235,
287,
63,
3527,
8,
277,
304,
267,
13466,
275,
12373,
8,
24944,
2317,
1012,
398,
13466,
14,
5652,
342,
267,
13466,
14,
5652,
342,
398,
291,
14,
1815,
8,
6993,
14,
10274,
63,
3527,
360,
5652,
1333,
267,
291,
14,
3334,
8,
6993,
14,
10274,
63,
3527,
360,
2775,
1333,
339,
347,
511,
63,
3280,
63,
6851,
63,
765,
63,
5352,
8,
277,
304,
267,
13466,
275,
12373,
8,
24944,
2317,
1012,
398,
13466,
14,
5652,
342,
267,
13466,
14,
2775,
275,
9615,
267,
13466,
14,
5652,
342,
398,
291,
14,
629,
8,
18,
12,
13466,
14,
1955,
63,
1618,
63,
4508,
63,
3527,
360,
5652,
1333,
267,
291,
14,
629,
8,
17,
12,
13466,
14,
1955,
63,
1618,
63,
4508,
63,
3527,
360,
2775,
1333,
267,
291,
14,
629,
8,
16,
12,
13466,
14,
1955,
63,
1618,
63,
4508,
63,
3527,
360,
374,
63,
265,
1333,
339,
347,
511,
63,
3280,
63,
2425,
63,
3059,
63,
6878,
63,
13797,
63,
4764,
63,
6993,
63,
1462,
8,
277,
304,
267,
4566,
275,
12373,
480,
2713,
593,
72,
2308,
7129,
531,
398,
754,
275,
4566,
14,
4142,
342,
398,
291,
14,
629,
480,
4521,
593,
40,
2090,
7129,
401,
754,
9,
398,
754,
275,
4566,
14,
1294,
342,
398,
291,
14,
629,
5234,
2713,
401,
298,
47,
72,
2308,
401,
298,
6542,
2255,
754,
9,
267,
291,
14,
629,
2941,
4142,
297,
283,
1294,
995,
4566,
14,
3431,
1012,
199,
199,
3,
7819,
5918,
199,
3,
710,
2569,
1233,
365,
370,
2291,
314,
5343,
402,
314,
12373,
1021,
14,
221,
3091,
199,
3,
4493,
1077,
506,
5784,
370,
7003,
5084,
642,
3721,
14,
199,
199,
3,
5679,
1021,
1808,
315,
314,
4566,
5343,
3432,
14,
199,
533,
23884,
2317,
26,
272,
347,
636,
826,
721,
277,
304,
267,
291,
423,
2775,
275,
488,
267,
291,
423,
5652,
275,
488,
339,
768,
1829,
272,
347,
3623,
8,
277,
304,
267,
372,
291,
423,
2775,
339,
768,
2775,
14,
8345,
272,
347,
3623,
8,
277,
12,
574,
304,
267,
291,
423,
2775,
275,
574,
339,
347,
7074,
8,
277,
304,
267,
340,
291,
423,
5652,
508,
283,
265,
356,
288,
291,
423,
5652,
275,
283,
1997,
7,
267,
587,
26,
288,
291,
423,
5652,
275,
283,
265,
7,
339,
347,
365,
63,
265,
8,
277,
304,
267,
372,
291,
423,
5652,
508,
283,
265,
7,
199,
199,
3,
6496,
367,
314,
23884,
2317,
1021,
14,
221,
2900,
402,
314,
874,
2295,
1077,
986,
14,
199,
533,
23884,
2317,
774,
8,
31305,
290,
304,
272,
347,
511,
63,
390,
63,
353,
83,
63,
265,
8,
277,
304,
267,
13466,
275,
23884,
2317,
342,
398,
13466,
14,
5652,
342,
267,
291,
14,
1815,
8,
6993,
14,
374,
63,
265,
1012,
339,
347,
511,
63,
390,
63,
12344,
63,
353,
83,
63,
1997,
8,
277,
304,
267,
13466,
275,
23884,
2317,
342,
398,
13466,
14,
5652,
342,
267,
13466,
14,
5652,
342,
398,
291,
14,
3334,
8,
6993,
14,
374,
63,
265,
1012,
339,
347,
511,
63,
5173,
63,
2546,
63,
265,
63,
1997,
8,
277,
304,
267,
13466,
275,
23884,
2317,
342,
398,
13466,
14,
5652,
342,
267,
13466,
14,
5652,
342,
267,
13466,
14,
5652,
342,
398,
291,
14,
1815,
8,
6993,
14,
374,
63,
265,
1012,
398,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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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
] |
OpenCanada/website
|
core/migrations/0021_streampage.py
|
1
|
10814
|
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import wagtail.core.blocks
import wagtail.embeds.blocks
import wagtail.images.blocks
from django.db import migrations, models
import articles.fields
import interactives.models
class Migration(migrations.Migration):
dependencies = [
('core', '0020_assign_theme_to_homepage'),
]
operations = [
migrations.CreateModel(
name='StreamPage',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('body', articles.fields.BodyField([('Heading', wagtail.core.blocks.StructBlock([(b'text', wagtail.core.blocks.CharBlock()), (b'heading_level', wagtail.core.blocks.ChoiceBlock(default=2, choices=[(2, '2'), (3, '3'), (4, '4'), (5, '5'), (6, '6')]))])), ('Paragraph', wagtail.core.blocks.StructBlock([(b'text', wagtail.core.blocks.RichTextBlock()), (b'use_dropcap', wagtail.core.blocks.BooleanBlock(required=False))])), ('Image', wagtail.core.blocks.StructBlock([(b'image', wagtail.images.blocks.ImageChooserBlock()), (b'placement', wagtail.core.blocks.ChoiceBlock(default='full', choices=[('left', 'Left Aligned'), ('right', 'Right Aligned'), ('full', 'Full Width'), ('nocrop', 'Full Width - No Cropping')])), (b'include_border', wagtail.core.blocks.BooleanBlock(default=False, required=False)), (b'expandable', wagtail.core.blocks.BooleanBlock(default=False, required=False)), (b'label', wagtail.core.blocks.CharBlock(help_text='Additional label to be displayed with the image.', required=False))])), ('Embed', wagtail.embeds.blocks.EmbedBlock(icon='site')), ('List', wagtail.core.blocks.ListBlock(wagtail.core.blocks.RichTextBlock(label='item'), icon='list-ul')), ('Sharable', articles.fields.SharableBlock()), ('PullQuote', articles.fields.PullQuoteBlock()), ('Quote', articles.fields.SimpleQuoteBlock()), ('Overflow', wagtail.core.blocks.StructBlock([(b'body', wagtail.core.blocks.StreamBlock([(b'Heading', wagtail.core.blocks.StructBlock([(b'text', wagtail.core.blocks.CharBlock()), (b'heading_level', wagtail.core.blocks.ChoiceBlock(default=2, choices=[(2, '2'), (3, '3'), (4, '4'), (5, '5'), (6, '6')]))])), (b'Paragraph', wagtail.core.blocks.StructBlock([(b'text', wagtail.core.blocks.RichTextBlock()), (b'use_dropcap', wagtail.core.blocks.BooleanBlock(required=False))])), (b'Image', wagtail.core.blocks.StructBlock([(b'image', wagtail.images.blocks.ImageChooserBlock()), (b'placement', wagtail.core.blocks.ChoiceBlock(default='full', choices=[('left', 'Left Aligned'), ('right', 'Right Aligned'), ('full', 'Full Width'), ('nocrop', 'Full Width - No Cropping')])), (b'include_border', wagtail.core.blocks.BooleanBlock(default=False, required=False)), (b'expandable', wagtail.core.blocks.BooleanBlock(default=False, required=False)), (b'label', wagtail.core.blocks.CharBlock(help_text='Additional label to be displayed with the image.', required=False))])), (b'Embed', wagtail.embeds.blocks.EmbedBlock(icon='site')), (b'List', wagtail.core.blocks.ListBlock(wagtail.core.blocks.RichTextBlock(label='item'), icon='list-ul')), (b'Sharable', articles.fields.SharableBlock()), (b'PullQuote', articles.fields.PullQuoteBlock()), (b'Quote', articles.fields.SimpleQuoteBlock()), (b'Interactive', articles.fields.InteractiveBlock(interactives.models.Interactive)), (b'RelatedItems', wagtail.core.blocks.StructBlock([(b'heading', wagtail.core.blocks.CharBlock(default='Related')), (b'items', wagtail.core.blocks.ListBlock(wagtail.core.blocks.PageChooserBlock(label='item')))], icon='list-ul')), (b'ColumnedContent', wagtail.core.blocks.StructBlock([(b'body', wagtail.core.blocks.StreamBlock([(b'Heading', wagtail.core.blocks.StructBlock([(b'text', wagtail.core.blocks.CharBlock()), (b'heading_level', wagtail.core.blocks.ChoiceBlock(default=2, choices=[(2, '2'), (3, '3'), (4, '4'), (5, '5'), (6, '6')]))])), (b'Paragraph', wagtail.core.blocks.StructBlock([(b'text', wagtail.core.blocks.RichTextBlock()), (b'use_dropcap', wagtail.core.blocks.BooleanBlock(required=False))])), (b'Image', wagtail.core.blocks.StructBlock([(b'image', wagtail.images.blocks.ImageChooserBlock()), (b'placement', wagtail.core.blocks.ChoiceBlock(default='full', choices=[('left', 'Left Aligned'), ('right', 'Right Aligned'), ('full', 'Full Width'), ('nocrop', 'Full Width - No Cropping')])), (b'include_border', wagtail.core.blocks.BooleanBlock(default=False, required=False)), (b'expandable', wagtail.core.blocks.BooleanBlock(default=False, required=False)), (b'label', wagtail.core.blocks.CharBlock(help_text='Additional label to be displayed with the image.', required=False))])), (b'Embed', wagtail.embeds.blocks.EmbedBlock(icon='site')), (b'List', wagtail.core.blocks.ListBlock(wagtail.core.blocks.RichTextBlock(label='item'), icon='list-ul')), (b'Sharable', articles.fields.SharableBlock()), (b'PullQuote', articles.fields.PullQuoteBlock()), (b'Quote', articles.fields.SimpleQuoteBlock()), (b'Interactive', articles.fields.InteractiveBlock(interactives.models.Interactive)), (b'RelatedItems', wagtail.core.blocks.StructBlock([(b'heading', wagtail.core.blocks.CharBlock(default='Related')), (b'items', wagtail.core.blocks.ListBlock(wagtail.core.blocks.PageChooserBlock(label='item')))], icon='list-ul'))], required=False))]))], required=False))])), ('FullBleed', wagtail.core.blocks.StructBlock([(b'body', wagtail.core.blocks.StreamBlock([(b'Heading', wagtail.core.blocks.StructBlock([(b'text', wagtail.core.blocks.CharBlock()), (b'heading_level', wagtail.core.blocks.ChoiceBlock(default=2, choices=[(2, '2'), (3, '3'), (4, '4'), (5, '5'), (6, '6')]))])), (b'Paragraph', wagtail.core.blocks.StructBlock([(b'text', wagtail.core.blocks.RichTextBlock()), (b'use_dropcap', wagtail.core.blocks.BooleanBlock(required=False))])), (b'Image', wagtail.core.blocks.StructBlock([(b'image', wagtail.images.blocks.ImageChooserBlock()), (b'placement', wagtail.core.blocks.ChoiceBlock(default='full', choices=[('left', 'Left Aligned'), ('right', 'Right Aligned'), ('full', 'Full Width'), ('nocrop', 'Full Width - No Cropping')])), (b'include_border', wagtail.core.blocks.BooleanBlock(default=False, required=False)), (b'expandable', wagtail.core.blocks.BooleanBlock(default=False, required=False)), (b'label', wagtail.core.blocks.CharBlock(help_text='Additional label to be displayed with the image.', required=False))])), (b'Embed', wagtail.embeds.blocks.EmbedBlock(icon='site')), (b'List', wagtail.core.blocks.ListBlock(wagtail.core.blocks.RichTextBlock(label='item'), icon='list-ul')), (b'Sharable', articles.fields.SharableBlock()), (b'PullQuote', articles.fields.PullQuoteBlock()), (b'Quote', articles.fields.SimpleQuoteBlock()), (b'Interactive', articles.fields.InteractiveBlock(interactives.models.Interactive)), (b'RelatedItems', wagtail.core.blocks.StructBlock([(b'heading', wagtail.core.blocks.CharBlock(default='Related')), (b'items', wagtail.core.blocks.ListBlock(wagtail.core.blocks.PageChooserBlock(label='item')))], icon='list-ul')), (b'ColumnedContent', wagtail.core.blocks.StructBlock([(b'body', wagtail.core.blocks.StreamBlock([(b'Heading', wagtail.core.blocks.StructBlock([(b'text', wagtail.core.blocks.CharBlock()), (b'heading_level', wagtail.core.blocks.ChoiceBlock(default=2, choices=[(2, '2'), (3, '3'), (4, '4'), (5, '5'), (6, '6')]))])), (b'Paragraph', wagtail.core.blocks.StructBlock([(b'text', wagtail.core.blocks.RichTextBlock()), (b'use_dropcap', wagtail.core.blocks.BooleanBlock(required=False))])), (b'Image', wagtail.core.blocks.StructBlock([(b'image', wagtail.images.blocks.ImageChooserBlock()), (b'placement', wagtail.core.blocks.ChoiceBlock(default='full', choices=[('left', 'Left Aligned'), ('right', 'Right Aligned'), ('full', 'Full Width'), ('nocrop', 'Full Width - No Cropping')])), (b'include_border', wagtail.core.blocks.BooleanBlock(default=False, required=False)), (b'expandable', wagtail.core.blocks.BooleanBlock(default=False, required=False)), (b'label', wagtail.core.blocks.CharBlock(help_text='Additional label to be displayed with the image.', required=False))])), (b'Embed', wagtail.embeds.blocks.EmbedBlock(icon='site')), (b'List', wagtail.core.blocks.ListBlock(wagtail.core.blocks.RichTextBlock(label='item'), icon='list-ul')), (b'Sharable', articles.fields.SharableBlock()), (b'PullQuote', articles.fields.PullQuoteBlock()), (b'Quote', articles.fields.SimpleQuoteBlock()), (b'Interactive', articles.fields.InteractiveBlock(interactives.models.Interactive)), (b'RelatedItems', wagtail.core.blocks.StructBlock([(b'heading', wagtail.core.blocks.CharBlock(default='Related')), (b'items', wagtail.core.blocks.ListBlock(wagtail.core.blocks.PageChooserBlock(label='item')))], icon='list-ul'))], required=False))]))], required=False))])), ('ColumnedContent', wagtail.core.blocks.StructBlock([(b'body', wagtail.core.blocks.StreamBlock([(b'Heading', wagtail.core.blocks.StructBlock([(b'text', wagtail.core.blocks.CharBlock()), (b'heading_level', wagtail.core.blocks.ChoiceBlock(default=2, choices=[(2, '2'), (3, '3'), (4, '4'), (5, '5'), (6, '6')]))])), (b'Paragraph', wagtail.core.blocks.StructBlock([(b'text', wagtail.core.blocks.RichTextBlock()), (b'use_dropcap', wagtail.core.blocks.BooleanBlock(required=False))])), (b'Image', wagtail.core.blocks.StructBlock([(b'image', wagtail.images.blocks.ImageChooserBlock()), (b'placement', wagtail.core.blocks.ChoiceBlock(default='full', choices=[('left', 'Left Aligned'), ('right', 'Right Aligned'), ('full', 'Full Width'), ('nocrop', 'Full Width - No Cropping')])), (b'include_border', wagtail.core.blocks.BooleanBlock(default=False, required=False)), (b'expandable', wagtail.core.blocks.BooleanBlock(default=False, required=False)), (b'label', wagtail.core.blocks.CharBlock(help_text='Additional label to be displayed with the image.', required=False))])), (b'Embed', wagtail.embeds.blocks.EmbedBlock(icon='site')), (b'List', wagtail.core.blocks.ListBlock(wagtail.core.blocks.RichTextBlock(label='item'), icon='list-ul')), (b'Sharable', articles.fields.SharableBlock()), (b'PullQuote', articles.fields.PullQuoteBlock()), (b'Quote', articles.fields.SimpleQuoteBlock()), (b'Interactive', articles.fields.InteractiveBlock(interactives.models.Interactive)), (b'RelatedItems', wagtail.core.blocks.StructBlock([(b'heading', wagtail.core.blocks.CharBlock(default='Related')), (b'items', wagtail.core.blocks.ListBlock(wagtail.core.blocks.PageChooserBlock(label='item')))], icon='list-ul'))], required=False))])), ('Interactive', articles.fields.InteractiveBlock(interactives.models.Interactive, icon='cogs')), ('RelatedItems', wagtail.core.blocks.StructBlock([(b'heading', wagtail.core.blocks.CharBlock(default='Related')), (b'items', wagtail.core.blocks.ListBlock(wagtail.core.blocks.PageChooserBlock(label='item')))], icon='list-ul'))])),
],
),
]
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
7328,
14,
1018,
14,
4166,
199,
646,
7328,
14,
6427,
83,
14,
4166,
199,
646,
7328,
14,
4782,
14,
4166,
199,
504,
1639,
14,
697,
492,
6180,
12,
1709,
199,
199,
646,
23242,
14,
955,
199,
646,
315,
2967,
67,
7301,
14,
992,
421,
199,
533,
12090,
8,
7685,
14,
9816,
304,
339,
5124,
275,
359,
267,
661,
1018,
297,
283,
20734,
63,
5038,
63,
7915,
63,
475,
63,
25539,
659,
272,
1622,
339,
5331,
275,
359,
267,
6180,
14,
14907,
8,
288,
536,
534,
3296,
3276,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
2030,
297,
23242,
14,
955,
14,
8173,
792,
8318,
23818,
297,
7328,
14,
1018,
14,
4166,
14,
17972,
7694,
66,
1133,
832,
297,
7328,
14,
1018,
14,
4166,
14,
14615,
4000,
334,
66,
7,
13983,
63,
1896,
297,
7328,
14,
1018,
14,
4166,
14,
9054,
3142,
8,
885,
29,
18,
12,
3415,
17497,
18,
12,
283,
18,
659,
334,
19,
12,
283,
19,
659,
334,
20,
12,
283,
20,
659,
334,
21,
12,
283,
21,
659,
334,
22,
12,
283,
22,
358,
2459,
12884,
661,
24038,
297,
7328,
14,
1018,
14,
4166,
14,
17972,
7694,
66,
1133,
832,
297,
7328,
14,
1018,
14,
4166,
14,
19537,
3142,
4000,
334,
66,
7,
1180,
63,
17264,
2352,
439,
297,
7328,
14,
1018,
14,
4166,
14,
4082,
3142,
8,
2427,
29,
797,
430,
12884,
661,
3491,
297,
7328,
14,
1018,
14,
4166,
14,
17972,
7694,
66,
7,
1569,
297,
7328,
14,
4782,
14,
4166,
14,
3491,
24096,
4000,
334,
66,
7,
16748,
297,
7328,
14,
1018,
14,
4166,
14,
9054,
3142,
8,
885,
534,
2861,
297,
3415,
11699,
3039,
297,
283,
8185,
15170,
784,
379,
659,
661,
1019,
297,
283,
9121,
15170,
784,
379,
659,
661,
2861,
297,
283,
9042,
644,
1466,
659,
661,
23507,
2675,
297,
283,
9042,
644,
1466,
446,
3091,
445,
20148,
2023,
395,
334,
66,
7,
2613,
63,
8665,
297,
7328,
14,
1018,
14,
4166,
14,
4082,
3142,
8,
885,
29,
797,
12,
1415,
29,
797,
1826,
334,
66,
7,
4441,
461,
297,
7328,
14,
1018,
14,
4166,
14,
4082,
3142,
8,
885,
29,
797,
12,
1415,
29,
797,
1826,
334,
66,
7,
1302,
297,
7328,
14,
1018,
14,
4166,
14,
14615,
8,
3437,
63,
505,
534,
8824,
1768,
370,
506,
9080,
543,
314,
1834,
3130,
1415,
29,
797,
430,
12884,
661,
13200,
297,
7328,
14,
6427,
83,
14,
4166,
14,
13200,
3142,
8,
4677,
534,
2124,
3855,
661,
1296,
297,
7328,
14,
1018,
14,
4166,
14,
1296,
3142,
8,
17296,
14,
1018,
14,
4166,
14,
19537,
3142,
8,
1302,
534,
1053,
659,
7016,
534,
513,
13,
348,
3855,
661,
2662,
19816,
297,
23242,
14,
955,
14,
2662,
19816,
3142,
4000,
661,
27318,
12838,
297,
23242,
14,
955,
14,
27318,
12838,
3142,
4000,
661,
12838,
297,
23242,
14,
955,
14,
3184,
12838,
3142,
4000,
661,
5674,
1659,
297,
7328,
14,
1018,
14,
4166,
14,
17972,
7694,
66,
7,
2030,
297,
7328,
14,
1018,
14,
4166,
14,
3296,
3142,
7694,
66,
7,
23818,
297,
7328,
14,
1018,
14,
4166,
14,
17972,
7694,
66,
1133,
832,
297,
7328,
14,
1018,
14,
4166,
14,
14615,
4000,
334,
66,
7,
13983,
63,
1896,
297,
7328,
14,
1018,
14,
4166,
14,
9054,
3142,
8,
885,
29,
18,
12,
3415,
17497,
18,
12,
283,
18,
659,
334,
19,
12,
283,
19,
659,
334,
20,
12,
283,
20,
659,
334,
21,
12,
283,
21,
659,
334,
22,
12,
283,
22,
358,
2459,
12884,
334,
66,
7,
24038,
297,
7328,
14,
1018,
14,
4166,
14,
17972,
7694,
66,
1133,
832,
297,
7328,
14,
1018,
14,
4166,
14,
19537,
3142,
4000,
334,
66,
7,
1180,
63,
17264,
2352,
439,
297,
7328,
14,
1018,
14,
4166,
14,
4082,
3142,
8,
2427,
29,
797,
430,
12884,
334,
66,
7,
3491,
297,
7328,
14,
1018,
14,
4166,
14,
17972,
7694,
66,
7,
1569,
297,
7328,
14,
4782,
14,
4166,
14,
3491,
24096,
4000,
334,
66,
7,
16748,
297,
7328,
14,
1018,
14,
4166,
14,
9054,
3142,
8,
885,
534,
2861,
297,
3415,
11699,
3039,
297,
283,
8185,
15170,
784,
379,
659,
661,
1019,
297,
283,
9121,
15170,
784,
379,
659,
661,
2861,
297,
283,
9042,
644,
1466,
659,
661,
23507,
2675,
297,
283,
9042,
644,
1466,
446,
3091,
445,
20148,
2023,
395,
334,
66,
7,
2613,
63,
8665,
297,
7328,
14,
1018,
14,
4166,
14,
4082,
3142,
8,
885,
29,
797,
12,
1415,
29,
797,
1826,
334,
66,
7,
4441,
461,
297,
7328,
14,
1018,
14,
4166,
14,
4082,
3142,
8,
885,
29,
797,
12,
1415,
29,
797,
1826,
334,
66,
7,
1302,
297,
7328,
14,
1018,
14,
4166,
14,
14615,
8,
3437,
63,
505,
534,
8824,
1768,
370,
506,
9080,
543,
314,
1834,
3130,
1415,
29,
797,
430,
12884,
334,
66,
7,
13200,
297,
7328,
14,
6427,
83,
14,
4166,
14,
13200,
3142,
8,
4677,
534,
2124,
3855,
334,
66,
7,
1296,
297,
7328,
14,
1018,
14,
4166,
14,
1296,
3142,
8,
17296,
14,
1018,
14,
4166,
14,
19537,
3142,
8,
1302,
534,
1053,
659,
7016,
534,
513,
13,
348,
3855,
334,
66,
7,
2662,
19816,
297,
23242,
14,
955,
14,
2662,
19816,
3142,
4000,
334,
66,
7,
27318,
12838,
297,
23242,
14,
955,
14,
27318,
12838,
3142,
4000,
334,
66,
7,
12838,
297,
23242,
14,
955,
14,
3184,
12838,
3142,
4000,
334,
66,
7,
23879,
297,
23242,
14,
955,
14,
23879,
3142,
8,
262,
2967,
67,
7301,
14,
992,
14,
23879,
1826,
334,
66,
7,
13885,
7412,
297,
7328,
14,
1018,
14,
4166,
14,
17972,
7694,
66,
7,
13983,
297,
7328,
14,
1018,
14,
4166,
14,
14615,
8,
885,
534,
13885,
3855,
334,
66,
7,
1744,
297,
7328,
14,
1018,
14,
4166,
14,
1296,
3142,
8,
17296,
14,
1018,
14,
4166,
14,
3276,
24096,
8,
1302,
534,
1053,
7058,
467,
7016,
534,
513,
13,
348,
3855,
334,
66,
7,
4547,
379,
2714,
297,
7328,
14,
1018,
14,
4166,
14,
17972
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
7328,
14,
1018,
14,
4166,
199,
646,
7328,
14,
6427,
83,
14,
4166,
199,
646,
7328,
14,
4782,
14,
4166,
199,
504,
1639,
14,
697,
492,
6180,
12,
1709,
199,
199,
646,
23242,
14,
955,
199,
646,
315,
2967,
67,
7301,
14,
992,
421,
199,
533,
12090,
8,
7685,
14,
9816,
304,
339,
5124,
275,
359,
267,
661,
1018,
297,
283,
20734,
63,
5038,
63,
7915,
63,
475,
63,
25539,
659,
272,
1622,
339,
5331,
275,
359,
267,
6180,
14,
14907,
8,
288,
536,
534,
3296,
3276,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
2030,
297,
23242,
14,
955,
14,
8173,
792,
8318,
23818,
297,
7328,
14,
1018,
14,
4166,
14,
17972,
7694,
66,
1133,
832,
297,
7328,
14,
1018,
14,
4166,
14,
14615,
4000,
334,
66,
7,
13983,
63,
1896,
297,
7328,
14,
1018,
14,
4166,
14,
9054,
3142,
8,
885,
29,
18,
12,
3415,
17497,
18,
12,
283,
18,
659,
334,
19,
12,
283,
19,
659,
334,
20,
12,
283,
20,
659,
334,
21,
12,
283,
21,
659,
334,
22,
12,
283,
22,
358,
2459,
12884,
661,
24038,
297,
7328,
14,
1018,
14,
4166,
14,
17972,
7694,
66,
1133,
832,
297,
7328,
14,
1018,
14,
4166,
14,
19537,
3142,
4000,
334,
66,
7,
1180,
63,
17264,
2352,
439,
297,
7328,
14,
1018,
14,
4166,
14,
4082,
3142,
8,
2427,
29,
797,
430,
12884,
661,
3491,
297,
7328,
14,
1018,
14,
4166,
14,
17972,
7694,
66,
7,
1569,
297,
7328,
14,
4782,
14,
4166,
14,
3491,
24096,
4000,
334,
66,
7,
16748,
297,
7328,
14,
1018,
14,
4166,
14,
9054,
3142,
8,
885,
534,
2861,
297,
3415,
11699,
3039,
297,
283,
8185,
15170,
784,
379,
659,
661,
1019,
297,
283,
9121,
15170,
784,
379,
659,
661,
2861,
297,
283,
9042,
644,
1466,
659,
661,
23507,
2675,
297,
283,
9042,
644,
1466,
446,
3091,
445,
20148,
2023,
395,
334,
66,
7,
2613,
63,
8665,
297,
7328,
14,
1018,
14,
4166,
14,
4082,
3142,
8,
885,
29,
797,
12,
1415,
29,
797,
1826,
334,
66,
7,
4441,
461,
297,
7328,
14,
1018,
14,
4166,
14,
4082,
3142,
8,
885,
29,
797,
12,
1415,
29,
797,
1826,
334,
66,
7,
1302,
297,
7328,
14,
1018,
14,
4166,
14,
14615,
8,
3437,
63,
505,
534,
8824,
1768,
370,
506,
9080,
543,
314,
1834,
3130,
1415,
29,
797,
430,
12884,
661,
13200,
297,
7328,
14,
6427,
83,
14,
4166,
14,
13200,
3142,
8,
4677,
534,
2124,
3855,
661,
1296,
297,
7328,
14,
1018,
14,
4166,
14,
1296,
3142,
8,
17296,
14,
1018,
14,
4166,
14,
19537,
3142,
8,
1302,
534,
1053,
659,
7016,
534,
513,
13,
348,
3855,
661,
2662,
19816,
297,
23242,
14,
955,
14,
2662,
19816,
3142,
4000,
661,
27318,
12838,
297,
23242,
14,
955,
14,
27318,
12838,
3142,
4000,
661,
12838,
297,
23242,
14,
955,
14,
3184,
12838,
3142,
4000,
661,
5674,
1659,
297,
7328,
14,
1018,
14,
4166,
14,
17972,
7694,
66,
7,
2030,
297,
7328,
14,
1018,
14,
4166,
14,
3296,
3142,
7694,
66,
7,
23818,
297,
7328,
14,
1018,
14,
4166,
14,
17972,
7694,
66,
1133,
832,
297,
7328,
14,
1018,
14,
4166,
14,
14615,
4000,
334,
66,
7,
13983,
63,
1896,
297,
7328,
14,
1018,
14,
4166,
14,
9054,
3142,
8,
885,
29,
18,
12,
3415,
17497,
18,
12,
283,
18,
659,
334,
19,
12,
283,
19,
659,
334,
20,
12,
283,
20,
659,
334,
21,
12,
283,
21,
659,
334,
22,
12,
283,
22,
358,
2459,
12884,
334,
66,
7,
24038,
297,
7328,
14,
1018,
14,
4166,
14,
17972,
7694,
66,
1133,
832,
297,
7328,
14,
1018,
14,
4166,
14,
19537,
3142,
4000,
334,
66,
7,
1180,
63,
17264,
2352,
439,
297,
7328,
14,
1018,
14,
4166,
14,
4082,
3142,
8,
2427,
29,
797,
430,
12884,
334,
66,
7,
3491,
297,
7328,
14,
1018,
14,
4166,
14,
17972,
7694,
66,
7,
1569,
297,
7328,
14,
4782,
14,
4166,
14,
3491,
24096,
4000,
334,
66,
7,
16748,
297,
7328,
14,
1018,
14,
4166,
14,
9054,
3142,
8,
885,
534,
2861,
297,
3415,
11699,
3039,
297,
283,
8185,
15170,
784,
379,
659,
661,
1019,
297,
283,
9121,
15170,
784,
379,
659,
661,
2861,
297,
283,
9042,
644,
1466,
659,
661,
23507,
2675,
297,
283,
9042,
644,
1466,
446,
3091,
445,
20148,
2023,
395,
334,
66,
7,
2613,
63,
8665,
297,
7328,
14,
1018,
14,
4166,
14,
4082,
3142,
8,
885,
29,
797,
12,
1415,
29,
797,
1826,
334,
66,
7,
4441,
461,
297,
7328,
14,
1018,
14,
4166,
14,
4082,
3142,
8,
885,
29,
797,
12,
1415,
29,
797,
1826,
334,
66,
7,
1302,
297,
7328,
14,
1018,
14,
4166,
14,
14615,
8,
3437,
63,
505,
534,
8824,
1768,
370,
506,
9080,
543,
314,
1834,
3130,
1415,
29,
797,
430,
12884,
334,
66,
7,
13200,
297,
7328,
14,
6427,
83,
14,
4166,
14,
13200,
3142,
8,
4677,
534,
2124,
3855,
334,
66,
7,
1296,
297,
7328,
14,
1018,
14,
4166,
14,
1296,
3142,
8,
17296,
14,
1018,
14,
4166,
14,
19537,
3142,
8,
1302,
534,
1053,
659,
7016,
534,
513,
13,
348,
3855,
334,
66,
7,
2662,
19816,
297,
23242,
14,
955,
14,
2662,
19816,
3142,
4000,
334,
66,
7,
27318,
12838,
297,
23242,
14,
955,
14,
27318,
12838,
3142,
4000,
334,
66,
7,
12838,
297,
23242,
14,
955,
14,
3184,
12838,
3142,
4000,
334,
66,
7,
23879,
297,
23242,
14,
955,
14,
23879,
3142,
8,
262,
2967,
67,
7301,
14,
992,
14,
23879,
1826,
334,
66,
7,
13885,
7412,
297,
7328,
14,
1018,
14,
4166,
14,
17972,
7694,
66,
7,
13983,
297,
7328,
14,
1018,
14,
4166,
14,
14615,
8,
885,
534,
13885,
3855,
334,
66,
7,
1744,
297,
7328,
14,
1018,
14,
4166,
14,
1296,
3142,
8,
17296,
14,
1018,
14,
4166,
14,
3276,
24096,
8,
1302,
534,
1053,
7058,
467,
7016,
534,
513,
13,
348,
3855,
334,
66,
7,
4547,
379,
2714,
297,
7328,
14,
1018,
14,
4166,
14,
17972,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Conservatory/quark
|
pymouse/build/lib.linux-x86_64-2.7/pymouse/__init__.py
|
7
|
1119
|
# -*- coding: iso-8859-1 -*-
# Copyright 2010 Pepijn de Vos
#
# 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.
"""The goal of PyMouse is to have a cross-platform way to control the mouse.
PyMouse should work on Windows, Mac and any Unix that has xlib.
See http://github.com/pepijndevos/PyMouse for more information.
"""
import sys
if sys.platform.startswith('java'):
from java_ import PyMouse
elif sys.platform == 'darwin':
from mac import PyMouse, PyMouseEvent
elif sys.platform == 'win32':
from windows import PyMouse, PyMouseEvent
else:
from unix import PyMouse, PyMouseEvent
|
gpl-2.0
|
[
3,
1882,
2803,
26,
11601,
13,
4830,
13,
17,
1882,
199,
199,
3,
257,
1898,
7129,
11379,
1038,
24016,
477,
812,
736,
199,
3,
199,
3,
257,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
257,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
257,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
755,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
257,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
257,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
257,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
257,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
257,
4204,
1334,
314,
844,
14,
199,
199,
624,
1918,
14850,
402,
1611,
17141,
365,
370,
1172,
282,
8059,
13,
3246,
4340,
370,
3304,
314,
12817,
14,
199,
2713,
17141,
1077,
1736,
641,
5417,
12,
10444,
436,
1263,
13074,
626,
965,
671,
773,
14,
199,
199,
9295,
1455,
921,
5031,
14,
957,
15,
321,
1038,
24016,
2374,
736,
15,
2713,
17141,
367,
1655,
2556,
14,
199,
624,
199,
199,
646,
984,
199,
199,
692,
984,
14,
3246,
14,
2460,
360,
6138,
735,
272,
687,
12120,
63,
492,
1611,
17141,
199,
199,
4164,
984,
14,
3246,
508,
283,
13245,
356,
272,
687,
4497,
492,
1611,
17141,
12,
1611,
17141,
2390,
199,
199,
4164,
984,
14,
3246,
508,
283,
2676,
708,
356,
272,
687,
10061,
492,
1611,
17141,
12,
1611,
17141,
2390,
199,
199,
2836,
26,
272,
687,
16572,
492,
1611,
17141,
12,
1611,
17141,
2390,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
11601,
13,
4830,
13,
17,
1882,
199,
199,
3,
257,
1898,
7129,
11379,
1038,
24016,
477,
812,
736,
199,
3,
199,
3,
257,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
257,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
257,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
755,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
257,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
257,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
257,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
257,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
257,
4204,
1334,
314,
844,
14,
199,
199,
624,
1918,
14850,
402,
1611,
17141,
365,
370,
1172,
282,
8059,
13,
3246,
4340,
370,
3304,
314,
12817,
14,
199,
2713,
17141,
1077,
1736,
641,
5417,
12,
10444,
436,
1263,
13074,
626,
965,
671,
773,
14,
199,
199,
9295,
1455,
921,
5031,
14,
957,
15,
321,
1038,
24016,
2374,
736,
15,
2713,
17141,
367,
1655,
2556,
14,
199,
624,
199,
199,
646,
984,
199,
199,
692,
984,
14,
3246,
14,
2460,
360,
6138,
735,
272,
687,
12120,
63,
492,
1611,
17141,
199,
199,
4164,
984,
14,
3246,
508,
283,
13245,
356,
272,
687,
4497,
492,
1611,
17141,
12,
1611,
17141,
2390,
199,
199,
4164,
984,
14,
3246,
508,
283,
2676,
708,
356,
272,
687,
10061,
492,
1611,
17141,
12,
1611,
17141,
2390,
199,
199,
2836,
26,
272,
687,
16572,
492,
1611,
17141,
12,
1611,
17141,
2390,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
boooka/GeoPowerOff
|
venv/lib/python2.7/site-packages/django/conf/locale/sl/formats.py
|
200
|
2120
|
# -*- encoding: utf-8 -*-
# This file is distributed under the same license as the Django package.
#
from __future__ import unicode_literals
# The *_FORMAT strings use the Django date format syntax,
# see http://docs.djangoproject.com/en/dev/ref/templates/builtins/#date
DATE_FORMAT = 'd. F Y'
TIME_FORMAT = 'H:i:s'
DATETIME_FORMAT = 'j. F Y. H:i'
YEAR_MONTH_FORMAT = 'F Y'
MONTH_DAY_FORMAT = 'j. F'
SHORT_DATE_FORMAT = 'j. M. Y'
SHORT_DATETIME_FORMAT = 'j.n.Y. H:i'
FIRST_DAY_OF_WEEK = 0
# The *_INPUT_FORMATS strings use the Python strftime format syntax,
# see http://docs.python.org/library/datetime.html#strftime-strptime-behavior
DATE_INPUT_FORMATS = (
'%d.%m.%Y', '%d.%m.%y', # '25.10.2006', '25.10.06'
'%d-%m-%Y', # '25-10-2006'
'%d. %m. %Y', '%d. %m. %y', # '25. 10. 2006', '25. 10. 06'
)
DATETIME_INPUT_FORMATS = (
'%d.%m.%Y %H:%M:%S', # '25.10.2006 14:30:59'
'%d.%m.%Y %H:%M:%S.%f', # '25.10.2006 14:30:59.000200'
'%d.%m.%Y %H:%M', # '25.10.2006 14:30'
'%d.%m.%Y', # '25.10.2006'
'%d.%m.%y %H:%M:%S', # '25.10.06 14:30:59'
'%d.%m.%y %H:%M:%S.%f', # '25.10.06 14:30:59.000200'
'%d.%m.%y %H:%M', # '25.10.06 14:30'
'%d.%m.%y', # '25.10.06'
'%d-%m-%Y %H:%M:%S', # '25-10-2006 14:30:59'
'%d-%m-%Y %H:%M:%S.%f', # '25-10-2006 14:30:59.000200'
'%d-%m-%Y %H:%M', # '25-10-2006 14:30'
'%d-%m-%Y', # '25-10-2006'
'%d. %m. %Y %H:%M:%S', # '25. 10. 2006 14:30:59'
'%d. %m. %Y %H:%M:%S.%f', # '25. 10. 2006 14:30:59.000200'
'%d. %m. %Y %H:%M', # '25. 10. 2006 14:30'
'%d. %m. %Y', # '25. 10. 2006'
'%d. %m. %y %H:%M:%S', # '25. 10. 06 14:30:59'
'%d. %m. %y %H:%M:%S.%f', # '25. 10. 06 14:30:59.000200'
'%d. %m. %y %H:%M', # '25. 10. 06 14:30'
'%d. %m. %y', # '25. 10. 06'
)
DECIMAL_SEPARATOR = ','
THOUSAND_SEPARATOR = '.'
NUMBER_GROUPING = 3
|
apache-2.0
|
[
3,
1882,
2644,
26,
2774,
13,
24,
1882,
199,
3,
961,
570,
365,
1854,
1334,
314,
2011,
4190,
465,
314,
5634,
2559,
14,
199,
3,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
3,
710,
20841,
4807,
3326,
675,
314,
5634,
1434,
1475,
6302,
12,
199,
3,
1937,
1455,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
2374,
15,
1121,
15,
5876,
15,
10372,
12645,
602,
199,
5390,
63,
4807,
275,
283,
68,
14,
481,
1488,
7,
199,
4961,
63,
4807,
275,
283,
40,
26,
73,
26,
83,
7,
199,
12488,
63,
4807,
275,
283,
74,
14,
481,
1488,
14,
869,
26,
73,
7,
199,
19216,
63,
16413,
63,
4807,
275,
283,
38,
1488,
7,
199,
16413,
63,
11655,
63,
4807,
275,
283,
74,
14,
481,
7,
199,
13003,
63,
5390,
63,
4807,
275,
283,
74,
14,
603,
14,
1488,
7,
199,
13003,
63,
12488,
63,
4807,
275,
283,
74,
14,
78,
14,
57,
14,
869,
26,
73,
7,
199,
12903,
63,
11655,
63,
3359,
63,
24929,
275,
378,
199,
199,
3,
710,
20841,
7321,
63,
14019,
3326,
675,
314,
2018,
14053,
1475,
6302,
12,
199,
3,
1937,
1455,
921,
4757,
14,
1548,
14,
1308,
15,
4342,
15,
2083,
14,
1360,
3,
6205,
13,
9866,
13,
17537,
199,
5390,
63,
7321,
63,
14019,
275,
334,
272,
1543,
68,
4111,
77,
4111,
57,
297,
1543,
68,
4111,
77,
4111,
89,
297,
260,
327,
283,
821,
14,
709,
14,
7968,
297,
283,
821,
14,
709,
14,
1690,
7,
272,
1543,
68,
3295,
77,
3295,
57,
297,
9326,
327,
283,
821,
13,
709,
13,
7968,
7,
272,
1543,
68,
14,
450,
77,
14,
450,
57,
297,
1543,
68,
14,
450,
77,
14,
450,
89,
297,
258,
327,
283,
821,
14,
1616,
14,
8315,
297,
283,
821,
14,
1616,
14,
24293,
7,
199,
9,
199,
199,
12488,
63,
7321,
63,
14019,
275,
334,
272,
1543,
68,
4111,
77,
4111,
57,
450,
40,
2689,
45,
2689,
51,
297,
3322,
327,
283,
821,
14,
709,
14,
7968,
4329,
26,
1216,
26,
1427,
7,
272,
1543,
68,
4111,
77,
4111,
57,
450,
40,
2689,
45,
2689,
51,
4111,
70,
297,
260,
327,
283,
821,
14,
709,
14,
7968,
4329,
26,
1216,
26,
1427,
14,
25080,
7,
272,
1543,
68,
4111,
77,
4111,
57,
450,
40,
2689,
45,
297,
5185,
327,
283,
821,
14,
709,
14,
7968,
4329,
26,
1216,
7,
272,
1543,
68,
4111,
77,
4111,
57,
297,
9326,
327,
283,
821,
14,
709,
14,
7968,
7,
272,
1543,
68,
4111,
77,
4111,
89,
450,
40,
2689,
45,
2689,
51,
297,
3322,
327,
283,
821,
14,
709,
14,
1690,
4329,
26,
1216,
26,
1427,
7,
272,
1543,
68,
4111,
77,
4111,
89,
450,
40,
2689,
45,
2689,
51,
4111,
70,
297,
260,
327,
283,
821,
14,
709,
14,
1690,
4329,
26,
1216,
26,
1427,
14,
25080,
7,
272,
1543,
68,
4111,
77,
4111,
89,
450,
40,
2689,
45,
297,
4483,
327,
283,
821,
14,
709,
14,
1690,
4329,
26,
1216,
7,
272,
1543,
68,
4111,
77,
4111,
89,
297,
9326,
327,
283,
821,
14,
709,
14,
1690,
7,
272,
1543,
68,
3295,
77,
3295,
57,
450,
40,
2689,
45,
2689,
51,
297,
3322,
327,
283,
821,
13,
709,
13,
7968,
4329,
26,
1216,
26,
1427,
7,
272,
1543,
68,
3295,
77,
3295,
57,
450,
40,
2689,
45,
2689,
51,
4111,
70,
297,
260,
327,
283,
821,
13,
709,
13,
7968,
4329,
26,
1216,
26,
1427,
14,
25080,
7,
272,
1543,
68,
3295,
77,
3295,
57,
450,
40,
2689,
45,
297,
5185,
327,
283,
821,
13,
709,
13,
7968,
4329,
26,
1216,
7,
272,
1543,
68,
3295,
77,
3295,
57,
297,
9326,
327,
283,
821,
13,
709,
13,
7968,
7,
272,
1543,
68,
14,
450,
77,
14,
450,
57,
450,
40,
2689,
45,
2689,
51,
297,
3515,
327,
283,
821,
14,
1616,
14,
8315,
4329,
26,
1216,
26,
1427,
7,
272,
1543,
68,
14,
450,
77,
14,
450,
57,
450,
40,
2689,
45,
2689,
51,
4111,
70,
297,
755,
327,
283,
821,
14,
1616,
14,
8315,
4329,
26,
1216,
26,
1427,
14,
25080,
7,
272,
1543,
68,
14,
450,
77,
14,
450,
57,
450,
40,
2689,
45,
297,
3777,
327,
283,
821,
14,
1616,
14,
8315,
4329,
26,
1216,
7,
272,
1543,
68,
14,
450,
77,
14,
450,
57,
297,
7861,
327,
283,
821,
14,
1616,
14,
8315,
7,
272,
1543,
68,
14,
450,
77,
14,
450,
89,
450,
40,
2689,
45,
2689,
51,
297,
3515,
327,
283,
821,
14,
1616,
14,
24293,
4329,
26,
1216,
26,
1427,
7,
272,
1543,
68,
14,
450,
77,
14,
450,
89,
450,
40,
2689,
45,
2689,
51,
4111,
70,
297,
755,
327,
283,
821,
14,
1616,
14,
24293,
4329,
26,
1216,
26,
1427,
14,
25080,
7,
272,
1543,
68,
14,
450,
77,
14,
450,
89,
450,
40,
2689,
45,
297,
3777,
327,
283,
821,
14,
1616,
14,
24293,
4329,
26,
1216,
7,
272,
1543,
68,
14,
450,
77,
14,
450,
89,
297,
7861,
327,
283,
821,
14,
1616,
14,
24293,
7,
199,
9,
199,
199,
23925,
63,
15828,
275,
13647,
199,
28714,
63,
15828,
275,
7815,
199,
9190,
63,
7823,
1206,
275,
650,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2644,
26,
2774,
13,
24,
1882,
199,
3,
961,
570,
365,
1854,
1334,
314,
2011,
4190,
465,
314,
5634,
2559,
14,
199,
3,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
3,
710,
20841,
4807,
3326,
675,
314,
5634,
1434,
1475,
6302,
12,
199,
3,
1937,
1455,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
2374,
15,
1121,
15,
5876,
15,
10372,
12645,
602,
199,
5390,
63,
4807,
275,
283,
68,
14,
481,
1488,
7,
199,
4961,
63,
4807,
275,
283,
40,
26,
73,
26,
83,
7,
199,
12488,
63,
4807,
275,
283,
74,
14,
481,
1488,
14,
869,
26,
73,
7,
199,
19216,
63,
16413,
63,
4807,
275,
283,
38,
1488,
7,
199,
16413,
63,
11655,
63,
4807,
275,
283,
74,
14,
481,
7,
199,
13003,
63,
5390,
63,
4807,
275,
283,
74,
14,
603,
14,
1488,
7,
199,
13003,
63,
12488,
63,
4807,
275,
283,
74,
14,
78,
14,
57,
14,
869,
26,
73,
7,
199,
12903,
63,
11655,
63,
3359,
63,
24929,
275,
378,
199,
199,
3,
710,
20841,
7321,
63,
14019,
3326,
675,
314,
2018,
14053,
1475,
6302,
12,
199,
3,
1937,
1455,
921,
4757,
14,
1548,
14,
1308,
15,
4342,
15,
2083,
14,
1360,
3,
6205,
13,
9866,
13,
17537,
199,
5390,
63,
7321,
63,
14019,
275,
334,
272,
1543,
68,
4111,
77,
4111,
57,
297,
1543,
68,
4111,
77,
4111,
89,
297,
260,
327,
283,
821,
14,
709,
14,
7968,
297,
283,
821,
14,
709,
14,
1690,
7,
272,
1543,
68,
3295,
77,
3295,
57,
297,
9326,
327,
283,
821,
13,
709,
13,
7968,
7,
272,
1543,
68,
14,
450,
77,
14,
450,
57,
297,
1543,
68,
14,
450,
77,
14,
450,
89,
297,
258,
327,
283,
821,
14,
1616,
14,
8315,
297,
283,
821,
14,
1616,
14,
24293,
7,
199,
9,
199,
199,
12488,
63,
7321,
63,
14019,
275,
334,
272,
1543,
68,
4111,
77,
4111,
57,
450,
40,
2689,
45,
2689,
51,
297,
3322,
327,
283,
821,
14,
709,
14,
7968,
4329,
26,
1216,
26,
1427,
7,
272,
1543,
68,
4111,
77,
4111,
57,
450,
40,
2689,
45,
2689,
51,
4111,
70,
297,
260,
327,
283,
821,
14,
709,
14,
7968,
4329,
26,
1216,
26,
1427,
14,
25080,
7,
272,
1543,
68,
4111,
77,
4111,
57,
450,
40,
2689,
45,
297,
5185,
327,
283,
821,
14,
709,
14,
7968,
4329,
26,
1216,
7,
272,
1543,
68,
4111,
77,
4111,
57,
297,
9326,
327,
283,
821,
14,
709,
14,
7968,
7,
272,
1543,
68,
4111,
77,
4111,
89,
450,
40,
2689,
45,
2689,
51,
297,
3322,
327,
283,
821,
14,
709,
14,
1690,
4329,
26,
1216,
26,
1427,
7,
272,
1543,
68,
4111,
77,
4111,
89,
450,
40,
2689,
45,
2689,
51,
4111,
70,
297,
260,
327,
283,
821,
14,
709,
14,
1690,
4329,
26,
1216,
26,
1427,
14,
25080,
7,
272,
1543,
68,
4111,
77,
4111,
89,
450,
40,
2689,
45,
297,
4483,
327,
283,
821,
14,
709,
14,
1690,
4329,
26,
1216,
7,
272,
1543,
68,
4111,
77,
4111,
89,
297,
9326,
327,
283,
821,
14,
709,
14,
1690,
7,
272,
1543,
68,
3295,
77,
3295,
57,
450,
40,
2689,
45,
2689,
51,
297,
3322,
327,
283,
821,
13,
709,
13,
7968,
4329,
26,
1216,
26,
1427,
7,
272,
1543,
68,
3295,
77,
3295,
57,
450,
40,
2689,
45,
2689,
51,
4111,
70,
297,
260,
327,
283,
821,
13,
709,
13,
7968,
4329,
26,
1216,
26,
1427,
14,
25080,
7,
272,
1543,
68,
3295,
77,
3295,
57,
450,
40,
2689,
45,
297,
5185,
327,
283,
821,
13,
709,
13,
7968,
4329,
26,
1216,
7,
272,
1543,
68,
3295,
77,
3295,
57,
297,
9326,
327,
283,
821,
13,
709,
13,
7968,
7,
272,
1543,
68,
14,
450,
77,
14,
450,
57,
450,
40,
2689,
45,
2689,
51,
297,
3515,
327,
283,
821,
14,
1616,
14,
8315,
4329,
26,
1216,
26,
1427,
7,
272,
1543,
68,
14,
450,
77,
14,
450,
57,
450,
40,
2689,
45,
2689,
51,
4111,
70,
297,
755,
327,
283,
821,
14,
1616,
14,
8315,
4329,
26,
1216,
26,
1427,
14,
25080,
7,
272,
1543,
68,
14,
450,
77,
14,
450,
57,
450,
40,
2689,
45,
297,
3777,
327,
283,
821,
14,
1616,
14,
8315,
4329,
26,
1216,
7,
272,
1543,
68,
14,
450,
77,
14,
450,
57,
297,
7861,
327,
283,
821,
14,
1616,
14,
8315,
7,
272,
1543,
68,
14,
450,
77,
14,
450,
89,
450,
40,
2689,
45,
2689,
51,
297,
3515,
327,
283,
821,
14,
1616,
14,
24293,
4329,
26,
1216,
26,
1427,
7,
272,
1543,
68,
14,
450,
77,
14,
450,
89,
450,
40,
2689,
45,
2689,
51,
4111,
70,
297,
755,
327,
283,
821,
14,
1616,
14,
24293,
4329,
26,
1216,
26,
1427,
14,
25080,
7,
272,
1543,
68,
14,
450,
77,
14,
450,
89,
450,
40,
2689,
45,
297,
3777,
327,
283,
821,
14,
1616,
14,
24293,
4329,
26,
1216,
7,
272,
1543,
68,
14,
450,
77,
14,
450,
89,
297,
7861,
327,
283,
821,
14,
1616,
14,
24293,
7,
199,
9,
199,
199,
23925,
63,
15828,
275,
13647,
199,
28714,
63,
15828,
275,
7815,
199,
9190,
63,
7823,
1206,
275,
650,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
tafaRU/odoo
|
addons/payment_ogone/controllers/main.py
|
389
|
1179
|
# -*- coding: utf-8 -*-
import logging
import pprint
import werkzeug
from openerp import http, SUPERUSER_ID
from openerp.http import request
_logger = logging.getLogger(__name__)
class OgoneController(http.Controller):
_accept_url = '/payment/ogone/test/accept'
_decline_url = '/payment/ogone/test/decline'
_exception_url = '/payment/ogone/test/exception'
_cancel_url = '/payment/ogone/test/cancel'
@http.route([
'/payment/ogone/accept', '/payment/ogone/test/accept',
'/payment/ogone/decline', '/payment/ogone/test/decline',
'/payment/ogone/exception', '/payment/ogone/test/exception',
'/payment/ogone/cancel', '/payment/ogone/test/cancel',
], type='http', auth='none')
def ogone_form_feedback(self, **post):
""" Ogone contacts using GET, at least for accept """
_logger.info('Ogone: entering form_feedback with post data %s', pprint.pformat(post)) # debug
cr, uid, context = request.cr, SUPERUSER_ID, request.context
request.registry['payment.transaction'].form_feedback(cr, uid, post, 'ogone', context=context)
return werkzeug.utils.redirect(post.pop('return_url', '/'))
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
646,
2050,
199,
646,
10933,
199,
646,
10380,
199,
199,
504,
5166,
492,
1455,
12,
12824,
63,
998,
199,
504,
5166,
14,
1014,
492,
1056,
199,
199,
63,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
593,
32227,
7506,
8,
1014,
14,
7506,
304,
272,
485,
5694,
63,
633,
275,
1994,
7948,
15,
29163,
15,
396,
15,
5694,
7,
272,
485,
9427,
1132,
63,
633,
275,
1994,
7948,
15,
29163,
15,
396,
15,
9427,
1132,
7,
272,
485,
1971,
63,
633,
275,
1994,
7948,
15,
29163,
15,
396,
15,
1971,
7,
272,
485,
6406,
63,
633,
275,
1994,
7948,
15,
29163,
15,
396,
15,
6406,
7,
339,
768,
1014,
14,
4449,
779,
267,
1994,
7948,
15,
29163,
15,
5694,
297,
1994,
7948,
15,
29163,
15,
396,
15,
5694,
297,
267,
1994,
7948,
15,
29163,
15,
9427,
1132,
297,
1994,
7948,
15,
29163,
15,
396,
15,
9427,
1132,
297,
267,
1994,
7948,
15,
29163,
15,
1971,
297,
1994,
7948,
15,
29163,
15,
396,
15,
1971,
297,
267,
1994,
7948,
15,
29163,
15,
6406,
297,
1994,
7948,
15,
29163,
15,
396,
15,
6406,
297,
272,
2156,
730,
534,
1014,
297,
1790,
534,
3592,
358,
272,
347,
312,
32227,
63,
964,
63,
13485,
8,
277,
12,
1011,
1932,
304,
267,
408,
593,
32227,
27989,
1808,
9576,
12,
737,
5210,
367,
4729,
408,
267,
485,
2921,
14,
815,
360,
47,
32227,
26,
9509,
316,
1824,
63,
13485,
543,
2963,
666,
450,
83,
297,
10933,
14,
24225,
8,
1932,
430,
221,
327,
3105,
267,
2467,
12,
1747,
12,
1067,
275,
1056,
14,
1556,
12,
12824,
63,
998,
12,
1056,
14,
1100,
267,
1056,
14,
5189,
459,
7948,
14,
5945,
2278,
964,
63,
13485,
8,
1556,
12,
1747,
12,
2963,
12,
283,
29163,
297,
1067,
29,
1100,
9,
267,
372,
10380,
14,
1208,
14,
4876,
8,
1932,
14,
1935,
360,
1107,
63,
633,
297,
1994,
1333,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
646,
2050,
199,
646,
10933,
199,
646,
10380,
199,
199,
504,
5166,
492,
1455,
12,
12824,
63,
998,
199,
504,
5166,
14,
1014,
492,
1056,
199,
199,
63,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
593,
32227,
7506,
8,
1014,
14,
7506,
304,
272,
485,
5694,
63,
633,
275,
1994,
7948,
15,
29163,
15,
396,
15,
5694,
7,
272,
485,
9427,
1132,
63,
633,
275,
1994,
7948,
15,
29163,
15,
396,
15,
9427,
1132,
7,
272,
485,
1971,
63,
633,
275,
1994,
7948,
15,
29163,
15,
396,
15,
1971,
7,
272,
485,
6406,
63,
633,
275,
1994,
7948,
15,
29163,
15,
396,
15,
6406,
7,
339,
768,
1014,
14,
4449,
779,
267,
1994,
7948,
15,
29163,
15,
5694,
297,
1994,
7948,
15,
29163,
15,
396,
15,
5694,
297,
267,
1994,
7948,
15,
29163,
15,
9427,
1132,
297,
1994,
7948,
15,
29163,
15,
396,
15,
9427,
1132,
297,
267,
1994,
7948,
15,
29163,
15,
1971,
297,
1994,
7948,
15,
29163,
15,
396,
15,
1971,
297,
267,
1994,
7948,
15,
29163,
15,
6406,
297,
1994,
7948,
15,
29163,
15,
396,
15,
6406,
297,
272,
2156,
730,
534,
1014,
297,
1790,
534,
3592,
358,
272,
347,
312,
32227,
63,
964,
63,
13485,
8,
277,
12,
1011,
1932,
304,
267,
408,
593,
32227,
27989,
1808,
9576,
12,
737,
5210,
367,
4729,
408,
267,
485,
2921,
14,
815,
360,
47,
32227,
26,
9509,
316,
1824,
63,
13485,
543,
2963,
666,
450,
83,
297,
10933,
14,
24225,
8,
1932,
430,
221,
327,
3105,
267,
2467,
12,
1747,
12,
1067,
275,
1056,
14,
1556,
12,
12824,
63,
998,
12,
1056,
14,
1100,
267,
1056,
14,
5189,
459,
7948,
14,
5945,
2278,
964,
63,
13485,
8,
1556,
12,
1747,
12,
2963,
12,
283,
29163,
297,
1067,
29,
1100,
9,
267,
372,
10380,
14,
1208,
14,
4876,
8,
1932,
14,
1935,
360,
1107,
63,
633,
297,
1994,
1333,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
aabdin01/concourse
|
concourse-driver-python/concourse/concourse.py
|
7
|
49719
|
__author__ = "Jeff Nelson"
__copyright__ = "Copyright 2015, Cinchapi Inc."
__license__ = "Apache, Version 2.0"
from thrift import Thrift
from thrift.transport import TSocket
from thriftapi import ConcourseService
from thriftapi.shared.ttypes import *
from utils import *
from collections import OrderedDict
import ujson
from configparser import ConfigParser
import itertools
import os
class Concourse(object):
""" Concourse is a self-tuning database that makes it easier to quickly build reliable and scalable systems.
Concourse dynamically adapts to any application and offers features like automatic indexing, version control, and
distributed ACID transactions within a big data platform that manages itself, reduces costs and allows developers
to focus on what really matters.
Data Model:
The Concourse data model is lightweight and flexible. Unlike other databases, Concourse is completely schemaless and
does not hold data in tables or collections. Concourse is simply a distributed document-graph. All data is
stored in records (similar to documents or rows in other databases). Each record has multiple keys. And each
key has one or more distinct values. Like any graph, you can link records to one another. And the structure of one
record does not affect the structure of another.
- Record: A logical grouping of data about a single person, place or thing (i.e. an object). Each record is
identified by a unique primary key.
- Key: A attribute that maps to one or more distinct values.
- Value: A dynamically typed quantity.
Data Types:
Concourse natively stores the following primitives: bool, double, integer, string (UTF-8) and Tag (a string that is
not full text searchable). Any other data type will be stored as its __str__ representation.
Links:
Concourse allows linking a key in one record to another record using the link() function. Links are retrievable and
queryable just like any other value.
Transactions:
By default, Concourse conducts every operation in autocommit mode where every change is immediately written.
You can also stage a group of operations in an ACID transaction. Transactions are managed using the stage(),
commit() and abort() commands.
Version Control:
Concourse automatically tracks every changes to data and the API exposes several methods to tap into this feature.
1) You can get() and select() previous version of data by specifying a timestamp using natural language or a unix
timestamp integer in microseconds.
2) You can browse() and find() records that matched a criteria in the past by specifying a timestamp using natural
language or a unix timestamp integer in microseconds.
3) You can audit() and diff() changes over time, revert() to previous states and chronologize() how data has
evolved within a range of time.
"""
@staticmethod
def connect(host="localhost", port=1717, username="admin", password="admin", environment="", **kwargs):
""" This is an alias for the constructor.
"""
return Concourse(host, port, username, password, environment, **kwargs)
def __init__(self, host="localhost", port=1717, username="admin", password="admin", environment="", **kwargs):
""" Initialize a new client connection
:param host: the server host (default: localhost)
:param port: the listener post (default: 1717)
:param username: the username with which to connect (default: admin)
:param password: the password for the username (default: admin)
:param environment: the environment to use, (default: the 'default_environment' in the server's
concourse.prefs file)
You may specify the path to a preferences file using the 'prefs' keyword argument. If a prefs file
is supplied, the values contained therewithin for any of arguments above become the default
if the arguments are not explicitly given values.
:return: the handle
"""
username = username or find_in_kwargs_by_alias('username', kwargs)
password = password or find_in_kwargs_by_alias('password', kwargs)
prefs = find_in_kwargs_by_alias('prefs', kwargs)
if prefs:
# Hack to use ConfigParser with java style properties file
with open(os.path.abspath(os.path.expanduser(prefs))) as stream:
lines = itertools.chain(("[default]",), stream)
prefs = ConfigParser()
prefs.read_file(lines)
prefs = dict(prefs._sections['default'])
else:
prefs = {}
self.host = prefs.get('host', host)
self.port = int(prefs.get('port', port))
self.username = prefs.get('username', username)
self.password = prefs.get('password', password)
self.environment = prefs.get('environment', environment)
try:
transport = TSocket.TSocket(self.host, self.port)
transport = TTransport.TBufferedTransport(transport)
protocol = TBinaryProtocol.TBinaryProtocol(transport)
self.client = ConcourseService.Client(protocol)
transport.open()
self.transport = transport
self.__authenticate()
self.transaction = None
except Thrift.TException:
raise RuntimeError("Could not connect to the Concourse Server at "+self.host+":"+str(self.port))
def __authenticate(self):
""" Internal method to login with the username/password and locally store the AccessToken for use with
subsequent operations.
"""
try:
self.creds = self.client.login(self.username, self.password, self.environment)
except Thrift.TException as e:
raise e
def abort(self):
""" Abort the current transaction and discard any changes that were staged. After returning, the
driver will return to autocommit mode and all subsequent changes will be committed immediately.
"""
if self.transaction:
token = self.transaction
self.transaction = None
self.client.abort(self.creds, token, self.environment)
def add(self, key, value, records=None, **kwargs):
""" Add a a value to a key within a record if it does not exist.
:param key: string
:param value: object
:param record: int (optional) or records: list (optional)
:return: 1) a boolean that indicates whether the value was added, if a record is supplied 2) a dict mapping
record to a boolean that indicates whether the value was added, if a list of records is supplied 3) the id of
the new record where the data was added, if not record is supplied as an argument
"""
value = python_to_thrift(value)
records = records or kwargs.get('record')
if records is None:
return self.client.addKeyValue(key, value, self.creds,
self.transaction, self.environment)
elif isinstance(records, list):
return self.client.addKeyValueRecords(key, value, records,
self.creds, self.transaction, self.environment)
elif isinstance(records, (int, long)):
return self.client.addKeyValueRecord(key, value, records,
self.creds, self.transaction, self.environment)
else:
require_kwarg('key and value')
def audit(self, key=None, record=None, start=None, end=None, **kwargs):
""" Return a log of revisions.
:param key:string (optional)
:param record:int
:param start:string|int (optional)
:param end:string|int (optional)
:return: a dict mapping a timestamp to a description of changes
"""
start = start or find_in_kwargs_by_alias('timestamp', kwargs)
startstr = isinstance(start, basestring)
endstr = isinstance(end, basestring)
if isinstance(key, int):
record = key
key = None
if key and record and start and not startstr and end and not endstr:
data = self.client.auditKeyRecordStartEnd(key, record, start, end, self.creds, self.transaction,
self.environment)
elif key and record and start and startstr and end and endstr:
data = self.client.auditKeyRecordStartstrEndstr(key, record, start, end, self.creds, self.transaction,
self.environment)
elif key and record and start and not startstr:
data = self.client.auditKeyRecordStart(key, record, start, self.creds, self.transaction, self.environment)
elif key and record and start and startstr:
data = self.client.auditKeyRecordStartstr(key, record, start, self.creds, self.transaction, self.environment)
elif key and record:
data = self.client.auditKeyRecord(key, record, self.creds, self.transaction, self.environment)
elif record and start and not startstr and end and not endstr:
data = self.client.auditRecordStartEnd(record, start, end, self.creds, self.transaction,
self.environment)
elif record and start and startstr and end and endstr:
data = self.client.auditRecordStartstrEndstr(record, start, end, self.creds, self.transaction,
self.environment)
elif record and start and not startstr:
data = self.client.auditRecordStart(record, start, self.creds, self.transaction, self.environment)
elif record and start and startstr:
data = self.client.auditRecordStartstr(record, start, self.creds, self.transaction, self.environment)
elif record:
data = self.client.auditRecord(record, self.creds, self.transaction, self.environment)
else:
require_kwarg('record')
data = OrderedDict(sorted(data.items()))
return data
def browse(self, keys=None, timestamp=None, **kwargs):
""" Return a view of all the values indexed for a key or group of keys.
:param key: string or keys: list
:param timestamp:string (optional)
:return: 1) a dict mapping a value to a set of records containing the value if a single key is specified or
2) a dict mapping a key to a dict mapping a value to set of records containing that value of a list of keys
is specified
"""
keys = keys or kwargs.get('key')
timestamp = timestamp or find_in_kwargs_by_alias('timestamp', kwargs)
timestamp_is_string = isinstance(timestamp, basestring)
if isinstance(keys, list) and timestamp and not timestamp_is_string:
data = self.client.browseKeysTime(keys, timestamp, self.creds, self.transaction, self.environment)
elif isinstance(keys, list) and timestamp and timestamp_is_string:
data = self.client.browseKeysTimestr(keys, timestamp, self.creds, self.transaction, self.environment)
elif isinstance(keys, list):
data = self.client.browseKeys(keys, self.creds, self.transaction, self.environment)
elif timestamp and not timestamp_is_string:
data = self.client.browseKeyTime(keys, timestamp, self.creds, self.transaction, self.environment)
elif timestamp and timestamp_is_string:
data = self.client.browseKeyTimestr(keys, timestamp, self.creds, self.transaction, self.environment)
elif keys:
data = self.client.browseKey(keys, self.creds, self.transaction, self.environment)
else:
require_kwarg('key or keys')
return pythonify(data)
def chronologize(self, key, record, start=None, end=None, **kwargs):
""" Return a chronological view that shows the state of a field (key/record) over a range of time.
:param key: string
:param record: int
:param start: string|int (optional)
:param end: string|int (optional)
:return: the chronological view of the field over the specified (or entire) range of time
"""
start = start or find_in_kwargs_by_alias('timestamp', kwargs)
startstr = isinstance(start, basestring)
endstr = isinstance(end, basestring)
if start and not startstr and end and not endstr:
data = self.client.chronologizeKeyRecordStartEnd(key, record, start, end, self.creds, self.transaction,
self.environment)
elif start and startstr and end and endstr:
data = self.client.chronologizeKeyRecordStartstrEndstr(key, record, start, end, self.creds, self.transaction,
self.environment)
elif start and not startstr:
data = self.client.chronologizeKeyRecordStart(key, record, start, self.creds, self.transaction,
self.environment)
elif start and startstr:
data = self.client.chronologizeKeyRecordStartstr(key, record, start, self.creds, self.transaction,
self.environment)
else:
data = self.client.chronologizeKeyRecord(key, record, self.creds, self.transaction, self.environment)
data = OrderedDict(sorted(data.items()))
return pythonify(data)
def clear(self, keys=None, records=None, **kwargs):
""" Atomically remove all the data from a field or an entire record.
:param key: string or keys: list
:param record: int or records list
"""
keys = keys or kwargs.get('key')
records = records or kwargs.get('record')
if isinstance(keys, list) and isinstance(records, list):
return self.client.clearKeysRecords(keys, records, self.creds, self.transaction, self.environment)
elif isinstance(records, list) and not keys:
return self.client.clearRecords(records, self.creds, self.transaction, self.environment)
elif isinstance(keys, list) and records:
return self.client.clearKeysRecord(keys, records, self.creds, self.transaction, self.environment)
elif isinstance(records, list) and keys:
return self.client.clearKeyRecords(keys, records, self.creds, self.transaction, self.environment)
elif keys and records:
return self.client.clearKeyRecord(keys, records, self.creds, self.transaction, self.environment)
elif records:
return self.client.clearRecord(records, self.creds, self.transaction, self.environment)
else:
require_kwarg('record or records')
def commit(self):
""" Commit the currently running transaction.
:return: True if the transaction commits. Otherwise, False.
"""
token = self.transaction
self.transaction = None
if token:
return self.client.commit(self.creds, token, self.environment)
else:
return False
def describe(self, records=None, timestamp=None, **kwargs):
""" Return all keys in a record at the present or the specified timestamp.
:param record (int) or records (list)
:param timestamp: string|int (optional)
:return: a set of keys if a single record if provided, if multiple records are provided, a mapping from the
record to a set of keys
"""
timestamp = timestamp or find_in_kwargs_by_alias('timestamp', kwargs)
timestr = isinstance(timestamp, basestring)
records = records or kwargs.get('record')
if isinstance(records, list) and timestamp and not timestr:
return self.client.describeRecordsTime(records, timestamp, self.creds, self.transaction, self.environment)
elif isinstance(records, list) and timestamp and timestr:
return self.client.describeRecordsTimestr(records, timestamp, self.creds, self.transaction, self.environment)
elif isinstance(records, list):
return self.client.describeRecords(records, self.creds, self.transaction, self.environment)
elif timestamp and not timestr:
return self.client.describeRecordTime(records, timestamp, self.creds, self.transaction, self.environment)
elif timestamp and timestr:
return self.client.describeRecordTimestr(records, timestamp, self.creds, self.transaction, self.environment)
else:
return self.client.describeRecord(records, self.creds, self.transaction, self.environment)
def diff(self, key=None, record=None, start=None, end=None, **kwargs):
""" Return the differences in a field, record of index from a start timestamp to an end timestamp.
:param key:
:param record:
:param start:
:param end:
:return:
"""
start = start or find_in_kwargs_by_alias('timestamp', kwargs)
startstr = isinstance(start, basestring)
endstr = isinstance(end, basestring)
if key and record and start and not startstr and end and not endstr:
data = self.client.diffKeyRecordStartEnd(key, record, start, end, self.creds, self.transaction,
self.environment)
elif key and record and start and startstr and end and endstr:
data = self.client.diffKeyRecordStartstrEndstr(key, record, start, end, self.creds, self.transaction,
self.environment)
elif key and record and start and not startstr:
data = self.client.diffKeyRecordStart(key, record, start, self.creds, self.transaction, self.environment)
elif key and record and start and startstr:
data = self.client.diffKeyRecordStartstr(key, record, start, self.creds, self.transaction, self.environment)
elif key and start and not startstr and end and not endstr:
data = self.client.diffKeyStartEnd(key, start, end, self.creds, self.transaction, self.environment)
elif key and start and startstr and end and endstr:
data = self.client.diffKeyStartstrEndstr(key, start, end, self.creds, self.transaction, self.environment)
elif key and start and not startstr:
data = self.client.diffKeyStart(key, start, self.creds, self.transaction, self.environment)
elif key and start and startstr:
data = self.client.diffKeyStartstr(key, start, self.creds, self.transaction, self.environment)
elif record and start and not startstr and end and not endstr:
data = self.client.diffRecordStartEnd(record, start, end, self.creds, self.transaction, self.environment)
elif record and start and startstr and end and endstr:
data = self.client.diffRecordStartstrEndstr(record, start, end, self.creds, self.transaction,
self.environment)
elif record and start and not startstr:
data = self.client.diffRecordStart(record, start, self.creds, self.transaction, self.environment)
elif record and start and startstr:
data = self.client.diffRecordStartstr(record, start, self.creds, self.transaction, self.environment)
else:
require_kwarg('start and (record or key)')
return pythonify(data)
def close(self):
""" Close the connection.
"""
self.exit()
def exit(self):
""" Close the connection.
"""
self.client.logout(self.creds, self.environment)
self.transport.close()
def find(self, criteria=None, **kwargs):
"""
:param criteria:
:return:
"""
criteria = criteria or find_in_kwargs_by_alias('criteria', kwargs)
key = kwargs.get('key')
operator = kwargs.get('operator')
operatorstr = isinstance(operator, basestring)
values = kwargs.get('value') or kwargs.get('values')
values = [values] if not isinstance(values, list) else values
values = thriftify(values)
timestamp = find_in_kwargs_by_alias('timestamp', kwargs)
timestr = isinstance(timestamp, basestring)
if criteria:
data = self.client.findCcl(criteria, self.creds, self.transaction, self.environment)
elif key and operator and not operatorstr and values and not timestamp:
data = self.client.findKeyOperatorValues(key, operator, values, self.creds, self.transaction,
self.environment)
elif key and operator and operatorstr and values and not timestamp:
data = self.client.findKeyOperatorstrValues(key, operator, values, self.creds, self.transaction,
self.environment)
elif key and operator and not operatorstr and values and timestamp and not timestr:
data = self.client.findKeyOperatorValuesTime(key, operator, values, timestamp, self.creds, self.transaction,
self.environment)
elif key and operator and operatorstr and values and timestamp and not timestr:
data = self.client.findKeyOperatorstrValuesTime(key, operator, values, timestamp, self.creds,
self.transaction, self.environment)
elif key and operator and not operatorstr and values and timestamp and timestr:
data = self.client.findKeyOperatorValuesTimestr(key, operator, values, timestamp, self.creds,
self.transaction, self.environment)
elif key and operator and operatorstr and values and timestamp and timestr:
data = self.client.findKeyOperatorstrValuesTimestr(key, operator, values, timestamp, self.creds,
self.transaction, self.environment)
else:
require_kwarg('criteria or all of (key, operator and value/s)')
data = list(data) if isinstance(data, set) else data
return data
def find_or_add(self, key, value):
"""
:param key:
:param value:
:return:
"""
value = python_to_thrift(value)
return self.client.findOrAddKeyValue(key, value, self.creds, self.transaction, self.environment)
def find_or_insert(self, criteria=None, data=None, **kwargs):
"""
:param criteria:
:param data:
:param kwargs:
:return:
"""
data = data or kwargs.get('json')
if isinstance(data, dict) or isinstance(data, list):
data = ujson.dumps(data)
criteria = criteria or find_in_kwargs_by_alias('criteria', kwargs)
return self.client.findOrInsertCclJson(criteria, data, self.creds, self.transaction, self.environment)
def get(self, keys=None, criteria=None, records=None, timestamp=None, **kwargs):
"""
:param keys:
:param criteria:
:param records:
:param timestamp:
:return:
"""
criteria = criteria or find_in_kwargs_by_alias('criteria', kwargs)
keys = keys or kwargs.get('key')
records = records or kwargs.get('record')
timestamp = timestamp or find_in_kwargs_by_alias('timestamp', kwargs)
timestr = isinstance(timestamp, basestring)
# Handle case when kwargs are not used and the second parameter is a the record
# (e.g. trying to get key/record(s))
if (isinstance(criteria, int) or isinstance(criteria, list)) and not records:
records = criteria
criteria = None
if isinstance(records, list) and not keys and not timestamp:
data = self.client.getRecords(records, self.creds, self.transaction, self.environment)
elif isinstance(records, list) and timestamp and not timestr and not keys:
data = self.client.getRecordsTime(records, timestamp, self.creds, self.transaction, self.environment)
elif isinstance(records, list) and timestamp and timestr and not keys:
data = self.client.getRecordsTimestr(records, timestamp, self.creds, self.transaction, self.environment)
elif isinstance(records, list) and isinstance(keys, list) and not timestamp:
data = self.client.getKeysRecords(keys, records, self.creds, self.transaction, self.environment)
elif isinstance(records, list) and isinstance(keys, list) and timestamp and not timestr:
data = self.client.getKeysRecordsTime(keys, records, timestamp, self.creds, self.transaction,
self.environment)
elif isinstance(records, list) and isinstance(keys, list) and timestamp and timestr:
data = self.client.getKeysRecordsTimestr(keys, records, timestamp, self.creds, self.transaction,
self.environment)
elif isinstance(keys, list) and criteria and not timestamp:
data = self.client.getKeysCcl(keys, criteria, self.creds, self.transaction, self.environment)
elif isinstance(keys, list) and criteria and timestamp and not timestr:
data = self.client.getKeysCclTime(keys, criteria, timestamp, self.creds, self.transaction, self.environment)
elif isinstance(keys, list) and criteria and timestamp and timestr:
data = self.client.getKeysCclTimestr(keys, criteria, timestamp, self.creds, self.transaction,
self.environment)
elif isinstance(keys, list) and records and not timestamp:
data = self.client.getKeysRecord(keys, records, self.creds, self.transaction, self.environment)
elif isinstance(keys, list) and records and timestamp and not timestr:
data = self.client.getKeysRecordTime(keys, records, timestamp, self.creds, self.transaction,
self.environment)
elif isinstance(keys, list) and records and timestamp and timestr:
data = self.client.getKeysRecordTimestr(keys, records, timestamp, self.creds, self.transaction,
self.environment)
elif criteria and not keys and not timestamp:
data = self.client.getCcl(criteria, self.creds, self.transaction, self.environment)
elif criteria and timestamp and not timestr and not keys:
data = self.client.getCclTime(criteria, timestamp, self.creds, self.transaction, self.environment)
elif criteria and timestamp and timestr and not keys:
data = self.client.getCclTimestr(criteria, timestamp, self.creds, self.transaction, self.environment)
elif records and not keys and not timestamp:
data = self.client.getRecord(records, self.creds, self.transaction, self.environment)
elif records and timestamp and not timestr and not keys:
data = self.client.getRecordsTime(records, timestamp, self.creds, self.transaction, self.environment)
elif records and timestamp and timestr and not keys:
data = self.client.getRecordsTimestr(records, timestamp, self.creds, self.transaction, self.environment)
elif keys and criteria and not timestamp:
data = self.client.getKeyCcl(keys, criteria, self.creds, self.transaction, self.environment)
elif keys and criteria and timestamp and not timestr:
data = self.client.getKeyCclTime(keys, criteria, timestamp, self.creds, self.transaction,
self.environment)
elif keys and criteria and timestamp and timestr:
data = self.client.getKeyCclTimestr(keys, criteria, timestamp, self.creds, self.transaction,
self.environment)
elif keys and isinstance(records, list) and not timestamp:
data = self.client.getKeyRecords(keys, records, self.creds, self.transaction, self.environment)
elif keys and records and not timestamp:
data = self.client.getKeyRecord(keys, records, self.creds, self.transaction, self.environment)
elif keys and isinstance(records, list) and timestamp and not timestr:
data = self.client.getKeyRecordsTime(keys, records, timestamp, self.creds, self.transaction,
self.environment)
elif keys and isinstance(records, list) and timestamp and timestr:
data = self.client.getKeyRecordsTimestr(keys, records, timestamp, self.creds, self.transaction,
self.environment)
elif keys and records and timestamp and not timestr:
data = self.client.getKeyRecordTime(keys, records, timestamp, self.creds, self.transaction,
self.environment)
elif keys and records and timestamp and timestr:
data = self.client.getKeyRecordTimestr(keys, records, timestamp, self.creds, self.transaction,
self.environment)
else:
require_kwarg('criteria or (key and record)')
return pythonify(data)
def get_server_environment(self):
""" Return the environment to which the client is connected.
:return: the environment
"""
return self.client.getServerEnvironment(self.creds, self.transaction, self.environment)
def get_server_version(self):
""" Return the version of Concourse Server to which the client is connected. Generally speaking, a client cannot
talk to a newer version of Concourse Server.
:return: the server version
"""
return self.client.getServerVersion()
def insert(self, data, records=None, **kwargs):
""" Bulk insert data from a dict, a list of dicts or a JSON string. This operation is atomic, within each record.
An insert can only succeed within a record if all the data can be successfully added, which means the insert
will fail if any aspect of the data already exists in the record.
If no record or records are specified, the following behaviour occurs
- data is a dict or a JSON object:
The data is inserted into a new record
- data is a list of dicts or a JSON array of objects:
Each dict/object is inserted into a new record
If a record or records are specified, the data must be a JSON object or a dict. In this case, the object/dict is
inserted into every record specified as an argument to the function.
:param data (dict | list | string):
:param record (int) or records(list):
:return: the list of records into which data was inserted, if no records are specified as method arguments.
Otherwise, a bool indicating whether the insert was successful if a single record is specified as an argument
or a dict mapping each specified record to a bool that indicates whether the insert was successful for that
record
"""
data = data or kwargs.get('json')
records = records or kwargs.get('record')
if isinstance(data, dict) or isinstance(data, list):
data = ujson.dumps(data)
if isinstance(records, list):
result = self.client.insertJsonRecords(data, records, self.creds, self.transaction, self.environment)
elif records:
result = self.client.insertJsonRecord(data, records, self.creds, self.transaction, self.environment)
else:
result = self.client.insertJson(data, self.creds, self.transaction, self.environment)
result = list(result) if isinstance(result, set) else result
return result
def inventory(self):
""" Return a list of all the records that have any data.
:return: the inventory
"""
data = self.client.inventory(self.creds, self.transaction, self.environment)
return list(data) if isinstance(data, set) else data
def jsonify(self, records=None, include_id=False, timestamp=None, **kwargs):
"""
:param records:
:param include_id:
:param timestamp:
:param kwargs:
:return:
"""
records = records or kwargs.get('record')
records = list(records) if not isinstance(records, list) else records
timestamp = timestamp or find_in_kwargs_by_alias('timestamp', kwargs)
include_id = include_id or kwargs.get('id', False)
timestr = isinstance(timestamp, basestring)
if not timestamp:
return self.client.jsonifyRecords(records, include_id, self.creds, self.transaction, self.environment)
elif timestamp and not timestr:
return self.client.jsonifyRecordsTime(records, timestamp, include_id, self.creds, self.transaction,
self.environment)
elif timestamp and timestr:
return self.client.jsonifyRecordsTimestr(records, timestamp, include_id, self.creds, self.transaction,
self.environment)
else:
require_kwarg('record or records')
def link(self, key, source, destinations=None, **kwargs):
"""
:param key:
:param source:
:param destinations:
:param destination:
:return:
"""
destinations = destinations or kwargs.get('destination')
if not isinstance(destinations, list):
return self.add(key, Link.to(destinations), source)
else:
data = dict()
for dest in destinations:
data[dest] = self.add(key, Link.to(dest), source)
return data
def logout(self):
"""
:return:
"""
self.client.logout(self.creds, self.environment)
def ping(self, records, **kwargs):
"""
:param records:
:return:
"""
records = records or kwargs.get('record')
if isinstance(records, list):
return self.client.pingRecords(records, self.creds, self.transaction, self.environment)
else:
return self.client.pingRecord(records, self.creds, self.transaction, self.environment)
def remove(self, key, value, records=None, **kwargs):
"""
:param key:
:param value:
:param records:
:return:
"""
value = python_to_thrift(value)
records = records or kwargs.get('record')
if isinstance(records, list):
return self.client.removeKeyValueRecords(key, value, records, self.creds, self.transaction,
self.environment)
elif isinstance(records, (int, long)):
return self.client.removeKeyValueRecord(key, value, records, self.creds, self.transaction, self.environment)
else:
require_kwarg('record or records')
def revert(self, keys=None, records=None, timestamp=None, **kwargs):
"""
:param keys:
:param records:
:param timestamp:
:return:
"""
keys = keys or kwargs.get('key')
records = records or kwargs.get('record')
timestamp = timestamp or find_in_kwargs_by_alias('timestamp', kwargs)
timestr = isinstance(timestamp, basestring)
if isinstance(keys, list) and isinstance(records, list) and timestamp and not timestr:
self.client.revertKeysRecordsTime(keys, records, timestamp, self.creds, self.transaction, self.environment)
elif isinstance(keys, list) and isinstance(records, list) and timestamp and timestr:
self.client.revertKeysRecordsTimestr(keys, records, timestamp, self.creds, self.transaction,
self.environment)
elif isinstance(keys, list) and records and timestamp and not timestr:
self.client.revertKeysRecordTime(keys, records, timestamp, self.creds, self.transaction, self.environment)
elif isinstance(keys, list) and records and timestamp and timestr:
self.client.revertKeysRecordTimestr(keys, records, timestamp, self.creds, self.transaction, self.environment)
elif isinstance(records, list) and keys and timestamp and not timestr:
self.client.revertKeyRecordsTime(keys, records, timestamp, self.creds, self.transaction, self.environment)
elif isinstance(records, list) and keys and timestamp and timestr:
self.client.revertKeyRecordsTimestr(keys, records, timestamp, self.creds, self.transaction, self.environment)
elif keys and records and timestamp and not timestr:
self.client.revertKeyRecordTime(keys, records, timestamp, self.creds, self.transaction, self.environment)
elif keys and records and timestamp and timestr:
self.client.revertKeyRecordTimestr(keys, records, timestamp, self.creds, self.transaction, self.environment)
else:
require_kwarg('keys, record and timestamp')
def search(self, key, query):
"""
:param key:
:param query:
:return:
"""
data = self.client.search(key, query, self.creds, self.transaction, self.environment)
data = list(data) if isinstance(data, set) else data
return data
def select(self, keys=None, criteria=None, records=None, timestamp=None, **kwargs):
"""
:param keys:
:param criteria:
:param records:
:param timestamp:
:return:
"""
criteria = criteria or find_in_kwargs_by_alias('criteria', kwargs)
keys = keys or kwargs.get('key')
records = records or kwargs.get('record')
timestamp = timestamp or find_in_kwargs_by_alias('timestamp', kwargs)
timestr = isinstance(timestamp, basestring)
# Handle case when kwargs are not used and the second parameter is a the record
# (e.g. trying to get key/record(s))
if (isinstance(criteria, int) or isinstance(criteria, list)) and not records:
records = criteria
criteria = None
if isinstance(records, list) and not keys and not timestamp:
data = self.client.selectRecords(records, self.creds, self.transaction, self.environment)
elif isinstance(records, list) and timestamp and not timestr and not keys:
data = self.client.selectRecordsTime(records, timestamp, self.creds, self.transaction, self.environment)
elif isinstance(records, list) and timestamp and timestr and not keys:
data = self.client.selectRecordsTimestr(records, timestamp, self.creds, self.transaction, self.environment)
elif isinstance(records, list) and isinstance(keys, list) and not timestamp:
data = self.client.selectKeysRecords(keys, records, self.creds, self.transaction, self.environment)
elif isinstance(records, list) and isinstance(keys, list) and timestamp and not timestr:
data = self.client.selectKeysRecordsTime(keys, records, timestamp, self.creds, self.transaction,
self.environment)
elif isinstance(records, list) and isinstance(keys, list) and timestamp and timestr:
data = self.client.selectKeysRecordsTimestr(keys, records, timestamp, self.creds, self.transaction,
self.environment)
elif isinstance(keys, list) and criteria and not timestamp:
data = self.client.selectKeysCcl(keys, criteria, self.creds, self.transaction, self.environment)
elif isinstance(keys, list) and criteria and timestamp and not timestr:
data = self.client.selectKeysCclTime(keys, criteria, timestamp, self.creds, self.transaction,
self.environment)
elif isinstance(keys, list) and criteria and timestamp and timestr:
data = self.client.selectKeysCclTimestr(keys, criteria, timestamp, self.creds, self.transaction,
self.environment)
elif isinstance(keys, list) and records and not timestamp:
data = self.client.selectKeysRecord(keys, records, self.creds, self.transaction, self.environment)
elif isinstance(keys, list) and records and timestamp and not timestr:
data = self.client.selectKeysRecordTime(keys, records, timestamp, self.creds, self.transaction,
self.environment)
elif isinstance(keys, list) and records and timestamp and timestr:
data = self.client.selectKeysRecordTimestr(keys, records, timestamp, self.creds, self.transaction,
self.environment)
elif criteria and not keys and not timestamp:
data = self.client.selectCcl(criteria, self.creds, self.transaction, self.environment)
elif criteria and timestamp and not timestr and not keys:
data = self.client.selectCclTime(criteria, timestamp, self.creds, self.transaction, self.environment)
elif criteria and timestamp and timestr and not keys:
data = self.client.selectCclTimestr(criteria, timestamp, self.creds, self.transaction, self.environment)
elif records and not keys and not timestamp:
data = self.client.selectRecord(records, self.creds, self.transaction, self.environment)
elif records and not isinstance(records, list) and timestamp and not timestr and not keys:
data = self.client.selectRecordTime(records, timestamp, self.creds, self.transaction, self.environment)
elif records and timestamp and not timestr and not keys:
data = self.client.selectRecordsTime(records, timestamp, self.creds, self.transaction, self.environment)
elif records and not isinstance(records, list) and timestamp and timestr and not keys:
data = self.client.selectRecordTimestr(records, timestamp, self.creds, self.transaction, self.environment)
elif isinstance(records, list) and timestamp and timestr and not keys:
data = self.client.selectRecordsTimestr(records, timestamp, self.creds, self.transaction, self.environment)
elif keys and criteria and not timestamp:
data = self.client.selectKeyCcl(keys, criteria, self.creds, self.transaction, self.environment)
elif keys and criteria and timestamp and not timestr:
data = self.client.selectKeyCclTime(keys, criteria, timestamp, self.creds, self.transaction,
self.environment)
elif keys and criteria and timestamp and timestr:
data = self.client.selectKeyCclTimestr(keys, criteria, timestamp, self.creds, self.transaction,
self.environment)
elif keys and isinstance(records, list) and not timestamp:
data = self.client.selectKeyRecords(keys, records, self.creds, self.transaction, self.environment)
elif keys and records and not timestamp:
data = self.client.selectKeyRecord(keys, records, self.creds, self.transaction, self.environment)
elif keys and isinstance(records, list) and timestamp and not timestr:
data = self.client.selectKeyRecordsTime(keys, records, timestamp, self.creds, self.transaction,
self.environment)
elif keys and isinstance(records, list) and timestamp and timestr:
data = self.client.selectKeyRecordsTimestr(keys, records, timestamp, self.creds, self.transaction,
self.environment)
elif keys and records and timestamp and not timestr:
data = self.client.selectKeyRecordTime(keys, records, timestamp, self.creds, self.transaction,
self.environment)
elif keys and records and timestamp and timestr:
data = self.client.selectKeyRecordTimestr(keys, records, timestamp, self.creds, self.transaction,
self.environment)
elif records and not isinstance(records, list) and not timestamp:
data = self.client.selectRecord(records, self.creds, self.transaction, self.environment)
elif records and not isinstance(records, list) and timestamp and not timestr:
data = self.client.selectRecordTime(records, timestamp, self.creds, self.transaction, self.environment)
elif records and not isinstance(records, list) and timestamp and timestr:
data = self.client.selectRecordTimestr(records, timestamp, self.creds, self.transaction, self.environment)
elif records and not timestamp:
data = self.client.selectRecords(records, self.creds, self.transaction, self.environment)
elif records and timestamp and not timestr:
data = self.client.selectRecordsTime(records, timestamp, self.creds, self.transaction, self.environment)
elif records and timestamp and timestr:
data = self.client.selectRecordsTimestr(records, timestamp, self.creds, self.transaction, self.environment)
else:
require_kwarg('criteria or record')
return pythonify(data)
def set(self, key, value, records=None, **kwargs):
"""
:param key:
:param value:
:param records:
:return:
"""
records = records or kwargs.get('record')
value = python_to_thrift(value)
if not records:
return self.client.setKeyValue(key, value, self.creds, self.transaction, self.environment)
elif isinstance(records, list):
self.client.setKeyValueRecords(key, value, records, self.creds, self.transaction, self.environment)
elif isinstance(records, (int, long)):
self.client.setKeyValueRecord(key, value, records, self.creds, self.transaction, self.environment)
else:
require_kwarg('record or records')
def stage(self):
"""
:return:
"""
self.transaction = self.client.stage(self.creds, self.environment)
def time(self, phrase=None):
"""
:param phrase:
:return:
"""
if phrase:
return self.client.timePhrase(phrase, self.creds, self.transaction, self.environment)
else:
return self.client.time(self.creds, self.transaction, self.environment)
def unlink(self, key, source, destinations=None, **kwargs):
"""
:param key:
:param source:
:param destination:
:return:
"""
destinations = destinations or kwargs.get('destination')
if not isinstance(destinations, list):
return self.remove(key=key, value=Link.to(destinations), record=source)
else:
data = dict()
for dest in destinations:
data[dest] = self.remove(key, Link.to(dest), source)
return data
def verify(self, key, value, record, timestamp=None, **kwargs):
value = python_to_thrift(value)
timestamp = timestamp or find_in_kwargs_by_alias('timestamp', kwargs)
timestr = isinstance(timestamp, basestring)
if not timestamp:
return self.client.verifyKeyValueRecord(key, value, record, self.creds, self.transaction, self.environment)
elif timestamp and not timestr:
return self.client.verifyKeyValueRecordTime(key, value, record, timestamp, self.creds, self.transaction,
self.environment)
elif timestamp and timestr:
return self.client.verifyKeyValueRecordTimestr(key, value, record, timestamp, self.creds, self.transaction,
self.environment)
def verify_and_swap(self, key=None, expected=None, record=None, replacement=None, **kwargs):
"""
:param key:
:param expected:
:param record:
:param replacement:
:return:
"""
expected = expected or find_in_kwargs_by_alias('expected', **kwargs)
replacement = replacement or find_in_kwargs_by_alias('replacement', **kwargs)
expected = python_to_thrift(expected)
replacement = python_to_thrift(replacement)
if key and expected and record and replacement:
return self.client.verifyAndSwap(key, expected, record, replacement, self.creds, self.transaction,
self.environment)
else:
require_kwarg('key, expected, record and replacement')
def verify_or_set(self, key, value, record):
"""
:param key:
:param value:
:param record:
:return:
"""
value = python_to_thrift(value)
return self.client.verifyOrSet(key, value, record, self.creds, self.transaction, self.environment)
|
apache-2.0
|
[
363,
2502,
363,
275,
298,
42,
3609,
653,
352,
834,
2,
199,
363,
7307,
363,
275,
298,
7384,
6900,
12,
445,
28494,
1246,
3277,
2122,
199,
363,
1682,
363,
275,
298,
28993,
12,
3394,
499,
14,
16,
2,
199,
199,
504,
17199,
492,
3868,
6501,
199,
504,
17199,
14,
5545,
492,
377,
3869,
199,
504,
17199,
1246,
492,
1448,
1972,
3167,
199,
504,
17199,
1246,
14,
5555,
14,
21776,
492,
627,
199,
504,
3778,
492,
627,
199,
504,
5055,
492,
8773,
199,
646,
399,
1001,
199,
504,
21230,
492,
14196,
199,
646,
7975,
199,
646,
747,
421,
199,
533,
1448,
1972,
8,
785,
304,
272,
408,
1448,
1972,
365,
282,
291,
13,
10032,
316,
3050,
626,
7704,
652,
14905,
370,
23661,
1900,
32150,
436,
5269,
461,
10460,
14,
272,
1448,
1972,
18774,
1503,
439,
1086,
370,
1263,
4223,
436,
32563,
4534,
2839,
4834,
16356,
12,
1015,
3304,
12,
436,
272,
1854,
6570,
998,
15809,
4453,
282,
7282,
666,
4298,
626,
31965,
6337,
12,
295,
10569,
26819,
436,
6127,
19782,
272,
370,
16470,
641,
4052,
7710,
2530,
878,
14,
339,
3918,
5822,
26,
339,
710,
1448,
1972,
666,
1402,
365,
10540,
3463,
436,
26841,
14,
25059,
1163,
16219,
12,
1448,
1972,
365,
14793,
4177,
2003,
436,
272,
1630,
440,
10266,
666,
315,
6716,
503,
5055,
14,
1448,
1972,
365,
9329,
282,
1854,
2213,
13,
2180,
14,
2900,
666,
365,
272,
5489,
315,
5767,
334,
23079,
370,
8247,
503,
4730,
315,
1163,
16219,
680,
7048,
2777,
965,
3663,
2883,
14,
6061,
1924,
272,
790,
965,
1373,
503,
1655,
15392,
1338,
14,
16485,
1263,
3343,
12,
1265,
883,
2142,
5767,
370,
1373,
4573,
14,
6061,
314,
5523,
402,
1373,
272,
2777,
1630,
440,
12787,
314,
5523,
402,
4573,
14,
339,
446,
12651,
26,
437,
11461,
17786,
402,
666,
3595,
282,
2849,
4954,
12,
4192,
503,
8377,
334,
73,
14,
69,
14,
376,
909,
680,
7048,
2777,
365,
272,
15836,
701,
282,
3747,
5062,
790,
14,
272,
446,
2606,
26,
437,
2225,
626,
9033,
370,
1373,
503,
1655,
15392,
1338,
14,
272,
446,
1594,
26,
437,
18774,
20041,
12524,
14,
339,
3918,
18851,
26,
339,
1448,
1972,
302,
17330,
14086,
314,
2569,
1979,
22337,
26,
2155,
12,
4270,
12,
3000,
12,
1059,
334,
6610,
13,
24,
9,
436,
8053,
334,
65,
1059,
626,
365,
272,
440,
2615,
1318,
2754,
461,
680,
6184,
1163,
666,
730,
911,
506,
5489,
465,
2399,
636,
495,
363,
6025,
14,
339,
10967,
83,
26,
339,
1448,
1972,
6127,
25833,
282,
790,
315,
1373,
2777,
370,
4573,
2777,
1808,
314,
2142,
342,
805,
14,
10967,
83,
787,
4444,
6857,
461,
436,
272,
1827,
461,
2951,
2839,
1263,
1163,
574,
14,
339,
6266,
3723,
26,
339,
4885,
849,
12,
1448,
1972,
406,
1601,
83,
4036,
3439,
315,
24845,
818,
2382,
4036,
1570,
365,
9939,
5313,
14,
272,
2047,
883,
2597,
9546,
282,
1572,
402,
5331,
315,
376,
6570,
998,
6008,
14,
6266,
3723,
787,
12883,
1808,
314,
9546,
1062,
272,
5532,
342,
436,
12004,
342,
3718,
14,
339,
3394,
8612,
26,
339,
1448,
1972,
5847,
18917,
4036,
4493,
370,
666,
436,
314,
3261,
444,
10553,
9978,
3102,
370,
24410,
1901,
642,
3878,
14,
272,
413,
9,
2047,
883,
664,
342,
436,
3504,
342,
4136,
1015,
402,
666,
701,
9176,
282,
4913,
1808,
19981,
2637,
503,
282,
16572,
2126,
4913,
3000,
315,
21574,
14,
272,
499,
9,
2047,
883,
19249,
342,
436,
2342,
342,
5767,
626,
7838,
282,
15647,
315,
314,
13541,
701,
9176,
282,
4913,
1808,
19981,
2126,
2637,
503,
282,
16572,
4913,
3000,
315,
21574,
14,
272,
650,
9,
2047,
883,
13968,
342,
436,
3915,
342,
4493,
1806,
900,
12,
23347,
342,
370,
4136,
6363,
436,
221,
682,
2641,
79,
793,
794,
342,
4212,
666,
965,
267,
325,
5650,
1354,
4453,
282,
1425,
402,
900,
14,
272,
408,
339,
768,
4639,
272,
347,
4907,
8,
1102,
628,
5967,
401,
1844,
29,
1196,
1196,
12,
3434,
628,
2113,
401,
2505,
628,
2113,
401,
3734,
8772,
1011,
958,
304,
267,
408,
961,
365,
376,
5162,
367,
314,
3787,
14,
267,
408,
267,
372,
1448,
1972,
8,
1102,
12,
1844,
12,
3434,
12,
2505,
12,
3734,
12,
1011,
958,
9,
339,
347,
636,
826,
721,
277,
12,
1591,
628,
5967,
401,
1844,
29,
1196,
1196,
12,
3434,
628,
2113,
401,
2505,
628,
2113,
401,
3734,
8772,
1011,
958,
304,
267,
408,
11578,
282,
892,
1890,
1950,
398,
520,
635,
1591,
26,
314,
1654,
1591,
334,
885,
26,
11667,
9,
267,
520,
635,
1844,
26,
314,
11647,
2963,
334,
885,
26,
5557,
1196,
9,
267,
520,
635,
3434,
26,
314,
3434,
543,
1314,
370,
4907,
334,
885,
26,
4628,
9,
267,
520,
635,
2505,
26,
314,
2505,
367,
314,
3434,
334,
885,
26,
4628,
9,
267,
520,
635,
3734,
26,
314,
3734,
370,
675,
12,
334,
885,
26,
314,
283,
885,
63,
5418,
7,
315,
314,
1654,
1159,
1169,
406,
1972,
14,
17253,
570,
9,
398,
2047,
1443,
4165,
314,
931,
370,
282,
23453,
570,
1808,
314,
283,
17253,
7,
4252,
1423,
14,
982,
282,
28516,
570,
267,
365,
6841,
12,
314,
1338,
10470,
2337,
12541,
367,
1263,
402,
2368,
3432,
8649,
314,
849,
267,
340,
314,
2368,
787,
440,
7662,
1627,
1338,
14,
398,
520,
1107,
26,
314,
2429,
267,
408,
267,
3434,
275,
3434,
503,
2342,
63,
262,
63,
958,
63,
991,
63,
3620,
360,
2473,
297,
2074,
9,
267,
2505,
275,
2505,
503,
2342,
63,
262,
63,
958,
63,
991,
63,
3620,
360,
2060,
297,
2074,
9,
267,
28516,
275,
2342,
63,
262,
63,
958,
63,
991,
63,
3620,
360,
17253,
297,
2074,
9,
267,
340,
28516,
26,
288,
327,
30802,
370,
675,
14196,
543,
12120,
3449,
4382,
570,
288,
543,
1551,
8,
736,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
12131,
8,
17253,
1724,
465,
2547,
26,
355,
2385,
275,
7975,
14,
4429,
9313,
59,
885,
11472,
395,
2547,
9,
355,
28516,
275,
14196,
342,
355,
28516,
14,
739,
63,
493,
8,
1278,
9,
355,
28516,
275,
1211,
8,
17253,
423,
7786,
459,
885,
1105,
267,
587,
26,
288,
28516,
275,
1052,
267,
291,
14,
1102,
275,
28516,
14,
362,
360,
1102,
297,
1591,
9,
267,
291,
14,
719,
275,
1109,
8
] |
[
2502,
363,
275,
298,
42,
3609,
653,
352,
834,
2,
199,
363,
7307,
363,
275,
298,
7384,
6900,
12,
445,
28494,
1246,
3277,
2122,
199,
363,
1682,
363,
275,
298,
28993,
12,
3394,
499,
14,
16,
2,
199,
199,
504,
17199,
492,
3868,
6501,
199,
504,
17199,
14,
5545,
492,
377,
3869,
199,
504,
17199,
1246,
492,
1448,
1972,
3167,
199,
504,
17199,
1246,
14,
5555,
14,
21776,
492,
627,
199,
504,
3778,
492,
627,
199,
504,
5055,
492,
8773,
199,
646,
399,
1001,
199,
504,
21230,
492,
14196,
199,
646,
7975,
199,
646,
747,
421,
199,
533,
1448,
1972,
8,
785,
304,
272,
408,
1448,
1972,
365,
282,
291,
13,
10032,
316,
3050,
626,
7704,
652,
14905,
370,
23661,
1900,
32150,
436,
5269,
461,
10460,
14,
272,
1448,
1972,
18774,
1503,
439,
1086,
370,
1263,
4223,
436,
32563,
4534,
2839,
4834,
16356,
12,
1015,
3304,
12,
436,
272,
1854,
6570,
998,
15809,
4453,
282,
7282,
666,
4298,
626,
31965,
6337,
12,
295,
10569,
26819,
436,
6127,
19782,
272,
370,
16470,
641,
4052,
7710,
2530,
878,
14,
339,
3918,
5822,
26,
339,
710,
1448,
1972,
666,
1402,
365,
10540,
3463,
436,
26841,
14,
25059,
1163,
16219,
12,
1448,
1972,
365,
14793,
4177,
2003,
436,
272,
1630,
440,
10266,
666,
315,
6716,
503,
5055,
14,
1448,
1972,
365,
9329,
282,
1854,
2213,
13,
2180,
14,
2900,
666,
365,
272,
5489,
315,
5767,
334,
23079,
370,
8247,
503,
4730,
315,
1163,
16219,
680,
7048,
2777,
965,
3663,
2883,
14,
6061,
1924,
272,
790,
965,
1373,
503,
1655,
15392,
1338,
14,
16485,
1263,
3343,
12,
1265,
883,
2142,
5767,
370,
1373,
4573,
14,
6061,
314,
5523,
402,
1373,
272,
2777,
1630,
440,
12787,
314,
5523,
402,
4573,
14,
339,
446,
12651,
26,
437,
11461,
17786,
402,
666,
3595,
282,
2849,
4954,
12,
4192,
503,
8377,
334,
73,
14,
69,
14,
376,
909,
680,
7048,
2777,
365,
272,
15836,
701,
282,
3747,
5062,
790,
14,
272,
446,
2606,
26,
437,
2225,
626,
9033,
370,
1373,
503,
1655,
15392,
1338,
14,
272,
446,
1594,
26,
437,
18774,
20041,
12524,
14,
339,
3918,
18851,
26,
339,
1448,
1972,
302,
17330,
14086,
314,
2569,
1979,
22337,
26,
2155,
12,
4270,
12,
3000,
12,
1059,
334,
6610,
13,
24,
9,
436,
8053,
334,
65,
1059,
626,
365,
272,
440,
2615,
1318,
2754,
461,
680,
6184,
1163,
666,
730,
911,
506,
5489,
465,
2399,
636,
495,
363,
6025,
14,
339,
10967,
83,
26,
339,
1448,
1972,
6127,
25833,
282,
790,
315,
1373,
2777,
370,
4573,
2777,
1808,
314,
2142,
342,
805,
14,
10967,
83,
787,
4444,
6857,
461,
436,
272,
1827,
461,
2951,
2839,
1263,
1163,
574,
14,
339,
6266,
3723,
26,
339,
4885,
849,
12,
1448,
1972,
406,
1601,
83,
4036,
3439,
315,
24845,
818,
2382,
4036,
1570,
365,
9939,
5313,
14,
272,
2047,
883,
2597,
9546,
282,
1572,
402,
5331,
315,
376,
6570,
998,
6008,
14,
6266,
3723,
787,
12883,
1808,
314,
9546,
1062,
272,
5532,
342,
436,
12004,
342,
3718,
14,
339,
3394,
8612,
26,
339,
1448,
1972,
5847,
18917,
4036,
4493,
370,
666,
436,
314,
3261,
444,
10553,
9978,
3102,
370,
24410,
1901,
642,
3878,
14,
272,
413,
9,
2047,
883,
664,
342,
436,
3504,
342,
4136,
1015,
402,
666,
701,
9176,
282,
4913,
1808,
19981,
2637,
503,
282,
16572,
2126,
4913,
3000,
315,
21574,
14,
272,
499,
9,
2047,
883,
19249,
342,
436,
2342,
342,
5767,
626,
7838,
282,
15647,
315,
314,
13541,
701,
9176,
282,
4913,
1808,
19981,
2126,
2637,
503,
282,
16572,
4913,
3000,
315,
21574,
14,
272,
650,
9,
2047,
883,
13968,
342,
436,
3915,
342,
4493,
1806,
900,
12,
23347,
342,
370,
4136,
6363,
436,
221,
682,
2641,
79,
793,
794,
342,
4212,
666,
965,
267,
325,
5650,
1354,
4453,
282,
1425,
402,
900,
14,
272,
408,
339,
768,
4639,
272,
347,
4907,
8,
1102,
628,
5967,
401,
1844,
29,
1196,
1196,
12,
3434,
628,
2113,
401,
2505,
628,
2113,
401,
3734,
8772,
1011,
958,
304,
267,
408,
961,
365,
376,
5162,
367,
314,
3787,
14,
267,
408,
267,
372,
1448,
1972,
8,
1102,
12,
1844,
12,
3434,
12,
2505,
12,
3734,
12,
1011,
958,
9,
339,
347,
636,
826,
721,
277,
12,
1591,
628,
5967,
401,
1844,
29,
1196,
1196,
12,
3434,
628,
2113,
401,
2505,
628,
2113,
401,
3734,
8772,
1011,
958,
304,
267,
408,
11578,
282,
892,
1890,
1950,
398,
520,
635,
1591,
26,
314,
1654,
1591,
334,
885,
26,
11667,
9,
267,
520,
635,
1844,
26,
314,
11647,
2963,
334,
885,
26,
5557,
1196,
9,
267,
520,
635,
3434,
26,
314,
3434,
543,
1314,
370,
4907,
334,
885,
26,
4628,
9,
267,
520,
635,
2505,
26,
314,
2505,
367,
314,
3434,
334,
885,
26,
4628,
9,
267,
520,
635,
3734,
26,
314,
3734,
370,
675,
12,
334,
885,
26,
314,
283,
885,
63,
5418,
7,
315,
314,
1654,
1159,
1169,
406,
1972,
14,
17253,
570,
9,
398,
2047,
1443,
4165,
314,
931,
370,
282,
23453,
570,
1808,
314,
283,
17253,
7,
4252,
1423,
14,
982,
282,
28516,
570,
267,
365,
6841,
12,
314,
1338,
10470,
2337,
12541,
367,
1263,
402,
2368,
3432,
8649,
314,
849,
267,
340,
314,
2368,
787,
440,
7662,
1627,
1338,
14,
398,
520,
1107,
26,
314,
2429,
267,
408,
267,
3434,
275,
3434,
503,
2342,
63,
262,
63,
958,
63,
991,
63,
3620,
360,
2473,
297,
2074,
9,
267,
2505,
275,
2505,
503,
2342,
63,
262,
63,
958,
63,
991,
63,
3620,
360,
2060,
297,
2074,
9,
267,
28516,
275,
2342,
63,
262,
63,
958,
63,
991,
63,
3620,
360,
17253,
297,
2074,
9,
267,
340,
28516,
26,
288,
327,
30802,
370,
675,
14196,
543,
12120,
3449,
4382,
570,
288,
543,
1551,
8,
736,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
12131,
8,
17253,
1724,
465,
2547,
26,
355,
2385,
275,
7975,
14,
4429,
9313,
59,
885,
11472,
395,
2547,
9,
355,
28516,
275,
14196,
342,
355,
28516,
14,
739,
63,
493,
8,
1278,
9,
355,
28516,
275,
1211,
8,
17253,
423,
7786,
459,
885,
1105,
267,
587,
26,
288,
28516,
275,
1052,
267,
291,
14,
1102,
275,
28516,
14,
362,
360,
1102,
297,
1591,
9,
267,
291,
14,
719,
275,
1109,
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,
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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
] |
ignatenkobrain/dnf
|
dnf/yum/misc.py
|
1
|
17291
|
# misc.py
# Copyright (C) 2012-2014 Red Hat, Inc.
#
# This copyrighted material is made available to anyone wishing to use,
# modify, copy, or redistribute it subject to the terms and conditions of
# the GNU General Public License v.2, or (at your option) any later version.
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY expressed or implied, including the implied warranties of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details. You should have received a copy of the
# GNU General Public License along with this program; if not, write to the
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the
# source code or documentation are not subject to the GNU General Public
# License and may only be used or replicated with the express permission of
# Red Hat, Inc.
#
"""
Assorted utility functions for yum.
"""
from __future__ import print_function, absolute_import
from __future__ import unicode_literals
from dnf.exceptions import MiscError
from dnf.pycomp import base64_decodebytes, basestring, unicode
from stat import *
import bz2
import dnf.const
import dnf.crypto
import dnf.exceptions
import dnf.i18n
import errno
import glob
import gpgme
import gpgme.editutil
import gzip
import hashlib
import io
import lzma
import os
import os.path
import pwd
import re
import shutil
import tempfile
_available_checksums = set(['md5', 'sha1', 'sha256', 'sha384', 'sha512'])
_default_checksums = ['sha256']
_re_compiled_glob_match = None
def re_glob(s):
""" Tests if a string is a shell wildcard. """
global _re_compiled_glob_match
if _re_compiled_glob_match is None:
_re_compiled_glob_match = re.compile('[*?]|\[.+\]').search
return _re_compiled_glob_match(s)
_re_compiled_full_match = None
def re_full_search_needed(s):
""" Tests if a string needs a full nevra match, instead of just name. """
global _re_compiled_full_match
if _re_compiled_full_match is None:
# A glob, or a "." or "-" separator, followed by something (the ".")
one = re.compile('.*([-.*?]|\[.+\]).').match
# Any epoch, for envra
two = re.compile('[0-9]+:').match
_re_compiled_full_match = (one, two)
for rec in _re_compiled_full_match:
if rec(s):
return True
return False
class Checksums(object):
""" Generate checksum(s), on given pieces of data. Producing the
Length and the result(s) when complete. """
def __init__(self, checksums=None, ignore_missing=False, ignore_none=False):
if checksums is None:
checksums = _default_checksums
self._sumalgos = []
self._sumtypes = []
self._len = 0
done = set()
for sumtype in checksums:
if sumtype == 'sha':
sumtype = 'sha1'
if sumtype in done:
continue
if sumtype in _available_checksums:
sumalgo = hashlib.new(sumtype)
elif ignore_missing:
continue
else:
raise MiscError('Error Checksumming, bad checksum type %s' %
sumtype)
done.add(sumtype)
self._sumtypes.append(sumtype)
self._sumalgos.append(sumalgo)
if not done and not ignore_none:
raise MiscError('Error Checksumming, no valid checksum type')
def __len__(self):
return self._len
# Note that len(x) is assert limited to INT_MAX, which is 2GB on i686.
length = property(fget=lambda self: self._len)
def update(self, data):
self._len += len(data)
for sumalgo in self._sumalgos:
data = data.encode('utf-8') if isinstance(data, unicode) else data
sumalgo.update(data)
def read(self, fo, size=2**16):
data = fo.read(size)
self.update(data)
return data
def hexdigests(self):
ret = {}
for sumtype, sumdata in zip(self._sumtypes, self._sumalgos):
ret[sumtype] = sumdata.hexdigest()
return ret
def hexdigest(self, checksum=None):
if checksum is None:
if not self._sumtypes:
return None
checksum = self._sumtypes[0]
if checksum == 'sha':
checksum = 'sha1'
return self.hexdigests()[checksum]
def digests(self):
ret = {}
for sumtype, sumdata in zip(self._sumtypes, self._sumalgos):
ret[sumtype] = sumdata.digest()
return ret
def digest(self, checksum=None):
if checksum is None:
if not self._sumtypes:
return None
checksum = self._sumtypes[0]
if checksum == 'sha':
checksum = 'sha1'
return self.digests()[checksum]
def get_default_chksum_type():
return _default_checksums[0]
def checksum(sumtype, file, CHUNK=2**16, datasize=None):
"""takes filename, hand back Checksum of it
sumtype = md5 or sha/sha1/sha256/sha512 (note sha == sha1)
filename = /path/to/file
CHUNK=65536 by default"""
# chunking brazenly lifted from Ryan Tomayko
if isinstance(file, basestring):
try:
with open(file, 'rb', CHUNK) as fo:
return checksum(sumtype, fo, CHUNK, datasize)
except (IOError, OSError):
raise MiscError('Error opening file for checksum: %s' % file)
try:
# assumes file is a file-like-object
data = Checksums([sumtype])
while data.read(file, CHUNK):
if datasize is not None and data.length > datasize:
break
# This screws up the length, but that shouldn't matter. We only care
# if this checksum == what we expect.
if datasize is not None and datasize != data.length:
return '!%u!%s' % (datasize, data.hexdigest(sumtype))
return data.hexdigest(sumtype)
except (IOError, OSError) as e:
raise MiscError('Error reading file for checksum: %s' % file)
def getFileList(path, ext, filelist):
"""Return all files in path matching ext, store them in filelist,
recurse dirs return list object"""
extlen = len(ext)
try:
dir_list = os.listdir(path)
except OSError as e:
raise MiscError(('Error accessing directory %s, %s') % (path, e))
for d in dir_list:
if os.path.isdir(path + '/' + d):
filelist = getFileList(path + '/' + d, ext, filelist)
else:
if not ext or d[-extlen:].lower() == '%s' % (ext):
newpath = os.path.normpath(path + '/' + d)
filelist.append(newpath)
return filelist
class GenericHolder(object):
"""Generic Holder class used to hold other objects of known types
It exists purely to be able to do object.somestuff, object.someotherstuff
or object[key] and pass object to another function that will
understand it"""
def __init__(self, iter=None):
self.__iter = iter
def __iter__(self):
if self.__iter is not None:
return iter(self[self.__iter])
def __getitem__(self, item):
if hasattr(self, item):
return getattr(self, item)
else:
raise KeyError(item)
def all_lists(self):
"""Return a dictionary of all lists."""
return {key: list_ for key, list_ in vars(self).items()
if type(list_) is list}
def merge_lists(self, other):
""" Concatenate the list attributes from 'other' to ours. """
for (key, val) in other.all_lists().items():
vars(self).setdefault(key, []).extend(val)
return self
def procgpgkey(rawkey):
'''Convert ASCII armoured GPG key to binary
'''
# Normalise newlines
rawkey = re.sub(b'\r\n?', b'\n', rawkey)
# Extract block
block = io.BytesIO()
inblock = 0
pastheaders = 0
for line in rawkey.split(b'\n'):
if line.startswith(b'-----BEGIN PGP PUBLIC KEY BLOCK-----'):
inblock = 1
elif inblock and line.strip() == b'':
pastheaders = 1
elif inblock and line.startswith(b'-----END PGP PUBLIC KEY BLOCK-----'):
# Hit the end of the block, get out
break
elif pastheaders and line.startswith(b'='):
# Hit the CRC line, don't include this and stop
break
elif pastheaders:
block.write(line + b'\n')
# Decode and return
return base64_decodebytes(block.getvalue())
def keyInstalled(ts, keyid, timestamp):
'''
Return if the GPG key described by the given keyid and timestamp are
installed in the rpmdb.
The keyid and timestamp should both be passed as integers.
The ts is an rpm transaction set object
Return values:
- -1 key is not installed
- 0 key with matching ID and timestamp is installed
- 1 key with matching ID is installed but has an older timestamp
- 2 key with matching ID is installed but has a newer timestamp
No effort is made to handle duplicates. The first matching keyid is used to
calculate the return result.
'''
# Search
for hdr in ts.dbMatch('name', 'gpg-pubkey'):
if hdr['version'] == keyid:
installedts = int(hdr['release'], 16)
if installedts == timestamp:
return 0
elif installedts < timestamp:
return 1
else:
return 2
return -1
def import_key_to_pubring(rawkey, keyid, gpgdir=None, make_ro_copy=True):
if not os.path.exists(gpgdir):
os.makedirs(gpgdir)
key_fo = io.BytesIO(rawkey)
with dnf.crypto.pubring_dir(gpgdir):
# import the key
ctx = gpgme.Context()
fp = open(os.path.join(gpgdir, 'gpg.conf'), 'wb')
fp.write(b'')
fp.close()
ctx.import_(key_fo)
key_fo.close()
# ultimately trust the key or pygpgme is definitionally stupid
k = ctx.get_key(keyid)
gpgme.editutil.edit_trust(ctx, k, gpgme.VALIDITY_ULTIMATE)
if make_ro_copy:
rodir = gpgdir + '-ro'
if not os.path.exists(rodir):
os.makedirs(rodir, mode=0o755)
for f in glob.glob(gpgdir + '/*'):
basename = os.path.basename(f)
ro_f = rodir + '/' + basename
shutil.copy(f, ro_f)
os.chmod(ro_f, 0o755)
fp = open(rodir + '/gpg.conf', 'w', 0o755)
# yes it is this stupid, why do you ask?
opts = """lock-never
no-auto-check-trustdb
trust-model direct
no-expensive-trust-checks
no-permission-warning
preserve-permissions
"""
fp.write(opts)
fp.close()
return True
def getCacheDir():
"""return a path to a valid and safe cachedir - only used when not running
as root or when --tempcache is set"""
uid = os.geteuid()
try:
usertup = pwd.getpwuid(uid)
username = dnf.i18n.ucd(usertup[0])
except KeyError:
return None # if it returns None then, well, it's bollocksed
# check for /var/tmp/dnf-username-* -
prefix = '%s-%s-' % (dnf.const.PREFIX, username)
dirpath = '%s/%s*' % (dnf.const.TMPDIR, prefix)
cachedirs = sorted(glob.glob(dirpath))
for thisdir in cachedirs:
stats = os.lstat(thisdir)
if S_ISDIR(stats[0]) and S_IMODE(stats[0]) == 448 and stats[4] == uid:
return thisdir
# make the dir (tempfile.mkdtemp())
cachedir = tempfile.mkdtemp(prefix=prefix, dir=dnf.const.TMPDIR)
return cachedir
def _decompress_chunked(source, dest, ztype):
if ztype == 'bz2':
s_fn = bz2.BZ2File(source, 'r')
elif ztype == 'xz':
s_fn = lzma.LZMAFile(source, 'r')
elif ztype == 'gz':
s_fn = gzip.GzipFile(source, 'r')
destination = open(dest, 'wb')
while True:
try:
data = s_fn.read(1024000)
except IOError:
break
if not data:
break
try:
destination.write(data)
except (OSError, IOError) as e:
msg = "Error writing to file %s: %s" % (dest, str(e))
raise dnf.exceptions.MiscError(msg)
destination.close()
s_fn.close()
def seq_max_split(seq, max_entries):
""" Given a seq, split into a list of lists of length max_entries each. """
ret = []
num = len(seq)
seq = list(seq) # Trying to use a set/etc. here is bad
beg = 0
while num > max_entries:
end = beg + max_entries
ret.append(seq[beg:end])
beg += max_entries
num -= max_entries
ret.append(seq[beg:])
return ret
def unlink_f(filename):
""" Call os.unlink, but don't die if the file isn't there. This is the main
difference between "rm -f" and plain "rm". """
try:
os.unlink(filename)
except OSError as e:
if e.errno != errno.ENOENT:
raise
def stat_f(filename, ignore_EACCES=False):
""" Call os.stat(), but don't die if the file isn't there. Returns None. """
try:
return os.stat(filename)
except OSError as e:
if e.errno in (errno.ENOENT, errno.ENOTDIR):
return None
if ignore_EACCES and e.errno == errno.EACCES:
return None
raise
def _getloginuid():
""" Get the audit-uid/login-uid, if available. None is returned if there
was a problem. Note that no caching is done here. """
# We might normally call audit.audit_getloginuid(), except that requires
# importing all of the audit module. And it doesn't work anyway: BZ 518721
try:
with open("/proc/self/loginuid") as fo:
data = fo.read()
return int(data)
except (IOError, ValueError):
return None
_cached_getloginuid = None
def getloginuid():
""" Get the audit-uid/login-uid, if available. None is returned if there
was a problem. The value is cached, so you don't have to save it. """
global _cached_getloginuid
if _cached_getloginuid is None:
_cached_getloginuid = _getloginuid()
return _cached_getloginuid
def decompress(filename, dest=None, fn_only=False, check_timestamps=False):
"""take a filename and decompress it into the same relative location.
if the file is not compressed just return the file"""
out = dest
if not dest:
out = filename
if filename.endswith('.gz'):
ztype = 'gz'
if not dest:
out = filename.replace('.gz', '')
elif filename.endswith('.bz') or filename.endswith('.bz2'):
ztype = 'bz2'
if not dest:
if filename.endswith('.bz'):
out = filename.replace('.bz', '')
else:
out = filename.replace('.bz2', '')
elif filename.endswith('.xz'):
ztype = 'xz'
if not dest:
out = filename.replace('.xz', '')
else:
out = filename # returning the same file since it is not compressed
ztype = None
if ztype and not fn_only:
if check_timestamps:
fi = stat_f(filename)
fo = stat_f(out)
if fi and fo and fo.st_mtime == fi.st_mtime:
return out
_decompress_chunked(filename, out, ztype)
if check_timestamps and fi:
os.utime(out, (fi.st_mtime, fi.st_mtime))
return out
def calculate_repo_gen_dest(filename, generated_name):
dest = os.path.dirname(filename)
dest += '/gen'
if not os.path.exists(dest):
os.makedirs(dest, mode=0o755)
return dest + '/' + generated_name
def repo_gen_decompress(filename, generated_name, cached=False):
""" This is a wrapper around decompress, where we work out a cached
generated name, and use check_timestamps. filename _must_ be from
a repo. and generated_name is the type of the file. """
dest = calculate_repo_gen_dest(filename, generated_name)
return decompress(filename, dest=dest, check_timestamps=True, fn_only=cached)
def read_in_items_from_dot_dir(thisglob, line_as_list=True):
""" Takes a glob of a dir (like /etc/foo.d/\*.foo) returns a list of all the
lines in all the files matching that glob, ignores comments and blank
lines, optional paramater 'line_as_list tells whether to treat each line
as a space or comma-separated list, defaults to True.
"""
results = []
for fname in glob.glob(thisglob):
with open(fname) as f:
for line in f:
if re.match('\s*(#|$)', line):
continue
line = line.rstrip() # no more trailing \n's
line = line.lstrip() # be nice
if not line:
continue
if line_as_list:
line = line.replace('\n', ' ')
line = line.replace(',', ' ')
results.extend(line.split())
continue
results.append(line)
return results
|
gpl-2.0
|
[
3,
18576,
14,
647,
199,
3,
1898,
334,
35,
9,
6029,
13,
7280,
221,
9572,
13002,
12,
3277,
14,
199,
3,
199,
3,
961,
1331,
31816,
471,
6285,
365,
6326,
2808,
370,
29165,
13809,
316,
370,
675,
12,
199,
3,
2811,
12,
1331,
12,
503,
3604,
652,
5420,
370,
314,
2895,
436,
3704,
402,
199,
3,
314,
1664,
1696,
1684,
844,
373,
14,
18,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
2428,
199,
3,
1821,
3408,
19147,
503,
2478,
12,
5893,
314,
2478,
3712,
1417,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
1696,
199,
3,
1684,
844,
367,
1655,
2436,
14,
221,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
199,
3,
1664,
1696,
1684,
844,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
199,
3,
2868,
2290,
2752,
12,
3277,
2020,
8026,
11236,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
199,
3,
11315,
13,
10067,
12,
8217,
14,
221,
6184,
9572,
13002,
21032,
10375,
626,
787,
30147,
972,
315,
314,
199,
3,
1350,
1233,
503,
3794,
787,
440,
5420,
370,
314,
1664,
1696,
1684,
199,
3,
844,
436,
1443,
1454,
506,
1202,
503,
32436,
543,
314,
4056,
4983,
402,
199,
3,
9572,
13002,
12,
3277,
14,
199,
3,
199,
199,
624,
199,
9824,
1376,
11420,
3423,
367,
24717,
14,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
12,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
504,
28215,
14,
3924,
492,
603,
10840,
547,
199,
504,
28215,
14,
647,
863,
492,
1300,
772,
63,
2708,
2394,
12,
7116,
12,
2649,
199,
504,
5672,
492,
627,
199,
646,
15055,
18,
199,
646,
28215,
14,
1297,
199,
646,
28215,
14,
10316,
199,
646,
28215,
14,
3924,
199,
646,
28215,
14,
73,
1085,
78,
199,
646,
7554,
199,
646,
5739,
199,
646,
30067,
278,
199,
646,
30067,
278,
14,
3773,
1974,
199,
646,
11756,
199,
646,
8337,
199,
646,
5890,
199,
646,
634,
90,
391,
199,
646,
747,
199,
646,
747,
14,
515,
199,
646,
14374,
199,
646,
295,
199,
646,
5145,
199,
646,
5549,
199,
199,
63,
4561,
63,
8928,
83,
275,
663,
2941,
1064,
21,
297,
283,
4835,
17,
297,
283,
4835,
3912,
297,
283,
4835,
8188,
297,
283,
4835,
7736,
1105,
199,
63,
885,
63,
8928,
83,
275,
788,
4835,
3912,
418,
421,
199,
63,
264,
63,
8427,
63,
6463,
63,
1431,
275,
488,
199,
318,
295,
63,
6463,
8,
83,
304,
272,
408,
6496,
340,
282,
1059,
365,
282,
5218,
16792,
14,
408,
272,
2288,
485,
264,
63,
8427,
63,
6463,
63,
1431,
272,
340,
485,
264,
63,
8427,
63,
6463,
63,
1431,
365,
488,
26,
267,
485,
264,
63,
8427,
63,
6463,
63,
1431,
275,
295,
14,
2014,
11894,
15279,
61,
6113,
59,
6977,
32174,
1959,
1733,
272,
372,
485,
264,
63,
8427,
63,
6463,
63,
1431,
8,
83,
9,
199,
199,
63,
264,
63,
8427,
63,
2861,
63,
1431,
275,
488,
199,
318,
295,
63,
2861,
63,
1733,
63,
11368,
8,
83,
304,
272,
408,
6496,
340,
282,
1059,
4839,
282,
2615,
1279,
86,
345,
1336,
12,
3140,
402,
2951,
536,
14,
408,
272,
2288,
485,
264,
63,
8427,
63,
2861,
63,
1431,
272,
340,
485,
264,
63,
8427,
63,
2861,
63,
1431,
365,
488,
26,
267,
327,
437,
5739,
12,
503,
282,
14530,
503,
17155,
9432,
12,
9437,
701,
6020,
334,
1589,
298,
2685,
267,
1373,
275,
295,
14,
2014,
360,
2795,
11468,
6697,
61,
6113,
59,
6977,
60,
6575,
1959,
1431,
267,
327,
6184,
9463,
12,
367,
2589,
345,
267,
2877,
275,
295,
14,
2014,
11894,
16,
13,
25,
2807,
26,
1959,
1431,
267,
485,
264,
63,
8427,
63,
2861,
63,
1431,
275,
334,
368,
12,
2877,
9,
272,
367,
6488,
315,
485,
264,
63,
8427,
63,
2861,
63,
1431,
26,
267,
340,
6488,
8,
83,
304,
288,
372,
715,
272,
372,
756,
421,
199,
533,
2670,
22178,
8,
785,
304,
272,
408,
7958,
9040,
8,
83,
395,
641,
1627,
10338,
402,
666,
14,
2165,
14713,
314,
267,
19893,
436,
314,
754,
8,
83,
9,
1380,
4890,
14,
408,
339,
347,
636,
826,
721,
277,
12,
9040,
83,
29,
403,
12,
3686,
63,
4752,
29,
797,
12,
3686,
63,
3592,
29,
797,
304,
267,
340,
9040,
83,
365,
488,
26,
288,
9040,
83,
275,
485,
885,
63,
8928,
83,
267,
291,
423,
1838,
6731,
736,
275,
942,
267,
291,
423,
1838,
1313,
275,
942,
267,
291,
423,
552,
275,
378,
398,
4224,
275,
663,
342,
267,
367,
3089,
466,
315,
9040,
83,
26,
288,
340,
3089,
466,
508,
283,
4835,
356,
355,
3089,
466,
275,
283,
4835,
17,
7,
288,
340,
3089,
466,
315,
4224,
26,
355,
1980,
953,
340,
3089,
466,
315,
485,
4561,
63,
8928,
83,
26,
355,
3089,
21734,
275,
8337,
14,
1222,
8,
1838,
466,
9,
288,
916,
3686,
63,
4752,
26,
355,
1980,
288,
587,
26,
355,
746,
603,
10840,
547,
360,
547,
2670,
1838,
14566,
12,
4875,
9040,
730,
450,
83,
7,
450,
1816,
3089,
466,
9,
288,
4224,
14,
525,
8,
1838,
466,
9,
288,
291,
423,
1838,
1313,
14,
740,
8,
1838,
466,
9,
288,
291,
423,
1838,
6731,
736,
14,
740,
8,
1838,
21734,
9,
267,
340,
440,
4224,
436,
440,
3686,
63,
3592,
26,
288,
746,
603,
10840,
547,
360,
547,
2670,
1838,
14566,
12,
949,
1686,
9040,
730,
358,
339,
347,
636,
552,
721,
277,
304,
267,
372,
291,
423,
552,
339,
327,
3390,
626,
822,
8,
88,
9,
365,
702,
13988,
370,
16429,
63,
4283,
12,
1314,
365,
499,
6487,
641,
284,
10253,
14,
272,
2582,
275,
3324,
8,
27823,
29,
2734,
291,
26,
291,
423,
552,
9,
339,
347,
1678,
8,
277,
12,
666,
304,
267,
291,
423,
552,
847,
822,
8,
576,
9,
267,
367,
3089,
21734,
315,
291,
423,
1838,
6731,
736,
26,
288,
666,
275,
666,
14,
2143,
360,
1624,
13,
24,
358,
340,
1228,
8,
576,
12,
2649,
9,
587,
666,
288,
3089,
21734,
14,
873,
8,
576,
9,
339
] |
[
18576,
14,
647,
199,
3,
1898,
334,
35,
9,
6029,
13,
7280,
221,
9572,
13002,
12,
3277,
14,
199,
3,
199,
3,
961,
1331,
31816,
471,
6285,
365,
6326,
2808,
370,
29165,
13809,
316,
370,
675,
12,
199,
3,
2811,
12,
1331,
12,
503,
3604,
652,
5420,
370,
314,
2895,
436,
3704,
402,
199,
3,
314,
1664,
1696,
1684,
844,
373,
14,
18,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
2428,
199,
3,
1821,
3408,
19147,
503,
2478,
12,
5893,
314,
2478,
3712,
1417,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
1696,
199,
3,
1684,
844,
367,
1655,
2436,
14,
221,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
199,
3,
1664,
1696,
1684,
844,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
199,
3,
2868,
2290,
2752,
12,
3277,
2020,
8026,
11236,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
199,
3,
11315,
13,
10067,
12,
8217,
14,
221,
6184,
9572,
13002,
21032,
10375,
626,
787,
30147,
972,
315,
314,
199,
3,
1350,
1233,
503,
3794,
787,
440,
5420,
370,
314,
1664,
1696,
1684,
199,
3,
844,
436,
1443,
1454,
506,
1202,
503,
32436,
543,
314,
4056,
4983,
402,
199,
3,
9572,
13002,
12,
3277,
14,
199,
3,
199,
199,
624,
199,
9824,
1376,
11420,
3423,
367,
24717,
14,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
12,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
504,
28215,
14,
3924,
492,
603,
10840,
547,
199,
504,
28215,
14,
647,
863,
492,
1300,
772,
63,
2708,
2394,
12,
7116,
12,
2649,
199,
504,
5672,
492,
627,
199,
646,
15055,
18,
199,
646,
28215,
14,
1297,
199,
646,
28215,
14,
10316,
199,
646,
28215,
14,
3924,
199,
646,
28215,
14,
73,
1085,
78,
199,
646,
7554,
199,
646,
5739,
199,
646,
30067,
278,
199,
646,
30067,
278,
14,
3773,
1974,
199,
646,
11756,
199,
646,
8337,
199,
646,
5890,
199,
646,
634,
90,
391,
199,
646,
747,
199,
646,
747,
14,
515,
199,
646,
14374,
199,
646,
295,
199,
646,
5145,
199,
646,
5549,
199,
199,
63,
4561,
63,
8928,
83,
275,
663,
2941,
1064,
21,
297,
283,
4835,
17,
297,
283,
4835,
3912,
297,
283,
4835,
8188,
297,
283,
4835,
7736,
1105,
199,
63,
885,
63,
8928,
83,
275,
788,
4835,
3912,
418,
421,
199,
63,
264,
63,
8427,
63,
6463,
63,
1431,
275,
488,
199,
318,
295,
63,
6463,
8,
83,
304,
272,
408,
6496,
340,
282,
1059,
365,
282,
5218,
16792,
14,
408,
272,
2288,
485,
264,
63,
8427,
63,
6463,
63,
1431,
272,
340,
485,
264,
63,
8427,
63,
6463,
63,
1431,
365,
488,
26,
267,
485,
264,
63,
8427,
63,
6463,
63,
1431,
275,
295,
14,
2014,
11894,
15279,
61,
6113,
59,
6977,
32174,
1959,
1733,
272,
372,
485,
264,
63,
8427,
63,
6463,
63,
1431,
8,
83,
9,
199,
199,
63,
264,
63,
8427,
63,
2861,
63,
1431,
275,
488,
199,
318,
295,
63,
2861,
63,
1733,
63,
11368,
8,
83,
304,
272,
408,
6496,
340,
282,
1059,
4839,
282,
2615,
1279,
86,
345,
1336,
12,
3140,
402,
2951,
536,
14,
408,
272,
2288,
485,
264,
63,
8427,
63,
2861,
63,
1431,
272,
340,
485,
264,
63,
8427,
63,
2861,
63,
1431,
365,
488,
26,
267,
327,
437,
5739,
12,
503,
282,
14530,
503,
17155,
9432,
12,
9437,
701,
6020,
334,
1589,
298,
2685,
267,
1373,
275,
295,
14,
2014,
360,
2795,
11468,
6697,
61,
6113,
59,
6977,
60,
6575,
1959,
1431,
267,
327,
6184,
9463,
12,
367,
2589,
345,
267,
2877,
275,
295,
14,
2014,
11894,
16,
13,
25,
2807,
26,
1959,
1431,
267,
485,
264,
63,
8427,
63,
2861,
63,
1431,
275,
334,
368,
12,
2877,
9,
272,
367,
6488,
315,
485,
264,
63,
8427,
63,
2861,
63,
1431,
26,
267,
340,
6488,
8,
83,
304,
288,
372,
715,
272,
372,
756,
421,
199,
533,
2670,
22178,
8,
785,
304,
272,
408,
7958,
9040,
8,
83,
395,
641,
1627,
10338,
402,
666,
14,
2165,
14713,
314,
267,
19893,
436,
314,
754,
8,
83,
9,
1380,
4890,
14,
408,
339,
347,
636,
826,
721,
277,
12,
9040,
83,
29,
403,
12,
3686,
63,
4752,
29,
797,
12,
3686,
63,
3592,
29,
797,
304,
267,
340,
9040,
83,
365,
488,
26,
288,
9040,
83,
275,
485,
885,
63,
8928,
83,
267,
291,
423,
1838,
6731,
736,
275,
942,
267,
291,
423,
1838,
1313,
275,
942,
267,
291,
423,
552,
275,
378,
398,
4224,
275,
663,
342,
267,
367,
3089,
466,
315,
9040,
83,
26,
288,
340,
3089,
466,
508,
283,
4835,
356,
355,
3089,
466,
275,
283,
4835,
17,
7,
288,
340,
3089,
466,
315,
4224,
26,
355,
1980,
953,
340,
3089,
466,
315,
485,
4561,
63,
8928,
83,
26,
355,
3089,
21734,
275,
8337,
14,
1222,
8,
1838,
466,
9,
288,
916,
3686,
63,
4752,
26,
355,
1980,
288,
587,
26,
355,
746,
603,
10840,
547,
360,
547,
2670,
1838,
14566,
12,
4875,
9040,
730,
450,
83,
7,
450,
1816,
3089,
466,
9,
288,
4224,
14,
525,
8,
1838,
466,
9,
288,
291,
423,
1838,
1313,
14,
740,
8,
1838,
466,
9,
288,
291,
423,
1838,
6731,
736,
14,
740,
8,
1838,
21734,
9,
267,
340,
440,
4224,
436,
440,
3686,
63,
3592,
26,
288,
746,
603,
10840,
547,
360,
547,
2670,
1838,
14566,
12,
949,
1686,
9040,
730,
358,
339,
347,
636,
552,
721,
277,
304,
267,
372,
291,
423,
552,
339,
327,
3390,
626,
822,
8,
88,
9,
365,
702,
13988,
370,
16429,
63,
4283,
12,
1314,
365,
499,
6487,
641,
284,
10253,
14,
272,
2582,
275,
3324,
8,
27823,
29,
2734,
291,
26,
291,
423,
552,
9,
339,
347,
1678,
8,
277,
12,
666,
304,
267,
291,
423,
552,
847,
822,
8,
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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
] |
thjashin/tensorflow
|
tensorflow/python/training/session_run_hook.py
|
31
|
9435
|
# 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.
# ==============================================================================
"""A SessionRunHook extends `session.run()` calls for the `MonitoredSession`.
SessionRunHooks are useful to track training, report progress, request early
stopping and more. SessionRunHooks use the observer pattern and notify at the
following points:
- when a session starts being used
- before a call to the `session.run()`
- after a call to the `session.run()`
- when the session closed
A SessionRunHook encapsulates a piece of reusable/composable computation that
can piggyback a call to `MonitoredSession.run()`. A hook can add any
ops-or-tensor/feeds to the run call, and when the run call finishes with success
gets the outputs it requested. Hooks are allowed to add ops to the graph in
`hook.begin()`. The graph is finalized after the `begin()` method is called.
There are a few pre-defined monitors:
- StopAtStepHook: Request stop based on global_step
- CheckpointSaverHook: saves checkpoint
- LoggingTensorHook: outputs one or more tensor values to log
- NanTensorHook: Request stop if given `Tensor` contains Nans.
- SummarySaverHook: saves summaries to a summary writer
For more specific needs, you can create custom hooks:
class ExampleHook(SessionRunHook):
def begin(self):
# You can add ops to the graph here.
print('Starting the session.')
self.your_tensor = ...
def end(self, session):
print('Done with the session.')
def before_run(self, run_context):
print('before calling session.run)
return SessionRunArgs(self.your_tensor)
def after_run(self, run_context, run_values)
print('Done running one step. The value of my tensor: %s',
run_values.results)
if you-need-to-stop-loop:
run_context.request_stop()
To understand how hooks interact with calls to `MonitoredSession.run()`,
look at following code:
with SupervisedSession(hooks=your_hooks, ...) as sess
while not sess.should_stop()
sess.run(your_fetches)
Above user code leads to following execution:
call hooks.begin
sess = tf.Session()
while not stop is requested:
call hooks.before_run()
results = sess.run(merged_fetches)
call hooks.after_run()
call hooks.end()
sess.close()
@@SessionRunHook
@@SessionRunArgs
@@SessionRunContext
@@SessionRunValues
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import collections
class SessionRunHook(object):
"""Hook to extend calls to MonitoredSession.run()."""
def begin(self):
"""Called once before using the session.
When called, the default graph is the one that will be launched in the
session. The hook can modify the graph by adding new operations to it.
After the `begin()` call the graph will be finalized and the other callbacks
can not modify the graph anymore. Second call of `begin()` on the same
graph, should not change the graph.
"""
pass
def after_create_session(self, session, coord): # pylint: disable=unused-argument
"""Called when new TensorFlow session is created.
This is called to signal the hooks that a new session has been created. This
has two essential differences with the situation in which `begin` is called:
* When this is called, the graph is finalized and ops can no longer be added
to the graph.
* This method will also be called as a result of recovering a wrapped
session, not only at the beginning of the overall session.
Args:
session: A TensorFlow Session that has been created.
coord: A Coordinator object which keeps track of all threads.
"""
pass
def before_run(self, run_context): # pylint: disable=unused-argument
"""Called before each call to run().
You can return from this call a `SessionRunArgs` object indicating ops or
tensors to add to the upcoming `run()` call. These ops/tensors will be run
together with the ops/tensors originally passed to the original run() call.
The run args you return can also contain feeds to be added to the run()
call.
The `run_context` argument is a `SessionRunContext` that provides
information about the upcoming `run()` call: the originally requested
op/tensors, the TensorFlow Session.
At this point graph is finalized and you can not add ops.
Args:
run_context: A `SessionRunContext` object.
Returns:
None or a `SessionRunArgs` object.
"""
return None
def after_run(self,
run_context, # pylint: disable=unused-argument
run_values): # pylint: disable=unused-argument
"""Called after each call to run().
The `run_values` argument contains results of requested ops/tensors by
`before_run()`.
The `run_context` argument is the same one send to `before_run` call.
`run_context.request_stop()` can be called to stop the iteration.
Args:
run_context: A `SessionRunContext` object.
run_values: A SessionRunValues object.
"""
pass
def end(self, session): # pylint: disable=unused-argument
"""Called at the end of session.
The `session` argument can be used in case the hook wants to run final ops,
such as saving a last checkpoint.
Args:
session: A TensorFlow Session that will be soon closed.
"""
pass
class SessionRunArgs(
collections.namedtuple("SessionRunArgs",
["fetches", "feed_dict", "options"])):
"""Represents arguments to be added to a `Session.run()` call.
Args:
fetches: Exactly like the 'fetches' argument to Session.Run().
Can be a single tensor or op, a list of 'fetches' or a dictionary
of fetches. For example:
fetches = global_step_tensor
fetches = [train_op, summary_op, global_step_tensor]
fetches = {'step': global_step_tensor, 'summ': summary_op}
Note that this can recurse as expected:
fetches = {'step': global_step_tensor,
'ops': [train_op, check_nan_op]}
feed_dict: Exactly like the `feed_dict` argument to `Session.Run()`
options: Exactly like the `options` argument to `Session.run()`, i.e., a
config_pb2.RunOptions proto.
"""
def __new__(cls, fetches, feed_dict=None, options=None):
return super(SessionRunArgs, cls).__new__(cls, fetches, feed_dict, options)
class SessionRunContext(object):
"""Provides information about the `session.run()` call being made.
Provides information about original request to `Session.Run()` function.
SessionRunHook objects can stop the loop by calling `request_stop()` of
`run_context`. In the future we may use this object to add more information
about run without changing the Hook API.
"""
def __init__(self, original_args, session):
"""Initializes SessionRunContext."""
self._original_args = original_args
self._session = session
self._stop_requested = False
@property
def original_args(self):
"""A `SessionRunArgs` object holding the original arguments of `run()`.
If user called `MonitoredSession.run(fetches=a, feed_dict=b)`, then this
field is equal to SessionRunArgs(a, b).
Returns:
A `SessionRunArgs` object
"""
return self._original_args
@property
def session(self):
"""A TensorFlow session object which will execute the `run`."""
return self._session
@property
def stop_requested(self):
"""Returns whether a stop is requested or not.
If true, `MonitoredSession` stops iterations.
Returns:
A `bool`
"""
return self._stop_requested
def request_stop(self):
"""Sets stop requested field.
Hooks can use this function to request stop of iterations.
`MonitoredSession` checks whether this is called or not.
"""
self._stop_requested = True
class SessionRunValues(
collections.namedtuple("SessionRunValues",
["results", "options", "run_metadata"])):
"""Contains the results of `Session.run()`.
In the future we may use this object to add more information about result of
run without changing the Hook API.
Args:
results: The return values from `Session.run()` corresponding to the fetches
attribute returned in the RunArgs. Note that this has the same shape as
the RunArgs fetches. For example:
fetches = global_step_tensor
=> results = nparray(int)
fetches = [train_op, summary_op, global_step_tensor]
=> results = [None, nparray(string), nparray(int)]
fetches = {'step': global_step_tensor, 'summ': summary_op}
=> results = {'step': nparray(int), 'summ': nparray(string)}
options: `RunOptions` from the `Session.run()` call.
run_metadata: `RunMetadata` from the `Session.run()` call.
"""
|
apache-2.0
|
[
3,
1898,
7800,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
33,
8596,
2540,
8481,
16879,
658,
1730,
14,
1065,
11995,
4882,
367,
314,
658,
6671,
17043,
4434,
2313,
199,
199,
4434,
2540,
8481,
83,
787,
2997,
370,
4426,
6093,
12,
3622,
6696,
12,
1056,
14670,
199,
2379,
4073,
436,
1655,
14,
8596,
2540,
8481,
83,
675,
314,
27336,
3851,
436,
11705,
737,
314,
199,
21589,
4501,
26,
199,
446,
1380,
282,
2351,
9174,
3769,
1202,
199,
446,
2544,
282,
1240,
370,
314,
658,
1730,
14,
1065,
11995,
199,
446,
2410,
282,
1240,
370,
314,
658,
1730,
14,
1065,
11995,
199,
446,
1380,
314,
2351,
6876,
199,
199,
33,
8596,
2540,
8481,
22667,
15409,
282,
14854,
402,
295,
14418,
15,
863,
736,
461,
14009,
626,
199,
2425,
299,
528,
4312,
894,
282,
1240,
370,
658,
6671,
17043,
4434,
14,
1065,
25593,
437,
5759,
883,
1050,
1263,
199,
1483,
13,
269,
13,
3128,
15,
11522,
370,
314,
1255,
1240,
12,
436,
1380,
314,
1255,
1240,
9578,
397,
543,
3182,
199,
24894,
314,
4704,
652,
5839,
14,
24837,
83,
787,
4370,
370,
1050,
4156,
370,
314,
3343,
315,
199,
64,
3664,
14,
5037,
25593,
710,
3343,
365,
4242,
1759,
2410,
314,
658,
5037,
11995,
1083,
365,
2797,
14,
199,
199,
10924,
787,
282,
9284,
876,
13,
4037,
26862,
26,
199,
446,
8015,
1271,
7801,
8481,
26,
4784,
3631,
4079,
641,
2288,
63,
2926,
199,
446,
2670,
1403,
20829,
8481,
26,
23050,
9997,
199,
446,
19928,
3861,
8481,
26,
4704,
1373,
503,
1655,
2345,
1338,
370,
943,
199,
446,
653,
290,
3861,
8481,
26,
4784,
3631,
340,
1627,
658,
3861,
64,
3509,
653,
796,
14,
199,
446,
22486,
20829,
8481,
26,
23050,
23747,
370,
282,
6212,
7060,
199,
199,
1858,
1655,
2488,
4839,
12,
1265,
883,
1218,
3537,
12604,
26,
523,
1021,
5679,
8481,
8,
4434,
2540,
8481,
304,
272,
347,
5386,
8,
277,
304,
489,
327,
2047,
883,
1050,
4156,
370,
314,
3343,
2348,
14,
489,
870,
360,
14139,
314,
2351,
2659,
489,
291,
14,
12695,
63,
3128,
275,
2263,
339,
347,
1284,
8,
277,
12,
2351,
304,
489,
870,
360,
10759,
543,
314,
2351,
2659,
339,
347,
2544,
63,
1065,
8,
277,
12,
1255,
63,
1100,
304,
489,
870,
360,
5182,
6358,
2351,
14,
1065,
9,
489,
372,
8596,
2540,
6213,
8,
277,
14,
12695,
63,
3128,
9,
339,
347,
2410,
63,
1065,
8,
277,
12,
1255,
63,
1100,
12,
1255,
63,
1459,
9,
489,
870,
360,
10759,
3879,
1373,
3650,
14,
710,
574,
402,
3002,
2345,
26,
450,
83,
297,
288,
1255,
63,
1459,
14,
2604,
9,
489,
340,
1265,
13,
9321,
13,
475,
13,
2379,
13,
3813,
26,
267,
1255,
63,
1100,
14,
1069,
63,
2379,
342,
199,
199,
1378,
20647,
4212,
12604,
17232,
543,
4882,
370,
658,
6671,
17043,
4434,
14,
1065,
342,
3559,
199,
11660,
737,
2569,
1233,
26,
523,
543,
17897,
17311,
4434,
8,
7922,
29,
12695,
63,
7922,
12,
19172,
465,
4043,
272,
1830,
440,
4043,
14,
5626,
63,
2379,
342,
489,
4043,
14,
1065,
8,
12695,
63,
3535,
397,
9,
199,
199,
33,
3395,
922,
1233,
27401,
370,
2569,
6451,
26,
523,
1240,
12604,
14,
5037,
523,
4043,
275,
2833,
14,
4434,
342,
523,
1830,
440,
3631,
365,
5839,
26,
272,
1240,
12604,
14,
5182,
63,
1065,
342,
272,
2058,
275,
4043,
14,
1065,
8,
15269,
63,
3535,
397,
9,
272,
1240,
12604,
14,
4399,
63,
1065,
342,
523,
1240,
12604,
14,
500,
342,
523,
4043,
14,
1600,
342,
199,
199,
7492,
4434,
2540,
8481,
199,
7492,
4434,
2540,
6213,
199,
7492,
4434,
2540,
2998,
199,
7492,
4434,
2540,
6550,
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,
5055,
421,
199,
533,
8596,
2540,
8481,
8,
785,
304,
523,
408,
8481,
370,
12247,
4882,
370,
10953,
17043,
4434,
14,
1065,
20693,
819,
347,
5386,
8,
277,
304,
272,
408,
10474,
5403,
2544,
1808,
314,
2351,
14,
339,
3979,
2797,
12,
314,
849,
3343,
365,
314,
1373,
626,
911,
506,
27725,
315,
314,
272,
2351,
14,
221,
710,
5759,
883,
2811,
314,
3343,
701,
7791,
892,
5331,
370,
652,
14,
272,
12836,
314,
658,
5037,
11995,
1240,
314,
3343,
911,
506,
4242,
1759,
436,
314,
1163,
13484,
272,
883,
440,
2811,
314,
3343,
20827,
14,
16707,
1240,
402,
658,
5037,
11995,
641,
314,
2011,
272,
3343,
12,
1077,
440,
1570,
314,
3343,
14,
272,
408,
272,
986,
819,
347,
2410,
63,
981,
63,
1730,
8,
277,
12,
2351,
12,
11021,
304,
221,
327,
4287,
26,
3507,
29,
8618,
13,
2094,
272,
408,
10474,
1380,
892,
9134,
2351,
365,
2737,
14,
339,
961,
365,
2797,
370,
4673,
314,
12604,
626,
282,
892,
2351,
965,
2757,
2737,
14,
961,
272,
965,
2877,
22829,
1009,
15109,
543,
314,
25781,
315,
1314,
658,
5037,
64,
365,
2797,
26,
339,
627,
3979,
642,
365,
2797,
12,
314,
3343,
365,
4242,
1759,
436,
4156,
883,
949,
8088,
506,
3483,
267,
370,
314,
3343,
14,
272,
627,
961,
1083,
911,
2597,
506,
2797,
465,
282,
754,
402,
22803,
316,
282,
8072,
267,
2351,
12,
440,
1454,
737,
314,
9608,
402,
314,
20347,
2351,
14,
339,
3033,
26,
489,
2351,
26,
437,
9134,
8596,
626,
965,
2757,
2737,
14,
489,
11021,
26,
437,
25334,
707,
909,
1314,
18578
] |
[
1898,
7800,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
33,
8596,
2540,
8481,
16879,
658,
1730,
14,
1065,
11995,
4882,
367,
314,
658,
6671,
17043,
4434,
2313,
199,
199,
4434,
2540,
8481,
83,
787,
2997,
370,
4426,
6093,
12,
3622,
6696,
12,
1056,
14670,
199,
2379,
4073,
436,
1655,
14,
8596,
2540,
8481,
83,
675,
314,
27336,
3851,
436,
11705,
737,
314,
199,
21589,
4501,
26,
199,
446,
1380,
282,
2351,
9174,
3769,
1202,
199,
446,
2544,
282,
1240,
370,
314,
658,
1730,
14,
1065,
11995,
199,
446,
2410,
282,
1240,
370,
314,
658,
1730,
14,
1065,
11995,
199,
446,
1380,
314,
2351,
6876,
199,
199,
33,
8596,
2540,
8481,
22667,
15409,
282,
14854,
402,
295,
14418,
15,
863,
736,
461,
14009,
626,
199,
2425,
299,
528,
4312,
894,
282,
1240,
370,
658,
6671,
17043,
4434,
14,
1065,
25593,
437,
5759,
883,
1050,
1263,
199,
1483,
13,
269,
13,
3128,
15,
11522,
370,
314,
1255,
1240,
12,
436,
1380,
314,
1255,
1240,
9578,
397,
543,
3182,
199,
24894,
314,
4704,
652,
5839,
14,
24837,
83,
787,
4370,
370,
1050,
4156,
370,
314,
3343,
315,
199,
64,
3664,
14,
5037,
25593,
710,
3343,
365,
4242,
1759,
2410,
314,
658,
5037,
11995,
1083,
365,
2797,
14,
199,
199,
10924,
787,
282,
9284,
876,
13,
4037,
26862,
26,
199,
446,
8015,
1271,
7801,
8481,
26,
4784,
3631,
4079,
641,
2288,
63,
2926,
199,
446,
2670,
1403,
20829,
8481,
26,
23050,
9997,
199,
446,
19928,
3861,
8481,
26,
4704,
1373,
503,
1655,
2345,
1338,
370,
943,
199,
446,
653,
290,
3861,
8481,
26,
4784,
3631,
340,
1627,
658,
3861,
64,
3509,
653,
796,
14,
199,
446,
22486,
20829,
8481,
26,
23050,
23747,
370,
282,
6212,
7060,
199,
199,
1858,
1655,
2488,
4839,
12,
1265,
883,
1218,
3537,
12604,
26,
523,
1021,
5679,
8481,
8,
4434,
2540,
8481,
304,
272,
347,
5386,
8,
277,
304,
489,
327,
2047,
883,
1050,
4156,
370,
314,
3343,
2348,
14,
489,
870,
360,
14139,
314,
2351,
2659,
489,
291,
14,
12695,
63,
3128,
275,
2263,
339,
347,
1284,
8,
277,
12,
2351,
304,
489,
870,
360,
10759,
543,
314,
2351,
2659,
339,
347,
2544,
63,
1065,
8,
277,
12,
1255,
63,
1100,
304,
489,
870,
360,
5182,
6358,
2351,
14,
1065,
9,
489,
372,
8596,
2540,
6213,
8,
277,
14,
12695,
63,
3128,
9,
339,
347,
2410,
63,
1065,
8,
277,
12,
1255,
63,
1100,
12,
1255,
63,
1459,
9,
489,
870,
360,
10759,
3879,
1373,
3650,
14,
710,
574,
402,
3002,
2345,
26,
450,
83,
297,
288,
1255,
63,
1459,
14,
2604,
9,
489,
340,
1265,
13,
9321,
13,
475,
13,
2379,
13,
3813,
26,
267,
1255,
63,
1100,
14,
1069,
63,
2379,
342,
199,
199,
1378,
20647,
4212,
12604,
17232,
543,
4882,
370,
658,
6671,
17043,
4434,
14,
1065,
342,
3559,
199,
11660,
737,
2569,
1233,
26,
523,
543,
17897,
17311,
4434,
8,
7922,
29,
12695,
63,
7922,
12,
19172,
465,
4043,
272,
1830,
440,
4043,
14,
5626,
63,
2379,
342,
489,
4043,
14,
1065,
8,
12695,
63,
3535,
397,
9,
199,
199,
33,
3395,
922,
1233,
27401,
370,
2569,
6451,
26,
523,
1240,
12604,
14,
5037,
523,
4043,
275,
2833,
14,
4434,
342,
523,
1830,
440,
3631,
365,
5839,
26,
272,
1240,
12604,
14,
5182,
63,
1065,
342,
272,
2058,
275,
4043,
14,
1065,
8,
15269,
63,
3535,
397,
9,
272,
1240,
12604,
14,
4399,
63,
1065,
342,
523,
1240,
12604,
14,
500,
342,
523,
4043,
14,
1600,
342,
199,
199,
7492,
4434,
2540,
8481,
199,
7492,
4434,
2540,
6213,
199,
7492,
4434,
2540,
2998,
199,
7492,
4434,
2540,
6550,
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,
5055,
421,
199,
533,
8596,
2540,
8481,
8,
785,
304,
523,
408,
8481,
370,
12247,
4882,
370,
10953,
17043,
4434,
14,
1065,
20693,
819,
347,
5386,
8,
277,
304,
272,
408,
10474,
5403,
2544,
1808,
314,
2351,
14,
339,
3979,
2797,
12,
314,
849,
3343,
365,
314,
1373,
626,
911,
506,
27725,
315,
314,
272,
2351,
14,
221,
710,
5759,
883,
2811,
314,
3343,
701,
7791,
892,
5331,
370,
652,
14,
272,
12836,
314,
658,
5037,
11995,
1240,
314,
3343,
911,
506,
4242,
1759,
436,
314,
1163,
13484,
272,
883,
440,
2811,
314,
3343,
20827,
14,
16707,
1240,
402,
658,
5037,
11995,
641,
314,
2011,
272,
3343,
12,
1077,
440,
1570,
314,
3343,
14,
272,
408,
272,
986,
819,
347,
2410,
63,
981,
63,
1730,
8,
277,
12,
2351,
12,
11021,
304,
221,
327,
4287,
26,
3507,
29,
8618,
13,
2094,
272,
408,
10474,
1380,
892,
9134,
2351,
365,
2737,
14,
339,
961,
365,
2797,
370,
4673,
314,
12604,
626,
282,
892,
2351,
965,
2757,
2737,
14,
961,
272,
965,
2877,
22829,
1009,
15109,
543,
314,
25781,
315,
1314,
658,
5037,
64,
365,
2797,
26,
339,
627,
3979,
642,
365,
2797,
12,
314,
3343,
365,
4242,
1759,
436,
4156,
883,
949,
8088,
506,
3483,
267,
370,
314,
3343,
14,
272,
627,
961,
1083,
911,
2597,
506,
2797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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
] |
fernandog/osmc
|
package/mediacenter-addon-osmc/src/script.module.osmcsetting.networking/resources/lib/osmc_bluetooth_agent.py
|
15
|
7110
|
#!usr/bin/python
from optparse import OptionParser
import traceback
import dbus
import dbus.service
import dbus.mainloop.glib
try:
from gi.repository import GObject
except ImportError:
import gobject as GObject
import bluezutils
import json
PEXPECT_SOL = 'SOL@'
PEXPECT_EOL = '@EOL'
BUS_NAME = 'org.bluez'
AGENT_INTERFACE = 'org.bluez.Agent1'
AGENT_PATH = "/test/agent"
bus = None
device_obj = None
dev_path = None
def return_status(result, messages):
return_dict = {result : messages}
print PEXPECT_SOL+ json.dumps(return_dict) + PEXPECT_EOL
def decode_response(message):
if message.startswith(PEXPECT_SOL):
jsonStr = message.replace(PEXPECT_SOL,'').replace(PEXPECT_EOL,'')
returnValue = json.loads(jsonStr)
if returnValue.keys()[0] == 'RETURN_VALUE':
return str(returnValue.values()[0][0])
return None
return message
def set_trusted(path, boolean):
props = dbus.Interface(bus.get_object("org.bluez", path),
"org.freedesktop.DBus.Properties")
props.Set("org.bluez.Device1", "Trusted", boolean)
class Rejected(dbus.DBusException):
_dbus_error_name = "org.bluez.Error.Rejected"
class Agent(dbus.service.Object):
exit_on_release = True
return_code = 9
error_message = None
def set_return(self, return_code, error_message):
self.return_code = return_code
self.error_message = error_message
def set_exit_on_release(self, exit_on_release):
self.exit_on_release = exit_on_release
@dbus.service.method(AGENT_INTERFACE,
in_signature="", out_signature="")
def Release(self):
if self.exit_on_release:
mainloop.quit()
@dbus.service.method(AGENT_INTERFACE,
in_signature="os", out_signature="")
def AuthorizeService(self, device, uuid):
message_list = ['AUTHORIZE_SERVICE', device, uuid]
return_status('YESNO_INPUT', message_list)
returnStr = raw_input('Confirm Passkey:')
returnValue = decode_response(returnStr)
if returnValue == 'YES':
return
raise Rejected("Connection rejected by user")
@dbus.service.method(AGENT_INTERFACE,
in_signature="o", out_signature="s")
def RequestPinCode(self, device):
message_list = [ 'REQUEST_PIN', device ]
return_status('NUMERIC_INPUT', message_list)
returnStr = raw_input('Enter Pin: ')
returnValue = decode_response(returnStr)
pin = '0000'
if not returnValue == None:
pin = returnValue;
message_list = ['ENTER_PIN', str(pin)]
return_status('NOTIFICATION', message_list)
set_trusted(device, True)
return pin
@dbus.service.method(AGENT_INTERFACE,
in_signature="o", out_signature="u")
def RequestPasskey(self, device):
message_list = [ 'REQUEST_PIN', device ]
return_status('NUMERIC_INPUT', message_list)
returnStr = raw_input('Enter Pin: ')
returnValue = decode_response(returnStr)
pin = '0000'
if not returnValue == None:
pin = returnValue;
message_list = ['ENTER_PIN', str(pin)]
return_status('NOTIFICATION', message_list)
return dbus.UInt32(pin)
@dbus.service.method(AGENT_INTERFACE,
in_signature="ouq", out_signature="")
def DisplayPasskey(self, device, passkey, entered):
message_list = ['ENTER_PIN', str(passkey) ]
return_status('NOTIFICATION', message_list)
@dbus.service.method(AGENT_INTERFACE,
in_signature="os", out_signature="")
def DisplayPinCode(self, device, pincode):
message_list = ['ENTER_PIN', str(pincode) ]
return_status('NOTIFICATION', message_list)
@dbus.service.method(AGENT_INTERFACE,
in_signature="ou", out_signature="")
def RequestConfirmation(self, device, passkey):
message_list = ['CONFIRM_PASSKEY', passkey]
return_status('YESNO_INPUT', message_list)
returnStr = raw_input('Confirm Passkey:')
returnValue = decode_response(returnStr)
if returnValue == 'YES':
return
raise Rejected("Passkey doesn't match")
@dbus.service.method(AGENT_INTERFACE,
in_signature="o", out_signature="")
def RequestAuthorization(self, device):
message_list = ['AUTHORIZE_DEVICE', device]
return_status('YESNO_INPUT', message_list)
returnStr = raw_input('AUTHORIZE Device:')
returnValue = decode_response(returnStr)
if returnValue.keys()[0] == 'RETURN_VALUE':
if returnValue == 'YES':
return
raise Rejected("Passkey doesn't match")
def pair_successful():
set_trusted(dev_path, True)
agent.set_return(0, None)
mainloop.quit()
def pair_error(error):
set_trusted(dev_path, False)
err_name = error.get_dbus_name()
if err_name == "org.freedesktop.DBus.Error.NoReply" and device_obj:
agent.set_return(1, ' Timed out. Cancelling pairing')
device_obj.CancelPairing()
else:
if error.get_dbus_message() == 'Already Exists':
# we do not want to return an error code in this case
agent.set_return(0, None)
else:
agent.set_return(1, error.get_dbus_message())
mainloop.quit()
if __name__ == '__main__':
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
bus = dbus.SystemBus()
parser = OptionParser()
parser.add_option("-i", "--adapter", action="store",
type="string",
dest="adapter_pattern",
default=None)
parser.add_option("-c", "--capability", action="store",
type="string", dest="capability",
default="KeyboardDisplay")
parser.add_option("-t", "--timeout", action="store",
type="int", dest="timeout",
default=60000)
(options, args) = parser.parse_args()
agent = Agent(bus, AGENT_PATH)
mainloop = GObject.MainLoop()
obj = bus.get_object(BUS_NAME, "/org/bluez")
manager = dbus.Interface(obj, "org.bluez.AgentManager1")
manager.RegisterAgent(AGENT_PATH, options.capability)
if len(args) > 0:
try:
device = bluezutils.find_device(args[0],
options.adapter_pattern)
except:
return_status('DEVICE_NOT_FOUND' , ['Device not Found' ])
exit(1)
dev_path = device.object_path
agent.set_exit_on_release(False)
device.Pair(reply_handler=pair_successful, error_handler=pair_error,
timeout=options.timeout)
device_obj = device
mainloop.run()
manager.UnregisterAgent(AGENT_PATH)
if agent.error_message is not None:
return_status('PAIRING_FAILED', [agent.error_message ])
else:
return_status('PAIRING_OK', [])
|
gpl-2.0
|
[
3168,
2647,
15,
1393,
15,
1548,
199,
199,
504,
8691,
492,
13491,
199,
646,
5190,
199,
646,
21140,
199,
646,
21140,
14,
1364,
199,
646,
21140,
14,
22644,
14,
30816,
199,
893,
26,
272,
687,
18895,
14,
8421,
492,
31264,
199,
2590,
3545,
26,
272,
492,
25595,
465,
31264,
199,
646,
10030,
90,
1208,
199,
646,
2022,
199,
199,
48,
16957,
63,
15096,
275,
283,
15096,
32,
7,
199,
48,
16957,
63,
37,
2228,
275,
10267,
37,
2228,
7,
199,
199,
24753,
63,
2339,
275,
283,
1308,
14,
6304,
90,
7,
199,
14565,
63,
17598,
275,
283,
1308,
14,
6304,
90,
14,
7788,
17,
7,
199,
14565,
63,
3243,
275,
3286,
396,
15,
4054,
2,
199,
199,
5610,
275,
488,
199,
1782,
63,
1113,
275,
488,
199,
2374,
63,
515,
275,
488,
199,
199,
318,
372,
63,
1205,
8,
1099,
12,
3788,
304,
272,
372,
63,
807,
275,
469,
1099,
520,
3788,
93,
272,
870,
510,
16957,
63,
15096,
11,
2022,
14,
4180,
8,
1107,
63,
807,
9,
435,
510,
16957,
63,
37,
2228,
199,
199,
318,
4849,
63,
1310,
8,
1188,
304,
272,
340,
1245,
14,
2460,
8,
48,
16957,
63,
15096,
304,
267,
2022,
2848,
275,
1245,
14,
1814,
8,
48,
16957,
63,
15096,
2584,
1959,
1814,
8,
48,
16957,
63,
37,
2228,
2584,
358,
267,
372,
1110,
275,
2022,
14,
3640,
8,
1001,
2848,
9,
267,
340,
372,
1110,
14,
1612,
3430,
16,
61,
508,
283,
9677,
63,
7041,
356,
288,
372,
620,
8,
1107,
1110,
14,
1459,
3430,
16,
1527,
16,
566,
267,
372,
488,
272,
372,
1245,
1362,
199,
318,
663,
63,
17549,
8,
515,
12,
5046,
304,
272,
10792,
275,
21140,
14,
4267,
8,
5610,
14,
362,
63,
785,
480,
1308,
14,
6304,
90,
401,
931,
395,
2574,
298,
1308,
14,
4624,
14487,
14,
2846,
527,
14,
8516,
531,
272,
10792,
14,
1084,
480,
1308,
14,
6304,
90,
14,
2510,
17,
401,
298,
14064,
7274,
401,
5046,
9,
199,
199,
533,
799,
8553,
8,
17066,
14,
2846,
527,
1726,
304,
272,
485,
17066,
63,
705,
63,
354,
275,
298,
1308,
14,
6304,
90,
14,
547,
14,
497,
8553,
2,
421,
199,
533,
19866,
8,
17066,
14,
1364,
14,
1692,
304,
272,
4458,
63,
265,
63,
3221,
275,
715,
272,
372,
63,
600,
275,
1749,
272,
1125,
63,
1188,
275,
488,
272,
347,
663,
63,
1107,
8,
277,
12,
372,
63,
600,
12,
1125,
63,
1188,
304,
267,
291,
14,
1107,
63,
600,
275,
372,
63,
600,
267,
291,
14,
705,
63,
1188,
275,
1125,
63,
1188,
339,
347,
663,
63,
2224,
63,
265,
63,
3221,
8,
277,
12,
4458,
63,
265,
63,
3221,
304,
267,
291,
14,
2224,
63,
265,
63,
3221,
275,
4458,
63,
265,
63,
3221,
339,
768,
17066,
14,
1364,
14,
765,
8,
14565,
63,
17598,
12,
586,
315,
63,
5233,
8772,
734,
63,
5233,
18413,
272,
347,
17646,
8,
277,
304,
267,
340,
291,
14,
2224,
63,
265,
63,
3221,
26,
288,
2446,
3813,
14,
10589,
342,
339,
768,
17066,
14,
1364,
14,
765,
8,
14565,
63,
17598,
12,
586,
315,
63,
5233,
628,
736,
401,
734,
63,
5233,
18413,
272,
347,
6529,
794,
3167,
8,
277,
12,
2243,
12,
5377,
304,
267,
1245,
63,
513,
275,
788,
27938,
11025,
63,
10486,
297,
2243,
12,
5377,
61,
267,
372,
63,
1205,
360,
15641,
2826,
63,
7321,
297,
1245,
63,
513,
9,
267,
372,
2848,
275,
3066,
63,
1210,
360,
26857,
8325,
498,
10993,
267,
372,
1110,
275,
4849,
63,
1310,
8,
1107,
2848,
9,
267,
340,
372,
1110,
508,
283,
15641,
356,
355,
372,
267,
746,
799,
8553,
480,
3225,
18935,
701,
922,
531,
339,
768,
17066,
14,
1364,
14,
765,
8,
14565,
63,
17598,
12,
586,
315,
63,
5233,
628,
79,
401,
734,
63,
5233,
628,
83,
531,
272,
347,
4784,
19909,
3034,
8,
277,
12,
2243,
304,
267,
1245,
63,
513,
275,
359,
283,
6780,
63,
30929,
297,
2243,
1622,
267,
372,
63,
1205,
360,
28425,
63,
7321,
297,
1245,
63,
513,
9,
267,
372,
2848,
275,
3066,
63,
1210,
360,
8468,
26486,
26,
5320,
267,
372,
1110,
275,
4849,
63,
1310,
8,
1107,
2848,
9,
267,
10713,
275,
283,
993,
7,
267,
340,
440,
372,
1110,
508,
488,
26,
288,
10713,
275,
372,
1110,
27,
267,
1245,
63,
513,
275,
788,
12533,
63,
30929,
297,
620,
8,
7751,
1874,
267,
372,
63,
1205,
360,
22839,
2594,
297,
1245,
63,
513,
9,
267,
663,
63,
17549,
8,
1782,
12,
715,
9,
267,
372,
10713,
5493,
768,
17066,
14,
1364,
14,
765,
8,
14565,
63,
17598,
12,
586,
315,
63,
5233,
628,
79,
401,
734,
63,
5233,
628,
85,
531,
272,
347,
4784,
4986,
498,
8,
277,
12,
2243,
304,
267,
1245,
63,
513,
275,
359,
283,
6780,
63,
30929,
297,
2243,
1622,
267,
372,
63,
1205,
360,
28425,
63,
7321,
297,
1245,
63,
513,
9,
267,
372,
2848,
275,
3066,
63,
1210,
360,
8468,
26486,
26,
5320,
267,
372,
1110,
275,
4849,
63,
1310,
8,
1107,
2848,
9,
267,
10713,
275,
283,
993,
7,
267,
340,
440,
372,
1110,
508,
488,
26,
288,
10713,
275,
372,
1110,
27,
267,
1245,
63,
513,
275,
788,
12533,
63,
30929,
297,
620,
8,
7751,
1874,
267,
372,
63,
1205,
360,
22839,
2594,
297,
1245,
63,
513,
9,
267,
372,
21140,
14,
13304,
708,
8,
7751,
9,
339,
768,
17066,
14,
1364,
14,
765,
8,
14565,
63,
17598,
12,
586,
315,
63,
5233,
628,
810,
81,
401,
734,
63,
5233,
18413,
272,
347,
12175,
4986,
498,
8,
277,
12,
2243,
12,
986,
498,
12,
19138,
304,
267,
1245,
63,
513,
275,
788,
12533,
63,
30929,
297,
620,
8,
1529,
498,
9,
1622,
267,
372,
63,
1205,
360,
22839,
2594,
297,
1245,
63,
513,
9,
339,
768,
17066,
14,
1364,
14,
765,
8,
14565,
63,
17598,
12,
586,
315,
63,
5233,
628,
736,
401,
734,
63,
5233,
18413,
272,
347,
12175,
19909,
3034,
8,
277,
12,
2243,
12,
10713,
600,
304,
267,
1245,
63,
513,
275,
788,
12533,
63,
30929,
297,
620,
8,
7751,
600,
9,
1622,
267,
372,
63,
1205,
360,
22839,
2594,
297,
1245,
63,
513,
9,
339,
768,
17066,
14,
1364,
14,
765,
8
] |
[
2647,
15,
1393,
15,
1548,
199,
199,
504,
8691,
492,
13491,
199,
646,
5190,
199,
646,
21140,
199,
646,
21140,
14,
1364,
199,
646,
21140,
14,
22644,
14,
30816,
199,
893,
26,
272,
687,
18895,
14,
8421,
492,
31264,
199,
2590,
3545,
26,
272,
492,
25595,
465,
31264,
199,
646,
10030,
90,
1208,
199,
646,
2022,
199,
199,
48,
16957,
63,
15096,
275,
283,
15096,
32,
7,
199,
48,
16957,
63,
37,
2228,
275,
10267,
37,
2228,
7,
199,
199,
24753,
63,
2339,
275,
283,
1308,
14,
6304,
90,
7,
199,
14565,
63,
17598,
275,
283,
1308,
14,
6304,
90,
14,
7788,
17,
7,
199,
14565,
63,
3243,
275,
3286,
396,
15,
4054,
2,
199,
199,
5610,
275,
488,
199,
1782,
63,
1113,
275,
488,
199,
2374,
63,
515,
275,
488,
199,
199,
318,
372,
63,
1205,
8,
1099,
12,
3788,
304,
272,
372,
63,
807,
275,
469,
1099,
520,
3788,
93,
272,
870,
510,
16957,
63,
15096,
11,
2022,
14,
4180,
8,
1107,
63,
807,
9,
435,
510,
16957,
63,
37,
2228,
199,
199,
318,
4849,
63,
1310,
8,
1188,
304,
272,
340,
1245,
14,
2460,
8,
48,
16957,
63,
15096,
304,
267,
2022,
2848,
275,
1245,
14,
1814,
8,
48,
16957,
63,
15096,
2584,
1959,
1814,
8,
48,
16957,
63,
37,
2228,
2584,
358,
267,
372,
1110,
275,
2022,
14,
3640,
8,
1001,
2848,
9,
267,
340,
372,
1110,
14,
1612,
3430,
16,
61,
508,
283,
9677,
63,
7041,
356,
288,
372,
620,
8,
1107,
1110,
14,
1459,
3430,
16,
1527,
16,
566,
267,
372,
488,
272,
372,
1245,
1362,
199,
318,
663,
63,
17549,
8,
515,
12,
5046,
304,
272,
10792,
275,
21140,
14,
4267,
8,
5610,
14,
362,
63,
785,
480,
1308,
14,
6304,
90,
401,
931,
395,
2574,
298,
1308,
14,
4624,
14487,
14,
2846,
527,
14,
8516,
531,
272,
10792,
14,
1084,
480,
1308,
14,
6304,
90,
14,
2510,
17,
401,
298,
14064,
7274,
401,
5046,
9,
199,
199,
533,
799,
8553,
8,
17066,
14,
2846,
527,
1726,
304,
272,
485,
17066,
63,
705,
63,
354,
275,
298,
1308,
14,
6304,
90,
14,
547,
14,
497,
8553,
2,
421,
199,
533,
19866,
8,
17066,
14,
1364,
14,
1692,
304,
272,
4458,
63,
265,
63,
3221,
275,
715,
272,
372,
63,
600,
275,
1749,
272,
1125,
63,
1188,
275,
488,
272,
347,
663,
63,
1107,
8,
277,
12,
372,
63,
600,
12,
1125,
63,
1188,
304,
267,
291,
14,
1107,
63,
600,
275,
372,
63,
600,
267,
291,
14,
705,
63,
1188,
275,
1125,
63,
1188,
339,
347,
663,
63,
2224,
63,
265,
63,
3221,
8,
277,
12,
4458,
63,
265,
63,
3221,
304,
267,
291,
14,
2224,
63,
265,
63,
3221,
275,
4458,
63,
265,
63,
3221,
339,
768,
17066,
14,
1364,
14,
765,
8,
14565,
63,
17598,
12,
586,
315,
63,
5233,
8772,
734,
63,
5233,
18413,
272,
347,
17646,
8,
277,
304,
267,
340,
291,
14,
2224,
63,
265,
63,
3221,
26,
288,
2446,
3813,
14,
10589,
342,
339,
768,
17066,
14,
1364,
14,
765,
8,
14565,
63,
17598,
12,
586,
315,
63,
5233,
628,
736,
401,
734,
63,
5233,
18413,
272,
347,
6529,
794,
3167,
8,
277,
12,
2243,
12,
5377,
304,
267,
1245,
63,
513,
275,
788,
27938,
11025,
63,
10486,
297,
2243,
12,
5377,
61,
267,
372,
63,
1205,
360,
15641,
2826,
63,
7321,
297,
1245,
63,
513,
9,
267,
372,
2848,
275,
3066,
63,
1210,
360,
26857,
8325,
498,
10993,
267,
372,
1110,
275,
4849,
63,
1310,
8,
1107,
2848,
9,
267,
340,
372,
1110,
508,
283,
15641,
356,
355,
372,
267,
746,
799,
8553,
480,
3225,
18935,
701,
922,
531,
339,
768,
17066,
14,
1364,
14,
765,
8,
14565,
63,
17598,
12,
586,
315,
63,
5233,
628,
79,
401,
734,
63,
5233,
628,
83,
531,
272,
347,
4784,
19909,
3034,
8,
277,
12,
2243,
304,
267,
1245,
63,
513,
275,
359,
283,
6780,
63,
30929,
297,
2243,
1622,
267,
372,
63,
1205,
360,
28425,
63,
7321,
297,
1245,
63,
513,
9,
267,
372,
2848,
275,
3066,
63,
1210,
360,
8468,
26486,
26,
5320,
267,
372,
1110,
275,
4849,
63,
1310,
8,
1107,
2848,
9,
267,
10713,
275,
283,
993,
7,
267,
340,
440,
372,
1110,
508,
488,
26,
288,
10713,
275,
372,
1110,
27,
267,
1245,
63,
513,
275,
788,
12533,
63,
30929,
297,
620,
8,
7751,
1874,
267,
372,
63,
1205,
360,
22839,
2594,
297,
1245,
63,
513,
9,
267,
663,
63,
17549,
8,
1782,
12,
715,
9,
267,
372,
10713,
5493,
768,
17066,
14,
1364,
14,
765,
8,
14565,
63,
17598,
12,
586,
315,
63,
5233,
628,
79,
401,
734,
63,
5233,
628,
85,
531,
272,
347,
4784,
4986,
498,
8,
277,
12,
2243,
304,
267,
1245,
63,
513,
275,
359,
283,
6780,
63,
30929,
297,
2243,
1622,
267,
372,
63,
1205,
360,
28425,
63,
7321,
297,
1245,
63,
513,
9,
267,
372,
2848,
275,
3066,
63,
1210,
360,
8468,
26486,
26,
5320,
267,
372,
1110,
275,
4849,
63,
1310,
8,
1107,
2848,
9,
267,
10713,
275,
283,
993,
7,
267,
340,
440,
372,
1110,
508,
488,
26,
288,
10713,
275,
372,
1110,
27,
267,
1245,
63,
513,
275,
788,
12533,
63,
30929,
297,
620,
8,
7751,
1874,
267,
372,
63,
1205,
360,
22839,
2594,
297,
1245,
63,
513,
9,
267,
372,
21140,
14,
13304,
708,
8,
7751,
9,
339,
768,
17066,
14,
1364,
14,
765,
8,
14565,
63,
17598,
12,
586,
315,
63,
5233,
628,
810,
81,
401,
734,
63,
5233,
18413,
272,
347,
12175,
4986,
498,
8,
277,
12,
2243,
12,
986,
498,
12,
19138,
304,
267,
1245,
63,
513,
275,
788,
12533,
63,
30929,
297,
620,
8,
1529,
498,
9,
1622,
267,
372,
63,
1205,
360,
22839,
2594,
297,
1245,
63,
513,
9,
339,
768,
17066,
14,
1364,
14,
765,
8,
14565,
63,
17598,
12,
586,
315,
63,
5233,
628,
736,
401,
734,
63,
5233,
18413,
272,
347,
12175,
19909,
3034,
8,
277,
12,
2243,
12,
10713,
600,
304,
267,
1245,
63,
513,
275,
788,
12533,
63,
30929,
297,
620,
8,
7751,
600,
9,
1622,
267,
372,
63,
1205,
360,
22839,
2594,
297,
1245,
63,
513,
9,
339,
768,
17066,
14,
1364,
14,
765,
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,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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
] |
TribeMedia/synapse
|
synapse/storage/search.py
|
2
|
21943
|
# -*- coding: utf-8 -*-
# Copyright 2015, 2016 OpenMarket Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from twisted.internet import defer
from .background_updates import BackgroundUpdateStore
from synapse.api.errors import SynapseError
from synapse.storage.engines import PostgresEngine, Sqlite3Engine
import logging
import re
import ujson as json
logger = logging.getLogger(__name__)
class SearchStore(BackgroundUpdateStore):
EVENT_SEARCH_UPDATE_NAME = "event_search"
EVENT_SEARCH_ORDER_UPDATE_NAME = "event_search_order"
EVENT_SEARCH_USE_GIST_POSTGRES_NAME = "event_search_postgres_gist"
def __init__(self, hs):
super(SearchStore, self).__init__(hs)
self.register_background_update_handler(
self.EVENT_SEARCH_UPDATE_NAME, self._background_reindex_search
)
self.register_background_update_handler(
self.EVENT_SEARCH_ORDER_UPDATE_NAME,
self._background_reindex_search_order
)
self.register_background_update_handler(
self.EVENT_SEARCH_USE_GIST_POSTGRES_NAME,
self._background_reindex_gist_search
)
@defer.inlineCallbacks
def _background_reindex_search(self, progress, batch_size):
target_min_stream_id = progress["target_min_stream_id_inclusive"]
max_stream_id = progress["max_stream_id_exclusive"]
rows_inserted = progress.get("rows_inserted", 0)
INSERT_CLUMP_SIZE = 1000
TYPES = ["m.room.name", "m.room.message", "m.room.topic"]
def reindex_search_txn(txn):
sql = (
"SELECT stream_ordering, event_id, room_id, type, content FROM events"
" WHERE ? <= stream_ordering AND stream_ordering < ?"
" AND (%s)"
" ORDER BY stream_ordering DESC"
" LIMIT ?"
) % (" OR ".join("type = '%s'" % (t,) for t in TYPES),)
txn.execute(sql, (target_min_stream_id, max_stream_id, batch_size))
rows = self.cursor_to_dict(txn)
if not rows:
return 0
min_stream_id = rows[-1]["stream_ordering"]
event_search_rows = []
for row in rows:
try:
event_id = row["event_id"]
room_id = row["room_id"]
etype = row["type"]
try:
content = json.loads(row["content"])
except:
continue
if etype == "m.room.message":
key = "content.body"
value = content["body"]
elif etype == "m.room.topic":
key = "content.topic"
value = content["topic"]
elif etype == "m.room.name":
key = "content.name"
value = content["name"]
except (KeyError, AttributeError):
# If the event is missing a necessary field then
# skip over it.
continue
if not isinstance(value, basestring):
# If the event body, name or topic isn't a string
# then skip over it
continue
event_search_rows.append((event_id, room_id, key, value))
if isinstance(self.database_engine, PostgresEngine):
sql = (
"INSERT INTO event_search (event_id, room_id, key, vector)"
" VALUES (?,?,?,to_tsvector('english', ?))"
)
elif isinstance(self.database_engine, Sqlite3Engine):
sql = (
"INSERT INTO event_search (event_id, room_id, key, value)"
" VALUES (?,?,?,?)"
)
else:
# This should be unreachable.
raise Exception("Unrecognized database engine")
for index in range(0, len(event_search_rows), INSERT_CLUMP_SIZE):
clump = event_search_rows[index:index + INSERT_CLUMP_SIZE]
txn.executemany(sql, clump)
progress = {
"target_min_stream_id_inclusive": target_min_stream_id,
"max_stream_id_exclusive": min_stream_id,
"rows_inserted": rows_inserted + len(event_search_rows)
}
self._background_update_progress_txn(
txn, self.EVENT_SEARCH_UPDATE_NAME, progress
)
return len(event_search_rows)
result = yield self.runInteraction(
self.EVENT_SEARCH_UPDATE_NAME, reindex_search_txn
)
if not result:
yield self._end_background_update(self.EVENT_SEARCH_UPDATE_NAME)
defer.returnValue(result)
@defer.inlineCallbacks
def _background_reindex_gist_search(self, progress, batch_size):
def create_index(conn):
conn.rollback()
conn.set_session(autocommit=True)
c = conn.cursor()
c.execute(
"CREATE INDEX CONCURRENTLY event_search_fts_idx_gist"
" ON event_search USING GIST (vector)"
)
c.execute("DROP INDEX event_search_fts_idx")
conn.set_session(autocommit=False)
if isinstance(self.database_engine, PostgresEngine):
yield self.runWithConnection(create_index)
yield self._end_background_update(self.EVENT_SEARCH_USE_GIST_POSTGRES_NAME)
defer.returnValue(1)
@defer.inlineCallbacks
def _background_reindex_search_order(self, progress, batch_size):
target_min_stream_id = progress["target_min_stream_id_inclusive"]
max_stream_id = progress["max_stream_id_exclusive"]
rows_inserted = progress.get("rows_inserted", 0)
have_added_index = progress['have_added_indexes']
if not have_added_index:
def create_index(conn):
conn.rollback()
conn.set_session(autocommit=True)
c = conn.cursor()
# We create with NULLS FIRST so that when we search *backwards*
# we get the ones with non null origin_server_ts *first*
c.execute(
"CREATE INDEX CONCURRENTLY event_search_room_order ON event_search("
"room_id, origin_server_ts NULLS FIRST, stream_ordering NULLS FIRST)"
)
c.execute(
"CREATE INDEX CONCURRENTLY event_search_order ON event_search("
"origin_server_ts NULLS FIRST, stream_ordering NULLS FIRST)"
)
conn.set_session(autocommit=False)
yield self.runWithConnection(create_index)
pg = dict(progress)
pg["have_added_indexes"] = True
yield self.runInteraction(
self.EVENT_SEARCH_ORDER_UPDATE_NAME,
self._background_update_progress_txn,
self.EVENT_SEARCH_ORDER_UPDATE_NAME, pg,
)
def reindex_search_txn(txn):
sql = (
"UPDATE event_search AS es SET stream_ordering = e.stream_ordering,"
" origin_server_ts = e.origin_server_ts"
" FROM events AS e"
" WHERE e.event_id = es.event_id"
" AND ? <= e.stream_ordering AND e.stream_ordering < ?"
" RETURNING es.stream_ordering"
)
min_stream_id = max_stream_id - batch_size
txn.execute(sql, (min_stream_id, max_stream_id))
rows = txn.fetchall()
if min_stream_id < target_min_stream_id:
# We've recached the end.
return len(rows), False
progress = {
"target_min_stream_id_inclusive": target_min_stream_id,
"max_stream_id_exclusive": min_stream_id,
"rows_inserted": rows_inserted + len(rows),
"have_added_indexes": True,
}
self._background_update_progress_txn(
txn, self.EVENT_SEARCH_ORDER_UPDATE_NAME, progress
)
return len(rows), True
num_rows, finished = yield self.runInteraction(
self.EVENT_SEARCH_ORDER_UPDATE_NAME, reindex_search_txn
)
if not finished:
yield self._end_background_update(self.EVENT_SEARCH_ORDER_UPDATE_NAME)
defer.returnValue(num_rows)
@defer.inlineCallbacks
def search_msgs(self, room_ids, search_term, keys):
"""Performs a full text search over events with given keys.
Args:
room_ids (list): List of room ids to search in
search_term (str): Search term to search for
keys (list): List of keys to search in, currently supports
"content.body", "content.name", "content.topic"
Returns:
list of dicts
"""
clauses = []
search_query = search_query = _parse_query(self.database_engine, search_term)
args = []
# Make sure we don't explode because the person is in too many rooms.
# We filter the results below regardless.
if len(room_ids) < 500:
clauses.append(
"room_id IN (%s)" % (",".join(["?"] * len(room_ids)),)
)
args.extend(room_ids)
local_clauses = []
for key in keys:
local_clauses.append("key = ?")
args.append(key)
clauses.append(
"(%s)" % (" OR ".join(local_clauses),)
)
count_args = args
count_clauses = clauses
if isinstance(self.database_engine, PostgresEngine):
sql = (
"SELECT ts_rank_cd(vector, to_tsquery('english', ?)) AS rank,"
" room_id, event_id"
" FROM event_search"
" WHERE vector @@ to_tsquery('english', ?)"
)
args = [search_query, search_query] + args
count_sql = (
"SELECT room_id, count(*) as count FROM event_search"
" WHERE vector @@ to_tsquery('english', ?)"
)
count_args = [search_query] + count_args
elif isinstance(self.database_engine, Sqlite3Engine):
sql = (
"SELECT rank(matchinfo(event_search)) as rank, room_id, event_id"
" FROM event_search"
" WHERE value MATCH ?"
)
args = [search_query] + args
count_sql = (
"SELECT room_id, count(*) as count FROM event_search"
" WHERE value MATCH ?"
)
count_args = [search_term] + count_args
else:
# This should be unreachable.
raise Exception("Unrecognized database engine")
for clause in clauses:
sql += " AND " + clause
for clause in count_clauses:
count_sql += " AND " + clause
# We add an arbitrary limit here to ensure we don't try to pull the
# entire table from the database.
sql += " ORDER BY rank DESC LIMIT 500"
results = yield self._execute(
"search_msgs", self.cursor_to_dict, sql, *args
)
results = filter(lambda row: row["room_id"] in room_ids, results)
events = yield self._get_events([r["event_id"] for r in results])
event_map = {
ev.event_id: ev
for ev in events
}
highlights = None
if isinstance(self.database_engine, PostgresEngine):
highlights = yield self._find_highlights_in_postgres(search_query, events)
count_sql += " GROUP BY room_id"
count_results = yield self._execute(
"search_rooms_count", self.cursor_to_dict, count_sql, *count_args
)
count = sum(row["count"] for row in count_results if row["room_id"] in room_ids)
defer.returnValue({
"results": [
{
"event": event_map[r["event_id"]],
"rank": r["rank"],
}
for r in results
if r["event_id"] in event_map
],
"highlights": highlights,
"count": count,
})
@defer.inlineCallbacks
def search_rooms(self, room_ids, search_term, keys, limit, pagination_token=None):
"""Performs a full text search over events with given keys.
Args:
room_id (list): The room_ids to search in
search_term (str): Search term to search for
keys (list): List of keys to search in, currently supports
"content.body", "content.name", "content.topic"
pagination_token (str): A pagination token previously returned
Returns:
list of dicts
"""
clauses = []
search_query = search_query = _parse_query(self.database_engine, search_term)
args = []
# Make sure we don't explode because the person is in too many rooms.
# We filter the results below regardless.
if len(room_ids) < 500:
clauses.append(
"room_id IN (%s)" % (",".join(["?"] * len(room_ids)),)
)
args.extend(room_ids)
local_clauses = []
for key in keys:
local_clauses.append("key = ?")
args.append(key)
clauses.append(
"(%s)" % (" OR ".join(local_clauses),)
)
# take copies of the current args and clauses lists, before adding
# pagination clauses to main query.
count_args = list(args)
count_clauses = list(clauses)
if pagination_token:
try:
origin_server_ts, stream = pagination_token.split(",")
origin_server_ts = int(origin_server_ts)
stream = int(stream)
except:
raise SynapseError(400, "Invalid pagination token")
clauses.append(
"(origin_server_ts < ?"
" OR (origin_server_ts = ? AND stream_ordering < ?))"
)
args.extend([origin_server_ts, origin_server_ts, stream])
if isinstance(self.database_engine, PostgresEngine):
sql = (
"SELECT ts_rank_cd(vector, to_tsquery('english', ?)) as rank,"
" origin_server_ts, stream_ordering, room_id, event_id"
" FROM event_search"
" WHERE vector @@ to_tsquery('english', ?) AND "
)
args = [search_query, search_query] + args
count_sql = (
"SELECT room_id, count(*) as count FROM event_search"
" WHERE vector @@ to_tsquery('english', ?) AND "
)
count_args = [search_query] + count_args
elif isinstance(self.database_engine, Sqlite3Engine):
# We use CROSS JOIN here to ensure we use the right indexes.
# https://sqlite.org/optoverview.html#crossjoin
#
# We want to use the full text search index on event_search to
# extract all possible matches first, then lookup those matches
# in the events table to get the topological ordering. We need
# to use the indexes in this order because sqlite refuses to
# MATCH unless it uses the full text search index
sql = (
"SELECT rank(matchinfo) as rank, room_id, event_id,"
" origin_server_ts, stream_ordering"
" FROM (SELECT key, event_id, matchinfo(event_search) as matchinfo"
" FROM event_search"
" WHERE value MATCH ?"
" )"
" CROSS JOIN events USING (event_id)"
" WHERE "
)
args = [search_query] + args
count_sql = (
"SELECT room_id, count(*) as count FROM event_search"
" WHERE value MATCH ? AND "
)
count_args = [search_term] + count_args
else:
# This should be unreachable.
raise Exception("Unrecognized database engine")
sql += " AND ".join(clauses)
count_sql += " AND ".join(count_clauses)
# We add an arbitrary limit here to ensure we don't try to pull the
# entire table from the database.
if isinstance(self.database_engine, PostgresEngine):
sql += (
" ORDER BY origin_server_ts DESC NULLS LAST,"
" stream_ordering DESC NULLS LAST LIMIT ?"
)
elif isinstance(self.database_engine, Sqlite3Engine):
sql += " ORDER BY origin_server_ts DESC, stream_ordering DESC LIMIT ?"
else:
raise Exception("Unrecognized database engine")
args.append(limit)
results = yield self._execute(
"search_rooms", self.cursor_to_dict, sql, *args
)
results = filter(lambda row: row["room_id"] in room_ids, results)
events = yield self._get_events([r["event_id"] for r in results])
event_map = {
ev.event_id: ev
for ev in events
}
highlights = None
if isinstance(self.database_engine, PostgresEngine):
highlights = yield self._find_highlights_in_postgres(search_query, events)
count_sql += " GROUP BY room_id"
count_results = yield self._execute(
"search_rooms_count", self.cursor_to_dict, count_sql, *count_args
)
count = sum(row["count"] for row in count_results if row["room_id"] in room_ids)
defer.returnValue({
"results": [
{
"event": event_map[r["event_id"]],
"rank": r["rank"],
"pagination_token": "%s,%s" % (
r["origin_server_ts"], r["stream_ordering"]
),
}
for r in results
if r["event_id"] in event_map
],
"highlights": highlights,
"count": count,
})
def _find_highlights_in_postgres(self, search_query, events):
"""Given a list of events and a search term, return a list of words
that match from the content of the event.
This is used to give a list of words that clients can match against to
highlight the matching parts.
Args:
search_query (str)
events (list): A list of events
Returns:
deferred : A set of strings.
"""
def f(txn):
highlight_words = set()
for event in events:
# As a hack we simply join values of all possible keys. This is
# fine since we're only using them to find possible highlights.
values = []
for key in ("body", "name", "topic"):
v = event.content.get(key, None)
if v:
values.append(v)
if not values:
continue
value = " ".join(values)
# We need to find some values for StartSel and StopSel that
# aren't in the value so that we can pick results out.
start_sel = "<"
stop_sel = ">"
while start_sel in value:
start_sel += "<"
while stop_sel in value:
stop_sel += ">"
query = "SELECT ts_headline(?, to_tsquery('english', ?), %s)" % (
_to_postgres_options({
"StartSel": start_sel,
"StopSel": stop_sel,
"MaxFragments": "50",
})
)
txn.execute(query, (value, search_query,))
headline, = txn.fetchall()[0]
# Now we need to pick the possible highlights out of the haedline
# result.
matcher_regex = "%s(.*?)%s" % (
re.escape(start_sel),
re.escape(stop_sel),
)
res = re.findall(matcher_regex, headline)
highlight_words.update([r.lower() for r in res])
return highlight_words
return self.runInteraction("_find_highlights", f)
def _to_postgres_options(options_dict):
return "'%s'" % (
",".join("%s=%s" % (k, v) for k, v in options_dict.items()),
)
def _parse_query(database_engine, search_term):
"""Takes a plain unicode string from the user and converts it into a form
that can be passed to database.
We use this so that we can add prefix matching, which isn't something
that is supported by default.
"""
# Pull out the individual words, discarding any non-word characters.
results = re.findall(r"([\w\-]+)", search_term, re.UNICODE)
if isinstance(database_engine, PostgresEngine):
return " & ".join(result + ":*" for result in results)
elif isinstance(database_engine, Sqlite3Engine):
return " & ".join(result + "*" for result in results)
else:
# This should be unreachable.
raise Exception("Unrecognized database engine")
|
apache-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
1898,
6900,
12,
7800,
3232,
21667,
12126,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
504,
7390,
14,
4901,
492,
10133,
199,
199,
504,
1275,
7451,
63,
7618,
492,
10257,
3928,
4152,
5502,
199,
504,
9560,
19111,
14,
1246,
14,
2550,
492,
29988,
19111,
547,
199,
504,
9560,
19111,
14,
3494,
14,
30378,
492,
7711,
7266,
8524,
12,
428,
29498,
19,
8524,
199,
199,
646,
2050,
199,
646,
295,
199,
646,
399,
1001,
465,
2022,
421,
199,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
8730,
5502,
8,
14148,
4152,
5502,
304,
339,
6461,
63,
15962,
63,
10383,
63,
2339,
275,
298,
1430,
63,
1733,
2,
272,
6461,
63,
15962,
63,
12125,
63,
10383,
63,
2339,
275,
298,
1430,
63,
1733,
63,
1648,
2,
272,
6461,
63,
15962,
63,
4701,
63,
39,
6225,
63,
4030,
39,
3830,
63,
2339,
275,
298,
1430,
63,
1733,
63,
10675,
63,
71,
631,
2,
339,
347,
636,
826,
721,
277,
12,
17446,
304,
267,
1613,
8,
5278,
5502,
12,
291,
2843,
826,
721,
4213,
9,
267,
291,
14,
2683,
63,
7451,
63,
873,
63,
2232,
8,
288,
291,
14,
8193,
63,
15962,
63,
10383,
63,
2339,
12,
291,
423,
7451,
63,
21764,
63,
1733,
267,
776,
267,
291,
14,
2683,
63,
7451,
63,
873,
63,
2232,
8,
288,
291,
14,
8193,
63,
15962,
63,
12125,
63,
10383,
63,
2339,
12,
288,
291,
423,
7451,
63,
21764,
63,
1733,
63,
1648,
267,
776,
267,
291,
14,
2683,
63,
7451,
63,
873,
63,
2232,
8,
288,
291,
14,
8193,
63,
15962,
63,
4701,
63,
39,
6225,
63,
4030,
39,
3830,
63,
2339,
12,
288,
291,
423,
7451,
63,
21764,
63,
71,
631,
63,
1733,
267,
776,
339,
768,
11610,
14,
24813,
272,
347,
485,
7451,
63,
21764,
63,
1733,
8,
277,
12,
6696,
12,
3522,
63,
890,
304,
267,
1347,
63,
827,
63,
1745,
63,
344,
275,
6696,
905,
1375,
63,
827,
63,
1745,
63,
344,
63,
26062,
937,
267,
1390,
63,
1745,
63,
344,
275,
6696,
905,
988,
63,
1745,
63,
344,
63,
12730,
937,
267,
4730,
63,
28565,
275,
6696,
14,
362,
480,
3838,
63,
28565,
401,
378,
9,
398,
22542,
63,
1981,
22759,
63,
4305,
275,
5198,
267,
32317,
275,
2097,
77,
14,
11245,
14,
354,
401,
298,
77,
14,
11245,
14,
1188,
401,
298,
77,
14,
11245,
14,
5746,
937,
398,
347,
295,
1080,
63,
1733,
63,
18174,
8,
18174,
304,
288,
3875,
275,
334,
355,
298,
4859,
2547,
63,
7128,
12,
1566,
63,
344,
12,
14726,
63,
344,
12,
730,
12,
1564,
4442,
4474,
2,
355,
298,
6038,
5805,
2695,
2547,
63,
7128,
2401,
2547,
63,
7128,
665,
5805,
2,
355,
298,
2401,
4366,
83,
2924,
355,
298,
16044,
6515,
2547,
63,
7128,
23915,
2,
355,
298,
5138,
5805,
2,
288,
776,
450,
1689,
1549,
3680,
904,
480,
466,
275,
1543,
83,
4065,
450,
334,
84,
4258,
367,
307,
315,
32317,
16945,
953,
23883,
14,
2526,
8,
3009,
12,
334,
1375,
63,
827,
63,
1745,
63,
344,
12,
1390,
63,
1745,
63,
344,
12,
3522,
63,
890,
430,
953,
4730,
275,
291,
14,
3937,
63,
475,
63,
807,
8,
18174,
9,
288,
340,
440,
4730,
26,
355,
372,
378,
953,
1748,
63,
1745,
63,
344,
275,
4730,
1988,
17,
7541,
1745,
63,
7128,
937,
953,
1566,
63,
1733,
63,
3838,
275,
942,
288,
367,
1962,
315,
4730,
26,
355,
862,
26,
490,
1566,
63,
344,
275,
1962,
905,
1430,
63,
344,
937,
490,
14726,
63,
344,
275,
1962,
905,
11245,
63,
344,
937,
490,
30527,
275,
1962,
905,
466,
937,
490,
862,
26,
717,
1564,
275,
2022,
14,
3640,
8,
1143,
905,
1317,
3135,
490,
871,
26,
717,
1980,
4951,
340,
30527,
508,
298,
77,
14,
11245,
14,
1188,
582,
717,
790,
275,
298,
1317,
14,
2030,
2,
717,
574,
275,
1564,
905,
2030,
937,
490,
916,
30527,
508,
298,
77,
14,
11245,
14,
5746,
582,
717,
790,
275,
298,
1317,
14,
5746,
2,
717,
574,
275,
1564,
905,
5746,
937,
490,
916,
30527,
508,
298,
77,
14,
11245,
14,
354,
582,
717,
790,
275,
298,
1317,
14,
354,
2,
717,
574,
275,
1564,
905,
354,
937,
355,
871,
334,
10230,
12,
4281,
304,
490,
327,
982,
314,
1566,
365,
4124,
282,
5784,
901,
2066,
490,
327,
3372,
1806,
652,
14,
490,
1980,
2234,
340,
440,
1228,
8,
585,
12,
7116,
304,
490,
327,
982,
314,
1566,
2396,
12,
536,
503,
7482,
5712,
1133,
282,
1059,
490,
327,
2066,
3372,
1806,
652,
490,
1980,
2234,
1566,
63,
1733,
63,
3838,
14,
740,
1332,
1430,
63,
344,
12,
14726,
63,
344,
12,
790,
12,
574,
430,
953,
340,
1228,
8,
277,
14,
4659,
63,
3908,
12,
7711,
7266,
8524,
304,
355,
3875,
275,
334,
490,
298,
10258,
12872,
1566,
63,
1733,
334,
1430,
63,
344,
12,
14726,
63,
344,
12,
790,
12,
5477,
2924,
490,
298,
13992,
7558,
12,
22556,
22556,
475,
63,
1086,
4106,
360,
17872,
297,
5805,
430,
2,
355,
776,
288,
916,
1228,
8,
277,
14,
4659,
63,
3908,
12,
428,
29498,
19,
8524,
304,
355,
3875,
275,
334,
490,
298,
10258,
12872,
1566,
63,
1733,
334,
1430,
63,
344,
12,
14726,
63,
344,
12,
790,
12,
574,
2924,
490,
298,
13992,
7558,
12,
22556,
22556,
31,
2924,
355,
776,
288,
587,
26,
355,
327,
961,
1077,
506,
625,
15837,
14,
355,
746,
2186,
480
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
1898,
6900,
12,
7800,
3232,
21667,
12126,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
504,
7390,
14,
4901,
492,
10133,
199,
199,
504,
1275,
7451,
63,
7618,
492,
10257,
3928,
4152,
5502,
199,
504,
9560,
19111,
14,
1246,
14,
2550,
492,
29988,
19111,
547,
199,
504,
9560,
19111,
14,
3494,
14,
30378,
492,
7711,
7266,
8524,
12,
428,
29498,
19,
8524,
199,
199,
646,
2050,
199,
646,
295,
199,
646,
399,
1001,
465,
2022,
421,
199,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
8730,
5502,
8,
14148,
4152,
5502,
304,
339,
6461,
63,
15962,
63,
10383,
63,
2339,
275,
298,
1430,
63,
1733,
2,
272,
6461,
63,
15962,
63,
12125,
63,
10383,
63,
2339,
275,
298,
1430,
63,
1733,
63,
1648,
2,
272,
6461,
63,
15962,
63,
4701,
63,
39,
6225,
63,
4030,
39,
3830,
63,
2339,
275,
298,
1430,
63,
1733,
63,
10675,
63,
71,
631,
2,
339,
347,
636,
826,
721,
277,
12,
17446,
304,
267,
1613,
8,
5278,
5502,
12,
291,
2843,
826,
721,
4213,
9,
267,
291,
14,
2683,
63,
7451,
63,
873,
63,
2232,
8,
288,
291,
14,
8193,
63,
15962,
63,
10383,
63,
2339,
12,
291,
423,
7451,
63,
21764,
63,
1733,
267,
776,
267,
291,
14,
2683,
63,
7451,
63,
873,
63,
2232,
8,
288,
291,
14,
8193,
63,
15962,
63,
12125,
63,
10383,
63,
2339,
12,
288,
291,
423,
7451,
63,
21764,
63,
1733,
63,
1648,
267,
776,
267,
291,
14,
2683,
63,
7451,
63,
873,
63,
2232,
8,
288,
291,
14,
8193,
63,
15962,
63,
4701,
63,
39,
6225,
63,
4030,
39,
3830,
63,
2339,
12,
288,
291,
423,
7451,
63,
21764,
63,
71,
631,
63,
1733,
267,
776,
339,
768,
11610,
14,
24813,
272,
347,
485,
7451,
63,
21764,
63,
1733,
8,
277,
12,
6696,
12,
3522,
63,
890,
304,
267,
1347,
63,
827,
63,
1745,
63,
344,
275,
6696,
905,
1375,
63,
827,
63,
1745,
63,
344,
63,
26062,
937,
267,
1390,
63,
1745,
63,
344,
275,
6696,
905,
988,
63,
1745,
63,
344,
63,
12730,
937,
267,
4730,
63,
28565,
275,
6696,
14,
362,
480,
3838,
63,
28565,
401,
378,
9,
398,
22542,
63,
1981,
22759,
63,
4305,
275,
5198,
267,
32317,
275,
2097,
77,
14,
11245,
14,
354,
401,
298,
77,
14,
11245,
14,
1188,
401,
298,
77,
14,
11245,
14,
5746,
937,
398,
347,
295,
1080,
63,
1733,
63,
18174,
8,
18174,
304,
288,
3875,
275,
334,
355,
298,
4859,
2547,
63,
7128,
12,
1566,
63,
344,
12,
14726,
63,
344,
12,
730,
12,
1564,
4442,
4474,
2,
355,
298,
6038,
5805,
2695,
2547,
63,
7128,
2401,
2547,
63,
7128,
665,
5805,
2,
355,
298,
2401,
4366,
83,
2924,
355,
298,
16044,
6515,
2547,
63,
7128,
23915,
2,
355,
298,
5138,
5805,
2,
288,
776,
450,
1689,
1549,
3680,
904,
480,
466,
275,
1543,
83,
4065,
450,
334,
84,
4258,
367,
307,
315,
32317,
16945,
953,
23883,
14,
2526,
8,
3009,
12,
334,
1375,
63,
827,
63,
1745,
63,
344,
12,
1390,
63,
1745,
63,
344,
12,
3522,
63,
890,
430,
953,
4730,
275,
291,
14,
3937,
63,
475,
63,
807,
8,
18174,
9,
288,
340,
440,
4730,
26,
355,
372,
378,
953,
1748,
63,
1745,
63,
344,
275,
4730,
1988,
17,
7541,
1745,
63,
7128,
937,
953,
1566,
63,
1733,
63,
3838,
275,
942,
288,
367,
1962,
315,
4730,
26,
355,
862,
26,
490,
1566,
63,
344,
275,
1962,
905,
1430,
63,
344,
937,
490,
14726,
63,
344,
275,
1962,
905,
11245,
63,
344,
937,
490,
30527,
275,
1962,
905,
466,
937,
490,
862,
26,
717,
1564,
275,
2022,
14,
3640,
8,
1143,
905,
1317,
3135,
490,
871,
26,
717,
1980,
4951,
340,
30527,
508,
298,
77,
14,
11245,
14,
1188,
582,
717,
790,
275,
298,
1317,
14,
2030,
2,
717,
574,
275,
1564,
905,
2030,
937,
490,
916,
30527,
508,
298,
77,
14,
11245,
14,
5746,
582,
717,
790,
275,
298,
1317,
14,
5746,
2,
717,
574,
275,
1564,
905,
5746,
937,
490,
916,
30527,
508,
298,
77,
14,
11245,
14,
354,
582,
717,
790,
275,
298,
1317,
14,
354,
2,
717,
574,
275,
1564,
905,
354,
937,
355,
871,
334,
10230,
12,
4281,
304,
490,
327,
982,
314,
1566,
365,
4124,
282,
5784,
901,
2066,
490,
327,
3372,
1806,
652,
14,
490,
1980,
2234,
340,
440,
1228,
8,
585,
12,
7116,
304,
490,
327,
982,
314,
1566,
2396,
12,
536,
503,
7482,
5712,
1133,
282,
1059,
490,
327,
2066,
3372,
1806,
652,
490,
1980,
2234,
1566,
63,
1733,
63,
3838,
14,
740,
1332,
1430,
63,
344,
12,
14726,
63,
344,
12,
790,
12,
574,
430,
953,
340,
1228,
8,
277,
14,
4659,
63,
3908,
12,
7711,
7266,
8524,
304,
355,
3875,
275,
334,
490,
298,
10258,
12872,
1566,
63,
1733,
334,
1430,
63,
344,
12,
14726,
63,
344,
12,
790,
12,
5477,
2924,
490,
298,
13992,
7558,
12,
22556,
22556,
475,
63,
1086,
4106,
360,
17872,
297,
5805,
430,
2,
355,
776,
288,
916,
1228,
8,
277,
14,
4659,
63,
3908,
12,
428,
29498,
19,
8524,
304,
355,
3875,
275,
334,
490,
298,
10258,
12872,
1566,
63,
1733,
334,
1430,
63,
344,
12,
14726,
63,
344,
12,
790,
12,
574,
2924,
490,
298,
13992,
7558,
12,
22556,
22556,
31,
2924,
355,
776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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
us-ignite/us_ignite
|
us_ignite/visualize/views.py
|
1
|
4853
|
from collections import Counter
from itertools import chain, combinations
from django.conf import settings
from django.core.urlresolvers import reverse
from django.utils.http import urlquote
from django.template.response import TemplateResponse
from us_ignite.apps.models import Application, Domain
from us_ignite.actionclusters.models import ActionCluster, Domain as ACDomain
from us_ignite.common.response import json_response
def _get_domain(label):
domain = Domain.objects.get(name__exact=label)
return domain.slug
def _get_ac_domain(label):
domain = ACDomain.objects.get(name__exact=label)
return domain.slug
URLS = {
'app_stage': ('app_list_stage', Application.get_stage_id),
'app_domain': ('app_list_domain', _get_domain),
'ac_stage': ('actioncluster_list_stage', ActionCluster.get_stage_id),
'ac_domain': ('actioncluster_list_domain', _get_ac_domain)
}
def _get_search_url(name, label):
if name in URLS:
slug, function = URLS[name]
args = [function(label)] if function else []
path = reverse(slug, args=args)
else:
path = '%s?q=%s' % (reverse('search'), urlquote(label))
return u'%s%s' % (settings.SITE_URL, path)
def get_chart_data(counter, name):
chart_data = []
for i, (key, value) in enumerate(counter.items()):
chart_data.append({
'label': key,
'value': value,
'id': '%s-%s' % (name, i),
'url': _get_search_url(name, key),
})
return chart_data
def get_app_stats(display = 0):
if display == 0:
app_list = Application.objects.select_related('app_domain').all()
else:
app_list = Application.objects.select_related('app_domain').filter(status=display)
domain_list = []
stage_list = []
feature_list = []
for app in app_list:
if app.domain:
domain_list.append(app.domain.name)
stage_list.append(app.get_stage_display())
feature_list += [f.name for f in app.features.all()]
stats = {
'total': len(app_list),
'domain': get_chart_data(Counter(domain_list), 'app_domain'),
'stage': get_chart_data(Counter(stage_list), 'app_stage'),
'feature': get_chart_data(Counter(feature_list), 'feature'),
}
return stats
def get_actioncluster_stats(display = 0):
if display == 0:
ac_list = ActionCluster.objects.select_related('ac_domain').all()
else:
ac_list = ActionCluster.objects.select_related('ac_domain').filter(status=display)
domain_list = []
stage_list = []
feature_list = []
for ac in ac_list:
if ac.domain:
domain_list.append(ac.domain.name)
stage_list.append(ac.get_stage_display())
feature_list += [f.name for f in ac.features.all()]
stats = {
'total': len(ac_list),
'domain': get_chart_data(Counter(domain_list), 'ac_domain'),
'stage': get_chart_data(Counter(stage_list), 'ac_stage'),
'feature': get_chart_data(Counter(feature_list), 'feature'),
}
return stats
def get_hub_stats():
stats = {}
return stats
def visual_list(request):
context = {
'apps': get_app_stats(1),
'hubs': get_hub_stats(),
}
return TemplateResponse(request, 'visualize/object_list.html', context)
def visual_json(request):
def in_dictlist((key, value), my_dictlist):
for this in my_dictlist:
if this[key] == value:
return this
return {}
apps = get_app_stats(1)
acs = get_actioncluster_stats(1)
stages = list(chain(apps.get('stage'), acs.get('stage')))
domains = list(chain(apps.get('domain'), acs.get('domain')))
features = list(chain(apps.get('feature'), acs.get('feature')))
new_stages = []
new_domains = []
new_features = []
stage_label = []
for stage in stages:
if stage['label'] not in stage_label:
stage_label.append(stage['label'])
domain_label = []
for domain in domains:
if domain['label'] not in domain_label:
domain_label.append(domain['label'])
feature_label = []
for feature in features:
if feature['label'] not in feature_label:
feature_label.append(feature['label'])
for label in stage_label:
new_stages.append(in_dictlist(('label', label), stages))
for label in domain_label:
new_domains.append(in_dictlist(('label', label), domains))
for label in feature_label:
new_features.append(in_dictlist(('label', label), features))
get_status = {
'domain': new_domains,
'total': apps.get('total') + acs.get('total'),
'feature': new_features,
'stage': new_stages
}
context = {
'apps': get_status
}
return json_response(context, callback='chart.render')
|
bsd-3-clause
|
[
504,
5055,
492,
14427,
199,
504,
7975,
492,
6036,
12,
15821,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
504,
1639,
14,
1208,
14,
1014,
492,
1166,
3513,
199,
504,
1639,
14,
1160,
14,
1310,
492,
29264,
199,
199,
504,
2739,
63,
1030,
1175,
14,
5181,
14,
992,
492,
13515,
12,
14061,
199,
504,
2739,
63,
1030,
1175,
14,
1287,
9170,
14,
992,
492,
10033,
9581,
12,
14061,
465,
6570,
7705,
199,
504,
2739,
63,
1030,
1175,
14,
2330,
14,
1310,
492,
2022,
63,
1310,
421,
199,
318,
485,
362,
63,
2261,
8,
1302,
304,
272,
2881,
275,
14061,
14,
1462,
14,
362,
8,
354,
363,
7327,
29,
1302,
9,
272,
372,
2881,
14,
5464,
199,
199,
318,
485,
362,
63,
645,
63,
2261,
8,
1302,
304,
272,
2881,
275,
6570,
7705,
14,
1462,
14,
362,
8,
354,
363,
7327,
29,
1302,
9,
272,
372,
2881,
14,
5464,
199,
199,
31582,
275,
469,
272,
283,
571,
63,
8614,
356,
661,
571,
63,
513,
63,
8614,
297,
13515,
14,
362,
63,
8614,
63,
344,
395,
272,
283,
571,
63,
2261,
356,
661,
571,
63,
513,
63,
2261,
297,
485,
362,
63,
2261,
395,
272,
283,
645,
63,
8614,
356,
661,
1287,
4201,
63,
513,
63,
8614,
297,
10033,
9581,
14,
362,
63,
8614,
63,
344,
395,
272,
283,
645,
63,
2261,
356,
661,
1287,
4201,
63,
513,
63,
2261,
297,
485,
362,
63,
645,
63,
2261,
9,
199,
93,
421,
199,
318,
485,
362,
63,
1733,
63,
633,
8,
354,
12,
1768,
304,
272,
340,
536,
315,
2851,
51,
26,
267,
8889,
12,
805,
275,
2851,
51,
59,
354,
61,
267,
1249,
275,
359,
1593,
8,
1302,
1874,
340,
805,
587,
942,
267,
931,
275,
3837,
8,
5464,
12,
1249,
29,
589,
9,
272,
587,
26,
267,
931,
275,
1543,
83,
31,
81,
2458,
83,
7,
450,
334,
4471,
360,
1733,
659,
1166,
3513,
8,
1302,
430,
272,
372,
399,
5956,
83,
5,
83,
7,
450,
334,
1751,
14,
7917,
63,
2632,
12,
931,
9,
421,
199,
318,
664,
63,
9019,
63,
576,
8,
5337,
12,
536,
304,
272,
10943,
63,
576,
275,
942,
272,
367,
284,
12,
334,
498,
12,
574,
9,
315,
3874,
8,
5337,
14,
1744,
5109,
267,
10943,
63,
576,
14,
740,
2561,
288,
283,
1302,
356,
790,
12,
288,
283,
585,
356,
574,
12,
288,
283,
344,
356,
1543,
83,
3295,
83,
7,
450,
334,
354,
12,
284,
395,
288,
283,
633,
356,
485,
362,
63,
1733,
63,
633,
8,
354,
12,
790,
395,
267,
3828,
272,
372,
10943,
63,
576,
421,
199,
318,
664,
63,
571,
63,
3200,
8,
2918,
275,
378,
304,
272,
340,
2929,
508,
378,
26,
267,
1145,
63,
513,
275,
13515,
14,
1462,
14,
2416,
63,
2407,
360,
571,
63,
2261,
1959,
452,
342,
272,
587,
26,
267,
1145,
63,
513,
275,
13515,
14,
1462,
14,
2416,
63,
2407,
360,
571,
63,
2261,
1959,
1541,
8,
1205,
29,
2918,
9,
272,
2881,
63,
513,
275,
942,
272,
9546,
63,
513,
275,
942,
272,
3878,
63,
513,
275,
942,
272,
367,
1145,
315,
1145,
63,
513,
26,
267,
340,
1145,
14,
2261,
26,
288,
2881,
63,
513,
14,
740,
8,
571,
14,
2261,
14,
354,
9,
267,
9546,
63,
513,
14,
740,
8,
571,
14,
362,
63,
8614,
63,
2918,
1012,
267,
3878,
63,
513,
847,
359,
70,
14,
354,
367,
289,
315,
1145,
14,
3179,
14,
452,
5106,
272,
5020,
275,
469,
267,
283,
2923,
356,
822,
8,
571,
63,
513,
395,
267,
283,
2261,
356,
664,
63,
9019,
63,
576,
8,
11348,
8,
2261,
63,
513,
395,
283,
571,
63,
2261,
659,
267,
283,
8614,
356,
664,
63,
9019,
63,
576,
8,
11348,
8,
8614,
63,
513,
395,
283,
571,
63,
8614,
659,
267,
283,
4445,
356,
664,
63,
9019,
63,
576,
8,
11348,
8,
4445,
63,
513,
395,
283,
4445,
659,
272,
789,
272,
372,
5020,
199,
199,
318,
664,
63,
1287,
4201,
63,
3200,
8,
2918,
275,
378,
304,
272,
340,
2929,
508,
378,
26,
267,
1066,
63,
513,
275,
10033,
9581,
14,
1462,
14,
2416,
63,
2407,
360,
645,
63,
2261,
1959,
452,
342,
272,
587,
26,
267,
1066,
63,
513,
275,
10033,
9581,
14,
1462,
14,
2416,
63,
2407,
360,
645,
63,
2261,
1959,
1541,
8,
1205,
29,
2918,
9,
272,
2881,
63,
513,
275,
942,
272,
9546,
63,
513,
275,
942,
272,
3878,
63,
513,
275,
942,
272,
367,
1066,
315,
1066,
63,
513,
26,
267,
340,
1066,
14,
2261,
26,
288,
2881,
63,
513,
14,
740,
8,
645,
14,
2261,
14,
354,
9,
267,
9546,
63,
513,
14,
740,
8,
645,
14,
362,
63,
8614,
63,
2918,
1012,
267,
3878,
63,
513,
847,
359,
70,
14,
354,
367,
289,
315,
1066,
14,
3179,
14,
452,
5106,
272,
5020,
275,
469,
267,
283,
2923,
356,
822,
8,
645,
63,
513,
395,
267,
283,
2261,
356,
664,
63,
9019,
63,
576,
8,
11348,
8,
2261,
63,
513,
395,
283,
645,
63,
2261,
659,
267,
283,
8614,
356,
664,
63,
9019,
63,
576,
8,
11348,
8,
8614,
63,
513,
395,
283,
645,
63,
8614,
659,
267,
283,
4445,
356,
664,
63,
9019,
63,
576,
8,
11348,
8,
4445,
63,
513,
395,
283,
4445,
659,
272,
789,
272,
372,
5020,
199,
199,
318,
664,
63,
16560,
63,
3200,
837,
272,
5020,
275,
1052,
272,
372,
5020,
421,
199,
318,
13104,
63,
513,
8,
1069,
304,
272,
1067,
275,
469,
267,
283,
5181,
356,
664,
63,
571,
63,
3200,
8,
17,
395,
267,
283,
16560,
83,
356,
664,
63,
16560,
63,
3200,
1062,
272,
789,
272,
372,
29264,
8,
1069,
12,
283,
16948,
794,
15,
785,
63,
513,
14,
1360,
297,
1067,
9,
421,
199,
318,
13104,
63,
1001,
8,
1069,
304,
272,
347,
315,
63,
807,
513,
1332,
498,
12,
574,
395,
3002,
63,
807,
513,
304,
267,
367,
642,
315,
3002,
63,
807,
513,
26,
288,
340,
642,
59,
498,
61,
508,
574,
26,
355,
372,
642,
267,
372,
1052,
339,
8686,
275,
664,
63,
571,
63,
3200,
8,
17,
9,
272,
29592,
275,
664,
63,
1287,
4201,
63,
3200,
8
] |
[
5055,
492,
14427,
199,
504,
7975,
492,
6036,
12,
15821,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
504,
1639,
14,
1208,
14,
1014,
492,
1166,
3513,
199,
504,
1639,
14,
1160,
14,
1310,
492,
29264,
199,
199,
504,
2739,
63,
1030,
1175,
14,
5181,
14,
992,
492,
13515,
12,
14061,
199,
504,
2739,
63,
1030,
1175,
14,
1287,
9170,
14,
992,
492,
10033,
9581,
12,
14061,
465,
6570,
7705,
199,
504,
2739,
63,
1030,
1175,
14,
2330,
14,
1310,
492,
2022,
63,
1310,
421,
199,
318,
485,
362,
63,
2261,
8,
1302,
304,
272,
2881,
275,
14061,
14,
1462,
14,
362,
8,
354,
363,
7327,
29,
1302,
9,
272,
372,
2881,
14,
5464,
199,
199,
318,
485,
362,
63,
645,
63,
2261,
8,
1302,
304,
272,
2881,
275,
6570,
7705,
14,
1462,
14,
362,
8,
354,
363,
7327,
29,
1302,
9,
272,
372,
2881,
14,
5464,
199,
199,
31582,
275,
469,
272,
283,
571,
63,
8614,
356,
661,
571,
63,
513,
63,
8614,
297,
13515,
14,
362,
63,
8614,
63,
344,
395,
272,
283,
571,
63,
2261,
356,
661,
571,
63,
513,
63,
2261,
297,
485,
362,
63,
2261,
395,
272,
283,
645,
63,
8614,
356,
661,
1287,
4201,
63,
513,
63,
8614,
297,
10033,
9581,
14,
362,
63,
8614,
63,
344,
395,
272,
283,
645,
63,
2261,
356,
661,
1287,
4201,
63,
513,
63,
2261,
297,
485,
362,
63,
645,
63,
2261,
9,
199,
93,
421,
199,
318,
485,
362,
63,
1733,
63,
633,
8,
354,
12,
1768,
304,
272,
340,
536,
315,
2851,
51,
26,
267,
8889,
12,
805,
275,
2851,
51,
59,
354,
61,
267,
1249,
275,
359,
1593,
8,
1302,
1874,
340,
805,
587,
942,
267,
931,
275,
3837,
8,
5464,
12,
1249,
29,
589,
9,
272,
587,
26,
267,
931,
275,
1543,
83,
31,
81,
2458,
83,
7,
450,
334,
4471,
360,
1733,
659,
1166,
3513,
8,
1302,
430,
272,
372,
399,
5956,
83,
5,
83,
7,
450,
334,
1751,
14,
7917,
63,
2632,
12,
931,
9,
421,
199,
318,
664,
63,
9019,
63,
576,
8,
5337,
12,
536,
304,
272,
10943,
63,
576,
275,
942,
272,
367,
284,
12,
334,
498,
12,
574,
9,
315,
3874,
8,
5337,
14,
1744,
5109,
267,
10943,
63,
576,
14,
740,
2561,
288,
283,
1302,
356,
790,
12,
288,
283,
585,
356,
574,
12,
288,
283,
344,
356,
1543,
83,
3295,
83,
7,
450,
334,
354,
12,
284,
395,
288,
283,
633,
356,
485,
362,
63,
1733,
63,
633,
8,
354,
12,
790,
395,
267,
3828,
272,
372,
10943,
63,
576,
421,
199,
318,
664,
63,
571,
63,
3200,
8,
2918,
275,
378,
304,
272,
340,
2929,
508,
378,
26,
267,
1145,
63,
513,
275,
13515,
14,
1462,
14,
2416,
63,
2407,
360,
571,
63,
2261,
1959,
452,
342,
272,
587,
26,
267,
1145,
63,
513,
275,
13515,
14,
1462,
14,
2416,
63,
2407,
360,
571,
63,
2261,
1959,
1541,
8,
1205,
29,
2918,
9,
272,
2881,
63,
513,
275,
942,
272,
9546,
63,
513,
275,
942,
272,
3878,
63,
513,
275,
942,
272,
367,
1145,
315,
1145,
63,
513,
26,
267,
340,
1145,
14,
2261,
26,
288,
2881,
63,
513,
14,
740,
8,
571,
14,
2261,
14,
354,
9,
267,
9546,
63,
513,
14,
740,
8,
571,
14,
362,
63,
8614,
63,
2918,
1012,
267,
3878,
63,
513,
847,
359,
70,
14,
354,
367,
289,
315,
1145,
14,
3179,
14,
452,
5106,
272,
5020,
275,
469,
267,
283,
2923,
356,
822,
8,
571,
63,
513,
395,
267,
283,
2261,
356,
664,
63,
9019,
63,
576,
8,
11348,
8,
2261,
63,
513,
395,
283,
571,
63,
2261,
659,
267,
283,
8614,
356,
664,
63,
9019,
63,
576,
8,
11348,
8,
8614,
63,
513,
395,
283,
571,
63,
8614,
659,
267,
283,
4445,
356,
664,
63,
9019,
63,
576,
8,
11348,
8,
4445,
63,
513,
395,
283,
4445,
659,
272,
789,
272,
372,
5020,
199,
199,
318,
664,
63,
1287,
4201,
63,
3200,
8,
2918,
275,
378,
304,
272,
340,
2929,
508,
378,
26,
267,
1066,
63,
513,
275,
10033,
9581,
14,
1462,
14,
2416,
63,
2407,
360,
645,
63,
2261,
1959,
452,
342,
272,
587,
26,
267,
1066,
63,
513,
275,
10033,
9581,
14,
1462,
14,
2416,
63,
2407,
360,
645,
63,
2261,
1959,
1541,
8,
1205,
29,
2918,
9,
272,
2881,
63,
513,
275,
942,
272,
9546,
63,
513,
275,
942,
272,
3878,
63,
513,
275,
942,
272,
367,
1066,
315,
1066,
63,
513,
26,
267,
340,
1066,
14,
2261,
26,
288,
2881,
63,
513,
14,
740,
8,
645,
14,
2261,
14,
354,
9,
267,
9546,
63,
513,
14,
740,
8,
645,
14,
362,
63,
8614,
63,
2918,
1012,
267,
3878,
63,
513,
847,
359,
70,
14,
354,
367,
289,
315,
1066,
14,
3179,
14,
452,
5106,
272,
5020,
275,
469,
267,
283,
2923,
356,
822,
8,
645,
63,
513,
395,
267,
283,
2261,
356,
664,
63,
9019,
63,
576,
8,
11348,
8,
2261,
63,
513,
395,
283,
645,
63,
2261,
659,
267,
283,
8614,
356,
664,
63,
9019,
63,
576,
8,
11348,
8,
8614,
63,
513,
395,
283,
645,
63,
8614,
659,
267,
283,
4445,
356,
664,
63,
9019,
63,
576,
8,
11348,
8,
4445,
63,
513,
395,
283,
4445,
659,
272,
789,
272,
372,
5020,
199,
199,
318,
664,
63,
16560,
63,
3200,
837,
272,
5020,
275,
1052,
272,
372,
5020,
421,
199,
318,
13104,
63,
513,
8,
1069,
304,
272,
1067,
275,
469,
267,
283,
5181,
356,
664,
63,
571,
63,
3200,
8,
17,
395,
267,
283,
16560,
83,
356,
664,
63,
16560,
63,
3200,
1062,
272,
789,
272,
372,
29264,
8,
1069,
12,
283,
16948,
794,
15,
785,
63,
513,
14,
1360,
297,
1067,
9,
421,
199,
318,
13104,
63,
1001,
8,
1069,
304,
272,
347,
315,
63,
807,
513,
1332,
498,
12,
574,
395,
3002,
63,
807,
513,
304,
267,
367,
642,
315,
3002,
63,
807,
513,
26,
288,
340,
642,
59,
498,
61,
508,
574,
26,
355,
372,
642,
267,
372,
1052,
339,
8686,
275,
664,
63,
571,
63,
3200,
8,
17,
9,
272,
29592,
275,
664,
63,
1287,
4201,
63,
3200,
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,
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
] |
gajim/gajim
|
setup.py
|
1
|
6382
|
#!/usr/bin/env python3
import os
import sys
if sys.version_info < (3, 7):
sys.exit('Gajim needs Python 3.7+')
from setuptools import setup, find_packages
from setuptools import Command
from setuptools.command.build_py import build_py as _build
from setuptools.command.install import install as _install
from distutils import log
from distutils.util import newer
from pathlib import Path
pos = Path('po').glob('*.po')
ALL_LINGUAS = sorted([x.stem for x in pos])
MAN_FILES = ['gajim.1', 'gajim-history-manager.1', 'gajim-remote.1']
META_FILES = [('data/org.gajim.Gajim.desktop', 'share/applications', '--desktop'),
('data/org.gajim.Gajim.appdata.xml', 'share/metainfo', '--xml')]
cwd = Path(__file__).resolve().parent
build_dir = cwd / 'build'
def update_trans():
'''
Update translation files
'''
template = Path('po') / 'gajim.pot'
files = list(Path('gajim').rglob('*.py'))
files.extend(Path('gajim').rglob('*.ui'))
files.append(Path('data') / 'org.gajim.Gajim.desktop.in')
files.append(Path('data') / 'org.gajim.Gajim.appdata.xml.in')
cmd = 'xgettext -c# --from-code=utf-8 --keyword=Q_ -o %s %s' % (
template, ' '.join([str(f) for f in files]))
if os.system(cmd) != 0:
msg = f'ERROR: {template} could not be created!\n'
raise SystemExit(msg)
for lang in ALL_LINGUAS:
po_file = Path('po') / (lang + '.po')
cmd = f'msgmerge -U {po_file} {template}'
if os.system(cmd) != 0:
msg = 'ERROR: Updating language translation file failed.'
ask = msg + '\n Continue updating y/n [n] '
reply = input(ask)
if reply in ['n', 'N']:
raise SystemExit(msg)
log.info('Updating %s', po_file)
def build_trans(build_cmd):
'''
Translate the language files into gajim.mo
'''
for lang in ALL_LINGUAS:
po_file = Path('po') / (lang + '.po')
mo_file = build_dir / 'mo' / lang / 'LC_MESSAGES' / 'gajim.mo'
mo_dir = mo_file.parent
if not (mo_dir.is_dir() or mo_dir.is_symlink()):
mo_dir.mkdir(parents=True)
if newer(po_file, mo_file):
cmd = f'msgfmt {po_file} -o {mo_file}'
if os.system(cmd) != 0:
mo_file.unlink()
msg = 'ERROR: Building language translation files failed.'
ask = msg + '\n Continue building y/n [n] '
reply = input(ask)
if reply in ['n', 'N']:
raise SystemExit(msg)
log.info('Compiling %s >> %s', po_file, mo_file)
def install_trans(install_cmd):
data_files = install_cmd.distribution.data_files
for lang in ALL_LINGUAS:
mo_file = str(build_dir / 'mo' / lang / 'LC_MESSAGES' / 'gajim.mo')
target = f'share/locale/{lang}/LC_MESSAGES'
data_files.append((target, [mo_file]))
def build_man(build_cmd):
'''
Compress Gajim manual files
'''
newdir = build_dir / 'man'
if not (newdir.is_dir() or newdir.is_symlink()):
newdir.mkdir()
for man in MAN_FILES:
filename = Path('data') / man
man_file_gz = newdir / (man + '.gz')
if man_file_gz.exists():
if newer(filename, man_file_gz):
man_file_gz.unlink()
else:
continue
import gzip
# Binary io, so open is OK
with open(filename, 'rb') as f_in,\
gzip.open(man_file_gz, 'wb') as f_out:
f_out.writelines(f_in)
log.info('Compiling %s >> %s', filename, man_file_gz)
def install_man(install_cmd):
data_files = install_cmd.distribution.data_files
man_dir = build_dir / 'man'
target = 'share/man/man1'
for man in MAN_FILES:
man_file_gz = str(man_dir / (man + '.gz'))
data_files.append((target, [man_file_gz]))
def build_intl(build_cmd):
'''
Merge translation files into desktop and mime files
'''
base = build_dir
for filename, _, option in META_FILES:
newfile = base / filename
newdir = newfile.parent
if not(newdir.is_dir() or newdir.is_symlink()):
newdir.mkdir()
merge(Path(filename + '.in'), newfile, option)
def install_intl(install_cmd):
data_files = install_cmd.distribution.data_files
for filename, target, _ in META_FILES:
data_files.append((target, [str(build_dir / filename)]))
def merge(in_file, out_file, option, po_dir='po'):
'''
Run the msgfmt command.
'''
if in_file.exists():
cmd = (('msgfmt %(opt)s -d %(po_dir)s --template %(in_file)s '
'-o %(out_file)s') %
{'opt': option,
'po_dir': po_dir,
'in_file': in_file,
'out_file': out_file})
if os.system(cmd) != 0:
msg = ('ERROR: %s was not merged into the translation files!\n' %
out_file)
raise SystemExit(msg)
log.info('Compiling %s >> %s', in_file, out_file)
class build(_build):
def run(self):
build_trans(self)
if sys.platform != 'win32':
build_man(self)
build_intl(self)
_build.run(self)
class install(_install):
def run(self):
install_trans(self)
if sys.platform != 'win32':
install_man(self)
install_intl(self)
_install.run(self)
class update_po(Command):
description = "Update po files"
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
update_trans()
# only install subdirectories of data
data_files_app_icon = [
("share/icons/hicolor/scalable/apps",
["gajim/data/icons/hicolor/scalable/apps/org.gajim.Gajim.svg"]),
("share/icons/hicolor/scalable/apps",
["gajim/data/icons/hicolor/scalable/apps/org.gajim.Gajim-symbolic.svg"])
]
data_files = data_files_app_icon
setup(
cmdclass={
'build_py': build,
'install': install,
'update_po': update_po,
},
entry_points={
'console_scripts': [
'gajim-remote = gajim.gajim_remote:main',
],
'gui_scripts': [
'gajim = gajim.gajim:main',
'gajim-history-manager = gajim.history_manager:main',
]
},
data_files=data_files
)
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
19,
199,
199,
646,
747,
199,
646,
984,
199,
199,
692,
984,
14,
1023,
63,
815,
665,
334,
19,
12,
1520,
304,
272,
984,
14,
2224,
360,
39,
9091,
1017,
4839,
2018,
650,
14,
23,
13854,
199,
199,
504,
9116,
492,
3272,
12,
2342,
63,
5154,
199,
504,
9116,
492,
5817,
199,
504,
9116,
14,
1531,
14,
1506,
63,
647,
492,
1900,
63,
647,
465,
485,
1506,
199,
504,
9116,
14,
1531,
14,
3174,
492,
3907,
465,
485,
3174,
199,
504,
7065,
492,
943,
199,
504,
7065,
14,
1974,
492,
15666,
199,
504,
32212,
492,
6912,
199,
199,
1712,
275,
6912,
360,
555,
1959,
6463,
360,
4856,
555,
358,
199,
1761,
63,
44,
1206,
53,
1179,
275,
3355,
779,
88,
14,
18446,
367,
671,
315,
2086,
566,
199,
6588,
63,
9472,
275,
788,
5294,
74,
1017,
14,
17,
297,
283,
5294,
74,
1017,
13,
5570,
13,
2609,
14,
17,
297,
283,
5294,
74,
1017,
13,
3846,
14,
17,
418,
199,
10614,
63,
9472,
275,
4274,
576,
15,
1308,
14,
5294,
74,
1017,
14,
39,
9091,
1017,
14,
14487,
297,
283,
6251,
15,
15853,
297,
2850,
14487,
659,
1598,
661,
576,
15,
1308,
14,
5294,
74,
1017,
14,
39,
9091,
1017,
14,
571,
576,
14,
1652,
297,
283,
6251,
15,
2024,
815,
297,
2850,
1652,
5440,
199,
6525,
275,
6912,
3460,
493,
28634,
6983,
1252,
1708,
199,
1506,
63,
694,
275,
8288,
1182,
283,
1506,
7,
421,
199,
318,
1678,
63,
1515,
837,
272,
1449,
272,
6162,
7761,
1584,
272,
1449,
272,
1978,
275,
6912,
360,
555,
358,
1182,
283,
5294,
74,
1017,
14,
14173,
7,
272,
1584,
275,
769,
8,
2042,
360,
5294,
74,
1017,
1959,
82,
6463,
360,
4856,
647,
1333,
272,
1584,
14,
2880,
8,
2042,
360,
5294,
74,
1017,
1959,
82,
6463,
360,
4856,
1907,
1333,
272,
1584,
14,
740,
8,
2042,
360,
576,
358,
1182,
283,
1308,
14,
5294,
74,
1017,
14,
39,
9091,
1017,
14,
14487,
14,
262,
358,
272,
1584,
14,
740,
8,
2042,
360,
576,
358,
1182,
283,
1308,
14,
5294,
74,
1017,
14,
39,
9091,
1017,
14,
571,
576,
14,
1652,
14,
262,
358,
272,
2088,
275,
283,
88,
5152,
446,
67,
3,
1553,
504,
13,
600,
29,
1624,
13,
24,
1553,
6691,
29,
49,
63,
446,
79,
450,
83,
450,
83,
7,
450,
334,
267,
1978,
12,
283,
1987,
904,
779,
495,
8,
70,
9,
367,
289,
315,
1584,
2459,
272,
340,
747,
14,
2253,
8,
1760,
9,
1137,
378,
26,
267,
1499,
275,
289,
7,
3170,
26,
469,
1160,
93,
4293,
440,
506,
2737,
12525,
78,
7,
267,
746,
14838,
8,
1328,
9,
339,
367,
6339,
315,
11727,
63,
44,
1206,
53,
1179,
26,
267,
1115,
63,
493,
275,
6912,
360,
555,
358,
1182,
334,
4159,
435,
1987,
555,
358,
267,
2088,
275,
289,
6704,
1226,
5628,
446,
53,
469,
555,
63,
493,
93,
469,
1160,
6834,
267,
340,
747,
14,
2253,
8,
1760,
9,
1137,
378,
26,
288,
1499,
275,
283,
3170,
26,
4949,
9239,
2637,
7761,
570,
3405,
3530,
288,
7198,
275,
1499,
435,
1557,
78,
1448,
1781,
12928,
612,
15,
78,
359,
78,
61,
283,
288,
9351,
275,
1324,
8,
813,
9,
288,
340,
9351,
315,
788,
78,
297,
283,
46,
2565,
355,
746,
14838,
8,
1328,
9,
267,
943,
14,
815,
360,
24993,
450,
83,
297,
1115,
63,
493,
9,
421,
199,
318,
1900,
63,
1515,
8,
1506,
63,
1760,
304,
272,
1449,
272,
25540,
314,
2637,
1584,
1901,
486,
9091,
1017,
14,
573,
272,
1449,
272,
367,
6339,
315,
11727,
63,
44,
1206,
53,
1179,
26,
267,
1115,
63,
493,
275,
6912,
360,
555,
358,
1182,
334,
4159,
435,
1987,
555,
358,
267,
1303,
63,
493,
275,
1900,
63,
694,
1182,
283,
573,
7,
1182,
6339,
1182,
283,
7027,
63,
23229,
7,
1182,
283,
5294,
74,
1017,
14,
573,
7,
267,
1303,
63,
694,
275,
1303,
63,
493,
14,
1708,
267,
340,
440,
334,
573,
63,
694,
14,
374,
63,
694,
342,
503,
1303,
63,
694,
14,
374,
63,
13380,
5109,
288,
1303,
63,
694,
14,
8215,
8,
8859,
29,
549,
9,
398,
340,
15666,
8,
555,
63,
493,
12,
1303,
63,
493,
304,
288,
2088,
275,
289,
6704,
1226,
5045,
469,
555,
63,
493,
93,
446,
79,
469,
573,
63,
493,
6834,
288,
340,
747,
14,
2253,
8,
1760,
9,
1137,
378,
26,
355,
1303,
63,
493,
14,
7162,
342,
355,
1499,
275,
283,
3170,
26,
6516,
316,
2637,
7761,
1584,
3405,
3530,
355,
7198,
275,
1499,
435,
1557,
78,
1448,
1781,
10015,
612,
15,
78,
359,
78,
61,
283,
355,
9351,
275,
1324,
8,
813,
9,
355,
340,
9351,
315,
788,
78,
297,
283,
46,
2565,
490,
746,
14838,
8,
1328,
9,
288,
943,
14,
815,
360,
2404,
5662,
450,
83,
4331,
450,
83,
297,
1115,
63,
493,
12,
1303,
63,
493,
9,
421,
199,
318,
3907,
63,
1515,
8,
3174,
63,
1760,
304,
272,
666,
63,
1725,
275,
3907,
63,
1760,
14,
4972,
14,
576,
63,
1725,
272,
367,
6339,
315,
11727,
63,
44,
1206,
53,
1179,
26,
267,
1303,
63,
493,
275,
620,
8,
1506,
63,
694,
1182,
283,
573,
7,
1182,
6339,
1182,
283,
7027,
63,
23229,
7,
1182,
283,
5294,
74,
1017,
14,
573,
358,
267,
1347,
275,
289,
1159,
31527,
15,
5508,
5321,
4159,
5995,
7027,
63,
23229,
7,
267,
666,
63,
1725,
14,
740,
1332,
1375,
12,
359,
573,
63,
493,
2459,
421,
199,
318,
1900,
63,
1237,
8,
1506,
63,
1760,
304,
272,
1449,
272,
3599,
753,
598,
9091,
1017,
8722,
1584,
272,
1449,
272,
892,
694,
275,
1900,
63,
694,
1182,
283,
1237,
7,
272,
340,
440,
334,
1222,
694,
14,
374,
63,
694,
342,
503,
892,
694,
14,
374,
63,
13380,
5109,
267,
892,
694,
14,
8215,
342,
339,
367,
2169,
315,
26688,
63,
9472,
26,
267,
1788,
275,
6912,
360,
576,
358,
1182,
2169,
267,
2169,
63,
493,
63,
6838,
275,
892,
694,
1182,
334,
1237,
435,
1987,
6838,
358,
267,
340,
2169,
63,
493,
63,
6838,
14,
2444,
837,
288,
340,
15666,
8,
1501,
12,
2169,
63,
493,
63,
6838,
304,
355,
2169,
63,
493,
63,
6838,
14,
7162
] |
[
2647,
15,
1393,
15,
1813,
2366,
19,
199,
199,
646,
747,
199,
646,
984,
199,
199,
692,
984,
14,
1023,
63,
815,
665,
334,
19,
12,
1520,
304,
272,
984,
14,
2224,
360,
39,
9091,
1017,
4839,
2018,
650,
14,
23,
13854,
199,
199,
504,
9116,
492,
3272,
12,
2342,
63,
5154,
199,
504,
9116,
492,
5817,
199,
504,
9116,
14,
1531,
14,
1506,
63,
647,
492,
1900,
63,
647,
465,
485,
1506,
199,
504,
9116,
14,
1531,
14,
3174,
492,
3907,
465,
485,
3174,
199,
504,
7065,
492,
943,
199,
504,
7065,
14,
1974,
492,
15666,
199,
504,
32212,
492,
6912,
199,
199,
1712,
275,
6912,
360,
555,
1959,
6463,
360,
4856,
555,
358,
199,
1761,
63,
44,
1206,
53,
1179,
275,
3355,
779,
88,
14,
18446,
367,
671,
315,
2086,
566,
199,
6588,
63,
9472,
275,
788,
5294,
74,
1017,
14,
17,
297,
283,
5294,
74,
1017,
13,
5570,
13,
2609,
14,
17,
297,
283,
5294,
74,
1017,
13,
3846,
14,
17,
418,
199,
10614,
63,
9472,
275,
4274,
576,
15,
1308,
14,
5294,
74,
1017,
14,
39,
9091,
1017,
14,
14487,
297,
283,
6251,
15,
15853,
297,
2850,
14487,
659,
1598,
661,
576,
15,
1308,
14,
5294,
74,
1017,
14,
39,
9091,
1017,
14,
571,
576,
14,
1652,
297,
283,
6251,
15,
2024,
815,
297,
2850,
1652,
5440,
199,
6525,
275,
6912,
3460,
493,
28634,
6983,
1252,
1708,
199,
1506,
63,
694,
275,
8288,
1182,
283,
1506,
7,
421,
199,
318,
1678,
63,
1515,
837,
272,
1449,
272,
6162,
7761,
1584,
272,
1449,
272,
1978,
275,
6912,
360,
555,
358,
1182,
283,
5294,
74,
1017,
14,
14173,
7,
272,
1584,
275,
769,
8,
2042,
360,
5294,
74,
1017,
1959,
82,
6463,
360,
4856,
647,
1333,
272,
1584,
14,
2880,
8,
2042,
360,
5294,
74,
1017,
1959,
82,
6463,
360,
4856,
1907,
1333,
272,
1584,
14,
740,
8,
2042,
360,
576,
358,
1182,
283,
1308,
14,
5294,
74,
1017,
14,
39,
9091,
1017,
14,
14487,
14,
262,
358,
272,
1584,
14,
740,
8,
2042,
360,
576,
358,
1182,
283,
1308,
14,
5294,
74,
1017,
14,
39,
9091,
1017,
14,
571,
576,
14,
1652,
14,
262,
358,
272,
2088,
275,
283,
88,
5152,
446,
67,
3,
1553,
504,
13,
600,
29,
1624,
13,
24,
1553,
6691,
29,
49,
63,
446,
79,
450,
83,
450,
83,
7,
450,
334,
267,
1978,
12,
283,
1987,
904,
779,
495,
8,
70,
9,
367,
289,
315,
1584,
2459,
272,
340,
747,
14,
2253,
8,
1760,
9,
1137,
378,
26,
267,
1499,
275,
289,
7,
3170,
26,
469,
1160,
93,
4293,
440,
506,
2737,
12525,
78,
7,
267,
746,
14838,
8,
1328,
9,
339,
367,
6339,
315,
11727,
63,
44,
1206,
53,
1179,
26,
267,
1115,
63,
493,
275,
6912,
360,
555,
358,
1182,
334,
4159,
435,
1987,
555,
358,
267,
2088,
275,
289,
6704,
1226,
5628,
446,
53,
469,
555,
63,
493,
93,
469,
1160,
6834,
267,
340,
747,
14,
2253,
8,
1760,
9,
1137,
378,
26,
288,
1499,
275,
283,
3170,
26,
4949,
9239,
2637,
7761,
570,
3405,
3530,
288,
7198,
275,
1499,
435,
1557,
78,
1448,
1781,
12928,
612,
15,
78,
359,
78,
61,
283,
288,
9351,
275,
1324,
8,
813,
9,
288,
340,
9351,
315,
788,
78,
297,
283,
46,
2565,
355,
746,
14838,
8,
1328,
9,
267,
943,
14,
815,
360,
24993,
450,
83,
297,
1115,
63,
493,
9,
421,
199,
318,
1900,
63,
1515,
8,
1506,
63,
1760,
304,
272,
1449,
272,
25540,
314,
2637,
1584,
1901,
486,
9091,
1017,
14,
573,
272,
1449,
272,
367,
6339,
315,
11727,
63,
44,
1206,
53,
1179,
26,
267,
1115,
63,
493,
275,
6912,
360,
555,
358,
1182,
334,
4159,
435,
1987,
555,
358,
267,
1303,
63,
493,
275,
1900,
63,
694,
1182,
283,
573,
7,
1182,
6339,
1182,
283,
7027,
63,
23229,
7,
1182,
283,
5294,
74,
1017,
14,
573,
7,
267,
1303,
63,
694,
275,
1303,
63,
493,
14,
1708,
267,
340,
440,
334,
573,
63,
694,
14,
374,
63,
694,
342,
503,
1303,
63,
694,
14,
374,
63,
13380,
5109,
288,
1303,
63,
694,
14,
8215,
8,
8859,
29,
549,
9,
398,
340,
15666,
8,
555,
63,
493,
12,
1303,
63,
493,
304,
288,
2088,
275,
289,
6704,
1226,
5045,
469,
555,
63,
493,
93,
446,
79,
469,
573,
63,
493,
6834,
288,
340,
747,
14,
2253,
8,
1760,
9,
1137,
378,
26,
355,
1303,
63,
493,
14,
7162,
342,
355,
1499,
275,
283,
3170,
26,
6516,
316,
2637,
7761,
1584,
3405,
3530,
355,
7198,
275,
1499,
435,
1557,
78,
1448,
1781,
10015,
612,
15,
78,
359,
78,
61,
283,
355,
9351,
275,
1324,
8,
813,
9,
355,
340,
9351,
315,
788,
78,
297,
283,
46,
2565,
490,
746,
14838,
8,
1328,
9,
288,
943,
14,
815,
360,
2404,
5662,
450,
83,
4331,
450,
83,
297,
1115,
63,
493,
12,
1303,
63,
493,
9,
421,
199,
318,
3907,
63,
1515,
8,
3174,
63,
1760,
304,
272,
666,
63,
1725,
275,
3907,
63,
1760,
14,
4972,
14,
576,
63,
1725,
272,
367,
6339,
315,
11727,
63,
44,
1206,
53,
1179,
26,
267,
1303,
63,
493,
275,
620,
8,
1506,
63,
694,
1182,
283,
573,
7,
1182,
6339,
1182,
283,
7027,
63,
23229,
7,
1182,
283,
5294,
74,
1017,
14,
573,
358,
267,
1347,
275,
289,
1159,
31527,
15,
5508,
5321,
4159,
5995,
7027,
63,
23229,
7,
267,
666,
63,
1725,
14,
740,
1332,
1375,
12,
359,
573,
63,
493,
2459,
421,
199,
318,
1900,
63,
1237,
8,
1506,
63,
1760,
304,
272,
1449,
272,
3599,
753,
598,
9091,
1017,
8722,
1584,
272,
1449,
272,
892,
694,
275,
1900,
63,
694,
1182,
283,
1237,
7,
272,
340,
440,
334,
1222,
694,
14,
374,
63,
694,
342,
503,
892,
694,
14,
374,
63,
13380,
5109,
267,
892,
694,
14,
8215,
342,
339,
367,
2169,
315,
26688,
63,
9472,
26,
267,
1788,
275,
6912,
360,
576,
358,
1182,
2169,
267,
2169,
63,
493,
63,
6838,
275,
892,
694,
1182,
334,
1237,
435,
1987,
6838,
358,
267,
340,
2169,
63,
493,
63,
6838,
14,
2444,
837,
288,
340,
15666,
8,
1501,
12,
2169,
63,
493,
63,
6838,
304,
355,
2169,
63,
493,
63,
6838,
14,
7162,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Workday/OpenFrame
|
tools/telemetry/third_party/webpagereplay/third_party/dns/rdtypes/ANY/__init__.py
|
243
|
1191
|
# Copyright (C) 2003-2007, 2009, 2010 Nominum, Inc.
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for any purpose with or without fee is hereby granted,
# provided that the above copyright notice and this permission notice
# appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
"""Class ANY (generic) rdata type classes."""
__all__ = [
'AFSDB',
'CERT',
'CNAME',
'DLV',
'DNAME',
'DNSKEY',
'DS',
'GPOS',
'HINFO',
'HIP',
'ISDN',
'KEY',
'LOC',
'MX',
'NS',
'NSEC',
'NSEC3',
'NSEC3PARAM',
'NXT',
'PTR',
'RP',
'RRSIG',
'RT',
'SIG',
'SOA',
'SPF',
'SSHFP',
'TXT',
'X25',
]
|
bsd-3-clause
|
[
3,
1898,
334,
35,
9,
13004,
13,
9488,
12,
8937,
12,
7129,
653,
676,
262,
453,
12,
3277,
14,
199,
3,
199,
3,
8779,
370,
675,
12,
1331,
12,
2811,
12,
436,
11207,
642,
2032,
436,
2399,
199,
3,
3794,
367,
1263,
12016,
543,
503,
1928,
14751,
365,
11882,
10009,
12,
199,
3,
2741,
626,
314,
3432,
4248,
4245,
436,
642,
4983,
4245,
199,
3,
7468,
315,
1006,
6866,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
2,
2401,
4825,
4896,
2639,
8990,
51,
11727,
2990,
199,
3,
1663,
14142,
7816,
2296,
5749,
4141,
6931,
11727,
5292,
2990,
1634,
199,
3,
3169,
2401,
3092,
14,
1621,
4825,
6461,
7000,
4825,
4896,
2639,
6262,
7024,
2381,
199,
3,
1821,
8820,
12,
8703,
12,
9168,
12,
1549,
9110,
6736,
1549,
1821,
6736,
199,
3,
28752,
4118,
27362,
20668,
1206,
4442,
9102,
1634,
4815,
12,
7126,
1549,
9206,
12,
7061,
1621,
1261,
199,
3,
9612,
1634,
7066,
12,
9254,
1549,
5010,
7056,
25657,
9612,
12,
7043,
5738,
199,
3,
1634,
1549,
1621,
11287,
1663,
2334,
4815,
1549,
13873,
30340,
1634,
5749,
4141,
14,
199,
199,
624,
2543,
1821,
334,
6767,
9,
27020,
730,
3992,
1041,
199,
199,
363,
452,
363,
275,
359,
272,
283,
5699,
51,
2846,
297,
272,
283,
11163,
297,
272,
283,
35,
2339,
297,
272,
283,
8045,
54,
297,
272,
283,
36,
2339,
297,
272,
283,
12323,
3078,
297,
272,
283,
3177,
297,
272,
283,
39,
9263,
297,
272,
283,
40,
4531,
297,
272,
283,
40,
1772,
297,
272,
283,
1311,
10872,
297,
272,
283,
3078,
297,
272,
283,
5752,
297,
272,
283,
17401,
297,
272,
283,
2709,
297,
272,
283,
46,
15048,
297,
272,
283,
46,
15048,
19,
297,
272,
283,
46,
15048,
19,
7258,
297,
272,
283,
16764,
52,
297,
272,
283,
14528,
297,
272,
283,
18612,
297,
272,
283,
13381,
7864,
297,
272,
283,
11876,
297,
272,
283,
7864,
297,
272,
283,
4118,
33,
297,
272,
283,
5763,
38,
297,
272,
283,
13716,
17095,
297,
272,
283,
17715,
297,
272,
283,
56,
821,
297,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
334,
35,
9,
13004,
13,
9488,
12,
8937,
12,
7129,
653,
676,
262,
453,
12,
3277,
14,
199,
3,
199,
3,
8779,
370,
675,
12,
1331,
12,
2811,
12,
436,
11207,
642,
2032,
436,
2399,
199,
3,
3794,
367,
1263,
12016,
543,
503,
1928,
14751,
365,
11882,
10009,
12,
199,
3,
2741,
626,
314,
3432,
4248,
4245,
436,
642,
4983,
4245,
199,
3,
7468,
315,
1006,
6866,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
2,
2401,
4825,
4896,
2639,
8990,
51,
11727,
2990,
199,
3,
1663,
14142,
7816,
2296,
5749,
4141,
6931,
11727,
5292,
2990,
1634,
199,
3,
3169,
2401,
3092,
14,
1621,
4825,
6461,
7000,
4825,
4896,
2639,
6262,
7024,
2381,
199,
3,
1821,
8820,
12,
8703,
12,
9168,
12,
1549,
9110,
6736,
1549,
1821,
6736,
199,
3,
28752,
4118,
27362,
20668,
1206,
4442,
9102,
1634,
4815,
12,
7126,
1549,
9206,
12,
7061,
1621,
1261,
199,
3,
9612,
1634,
7066,
12,
9254,
1549,
5010,
7056,
25657,
9612,
12,
7043,
5738,
199,
3,
1634,
1549,
1621,
11287,
1663,
2334,
4815,
1549,
13873,
30340,
1634,
5749,
4141,
14,
199,
199,
624,
2543,
1821,
334,
6767,
9,
27020,
730,
3992,
1041,
199,
199,
363,
452,
363,
275,
359,
272,
283,
5699,
51,
2846,
297,
272,
283,
11163,
297,
272,
283,
35,
2339,
297,
272,
283,
8045,
54,
297,
272,
283,
36,
2339,
297,
272,
283,
12323,
3078,
297,
272,
283,
3177,
297,
272,
283,
39,
9263,
297,
272,
283,
40,
4531,
297,
272,
283,
40,
1772,
297,
272,
283,
1311,
10872,
297,
272,
283,
3078,
297,
272,
283,
5752,
297,
272,
283,
17401,
297,
272,
283,
2709,
297,
272,
283,
46,
15048,
297,
272,
283,
46,
15048,
19,
297,
272,
283,
46,
15048,
19,
7258,
297,
272,
283,
16764,
52,
297,
272,
283,
14528,
297,
272,
283,
18612,
297,
272,
283,
13381,
7864,
297,
272,
283,
11876,
297,
272,
283,
7864,
297,
272,
283,
4118,
33,
297,
272,
283,
5763,
38,
297,
272,
283,
13716,
17095,
297,
272,
283,
17715,
297,
272,
283,
56,
821,
297,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
HazyResearch/snorkel
|
snorkel/learning/structure/gen_learning.py
|
2
|
12973
|
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
from builtins import *
from .constants import *
from numba import jit
import numpy as np
class DependencySelector(object):
"""
Fast method for identifying dependencies among labeling functions.
"""
def __init__(self):
pass
def select(self, L, higher_order=False, propensity=False, threshold=0.05, truncation=10):
"""
Identifies a dependency structure among labeling functions for a given data set.
By default searches for correlations, i.e., the DEP_SIMILAR dependency type.
:param L: labeling function output matrix
:param higher_order: bool indicating whether to additionally search for higher order
fixing and reinforcing dependencies (DEP_FIXING and DEP_REINFORCING)
:param propensity: bool indicating whether to include LF propensity dependencies during learning
:param threshold: minimum magnitude weight a dependency must have to be returned (in log scale), also
regularization strength
:param truncation: number of iterations between truncation step for regularization
:return: collection of tuples of the format (LF 1 index, LF 2 index, dependency type),
see snorkel.learning.constants
"""
try:
L = L.todense()
except AttributeError:
pass
m, n = L.shape
# Initializes data structures
deps = set()
n_weights = 2 * n
if higher_order:
n_weights += 4 * n
if propensity:
n_weights += 1
weights = np.zeros((n_weights,))
joint = np.zeros((6,))
# joint[0] = P(Y = -1, L_j = -1)
# joint[1] = P(Y = -1, L_j = 0)
# joint[2] = P(Y = -1, L_j = 1)
# joint[3] = P(Y = 1, L_j = -1)
# joint[4] = P(Y = 1, L_j = 0)
# joint[5] = P(Y = 1, L_j = 1)
for j in range(n):
# Initializes weights
for k in range(n):
weights[k] = 1.0
for k in range(n, len(weights)):
weights[k] = 0.0
if propensity:
weights[len(weights) - 1] = 0.0
_fit_deps(m, n, j, L, weights, joint, higher_order, propensity, threshold, truncation)
for k in range(n):
if abs(weights[n + k]) > threshold:
deps.add((j, k, DEP_SIMILAR) if j < k else (k, j, DEP_SIMILAR))
if higher_order:
if abs(weights[2 * n + k]) > threshold:
deps.add((j, k, DEP_REINFORCING))
if abs(weights[3 * n + k]) > threshold:
deps.add((k, j, DEP_REINFORCING))
if abs(weights[4 * n + k]) > threshold:
deps.add((j, k, DEP_FIXING))
if abs(weights[5 * n + k]) > threshold:
deps.add((k, j, DEP_FIXING))
return deps
@jit(nopython=True, cache=True, nogil=True)
def _fit_deps(m, n, j, L, weights, joint, higher_order, propensity, regularization, truncation):
step_size = 1.0 / m
epochs = 10
l1delta = regularization * step_size * truncation
last_weight = len(weights) - 1
for t in range(epochs):
for i in range(m):
# Processes a training example
# First, computes joint and conditional distributions
joint[:] = 0, 0, 0, 0, 0, 0
for k in range(n):
if j == k:
# Accuracy
joint[0] += weights[j]
joint[5] += weights[j]
joint[2] -= weights[j]
joint[3] -= weights[j]
else:
if L[i, k] == 1:
# Accuracy
joint[0] -= weights[k]
joint[1] -= weights[k]
joint[2] -= weights[k]
joint[3] += weights[k]
joint[4] += weights[k]
joint[5] += weights[k]
# Similar
joint[2] += weights[n + k]
joint[5] += weights[n + k]
if higher_order:
# Reinforcement
joint[5] += weights[2 * n + k] + weights[3 * n + k]
joint[1] -= weights[2 * n + k]
joint[4] -= weights[2 * n + k]
# Fixing
joint[3] += weights[4 * n + k]
joint[1] -= weights[4 * n + k]
joint[4] -= weights[4 * n + k]
joint[0] += weights[5 * n + k]
elif L[i, k] == -1:
# Accuracy
joint[0] += weights[k]
joint[1] += weights[k]
joint[2] += weights[k]
joint[3] -= weights[k]
joint[4] -= weights[k]
joint[5] -= weights[k]
# Similar
joint[0] += weights[n + k]
joint[3] += weights[n + k]
if higher_order:
# Reinforcement
joint[0] += weights[2 * n + k] + weights[3 * n + k]
joint[1] -= weights[2 * n + k]
joint[4] -= weights[2 * n + k]
# Fixing
joint[2] += weights[4 * n + k]
joint[1] -= weights[4 * n + k]
joint[4] -= weights[4 * n + k]
joint[5] += weights[5 * n + k]
else:
# Similar
joint[1] += weights[n + k]
joint[4] += weights[n + k]
if higher_order:
# Reinforcement
joint[0] -= weights[3 * n + k]
joint[2] -= weights[3 * n + k]
joint[3] -= weights[3 * n + k]
joint[5] -= weights[3 * n + k]
# Fixing
joint[0] -= weights[5 * n + k]
joint[2] -= weights[5 * n + k]
joint[3] -= weights[5 * n + k]
joint[5] -= weights[5 * n + k]
if propensity:
joint[0] += weights[last_weight]
joint[2] += weights[last_weight]
joint[3] += weights[last_weight]
joint[5] += weights[last_weight]
joint = np.exp(joint)
joint /= np.sum(joint)
marginal_pos = np.sum(joint[3:6])
marginal_neg = np.sum(joint[0:3])
if L[i, j] == 1:
conditional_pos = joint[5] / (joint[2] + joint[5])
conditional_neg = joint[2] / (joint[2] + joint[5])
elif L[i, j] == -1:
conditional_pos = joint[3] / (joint[0] + joint[3])
conditional_neg = joint[0] / (joint[0] + joint[3])
else:
conditional_pos = joint[4] / (joint[1] + joint[4])
conditional_neg = joint[1] / (joint[1] + joint[4])
# Second, takes likelihood gradient step
for k in range(n):
if j == k:
# Accuracy
weights[j] -= step_size * (joint[5] + joint[0] - joint[2] - joint[3])
if L[i, j] == 1:
weights[j] += step_size * (conditional_pos - conditional_neg)
elif L[i, j] == -1:
weights[j] += step_size * (conditional_neg - conditional_pos)
else:
if L[i, k] == 1:
# Accuracy
weights[k] -= step_size * (marginal_pos - marginal_neg - conditional_pos + conditional_neg)
# Similar
weights[n + k] -= step_size * (joint[2] + joint[5])
if L[i, j] == 1:
weights[n + k] += step_size
if higher_order:
# Incoming reinforcement
weights[2 * n + k] -= step_size * (joint[5] - joint[1] - joint[4])
if L[i, j] == 1:
weights[2 * n + k] += step_size * conditional_pos
elif L[i, j] == 0:
weights[2 * n + k] += step_size * -1
# Outgoing reinforcement
weights[3 * n + k] -= step_size * joint[5]
if L[i, j] == 1:
weights[3 * n + k] += step_size * conditional_pos
# Incoming fixing
weights[4 * n + k] -= step_size * (joint[3] - joint[1] - joint[4])
if L[i, j] == -1:
weights[4 * n + k] += step_size * conditional_pos
elif L[i, j] == 0:
weights[4 * n + k] += step_size * -1
# Outgoing fixing
weights[5 * n + k] -= step_size * joint[0]
if L[i, j] == -1:
weights[5 * n + k] += step_size * conditional_neg
elif L[i, k] == -1:
# Accuracy
weights[k] -= step_size * (marginal_neg - marginal_pos - conditional_neg + conditional_pos)
# Similar
weights[n + k] -= step_size * (joint[0] + joint[3])
if L[i, j] == -1:
weights[n + k] += step_size
if higher_order:
# Incoming reinforcement
weights[2 * n + k] -= step_size * (joint[0] - joint[1] - joint[4])
if L[i, j] == -1:
weights[2 * n + k] += step_size * conditional_neg
elif L[i, j] == 0:
weights[2 * n + k] += step_size * -1
# Outgoing reinforcement
weights[3 * n + k] -= step_size * joint[0]
if L[i, j] == -1:
weights[3 * n + k] += step_size * conditional_neg
# Incoming fixing
weights[4 * n + k] -= step_size * (joint[2] - joint[1] - joint[4])
if L[i, j] == 1:
weights[4 * n + k] += step_size * conditional_neg
elif L[i, j] == 0:
weights[4 * n + k] += step_size * -1
# Outgoing fixing
weights[5 * n + k] -= step_size * joint[5]
if L[i, j] == 1:
weights[5 * n + k] += step_size * conditional_pos
else:
# Similar
weights[n + k] -= step_size * (joint[1] + joint[4])
if L[i, j] == 0:
weights[n + k] += step_size
if higher_order:
# No effect of incoming reinforcement
# Outgoing reinforcement
weights[3 * n + k] -= step_size * (-1 * joint[0] - joint[2] - joint[3] - joint[5])
if L[i, j] != 0:
weights[3 * n + k] += step_size * -1
# No effect of incoming fixing
# Outgoing fixing
weights[5 * n + k] -= step_size * (-1 * joint[0] - joint[2] - joint[3] - joint[5])
if L[i, j] != 0:
weights[5 * n + k] += step_size * -1
if propensity:
weights[last_weight] -= step_size * (joint[0] + joint[2] + joint[3] + joint[5])
if L[i, j] != 0:
weights[last_weight] += step_size
# Third, takes regularization gradient step
if (t * m + i) % truncation == 0:
for k in range(len(weights)):
weights[k] = max(0, weights[k] - l1delta) if weights[k] > 0 else min(0, weights[k] + l1delta)
|
apache-2.0
|
[
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,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
504,
12963,
492,
627,
199,
199,
504,
1275,
5559,
492,
627,
199,
504,
1967,
2470,
492,
31292,
199,
646,
2680,
465,
980,
421,
199,
533,
22922,
11212,
8,
785,
304,
272,
408,
272,
22613,
1083,
367,
21119,
5124,
16885,
1768,
316,
3423,
14,
272,
408,
272,
347,
636,
826,
721,
277,
304,
267,
986,
339,
347,
3504,
8,
277,
12,
491,
12,
10948,
63,
1648,
29,
797,
12,
557,
897,
3677,
29,
797,
12,
8765,
29,
16,
14,
1717,
12,
8181,
1063,
29,
709,
304,
267,
408,
267,
473,
2433,
397,
282,
5936,
5523,
16885,
1768,
316,
3423,
367,
282,
1627,
666,
663,
14,
398,
4885,
849,
21858,
367,
1970,
15741,
12,
284,
14,
69,
2020,
314,
30850,
63,
16590,
1193,
689,
5936,
730,
14,
398,
520,
635,
491,
26,
1768,
316,
805,
1072,
3634,
267,
520,
635,
10948,
63,
1648,
26,
2155,
9297,
3775,
370,
10234,
1183,
2754,
367,
10948,
1865,
2490,
5325,
316,
436,
295,
262,
509,
4477,
5124,
334,
10814,
63,
5192,
1206,
436,
30850,
63,
907,
568,
2707,
35,
1206,
9,
267,
520,
635,
557,
897,
3677,
26,
2155,
9297,
3775,
370,
2387,
491,
38,
557,
897,
3677,
5124,
5309,
9328,
267,
520,
635,
8765,
26,
7481,
22877,
5401,
282,
5936,
1471,
1172,
370,
506,
2138,
334,
262,
943,
4666,
395,
2597,
2079,
21095,
410,
15796,
267,
520,
635,
8181,
1063,
26,
1329,
402,
10615,
3382,
8181,
1063,
3650,
367,
21095,
267,
520,
1107,
26,
3245,
402,
6346,
402,
314,
1475,
334,
15965,
413,
1478,
12,
491,
38,
499,
1478,
12,
5936,
730,
395,
326,
1937,
6895,
4708,
352,
14,
10546,
14,
5559,
267,
408,
267,
862,
26,
288,
491,
275,
491,
14,
23526,
342,
267,
871,
4281,
26,
288,
986,
398,
333,
12,
302,
275,
491,
14,
1392,
398,
327,
6026,
6491,
666,
13955,
267,
10140,
275,
663,
342,
267,
302,
63,
4916,
275,
499,
627,
302,
267,
340,
10948,
63,
1648,
26,
288,
302,
63,
4916,
847,
841,
627,
302,
267,
340,
557,
897,
3677,
26,
288,
302,
63,
4916,
847,
413,
267,
4931,
275,
980,
14,
4250,
1332,
78,
63,
4916,
4641,
267,
22211,
275,
980,
14,
4250,
1332,
22,
4641,
267,
327,
22211,
59,
16,
61,
275,
510,
8,
57,
275,
446,
17,
12,
491,
63,
74,
275,
446,
17,
9,
267,
327,
22211,
59,
17,
61,
275,
510,
8,
57,
275,
446,
17,
12,
491,
63,
74,
275,
221,
378,
9,
267,
327,
22211,
59,
18,
61,
275,
510,
8,
57,
275,
446,
17,
12,
491,
63,
74,
275,
221,
413,
9,
267,
327,
22211,
59,
19,
61,
275,
510,
8,
57,
275,
221,
413,
12,
491,
63,
74,
275,
446,
17,
9,
267,
327,
22211,
59,
20,
61,
275,
510,
8,
57,
275,
221,
413,
12,
491,
63,
74,
275,
221,
378,
9,
267,
327,
22211,
59,
21,
61,
275,
510,
8,
57,
275,
221,
413,
12,
491,
63,
74,
275,
221,
413,
9,
398,
367,
1335,
315,
1425,
8,
78,
304,
288,
327,
6026,
6491,
4931,
288,
367,
1022,
315,
1425,
8,
78,
304,
355,
4931,
59,
75,
61,
275,
413,
14,
16,
288,
367,
1022,
315,
1425,
8,
78,
12,
822,
8,
4916,
2298,
355,
4931,
59,
75,
61,
275,
378,
14,
16,
288,
340,
557,
897,
3677,
26,
355,
4931,
59,
552,
8,
4916,
9,
446,
413,
61,
275,
378,
14,
16,
953,
485,
3269,
63,
5846,
8,
77,
12,
302,
12,
1335,
12,
491,
12,
4931,
12,
22211,
12,
10948,
63,
1648,
12,
557,
897,
3677,
12,
221,
8765,
12,
8181,
1063,
9,
953,
367,
1022,
315,
1425,
8,
78,
304,
355,
340,
2853,
8,
4916,
59,
78,
435,
1022,
566,
690,
8765,
26,
490,
10140,
14,
525,
1332,
74,
12,
1022,
12,
30850,
63,
16590,
1193,
689,
9,
340,
1335,
665,
1022,
587,
334,
75,
12,
1335,
12,
30850,
63,
16590,
1193,
689,
430,
355,
340,
10948,
63,
1648,
26,
490,
340,
2853,
8,
4916,
59,
18,
627,
302,
435,
1022,
566,
690,
8765,
26,
717,
10140,
14,
525,
1332,
74,
12,
1022,
12,
30850,
63,
907,
568,
2707,
35,
1206,
430,
490,
340,
2853,
8,
4916,
59,
19,
627,
302,
435,
1022,
566,
690,
8765,
26,
717,
10140,
14,
525,
1332,
75,
12,
1335,
12,
30850,
63,
907,
568,
2707,
35,
1206,
430,
490,
340,
2853,
8,
4916,
59,
20,
627,
302,
435,
1022,
566,
690,
8765,
26,
717,
10140,
14,
525,
1332,
74,
12,
1022,
12,
30850,
63,
5192,
1206,
430,
490,
340,
2853,
8,
4916,
59,
21,
627,
302,
435,
1022,
566,
690,
8765,
26,
717,
10140,
14,
525,
1332,
75,
12,
1335,
12,
30850,
63,
5192,
1206,
430,
398,
372,
10140,
421,
199,
32,
17676,
8,
78,
927,
898,
29,
549,
12,
2581,
29,
549,
12,
949,
30170,
29,
549,
9,
199,
318,
485,
3269,
63,
5846,
8,
77,
12,
302,
12,
1335,
12,
491,
12,
4931,
12,
22211,
12,
10948,
63,
1648,
12,
557,
897,
3677,
12,
21095,
12,
8181,
1063,
304,
272,
3650,
63,
890,
275,
413,
14,
16,
1182,
333,
272,
18463,
275,
1616,
272,
634,
17,
3136,
275,
21095,
627,
3650,
63,
890,
627,
8181,
1063,
272,
2061,
63,
3463,
275,
822,
8,
4916,
9,
446,
413,
339,
367,
307,
315,
1425,
8,
13161,
304,
267,
367,
284,
315,
1425,
8,
77,
304,
288,
327,
2165,
5804,
282,
6093,
2893,
953,
327,
7758,
12,
21445,
22211,
436,
12303,
10208,
288,
22211,
5873,
275,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
288,
367,
1022,
315,
1425,
8,
78,
304,
355,
340,
1335,
508,
1022,
26,
490,
327,
4473,
7933,
490,
22211,
59,
16,
61,
847,
4931,
59,
74,
61,
490,
22211,
59,
21,
61,
847,
4931,
59,
74,
61,
490,
22211,
59,
18,
61,
4862,
4931,
59,
74,
61,
490,
22211,
59,
19,
61,
4862,
4931,
59,
74,
61,
355,
587,
26,
490,
340,
491,
59,
73,
12,
1022,
61,
508,
413,
26,
717,
327,
4473,
7933,
717,
22211,
59,
16,
61,
4862,
4931
] |
[
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
504,
12963,
492,
627,
199,
199,
504,
1275,
5559,
492,
627,
199,
504,
1967,
2470,
492,
31292,
199,
646,
2680,
465,
980,
421,
199,
533,
22922,
11212,
8,
785,
304,
272,
408,
272,
22613,
1083,
367,
21119,
5124,
16885,
1768,
316,
3423,
14,
272,
408,
272,
347,
636,
826,
721,
277,
304,
267,
986,
339,
347,
3504,
8,
277,
12,
491,
12,
10948,
63,
1648,
29,
797,
12,
557,
897,
3677,
29,
797,
12,
8765,
29,
16,
14,
1717,
12,
8181,
1063,
29,
709,
304,
267,
408,
267,
473,
2433,
397,
282,
5936,
5523,
16885,
1768,
316,
3423,
367,
282,
1627,
666,
663,
14,
398,
4885,
849,
21858,
367,
1970,
15741,
12,
284,
14,
69,
2020,
314,
30850,
63,
16590,
1193,
689,
5936,
730,
14,
398,
520,
635,
491,
26,
1768,
316,
805,
1072,
3634,
267,
520,
635,
10948,
63,
1648,
26,
2155,
9297,
3775,
370,
10234,
1183,
2754,
367,
10948,
1865,
2490,
5325,
316,
436,
295,
262,
509,
4477,
5124,
334,
10814,
63,
5192,
1206,
436,
30850,
63,
907,
568,
2707,
35,
1206,
9,
267,
520,
635,
557,
897,
3677,
26,
2155,
9297,
3775,
370,
2387,
491,
38,
557,
897,
3677,
5124,
5309,
9328,
267,
520,
635,
8765,
26,
7481,
22877,
5401,
282,
5936,
1471,
1172,
370,
506,
2138,
334,
262,
943,
4666,
395,
2597,
2079,
21095,
410,
15796,
267,
520,
635,
8181,
1063,
26,
1329,
402,
10615,
3382,
8181,
1063,
3650,
367,
21095,
267,
520,
1107,
26,
3245,
402,
6346,
402,
314,
1475,
334,
15965,
413,
1478,
12,
491,
38,
499,
1478,
12,
5936,
730,
395,
326,
1937,
6895,
4708,
352,
14,
10546,
14,
5559,
267,
408,
267,
862,
26,
288,
491,
275,
491,
14,
23526,
342,
267,
871,
4281,
26,
288,
986,
398,
333,
12,
302,
275,
491,
14,
1392,
398,
327,
6026,
6491,
666,
13955,
267,
10140,
275,
663,
342,
267,
302,
63,
4916,
275,
499,
627,
302,
267,
340,
10948,
63,
1648,
26,
288,
302,
63,
4916,
847,
841,
627,
302,
267,
340,
557,
897,
3677,
26,
288,
302,
63,
4916,
847,
413,
267,
4931,
275,
980,
14,
4250,
1332,
78,
63,
4916,
4641,
267,
22211,
275,
980,
14,
4250,
1332,
22,
4641,
267,
327,
22211,
59,
16,
61,
275,
510,
8,
57,
275,
446,
17,
12,
491,
63,
74,
275,
446,
17,
9,
267,
327,
22211,
59,
17,
61,
275,
510,
8,
57,
275,
446,
17,
12,
491,
63,
74,
275,
221,
378,
9,
267,
327,
22211,
59,
18,
61,
275,
510,
8,
57,
275,
446,
17,
12,
491,
63,
74,
275,
221,
413,
9,
267,
327,
22211,
59,
19,
61,
275,
510,
8,
57,
275,
221,
413,
12,
491,
63,
74,
275,
446,
17,
9,
267,
327,
22211,
59,
20,
61,
275,
510,
8,
57,
275,
221,
413,
12,
491,
63,
74,
275,
221,
378,
9,
267,
327,
22211,
59,
21,
61,
275,
510,
8,
57,
275,
221,
413,
12,
491,
63,
74,
275,
221,
413,
9,
398,
367,
1335,
315,
1425,
8,
78,
304,
288,
327,
6026,
6491,
4931,
288,
367,
1022,
315,
1425,
8,
78,
304,
355,
4931,
59,
75,
61,
275,
413,
14,
16,
288,
367,
1022,
315,
1425,
8,
78,
12,
822,
8,
4916,
2298,
355,
4931,
59,
75,
61,
275,
378,
14,
16,
288,
340,
557,
897,
3677,
26,
355,
4931,
59,
552,
8,
4916,
9,
446,
413,
61,
275,
378,
14,
16,
953,
485,
3269,
63,
5846,
8,
77,
12,
302,
12,
1335,
12,
491,
12,
4931,
12,
22211,
12,
10948,
63,
1648,
12,
557,
897,
3677,
12,
221,
8765,
12,
8181,
1063,
9,
953,
367,
1022,
315,
1425,
8,
78,
304,
355,
340,
2853,
8,
4916,
59,
78,
435,
1022,
566,
690,
8765,
26,
490,
10140,
14,
525,
1332,
74,
12,
1022,
12,
30850,
63,
16590,
1193,
689,
9,
340,
1335,
665,
1022,
587,
334,
75,
12,
1335,
12,
30850,
63,
16590,
1193,
689,
430,
355,
340,
10948,
63,
1648,
26,
490,
340,
2853,
8,
4916,
59,
18,
627,
302,
435,
1022,
566,
690,
8765,
26,
717,
10140,
14,
525,
1332,
74,
12,
1022,
12,
30850,
63,
907,
568,
2707,
35,
1206,
430,
490,
340,
2853,
8,
4916,
59,
19,
627,
302,
435,
1022,
566,
690,
8765,
26,
717,
10140,
14,
525,
1332,
75,
12,
1335,
12,
30850,
63,
907,
568,
2707,
35,
1206,
430,
490,
340,
2853,
8,
4916,
59,
20,
627,
302,
435,
1022,
566,
690,
8765,
26,
717,
10140,
14,
525,
1332,
74,
12,
1022,
12,
30850,
63,
5192,
1206,
430,
490,
340,
2853,
8,
4916,
59,
21,
627,
302,
435,
1022,
566,
690,
8765,
26,
717,
10140,
14,
525,
1332,
75,
12,
1335,
12,
30850,
63,
5192,
1206,
430,
398,
372,
10140,
421,
199,
32,
17676,
8,
78,
927,
898,
29,
549,
12,
2581,
29,
549,
12,
949,
30170,
29,
549,
9,
199,
318,
485,
3269,
63,
5846,
8,
77,
12,
302,
12,
1335,
12,
491,
12,
4931,
12,
22211,
12,
10948,
63,
1648,
12,
557,
897,
3677,
12,
21095,
12,
8181,
1063,
304,
272,
3650,
63,
890,
275,
413,
14,
16,
1182,
333,
272,
18463,
275,
1616,
272,
634,
17,
3136,
275,
21095,
627,
3650,
63,
890,
627,
8181,
1063,
272,
2061,
63,
3463,
275,
822,
8,
4916,
9,
446,
413,
339,
367,
307,
315,
1425,
8,
13161,
304,
267,
367,
284,
315,
1425,
8,
77,
304,
288,
327,
2165,
5804,
282,
6093,
2893,
953,
327,
7758,
12,
21445,
22211,
436,
12303,
10208,
288,
22211,
5873,
275,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
288,
367,
1022,
315,
1425,
8,
78,
304,
355,
340,
1335,
508,
1022,
26,
490,
327,
4473,
7933,
490,
22211,
59,
16,
61,
847,
4931,
59,
74,
61,
490,
22211,
59,
21,
61,
847,
4931,
59,
74,
61,
490,
22211,
59,
18,
61,
4862,
4931,
59,
74,
61,
490,
22211,
59,
19,
61,
4862,
4931,
59,
74,
61,
355,
587,
26,
490,
340,
491,
59,
73,
12,
1022,
61,
508,
413,
26,
717,
327,
4473,
7933,
717,
22211,
59,
16,
61,
4862,
4931,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ruleant/weblate
|
weblate/trans/migrations/0043_auto__add_vote__add_unique_vote_suggestion_user.py
|
2
|
18461
|
# -*- coding: utf-8 -*-
#
# Copyright © 2012 - 2014 Michal Čihař <michal@cihar.com>
#
# This file is part of Weblate <http://weblate.org/>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
from south.db import db
from south.v2 import SchemaMigration
class Migration(SchemaMigration):
def forwards(self, orm):
# Adding model 'Vote'
db.create_table(u'trans_vote', (
(u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
('suggestion', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['trans.Suggestion'])),
('user', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['auth.User'])),
('positive', self.gf('django.db.models.fields.BooleanField')(default=True)),
))
db.send_create_signal('trans', ['Vote'])
# Adding unique constraint on 'Vote', fields ['suggestion', 'user']
db.create_unique(u'trans_vote', ['suggestion_id', 'user_id'])
def backwards(self, orm):
# Removing unique constraint on 'Vote', fields ['suggestion', 'user']
db.delete_unique(u'trans_vote', ['suggestion_id', 'user_id'])
# Deleting model 'Vote'
db.delete_table(u'trans_vote')
models = {
u'auth.group': {
'Meta': {'object_name': 'Group'},
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
},
u'auth.permission': {
'Meta': {'ordering': "(u'content_type__app_label', u'content_type__model', u'codename')", 'unique_together': "((u'content_type', u'codename'),)", 'object_name': 'Permission'},
'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['contenttypes.ContentType']"}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
},
u'auth.user': {
'Meta': {'object_name': 'User'},
'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
},
u'contenttypes.contenttype': {
'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
},
u'lang.language': {
'Meta': {'ordering': "['name']", 'object_name': 'Language'},
'code': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '50'}),
'direction': ('django.db.models.fields.CharField', [], {'default': "'ltr'", 'max_length': '3'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'nplurals': ('django.db.models.fields.SmallIntegerField', [], {'default': '0'}),
'plural_type': ('django.db.models.fields.IntegerField', [], {'default': '1'}),
'pluralequation': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'})
},
'trans.change': {
'Meta': {'ordering': "['-timestamp']", 'object_name': 'Change'},
'action': ('django.db.models.fields.IntegerField', [], {'default': '2'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'target': ('django.db.models.fields.TextField', [], {'default': "''", 'blank': 'True'}),
'timestamp': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'db_index': 'True', 'blank': 'True'}),
'translation': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['trans.Translation']"}),
'unit': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['trans.Unit']", 'null': 'True'}),
'user': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.User']", 'null': 'True'})
},
'trans.check': {
'Meta': {'unique_together': "(('checksum', 'project', 'language', 'check'),)", 'object_name': 'Check'},
'check': ('django.db.models.fields.CharField', [], {'max_length': '20'}),
'checksum': ('django.db.models.fields.CharField', [], {'max_length': '40', 'db_index': 'True'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'ignore': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'db_index': 'True'}),
'language': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['lang.Language']", 'null': 'True', 'blank': 'True'}),
'project': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['trans.Project']"})
},
'trans.comment': {
'Meta': {'ordering': "['timestamp']", 'object_name': 'Comment'},
'checksum': ('django.db.models.fields.CharField', [], {'max_length': '40', 'db_index': 'True'}),
'comment': ('django.db.models.fields.TextField', [], {}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'language': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['lang.Language']", 'null': 'True', 'blank': 'True'}),
'project': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['trans.Project']"}),
'timestamp': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'db_index': 'True', 'blank': 'True'}),
'user': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.User']", 'null': 'True', 'blank': 'True'})
},
'trans.dictionary': {
'Meta': {'ordering': "['source']", 'object_name': 'Dictionary'},
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'language': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['lang.Language']"}),
'project': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['trans.Project']"}),
'source': ('django.db.models.fields.CharField', [], {'max_length': '200', 'db_index': 'True'}),
'target': ('django.db.models.fields.CharField', [], {'max_length': '200'})
},
'trans.indexupdate': {
'Meta': {'object_name': 'IndexUpdate'},
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'source': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
'unit': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['trans.Unit']"})
},
'trans.project': {
'Meta': {'ordering': "['name']", 'object_name': 'Project'},
'commit_message': ('django.db.models.fields.TextField', [], {'default': "'Translated using Weblate (%(language_name)s)\\n\\nCurrently translated at %(translated_percent)s%% (%(translated)s of %(total)s strings)'"}),
'committer_email': ('django.db.models.fields.EmailField', [], {'default': "'noreply@weblate.org'", 'max_length': '75'}),
'committer_name': ('django.db.models.fields.CharField', [], {'default': "'Weblate'", 'max_length': '200'}),
'enable_acl': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'instructions': ('django.db.models.fields.URLField', [], {'max_length': '200', 'blank': 'True'}),
'license': ('django.db.models.fields.CharField', [], {'max_length': '150', 'blank': 'True'}),
'license_url': ('django.db.models.fields.URLField', [], {'max_length': '200', 'blank': 'True'}),
'mail': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
'merge_style': ('django.db.models.fields.CharField', [], {'default': "'merge'", 'max_length': '10'}),
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '100'}),
'new_lang': ('django.db.models.fields.CharField', [], {'default': "'contact'", 'max_length': '10'}),
'push_on_commit': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'set_translation_team': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
'slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '50'}),
'web': ('django.db.models.fields.URLField', [], {'max_length': '200'})
},
'trans.subproject': {
'Meta': {'ordering': "['project__name', 'name']", 'unique_together': "(('project', 'name'), ('project', 'slug'))", 'object_name': 'SubProject'},
'allow_translation_propagation': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
'branch': ('django.db.models.fields.CharField', [], {'default': "'master'", 'max_length': '50'}),
'extra_commit_file': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '200', 'blank': 'True'}),
'file_format': ('django.db.models.fields.CharField', [], {'default': "'auto'", 'max_length': '50'}),
'filemask': ('django.db.models.fields.CharField', [], {'max_length': '200'}),
'git_export': ('django.db.models.fields.CharField', [], {'max_length': '200', 'blank': 'True'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'locked': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'pre_commit_script': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '200', 'blank': 'True'}),
'project': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['trans.Project']"}),
'push': ('django.db.models.fields.CharField', [], {'max_length': '200', 'blank': 'True'}),
'repo': ('django.db.models.fields.CharField', [], {'max_length': '200'}),
'report_source_bugs': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
'repoweb': ('django.db.models.fields.URLField', [], {'max_length': '200', 'blank': 'True'}),
'save_history': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
'slug': ('django.db.models.fields.SlugField', [], {'max_length': '50'}),
'template': ('django.db.models.fields.CharField', [], {'max_length': '200', 'blank': 'True'})
},
'trans.suggestion': {
'Meta': {'object_name': 'Suggestion'},
'checksum': ('django.db.models.fields.CharField', [], {'max_length': '40', 'db_index': 'True'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'language': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['lang.Language']"}),
'project': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['trans.Project']"}),
'target': ('django.db.models.fields.TextField', [], {}),
'user': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.User']", 'null': 'True', 'blank': 'True'}),
'votes': ('django.db.models.fields.related.ManyToManyField', [], {'related_name': "'user_votes'", 'symmetrical': 'False', 'through': "orm['trans.Vote']", 'to': u"orm['auth.User']"})
},
'trans.translation': {
'Meta': {'ordering': "['language__name']", 'object_name': 'Translation'},
'enabled': ('django.db.models.fields.BooleanField', [], {'default': 'True', 'db_index': 'True'}),
'failing_checks': ('django.db.models.fields.IntegerField', [], {'default': '0', 'db_index': 'True'}),
'filename': ('django.db.models.fields.CharField', [], {'max_length': '200'}),
'fuzzy': ('django.db.models.fields.IntegerField', [], {'default': '0', 'db_index': 'True'}),
'have_suggestion': ('django.db.models.fields.IntegerField', [], {'default': '0', 'db_index': 'True'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'language': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['lang.Language']"}),
'language_code': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '20'}),
'lock_time': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'lock_user': ('django.db.models.fields.related.ForeignKey', [], {'default': 'None', 'to': u"orm['auth.User']", 'null': 'True', 'blank': 'True'}),
'revision': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '100', 'blank': 'True'}),
'subproject': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['trans.SubProject']"}),
'total': ('django.db.models.fields.IntegerField', [], {'default': '0', 'db_index': 'True'}),
'total_words': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
'translated': ('django.db.models.fields.IntegerField', [], {'default': '0', 'db_index': 'True'}),
'translated_words': ('django.db.models.fields.IntegerField', [], {'default': '0'})
},
'trans.unit': {
'Meta': {'ordering': "['position']", 'object_name': 'Unit'},
'checksum': ('django.db.models.fields.CharField', [], {'max_length': '40', 'db_index': 'True'}),
'comment': ('django.db.models.fields.TextField', [], {'default': "''", 'blank': 'True'}),
'context': ('django.db.models.fields.TextField', [], {'default': "''", 'blank': 'True'}),
'flags': ('django.db.models.fields.TextField', [], {'default': "''", 'blank': 'True'}),
'fuzzy': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'db_index': 'True'}),
'has_comment': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'db_index': 'True'}),
'has_failing_check': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'db_index': 'True'}),
'has_suggestion': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'db_index': 'True'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'location': ('django.db.models.fields.TextField', [], {'default': "''", 'blank': 'True'}),
'num_words': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
'position': ('django.db.models.fields.IntegerField', [], {'db_index': 'True'}),
'previous_source': ('django.db.models.fields.TextField', [], {'default': "''", 'blank': 'True'}),
'source': ('django.db.models.fields.TextField', [], {}),
'target': ('django.db.models.fields.TextField', [], {'default': "''", 'blank': 'True'}),
'translated': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'db_index': 'True'}),
'translation': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['trans.Translation']"})
},
'trans.vote': {
'Meta': {'unique_together': "(('suggestion', 'user'),)", 'object_name': 'Vote'},
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'positive': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
'suggestion': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['trans.Suggestion']"}),
'user': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.User']"})
}
}
complete_apps = ['trans']
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
22405,
103,
6029,
446,
6927,
603,
1158,
279,
221,
129,
235,
73,
2411,
130,
248,
665,
77,
1158,
279,
32,
559,
8210,
14,
957,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
6001,
750,
665,
1014,
921,
2520,
750,
14,
1308,
3133,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
504,
12919,
14,
697,
492,
1592,
199,
504,
12919,
14,
86,
18,
492,
24765,
421,
199,
533,
12090,
8,
24822,
304,
339,
347,
17465,
8,
277,
12,
9813,
304,
267,
327,
12934,
1402,
283,
54,
1583,
7,
267,
1592,
14,
981,
63,
1224,
8,
85,
1133,
1320,
63,
14317,
297,
334,
288,
334,
85,
7,
344,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
7533,
3327,
63,
498,
29,
549,
1826,
288,
661,
19957,
1636,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
7533,
475,
29,
1025,
459,
1515,
14,
51,
11914,
1636,
16607,
288,
661,
751,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
7533,
475,
29,
1025,
459,
1178,
14,
1899,
16607,
288,
661,
8965,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
7533,
885,
29,
549,
1826,
267,
5082,
267,
1592,
14,
2254,
63,
981,
63,
4653,
360,
1515,
297,
788,
54,
1583,
1105,
398,
327,
12934,
3747,
5828,
641,
283,
54,
1583,
297,
1504,
788,
19957,
1636,
297,
283,
751,
418,
267,
1592,
14,
981,
63,
3235,
8,
85,
1133,
1320,
63,
14317,
297,
788,
19957,
1636,
63,
344,
297,
283,
751,
63,
344,
1105,
2378,
347,
8552,
8,
277,
12,
9813,
304,
267,
327,
29343,
3747,
5828,
641,
283,
54,
1583,
297,
1504,
788,
19957,
1636,
297,
283,
751,
418,
267,
1592,
14,
1807,
63,
3235,
8,
85,
1133,
1320,
63,
14317,
297,
788,
19957,
1636,
63,
344,
297,
283,
751,
63,
344,
1105,
398,
327,
15920,
1402,
283,
54,
1583,
7,
267,
1592,
14,
1807,
63,
1224,
8,
85,
1133,
1320,
63,
14317,
358,
2378,
1709,
275,
469,
267,
399,
7,
1178,
14,
923,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
2448,
2267,
288,
399,
7,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
3235,
356,
283,
549,
297,
283,
988,
63,
1267,
356,
283,
1257,
1604,
288,
283,
6060,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
7624,
297,
990,
791,
475,
356,
399,
2,
1025,
459,
1178,
14,
7980,
6256,
283,
10247,
356,
283,
797,
297,
283,
2500,
356,
283,
549,
3071,
267,
1660,
267,
399,
7,
1178,
14,
5693,
356,
469,
288,
283,
3396,
356,
791,
7128,
356,
7340,
85,
7,
1317,
63,
466,
363,
571,
63,
1302,
297,
399,
7,
1317,
63,
466,
363,
1238,
297,
399,
7,
11879,
18106,
283,
3235,
63,
6314,
356,
298,
1332,
85,
7,
1317,
63,
466,
297,
399,
7,
11879,
9878,
283,
785,
63,
354,
356,
283,
7980,
2267,
288,
283,
11879,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1960,
1604,
288,
283,
1317,
63,
466,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
297,
990,
791,
475,
356,
399,
2,
1025,
459,
10778,
14,
11282,
6097,
288,
399,
7,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1400,
3071,
267,
1660,
267,
399,
7,
1178,
14,
751,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
1899,
2267,
288,
283,
602,
63,
11806,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
297,
990,
791,
885,
356,
283,
2083,
14,
2083,
14,
2131,
1604,
288,
283,
2123,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
16577,
297,
990,
791,
988,
63,
1267,
356,
283,
2194,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
2246,
63,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1216,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
2634,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
7624,
297,
990,
791,
475,
356,
399,
2,
1025,
459,
1178,
14,
2448,
6256,
283,
10247,
356,
283,
797,
297,
283,
2500,
356,
283,
549,
1604,
288,
399,
7,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
374,
63,
2682,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
549,
1604,
288,
283,
374,
63,
7018,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
797,
1604,
288,
283,
374,
63,
11434,
356,
661,
1176,
14,
697
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
22405,
103,
6029,
446,
6927,
603,
1158,
279,
221,
129,
235,
73,
2411,
130,
248,
665,
77,
1158,
279,
32,
559,
8210,
14,
957,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
6001,
750,
665,
1014,
921,
2520,
750,
14,
1308,
3133,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
504,
12919,
14,
697,
492,
1592,
199,
504,
12919,
14,
86,
18,
492,
24765,
421,
199,
533,
12090,
8,
24822,
304,
339,
347,
17465,
8,
277,
12,
9813,
304,
267,
327,
12934,
1402,
283,
54,
1583,
7,
267,
1592,
14,
981,
63,
1224,
8,
85,
1133,
1320,
63,
14317,
297,
334,
288,
334,
85,
7,
344,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
7533,
3327,
63,
498,
29,
549,
1826,
288,
661,
19957,
1636,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
7533,
475,
29,
1025,
459,
1515,
14,
51,
11914,
1636,
16607,
288,
661,
751,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
7533,
475,
29,
1025,
459,
1178,
14,
1899,
16607,
288,
661,
8965,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
7533,
885,
29,
549,
1826,
267,
5082,
267,
1592,
14,
2254,
63,
981,
63,
4653,
360,
1515,
297,
788,
54,
1583,
1105,
398,
327,
12934,
3747,
5828,
641,
283,
54,
1583,
297,
1504,
788,
19957,
1636,
297,
283,
751,
418,
267,
1592,
14,
981,
63,
3235,
8,
85,
1133,
1320,
63,
14317,
297,
788,
19957,
1636,
63,
344,
297,
283,
751,
63,
344,
1105,
2378,
347,
8552,
8,
277,
12,
9813,
304,
267,
327,
29343,
3747,
5828,
641,
283,
54,
1583,
297,
1504,
788,
19957,
1636,
297,
283,
751,
418,
267,
1592,
14,
1807,
63,
3235,
8,
85,
1133,
1320,
63,
14317,
297,
788,
19957,
1636,
63,
344,
297,
283,
751,
63,
344,
1105,
398,
327,
15920,
1402,
283,
54,
1583,
7,
267,
1592,
14,
1807,
63,
1224,
8,
85,
1133,
1320,
63,
14317,
358,
2378,
1709,
275,
469,
267,
399,
7,
1178,
14,
923,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
2448,
2267,
288,
399,
7,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
3235,
356,
283,
549,
297,
283,
988,
63,
1267,
356,
283,
1257,
1604,
288,
283,
6060,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
7624,
297,
990,
791,
475,
356,
399,
2,
1025,
459,
1178,
14,
7980,
6256,
283,
10247,
356,
283,
797,
297,
283,
2500,
356,
283,
549,
3071,
267,
1660,
267,
399,
7,
1178,
14,
5693,
356,
469,
288,
283,
3396,
356,
791,
7128,
356,
7340,
85,
7,
1317,
63,
466,
363,
571,
63,
1302,
297,
399,
7,
1317,
63,
466,
363,
1238,
297,
399,
7,
11879,
18106,
283,
3235,
63,
6314,
356,
298,
1332,
85,
7,
1317,
63,
466,
297,
399,
7,
11879,
9878,
283,
785,
63,
354,
356,
283,
7980,
2267,
288,
283,
11879,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1960,
1604,
288,
283,
1317,
63,
466,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
297,
990,
791,
475,
356,
399,
2,
1025,
459,
10778,
14,
11282,
6097,
288,
399,
7,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1400,
3071,
267,
1660,
267,
399,
7,
1178,
14,
751,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
1899,
2267,
288,
283,
602,
63,
11806,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
297,
990,
791,
885,
356,
283,
2083,
14,
2083,
14,
2131,
1604,
288,
283,
2123,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
16577,
297,
990,
791,
988,
63,
1267,
356,
283,
2194,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
2246,
63,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1216,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
2634,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
7624,
297,
990,
791,
475,
356,
399,
2,
1025,
459,
1178,
14,
2448,
6256,
283,
10247,
356,
283,
797,
297,
283,
2500,
356,
283,
549,
1604,
288,
399,
7,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
374,
63,
2682,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356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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
] |
whn09/tensorflow
|
tensorflow/examples/learn/iris_custom_decay_dnn.py
|
30
|
2039
|
# 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.
"""Example of DNNClassifier for Iris plant dataset, with exponential decay."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from sklearn import datasets
from sklearn import metrics
from sklearn.cross_validation import train_test_split
import tensorflow as tf
def optimizer_exp_decay():
global_step = tf.contrib.framework.get_or_create_global_step()
learning_rate = tf.train.exponential_decay(
learning_rate=0.1, global_step=global_step,
decay_steps=100, decay_rate=0.001)
return tf.train.AdagradOptimizer(learning_rate=learning_rate)
def main(unused_argv):
iris = datasets.load_iris()
x_train, x_test, y_train, y_test = train_test_split(
iris.data, iris.target, test_size=0.2, random_state=42)
feature_columns = tf.contrib.learn.infer_real_valued_columns_from_input(
x_train)
classifier = tf.contrib.learn.DNNClassifier(feature_columns=feature_columns,
hidden_units=[10, 20, 10],
n_classes=3,
optimizer=optimizer_exp_decay)
classifier.fit(x_train, y_train, steps=800)
predictions = list(classifier.predict(x_test, as_iterable=True))
score = metrics.accuracy_score(y_test, predictions)
print('Accuracy: {0:f}'.format(score))
if __name__ == '__main__':
tf.app.run()
|
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,
9846,
402,
577,
7178,
8508,
367,
473,
5719,
1620,
867,
4789,
12,
543,
23160,
16696,
1041,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
504,
6357,
492,
13148,
199,
504,
6357,
492,
7186,
199,
504,
6357,
14,
7925,
63,
6136,
492,
3560,
63,
396,
63,
1294,
199,
646,
3228,
465,
2833,
421,
199,
318,
10736,
63,
1474,
63,
16889,
837,
523,
2288,
63,
2926,
275,
2833,
14,
2828,
14,
4857,
14,
362,
63,
269,
63,
981,
63,
2966,
63,
2926,
342,
523,
9328,
63,
1866,
275,
2833,
14,
2834,
14,
27093,
63,
16889,
8,
489,
9328,
63,
1866,
29,
16,
14,
17,
12,
2288,
63,
2926,
29,
2966,
63,
2926,
12,
489,
16696,
63,
5895,
29,
1960,
12,
16696,
63,
1866,
29,
16,
14,
4587,
9,
523,
372,
2833,
14,
2834,
14,
2767,
27707,
13946,
8,
10546,
63,
1866,
29,
10546,
63,
1866,
9,
421,
199,
318,
2446,
8,
8618,
63,
3020,
304,
523,
12192,
275,
13148,
14,
912,
63,
11885,
342,
523,
671,
63,
2834,
12,
671,
63,
396,
12,
612,
63,
2834,
12,
612,
63,
396,
275,
3560,
63,
396,
63,
1294,
8,
489,
12192,
14,
576,
12,
12192,
14,
1375,
12,
511,
63,
890,
29,
16,
14,
18,
12,
2196,
63,
929,
29,
2260,
9,
819,
3878,
63,
3406,
275,
2833,
14,
2828,
14,
4643,
14,
14578,
63,
3093,
63,
16611,
63,
3406,
63,
504,
63,
1210,
8,
489,
671,
63,
2834,
9,
523,
12429,
275,
2833,
14,
2828,
14,
4643,
14,
36,
7178,
8508,
8,
4445,
63,
3406,
29,
4445,
63,
3406,
12,
6343,
8752,
63,
5260,
1524,
709,
12,
3388,
12,
1616,
467,
6343,
302,
63,
2888,
29,
19,
12,
6343,
10736,
29,
12290,
63,
1474,
63,
16889,
9,
819,
12429,
14,
3269,
8,
88,
63,
2834,
12,
612,
63,
2834,
12,
7124,
29,
6718,
9,
523,
7914,
275,
769,
8,
14720,
14,
6892,
8,
88,
63,
396,
12,
465,
63,
8147,
29,
549,
430,
523,
5396,
275,
7186,
14,
13374,
63,
3397,
8,
89,
63,
396,
12,
7914,
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,
2833,
14,
571,
14,
1065,
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
] |
[
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,
9846,
402,
577,
7178,
8508,
367,
473,
5719,
1620,
867,
4789,
12,
543,
23160,
16696,
1041,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
504,
6357,
492,
13148,
199,
504,
6357,
492,
7186,
199,
504,
6357,
14,
7925,
63,
6136,
492,
3560,
63,
396,
63,
1294,
199,
646,
3228,
465,
2833,
421,
199,
318,
10736,
63,
1474,
63,
16889,
837,
523,
2288,
63,
2926,
275,
2833,
14,
2828,
14,
4857,
14,
362,
63,
269,
63,
981,
63,
2966,
63,
2926,
342,
523,
9328,
63,
1866,
275,
2833,
14,
2834,
14,
27093,
63,
16889,
8,
489,
9328,
63,
1866,
29,
16,
14,
17,
12,
2288,
63,
2926,
29,
2966,
63,
2926,
12,
489,
16696,
63,
5895,
29,
1960,
12,
16696,
63,
1866,
29,
16,
14,
4587,
9,
523,
372,
2833,
14,
2834,
14,
2767,
27707,
13946,
8,
10546,
63,
1866,
29,
10546,
63,
1866,
9,
421,
199,
318,
2446,
8,
8618,
63,
3020,
304,
523,
12192,
275,
13148,
14,
912,
63,
11885,
342,
523,
671,
63,
2834,
12,
671,
63,
396,
12,
612,
63,
2834,
12,
612,
63,
396,
275,
3560,
63,
396,
63,
1294,
8,
489,
12192,
14,
576,
12,
12192,
14,
1375,
12,
511,
63,
890,
29,
16,
14,
18,
12,
2196,
63,
929,
29,
2260,
9,
819,
3878,
63,
3406,
275,
2833,
14,
2828,
14,
4643,
14,
14578,
63,
3093,
63,
16611,
63,
3406,
63,
504,
63,
1210,
8,
489,
671,
63,
2834,
9,
523,
12429,
275,
2833,
14,
2828,
14,
4643,
14,
36,
7178,
8508,
8,
4445,
63,
3406,
29,
4445,
63,
3406,
12,
6343,
8752,
63,
5260,
1524,
709,
12,
3388,
12,
1616,
467,
6343,
302,
63,
2888,
29,
19,
12,
6343,
10736,
29,
12290,
63,
1474,
63,
16889,
9,
819,
12429,
14,
3269,
8,
88,
63,
2834,
12,
612,
63,
2834,
12,
7124,
29,
6718,
9,
523,
7914,
275,
769,
8,
14720,
14,
6892,
8,
88,
63,
396,
12,
465,
63,
8147,
29,
549,
430,
523,
5396,
275,
7186,
14,
13374,
63,
3397,
8,
89,
63,
396,
12,
7914,
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,
2833,
14,
571,
14,
1065,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
anuragpapineni/Hearthbreaker-evolved-agent
|
hearthbreaker/cards/minions/warrior.py
|
2
|
2859
|
from hearthbreaker.effects.minion import Buff, IncreaseArmor, GiveCharge
import hearthbreaker.targeting
from hearthbreaker.constants import CHARACTER_CLASS, CARD_RARITY
from hearthbreaker.game_objects import MinionCard, Minion, WeaponCard, Weapon
class ArathiWeaponsmith(MinionCard):
def __init__(self):
super().__init__("Arathi Weaponsmith", 4, CHARACTER_CLASS.WARRIOR, CARD_RARITY.COMMON)
def create_minion(self, player):
class BattleAxe(WeaponCard):
def __init__(self):
super().__init__("Battle Axe", 1, CHARACTER_CLASS.WARRIOR, CARD_RARITY.SPECIAL)
def create_weapon(self, player):
return Weapon(2, 2)
def equip_battle_axe(minion):
battle_axe = BattleAxe().create_weapon(player)
battle_axe.equip(player)
return Minion(3, 3, battlecry=equip_battle_axe)
class Armorsmith(MinionCard):
def __init__(self):
super().__init__("Armorsmith", 2, CHARACTER_CLASS.WARRIOR, CARD_RARITY.RARE)
def create_minion(self, player):
return Minion(1, 4, effects=[IncreaseArmor("damaged", 1, "minion", players="friendly", include_self=True)])
class CruelTaskmaster(MinionCard):
def __init__(self):
super().__init__("Cruel Taskmaster", 2, CHARACTER_CLASS.WARRIOR, CARD_RARITY.COMMON,
targeting_func=hearthbreaker.targeting.find_minion_battlecry_target)
def create_minion(self, player):
def deal_one_damage_and_give_two_attack(minion):
if minion.card.target is not None:
minion.card.target.damage(1, self)
minion.card.target.change_attack(2)
return Minion(2, 2, battlecry=deal_one_damage_and_give_two_attack)
class FrothingBerserker(MinionCard):
def __init__(self):
super().__init__("Frothing Berserker", 3, CHARACTER_CLASS.WARRIOR, CARD_RARITY.RARE)
def create_minion(self, player):
minion = Minion(2, 4, effects=[Buff("damaged", "minion", "self", 1, 0, "both", True)])
return minion
class GrommashHellscream(MinionCard):
def __init__(self):
super().__init__("Grommash Hellscream", 8, CHARACTER_CLASS.WARRIOR, CARD_RARITY.LEGENDARY)
def create_minion(self, player):
return Minion(4, 9, charge=True, effects=[Buff("enraged", attack=6)])
class KorkronElite(MinionCard):
def __init__(self):
super().__init__("Kor'kron Elite", 4, CHARACTER_CLASS.WARRIOR, CARD_RARITY.COMMON)
def create_minion(self, player):
return Minion(4, 3, charge=True)
class WarsongCommander(MinionCard):
def __init__(self):
super().__init__("Warsong Commander", 3, CHARACTER_CLASS.WARRIOR, CARD_RARITY.FREE)
def create_minion(self, player):
return Minion(2, 3, effects=[GiveCharge("placed", "attack_less_than_or_equal_to_3", "other")])
|
mit
|
[
504,
946,
19677,
4785,
281,
14,
27626,
14,
827,
1636,
492,
699,
3043,
12,
1010,
16772,
1596,
12416,
12,
25495,
31539,
199,
646,
946,
19677,
4785,
281,
14,
1375,
316,
199,
504,
946,
19677,
4785,
281,
14,
5559,
492,
9502,
63,
6885,
12,
445,
7816,
63,
50,
689,
1922,
199,
504,
946,
19677,
4785,
281,
14,
5097,
63,
1462,
492,
10195,
1636,
13832,
12,
10195,
1636,
12,
2136,
21921,
13832,
12,
2136,
21921,
421,
199,
533,
437,
345,
273,
73,
6004,
21921,
3300,
448,
8,
4649,
1636,
13832,
304,
272,
347,
636,
826,
721,
277,
304,
267,
1613,
11027,
826,
29093,
33,
345,
273,
73,
2136,
21921,
3300,
448,
401,
841,
12,
9502,
63,
6885,
14,
55,
27052,
726,
12,
445,
7816,
63,
50,
689,
1922,
14,
21637,
9,
339,
347,
1218,
63,
827,
1636,
8,
277,
12,
7748,
304,
267,
1021,
699,
29274,
33,
1845,
8,
6004,
21921,
13832,
304,
288,
347,
636,
826,
721,
277,
304,
355,
1613,
11027,
826,
29093,
34,
29274,
437,
1845,
401,
413,
12,
9502,
63,
6885,
14,
55,
27052,
726,
12,
445,
7816,
63,
50,
689,
1922,
14,
25748,
9,
953,
347,
1218,
63,
30804,
8,
277,
12,
7748,
304,
355,
372,
2136,
21921,
8,
18,
12,
499,
9,
398,
347,
11960,
711,
63,
29787,
63,
1219,
69,
8,
827,
1636,
304,
288,
330,
29274,
63,
1219,
69,
275,
699,
29274,
33,
1845,
1252,
981,
63,
30804,
8,
6147,
9,
288,
330,
29274,
63,
1219,
69,
14,
15788,
711,
8,
6147,
9,
398,
372,
10195,
1636,
8,
19,
12,
650,
12,
330,
29274,
3019,
29,
15788,
711,
63,
29787,
63,
1219,
69,
9,
421,
199,
533,
1952,
77,
1384,
77,
448,
8,
4649,
1636,
13832,
304,
272,
347,
636,
826,
721,
277,
304,
267,
1613,
11027,
826,
29093,
1596,
77,
1384,
77,
448,
401,
499,
12,
9502,
63,
6885,
14,
55,
27052,
726,
12,
445,
7816,
63,
50,
689,
1922,
14,
50,
8693,
9,
339,
347,
1218,
63,
827,
1636,
8,
277,
12,
7748,
304,
267,
372,
10195,
1636,
8,
17,
12,
841,
12,
22414,
1524,
607,
16772,
1596,
12416,
480,
26551,
68,
401,
413,
12,
298,
827,
1636,
401,
30130,
628,
17317,
401,
2387,
63,
277,
29,
549,
3948,
421,
199,
533,
445,
431,
76,
4476,
4133,
8,
4649,
1636,
13832,
304,
272,
347,
636,
826,
721,
277,
304,
267,
1613,
11027,
826,
29093,
35,
431,
76,
8495,
4133,
401,
499,
12,
9502,
63,
6885,
14,
55,
27052,
726,
12,
445,
7816,
63,
50,
689,
1922,
14,
21637,
12,
586,
1347,
316,
63,
1532,
29,
426,
19677,
4785,
281,
14,
1375,
316,
14,
1623,
63,
827,
1636,
63,
29787,
3019,
63,
1375,
9,
339,
347,
1218,
63,
827,
1636,
8,
277,
12,
7748,
304,
267,
347,
7962,
63,
368,
63,
26551,
63,
460,
63,
26035,
63,
5601,
63,
24171,
8,
827,
1636,
304,
288,
340,
1748,
1636,
14,
5841,
14,
1375,
365,
440,
488,
26,
355,
1748,
1636,
14,
5841,
14,
1375,
14,
26551,
8,
17,
12,
291,
9,
355,
1748,
1636,
14,
5841,
14,
1375,
14,
1461,
63,
24171,
8,
18,
9,
398,
372,
10195,
1636,
8,
18,
12,
499,
12,
330,
29274,
3019,
29,
21245,
63,
368,
63,
26551,
63,
460,
63,
26035,
63,
5601,
63,
24171,
9,
421,
199,
533,
481,
293,
2127,
24947,
332,
2570,
8,
4649,
1636,
13832,
304,
272,
347,
636,
826,
721,
277,
304,
267,
1613,
11027,
826,
29093,
38,
293,
2127,
23207,
332,
2570,
401,
650,
12,
9502,
63,
6885,
14,
55,
27052,
726,
12,
445,
7816,
63,
50,
689,
1922,
14,
50,
8693,
9,
339,
347,
1218,
63,
827,
1636,
8,
277,
12,
7748,
304,
267,
1748,
1636,
275,
10195,
1636,
8,
18,
12,
841,
12,
22414,
1524,
1713,
556,
480,
26551,
68,
401,
298,
827,
1636,
401,
298,
277,
401,
413,
12,
378,
12,
298,
10727,
401,
715,
3948,
267,
372,
1748,
1636,
421,
199,
533,
598,
417,
77,
1119,
40,
6840,
67,
1091,
8,
4649,
1636,
13832,
304,
272,
347,
636,
826,
721,
277,
304,
267,
1613,
11027,
826,
29093,
39,
417,
77,
1119,
869,
6840,
67,
1091,
401,
1695,
12,
9502,
63,
6885,
14,
55,
27052,
726,
12,
445,
7816,
63,
50,
689,
1922,
14,
25086,
3902,
4392,
9,
339,
347,
1218,
63,
827,
1636,
8,
277,
12,
7748,
304,
267,
372,
10195,
1636,
8,
20,
12,
1749,
12,
11204,
29,
549,
12,
22414,
1524,
1713,
556,
480,
287,
345,
3046,
401,
23326,
29,
22,
3948,
421,
199,
533,
1804,
4708,
2641,
37,
5333,
8,
4649,
1636,
13832,
304,
272,
347,
636,
826,
721,
277,
304,
267,
1613,
11027,
826,
29093,
43,
269,
7,
75,
2641,
662,
5333,
401,
841,
12,
9502,
63,
6885,
14,
55,
27052,
726,
12,
445,
7816,
63,
50,
689,
1922,
14,
21637,
9,
339,
347,
1218,
63,
827,
1636,
8,
277,
12,
7748,
304,
267,
372,
10195,
1636,
8,
20,
12,
650,
12,
11204,
29,
549,
9,
421,
199,
533,
644,
285,
19351,
5150,
11438,
8,
4649,
1636,
13832,
304,
272,
347,
636,
826,
721,
277,
304,
267,
1613,
11027,
826,
29093,
55,
285,
19351,
7046,
11438,
401,
650,
12,
9502,
63,
6885,
14,
55,
27052,
726,
12,
445,
7816,
63,
50,
689,
1922,
14,
28170,
9,
339,
347,
1218,
63,
827,
1636,
8,
277,
12,
7748,
304,
267,
372,
10195,
1636,
8,
18,
12,
650,
12,
22414,
1524,
39,
1912,
31539,
480,
2778,
68,
401,
298,
24171,
63,
2003,
63,
13797,
63,
269,
63,
1452,
63,
475,
63,
19,
401,
298,
1848,
13403,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
946,
19677,
4785,
281,
14,
27626,
14,
827,
1636,
492,
699,
3043,
12,
1010,
16772,
1596,
12416,
12,
25495,
31539,
199,
646,
946,
19677,
4785,
281,
14,
1375,
316,
199,
504,
946,
19677,
4785,
281,
14,
5559,
492,
9502,
63,
6885,
12,
445,
7816,
63,
50,
689,
1922,
199,
504,
946,
19677,
4785,
281,
14,
5097,
63,
1462,
492,
10195,
1636,
13832,
12,
10195,
1636,
12,
2136,
21921,
13832,
12,
2136,
21921,
421,
199,
533,
437,
345,
273,
73,
6004,
21921,
3300,
448,
8,
4649,
1636,
13832,
304,
272,
347,
636,
826,
721,
277,
304,
267,
1613,
11027,
826,
29093,
33,
345,
273,
73,
2136,
21921,
3300,
448,
401,
841,
12,
9502,
63,
6885,
14,
55,
27052,
726,
12,
445,
7816,
63,
50,
689,
1922,
14,
21637,
9,
339,
347,
1218,
63,
827,
1636,
8,
277,
12,
7748,
304,
267,
1021,
699,
29274,
33,
1845,
8,
6004,
21921,
13832,
304,
288,
347,
636,
826,
721,
277,
304,
355,
1613,
11027,
826,
29093,
34,
29274,
437,
1845,
401,
413,
12,
9502,
63,
6885,
14,
55,
27052,
726,
12,
445,
7816,
63,
50,
689,
1922,
14,
25748,
9,
953,
347,
1218,
63,
30804,
8,
277,
12,
7748,
304,
355,
372,
2136,
21921,
8,
18,
12,
499,
9,
398,
347,
11960,
711,
63,
29787,
63,
1219,
69,
8,
827,
1636,
304,
288,
330,
29274,
63,
1219,
69,
275,
699,
29274,
33,
1845,
1252,
981,
63,
30804,
8,
6147,
9,
288,
330,
29274,
63,
1219,
69,
14,
15788,
711,
8,
6147,
9,
398,
372,
10195,
1636,
8,
19,
12,
650,
12,
330,
29274,
3019,
29,
15788,
711,
63,
29787,
63,
1219,
69,
9,
421,
199,
533,
1952,
77,
1384,
77,
448,
8,
4649,
1636,
13832,
304,
272,
347,
636,
826,
721,
277,
304,
267,
1613,
11027,
826,
29093,
1596,
77,
1384,
77,
448,
401,
499,
12,
9502,
63,
6885,
14,
55,
27052,
726,
12,
445,
7816,
63,
50,
689,
1922,
14,
50,
8693,
9,
339,
347,
1218,
63,
827,
1636,
8,
277,
12,
7748,
304,
267,
372,
10195,
1636,
8,
17,
12,
841,
12,
22414,
1524,
607,
16772,
1596,
12416,
480,
26551,
68,
401,
413,
12,
298,
827,
1636,
401,
30130,
628,
17317,
401,
2387,
63,
277,
29,
549,
3948,
421,
199,
533,
445,
431,
76,
4476,
4133,
8,
4649,
1636,
13832,
304,
272,
347,
636,
826,
721,
277,
304,
267,
1613,
11027,
826,
29093,
35,
431,
76,
8495,
4133,
401,
499,
12,
9502,
63,
6885,
14,
55,
27052,
726,
12,
445,
7816,
63,
50,
689,
1922,
14,
21637,
12,
586,
1347,
316,
63,
1532,
29,
426,
19677,
4785,
281,
14,
1375,
316,
14,
1623,
63,
827,
1636,
63,
29787,
3019,
63,
1375,
9,
339,
347,
1218,
63,
827,
1636,
8,
277,
12,
7748,
304,
267,
347,
7962,
63,
368,
63,
26551,
63,
460,
63,
26035,
63,
5601,
63,
24171,
8,
827,
1636,
304,
288,
340,
1748,
1636,
14,
5841,
14,
1375,
365,
440,
488,
26,
355,
1748,
1636,
14,
5841,
14,
1375,
14,
26551,
8,
17,
12,
291,
9,
355,
1748,
1636,
14,
5841,
14,
1375,
14,
1461,
63,
24171,
8,
18,
9,
398,
372,
10195,
1636,
8,
18,
12,
499,
12,
330,
29274,
3019,
29,
21245,
63,
368,
63,
26551,
63,
460,
63,
26035,
63,
5601,
63,
24171,
9,
421,
199,
533,
481,
293,
2127,
24947,
332,
2570,
8,
4649,
1636,
13832,
304,
272,
347,
636,
826,
721,
277,
304,
267,
1613,
11027,
826,
29093,
38,
293,
2127,
23207,
332,
2570,
401,
650,
12,
9502,
63,
6885,
14,
55,
27052,
726,
12,
445,
7816,
63,
50,
689,
1922,
14,
50,
8693,
9,
339,
347,
1218,
63,
827,
1636,
8,
277,
12,
7748,
304,
267,
1748,
1636,
275,
10195,
1636,
8,
18,
12,
841,
12,
22414,
1524,
1713,
556,
480,
26551,
68,
401,
298,
827,
1636,
401,
298,
277,
401,
413,
12,
378,
12,
298,
10727,
401,
715,
3948,
267,
372,
1748,
1636,
421,
199,
533,
598,
417,
77,
1119,
40,
6840,
67,
1091,
8,
4649,
1636,
13832,
304,
272,
347,
636,
826,
721,
277,
304,
267,
1613,
11027,
826,
29093,
39,
417,
77,
1119,
869,
6840,
67,
1091,
401,
1695,
12,
9502,
63,
6885,
14,
55,
27052,
726,
12,
445,
7816,
63,
50,
689,
1922,
14,
25086,
3902,
4392,
9,
339,
347,
1218,
63,
827,
1636,
8,
277,
12,
7748,
304,
267,
372,
10195,
1636,
8,
20,
12,
1749,
12,
11204,
29,
549,
12,
22414,
1524,
1713,
556,
480,
287,
345,
3046,
401,
23326,
29,
22,
3948,
421,
199,
533,
1804,
4708,
2641,
37,
5333,
8,
4649,
1636,
13832,
304,
272,
347,
636,
826,
721,
277,
304,
267,
1613,
11027,
826,
29093,
43,
269,
7,
75,
2641,
662,
5333,
401,
841,
12,
9502,
63,
6885,
14,
55,
27052,
726,
12,
445,
7816,
63,
50,
689,
1922,
14,
21637,
9,
339,
347,
1218,
63,
827,
1636,
8,
277,
12,
7748,
304,
267,
372,
10195,
1636,
8,
20,
12,
650,
12,
11204,
29,
549,
9,
421,
199,
533,
644,
285,
19351,
5150,
11438,
8,
4649,
1636,
13832,
304,
272,
347,
636,
826,
721,
277,
304,
267,
1613,
11027,
826,
29093,
55,
285,
19351,
7046,
11438,
401,
650,
12,
9502,
63,
6885,
14,
55,
27052,
726,
12,
445,
7816,
63,
50,
689,
1922,
14,
28170,
9,
339,
347,
1218,
63,
827,
1636,
8,
277,
12,
7748,
304,
267,
372,
10195,
1636,
8,
18,
12,
650,
12,
22414,
1524,
39,
1912,
31539,
480,
2778,
68,
401,
298,
24171,
63,
2003,
63,
13797,
63,
269,
63,
1452,
63,
475,
63,
19,
401,
298,
1848,
13403,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
aperigault/ansible
|
lib/ansible/modules/crypto/acme/acme_inspect.py
|
20
|
12317
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
# (c) 2018 Felix Fontein (@felixfontein)
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'community'}
DOCUMENTATION = r'''
---
module: acme_inspect
author: "Felix Fontein (@felixfontein)"
version_added: "2.8"
short_description: Send direct requests to an ACME server
description:
- "Allows to send direct requests to an ACME server with the
L(ACME protocol,https://tools.ietf.org/html/rfc8555),
which is supported by CAs such as L(Let's Encrypt,https://letsencrypt.org/)."
- "This module can be used to debug failed certificate request attempts,
for example when M(acme_certificate) fails or encounters a problem which
you wish to investigate."
- "The module can also be used to directly access features of an ACME servers
which are not yet supported by the Ansible ACME modules."
notes:
- "The I(account_uri) option must be specified for properly authenticated
ACME v2 requests (except a C(new-account) request)."
- "Using the C(ansible) tool, M(acme_inspect) can be used to directly execute
ACME requests without the need of writing a playbook. For example, the
following command retrieves the ACME account with ID 1 from Let's Encrypt
(assuming C(/path/to/key) is the correct private account key):
C(ansible localhost -m acme_inspect -a \"account_key_src=/path/to/key
acme_directory=https://acme-v02.api.letsencrypt.org/directory acme_version=2
account_uri=https://acme-v02.api.letsencrypt.org/acme/acct/1 method=get
url=https://acme-v02.api.letsencrypt.org/acme/acct/1\")"
seealso:
- name: Automatic Certificate Management Environment (ACME)
description: The specification of the ACME protocol (RFC 8555).
link: https://tools.ietf.org/html/rfc8555
- name: ACME TLS ALPN Challenge Extension
description: The current draft specification of the C(tls-alpn-01) challenge.
link: https://tools.ietf.org/html/draft-ietf-acme-tls-alpn-05
extends_documentation_fragment:
- acme
options:
url:
description:
- "The URL to send the request to."
- "Must be specified if I(method) is not C(directory-only)."
type: str
method:
description:
- "The method to use to access the given URL on the ACME server."
- "The value C(post) executes an authenticated POST request. The content
must be specified in the I(content) option."
- "The value C(get) executes an authenticated POST-as-GET request for ACME v2,
and a regular GET request for ACME v1."
- "The value C(directory-only) only retrieves the directory, without doing
a request."
type: str
default: get
choices:
- get
- post
- directory-only
content:
description:
- "An encoded JSON object which will be sent as the content if I(method)
is C(post)."
- "Required when I(method) is C(post), and not allowed otherwise."
type: str
fail_on_acme_error:
description:
- "If I(method) is C(post) or C(get), make the module fail in case an ACME
error is returned."
type: bool
default: yes
'''
EXAMPLES = r'''
- name: Get directory
acme_inspect:
acme_directory: https://acme-staging-v02.api.letsencrypt.org/directory
acme_version: 2
method: directory-only
register: directory
- name: Create an account
acme_inspect:
acme_directory: https://acme-staging-v02.api.letsencrypt.org/directory
acme_version: 2
account_key_src: /etc/pki/cert/private/account.key
url: "{{ directory.newAccount}}"
method: post
content: '{"termsOfServiceAgreed":true}'
register: account_creation
# account_creation.headers.location contains the account URI
# if creation was successful
- name: Get account information
acme_inspect:
acme_directory: https://acme-staging-v02.api.letsencrypt.org/directory
acme_version: 2
account_key_src: /etc/pki/cert/private/account.key
account_uri: "{{ account_creation.headers.location }}"
url: "{{ account_creation.headers.location }}"
method: get
- name: Update account contacts
acme_inspect:
acme_directory: https://acme-staging-v02.api.letsencrypt.org/directory
acme_version: 2
account_key_src: /etc/pki/cert/private/account.key
account_uri: "{{ account_creation.headers.location }}"
url: "{{ account_creation.headers.location }}"
method: post
content: '{{ account_info | to_json }}'
vars:
account_info:
# For valid values, see
# https://tools.ietf.org/html/rfc8555#section-7.3
contact:
- mailto:me@example.com
- name: Create certificate order
acme_certificate:
acme_directory: https://acme-staging-v02.api.letsencrypt.org/directory
acme_version: 2
account_key_src: /etc/pki/cert/private/account.key
account_uri: "{{ account_creation.headers.location }}"
csr: /etc/pki/cert/csr/sample.com.csr
fullchain_dest: /etc/httpd/ssl/sample.com-fullchain.crt
challenge: http-01
register: certificate_request
# Assume something went wrong. certificate_request.order_uri contains
# the order URI.
- name: Get order information
acme_inspect:
acme_directory: https://acme-staging-v02.api.letsencrypt.org/directory
acme_version: 2
account_key_src: /etc/pki/cert/private/account.key
account_uri: "{{ account_creation.headers.location }}"
url: "{{ certificate_request.order_uri }}"
method: get
register: order
- name: Get first authz for order
acme_inspect:
acme_directory: https://acme-staging-v02.api.letsencrypt.org/directory
acme_version: 2
account_key_src: /etc/pki/cert/private/account.key
account_uri: "{{ account_creation.headers.location }}"
url: "{{ order.output_json.authorizations[0] }}"
method: get
register: authz
- name: Get HTTP-01 challenge for authz
acme_inspect:
acme_directory: https://acme-staging-v02.api.letsencrypt.org/directory
acme_version: 2
account_key_src: /etc/pki/cert/private/account.key
account_uri: "{{ account_creation.headers.location }}"
url: "{{ authz.output_json.challenges | selectattr('type', 'equalto', 'http-01') }}"
method: get
register: http01challenge
- name: Activate HTTP-01 challenge manually
acme_inspect:
acme_directory: https://acme-staging-v02.api.letsencrypt.org/directory
acme_version: 2
account_key_src: /etc/pki/cert/private/account.key
account_uri: "{{ account_creation.headers.location }}"
url: "{{ http01challenge.url }}"
method: post
content: '{}'
'''
RETURN = '''
directory:
description: The ACME directory's content
returned: always
type: dict
sample: |
{
"a85k3x9f91A4": "https://community.letsencrypt.org/t/adding-random-entries-to-the-directory/33417",
"keyChange": "https://acme-v02.api.letsencrypt.org/acme/key-change",
"meta": {
"caaIdentities": [
"letsencrypt.org"
],
"termsOfService": "https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf",
"website": "https://letsencrypt.org"
},
"newAccount": "https://acme-v02.api.letsencrypt.org/acme/new-acct",
"newNonce": "https://acme-v02.api.letsencrypt.org/acme/new-nonce",
"newOrder": "https://acme-v02.api.letsencrypt.org/acme/new-order",
"revokeCert": "https://acme-v02.api.letsencrypt.org/acme/revoke-cert"
}
headers:
description: The request's HTTP headers (with lowercase keys)
returned: always
type: dict
sample: |
{
"boulder-requester": "12345",
"cache-control": "max-age=0, no-cache, no-store",
"connection": "close",
"content-length": "904",
"content-type": "application/json",
"cookies": {},
"cookies_string": "",
"date": "Wed, 07 Nov 2018 12:34:56 GMT",
"expires": "Wed, 07 Nov 2018 12:44:56 GMT",
"link": "<https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf>;rel=\"terms-of-service\"",
"msg": "OK (904 bytes)",
"pragma": "no-cache",
"replay-nonce": "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGH",
"server": "nginx",
"status": 200,
"strict-transport-security": "max-age=604800",
"url": "https://acme-v02.api.letsencrypt.org/acme/acct/46161",
"x-frame-options": "DENY"
}
output_text:
description: The raw text output
returned: always
type: str
sample: "{\\n \\\"id\\\": 12345,\\n \\\"key\\\": {\\n \\\"kty\\\": \\\"RSA\\\",\\n ..."
output_json:
description: The output parsed as JSON
returned: if output can be parsed as JSON
type: dict
sample:
- id: 12345
- key:
- kty: RSA
- ...
'''
from ansible.module_utils.acme import (
ModuleFailException, ACMEAccount, set_crypto_backend,
)
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils._text import to_native, to_bytes
import json
def main():
module = AnsibleModule(
argument_spec=dict(
account_key_src=dict(type='path', aliases=['account_key']),
account_key_content=dict(type='str', no_log=True),
account_uri=dict(type='str'),
acme_directory=dict(type='str', default='https://acme-staging.api.letsencrypt.org/directory'),
acme_version=dict(type='int', default=1, choices=[1, 2]),
validate_certs=dict(type='bool', default=True),
url=dict(type='str'),
method=dict(type='str', choices=['get', 'post', 'directory-only'], default='get'),
content=dict(type='str'),
fail_on_acme_error=dict(type='bool', default=True),
select_crypto_backend=dict(type='str', default='auto', choices=['auto', 'openssl', 'cryptography']),
),
mutually_exclusive=(
['account_key_src', 'account_key_content'],
),
required_if=(
['method', 'get', ['url']],
['method', 'post', ['url', 'content']],
['method', 'get', ['account_key_src', 'account_key_content'], True],
['method', 'post', ['account_key_src', 'account_key_content'], True],
),
)
set_crypto_backend(module)
if not module.params.get('validate_certs'):
module.warn(warning='Disabling certificate validation for communications with ACME endpoint. ' +
'This should only be done for testing against a local ACME server for ' +
'development purposes, but *never* for production purposes.')
result = dict()
changed = False
try:
# Get hold of ACMEAccount object (includes directory)
account = ACMEAccount(module)
method = module.params['method']
result['directory'] = account.directory.directory
# Do we have to do more requests?
if method != 'directory-only':
url = module.params['url']
fail_on_acme_error = module.params['fail_on_acme_error']
# Do request
if method == 'get':
data, info = account.get_request(url, parse_json_result=False, fail_on_error=False)
elif method == 'post':
changed = True # only POSTs can change
data, info = account.send_signed_request(url, to_bytes(module.params['content']), parse_json_result=False, encode_payload=False)
# Update results
result.update(dict(
headers=info,
output_text=to_native(data),
))
# See if we can parse the result as JSON
try:
result['output_json'] = json.loads(data)
except Exception as dummy:
pass
# Fail if error was returned
if fail_on_acme_error and info['status'] >= 400:
raise ModuleFailException("ACME request failed: CODE: {0} RESULT: {1}".format(info['status'], data))
# Done!
module.exit_json(changed=changed, **result)
except ModuleFailException as e:
e.do_fail(module, **result)
if __name__ == '__main__':
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
334,
67,
9,
14894,
7949,
20528,
481,
265,
15859,
8593,
771,
317,
1949,
265,
15859,
9,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
363,
6577,
363,
275,
730,
421,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
936,
421,
199,
8948,
275,
519,
2344,
199,
2595,
199,
578,
26,
32433,
63,
10955,
199,
2502,
26,
298,
3456,
20528,
481,
265,
15859,
8593,
771,
317,
1949,
265,
15859,
2924,
199,
1023,
63,
3270,
26,
298,
18,
14,
24,
2,
199,
3612,
63,
1802,
26,
10217,
4125,
4145,
370,
376,
6570,
3635,
1654,
199,
1802,
26,
2043,
446,
298,
19780,
370,
3222,
4125,
4145,
370,
376,
6570,
3635,
1654,
543,
314,
489,
491,
8,
1348,
3635,
4113,
12,
2859,
921,
2537,
14,
15799,
14,
1308,
15,
1360,
15,
8973,
12593,
21,
395,
489,
1314,
365,
3748,
701,
445,
2822,
4066,
465,
491,
8,
15314,
1159,
3447,
4997,
12,
2859,
921,
2723,
31561,
14,
1308,
15,
17617,
2043,
446,
298,
2765,
859,
883,
506,
1202,
370,
3105,
3405,
5897,
1056,
12454,
12,
489,
367,
2893,
1380,
603,
8,
18107,
63,
6999,
9,
6918,
503,
655,
16558,
282,
5160,
1314,
489,
1265,
13809,
370,
315,
27174,
323,
2122,
2043,
446,
298,
1918,
859,
883,
2597,
506,
1202,
370,
5370,
2879,
4534,
402,
376,
6570,
3635,
8037,
489,
1314,
787,
440,
5966,
3748,
701,
314,
2622,
6570,
3635,
4621,
2122,
199,
5983,
26,
2043,
446,
298,
1918,
473,
8,
2048,
63,
2302,
9,
945,
1471,
506,
2013,
367,
7684,
15082,
489,
6570,
3635,
373,
18,
4145,
334,
2590,
282,
445,
8,
1222,
13,
2048,
9,
1056,
17617,
2043,
446,
298,
10369,
314,
445,
8,
4853,
9,
4744,
12,
603,
8,
18107,
63,
10955,
9,
883,
506,
1202,
370,
5370,
5341,
489,
6570,
3635,
4145,
1928,
314,
1929,
402,
3575,
282,
15695,
14,
2104,
2893,
12,
314,
489,
2569,
1414,
9619,
2310,
314,
6570,
3635,
2933,
543,
2870,
413,
687,
12230,
1159,
3447,
4997,
489,
334,
405,
12848,
445,
29478,
515,
15,
475,
15,
498,
9,
365,
314,
3211,
5726,
2933,
790,
304,
489,
445,
8,
4853,
11667,
446,
77,
32433,
63,
10955,
446,
65,
8441,
2048,
63,
498,
63,
2164,
13043,
515,
15,
475,
15,
498,
489,
32433,
63,
3619,
29,
2859,
921,
18107,
13,
86,
996,
14,
1246,
14,
2723,
31561,
14,
1308,
15,
3619,
32433,
63,
1023,
29,
18,
489,
2933,
63,
2302,
29,
2859,
921,
18107,
13,
86,
996,
14,
1246,
14,
2723,
31561,
14,
1308,
15,
18107,
15,
23015,
15,
17,
1083,
29,
362,
489,
1166,
29,
2859,
921,
18107,
13,
86,
996,
14,
1246,
14,
2723,
31561,
14,
1308,
15,
18107,
15,
23015,
15,
17,
60,
531,
2,
199,
3239,
12344,
26,
523,
446,
536,
26,
9195,
3889,
12904,
8259,
9711,
334,
1348,
3635,
9,
272,
1369,
26,
710,
8929,
402,
314,
6570,
3635,
4113,
334,
14468,
1695,
15722,
680,
272,
2142,
26,
4178,
921,
2537,
14,
15799,
14,
1308,
15,
1360,
15,
8973,
12593,
21,
523,
446,
536,
26,
6570,
3635,
12213,
12112,
9060,
2799,
8537,
13282,
272,
1369,
26,
710,
1453,
11872,
8929,
402,
314,
445,
8,
9945,
13,
279,
4812,
13,
614,
9,
14929,
14,
272,
2142,
26,
4178,
921,
2537,
14,
15799,
14,
1308,
15,
1360,
15,
7185,
13,
15799,
13,
18107,
13,
9945,
13,
279,
4812,
13,
1717,
199,
11036,
63,
9970,
63,
7677,
26,
523,
446,
32433,
199,
1419,
26,
523,
1166,
26,
272,
1369,
26,
489,
446,
298,
1918,
2851,
370,
3222,
314,
1056,
370,
2122,
489,
446,
298,
13757,
506,
2013,
340,
473,
8,
765,
9,
365,
440,
445,
8,
3619,
13,
2118,
17617,
272,
730,
26,
620,
523,
1083,
26,
272,
1369,
26,
489,
446,
298,
1918,
1083,
370,
675,
370,
2879,
314,
1627,
2851,
641,
314,
6570,
3635,
1654,
2122,
489,
446,
298,
1918,
574,
445,
8,
1932,
9,
24956,
376,
15082,
8761,
1056,
14,
710,
1564,
268,
1471,
506,
2013,
315,
314,
473,
8,
1317,
9,
945,
2122,
489,
446,
298,
1918,
574,
445,
8,
362,
9,
24956,
376,
15082,
8761,
13,
305,
13,
2970,
1056,
367,
6570,
3635,
373,
18,
12,
268,
436,
282,
5578,
9576,
1056,
367,
6570,
3635,
373,
17,
2122,
489,
446,
298,
1918,
574,
445,
8,
3619,
13,
2118,
9,
1454,
9619,
2310,
314,
2082,
12,
1928,
9689,
268,
282,
1056,
2122,
272,
730,
26,
620,
272,
849,
26,
664,
272,
3415,
26,
272,
446,
664,
272,
446,
2963,
272,
446,
2082,
13,
2118,
523,
1564,
26,
272,
1369,
26,
489,
446,
298,
2493,
5737,
4840,
909,
1314,
911,
506,
4847,
465,
314,
1564,
340,
473,
8,
765,
9,
268,
365,
445,
8,
1932,
17617,
489,
446,
298,
8030,
1380,
473,
8,
765,
9,
365,
445,
8,
1932,
395,
436,
440,
4370,
4257,
2122,
272,
730,
26,
620,
523,
2449,
63,
265,
63,
18107,
63,
705,
26,
272,
1369,
26,
489,
446,
298,
3917,
473,
8,
765,
9,
365,
445,
8,
1932,
9,
503,
445,
8,
362,
395,
1852,
314,
859,
2449,
315,
1930,
376,
6570,
3635,
268,
1125,
365,
2138,
2122,
272,
730,
26,
2155,
272,
849,
26,
9456,
199,
2344,
199,
199,
8918,
275,
519,
2344,
199,
13,
536,
26,
2372,
2082,
523,
32433,
63,
10955,
26,
272,
32433,
63,
3619,
26,
4178,
921,
18107,
13,
26840,
13,
86,
996,
14,
1246,
14,
2723,
31561,
14,
1308,
15,
3619,
272,
32433,
63,
1023,
26,
499,
272,
1083,
26,
2082,
13,
2118,
523,
2274,
26,
2082,
199,
199,
13,
536,
26,
2790,
376,
2933,
523,
32433,
63,
10955,
26,
272,
32433,
63,
3619,
26,
4178,
921,
18107,
13,
26840,
13,
86,
996,
14,
1246,
14,
2723,
31561,
14,
1308,
15,
3619,
272,
32433,
63,
1023,
26,
499,
272,
2933,
63,
498,
63,
2164,
26
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
334,
67,
9,
14894,
7949,
20528,
481,
265,
15859,
8593,
771,
317,
1949,
265,
15859,
9,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
363,
6577,
363,
275,
730,
421,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
936,
421,
199,
8948,
275,
519,
2344,
199,
2595,
199,
578,
26,
32433,
63,
10955,
199,
2502,
26,
298,
3456,
20528,
481,
265,
15859,
8593,
771,
317,
1949,
265,
15859,
2924,
199,
1023,
63,
3270,
26,
298,
18,
14,
24,
2,
199,
3612,
63,
1802,
26,
10217,
4125,
4145,
370,
376,
6570,
3635,
1654,
199,
1802,
26,
2043,
446,
298,
19780,
370,
3222,
4125,
4145,
370,
376,
6570,
3635,
1654,
543,
314,
489,
491,
8,
1348,
3635,
4113,
12,
2859,
921,
2537,
14,
15799,
14,
1308,
15,
1360,
15,
8973,
12593,
21,
395,
489,
1314,
365,
3748,
701,
445,
2822,
4066,
465,
491,
8,
15314,
1159,
3447,
4997,
12,
2859,
921,
2723,
31561,
14,
1308,
15,
17617,
2043,
446,
298,
2765,
859,
883,
506,
1202,
370,
3105,
3405,
5897,
1056,
12454,
12,
489,
367,
2893,
1380,
603,
8,
18107,
63,
6999,
9,
6918,
503,
655,
16558,
282,
5160,
1314,
489,
1265,
13809,
370,
315,
27174,
323,
2122,
2043,
446,
298,
1918,
859,
883,
2597,
506,
1202,
370,
5370,
2879,
4534,
402,
376,
6570,
3635,
8037,
489,
1314,
787,
440,
5966,
3748,
701,
314,
2622,
6570,
3635,
4621,
2122,
199,
5983,
26,
2043,
446,
298,
1918,
473,
8,
2048,
63,
2302,
9,
945,
1471,
506,
2013,
367,
7684,
15082,
489,
6570,
3635,
373,
18,
4145,
334,
2590,
282,
445,
8,
1222,
13,
2048,
9,
1056,
17617,
2043,
446,
298,
10369,
314,
445,
8,
4853,
9,
4744,
12,
603,
8,
18107,
63,
10955,
9,
883,
506,
1202,
370,
5370,
5341,
489,
6570,
3635,
4145,
1928,
314,
1929,
402,
3575,
282,
15695,
14,
2104,
2893,
12,
314,
489,
2569,
1414,
9619,
2310,
314,
6570,
3635,
2933,
543,
2870,
413,
687,
12230,
1159,
3447,
4997,
489,
334,
405,
12848,
445,
29478,
515,
15,
475,
15,
498,
9,
365,
314,
3211,
5726,
2933,
790,
304,
489,
445,
8,
4853,
11667,
446,
77,
32433,
63,
10955,
446,
65,
8441,
2048,
63,
498,
63,
2164,
13043,
515,
15,
475,
15,
498,
489,
32433,
63,
3619,
29,
2859,
921,
18107,
13,
86,
996,
14,
1246,
14,
2723,
31561,
14,
1308,
15,
3619,
32433,
63,
1023,
29,
18,
489,
2933,
63,
2302,
29,
2859,
921,
18107,
13,
86,
996,
14,
1246,
14,
2723,
31561,
14,
1308,
15,
18107,
15,
23015,
15,
17,
1083,
29,
362,
489,
1166,
29,
2859,
921,
18107,
13,
86,
996,
14,
1246,
14,
2723,
31561,
14,
1308,
15,
18107,
15,
23015,
15,
17,
60,
531,
2,
199,
3239,
12344,
26,
523,
446,
536,
26,
9195,
3889,
12904,
8259,
9711,
334,
1348,
3635,
9,
272,
1369,
26,
710,
8929,
402,
314,
6570,
3635,
4113,
334,
14468,
1695,
15722,
680,
272,
2142,
26,
4178,
921,
2537,
14,
15799,
14,
1308,
15,
1360,
15,
8973,
12593,
21,
523,
446,
536,
26,
6570,
3635,
12213,
12112,
9060,
2799,
8537,
13282,
272,
1369,
26,
710,
1453,
11872,
8929,
402,
314,
445,
8,
9945,
13,
279,
4812,
13,
614,
9,
14929,
14,
272,
2142,
26,
4178,
921,
2537,
14,
15799,
14,
1308,
15,
1360,
15,
7185,
13,
15799,
13,
18107,
13,
9945,
13,
279,
4812,
13,
1717,
199,
11036,
63,
9970,
63,
7677,
26,
523,
446,
32433,
199,
1419,
26,
523,
1166,
26,
272,
1369,
26,
489,
446,
298,
1918,
2851,
370,
3222,
314,
1056,
370,
2122,
489,
446,
298,
13757,
506,
2013,
340,
473,
8,
765,
9,
365,
440,
445,
8,
3619,
13,
2118,
17617,
272,
730,
26,
620,
523,
1083,
26,
272,
1369,
26,
489,
446,
298,
1918,
1083,
370,
675,
370,
2879,
314,
1627,
2851,
641,
314,
6570,
3635,
1654,
2122,
489,
446,
298,
1918,
574,
445,
8,
1932,
9,
24956,
376,
15082,
8761,
1056,
14,
710,
1564,
268,
1471,
506,
2013,
315,
314,
473,
8,
1317,
9,
945,
2122,
489,
446,
298,
1918,
574,
445,
8,
362,
9,
24956,
376,
15082,
8761,
13,
305,
13,
2970,
1056,
367,
6570,
3635,
373,
18,
12,
268,
436,
282,
5578,
9576,
1056,
367,
6570,
3635,
373,
17,
2122,
489,
446,
298,
1918,
574,
445,
8,
3619,
13,
2118,
9,
1454,
9619,
2310,
314,
2082,
12,
1928,
9689,
268,
282,
1056,
2122,
272,
730,
26,
620,
272,
849,
26,
664,
272,
3415,
26,
272,
446,
664,
272,
446,
2963,
272,
446,
2082,
13,
2118,
523,
1564,
26,
272,
1369,
26,
489,
446,
298,
2493,
5737,
4840,
909,
1314,
911,
506,
4847,
465,
314,
1564,
340,
473,
8,
765,
9,
268,
365,
445,
8,
1932,
17617,
489,
446,
298,
8030,
1380,
473,
8,
765,
9,
365,
445,
8,
1932,
395,
436,
440,
4370,
4257,
2122,
272,
730,
26,
620,
523,
2449,
63,
265,
63,
18107,
63,
705,
26,
272,
1369,
26,
489,
446,
298,
3917,
473,
8,
765,
9,
365,
445,
8,
1932,
9,
503,
445,
8,
362,
395,
1852,
314,
859,
2449,
315,
1930,
376,
6570,
3635,
268,
1125,
365,
2138,
2122,
272,
730,
26,
2155,
272,
849,
26,
9456,
199,
2344,
199,
199,
8918,
275,
519,
2344,
199,
13,
536,
26,
2372,
2082,
523,
32433,
63,
10955,
26,
272,
32433,
63,
3619,
26,
4178,
921,
18107,
13,
26840,
13,
86,
996,
14,
1246,
14,
2723,
31561,
14,
1308,
15,
3619,
272,
32433,
63,
1023,
26,
499,
272,
1083,
26,
2082,
13,
2118,
523,
2274,
26,
2082,
199,
199,
13,
536,
26,
2790,
376,
2933,
523,
32433,
63,
10955,
26,
272,
32433,
63,
3619,
26,
4178,
921,
18107,
13,
26840,
13,
86,
996,
14,
1246,
14,
2723,
31561,
14,
1308,
15,
3619,
272,
32433,
63,
1023,
26,
499,
272,
2933,
63,
498,
63,
2164,
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,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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
] |
garrettjonesgoogle/api-client-staging
|
generated/python/gapic-google-iam-admin-v1/google/cloud/gapic/iam_admin/v1/enums.py
|
8
|
2472
|
# Copyright 2016 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Wrappers for protocol buffer enum types."""
class ServiceAccountKeyAlgorithm(object):
"""
Supported key algorithms.
Attributes:
KEY_ALG_UNSPECIFIED (int): An unspecified key algorithm.
KEY_ALG_RSA_1024 (int): 1k RSA Key.
KEY_ALG_RSA_2048 (int): 2k RSA Key.
"""
KEY_ALG_UNSPECIFIED = 0
KEY_ALG_RSA_1024 = 1
KEY_ALG_RSA_2048 = 2
class ServiceAccountPrivateKeyType(object):
"""
Supported private key output formats.
Attributes:
TYPE_UNSPECIFIED (int): Unspecified. Equivalent to ``TYPE_GOOGLE_CREDENTIALS_FILE``.
TYPE_PKCS12_FILE (int): PKCS12 format.
The password for the PKCS12 file is ``notasecret``.
For more information, see https://tools.ietf.org/html/rfc7292.
TYPE_GOOGLE_CREDENTIALS_FILE (int): Google Credentials File format.
"""
TYPE_UNSPECIFIED = 0
TYPE_PKCS12_FILE = 1
TYPE_GOOGLE_CREDENTIALS_FILE = 2
class ServiceAccountPublicKeyType(object):
"""
Supported public key output formats.
Attributes:
TYPE_NONE (int): Unspecified. Returns nothing here.
TYPE_X509_PEM_FILE (int): X509 PEM format.
TYPE_RAW_PUBLIC_KEY (int): Raw public key.
"""
TYPE_NONE = 0
TYPE_X509_PEM_FILE = 1
TYPE_RAW_PUBLIC_KEY = 2
class ListServiceAccountKeysRequest(object):
class KeyType(object):
"""
``KeyType`` filters to selectively retrieve certain varieties
of keys.
Attributes:
KEY_TYPE_UNSPECIFIED (int): Unspecified key type. The presence of this in the
message will immediately result in an error.
USER_MANAGED (int): User-managed keys (managed and rotated by the user).
SYSTEM_MANAGED (int): System-managed keys (managed and rotated by Google).
"""
KEY_TYPE_UNSPECIFIED = 0
USER_MANAGED = 1
SYSTEM_MANAGED = 2
|
bsd-3-clause
|
[
3,
1898,
7800,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
624,
4590,
83,
367,
4113,
3335,
4952,
2943,
1041,
421,
199,
533,
7591,
6009,
1197,
11570,
8,
785,
304,
272,
408,
272,
26167,
790,
18036,
14,
339,
9382,
26,
489,
9301,
63,
26613,
63,
1734,
22917,
19679,
334,
442,
304,
1626,
21994,
790,
5563,
14,
489,
9301,
63,
26613,
63,
12115,
63,
7727,
334,
442,
304,
413,
75,
18471,
2606,
14,
489,
9301,
63,
26613,
63,
12115,
63,
18343,
334,
442,
304,
499,
75,
18471,
2606,
14,
272,
408,
272,
9301,
63,
26613,
63,
1734,
22917,
19679,
275,
378,
272,
9301,
63,
26613,
63,
12115,
63,
7727,
275,
413,
272,
9301,
63,
26613,
63,
12115,
63,
18343,
275,
499,
421,
199,
533,
7591,
6009,
31757,
804,
8,
785,
304,
272,
408,
272,
26167,
5726,
790,
1072,
6752,
14,
339,
9382,
26,
489,
11511,
63,
1734,
22917,
19679,
334,
442,
304,
15254,
28387,
14,
24228,
370,
1124,
2711,
63,
24243,
63,
30553,
8246,
51,
63,
3817,
4345,
489,
11511,
63,
29247,
713,
63,
3817,
334,
442,
304,
32040,
713,
1475,
14,
267,
710,
2505,
367,
314,
32040,
713,
570,
365,
1124,
1397,
482,
3740,
4345,
267,
2104,
1655,
2556,
12,
1937,
4178,
921,
2537,
14,
15799,
14,
1308,
15,
1360,
15,
8973,
23,
17027,
14,
489,
11511,
63,
24243,
63,
30553,
8246,
51,
63,
3817,
334,
442,
304,
4475,
23934,
3814,
1475,
14,
272,
408,
272,
11511,
63,
1734,
22917,
19679,
275,
378,
272,
11511,
63,
29247,
713,
63,
3817,
275,
413,
272,
11511,
63,
24243,
63,
30553,
8246,
51,
63,
3817,
275,
499,
421,
199,
533,
7591,
6009,
26238,
804,
8,
785,
304,
272,
408,
272,
26167,
4575,
790,
1072,
6752,
14,
339,
9382,
26,
489,
11511,
63,
9185,
334,
442,
304,
15254,
28387,
14,
1803,
6548,
2348,
14,
489,
11511,
63,
56,
6576,
63,
24160,
63,
3817,
334,
442,
304,
1323,
6576,
25957,
1475,
14,
489,
11511,
63,
4307,
63,
19476,
63,
3078,
334,
442,
304,
13480,
4575,
790,
14,
272,
408,
272,
11511,
63,
9185,
275,
378,
272,
11511,
63,
56,
6576,
63,
24160,
63,
3817,
275,
413,
272,
11511,
63,
4307,
63,
19476,
63,
3078,
275,
499,
421,
199,
533,
3820,
3167,
6009,
6340,
2017,
8,
785,
304,
272,
1021,
2606,
804,
8,
785,
304,
267,
408,
267,
1124,
1197,
804,
1040,
4766,
370,
542,
10251,
9462,
8044,
9842,
4172,
69,
1417,
267,
402,
2883,
14,
398,
9382,
26,
881,
9301,
63,
2711,
63,
1734,
22917,
19679,
334,
442,
304,
15254,
28387,
790,
730,
14,
710,
20024,
402,
642,
315,
314,
288,
1245,
911,
9939,
754,
315,
376,
1125,
14,
881,
13044,
63,
20600,
1149,
334,
442,
304,
2876,
13,
11122,
2883,
334,
11122,
436,
7513,
972,
701,
314,
922,
680,
881,
20859,
63,
20600,
1149,
334,
442,
304,
6187,
13,
11122,
2883,
334,
11122,
436,
7513,
972,
701,
4475,
680,
267,
408,
267,
9301,
63,
2711,
63,
1734,
22917,
19679,
275,
378,
267,
13044,
63,
20600,
1149,
275,
413,
267,
20859,
63,
20600,
1149,
275,
499,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
7800,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
624,
4590,
83,
367,
4113,
3335,
4952,
2943,
1041,
421,
199,
533,
7591,
6009,
1197,
11570,
8,
785,
304,
272,
408,
272,
26167,
790,
18036,
14,
339,
9382,
26,
489,
9301,
63,
26613,
63,
1734,
22917,
19679,
334,
442,
304,
1626,
21994,
790,
5563,
14,
489,
9301,
63,
26613,
63,
12115,
63,
7727,
334,
442,
304,
413,
75,
18471,
2606,
14,
489,
9301,
63,
26613,
63,
12115,
63,
18343,
334,
442,
304,
499,
75,
18471,
2606,
14,
272,
408,
272,
9301,
63,
26613,
63,
1734,
22917,
19679,
275,
378,
272,
9301,
63,
26613,
63,
12115,
63,
7727,
275,
413,
272,
9301,
63,
26613,
63,
12115,
63,
18343,
275,
499,
421,
199,
533,
7591,
6009,
31757,
804,
8,
785,
304,
272,
408,
272,
26167,
5726,
790,
1072,
6752,
14,
339,
9382,
26,
489,
11511,
63,
1734,
22917,
19679,
334,
442,
304,
15254,
28387,
14,
24228,
370,
1124,
2711,
63,
24243,
63,
30553,
8246,
51,
63,
3817,
4345,
489,
11511,
63,
29247,
713,
63,
3817,
334,
442,
304,
32040,
713,
1475,
14,
267,
710,
2505,
367,
314,
32040,
713,
570,
365,
1124,
1397,
482,
3740,
4345,
267,
2104,
1655,
2556,
12,
1937,
4178,
921,
2537,
14,
15799,
14,
1308,
15,
1360,
15,
8973,
23,
17027,
14,
489,
11511,
63,
24243,
63,
30553,
8246,
51,
63,
3817,
334,
442,
304,
4475,
23934,
3814,
1475,
14,
272,
408,
272,
11511,
63,
1734,
22917,
19679,
275,
378,
272,
11511,
63,
29247,
713,
63,
3817,
275,
413,
272,
11511,
63,
24243,
63,
30553,
8246,
51,
63,
3817,
275,
499,
421,
199,
533,
7591,
6009,
26238,
804,
8,
785,
304,
272,
408,
272,
26167,
4575,
790,
1072,
6752,
14,
339,
9382,
26,
489,
11511,
63,
9185,
334,
442,
304,
15254,
28387,
14,
1803,
6548,
2348,
14,
489,
11511,
63,
56,
6576,
63,
24160,
63,
3817,
334,
442,
304,
1323,
6576,
25957,
1475,
14,
489,
11511,
63,
4307,
63,
19476,
63,
3078,
334,
442,
304,
13480,
4575,
790,
14,
272,
408,
272,
11511,
63,
9185,
275,
378,
272,
11511,
63,
56,
6576,
63,
24160,
63,
3817,
275,
413,
272,
11511,
63,
4307,
63,
19476,
63,
3078,
275,
499,
421,
199,
533,
3820,
3167,
6009,
6340,
2017,
8,
785,
304,
272,
1021,
2606,
804,
8,
785,
304,
267,
408,
267,
1124,
1197,
804,
1040,
4766,
370,
542,
10251,
9462,
8044,
9842,
4172,
69,
1417,
267,
402,
2883,
14,
398,
9382,
26,
881,
9301,
63,
2711,
63,
1734,
22917,
19679,
334,
442,
304,
15254,
28387,
790,
730,
14,
710,
20024,
402,
642,
315,
314,
288,
1245,
911,
9939,
754,
315,
376,
1125,
14,
881,
13044,
63,
20600,
1149,
334,
442,
304,
2876,
13,
11122,
2883,
334,
11122,
436,
7513,
972,
701,
314,
922,
680,
881,
20859,
63,
20600,
1149,
334,
442,
304,
6187,
13,
11122,
2883,
334,
11122,
436,
7513,
972,
701,
4475,
680,
267,
408,
267,
9301,
63,
2711,
63,
1734,
22917,
19679,
275,
378,
267,
13044,
63,
20600,
1149,
275,
413,
267,
20859,
63,
20600,
1149,
275,
499,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
chirilo/remo
|
vendor-local/lib/python/rest_framework/authentication.py
|
8
|
5945
|
"""
Provides various authentication policies.
"""
from __future__ import unicode_literals
import base64
from django.contrib.auth import authenticate
from django.middleware.csrf import CsrfViewMiddleware
from django.utils.translation import ugettext_lazy as _
from rest_framework import exceptions, HTTP_HEADER_ENCODING
from rest_framework.authtoken.models import Token
def get_authorization_header(request):
"""
Return request's 'Authorization:' header, as a bytestring.
Hide some test client ickyness where the header can be unicode.
"""
auth = request.META.get('HTTP_AUTHORIZATION', b'')
if isinstance(auth, type('')):
# Work around django test client oddness
auth = auth.encode(HTTP_HEADER_ENCODING)
return auth
class CSRFCheck(CsrfViewMiddleware):
def _reject(self, request, reason):
# Return the failure reason instead of an HttpResponse
return reason
class BaseAuthentication(object):
"""
All authentication classes should extend BaseAuthentication.
"""
def authenticate(self, request):
"""
Authenticate the request and return a two-tuple of (user, token).
"""
raise NotImplementedError(".authenticate() must be overridden.")
def authenticate_header(self, request):
"""
Return a string to be used as the value of the `WWW-Authenticate`
header in a `401 Unauthenticated` response, or `None` if the
authentication scheme should return `403 Permission Denied` responses.
"""
pass
class BasicAuthentication(BaseAuthentication):
"""
HTTP Basic authentication against username/password.
"""
www_authenticate_realm = 'api'
def authenticate(self, request):
"""
Returns a `User` if a correct username and password have been supplied
using HTTP Basic authentication. Otherwise returns `None`.
"""
auth = get_authorization_header(request).split()
if not auth or auth[0].lower() != b'basic':
return None
if len(auth) == 1:
msg = _('Invalid basic header. No credentials provided.')
raise exceptions.AuthenticationFailed(msg)
elif len(auth) > 2:
msg = _('Invalid basic header. Credentials string should not contain spaces.')
raise exceptions.AuthenticationFailed(msg)
try:
auth_parts = base64.b64decode(auth[1]).decode(HTTP_HEADER_ENCODING).partition(':')
except (TypeError, UnicodeDecodeError):
msg = _('Invalid basic header. Credentials not correctly base64 encoded.')
raise exceptions.AuthenticationFailed(msg)
userid, password = auth_parts[0], auth_parts[2]
return self.authenticate_credentials(userid, password)
def authenticate_credentials(self, userid, password):
"""
Authenticate the userid and password against username and password.
"""
user = authenticate(username=userid, password=password)
if user is None:
raise exceptions.AuthenticationFailed(_('Invalid username/password.'))
if not user.is_active:
raise exceptions.AuthenticationFailed(_('User inactive or deleted.'))
return (user, None)
def authenticate_header(self, request):
return 'Basic realm="%s"' % self.www_authenticate_realm
class SessionAuthentication(BaseAuthentication):
"""
Use Django's session framework for authentication.
"""
def authenticate(self, request):
"""
Returns a `User` if the request session currently has a logged in user.
Otherwise returns `None`.
"""
# Get the underlying HttpRequest object
request = request._request
user = getattr(request, 'user', None)
# Unauthenticated, CSRF validation not required
if not user or not user.is_active:
return None
self.enforce_csrf(request)
# CSRF passed with authenticated user
return (user, None)
def enforce_csrf(self, request):
"""
Enforce CSRF validation for session based authentication.
"""
reason = CSRFCheck().process_view(request, None, (), {})
if reason:
# CSRF failed, bail with explicit error message
raise exceptions.PermissionDenied('CSRF Failed: %s' % reason)
class TokenAuthentication(BaseAuthentication):
"""
Simple token based authentication.
Clients should authenticate by passing the token key in the "Authorization"
HTTP header, prepended with the string "Token ". For example:
Authorization: Token 401f7ac837da42b97f613d789819ff93537bee6a
"""
model = Token
"""
A custom token model may be used, but must have the following properties.
* key -- The string identifying the token
* user -- The user to which the token belongs
"""
def authenticate(self, request):
auth = get_authorization_header(request).split()
if not auth or auth[0].lower() != b'token':
return None
if len(auth) == 1:
msg = _('Invalid token header. No credentials provided.')
raise exceptions.AuthenticationFailed(msg)
elif len(auth) > 2:
msg = _('Invalid token header. Token string should not contain spaces.')
raise exceptions.AuthenticationFailed(msg)
return self.authenticate_credentials(auth[1])
def authenticate_credentials(self, key):
try:
token = self.model.objects.select_related('user').get(key=key)
except self.model.DoesNotExist:
raise exceptions.AuthenticationFailed(_('Invalid token.'))
if not token.user.is_active:
raise exceptions.AuthenticationFailed(_('User inactive or deleted.'))
return (token.user, token)
def authenticate_header(self, request):
return 'Token'
|
bsd-3-clause
|
[
624,
199,
17473,
7750,
6299,
14118,
14,
199,
624,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
646,
1300,
772,
199,
504,
1639,
14,
2828,
14,
1178,
492,
12895,
199,
504,
1639,
14,
5754,
14,
10088,
492,
22145,
25322,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
485,
199,
504,
4618,
63,
4857,
492,
4967,
12,
3101,
63,
7311,
63,
16314,
199,
504,
4618,
63,
4857,
14,
1178,
1418,
14,
992,
492,
8767,
421,
199,
318,
664,
63,
15846,
63,
1291,
8,
1069,
304,
272,
408,
272,
1432,
1056,
1159,
283,
11626,
4881,
1406,
12,
465,
282,
23888,
14,
339,
869,
2655,
2005,
511,
1890,
284,
346,
89,
4171,
2382,
314,
1406,
883,
506,
2649,
14,
272,
408,
272,
1790,
275,
1056,
14,
10614,
14,
362,
360,
2856,
63,
25303,
2594,
297,
330,
17483,
272,
340,
1228,
8,
1178,
12,
730,
360,
8109,
267,
327,
9361,
6818,
1639,
511,
1890,
16699,
4171,
267,
1790,
275,
1790,
14,
2143,
8,
2856,
63,
7311,
63,
16314,
9,
272,
372,
1790,
421,
199,
533,
22468,
1799,
8,
13912,
25322,
304,
272,
347,
485,
16857,
8,
277,
12,
1056,
12,
4499,
304,
267,
327,
1432,
314,
5988,
4499,
3140,
402,
376,
6183,
267,
372,
4499,
421,
199,
533,
3523,
10348,
8,
785,
304,
272,
408,
272,
2900,
6299,
3992,
1077,
12247,
3523,
10348,
14,
272,
408,
339,
347,
12895,
8,
277,
12,
1056,
304,
267,
408,
267,
3590,
7672,
314,
1056,
436,
372,
282,
2877,
13,
2960,
402,
334,
751,
12,
1526,
680,
267,
408,
267,
746,
4279,
9520,
13975,
342,
1471,
506,
10087,
2685,
339,
347,
12895,
63,
1291,
8,
277,
12,
1056,
304,
267,
408,
267,
1432,
282,
1059,
370,
506,
1202,
465,
314,
574,
402,
314,
658,
27084,
13,
21476,
64,
267,
1406,
315,
282,
658,
8854,
1910,
12177,
64,
1177,
12,
503,
658,
403,
64,
340,
314,
267,
6299,
5687,
1077,
372,
658,
13353,
8779,
25187,
5299,
64,
9320,
14,
267,
408,
267,
986,
421,
199,
533,
10082,
10348,
8,
1563,
10348,
304,
272,
408,
272,
3101,
10082,
6299,
6169,
3434,
15,
2060,
14,
272,
408,
272,
20732,
63,
13975,
63,
7728,
275,
283,
1246,
7,
339,
347,
12895,
8,
277,
12,
1056,
304,
267,
408,
267,
1803,
282,
658,
1899,
64,
340,
282,
3211,
3434,
436,
2505,
1172,
2757,
6841,
267,
1808,
3101,
10082,
6299,
14,
221,
6630,
2529,
658,
403,
2313,
267,
408,
267,
1790,
275,
664,
63,
15846,
63,
1291,
8,
1069,
680,
1294,
342,
398,
340,
440,
1790,
503,
1790,
59,
16,
1055,
2325,
342,
1137,
330,
7,
4316,
356,
288,
372,
488,
398,
340,
822,
8,
1178,
9,
508,
413,
26,
288,
1499,
275,
4018,
3364,
5678,
1406,
14,
3091,
6235,
2741,
2659,
288,
746,
4967,
14,
10348,
4276,
8,
1328,
9,
267,
916,
822,
8,
1178,
9,
690,
499,
26,
288,
1499,
275,
4018,
3364,
5678,
1406,
14,
23934,
1059,
1077,
440,
1395,
7883,
2659,
288,
746,
4967,
14,
10348,
4276,
8,
1328,
9,
398,
862,
26,
288,
1790,
63,
4181,
275,
1300,
772,
14,
66,
772,
2708,
8,
1178,
59,
17,
6575,
2708,
8,
2856,
63,
7311,
63,
16314,
680,
5312,
11633,
267,
871,
334,
4333,
12,
18965,
304,
288,
1499,
275,
4018,
3364,
5678,
1406,
14,
23934,
440,
6657,
1300,
772,
5737,
2659,
288,
746,
4967,
14,
10348,
4276,
8,
1328,
9,
398,
25580,
12,
2505,
275,
1790,
63,
4181,
59,
16,
467,
1790,
63,
4181,
59,
18,
61,
267,
372,
291,
14,
13975,
63,
6942,
8,
19737,
12,
2505,
9,
339,
347,
12895,
63,
6942,
8,
277,
12,
25580,
12,
2505,
304,
267,
408,
267,
3590,
7672,
314,
25580,
436,
2505,
6169,
3434,
436,
2505,
14,
267,
408,
267,
922,
275,
12895,
8,
2473,
29,
19737,
12,
2505,
29,
2060,
9,
398,
340,
922,
365,
488,
26,
288,
746,
4967,
14,
10348,
4276,
6723,
3364,
3434,
15,
2060,
12459,
398,
340,
440,
922,
14,
374,
63,
2682,
26,
288,
746,
4967,
14,
10348,
4276,
6723,
1899,
21325,
503,
5463,
12459,
398,
372,
334,
751,
12,
488,
9,
339,
347,
12895,
63,
1291,
8,
277,
12,
1056,
304,
267,
372,
283,
6845,
10482,
5961,
83,
4507,
450,
291,
14,
1544,
63,
13975,
63,
7728,
421,
199,
533,
8596,
10348,
8,
1563,
10348,
304,
272,
408,
272,
3645,
5634,
1159,
2351,
10059,
367,
6299,
14,
272,
408,
339,
347,
12895,
8,
277,
12,
1056,
304,
267,
408,
267,
1803,
282,
658,
1899,
64,
340,
314,
1056,
2351,
5544,
965,
282,
10367,
315,
922,
14,
267,
6630,
2529,
658,
403,
2313,
267,
408,
398,
327,
2372,
314,
8793,
20730,
909,
267,
1056,
275,
1056,
423,
1069,
267,
922,
275,
2519,
8,
1069,
12,
283,
751,
297,
488,
9,
398,
327,
1910,
12177,
12,
22468,
6411,
440,
1415,
267,
340,
440,
922,
503,
440,
922,
14,
374,
63,
2682,
26,
288,
372,
488,
398,
291,
14,
19817,
63,
10088,
8,
1069,
9,
398,
327,
22468,
3032,
543,
15082,
922,
267,
372,
334,
751,
12,
488,
9,
339,
347,
15814,
63,
10088,
8,
277,
12,
1056,
304,
267,
408,
267,
3447,
3990,
22468,
6411,
367,
2351,
4079,
6299,
14,
267,
408,
267,
4499,
275,
22468,
1799,
1252,
1412,
63,
1345,
8,
1069,
12,
488,
12,
11969,
5009,
267,
340,
4499,
26,
288,
327,
22468,
3405,
12,
31571,
543,
5027,
1125,
1245,
288,
746,
4967,
14,
7980,
15729,
360,
26405,
16277,
26,
450,
83,
7,
450,
4499,
9,
421,
199,
533,
8767,
10348,
8,
1563,
10348,
304,
272,
408,
272,
5870,
1526,
4079,
6299,
14,
339,
6810,
83,
1077,
12895,
701,
9476,
314,
1526,
790,
315,
314,
298,
11626,
2,
272,
3101,
1406,
12,
20247,
543,
314,
1059,
298,
3264,
3680,
221,
2104,
2893,
26,
398,
21527,
26,
8767,
13952,
70,
23,
645,
24,
1401,
983,
2260,
66,
2576,
70,
30896,
68,
23,
13176,
1167,
556,
32258,
1401,
19446,
22,
65,
272,
408,
339,
1402,
275,
8767,
272,
408,
272,
437,
3537,
1526,
1402,
1443,
506,
1202,
12,
1325,
1471,
1172,
314,
2569,
4382,
14,
339,
627,
790,
1553,
710,
1059,
21119,
314,
1526,
272,
627,
922,
1553,
710,
922,
370,
1314,
314,
1526,
15006,
272,
408,
339,
347,
12895,
8,
277,
12,
1056,
304
] |
[
199,
17473,
7750,
6299,
14118,
14,
199,
624,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
646,
1300,
772,
199,
504,
1639,
14,
2828,
14,
1178,
492,
12895,
199,
504,
1639,
14,
5754,
14,
10088,
492,
22145,
25322,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
485,
199,
504,
4618,
63,
4857,
492,
4967,
12,
3101,
63,
7311,
63,
16314,
199,
504,
4618,
63,
4857,
14,
1178,
1418,
14,
992,
492,
8767,
421,
199,
318,
664,
63,
15846,
63,
1291,
8,
1069,
304,
272,
408,
272,
1432,
1056,
1159,
283,
11626,
4881,
1406,
12,
465,
282,
23888,
14,
339,
869,
2655,
2005,
511,
1890,
284,
346,
89,
4171,
2382,
314,
1406,
883,
506,
2649,
14,
272,
408,
272,
1790,
275,
1056,
14,
10614,
14,
362,
360,
2856,
63,
25303,
2594,
297,
330,
17483,
272,
340,
1228,
8,
1178,
12,
730,
360,
8109,
267,
327,
9361,
6818,
1639,
511,
1890,
16699,
4171,
267,
1790,
275,
1790,
14,
2143,
8,
2856,
63,
7311,
63,
16314,
9,
272,
372,
1790,
421,
199,
533,
22468,
1799,
8,
13912,
25322,
304,
272,
347,
485,
16857,
8,
277,
12,
1056,
12,
4499,
304,
267,
327,
1432,
314,
5988,
4499,
3140,
402,
376,
6183,
267,
372,
4499,
421,
199,
533,
3523,
10348,
8,
785,
304,
272,
408,
272,
2900,
6299,
3992,
1077,
12247,
3523,
10348,
14,
272,
408,
339,
347,
12895,
8,
277,
12,
1056,
304,
267,
408,
267,
3590,
7672,
314,
1056,
436,
372,
282,
2877,
13,
2960,
402,
334,
751,
12,
1526,
680,
267,
408,
267,
746,
4279,
9520,
13975,
342,
1471,
506,
10087,
2685,
339,
347,
12895,
63,
1291,
8,
277,
12,
1056,
304,
267,
408,
267,
1432,
282,
1059,
370,
506,
1202,
465,
314,
574,
402,
314,
658,
27084,
13,
21476,
64,
267,
1406,
315,
282,
658,
8854,
1910,
12177,
64,
1177,
12,
503,
658,
403,
64,
340,
314,
267,
6299,
5687,
1077,
372,
658,
13353,
8779,
25187,
5299,
64,
9320,
14,
267,
408,
267,
986,
421,
199,
533,
10082,
10348,
8,
1563,
10348,
304,
272,
408,
272,
3101,
10082,
6299,
6169,
3434,
15,
2060,
14,
272,
408,
272,
20732,
63,
13975,
63,
7728,
275,
283,
1246,
7,
339,
347,
12895,
8,
277,
12,
1056,
304,
267,
408,
267,
1803,
282,
658,
1899,
64,
340,
282,
3211,
3434,
436,
2505,
1172,
2757,
6841,
267,
1808,
3101,
10082,
6299,
14,
221,
6630,
2529,
658,
403,
2313,
267,
408,
267,
1790,
275,
664,
63,
15846,
63,
1291,
8,
1069,
680,
1294,
342,
398,
340,
440,
1790,
503,
1790,
59,
16,
1055,
2325,
342,
1137,
330,
7,
4316,
356,
288,
372,
488,
398,
340,
822,
8,
1178,
9,
508,
413,
26,
288,
1499,
275,
4018,
3364,
5678,
1406,
14,
3091,
6235,
2741,
2659,
288,
746,
4967,
14,
10348,
4276,
8,
1328,
9,
267,
916,
822,
8,
1178,
9,
690,
499,
26,
288,
1499,
275,
4018,
3364,
5678,
1406,
14,
23934,
1059,
1077,
440,
1395,
7883,
2659,
288,
746,
4967,
14,
10348,
4276,
8,
1328,
9,
398,
862,
26,
288,
1790,
63,
4181,
275,
1300,
772,
14,
66,
772,
2708,
8,
1178,
59,
17,
6575,
2708,
8,
2856,
63,
7311,
63,
16314,
680,
5312,
11633,
267,
871,
334,
4333,
12,
18965,
304,
288,
1499,
275,
4018,
3364,
5678,
1406,
14,
23934,
440,
6657,
1300,
772,
5737,
2659,
288,
746,
4967,
14,
10348,
4276,
8,
1328,
9,
398,
25580,
12,
2505,
275,
1790,
63,
4181,
59,
16,
467,
1790,
63,
4181,
59,
18,
61,
267,
372,
291,
14,
13975,
63,
6942,
8,
19737,
12,
2505,
9,
339,
347,
12895,
63,
6942,
8,
277,
12,
25580,
12,
2505,
304,
267,
408,
267,
3590,
7672,
314,
25580,
436,
2505,
6169,
3434,
436,
2505,
14,
267,
408,
267,
922,
275,
12895,
8,
2473,
29,
19737,
12,
2505,
29,
2060,
9,
398,
340,
922,
365,
488,
26,
288,
746,
4967,
14,
10348,
4276,
6723,
3364,
3434,
15,
2060,
12459,
398,
340,
440,
922,
14,
374,
63,
2682,
26,
288,
746,
4967,
14,
10348,
4276,
6723,
1899,
21325,
503,
5463,
12459,
398,
372,
334,
751,
12,
488,
9,
339,
347,
12895,
63,
1291,
8,
277,
12,
1056,
304,
267,
372,
283,
6845,
10482,
5961,
83,
4507,
450,
291,
14,
1544,
63,
13975,
63,
7728,
421,
199,
533,
8596,
10348,
8,
1563,
10348,
304,
272,
408,
272,
3645,
5634,
1159,
2351,
10059,
367,
6299,
14,
272,
408,
339,
347,
12895,
8,
277,
12,
1056,
304,
267,
408,
267,
1803,
282,
658,
1899,
64,
340,
314,
1056,
2351,
5544,
965,
282,
10367,
315,
922,
14,
267,
6630,
2529,
658,
403,
2313,
267,
408,
398,
327,
2372,
314,
8793,
20730,
909,
267,
1056,
275,
1056,
423,
1069,
267,
922,
275,
2519,
8,
1069,
12,
283,
751,
297,
488,
9,
398,
327,
1910,
12177,
12,
22468,
6411,
440,
1415,
267,
340,
440,
922,
503,
440,
922,
14,
374,
63,
2682,
26,
288,
372,
488,
398,
291,
14,
19817,
63,
10088,
8,
1069,
9,
398,
327,
22468,
3032,
543,
15082,
922,
267,
372,
334,
751,
12,
488,
9,
339,
347,
15814,
63,
10088,
8,
277,
12,
1056,
304,
267,
408,
267,
3447,
3990,
22468,
6411,
367,
2351,
4079,
6299,
14,
267,
408,
267,
4499,
275,
22468,
1799,
1252,
1412,
63,
1345,
8,
1069,
12,
488,
12,
11969,
5009,
267,
340,
4499,
26,
288,
327,
22468,
3405,
12,
31571,
543,
5027,
1125,
1245,
288,
746,
4967,
14,
7980,
15729,
360,
26405,
16277,
26,
450,
83,
7,
450,
4499,
9,
421,
199,
533,
8767,
10348,
8,
1563,
10348,
304,
272,
408,
272,
5870,
1526,
4079,
6299,
14,
339,
6810,
83,
1077,
12895,
701,
9476,
314,
1526,
790,
315,
314,
298,
11626,
2,
272,
3101,
1406,
12,
20247,
543,
314,
1059,
298,
3264,
3680,
221,
2104,
2893,
26,
398,
21527,
26,
8767,
13952,
70,
23,
645,
24,
1401,
983,
2260,
66,
2576,
70,
30896,
68,
23,
13176,
1167,
556,
32258,
1401,
19446,
22,
65,
272,
408,
339,
1402,
275,
8767,
272,
408,
272,
437,
3537,
1526,
1402,
1443,
506,
1202,
12,
1325,
1471,
1172,
314,
2569,
4382,
14,
339,
627,
790,
1553,
710,
1059,
21119,
314,
1526,
272,
627,
922,
1553,
710,
922,
370,
1314,
314,
1526,
15006,
272,
408,
339,
347,
12895,
8,
277,
12,
1056,
304,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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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
] |
eclecticitguy/pynet_paid
|
class3/ex1_cfg_change_checker.py
|
1
|
1466
|
#!/usr/bin/env python
from snmp_helper import snmp_get_oid_v3,snmp_extract
from time import localtime, asctime
COMMUNITY_STRING = 'galileo'
SNMP_PORT = 161
SYS_NAME = '1.3.6.1.2.1.1.5.0'
SYS_UPTIME = '1.3.6.1.2.1.1.3.0'
RUN_LAST_CHANGED = '1.3.6.1.4.1.9.9.43.1.1.1.0'
SYS_TIME_SEC = 100
DEBUG = True
class NetworkDevice(object):
def __init__(self, device_name, uptime, last_changed, config_changed=False):
self.device_name = device_name
self.uptime = uptime
self.last_changed = last_changed
self.config_changed = config_changed
def main():
a_user = 'pysnmp'
auth_key = 'galileo1'
encrypt_key = 'galileo1'
pynet_rtr1 = ('184.105.247.70', SNMP_PORT)
pynet_rtr2 = ('184.105.247.71', SNMP_PORT)
snmp_user = (a_user, auth_key, encrypt_key)
for a_device in (pynet_rtr1, pynet_rtr2):
snmp_results = []
for oid in (SYS_NAME, SYS_UPTIME, RUN_LAST_CHANGED):
try:
value = snmp_extract(snmp_get_oid_v3(a_device, snmp_user, oid=oid))
snmp_results.append(int(value))
except ValueError:
snmp_results.append(value)
device_name, uptime, last_changed = snmp_results
if DEBUG:
print "\nConnected to device = {0}".format(device_name)
print "Last changed timestamp = {0}".format(last_changed)
print "Uptime = {0}".format(uptime)
if __name__ == "__main__":
main()
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
504,
20143,
63,
3676,
492,
20143,
63,
362,
63,
1170,
63,
86,
19,
12,
15523,
63,
5005,
199,
504,
900,
492,
2257,
521,
12,
16635,
521,
199,
199,
5378,
1734,
1922,
63,
5353,
275,
283,
27074,
441,
79,
7,
199,
30919,
63,
3657,
275,
32372,
199,
13326,
63,
2339,
275,
283,
17,
14,
19,
14,
22,
14,
17,
14,
18,
14,
17,
14,
17,
14,
21,
14,
16,
7,
199,
13326,
63,
2160,
4961,
275,
283,
17,
14,
19,
14,
22,
14,
17,
14,
18,
14,
17,
14,
17,
14,
19,
14,
16,
7,
199,
9390,
63,
16901,
63,
21488,
275,
283,
17,
14,
19,
14,
22,
14,
17,
14,
20,
14,
17,
14,
25,
14,
25,
14,
2824,
14,
17,
14,
17,
14,
17,
14,
16,
7,
199,
13326,
63,
4961,
63,
15048,
275,
2948,
199,
5287,
275,
715,
199,
199,
533,
7220,
2510,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
2243,
63,
354,
12,
1536,
521,
12,
2061,
63,
2489,
12,
1101,
63,
2489,
29,
797,
304,
398,
291,
14,
1782,
63,
354,
275,
2243,
63,
354,
267,
291,
14,
24853,
275,
1536,
521,
267,
291,
14,
2019,
63,
2489,
275,
2061,
63,
2489,
267,
291,
14,
888,
63,
2489,
275,
1101,
63,
2489,
199,
199,
318,
2446,
837,
272,
282,
63,
751,
275,
283,
15983,
78,
311,
7,
272,
1790,
63,
498,
275,
283,
27074,
441,
79,
17,
7,
272,
14645,
63,
498,
275,
283,
27074,
441,
79,
17,
7,
339,
1134,
846,
63,
82,
454,
17,
275,
661,
10078,
14,
7320,
14,
11717,
14,
2760,
297,
26549,
63,
3657,
9,
272,
1134,
846,
63,
82,
454,
18,
275,
661,
10078,
14,
7320,
14,
11717,
14,
3172,
297,
26549,
63,
3657,
9,
339,
20143,
63,
751,
275,
334,
65,
63,
751,
12,
1790,
63,
498,
12,
14645,
63,
498,
9,
339,
367,
282,
63,
1782,
315,
334,
647,
846,
63,
82,
454,
17,
12,
1134,
846,
63,
82,
454,
18,
304,
267,
20143,
63,
2604,
275,
942,
267,
367,
20109,
315,
334,
13326,
63,
2339,
12,
10046,
51,
63,
2160,
4961,
12,
21277,
63,
16901,
63,
21488,
304,
288,
862,
26,
355,
574,
275,
20143,
63,
5005,
8,
15523,
63,
362,
63,
1170,
63,
86,
19,
8,
65,
63,
1782,
12,
20143,
63,
751,
12,
20109,
29,
1170,
430,
355,
20143,
63,
2604,
14,
740,
8,
442,
8,
585,
430,
288,
871,
1722,
26,
355,
20143,
63,
2604,
14,
740,
8,
585,
9,
398,
2243,
63,
354,
12,
1536,
521,
12,
2061,
63,
2489,
275,
20143,
63,
2604,
398,
340,
10990,
26,
288,
870,
1867,
78,
16382,
370,
2243,
275,
469,
16,
5469,
908,
8,
1782,
63,
354,
9,
288,
870,
298,
6090,
2896,
4913,
275,
469,
16,
5469,
908,
8,
2019,
63,
2489,
9,
288,
870,
298,
1721,
521,
275,
469,
16,
5469,
908,
8,
24853,
9,
4388,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
2043,
2446,
342,
6905,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
504,
20143,
63,
3676,
492,
20143,
63,
362,
63,
1170,
63,
86,
19,
12,
15523,
63,
5005,
199,
504,
900,
492,
2257,
521,
12,
16635,
521,
199,
199,
5378,
1734,
1922,
63,
5353,
275,
283,
27074,
441,
79,
7,
199,
30919,
63,
3657,
275,
32372,
199,
13326,
63,
2339,
275,
283,
17,
14,
19,
14,
22,
14,
17,
14,
18,
14,
17,
14,
17,
14,
21,
14,
16,
7,
199,
13326,
63,
2160,
4961,
275,
283,
17,
14,
19,
14,
22,
14,
17,
14,
18,
14,
17,
14,
17,
14,
19,
14,
16,
7,
199,
9390,
63,
16901,
63,
21488,
275,
283,
17,
14,
19,
14,
22,
14,
17,
14,
20,
14,
17,
14,
25,
14,
25,
14,
2824,
14,
17,
14,
17,
14,
17,
14,
16,
7,
199,
13326,
63,
4961,
63,
15048,
275,
2948,
199,
5287,
275,
715,
199,
199,
533,
7220,
2510,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
2243,
63,
354,
12,
1536,
521,
12,
2061,
63,
2489,
12,
1101,
63,
2489,
29,
797,
304,
398,
291,
14,
1782,
63,
354,
275,
2243,
63,
354,
267,
291,
14,
24853,
275,
1536,
521,
267,
291,
14,
2019,
63,
2489,
275,
2061,
63,
2489,
267,
291,
14,
888,
63,
2489,
275,
1101,
63,
2489,
199,
199,
318,
2446,
837,
272,
282,
63,
751,
275,
283,
15983,
78,
311,
7,
272,
1790,
63,
498,
275,
283,
27074,
441,
79,
17,
7,
272,
14645,
63,
498,
275,
283,
27074,
441,
79,
17,
7,
339,
1134,
846,
63,
82,
454,
17,
275,
661,
10078,
14,
7320,
14,
11717,
14,
2760,
297,
26549,
63,
3657,
9,
272,
1134,
846,
63,
82,
454,
18,
275,
661,
10078,
14,
7320,
14,
11717,
14,
3172,
297,
26549,
63,
3657,
9,
339,
20143,
63,
751,
275,
334,
65,
63,
751,
12,
1790,
63,
498,
12,
14645,
63,
498,
9,
339,
367,
282,
63,
1782,
315,
334,
647,
846,
63,
82,
454,
17,
12,
1134,
846,
63,
82,
454,
18,
304,
267,
20143,
63,
2604,
275,
942,
267,
367,
20109,
315,
334,
13326,
63,
2339,
12,
10046,
51,
63,
2160,
4961,
12,
21277,
63,
16901,
63,
21488,
304,
288,
862,
26,
355,
574,
275,
20143,
63,
5005,
8,
15523,
63,
362,
63,
1170,
63,
86,
19,
8,
65,
63,
1782,
12,
20143,
63,
751,
12,
20109,
29,
1170,
430,
355,
20143,
63,
2604,
14,
740,
8,
442,
8,
585,
430,
288,
871,
1722,
26,
355,
20143,
63,
2604,
14,
740,
8,
585,
9,
398,
2243,
63,
354,
12,
1536,
521,
12,
2061,
63,
2489,
275,
20143,
63,
2604,
398,
340,
10990,
26,
288,
870,
1867,
78,
16382,
370,
2243,
275,
469,
16,
5469,
908,
8,
1782,
63,
354,
9,
288,
870,
298,
6090,
2896,
4913,
275,
469,
16,
5469,
908,
8,
2019,
63,
2489,
9,
288,
870,
298,
1721,
521,
275,
469,
16,
5469,
908,
8,
24853,
9,
4388,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
2043,
2446,
342,
6905,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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
] |
yugangw-msft/autorest
|
src/generator/AutoRest.Python.Tests/Expected/AcceptanceTests/UrlMultiCollectionFormat/autoresturlmutlicollectionformattestservice/auto_rest_url_mutli_collection_format_test_service.py
|
5
|
2307
|
# coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
#
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------
from msrest.service_client import ServiceClient
from msrest import Configuration, Serializer, Deserializer
from .version import VERSION
from .operations.queries_operations import QueriesOperations
from . import models
class AutoRestUrlMutliCollectionFormatTestServiceConfiguration(Configuration):
"""Configuration for AutoRestUrlMutliCollectionFormatTestService
Note that all parameters used to create this instance are saved as instance
attributes.
:param str base_url: Service URL
:param str filepath: Existing config
"""
def __init__(
self, base_url=None, filepath=None):
if not base_url:
base_url = 'http://localhost'
super(AutoRestUrlMutliCollectionFormatTestServiceConfiguration, self).__init__(base_url, filepath)
self.add_user_agent('autoresturlmutlicollectionformattestservice/{}'.format(VERSION))
class AutoRestUrlMutliCollectionFormatTestService(object):
"""Test Infrastructure for AutoRest
:ivar config: Configuration for client.
:vartype config: AutoRestUrlMutliCollectionFormatTestServiceConfiguration
:ivar queries: Queries operations
:vartype queries: .operations.QueriesOperations
:param str base_url: Service URL
:param str filepath: Existing config
"""
def __init__(
self, base_url=None, filepath=None):
self.config = AutoRestUrlMutliCollectionFormatTestServiceConfiguration(base_url, filepath)
self._client = ServiceClient(None, self.config)
client_models = {k: v for k, v in models.__dict__.items() if isinstance(v, type)}
self._serialize = Serializer(client_models)
self._deserialize = Deserializer(client_models)
self.queries = QueriesOperations(
self._client, self.config, self._serialize, self._deserialize)
|
mit
|
[
3,
2803,
29,
1624,
13,
24,
199,
3,
24775,
199,
3,
1898,
334,
67,
9,
15332,
11098,
14,
2900,
4481,
4644,
14,
199,
3,
3909,
1334,
314,
10697,
844,
14,
1666,
844,
14,
2424,
315,
314,
2199,
1738,
367,
199,
3,
4190,
2556,
14,
199,
3,
199,
3,
5495,
4046,
701,
15332,
334,
50,
9,
9195,
13726,
5495,
15042,
14,
199,
3,
18784,
1443,
7675,
8927,
5953,
436,
911,
506,
14669,
340,
314,
1233,
365,
199,
3,
31904,
14,
199,
3,
24775,
199,
199,
504,
6605,
3911,
14,
1364,
63,
1258,
492,
7591,
3041,
199,
504,
6605,
3911,
492,
11595,
12,
25555,
12,
1487,
8349,
199,
504,
1275,
1023,
492,
15945,
199,
504,
1275,
8170,
14,
10590,
63,
8170,
492,
5843,
5460,
12929,
199,
504,
1275,
492,
1709,
421,
199,
533,
9195,
13726,
6417,
22539,
317,
7768,
3484,
774,
3167,
5688,
8,
5688,
304,
272,
408,
5688,
367,
9195,
13726,
6417,
22539,
317,
7768,
3484,
774,
3167,
272,
3390,
626,
1006,
2633,
1202,
370,
1218,
642,
1256,
787,
6290,
465,
1256,
272,
3004,
14,
339,
520,
635,
620,
1300,
63,
633,
26,
7591,
2851,
272,
520,
635,
620,
9911,
26,
1316,
26958,
1101,
272,
408,
339,
347,
636,
826,
721,
288,
291,
12,
1300,
63,
633,
29,
403,
12,
9911,
29,
403,
304,
398,
340,
440,
1300,
63,
633,
26,
288,
1300,
63,
633,
275,
283,
1014,
921,
5967,
7,
398,
1613,
8,
3358,
13726,
6417,
22539,
317,
7768,
3484,
774,
3167,
5688,
12,
291,
2843,
826,
721,
1095,
63,
633,
12,
9911,
9,
398,
291,
14,
525,
63,
751,
63,
4054,
360,
27082,
270,
633,
6552,
317,
3627,
908,
396,
1364,
30837,
908,
8,
4612,
430,
421,
199,
533,
9195,
13726,
6417,
22539,
317,
7768,
3484,
774,
3167,
8,
785,
304,
272,
408,
774,
1010,
21844,
6976,
367,
9195,
13726,
339,
520,
7725,
1101,
26,
11595,
367,
1890,
14,
272,
520,
19729,
1101,
26,
9195,
13726,
6417,
22539,
317,
7768,
3484,
774,
3167,
5688,
339,
520,
7725,
9212,
26,
5843,
5460,
5331,
272,
520,
19729,
9212,
26,
1275,
8170,
14,
13611,
12929,
339,
520,
635,
620,
1300,
63,
633,
26,
7591,
2851,
272,
520,
635,
620,
9911,
26,
1316,
26958,
1101,
272,
408,
339,
347,
636,
826,
721,
288,
291,
12,
1300,
63,
633,
29,
403,
12,
9911,
29,
403,
304,
398,
291,
14,
888,
275,
9195,
13726,
6417,
22539,
317,
7768,
3484,
774,
3167,
5688,
8,
1095,
63,
633,
12,
9911,
9,
267,
291,
423,
1258,
275,
7591,
3041,
8,
403,
12,
291,
14,
888,
9,
398,
1890,
63,
992,
275,
469,
75,
26,
373,
367,
1022,
12,
373,
315,
1709,
855,
807,
4343,
1744,
342,
340,
1228,
8,
86,
12,
730,
6769,
267,
291,
423,
3549,
275,
25555,
8,
1258,
63,
992,
9,
267,
291,
423,
11143,
275,
1487,
8349,
8,
1258,
63,
992,
9,
398,
291,
14,
10590,
275,
5843,
5460,
12929,
8,
288,
291,
423,
1258,
12,
291,
14,
888,
12,
291,
423,
3549,
12,
291,
423,
11143,
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
] |
[
2803,
29,
1624,
13,
24,
199,
3,
24775,
199,
3,
1898,
334,
67,
9,
15332,
11098,
14,
2900,
4481,
4644,
14,
199,
3,
3909,
1334,
314,
10697,
844,
14,
1666,
844,
14,
2424,
315,
314,
2199,
1738,
367,
199,
3,
4190,
2556,
14,
199,
3,
199,
3,
5495,
4046,
701,
15332,
334,
50,
9,
9195,
13726,
5495,
15042,
14,
199,
3,
18784,
1443,
7675,
8927,
5953,
436,
911,
506,
14669,
340,
314,
1233,
365,
199,
3,
31904,
14,
199,
3,
24775,
199,
199,
504,
6605,
3911,
14,
1364,
63,
1258,
492,
7591,
3041,
199,
504,
6605,
3911,
492,
11595,
12,
25555,
12,
1487,
8349,
199,
504,
1275,
1023,
492,
15945,
199,
504,
1275,
8170,
14,
10590,
63,
8170,
492,
5843,
5460,
12929,
199,
504,
1275,
492,
1709,
421,
199,
533,
9195,
13726,
6417,
22539,
317,
7768,
3484,
774,
3167,
5688,
8,
5688,
304,
272,
408,
5688,
367,
9195,
13726,
6417,
22539,
317,
7768,
3484,
774,
3167,
272,
3390,
626,
1006,
2633,
1202,
370,
1218,
642,
1256,
787,
6290,
465,
1256,
272,
3004,
14,
339,
520,
635,
620,
1300,
63,
633,
26,
7591,
2851,
272,
520,
635,
620,
9911,
26,
1316,
26958,
1101,
272,
408,
339,
347,
636,
826,
721,
288,
291,
12,
1300,
63,
633,
29,
403,
12,
9911,
29,
403,
304,
398,
340,
440,
1300,
63,
633,
26,
288,
1300,
63,
633,
275,
283,
1014,
921,
5967,
7,
398,
1613,
8,
3358,
13726,
6417,
22539,
317,
7768,
3484,
774,
3167,
5688,
12,
291,
2843,
826,
721,
1095,
63,
633,
12,
9911,
9,
398,
291,
14,
525,
63,
751,
63,
4054,
360,
27082,
270,
633,
6552,
317,
3627,
908,
396,
1364,
30837,
908,
8,
4612,
430,
421,
199,
533,
9195,
13726,
6417,
22539,
317,
7768,
3484,
774,
3167,
8,
785,
304,
272,
408,
774,
1010,
21844,
6976,
367,
9195,
13726,
339,
520,
7725,
1101,
26,
11595,
367,
1890,
14,
272,
520,
19729,
1101,
26,
9195,
13726,
6417,
22539,
317,
7768,
3484,
774,
3167,
5688,
339,
520,
7725,
9212,
26,
5843,
5460,
5331,
272,
520,
19729,
9212,
26,
1275,
8170,
14,
13611,
12929,
339,
520,
635,
620,
1300,
63,
633,
26,
7591,
2851,
272,
520,
635,
620,
9911,
26,
1316,
26958,
1101,
272,
408,
339,
347,
636,
826,
721,
288,
291,
12,
1300,
63,
633,
29,
403,
12,
9911,
29,
403,
304,
398,
291,
14,
888,
275,
9195,
13726,
6417,
22539,
317,
7768,
3484,
774,
3167,
5688,
8,
1095,
63,
633,
12,
9911,
9,
267,
291,
423,
1258,
275,
7591,
3041,
8,
403,
12,
291,
14,
888,
9,
398,
1890,
63,
992,
275,
469,
75,
26,
373,
367,
1022,
12,
373,
315,
1709,
855,
807,
4343,
1744,
342,
340,
1228,
8,
86,
12,
730,
6769,
267,
291,
423,
3549,
275,
25555,
8,
1258,
63,
992,
9,
267,
291,
423,
11143,
275,
1487,
8349,
8,
1258,
63,
992,
9,
398,
291,
14,
10590,
275,
5843,
5460,
12929,
8,
288,
291,
423,
1258,
12,
291,
14,
888,
12,
291,
423,
3549,
12,
291,
423,
11143,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
petewarden/tensorflow
|
tensorflow/lite/python/convert_saved_model.py
|
17
|
7669
|
# Copyright 2018 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.
# ==============================================================================
"""Functions to convert SavedModel to frozen GraphDefs."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from tensorflow.lite.python import util
from tensorflow.core.framework import types_pb2
from tensorflow.python.client import session
from tensorflow.python.framework import ops
from tensorflow.python.platform import tf_logging as logging
from tensorflow.python.saved_model import constants
from tensorflow.python.saved_model import loader
def _log_tensor_details(tensor_info):
"""Log tensor details: name, shape, and type."""
for key in tensor_info:
val = tensor_info[key]
dtype = types_pb2.DataType.Name(val.dtype)
if val.tensor_shape.unknown_rank:
shape = "unknown_rank"
else:
dims = [str(dim.size) for dim in val.tensor_shape.dim]
shape = "({})".format(", ".join(dims))
logging.info("Tensor's key in saved_model's tensor_map: %s", key)
logging.info(" tensor name: %s, shape: %s, type: %s", val.name, shape,
dtype)
def get_meta_graph_def(saved_model_dir, tag_set):
"""Validate saved_model and extract MetaGraphDef.
Args:
saved_model_dir: saved_model path to convert.
tag_set: Set of tag(s) of the MetaGraphDef to load.
Returns:
The meta_graph_def used for tflite conversion.
Raises:
ValueError: No valid MetaGraphDef for given tag_set.
"""
with session.Session(graph=ops.Graph()) as sess:
return loader.load(sess, tag_set, saved_model_dir)
def get_signature_def(meta_graph, signature_key):
"""Get the signature def from meta_graph with given signature_key.
Args:
meta_graph: meta_graph_def.
signature_key: signature_def in the meta_graph_def.
Returns:
The signature_def used for tflite conversion.
Raises:
ValueError: Given signature_key is not valid for this meta_graph.
"""
signature_def_map = meta_graph.signature_def
signature_def_keys = set(signature_def_map.keys())
logging.info(
"The given SavedModel MetaGraphDef contains SignatureDefs with the "
"following keys: %s", signature_def_keys)
if signature_key not in signature_def_keys:
raise ValueError("No '{}' in the SavedModel\'s SignatureDefs. Possible "
"values are '{}'.".format(signature_key,
",".join(signature_def_keys)))
return signature_def_map[signature_key]
def get_inputs_outputs(signature_def):
"""Get inputs and outputs from SignatureDef.
Args:
signature_def: SignatureDef in the meta_graph_def for conversion.
Returns:
The inputs and outputs in the graph for conversion.
"""
inputs_tensor_info = signature_def.inputs
outputs_tensor_info = signature_def.outputs
logging.info("input tensors info: ")
_log_tensor_details(inputs_tensor_info)
logging.info("output tensors info: ")
_log_tensor_details(outputs_tensor_info)
def gather_names(tensor_info):
return [tensor_info[key].name for key in tensor_info]
inputs = gather_names(inputs_tensor_info)
outputs = gather_names(outputs_tensor_info)
return inputs, outputs
def _get_tensors(graph, signature_def_tensor_names=None,
user_tensor_names=None):
"""Gets the tensors associated with the tensor names.
Either signature_def_tensor_names or user_tensor_names should be provided. If
the user provides tensors, the tensors associated with the user provided
tensor names are provided. Otherwise, the tensors associated with the names in
the SignatureDef are provided.
Args:
graph: GraphDef representing graph.
signature_def_tensor_names: Tensor names stored in either the inputs or
outputs of a SignatureDef. (default None)
user_tensor_names: Tensor names provided by the user. (default None)
Returns:
List of tensors.
Raises:
ValueError:
signature_def_tensors and user_tensor_names are undefined or empty.
user_tensor_names are not valid.
"""
tensors = []
if user_tensor_names:
# Sort the tensor names.
user_tensor_names = sorted(user_tensor_names)
tensors = util.get_tensors_from_tensor_names(graph, user_tensor_names)
elif signature_def_tensor_names:
tensors = [
graph.get_tensor_by_name(name)
for name in sorted(signature_def_tensor_names)
]
else:
# Throw ValueError if signature_def_tensors and user_tensor_names are both
# either undefined or empty.
raise ValueError(
"Specify either signature_def_tensor_names or user_tensor_names")
return tensors
def freeze_saved_model(saved_model_dir, input_arrays, input_shapes,
output_arrays, tag_set, signature_key):
"""Converts a SavedModel to a frozen graph.
Args:
saved_model_dir: SavedModel directory to convert.
input_arrays: List of input tensors to freeze graph with. Uses input arrays
from SignatureDef when none are provided.
input_shapes: Dict of strings representing input tensor names to list of
integers representing input shapes (e.g., {"foo": : [1, 16, 16, 3]}).
Automatically determined when input shapes is None (e.g., {"foo" : None}).
output_arrays: List of output tensors to freeze graph with. Uses output
arrays from SignatureDef when none are provided.
tag_set: Set of tags identifying the MetaGraphDef within the SavedModel to
analyze. All tags in the tag set must be present.
signature_key: Key identifying SignatureDef containing inputs and outputs.
Returns:
frozen_graph_def: Frozen GraphDef.
in_tensors: List of input tensors for the graph.
out_tensors: List of output tensors for the graph.
graph: `Graph` object.
Raises:
ValueError:
SavedModel doesn't contain a MetaGraphDef identified by tag_set.
signature_key is not in the MetaGraphDef.
assets/ directory is in the MetaGraphDef.
input_shapes does not match the length of input_arrays.
input_arrays or output_arrays are not valid.
"""
# Read SignatureDef.
meta_graph = get_meta_graph_def(saved_model_dir, tag_set)
signature_def = get_signature_def(meta_graph, signature_key)
inputs, outputs = get_inputs_outputs(signature_def)
# Check SavedModel for assets directory.
collection_def = meta_graph.collection_def
if constants.ASSETS_KEY in collection_def:
raise ValueError("SavedModels with assets/ directory are not supported.")
graph = ops.Graph()
with session.Session(graph=graph) as sess:
loader.load(sess, meta_graph.meta_info_def.tags, saved_model_dir)
# Gets input and output tensors.
# TODO(zhixianyan): Use TFLite supported Op list to filter outputs.
in_tensors = _get_tensors(graph, inputs, input_arrays)
out_tensors = _get_tensors(graph, outputs, output_arrays)
util.set_tensor_shapes(in_tensors, input_shapes)
frozen_graph_def = util.freeze_graph(sess, in_tensors, out_tensors)
return frozen_graph_def, in_tensors, out_tensors, sess.graph
|
apache-2.0
|
[
3,
1898,
14894,
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,
13967,
370,
3957,
29026,
1685,
370,
8101,
11513,
872,
2319,
1041,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
504,
3228,
14,
5333,
14,
1548,
492,
4884,
199,
504,
3228,
14,
1018,
14,
4857,
492,
2943,
63,
3317,
18,
199,
504,
3228,
14,
1548,
14,
1258,
492,
2351,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4156,
199,
504,
3228,
14,
1548,
14,
3246,
492,
2833,
63,
4806,
465,
2050,
199,
504,
3228,
14,
1548,
14,
8420,
63,
1238,
492,
5262,
199,
504,
3228,
14,
1548,
14,
8420,
63,
1238,
492,
5077,
421,
199,
318,
485,
793,
63,
3128,
63,
5087,
8,
3128,
63,
815,
304,
523,
408,
2445,
2345,
2436,
26,
536,
12,
2215,
12,
436,
730,
1041,
523,
367,
790,
315,
2345,
63,
815,
26,
272,
1139,
275,
2345,
63,
815,
59,
498,
61,
272,
2152,
275,
2943,
63,
3317,
18,
14,
23516,
14,
985,
8,
637,
14,
2271,
9,
272,
340,
1139,
14,
3128,
63,
1392,
14,
5187,
63,
4648,
26,
489,
2215,
275,
298,
5187,
63,
4648,
2,
272,
587,
26,
489,
17476,
275,
359,
495,
8,
3572,
14,
890,
9,
367,
8134,
315,
1139,
14,
3128,
63,
1392,
14,
3572,
61,
489,
2215,
275,
298,
14079,
1674,
908,
11854,
3680,
904,
8,
5380,
430,
339,
2050,
14,
815,
480,
3861,
1159,
790,
315,
6290,
63,
1238,
1159,
2345,
63,
1130,
26,
450,
83,
401,
790,
9,
272,
2050,
14,
815,
480,
2345,
536,
26,
450,
83,
12,
2215,
26,
450,
83,
12,
730,
26,
450,
83,
401,
1139,
14,
354,
12,
2215,
12,
326,
2152,
9,
421,
199,
318,
664,
63,
2024,
63,
2180,
63,
318,
8,
8420,
63,
1238,
63,
694,
12,
1947,
63,
409,
304,
523,
408,
12584,
6290,
63,
1238,
436,
5536,
6288,
31725,
14,
819,
3033,
26,
272,
6290,
63,
1238,
63,
694,
26,
6290,
63,
1238,
931,
370,
3957,
14,
272,
1947,
63,
409,
26,
2494,
402,
1947,
8,
83,
9,
402,
314,
6288,
31725,
370,
2248,
14,
819,
1803,
26,
272,
710,
3404,
63,
2180,
63,
318,
1202,
367,
2833,
5333,
8603,
14,
819,
6218,
26,
272,
1722,
26,
3091,
1686,
6288,
31725,
367,
1627,
1947,
63,
409,
14,
523,
408,
523,
543,
2351,
14,
4434,
8,
2180,
29,
1483,
14,
4578,
1012,
465,
4043,
26,
272,
372,
5077,
14,
912,
8,
5480,
12,
1947,
63,
409,
12,
6290,
63,
1238,
63,
694,
9,
421,
199,
318,
664,
63,
5233,
63,
318,
8,
2024,
63,
2180,
12,
4955,
63,
498,
304,
523,
408,
1002,
314,
4955,
347,
687,
3404,
63,
2180,
543,
1627,
4955,
63,
498,
14,
819,
3033,
26,
272,
3404,
63,
2180,
26,
3404,
63,
2180,
63,
318,
14,
272,
4955,
63,
498,
26,
4955,
63,
318,
315,
314,
3404,
63,
2180,
63,
318,
14,
819,
1803,
26,
272,
710,
4955,
63,
318,
1202,
367,
2833,
5333,
8603,
14,
819,
6218,
26,
272,
1722,
26,
9138,
4955,
63,
498,
365,
440,
1686,
367,
642,
3404,
63,
2180,
14,
523,
408,
523,
4955,
63,
318,
63,
1130,
275,
3404,
63,
2180,
14,
5233,
63,
318,
523,
4955,
63,
318,
63,
1612,
275,
663,
8,
5233,
63,
318,
63,
1130,
14,
1612,
1012,
523,
2050,
14,
815,
8,
489,
298,
1918,
1627,
29026,
1685,
6288,
31725,
3509,
18603,
872,
2319,
543,
314,
298,
489,
298,
21589,
2883,
26,
450,
83,
401,
4955,
63,
318,
63,
1612,
9,
523,
340,
4955,
63,
498,
440,
315,
4955,
63,
318,
63,
1612,
26,
272,
746,
1722,
480,
1944,
19574,
315,
314,
29026,
1685,
3985,
83,
18603,
872,
2319,
14,
18558,
298,
2151,
298,
1459,
787,
9005,
1370,
1674,
908,
8,
5233,
63,
498,
12,
6901,
19089,
904,
8,
5233,
63,
318,
63,
1612,
1724,
523,
372,
4955,
63,
318,
63,
1130,
59,
5233,
63,
498,
61,
421,
199,
318,
664,
63,
3711,
63,
4467,
8,
5233,
63,
318,
304,
523,
408,
1002,
4153,
436,
4704,
687,
18603,
6172,
14,
819,
3033,
26,
272,
4955,
63,
318,
26,
18603,
6172,
315,
314,
3404,
63,
2180,
63,
318,
367,
8603,
14,
819,
1803,
26,
272,
710,
4153,
436,
4704,
315,
314,
3343,
367,
8603,
14,
523,
408,
523,
4153,
63,
3128,
63,
815,
275,
4955,
63,
318,
14,
3711,
523,
4704,
63,
3128,
63,
815,
275,
4955,
63,
318,
14,
4467,
523,
2050,
14,
815,
480,
1210,
10519,
2256,
26,
6099,
523,
485,
793,
63,
3128,
63,
5087,
8,
3711,
63,
3128,
63,
815,
9,
523,
2050,
14,
815,
480,
1199,
10519,
2256,
26,
6099,
523,
485,
793,
63,
3128,
63,
5087,
8,
4467,
63,
3128,
63,
815,
9,
819,
347,
13082,
63,
1247,
8,
3128,
63,
815,
304,
272,
372,
359,
3128,
63,
815,
59,
498,
1055,
354,
367,
790,
315,
2345,
63,
815,
61,
819,
4153,
275,
13082,
63,
1247,
8,
3711,
63,
3128,
63,
815,
9,
523,
4704,
275,
13082,
63,
1247,
8,
4467,
63,
3128,
63,
815,
9,
523,
372,
4153,
12,
4704,
421,
199,
318,
485,
362,
63,
10206,
8,
2180,
12,
4955,
63,
318,
63,
3128,
63,
1247,
29,
403,
12,
326,
922,
63,
3128,
63,
1247,
29,
403,
304,
523,
408,
14426,
314,
10519,
4568,
543,
314,
2345,
1561,
14,
819,
13083,
4955,
63
] |
[
1898,
14894,
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,
13967,
370,
3957,
29026,
1685,
370,
8101,
11513,
872,
2319,
1041,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
504,
3228,
14,
5333,
14,
1548,
492,
4884,
199,
504,
3228,
14,
1018,
14,
4857,
492,
2943,
63,
3317,
18,
199,
504,
3228,
14,
1548,
14,
1258,
492,
2351,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4156,
199,
504,
3228,
14,
1548,
14,
3246,
492,
2833,
63,
4806,
465,
2050,
199,
504,
3228,
14,
1548,
14,
8420,
63,
1238,
492,
5262,
199,
504,
3228,
14,
1548,
14,
8420,
63,
1238,
492,
5077,
421,
199,
318,
485,
793,
63,
3128,
63,
5087,
8,
3128,
63,
815,
304,
523,
408,
2445,
2345,
2436,
26,
536,
12,
2215,
12,
436,
730,
1041,
523,
367,
790,
315,
2345,
63,
815,
26,
272,
1139,
275,
2345,
63,
815,
59,
498,
61,
272,
2152,
275,
2943,
63,
3317,
18,
14,
23516,
14,
985,
8,
637,
14,
2271,
9,
272,
340,
1139,
14,
3128,
63,
1392,
14,
5187,
63,
4648,
26,
489,
2215,
275,
298,
5187,
63,
4648,
2,
272,
587,
26,
489,
17476,
275,
359,
495,
8,
3572,
14,
890,
9,
367,
8134,
315,
1139,
14,
3128,
63,
1392,
14,
3572,
61,
489,
2215,
275,
298,
14079,
1674,
908,
11854,
3680,
904,
8,
5380,
430,
339,
2050,
14,
815,
480,
3861,
1159,
790,
315,
6290,
63,
1238,
1159,
2345,
63,
1130,
26,
450,
83,
401,
790,
9,
272,
2050,
14,
815,
480,
2345,
536,
26,
450,
83,
12,
2215,
26,
450,
83,
12,
730,
26,
450,
83,
401,
1139,
14,
354,
12,
2215,
12,
326,
2152,
9,
421,
199,
318,
664,
63,
2024,
63,
2180,
63,
318,
8,
8420,
63,
1238,
63,
694,
12,
1947,
63,
409,
304,
523,
408,
12584,
6290,
63,
1238,
436,
5536,
6288,
31725,
14,
819,
3033,
26,
272,
6290,
63,
1238,
63,
694,
26,
6290,
63,
1238,
931,
370,
3957,
14,
272,
1947,
63,
409,
26,
2494,
402,
1947,
8,
83,
9,
402,
314,
6288,
31725,
370,
2248,
14,
819,
1803,
26,
272,
710,
3404,
63,
2180,
63,
318,
1202,
367,
2833,
5333,
8603,
14,
819,
6218,
26,
272,
1722,
26,
3091,
1686,
6288,
31725,
367,
1627,
1947,
63,
409,
14,
523,
408,
523,
543,
2351,
14,
4434,
8,
2180,
29,
1483,
14,
4578,
1012,
465,
4043,
26,
272,
372,
5077,
14,
912,
8,
5480,
12,
1947,
63,
409,
12,
6290,
63,
1238,
63,
694,
9,
421,
199,
318,
664,
63,
5233,
63,
318,
8,
2024,
63,
2180,
12,
4955,
63,
498,
304,
523,
408,
1002,
314,
4955,
347,
687,
3404,
63,
2180,
543,
1627,
4955,
63,
498,
14,
819,
3033,
26,
272,
3404,
63,
2180,
26,
3404,
63,
2180,
63,
318,
14,
272,
4955,
63,
498,
26,
4955,
63,
318,
315,
314,
3404,
63,
2180,
63,
318,
14,
819,
1803,
26,
272,
710,
4955,
63,
318,
1202,
367,
2833,
5333,
8603,
14,
819,
6218,
26,
272,
1722,
26,
9138,
4955,
63,
498,
365,
440,
1686,
367,
642,
3404,
63,
2180,
14,
523,
408,
523,
4955,
63,
318,
63,
1130,
275,
3404,
63,
2180,
14,
5233,
63,
318,
523,
4955,
63,
318,
63,
1612,
275,
663,
8,
5233,
63,
318,
63,
1130,
14,
1612,
1012,
523,
2050,
14,
815,
8,
489,
298,
1918,
1627,
29026,
1685,
6288,
31725,
3509,
18603,
872,
2319,
543,
314,
298,
489,
298,
21589,
2883,
26,
450,
83,
401,
4955,
63,
318,
63,
1612,
9,
523,
340,
4955,
63,
498,
440,
315,
4955,
63,
318,
63,
1612,
26,
272,
746,
1722,
480,
1944,
19574,
315,
314,
29026,
1685,
3985,
83,
18603,
872,
2319,
14,
18558,
298,
2151,
298,
1459,
787,
9005,
1370,
1674,
908,
8,
5233,
63,
498,
12,
6901,
19089,
904,
8,
5233,
63,
318,
63,
1612,
1724,
523,
372,
4955,
63,
318,
63,
1130,
59,
5233,
63,
498,
61,
421,
199,
318,
664,
63,
3711,
63,
4467,
8,
5233,
63,
318,
304,
523,
408,
1002,
4153,
436,
4704,
687,
18603,
6172,
14,
819,
3033,
26,
272,
4955,
63,
318,
26,
18603,
6172,
315,
314,
3404,
63,
2180,
63,
318,
367,
8603,
14,
819,
1803,
26,
272,
710,
4153,
436,
4704,
315,
314,
3343,
367,
8603,
14,
523,
408,
523,
4153,
63,
3128,
63,
815,
275,
4955,
63,
318,
14,
3711,
523,
4704,
63,
3128,
63,
815,
275,
4955,
63,
318,
14,
4467,
523,
2050,
14,
815,
480,
1210,
10519,
2256,
26,
6099,
523,
485,
793,
63,
3128,
63,
5087,
8,
3711,
63,
3128,
63,
815,
9,
523,
2050,
14,
815,
480,
1199,
10519,
2256,
26,
6099,
523,
485,
793,
63,
3128,
63,
5087,
8,
4467,
63,
3128,
63,
815,
9,
819,
347,
13082,
63,
1247,
8,
3128,
63,
815,
304,
272,
372,
359,
3128,
63,
815,
59,
498,
1055,
354,
367,
790,
315,
2345,
63,
815,
61,
819,
4153,
275,
13082,
63,
1247,
8,
3711,
63,
3128,
63,
815,
9,
523,
4704,
275,
13082,
63,
1247,
8,
4467,
63,
3128,
63,
815,
9,
523,
372,
4153,
12,
4704,
421,
199,
318,
485,
362,
63,
10206,
8,
2180,
12,
4955,
63,
318,
63,
3128,
63,
1247,
29,
403,
12,
326,
922,
63,
3128,
63,
1247,
29,
403,
304,
523,
408,
14426,
314,
10519,
4568,
543,
314,
2345,
1561,
14,
819,
13083,
4955,
63,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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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
] |
JohnAdders/domoticz
|
plugins/examples/HTTP.py
|
9
|
7970
|
# Google Home page example
#
# Author: Dnpwwo, 2017 - 2018
#
# Demonstrates HTTP/HTTPS connectivity.
# After connection it performs a GET on www.google.com and receives a 302 (Page Moved) response
# It then does a subsequent GET on the Location specified in the 302 response and receives a 200 response.
#
"""
<plugin key="Google" name="Google Home page example" author="Dnpwwo" version="2.2.6" externallink="https://www.google.com">
<description>
<h2>Google Home page example</h2><br/>
Will hit the supplied URL every 5 heartbeats in the request protocol. Redirects are handled.
</description>
<params>
<param field="Address" label="IP Address" width="200px" required="true" default="www.google.com"/>
<param field="Mode1" label="Protocol" width="75px">
<options>
<option label="HTTPS" value="443"/>
<option label="HTTP" value="80" default="true" />
</options>
</param>
<param field="Mode6" label="Debug" width="150px">
<options>
<option label="None" value="0" default="true" />
<option label="Python Only" value="2"/>
<option label="Basic Debugging" value="62"/>
<option label="Basic+Messages" value="126"/>
<option label="Connections Only" value="16"/>
<option label="Connections+Python" value="18"/>
<option label="Connections+Queue" value="144"/>
<option label="All" value="-1"/>
</options>
</param>
</params>
</plugin>
"""
import Domoticz
class BasePlugin:
httpConn = None
runAgain = 6
disconnectCount = 0
sProtocol = "HTTP"
def __init__(self):
return
def onStart(self):
if Parameters["Mode6"] != "0":
Domoticz.Debugging(int(Parameters["Mode6"]))
DumpConfigToLog()
if (Parameters["Mode1"] == "443"): self.sProtocol = "HTTPS"
self.httpConn = Domoticz.Connection(Name=self.sProtocol+" Test", Transport="TCP/IP", Protocol=self.sProtocol, Address=Parameters["Address"], Port=Parameters["Mode1"])
self.httpConn.Connect()
def onStop(self):
Domoticz.Log("onStop - Plugin is stopping.")
def onConnect(self, Connection, Status, Description):
if (Status == 0):
Domoticz.Debug("Google connected successfully.")
sendData = { 'Verb' : 'GET',
'URL' : '/',
'Headers' : { 'Content-Type': 'text/xml; charset=utf-8', \
'Connection': 'keep-alive', \
'Accept': 'Content-Type: text/html; charset=UTF-8', \
'Host': Parameters["Address"]+":"+Parameters["Mode1"], \
'User-Agent':'Domoticz/1.0' }
}
Connection.Send(sendData)
else:
Domoticz.Log("Failed to connect ("+str(Status)+") to: "+Parameters["Address"]+":"+Parameters["Mode1"]+" with error: "+Description)
def onMessage(self, Connection, Data):
DumpHTTPResponseToLog(Data)
strData = Data["Data"].decode("utf-8", "ignore")
Status = int(Data["Status"])
LogMessage(strData)
if (Status == 200):
if ((self.disconnectCount & 1) == 1):
Domoticz.Log("Good Response received from Google, Disconnecting.")
self.httpConn.Disconnect()
else:
Domoticz.Log("Good Response received from Google, Dropping connection.")
self.httpConn = None
self.disconnectCount = self.disconnectCount + 1
elif (Status == 302):
Domoticz.Log("Google returned a Page Moved Error.")
sendData = { 'Verb' : 'GET',
'URL' : Data["Headers"]["Location"],
'Headers' : { 'Content-Type': 'text/xml; charset=utf-8', \
'Connection': 'keep-alive', \
'Accept': 'Content-Type: text/html; charset=UTF-8', \
'Host': Parameters["Address"]+":"+Parameters["Mode1"], \
'User-Agent':'Domoticz/1.0' },
}
Connection.Send(sendData)
elif (Status == 400):
Domoticz.Error("Google returned a Bad Request Error.")
elif (Status == 500):
Domoticz.Error("Google returned a Server Error.")
else:
Domoticz.Error("Google returned a status: "+str(Status))
def onCommand(self, Unit, Command, Level, Hue):
Domoticz.Debug("onCommand called for Unit " + str(Unit) + ": Parameter '" + str(Command) + "', Level: " + str(Level))
def onDisconnect(self, Connection):
Domoticz.Log("onDisconnect called for connection to: "+Connection.Address+":"+Connection.Port)
def onHeartbeat(self):
if (self.httpConn != None and (self.httpConn.Connecting() or self.httpConn.Connected())):
Domoticz.Debug("onHeartbeat called, Connection is alive.")
else:
self.runAgain = self.runAgain - 1
if self.runAgain <= 0:
if (self.httpConn == None):
self.httpConn = Domoticz.Connection(Name=self.sProtocol+" Test", Transport="TCP/IP", Protocol=self.sProtocol, Address=Parameters["Address"], Port=Parameters["Mode1"])
self.httpConn.Connect()
self.runAgain = 6
else:
Domoticz.Debug("onHeartbeat called, run again in "+str(self.runAgain)+" heartbeats.")
global _plugin
_plugin = BasePlugin()
def onStart():
global _plugin
_plugin.onStart()
def onStop():
global _plugin
_plugin.onStop()
def onConnect(Connection, Status, Description):
global _plugin
_plugin.onConnect(Connection, Status, Description)
def onMessage(Connection, Data):
global _plugin
_plugin.onMessage(Connection, Data)
def onCommand(Unit, Command, Level, Hue):
global _plugin
_plugin.onCommand(Unit, Command, Level, Hue)
def onNotification(Name, Subject, Text, Status, Priority, Sound, ImageFile):
global _plugin
_plugin.onNotification(Name, Subject, Text, Status, Priority, Sound, ImageFile)
def onDisconnect(Connection):
global _plugin
_plugin.onDisconnect(Connection)
def onHeartbeat():
global _plugin
_plugin.onHeartbeat()
# Generic helper functions
def LogMessage(Message):
if Parameters["Mode6"] == "File":
f = open(Parameters["HomeFolder"]+"http.html","w")
f.write(Message)
f.close()
Domoticz.Log("File written")
def DumpConfigToLog():
for x in Parameters:
if Parameters[x] != "":
Domoticz.Debug( "'" + x + "':'" + str(Parameters[x]) + "'")
Domoticz.Debug("Device count: " + str(len(Devices)))
for x in Devices:
Domoticz.Debug("Device: " + str(x) + " - " + str(Devices[x]))
Domoticz.Debug("Device ID: '" + str(Devices[x].ID) + "'")
Domoticz.Debug("Device Name: '" + Devices[x].Name + "'")
Domoticz.Debug("Device nValue: " + str(Devices[x].nValue))
Domoticz.Debug("Device sValue: '" + Devices[x].sValue + "'")
Domoticz.Debug("Device LastLevel: " + str(Devices[x].LastLevel))
return
def DumpHTTPResponseToLog(httpDict):
if isinstance(httpDict, dict):
Domoticz.Debug("HTTP Details ("+str(len(httpDict))+"):")
for x in httpDict:
if isinstance(httpDict[x], dict):
Domoticz.Debug("--->'"+x+" ("+str(len(httpDict[x]))+"):")
for y in httpDict[x]:
Domoticz.Debug("------->'" + y + "':'" + str(httpDict[x][y]) + "'")
else:
Domoticz.Debug("--->'" + x + "':'" + str(httpDict[x]) + "'")
|
gpl-3.0
|
[
3,
4475,
14621,
2034,
2893,
199,
3,
199,
3,
6529,
26,
577,
1590,
978,
79,
12,
9708,
446,
14894,
199,
3,
199,
3,
257,
1487,
2106,
31216,
3101,
15,
14921,
20170,
14,
199,
3,
257,
12836,
1950,
652,
18628,
282,
9576,
641,
221,
20732,
14,
3098,
14,
957,
436,
23192,
282,
11485,
334,
3276,
6445,
9,
1177,
199,
3,
257,
2779,
2066,
1630,
282,
13372,
9576,
641,
314,
12625,
2013,
315,
314,
11485,
1177,
436,
23192,
282,
1926,
1177,
14,
199,
3,
199,
624,
199,
28,
2718,
790,
628,
13266,
2,
536,
628,
13266,
14621,
2034,
2893,
2,
4132,
628,
36,
1590,
978,
79,
2,
1015,
628,
18,
14,
18,
14,
22,
2,
21815,
452,
2292,
628,
2859,
921,
1544,
14,
3098,
14,
957,
1743,
272,
665,
1802,
30,
267,
665,
72,
18,
30,
13266,
14621,
2034,
2893,
1108,
72,
18,
2535,
3289,
3133,
267,
12823,
9793,
314,
6841,
2851,
4036,
959,
946,
580,
1235,
1956,
315,
314,
1056,
4113,
14,
221,
18532,
83,
787,
8860,
14,
272,
3068,
1802,
30,
272,
665,
1162,
30,
267,
665,
635,
901,
628,
1476,
2,
1768,
628,
1772,
9906,
2,
3462,
628,
1840,
5326,
2,
1415,
628,
2052,
2,
849,
628,
1544,
14,
3098,
14,
957,
7897,
267,
665,
635,
901,
628,
1385,
17,
2,
1768,
628,
3658,
2,
3462,
628,
2194,
5326,
1743,
288,
665,
1419,
30,
355,
665,
1422,
1768,
628,
14921,
2,
574,
628,
16284,
7897,
355,
665,
1422,
1768,
628,
2856,
2,
574,
628,
1257,
2,
221,
849,
628,
2052,
2,
7082,
288,
3068,
1419,
30,
267,
3068,
635,
30,
267,
665,
635,
901,
628,
1385,
22,
2,
1768,
628,
7084,
2,
3462,
628,
8251,
5326,
1743,
288,
665,
1419,
30,
355,
665,
1422,
1768,
628,
403,
2,
574,
628,
16,
2,
221,
849,
628,
2052,
2,
7082,
355,
665,
1422,
1768,
628,
4718,
5972,
2,
574,
628,
18,
7897,
355,
665,
1422,
1768,
628,
6845,
14245,
1540,
2,
574,
628,
2789,
7897,
355,
665,
1422,
1768,
628,
6845,
11,
14508,
2,
574,
628,
7957,
7897,
355,
665,
1422,
1768,
628,
22122,
5972,
2,
574,
628,
975,
7897,
355,
665,
1422,
1768,
628,
22122,
11,
4718,
2,
574,
628,
1085,
7897,
355,
665,
1422,
1768,
628,
22122,
11,
3737,
2,
574,
628,
9862,
7897,
355,
665,
1422,
1768,
628,
2422,
2,
574,
27295,
17,
7897,
288,
3068,
1419,
30,
267,
3068,
635,
30,
272,
3068,
1162,
30,
199,
1108,
2718,
30,
199,
624,
199,
646,
4226,
573,
764,
90,
199,
199,
533,
3523,
5061,
26,
272,
1455,
6805,
275,
488,
272,
1255,
5676,
1581,
275,
1227,
272,
17639,
2353,
275,
378,
272,
308,
3658,
275,
298,
2856,
2,
272,
272,
347,
636,
826,
721,
277,
304,
267,
372,
339,
347,
641,
3162,
8,
277,
304,
267,
340,
3897,
905,
1385,
22,
937,
1137,
298,
16,
582,
288,
4226,
573,
764,
90,
14,
7084,
1540,
8,
442,
8,
5976,
905,
1385,
22,
13045,
288,
19460,
2028,
1378,
2445,
342,
267,
340,
334,
5976,
905,
1385,
17,
937,
508,
298,
16284,
2349,
291,
14,
83,
3658,
275,
298,
14921,
2,
267,
291,
14,
1014,
6805,
275,
4226,
573,
764,
90,
14,
3225,
8,
985,
29,
277,
14,
83,
3658,
5207,
1379,
401,
27018,
628,
9735,
15,
1772,
401,
11557,
29,
277,
14,
83,
3658,
12,
9906,
29,
5976,
905,
1476,
2255,
10977,
29,
5976,
905,
1385,
17,
3135,
267,
291,
14,
1014,
6805,
14,
8631,
342,
339,
347,
641,
6293,
8,
277,
304,
267,
4226,
573,
764,
90,
14,
2445,
480,
265,
6293,
446,
11349,
365,
23599,
2685,
339,
347,
641,
8631,
8,
277,
12,
8113,
12,
9795,
12,
11994,
304,
267,
340,
334,
3694,
508,
378,
304,
288,
4226,
573,
764,
90,
14,
7084,
480,
13266,
8539,
8792,
2685,
288,
3222,
1451,
275,
469,
283,
3673,
66,
7,
520,
283,
2970,
297,
586,
283,
2632,
7,
221,
520,
17220,
586,
283,
9883,
7,
520,
469,
283,
2714,
13,
804,
356,
283,
505,
15,
1652,
27,
5960,
29,
1624,
13,
24,
297,
971,
4318,
283,
3225,
356,
283,
3250,
13,
9631,
297,
971,
4318,
283,
8422,
356,
283,
2714,
13,
804,
26,
1318,
15,
1360,
27,
5960,
29,
6610,
13,
24,
297,
971,
4318,
283,
4965,
356,
3897,
905,
1476,
937,
11,
5122,
11,
5976,
905,
1385,
17,
2255,
971,
4318,
283,
1899,
13,
7788,
5242,
2585,
573,
764,
90,
15,
17,
14,
16,
7,
789,
2432,
789,
288,
8113,
14,
6795,
8,
2254,
1451,
9,
267,
587,
26,
288,
4226,
573,
764,
90,
14,
2445,
480,
4276,
370,
4907,
1689,
11,
495,
8,
3694,
6393,
531,
370,
26,
7210,
5976,
905,
1476,
937,
11,
5122,
11,
5976,
905,
1385,
17,
937,
5207,
543,
1125,
26,
7210,
5831,
9,
339,
347,
641,
2209,
8,
277,
12,
8113,
12,
3918,
304,
267,
19460,
27068,
1378,
2445,
8,
1451,
9,
2728,
620,
1451,
275,
3918,
905,
1451,
4140,
2708,
480,
1624,
13,
24,
401,
298,
4247,
531,
267,
9795,
275,
1109,
8,
1451,
905,
3694,
3135,
267,
5297,
2209,
8,
495,
1451,
9,
398,
340,
334,
3694,
508,
1926,
304,
288,
340,
3666,
277,
14,
10673,
2353,
1253,
413,
9,
508,
413,
304,
355,
4226,
573,
764,
90,
14,
2445,
480,
20652,
7232,
3086,
687,
4475,
12,
5289,
2242,
316,
2685,
355,
291,
14,
1014,
6805,
14,
16761,
342,
288,
587,
26,
355,
4226,
573,
764,
90,
14,
2445,
480,
20652,
7232,
3086,
687,
4475,
12,
577,
20148,
1950,
2685,
355,
291,
14,
1014,
6805,
275,
488,
288,
291,
14,
10673,
2353,
275,
291,
14,
10673,
2353,
435,
413,
267,
916,
334,
3694,
508,
11485,
304,
288,
4226,
573,
764,
90,
14,
2445,
480,
13266,
2138,
282,
10331,
6445,
4520,
2685,
288,
3222,
1451,
275,
469,
283,
3673,
66,
7,
520,
283,
2970,
297,
586,
283,
2632,
7,
221,
520,
3918,
905,
9883,
6611,
6592,
2255,
586,
283,
9883,
7,
520,
469,
283,
2714,
13,
804,
356,
283,
505,
15,
1652,
27,
5960,
29,
1624,
13,
24,
297,
971,
4318,
283,
3225,
356,
283,
3250,
13,
9631,
297,
971,
4318,
283,
8422,
356,
283,
2714,
13,
804,
26,
1318,
15,
1360,
27,
5960,
29,
6610,
13,
24,
297,
971,
4318,
283,
4965,
356,
3897,
905,
1476,
937
] |
[
4475,
14621,
2034,
2893,
199,
3,
199,
3,
6529,
26,
577,
1590,
978,
79,
12,
9708,
446,
14894,
199,
3,
199,
3,
257,
1487,
2106,
31216,
3101,
15,
14921,
20170,
14,
199,
3,
257,
12836,
1950,
652,
18628,
282,
9576,
641,
221,
20732,
14,
3098,
14,
957,
436,
23192,
282,
11485,
334,
3276,
6445,
9,
1177,
199,
3,
257,
2779,
2066,
1630,
282,
13372,
9576,
641,
314,
12625,
2013,
315,
314,
11485,
1177,
436,
23192,
282,
1926,
1177,
14,
199,
3,
199,
624,
199,
28,
2718,
790,
628,
13266,
2,
536,
628,
13266,
14621,
2034,
2893,
2,
4132,
628,
36,
1590,
978,
79,
2,
1015,
628,
18,
14,
18,
14,
22,
2,
21815,
452,
2292,
628,
2859,
921,
1544,
14,
3098,
14,
957,
1743,
272,
665,
1802,
30,
267,
665,
72,
18,
30,
13266,
14621,
2034,
2893,
1108,
72,
18,
2535,
3289,
3133,
267,
12823,
9793,
314,
6841,
2851,
4036,
959,
946,
580,
1235,
1956,
315,
314,
1056,
4113,
14,
221,
18532,
83,
787,
8860,
14,
272,
3068,
1802,
30,
272,
665,
1162,
30,
267,
665,
635,
901,
628,
1476,
2,
1768,
628,
1772,
9906,
2,
3462,
628,
1840,
5326,
2,
1415,
628,
2052,
2,
849,
628,
1544,
14,
3098,
14,
957,
7897,
267,
665,
635,
901,
628,
1385,
17,
2,
1768,
628,
3658,
2,
3462,
628,
2194,
5326,
1743,
288,
665,
1419,
30,
355,
665,
1422,
1768,
628,
14921,
2,
574,
628,
16284,
7897,
355,
665,
1422,
1768,
628,
2856,
2,
574,
628,
1257,
2,
221,
849,
628,
2052,
2,
7082,
288,
3068,
1419,
30,
267,
3068,
635,
30,
267,
665,
635,
901,
628,
1385,
22,
2,
1768,
628,
7084,
2,
3462,
628,
8251,
5326,
1743,
288,
665,
1419,
30,
355,
665,
1422,
1768,
628,
403,
2,
574,
628,
16,
2,
221,
849,
628,
2052,
2,
7082,
355,
665,
1422,
1768,
628,
4718,
5972,
2,
574,
628,
18,
7897,
355,
665,
1422,
1768,
628,
6845,
14245,
1540,
2,
574,
628,
2789,
7897,
355,
665,
1422,
1768,
628,
6845,
11,
14508,
2,
574,
628,
7957,
7897,
355,
665,
1422,
1768,
628,
22122,
5972,
2,
574,
628,
975,
7897,
355,
665,
1422,
1768,
628,
22122,
11,
4718,
2,
574,
628,
1085,
7897,
355,
665,
1422,
1768,
628,
22122,
11,
3737,
2,
574,
628,
9862,
7897,
355,
665,
1422,
1768,
628,
2422,
2,
574,
27295,
17,
7897,
288,
3068,
1419,
30,
267,
3068,
635,
30,
272,
3068,
1162,
30,
199,
1108,
2718,
30,
199,
624,
199,
646,
4226,
573,
764,
90,
199,
199,
533,
3523,
5061,
26,
272,
1455,
6805,
275,
488,
272,
1255,
5676,
1581,
275,
1227,
272,
17639,
2353,
275,
378,
272,
308,
3658,
275,
298,
2856,
2,
272,
272,
347,
636,
826,
721,
277,
304,
267,
372,
339,
347,
641,
3162,
8,
277,
304,
267,
340,
3897,
905,
1385,
22,
937,
1137,
298,
16,
582,
288,
4226,
573,
764,
90,
14,
7084,
1540,
8,
442,
8,
5976,
905,
1385,
22,
13045,
288,
19460,
2028,
1378,
2445,
342,
267,
340,
334,
5976,
905,
1385,
17,
937,
508,
298,
16284,
2349,
291,
14,
83,
3658,
275,
298,
14921,
2,
267,
291,
14,
1014,
6805,
275,
4226,
573,
764,
90,
14,
3225,
8,
985,
29,
277,
14,
83,
3658,
5207,
1379,
401,
27018,
628,
9735,
15,
1772,
401,
11557,
29,
277,
14,
83,
3658,
12,
9906,
29,
5976,
905,
1476,
2255,
10977,
29,
5976,
905,
1385,
17,
3135,
267,
291,
14,
1014,
6805,
14,
8631,
342,
339,
347,
641,
6293,
8,
277,
304,
267,
4226,
573,
764,
90,
14,
2445,
480,
265,
6293,
446,
11349,
365,
23599,
2685,
339,
347,
641,
8631,
8,
277,
12,
8113,
12,
9795,
12,
11994,
304,
267,
340,
334,
3694,
508,
378,
304,
288,
4226,
573,
764,
90,
14,
7084,
480,
13266,
8539,
8792,
2685,
288,
3222,
1451,
275,
469,
283,
3673,
66,
7,
520,
283,
2970,
297,
586,
283,
2632,
7,
221,
520,
17220,
586,
283,
9883,
7,
520,
469,
283,
2714,
13,
804,
356,
283,
505,
15,
1652,
27,
5960,
29,
1624,
13,
24,
297,
971,
4318,
283,
3225,
356,
283,
3250,
13,
9631,
297,
971,
4318,
283,
8422,
356,
283,
2714,
13,
804,
26,
1318,
15,
1360,
27,
5960,
29,
6610,
13,
24,
297,
971,
4318,
283,
4965,
356,
3897,
905,
1476,
937,
11,
5122,
11,
5976,
905,
1385,
17,
2255,
971,
4318,
283,
1899,
13,
7788,
5242,
2585,
573,
764,
90,
15,
17,
14,
16,
7,
789,
2432,
789,
288,
8113,
14,
6795,
8,
2254,
1451,
9,
267,
587,
26,
288,
4226,
573,
764,
90,
14,
2445,
480,
4276,
370,
4907,
1689,
11,
495,
8,
3694,
6393,
531,
370,
26,
7210,
5976,
905,
1476,
937,
11,
5122,
11,
5976,
905,
1385,
17,
937,
5207,
543,
1125,
26,
7210,
5831,
9,
339,
347,
641,
2209,
8,
277,
12,
8113,
12,
3918,
304,
267,
19460,
27068,
1378,
2445,
8,
1451,
9,
2728,
620,
1451,
275,
3918,
905,
1451,
4140,
2708,
480,
1624,
13,
24,
401,
298,
4247,
531,
267,
9795,
275,
1109,
8,
1451,
905,
3694,
3135,
267,
5297,
2209,
8,
495,
1451,
9,
398,
340,
334,
3694,
508,
1926,
304,
288,
340,
3666,
277,
14,
10673,
2353,
1253,
413,
9,
508,
413,
304,
355,
4226,
573,
764,
90,
14,
2445,
480,
20652,
7232,
3086,
687,
4475,
12,
5289,
2242,
316,
2685,
355,
291,
14,
1014,
6805,
14,
16761,
342,
288,
587,
26,
355,
4226,
573,
764,
90,
14,
2445,
480,
20652,
7232,
3086,
687,
4475,
12,
577,
20148,
1950,
2685,
355,
291,
14,
1014,
6805,
275,
488,
288,
291,
14,
10673,
2353,
275,
291,
14,
10673,
2353,
435,
413,
267,
916,
334,
3694,
508,
11485,
304,
288,
4226,
573,
764,
90,
14,
2445,
480,
13266,
2138,
282,
10331,
6445,
4520,
2685,
288,
3222,
1451,
275,
469,
283,
3673,
66,
7,
520,
283,
2970,
297,
586,
283,
2632,
7,
221,
520,
3918,
905,
9883,
6611,
6592,
2255,
586,
283,
9883,
7,
520,
469,
283,
2714,
13,
804,
356,
283,
505,
15,
1652,
27,
5960,
29,
1624,
13,
24,
297,
971,
4318,
283,
3225,
356,
283,
3250,
13,
9631,
297,
971,
4318,
283,
8422,
356,
283,
2714,
13,
804,
26,
1318,
15,
1360,
27,
5960,
29,
6610,
13,
24,
297,
971,
4318,
283,
4965,
356,
3897,
905,
1476,
937,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
31415us/trajectory
|
py/env/lib/python2.7/site-packages/shapely/geometry/linestring.py
|
3
|
8309
|
"""Line strings and related utilities
"""
from ctypes import c_double, cast, POINTER
from ctypes import ArgumentError
from shapely.coords import required
from shapely.geos import lgeos, TopologicalError
from shapely.geometry.base import BaseGeometry, geom_factory
from shapely.geometry.proxy import CachingGeometryProxy
__all__ = ['LineString', 'asLineString']
class LineString(BaseGeometry):
"""
A one-dimensional figure comprising one or more line segments
A LineString has non-zero length and zero area. It may approximate a curve
and need not be straight. Unlike a LinearRing, a LineString is not closed.
"""
def __init__(self, coordinates=None):
"""
Parameters
----------
coordinates : sequence
A sequence of (x, y [,z]) numeric coordinate pairs or triples or
an object that provides the numpy array interface, including another
instance of LineString.
Example
-------
Create a line with two segments
>>> a = LineString([[0, 0], [1, 0], [1, 1]])
>>> a.length
2.0
"""
BaseGeometry.__init__(self)
if coordinates is not None:
self._set_coords(coordinates)
@property
def __geo_interface__(self):
return {
'type': 'LineString',
'coordinates': tuple(self.coords)
}
@property
def ctypes(self):
if not self._ctypes_data:
self._ctypes_data = self.coords.ctypes
return self._ctypes_data
def array_interface(self):
"""Provide the Numpy array protocol."""
return self.coords.array_interface()
__array_interface__ = property(array_interface)
# Coordinate access
def _set_coords(self, coordinates):
self.empty()
self._geom, self._ndim = geos_linestring_from_py(coordinates)
coords = property(BaseGeometry._get_coords, _set_coords)
@property
def xy(self):
"""Separate arrays of X and Y coordinate values
Example:
>>> x, y = LineString(((0, 0), (1, 1))).xy
>>> list(x)
[0.0, 1.0]
>>> list(y)
[0.0, 1.0]
"""
return self.coords.xy
def parallel_offset(
self, distance, side,
resolution=16, join_style=1, mitre_limit=1.0):
"""Returns a LineString or MultiLineString geometry at a distance from
the object on its right or its left side.
Distance must be a positive float value. The side parameter may be
'left' or 'right'. The resolution of the buffer around each vertex of
the object increases by increasing the resolution keyword parameter or
third positional parameter.
The join style is for outside corners between line segments. Accepted
values are 1 => ROUND, 2 => MITRE, 3 => BEVEL.
The mitre ratio limit is used for very sharp corners. It is the ratio
of the distance from the corner to the end of the mitred offset corner.
When two line segments meet at a sharp angle, a miter join will extend
far beyond the original geometry. To prevent unreasonable geometry, the
mitre limit allows controlling the maximum length of the join corner.
Corners with a ratio which exceed the limit will be beveled."""
try:
return geom_factory(self.impl['parallel_offset'](
self, distance, resolution, join_style, mitre_limit,
bool(side=='left')))
except WindowsError:
raise TopologicalError()
class LineStringAdapter(CachingGeometryProxy, LineString):
def __init__(self, context):
self.context = context
self.factory = geos_linestring_from_py
@property
def _ndim(self):
try:
# From array protocol
array = self.context.__array_interface__
n = array['shape'][1]
assert n == 2 or n == 3
return n
except AttributeError:
# Fall back on list
return len(self.context[0])
@property
def __array_interface__(self):
"""Provide the Numpy array protocol."""
try:
return self.context.__array_interface__
except AttributeError:
return self.array_interface()
_get_coords = BaseGeometry._get_coords
def _set_coords(self, ob):
raise NotImplementedError(
"Adapters can not modify their coordinate sources")
coords = property(_get_coords)
def asLineString(context):
"""Adapt an object the LineString interface"""
return LineStringAdapter(context)
def geos_linestring_from_py(ob, update_geom=None, update_ndim=0):
# If numpy is present, we use numpy.require to ensure that we have a
# C-continguous array that owns its data. View data will be copied.
ob = required(ob)
try:
# From array protocol
array = ob.__array_interface__
assert len(array['shape']) == 2
m = array['shape'][0]
if m < 2:
raise ValueError(
"LineStrings must have at least 2 coordinate tuples")
try:
n = array['shape'][1]
except IndexError:
raise ValueError(
"Input %s is the wrong shape for a LineString" % str(ob))
assert n == 2 or n == 3
# Make pointer to the coordinate array
if isinstance(array['data'], tuple):
# numpy tuple (addr, read-only)
cp = cast(array['data'][0], POINTER(c_double))
else:
cp = array['data']
# Create a coordinate sequence
if update_geom is not None:
cs = lgeos.GEOSGeom_getCoordSeq(update_geom)
if n != update_ndim:
raise ValueError(
"Wrong coordinate dimensions; this geometry has dimensions: %d" \
% update_ndim)
else:
cs = lgeos.GEOSCoordSeq_create(m, n)
# add to coordinate sequence
for i in xrange(m):
dx = c_double(cp[n*i])
dy = c_double(cp[n*i+1])
dz = None
if n == 3:
try:
dz = c_double(cp[n*i+2])
except IndexError:
raise ValueError("Inconsistent coordinate dimensionality")
# Because of a bug in the GEOS C API,
# always set X before Y
lgeos.GEOSCoordSeq_setX(cs, i, dx)
lgeos.GEOSCoordSeq_setY(cs, i, dy)
if n == 3:
lgeos.GEOSCoordSeq_setZ(cs, i, dz)
except AttributeError:
# Fall back on list
m = len(ob)
if m < 2:
raise ValueError(
"LineStrings must have at least 2 coordinate tuples")
try:
n = len(ob[0])
except TypeError:
raise ValueError(
"Input %s is the wrong shape for a LineString" % str(ob))
assert n == 2 or n == 3
# Create a coordinate sequence
if update_geom is not None:
cs = lgeos.GEOSGeom_getCoordSeq(update_geom)
if n != update_ndim:
raise ValueError(
"Wrong coordinate dimensions; this geometry has dimensions: %d" \
% update_ndim)
else:
cs = lgeos.GEOSCoordSeq_create(m, n)
# add to coordinate sequence
for i in xrange(m):
coords = ob[i]
# Because of a bug in the GEOS C API,
# always set X before Y
lgeos.GEOSCoordSeq_setX(cs, i, coords[0])
lgeos.GEOSCoordSeq_setY(cs, i, coords[1])
if n == 3:
try:
lgeos.GEOSCoordSeq_setZ(cs, i, coords[2])
except IndexError:
raise ValueError("Inconsistent coordinate dimensionality")
if update_geom is not None:
return None
else:
return lgeos.GEOSGeom_createLineString(cs), n
def update_linestring_from_py(geom, ob):
geos_linestring_from_py(ob, geom._geom, geom._ndim)
# Test runner
def _test():
import doctest
doctest.testmod()
if __name__ == "__main__":
_test()
|
mit
|
[
624,
3049,
3326,
436,
4048,
15841,
199,
624,
199,
199,
504,
5577,
492,
286,
63,
3157,
12,
9106,
12,
6569,
199,
504,
5577,
492,
5886,
547,
199,
199,
504,
2215,
590,
14,
8032,
492,
1415,
199,
504,
2215,
590,
14,
12151,
492,
634,
12151,
12,
14132,
79,
7954,
547,
199,
504,
2215,
590,
14,
7660,
14,
1095,
492,
3523,
6831,
12,
9671,
63,
3702,
199,
504,
2215,
590,
14,
7660,
14,
3280,
492,
445,
23302,
6831,
4936,
199,
199,
363,
452,
363,
275,
788,
22134,
297,
283,
305,
22134,
418,
421,
199,
533,
30020,
8,
1563,
6831,
304,
272,
408,
272,
437,
1373,
13,
13014,
9658,
1013,
322,
1044,
1373,
503,
1655,
1004,
11998,
2286,
437,
30020,
965,
2222,
13,
4262,
2582,
436,
4697,
9150,
14,
2779,
1443,
19917,
282,
15318,
272,
436,
1929,
440,
506,
23669,
14,
25059,
282,
12489,
15420,
12,
282,
30020,
365,
440,
6876,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
8983,
29,
403,
304,
267,
408,
267,
3897,
267,
4143,
267,
8983,
520,
3414,
288,
437,
3414,
402,
334,
88,
12,
612,
359,
12,
90,
566,
8950,
10021,
6342,
503,
31733,
503,
288,
376,
909,
626,
6571,
314,
2680,
1625,
3217,
12,
5893,
4573,
288,
1256,
402,
30020,
14,
398,
5679,
267,
5514,
267,
2790,
282,
1004,
543,
2877,
11998,
8592,
1306,
282,
275,
30020,
4038,
16,
12,
378,
467,
359,
17,
12,
378,
467,
359,
17,
12,
413,
3934,
881,
1306,
282,
14,
1267,
881,
499,
14,
16,
267,
408,
267,
3523,
6831,
855,
826,
721,
277,
9,
267,
340,
8983,
365,
440,
488,
26,
288,
291,
423,
409,
63,
8032,
8,
12924,
9,
339,
768,
1829,
272,
347,
636,
6721,
63,
3266,
721,
277,
304,
267,
372,
469,
288,
283,
466,
356,
283,
22134,
297,
288,
283,
12924,
356,
2008,
8,
277,
14,
8032,
9,
288,
789,
339,
768,
1829,
272,
347,
5577,
8,
277,
304,
267,
340,
440,
291,
423,
9798,
63,
576,
26,
288,
291,
423,
9798,
63,
576,
275,
291,
14,
8032,
14,
9798,
267,
372,
291,
423,
9798,
63,
576,
339,
347,
1625,
63,
3266,
8,
277,
304,
267,
408,
25107,
314,
20535,
1625,
4113,
1041,
267,
372,
291,
14,
8032,
14,
1144,
63,
3266,
342,
2286,
636,
1144,
63,
3266,
363,
275,
3324,
8,
1144,
63,
3266,
9,
339,
327,
25334,
323,
2879,
272,
347,
485,
409,
63,
8032,
8,
277,
12,
8983,
304,
267,
291,
14,
1667,
342,
267,
291,
423,
6481,
12,
291,
423,
8322,
275,
30259,
63,
604,
875,
63,
504,
63,
647,
8,
12924,
9,
339,
13259,
275,
3324,
8,
1563,
6831,
423,
362,
63,
8032,
12,
485,
409,
63,
8032,
9,
339,
768,
1829,
272,
347,
13222,
8,
277,
304,
267,
408,
12653,
323,
6572,
402,
1323,
436,
1488,
10021,
1338,
2728,
5679,
26,
268,
881,
1306,
671,
12,
612,
275,
30020,
12925,
16,
12,
378,
395,
334,
17,
12,
413,
23261,
1702,
881,
1306,
769,
8,
88,
9,
881,
359,
16,
14,
16,
12,
413,
14,
16,
61,
881,
1306,
769,
8,
89,
9,
881,
359,
16,
14,
16,
12,
413,
14,
16,
61,
267,
408,
267,
372,
291,
14,
8032,
14,
1702,
2286,
347,
9861,
63,
2743,
8,
267,
291,
12,
6033,
12,
5366,
12,
4960,
12401,
29,
975,
12,
4263,
63,
2487,
29,
17,
12,
30714,
264,
63,
3097,
29,
17,
14,
16,
304,
2728,
408,
3407,
282,
30020,
503,
6879,
22134,
3400,
737,
282,
6033,
687,
267,
314,
909,
641,
2399,
2451,
503,
2399,
3602,
5366,
14,
2728,
21892,
1471,
506,
282,
7317,
2069,
574,
14,
710,
5366,
2725,
1443,
506,
267,
283,
3039,
7,
503,
283,
1019,
1370,
710,
12401,
402,
314,
3335,
6818,
1924,
12759,
402,
267,
314,
909,
10035,
3274,
701,
22255,
314,
12401,
4252,
2725,
503,
267,
10919,
11333,
2725,
14,
2728,
710,
4263,
3449,
365,
367,
9682,
31657,
3382,
1004,
11998,
14,
4473,
7203,
267,
1338,
787,
413,
9265,
9769,
6131,
12,
499,
9265,
10697,
907,
12,
650,
9265,
6262,
10429,
14,
2728,
710,
30714,
264,
10463,
2304,
365,
1202,
367,
7437,
1033,
12868,
31657,
14,
2779,
365,
314,
10463,
267,
402,
314,
6033,
687,
314,
17703,
370,
314,
1284,
402,
314,
30714,
581,
3268,
17703,
14,
267,
3979,
2877,
1004,
11998,
26743,
737,
282,
1033,
12868,
9324,
12,
282,
333,
1661,
4263,
911,
12247,
267,
12474,
20561,
314,
3379,
3400,
14,
4005,
7981,
625,
5764,
461,
3400,
12,
314,
267,
30714,
264,
2304,
6127,
30350,
314,
5696,
2582,
402,
314,
4263,
17703,
14,
267,
445,
6161,
1192,
543,
282,
10463,
1314,
24068,
314,
2304,
911,
506,
506,
432,
1146,
1041,
398,
862,
26,
288,
372,
9671,
63,
3702,
8,
277,
14,
5472,
459,
11887,
63,
2743,
21407,
355,
291,
12,
6033,
12,
12401,
12,
4263,
63,
2487,
12,
30714,
264,
63,
3097,
12,
8892,
2155,
8,
2441,
6803,
3039,
7058,
267,
871,
23950,
26,
288,
746,
14132,
79,
7954,
547,
342,
27844,
199,
533,
30020,
10200,
8,
35,
23302,
6831,
4936,
12,
30020,
304,
339,
347,
636,
826,
721,
277,
12,
1067,
304,
267,
291,
14,
1100,
275,
1067,
267,
291,
14,
3702,
275,
30259,
63,
604,
875,
63,
504,
63,
647,
339,
768,
1829,
272,
347,
485,
8322,
8,
277,
304,
267,
862,
26,
288,
327,
11606,
1625,
4113,
288,
1625,
275,
291,
14,
1100,
855,
1144,
63,
3266,
363,
288,
302,
275,
1625,
459,
1392,
3488,
17,
61,
288,
702,
302,
508,
499,
503,
302,
508,
650,
288,
372,
302,
267,
871,
4281,
26,
288,
327,
481,
452,
1771,
641,
769,
288,
372,
822,
8,
277,
14,
1100,
59,
16,
566,
339,
768,
1829,
272,
347,
636,
1144,
63,
3266,
721,
277,
304,
267,
408,
25107,
314,
20535,
1625,
4113,
1041,
267,
862,
26,
288,
372,
291,
14,
1100,
855,
1144,
63,
3266,
363,
267,
871,
4281,
26,
288,
372,
291,
14,
1144,
63,
3266,
342,
339,
485,
362,
63,
8032,
275,
3523,
6831,
423,
362,
63,
8032,
339,
347,
485,
409,
63,
8032,
8,
277,
12,
2607,
304,
267,
746,
4279,
8,
288,
298,
2767,
12552,
883,
440,
2811,
3932,
10021,
5274,
531,
339,
13259,
275,
3324,
1547,
362,
63,
8032,
9,
421,
199,
318,
465,
22134,
8,
1100,
304,
272
] |
[
3049,
3326,
436,
4048,
15841,
199,
624,
199,
199,
504,
5577,
492,
286,
63,
3157,
12,
9106,
12,
6569,
199,
504,
5577,
492,
5886,
547,
199,
199,
504,
2215,
590,
14,
8032,
492,
1415,
199,
504,
2215,
590,
14,
12151,
492,
634,
12151,
12,
14132,
79,
7954,
547,
199,
504,
2215,
590,
14,
7660,
14,
1095,
492,
3523,
6831,
12,
9671,
63,
3702,
199,
504,
2215,
590,
14,
7660,
14,
3280,
492,
445,
23302,
6831,
4936,
199,
199,
363,
452,
363,
275,
788,
22134,
297,
283,
305,
22134,
418,
421,
199,
533,
30020,
8,
1563,
6831,
304,
272,
408,
272,
437,
1373,
13,
13014,
9658,
1013,
322,
1044,
1373,
503,
1655,
1004,
11998,
2286,
437,
30020,
965,
2222,
13,
4262,
2582,
436,
4697,
9150,
14,
2779,
1443,
19917,
282,
15318,
272,
436,
1929,
440,
506,
23669,
14,
25059,
282,
12489,
15420,
12,
282,
30020,
365,
440,
6876,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
8983,
29,
403,
304,
267,
408,
267,
3897,
267,
4143,
267,
8983,
520,
3414,
288,
437,
3414,
402,
334,
88,
12,
612,
359,
12,
90,
566,
8950,
10021,
6342,
503,
31733,
503,
288,
376,
909,
626,
6571,
314,
2680,
1625,
3217,
12,
5893,
4573,
288,
1256,
402,
30020,
14,
398,
5679,
267,
5514,
267,
2790,
282,
1004,
543,
2877,
11998,
8592,
1306,
282,
275,
30020,
4038,
16,
12,
378,
467,
359,
17,
12,
378,
467,
359,
17,
12,
413,
3934,
881,
1306,
282,
14,
1267,
881,
499,
14,
16,
267,
408,
267,
3523,
6831,
855,
826,
721,
277,
9,
267,
340,
8983,
365,
440,
488,
26,
288,
291,
423,
409,
63,
8032,
8,
12924,
9,
339,
768,
1829,
272,
347,
636,
6721,
63,
3266,
721,
277,
304,
267,
372,
469,
288,
283,
466,
356,
283,
22134,
297,
288,
283,
12924,
356,
2008,
8,
277,
14,
8032,
9,
288,
789,
339,
768,
1829,
272,
347,
5577,
8,
277,
304,
267,
340,
440,
291,
423,
9798,
63,
576,
26,
288,
291,
423,
9798,
63,
576,
275,
291,
14,
8032,
14,
9798,
267,
372,
291,
423,
9798,
63,
576,
339,
347,
1625,
63,
3266,
8,
277,
304,
267,
408,
25107,
314,
20535,
1625,
4113,
1041,
267,
372,
291,
14,
8032,
14,
1144,
63,
3266,
342,
2286,
636,
1144,
63,
3266,
363,
275,
3324,
8,
1144,
63,
3266,
9,
339,
327,
25334,
323,
2879,
272,
347,
485,
409,
63,
8032,
8,
277,
12,
8983,
304,
267,
291,
14,
1667,
342,
267,
291,
423,
6481,
12,
291,
423,
8322,
275,
30259,
63,
604,
875,
63,
504,
63,
647,
8,
12924,
9,
339,
13259,
275,
3324,
8,
1563,
6831,
423,
362,
63,
8032,
12,
485,
409,
63,
8032,
9,
339,
768,
1829,
272,
347,
13222,
8,
277,
304,
267,
408,
12653,
323,
6572,
402,
1323,
436,
1488,
10021,
1338,
2728,
5679,
26,
268,
881,
1306,
671,
12,
612,
275,
30020,
12925,
16,
12,
378,
395,
334,
17,
12,
413,
23261,
1702,
881,
1306,
769,
8,
88,
9,
881,
359,
16,
14,
16,
12,
413,
14,
16,
61,
881,
1306,
769,
8,
89,
9,
881,
359,
16,
14,
16,
12,
413,
14,
16,
61,
267,
408,
267,
372,
291,
14,
8032,
14,
1702,
2286,
347,
9861,
63,
2743,
8,
267,
291,
12,
6033,
12,
5366,
12,
4960,
12401,
29,
975,
12,
4263,
63,
2487,
29,
17,
12,
30714,
264,
63,
3097,
29,
17,
14,
16,
304,
2728,
408,
3407,
282,
30020,
503,
6879,
22134,
3400,
737,
282,
6033,
687,
267,
314,
909,
641,
2399,
2451,
503,
2399,
3602,
5366,
14,
2728,
21892,
1471,
506,
282,
7317,
2069,
574,
14,
710,
5366,
2725,
1443,
506,
267,
283,
3039,
7,
503,
283,
1019,
1370,
710,
12401,
402,
314,
3335,
6818,
1924,
12759,
402,
267,
314,
909,
10035,
3274,
701,
22255,
314,
12401,
4252,
2725,
503,
267,
10919,
11333,
2725,
14,
2728,
710,
4263,
3449,
365,
367,
9682,
31657,
3382,
1004,
11998,
14,
4473,
7203,
267,
1338,
787,
413,
9265,
9769,
6131,
12,
499,
9265,
10697,
907,
12,
650,
9265,
6262,
10429,
14,
2728,
710,
30714,
264,
10463,
2304,
365,
1202,
367,
7437,
1033,
12868,
31657,
14,
2779,
365,
314,
10463,
267,
402,
314,
6033,
687,
314,
17703,
370,
314,
1284,
402,
314,
30714,
581,
3268,
17703,
14,
267,
3979,
2877,
1004,
11998,
26743,
737,
282,
1033,
12868,
9324,
12,
282,
333,
1661,
4263,
911,
12247,
267,
12474,
20561,
314,
3379,
3400,
14,
4005,
7981,
625,
5764,
461,
3400,
12,
314,
267,
30714,
264,
2304,
6127,
30350,
314,
5696,
2582,
402,
314,
4263,
17703,
14,
267,
445,
6161,
1192,
543,
282,
10463,
1314,
24068,
314,
2304,
911,
506,
506,
432,
1146,
1041,
398,
862,
26,
288,
372,
9671,
63,
3702,
8,
277,
14,
5472,
459,
11887,
63,
2743,
21407,
355,
291,
12,
6033,
12,
12401,
12,
4263,
63,
2487,
12,
30714,
264,
63,
3097,
12,
8892,
2155,
8,
2441,
6803,
3039,
7058,
267,
871,
23950,
26,
288,
746,
14132,
79,
7954,
547,
342,
27844,
199,
533,
30020,
10200,
8,
35,
23302,
6831,
4936,
12,
30020,
304,
339,
347,
636,
826,
721,
277,
12,
1067,
304,
267,
291,
14,
1100,
275,
1067,
267,
291,
14,
3702,
275,
30259,
63,
604,
875,
63,
504,
63,
647,
339,
768,
1829,
272,
347,
485,
8322,
8,
277,
304,
267,
862,
26,
288,
327,
11606,
1625,
4113,
288,
1625,
275,
291,
14,
1100,
855,
1144,
63,
3266,
363,
288,
302,
275,
1625,
459,
1392,
3488,
17,
61,
288,
702,
302,
508,
499,
503,
302,
508,
650,
288,
372,
302,
267,
871,
4281,
26,
288,
327,
481,
452,
1771,
641,
769,
288,
372,
822,
8,
277,
14,
1100,
59,
16,
566,
339,
768,
1829,
272,
347,
636,
1144,
63,
3266,
721,
277,
304,
267,
408,
25107,
314,
20535,
1625,
4113,
1041,
267,
862,
26,
288,
372,
291,
14,
1100,
855,
1144,
63,
3266,
363,
267,
871,
4281,
26,
288,
372,
291,
14,
1144,
63,
3266,
342,
339,
485,
362,
63,
8032,
275,
3523,
6831,
423,
362,
63,
8032,
339,
347,
485,
409,
63,
8032,
8,
277,
12,
2607,
304,
267,
746,
4279,
8,
288,
298,
2767,
12552,
883,
440,
2811,
3932,
10021,
5274,
531,
339,
13259,
275,
3324,
1547,
362,
63,
8032,
9,
421,
199,
318,
465,
22134,
8,
1100,
304,
272,
0
] |
[
1,
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rawlingson/SickRage
|
lib/hachoir_parser/image/bmp.py
|
95
|
6682
|
"""
Microsoft Bitmap picture parser.
- file extension: ".bmp"
Author: Victor Stinner
Creation: 16 december 2005
"""
from hachoir_parser import Parser
from hachoir_core.field import (FieldSet,
UInt8, UInt16, UInt32, Bits,
String, RawBytes, Enum,
PaddingBytes, NullBytes, createPaddingField)
from hachoir_core.endian import LITTLE_ENDIAN
from hachoir_core.text_handler import textHandler, hexadecimal
from hachoir_parser.image.common import RGB, PaletteRGBA
from hachoir_core.tools import alignValue
class Pixel4bit(Bits):
static_size = 4
def __init__(self, parent, name):
Bits.__init__(self, parent, name, 4)
class ImageLine(FieldSet):
def __init__(self, parent, name, width, pixel_class):
FieldSet.__init__(self, parent, name)
self._pixel = pixel_class
self._width = width
self._size = alignValue(self._width * self._pixel.static_size, 32)
def createFields(self):
for x in xrange(self._width):
yield self._pixel(self, "pixel[]")
size = self.size - self.current_size
if size:
yield createPaddingField(self, size)
class ImagePixels(FieldSet):
def __init__(self, parent, name, width, height, pixel_class, size=None):
FieldSet.__init__(self, parent, name, size=size)
self._width = width
self._height = height
self._pixel = pixel_class
def createFields(self):
for y in xrange(self._height-1, -1, -1):
yield ImageLine(self, "line[%u]" % y, self._width, self._pixel)
size = (self.size - self.current_size) // 8
if size:
yield NullBytes(self, "padding", size)
class CIEXYZ(FieldSet):
def createFields(self):
yield UInt32(self, "x")
yield UInt32(self, "y")
yield UInt32(self, "z")
class BmpHeader(FieldSet):
color_space_name = {
1: "Business (Saturation)",
2: "Graphics (Relative)",
4: "Images (Perceptual)",
8: "Absolute colormetric (Absolute)",
}
def getFormatVersion(self):
if "gamma_blue" in self:
return 4
if "important_color" in self:
return 3
return 2
def createFields(self):
# Version 2 (12 bytes)
yield UInt32(self, "header_size", "Header size")
yield UInt32(self, "width", "Width (pixels)")
yield UInt32(self, "height", "Height (pixels)")
yield UInt16(self, "nb_plan", "Number of plan (=1)")
yield UInt16(self, "bpp", "Bits per pixel") # may be zero for PNG/JPEG picture
# Version 3 (40 bytes)
if self["header_size"].value < 40:
return
yield Enum(UInt32(self, "compression", "Compression method"), BmpFile.COMPRESSION_NAME)
yield UInt32(self, "image_size", "Image size (bytes)")
yield UInt32(self, "horizontal_dpi", "Horizontal DPI")
yield UInt32(self, "vertical_dpi", "Vertical DPI")
yield UInt32(self, "used_colors", "Number of color used")
yield UInt32(self, "important_color", "Number of import colors")
# Version 4 (108 bytes)
if self["header_size"].value < 108:
return
yield textHandler(UInt32(self, "red_mask"), hexadecimal)
yield textHandler(UInt32(self, "green_mask"), hexadecimal)
yield textHandler(UInt32(self, "blue_mask"), hexadecimal)
yield textHandler(UInt32(self, "alpha_mask"), hexadecimal)
yield Enum(UInt32(self, "color_space"), self.color_space_name)
yield CIEXYZ(self, "red_primary")
yield CIEXYZ(self, "green_primary")
yield CIEXYZ(self, "blue_primary")
yield UInt32(self, "gamma_red")
yield UInt32(self, "gamma_green")
yield UInt32(self, "gamma_blue")
def parseImageData(parent, name, size, header):
if ("compression" not in header) or (header["compression"].value in (0, 3)):
width = header["width"].value
height = header["height"].value
bpp = header["bpp"].value
if bpp == 32:
cls = UInt32
elif bpp == 24:
cls = RGB
elif bpp == 8:
cls = UInt8
elif bpp == 4:
cls = Pixel4bit
else:
cls = None
if cls:
return ImagePixels(parent, name, width, height, cls, size=size*8)
return RawBytes(parent, name, size)
class BmpFile(Parser):
PARSER_TAGS = {
"id": "bmp",
"category": "image",
"file_ext": ("bmp",),
"mime": (u"image/x-ms-bmp", u"image/x-bmp"),
"min_size": 30*8,
# "magic": (("BM", 0),),
"magic_regex": ((
# "BM", <filesize>, <reserved>, header_size=(12|40|108)
"BM.{4}.{8}[\x0C\x28\x6C]\0{3}",
0),),
"description": "Microsoft bitmap (BMP) picture"
}
endian = LITTLE_ENDIAN
COMPRESSION_NAME = {
0: u"Uncompressed",
1: u"RLE 8-bit",
2: u"RLE 4-bit",
3: u"Bitfields",
4: u"JPEG",
5: u"PNG",
}
def validate(self):
if self.stream.readBytes(0, 2) != 'BM':
return "Wrong file signature"
if self["header/header_size"].value not in (12, 40, 108):
return "Unknown header size (%s)" % self["header_size"].value
if self["header/nb_plan"].value != 1:
return "Invalid number of planes"
return True
def createFields(self):
yield String(self, "signature", 2, "Header (\"BM\")", charset="ASCII")
yield UInt32(self, "file_size", "File size (bytes)")
yield PaddingBytes(self, "reserved", 4, "Reserved")
yield UInt32(self, "data_start", "Data start position")
yield BmpHeader(self, "header")
# Compute number of color
header = self["header"]
bpp = header["bpp"].value
if 0 < bpp <= 8:
if "used_colors" in header and header["used_colors"].value:
nb_color = header["used_colors"].value
else:
nb_color = (1 << bpp)
else:
nb_color = 0
# Color palette (if any)
if nb_color:
yield PaletteRGBA(self, "palette", nb_color)
# Seek to data start
field = self.seekByte(self["data_start"].value)
if field:
yield field
# Image pixels
size = min(self["file_size"].value-self["data_start"].value, (self.size - self.current_size)//8)
yield parseImageData(self, "pixels", size, header)
def createDescription(self):
return u"Microsoft Bitmap version %s" % self["header"].getFormatVersion()
def createContentSize(self):
return self["file_size"].value * 8
|
gpl-3.0
|
[
624,
199,
12940,
10199,
1130,
24945,
1798,
14,
199,
13,
570,
3329,
26,
3680,
22308,
2,
199,
199,
5949,
26,
6561,
630,
428,
1346,
1372,
199,
13921,
26,
3193,
477,
26381,
11811,
199,
624,
199,
199,
504,
394,
21301,
63,
2087,
492,
10191,
199,
504,
394,
21301,
63,
1018,
14,
698,
492,
334,
23532,
12,
272,
10666,
24,
12,
10666,
975,
12,
10666,
708,
12,
26612,
12,
272,
2624,
12,
13480,
5571,
12,
11305,
12,
272,
510,
4095,
5571,
12,
12119,
5571,
12,
1218,
15069,
792,
9,
199,
504,
394,
21301,
63,
1018,
14,
15009,
492,
491,
31783,
63,
21046,
199,
504,
394,
21301,
63,
1018,
14,
505,
63,
2232,
492,
1318,
2461,
12,
20379,
199,
504,
394,
21301,
63,
2087,
14,
1569,
14,
2330,
492,
19013,
12,
510,
22116,
21631,
199,
504,
394,
21301,
63,
1018,
14,
2537,
492,
6998,
1110,
199,
199,
533,
510,
5887,
20,
2075,
8,
10787,
304,
272,
2955,
63,
890,
275,
841,
272,
347,
636,
826,
721,
277,
12,
1676,
12,
536,
304,
267,
26612,
855,
826,
721,
277,
12,
1676,
12,
536,
12,
841,
9,
199,
199,
533,
6047,
3049,
8,
23532,
304,
272,
347,
636,
826,
721,
277,
12,
1676,
12,
536,
12,
3462,
12,
7148,
63,
533,
304,
267,
5024,
1084,
855,
826,
721,
277,
12,
1676,
12,
536,
9,
267,
291,
423,
8435,
275,
7148,
63,
533,
267,
291,
423,
2063,
275,
3462,
267,
291,
423,
890,
275,
6998,
1110,
8,
277,
423,
2063,
627,
291,
423,
8435,
14,
1986,
63,
890,
12,
4337,
9,
339,
347,
24828,
8,
277,
304,
267,
367,
671,
315,
4945,
8,
277,
423,
2063,
304,
288,
1995,
291,
423,
8435,
8,
277,
12,
298,
8435,
31346,
267,
1568,
275,
291,
14,
890,
446,
291,
14,
1818,
63,
890,
267,
340,
1568,
26,
288,
1995,
1218,
15069,
792,
8,
277,
12,
1568,
9,
199,
199,
533,
6047,
29170,
8,
23532,
304,
272,
347,
636,
826,
721,
277,
12,
1676,
12,
536,
12,
3462,
12,
4569,
12,
7148,
63,
533,
12,
1568,
29,
403,
304,
267,
5024,
1084,
855,
826,
721,
277,
12,
1676,
12,
536,
12,
1568,
29,
890,
9,
267,
291,
423,
2063,
275,
3462,
267,
291,
423,
3333,
275,
4569,
267,
291,
423,
8435,
275,
7148,
63,
533,
339,
347,
24828,
8,
277,
304,
267,
367,
612,
315,
4945,
8,
277,
423,
3333,
13,
17,
12,
446,
17,
12,
446,
17,
304,
288,
1995,
6047,
3049,
8,
277,
12,
298,
604,
9722,
85,
8480,
450,
612,
12,
291,
423,
2063,
12,
291,
423,
8435,
9,
267,
1568,
275,
334,
277,
14,
890,
446,
291,
14,
1818,
63,
890,
9,
5001,
1695,
267,
340,
1568,
26,
288,
1995,
12119,
5571,
8,
277,
12,
298,
8358,
401,
1568,
9,
199,
199,
533,
445,
41,
1438,
26184,
8,
23532,
304,
272,
347,
24828,
8,
277,
304,
267,
1995,
10666,
708,
8,
277,
12,
298,
88,
531,
267,
1995,
10666,
708,
8,
277,
12,
298,
89,
531,
267,
1995,
10666,
708,
8,
277,
12,
298,
90,
531,
199,
199,
533,
699,
311,
2567,
8,
23532,
304,
272,
3164,
63,
2638,
63,
354,
275,
469,
267,
413,
26,
298,
12106,
9585,
334,
22332,
1542,
4186,
267,
499,
26,
298,
18859,
334,
15277,
4186,
267,
841,
26,
298,
18882,
334,
2623,
716,
1061,
4186,
267,
1695,
26,
298,
24677,
3164,
5165,
334,
24677,
4186,
272,
789,
339,
347,
664,
3484,
3353,
8,
277,
304,
267,
340,
298,
7325,
63,
6304,
2,
315,
291,
26,
288,
372,
841,
267,
340,
298,
19559,
63,
2326,
2,
315,
291,
26,
288,
372,
650,
267,
372,
499,
339,
347,
24828,
8,
277,
304,
267,
327,
3394,
499,
334,
713,
2783,
9,
267,
1995,
10666,
708,
8,
277,
12,
298,
1291,
63,
890,
401,
298,
2567,
1568,
531,
267,
1995,
10666,
708,
8,
277,
12,
298,
2063,
401,
298,
6216,
334,
15727,
6320,
267,
1995,
10666,
708,
8,
277,
12,
298,
3333,
401,
298,
8436,
334,
15727,
6320,
267,
1995,
10666,
975,
8,
277,
12,
298,
4994,
63,
5140,
401,
298,
3259,
402,
8683,
24649,
17,
6320,
267,
1995,
10666,
975,
8,
277,
12,
298,
66,
802,
401,
298,
10787,
1126,
7148,
531,
327,
1443,
506,
4697,
367,
26951,
15,
28412,
24945,
398,
327,
3394,
650,
334,
2167,
2783,
9,
267,
340,
291,
905,
1291,
63,
890,
4140,
585,
665,
6335,
26,
288,
372,
267,
1995,
11305,
8,
13304,
708,
8,
277,
12,
298,
12849,
401,
298,
25551,
1083,
1288,
699,
311,
1173,
14,
30193,
63,
2339,
9,
267,
1995,
10666,
708,
8,
277,
12,
298,
1569,
63,
890,
401,
298,
3491,
1568,
334,
2394,
6320,
267,
1995,
10666,
708,
8,
277,
12,
298,
11392,
63,
23595,
401,
298,
19918,
577,
2252,
531,
267,
1995,
10666,
708,
8,
277,
12,
298,
7870,
63,
23595,
401,
298,
19462,
577,
2252,
531,
267,
1995,
10666,
708,
8,
277,
12,
298,
2972,
63,
7120,
401,
298,
3259,
402,
3164,
1202,
531,
267,
1995,
10666,
708,
8,
277,
12,
298,
19559,
63,
2326,
401,
298,
3259,
402,
492,
9229,
531,
398,
327,
3394,
841,
334,
8079,
2783,
9,
267,
340,
291,
905,
1291,
63,
890,
4140,
585,
665,
24579,
26,
288,
372,
267,
1995,
1318,
2461,
8,
13304,
708,
8,
277,
12,
298,
581,
63,
2629,
1288,
20379,
9,
267,
1995,
1318,
2461,
8,
13304,
708,
8,
277,
12,
298,
7731,
63,
2629,
1288,
20379,
9,
267,
1995,
1318,
2461,
8,
13304,
708,
8,
277,
12,
298,
6304,
63,
2629,
1288,
20379,
9,
267,
1995,
1318,
2461,
8,
13304,
708,
8,
277,
12,
298,
4468,
63,
2629,
1288,
20379,
9,
267,
1995,
11305,
8,
13304,
708,
8,
277,
12,
298,
2326,
63,
2638,
1288,
291,
14,
2326,
63,
2638,
63,
354,
9,
267,
1995,
445,
41,
1438,
26184,
8,
277,
12,
298,
581,
63,
3327,
531,
267,
1995,
445,
41,
1438,
26184,
8,
277,
12,
298,
7731,
63,
3327,
531,
267,
1995,
445,
41,
1438,
26184,
8,
277,
12,
298,
6304,
63,
3327,
531,
267,
1995,
10666,
708,
8,
277,
12,
298,
7325,
63,
581,
531,
267,
1995,
10666,
708,
8,
277,
12,
298,
7325,
63,
7731,
531,
267,
1995,
10666,
708,
8,
277,
12,
298,
7325,
63,
6304,
531,
199,
199
] |
[
199,
12940,
10199,
1130,
24945,
1798,
14,
199,
13,
570,
3329,
26,
3680,
22308,
2,
199,
199,
5949,
26,
6561,
630,
428,
1346,
1372,
199,
13921,
26,
3193,
477,
26381,
11811,
199,
624,
199,
199,
504,
394,
21301,
63,
2087,
492,
10191,
199,
504,
394,
21301,
63,
1018,
14,
698,
492,
334,
23532,
12,
272,
10666,
24,
12,
10666,
975,
12,
10666,
708,
12,
26612,
12,
272,
2624,
12,
13480,
5571,
12,
11305,
12,
272,
510,
4095,
5571,
12,
12119,
5571,
12,
1218,
15069,
792,
9,
199,
504,
394,
21301,
63,
1018,
14,
15009,
492,
491,
31783,
63,
21046,
199,
504,
394,
21301,
63,
1018,
14,
505,
63,
2232,
492,
1318,
2461,
12,
20379,
199,
504,
394,
21301,
63,
2087,
14,
1569,
14,
2330,
492,
19013,
12,
510,
22116,
21631,
199,
504,
394,
21301,
63,
1018,
14,
2537,
492,
6998,
1110,
199,
199,
533,
510,
5887,
20,
2075,
8,
10787,
304,
272,
2955,
63,
890,
275,
841,
272,
347,
636,
826,
721,
277,
12,
1676,
12,
536,
304,
267,
26612,
855,
826,
721,
277,
12,
1676,
12,
536,
12,
841,
9,
199,
199,
533,
6047,
3049,
8,
23532,
304,
272,
347,
636,
826,
721,
277,
12,
1676,
12,
536,
12,
3462,
12,
7148,
63,
533,
304,
267,
5024,
1084,
855,
826,
721,
277,
12,
1676,
12,
536,
9,
267,
291,
423,
8435,
275,
7148,
63,
533,
267,
291,
423,
2063,
275,
3462,
267,
291,
423,
890,
275,
6998,
1110,
8,
277,
423,
2063,
627,
291,
423,
8435,
14,
1986,
63,
890,
12,
4337,
9,
339,
347,
24828,
8,
277,
304,
267,
367,
671,
315,
4945,
8,
277,
423,
2063,
304,
288,
1995,
291,
423,
8435,
8,
277,
12,
298,
8435,
31346,
267,
1568,
275,
291,
14,
890,
446,
291,
14,
1818,
63,
890,
267,
340,
1568,
26,
288,
1995,
1218,
15069,
792,
8,
277,
12,
1568,
9,
199,
199,
533,
6047,
29170,
8,
23532,
304,
272,
347,
636,
826,
721,
277,
12,
1676,
12,
536,
12,
3462,
12,
4569,
12,
7148,
63,
533,
12,
1568,
29,
403,
304,
267,
5024,
1084,
855,
826,
721,
277,
12,
1676,
12,
536,
12,
1568,
29,
890,
9,
267,
291,
423,
2063,
275,
3462,
267,
291,
423,
3333,
275,
4569,
267,
291,
423,
8435,
275,
7148,
63,
533,
339,
347,
24828,
8,
277,
304,
267,
367,
612,
315,
4945,
8,
277,
423,
3333,
13,
17,
12,
446,
17,
12,
446,
17,
304,
288,
1995,
6047,
3049,
8,
277,
12,
298,
604,
9722,
85,
8480,
450,
612,
12,
291,
423,
2063,
12,
291,
423,
8435,
9,
267,
1568,
275,
334,
277,
14,
890,
446,
291,
14,
1818,
63,
890,
9,
5001,
1695,
267,
340,
1568,
26,
288,
1995,
12119,
5571,
8,
277,
12,
298,
8358,
401,
1568,
9,
199,
199,
533,
445,
41,
1438,
26184,
8,
23532,
304,
272,
347,
24828,
8,
277,
304,
267,
1995,
10666,
708,
8,
277,
12,
298,
88,
531,
267,
1995,
10666,
708,
8,
277,
12,
298,
89,
531,
267,
1995,
10666,
708,
8,
277,
12,
298,
90,
531,
199,
199,
533,
699,
311,
2567,
8,
23532,
304,
272,
3164,
63,
2638,
63,
354,
275,
469,
267,
413,
26,
298,
12106,
9585,
334,
22332,
1542,
4186,
267,
499,
26,
298,
18859,
334,
15277,
4186,
267,
841,
26,
298,
18882,
334,
2623,
716,
1061,
4186,
267,
1695,
26,
298,
24677,
3164,
5165,
334,
24677,
4186,
272,
789,
339,
347,
664,
3484,
3353,
8,
277,
304,
267,
340,
298,
7325,
63,
6304,
2,
315,
291,
26,
288,
372,
841,
267,
340,
298,
19559,
63,
2326,
2,
315,
291,
26,
288,
372,
650,
267,
372,
499,
339,
347,
24828,
8,
277,
304,
267,
327,
3394,
499,
334,
713,
2783,
9,
267,
1995,
10666,
708,
8,
277,
12,
298,
1291,
63,
890,
401,
298,
2567,
1568,
531,
267,
1995,
10666,
708,
8,
277,
12,
298,
2063,
401,
298,
6216,
334,
15727,
6320,
267,
1995,
10666,
708,
8,
277,
12,
298,
3333,
401,
298,
8436,
334,
15727,
6320,
267,
1995,
10666,
975,
8,
277,
12,
298,
4994,
63,
5140,
401,
298,
3259,
402,
8683,
24649,
17,
6320,
267,
1995,
10666,
975,
8,
277,
12,
298,
66,
802,
401,
298,
10787,
1126,
7148,
531,
327,
1443,
506,
4697,
367,
26951,
15,
28412,
24945,
398,
327,
3394,
650,
334,
2167,
2783,
9,
267,
340,
291,
905,
1291,
63,
890,
4140,
585,
665,
6335,
26,
288,
372,
267,
1995,
11305,
8,
13304,
708,
8,
277,
12,
298,
12849,
401,
298,
25551,
1083,
1288,
699,
311,
1173,
14,
30193,
63,
2339,
9,
267,
1995,
10666,
708,
8,
277,
12,
298,
1569,
63,
890,
401,
298,
3491,
1568,
334,
2394,
6320,
267,
1995,
10666,
708,
8,
277,
12,
298,
11392,
63,
23595,
401,
298,
19918,
577,
2252,
531,
267,
1995,
10666,
708,
8,
277,
12,
298,
7870,
63,
23595,
401,
298,
19462,
577,
2252,
531,
267,
1995,
10666,
708,
8,
277,
12,
298,
2972,
63,
7120,
401,
298,
3259,
402,
3164,
1202,
531,
267,
1995,
10666,
708,
8,
277,
12,
298,
19559,
63,
2326,
401,
298,
3259,
402,
492,
9229,
531,
398,
327,
3394,
841,
334,
8079,
2783,
9,
267,
340,
291,
905,
1291,
63,
890,
4140,
585,
665,
24579,
26,
288,
372,
267,
1995,
1318,
2461,
8,
13304,
708,
8,
277,
12,
298,
581,
63,
2629,
1288,
20379,
9,
267,
1995,
1318,
2461,
8,
13304,
708,
8,
277,
12,
298,
7731,
63,
2629,
1288,
20379,
9,
267,
1995,
1318,
2461,
8,
13304,
708,
8,
277,
12,
298,
6304,
63,
2629,
1288,
20379,
9,
267,
1995,
1318,
2461,
8,
13304,
708,
8,
277,
12,
298,
4468,
63,
2629,
1288,
20379,
9,
267,
1995,
11305,
8,
13304,
708,
8,
277,
12,
298,
2326,
63,
2638,
1288,
291,
14,
2326,
63,
2638,
63,
354,
9,
267,
1995,
445,
41,
1438,
26184,
8,
277,
12,
298,
581,
63,
3327,
531,
267,
1995,
445,
41,
1438,
26184,
8,
277,
12,
298,
7731,
63,
3327,
531,
267,
1995,
445,
41,
1438,
26184,
8,
277,
12,
298,
6304,
63,
3327,
531,
267,
1995,
10666,
708,
8,
277,
12,
298,
7325,
63,
581,
531,
267,
1995,
10666,
708,
8,
277,
12,
298,
7325,
63,
7731,
531,
267,
1995,
10666,
708,
8,
277,
12,
298,
7325,
63,
6304,
531,
199,
199,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ksrajkumar/openerp-6.1
|
openerp/addons/point_of_sale/wizard/pos_receipt.py
|
9
|
2286
|
# -*- 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 osv import osv
from tools.translate import _
class pos_receipt(osv.osv_memory):
_name = 'pos.receipt'
_description = 'Point of sale receipt'
def view_init(self, cr, uid, fields_list, context=None):
"""
Creates view dynamically and adding fields at runtime.
@param self: The object pointer.
@param cr: A database cursor
@param uid: ID of the user currently logged in
@param context: A standard dictionary
@return: New arch of view with new columns.
"""
order_lst = self. pool.get('pos.order').browse(cr, uid, context['active_id'], context=context)
def print_report(self, cr, uid, ids, context=None):
"""
To get the date and print the report
@param self: The object pointer.
@param cr: A database cursor
@param uid: ID of the user currently logged in
@param context: A standard dictionary
@return : retrun report
"""
if context is None:
context = {}
datas = {'ids': context.get('active_ids', [])}
return {
'type': 'ir.actions.report.xml',
'report_name': 'pos.receipt',
'datas': datas,
}
pos_receipt()
# 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,
9506,
492,
9506,
199,
504,
7249,
14,
5275,
492,
485,
199,
199,
533,
2086,
63,
18905,
8,
4795,
14,
4795,
63,
4844,
304,
272,
485,
354,
275,
283,
1712,
14,
18905,
7,
272,
485,
1802,
275,
283,
3428,
402,
13590,
31594,
7,
339,
347,
2455,
63,
826,
8,
277,
12,
2467,
12,
1747,
12,
1504,
63,
513,
12,
1067,
29,
403,
304,
267,
408,
267,
10560,
2455,
18774,
436,
7791,
1504,
737,
8836,
14,
267,
768,
635,
291,
26,
710,
909,
7849,
14,
267,
768,
635,
2467,
26,
437,
3050,
3920,
267,
768,
635,
1747,
26,
2870,
402,
314,
922,
5544,
10367,
315,
267,
768,
635,
1067,
26,
437,
4465,
2600,
267,
768,
1107,
26,
7053,
3819,
402,
2455,
543,
892,
4362,
14,
267,
408,
267,
1865,
63,
6916,
275,
291,
14,
4203,
14,
362,
360,
1712,
14,
1648,
1959,
4570,
8,
1556,
12,
1747,
12,
1067,
459,
2682,
63,
344,
995,
1067,
29,
1100,
9,
339,
347,
870,
63,
3070,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
1067,
29,
403,
304,
267,
408,
267,
4005,
664,
314,
1434,
436,
870,
314,
3622,
267,
768,
635,
291,
26,
710,
909,
7849,
14,
267,
768,
635,
2467,
26,
437,
3050,
3920,
267,
768,
635,
1747,
26,
2870,
402,
314,
922,
5544,
10367,
315,
267,
768,
635,
1067,
26,
437,
4465,
2600,
267,
768,
1107,
520,
295,
454,
324,
3622,
267,
408,
267,
340,
1067,
365,
488,
26,
288,
1067,
275,
1052,
267,
15012,
275,
791,
1580,
356,
1067,
14,
362,
360,
2682,
63,
1580,
297,
3073,
93,
267,
372,
469,
288,
283,
466,
356,
283,
723,
14,
3723,
14,
3070,
14,
1652,
297,
288,
283,
3070,
63,
354,
356,
283,
1712,
14,
18905,
297,
288,
283,
11563,
356,
15012,
12,
267,
789,
199,
199,
1712,
63,
18905,
342,
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
] |
[
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,
9506,
492,
9506,
199,
504,
7249,
14,
5275,
492,
485,
199,
199,
533,
2086,
63,
18905,
8,
4795,
14,
4795,
63,
4844,
304,
272,
485,
354,
275,
283,
1712,
14,
18905,
7,
272,
485,
1802,
275,
283,
3428,
402,
13590,
31594,
7,
339,
347,
2455,
63,
826,
8,
277,
12,
2467,
12,
1747,
12,
1504,
63,
513,
12,
1067,
29,
403,
304,
267,
408,
267,
10560,
2455,
18774,
436,
7791,
1504,
737,
8836,
14,
267,
768,
635,
291,
26,
710,
909,
7849,
14,
267,
768,
635,
2467,
26,
437,
3050,
3920,
267,
768,
635,
1747,
26,
2870,
402,
314,
922,
5544,
10367,
315,
267,
768,
635,
1067,
26,
437,
4465,
2600,
267,
768,
1107,
26,
7053,
3819,
402,
2455,
543,
892,
4362,
14,
267,
408,
267,
1865,
63,
6916,
275,
291,
14,
4203,
14,
362,
360,
1712,
14,
1648,
1959,
4570,
8,
1556,
12,
1747,
12,
1067,
459,
2682,
63,
344,
995,
1067,
29,
1100,
9,
339,
347,
870,
63,
3070,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
1067,
29,
403,
304,
267,
408,
267,
4005,
664,
314,
1434,
436,
870,
314,
3622,
267,
768,
635,
291,
26,
710,
909,
7849,
14,
267,
768,
635,
2467,
26,
437,
3050,
3920,
267,
768,
635,
1747,
26,
2870,
402,
314,
922,
5544,
10367,
315,
267,
768,
635,
1067,
26,
437,
4465,
2600,
267,
768,
1107,
520,
295,
454,
324,
3622,
267,
408,
267,
340,
1067,
365,
488,
26,
288,
1067,
275,
1052,
267,
15012,
275,
791,
1580,
356,
1067,
14,
362,
360,
2682,
63,
1580,
297,
3073,
93,
267,
372,
469,
288,
283,
466,
356,
283,
723,
14,
3723,
14,
3070,
14,
1652,
297,
288,
283,
3070,
63,
354,
356,
283,
1712,
14,
18905,
297,
288,
283,
11563,
356,
15012,
12,
267,
789,
199,
199,
1712,
63,
18905,
342,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
semonte/intellij-community
|
python/helpers/coveragepy/coverage/backunittest.py
|
95
|
1515
|
# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
# For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt
"""Implementations of unittest features from the future."""
# Use unittest2 if it's available, otherwise unittest. This gives us
# back-ported features for 2.6.
try:
import unittest2 as unittest
except ImportError:
import unittest
def unittest_has(method):
"""Does `unittest.TestCase` have `method` defined?"""
return hasattr(unittest.TestCase, method)
class TestCase(unittest.TestCase):
"""Just like unittest.TestCase, but with assert methods added.
Designed to be compatible with 3.1 unittest. Methods are only defined if
`unittest` doesn't have them.
"""
# pylint: disable=missing-docstring
# Many Pythons have this method defined. But PyPy3 has a bug with it
# somehow (https://bitbucket.org/pypy/pypy/issues/2092), so always use our
# own implementation that works everywhere, at least for the ways we're
# calling it.
def assertCountEqual(self, s1, s2):
"""Assert these have the same elements, regardless of order."""
self.assertEqual(sorted(s1), sorted(s2))
if not unittest_has('assertRaisesRegex'):
def assertRaisesRegex(self, *args, **kwargs):
return self.assertRaisesRegexp(*args, **kwargs)
if not unittest_has('assertRegex'):
def assertRegex(self, *args, **kwargs):
return self.assertRegexpMatches(*args, **kwargs)
|
apache-2.0
|
[
3,
3909,
1334,
314,
3668,
844,
26,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
2104,
2436,
26,
4178,
921,
25668,
14,
1308,
15,
7439,
15,
10828,
647,
15,
2164,
15,
885,
15,
4609,
4047,
14,
2424,
199,
199,
624,
26924,
1298,
402,
2882,
4534,
687,
314,
6466,
1041,
199,
199,
3,
3645,
2882,
18,
340,
652,
1159,
2808,
12,
4257,
2882,
14,
221,
961,
10557,
2739,
199,
3,
1771,
13,
2315,
4534,
367,
499,
14,
22,
14,
199,
893,
26,
272,
492,
2882,
18,
465,
2882,
199,
2590,
3545,
26,
272,
492,
2882,
421,
199,
318,
2882,
63,
1989,
8,
765,
304,
272,
408,
6586,
658,
2796,
14,
1746,
64,
1172,
658,
765,
64,
3247,
30196,
272,
372,
2688,
8,
2796,
14,
1746,
12,
1083,
9,
421,
199,
533,
7640,
8,
2796,
14,
1746,
304,
272,
408,
22850,
2839,
2882,
14,
1746,
12,
1325,
543,
702,
3102,
3483,
14,
339,
1487,
1737,
370,
506,
9025,
543,
650,
14,
17,
2882,
14,
221,
17653,
787,
1454,
3247,
340,
272,
658,
2796,
64,
3181,
1133,
1172,
3062,
14,
339,
408,
272,
327,
4287,
26,
3507,
29,
4752,
13,
12485,
339,
327,
15517,
2018,
83,
1172,
642,
1083,
3247,
14,
221,
11017,
1611,
2713,
19,
965,
282,
6519,
543,
652,
272,
327,
29437,
334,
2859,
921,
25668,
14,
1308,
15,
20233,
15,
20233,
15,
10115,
15,
1165,
2942,
395,
880,
3544,
675,
4154,
272,
327,
5705,
4514,
626,
5419,
4036,
4509,
12,
737,
5210,
367,
314,
15217,
781,
3984,
272,
327,
6358,
652,
14,
272,
347,
702,
29004,
8,
277,
12,
308,
17,
12,
308,
18,
304,
267,
408,
9699,
3520,
1172,
314,
2011,
4008,
12,
15270,
402,
1865,
1041,
267,
291,
14,
629,
8,
5917,
8,
83,
17,
395,
3355,
8,
83,
18,
430,
339,
340,
440,
2882,
63,
1989,
360,
16499,
735,
267,
347,
702,
1811,
5103,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
288,
372,
291,
14,
10835,
2031,
589,
12,
1011,
958,
9,
339,
340,
440,
2882,
63,
1989,
360,
31132,
735,
267,
347,
702,
5103,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
288,
372,
291,
14,
26672,
2031,
589,
12,
1011,
958,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
3909,
1334,
314,
3668,
844,
26,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
2104,
2436,
26,
4178,
921,
25668,
14,
1308,
15,
7439,
15,
10828,
647,
15,
2164,
15,
885,
15,
4609,
4047,
14,
2424,
199,
199,
624,
26924,
1298,
402,
2882,
4534,
687,
314,
6466,
1041,
199,
199,
3,
3645,
2882,
18,
340,
652,
1159,
2808,
12,
4257,
2882,
14,
221,
961,
10557,
2739,
199,
3,
1771,
13,
2315,
4534,
367,
499,
14,
22,
14,
199,
893,
26,
272,
492,
2882,
18,
465,
2882,
199,
2590,
3545,
26,
272,
492,
2882,
421,
199,
318,
2882,
63,
1989,
8,
765,
304,
272,
408,
6586,
658,
2796,
14,
1746,
64,
1172,
658,
765,
64,
3247,
30196,
272,
372,
2688,
8,
2796,
14,
1746,
12,
1083,
9,
421,
199,
533,
7640,
8,
2796,
14,
1746,
304,
272,
408,
22850,
2839,
2882,
14,
1746,
12,
1325,
543,
702,
3102,
3483,
14,
339,
1487,
1737,
370,
506,
9025,
543,
650,
14,
17,
2882,
14,
221,
17653,
787,
1454,
3247,
340,
272,
658,
2796,
64,
3181,
1133,
1172,
3062,
14,
339,
408,
272,
327,
4287,
26,
3507,
29,
4752,
13,
12485,
339,
327,
15517,
2018,
83,
1172,
642,
1083,
3247,
14,
221,
11017,
1611,
2713,
19,
965,
282,
6519,
543,
652,
272,
327,
29437,
334,
2859,
921,
25668,
14,
1308,
15,
20233,
15,
20233,
15,
10115,
15,
1165,
2942,
395,
880,
3544,
675,
4154,
272,
327,
5705,
4514,
626,
5419,
4036,
4509,
12,
737,
5210,
367,
314,
15217,
781,
3984,
272,
327,
6358,
652,
14,
272,
347,
702,
29004,
8,
277,
12,
308,
17,
12,
308,
18,
304,
267,
408,
9699,
3520,
1172,
314,
2011,
4008,
12,
15270,
402,
1865,
1041,
267,
291,
14,
629,
8,
5917,
8,
83,
17,
395,
3355,
8,
83,
18,
430,
339,
340,
440,
2882,
63,
1989,
360,
16499,
735,
267,
347,
702,
1811,
5103,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
288,
372,
291,
14,
10835,
2031,
589,
12,
1011,
958,
9,
339,
340,
440,
2882,
63,
1989,
360,
31132,
735,
267,
347,
702,
5103,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
288,
372,
291,
14,
26672,
2031,
589,
12,
1011,
958,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
Malpp/Mouse
|
main.py
|
1
|
1323
|
import win32api, win32con, win32gui, sys
from flask import Flask, send_from_directory, request
def click():
(x,y) = win32gui.GetCursorPos()
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,x,y,0,0)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,x,y,0,0)
def rclick():
(x,y) = win32gui.GetCursorPos()
win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTDOWN,x,y,0,0)
win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTUP,x,y,0,0)
def move(xx,yy):
(x,y) = win32gui.GetCursorPos()
win32api.SetCursorPos((x+int(xx),y+int(yy)))
def scroll(yy):
(x,y) = win32gui.GetCursorPos()
win32api.mouse_event(win32con.MOUSEEVENTF_WHEEL, x, y, yy, 0)
app = Flask(__name__)
@app.route("/")
def index():
return send_from_directory('', 'index.html')
@app.route("/move")
def mPage():
move(request.args.get('x'),request.args.get('y'))
return ""
@app.route("/click")
def cPage():
click()
return ""
@app.route("/rclick")
def rPage():
rclick()
return ""
@app.route("/scroll")
def sPage():
scroll(int(request.args.get('y')))
return ""
@app.route('/js/<path:path>')
def send_js(path):
return send_from_directory('js', path)
if __name__ == "__main__":
app.debug = True
app.run(host="0.0.0.0",port=80)
|
mit
|
[
646,
4747,
708,
1246,
12,
4747,
708,
388,
12,
4747,
708,
5885,
12,
984,
202,
199,
504,
7209,
492,
16704,
12,
3222,
63,
504,
63,
3619,
12,
1056,
2999,
199,
318,
8968,
837,
1128,
334,
88,
12,
89,
9,
275,
4747,
708,
5885,
14,
1002,
8993,
6981,
342,
1128,
4747,
708,
1246,
14,
10544,
63,
1430,
8,
2676,
708,
388,
14,
25571,
8193,
38,
63,
9894,
8819,
12,
88,
12,
89,
12,
16,
12,
16,
9,
1128,
4747,
708,
1246,
14,
10544,
63,
1430,
8,
2676,
708,
388,
14,
25571,
8193,
38,
63,
9894,
2160,
12,
88,
12,
89,
12,
16,
12,
16,
9,
2999,
199,
318,
519,
4891,
837,
1128,
334,
88,
12,
89,
9,
275,
4747,
708,
5885,
14,
1002,
8993,
6981,
342,
1128,
4747,
708,
1246,
14,
10544,
63,
1430,
8,
2676,
708,
388,
14,
25571,
8193,
38,
63,
12811,
8819,
12,
88,
12,
89,
12,
16,
12,
16,
9,
1128,
4747,
708,
1246,
14,
10544,
63,
1430,
8,
2676,
708,
388,
14,
25571,
8193,
38,
63,
12811,
2160,
12,
88,
12,
89,
12,
16,
12,
16,
9,
2999,
199,
318,
4057,
8,
2154,
12,
7566,
304,
1128,
334,
88,
12,
89,
9,
275,
4747,
708,
5885,
14,
1002,
8993,
6981,
342,
1128,
4747,
708,
1246,
14,
1084,
8993,
6981,
1332,
88,
11,
442,
8,
2154,
395,
89,
11,
442,
8,
7566,
1724,
2999,
199,
318,
13704,
8,
7566,
304,
1128,
334,
88,
12,
89,
9,
275,
4747,
708,
5885,
14,
1002,
8993,
6981,
342,
1128,
4747,
708,
1246,
14,
10544,
63,
1430,
8,
2676,
708,
388,
14,
25571,
8193,
38,
63,
31588,
2901,
12,
671,
12,
612,
12,
20435,
12,
378,
9,
2999,
199,
571,
275,
16704,
3460,
354,
3368,
15497,
202,
199,
32,
571,
14,
4449,
19031,
202,
199,
318,
1478,
837,
1128,
372,
3222,
63,
504,
63,
3619,
8594,
283,
1080,
14,
1360,
358,
2999,
199,
32,
571,
14,
4449,
4769,
1185,
531,
202,
199,
318,
333,
3276,
837,
1128,
4057,
8,
1069,
14,
589,
14,
362,
360,
88,
659,
1069,
14,
589,
14,
362,
360,
89,
1333,
1128,
372,
3087,
2999,
199,
32,
571,
14,
4449,
4769,
4891,
531,
202,
199,
318,
286,
3276,
837,
1128,
8968,
342,
1128,
372,
3087,
2999,
199,
32,
571,
14,
4449,
4769,
1195,
8442,
531,
202,
199,
318,
519,
3276,
837,
1128,
519,
4891,
342,
1128,
372,
3087,
2999,
199,
32,
571,
14,
4449,
4769,
6755,
531,
202,
199,
318,
308,
3276,
837,
1128,
13704,
8,
442,
8,
1069,
14,
589,
14,
362,
360,
89,
7058,
1128,
372,
3087,
2999,
199,
32,
571,
14,
4449,
2336,
3596,
8316,
515,
26,
515,
5971,
202,
199,
318,
3222,
63,
3596,
8,
515,
304,
1128,
372,
3222,
63,
504,
63,
3619,
360,
3596,
297,
931,
9,
2999,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
1128,
1145,
14,
1757,
275,
715,
1128,
1145,
14,
1065,
8,
1102,
628,
16,
14,
16,
14,
16,
14,
16,
401,
719,
29,
1257,
9,
1223,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
4747,
708,
1246,
12,
4747,
708,
388,
12,
4747,
708,
5885,
12,
984,
202,
199,
504,
7209,
492,
16704,
12,
3222,
63,
504,
63,
3619,
12,
1056,
2999,
199,
318,
8968,
837,
1128,
334,
88,
12,
89,
9,
275,
4747,
708,
5885,
14,
1002,
8993,
6981,
342,
1128,
4747,
708,
1246,
14,
10544,
63,
1430,
8,
2676,
708,
388,
14,
25571,
8193,
38,
63,
9894,
8819,
12,
88,
12,
89,
12,
16,
12,
16,
9,
1128,
4747,
708,
1246,
14,
10544,
63,
1430,
8,
2676,
708,
388,
14,
25571,
8193,
38,
63,
9894,
2160,
12,
88,
12,
89,
12,
16,
12,
16,
9,
2999,
199,
318,
519,
4891,
837,
1128,
334,
88,
12,
89,
9,
275,
4747,
708,
5885,
14,
1002,
8993,
6981,
342,
1128,
4747,
708,
1246,
14,
10544,
63,
1430,
8,
2676,
708,
388,
14,
25571,
8193,
38,
63,
12811,
8819,
12,
88,
12,
89,
12,
16,
12,
16,
9,
1128,
4747,
708,
1246,
14,
10544,
63,
1430,
8,
2676,
708,
388,
14,
25571,
8193,
38,
63,
12811,
2160,
12,
88,
12,
89,
12,
16,
12,
16,
9,
2999,
199,
318,
4057,
8,
2154,
12,
7566,
304,
1128,
334,
88,
12,
89,
9,
275,
4747,
708,
5885,
14,
1002,
8993,
6981,
342,
1128,
4747,
708,
1246,
14,
1084,
8993,
6981,
1332,
88,
11,
442,
8,
2154,
395,
89,
11,
442,
8,
7566,
1724,
2999,
199,
318,
13704,
8,
7566,
304,
1128,
334,
88,
12,
89,
9,
275,
4747,
708,
5885,
14,
1002,
8993,
6981,
342,
1128,
4747,
708,
1246,
14,
10544,
63,
1430,
8,
2676,
708,
388,
14,
25571,
8193,
38,
63,
31588,
2901,
12,
671,
12,
612,
12,
20435,
12,
378,
9,
2999,
199,
571,
275,
16704,
3460,
354,
3368,
15497,
202,
199,
32,
571,
14,
4449,
19031,
202,
199,
318,
1478,
837,
1128,
372,
3222,
63,
504,
63,
3619,
8594,
283,
1080,
14,
1360,
358,
2999,
199,
32,
571,
14,
4449,
4769,
1185,
531,
202,
199,
318,
333,
3276,
837,
1128,
4057,
8,
1069,
14,
589,
14,
362,
360,
88,
659,
1069,
14,
589,
14,
362,
360,
89,
1333,
1128,
372,
3087,
2999,
199,
32,
571,
14,
4449,
4769,
4891,
531,
202,
199,
318,
286,
3276,
837,
1128,
8968,
342,
1128,
372,
3087,
2999,
199,
32,
571,
14,
4449,
4769,
1195,
8442,
531,
202,
199,
318,
519,
3276,
837,
1128,
519,
4891,
342,
1128,
372,
3087,
2999,
199,
32,
571,
14,
4449,
4769,
6755,
531,
202,
199,
318,
308,
3276,
837,
1128,
13704,
8,
442,
8,
1069,
14,
589,
14,
362,
360,
89,
7058,
1128,
372,
3087,
2999,
199,
32,
571,
14,
4449,
2336,
3596,
8316,
515,
26,
515,
5971,
202,
199,
318,
3222,
63,
3596,
8,
515,
304,
1128,
372,
3222,
63,
504,
63,
3619,
360,
3596,
297,
931,
9,
2999,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
1128,
1145,
14,
1757,
275,
715,
1128,
1145,
14,
1065,
8,
1102,
628,
16,
14,
16,
14,
16,
14,
16,
401,
719,
29,
1257,
9,
1223,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
mscuthbert/abjad
|
abjad/tools/rhythmmakertools/Talea.py
|
1
|
4052
|
# -*- encoding: utf-8 -*-
from abjad.tools import datastructuretools
from abjad.tools import durationtools
from abjad.tools import mathtools
from abjad.tools.abctools import AbjadValueObject
class Talea(AbjadValueObject):
'''Talea.
.. container:: example
::
>>> talea = rhythmmakertools.Talea(
... counts=(2, 1, 3, 2, 4, 1, 1),
... denominator=16,
... )
.. container:: example
::
>>> talea[2]
NonreducedFraction(3, 16)
.. container:: example
::
>>> for nonreduced_fraction in talea[3:9]:
... nonreduced_fraction
...
NonreducedFraction(2, 16)
NonreducedFraction(4, 16)
NonreducedFraction(1, 16)
NonreducedFraction(1, 16)
NonreducedFraction(2, 16)
NonreducedFraction(1, 16)
'''
### CLASS VARIABLES ###
__documentation_section__ = 'Specifiers'
__slots__ = (
'_counts',
'_denominator',
)
### INITIALIZER ###
def __init__(
self,
counts=(1,),
denominator=16,
):
counts = self._to_tuple(counts)
assert isinstance(counts, tuple)
assert all(isinstance(x, int) for x in counts)
self._counts = counts
assert mathtools.is_nonnegative_integer_power_of_two(denominator)
self._denominator = denominator
### SPECIAL METHODS ###
def __eq__(self, expr):
r'''Is true when `expr` is a talea with `counts` and `denominator`
equal to those of this talea. Otherwise false.
Returns boolean.
'''
from abjad.tools import systemtools
return systemtools.StorageFormatManager.compare(self, expr)
def __getitem__(self, item):
r'''Gets non-reduced fraction at `item` cyclically.
Returns non-reduced fraction or non-reduced fractions.
'''
counts = datastructuretools.CyclicTuple(self.counts)
if isinstance(item, int):
count = counts[item]
return mathtools.NonreducedFraction(count, self.denominator)
elif isinstance(item, slice):
counts = counts[item]
result = [mathtools.NonreducedFraction(count, self.denominator)
for count in counts]
return result
raise ValueError(item)
def __hash__(self):
r'''Hashes talea.
Returns integer.
'''
from abjad.tools import systemtools
hash_values = systemtools.StorageFormatManager.get_hash_values(self)
return hash(hash_values)
def __iter__(self):
r'''Iterates talea.
.. container:: example
::
>>> talea = rhythmmakertools.Talea(
... counts=(2, 1, 3, 2, 4, 1, 1),
... denominator=16,
... )
>>> for duration in talea:
... duration
...
Duration(1, 8)
Duration(1, 16)
Duration(3, 16)
Duration(1, 8)
Duration(1, 4)
Duration(1, 16)
Duration(1, 16)
Yields durations.
'''
for count in self.counts:
duration = durationtools.Duration(count, self.denominator)
yield duration
def __len__(self):
r'''Gets length of talea.
Returns integer.
'''
return len(self.counts)
### PRIVATE METHODS ###
@staticmethod
def _to_tuple(expr):
if isinstance(expr, list):
expr = tuple(expr)
return expr
### PUBLIC PROPERTIES ###
@property
def counts(self):
r'''Gets counts of talea.
Returns tuple.
'''
return self._counts
@property
def denominator(self):
r'''Gets denominator of talea.
Returns nonnegative integer power of two.
'''
return self._denominator
|
gpl-3.0
|
[
3,
1882,
2644,
26,
2774,
13,
24,
1882,
199,
504,
282,
468,
350,
14,
2537,
492,
666,
6976,
2537,
199,
504,
282,
468,
350,
14,
2537,
492,
7373,
2537,
199,
504,
282,
468,
350,
14,
2537,
492,
3473,
2537,
199,
504,
282,
468,
350,
14,
2537,
14,
371,
319,
5998,
492,
437,
468,
350,
1110,
1692,
421,
199,
533,
377,
1895,
65,
8,
33,
468,
350,
1110,
1692,
304,
272,
1449,
52,
1895,
65,
14,
339,
2508,
221,
3970,
447,
2893,
398,
3800,
953,
1306,
307,
1895,
65,
275,
519,
3577,
273,
77,
14367,
2537,
14,
52,
1895,
65,
8,
288,
2263,
259,
8242,
2687,
18,
12,
413,
12,
650,
12,
499,
12,
841,
12,
413,
12,
413,
395,
288,
2263,
259,
21859,
29,
975,
12,
288,
2263,
259,
776,
339,
2508,
221,
3970,
447,
2893,
398,
3800,
953,
1306,
307,
1895,
65,
59,
18,
61,
288,
10172,
19523,
27217,
8,
19,
12,
3193,
9,
339,
2508,
221,
3970,
447,
2893,
398,
3800,
953,
1306,
367,
2222,
19523,
63,
13054,
315,
307,
1895,
65,
59,
19,
26,
25,
2189,
288,
2263,
258,
2222,
19523,
63,
13054,
288,
2263,
288,
10172,
19523,
27217,
8,
18,
12,
3193,
9,
288,
10172,
19523,
27217,
8,
20,
12,
3193,
9,
288,
10172,
19523,
27217,
8,
17,
12,
3193,
9,
288,
10172,
19523,
27217,
8,
17,
12,
3193,
9,
288,
10172,
19523,
27217,
8,
18,
12,
3193,
9,
288,
10172,
19523,
27217,
8,
17,
12,
3193,
9,
339,
1449,
339,
6754,
24221,
30098,
17041,
6754,
339,
636,
9970,
63,
2792,
363,
275,
283,
6154,
6069,
7,
339,
636,
7257,
363,
275,
334,
267,
2513,
6851,
297,
267,
2513,
17126,
297,
267,
776,
339,
6754,
26105,
5357,
540,
6754,
339,
347,
636,
826,
721,
267,
291,
12,
267,
8242,
2687,
17,
4706,
267,
21859,
29,
975,
12,
267,
3461,
267,
8242,
275,
291,
423,
475,
63,
2960,
8,
6851,
9,
267,
702,
1228,
8,
6851,
12,
2008,
9,
267,
702,
1006,
8,
6074,
8,
88,
12,
1109,
9,
367,
671,
315,
8242,
9,
267,
291,
423,
6851,
275,
8242,
267,
702,
3473,
2537,
14,
374,
63,
2865,
7371,
63,
4115,
63,
5652,
63,
1618,
63,
5601,
8,
17126,
9,
267,
291,
423,
17126,
275,
21859,
339,
6754,
8820,
27411,
3177,
6754,
339,
347,
636,
4077,
721,
277,
12,
5348,
304,
267,
519,
2344,
1831,
2549,
1380,
658,
3684,
64,
365,
282,
307,
1895,
65,
543,
658,
6851,
64,
436,
658,
17126,
64,
267,
4472,
370,
5204,
402,
642,
307,
1895,
65,
14,
6630,
3055,
14,
398,
1803,
5046,
14,
267,
1449,
267,
687,
282,
468,
350,
14,
2537,
492,
2656,
2537,
267,
372,
2656,
2537,
14,
6408,
3484,
2988,
14,
5785,
8,
277,
12,
5348,
9,
339,
347,
636,
6095,
721,
277,
12,
1242,
304,
267,
519,
2344,
14426,
2222,
13,
19523,
12347,
737,
658,
1053,
64,
32637,
1183,
14,
398,
1803,
2222,
13,
19523,
12347,
503,
2222,
13,
19523,
28213,
2452,
14,
267,
1449,
267,
8242,
275,
666,
6976,
2537,
14,
9156,
17542,
7075,
8,
277,
14,
6851,
9,
267,
340,
1228,
8,
1053,
12,
1109,
304,
288,
2338,
275,
8242,
59,
1053,
61,
288,
372,
3473,
2537,
14,
6932,
19523,
27217,
8,
835,
12,
291,
14,
17126,
9,
267,
916,
1228,
8,
1053,
12,
6014,
304,
288,
8242,
275,
8242,
59,
1053,
61,
288,
754,
275,
359,
3442,
2537,
14,
6932,
19523,
27217,
8,
835,
12,
291,
14,
17126,
9,
355,
367,
2338,
315,
8242,
61,
288,
372,
754,
267,
746,
1722,
8,
1053,
9,
339,
347,
636,
2227,
721,
277,
304,
267,
519,
2344,
31660,
307,
1895,
65,
14,
398,
1803,
3000,
14,
267,
1449,
267,
687,
282,
468,
350,
14,
2537,
492,
2656,
2537,
267,
2631,
63,
1459,
275,
2656,
2537,
14,
6408,
3484,
2988,
14,
362,
63,
2227,
63,
1459,
8,
277,
9,
267,
372,
2631,
8,
2227,
63,
1459,
9,
339,
347,
636,
1661,
721,
277,
304,
267,
519,
2344,
3315,
2335,
307,
1895,
65,
14,
398,
2508,
221,
3970,
447,
2893,
953,
3800,
2234,
1306,
307,
1895,
65,
275,
519,
3577,
273,
77,
14367,
2537,
14,
52,
1895,
65,
8,
355,
2263,
259,
8242,
2687,
18,
12,
413,
12,
650,
12,
499,
12,
841,
12,
413,
12,
413,
395,
355,
2263,
259,
21859,
29,
975,
12,
355,
2263,
259,
776,
355,
1306,
367,
7373,
315,
307,
1895,
65,
26,
355,
2263,
258,
7373,
355,
2263,
355,
31836,
8,
17,
12,
1695,
9,
355,
31836,
8,
17,
12,
3193,
9,
355,
31836,
8,
19,
12,
3193,
9,
355,
31836,
8,
17,
12,
1695,
9,
355,
31836,
8,
17,
12,
841,
9,
355,
31836,
8,
17,
12,
3193,
9,
355,
31836,
8,
17,
12,
3193,
9,
398,
23771,
83,
366,
6556,
14,
267,
1449,
267,
367,
2338,
315,
291,
14,
6851,
26,
288,
7373,
275,
7373,
2537,
14,
13283,
8,
835,
12,
291,
14,
17126,
9,
288,
1995,
7373,
339,
347,
636,
552,
721,
277,
304,
267,
519,
2344,
14426,
2582,
402,
307,
1895,
65,
14,
398,
1803,
3000,
14,
267,
1449,
267,
372,
822,
8,
277,
14,
6851,
9,
339,
6754,
28644,
1951,
27411,
3177,
6754,
339,
768,
4639,
272,
347,
485,
475,
63,
2960,
8,
3684,
304,
267,
340,
1228,
8,
3684,
12,
769,
304,
288,
5348,
275,
2008,
8,
3684,
9,
267,
372,
5348,
339,
6754,
21755,
3611,
4227,
29807,
6754,
339,
768,
1829,
272,
347,
8242,
8,
277,
304,
267,
519,
2344,
14426,
8242,
402,
307,
1895,
65,
14,
398,
1803,
2008,
14,
267,
1449,
267,
372,
291,
423,
6851,
339,
768,
1829,
272,
347,
21859,
8,
277,
304,
267,
519,
2344,
14426,
21859,
402,
307,
1895,
65,
14,
398,
1803,
2222,
7371,
3000,
7074,
402,
2877,
14,
267,
1449,
267,
372,
291,
423,
17126,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2644,
26,
2774,
13,
24,
1882,
199,
504,
282,
468,
350,
14,
2537,
492,
666,
6976,
2537,
199,
504,
282,
468,
350,
14,
2537,
492,
7373,
2537,
199,
504,
282,
468,
350,
14,
2537,
492,
3473,
2537,
199,
504,
282,
468,
350,
14,
2537,
14,
371,
319,
5998,
492,
437,
468,
350,
1110,
1692,
421,
199,
533,
377,
1895,
65,
8,
33,
468,
350,
1110,
1692,
304,
272,
1449,
52,
1895,
65,
14,
339,
2508,
221,
3970,
447,
2893,
398,
3800,
953,
1306,
307,
1895,
65,
275,
519,
3577,
273,
77,
14367,
2537,
14,
52,
1895,
65,
8,
288,
2263,
259,
8242,
2687,
18,
12,
413,
12,
650,
12,
499,
12,
841,
12,
413,
12,
413,
395,
288,
2263,
259,
21859,
29,
975,
12,
288,
2263,
259,
776,
339,
2508,
221,
3970,
447,
2893,
398,
3800,
953,
1306,
307,
1895,
65,
59,
18,
61,
288,
10172,
19523,
27217,
8,
19,
12,
3193,
9,
339,
2508,
221,
3970,
447,
2893,
398,
3800,
953,
1306,
367,
2222,
19523,
63,
13054,
315,
307,
1895,
65,
59,
19,
26,
25,
2189,
288,
2263,
258,
2222,
19523,
63,
13054,
288,
2263,
288,
10172,
19523,
27217,
8,
18,
12,
3193,
9,
288,
10172,
19523,
27217,
8,
20,
12,
3193,
9,
288,
10172,
19523,
27217,
8,
17,
12,
3193,
9,
288,
10172,
19523,
27217,
8,
17,
12,
3193,
9,
288,
10172,
19523,
27217,
8,
18,
12,
3193,
9,
288,
10172,
19523,
27217,
8,
17,
12,
3193,
9,
339,
1449,
339,
6754,
24221,
30098,
17041,
6754,
339,
636,
9970,
63,
2792,
363,
275,
283,
6154,
6069,
7,
339,
636,
7257,
363,
275,
334,
267,
2513,
6851,
297,
267,
2513,
17126,
297,
267,
776,
339,
6754,
26105,
5357,
540,
6754,
339,
347,
636,
826,
721,
267,
291,
12,
267,
8242,
2687,
17,
4706,
267,
21859,
29,
975,
12,
267,
3461,
267,
8242,
275,
291,
423,
475,
63,
2960,
8,
6851,
9,
267,
702,
1228,
8,
6851,
12,
2008,
9,
267,
702,
1006,
8,
6074,
8,
88,
12,
1109,
9,
367,
671,
315,
8242,
9,
267,
291,
423,
6851,
275,
8242,
267,
702,
3473,
2537,
14,
374,
63,
2865,
7371,
63,
4115,
63,
5652,
63,
1618,
63,
5601,
8,
17126,
9,
267,
291,
423,
17126,
275,
21859,
339,
6754,
8820,
27411,
3177,
6754,
339,
347,
636,
4077,
721,
277,
12,
5348,
304,
267,
519,
2344,
1831,
2549,
1380,
658,
3684,
64,
365,
282,
307,
1895,
65,
543,
658,
6851,
64,
436,
658,
17126,
64,
267,
4472,
370,
5204,
402,
642,
307,
1895,
65,
14,
6630,
3055,
14,
398,
1803,
5046,
14,
267,
1449,
267,
687,
282,
468,
350,
14,
2537,
492,
2656,
2537,
267,
372,
2656,
2537,
14,
6408,
3484,
2988,
14,
5785,
8,
277,
12,
5348,
9,
339,
347,
636,
6095,
721,
277,
12,
1242,
304,
267,
519,
2344,
14426,
2222,
13,
19523,
12347,
737,
658,
1053,
64,
32637,
1183,
14,
398,
1803,
2222,
13,
19523,
12347,
503,
2222,
13,
19523,
28213,
2452,
14,
267,
1449,
267,
8242,
275,
666,
6976,
2537,
14,
9156,
17542,
7075,
8,
277,
14,
6851,
9,
267,
340,
1228,
8,
1053,
12,
1109,
304,
288,
2338,
275,
8242,
59,
1053,
61,
288,
372,
3473,
2537,
14,
6932,
19523,
27217,
8,
835,
12,
291,
14,
17126,
9,
267,
916,
1228,
8,
1053,
12,
6014,
304,
288,
8242,
275,
8242,
59,
1053,
61,
288,
754,
275,
359,
3442,
2537,
14,
6932,
19523,
27217,
8,
835,
12,
291,
14,
17126,
9,
355,
367,
2338,
315,
8242,
61,
288,
372,
754,
267,
746,
1722,
8,
1053,
9,
339,
347,
636,
2227,
721,
277,
304,
267,
519,
2344,
31660,
307,
1895,
65,
14,
398,
1803,
3000,
14,
267,
1449,
267,
687,
282,
468,
350,
14,
2537,
492,
2656,
2537,
267,
2631,
63,
1459,
275,
2656,
2537,
14,
6408,
3484,
2988,
14,
362,
63,
2227,
63,
1459,
8,
277,
9,
267,
372,
2631,
8,
2227,
63,
1459,
9,
339,
347,
636,
1661,
721,
277,
304,
267,
519,
2344,
3315,
2335,
307,
1895,
65,
14,
398,
2508,
221,
3970,
447,
2893,
953,
3800,
2234,
1306,
307,
1895,
65,
275,
519,
3577,
273,
77,
14367,
2537,
14,
52,
1895,
65,
8,
355,
2263,
259,
8242,
2687,
18,
12,
413,
12,
650,
12,
499,
12,
841,
12,
413,
12,
413,
395,
355,
2263,
259,
21859,
29,
975,
12,
355,
2263,
259,
776,
355,
1306,
367,
7373,
315,
307,
1895,
65,
26,
355,
2263,
258,
7373,
355,
2263,
355,
31836,
8,
17,
12,
1695,
9,
355,
31836,
8,
17,
12,
3193,
9,
355,
31836,
8,
19,
12,
3193,
9,
355,
31836,
8,
17,
12,
1695,
9,
355,
31836,
8,
17,
12,
841,
9,
355,
31836,
8,
17,
12,
3193,
9,
355,
31836,
8,
17,
12,
3193,
9,
398,
23771,
83,
366,
6556,
14,
267,
1449,
267,
367,
2338,
315,
291,
14,
6851,
26,
288,
7373,
275,
7373,
2537,
14,
13283,
8,
835,
12,
291,
14,
17126,
9,
288,
1995,
7373,
339,
347,
636,
552,
721,
277,
304,
267,
519,
2344,
14426,
2582,
402,
307,
1895,
65,
14,
398,
1803,
3000,
14,
267,
1449,
267,
372,
822,
8,
277,
14,
6851,
9,
339,
6754,
28644,
1951,
27411,
3177,
6754,
339,
768,
4639,
272,
347,
485,
475,
63,
2960,
8,
3684,
304,
267,
340,
1228,
8,
3684,
12,
769,
304,
288,
5348,
275,
2008,
8,
3684,
9,
267,
372,
5348,
339,
6754,
21755,
3611,
4227,
29807,
6754,
339,
768,
1829,
272,
347,
8242,
8,
277,
304,
267,
519,
2344,
14426,
8242,
402,
307,
1895,
65,
14,
398,
1803,
2008,
14,
267,
1449,
267,
372,
291,
423,
6851,
339,
768,
1829,
272,
347,
21859,
8,
277,
304,
267,
519,
2344,
14426,
21859,
402,
307,
1895,
65,
14,
398,
1803,
2222,
7371,
3000,
7074,
402,
2877,
14,
267,
1449,
267,
372,
291,
423,
17126,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
hothHowler/pymc3
|
pymc3/theanof.py
|
13
|
5296
|
from .vartypes import typefilter, continuous_types
from theano import theano, scalar, tensor as t
from theano.gof.graph import inputs
from .memoize import memoize
from .blocking import ArrayOrdering
__all__ = ['gradient', 'hessian', 'hessian_diag', 'inputvars', 'cont_inputs', 'jacobian', 'CallableTensor', 'join_nonshared_inputs', 'make_shared_replacements']
def inputvars(a):
"""
Get the inputs into a theano variables
Parameters
----------
a : theano variable
Returns
-------
r : list of tensor variables that are inputs
"""
return [v for v in inputs(makeiter(a)) if isinstance(v, t.TensorVariable)]
def cont_inputs(f):
"""
Get the continuous inputs into a theano variables
Parameters
----------
a : theano variable
Returns
-------
r : list of tensor variables that are continuous inputs
"""
return typefilter(inputvars(f), continuous_types)
"""
Theano derivative functions
"""
def gradient1(f, v):
"""flat gradient of f wrt v"""
return t.flatten(t.grad(f, v, disconnected_inputs='warn'))
empty_gradient = t.zeros(0, dtype='float32')
@memoize
def gradient(f, vars=None):
if vars is None:
vars = cont_inputs(f)
if vars:
return t.concatenate([gradient1(f, v) for v in vars], axis=0)
else:
return empty_gradient
def jacobian1(f, v):
"""jacobian of f wrt v"""
f = t.flatten(f)
idx = t.arange(f.shape[0])
def grad_i(i):
return gradient1(f[i], v)
return theano.map(grad_i, idx)[0]
@memoize
def jacobian(f, vars=None):
if vars is None:
vars = cont_inputs(f)
if vars:
return t.concatenate([jacobian1(f, v) for v in vars], axis=1)
else:
return empty_gradient
@memoize
def hessian(f, vars=None):
return -jacobian(gradient(f, vars), vars)
def hessian_diag1(f, v):
g = gradient1(f, v)
idx = t.arange(g.shape[0])
def hess_ii(i):
return gradient1(g[i], v)[i]
return theano.map(hess_ii, idx)[0]
@memoize
def hessian_diag(f, vars=None):
if vars is None:
vars = cont_inputs(f)
if vars:
return -t.concatenate([hessian_diag1(f, v) for v in vars], axis=0)
else:
return empty_gradient
def makeiter(a):
if isinstance(a, (tuple, list)):
return a
else:
return [a]
class IdentityOp(scalar.UnaryScalarOp):
@staticmethod
def st_impl(x):
return x
def impl(self, x):
return x
def grad(self, inp, grads):
x, = inp
gz, = grads
return grads
def c_code(self, node, name, inp, out, sub):
x, = inp
z, = out
return """%(z)s = %(x)s;""" % locals()
def __eq__(self, other):
return type(self) == type(other)
def __hash__(self):
return hash(type(self))
def make_shared_replacements(vars, model):
"""
Makes shared replacements for all *other* variables than the ones passed.
This way functions can be called many times without setting unchanging variables. Allows us
to use func.trust_input by removing the need for DictToArrayBijection and kwargs.
Parameters
----------
vars : list of variables not to make shared
model : model
Returns
-------
Dict of variable -> new shared variable
"""
othervars = set(model.vars) - set(vars)
return {var : theano.shared(var.tag.test_value, var.name + '_shared') for var in othervars }
def join_nonshared_inputs(xs, vars, shared):
"""
Takes a list of theano Variables and joins their non shared inputs into a single input.
Parameters
----------
xs : list of theano tensors
vars : list of variables to join
Returns
-------
tensors, inarray
tensors : list of same tensors but with inarray as input
inarray : vector of inputs
"""
joined = theano.tensor.concatenate([var.ravel() for var in vars])
tensor_type = joined.type
inarray = tensor_type('inarray')
ordering = ArrayOrdering(vars)
inarray.tag.test_value = joined.tag.test_value
get_var = { var.name : var for var in vars}
replace = {
get_var[var] : reshape_t(inarray[slc], shp).astype(dtyp)
for var, slc, shp, dtyp in ordering.vmap }
replace.update(shared)
xs_special = [theano.clone(x, replace, strict=False) for x in xs]
return xs_special, inarray
def reshape_t(x, shape):
"""Work around fact that x.reshape(()) doesn't work"""
if shape != (): return x.reshape(shape)
else: return x[0]
class CallableTensor(object):
"""Turns a symbolic variable with one input into a function that returns symbolic arguments with the one variable replaced with the input.
"""
def __init__(self, tensor):
self.tensor = tensor
def __call__(self, input):
""" Replaces the single input of symbolic variable to be the passed argument.
Parameters
----------
input : TensorVariable
"""
oldinput, = inputvars(self.tensor)
return theano.clone(self.tensor, { oldinput : input }, strict=False)
scalar_identity = IdentityOp(scalar.upgrade_to_float, name='scalar_identity')
identity = t.Elemwise(scalar_identity, name='identity')
|
apache-2.0
|
[
504,
1275,
1391,
1313,
492,
730,
1541,
12,
19922,
63,
1313,
199,
504,
14377,
492,
14377,
12,
6917,
12,
221,
2345,
465,
307,
199,
504,
14377,
14,
71,
1618,
14,
2180,
492,
4153,
199,
504,
1275,
11979,
794,
492,
11955,
794,
199,
504,
1275,
13091,
492,
8725,
4738,
316,
199,
199,
363,
452,
363,
275,
788,
7490,
297,
283,
72,
21663,
297,
283,
72,
21663,
63,
6706,
297,
283,
1210,
2936,
297,
283,
11096,
63,
3711,
297,
283,
27342,
297,
283,
16410,
3861,
297,
283,
904,
63,
2865,
5555,
63,
3711,
297,
283,
1875,
63,
5555,
63,
1814,
1470,
418,
199,
199,
318,
1324,
2936,
8,
65,
304,
272,
408,
272,
2372,
314,
4153,
1901,
282,
14377,
2860,
339,
3897,
272,
4143,
267,
282,
520,
14377,
1750,
339,
1803,
272,
5514,
267,
519,
520,
769,
402,
2345,
2860,
626,
787,
4153,
272,
408,
272,
372,
359,
86,
367,
373,
315,
4153,
8,
1875,
1661,
8,
65,
430,
340,
1228,
8,
86,
12,
307,
14,
3861,
2773,
1874,
199,
199,
318,
13770,
63,
3711,
8,
70,
304,
272,
408,
272,
2372,
314,
19922,
4153,
1901,
282,
14377,
2860,
339,
3897,
272,
4143,
267,
282,
520,
14377,
1750,
339,
1803,
272,
5514,
267,
519,
520,
769,
402,
2345,
2860,
626,
787,
19922,
4153,
272,
408,
272,
372,
730,
1541,
8,
1210,
2936,
8,
70,
395,
19922,
63,
1313,
9,
4388,
199,
624,
199,
1918,
8143,
18883,
3423,
199,
624,
199,
318,
6709,
17,
8,
70,
12,
373,
304,
272,
408,
7088,
6709,
402,
289,
23105,
373,
624,
272,
372,
307,
14,
8487,
8,
84,
14,
6017,
8,
70,
12,
373,
12,
25602,
63,
3711,
534,
4050,
1333,
421,
199,
1667,
63,
7490,
275,
307,
14,
4250,
8,
16,
12,
2152,
534,
1609,
708,
358,
199,
32,
11979,
794,
199,
318,
6709,
8,
70,
12,
6802,
29,
403,
304,
272,
340,
6802,
365,
488,
26,
267,
6802,
275,
13770,
63,
3711,
8,
70,
9,
339,
340,
6802,
26,
4960,
372,
307,
14,
13433,
779,
7490,
17,
8,
70,
12,
373,
9,
367,
373,
315,
6802,
467,
3114,
29,
16,
9,
272,
587,
26,
267,
372,
2701,
63,
7490,
421,
199,
318,
1335,
22065,
17,
8,
70,
12,
373,
304,
272,
408,
27342,
402,
289,
23105,
373,
624,
272,
289,
275,
307,
14,
8487,
8,
70,
9,
272,
4280,
275,
307,
14,
5605,
8,
70,
14,
1392,
59,
16,
566,
339,
347,
7659,
63,
73,
8,
73,
304,
267,
372,
6709,
17,
8,
70,
59,
73,
467,
373,
9,
339,
372,
14377,
14,
1130,
8,
6017,
63,
73,
12,
4280,
2788,
16,
61,
421,
199,
32,
11979,
794,
199,
318,
1335,
22065,
8,
70,
12,
6802,
29,
403,
304,
272,
340,
6802,
365,
488,
26,
267,
6802,
275,
13770,
63,
3711,
8,
70,
9,
339,
340,
6802,
26,
267,
372,
307,
14,
13433,
779,
27342,
17,
8,
70,
12,
373,
9,
367,
373,
315,
6802,
467,
3114,
29,
17,
9,
272,
587,
26,
4960,
372,
2701,
63,
7490,
421,
199,
32,
11979,
794,
199,
318,
394,
21663,
8,
70,
12,
6802,
29,
403,
304,
272,
372,
446,
27342,
8,
7490,
8,
70,
12,
6802,
395,
6802,
9,
421,
199,
318,
394,
21663,
63,
6706,
17,
8,
70,
12,
373,
304,
339,
486,
275,
6709,
17,
8,
70,
12,
373,
9,
272,
4280,
275,
307,
14,
5605,
8,
71,
14,
1392,
59,
16,
566,
339,
347,
946,
385,
63,
5908,
8,
73,
304,
267,
372,
6709,
17,
8,
71,
59,
73,
467,
373,
2788,
73,
61,
339,
372,
14377,
14,
1130,
8,
31421,
63,
5908,
12,
4280,
2788,
16,
61,
421,
199,
32,
11979,
794,
199,
318,
394,
21663,
63,
6706,
8,
70,
12,
6802,
29,
403,
304,
272,
340,
6802,
365,
488,
26,
267,
6802,
275,
13770,
63,
3711,
8,
70,
9,
339,
340,
6802,
26,
267,
372,
446,
84,
14,
13433,
779,
72,
21663,
63,
6706,
17,
8,
70,
12,
373,
9,
367,
373,
315,
6802,
467,
3114,
29,
16,
9,
272,
587,
26,
4960,
372,
2701,
63,
7490,
421,
199,
318,
1852,
1661,
8,
65,
304,
272,
340,
1228,
8,
65,
12,
334,
2960,
12,
769,
2298,
267,
372,
282,
272,
587,
26,
267,
372,
359,
65,
61,
421,
199,
533,
22034,
4619,
8,
7033,
14,
22401,
13090,
4619,
304,
272,
768,
4639,
272,
347,
410,
63,
5472,
8,
88,
304,
267,
372,
671,
339,
347,
11512,
8,
277,
12,
671,
304,
267,
372,
671,
339,
347,
7659,
8,
277,
12,
10702,
12,
18300,
304,
267,
671,
12,
275,
10702,
267,
486,
90,
12,
275,
18300,
267,
372,
18300,
339,
347,
286,
63,
600,
8,
277,
12,
1031,
12,
536,
12,
10702,
12,
734,
12,
1007,
304,
267,
671,
12,
275,
10702,
267,
1315,
12,
275,
734,
267,
372,
408,
2840,
90,
9,
83,
275,
2818,
88,
9,
83,
27,
624,
450,
9480,
342,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
372,
730,
8,
277,
9,
508,
730,
8,
1848,
9,
339,
347,
636,
2227,
721,
277,
304,
267,
372,
2631,
8,
466,
8,
277,
430,
199,
199,
318,
1852,
63,
5555,
63,
1814,
1470,
8,
2936,
12,
1402,
304,
272,
408,
272,
23365,
5709,
22372,
367,
1006,
627,
1848,
10,
2860,
2419,
314,
7869,
3032,
14,
339,
961,
4340,
3423,
883,
506,
2797,
5002,
5431,
1928,
4260,
625,
29131,
2860,
14,
22819,
2739,
5591,
370,
675,
2562,
14,
15756,
63,
1210,
701,
12881,
314,
1929,
367,
7448,
1378,
3836,
17975,
8923,
436,
2074,
14,
339,
3897,
272,
4143,
272,
6802,
520,
769,
402,
2860,
440,
370,
1852,
5709,
272,
1402,
520,
1402,
18407,
1803,
272,
5514,
272,
7448,
402,
1750,
1035,
892,
5709,
1750,
272,
408,
272,
1163,
2936,
275,
663,
8,
1238,
14,
2936,
9,
446,
663,
8,
2936,
9,
272,
372,
469,
1391,
520,
14377,
14,
5555,
8,
1391,
14,
1450,
14,
396,
63,
585,
12,
2729,
14,
354,
435,
2513,
5555,
358,
367,
2729,
315,
1163,
2936,
789,
199,
199,
318,
4263,
63,
2865,
5555,
63,
3711,
8,
7977,
12,
6802,
12,
5709,
304,
272,
408,
272,
17415,
282,
769,
402,
14377,
17198,
436,
18266,
3932,
2222,
5709,
4153,
1901,
282,
2849,
1324,
14,
2286,
3897,
272,
4143,
272
] |
[
1275,
1391,
1313,
492,
730,
1541,
12,
19922,
63,
1313,
199,
504,
14377,
492,
14377,
12,
6917,
12,
221,
2345,
465,
307,
199,
504,
14377,
14,
71,
1618,
14,
2180,
492,
4153,
199,
504,
1275,
11979,
794,
492,
11955,
794,
199,
504,
1275,
13091,
492,
8725,
4738,
316,
199,
199,
363,
452,
363,
275,
788,
7490,
297,
283,
72,
21663,
297,
283,
72,
21663,
63,
6706,
297,
283,
1210,
2936,
297,
283,
11096,
63,
3711,
297,
283,
27342,
297,
283,
16410,
3861,
297,
283,
904,
63,
2865,
5555,
63,
3711,
297,
283,
1875,
63,
5555,
63,
1814,
1470,
418,
199,
199,
318,
1324,
2936,
8,
65,
304,
272,
408,
272,
2372,
314,
4153,
1901,
282,
14377,
2860,
339,
3897,
272,
4143,
267,
282,
520,
14377,
1750,
339,
1803,
272,
5514,
267,
519,
520,
769,
402,
2345,
2860,
626,
787,
4153,
272,
408,
272,
372,
359,
86,
367,
373,
315,
4153,
8,
1875,
1661,
8,
65,
430,
340,
1228,
8,
86,
12,
307,
14,
3861,
2773,
1874,
199,
199,
318,
13770,
63,
3711,
8,
70,
304,
272,
408,
272,
2372,
314,
19922,
4153,
1901,
282,
14377,
2860,
339,
3897,
272,
4143,
267,
282,
520,
14377,
1750,
339,
1803,
272,
5514,
267,
519,
520,
769,
402,
2345,
2860,
626,
787,
19922,
4153,
272,
408,
272,
372,
730,
1541,
8,
1210,
2936,
8,
70,
395,
19922,
63,
1313,
9,
4388,
199,
624,
199,
1918,
8143,
18883,
3423,
199,
624,
199,
318,
6709,
17,
8,
70,
12,
373,
304,
272,
408,
7088,
6709,
402,
289,
23105,
373,
624,
272,
372,
307,
14,
8487,
8,
84,
14,
6017,
8,
70,
12,
373,
12,
25602,
63,
3711,
534,
4050,
1333,
421,
199,
1667,
63,
7490,
275,
307,
14,
4250,
8,
16,
12,
2152,
534,
1609,
708,
358,
199,
32,
11979,
794,
199,
318,
6709,
8,
70,
12,
6802,
29,
403,
304,
272,
340,
6802,
365,
488,
26,
267,
6802,
275,
13770,
63,
3711,
8,
70,
9,
339,
340,
6802,
26,
4960,
372,
307,
14,
13433,
779,
7490,
17,
8,
70,
12,
373,
9,
367,
373,
315,
6802,
467,
3114,
29,
16,
9,
272,
587,
26,
267,
372,
2701,
63,
7490,
421,
199,
318,
1335,
22065,
17,
8,
70,
12,
373,
304,
272,
408,
27342,
402,
289,
23105,
373,
624,
272,
289,
275,
307,
14,
8487,
8,
70,
9,
272,
4280,
275,
307,
14,
5605,
8,
70,
14,
1392,
59,
16,
566,
339,
347,
7659,
63,
73,
8,
73,
304,
267,
372,
6709,
17,
8,
70,
59,
73,
467,
373,
9,
339,
372,
14377,
14,
1130,
8,
6017,
63,
73,
12,
4280,
2788,
16,
61,
421,
199,
32,
11979,
794,
199,
318,
1335,
22065,
8,
70,
12,
6802,
29,
403,
304,
272,
340,
6802,
365,
488,
26,
267,
6802,
275,
13770,
63,
3711,
8,
70,
9,
339,
340,
6802,
26,
267,
372,
307,
14,
13433,
779,
27342,
17,
8,
70,
12,
373,
9,
367,
373,
315,
6802,
467,
3114,
29,
17,
9,
272,
587,
26,
4960,
372,
2701,
63,
7490,
421,
199,
32,
11979,
794,
199,
318,
394,
21663,
8,
70,
12,
6802,
29,
403,
304,
272,
372,
446,
27342,
8,
7490,
8,
70,
12,
6802,
395,
6802,
9,
421,
199,
318,
394,
21663,
63,
6706,
17,
8,
70,
12,
373,
304,
339,
486,
275,
6709,
17,
8,
70,
12,
373,
9,
272,
4280,
275,
307,
14,
5605,
8,
71,
14,
1392,
59,
16,
566,
339,
347,
946,
385,
63,
5908,
8,
73,
304,
267,
372,
6709,
17,
8,
71,
59,
73,
467,
373,
2788,
73,
61,
339,
372,
14377,
14,
1130,
8,
31421,
63,
5908,
12,
4280,
2788,
16,
61,
421,
199,
32,
11979,
794,
199,
318,
394,
21663,
63,
6706,
8,
70,
12,
6802,
29,
403,
304,
272,
340,
6802,
365,
488,
26,
267,
6802,
275,
13770,
63,
3711,
8,
70,
9,
339,
340,
6802,
26,
267,
372,
446,
84,
14,
13433,
779,
72,
21663,
63,
6706,
17,
8,
70,
12,
373,
9,
367,
373,
315,
6802,
467,
3114,
29,
16,
9,
272,
587,
26,
4960,
372,
2701,
63,
7490,
421,
199,
318,
1852,
1661,
8,
65,
304,
272,
340,
1228,
8,
65,
12,
334,
2960,
12,
769,
2298,
267,
372,
282,
272,
587,
26,
267,
372,
359,
65,
61,
421,
199,
533,
22034,
4619,
8,
7033,
14,
22401,
13090,
4619,
304,
272,
768,
4639,
272,
347,
410,
63,
5472,
8,
88,
304,
267,
372,
671,
339,
347,
11512,
8,
277,
12,
671,
304,
267,
372,
671,
339,
347,
7659,
8,
277,
12,
10702,
12,
18300,
304,
267,
671,
12,
275,
10702,
267,
486,
90,
12,
275,
18300,
267,
372,
18300,
339,
347,
286,
63,
600,
8,
277,
12,
1031,
12,
536,
12,
10702,
12,
734,
12,
1007,
304,
267,
671,
12,
275,
10702,
267,
1315,
12,
275,
734,
267,
372,
408,
2840,
90,
9,
83,
275,
2818,
88,
9,
83,
27,
624,
450,
9480,
342,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
372,
730,
8,
277,
9,
508,
730,
8,
1848,
9,
339,
347,
636,
2227,
721,
277,
304,
267,
372,
2631,
8,
466,
8,
277,
430,
199,
199,
318,
1852,
63,
5555,
63,
1814,
1470,
8,
2936,
12,
1402,
304,
272,
408,
272,
23365,
5709,
22372,
367,
1006,
627,
1848,
10,
2860,
2419,
314,
7869,
3032,
14,
339,
961,
4340,
3423,
883,
506,
2797,
5002,
5431,
1928,
4260,
625,
29131,
2860,
14,
22819,
2739,
5591,
370,
675,
2562,
14,
15756,
63,
1210,
701,
12881,
314,
1929,
367,
7448,
1378,
3836,
17975,
8923,
436,
2074,
14,
339,
3897,
272,
4143,
272,
6802,
520,
769,
402,
2860,
440,
370,
1852,
5709,
272,
1402,
520,
1402,
18407,
1803,
272,
5514,
272,
7448,
402,
1750,
1035,
892,
5709,
1750,
272,
408,
272,
1163,
2936,
275,
663,
8,
1238,
14,
2936,
9,
446,
663,
8,
2936,
9,
272,
372,
469,
1391,
520,
14377,
14,
5555,
8,
1391,
14,
1450,
14,
396,
63,
585,
12,
2729,
14,
354,
435,
2513,
5555,
358,
367,
2729,
315,
1163,
2936,
789,
199,
199,
318,
4263,
63,
2865,
5555,
63,
3711,
8,
7977,
12,
6802,
12,
5709,
304,
272,
408,
272,
17415,
282,
769,
402,
14377,
17198,
436,
18266,
3932,
2222,
5709,
4153,
1901,
282,
2849,
1324,
14,
2286,
3897,
272,
4143,
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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
berkeley-stat159/project-beta
|
code/utils/vmt_utils.py
|
4
|
3559
|
# General utility functions for vm_tools
"""
These functions are meant to manipulate and reshape data, to facilitate bootstrapping,
Statistical functions (those concerned with prediction accuracy, significance levels)
"""
import numpy as np
def _svd(M,**kwargs):
"""
same as np.linagle.svd() function
add exception handle
"""
try:
U,S,Vh = np.linalg.svd(M,**kwargs)
except np.linalg.LinAlgError as e:
print ("NORMAL SVD FAILED, trying more robust dgesvd..")
from .svd_dgesvd import svd_dgesvd
U,S,Vh = svd_dgesvd(M,**kwargs)
return U,S,Vh
def mult_diag(d, mtx, left=True):
"""Multiply a full matrix by a diagonal matrix.
This function should always be faster than dot.
input:
d -- 1D (N,) array (contains the diagonal elements)
mtx -- 2D (N,N) array
Output:
mult_diag(d, mts, left=True) == dot(diag(d), mtx)
mult_diag(d, mts, left=False) == dot(mtx, diag(d))
By Pietro Berkes
From http://mail.scipy.org/pipermail/numpy-discussion/2007-March/026807.html
"""
if left:
return (d*mtx.T).T
else:
return d*mtx
def as_list(x):
"""Assure that a variable that might either be a scalar or a list is a list."""
if x is None:
return []
if not isinstance(x,(list,tuple)):
x = [x]
return x
# def split_data(n_splits,n_tps,is_contiguous=True):
# """Splits data of length "n_tps" up in to "n_splits" cross-validation chunks
# Parameters
# ----------
# n_splits : scalar
# number of splits
# n_tps : scalar
# number of time points to subdivide
# is_contiguous : bool
# Governs whether chunks are contiguous
# Returns a list ("splits") of (trnIdx,valIdx) pairs of indices
# (Each split is n_tps/n_splits long)
# """
# splits = []
# n_per_split = n_tps/n_splits
# if is_contiguous:
# indices = np.arange(n_tps)
# else:
# indices = np.random.permutation(n_tps)
# for ii in range(n_splits):
# vIdx = indices[ii*n_per_split:(ii+1)*n_per_split]
# t1 = indices[0:ii*n_per_split]
# t2 = indices[(ii+1)*n_per_split:]
# tIdx = np.concatenate((t1,t2))
# splits.append((tIdx,vIdx))
# return splits
def add_lags(X,lags=(2,3,4)):
"""
Add lags to design matrix (X)
X should be a TIME x CHANNELS matrix
lags should be a list of time points (nTRs from stim onset), e.g. [2,3,4]
"""
nlags = len(lags)
lags = [x-1 for x in lags] # make lags 0-first python indices
nTP,nChan = X.shape
XA = np.zeros((nTP,nChan*nlags))
for iL,L in enumerate(lags):
XA[:,nChan*iL:nChan*(iL+1)] = np.concatenate((np.zeros((L,nChan)),X[:nTP-L,:]),axis=0)
X = XA
return X
def add_constant(X,is_first=True):
"""
Add a constant to a design matrix
X should be a TIME x CHANNELS matrix
is_first default is True (= add column of ones on LEFT); False = Right
"""
if is_first:
X = np.concatenate((np.ones((X.shape[0],1)),X),axis=1)
else:
X = np.concatenate((np.ones((X.shape[0],1)),X),axis=1)
return X
def contig_partition(n_datapts,n_splits):
"""Evenly partition n_datapts into n_splits
Each pair is a partition of X, where validation is an iterable
of length n_datapts/n_splits.
"""
nn = np.cast['int32'](np.ceil(np.linspace(0,n_datapts,n_splits+1)))
val = [np.arange(st,fn) for st,fn in zip(nn[:-1],nn[1:])]
trn = [np.array([x for x in range(n_datapts) if not x in v]) for v in val]
return trn,val
|
bsd-3-clause
|
[
3,
1696,
11420,
3423,
367,
4169,
63,
2537,
199,
624,
199,
20676,
3423,
787,
18329,
370,
27232,
436,
21460,
666,
12,
370,
30242,
1051,
323,
8498,
14183,
3637,
12,
221,
199,
3391,
30364,
3423,
334,
273,
3362,
406,
2247,
7439,
543,
12044,
12862,
12,
2070,
12061,
554,
11106,
9,
199,
624,
199,
646,
2680,
465,
980,
199,
199,
318,
485,
18675,
8,
45,
12663,
958,
304,
272,
408,
272,
2011,
465,
980,
14,
472,
643,
274,
14,
18675,
342,
805,
272,
1050,
1919,
2429,
272,
408,
272,
862,
26,
267,
738,
12,
51,
12,
54,
72,
275,
980,
14,
10096,
14,
18675,
8,
45,
12663,
958,
9,
272,
871,
980,
14,
10096,
14,
27889,
28846,
547,
465,
325,
26,
267,
870,
1689,
10765,
14056,
36,
26892,
12,
9936,
1655,
23399,
366,
303,
18675,
703,
531,
267,
687,
1275,
18675,
63,
68,
303,
18675,
492,
26937,
63,
68,
303,
18675,
267,
738,
12,
51,
12,
54,
72,
275,
26937,
63,
68,
303,
18675,
8,
45,
12663,
958,
9,
272,
372,
738,
12,
51,
12,
54,
72,
199,
199,
318,
20861,
63,
6706,
8,
68,
12,
333,
2347,
12,
3602,
29,
549,
304,
272,
408,
25314,
590,
282,
2615,
3634,
701,
282,
16788,
3634,
14,
272,
961,
805,
1077,
3544,
506,
12930,
2419,
6308,
14,
339,
1324,
26,
489,
366,
1553,
413,
36,
334,
46,
4258,
1625,
334,
6134,
314,
16788,
4008,
9,
489,
333,
2347,
1553,
499,
36,
334,
46,
12,
46,
9,
1625,
339,
7242,
26,
489,
20861,
63,
6706,
8,
68,
12,
333,
1086,
12,
3602,
29,
549,
9,
508,
6308,
8,
6706,
8,
68,
395,
333,
2347,
9,
489,
20861,
63,
6706,
8,
68,
12,
333,
1086,
12,
3602,
29,
797,
9,
508,
6308,
8,
26029,
12,
8348,
8,
68,
430,
2286,
4885,
510,
14077,
293,
23207,
9246,
272,
11606,
1455,
921,
1198,
14,
14248,
14,
1308,
15,
1038,
529,
1198,
15,
4714,
13,
14410,
15,
9488,
13,
45,
1047,
15,
14842,
11369,
14,
1360,
272,
408,
272,
340,
3602,
26,
267,
372,
334,
68,
10,
26029,
14,
52,
680,
52,
5591,
587,
26,
267,
372,
366,
10,
26029,
199,
199,
318,
465,
63,
513,
8,
88,
304,
272,
408,
9824,
608,
626,
282,
1750,
626,
5594,
1902,
506,
282,
6917,
503,
282,
769,
365,
282,
769,
1041,
272,
340,
671,
365,
488,
26,
267,
372,
942,
272,
340,
440,
1228,
8,
88,
12803,
513,
12,
2960,
2298,
267,
671,
275,
359,
88,
61,
272,
372,
671,
421,
199,
3,
347,
3715,
63,
576,
8,
78,
63,
16508,
12,
78,
63,
30543,
12,
374,
63,
16583,
29,
549,
304,
199,
3,
257,
408,
8862,
83,
666,
402,
2582,
298,
78,
63,
30543,
2,
1536,
315,
370,
298,
78,
63,
16508,
2,
8059,
13,
6136,
8291,
1362,
199,
3,
257,
3897,
199,
3,
257,
4143,
199,
3,
257,
302,
63,
16508,
520,
6917,
199,
3,
755,
1329,
402,
19115,
199,
3,
257,
302,
63,
30543,
520,
6917,
199,
3,
755,
1329,
402,
900,
4501,
370,
1007,
16081,
199,
3,
257,
365,
63,
16583,
520,
2155,
199,
3,
755,
598,
1883,
561,
3775,
8291,
787,
26611,
1362,
199,
3,
257,
1803,
282,
769,
1689,
16508,
531,
402,
334,
454,
78,
12215,
12,
637,
12215,
9,
6342,
402,
4918,
199,
3,
257,
334,
22321,
3715,
365,
302,
63,
30543,
15,
78,
63,
16508,
1846,
9,
199,
3,
257,
408,
199,
3,
257,
19115,
275,
942,
199,
3,
257,
302,
63,
529,
63,
1294,
275,
302,
63,
30543,
15,
78,
63,
16508,
199,
3,
257,
340,
365,
63,
16583,
26,
199,
3,
755,
4918,
275,
980,
14,
5605,
8,
78,
63,
30543,
9,
199,
3,
257,
587,
26,
199,
3,
755,
4918,
275,
980,
14,
2355,
14,
23832,
8,
78,
63,
30543,
9,
199,
3,
257,
367,
15393,
315,
1425,
8,
78,
63,
16508,
304,
199,
3,
755,
373,
12215,
275,
4918,
59,
5908,
10,
78,
63,
529,
63,
1294,
20334,
5908,
11,
17,
3342,
78,
63,
529,
63,
1294,
61,
199,
3,
755,
307,
17,
275,
4918,
59,
16,
26,
5908,
10,
78,
63,
529,
63,
1294,
61,
199,
3,
755,
307,
18,
275,
4918,
7528,
5908,
11,
17,
3342,
78,
63,
529,
63,
1294,
2938,
199,
3,
755,
307,
12215,
275,
980,
14,
13433,
1332,
84,
17,
12,
84,
18,
430,
199,
3,
755,
19115,
14,
740,
1332,
84,
12215,
12,
86,
12215,
430,
199,
3,
257,
372,
19115,
199,
199,
318,
1050,
63,
1550,
8,
56,
12,
1550,
2687,
18,
12,
19,
12,
20,
2298,
272,
408,
272,
2654,
1127,
458,
370,
12899,
3634,
334,
56,
9,
272,
1323,
1077,
506,
282,
17032,
671,
6624,
13935,
51,
3634,
272,
1127,
458,
1077,
506,
282,
769,
402,
900,
4501,
334,
78,
1766,
83,
687,
29965,
641,
409,
395,
325,
14,
71,
14,
359,
18,
12,
19,
12,
20,
61,
272,
408,
272,
302,
1550,
275,
822,
8,
1550,
9,
272,
1127,
458,
275,
359,
88,
13,
17,
367,
671,
315,
1127,
458,
61,
327,
1852,
1127,
458,
378,
13,
2246,
2366,
4918,
272,
302,
6495,
12,
78,
27039,
275,
1323,
14,
1392,
272,
1323,
33,
275,
980,
14,
4250,
1332,
78,
6495,
12,
78,
27039,
10,
78,
1550,
430,
272,
367,
284,
44,
12,
44,
315,
3874,
8,
1550,
304,
267,
1323,
33,
3981,
78,
27039,
10,
73,
44,
26,
78,
27039,
5830,
73,
44,
11,
17,
1874,
275,
980,
14,
13433,
1332,
1590,
14,
4250,
1332,
44,
12,
78,
27039,
1826,
56,
1491,
78,
6495,
13,
44,
12,
26,
2522,
3127,
29,
16,
9,
272,
1323,
275,
1323,
33,
272,
372,
1323,
199,
199,
318,
1050,
63,
4083,
8,
56,
12,
374,
63,
2246,
29,
549,
304,
272,
408,
272,
2654,
282,
4413,
370,
282,
12899,
3634,
272,
1323,
1077,
506,
282,
17032,
671,
6624,
13935,
51,
3634,
272,
365,
63,
2246,
849,
365,
715,
24649,
1050,
2763,
402,
7869,
641,
6578,
2736,
756,
275,
20854,
272,
408,
272,
340,
365,
63,
2246,
26,
267,
1323,
275,
980,
14,
13433,
1332,
1590,
14,
4548,
1332,
56,
14,
1392,
59,
16,
467,
17,
1826,
56,
395,
3127,
29,
17,
9,
272,
587,
26,
267,
1323,
275,
980,
14,
13433,
1332,
1590,
14,
4548,
1332
] |
[
1696,
11420,
3423,
367,
4169,
63,
2537,
199,
624,
199,
20676,
3423,
787,
18329,
370,
27232,
436,
21460,
666,
12,
370,
30242,
1051,
323,
8498,
14183,
3637,
12,
221,
199,
3391,
30364,
3423,
334,
273,
3362,
406,
2247,
7439,
543,
12044,
12862,
12,
2070,
12061,
554,
11106,
9,
199,
624,
199,
646,
2680,
465,
980,
199,
199,
318,
485,
18675,
8,
45,
12663,
958,
304,
272,
408,
272,
2011,
465,
980,
14,
472,
643,
274,
14,
18675,
342,
805,
272,
1050,
1919,
2429,
272,
408,
272,
862,
26,
267,
738,
12,
51,
12,
54,
72,
275,
980,
14,
10096,
14,
18675,
8,
45,
12663,
958,
9,
272,
871,
980,
14,
10096,
14,
27889,
28846,
547,
465,
325,
26,
267,
870,
1689,
10765,
14056,
36,
26892,
12,
9936,
1655,
23399,
366,
303,
18675,
703,
531,
267,
687,
1275,
18675,
63,
68,
303,
18675,
492,
26937,
63,
68,
303,
18675,
267,
738,
12,
51,
12,
54,
72,
275,
26937,
63,
68,
303,
18675,
8,
45,
12663,
958,
9,
272,
372,
738,
12,
51,
12,
54,
72,
199,
199,
318,
20861,
63,
6706,
8,
68,
12,
333,
2347,
12,
3602,
29,
549,
304,
272,
408,
25314,
590,
282,
2615,
3634,
701,
282,
16788,
3634,
14,
272,
961,
805,
1077,
3544,
506,
12930,
2419,
6308,
14,
339,
1324,
26,
489,
366,
1553,
413,
36,
334,
46,
4258,
1625,
334,
6134,
314,
16788,
4008,
9,
489,
333,
2347,
1553,
499,
36,
334,
46,
12,
46,
9,
1625,
339,
7242,
26,
489,
20861,
63,
6706,
8,
68,
12,
333,
1086,
12,
3602,
29,
549,
9,
508,
6308,
8,
6706,
8,
68,
395,
333,
2347,
9,
489,
20861,
63,
6706,
8,
68,
12,
333,
1086,
12,
3602,
29,
797,
9,
508,
6308,
8,
26029,
12,
8348,
8,
68,
430,
2286,
4885,
510,
14077,
293,
23207,
9246,
272,
11606,
1455,
921,
1198,
14,
14248,
14,
1308,
15,
1038,
529,
1198,
15,
4714,
13,
14410,
15,
9488,
13,
45,
1047,
15,
14842,
11369,
14,
1360,
272,
408,
272,
340,
3602,
26,
267,
372,
334,
68,
10,
26029,
14,
52,
680,
52,
5591,
587,
26,
267,
372,
366,
10,
26029,
199,
199,
318,
465,
63,
513,
8,
88,
304,
272,
408,
9824,
608,
626,
282,
1750,
626,
5594,
1902,
506,
282,
6917,
503,
282,
769,
365,
282,
769,
1041,
272,
340,
671,
365,
488,
26,
267,
372,
942,
272,
340,
440,
1228,
8,
88,
12803,
513,
12,
2960,
2298,
267,
671,
275,
359,
88,
61,
272,
372,
671,
421,
199,
3,
347,
3715,
63,
576,
8,
78,
63,
16508,
12,
78,
63,
30543,
12,
374,
63,
16583,
29,
549,
304,
199,
3,
257,
408,
8862,
83,
666,
402,
2582,
298,
78,
63,
30543,
2,
1536,
315,
370,
298,
78,
63,
16508,
2,
8059,
13,
6136,
8291,
1362,
199,
3,
257,
3897,
199,
3,
257,
4143,
199,
3,
257,
302,
63,
16508,
520,
6917,
199,
3,
755,
1329,
402,
19115,
199,
3,
257,
302,
63,
30543,
520,
6917,
199,
3,
755,
1329,
402,
900,
4501,
370,
1007,
16081,
199,
3,
257,
365,
63,
16583,
520,
2155,
199,
3,
755,
598,
1883,
561,
3775,
8291,
787,
26611,
1362,
199,
3,
257,
1803,
282,
769,
1689,
16508,
531,
402,
334,
454,
78,
12215,
12,
637,
12215,
9,
6342,
402,
4918,
199,
3,
257,
334,
22321,
3715,
365,
302,
63,
30543,
15,
78,
63,
16508,
1846,
9,
199,
3,
257,
408,
199,
3,
257,
19115,
275,
942,
199,
3,
257,
302,
63,
529,
63,
1294,
275,
302,
63,
30543,
15,
78,
63,
16508,
199,
3,
257,
340,
365,
63,
16583,
26,
199,
3,
755,
4918,
275,
980,
14,
5605,
8,
78,
63,
30543,
9,
199,
3,
257,
587,
26,
199,
3,
755,
4918,
275,
980,
14,
2355,
14,
23832,
8,
78,
63,
30543,
9,
199,
3,
257,
367,
15393,
315,
1425,
8,
78,
63,
16508,
304,
199,
3,
755,
373,
12215,
275,
4918,
59,
5908,
10,
78,
63,
529,
63,
1294,
20334,
5908,
11,
17,
3342,
78,
63,
529,
63,
1294,
61,
199,
3,
755,
307,
17,
275,
4918,
59,
16,
26,
5908,
10,
78,
63,
529,
63,
1294,
61,
199,
3,
755,
307,
18,
275,
4918,
7528,
5908,
11,
17,
3342,
78,
63,
529,
63,
1294,
2938,
199,
3,
755,
307,
12215,
275,
980,
14,
13433,
1332,
84,
17,
12,
84,
18,
430,
199,
3,
755,
19115,
14,
740,
1332,
84,
12215,
12,
86,
12215,
430,
199,
3,
257,
372,
19115,
199,
199,
318,
1050,
63,
1550,
8,
56,
12,
1550,
2687,
18,
12,
19,
12,
20,
2298,
272,
408,
272,
2654,
1127,
458,
370,
12899,
3634,
334,
56,
9,
272,
1323,
1077,
506,
282,
17032,
671,
6624,
13935,
51,
3634,
272,
1127,
458,
1077,
506,
282,
769,
402,
900,
4501,
334,
78,
1766,
83,
687,
29965,
641,
409,
395,
325,
14,
71,
14,
359,
18,
12,
19,
12,
20,
61,
272,
408,
272,
302,
1550,
275,
822,
8,
1550,
9,
272,
1127,
458,
275,
359,
88,
13,
17,
367,
671,
315,
1127,
458,
61,
327,
1852,
1127,
458,
378,
13,
2246,
2366,
4918,
272,
302,
6495,
12,
78,
27039,
275,
1323,
14,
1392,
272,
1323,
33,
275,
980,
14,
4250,
1332,
78,
6495,
12,
78,
27039,
10,
78,
1550,
430,
272,
367,
284,
44,
12,
44,
315,
3874,
8,
1550,
304,
267,
1323,
33,
3981,
78,
27039,
10,
73,
44,
26,
78,
27039,
5830,
73,
44,
11,
17,
1874,
275,
980,
14,
13433,
1332,
1590,
14,
4250,
1332,
44,
12,
78,
27039,
1826,
56,
1491,
78,
6495,
13,
44,
12,
26,
2522,
3127,
29,
16,
9,
272,
1323,
275,
1323,
33,
272,
372,
1323,
199,
199,
318,
1050,
63,
4083,
8,
56,
12,
374,
63,
2246,
29,
549,
304,
272,
408,
272,
2654,
282,
4413,
370,
282,
12899,
3634,
272,
1323,
1077,
506,
282,
17032,
671,
6624,
13935,
51,
3634,
272,
365,
63,
2246,
849,
365,
715,
24649,
1050,
2763,
402,
7869,
641,
6578,
2736,
756,
275,
20854,
272,
408,
272,
340,
365,
63,
2246,
26,
267,
1323,
275,
980,
14,
13433,
1332,
1590,
14,
4548,
1332,
56,
14,
1392,
59,
16,
467,
17,
1826,
56,
395,
3127,
29,
17,
9,
272,
587,
26,
267,
1323,
275,
980,
14,
13433,
1332,
1590,
14,
4548,
1332,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
SHASHANKB/spark
|
examples/src/main/python/sql/streaming/structured_network_wordcount.py
|
76
|
2534
|
#
# 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.
#
"""
Counts words in UTF8 encoded, '\n' delimited text received from the network.
Usage: structured_network_wordcount.py <hostname> <port>
<hostname> and <port> describe the TCP server that Structured Streaming
would connect to receive data.
To run this on your local machine, you need to first run a Netcat server
`$ nc -lk 9999`
and then run the example
`$ bin/spark-submit examples/src/main/python/sql/streaming/structured_network_wordcount.py
localhost 9999`
"""
from __future__ import print_function
import sys
from pyspark.sql import SparkSession
from pyspark.sql.functions import explode
from pyspark.sql.functions import split
if __name__ == "__main__":
if len(sys.argv) != 3:
print("Usage: structured_network_wordcount.py <hostname> <port>", file=sys.stderr)
exit(-1)
host = sys.argv[1]
port = int(sys.argv[2])
spark = SparkSession\
.builder\
.appName("StructuredNetworkWordCount")\
.getOrCreate()
# Create DataFrame representing the stream of input lines from connection to host:port
lines = spark\
.readStream\
.format('socket')\
.option('host', host)\
.option('port', port)\
.load()
# Split the lines into words
words = lines.select(
# explode turns each item in an array into a separate row
explode(
split(lines.value, ' ')
).alias('word')
)
# Generate running word count
wordCounts = words.groupBy('word').count()
# Start running the query that prints the running counts to the console
query = wordCounts\
.writeStream\
.outputMode('complete')\
.format('console')\
.start()
query.awaitTermination()
|
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,
199,
14826,
83,
5932,
315,
9094,
24,
5737,
12,
1557,
78,
7,
21941,
1318,
3086,
687,
314,
2784,
14,
199,
11028,
26,
21781,
63,
1200,
63,
1027,
835,
14,
647,
665,
4269,
30,
665,
719,
30,
2043,
665,
4269,
30,
436,
665,
719,
30,
13743,
314,
13488,
1654,
626,
13039,
3297,
28167,
2043,
3955,
4907,
370,
9128,
666,
14,
421,
4005,
1255,
642,
641,
2195,
2257,
6844,
12,
1265,
1929,
370,
1642,
1255,
282,
5365,
3385,
1654,
272,
658,
4,
12698,
446,
23333,
221,
5008,
64,
199,
436,
2066,
1255,
314,
2893,
272,
658,
4,
2517,
15,
9852,
13,
7275,
7251,
15,
2164,
15,
973,
15,
1548,
15,
3009,
15,
12076,
15,
15774,
63,
1200,
63,
1027,
835,
14,
647,
272,
11667,
221,
5008,
64,
199,
624,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
984,
199,
199,
504,
15847,
14,
3009,
492,
13932,
4434,
199,
504,
15847,
14,
3009,
14,
5777,
492,
15868,
271,
199,
504,
15847,
14,
3009,
14,
5777,
492,
3715,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
340,
822,
8,
1274,
14,
3020,
9,
1137,
650,
26,
267,
870,
480,
7692,
26,
21781,
63,
1200,
63,
1027,
835,
14,
647,
665,
4269,
30,
665,
719,
7166,
570,
29,
1274,
14,
3083,
9,
267,
4458,
2801,
17,
9,
339,
1591,
275,
984,
14,
3020,
59,
17,
61,
272,
1844,
275,
1109,
8,
1274,
14,
3020,
59,
18,
566,
339,
15442,
275,
13932,
4434,
60,
267,
1275,
5649,
60,
267,
1275,
571,
985,
480,
27486,
4491,
10155,
2353,
27681,
267,
1275,
30457,
2499,
342,
339,
327,
2790,
10071,
6144,
314,
2547,
402,
1324,
2385,
687,
1950,
370,
1591,
26,
719,
272,
2385,
275,
15442,
60,
267,
1275,
739,
3296,
60,
267,
1275,
908,
360,
3450,
24431,
267,
1275,
1422,
360,
1102,
297,
1591,
2862,
267,
1275,
1422,
360,
719,
297,
1844,
2862,
267,
1275,
912,
342,
339,
327,
11740,
314,
2385,
1901,
5932,
272,
5932,
275,
2385,
14,
2416,
8,
267,
327,
15868,
271,
25449,
1924,
1242,
315,
376,
1625,
1901,
282,
7396,
1962,
267,
15868,
271,
8,
288,
3715,
8,
1278,
14,
585,
12,
283,
5320,
267,
7092,
3620,
360,
1027,
358,
272,
776,
339,
327,
7958,
3879,
4349,
2338,
272,
4349,
23209,
275,
5932,
14,
923,
2175,
360,
1027,
1959,
835,
342,
339,
327,
7707,
3879,
314,
1827,
626,
14767,
314,
3879,
8242,
370,
314,
8559,
272,
1827,
275,
4349,
23209,
60,
267,
1275,
952,
3296,
60,
267,
1275,
1199,
1385,
360,
4883,
24431,
267,
1275,
908,
360,
6614,
24431,
267,
1275,
928,
342,
339,
1827,
14,
32365,
12154,
425,
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
] |
[
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,
199,
14826,
83,
5932,
315,
9094,
24,
5737,
12,
1557,
78,
7,
21941,
1318,
3086,
687,
314,
2784,
14,
199,
11028,
26,
21781,
63,
1200,
63,
1027,
835,
14,
647,
665,
4269,
30,
665,
719,
30,
2043,
665,
4269,
30,
436,
665,
719,
30,
13743,
314,
13488,
1654,
626,
13039,
3297,
28167,
2043,
3955,
4907,
370,
9128,
666,
14,
421,
4005,
1255,
642,
641,
2195,
2257,
6844,
12,
1265,
1929,
370,
1642,
1255,
282,
5365,
3385,
1654,
272,
658,
4,
12698,
446,
23333,
221,
5008,
64,
199,
436,
2066,
1255,
314,
2893,
272,
658,
4,
2517,
15,
9852,
13,
7275,
7251,
15,
2164,
15,
973,
15,
1548,
15,
3009,
15,
12076,
15,
15774,
63,
1200,
63,
1027,
835,
14,
647,
272,
11667,
221,
5008,
64,
199,
624,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
984,
199,
199,
504,
15847,
14,
3009,
492,
13932,
4434,
199,
504,
15847,
14,
3009,
14,
5777,
492,
15868,
271,
199,
504,
15847,
14,
3009,
14,
5777,
492,
3715,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
340,
822,
8,
1274,
14,
3020,
9,
1137,
650,
26,
267,
870,
480,
7692,
26,
21781,
63,
1200,
63,
1027,
835,
14,
647,
665,
4269,
30,
665,
719,
7166,
570,
29,
1274,
14,
3083,
9,
267,
4458,
2801,
17,
9,
339,
1591,
275,
984,
14,
3020,
59,
17,
61,
272,
1844,
275,
1109,
8,
1274,
14,
3020,
59,
18,
566,
339,
15442,
275,
13932,
4434,
60,
267,
1275,
5649,
60,
267,
1275,
571,
985,
480,
27486,
4491,
10155,
2353,
27681,
267,
1275,
30457,
2499,
342,
339,
327,
2790,
10071,
6144,
314,
2547,
402,
1324,
2385,
687,
1950,
370,
1591,
26,
719,
272,
2385,
275,
15442,
60,
267,
1275,
739,
3296,
60,
267,
1275,
908,
360,
3450,
24431,
267,
1275,
1422,
360,
1102,
297,
1591,
2862,
267,
1275,
1422,
360,
719,
297,
1844,
2862,
267,
1275,
912,
342,
339,
327,
11740,
314,
2385,
1901,
5932,
272,
5932,
275,
2385,
14,
2416,
8,
267,
327,
15868,
271,
25449,
1924,
1242,
315,
376,
1625,
1901,
282,
7396,
1962,
267,
15868,
271,
8,
288,
3715,
8,
1278,
14,
585,
12,
283,
5320,
267,
7092,
3620,
360,
1027,
358,
272,
776,
339,
327,
7958,
3879,
4349,
2338,
272,
4349,
23209,
275,
5932,
14,
923,
2175,
360,
1027,
1959,
835,
342,
339,
327,
7707,
3879,
314,
1827,
626,
14767,
314,
3879,
8242,
370,
314,
8559,
272,
1827,
275,
4349,
23209,
60,
267,
1275,
952,
3296,
60,
267,
1275,
1199,
1385,
360,
4883,
24431,
267,
1275,
908,
360,
6614,
24431,
267,
1275,
928,
342,
339,
1827,
14,
32365,
12154,
425,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ChristianKniep/QNIB
|
serverfiles/usr/local/lib/networkx-1.6/networkx/algorithms/centrality/tests/test_current_flow_betweenness_centrality_subset.py
|
75
|
7708
|
#!/usr/bin/env python
from nose.tools import *
from nose import SkipTest
import networkx
from nose.plugins.attrib import attr
from networkx import edge_current_flow_betweenness_centrality \
as edge_current_flow
from networkx import edge_current_flow_betweenness_centrality_subset \
as edge_current_flow_subset
class TestFlowBetweennessCentrality(object):
numpy=1 # nosetests attribute, use nosetests -a 'not numpy' to skip test
@classmethod
def setupClass(cls):
global np
try:
import numpy as np
import scipy
except ImportError:
raise SkipTest('NumPy not available.')
def test_K4_normalized(self):
"""Betweenness centrality: K4"""
G=networkx.complete_graph(4)
b=networkx.current_flow_betweenness_centrality_subset(G,
G.nodes(),
G.nodes(),
normalized=True)
b_answer=networkx.current_flow_betweenness_centrality(G,normalized=True)
for n in sorted(G):
assert_almost_equal(b[n],b_answer[n])
def test_K4(self):
"""Betweenness centrality: K4"""
G=networkx.complete_graph(4)
b=networkx.current_flow_betweenness_centrality_subset(G,
G.nodes(),
G.nodes(),
normalized=True)
b_answer=networkx.current_flow_betweenness_centrality(G,normalized=True)
for n in sorted(G):
assert_almost_equal(b[n],b_answer[n])
# test weighted network
G.add_edge(0,1,{'weight':0.5,'other':0.3})
b=networkx.current_flow_betweenness_centrality_subset(G,
G.nodes(),
G.nodes(),
normalized=True,
weight=None)
for n in sorted(G):
assert_almost_equal(b[n],b_answer[n])
b=networkx.current_flow_betweenness_centrality_subset(G,
G.nodes(),
G.nodes(),
normalized=True)
b_answer=networkx.current_flow_betweenness_centrality(G,normalized=True)
for n in sorted(G):
assert_almost_equal(b[n],b_answer[n])
b=networkx.current_flow_betweenness_centrality_subset(G,
G.nodes(),
G.nodes(),
normalized=True,
weight='other')
b_answer=networkx.current_flow_betweenness_centrality(G,normalized=True,weight='other')
for n in sorted(G):
assert_almost_equal(b[n],b_answer[n])
def test_P4_normalized(self):
"""Betweenness centrality: P4 normalized"""
G=networkx.path_graph(4)
b=networkx.current_flow_betweenness_centrality_subset(G,
G.nodes(),
G.nodes(),
normalized=True)
b_answer=networkx.current_flow_betweenness_centrality(G,normalized=True)
for n in sorted(G):
assert_almost_equal(b[n],b_answer[n])
def test_P4(self):
"""Betweenness centrality: P4"""
G=networkx.path_graph(4)
b=networkx.current_flow_betweenness_centrality_subset(G,
G.nodes(),
G.nodes(),
normalized=True)
b_answer=networkx.current_flow_betweenness_centrality(G,normalized=True)
for n in sorted(G):
assert_almost_equal(b[n],b_answer[n])
def test_star(self):
"""Betweenness centrality: star """
G=networkx.Graph()
G.add_star(['a','b','c','d'])
b=networkx.current_flow_betweenness_centrality_subset(G,
G.nodes(),
G.nodes(),
normalized=True)
b_answer=networkx.current_flow_betweenness_centrality(G,normalized=True)
for n in sorted(G):
assert_almost_equal(b[n],b_answer[n])
# class TestWeightedFlowBetweennessCentrality():
# pass
class TestEdgeFlowBetweennessCentrality(object):
numpy=1 # nosetests attribute, use nosetests -a 'not numpy' to skip test
@classmethod
def setupClass(cls):
global np
try:
import numpy as np
import scipy
except ImportError:
raise SkipTest('NumPy not available.')
def test_K4_normalized(self):
"""Betweenness centrality: K4"""
G=networkx.complete_graph(4)
b=edge_current_flow_subset(G,G.nodes(),G.nodes(),normalized=True)
b_answer=edge_current_flow(G,normalized=True)
for (s,t),v1 in b_answer.items():
v2=b.get((s,t),b.get((t,s)))
assert_almost_equal(v1,v2)
def test_K4(self):
"""Betweenness centrality: K4"""
G=networkx.complete_graph(4)
b=edge_current_flow_subset(G,G.nodes(),G.nodes(),normalized=False)
b_answer=edge_current_flow(G,normalized=False)
for (s,t),v1 in b_answer.items():
v2=b.get((s,t),b.get((t,s)))
assert_almost_equal(v1,v2)
# test weighted network
G.add_edge(0,1,{'weight':0.5,'other':0.3})
b=edge_current_flow_subset(G,G.nodes(),G.nodes(),normalized=False,weight=None)
# weight is None => same as unweighted network
for (s,t),v1 in b_answer.items():
v2=b.get((s,t),b.get((t,s)))
assert_almost_equal(v1,v2)
b=edge_current_flow_subset(G,G.nodes(),G.nodes(),normalized=False)
b_answer=edge_current_flow(G,normalized=False)
for (s,t),v1 in b_answer.items():
v2=b.get((s,t),b.get((t,s)))
assert_almost_equal(v1,v2)
b=edge_current_flow_subset(G,G.nodes(),G.nodes(),normalized=False,weight='other')
b_answer=edge_current_flow(G,normalized=False,weight='other')
for (s,t),v1 in b_answer.items():
v2=b.get((s,t),b.get((t,s)))
assert_almost_equal(v1,v2)
def test_C4(self):
"""Edge betweenness centrality: C4"""
G=networkx.cycle_graph(4)
b=edge_current_flow_subset(G,G.nodes(),G.nodes(),normalized=True)
b_answer=edge_current_flow(G,normalized=True)
for (s,t),v1 in b_answer.items():
v2=b.get((s,t),b.get((t,s)))
assert_almost_equal(v1,v2)
def test_P4(self):
"""Edge betweenness centrality: P4"""
G=networkx.path_graph(4)
b=edge_current_flow_subset(G,G.nodes(),G.nodes(),normalized=True)
b_answer=edge_current_flow(G,normalized=True)
for (s,t),v1 in b_answer.items():
v2=b.get((s,t),b.get((t,s)))
assert_almost_equal(v1,v2)
|
gpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
504,
11354,
14,
2537,
492,
627,
199,
504,
11354,
492,
18795,
199,
646,
24313,
199,
504,
11354,
14,
5265,
14,
6640,
492,
1921,
199,
199,
504,
24313,
492,
6275,
63,
1818,
63,
1659,
63,
13007,
4171,
63,
2497,
28602,
971,
272,
465,
6275,
63,
1818,
63,
1659,
199,
199,
504,
24313,
492,
6275,
63,
1818,
63,
1659,
63,
13007,
4171,
63,
2497,
28602,
63,
9401,
971,
272,
465,
6275,
63,
1818,
63,
1659,
63,
9401,
199,
199,
533,
1379,
5060,
24472,
3109,
4171,
18345,
28602,
8,
785,
304,
272,
2680,
29,
17,
327,
11354,
2219,
2225,
12,
675,
11354,
2219,
446,
65,
283,
1397,
2680,
7,
370,
3372,
511,
272,
768,
3744,
272,
347,
3272,
2543,
8,
1886,
304,
267,
2288,
980,
267,
862,
26,
288,
492,
2680,
465,
980,
288,
492,
7026,
267,
871,
3545,
26,
288,
746,
18795,
360,
5667,
2713,
440,
2808,
2659,
199,
5493,
347,
511,
63,
43,
20,
63,
12916,
8,
277,
304,
267,
408,
24472,
3109,
4171,
9679,
28602,
26,
1804,
20,
624,
267,
598,
29,
1200,
88,
14,
4883,
63,
2180,
8,
20,
9,
267,
330,
29,
1200,
88,
14,
1818,
63,
1659,
63,
13007,
4171,
63,
2497,
28602,
63,
9401,
8,
39,
12,
16854,
598,
14,
2415,
1062,
16854,
598,
14,
2415,
1062,
16854,
9657,
29,
549,
9,
267,
330,
63,
5934,
29,
1200,
88,
14,
1818,
63,
1659,
63,
13007,
4171,
63,
2497,
28602,
8,
39,
12,
12916,
29,
549,
9,
267,
367,
302,
315,
3355,
8,
39,
304,
288,
702,
63,
4398,
63,
1452,
8,
66,
59,
78,
467,
66,
63,
5934,
59,
78,
566,
2378,
347,
511,
63,
43,
20,
8,
277,
304,
267,
408,
24472,
3109,
4171,
9679,
28602,
26,
1804,
20,
624,
267,
598,
29,
1200,
88,
14,
4883,
63,
2180,
8,
20,
9,
267,
330,
29,
1200,
88,
14,
1818,
63,
1659,
63,
13007,
4171,
63,
2497,
28602,
63,
9401,
8,
39,
12,
16854,
598,
14,
2415,
1062,
16854,
598,
14,
2415,
1062,
16854,
9657,
29,
549,
9,
267,
330,
63,
5934,
29,
1200,
88,
14,
1818,
63,
1659,
63,
13007,
4171,
63,
2497,
28602,
8,
39,
12,
12916,
29,
549,
9,
267,
367,
302,
315,
3355,
8,
39,
304,
288,
702,
63,
4398,
63,
1452,
8,
66,
59,
78,
467,
66,
63,
5934,
59,
78,
566,
267,
327,
511,
14609,
2784,
267,
598,
14,
525,
63,
5173,
8,
16,
12,
17,
12,
1445,
3463,
356,
16,
14,
21,
2584,
1848,
356,
16,
14,
19,
1552,
267,
330,
29,
1200,
88,
14,
1818,
63,
1659,
63,
13007,
4171,
63,
2497,
28602,
63,
9401,
8,
39,
12,
16854,
598,
14,
2415,
1062,
16854,
598,
14,
2415,
1062,
16854,
9657,
29,
549,
12,
16854,
5401,
29,
403,
9,
267,
367,
302,
315,
3355,
8,
39,
304,
288,
702,
63,
4398,
63,
1452,
8,
66,
59,
78,
467,
66,
63,
5934,
59,
78,
566,
267,
330,
29,
1200,
88,
14,
1818,
63,
1659,
63,
13007,
4171,
63,
2497,
28602,
63,
9401,
8,
39,
12,
16854,
598,
14,
2415,
1062,
16854,
598,
14,
2415,
1062,
16854,
9657,
29,
549,
9,
267,
330,
63,
5934,
29,
1200,
88,
14,
1818,
63,
1659,
63,
13007,
4171,
63,
2497,
28602,
8,
39,
12,
12916,
29,
549,
9,
267,
367,
302,
315,
3355,
8,
39,
304,
288,
702,
63,
4398,
63,
1452,
8,
66,
59,
78,
467,
66,
63,
5934,
59,
78,
566,
267,
330,
29,
1200,
88,
14,
1818,
63,
1659,
63,
13007,
4171,
63,
2497,
28602,
63,
9401,
8,
39,
12,
16854,
598,
14,
2415,
1062,
16854,
598,
14,
2415,
1062,
16854,
9657,
29,
549,
12,
16854,
5401,
534,
1848,
358,
267,
330,
63,
5934,
29,
1200,
88,
14,
1818,
63,
1659,
63,
13007,
4171,
63,
2497,
28602,
8,
39,
12,
12916,
29,
549,
12,
3463,
534,
1848,
358,
267,
367,
302,
315,
3355,
8,
39,
304,
288,
702,
63,
4398,
63,
1452,
8,
66,
59,
78,
467,
66,
63,
5934,
59,
78,
566,
2378,
347,
511,
63,
48,
20,
63,
12916,
8,
277,
304,
267,
408,
24472,
3109,
4171,
9679,
28602,
26,
510,
20,
9657,
624,
267,
598,
29,
1200,
88,
14,
515,
63,
2180,
8,
20,
9,
267,
330,
29,
1200,
88,
14,
1818,
63,
1659,
63,
13007,
4171,
63,
2497,
28602,
63,
9401,
8,
39,
12,
16854,
598,
14,
2415,
1062,
16854,
598,
14,
2415,
1062,
16854,
9657,
29,
549,
9,
267,
330,
63,
5934,
29,
1200,
88,
14,
1818,
63,
1659,
63,
13007,
4171,
63,
2497,
28602,
8,
39,
12,
12916,
29,
549,
9,
267,
367,
302,
315,
3355,
8,
39,
304,
288,
702,
63,
4398,
63,
1452,
8,
66,
59,
78,
467,
66,
63,
5934,
59,
78,
566,
2378,
347,
511,
63,
48,
20,
8,
277,
304,
267,
408,
24472,
3109,
4171,
9679,
28602,
26,
510,
20,
624,
267,
598,
29,
1200,
88,
14,
515,
63,
2180,
8,
20,
9,
267,
330,
29,
1200,
88,
14,
1818,
63,
1659,
63,
13007,
4171,
63,
2497,
28602,
63,
9401,
8,
39,
12,
16854,
598,
14,
2415,
1062,
16854,
598,
14,
2415,
1062,
16854,
9657,
29,
549,
9,
267,
330,
63,
5934,
29,
1200,
88,
14,
1818,
63,
1659,
63,
13007,
4171,
63,
2497,
28602,
8,
39,
12,
12916,
29,
549,
9,
267,
367,
302,
315,
3355,
8,
39,
304,
288,
702,
63,
4398,
63,
1452,
8,
66,
59,
78,
467,
66,
63,
5934,
59,
78,
566,
339,
347,
511,
63,
7848,
8,
277,
304,
267,
408,
24472,
3109,
4171,
9679,
28602,
26,
14664,
408,
267,
598,
29,
1200,
88,
14,
4578,
342,
267,
598,
14,
525,
63,
7848,
2941,
65,
1673,
66,
1673,
67,
1673,
68,
1105,
267,
330,
29,
1200,
88,
14,
1818,
63,
1659,
63,
13007,
4171,
63,
2497,
28602,
63,
9401,
8,
39,
12,
16854,
598,
14,
2415,
1062,
16854,
598,
14,
2415,
1062,
16854,
9657,
29,
549,
9,
267,
330,
63,
5934,
29,
1200,
88,
14,
1818,
63,
1659,
63,
13007,
4171,
63,
2497,
28602,
8,
39,
12,
12916,
29,
549,
9,
267,
367,
302,
315,
3355,
8,
39,
304,
288,
702,
63,
4398,
63,
1452,
8,
66,
59,
78,
467,
66,
63,
5934,
59,
78,
566,
4388,
199,
3,
1021
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
504,
11354,
14,
2537,
492,
627,
199,
504,
11354,
492,
18795,
199,
646,
24313,
199,
504,
11354,
14,
5265,
14,
6640,
492,
1921,
199,
199,
504,
24313,
492,
6275,
63,
1818,
63,
1659,
63,
13007,
4171,
63,
2497,
28602,
971,
272,
465,
6275,
63,
1818,
63,
1659,
199,
199,
504,
24313,
492,
6275,
63,
1818,
63,
1659,
63,
13007,
4171,
63,
2497,
28602,
63,
9401,
971,
272,
465,
6275,
63,
1818,
63,
1659,
63,
9401,
199,
199,
533,
1379,
5060,
24472,
3109,
4171,
18345,
28602,
8,
785,
304,
272,
2680,
29,
17,
327,
11354,
2219,
2225,
12,
675,
11354,
2219,
446,
65,
283,
1397,
2680,
7,
370,
3372,
511,
272,
768,
3744,
272,
347,
3272,
2543,
8,
1886,
304,
267,
2288,
980,
267,
862,
26,
288,
492,
2680,
465,
980,
288,
492,
7026,
267,
871,
3545,
26,
288,
746,
18795,
360,
5667,
2713,
440,
2808,
2659,
199,
5493,
347,
511,
63,
43,
20,
63,
12916,
8,
277,
304,
267,
408,
24472,
3109,
4171,
9679,
28602,
26,
1804,
20,
624,
267,
598,
29,
1200,
88,
14,
4883,
63,
2180,
8,
20,
9,
267,
330,
29,
1200,
88,
14,
1818,
63,
1659,
63,
13007,
4171,
63,
2497,
28602,
63,
9401,
8,
39,
12,
16854,
598,
14,
2415,
1062,
16854,
598,
14,
2415,
1062,
16854,
9657,
29,
549,
9,
267,
330,
63,
5934,
29,
1200,
88,
14,
1818,
63,
1659,
63,
13007,
4171,
63,
2497,
28602,
8,
39,
12,
12916,
29,
549,
9,
267,
367,
302,
315,
3355,
8,
39,
304,
288,
702,
63,
4398,
63,
1452,
8,
66,
59,
78,
467,
66,
63,
5934,
59,
78,
566,
2378,
347,
511,
63,
43,
20,
8,
277,
304,
267,
408,
24472,
3109,
4171,
9679,
28602,
26,
1804,
20,
624,
267,
598,
29,
1200,
88,
14,
4883,
63,
2180,
8,
20,
9,
267,
330,
29,
1200,
88,
14,
1818,
63,
1659,
63,
13007,
4171,
63,
2497,
28602,
63,
9401,
8,
39,
12,
16854,
598,
14,
2415,
1062,
16854,
598,
14,
2415,
1062,
16854,
9657,
29,
549,
9,
267,
330,
63,
5934,
29,
1200,
88,
14,
1818,
63,
1659,
63,
13007,
4171,
63,
2497,
28602,
8,
39,
12,
12916,
29,
549,
9,
267,
367,
302,
315,
3355,
8,
39,
304,
288,
702,
63,
4398,
63,
1452,
8,
66,
59,
78,
467,
66,
63,
5934,
59,
78,
566,
267,
327,
511,
14609,
2784,
267,
598,
14,
525,
63,
5173,
8,
16,
12,
17,
12,
1445,
3463,
356,
16,
14,
21,
2584,
1848,
356,
16,
14,
19,
1552,
267,
330,
29,
1200,
88,
14,
1818,
63,
1659,
63,
13007,
4171,
63,
2497,
28602,
63,
9401,
8,
39,
12,
16854,
598,
14,
2415,
1062,
16854,
598,
14,
2415,
1062,
16854,
9657,
29,
549,
12,
16854,
5401,
29,
403,
9,
267,
367,
302,
315,
3355,
8,
39,
304,
288,
702,
63,
4398,
63,
1452,
8,
66,
59,
78,
467,
66,
63,
5934,
59,
78,
566,
267,
330,
29,
1200,
88,
14,
1818,
63,
1659,
63,
13007,
4171,
63,
2497,
28602,
63,
9401,
8,
39,
12,
16854,
598,
14,
2415,
1062,
16854,
598,
14,
2415,
1062,
16854,
9657,
29,
549,
9,
267,
330,
63,
5934,
29,
1200,
88,
14,
1818,
63,
1659,
63,
13007,
4171,
63,
2497,
28602,
8,
39,
12,
12916,
29,
549,
9,
267,
367,
302,
315,
3355,
8,
39,
304,
288,
702,
63,
4398,
63,
1452,
8,
66,
59,
78,
467,
66,
63,
5934,
59,
78,
566,
267,
330,
29,
1200,
88,
14,
1818,
63,
1659,
63,
13007,
4171,
63,
2497,
28602,
63,
9401,
8,
39,
12,
16854,
598,
14,
2415,
1062,
16854,
598,
14,
2415,
1062,
16854,
9657,
29,
549,
12,
16854,
5401,
534,
1848,
358,
267,
330,
63,
5934,
29,
1200,
88,
14,
1818,
63,
1659,
63,
13007,
4171,
63,
2497,
28602,
8,
39,
12,
12916,
29,
549,
12,
3463,
534,
1848,
358,
267,
367,
302,
315,
3355,
8,
39,
304,
288,
702,
63,
4398,
63,
1452,
8,
66,
59,
78,
467,
66,
63,
5934,
59,
78,
566,
2378,
347,
511,
63,
48,
20,
63,
12916,
8,
277,
304,
267,
408,
24472,
3109,
4171,
9679,
28602,
26,
510,
20,
9657,
624,
267,
598,
29,
1200,
88,
14,
515,
63,
2180,
8,
20,
9,
267,
330,
29,
1200,
88,
14,
1818,
63,
1659,
63,
13007,
4171,
63,
2497,
28602,
63,
9401,
8,
39,
12,
16854,
598,
14,
2415,
1062,
16854,
598,
14,
2415,
1062,
16854,
9657,
29,
549,
9,
267,
330,
63,
5934,
29,
1200,
88,
14,
1818,
63,
1659,
63,
13007,
4171,
63,
2497,
28602,
8,
39,
12,
12916,
29,
549,
9,
267,
367,
302,
315,
3355,
8,
39,
304,
288,
702,
63,
4398,
63,
1452,
8,
66,
59,
78,
467,
66,
63,
5934,
59,
78,
566,
2378,
347,
511,
63,
48,
20,
8,
277,
304,
267,
408,
24472,
3109,
4171,
9679,
28602,
26,
510,
20,
624,
267,
598,
29,
1200,
88,
14,
515,
63,
2180,
8,
20,
9,
267,
330,
29,
1200,
88,
14,
1818,
63,
1659,
63,
13007,
4171,
63,
2497,
28602,
63,
9401,
8,
39,
12,
16854,
598,
14,
2415,
1062,
16854,
598,
14,
2415,
1062,
16854,
9657,
29,
549,
9,
267,
330,
63,
5934,
29,
1200,
88,
14,
1818,
63,
1659,
63,
13007,
4171,
63,
2497,
28602,
8,
39,
12,
12916,
29,
549,
9,
267,
367,
302,
315,
3355,
8,
39,
304,
288,
702,
63,
4398,
63,
1452,
8,
66,
59,
78,
467,
66,
63,
5934,
59,
78,
566,
339,
347,
511,
63,
7848,
8,
277,
304,
267,
408,
24472,
3109,
4171,
9679,
28602,
26,
14664,
408,
267,
598,
29,
1200,
88,
14,
4578,
342,
267,
598,
14,
525,
63,
7848,
2941,
65,
1673,
66,
1673,
67,
1673,
68,
1105,
267,
330,
29,
1200,
88,
14,
1818,
63,
1659,
63,
13007,
4171,
63,
2497,
28602,
63,
9401,
8,
39,
12,
16854,
598,
14,
2415,
1062,
16854,
598,
14,
2415,
1062,
16854,
9657,
29,
549,
9,
267,
330,
63,
5934,
29,
1200,
88,
14,
1818,
63,
1659,
63,
13007,
4171,
63,
2497,
28602,
8,
39,
12,
12916,
29,
549,
9,
267,
367,
302,
315,
3355,
8,
39,
304,
288,
702,
63,
4398,
63,
1452,
8,
66,
59,
78,
467,
66,
63,
5934,
59,
78,
566,
4388,
199,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1,
1,
1,
1,
1
] |
zhangwengame/shadowsocks
|
shadowsocks/crypto/rc4_md5.py
|
1042
|
1339
|
#!/usr/bin/env python
#
# Copyright 2015 clowwindy
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from __future__ import absolute_import, division, print_function, \
with_statement
import hashlib
from shadowsocks.crypto import openssl
__all__ = ['ciphers']
def create_cipher(alg, key, iv, op, key_as_bytes=0, d=None, salt=None,
i=1, padding=1):
md5 = hashlib.md5()
md5.update(key)
md5.update(iv)
rc4_key = md5.digest()
return openssl.OpenSSLCrypto(b'rc4', rc4_key, b'', op)
ciphers = {
'rc4-md5': (16, 16, create_cipher),
}
def test():
from shadowsocks.crypto import util
cipher = create_cipher('rc4-md5', b'k' * 32, b'i' * 16, 1)
decipher = create_cipher('rc4-md5', b'k' * 32, b'i' * 16, 0)
util.run_cipher(cipher, decipher)
if __name__ == '__main__':
test()
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
6900,
286,
674,
11530,
89,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
12,
971,
272,
543,
63,
6242,
199,
199,
646,
8337,
199,
199,
504,
15084,
21234,
14,
10316,
492,
1551,
4266,
199,
199,
363,
452,
363,
275,
788,
27426,
418,
421,
199,
318,
1218,
63,
9231,
8,
6731,
12,
790,
12,
18831,
12,
1687,
12,
790,
63,
305,
63,
2394,
29,
16,
12,
366,
29,
403,
12,
10105,
29,
403,
12,
2116,
284,
29,
17,
12,
6273,
29,
17,
304,
272,
6128,
21,
275,
8337,
14,
1064,
21,
342,
272,
6128,
21,
14,
873,
8,
498,
9,
272,
6128,
21,
14,
873,
8,
1003,
9,
272,
4819,
20,
63,
498,
275,
6128,
21,
14,
5671,
342,
272,
372,
1551,
4266,
14,
22791,
17134,
8,
66,
7,
1195,
20,
297,
4819,
20,
63,
498,
12,
330,
6448,
1687,
9,
421,
199,
27426,
275,
469,
272,
283,
1195,
20,
13,
1064,
21,
356,
334,
975,
12,
3193,
12,
1218,
63,
9231,
395,
199,
93,
421,
199,
318,
511,
837,
272,
687,
15084,
21234,
14,
10316,
492,
4884,
339,
10830,
275,
1218,
63,
9231,
360,
1195,
20,
13,
1064,
21,
297,
330,
7,
75,
7,
627,
4337,
12,
330,
7,
73,
7,
627,
3193,
12,
413,
9,
272,
477,
9231,
275,
1218,
63,
9231,
360,
1195,
20,
13,
1064,
21,
297,
330,
7,
75,
7,
627,
4337,
12,
330,
7,
73,
7,
627,
3193,
12,
378,
9,
339,
4884,
14,
1065,
63,
9231,
8,
9231,
12,
477,
9231,
9,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
511,
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
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
6900,
286,
674,
11530,
89,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
12,
971,
272,
543,
63,
6242,
199,
199,
646,
8337,
199,
199,
504,
15084,
21234,
14,
10316,
492,
1551,
4266,
199,
199,
363,
452,
363,
275,
788,
27426,
418,
421,
199,
318,
1218,
63,
9231,
8,
6731,
12,
790,
12,
18831,
12,
1687,
12,
790,
63,
305,
63,
2394,
29,
16,
12,
366,
29,
403,
12,
10105,
29,
403,
12,
2116,
284,
29,
17,
12,
6273,
29,
17,
304,
272,
6128,
21,
275,
8337,
14,
1064,
21,
342,
272,
6128,
21,
14,
873,
8,
498,
9,
272,
6128,
21,
14,
873,
8,
1003,
9,
272,
4819,
20,
63,
498,
275,
6128,
21,
14,
5671,
342,
272,
372,
1551,
4266,
14,
22791,
17134,
8,
66,
7,
1195,
20,
297,
4819,
20,
63,
498,
12,
330,
6448,
1687,
9,
421,
199,
27426,
275,
469,
272,
283,
1195,
20,
13,
1064,
21,
356,
334,
975,
12,
3193,
12,
1218,
63,
9231,
395,
199,
93,
421,
199,
318,
511,
837,
272,
687,
15084,
21234,
14,
10316,
492,
4884,
339,
10830,
275,
1218,
63,
9231,
360,
1195,
20,
13,
1064,
21,
297,
330,
7,
75,
7,
627,
4337,
12,
330,
7,
73,
7,
627,
3193,
12,
413,
9,
272,
477,
9231,
275,
1218,
63,
9231,
360,
1195,
20,
13,
1064,
21,
297,
330,
7,
75,
7,
627,
4337,
12,
330,
7,
73,
7,
627,
3193,
12,
378,
9,
339,
4884,
14,
1065,
63,
9231,
8,
9231,
12,
477,
9231,
9,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
511,
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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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
] |
2rs2ts/moto
|
moto/ec2/utils.py
|
3
|
17955
|
from __future__ import unicode_literals
import random
import re
import six
EC2_RESOURCE_TO_PREFIX = {
'customer-gateway': 'cgw',
'dhcp-options': 'dopt',
'image': 'ami',
'instance': 'i',
'internet-gateway': 'igw',
'nat-gateway': 'nat',
'network-acl': 'acl',
'network-acl-subnet-assoc': 'aclassoc',
'network-interface': 'eni',
'network-interface-attachment': 'eni-attach',
'reserved-instance': 'uuid4',
'route-table': 'rtb',
'route-table-association': 'rtbassoc',
'security-group': 'sg',
'snapshot': 'snap',
'spot-instance-request': 'sir',
'spot-fleet-request': 'sfr',
'subnet': 'subnet',
'reservation': 'r',
'volume': 'vol',
'vpc': 'vpc',
'vpc-elastic-ip': 'eipalloc',
'vpc-elastic-ip-association': 'eipassoc',
'vpc-peering-connection': 'pcx',
'vpn-connection': 'vpn',
'vpn-gateway': 'vgw'}
EC2_PREFIX_TO_RESOURCE = dict((v, k)
for (k, v) in EC2_RESOURCE_TO_PREFIX.items())
def random_id(prefix='', size=8):
chars = list(range(10)) + ['a', 'b', 'c', 'd', 'e', 'f']
resource_id = ''.join(six.text_type(random.choice(chars))
for x in range(size))
return '{0}-{1}'.format(prefix, resource_id)
def random_ami_id():
return random_id(prefix=EC2_RESOURCE_TO_PREFIX['image'])
def random_instance_id():
return random_id(prefix=EC2_RESOURCE_TO_PREFIX['instance'])
def random_reservation_id():
return random_id(prefix=EC2_RESOURCE_TO_PREFIX['reservation'])
def random_security_group_id():
return random_id(prefix=EC2_RESOURCE_TO_PREFIX['security-group'])
def random_snapshot_id():
return random_id(prefix=EC2_RESOURCE_TO_PREFIX['snapshot'])
def random_spot_request_id():
return random_id(prefix=EC2_RESOURCE_TO_PREFIX['spot-instance-request'])
def random_spot_fleet_request_id():
return random_id(prefix=EC2_RESOURCE_TO_PREFIX['spot-fleet-request'])
def random_subnet_id():
return random_id(prefix=EC2_RESOURCE_TO_PREFIX['subnet'])
def random_subnet_association_id():
return random_id(prefix=EC2_RESOURCE_TO_PREFIX['route-table-association'])
def random_network_acl_id():
return random_id(prefix=EC2_RESOURCE_TO_PREFIX['network-acl'])
def random_network_acl_subnet_association_id():
return random_id(prefix=EC2_RESOURCE_TO_PREFIX['network-acl-subnet-assoc'])
def random_vpn_gateway_id():
return random_id(prefix=EC2_RESOURCE_TO_PREFIX['vpn-gateway'])
def random_vpn_connection_id():
return random_id(prefix=EC2_RESOURCE_TO_PREFIX['vpn-connection'])
def random_customer_gateway_id():
return random_id(prefix=EC2_RESOURCE_TO_PREFIX['customer-gateway'])
def random_volume_id():
return random_id(prefix=EC2_RESOURCE_TO_PREFIX['volume'])
def random_vpc_id():
return random_id(prefix=EC2_RESOURCE_TO_PREFIX['vpc'])
def random_vpc_peering_connection_id():
return random_id(prefix=EC2_RESOURCE_TO_PREFIX['vpc-peering-connection'])
def random_eip_association_id():
return random_id(prefix=EC2_RESOURCE_TO_PREFIX['vpc-elastic-ip-association'])
def random_internet_gateway_id():
return random_id(prefix=EC2_RESOURCE_TO_PREFIX['internet-gateway'])
def random_route_table_id():
return random_id(prefix=EC2_RESOURCE_TO_PREFIX['route-table'])
def random_eip_allocation_id():
return random_id(prefix=EC2_RESOURCE_TO_PREFIX['vpc-elastic-ip'])
def random_dhcp_option_id():
return random_id(prefix=EC2_RESOURCE_TO_PREFIX['dhcp-options'])
def random_eni_id():
return random_id(prefix=EC2_RESOURCE_TO_PREFIX['network-interface'])
def random_eni_attach_id():
return random_id(prefix=EC2_RESOURCE_TO_PREFIX['network-interface-attachment'])
def random_nat_gateway_id():
return random_id(prefix=EC2_RESOURCE_TO_PREFIX['nat-gateway'], size=17)
def random_public_ip():
return '54.214.{0}.{1}'.format(random.choice(range(255)),
random.choice(range(255)))
def random_private_ip():
return '10.{0}.{1}.{2}'.format(random.choice(range(255)),
random.choice(range(255)),
random.choice(range(255)))
def random_ip():
return "127.{0}.{1}.{2}".format(
random.randint(0, 255),
random.randint(0, 255),
random.randint(0, 255)
)
def generate_route_id(route_table_id, cidr_block):
return "%s~%s" % (route_table_id, cidr_block)
def split_route_id(route_id):
values = route_id.split('~')
return values[0], values[1]
def instance_ids_from_querystring(querystring_dict):
instance_ids = []
for key, value in querystring_dict.items():
if 'InstanceId' in key:
instance_ids.append(value[0])
return instance_ids
def image_ids_from_querystring(querystring_dict):
image_ids = []
for key, value in querystring_dict.items():
if 'ImageId' in key:
image_ids.append(value[0])
return image_ids
def route_table_ids_from_querystring(querystring_dict):
route_table_ids = []
for key, value in querystring_dict.items():
if 'RouteTableId' in key:
route_table_ids.append(value[0])
return route_table_ids
def network_acl_ids_from_querystring(querystring_dict):
network_acl_ids = []
for key, value in querystring_dict.items():
if 'NetworkAclId' in key:
network_acl_ids.append(value[0])
return network_acl_ids
def vpc_ids_from_querystring(querystring_dict):
vpc_ids = []
for key, value in querystring_dict.items():
if 'VpcId' in key:
vpc_ids.append(value[0])
return vpc_ids
def sequence_from_querystring(parameter, querystring_dict):
parameter_values = []
for key, value in querystring_dict.items():
if parameter in key:
parameter_values.append(value[0])
return parameter_values
def tags_from_query_string(querystring_dict):
prefix = 'Tag'
suffix = 'Key'
response_values = {}
for key, value in querystring_dict.items():
if key.startswith(prefix) and key.endswith(suffix):
tag_index = key.replace(prefix + ".", "").replace("." + suffix, "")
tag_key = querystring_dict.get("Tag.{0}.Key".format(tag_index))[0]
tag_value_key = "Tag.{0}.Value".format(tag_index)
if tag_value_key in querystring_dict:
response_values[tag_key] = querystring_dict.get(tag_value_key)[
0]
else:
response_values[tag_key] = None
return response_values
def dhcp_configuration_from_querystring(querystring, option=u'DhcpConfiguration'):
"""
turn:
{u'AWSAccessKeyId': [u'the_key'],
u'Action': [u'CreateDhcpOptions'],
u'DhcpConfiguration.1.Key': [u'domain-name'],
u'DhcpConfiguration.1.Value.1': [u'example.com'],
u'DhcpConfiguration.2.Key': [u'domain-name-servers'],
u'DhcpConfiguration.2.Value.1': [u'10.0.0.6'],
u'DhcpConfiguration.2.Value.2': [u'10.0.0.7'],
u'Signature': [u'uUMHYOoLM6r+sT4fhYjdNT6MHw22Wj1mafUpe0P0bY4='],
u'SignatureMethod': [u'HmacSHA256'],
u'SignatureVersion': [u'2'],
u'Timestamp': [u'2014-03-18T21:54:01Z'],
u'Version': [u'2013-10-15']}
into:
{u'domain-name': [u'example.com'], u'domain-name-servers': [u'10.0.0.6', u'10.0.0.7']}
"""
key_needle = re.compile(u'{0}.[0-9]+.Key'.format(option), re.UNICODE)
response_values = {}
for key, value in querystring.items():
if key_needle.match(key):
values = []
key_index = key.split(".")[1]
value_index = 1
while True:
value_key = u'{0}.{1}.Value.{2}'.format(
option, key_index, value_index)
if value_key in querystring:
values.extend(querystring[value_key])
else:
break
value_index += 1
response_values[value[0]] = values
return response_values
def optional_from_querystring(parameter, querystring):
parameter_array = querystring.get(parameter)
return parameter_array[0] if parameter_array else None
def filters_from_querystring(querystring_dict):
response_values = {}
for key, value in querystring_dict.items():
match = re.search(r"Filter.(\d).Name", key)
if match:
filter_index = match.groups()[0]
value_prefix = "Filter.{0}.Value".format(filter_index)
filter_values = [filter_value[0] for filter_key, filter_value in querystring_dict.items() if
filter_key.startswith(value_prefix)]
response_values[value[0]] = filter_values
return response_values
def dict_from_querystring(parameter, querystring_dict):
use_dict = {}
for key, value in querystring_dict.items():
match = re.search(r"{0}.(\d).(\w+)".format(parameter), key)
if match:
use_dict_index = match.groups()[0]
use_dict_element_property = match.groups()[1]
if not use_dict.get(use_dict_index):
use_dict[use_dict_index] = {}
use_dict[use_dict_index][use_dict_element_property] = value[0]
return use_dict
def keypair_names_from_querystring(querystring_dict):
keypair_names = []
for key, value in querystring_dict.items():
if 'KeyName' in key:
keypair_names.append(value[0])
return keypair_names
def get_object_value(obj, attr):
keys = attr.split('.')
val = obj
for key in keys:
if hasattr(val, key):
val = getattr(val, key)
elif isinstance(val, dict):
val = val[key]
else:
return None
return val
def is_tag_filter(filter_name):
return (filter_name.startswith('tag:') or
filter_name.startswith('tag-value') or
filter_name.startswith('tag-key'))
def get_obj_tag(obj, filter_name):
tag_name = filter_name.replace('tag:', '', 1)
tags = dict((tag['key'], tag['value']) for tag in obj.get_tags())
return tags.get(tag_name)
def get_obj_tag_names(obj):
tags = set((tag['key'] for tag in obj.get_tags()))
return tags
def get_obj_tag_values(obj):
tags = set((tag['value'] for tag in obj.get_tags()))
return tags
def tag_filter_matches(obj, filter_name, filter_values):
regex_filters = [re.compile(simple_aws_filter_to_re(f))
for f in filter_values]
if filter_name == 'tag-key':
tag_values = get_obj_tag_names(obj)
elif filter_name == 'tag-value':
tag_values = get_obj_tag_values(obj)
else:
tag_values = [get_obj_tag(obj, filter_name) or '']
for tag_value in tag_values:
if any(regex.match(tag_value) for regex in regex_filters):
return True
return False
filter_dict_attribute_mapping = {
'instance-state-name': 'state',
'instance-id': 'id',
'state-reason-code': '_state_reason.code',
'source-dest-check': 'source_dest_check',
'vpc-id': 'vpc_id',
'group-id': 'security_groups',
'instance.group-id': 'security_groups',
'instance-type': 'instance_type',
'private-ip-address': 'private_ip',
'ip-address': 'public_ip',
'availability-zone': 'placement',
'architecture': 'architecture'
}
def passes_filter_dict(instance, filter_dict):
for filter_name, filter_values in filter_dict.items():
if filter_name in filter_dict_attribute_mapping:
instance_attr = filter_dict_attribute_mapping[filter_name]
instance_value = get_object_value(instance, instance_attr)
if not instance_value_in_filter_values(instance_value, filter_values):
return False
elif is_tag_filter(filter_name):
if not tag_filter_matches(instance, filter_name, filter_values):
return False
else:
raise NotImplementedError(
"Filter dicts have not been implemented in Moto for '%s' yet. Feel free to open an issue at https://github.com/spulec/moto/issues" %
filter_name)
return True
def instance_value_in_filter_values(instance_value, filter_values):
if isinstance(instance_value, list):
if not set(filter_values).intersection(set(instance_value)):
return False
elif instance_value not in filter_values:
return False
return True
def filter_reservations(reservations, filter_dict):
result = []
for reservation in reservations:
new_instances = []
for instance in reservation.instances:
if passes_filter_dict(instance, filter_dict):
new_instances.append(instance)
if new_instances:
reservation.instances = new_instances
result.append(reservation)
return result
filter_dict_igw_mapping = {
"attachment.vpc-id": "vpc.id",
"attachment.state": "attachment_state",
"internet-gateway-id": "id",
}
def passes_igw_filter_dict(igw, filter_dict):
for filter_name, filter_values in filter_dict.items():
if filter_name in filter_dict_igw_mapping:
igw_attr = filter_dict_igw_mapping[filter_name]
if get_object_value(igw, igw_attr) not in filter_values:
return False
elif is_tag_filter(filter_name):
if not tag_filter_matches(igw, filter_name, filter_values):
return False
else:
raise NotImplementedError(
"Internet Gateway filter dicts have not been implemented in Moto for '%s' yet. Feel free to open an issue at https://github.com/spulec/moto/issues",
filter_name)
return True
def filter_internet_gateways(igws, filter_dict):
result = []
for igw in igws:
if passes_igw_filter_dict(igw, filter_dict):
result.append(igw)
return result
def is_filter_matching(obj, filter, filter_value):
value = obj.get_filter_value(filter)
if isinstance(value, six.string_types):
return value in filter_value
try:
value = set(value)
return (value and value.issubset(filter_value)) or value.issuperset(filter_value)
except TypeError:
return value in filter_value
def generic_filter(filters, objects):
if filters:
for (_filter, _filter_value) in filters.items():
objects = [obj for obj in objects if is_filter_matching(
obj, _filter, _filter_value)]
return objects
def simple_aws_filter_to_re(filter_string):
import fnmatch
tmp_filter = filter_string.replace('\?', '[?]')
tmp_filter = tmp_filter.replace('\*', '[*]')
tmp_filter = fnmatch.translate(tmp_filter)
return tmp_filter
def random_key_pair():
def random_hex():
return chr(random.choice(list(range(48, 58)) + list(range(97, 102))))
def random_fingerprint():
return ':'.join([random_hex() + random_hex() for i in range(20)])
def random_material():
return ''.join([
chr(random.choice(list(range(65, 91)) + list(range(48, 58)) +
list(range(97, 102))))
for i in range(1000)
])
material = "---- BEGIN RSA PRIVATE KEY ----" + random_material() + \
"-----END RSA PRIVATE KEY-----"
return {
'fingerprint': random_fingerprint(),
'material': material
}
def get_prefix(resource_id):
resource_id_prefix, separator, after = resource_id.partition('-')
if resource_id_prefix == EC2_RESOURCE_TO_PREFIX['network-interface']:
if after.startswith('attach'):
resource_id_prefix = EC2_RESOURCE_TO_PREFIX[
'network-interface-attachment']
if resource_id_prefix not in EC2_RESOURCE_TO_PREFIX.values():
uuid4hex = re.compile(
'[0-9a-f]{12}4[0-9a-f]{3}[89ab][0-9a-f]{15}\Z', re.I)
if uuid4hex.match(resource_id) is not None:
resource_id_prefix = EC2_RESOURCE_TO_PREFIX['reserved-instance']
else:
return None
return resource_id_prefix
def is_valid_resource_id(resource_id):
valid_prefixes = EC2_RESOURCE_TO_PREFIX.values()
resource_id_prefix = get_prefix(resource_id)
if resource_id_prefix not in valid_prefixes:
return False
resource_id_pattern = resource_id_prefix + '-[0-9a-f]{8}'
resource_pattern_re = re.compile(resource_id_pattern)
return resource_pattern_re.match(resource_id) is not None
def is_valid_cidr(cird):
cidr_pattern = '^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/(\d|[1-2]\d|3[0-2]))$'
cidr_pattern_re = re.compile(cidr_pattern)
return cidr_pattern_re.match(cird) is not None
def generate_instance_identity_document(instance):
"""
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-identity-documents.html
A JSON file that describes an instance. Usually retrieved by URL:
http://169.254.169.254/latest/dynamic/instance-identity/document
Here we just fill a dictionary that represents the document
Typically, this document is used by the amazon-ecs-agent when registering a
new ContainerInstance
"""
document = {
'devPayProductCodes': None,
'availabilityZone': instance.placement['AvailabilityZone'],
'privateIp': instance.private_ip_address,
'version': '2010-8-31',
'region': instance.placement['AvailabilityZone'][:-1],
'instanceId': instance.id,
'billingProducts': None,
'instanceType': instance.instance_type,
'accountId': '012345678910',
'pendingTime': '2015-11-19T16:32:11Z',
'imageId': instance.image_id,
'kernelId': instance.kernel_id,
'ramdiskId': instance.ramdisk_id,
'architecture': instance.architecture,
}
return document
|
apache-2.0
|
[
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
646,
2196,
199,
646,
295,
199,
646,
3816,
199,
199,
4220,
18,
63,
14110,
63,
2566,
63,
6351,
275,
469,
272,
283,
10178,
13,
7019,
356,
283,
67,
8392,
297,
272,
283,
10801,
13,
1419,
356,
283,
68,
2992,
297,
272,
283,
1569,
356,
283,
13496,
297,
272,
283,
842,
356,
283,
73,
297,
272,
283,
4901,
13,
7019,
356,
283,
528,
87,
297,
272,
283,
9468,
13,
7019,
356,
283,
9468,
297,
272,
283,
1200,
13,
5853,
356,
283,
5853,
297,
272,
283,
1200,
13,
5853,
13,
5327,
13,
16824,
356,
283,
65,
533,
679,
297,
272,
283,
1200,
13,
3266,
356,
283,
30647,
297,
272,
283,
1200,
13,
3266,
13,
8905,
356,
283,
30647,
13,
5040,
297,
272,
283,
10421,
13,
842,
356,
283,
2580,
20,
297,
272,
283,
4449,
13,
1224,
356,
283,
2591,
66,
297,
272,
283,
4449,
13,
1224,
13,
20252,
356,
283,
2591,
66,
16824,
297,
272,
283,
4416,
13,
923,
356,
283,
1226,
297,
272,
283,
4753,
356,
283,
10002,
297,
272,
283,
15185,
13,
842,
13,
1069,
356,
283,
338,
82,
297,
272,
283,
15185,
13,
21599,
386,
13,
1069,
356,
283,
83,
4391,
297,
272,
283,
5327,
356,
283,
5327,
297,
272,
283,
20522,
356,
283,
82,
297,
272,
283,
2405,
356,
283,
5650,
297,
272,
283,
11742,
356,
283,
11742,
297,
272,
283,
11742,
13,
15565,
13,
711,
356,
283,
69,
711,
9373,
297,
272,
283,
11742,
13,
15565,
13,
711,
13,
20252,
356,
283,
69,
711,
16824,
297,
272,
283,
11742,
13,
7866,
316,
13,
2105,
356,
283,
2352,
88,
297,
272,
283,
9702,
13,
2105,
356,
283,
9702,
297,
272,
283,
9702,
13,
7019,
356,
283,
26408,
936,
421,
199,
4220,
18,
63,
6351,
63,
2566,
63,
14110,
275,
1211,
1332,
86,
12,
1022,
9,
2892,
367,
334,
75,
12,
373,
9,
315,
15352,
18,
63,
14110,
63,
2566,
63,
6351,
14,
1744,
1012,
421,
199,
318,
2196,
63,
344,
8,
1861,
4581,
1568,
29,
24,
304,
272,
8365,
275,
769,
8,
1842,
8,
709,
430,
435,
788,
65,
297,
283,
66,
297,
283,
67,
297,
283,
68,
297,
283,
69,
297,
283,
70,
418,
339,
2073,
63,
344,
275,
6522,
904,
8,
4174,
14,
505,
63,
466,
8,
2355,
14,
5095,
8,
6574,
430,
2079,
367,
671,
315,
1425,
8,
890,
430,
272,
372,
5041,
16,
30289,
17,
5285,
908,
8,
1861,
12,
2073,
63,
344,
9,
421,
199,
318,
2196,
63,
13496,
63,
344,
837,
272,
372,
2196,
63,
344,
8,
1861,
29,
4220,
18,
63,
14110,
63,
2566,
63,
6351,
459,
1569,
1105,
421,
199,
318,
2196,
63,
842,
63,
344,
837,
272,
372,
2196,
63,
344,
8,
1861,
29,
4220,
18,
63,
14110,
63,
2566,
63,
6351,
459,
842,
1105,
421,
199,
318,
2196,
63,
20522,
63,
344,
837,
272,
372,
2196,
63,
344,
8,
1861,
29,
4220,
18,
63,
14110,
63,
2566,
63,
6351,
459,
20522,
1105,
421,
199,
318,
2196,
63,
4416,
63,
923,
63,
344,
837,
272,
372,
2196,
63,
344,
8,
1861,
29,
4220,
18,
63,
14110,
63,
2566,
63,
6351,
459,
4416,
13,
923,
1105,
421,
199,
318,
2196,
63,
4753,
63,
344,
837,
272,
372,
2196,
63,
344,
8,
1861,
29,
4220,
18,
63,
14110,
63,
2566,
63,
6351,
459,
4753,
1105,
421,
199,
318,
2196,
63,
15185,
63,
1069,
63,
344,
837,
272,
372,
2196,
63,
344,
8,
1861,
29,
4220,
18,
63,
14110,
63,
2566,
63,
6351,
459,
15185,
13,
842,
13,
1069,
1105,
421,
199,
318,
2196,
63,
15185,
63,
21599,
386,
63,
1069,
63,
344,
837,
272,
372,
2196,
63,
344,
8,
1861,
29,
4220,
18,
63,
14110,
63,
2566,
63,
6351,
459,
15185,
13,
21599,
386,
13,
1069,
1105,
421,
199,
318,
2196,
63,
5327,
63,
344,
837,
272,
372,
2196,
63,
344,
8,
1861,
29,
4220,
18,
63,
14110,
63,
2566,
63,
6351,
459,
5327,
1105,
421,
199,
318,
2196,
63,
5327,
63,
20252,
63,
344,
837,
272,
372,
2196,
63,
344,
8,
1861,
29,
4220,
18,
63,
14110,
63,
2566,
63,
6351,
459,
4449,
13,
1224,
13,
20252,
1105,
421,
199,
318,
2196,
63,
1200,
63,
5853,
63,
344,
837,
272,
372,
2196,
63,
344,
8,
1861,
29,
4220,
18,
63,
14110,
63,
2566,
63,
6351,
459,
1200,
13,
5853,
1105,
421,
199,
318,
2196,
63,
1200,
63,
5853,
63,
5327,
63,
20252,
63,
344,
837,
272,
372,
2196,
63,
344,
8,
1861,
29,
4220,
18,
63,
14110,
63,
2566,
63,
6351,
459,
1200,
13,
5853,
13,
5327,
13,
16824,
1105,
421,
199,
318,
2196,
63,
9702,
63,
7019,
63,
344,
837,
272,
372,
2196,
63,
344,
8,
1861,
29,
4220,
18,
63,
14110,
63,
2566,
63,
6351,
459,
9702,
13,
7019,
1105,
421,
199,
318,
2196,
63,
9702,
63,
2105,
63,
344,
837,
272,
372,
2196,
63,
344,
8,
1861,
29,
4220,
18,
63,
14110,
63,
2566,
63,
6351,
459,
9702,
13,
2105,
1105,
421,
199,
318,
2196,
63,
10178,
63,
7019,
63,
344,
837,
272,
372,
2196,
63,
344,
8,
1861,
29,
4220,
18,
63,
14110,
63,
2566,
63,
6351,
459,
10178,
13,
7019,
1105,
421,
199,
318,
2196,
63,
2405,
63,
344,
837,
272,
372,
2196,
63,
344,
8,
1861,
29,
4220,
18,
63,
14110,
63,
2566,
63,
6351,
459,
2405,
1105,
421,
199,
318,
2196,
63,
11742,
63,
344,
837,
272,
372,
2196,
63,
344,
8,
1861,
29,
4220,
18,
63,
14110,
63,
2566,
63,
6351,
459,
11742,
1105,
421,
199,
318,
2196,
63,
11742,
63,
7866,
316,
63,
2105,
63,
344,
837,
272,
372,
2196,
63,
344,
8,
1861,
29,
4220,
18,
63,
14110,
63,
2566,
63,
6351,
459,
11742,
13,
7866,
316,
13,
2105,
1105,
421,
199,
318,
2196,
63,
69,
711,
63,
20252,
63,
344,
837,
272,
372,
2196,
63,
344,
8,
1861,
29,
4220,
18,
63,
14110,
63,
2566,
63,
6351,
459,
11742,
13,
15565,
13,
711,
13,
20252,
1105,
421,
199,
318,
2196,
63,
4901,
63,
7019,
63,
344,
837,
272,
372,
2196,
63,
344,
8,
1861,
29,
4220,
18,
63,
14110,
63,
2566,
63,
6351,
459,
4901,
13,
7019,
1105,
421,
199,
318,
2196,
63,
4449
] |
[
636,
2443,
363,
492,
2649,
63,
5955,
199,
646,
2196,
199,
646,
295,
199,
646,
3816,
199,
199,
4220,
18,
63,
14110,
63,
2566,
63,
6351,
275,
469,
272,
283,
10178,
13,
7019,
356,
283,
67,
8392,
297,
272,
283,
10801,
13,
1419,
356,
283,
68,
2992,
297,
272,
283,
1569,
356,
283,
13496,
297,
272,
283,
842,
356,
283,
73,
297,
272,
283,
4901,
13,
7019,
356,
283,
528,
87,
297,
272,
283,
9468,
13,
7019,
356,
283,
9468,
297,
272,
283,
1200,
13,
5853,
356,
283,
5853,
297,
272,
283,
1200,
13,
5853,
13,
5327,
13,
16824,
356,
283,
65,
533,
679,
297,
272,
283,
1200,
13,
3266,
356,
283,
30647,
297,
272,
283,
1200,
13,
3266,
13,
8905,
356,
283,
30647,
13,
5040,
297,
272,
283,
10421,
13,
842,
356,
283,
2580,
20,
297,
272,
283,
4449,
13,
1224,
356,
283,
2591,
66,
297,
272,
283,
4449,
13,
1224,
13,
20252,
356,
283,
2591,
66,
16824,
297,
272,
283,
4416,
13,
923,
356,
283,
1226,
297,
272,
283,
4753,
356,
283,
10002,
297,
272,
283,
15185,
13,
842,
13,
1069,
356,
283,
338,
82,
297,
272,
283,
15185,
13,
21599,
386,
13,
1069,
356,
283,
83,
4391,
297,
272,
283,
5327,
356,
283,
5327,
297,
272,
283,
20522,
356,
283,
82,
297,
272,
283,
2405,
356,
283,
5650,
297,
272,
283,
11742,
356,
283,
11742,
297,
272,
283,
11742,
13,
15565,
13,
711,
356,
283,
69,
711,
9373,
297,
272,
283,
11742,
13,
15565,
13,
711,
13,
20252,
356,
283,
69,
711,
16824,
297,
272,
283,
11742,
13,
7866,
316,
13,
2105,
356,
283,
2352,
88,
297,
272,
283,
9702,
13,
2105,
356,
283,
9702,
297,
272,
283,
9702,
13,
7019,
356,
283,
26408,
936,
421,
199,
4220,
18,
63,
6351,
63,
2566,
63,
14110,
275,
1211,
1332,
86,
12,
1022,
9,
2892,
367,
334,
75,
12,
373,
9,
315,
15352,
18,
63,
14110,
63,
2566,
63,
6351,
14,
1744,
1012,
421,
199,
318,
2196,
63,
344,
8,
1861,
4581,
1568,
29,
24,
304,
272,
8365,
275,
769,
8,
1842,
8,
709,
430,
435,
788,
65,
297,
283,
66,
297,
283,
67,
297,
283,
68,
297,
283,
69,
297,
283,
70,
418,
339,
2073,
63,
344,
275,
6522,
904,
8,
4174,
14,
505,
63,
466,
8,
2355,
14,
5095,
8,
6574,
430,
2079,
367,
671,
315,
1425,
8,
890,
430,
272,
372,
5041,
16,
30289,
17,
5285,
908,
8,
1861,
12,
2073,
63,
344,
9,
421,
199,
318,
2196,
63,
13496,
63,
344,
837,
272,
372,
2196,
63,
344,
8,
1861,
29,
4220,
18,
63,
14110,
63,
2566,
63,
6351,
459,
1569,
1105,
421,
199,
318,
2196,
63,
842,
63,
344,
837,
272,
372,
2196,
63,
344,
8,
1861,
29,
4220,
18,
63,
14110,
63,
2566,
63,
6351,
459,
842,
1105,
421,
199,
318,
2196,
63,
20522,
63,
344,
837,
272,
372,
2196,
63,
344,
8,
1861,
29,
4220,
18,
63,
14110,
63,
2566,
63,
6351,
459,
20522,
1105,
421,
199,
318,
2196,
63,
4416,
63,
923,
63,
344,
837,
272,
372,
2196,
63,
344,
8,
1861,
29,
4220,
18,
63,
14110,
63,
2566,
63,
6351,
459,
4416,
13,
923,
1105,
421,
199,
318,
2196,
63,
4753,
63,
344,
837,
272,
372,
2196,
63,
344,
8,
1861,
29,
4220,
18,
63,
14110,
63,
2566,
63,
6351,
459,
4753,
1105,
421,
199,
318,
2196,
63,
15185,
63,
1069,
63,
344,
837,
272,
372,
2196,
63,
344,
8,
1861,
29,
4220,
18,
63,
14110,
63,
2566,
63,
6351,
459,
15185,
13,
842,
13,
1069,
1105,
421,
199,
318,
2196,
63,
15185,
63,
21599,
386,
63,
1069,
63,
344,
837,
272,
372,
2196,
63,
344,
8,
1861,
29,
4220,
18,
63,
14110,
63,
2566,
63,
6351,
459,
15185,
13,
21599,
386,
13,
1069,
1105,
421,
199,
318,
2196,
63,
5327,
63,
344,
837,
272,
372,
2196,
63,
344,
8,
1861,
29,
4220,
18,
63,
14110,
63,
2566,
63,
6351,
459,
5327,
1105,
421,
199,
318,
2196,
63,
5327,
63,
20252,
63,
344,
837,
272,
372,
2196,
63,
344,
8,
1861,
29,
4220,
18,
63,
14110,
63,
2566,
63,
6351,
459,
4449,
13,
1224,
13,
20252,
1105,
421,
199,
318,
2196,
63,
1200,
63,
5853,
63,
344,
837,
272,
372,
2196,
63,
344,
8,
1861,
29,
4220,
18,
63,
14110,
63,
2566,
63,
6351,
459,
1200,
13,
5853,
1105,
421,
199,
318,
2196,
63,
1200,
63,
5853,
63,
5327,
63,
20252,
63,
344,
837,
272,
372,
2196,
63,
344,
8,
1861,
29,
4220,
18,
63,
14110,
63,
2566,
63,
6351,
459,
1200,
13,
5853,
13,
5327,
13,
16824,
1105,
421,
199,
318,
2196,
63,
9702,
63,
7019,
63,
344,
837,
272,
372,
2196,
63,
344,
8,
1861,
29,
4220,
18,
63,
14110,
63,
2566,
63,
6351,
459,
9702,
13,
7019,
1105,
421,
199,
318,
2196,
63,
9702,
63,
2105,
63,
344,
837,
272,
372,
2196,
63,
344,
8,
1861,
29,
4220,
18,
63,
14110,
63,
2566,
63,
6351,
459,
9702,
13,
2105,
1105,
421,
199,
318,
2196,
63,
10178,
63,
7019,
63,
344,
837,
272,
372,
2196,
63,
344,
8,
1861,
29,
4220,
18,
63,
14110,
63,
2566,
63,
6351,
459,
10178,
13,
7019,
1105,
421,
199,
318,
2196,
63,
2405,
63,
344,
837,
272,
372,
2196,
63,
344,
8,
1861,
29,
4220,
18,
63,
14110,
63,
2566,
63,
6351,
459,
2405,
1105,
421,
199,
318,
2196,
63,
11742,
63,
344,
837,
272,
372,
2196,
63,
344,
8,
1861,
29,
4220,
18,
63,
14110,
63,
2566,
63,
6351,
459,
11742,
1105,
421,
199,
318,
2196,
63,
11742,
63,
7866,
316,
63,
2105,
63,
344,
837,
272,
372,
2196,
63,
344,
8,
1861,
29,
4220,
18,
63,
14110,
63,
2566,
63,
6351,
459,
11742,
13,
7866,
316,
13,
2105,
1105,
421,
199,
318,
2196,
63,
69,
711,
63,
20252,
63,
344,
837,
272,
372,
2196,
63,
344,
8,
1861,
29,
4220,
18,
63,
14110,
63,
2566,
63,
6351,
459,
11742,
13,
15565,
13,
711,
13,
20252,
1105,
421,
199,
318,
2196,
63,
4901,
63,
7019,
63,
344,
837,
272,
372,
2196,
63,
344,
8,
1861,
29,
4220,
18,
63,
14110,
63,
2566,
63,
6351,
459,
4901,
13,
7019,
1105,
421,
199,
318,
2196,
63,
4449,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
fangxingli/hue
|
desktop/core/ext-py/pysaml2-2.4.0/src/saml2/aes.py
|
34
|
3421
|
#!/usr/bin/env python
import os
from Crypto import Random
from Crypto.Cipher import AES
from base64 import b64encode, b64decode
__author__ = 'rolandh'
POSTFIX_MODE = {
"cbc": AES.MODE_CBC,
"cfb": AES.MODE_CFB,
"ecb": AES.MODE_CFB,
}
BLOCK_SIZE = 16
class AESCipher(object):
def __init__(self, key, iv=""):
"""
:param key: The encryption key
:param iv: Init vector
:return: AESCipher instance
"""
self.key = key
self.iv = iv
def build_cipher(self, iv="", alg="aes_128_cbc"):
"""
:param iv: init vector
:param alg: cipher algorithm
:return: A Cipher instance
"""
typ, bits, cmode = alg.split("_")
if not iv:
if self.iv:
iv = self.iv
else:
iv = Random.new().read(AES.block_size)
else:
assert len(iv) == AES.block_size
if bits not in ["128", "192", "256"]:
raise Exception("Unsupported key length")
try:
assert len(self.key) == int(bits) >> 3
except AssertionError:
raise Exception("Wrong Key length")
try:
return AES.new(self.key, POSTFIX_MODE[cmode], iv), iv
except KeyError:
raise Exception("Unsupported chaining mode")
def encrypt(self, msg, iv=None, alg="aes_128_cbc", padding="PKCS#7",
b64enc=True, block_size=BLOCK_SIZE):
"""
:param key: The encryption key
:param iv: init vector
:param msg: Message to be encrypted
:param padding: Which padding that should be used
:param b64enc: Whether the result should be base64encoded
:param block_size: If PKCS#7 padding which block size to use
:return: The encrypted message
"""
if padding == "PKCS#7":
_block_size = block_size
elif padding == "PKCS#5":
_block_size = 8
else:
_block_size = 0
if _block_size:
plen = _block_size - (len(msg) % _block_size)
c = chr(plen)
msg += c*plen
cipher, iv = self.build_cipher(iv, alg)
cmsg = iv + cipher.encrypt(msg)
if b64enc:
return b64encode(cmsg)
else:
return cmsg
def decrypt(self, msg, iv=None, padding="PKCS#7", b64dec=True):
"""
:param key: The encryption key
:param iv: init vector
:param msg: Base64 encoded message to be decrypted
:return: The decrypted message
"""
if b64dec:
data = b64decode(msg)
else:
data = msg
_iv = data[:AES.block_size]
if iv:
assert iv == _iv
cipher, iv = self.build_cipher(iv)
res = cipher.decrypt(data)[AES.block_size:]
if padding in ["PKCS#5", "PKCS#7"]:
res = res[:-ord(res[-1])]
return res
if __name__ == "__main__":
key_ = "1234523451234545" # 16 byte key
# Iff padded, the message doesn't have to be multiple of 16 in length
msg_ = "ToBeOrNotTobe W.S."
aes = AESCipher(key_)
iv_ = os.urandom(16)
encrypted_msg = aes.encrypt(key_, msg_, iv_)
txt = aes.decrypt(key_, encrypted_msg, iv_)
assert txt == msg_
encrypted_msg = aes.encrypt(key_, msg_, 0)
txt = aes.decrypt(key_, encrypted_msg, 0)
assert txt == msg_
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
646,
747,
199,
504,
18855,
492,
9571,
199,
504,
18855,
14,
21967,
492,
19093,
199,
504,
1300,
772,
492,
330,
772,
2143,
12,
330,
772,
2708,
199,
199,
363,
2502,
363,
275,
283,
8459,
460,
72,
7,
199,
199,
4030,
5192,
63,
6963,
275,
469,
272,
298,
19279,
582,
19093,
14,
6963,
63,
18255,
12,
272,
298,
24298,
582,
19093,
14,
6963,
63,
5487,
34,
12,
272,
298,
25467,
582,
19093,
14,
6963,
63,
5487,
34,
12,
199,
93,
199,
199,
8475,
63,
4305,
275,
3193,
421,
199,
533,
19093,
21967,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
790,
12,
18831,
17364,
267,
408,
398,
520,
635,
790,
26,
710,
14396,
790,
267,
520,
635,
18831,
26,
21026,
5477,
267,
520,
1107,
26,
19093,
21967,
1256,
267,
408,
267,
291,
14,
498,
275,
790,
267,
291,
14,
1003,
275,
18831,
339,
347,
1900,
63,
9231,
8,
277,
12,
18831,
8772,
15760,
628,
17499,
63,
3933,
63,
19279,
2349,
267,
408,
267,
520,
635,
18831,
26,
4205,
5477,
267,
520,
635,
15760,
26,
10830,
5563,
267,
520,
1107,
26,
437,
29683,
1256,
267,
408,
267,
6211,
12,
5821,
12,
286,
632,
275,
15760,
14,
1294,
11008,
531,
398,
340,
440,
18831,
26,
288,
340,
291,
14,
1003,
26,
355,
18831,
275,
291,
14,
1003,
288,
587,
26,
355,
18831,
275,
9571,
14,
1222,
1252,
739,
8,
14494,
14,
1457,
63,
890,
9,
267,
587,
26,
288,
702,
822,
8,
1003,
9,
508,
19093,
14,
1457,
63,
890,
398,
340,
5821,
440,
315,
2097,
3933,
401,
298,
5756,
401,
298,
3912,
6229,
288,
746,
2186,
480,
12647,
790,
2582,
531,
267,
862,
26,
288,
702,
822,
8,
277,
14,
498,
9,
508,
1109,
8,
5609,
9,
4331,
650,
267,
871,
9070,
26,
288,
746,
2186,
480,
14858,
2606,
2582,
531,
398,
862,
26,
288,
372,
19093,
14,
1222,
8,
277,
14,
498,
12,
8761,
5192,
63,
6963,
59,
67,
632,
467,
18831,
395,
18831,
267,
871,
4067,
26,
288,
746,
2186,
480,
12647,
6036,
316,
818,
531,
2378,
347,
14645,
8,
277,
12,
1499,
12,
18831,
29,
403,
12,
15760,
628,
17499,
63,
3933,
63,
19279,
401,
6273,
628,
29247,
3,
23,
401,
355,
330,
772,
10945,
29,
549,
12,
1853,
63,
890,
29,
8475,
63,
4305,
304,
267,
408,
267,
520,
635,
790,
26,
710,
14396,
790,
267,
520,
635,
18831,
26,
4205,
5477,
267,
520,
635,
1499,
26,
6430,
370,
506,
14862,
267,
520,
635,
6273,
26,
26058,
6273,
626,
1077,
506,
1202,
267,
520,
635,
330,
772,
10945,
26,
7480,
314,
754,
1077,
506,
1300,
772,
8167,
267,
520,
635,
1853,
63,
890,
26,
982,
32040,
3,
23,
6273,
1314,
1853,
1568,
370,
675,
267,
520,
1107,
26,
710,
14862,
1245,
267,
408,
398,
340,
6273,
508,
298,
29247,
3,
23,
582,
288,
485,
1457,
63,
890,
275,
1853,
63,
890,
267,
916,
6273,
508,
298,
29247,
3,
21,
582,
288,
485,
1457,
63,
890,
275,
1695,
267,
587,
26,
288,
485,
1457,
63,
890,
275,
378,
398,
340,
485,
1457,
63,
890,
26,
288,
299,
552,
275,
485,
1457,
63,
890,
446,
334,
552,
8,
1328,
9,
450,
485,
1457,
63,
890,
9,
288,
286,
275,
8678,
8,
80,
552,
9,
288,
1499,
847,
286,
10,
80,
552,
398,
10830,
12,
18831,
275,
291,
14,
1506,
63,
9231,
8,
1003,
12,
15760,
9,
267,
286,
1328,
275,
18831,
435,
10830,
14,
11929,
8,
1328,
9,
267,
340,
330,
772,
10945,
26,
288,
372,
330,
772,
2143,
8,
67,
1328,
9,
267,
587,
26,
288,
372,
286,
1328,
2378,
347,
20090,
8,
277,
12,
1499,
12,
18831,
29,
403,
12,
6273,
628,
29247,
3,
23,
401,
330,
772,
7778,
29,
549,
304,
267,
408,
267,
520,
635,
790,
26,
710,
14396,
790,
267,
520,
635,
18831,
26,
4205,
5477,
267,
520,
635,
1499,
26,
3523,
772,
5737,
1245,
370,
506,
477,
8274,
267,
520,
1107,
26,
710,
477,
8274,
1245,
267,
408,
267,
340,
330,
772,
7778,
26,
288,
666,
275,
330,
772,
2708,
8,
1328,
9,
267,
587,
26,
288,
666,
275,
1499,
398,
485,
1003,
275,
666,
1491,
14494,
14,
1457,
63,
890,
61,
267,
340,
18831,
26,
288,
702,
18831,
508,
485,
1003,
267,
10830,
12,
18831,
275,
291,
14,
1506,
63,
9231,
8,
1003,
9,
267,
522,
275,
10830,
14,
15682,
8,
576,
2788,
14494,
14,
1457,
63,
890,
2938,
267,
340,
6273,
315,
2097,
29247,
3,
21,
401,
298,
29247,
3,
23,
6229,
288,
522,
275,
522,
4439,
2181,
8,
470,
1988,
17,
12457,
267,
372,
522,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
790,
63,
275,
298,
4321,
2528,
9908,
4321,
16981,
2,
221,
327,
3193,
3696,
790,
272,
327,
473,
556,
21824,
12,
314,
1245,
3181,
1133,
1172,
370,
506,
3663,
402,
3193,
315,
2582,
272,
1499,
63,
275,
298,
1378,
3655,
2844,
1763,
1378,
1235,
644,
14,
51,
2122,
272,
282,
397,
275,
19093,
21967,
8,
498,
4602,
272,
18831,
63,
275,
747,
14,
22776,
8,
975,
9,
272,
14862,
63,
1328,
275,
282,
397,
14,
11929,
8,
498,
3131,
1499,
3131,
18831,
4602,
272,
9444,
275,
282,
397,
14,
15682,
8,
498,
3131,
14862,
63,
1328,
12,
18831,
4602,
272,
702,
9444,
508,
1499,
63,
339,
14862,
63,
1328,
275,
282,
397,
14,
11929,
8,
498,
3131,
1499,
3131,
378,
9,
272,
9444,
275,
282,
397,
14,
15682,
8,
498,
3131,
14862,
63,
1328,
12,
378,
9,
272,
702,
9444,
508,
1499,
63,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
646,
747,
199,
504,
18855,
492,
9571,
199,
504,
18855,
14,
21967,
492,
19093,
199,
504,
1300,
772,
492,
330,
772,
2143,
12,
330,
772,
2708,
199,
199,
363,
2502,
363,
275,
283,
8459,
460,
72,
7,
199,
199,
4030,
5192,
63,
6963,
275,
469,
272,
298,
19279,
582,
19093,
14,
6963,
63,
18255,
12,
272,
298,
24298,
582,
19093,
14,
6963,
63,
5487,
34,
12,
272,
298,
25467,
582,
19093,
14,
6963,
63,
5487,
34,
12,
199,
93,
199,
199,
8475,
63,
4305,
275,
3193,
421,
199,
533,
19093,
21967,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
790,
12,
18831,
17364,
267,
408,
398,
520,
635,
790,
26,
710,
14396,
790,
267,
520,
635,
18831,
26,
21026,
5477,
267,
520,
1107,
26,
19093,
21967,
1256,
267,
408,
267,
291,
14,
498,
275,
790,
267,
291,
14,
1003,
275,
18831,
339,
347,
1900,
63,
9231,
8,
277,
12,
18831,
8772,
15760,
628,
17499,
63,
3933,
63,
19279,
2349,
267,
408,
267,
520,
635,
18831,
26,
4205,
5477,
267,
520,
635,
15760,
26,
10830,
5563,
267,
520,
1107,
26,
437,
29683,
1256,
267,
408,
267,
6211,
12,
5821,
12,
286,
632,
275,
15760,
14,
1294,
11008,
531,
398,
340,
440,
18831,
26,
288,
340,
291,
14,
1003,
26,
355,
18831,
275,
291,
14,
1003,
288,
587,
26,
355,
18831,
275,
9571,
14,
1222,
1252,
739,
8,
14494,
14,
1457,
63,
890,
9,
267,
587,
26,
288,
702,
822,
8,
1003,
9,
508,
19093,
14,
1457,
63,
890,
398,
340,
5821,
440,
315,
2097,
3933,
401,
298,
5756,
401,
298,
3912,
6229,
288,
746,
2186,
480,
12647,
790,
2582,
531,
267,
862,
26,
288,
702,
822,
8,
277,
14,
498,
9,
508,
1109,
8,
5609,
9,
4331,
650,
267,
871,
9070,
26,
288,
746,
2186,
480,
14858,
2606,
2582,
531,
398,
862,
26,
288,
372,
19093,
14,
1222,
8,
277,
14,
498,
12,
8761,
5192,
63,
6963,
59,
67,
632,
467,
18831,
395,
18831,
267,
871,
4067,
26,
288,
746,
2186,
480,
12647,
6036,
316,
818,
531,
2378,
347,
14645,
8,
277,
12,
1499,
12,
18831,
29,
403,
12,
15760,
628,
17499,
63,
3933,
63,
19279,
401,
6273,
628,
29247,
3,
23,
401,
355,
330,
772,
10945,
29,
549,
12,
1853,
63,
890,
29,
8475,
63,
4305,
304,
267,
408,
267,
520,
635,
790,
26,
710,
14396,
790,
267,
520,
635,
18831,
26,
4205,
5477,
267,
520,
635,
1499,
26,
6430,
370,
506,
14862,
267,
520,
635,
6273,
26,
26058,
6273,
626,
1077,
506,
1202,
267,
520,
635,
330,
772,
10945,
26,
7480,
314,
754,
1077,
506,
1300,
772,
8167,
267,
520,
635,
1853,
63,
890,
26,
982,
32040,
3,
23,
6273,
1314,
1853,
1568,
370,
675,
267,
520,
1107,
26,
710,
14862,
1245,
267,
408,
398,
340,
6273,
508,
298,
29247,
3,
23,
582,
288,
485,
1457,
63,
890,
275,
1853,
63,
890,
267,
916,
6273,
508,
298,
29247,
3,
21,
582,
288,
485,
1457,
63,
890,
275,
1695,
267,
587,
26,
288,
485,
1457,
63,
890,
275,
378,
398,
340,
485,
1457,
63,
890,
26,
288,
299,
552,
275,
485,
1457,
63,
890,
446,
334,
552,
8,
1328,
9,
450,
485,
1457,
63,
890,
9,
288,
286,
275,
8678,
8,
80,
552,
9,
288,
1499,
847,
286,
10,
80,
552,
398,
10830,
12,
18831,
275,
291,
14,
1506,
63,
9231,
8,
1003,
12,
15760,
9,
267,
286,
1328,
275,
18831,
435,
10830,
14,
11929,
8,
1328,
9,
267,
340,
330,
772,
10945,
26,
288,
372,
330,
772,
2143,
8,
67,
1328,
9,
267,
587,
26,
288,
372,
286,
1328,
2378,
347,
20090,
8,
277,
12,
1499,
12,
18831,
29,
403,
12,
6273,
628,
29247,
3,
23,
401,
330,
772,
7778,
29,
549,
304,
267,
408,
267,
520,
635,
790,
26,
710,
14396,
790,
267,
520,
635,
18831,
26,
4205,
5477,
267,
520,
635,
1499,
26,
3523,
772,
5737,
1245,
370,
506,
477,
8274,
267,
520,
1107,
26,
710,
477,
8274,
1245,
267,
408,
267,
340,
330,
772,
7778,
26,
288,
666,
275,
330,
772,
2708,
8,
1328,
9,
267,
587,
26,
288,
666,
275,
1499,
398,
485,
1003,
275,
666,
1491,
14494,
14,
1457,
63,
890,
61,
267,
340,
18831,
26,
288,
702,
18831,
508,
485,
1003,
267,
10830,
12,
18831,
275,
291,
14,
1506,
63,
9231,
8,
1003,
9,
267,
522,
275,
10830,
14,
15682,
8,
576,
2788,
14494,
14,
1457,
63,
890,
2938,
267,
340,
6273,
315,
2097,
29247,
3,
21,
401,
298,
29247,
3,
23,
6229,
288,
522,
275,
522,
4439,
2181,
8,
470,
1988,
17,
12457,
267,
372,
522,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
790,
63,
275,
298,
4321,
2528,
9908,
4321,
16981,
2,
221,
327,
3193,
3696,
790,
272,
327,
473,
556,
21824,
12,
314,
1245,
3181,
1133,
1172,
370,
506,
3663,
402,
3193,
315,
2582,
272,
1499,
63,
275,
298,
1378,
3655,
2844,
1763,
1378,
1235,
644,
14,
51,
2122,
272,
282,
397,
275,
19093,
21967,
8,
498,
4602,
272,
18831,
63,
275,
747,
14,
22776,
8,
975,
9,
272,
14862,
63,
1328,
275,
282,
397,
14,
11929,
8,
498,
3131,
1499,
3131,
18831,
4602,
272,
9444,
275,
282,
397,
14,
15682,
8,
498,
3131,
14862,
63,
1328,
12,
18831,
4602,
272,
702,
9444,
508,
1499,
63,
339,
14862,
63,
1328,
275,
282,
397,
14,
11929,
8,
498,
3131,
1499,
3131,
378,
9,
272,
9444,
275,
282,
397,
14,
15682,
8,
498,
3131,
14862,
63,
1328,
12,
378,
9,
272,
702,
9444,
508,
1499,
63,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
ondras/TeaJS
|
deps/v8/third_party/icu/source/test/depstest/depstest.py
|
14
|
6906
|
#! /usr/bin/python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2011, International Business Machines
# Corporation and others. All Rights Reserved.
#
# file name: depstest.py
#
# created on: 2011may24
"""ICU dependency tester.
This probably works only on Linux.
The exit code is 0 if everything is fine, 1 for errors, 2 for only warnings.
Sample invocation:
~/svn.icu/trunk/src/source/test/depstest$ ./depstest.py ~/svn.icu/trunk/dbg
"""
__author__ = "Markus W. Scherer"
import glob
import os.path
import subprocess
import sys
import dependencies
_ignored_symbols = set()
_obj_files = {}
_symbols_to_files = {}
_return_value = 0
# Classes with vtables (and thus virtual methods).
_virtual_classes = set()
# Classes with weakly defined destructors.
# nm shows a symbol class of "W" rather than "T".
_weak_destructors = set()
def _ReadObjFile(root_path, library_name, obj_name):
global _ignored_symbols, _obj_files, _symbols_to_files
global _virtual_classes, _weak_destructors
lib_obj_name = library_name + "/" + obj_name
if lib_obj_name in _obj_files:
print "Warning: duplicate .o file " + lib_obj_name
_return_value = 2
return
path = os.path.join(root_path, library_name, obj_name)
nm_result = subprocess.Popen(["nm", "--demangle", "--format=sysv",
"--extern-only", "--no-sort", path],
stdout=subprocess.PIPE).communicate()[0]
obj_imports = set()
obj_exports = set()
for line in nm_result.splitlines():
fields = line.split("|")
if len(fields) == 1: continue
name = fields[0].strip()
# Ignore symbols like '__cxa_pure_virtual',
# 'vtable for __cxxabiv1::__si_class_type_info' or
# 'DW.ref.__gxx_personality_v0'.
if name.startswith("__cxa") or "__cxxabi" in name or "__gxx" in name:
_ignored_symbols.add(name)
continue
type = fields[2].strip()
if type == "U":
obj_imports.add(name)
else:
obj_exports.add(name)
_symbols_to_files[name] = lib_obj_name
# Is this a vtable? E.g., "vtable for icu_49::ByteSink".
if name.startswith("vtable for icu"):
_virtual_classes.add(name[name.index("::") + 2:])
# Is this a destructor? E.g., "icu_49::ByteSink::~ByteSink()".
index = name.find("::~")
if index >= 0 and type == "W":
_weak_destructors.add(name[index + 3:name.index("(", index)])
_obj_files[lib_obj_name] = {"imports": obj_imports, "exports": obj_exports}
def _ReadLibrary(root_path, library_name):
obj_paths = glob.glob(os.path.join(root_path, library_name, "*.o"))
for path in obj_paths:
_ReadObjFile(root_path, library_name, os.path.basename(path))
def _Resolve(name, parents):
global _ignored_symbols, _obj_files, _symbols_to_files, _return_value
item = dependencies.items[name]
item_type = item["type"]
if name in parents:
sys.exit("Error: %s %s has a circular dependency on itself: %s" %
(item_type, name, parents))
# Check if already cached.
exports = item.get("exports")
if exports != None: return item
# Calculcate recursively.
parents.append(name)
imports = set()
exports = set()
system_symbols = item.get("system_symbols")
if system_symbols == None: system_symbols = item["system_symbols"] = set()
files = item.get("files")
if files:
for file_name in files:
obj_file = _obj_files[file_name]
imports |= obj_file["imports"]
exports |= obj_file["exports"]
imports -= exports | _ignored_symbols
deps = item.get("deps")
if deps:
for dep in deps:
dep_item = _Resolve(dep, parents)
# Detect whether this item needs to depend on dep,
# except when this item has no files, that is, when it is just
# a deliberate umbrella group or library.
dep_exports = dep_item["exports"]
dep_system_symbols = dep_item["system_symbols"]
if files and imports.isdisjoint(dep_exports) and imports.isdisjoint(dep_system_symbols):
print "Info: %s %s does not need to depend on %s\n" % (item_type, name, dep)
# We always include the dependency's exports, even if we do not need them
# to satisfy local imports.
exports |= dep_exports
system_symbols |= dep_system_symbols
item["exports"] = exports
item["system_symbols"] = system_symbols
imports -= exports | system_symbols
for symbol in imports:
for file_name in files:
if symbol in _obj_files[file_name]["imports"]:
sys.stderr.write("Error: %s %s file %s imports %s but %s does not depend on %s\n" %
(item_type, name, file_name, symbol, name, _symbols_to_files.get(symbol)))
_return_value = 1
del parents[-1]
return item
def Process(root_path):
"""Loads dependencies.txt, reads the libraries' .o files, and processes them.
Modifies dependencies.items: Recursively builds each item's system_symbols and exports.
"""
global _ignored_symbols, _obj_files, _return_value
global _virtual_classes, _weak_destructors
dependencies.Load()
for name_and_item in dependencies.items.iteritems():
name = name_and_item[0]
item = name_and_item[1]
system_symbols = item.get("system_symbols")
if system_symbols:
for symbol in system_symbols:
_symbols_to_files[symbol] = name
for library_name in dependencies.libraries:
_ReadLibrary(root_path, library_name)
o_files_set = set(_obj_files.keys())
files_missing_from_deps = o_files_set - dependencies.files
files_missing_from_build = dependencies.files - o_files_set
if files_missing_from_deps:
sys.stderr.write("Error: files missing from dependencies.txt:\n%s\n" %
sorted(files_missing_from_deps))
_return_value = 1
if files_missing_from_build:
sys.stderr.write("Error: files in dependencies.txt but not built:\n%s\n" %
sorted(files_missing_from_build))
_return_value = 1
if not _return_value:
for library_name in dependencies.libraries:
_Resolve(library_name, [])
if not _return_value:
virtual_classes_with_weak_destructors = _virtual_classes & _weak_destructors
if virtual_classes_with_weak_destructors:
sys.stderr.write("Error: Some classes have virtual methods, and "
"an implicit or inline destructor "
"(see ICU ticket #8454 for details):\n%s\n" %
sorted(virtual_classes_with_weak_destructors))
_return_value = 1
def main():
global _return_value
if len(sys.argv) <= 1:
sys.exit(("Command line error: " +
"need one argument with the root path to the built ICU libraries/*.o files."))
Process(sys.argv[1])
if _ignored_symbols:
print "Info: ignored symbols:\n%s" % sorted(_ignored_symbols)
if not _return_value:
print "OK: Specified and actual dependencies match."
return _return_value
if __name__ == "__main__":
sys.exit(main())
|
bsd-3-clause
|
[
3168,
1182,
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
334,
35,
9,
7760,
12,
28220,
23813,
30611,
3746,
199,
3,
11098,
436,
11789,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
570,
536,
26,
10140,
396,
14,
647,
199,
3,
199,
3,
2737,
641,
26,
7760,
7551,
1194,
199,
199,
624,
948,
53,
5936,
17570,
14,
199,
199,
2765,
8646,
5419,
1454,
641,
10130,
14,
199,
199,
1918,
4458,
1233,
365,
378,
340,
8137,
365,
15701,
12,
413,
367,
2552,
12,
499,
367,
1454,
3598,
14,
199,
199,
8176,
19569,
26,
523,
6146,
15,
6836,
14,
530,
85,
15,
13409,
15,
2164,
15,
1365,
15,
396,
15,
5846,
396,
4,
16605,
5846,
396,
14,
647,
6146,
15,
6836,
14,
530,
85,
15,
13409,
15,
16310,
199,
624,
199,
199,
363,
2502,
363,
275,
298,
6470,
527,
644,
14,
428,
595,
3859,
2,
199,
199,
646,
5739,
199,
646,
747,
14,
515,
199,
646,
3873,
199,
646,
984,
199,
199,
646,
5124,
199,
199,
63,
11996,
63,
7450,
275,
663,
342,
199,
63,
1113,
63,
1725,
275,
1052,
199,
63,
7450,
63,
475,
63,
1725,
275,
1052,
199,
63,
1107,
63,
585,
275,
378,
199,
199,
3,
27939,
543,
373,
5987,
334,
460,
12850,
5791,
3102,
680,
199,
63,
2065,
63,
2888,
275,
663,
342,
199,
3,
27939,
543,
9282,
590,
3247,
32133,
83,
14,
199,
3,
16751,
13703,
282,
5272,
1021,
402,
298,
55,
2,
7830,
2419,
298,
52,
1674,
199,
63,
10350,
63,
271,
1426,
83,
275,
663,
342,
199,
199,
318,
485,
3284,
5665,
1173,
8,
1231,
63,
515,
12,
3555,
63,
354,
12,
1559,
63,
354,
304,
523,
2288,
485,
11996,
63,
7450,
12,
485,
1113,
63,
1725,
12,
485,
7450,
63,
475,
63,
1725,
523,
2288,
485,
2065,
63,
2888,
12,
485,
10350,
63,
271,
1426,
83,
523,
1973,
63,
1113,
63,
354,
275,
3555,
63,
354,
435,
10609,
435,
1559,
63,
354,
523,
340,
1973,
63,
1113,
63,
354,
315,
485,
1113,
63,
1725,
26,
272,
870,
298,
3849,
26,
9250,
1275,
79,
570,
298,
435,
1973,
63,
1113,
63,
354,
272,
485,
1107,
63,
585,
275,
499,
272,
372,
819,
931,
275,
747,
14,
515,
14,
904,
8,
1231,
63,
515,
12,
3555,
63,
354,
12,
1559,
63,
354,
9,
523,
16751,
63,
1099,
275,
3873,
14,
7942,
5234,
10756,
401,
4320,
23522,
4593,
401,
4320,
908,
29,
1274,
86,
401,
1816,
4320,
18587,
13,
2118,
401,
4320,
889,
13,
3191,
401,
931,
467,
3044,
3839,
29,
5781,
14,
6089,
680,
10664,
3430,
16,
61,
523,
1559,
63,
12775,
275,
663,
342,
523,
1559,
63,
20775,
275,
663,
342,
523,
367,
1004,
315,
16751,
63,
1099,
14,
7644,
837,
272,
1504,
275,
1004,
14,
1294,
25795,
531,
272,
340,
822,
8,
955,
9,
508,
413,
26,
1980,
272,
536,
275,
1504,
59,
16,
1055,
1913,
342,
272,
327,
14092,
6698,
2839,
2560,
67,
1800,
63,
5115,
63,
2065,
297,
272,
327,
283,
86,
1224,
367,
636,
9634,
371,
1003,
17,
20904,
338,
63,
533,
63,
466,
63,
815,
7,
503,
272,
327,
283,
19438,
14,
1121,
855,
71,
2154,
63,
5484,
6712,
63,
86,
16,
1370,
272,
340,
536,
14,
2460,
16232,
67,
1800,
531,
503,
4396,
9634,
14677,
2,
315,
536,
503,
4396,
71,
2154,
2,
315,
536,
26,
489,
485,
11996,
63,
7450,
14,
525,
8,
354,
9,
489,
1980,
272,
730,
275,
1504,
59,
18,
1055,
1913,
342,
272,
340,
730,
508,
298,
53,
582,
489,
1559,
63,
12775,
14,
525,
8,
354,
9,
272,
587,
26,
489,
1559,
63,
20775,
14,
525,
8,
354,
9,
489,
485,
7450,
63,
475,
63,
1725,
59,
354,
61,
275,
1973,
63,
1113,
63,
354,
489,
327,
6596,
642,
282,
373,
1224,
31,
662,
14,
71,
2020,
298,
86,
1224,
367,
284,
15140,
63,
1887,
447,
4861,
17111,
1674,
489,
340,
536,
14,
2460,
480,
86,
1224,
367,
284,
15140,
2349,
267,
485,
2065,
63,
2888,
14,
525,
8,
354,
59,
354,
14,
1080,
480,
447,
531,
435,
499,
5728,
489,
327,
6596,
642,
282,
32133,
31,
662,
14,
71,
2020,
298,
530,
85,
63,
1887,
447,
4861,
17111,
447,
94,
4861,
17111,
342,
1674,
489,
1478,
275,
536,
14,
1623,
480,
447,
94,
531,
489,
340,
1478,
2356,
378,
436,
730,
508,
298,
55,
582,
267,
485,
10350,
63,
271,
1426,
83,
14,
525,
8,
354,
59,
1080,
435,
650,
26,
354,
14,
1080,
480,
11854,
1478,
3948,
523,
485,
1113,
63,
1725,
59,
773,
63,
1113,
63,
354,
61,
275,
2420,
12775,
582,
1559,
63,
12775,
12,
298,
20775,
582,
1559,
63,
20775,
93,
199,
199,
318,
485,
3284,
7424,
8,
1231,
63,
515,
12,
3555,
63,
354,
304,
523,
1559,
63,
3771,
275,
5739,
14,
6463,
8,
736,
14,
515,
14,
904,
8,
1231,
63,
515,
12,
3555,
63,
354,
12,
298,
4856,
79,
2237,
523,
367,
931,
315,
1559,
63,
3771,
26,
272,
485,
3284,
5665,
1173,
8,
1231,
63,
515,
12,
3555,
63,
354,
12,
747,
14,
515,
14,
4846,
8,
515,
430,
199,
199,
318,
485,
27459,
8,
354,
12,
8623,
304,
523,
2288,
485,
11996,
63,
7450,
12,
485,
1113,
63,
1725,
12,
485,
7450,
63,
475,
63,
1725,
12,
485,
1107,
63,
585,
523,
1242,
275,
5124,
14,
1744,
59,
354,
61,
523,
1242,
63,
466,
275,
1242,
905,
466,
937,
523,
340,
536,
315,
8623,
26,
272,
984,
14,
2224,
480,
547,
26,
450,
83,
450,
83,
965,
282,
15032,
5936,
641,
6337,
26,
450,
83,
2,
450,
1467,
334,
1053,
63,
466,
12,
536,
12,
8623,
430,
523,
327,
2670,
340,
2575,
6328,
14,
523,
22609,
275,
1242,
14,
362,
480,
20775,
531,
523,
340,
22609,
1137,
488,
26,
372,
1242,
523,
327,
19821,
1411,
15035,
14,
523,
8623,
14,
740,
8,
354,
9,
523,
8925,
275,
663,
342,
523,
22609,
275,
663,
342,
523,
2656,
63,
7450,
275,
1242,
14,
362,
480,
2253,
63,
7450,
531,
523,
340,
2656,
63,
7450,
508,
488,
26,
2656,
63,
7450,
275,
1242,
905,
2253,
63,
7450,
937,
275,
663,
342,
523,
1584,
275,
1242,
14,
362,
480
] |
[
1182,
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
334,
35,
9,
7760,
12,
28220,
23813,
30611,
3746,
199,
3,
11098,
436,
11789,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
570,
536,
26,
10140,
396,
14,
647,
199,
3,
199,
3,
2737,
641,
26,
7760,
7551,
1194,
199,
199,
624,
948,
53,
5936,
17570,
14,
199,
199,
2765,
8646,
5419,
1454,
641,
10130,
14,
199,
199,
1918,
4458,
1233,
365,
378,
340,
8137,
365,
15701,
12,
413,
367,
2552,
12,
499,
367,
1454,
3598,
14,
199,
199,
8176,
19569,
26,
523,
6146,
15,
6836,
14,
530,
85,
15,
13409,
15,
2164,
15,
1365,
15,
396,
15,
5846,
396,
4,
16605,
5846,
396,
14,
647,
6146,
15,
6836,
14,
530,
85,
15,
13409,
15,
16310,
199,
624,
199,
199,
363,
2502,
363,
275,
298,
6470,
527,
644,
14,
428,
595,
3859,
2,
199,
199,
646,
5739,
199,
646,
747,
14,
515,
199,
646,
3873,
199,
646,
984,
199,
199,
646,
5124,
199,
199,
63,
11996,
63,
7450,
275,
663,
342,
199,
63,
1113,
63,
1725,
275,
1052,
199,
63,
7450,
63,
475,
63,
1725,
275,
1052,
199,
63,
1107,
63,
585,
275,
378,
199,
199,
3,
27939,
543,
373,
5987,
334,
460,
12850,
5791,
3102,
680,
199,
63,
2065,
63,
2888,
275,
663,
342,
199,
3,
27939,
543,
9282,
590,
3247,
32133,
83,
14,
199,
3,
16751,
13703,
282,
5272,
1021,
402,
298,
55,
2,
7830,
2419,
298,
52,
1674,
199,
63,
10350,
63,
271,
1426,
83,
275,
663,
342,
199,
199,
318,
485,
3284,
5665,
1173,
8,
1231,
63,
515,
12,
3555,
63,
354,
12,
1559,
63,
354,
304,
523,
2288,
485,
11996,
63,
7450,
12,
485,
1113,
63,
1725,
12,
485,
7450,
63,
475,
63,
1725,
523,
2288,
485,
2065,
63,
2888,
12,
485,
10350,
63,
271,
1426,
83,
523,
1973,
63,
1113,
63,
354,
275,
3555,
63,
354,
435,
10609,
435,
1559,
63,
354,
523,
340,
1973,
63,
1113,
63,
354,
315,
485,
1113,
63,
1725,
26,
272,
870,
298,
3849,
26,
9250,
1275,
79,
570,
298,
435,
1973,
63,
1113,
63,
354,
272,
485,
1107,
63,
585,
275,
499,
272,
372,
819,
931,
275,
747,
14,
515,
14,
904,
8,
1231,
63,
515,
12,
3555,
63,
354,
12,
1559,
63,
354,
9,
523,
16751,
63,
1099,
275,
3873,
14,
7942,
5234,
10756,
401,
4320,
23522,
4593,
401,
4320,
908,
29,
1274,
86,
401,
1816,
4320,
18587,
13,
2118,
401,
4320,
889,
13,
3191,
401,
931,
467,
3044,
3839,
29,
5781,
14,
6089,
680,
10664,
3430,
16,
61,
523,
1559,
63,
12775,
275,
663,
342,
523,
1559,
63,
20775,
275,
663,
342,
523,
367,
1004,
315,
16751,
63,
1099,
14,
7644,
837,
272,
1504,
275,
1004,
14,
1294,
25795,
531,
272,
340,
822,
8,
955,
9,
508,
413,
26,
1980,
272,
536,
275,
1504,
59,
16,
1055,
1913,
342,
272,
327,
14092,
6698,
2839,
2560,
67,
1800,
63,
5115,
63,
2065,
297,
272,
327,
283,
86,
1224,
367,
636,
9634,
371,
1003,
17,
20904,
338,
63,
533,
63,
466,
63,
815,
7,
503,
272,
327,
283,
19438,
14,
1121,
855,
71,
2154,
63,
5484,
6712,
63,
86,
16,
1370,
272,
340,
536,
14,
2460,
16232,
67,
1800,
531,
503,
4396,
9634,
14677,
2,
315,
536,
503,
4396,
71,
2154,
2,
315,
536,
26,
489,
485,
11996,
63,
7450,
14,
525,
8,
354,
9,
489,
1980,
272,
730,
275,
1504,
59,
18,
1055,
1913,
342,
272,
340,
730,
508,
298,
53,
582,
489,
1559,
63,
12775,
14,
525,
8,
354,
9,
272,
587,
26,
489,
1559,
63,
20775,
14,
525,
8,
354,
9,
489,
485,
7450,
63,
475,
63,
1725,
59,
354,
61,
275,
1973,
63,
1113,
63,
354,
489,
327,
6596,
642,
282,
373,
1224,
31,
662,
14,
71,
2020,
298,
86,
1224,
367,
284,
15140,
63,
1887,
447,
4861,
17111,
1674,
489,
340,
536,
14,
2460,
480,
86,
1224,
367,
284,
15140,
2349,
267,
485,
2065,
63,
2888,
14,
525,
8,
354,
59,
354,
14,
1080,
480,
447,
531,
435,
499,
5728,
489,
327,
6596,
642,
282,
32133,
31,
662,
14,
71,
2020,
298,
530,
85,
63,
1887,
447,
4861,
17111,
447,
94,
4861,
17111,
342,
1674,
489,
1478,
275,
536,
14,
1623,
480,
447,
94,
531,
489,
340,
1478,
2356,
378,
436,
730,
508,
298,
55,
582,
267,
485,
10350,
63,
271,
1426,
83,
14,
525,
8,
354,
59,
1080,
435,
650,
26,
354,
14,
1080,
480,
11854,
1478,
3948,
523,
485,
1113,
63,
1725,
59,
773,
63,
1113,
63,
354,
61,
275,
2420,
12775,
582,
1559,
63,
12775,
12,
298,
20775,
582,
1559,
63,
20775,
93,
199,
199,
318,
485,
3284,
7424,
8,
1231,
63,
515,
12,
3555,
63,
354,
304,
523,
1559,
63,
3771,
275,
5739,
14,
6463,
8,
736,
14,
515,
14,
904,
8,
1231,
63,
515,
12,
3555,
63,
354,
12,
298,
4856,
79,
2237,
523,
367,
931,
315,
1559,
63,
3771,
26,
272,
485,
3284,
5665,
1173,
8,
1231,
63,
515,
12,
3555,
63,
354,
12,
747,
14,
515,
14,
4846,
8,
515,
430,
199,
199,
318,
485,
27459,
8,
354,
12,
8623,
304,
523,
2288,
485,
11996,
63,
7450,
12,
485,
1113,
63,
1725,
12,
485,
7450,
63,
475,
63,
1725,
12,
485,
1107,
63,
585,
523,
1242,
275,
5124,
14,
1744,
59,
354,
61,
523,
1242,
63,
466,
275,
1242,
905,
466,
937,
523,
340,
536,
315,
8623,
26,
272,
984,
14,
2224,
480,
547,
26,
450,
83,
450,
83,
965,
282,
15032,
5936,
641,
6337,
26,
450,
83,
2,
450,
1467,
334,
1053,
63,
466,
12,
536,
12,
8623,
430,
523,
327,
2670,
340,
2575,
6328,
14,
523,
22609,
275,
1242,
14,
362,
480,
20775,
531,
523,
340,
22609,
1137,
488,
26,
372,
1242,
523,
327,
19821,
1411,
15035,
14,
523,
8623,
14,
740,
8,
354,
9,
523,
8925,
275,
663,
342,
523,
22609,
275,
663,
342,
523,
2656,
63,
7450,
275,
1242,
14,
362,
480,
2253,
63,
7450,
531,
523,
340,
2656,
63,
7450,
508,
488,
26,
2656,
63,
7450,
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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
] |
Vegasvikk/django-cms
|
cms/utils/django_load.py
|
25
|
3794
|
# -*- coding: utf-8 -*-
"""
This is revision from 3058ab9d9d4875589638cc45e84b59e7e1d7c9c3 of
https://github.com/ojii/django-load.
ANY changes to this file, be it upstream fixes or changes for the cms *must* be
documented clearly within this file with comments.
For documentation on how to use the functions described in this file, please
refer to http://django-load.readthedocs.org/en/latest/index.html.
"""
import imp
import traceback # changed
from django.utils.importlib import import_module
from django.utils.six.moves import filter, map
from .compat.dj import installed_apps
def get_module(app, modname, verbose, failfast):
"""
Internal function to load a module from a single app.
"""
module_name = '%s.%s' % (app, modname)
# the module *should* exist - raise an error if it doesn't
app_mod = import_module(app)
try:
imp.find_module(modname, app_mod.__path__ if hasattr(app_mod, '__path__') else None)
except ImportError:
# this ImportError will be due to the module not existing
# so here we can silently ignore it. But an ImportError
# when we import_module() should not be ignored
if failfast:
raise
elif verbose:
print(u"Could not find %r from %r" % (modname, app)) # changed
traceback.print_exc() # changed
return None
module = import_module(module_name)
if verbose:
print(u"Loaded %r from %r" % (modname, app))
return module
def load(modname, verbose=False, failfast=False):
"""
Loads all modules with name 'modname' from all installed apps.
If verbose is True, debug information will be printed to stdout.
If failfast is True, import errors will not be surpressed.
"""
for app in installed_apps():
get_module(app, modname, verbose, failfast)
def iterload(modname, verbose=False, failfast=False):
"""
Loads all modules with name 'modname' from all installed apps and returns
and iterator of those modules.
If verbose is True, debug information will be printed to stdout.
If failfast is True, import errors will not be surpressed.
"""
return filter(None, (get_module(app, modname, verbose, failfast)
for app in installed_apps()))
def load_object(import_path):
"""
Loads an object from an 'import_path', like in MIDDLEWARE_CLASSES and the
likes.
Import paths should be: "mypackage.mymodule.MyObject". It then imports the
module up until the last dot and tries to get the attribute after that dot
from the imported module.
If the import path does not contain any dots, a TypeError is raised.
If the module cannot be imported, an ImportError is raised.
If the attribute does not exist in the module, a AttributeError is raised.
"""
if '.' not in import_path:
raise TypeError(
"'import_path' argument to 'django_load.core.load_object' must "
"contain at least one dot."
)
module_name, object_name = import_path.rsplit('.', 1)
module = import_module(module_name)
return getattr(module, object_name)
def iterload_objects(import_paths):
"""
Load a list of objects.
"""
return map(load_object, import_paths)
def get_subclasses(c):
"""
Get all subclasses of a given class
"""
return c.__subclasses__() + sum(map(get_subclasses, c.__subclasses__()), [])
def load_from_file(module_path):
"""
Load a python module from its absolute filesystem path
"""
from imp import load_module, PY_SOURCE
imported = None
if module_path:
with open(module_path, 'r') as openfile:
imported = load_module("mod", openfile, module_path, ('imported', 'r', PY_SOURCE))
return imported
|
bsd-3-clause
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
199,
2765,
365,
6974,
687,
650,
18009,
371,
25,
68,
25,
68,
27931,
1229,
12031,
1703,
2055,
2322,
69,
1349,
66,
1427,
69,
23,
69,
17,
68,
23,
67,
25,
67,
19,
402,
199,
2859,
921,
5031,
14,
957,
15,
79,
74,
5908,
15,
1176,
13,
912,
14,
199,
199,
8974,
4493,
370,
642,
570,
12,
506,
652,
18932,
25079,
503,
4493,
367,
314,
19240,
627,
7790,
10,
506,
199,
29383,
5436,
590,
4453,
642,
570,
543,
6786,
14,
199,
199,
1858,
3794,
641,
4212,
370,
675,
314,
3423,
11736,
315,
642,
570,
12,
8749,
199,
21928,
370,
1455,
921,
1176,
13,
912,
14,
25085,
14,
1308,
15,
287,
15,
7410,
15,
1080,
14,
1360,
14,
199,
624,
199,
646,
1742,
199,
646,
5190,
327,
2896,
199,
199,
504,
1639,
14,
1208,
14,
25893,
492,
492,
63,
578,
199,
504,
1639,
14,
1208,
14,
4174,
14,
4912,
492,
2457,
12,
2341,
199,
199,
504,
1275,
5819,
14,
18256,
492,
4903,
63,
5181,
421,
199,
318,
664,
63,
578,
8,
571,
12,
13526,
12,
3376,
12,
1433,
20803,
304,
272,
408,
272,
12624,
805,
370,
2248,
282,
859,
687,
282,
2849,
1145,
14,
272,
408,
272,
859,
63,
354,
275,
1543,
83,
4111,
83,
7,
450,
334,
571,
12,
13526,
9,
272,
327,
314,
859,
627,
5626,
10,
2187,
446,
746,
376,
1125,
340,
652,
3181,
1133,
272,
1145,
63,
1494,
275,
492,
63,
578,
8,
571,
9,
272,
862,
26,
267,
1742,
14,
1623,
63,
578,
8,
14789,
12,
1145,
63,
1494,
855,
515,
363,
340,
2688,
8,
571,
63,
1494,
12,
2560,
515,
13766,
587,
488,
9,
272,
871,
3545,
26,
267,
327,
642,
3545,
911,
506,
7037,
370,
314,
859,
440,
3411,
267,
327,
880,
2348,
781,
883,
18030,
3686,
652,
14,
221,
11017,
376,
3545,
267,
327,
1380,
781,
492,
63,
578,
342,
1077,
440,
506,
5525,
267,
340,
1433,
20803,
26,
288,
746,
267,
916,
3376,
26,
288,
870,
8,
85,
2,
6531,
440,
2342,
450,
82,
687,
450,
82,
2,
450,
334,
14789,
12,
1145,
430,
327,
2896,
288,
5190,
14,
1361,
63,
2804,
342,
327,
2896,
267,
372,
488,
339,
859,
275,
492,
63,
578,
8,
578,
63,
354,
9,
339,
340,
3376,
26,
267,
870,
8,
85,
2,
19757,
450,
82,
687,
450,
82,
2,
450,
334,
14789,
12,
1145,
430,
272,
372,
859,
421,
199,
318,
2248,
8,
14789,
12,
3376,
29,
797,
12,
1433,
20803,
29,
797,
304,
272,
408,
272,
30367,
1006,
4621,
543,
536,
283,
14789,
7,
687,
1006,
4903,
8686,
14,
339,
982,
3376,
365,
715,
12,
3105,
2556,
911,
506,
12487,
370,
3839,
14,
339,
982,
1433,
20803,
365,
715,
12,
492,
2552,
911,
440,
506,
6296,
30455,
14,
272,
408,
272,
367,
1145,
315,
4903,
63,
5181,
837,
267,
664,
63,
578,
8,
571,
12,
13526,
12,
3376,
12,
1433,
20803,
9,
421,
199,
318,
2740,
912,
8,
14789,
12,
3376,
29,
797,
12,
1433,
20803,
29,
797,
304,
272,
408,
272,
30367,
1006,
4621,
543,
536,
283,
14789,
7,
687,
1006,
4903,
8686,
436,
2529,
272,
436,
6122,
402,
5204,
4621,
14,
339,
982,
3376,
365,
715,
12,
3105,
2556,
911,
506,
12487,
370,
3839,
14,
339,
982,
1433,
20803,
365,
715,
12,
492,
2552,
911,
440,
506,
6296,
30455,
14,
272,
408,
272,
372,
2457,
8,
403,
12,
334,
362,
63,
578,
8,
571,
12,
13526,
12,
3376,
12,
1433,
20803,
9,
586,
367,
1145,
315,
4903,
63,
5181,
4059,
199,
199,
318,
2248,
63,
785,
8,
646,
63,
515,
304,
272,
408,
272,
30367,
376,
909,
687,
376,
283,
646,
63,
515,
297,
2839,
315,
30718,
63,
13748,
436,
314,
272,
1212,
9246,
14,
339,
3161,
3792,
1077,
506,
26,
298,
1662,
2491,
14,
1662,
578,
14,
5713,
1692,
1674,
2779,
2066,
8925,
314,
272,
859,
1536,
5133,
314,
2061,
6308,
436,
11275,
370,
664,
314,
2225,
2410,
626,
6308,
272,
687,
314,
8439,
859,
14,
339,
982,
314,
492,
931,
1630,
440,
1395,
1263,
21185,
12,
282,
3146,
365,
4915,
14,
339,
982,
314,
859,
3913,
506,
8439,
12,
376,
3545,
365,
4915,
14,
339,
982,
314,
2225,
1630,
440,
2187,
315,
314,
859,
12,
282,
4281,
365,
4915,
14,
272,
408,
272,
340,
7815,
440,
315,
492,
63,
515,
26,
267,
746,
3146,
8,
288,
3546,
646,
63,
515,
7,
1423,
370,
283,
1176,
63,
912,
14,
1018,
14,
912,
63,
785,
7,
1471,
298,
288,
298,
7747,
737,
5210,
1373,
6308,
2122,
267,
776,
272,
859,
63,
354,
12,
909,
63,
354,
275,
492,
63,
515,
14,
13490,
14078,
413,
9,
272,
859,
275,
492,
63,
578,
8,
578,
63,
354,
9,
272,
372,
2519,
8,
578,
12,
909,
63,
354,
9,
199,
199,
318,
2740,
912,
63,
1462,
8,
646,
63,
3771,
304,
272,
408,
272,
7190,
282,
769,
402,
2251,
14,
272,
408,
272,
372,
2341,
8,
912,
63,
785,
12,
492,
63,
3771,
9,
199,
199,
318,
664,
63,
19094,
8,
67,
304,
272,
408,
272,
2372,
1006,
9180,
402,
282,
1627,
1021,
272,
408,
272,
372,
286,
855,
19094,
4533,
435,
3089,
8,
1130,
8,
362,
63,
19094,
12,
286,
855,
19094,
363,
4000,
3073,
199,
199,
318,
2248,
63,
504,
63,
493,
8,
578,
63,
515,
304,
272,
408,
272,
7190,
282,
2366,
859,
687,
2399,
3679,
10036,
931,
272,
408,
272,
687,
1742,
492,
2248,
63,
578,
12,
7843,
63,
10187,
339,
8439,
275,
488,
272,
340,
859,
63,
515,
26,
267,
543,
1551,
8,
578,
63,
515,
12,
283,
82,
358,
465,
1551,
493,
26,
288,
8439,
275,
2248,
63,
578,
480,
1494,
401,
1551,
493,
12,
859,
63,
515,
12,
661,
17932,
297,
283,
82,
297,
7843,
63,
10187,
430,
272,
372,
8439,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
199,
2765,
365,
6974,
687,
650,
18009,
371,
25,
68,
25,
68,
27931,
1229,
12031,
1703,
2055,
2322,
69,
1349,
66,
1427,
69,
23,
69,
17,
68,
23,
67,
25,
67,
19,
402,
199,
2859,
921,
5031,
14,
957,
15,
79,
74,
5908,
15,
1176,
13,
912,
14,
199,
199,
8974,
4493,
370,
642,
570,
12,
506,
652,
18932,
25079,
503,
4493,
367,
314,
19240,
627,
7790,
10,
506,
199,
29383,
5436,
590,
4453,
642,
570,
543,
6786,
14,
199,
199,
1858,
3794,
641,
4212,
370,
675,
314,
3423,
11736,
315,
642,
570,
12,
8749,
199,
21928,
370,
1455,
921,
1176,
13,
912,
14,
25085,
14,
1308,
15,
287,
15,
7410,
15,
1080,
14,
1360,
14,
199,
624,
199,
646,
1742,
199,
646,
5190,
327,
2896,
199,
199,
504,
1639,
14,
1208,
14,
25893,
492,
492,
63,
578,
199,
504,
1639,
14,
1208,
14,
4174,
14,
4912,
492,
2457,
12,
2341,
199,
199,
504,
1275,
5819,
14,
18256,
492,
4903,
63,
5181,
421,
199,
318,
664,
63,
578,
8,
571,
12,
13526,
12,
3376,
12,
1433,
20803,
304,
272,
408,
272,
12624,
805,
370,
2248,
282,
859,
687,
282,
2849,
1145,
14,
272,
408,
272,
859,
63,
354,
275,
1543,
83,
4111,
83,
7,
450,
334,
571,
12,
13526,
9,
272,
327,
314,
859,
627,
5626,
10,
2187,
446,
746,
376,
1125,
340,
652,
3181,
1133,
272,
1145,
63,
1494,
275,
492,
63,
578,
8,
571,
9,
272,
862,
26,
267,
1742,
14,
1623,
63,
578,
8,
14789,
12,
1145,
63,
1494,
855,
515,
363,
340,
2688,
8,
571,
63,
1494,
12,
2560,
515,
13766,
587,
488,
9,
272,
871,
3545,
26,
267,
327,
642,
3545,
911,
506,
7037,
370,
314,
859,
440,
3411,
267,
327,
880,
2348,
781,
883,
18030,
3686,
652,
14,
221,
11017,
376,
3545,
267,
327,
1380,
781,
492,
63,
578,
342,
1077,
440,
506,
5525,
267,
340,
1433,
20803,
26,
288,
746,
267,
916,
3376,
26,
288,
870,
8,
85,
2,
6531,
440,
2342,
450,
82,
687,
450,
82,
2,
450,
334,
14789,
12,
1145,
430,
327,
2896,
288,
5190,
14,
1361,
63,
2804,
342,
327,
2896,
267,
372,
488,
339,
859,
275,
492,
63,
578,
8,
578,
63,
354,
9,
339,
340,
3376,
26,
267,
870,
8,
85,
2,
19757,
450,
82,
687,
450,
82,
2,
450,
334,
14789,
12,
1145,
430,
272,
372,
859,
421,
199,
318,
2248,
8,
14789,
12,
3376,
29,
797,
12,
1433,
20803,
29,
797,
304,
272,
408,
272,
30367,
1006,
4621,
543,
536,
283,
14789,
7,
687,
1006,
4903,
8686,
14,
339,
982,
3376,
365,
715,
12,
3105,
2556,
911,
506,
12487,
370,
3839,
14,
339,
982,
1433,
20803,
365,
715,
12,
492,
2552,
911,
440,
506,
6296,
30455,
14,
272,
408,
272,
367,
1145,
315,
4903,
63,
5181,
837,
267,
664,
63,
578,
8,
571,
12,
13526,
12,
3376,
12,
1433,
20803,
9,
421,
199,
318,
2740,
912,
8,
14789,
12,
3376,
29,
797,
12,
1433,
20803,
29,
797,
304,
272,
408,
272,
30367,
1006,
4621,
543,
536,
283,
14789,
7,
687,
1006,
4903,
8686,
436,
2529,
272,
436,
6122,
402,
5204,
4621,
14,
339,
982,
3376,
365,
715,
12,
3105,
2556,
911,
506,
12487,
370,
3839,
14,
339,
982,
1433,
20803,
365,
715,
12,
492,
2552,
911,
440,
506,
6296,
30455,
14,
272,
408,
272,
372,
2457,
8,
403,
12,
334,
362,
63,
578,
8,
571,
12,
13526,
12,
3376,
12,
1433,
20803,
9,
586,
367,
1145,
315,
4903,
63,
5181,
4059,
199,
199,
318,
2248,
63,
785,
8,
646,
63,
515,
304,
272,
408,
272,
30367,
376,
909,
687,
376,
283,
646,
63,
515,
297,
2839,
315,
30718,
63,
13748,
436,
314,
272,
1212,
9246,
14,
339,
3161,
3792,
1077,
506,
26,
298,
1662,
2491,
14,
1662,
578,
14,
5713,
1692,
1674,
2779,
2066,
8925,
314,
272,
859,
1536,
5133,
314,
2061,
6308,
436,
11275,
370,
664,
314,
2225,
2410,
626,
6308,
272,
687,
314,
8439,
859,
14,
339,
982,
314,
492,
931,
1630,
440,
1395,
1263,
21185,
12,
282,
3146,
365,
4915,
14,
339,
982,
314,
859,
3913,
506,
8439,
12,
376,
3545,
365,
4915,
14,
339,
982,
314,
2225,
1630,
440,
2187,
315,
314,
859,
12,
282,
4281,
365,
4915,
14,
272,
408,
272,
340,
7815,
440,
315,
492,
63,
515,
26,
267,
746,
3146,
8,
288,
3546,
646,
63,
515,
7,
1423,
370,
283,
1176,
63,
912,
14,
1018,
14,
912,
63,
785,
7,
1471,
298,
288,
298,
7747,
737,
5210,
1373,
6308,
2122,
267,
776,
272,
859,
63,
354,
12,
909,
63,
354,
275,
492,
63,
515,
14,
13490,
14078,
413,
9,
272,
859,
275,
492,
63,
578,
8,
578,
63,
354,
9,
272,
372,
2519,
8,
578,
12,
909,
63,
354,
9,
199,
199,
318,
2740,
912,
63,
1462,
8,
646,
63,
3771,
304,
272,
408,
272,
7190,
282,
769,
402,
2251,
14,
272,
408,
272,
372,
2341,
8,
912,
63,
785,
12,
492,
63,
3771,
9,
199,
199,
318,
664,
63,
19094,
8,
67,
304,
272,
408,
272,
2372,
1006,
9180,
402,
282,
1627,
1021,
272,
408,
272,
372,
286,
855,
19094,
4533,
435,
3089,
8,
1130,
8,
362,
63,
19094,
12,
286,
855,
19094,
363,
4000,
3073,
199,
199,
318,
2248,
63,
504,
63,
493,
8,
578,
63,
515,
304,
272,
408,
272,
7190,
282,
2366,
859,
687,
2399,
3679,
10036,
931,
272,
408,
272,
687,
1742,
492,
2248,
63,
578,
12,
7843,
63,
10187,
339,
8439,
275,
488,
272,
340,
859,
63,
515,
26,
267,
543,
1551,
8,
578,
63,
515,
12,
283,
82,
358,
465,
1551,
493,
26,
288,
8439,
275,
2248,
63,
578,
480,
1494,
401,
1551,
493,
12,
859,
63,
515,
12,
661,
17932,
297,
283,
82,
297,
7843,
63,
10187,
430,
272,
372,
8439,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
aviciimaxwell/odoo
|
addons/anonymization/anonymization.py
|
77
|
28690
|
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
# $Id$
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from lxml import etree
import os
import base64
try:
import cPickle as pickle
except ImportError:
import pickle
import random
import datetime
from openerp.osv import fields, osv
from openerp.tools.translate import _
from openerp.tools.safe_eval import safe_eval as eval
from itertools import groupby
from operator import itemgetter
FIELD_STATES = [('clear', 'Clear'), ('anonymized', 'Anonymized'), ('not_existing', 'Not Existing'), ('new', 'New')]
ANONYMIZATION_STATES = FIELD_STATES + [('unstable', 'Unstable')]
WIZARD_ANONYMIZATION_STATES = [('clear', 'Clear'), ('anonymized', 'Anonymized'), ('unstable', 'Unstable')]
ANONYMIZATION_HISTORY_STATE = [('started', 'Started'), ('done', 'Done'), ('in_exception', 'Exception occured')]
ANONYMIZATION_DIRECTION = [('clear -> anonymized', 'clear -> anonymized'), ('anonymized -> clear', 'anonymized -> clear')]
def group(lst, cols):
if isinstance(cols, basestring):
cols = [cols]
return dict((k, [v for v in itr]) for k, itr in groupby(sorted(lst, key=itemgetter(*cols)), itemgetter(*cols)))
class ir_model_fields_anonymization(osv.osv):
_name = 'ir.model.fields.anonymization'
_rec_name = 'field_id'
_columns = {
'model_name': fields.char('Object Name', required=True),
'model_id': fields.many2one('ir.model', 'Object', ondelete='set null'),
'field_name': fields.char('Field Name', required=True),
'field_id': fields.many2one('ir.model.fields', 'Field', ondelete='set null'),
'state': fields.selection(selection=FIELD_STATES, String='Status', required=True, readonly=True),
}
_sql_constraints = [
('model_id_field_id_uniq', 'unique (model_name, field_name)', _("You cannot have two fields with the same name on the same object!")),
]
def _get_global_state(self, cr, uid, context=None):
ids = self.search(cr, uid, [('state', '<>', 'not_existing')], context=context)
fields = self.browse(cr, uid, ids, context=context)
if not len(fields) or len(fields) == len([f for f in fields if f.state == 'clear']):
state = 'clear' # all fields are clear
elif len(fields) == len([f for f in fields if f.state == 'anonymized']):
state = 'anonymized' # all fields are anonymized
else:
state = 'unstable' # fields are mixed: this should be fixed
return state
def _check_write(self, cr, uid, context=None):
"""check that the field is created from the menu and not from an database update
otherwise the database update can crash:"""
if context is None:
context = {}
if context.get('manual'):
global_state = self._get_global_state(cr, uid, context=context)
if global_state == 'anonymized':
raise osv.except_osv('Error!', "The database is currently anonymized, you cannot create, modify or delete fields.")
elif global_state == 'unstable':
msg = _("The database anonymization is currently in an unstable state. Some fields are anonymized," + \
" while some fields are not anonymized. You should try to solve this problem before trying to create, write or delete fields.")
raise osv.except_osv('Error!', msg)
return True
def _get_model_and_field_ids(self, cr, uid, vals, context=None):
model_and_field_ids = (False, False)
if 'field_name' in vals and vals['field_name'] and 'model_name' in vals and vals['model_name']:
ir_model_fields_obj = self.pool.get('ir.model.fields')
ir_model_obj = self.pool.get('ir.model')
model_ids = ir_model_obj.search(cr, uid, [('model', '=', vals['model_name'])], context=context)
if model_ids:
field_ids = ir_model_fields_obj.search(cr, uid, [('name', '=', vals['field_name']), ('model_id', '=', model_ids[0])], context=context)
if field_ids:
field_id = field_ids[0]
model_and_field_ids = (model_ids[0], field_id)
return model_and_field_ids
def create(self, cr, uid, vals, context=None):
# check field state: all should be clear before we can add a new field to anonymize:
self._check_write(cr, uid, context=context)
global_state = self._get_global_state(cr, uid, context=context)
if 'field_name' in vals and vals['field_name'] and 'model_name' in vals and vals['model_name']:
vals['model_id'], vals['field_id'] = self._get_model_and_field_ids(cr, uid, vals, context=context)
# check not existing fields:
if not vals.get('field_id'):
vals['state'] = 'not_existing'
else:
vals['state'] = global_state
res = super(ir_model_fields_anonymization, self).create(cr, uid, vals, context=context)
return res
def write(self, cr, uid, ids, vals, context=None):
# check field state: all should be clear before we can modify a field:
if not (len(vals.keys()) == 1 and vals.get('state') == 'clear'):
self._check_write(cr, uid, context=context)
if 'field_name' in vals and vals['field_name'] and 'model_name' in vals and vals['model_name']:
vals['model_id'], vals['field_id'] = self._get_model_and_field_ids(cr, uid, vals, context=context)
# check not existing fields:
if 'field_id' in vals:
if not vals.get('field_id'):
vals['state'] = 'not_existing'
else:
global_state = self._get_global_state(cr, uid, context)
if global_state != 'unstable':
vals['state'] = global_state
res = super(ir_model_fields_anonymization, self).write(cr, uid, ids, vals, context=context)
return res
def unlink(self, cr, uid, ids, context=None):
# check field state: all should be clear before we can unlink a field:
self._check_write(cr, uid, context=context)
res = super(ir_model_fields_anonymization, self).unlink(cr, uid, ids, context=context)
return res
def onchange_model_id(self, cr, uid, ids, model_id, context=None):
res = {'value': {
'field_name': False,
'field_id': False,
'model_name': False,
}}
if model_id:
ir_model_obj = self.pool.get('ir.model')
model_ids = ir_model_obj.search(cr, uid, [('id', '=', model_id)])
model_id = model_ids and model_ids[0] or None
model_name = model_id and ir_model_obj.browse(cr, uid, model_id).model or False
res['value']['model_name'] = model_name
return res
def onchange_model_name(self, cr, uid, ids, model_name, context=None):
res = {'value': {
'field_name': False,
'field_id': False,
'model_id': False,
}}
if model_name:
ir_model_obj = self.pool.get('ir.model')
model_ids = ir_model_obj.search(cr, uid, [('model', '=', model_name)])
model_id = model_ids and model_ids[0] or False
res['value']['model_id'] = model_id
return res
def onchange_field_name(self, cr, uid, ids, field_name, model_name):
res = {'value': {
'field_id': False,
}}
if field_name and model_name:
ir_model_fields_obj = self.pool.get('ir.model.fields')
field_ids = ir_model_fields_obj.search(cr, uid, [('name', '=', field_name), ('model', '=', model_name)])
field_id = field_ids and field_ids[0] or False
res['value']['field_id'] = field_id
return res
def onchange_field_id(self, cr, uid, ids, field_id, model_name):
res = {'value': {
'field_name': False,
}}
if field_id:
ir_model_fields_obj = self.pool.get('ir.model.fields')
field = ir_model_fields_obj.browse(cr, uid, field_id)
res['value']['field_name'] = field.name
return res
_defaults = {
'state': lambda *a: 'clear',
}
class ir_model_fields_anonymization_history(osv.osv):
_name = 'ir.model.fields.anonymization.history'
_order = "date desc"
_columns = {
'date': fields.datetime('Date', required=True, readonly=True),
'field_ids': fields.many2many('ir.model.fields.anonymization', 'anonymized_field_to_history_rel', 'field_id', 'history_id', 'Fields', readonly=True),
'state': fields.selection(selection=ANONYMIZATION_HISTORY_STATE, string='Status', required=True, readonly=True),
'direction': fields.selection(selection=ANONYMIZATION_DIRECTION, string='Direction', size=20, required=True, readonly=True),
'msg': fields.text('Message', readonly=True),
'filepath': fields.char(string='File path', readonly=True),
}
class ir_model_fields_anonymize_wizard(osv.osv_memory):
_name = 'ir.model.fields.anonymize.wizard'
def _get_state(self, cr, uid, ids, name, arg, context=None):
res = {}
state = self._get_state_value(cr, uid, context=None)
for id in ids:
res[id] = state
return res
def _get_summary(self, cr, uid, ids, name, arg, context=None):
res = {}
summary = self._get_summary_value(cr, uid, context)
for id in ids:
res[id] = summary
return res
_columns = {
'name': fields.char(string='File Name'),
'summary': fields.function(_get_summary, type='text', string='Summary'),
'file_export': fields.binary(string='Export'),
'file_import': fields.binary(string='Import', help="This is the file created by the anonymization process. It should have the '.pickle' extention."),
'state': fields.function(_get_state, string='Status', type='selection', selection=WIZARD_ANONYMIZATION_STATES, readonly=False),
'msg': fields.text(string='Message'),
}
def _get_state_value(self, cr, uid, context=None):
state = self.pool.get('ir.model.fields.anonymization')._get_global_state(cr, uid, context=context)
return state
def _get_summary_value(self, cr, uid, context=None):
summary = u''
anon_field_obj = self.pool.get('ir.model.fields.anonymization')
ir_model_fields_obj = self.pool.get('ir.model.fields')
anon_field_ids = anon_field_obj.search(cr, uid, [('state', '<>', 'not_existing')], context=context)
anon_fields = anon_field_obj.browse(cr, uid, anon_field_ids, context=context)
field_ids = [anon_field.field_id.id for anon_field in anon_fields if anon_field.field_id]
fields = ir_model_fields_obj.browse(cr, uid, field_ids, context=context)
fields_by_id = dict([(f.id, f) for f in fields])
for anon_field in anon_fields:
field = fields_by_id.get(anon_field.field_id.id)
values = {
'model_name': field.model_id.name,
'model_code': field.model_id.model,
'field_code': field.name,
'field_name': field.field_description,
'state': anon_field.state,
}
summary += u" * %(model_name)s (%(model_code)s) -> %(field_name)s (%(field_code)s): state: (%(state)s)\n" % values
return summary
def default_get(self, cr, uid, fields_list, context=None):
res = {}
res['name'] = '.pickle'
res['summary'] = self._get_summary_value(cr, uid, context)
res['state'] = self._get_state_value(cr, uid, context)
res['msg'] = _("""Before executing the anonymization process, you should make a backup of your database.""")
return res
def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, *args, **kwargs):
state = self.pool.get('ir.model.fields.anonymization')._get_global_state(cr, uid, context=context)
if context is None:
context = {}
step = context.get('step', 'new_window')
res = super(ir_model_fields_anonymize_wizard, self).fields_view_get(cr, uid, view_id, view_type, context, *args, **kwargs)
eview = etree.fromstring(res['arch'])
placeholder = eview.xpath("group[@name='placeholder1']")
if len(placeholder):
placeholder = placeholder[0]
if step == 'new_window' and state == 'clear':
# clicked in the menu and the fields are not anonymized: warn the admin that backuping the db is very important
placeholder.addnext(etree.Element('field', {'name': 'msg', 'colspan': '4', 'nolabel': '1'}))
placeholder.addnext(etree.Element('newline'))
placeholder.addnext(etree.Element('label', {'string': 'Warning'}))
eview.remove(placeholder)
elif step == 'new_window' and state == 'anonymized':
# clicked in the menu and the fields are already anonymized
placeholder.addnext(etree.Element('newline'))
placeholder.addnext(etree.Element('field', {'name': 'file_import', 'required': "1"}))
placeholder.addnext(etree.Element('label', {'string': 'Anonymization file'}))
eview.remove(placeholder)
elif step == 'just_anonymized':
# we just ran the anonymization process, we need the file export field
placeholder.addnext(etree.Element('newline'))
placeholder.addnext(etree.Element('field', {'name': 'file_export'}))
# we need to remove the button:
buttons = eview.xpath("button")
for button in buttons:
eview.remove(button)
# and add a message:
placeholder.addnext(etree.Element('field', {'name': 'msg', 'colspan': '4', 'nolabel': '1'}))
placeholder.addnext(etree.Element('newline'))
placeholder.addnext(etree.Element('label', {'string': 'Result'}))
# remove the placeholer:
eview.remove(placeholder)
elif step == 'just_desanonymized':
# we just reversed the anonymization process, we don't need any field
# we need to remove the button
buttons = eview.xpath("button")
for button in buttons:
eview.remove(button)
# and add a message
# and add a message:
placeholder.addnext(etree.Element('field', {'name': 'msg', 'colspan': '4', 'nolabel': '1'}))
placeholder.addnext(etree.Element('newline'))
placeholder.addnext(etree.Element('label', {'string': 'Result'}))
# remove the placeholer:
eview.remove(placeholder)
else:
msg = _("The database anonymization is currently in an unstable state. Some fields are anonymized," + \
" while some fields are not anonymized. You should try to solve this problem before trying to do anything else.")
raise osv.except_osv('Error!', msg)
res['arch'] = etree.tostring(eview)
return res
def _raise_after_history_update(self, cr, uid, history_id, error_type, error_msg):
self.pool.get('ir.model.fields.anonymization.history').write(cr, uid, history_id, {
'state': 'in_exception',
'msg': error_msg,
})
raise osv.except_osv(error_type, error_msg)
def anonymize_database(self, cr, uid, ids, context=None):
"""Sets the 'anonymized' state to defined fields"""
# create a new history record:
anonymization_history_model = self.pool.get('ir.model.fields.anonymization.history')
vals = {
'date': datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
'state': 'started',
'direction': 'clear -> anonymized',
}
history_id = anonymization_history_model.create(cr, uid, vals)
# check that all the defined fields are in the 'clear' state
state = self.pool.get('ir.model.fields.anonymization')._get_global_state(cr, uid, context=context)
if state == 'anonymized':
self._raise_after_history_update(cr, uid, history_id, _('Error !'), _("The database is currently anonymized, you cannot anonymize it again."))
elif state == 'unstable':
msg = _("The database anonymization is currently in an unstable state. Some fields are anonymized," + \
" while some fields are not anonymized. You should try to solve this problem before trying to do anything.")
self._raise_after_history_update(cr, uid, history_id, 'Error !', msg)
# do the anonymization:
dirpath = os.environ.get('HOME') or os.getcwd()
rel_filepath = 'field_anonymization_%s_%s.pickle' % (cr.dbname, history_id)
abs_filepath = os.path.abspath(os.path.join(dirpath, rel_filepath))
ir_model_fields_anonymization_model = self.pool.get('ir.model.fields.anonymization')
field_ids = ir_model_fields_anonymization_model.search(cr, uid, [('state', '<>', 'not_existing')], context=context)
fields = ir_model_fields_anonymization_model.browse(cr, uid, field_ids, context=context)
if not fields:
msg = "No fields are going to be anonymized."
self._raise_after_history_update(cr, uid, history_id, 'Error !', msg)
data = []
for field in fields:
model_name = field.model_id.model
field_name = field.field_id.name
field_type = field.field_id.ttype
table_name = self.pool[model_name]._table
# get the current value
sql = "select id, %s from %s" % (field_name, table_name)
cr.execute(sql)
records = cr.dictfetchall()
for record in records:
data.append({"model_id": model_name, "field_id": field_name, "id": record['id'], "value": record[field_name]})
# anonymize the value:
anonymized_value = None
sid = str(record['id'])
if field_type == 'char':
anonymized_value = 'xxx'+sid
elif field_type == 'selection':
anonymized_value = 'xxx'+sid
elif field_type == 'text':
anonymized_value = 'xxx'+sid
elif field_type == 'boolean':
anonymized_value = random.choice([True, False])
elif field_type == 'date':
anonymized_value = '2011-11-11'
elif field_type == 'datetime':
anonymized_value = '2011-11-11 11:11:11'
elif field_type == 'float':
anonymized_value = 0.0
elif field_type == 'integer':
anonymized_value = 0
elif field_type in ['binary', 'many2many', 'many2one', 'one2many', 'reference']: # cannot anonymize these kind of fields
msg = _("Cannot anonymize fields of these types: binary, many2many, many2one, one2many, reference.")
self._raise_after_history_update(cr, uid, history_id, 'Error !', msg)
if anonymized_value is None:
self._raise_after_history_update(cr, uid, history_id, _('Error !'), _("Anonymized value is None. This cannot happens."))
sql = "update %(table)s set %(field)s = %%(anonymized_value)s where id = %%(id)s" % {
'table': table_name,
'field': field_name,
}
cr.execute(sql, {
'anonymized_value': anonymized_value,
'id': record['id']
})
# save pickle:
fn = open(abs_filepath, 'w')
pickle.dump(data, fn, pickle.HIGHEST_PROTOCOL)
# update the anonymization fields:
values = {
'state': 'anonymized',
}
ir_model_fields_anonymization_model.write(cr, uid, field_ids, values, context=context)
# add a result message in the wizard:
msgs = ["Anonymization successful.",
"",
"Donot forget to save the resulting file to a safe place because you will not be able to revert the anonymization without this file.",
"",
"This file is also stored in the %s directory. The absolute file path is: %s.",
]
msg = '\n'.join(msgs) % (dirpath, abs_filepath)
fn = open(abs_filepath, 'r')
self.write(cr, uid, ids, {
'msg': msg,
'file_export': base64.encodestring(fn.read()),
})
fn.close()
# update the history record:
anonymization_history_model.write(cr, uid, history_id, {
'field_ids': [[6, 0, field_ids]],
'msg': msg,
'filepath': abs_filepath,
'state': 'done',
})
# handle the view:
view_id = self._id_get(cr, uid, 'ir.ui.view', 'view_ir_model_fields_anonymize_wizard_form', 'anonymization')
return {
'res_id': ids[0],
'view_id': [view_id],
'view_type': 'form',
"view_mode": 'form',
'res_model': 'ir.model.fields.anonymize.wizard',
'type': 'ir.actions.act_window',
'context': {'step': 'just_anonymized'},
'target':'new',
}
def reverse_anonymize_database(self, cr, uid, ids, context=None):
"""Set the 'clear' state to defined fields"""
ir_model_fields_anonymization_model = self.pool.get('ir.model.fields.anonymization')
anonymization_history_model = self.pool.get('ir.model.fields.anonymization.history')
# create a new history record:
vals = {
'date': datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
'state': 'started',
'direction': 'anonymized -> clear',
}
history_id = anonymization_history_model.create(cr, uid, vals)
# check that all the defined fields are in the 'anonymized' state
state = ir_model_fields_anonymization_model._get_global_state(cr, uid, context=context)
if state == 'clear':
raise osv.except_osv_('Error!', "The database is not currently anonymized, you cannot reverse the anonymization.")
elif state == 'unstable':
msg = _("The database anonymization is currently in an unstable state. Some fields are anonymized," + \
" while some fields are not anonymized. You should try to solve this problem before trying to do anything.")
raise osv.except_osv('Error!', msg)
wizards = self.browse(cr, uid, ids, context=context)
for wizard in wizards:
if not wizard.file_import:
msg = _("It is not possible to reverse the anonymization process without supplying the anonymization export file.")
self._raise_after_history_update(cr, uid, history_id, 'Error !', msg)
# reverse the anonymization:
# load the pickle file content into a data structure:
data = pickle.loads(base64.decodestring(wizard.file_import))
migration_fix_obj = self.pool.get('ir.model.fields.anonymization.migration.fix')
fix_ids = migration_fix_obj.search(cr, uid, [('target_version', '=', '8.0')])
fixes = migration_fix_obj.read(cr, uid, fix_ids, ['model_name', 'field_name', 'query', 'query_type', 'sequence'])
fixes = group(fixes, ('model_name', 'field_name'))
for line in data:
queries = []
table_name = self.pool[line['model_id']]._table if line['model_id'] in self.pool else None
# check if custom sql exists:
key = (line['model_id'], line['field_id'])
custom_updates = fixes.get(key)
if custom_updates:
custom_updates.sort(key=itemgetter('sequence'))
queries = [(record['query'], record['query_type']) for record in custom_updates if record['query_type']]
elif table_name:
queries = [("update %(table)s set %(field)s = %%(value)s where id = %%(id)s" % {
'table': table_name,
'field': line['field_id'],
}, 'sql')]
for query in queries:
if query[1] == 'sql':
sql = query[0]
cr.execute(sql, {
'value': line['value'],
'id': line['id']
})
elif query[1] == 'python':
raw_code = query[0]
code = raw_code % line
eval(code)
else:
raise Exception("Unknown query type '%s'. Valid types are: sql, python." % (query['query_type'], ))
# update the anonymization fields:
ir_model_fields_anonymization_model = self.pool.get('ir.model.fields.anonymization')
field_ids = ir_model_fields_anonymization_model.search(cr, uid, [('state', '<>', 'not_existing')], context=context)
values = {
'state': 'clear',
}
ir_model_fields_anonymization_model.write(cr, uid, field_ids, values, context=context)
# add a result message in the wizard:
msg = '\n'.join(["Successfully reversed the anonymization.",
"",
])
self.write(cr, uid, ids, {'msg': msg})
# update the history record:
anonymization_history_model.write(cr, uid, history_id, {
'field_ids': [[6, 0, field_ids]],
'msg': msg,
'filepath': False,
'state': 'done',
})
# handle the view:
view_id = self._id_get(cr, uid, 'ir.ui.view', 'view_ir_model_fields_anonymize_wizard_form', 'anonymization')
return {
'res_id': ids[0],
'view_id': [view_id],
'view_type': 'form',
"view_mode": 'form',
'res_model': 'ir.model.fields.anonymize.wizard',
'type': 'ir.actions.act_window',
'context': {'step': 'just_desanonymized'},
'target':'new',
}
def _id_get(self, cr, uid, model, id_str, mod):
if '.' in id_str:
mod, id_str = id_str.split('.')
try:
idn = self.pool.get('ir.model.data')._get_id(cr, uid, mod, id_str)
res = int(self.pool.get('ir.model.data').read(cr, uid, [idn], ['res_id'])[0]['res_id'])
except:
res = None
return res
class ir_model_fields_anonymization_migration_fix(osv.osv):
_name = 'ir.model.fields.anonymization.migration.fix'
_order = "sequence"
_columns = {
'target_version': fields.char('Target Version'),
'model_name': fields.char('Model'),
'field_name': fields.char('Field'),
'query': fields.text('Query'),
'query_type': fields.selection(string='Query', selection=[('sql', 'sql'), ('python', 'python')]),
'sequence': fields.integer('Sequence'),
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
3,
1882,
2644,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
8664,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
2900,
5924,
5702,
199,
3,
259,
2672,
1304,
4,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
259,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
259,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
504,
14490,
492,
7559,
199,
646,
747,
199,
646,
1300,
772,
199,
893,
26,
272,
492,
17572,
465,
5927,
199,
2590,
3545,
26,
272,
492,
5927,
199,
646,
2196,
199,
646,
2197,
199,
504,
5166,
14,
4795,
492,
1504,
12,
9506,
199,
504,
5166,
14,
2537,
14,
5275,
492,
485,
199,
504,
5166,
14,
2537,
14,
3489,
63,
2579,
492,
5048,
63,
2579,
465,
3468,
199,
199,
504,
7975,
492,
20371,
199,
504,
4182,
492,
1242,
7416,
421,
199,
8609,
63,
23162,
275,
4274,
3584,
297,
283,
9721,
659,
661,
290,
15224,
1759,
297,
283,
2493,
15224,
1759,
659,
661,
1397,
63,
5952,
297,
283,
1763,
1316,
26958,
659,
661,
1222,
297,
283,
4665,
5440,
199,
879,
32537,
45,
22800,
63,
23162,
275,
26130,
63,
23162,
435,
4274,
324,
11989,
297,
283,
1358,
11989,
5440,
199,
55,
5357,
7816,
63,
879,
32537,
45,
22800,
63,
23162,
275,
4274,
3584,
297,
283,
9721,
659,
661,
290,
15224,
1759,
297,
283,
2493,
15224,
1759,
659,
661,
324,
11989,
297,
283,
1358,
11989,
5440,
199,
879,
32537,
45,
22800,
63,
30895,
63,
6689,
275,
4274,
8924,
297,
283,
21031,
659,
661,
4456,
297,
283,
10759,
659,
661,
262,
63,
1971,
297,
283,
1726,
28408,
5440,
199,
879,
32537,
45,
22800,
63,
6098,
1075,
275,
4274,
3584,
1035,
376,
15224,
1759,
297,
283,
3584,
1035,
376,
15224,
1759,
659,
661,
290,
15224,
1759,
1035,
5436,
297,
283,
290,
15224,
1759,
1035,
5436,
5440,
421,
199,
318,
1572,
8,
6916,
12,
8850,
304,
272,
340,
1228,
8,
4574,
12,
7116,
304,
267,
8850,
275,
359,
4574,
61,
272,
372,
1211,
1332,
75,
12,
359,
86,
367,
373,
315,
284,
454,
566,
367,
1022,
12,
284,
454,
315,
20371,
8,
5917,
8,
6916,
12,
790,
29,
20832,
2031,
4574,
1826,
1242,
7416,
2031,
4574,
1724,
421,
199,
533,
8190,
63,
1238,
63,
955,
63,
290,
15224,
2072,
8,
4795,
14,
4795,
304,
272,
485,
354,
275,
283,
723,
14,
1238,
14,
955,
14,
290,
15224,
2072,
7,
272,
485,
2761,
63,
354,
275,
283,
698,
63,
344,
7,
339,
485,
3406,
275,
469,
267,
283,
1238,
63,
354,
356,
1504,
14,
1560,
360,
1692,
2812,
297,
1415,
29,
549,
395,
267,
283,
1238,
63,
344,
356,
1504,
14,
3479,
18,
368,
360,
723,
14,
1238,
297,
283,
1692,
297,
16549,
534,
409,
2973,
659,
267,
283,
698,
63,
354,
356,
1504,
14,
1560,
360,
792,
2812,
297,
1415,
29,
549,
395,
267,
283,
698,
63,
344,
356,
1504,
14,
3479,
18,
368,
360,
723,
14,
1238,
14,
955,
297,
283,
792,
297,
16549,
534,
409,
2973,
659,
267,
283,
929,
356,
1504,
14,
5592,
8,
5592,
29,
8609,
63,
23162,
12,
2624,
534,
3694,
297,
1415,
29,
549,
12,
6863,
29,
549,
395,
272,
789,
339,
485,
3009,
63,
9882,
275,
359,
267,
661,
1238,
63,
344,
63,
698,
63,
344,
63,
22484,
297,
283,
3235,
334,
1238,
63,
354,
12,
901,
63,
354,
3196,
3824,
5556,
3913,
1172,
2877,
1504,
543,
314,
2011,
536,
641,
314,
2011,
909,
1,
8150,
272,
1622,
339,
347,
485,
362,
63,
2966,
63,
929,
8,
277,
12,
2467,
12,
1747,
12,
1067,
29,
403,
304,
267,
2762,
275,
291,
14,
1733,
8,
1556,
12,
1747,
12,
4274,
929,
297,
2650,
4206,
283,
1397,
63,
5952,
2665,
1067,
29,
1100,
9,
267,
1504,
275,
291,
14,
4570,
8,
1556,
12,
1747,
12,
2762,
12,
1067,
29,
1100,
9,
267,
340,
440,
822,
8,
955,
9,
503,
822,
8,
955,
9,
508,
822,
779,
70,
367,
289,
315,
1504,
340,
289,
14,
929,
508,
283,
3584,
9090,
288,
1174,
275,
283,
3584,
7,
327,
1006,
1504,
787,
5436,
267,
916,
822,
8,
955,
9,
508,
822,
779,
70,
367,
289,
315,
1504,
340,
289,
14,
929,
508,
283,
290,
15224,
1759,
9090,
288,
1174,
275,
283,
290,
15224,
1759,
7,
327,
1006,
1504,
787,
376,
15224,
1759,
267,
587,
26,
288,
1174,
275,
283,
324,
11989,
7,
327,
1504,
787,
13492,
26,
642,
1077,
506,
6317,
398,
372,
1174,
339,
347,
485,
1074,
63,
952,
8,
277,
12,
2467,
12,
1747,
12,
1067,
29,
403,
304,
267,
408,
1074,
626,
314,
901,
365,
2737,
687,
314,
6269,
436,
440,
687,
376,
3050,
1678,
1779,
4257,
314,
3050,
1678,
883,
12420,
26,
624,
267,
340,
1067,
365,
488,
26,
288,
1067,
275,
1052,
398,
340,
1067,
14,
362,
360,
9285,
735,
288,
2288,
63,
929,
275,
291,
423,
362,
63,
2966,
63,
929,
8,
1556,
12,
1747,
12,
1067,
29,
1100,
9,
288,
340,
2288,
63,
929,
508,
283,
290,
15224,
1759,
356,
355,
746,
9506,
14,
2590,
63,
4795,
360,
547,
12389,
298,
1918,
3050,
365,
5544,
376,
15224,
1759,
12,
1265,
3913,
1218,
12,
2811,
503,
3145,
1504,
2685,
288,
916,
2288,
63,
929,
508,
283,
324,
11989,
356,
355,
1499,
275,
3824,
1918,
3050,
376,
15224,
2072
] |
[
1882,
2644,
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,
2900,
5924,
5702,
199,
3,
259,
2672,
1304,
4,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
259,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
259,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
504,
14490,
492,
7559,
199,
646,
747,
199,
646,
1300,
772,
199,
893,
26,
272,
492,
17572,
465,
5927,
199,
2590,
3545,
26,
272,
492,
5927,
199,
646,
2196,
199,
646,
2197,
199,
504,
5166,
14,
4795,
492,
1504,
12,
9506,
199,
504,
5166,
14,
2537,
14,
5275,
492,
485,
199,
504,
5166,
14,
2537,
14,
3489,
63,
2579,
492,
5048,
63,
2579,
465,
3468,
199,
199,
504,
7975,
492,
20371,
199,
504,
4182,
492,
1242,
7416,
421,
199,
8609,
63,
23162,
275,
4274,
3584,
297,
283,
9721,
659,
661,
290,
15224,
1759,
297,
283,
2493,
15224,
1759,
659,
661,
1397,
63,
5952,
297,
283,
1763,
1316,
26958,
659,
661,
1222,
297,
283,
4665,
5440,
199,
879,
32537,
45,
22800,
63,
23162,
275,
26130,
63,
23162,
435,
4274,
324,
11989,
297,
283,
1358,
11989,
5440,
199,
55,
5357,
7816,
63,
879,
32537,
45,
22800,
63,
23162,
275,
4274,
3584,
297,
283,
9721,
659,
661,
290,
15224,
1759,
297,
283,
2493,
15224,
1759,
659,
661,
324,
11989,
297,
283,
1358,
11989,
5440,
199,
879,
32537,
45,
22800,
63,
30895,
63,
6689,
275,
4274,
8924,
297,
283,
21031,
659,
661,
4456,
297,
283,
10759,
659,
661,
262,
63,
1971,
297,
283,
1726,
28408,
5440,
199,
879,
32537,
45,
22800,
63,
6098,
1075,
275,
4274,
3584,
1035,
376,
15224,
1759,
297,
283,
3584,
1035,
376,
15224,
1759,
659,
661,
290,
15224,
1759,
1035,
5436,
297,
283,
290,
15224,
1759,
1035,
5436,
5440,
421,
199,
318,
1572,
8,
6916,
12,
8850,
304,
272,
340,
1228,
8,
4574,
12,
7116,
304,
267,
8850,
275,
359,
4574,
61,
272,
372,
1211,
1332,
75,
12,
359,
86,
367,
373,
315,
284,
454,
566,
367,
1022,
12,
284,
454,
315,
20371,
8,
5917,
8,
6916,
12,
790,
29,
20832,
2031,
4574,
1826,
1242,
7416,
2031,
4574,
1724,
421,
199,
533,
8190,
63,
1238,
63,
955,
63,
290,
15224,
2072,
8,
4795,
14,
4795,
304,
272,
485,
354,
275,
283,
723,
14,
1238,
14,
955,
14,
290,
15224,
2072,
7,
272,
485,
2761,
63,
354,
275,
283,
698,
63,
344,
7,
339,
485,
3406,
275,
469,
267,
283,
1238,
63,
354,
356,
1504,
14,
1560,
360,
1692,
2812,
297,
1415,
29,
549,
395,
267,
283,
1238,
63,
344,
356,
1504,
14,
3479,
18,
368,
360,
723,
14,
1238,
297,
283,
1692,
297,
16549,
534,
409,
2973,
659,
267,
283,
698,
63,
354,
356,
1504,
14,
1560,
360,
792,
2812,
297,
1415,
29,
549,
395,
267,
283,
698,
63,
344,
356,
1504,
14,
3479,
18,
368,
360,
723,
14,
1238,
14,
955,
297,
283,
792,
297,
16549,
534,
409,
2973,
659,
267,
283,
929,
356,
1504,
14,
5592,
8,
5592,
29,
8609,
63,
23162,
12,
2624,
534,
3694,
297,
1415,
29,
549,
12,
6863,
29,
549,
395,
272,
789,
339,
485,
3009,
63,
9882,
275,
359,
267,
661,
1238,
63,
344,
63,
698,
63,
344,
63,
22484,
297,
283,
3235,
334,
1238,
63,
354,
12,
901,
63,
354,
3196,
3824,
5556,
3913,
1172,
2877,
1504,
543,
314,
2011,
536,
641,
314,
2011,
909,
1,
8150,
272,
1622,
339,
347,
485,
362,
63,
2966,
63,
929,
8,
277,
12,
2467,
12,
1747,
12,
1067,
29,
403,
304,
267,
2762,
275,
291,
14,
1733,
8,
1556,
12,
1747,
12,
4274,
929,
297,
2650,
4206,
283,
1397,
63,
5952,
2665,
1067,
29,
1100,
9,
267,
1504,
275,
291,
14,
4570,
8,
1556,
12,
1747,
12,
2762,
12,
1067,
29,
1100,
9,
267,
340,
440,
822,
8,
955,
9,
503,
822,
8,
955,
9,
508,
822,
779,
70,
367,
289,
315,
1504,
340,
289,
14,
929,
508,
283,
3584,
9090,
288,
1174,
275,
283,
3584,
7,
327,
1006,
1504,
787,
5436,
267,
916,
822,
8,
955,
9,
508,
822,
779,
70,
367,
289,
315,
1504,
340,
289,
14,
929,
508,
283,
290,
15224,
1759,
9090,
288,
1174,
275,
283,
290,
15224,
1759,
7,
327,
1006,
1504,
787,
376,
15224,
1759,
267,
587,
26,
288,
1174,
275,
283,
324,
11989,
7,
327,
1504,
787,
13492,
26,
642,
1077,
506,
6317,
398,
372,
1174,
339,
347,
485,
1074,
63,
952,
8,
277,
12,
2467,
12,
1747,
12,
1067,
29,
403,
304,
267,
408,
1074,
626,
314,
901,
365,
2737,
687,
314,
6269,
436,
440,
687,
376,
3050,
1678,
1779,
4257,
314,
3050,
1678,
883,
12420,
26,
624,
267,
340,
1067,
365,
488,
26,
288,
1067,
275,
1052,
398,
340,
1067,
14,
362,
360,
9285,
735,
288,
2288,
63,
929,
275,
291,
423,
362,
63,
2966,
63,
929,
8,
1556,
12,
1747,
12,
1067,
29,
1100,
9,
288,
340,
2288,
63,
929,
508,
283,
290,
15224,
1759,
356,
355,
746,
9506,
14,
2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