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
|
|---|---|---|---|---|---|---|---|---|
bbozhev/flask-test
|
flask/lib/python2.7/site-packages/werkzeug/testsuite/compat.py
|
146
|
1117
|
# -*- coding: utf-8 -*-
"""
werkzeug.testsuite.compat
~~~~~~~~~~~~~~~~~~~~~~~~~
Ensure that old stuff does not break on update.
:copyright: (c) 2014 by Armin Ronacher.
:license: BSD, see LICENSE for more details.
"""
import unittest
import warnings
from werkzeug.testsuite import WerkzeugTestCase
from werkzeug.wrappers import Response
from werkzeug.test import create_environ
class CompatTestCase(WerkzeugTestCase):
def test_old_imports(self):
from werkzeug.utils import Headers, MultiDict, CombinedMultiDict, \
Headers, EnvironHeaders
from werkzeug.http import Accept, MIMEAccept, CharsetAccept, \
LanguageAccept, ETags, HeaderSet, WWWAuthenticate, \
Authorization
def test_exposed_werkzeug_mod(self):
import werkzeug
for key in werkzeug.__all__:
# deprecated, skip it
if key in ('templates', 'Template'):
continue
getattr(werkzeug, key)
def suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(CompatTestCase))
return suite
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
10380,
14,
14239,
14,
5819,
272,
18294,
4919,
94,
339,
7523,
626,
2269,
8292,
1630,
440,
2059,
641,
1678,
14,
339,
520,
7307,
26,
334,
67,
9,
6927,
701,
1952,
827,
32472,
19728,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
1655,
2436,
14,
199,
624,
199,
646,
2882,
199,
646,
3598,
199,
504,
10380,
14,
14239,
492,
22798,
1746,
199,
199,
504,
10380,
14,
21148,
492,
7232,
199,
504,
10380,
14,
396,
492,
1218,
63,
2314,
421,
199,
533,
3599,
292,
1746,
8,
55,
8756,
1746,
304,
339,
347,
511,
63,
1753,
63,
12775,
8,
277,
304,
267,
687,
10380,
14,
1208,
492,
21391,
12,
29393,
12,
22170,
379,
21365,
12,
971,
1467,
21391,
12,
3447,
1489,
9883,
267,
687,
10380,
14,
1014,
492,
15506,
12,
14735,
8422,
12,
29392,
8422,
12,
971,
1467,
8466,
8422,
12,
662,
9440,
12,
10240,
1084,
12,
644,
11178,
21476,
12,
971,
1467,
21527,
339,
347,
511,
63,
26717,
63,
17719,
63,
1494,
8,
277,
304,
267,
492,
10380,
267,
367,
790,
315,
10380,
855,
452,
10651,
288,
327,
5906,
12,
3372,
652,
288,
340,
790,
315,
661,
5876,
297,
283,
4231,
735,
355,
1980,
288,
2519,
8,
17719,
12,
790,
9,
421,
199,
318,
5241,
837,
272,
5241,
275,
2882,
14,
10591,
342,
272,
5241,
14,
15714,
8,
2796,
14,
18275,
8,
2404,
292,
1746,
430,
272,
372,
5241,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
10380,
14,
14239,
14,
5819,
272,
18294,
4919,
94,
339,
7523,
626,
2269,
8292,
1630,
440,
2059,
641,
1678,
14,
339,
520,
7307,
26,
334,
67,
9,
6927,
701,
1952,
827,
32472,
19728,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
1655,
2436,
14,
199,
624,
199,
646,
2882,
199,
646,
3598,
199,
504,
10380,
14,
14239,
492,
22798,
1746,
199,
199,
504,
10380,
14,
21148,
492,
7232,
199,
504,
10380,
14,
396,
492,
1218,
63,
2314,
421,
199,
533,
3599,
292,
1746,
8,
55,
8756,
1746,
304,
339,
347,
511,
63,
1753,
63,
12775,
8,
277,
304,
267,
687,
10380,
14,
1208,
492,
21391,
12,
29393,
12,
22170,
379,
21365,
12,
971,
1467,
21391,
12,
3447,
1489,
9883,
267,
687,
10380,
14,
1014,
492,
15506,
12,
14735,
8422,
12,
29392,
8422,
12,
971,
1467,
8466,
8422,
12,
662,
9440,
12,
10240,
1084,
12,
644,
11178,
21476,
12,
971,
1467,
21527,
339,
347,
511,
63,
26717,
63,
17719,
63,
1494,
8,
277,
304,
267,
492,
10380,
267,
367,
790,
315,
10380,
855,
452,
10651,
288,
327,
5906,
12,
3372,
652,
288,
340,
790,
315,
661,
5876,
297,
283,
4231,
735,
355,
1980,
288,
2519,
8,
17719,
12,
790,
9,
421,
199,
318,
5241,
837,
272,
5241,
275,
2882,
14,
10591,
342,
272,
5241,
14,
15714,
8,
2796,
14,
18275,
8,
2404,
292,
1746,
430,
272,
372,
5241,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
sauliusl/mMass-fork
|
mspy/parser_mzdata.py
|
2
|
27202
|
# -------------------------------------------------------------------------
# Copyright (C) 2005-2013 Martin Strohalm <www.mmass.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.
# Complete text of GNU GPL can be found in the file LICENSE.TXT in the
# main directory of the program.
# -------------------------------------------------------------------------
# load libs
import xml.sax
import xml.dom.minidom
import base64
import struct
import os.path
import numpy
from copy import deepcopy
# load stopper
from mod_stopper import CHECK_FORCE_QUIT
# load objects
import obj_peak
import obj_peaklist
import obj_scan
# PARSE mzData DATA
# -----------------
class parseMZDATA():
"""Parse data from mzData."""
def __init__(self, path):
self.path = path
self._scans = None
self._scanlist = None
self._info = None
# check path
if not os.path.exists(path):
raise IOError, 'File not found! --> ' + self.path
# ----
def load(self):
"""Load all scans into memory."""
# init parser
handler = runHandler()
parser = xml.sax.make_parser()
parser.setContentHandler(handler)
# parse document
try:
document = file(self.path)
parser.parse(document)
document.close()
self._scans = handler.data
except xml.sax.SAXException:
self._scans = False
# make scanlist
if self._scans:
self._scanlist = deepcopy(self._scans)
for scanNumber in self._scanlist:
del self._scanlist[scanNumber]['mzData']
del self._scanlist[scanNumber]['mzEndian']
del self._scanlist[scanNumber]['mzPrecision']
del self._scanlist[scanNumber]['intData']
del self._scanlist[scanNumber]['intEndian']
del self._scanlist[scanNumber]['intPrecision']
# ----
def info(self):
"""Get document info."""
# get preloaded data if available
if self._info:
return self._info
# init parser
handler = infoHandler()
parser = xml.sax.make_parser()
parser.setContentHandler(handler)
# parse document
try:
document = file(self.path)
parser.parse(document)
document.close()
except stopParsing:
self._info = handler.data
except xml.sax.SAXException:
self._info = False
return self._info
# ----
def scanlist(self):
"""Get list of all scans in the document."""
# use preloaded data if available
if self._scanlist:
return self._scanlist
# init parser
handler = scanlistHandler()
parser = xml.sax.make_parser()
parser.setContentHandler(handler)
# parse document
try:
document = file(self.path)
parser.parse(document)
document.close()
self._scanlist = handler.data
except xml.sax.SAXException:
self._scanlist = False
return self._scanlist
# ----
def scan(self, scanID=None):
"""Get spectrum from document."""
# use preloaded data if available
if self._scans and scanID in self._scans:
data = self._scans[scanID]
# parse file
else:
handler = scanHandler(scanID)
parser = xml.sax.make_parser()
parser.setContentHandler(handler)
try:
document = file(self.path)
parser.parse(document)
document.close()
data = handler.data
except stopParsing:
data = handler.data
except xml.sax.SAXException:
return False
# check data
if not data:
return False
# return scan
return self._makeScan(data)
# ----
def _makeScan(self, scanData):
"""Make scan object from raw data."""
# parse peaks
points = self._parsePoints(scanData)
if scanData['spectrumType'] == 'discrete':
for x, p in enumerate(points):
points[x] = obj_peak.peak(p[0], p[1])
scan = obj_scan.scan(peaklist=obj_peaklist.peaklist(points))
else:
scan = obj_scan.scan(profile=points)
# set metadata
scan.title = scanData['title']
scan.scanNumber = scanData['scanNumber']
scan.parentScanNumber = scanData['parentScanNumber']
scan.msLevel = scanData['msLevel']
scan.polarity = scanData['polarity']
scan.retentionTime = scanData['retentionTime']
scan.totIonCurrent = scanData['totIonCurrent']
scan.basePeakMZ = scanData['basePeakMZ']
scan.basePeakIntensity = scanData['basePeakIntensity']
scan.precursorMZ = scanData['precursorMZ']
scan.precursorIntensity = scanData['precursorIntensity']
scan.precursorCharge = scanData['precursorCharge']
return scan
# ----
def _parsePoints(self, scanData):
"""Parse spectrum data."""
# check data
if not scanData['mzData'] or not scanData['intData']:
return []
# decode data
mzData = base64.b64decode(scanData['mzData'])
intData = base64.b64decode(scanData['intData'])
# get endian
mzEndian = '!'
intEndian = '!'
if scanData['mzEndian'] == 'little':
mzEndian = '<'
elif scanData['mzEndian'] == 'big':
mzEndian = '>'
if scanData['intEndian'] == 'little':
intEndian = '<'
elif scanData['intEndian'] == 'big':
intEndian = '>'
# get precision
mzPrecision = 'f'
intPrecision = 'f'
if scanData['mzPrecision'] == 64:
mzPrecision = 'd'
if scanData['intPrecision'] == 64:
intPrecision = 'd'
# convert from binary
count = len(mzData) / struct.calcsize(mzEndian + mzPrecision)
mzData = struct.unpack(mzEndian + mzPrecision * count, mzData[0:len(mzData)])
count = len(intData) / struct.calcsize(intEndian + intPrecision)
intData = struct.unpack(intEndian + intPrecision * count, intData[0:len(intData)])
# format
if scanData['spectrumType'] == 'discrete':
data = map(list, zip(mzData, intData))
else:
mzData = numpy.array(mzData)
mzData.shape = (-1,1)
intData = numpy.array(intData)
intData.shape = (-1,1)
data = numpy.concatenate((mzData,intData), axis=1)
data = data.copy()
return data
# ----
class infoHandler(xml.sax.handler.ContentHandler):
"""Get info data."""
def __init__(self):
self.data = {
'title': '',
'operator': '',
'contact': '',
'institution': '',
'date': '',
'instrument': '',
'notes': '',
}
self._isSampleName = False
self._isContact = False
self._isName = False
self._isInstitution = False
self._isContactInfo = False
self._isInstrumentName = False
# ----
def startElement(self, name, attrs):
"""Element started."""
# get instrument
if name == 'sampleName':
self._isSampleName = True
if name == 'contact':
self._isContact = True
elif name == 'name' and self._isContact:
self._isName = True
elif name == 'institution':
self._isInstitution = True
elif name == 'contactInfo':
self._isContactInfo = True
elif name == 'instrumentName':
self._isInstrumentName = True
# ----
def endElement(self, name):
"""Element ended."""
# stop parsing
if name == 'description':
raise stopParsing()
# stop elements
if name == 'sampleName':
self._isSampleName = False
if name == 'contact':
self._isContact = False
self._isName = False
elif name == 'name':
self._isName = False
elif name == 'institution':
self._isInstitution = False
elif name == 'contactInfo':
self._isContactInfo = False
elif name == 'instrumentName':
self._isInstrumentName = False
# ----
def characters(self, ch):
"""Grab characters."""
# get data
if self._isSampleName:
self.data['title'] += ch
elif self._isName:
self.data['operator'] += ch
elif self._isInstitution:
self.data['institution'] += ch
elif self._isContactInfo:
self.data['contact'] += ch
elif self._isInstrumentName:
self.data['instrument'] += ch
# ----
class scanlistHandler(xml.sax.handler.ContentHandler):
"""Get list of all scans in the document."""
def __init__(self):
self.data = {}
self.currentID = None
# ----
def startElement(self, name, attrs):
"""Element started."""
# get scan metadata
if name == 'spectrum':
# get scan ID
self.currentID = attrs.get('id', None)
if self.currentID != None:
self.currentID = int(self.currentID)
scan = {
'title': '',
'scanNumber': self.currentID,
'parentScanNumber': None,
'msLevel': None,
'pointsCount': None,
'polarity': None,
'retentionTime': None,
'lowMZ': None,
'highMZ': None,
'basePeakMZ': None,
'basePeakIntensity': None,
'totIonCurrent': None,
'precursorMZ': None,
'precursorIntensity': None,
'precursorCharge': None,
'spectrumType': 'unknown',
}
# add scan
self.data[self.currentID] = scan
# get spectrum type
elif name == 'acqSpecification':
attribute = attrs.get('spectrumType', False)
if attribute:
self.data[self.currentID]['spectrumType'] = attribute
# get other params
elif name == 'spectrumInstrument':
# get ms level
attribute = attrs.get('msLevel', 1)
if attribute:
self.data[self.currentID]['msLevel'] = int(attribute)
# get low m/z
attribute = attrs.get('mzRangeStart', None)
if attribute != None:
self.data[self.currentID]['lowMZ'] = float(attribute)
# get high m/z
attribute = attrs.get('mzRangeStop', None)
if attribute != None:
self.data[self.currentID]['highMZ'] = float(attribute)
# get other params
elif name == 'userParam' or name == 'cvParam':
paramName = attrs.get('name', None)
paramValue = attrs.get('value', None)
# get retention time
if paramName == 'TimeInMinutes' and paramValue != None:
try: self.data[self.currentID]['retentionTime'] = float(paramValue)*60
except ValueError: pass
# get total ion current
elif paramName == 'TotalIonCurrent' and paramValue != None:
try: self.data[self.currentID]['totIonCurrent'] = float(paramValue)
except ValueError: pass
# get precursor m/z
elif paramName == 'MassToChargeRatio' and paramValue != None:
try: self.data[self.currentID]['precursorMZ'] = float(paramValue)
except ValueError: pass
# get precursor charge
elif paramName == 'ChargeState' and paramValue != None:
try: self.data[self.currentID]['precursorCharge'] = int(paramValue)
except ValueError: pass
# get polarity
elif paramName == 'Polarity':
if paramValue in ('positive', 'Positive', '+'):
self.data[self.currentID]['polarity'] = 1
elif paramValue == ('negative', 'Negative', '-'):
self.data[self.currentID]['polarity'] = -1
# get parent scan
elif name == 'precursor':
attribute = attrs.get('spectrumRef', None)
if attribute != None:
self.data[self.currentID]['parentScanNumber'] = int(attribute)
# get spectrum length
elif name == 'data':
attribute = attrs.get('length', None)
if attribute != None:
self.data[self.currentID]['pointsCount'] = int(attribute)
# ----
def endElement(self, name):
"""Element ended."""
pass
# ----
def characters(self, ch):
"""Grab characters."""
pass
# ----
class scanHandler(xml.sax.handler.ContentHandler):
"""Get scan data."""
def __init__(self, scanID):
self.data = False
self.scanID = scanID
self._isMatch = False
self._isMzArray = False
self._isIntArray = False
# ----
def startElement(self, name, attrs):
"""Element started."""
# get scan metadata
if name == 'spectrum':
self._isMatch = False
# get scan ID
scanID = attrs.get('id', None)
if scanID != None:
scanID = int(scanID)
# selected scan
if self.scanID == None or scanID == self.scanID:
self._isMatch = True
self.data = {
'title': '',
'scanNumber': scanID,
'parentScanNumber': None,
'msLevel': None,
'pointsCount': None,
'polarity': None,
'retentionTime': None,
'lowMZ': None,
'highMZ': None,
'basePeakMZ': None,
'basePeakIntensity': None,
'totIonCurrent': None,
'precursorMZ': None,
'precursorIntensity': None,
'precursorCharge': None,
'spectrumType': 'unknown',
'mzData': None,
'mzEndian': None,
'mzPrecision': None,
'intData': None,
'intEndian': None,
'intPrecision': None,
}
# get spectrum type
elif name == 'acqSpecification' and self._isMatch:
attribute = attrs.get('spectrumType', False)
if attribute:
self.data['spectrumType'] = attribute
# get other params
elif name == 'spectrumInstrument' and self._isMatch:
# get ms level
attribute = attrs.get('msLevel', 1)
if attribute:
self.data['msLevel'] = int(attribute)
# get low m/z
attribute = attrs.get('mzRangeStart', None)
if attribute != None:
self.data['lowMZ'] = float(attribute)
# get high m/z
attribute = attrs.get('mzRangeStop', None)
if attribute != None:
self.data['highMZ'] = float(attribute)
# get other params
elif (name == 'userParam' or name == 'cvParam') and self._isMatch:
paramName = attrs.get('name','')
paramValue = attrs.get('value', None)
# get retention time
if paramName == 'TimeInMinutes' and paramValue != None:
try: self.data['retentionTime'] = float(paramValue)*60
except ValueError: pass
# get total ion current
elif paramName == 'TotalIonCurrent' and paramValue != None:
try: self.data['totIonCurrent'] = float(paramValue)
except ValueError: pass
# get precursor m/z
elif paramName == 'MassToChargeRatio' and paramValue != None:
try: self.data['precursorMZ'] = float(paramValue)
except ValueError: pass
# get precursor charge
elif paramName == 'ChargeState' and paramValue != None:
try: self.data['precursorCharge'] = int(paramValue)
except ValueError: pass
# get polarity
elif paramName == 'Polarity':
if paramValue in ('positive', 'Positive', '+'):
self.data['polarity'] = 1
elif paramValue == ('negative', 'Negative', '-'):
self.data['polarity'] = -1
# get parent scan
elif name == 'precursor' and self._isMatch:
attribute = attrs.get('spectrumRef', None)
if attribute != None:
self.data['parentScanNumber'] = int(attribute)
# get mz data
elif name == 'mzArrayBinary' and self._isMatch:
self._isMzArray = True
self.data['mzData'] = []
# get int data
elif name == 'intenArrayBinary' and self._isMatch:
self._isIntArray = True
self.data['intData'] = []
# get data
elif name == 'data' and self._isMatch:
# get points count
attribute = attrs.get('length', None)
if attribute != None:
self.data['pointsCount'] = int(attribute)
# get array params
endian = attrs.get('endian','network')
precision = attrs.get('precision', 32)
if self._isMzArray:
self.data['mzEndian'] = endian
if precision:
self.data['mzPrecision'] = int(precision)
elif self._isIntArray:
self.data['intEndian'] = endian
if precision:
self.data['intPrecision'] = int(precision)
# ----
def endElement(self, name):
"""Element ended."""
# stop parsing
if name == 'spectrum' and self._isMatch:
raise stopParsing()
# stop reading mz data
elif name == 'mzArrayBinary' and self._isMatch:
self._isMzArray = False
if not self.data['mzData']:
self.data['mzData'] = None
else:
self.data['mzData'] = ''.join(self.data['mzData'])
# stop reading int data
elif name == 'intenArrayBinary' and self._isMatch:
self._isIntArray = False
if not self.data['intData']:
self.data['intData'] = None
else:
self.data['intData'] = ''.join(self.data['intData'])
# ----
def characters(self, ch):
"""Grab characters."""
# get m/z array
if self._isMzArray:
self.data['mzData'].append(ch)
# get intensity array
elif self._isIntArray:
self.data['intData'].append(ch)
# ----
class runHandler(xml.sax.handler.ContentHandler):
"""Get whole run."""
def __init__(self):
self.data = {}
self.currentID = None
self._isMzArray = False
self._isIntArray = False
# ----
def startElement(self, name, attrs):
"""Element started."""
# get scan metadata
if name == 'spectrum':
# get scan ID
self.currentID = attrs.get('id', None)
if self.currentID != None:
self.currentID = int(self.currentID)
scan = {
'title': '',
'scanNumber': self.currentID,
'parentScanNumber': None,
'msLevel': None,
'pointsCount': None,
'polarity': None,
'retentionTime': None,
'lowMZ': None,
'highMZ': None,
'basePeakMZ': None,
'basePeakIntensity': None,
'totIonCurrent': None,
'precursorMZ': None,
'precursorIntensity': None,
'precursorCharge': None,
'spectrumType': 'unknown',
'mzData': None,
'mzEndian': None,
'mzPrecision': None,
'intData': None,
'intEndian': None,
'intPrecision': None,
}
# add scan
self.data[self.currentID] = scan
# get spectrum type
elif name == 'acqSpecification':
attribute = attrs.get('spectrumType', False)
if attribute:
self.data[self.currentID]['spectrumType'] = attribute
# get other params
elif name == 'spectrumInstrument':
# get ms level
attribute = attrs.get('msLevel', 1)
if attribute:
self.data[self.currentID]['msLevel'] = int(attribute)
# get low m/z
attribute = attrs.get('mzRangeStart', None)
if attribute != None:
self.data[self.currentID]['lowMZ'] = float(attribute)
# get high m/z
attribute = attrs.get('mzRangeStop', None)
if attribute != None:
self.data[self.currentID]['highMZ'] = float(attribute)
# get other params
elif (name == 'userParam' or name == 'cvParam'):
paramName = attrs.get('name','')
paramValue = attrs.get('value', None)
# get retention time
if paramName == 'TimeInMinutes' and paramValue != None:
try: self.data[self.currentID]['retentionTime'] = float(paramValue)*60
except ValueError: pass
# get total ion current
elif paramName == 'TotalIonCurrent' and paramValue != None:
try: self.data[self.currentID]['totIonCurrent'] = float(paramValue)
except ValueError: pass
# get precursor m/z
elif paramName == 'MassToChargeRatio' and paramValue != None:
try: self.data[self.currentID]['precursorMZ'] = float(paramValue)
except ValueError: pass
# get precursor m/z
elif paramName == 'ChargeState' and paramValue != None:
try: self.data[self.currentID]['precursorCharge'] = int(paramValue)
except ValueError: pass
# get polarity
elif paramName == 'Polarity':
if paramValue in ('positive', 'Positive', '+'):
self.data[self.currentID]['polarity'] = 1
elif paramValue == ('negative', 'Negative', '-'):
self.data[self.currentID]['polarity'] = -1
# get parent scan
elif name == 'precursor':
attribute = attrs.get('spectrumRef', None)
if attribute != None:
self.data[self.currentID]['parentScanNumber'] = int(attribute)
# get mz data
elif name == 'mzArrayBinary':
self._isMzArray = True
self.data[self.currentID]['mzData'] = []
# get int data
elif name == 'intenArrayBinary':
self._isIntArray = True
self.data[self.currentID]['intData'] = []
# get data
elif name == 'data':
# get points count
attribute = attrs.get('length', None)
if attribute != None:
self.data[self.currentID]['pointsCount'] = int(attribute)
# get array params
endian = attrs.get('endian','network')
precision = attrs.get('precision', 32)
if self._isMzArray:
self.data[self.currentID]['mzEndian'] = endian
if precision:
self.data[self.currentID]['mzPrecision'] = int(precision)
elif self._isIntArray:
self.data[self.currentID]['intEndian'] = endian
if precision:
self.data[self.currentID]['intPrecision'] = int(precision)
# ----
def endElement(self, name):
"""Element ended."""
# stop reading mz data
if name == 'mzArrayBinary':
self._isMzArray = False
if not self.data[self.currentID]['mzData']:
self.data[self.currentID]['mzData'] = None
else:
self.data[self.currentID]['mzData'] = ''.join(self.data[self.currentID]['mzData'])
# stop reading int data
elif name == 'intenArrayBinary':
self._isIntArray = False
if not self.data[self.currentID]['intData']:
self.data[self.currentID]['intData'] = None
else:
self.data[self.currentID]['intData'] = ''.join(self.data[self.currentID]['intData'])
# ----
def characters(self, ch):
"""Grab characters."""
# get m/z array
if self._isMzArray:
self.data[self.currentID]['mzData'].append(ch)
# get intensity array
elif self._isIntArray:
self.data[self.currentID]['intData'].append(ch)
# ----
class stopParsing(Exception):
"""Exeption to stop parsing XML data."""
pass
|
gpl-3.0
|
[
3,
18852,
199,
3,
258,
1898,
334,
35,
9,
11811,
13,
6965,
603,
26788,
428,
1374,
19785,
77,
665,
1544,
14,
596,
405,
14,
1308,
30,
199,
199,
3,
258,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
258,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
258,
314,
2868,
2290,
2752,
27,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
258,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
199,
3,
258,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
258,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
258,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
1666,
314,
199,
3,
258,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
199,
3,
258,
28393,
1318,
402,
1664,
14629,
883,
506,
1911,
315,
314,
570,
5113,
14,
17715,
315,
314,
199,
3,
258,
2446,
2082,
402,
314,
2240,
14,
199,
3,
18852,
199,
199,
3,
2248,
20314,
199,
646,
2748,
14,
14338,
199,
646,
2748,
14,
4556,
14,
21827,
199,
646,
1300,
772,
199,
646,
2702,
199,
646,
747,
14,
515,
199,
646,
2680,
199,
504,
1331,
492,
14800,
199,
199,
3,
2248,
3631,
529,
199,
504,
3413,
63,
2379,
529,
492,
17654,
63,
27240,
63,
2328,
649,
199,
199,
3,
2248,
2251,
199,
646,
1559,
63,
8556,
199,
646,
1559,
63,
8556,
513,
199,
646,
1559,
63,
6282,
421,
199,
3,
10263,
899,
333,
90,
1451,
7126,
199,
3,
10652,
13,
199,
199,
533,
2198,
45,
58,
3998,
837,
272,
408,
4003,
666,
687,
333,
90,
1451,
1041,
2286,
347,
636,
826,
721,
277,
12,
931,
304,
267,
291,
14,
515,
275,
931,
267,
291,
423,
551,
796,
275,
488,
267,
291,
423,
6282,
513,
275,
488,
267,
291,
423,
815,
275,
488,
2728,
327,
1104,
931,
267,
340,
440,
747,
14,
515,
14,
2444,
8,
515,
304,
288,
746,
5925,
12,
283,
1173,
440,
1911,
1,
10541,
283,
435,
291,
14,
515,
272,
327,
4099,
17635,
347,
2248,
8,
277,
304,
267,
408,
6200,
1006,
4061,
796,
1901,
4402,
1041,
2728,
327,
4205,
1798,
267,
3016,
275,
1255,
2461,
342,
267,
1798,
275,
2748,
14,
14338,
14,
1875,
63,
2087,
342,
267,
1798,
14,
28680,
2461,
8,
2232,
9,
2728,
327,
2198,
2213,
267,
862,
26,
288,
2213,
275,
570,
8,
277,
14,
515,
9,
288,
1798,
14,
1122,
8,
3554,
9,
288,
2213,
14,
1600,
342,
288,
291,
423,
551,
796,
275,
3016,
14,
576,
267,
871,
2748,
14,
14338,
14,
4251,
56,
1726,
26,
288,
291,
423,
551,
796,
275,
756,
2728,
327,
1852,
8000,
513,
267,
340,
291,
423,
551,
796,
26,
288,
291,
423,
6282,
513,
275,
14800,
8,
277,
423,
551,
796,
9,
288,
367,
8000,
3259,
315,
291,
423,
6282,
513,
26,
355,
2150,
291,
423,
6282,
513,
59,
6282,
3259,
2733,
28808,
1451,
418,
355,
2150,
291,
423,
6282,
513,
59,
6282,
3259,
2733,
28808,
1327,
6268,
418,
355,
2150,
291,
423,
6282,
513,
59,
6282,
3259,
2733,
28808,
28984,
418,
355,
2150,
291,
423,
6282,
513,
59,
6282,
3259,
2733,
442,
1451,
418,
355,
2150,
291,
423,
6282,
513,
59,
6282,
3259,
2733,
442,
1327,
6268,
418,
355,
2150,
291,
423,
6282,
513,
59,
6282,
3259,
2733,
442,
28984,
418,
272,
327,
4099,
17635,
347,
2256,
8,
277,
304,
267,
408,
1002,
2213,
2256,
1041,
2728,
327,
664,
876,
4591,
666,
340,
2808,
267,
340,
291,
423,
815,
26,
288,
372,
291,
423,
815,
2728,
327,
4205,
1798,
267,
3016,
275,
2256,
2461,
342,
267,
1798,
275,
2748,
14,
14338,
14,
1875,
63,
2087,
342,
267,
1798,
14,
28680,
2461,
8,
2232,
9,
2728,
327,
2198,
2213,
267,
862,
26,
288,
2213,
275,
570,
8,
277,
14,
515,
9,
288,
1798,
14,
1122,
8,
3554,
9,
288,
2213,
14,
1600,
342,
267,
871,
3631,
17412,
26,
288,
291,
423,
815,
275,
3016,
14,
576,
267,
871,
2748,
14,
14338,
14,
4251,
56,
1726,
26,
288,
291,
423,
815,
275,
756,
2728,
372,
291,
423,
815,
272,
327,
4099,
17635,
347,
8000,
513,
8,
277,
304,
267,
408,
1002,
769,
402,
1006,
4061,
796,
315,
314,
2213,
1041,
2728,
327,
675,
876,
4591,
666,
340,
2808,
267,
340,
291,
423,
6282,
513,
26,
288,
372,
291,
423,
6282,
513,
2728,
327,
4205,
1798,
267,
3016,
275,
8000,
513,
2461,
342,
267,
1798,
275,
2748,
14,
14338,
14,
1875,
63,
2087,
342,
267,
1798,
14,
28680,
2461,
8,
2232,
9,
2728,
327,
2198,
2213,
267,
862,
26,
288,
2213,
275,
570,
8,
277,
14,
515,
9,
288,
1798,
14,
1122,
8,
3554,
9,
288,
2213,
14,
1600,
342,
288,
291,
423,
6282,
513,
275,
3016,
14,
576,
267,
871,
2748,
14,
14338,
14,
4251,
56,
1726,
26,
288,
291,
423,
6282,
513,
275,
756,
2728,
372,
291,
423,
6282,
513,
272,
327,
4099,
17635,
347,
8000,
8,
277,
12,
8000,
998,
29,
403,
304,
267,
408,
1002,
20645,
687,
2213,
1041,
2728,
327,
675,
876,
4591,
666,
340,
2808,
267,
340,
291,
423,
551,
796,
436,
8000,
998,
315,
291,
423,
551,
796,
26,
288,
666,
275,
291,
423,
551,
796,
59,
6282,
998,
61,
2728,
327,
2198,
570,
267,
587,
26,
288,
3016,
275,
8000,
2461,
8,
6282,
998,
9,
288,
1798,
275,
2748,
14,
14338,
14,
1875,
63,
2087,
342,
288,
1798,
14,
28680,
2461,
8,
2232,
9,
288,
862,
26,
355,
2213,
275,
570,
8,
277,
14,
515,
9,
355,
1798,
14,
1122,
8,
3554,
9,
355,
2213,
14,
1600,
342,
355,
666,
275,
3016,
14,
576,
288,
871,
3631,
17412,
26,
355,
666,
275,
3016,
14,
576,
288,
871,
2748,
14,
14338,
14,
4251,
56,
1726,
26,
355,
372,
756,
2728,
327,
1104,
666,
267,
340,
440,
666,
26,
288,
372,
756,
2728,
327,
372,
8000,
267,
372,
291,
423,
1875,
15936,
8,
576,
9,
272,
327,
4099,
17635,
347,
485,
1875,
15936,
8,
277,
12,
8000,
1451,
304,
267,
408,
5483,
8000,
909,
687,
3066,
666,
1041,
2728,
327,
2198,
31803,
267,
4501,
275,
291,
423,
1122,
10225
] |
[
18852,
199,
3,
258,
1898,
334,
35,
9,
11811,
13,
6965,
603,
26788,
428,
1374,
19785,
77,
665,
1544,
14,
596,
405,
14,
1308,
30,
199,
199,
3,
258,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
258,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
258,
314,
2868,
2290,
2752,
27,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
258,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
199,
3,
258,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
258,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
258,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
1666,
314,
199,
3,
258,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
199,
3,
258,
28393,
1318,
402,
1664,
14629,
883,
506,
1911,
315,
314,
570,
5113,
14,
17715,
315,
314,
199,
3,
258,
2446,
2082,
402,
314,
2240,
14,
199,
3,
18852,
199,
199,
3,
2248,
20314,
199,
646,
2748,
14,
14338,
199,
646,
2748,
14,
4556,
14,
21827,
199,
646,
1300,
772,
199,
646,
2702,
199,
646,
747,
14,
515,
199,
646,
2680,
199,
504,
1331,
492,
14800,
199,
199,
3,
2248,
3631,
529,
199,
504,
3413,
63,
2379,
529,
492,
17654,
63,
27240,
63,
2328,
649,
199,
199,
3,
2248,
2251,
199,
646,
1559,
63,
8556,
199,
646,
1559,
63,
8556,
513,
199,
646,
1559,
63,
6282,
421,
199,
3,
10263,
899,
333,
90,
1451,
7126,
199,
3,
10652,
13,
199,
199,
533,
2198,
45,
58,
3998,
837,
272,
408,
4003,
666,
687,
333,
90,
1451,
1041,
2286,
347,
636,
826,
721,
277,
12,
931,
304,
267,
291,
14,
515,
275,
931,
267,
291,
423,
551,
796,
275,
488,
267,
291,
423,
6282,
513,
275,
488,
267,
291,
423,
815,
275,
488,
2728,
327,
1104,
931,
267,
340,
440,
747,
14,
515,
14,
2444,
8,
515,
304,
288,
746,
5925,
12,
283,
1173,
440,
1911,
1,
10541,
283,
435,
291,
14,
515,
272,
327,
4099,
17635,
347,
2248,
8,
277,
304,
267,
408,
6200,
1006,
4061,
796,
1901,
4402,
1041,
2728,
327,
4205,
1798,
267,
3016,
275,
1255,
2461,
342,
267,
1798,
275,
2748,
14,
14338,
14,
1875,
63,
2087,
342,
267,
1798,
14,
28680,
2461,
8,
2232,
9,
2728,
327,
2198,
2213,
267,
862,
26,
288,
2213,
275,
570,
8,
277,
14,
515,
9,
288,
1798,
14,
1122,
8,
3554,
9,
288,
2213,
14,
1600,
342,
288,
291,
423,
551,
796,
275,
3016,
14,
576,
267,
871,
2748,
14,
14338,
14,
4251,
56,
1726,
26,
288,
291,
423,
551,
796,
275,
756,
2728,
327,
1852,
8000,
513,
267,
340,
291,
423,
551,
796,
26,
288,
291,
423,
6282,
513,
275,
14800,
8,
277,
423,
551,
796,
9,
288,
367,
8000,
3259,
315,
291,
423,
6282,
513,
26,
355,
2150,
291,
423,
6282,
513,
59,
6282,
3259,
2733,
28808,
1451,
418,
355,
2150,
291,
423,
6282,
513,
59,
6282,
3259,
2733,
28808,
1327,
6268,
418,
355,
2150,
291,
423,
6282,
513,
59,
6282,
3259,
2733,
28808,
28984,
418,
355,
2150,
291,
423,
6282,
513,
59,
6282,
3259,
2733,
442,
1451,
418,
355,
2150,
291,
423,
6282,
513,
59,
6282,
3259,
2733,
442,
1327,
6268,
418,
355,
2150,
291,
423,
6282,
513,
59,
6282,
3259,
2733,
442,
28984,
418,
272,
327,
4099,
17635,
347,
2256,
8,
277,
304,
267,
408,
1002,
2213,
2256,
1041,
2728,
327,
664,
876,
4591,
666,
340,
2808,
267,
340,
291,
423,
815,
26,
288,
372,
291,
423,
815,
2728,
327,
4205,
1798,
267,
3016,
275,
2256,
2461,
342,
267,
1798,
275,
2748,
14,
14338,
14,
1875,
63,
2087,
342,
267,
1798,
14,
28680,
2461,
8,
2232,
9,
2728,
327,
2198,
2213,
267,
862,
26,
288,
2213,
275,
570,
8,
277,
14,
515,
9,
288,
1798,
14,
1122,
8,
3554,
9,
288,
2213,
14,
1600,
342,
267,
871,
3631,
17412,
26,
288,
291,
423,
815,
275,
3016,
14,
576,
267,
871,
2748,
14,
14338,
14,
4251,
56,
1726,
26,
288,
291,
423,
815,
275,
756,
2728,
372,
291,
423,
815,
272,
327,
4099,
17635,
347,
8000,
513,
8,
277,
304,
267,
408,
1002,
769,
402,
1006,
4061,
796,
315,
314,
2213,
1041,
2728,
327,
675,
876,
4591,
666,
340,
2808,
267,
340,
291,
423,
6282,
513,
26,
288,
372,
291,
423,
6282,
513,
2728,
327,
4205,
1798,
267,
3016,
275,
8000,
513,
2461,
342,
267,
1798,
275,
2748,
14,
14338,
14,
1875,
63,
2087,
342,
267,
1798,
14,
28680,
2461,
8,
2232,
9,
2728,
327,
2198,
2213,
267,
862,
26,
288,
2213,
275,
570,
8,
277,
14,
515,
9,
288,
1798,
14,
1122,
8,
3554,
9,
288,
2213,
14,
1600,
342,
288,
291,
423,
6282,
513,
275,
3016,
14,
576,
267,
871,
2748,
14,
14338,
14,
4251,
56,
1726,
26,
288,
291,
423,
6282,
513,
275,
756,
2728,
372,
291,
423,
6282,
513,
272,
327,
4099,
17635,
347,
8000,
8,
277,
12,
8000,
998,
29,
403,
304,
267,
408,
1002,
20645,
687,
2213,
1041,
2728,
327,
675,
876,
4591,
666,
340,
2808,
267,
340,
291,
423,
551,
796,
436,
8000,
998,
315,
291,
423,
551,
796,
26,
288,
666,
275,
291,
423,
551,
796,
59,
6282,
998,
61,
2728,
327,
2198,
570,
267,
587,
26,
288,
3016,
275,
8000,
2461,
8,
6282,
998,
9,
288,
1798,
275,
2748,
14,
14338,
14,
1875,
63,
2087,
342,
288,
1798,
14,
28680,
2461,
8,
2232,
9,
288,
862,
26,
355,
2213,
275,
570,
8,
277,
14,
515,
9,
355,
1798,
14,
1122,
8,
3554,
9,
355,
2213,
14,
1600,
342,
355,
666,
275,
3016,
14,
576,
288,
871,
3631,
17412,
26,
355,
666,
275,
3016,
14,
576,
288,
871,
2748,
14,
14338,
14,
4251,
56,
1726,
26,
355,
372,
756,
2728,
327,
1104,
666,
267,
340,
440,
666,
26,
288,
372,
756,
2728,
327,
372,
8000,
267,
372,
291,
423,
1875,
15936,
8,
576,
9,
272,
327,
4099,
17635,
347,
485,
1875,
15936,
8,
277,
12,
8000,
1451,
304,
267,
408,
5483,
8000,
909,
687,
3066,
666,
1041,
2728,
327,
2198,
31803,
267,
4501,
275,
291,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
1,
1,
1,
1,
1,
1
] |
ychfan/tensorflow
|
tensorflow/contrib/learn/python/learn/ops/embeddings_ops.py
|
116
|
3510
|
# 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.
# ==============================================================================
"""TensorFlow Ops to work with embeddings.
Note: categorical variables are handled via embeddings in many cases.
For example, in case of words.
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from tensorflow.contrib.framework import deprecated
from tensorflow.python.framework import ops
from tensorflow.python.ops import array_ops as array_ops_
from tensorflow.python.ops import math_ops
from tensorflow.python.ops import nn
from tensorflow.python.ops import variable_scope as vs
@deprecated('2016-12-01', 'Use `tf.embedding_lookup` instead.')
def embedding_lookup(params, ids, name='embedding_lookup'):
"""Provides a N dimensional version of tf.embedding_lookup.
Ids are flattened to a 1d tensor before being passed to embedding_lookup
then, they are unflattend to match the original ids shape plus an extra
leading dimension of the size of the embeddings.
Args:
params: List of tensors of size D0 x D1 x ... x Dn-2 x Dn-1.
ids: N-dimensional tensor of B0 x B1 x .. x Bn-2 x Bn-1.
Must contain indexes into params.
name: Optional name for the op.
Returns:
A tensor of size B0 x B1 x .. x Bn-2 x Bn-1 x D1 x ... x Dn-2 x Dn-1
containing the values from the params tensor(s) for indecies in ids.
Raises:
ValueError: if some parameters are invalid.
"""
with ops.name_scope(name, 'embedding_lookup', [params, ids]):
params = ops.convert_to_tensor(params)
ids = ops.convert_to_tensor(ids)
shape = array_ops_.shape(ids)
ids_flat = array_ops_.reshape(
ids, math_ops.reduce_prod(shape, keep_dims=True))
embeds_flat = nn.embedding_lookup(params, ids_flat, name)
embed_shape = array_ops_.concat([shape, [-1]], 0)
embeds = array_ops_.reshape(embeds_flat, embed_shape)
embeds.set_shape(ids.get_shape().concatenate(params.get_shape()[1:]))
return embeds
@deprecated('2016-12-01', 'Use `tf.contrib.layers.embed_sequence` instead.')
def categorical_variable(tensor_in, n_classes, embedding_size, name):
"""Creates an embedding for categorical variable with given number of classes.
Args:
tensor_in: Input tensor with class identifier (can be batch or
N-dimensional).
n_classes: Number of classes.
embedding_size: Size of embedding vector to represent each class.
name: Name of this categorical variable.
Returns:
Tensor of input shape, with additional dimension for embedding.
Example:
Calling categorical_variable([1, 2], 5, 10, "my_cat"), will return 2 x 10
tensor, where each row is representation of the class.
"""
with vs.variable_scope(name):
embeddings = vs.get_variable(name + '_embeddings',
[n_classes, embedding_size])
return embedding_lookup(embeddings, tensor_in)
|
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,
199,
624,
26998,
593,
1190,
370,
1736,
543,
6441,
21270,
14,
199,
199,
7443,
26,
22138,
2860,
787,
8860,
4799,
6441,
21270,
315,
5002,
5560,
14,
199,
1858,
2893,
12,
315,
1930,
402,
5932,
14,
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,
504,
3228,
14,
2828,
14,
4857,
492,
5906,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4156,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1625,
63,
1483,
465,
1625,
63,
1483,
63,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3473,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
11542,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1750,
63,
2645,
465,
8118,
421,
199,
32,
6667,
360,
9261,
13,
713,
13,
614,
297,
283,
6119,
658,
3249,
14,
14275,
63,
3892,
64,
3140,
2659,
199,
318,
12452,
63,
3892,
8,
1162,
12,
2762,
12,
536,
534,
14275,
63,
3892,
735,
523,
408,
17473,
282,
653,
28341,
1015,
402,
2833,
14,
14275,
63,
3892,
14,
819,
473,
795,
787,
18767,
370,
282,
413,
68,
2345,
2544,
3769,
3032,
370,
12452,
63,
3892,
523,
2066,
12,
2985,
787,
625,
8487,
68,
370,
1336,
314,
3379,
2762,
2215,
12254,
376,
2402,
523,
9186,
6240,
402,
314,
1568,
402,
314,
6441,
21270,
14,
819,
3033,
26,
272,
1862,
26,
3820,
402,
10519,
402,
1568,
577,
16,
671,
577,
17,
671,
2263,
671,
577,
78,
13,
18,
671,
577,
78,
13,
17,
14,
272,
2762,
26,
653,
13,
13014,
2345,
402,
699,
16,
671,
699,
17,
671,
2508,
671,
699,
78,
13,
18,
671,
699,
78,
13,
17,
14,
489,
9498,
1395,
10507,
1901,
1862,
14,
272,
536,
26,
4879,
536,
367,
314,
1687,
14,
819,
1803,
26,
272,
437,
2345,
402,
1568,
699,
16,
671,
699,
17,
671,
2508,
671,
699,
78,
13,
18,
671,
699,
78,
13,
17,
671,
577,
17,
671,
2263,
671,
577,
78,
13,
18,
671,
577,
78,
13,
17,
272,
3035,
314,
1338,
687,
314,
1862,
2345,
8,
83,
9,
367,
31043,
2578,
315,
2762,
14,
819,
6218,
26,
272,
1722,
26,
340,
2005,
2633,
787,
3866,
14,
523,
408,
523,
543,
4156,
14,
354,
63,
2645,
8,
354,
12,
283,
14275,
63,
3892,
297,
359,
1162,
12,
2762,
4682,
272,
1862,
275,
4156,
14,
3916,
63,
475,
63,
3128,
8,
1162,
9,
272,
2762,
275,
4156,
14,
3916,
63,
475,
63,
3128,
8,
1580,
9,
272,
2215,
275,
1625,
63,
1483,
3754,
1392,
8,
1580,
9,
272,
2762,
63,
7088,
275,
1625,
63,
1483,
3754,
5217,
8,
267,
2762,
12,
3473,
63,
1483,
14,
5270,
63,
8788,
8,
1392,
12,
4215,
63,
5380,
29,
549,
430,
272,
6441,
83,
63,
7088,
275,
11542,
14,
14275,
63,
3892,
8,
1162,
12,
2762,
63,
7088,
12,
536,
9,
272,
6441,
63,
1392,
275,
1625,
63,
1483,
3754,
9419,
779,
1392,
12,
5243,
17,
2365,
378,
9,
272,
6441,
83,
275,
1625,
63,
1483,
3754,
5217,
8,
6427,
83,
63,
7088,
12,
6441,
63,
1392,
9,
272,
6441,
83,
14,
409,
63,
1392,
8,
1580,
14,
362,
63,
1392,
1252,
13433,
8,
1162,
14,
362,
63,
1392,
3430,
17,
16720,
272,
372,
6441,
83,
421,
199,
32,
6667,
360,
9261,
13,
713,
13,
614,
297,
283,
6119,
658,
3249,
14,
2828,
14,
4359,
14,
6427,
63,
4041,
64,
3140,
2659,
199,
318,
22138,
63,
1975,
8,
3128,
63,
262,
12,
302,
63,
2888,
12,
12452,
63,
890,
12,
536,
304,
523,
408,
10607,
376,
12452,
367,
22138,
1750,
543,
1627,
1329,
402,
3992,
14,
819,
3033,
26,
272,
2345,
63,
262,
26,
6924,
2345,
543,
1021,
5148,
334,
2425,
506,
3522,
503,
489,
653,
13,
13014,
680,
272,
302,
63,
2888,
26,
4860,
402,
3992,
14,
272,
12452,
63,
890,
26,
14579,
402,
12452,
5477,
370,
2954,
1924,
1021,
14,
272,
536,
26,
2812,
402,
642,
22138,
1750,
14,
523,
1803,
26,
272,
5878,
402,
1324,
2215,
12,
543,
4722,
6240,
367,
12452,
14,
819,
5679,
26,
272,
23892,
22138,
63,
1975,
779,
17,
12,
499,
467,
959,
12,
1616,
12,
298,
1662,
63,
3385,
1288,
911,
372,
499,
671,
1616,
272,
2345,
12,
2382,
1924,
1962,
365,
6025,
402,
314,
1021,
14,
523,
408,
523,
543,
8118,
14,
1975,
63,
2645,
8,
354,
304,
272,
6441,
21270,
275,
8118,
14,
362,
63,
1975,
8,
354,
435,
2513,
32719,
297,
639,
359,
78,
63,
2888,
12,
12452,
63,
890,
566,
272,
372,
12452,
63,
3892,
8,
32719,
12,
2345,
63,
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,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
7800,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
199,
624,
26998,
593,
1190,
370,
1736,
543,
6441,
21270,
14,
199,
199,
7443,
26,
22138,
2860,
787,
8860,
4799,
6441,
21270,
315,
5002,
5560,
14,
199,
1858,
2893,
12,
315,
1930,
402,
5932,
14,
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,
504,
3228,
14,
2828,
14,
4857,
492,
5906,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4156,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1625,
63,
1483,
465,
1625,
63,
1483,
63,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3473,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
11542,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1750,
63,
2645,
465,
8118,
421,
199,
32,
6667,
360,
9261,
13,
713,
13,
614,
297,
283,
6119,
658,
3249,
14,
14275,
63,
3892,
64,
3140,
2659,
199,
318,
12452,
63,
3892,
8,
1162,
12,
2762,
12,
536,
534,
14275,
63,
3892,
735,
523,
408,
17473,
282,
653,
28341,
1015,
402,
2833,
14,
14275,
63,
3892,
14,
819,
473,
795,
787,
18767,
370,
282,
413,
68,
2345,
2544,
3769,
3032,
370,
12452,
63,
3892,
523,
2066,
12,
2985,
787,
625,
8487,
68,
370,
1336,
314,
3379,
2762,
2215,
12254,
376,
2402,
523,
9186,
6240,
402,
314,
1568,
402,
314,
6441,
21270,
14,
819,
3033,
26,
272,
1862,
26,
3820,
402,
10519,
402,
1568,
577,
16,
671,
577,
17,
671,
2263,
671,
577,
78,
13,
18,
671,
577,
78,
13,
17,
14,
272,
2762,
26,
653,
13,
13014,
2345,
402,
699,
16,
671,
699,
17,
671,
2508,
671,
699,
78,
13,
18,
671,
699,
78,
13,
17,
14,
489,
9498,
1395,
10507,
1901,
1862,
14,
272,
536,
26,
4879,
536,
367,
314,
1687,
14,
819,
1803,
26,
272,
437,
2345,
402,
1568,
699,
16,
671,
699,
17,
671,
2508,
671,
699,
78,
13,
18,
671,
699,
78,
13,
17,
671,
577,
17,
671,
2263,
671,
577,
78,
13,
18,
671,
577,
78,
13,
17,
272,
3035,
314,
1338,
687,
314,
1862,
2345,
8,
83,
9,
367,
31043,
2578,
315,
2762,
14,
819,
6218,
26,
272,
1722,
26,
340,
2005,
2633,
787,
3866,
14,
523,
408,
523,
543,
4156,
14,
354,
63,
2645,
8,
354,
12,
283,
14275,
63,
3892,
297,
359,
1162,
12,
2762,
4682,
272,
1862,
275,
4156,
14,
3916,
63,
475,
63,
3128,
8,
1162,
9,
272,
2762,
275,
4156,
14,
3916,
63,
475,
63,
3128,
8,
1580,
9,
272,
2215,
275,
1625,
63,
1483,
3754,
1392,
8,
1580,
9,
272,
2762,
63,
7088,
275,
1625,
63,
1483,
3754,
5217,
8,
267,
2762,
12,
3473,
63,
1483,
14,
5270,
63,
8788,
8,
1392,
12,
4215,
63,
5380,
29,
549,
430,
272,
6441,
83,
63,
7088,
275,
11542,
14,
14275,
63,
3892,
8,
1162,
12,
2762,
63,
7088,
12,
536,
9,
272,
6441,
63,
1392,
275,
1625,
63,
1483,
3754,
9419,
779,
1392,
12,
5243,
17,
2365,
378,
9,
272,
6441,
83,
275,
1625,
63,
1483,
3754,
5217,
8,
6427,
83,
63,
7088,
12,
6441,
63,
1392,
9,
272,
6441,
83,
14,
409,
63,
1392,
8,
1580,
14,
362,
63,
1392,
1252,
13433,
8,
1162,
14,
362,
63,
1392,
3430,
17,
16720,
272,
372,
6441,
83,
421,
199,
32,
6667,
360,
9261,
13,
713,
13,
614,
297,
283,
6119,
658,
3249,
14,
2828,
14,
4359,
14,
6427,
63,
4041,
64,
3140,
2659,
199,
318,
22138,
63,
1975,
8,
3128,
63,
262,
12,
302,
63,
2888,
12,
12452,
63,
890,
12,
536,
304,
523,
408,
10607,
376,
12452,
367,
22138,
1750,
543,
1627,
1329,
402,
3992,
14,
819,
3033,
26,
272,
2345,
63,
262,
26,
6924,
2345,
543,
1021,
5148,
334,
2425,
506,
3522,
503,
489,
653,
13,
13014,
680,
272,
302,
63,
2888,
26,
4860,
402,
3992,
14,
272,
12452,
63,
890,
26,
14579,
402,
12452,
5477,
370,
2954,
1924,
1021,
14,
272,
536,
26,
2812,
402,
642,
22138,
1750,
14,
523,
1803,
26,
272,
5878,
402,
1324,
2215,
12,
543,
4722,
6240,
367,
12452,
14,
819,
5679,
26,
272,
23892,
22138,
63,
1975,
779,
17,
12,
499,
467,
959,
12,
1616,
12,
298,
1662,
63,
3385,
1288,
911,
372,
499,
671,
1616,
272,
2345,
12,
2382,
1924,
1962,
365,
6025,
402,
314,
1021,
14,
523,
408,
523,
543,
8118,
14,
1975,
63,
2645,
8,
354,
304,
272,
6441,
21270,
275,
8118,
14,
362,
63,
1975,
8,
354,
435,
2513,
32719,
297,
639,
359,
78,
63,
2888,
12,
12452,
63,
890,
566,
272,
372,
12452,
63,
3892,
8,
32719,
12,
2345,
63,
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,
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,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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
] |
costingalan/python-lab
|
python/solutii/anda_ungureanu/caesar.py
|
7
|
2061
|
#!/usr/bin/env python
# *-* coding: UTF-8 *-*
"""Împăratul a primit serie de mesaje importante pe care este
important să le descifreze cât mai repede.
Din păcate mesagerul nu a apucat să îi spună împăratul care au fost
cheile alese pentru fiecare mesaj si tu ai fost ales să descifrezi
misterul.
Informatii:
În criptografie, cifrul lui Caesar este o metodă simplă de a cripta
un mesaj prin înlocuirea fiecărei litere cu litera de pe pozitia aflată
la un n pasi de ea în alfabet (unde este n este un număr întreg cunoscut
"""
from __future__ import print_function
def decripteaza(mesaj):
"""
Functi primeste ca parametru o linie de mesaj ce trebuie decriptat
si un numar. Fiecare litera este inlocuita cu cea de la numarul
intorduse pasi in urma. Cand se gaseste cuvantul "ave" randul este
considerat valid si mesajul este afisat, altfel este incrementat
numarul de pasi.
"""
nr_pasi = 0
mess = ['']
mess_final = " "
while "ave" not in mess_final:
for litera in mesaj:
if litera.isalpha():
if (ord(litera) - nr_pasi >= 97 and
ord(litera) - nr_pasi <= 122):
litera_m = chr(ord(litera)-nr_pasi)
else:
litera_m = chr(122-(nr_pasi-(ord(litera)-97)-1))
mess.append(litera_m)
else:
mess.append(litera)
mess_final = "".join(mess)
if 'ave' not in mess_final:
mess = ['']
mess_final = " "
nr_pasi = nr_pasi+1
print(mess_final)
def main():
"""
Se incearca deschiderea fisierului de intrare, daca operatia este
executata cu succes, se apeleaza functia de decriptare.
"""
try:
fisier = open("mesaje.secret", "r")
mesaje = fisier.read()
fisier.close()
except IOError:
print("Nu am putut obtine mesajele.")
return
for mesaj in mesaje.splitlines():
decripteaza(mesaj)
if __name__ == "__main__":
main()
|
mit
|
[
172,
120,
124,
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
627,
13,
10,
2803,
26,
9094,
13,
24,
627,
13,
10,
199,
199,
624,
128,
237,
311,
129,
226,
17565,
348,
282,
1979,
1147,
542,
11317,
477,
562,
2231,
6532,
492,
8949,
4837,
10296,
325,
1597,
199,
19559,
308,
129,
226,
1026,
4328,
692,
264,
806,
286,
128,
96,
84,
610,
73,
6375,
271,
14,
199,
36,
262,
299,
129,
226,
1411,
26560,
1456,
348,
15699,
282,
2771,
947,
292,
308,
129,
226,
13333,
107,
73,
2249,
324,
129,
226,
13333,
107,
311,
129,
226,
17565,
348,
10296,
10576,
289,
941,
199,
595,
441,
30960,
261,
12374,
454,
85,
289,
1873,
28654,
562,
2231,
74,
13877,
30799,
15933,
289,
941,
282,
2978,
308,
129,
226,
4328,
692,
264,
16079,
199,
1292,
351,
348,
14,
199,
607,
10928,
280,
73,
26,
272,
13333,
237,
78,
27825,
5816,
926,
329,
69,
12,
286,
692,
82,
348,
634,
1907,
8790,
397,
285,
325,
1597,
312,
562,
5766,
129,
226,
308,
5472,
129,
226,
477,
282,
286,
24210,
502,
199,
324,
562,
2231,
74,
5448,
262,
13333,
107,
78,
2102,
1907,
8273,
5883,
825,
129,
226,
264,
73,
1212,
266,
264,
30353,
1212,
2967,
477,
4837,
1115,
90,
5277,
65,
282,
7088,
129,
226,
199,
416,
625,
302,
19099,
73,
477,
24867,
13333,
107,
78,
282,
276,
17734,
334,
324,
271,
325,
1597,
302,
325,
1597,
625,
1967,
129,
226,
82,
13333,
107,
343,
1135,
286,
324,
26737,
337,
199,
624,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
421,
199,
318,
477,
1408,
80,
266,
4651,
65,
8,
27871,
74,
304,
272,
408,
272,
28794,
280,
21619,
1597,
1704,
18117,
454,
85,
312,
7403,
1873,
477,
562,
2231,
74,
10142,
20991,
464,
1873,
477,
1669,
292,
272,
13877,
625,
1967,
285,
14,
481,
1873,
28654,
1212,
2967,
325,
1597,
315,
2102,
4993,
65,
30353,
286,
4489,
477,
1127,
1967,
285,
348,
272,
1109,
2181,
1180,
19099,
73,
315,
7629,
391,
14,
445,
460,
542,
486,
482,
1597,
286,
9154,
867,
348,
298,
811,
2,
10261,
348,
325,
1597,
272,
11201,
292,
1686,
13877,
562,
2231,
74,
348,
325,
1597,
282,
329,
14997,
12,
741,
3249,
352,
325,
1597,
11609,
292,
272,
1967,
285,
348,
477,
19099,
73,
14,
272,
408,
272,
14762,
63,
15534,
73,
275,
378,
272,
15634,
275,
24506,
272,
15634,
63,
5094,
275,
298,
298,
272,
1830,
298,
811,
2,
440,
315,
15634,
63,
5094,
26,
267,
367,
1212,
2967,
315,
562,
2231,
74,
26,
288,
340,
1212,
2967,
14,
374,
4468,
837,
355,
340,
334,
2181,
8,
317,
2967,
9,
446,
14762,
63,
15534,
73,
2356,
15997,
436,
717,
6206,
8,
317,
2967,
9,
446,
14762,
63,
15534,
73,
2695,
24557,
304,
490,
1212,
2967,
63,
77,
275,
8678,
8,
2181,
8,
317,
2967,
7216,
7865,
63,
15534,
73,
9,
355,
587,
26,
490,
1212,
2967,
63,
77,
275,
8678,
8,
7507,
15426,
7865,
63,
15534,
73,
15426,
2181,
8,
317,
2967,
7216,
2576,
7216,
17,
430,
355,
15634,
14,
740,
8,
317,
2967,
63,
77,
9,
288,
587,
26,
355,
15634,
14,
740,
8,
317,
2967,
9,
267,
15634,
63,
5094,
275,
10587,
904,
8,
17091,
9,
267,
340,
283,
811,
7,
440,
315,
15634,
63,
5094,
26,
288,
15634,
275,
24506,
288,
15634,
63,
5094,
275,
298,
298,
288,
14762,
63,
15534,
73,
275,
14762,
63,
15534,
73,
11,
17,
272,
870,
8,
17091,
63,
5094,
9,
421,
199,
318,
2446,
837,
272,
408,
272,
3240,
315,
301,
285,
696,
477,
15820,
2655,
8273,
5883,
338,
281,
348,
1907,
477,
1109,
345,
264,
12,
366,
30632,
1758,
2159,
65,
325,
1597,
272,
2146,
337,
419,
30353,
27028,
12,
542,
282,
321,
274,
4651,
65,
2562,
14037,
477,
477,
1408,
80,
502,
264,
14,
272,
408,
272,
862,
26,
267,
5883,
338,
281,
275,
1551,
480,
27871,
6532,
14,
4731,
401,
298,
82,
531,
267,
562,
2231,
6532,
275,
5883,
338,
281,
14,
739,
342,
267,
5883,
338,
281,
14,
1600,
342,
272,
871,
5925,
26,
267,
870,
480,
21988,
8140,
5324,
337,
2607,
84,
1132,
562,
2231,
6532,
274,
2685,
267,
372,
339,
367,
562,
2231,
74,
315,
562,
2231,
6532,
14,
7644,
837,
267,
477,
1408,
80,
266,
4651,
65,
8,
27871,
74,
9,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
2446,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
120,
124,
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
627,
13,
10,
2803,
26,
9094,
13,
24,
627,
13,
10,
199,
199,
624,
128,
237,
311,
129,
226,
17565,
348,
282,
1979,
1147,
542,
11317,
477,
562,
2231,
6532,
492,
8949,
4837,
10296,
325,
1597,
199,
19559,
308,
129,
226,
1026,
4328,
692,
264,
806,
286,
128,
96,
84,
610,
73,
6375,
271,
14,
199,
36,
262,
299,
129,
226,
1411,
26560,
1456,
348,
15699,
282,
2771,
947,
292,
308,
129,
226,
13333,
107,
73,
2249,
324,
129,
226,
13333,
107,
311,
129,
226,
17565,
348,
10296,
10576,
289,
941,
199,
595,
441,
30960,
261,
12374,
454,
85,
289,
1873,
28654,
562,
2231,
74,
13877,
30799,
15933,
289,
941,
282,
2978,
308,
129,
226,
4328,
692,
264,
16079,
199,
1292,
351,
348,
14,
199,
607,
10928,
280,
73,
26,
272,
13333,
237,
78,
27825,
5816,
926,
329,
69,
12,
286,
692,
82,
348,
634,
1907,
8790,
397,
285,
325,
1597,
312,
562,
5766,
129,
226,
308,
5472,
129,
226,
477,
282,
286,
24210,
502,
199,
324,
562,
2231,
74,
5448,
262,
13333,
107,
78,
2102,
1907,
8273,
5883,
825,
129,
226,
264,
73,
1212,
266,
264,
30353,
1212,
2967,
477,
4837,
1115,
90,
5277,
65,
282,
7088,
129,
226,
199,
416,
625,
302,
19099,
73,
477,
24867,
13333,
107,
78,
282,
276,
17734,
334,
324,
271,
325,
1597,
302,
325,
1597,
625,
1967,
129,
226,
82,
13333,
107,
343,
1135,
286,
324,
26737,
337,
199,
624,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
421,
199,
318,
477,
1408,
80,
266,
4651,
65,
8,
27871,
74,
304,
272,
408,
272,
28794,
280,
21619,
1597,
1704,
18117,
454,
85,
312,
7403,
1873,
477,
562,
2231,
74,
10142,
20991,
464,
1873,
477,
1669,
292,
272,
13877,
625,
1967,
285,
14,
481,
1873,
28654,
1212,
2967,
325,
1597,
315,
2102,
4993,
65,
30353,
286,
4489,
477,
1127,
1967,
285,
348,
272,
1109,
2181,
1180,
19099,
73,
315,
7629,
391,
14,
445,
460,
542,
486,
482,
1597,
286,
9154,
867,
348,
298,
811,
2,
10261,
348,
325,
1597,
272,
11201,
292,
1686,
13877,
562,
2231,
74,
348,
325,
1597,
282,
329,
14997,
12,
741,
3249,
352,
325,
1597,
11609,
292,
272,
1967,
285,
348,
477,
19099,
73,
14,
272,
408,
272,
14762,
63,
15534,
73,
275,
378,
272,
15634,
275,
24506,
272,
15634,
63,
5094,
275,
298,
298,
272,
1830,
298,
811,
2,
440,
315,
15634,
63,
5094,
26,
267,
367,
1212,
2967,
315,
562,
2231,
74,
26,
288,
340,
1212,
2967,
14,
374,
4468,
837,
355,
340,
334,
2181,
8,
317,
2967,
9,
446,
14762,
63,
15534,
73,
2356,
15997,
436,
717,
6206,
8,
317,
2967,
9,
446,
14762,
63,
15534,
73,
2695,
24557,
304,
490,
1212,
2967,
63,
77,
275,
8678,
8,
2181,
8,
317,
2967,
7216,
7865,
63,
15534,
73,
9,
355,
587,
26,
490,
1212,
2967,
63,
77,
275,
8678,
8,
7507,
15426,
7865,
63,
15534,
73,
15426,
2181,
8,
317,
2967,
7216,
2576,
7216,
17,
430,
355,
15634,
14,
740,
8,
317,
2967,
63,
77,
9,
288,
587,
26,
355,
15634,
14,
740,
8,
317,
2967,
9,
267,
15634,
63,
5094,
275,
10587,
904,
8,
17091,
9,
267,
340,
283,
811,
7,
440,
315,
15634,
63,
5094,
26,
288,
15634,
275,
24506,
288,
15634,
63,
5094,
275,
298,
298,
288,
14762,
63,
15534,
73,
275,
14762,
63,
15534,
73,
11,
17,
272,
870,
8,
17091,
63,
5094,
9,
421,
199,
318,
2446,
837,
272,
408,
272,
3240,
315,
301,
285,
696,
477,
15820,
2655,
8273,
5883,
338,
281,
348,
1907,
477,
1109,
345,
264,
12,
366,
30632,
1758,
2159,
65,
325,
1597,
272,
2146,
337,
419,
30353,
27028,
12,
542,
282,
321,
274,
4651,
65,
2562,
14037,
477,
477,
1408,
80,
502,
264,
14,
272,
408,
272,
862,
26,
267,
5883,
338,
281,
275,
1551,
480,
27871,
6532,
14,
4731,
401,
298,
82,
531,
267,
562,
2231,
6532,
275,
5883,
338,
281,
14,
739,
342,
267,
5883,
338,
281,
14,
1600,
342,
272,
871,
5925,
26,
267,
870,
480,
21988,
8140,
5324,
337,
2607,
84,
1132,
562,
2231,
6532,
274,
2685,
267,
372,
339,
367,
562,
2231,
74,
315,
562,
2231,
6532,
14,
7644,
837,
267,
477,
1408,
80,
266,
4651,
65,
8,
27871,
74,
9,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
2446,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
vprime/puuuu
|
env/lib/python2.7/site-packages/django/contrib/sitemaps/tests/urls/http.py
|
106
|
1647
|
from datetime import datetime
from django.conf.urls import patterns, url
from django.contrib.sitemaps import Sitemap, GenericSitemap, FlatPageSitemap, views
from django.views.decorators.cache import cache_page
from django.contrib.sitemaps.tests.base import TestModel
class SimpleSitemap(Sitemap):
changefreq = "never"
priority = 0.5
location = '/location/'
lastmod = datetime.now()
def items(self):
return [object()]
simple_sitemaps = {
'simple': SimpleSitemap,
}
generic_sitemaps = {
'generic': GenericSitemap({'queryset': TestModel.objects.all()}),
}
flatpage_sitemaps = {
'flatpages': FlatPageSitemap,
}
urlpatterns = patterns('django.contrib.sitemaps.views',
(r'^simple/index\.xml$', 'index', {'sitemaps': simple_sitemaps}),
(r'^simple/custom-index\.xml$', 'index',
{'sitemaps': simple_sitemaps, 'template_name': 'custom_sitemap_index.xml'}),
(r'^simple/sitemap-(?P<section>.+)\.xml$', 'sitemap',
{'sitemaps': simple_sitemaps}),
(r'^simple/sitemap\.xml$', 'sitemap', {'sitemaps': simple_sitemaps}),
(r'^simple/custom-sitemap\.xml$', 'sitemap',
{'sitemaps': simple_sitemaps, 'template_name': 'custom_sitemap.xml'}),
(r'^generic/sitemap\.xml$', 'sitemap', {'sitemaps': generic_sitemaps}),
(r'^flatpages/sitemap\.xml$', 'sitemap', {'sitemaps': flatpage_sitemaps}),
url(r'^cached/index\.xml$', cache_page(1)(views.index),
{'sitemaps': simple_sitemaps, 'sitemap_url_name': 'cached_sitemap'}),
url(r'^cached/sitemap-(?P<section>.+)\.xml', cache_page(1)(views.sitemap),
{'sitemaps': simple_sitemaps}, name='cached_sitemap')
)
|
mit
|
[
504,
2197,
492,
2197,
199,
504,
1639,
14,
2190,
14,
3603,
492,
7970,
12,
1166,
199,
504,
1639,
14,
2828,
14,
30515,
492,
11666,
1130,
12,
8307,
8972,
1130,
12,
19005,
3276,
8972,
1130,
12,
6858,
199,
504,
1639,
14,
4196,
14,
11582,
14,
1637,
492,
2581,
63,
1606,
199,
199,
504,
1639,
14,
2828,
14,
30515,
14,
2219,
14,
1095,
492,
1379,
1685,
421,
199,
533,
5870,
8972,
1130,
8,
8972,
1130,
304,
272,
1570,
5646,
275,
298,
18178,
2,
272,
7464,
275,
378,
14,
21,
272,
2909,
275,
1994,
1985,
4805,
272,
2061,
1494,
275,
2197,
14,
2131,
342,
339,
347,
2974,
8,
277,
304,
267,
372,
359,
785,
5106,
199,
199,
4129,
63,
30515,
275,
469,
272,
283,
4129,
356,
5870,
8972,
1130,
12,
199,
93,
199,
199,
6767,
63,
30515,
275,
469,
272,
283,
6767,
356,
8307,
8972,
1130,
3252,
7924,
356,
1379,
1685,
14,
1462,
14,
452,
342,
8688,
199,
93,
199,
199,
26587,
63,
30515,
275,
469,
272,
283,
29974,
356,
19005,
3276,
8972,
1130,
12,
199,
93,
199,
199,
20050,
275,
7970,
360,
1176,
14,
2828,
14,
30515,
14,
4196,
297,
272,
334,
82,
4289,
4129,
15,
1080,
4537,
1652,
4268,
283,
1080,
297,
791,
30515,
356,
3486,
63,
30515,
8688,
272,
334,
82,
4289,
4129,
15,
4229,
13,
1080,
4537,
1652,
4268,
283,
1080,
297,
267,
791,
30515,
356,
3486,
63,
30515,
12,
283,
1160,
63,
354,
356,
283,
4229,
63,
17205,
63,
1080,
14,
1652,
1604,
272,
334,
82,
4289,
4129,
15,
17205,
13,
2229,
48,
28,
2792,
31411,
31477,
1652,
4268,
283,
17205,
297,
267,
791,
30515,
356,
3486,
63,
30515,
8688,
272,
334,
82,
4289,
4129,
15,
17205,
4537,
1652,
4268,
283,
17205,
297,
791,
30515,
356,
3486,
63,
30515,
8688,
272,
334,
82,
4289,
4129,
15,
4229,
13,
17205,
4537,
1652,
4268,
283,
17205,
297,
267,
791,
30515,
356,
3486,
63,
30515,
12,
283,
1160,
63,
354,
356,
283,
4229,
63,
17205,
14,
1652,
1604,
272,
334,
82,
4289,
6767,
15,
17205,
4537,
1652,
4268,
283,
17205,
297,
791,
30515,
356,
7809,
63,
30515,
8688,
272,
334,
82,
4289,
29974,
15,
17205,
4537,
1652,
4268,
283,
17205,
297,
791,
30515,
356,
6829,
1606,
63,
30515,
8688,
272,
1166,
8,
82,
4289,
5245,
15,
1080,
4537,
1652,
4268,
2581,
63,
1606,
8,
17,
5130,
4196,
14,
1080,
395,
267,
791,
30515,
356,
3486,
63,
30515,
12,
283,
17205,
63,
633,
63,
354,
356,
283,
5245,
63,
17205,
1604,
272,
1166,
8,
82,
4289,
5245,
15,
17205,
13,
2229,
48,
28,
2792,
31411,
31477,
1652,
297,
2581,
63,
1606,
8,
17,
5130,
4196,
14,
17205,
395,
267,
791,
30515,
356,
3486,
63,
30515,
1386,
536,
534,
5245,
63,
17205,
358,
199,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2197,
492,
2197,
199,
504,
1639,
14,
2190,
14,
3603,
492,
7970,
12,
1166,
199,
504,
1639,
14,
2828,
14,
30515,
492,
11666,
1130,
12,
8307,
8972,
1130,
12,
19005,
3276,
8972,
1130,
12,
6858,
199,
504,
1639,
14,
4196,
14,
11582,
14,
1637,
492,
2581,
63,
1606,
199,
199,
504,
1639,
14,
2828,
14,
30515,
14,
2219,
14,
1095,
492,
1379,
1685,
421,
199,
533,
5870,
8972,
1130,
8,
8972,
1130,
304,
272,
1570,
5646,
275,
298,
18178,
2,
272,
7464,
275,
378,
14,
21,
272,
2909,
275,
1994,
1985,
4805,
272,
2061,
1494,
275,
2197,
14,
2131,
342,
339,
347,
2974,
8,
277,
304,
267,
372,
359,
785,
5106,
199,
199,
4129,
63,
30515,
275,
469,
272,
283,
4129,
356,
5870,
8972,
1130,
12,
199,
93,
199,
199,
6767,
63,
30515,
275,
469,
272,
283,
6767,
356,
8307,
8972,
1130,
3252,
7924,
356,
1379,
1685,
14,
1462,
14,
452,
342,
8688,
199,
93,
199,
199,
26587,
63,
30515,
275,
469,
272,
283,
29974,
356,
19005,
3276,
8972,
1130,
12,
199,
93,
199,
199,
20050,
275,
7970,
360,
1176,
14,
2828,
14,
30515,
14,
4196,
297,
272,
334,
82,
4289,
4129,
15,
1080,
4537,
1652,
4268,
283,
1080,
297,
791,
30515,
356,
3486,
63,
30515,
8688,
272,
334,
82,
4289,
4129,
15,
4229,
13,
1080,
4537,
1652,
4268,
283,
1080,
297,
267,
791,
30515,
356,
3486,
63,
30515,
12,
283,
1160,
63,
354,
356,
283,
4229,
63,
17205,
63,
1080,
14,
1652,
1604,
272,
334,
82,
4289,
4129,
15,
17205,
13,
2229,
48,
28,
2792,
31411,
31477,
1652,
4268,
283,
17205,
297,
267,
791,
30515,
356,
3486,
63,
30515,
8688,
272,
334,
82,
4289,
4129,
15,
17205,
4537,
1652,
4268,
283,
17205,
297,
791,
30515,
356,
3486,
63,
30515,
8688,
272,
334,
82,
4289,
4129,
15,
4229,
13,
17205,
4537,
1652,
4268,
283,
17205,
297,
267,
791,
30515,
356,
3486,
63,
30515,
12,
283,
1160,
63,
354,
356,
283,
4229,
63,
17205,
14,
1652,
1604,
272,
334,
82,
4289,
6767,
15,
17205,
4537,
1652,
4268,
283,
17205,
297,
791,
30515,
356,
7809,
63,
30515,
8688,
272,
334,
82,
4289,
29974,
15,
17205,
4537,
1652,
4268,
283,
17205,
297,
791,
30515,
356,
6829,
1606,
63,
30515,
8688,
272,
1166,
8,
82,
4289,
5245,
15,
1080,
4537,
1652,
4268,
2581,
63,
1606,
8,
17,
5130,
4196,
14,
1080,
395,
267,
791,
30515,
356,
3486,
63,
30515,
12,
283,
17205,
63,
633,
63,
354,
356,
283,
5245,
63,
17205,
1604,
272,
1166,
8,
82,
4289,
5245,
15,
17205,
13,
2229,
48,
28,
2792,
31411,
31477,
1652,
297,
2581,
63,
1606,
8,
17,
5130,
4196,
14,
17205,
395,
267,
791,
30515,
356,
3486,
63,
30515,
1386,
536,
534,
5245,
63,
17205,
358,
199,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Craftyawesome/dolphin
|
Tools/find-includes-cycles.py
|
157
|
2630
|
#! /usr/bin/env python
'''
Run this script from Source/Core/ to find all the #include cycles.
'''
import subprocess
def get_local_includes_for(path):
lines = open(path).read().split('\n')
includes = [l.strip() for l in lines if l.strip().startswith('#include')]
return [i.split()[1][1:-1] for i in includes if '"' in i.split()[1]]
def find_all_files():
'''Could probably use os.walk, but meh.'''
f = subprocess.check_output(['find', '.', '-name', '*.h'],
universal_newlines=True).strip().split('\n')
return [p[2:] for p in f]
def make_include_graph():
return { f: get_local_includes_for(f) for f in find_all_files() }
def strongly_connected_components(graph):
"""
Tarjan's Algorithm (named for its discoverer, Robert Tarjan) is a graph theory algorithm
for finding the strongly connected components of a graph.
Based on: http://en.wikipedia.org/wiki/Tarjan%27s_strongly_connected_components_algorithm
"""
index_counter = [0]
stack = []
lowlinks = {}
index = {}
result = []
def strongconnect(node):
# set the depth index for this node to the smallest unused index
index[node] = index_counter[0]
lowlinks[node] = index_counter[0]
index_counter[0] += 1
stack.append(node)
# Consider successors of `node`
try:
successors = graph[node]
except:
successors = []
for successor in successors:
if successor not in lowlinks:
# Successor has not yet been visited; recurse on it
strongconnect(successor)
lowlinks[node] = min(lowlinks[node],lowlinks[successor])
elif successor in stack:
# the successor is in the stack and hence in the current strongly connected component (SCC)
lowlinks[node] = min(lowlinks[node],index[successor])
# If `node` is a root node, pop the stack and generate an SCC
if lowlinks[node] == index[node]:
connected_component = []
while True:
successor = stack.pop()
connected_component.append(successor)
if successor == node: break
component = tuple(connected_component)
# storing the result
result.append(component)
for node in graph:
if node not in lowlinks:
strongconnect(node)
return result
if __name__ == '__main__':
comp = strongly_connected_components(make_include_graph())
for c in comp:
if len(c) != 1:
print(c)
|
gpl-2.0
|
[
3168,
1182,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
2344,
199,
2540,
642,
2884,
687,
5800,
15,
5402,
15,
370,
2342,
1006,
314,
327,
2613,
19001,
14,
199,
2344,
199,
199,
646,
3873,
199,
199,
318,
664,
63,
1832,
63,
9441,
63,
509,
8,
515,
304,
272,
2385,
275,
1551,
8,
515,
680,
739,
1252,
1294,
2258,
78,
358,
272,
6952,
275,
359,
76,
14,
1913,
342,
367,
634,
315,
2385,
340,
634,
14,
1913,
1252,
2460,
7863,
2613,
5440,
272,
372,
359,
73,
14,
1294,
3430,
17,
1527,
17,
6809,
17,
61,
367,
284,
315,
6952,
340,
14788,
315,
284,
14,
1294,
3430,
17,
2677,
199,
199,
318,
2342,
63,
452,
63,
1725,
837,
272,
1449,
6531,
8646,
675,
747,
14,
7757,
12,
1325,
562,
72,
10595,
272,
289,
275,
3873,
14,
1074,
63,
1199,
2941,
1623,
297,
22608,
2475,
354,
297,
11937,
72,
995,
1816,
17508,
63,
13839,
29,
549,
680,
1913,
1252,
1294,
2258,
78,
358,
272,
372,
359,
80,
59,
18,
2938,
367,
299,
315,
289,
61,
199,
199,
318,
1852,
63,
2613,
63,
2180,
837,
272,
372,
469,
289,
26,
664,
63,
1832,
63,
9441,
63,
509,
8,
70,
9,
367,
289,
315,
2342,
63,
452,
63,
1725,
342,
789,
199,
199,
318,
30390,
63,
7113,
63,
4608,
8,
2180,
304,
272,
408,
272,
16017,
24418,
1159,
23823,
334,
4579,
367,
2399,
2153,
24617,
3859,
12,
6848,
12504,
16017,
24418,
9,
365,
282,
3343,
30629,
5563,
272,
367,
17196,
314,
30390,
8539,
7323,
402,
282,
3343,
14,
339,
21311,
641,
26,
1455,
921,
287,
14,
13961,
14,
1308,
15,
6797,
15,
24818,
24418,
5,
1465,
83,
63,
9370,
590,
63,
7113,
63,
4608,
63,
8833,
272,
408,
339,
1478,
63,
5337,
275,
359,
16,
61,
272,
3464,
275,
942,
272,
6465,
4614,
275,
1052,
272,
1478,
275,
1052,
272,
754,
275,
942,
339,
347,
16925,
2242,
8,
932,
304,
267,
327,
663,
314,
5818,
1478,
367,
642,
1031,
370,
314,
18604,
9563,
1478,
267,
1478,
59,
932,
61,
275,
1478,
63,
5337,
59,
16,
61,
267,
6465,
4614,
59,
932,
61,
275,
1478,
63,
5337,
59,
16,
61,
267,
1478,
63,
5337,
59,
16,
61,
847,
413,
267,
3464,
14,
740,
8,
932,
9,
398,
327,
24413,
3182,
1384,
402,
658,
932,
64,
267,
862,
26,
288,
3182,
1384,
275,
3343,
59,
932,
61,
267,
871,
26,
288,
3182,
1384,
275,
942,
267,
367,
3182,
269,
315,
3182,
1384,
26,
288,
340,
3182,
269,
440,
315,
6465,
4614,
26,
355,
327,
22318,
269,
965,
440,
5966,
2757,
15867,
27,
18011,
641,
652,
355,
16925,
2242,
8,
3742,
269,
9,
355,
6465,
4614,
59,
932,
61,
275,
1748,
8,
674,
4614,
59,
932,
467,
674,
4614,
59,
3742,
269,
566,
288,
916,
3182,
269,
315,
3464,
26,
355,
327,
314,
3182,
269,
365,
315,
314,
3464,
436,
19407,
315,
314,
1453,
30390,
8539,
3931,
334,
51,
2571,
9,
355,
6465,
4614,
59,
932,
61,
275,
1748,
8,
674,
4614,
59,
932,
467,
1080,
59,
3742,
269,
566,
398,
327,
982,
658,
932,
64,
365,
282,
1738,
1031,
12,
4560,
314,
3464,
436,
3550,
376,
428,
2571,
267,
340,
6465,
4614,
59,
932,
61,
508,
1478,
59,
932,
2189,
288,
8539,
63,
3173,
275,
942,
953,
1830,
715,
26,
355,
3182,
269,
275,
3464,
14,
1935,
342,
355,
8539,
63,
3173,
14,
740,
8,
3742,
269,
9,
355,
340,
3182,
269,
508,
1031,
26,
2059,
288,
3931,
275,
2008,
8,
7113,
63,
3173,
9,
288,
327,
16915,
314,
754,
288,
754,
14,
740,
8,
3173,
9,
339,
367,
1031,
315,
3343,
26,
267,
340,
1031,
440,
315,
6465,
4614,
26,
288,
16925,
2242,
8,
932,
9,
339,
372,
754,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
1013,
275,
30390,
63,
7113,
63,
4608,
8,
1875,
63,
2613,
63,
2180,
1012,
272,
367,
286,
315,
1013,
26,
267,
340,
822,
8,
67,
9,
1137,
413,
26,
288,
870,
8,
67,
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
] |
[
1182,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
2344,
199,
2540,
642,
2884,
687,
5800,
15,
5402,
15,
370,
2342,
1006,
314,
327,
2613,
19001,
14,
199,
2344,
199,
199,
646,
3873,
199,
199,
318,
664,
63,
1832,
63,
9441,
63,
509,
8,
515,
304,
272,
2385,
275,
1551,
8,
515,
680,
739,
1252,
1294,
2258,
78,
358,
272,
6952,
275,
359,
76,
14,
1913,
342,
367,
634,
315,
2385,
340,
634,
14,
1913,
1252,
2460,
7863,
2613,
5440,
272,
372,
359,
73,
14,
1294,
3430,
17,
1527,
17,
6809,
17,
61,
367,
284,
315,
6952,
340,
14788,
315,
284,
14,
1294,
3430,
17,
2677,
199,
199,
318,
2342,
63,
452,
63,
1725,
837,
272,
1449,
6531,
8646,
675,
747,
14,
7757,
12,
1325,
562,
72,
10595,
272,
289,
275,
3873,
14,
1074,
63,
1199,
2941,
1623,
297,
22608,
2475,
354,
297,
11937,
72,
995,
1816,
17508,
63,
13839,
29,
549,
680,
1913,
1252,
1294,
2258,
78,
358,
272,
372,
359,
80,
59,
18,
2938,
367,
299,
315,
289,
61,
199,
199,
318,
1852,
63,
2613,
63,
2180,
837,
272,
372,
469,
289,
26,
664,
63,
1832,
63,
9441,
63,
509,
8,
70,
9,
367,
289,
315,
2342,
63,
452,
63,
1725,
342,
789,
199,
199,
318,
30390,
63,
7113,
63,
4608,
8,
2180,
304,
272,
408,
272,
16017,
24418,
1159,
23823,
334,
4579,
367,
2399,
2153,
24617,
3859,
12,
6848,
12504,
16017,
24418,
9,
365,
282,
3343,
30629,
5563,
272,
367,
17196,
314,
30390,
8539,
7323,
402,
282,
3343,
14,
339,
21311,
641,
26,
1455,
921,
287,
14,
13961,
14,
1308,
15,
6797,
15,
24818,
24418,
5,
1465,
83,
63,
9370,
590,
63,
7113,
63,
4608,
63,
8833,
272,
408,
339,
1478,
63,
5337,
275,
359,
16,
61,
272,
3464,
275,
942,
272,
6465,
4614,
275,
1052,
272,
1478,
275,
1052,
272,
754,
275,
942,
339,
347,
16925,
2242,
8,
932,
304,
267,
327,
663,
314,
5818,
1478,
367,
642,
1031,
370,
314,
18604,
9563,
1478,
267,
1478,
59,
932,
61,
275,
1478,
63,
5337,
59,
16,
61,
267,
6465,
4614,
59,
932,
61,
275,
1478,
63,
5337,
59,
16,
61,
267,
1478,
63,
5337,
59,
16,
61,
847,
413,
267,
3464,
14,
740,
8,
932,
9,
398,
327,
24413,
3182,
1384,
402,
658,
932,
64,
267,
862,
26,
288,
3182,
1384,
275,
3343,
59,
932,
61,
267,
871,
26,
288,
3182,
1384,
275,
942,
267,
367,
3182,
269,
315,
3182,
1384,
26,
288,
340,
3182,
269,
440,
315,
6465,
4614,
26,
355,
327,
22318,
269,
965,
440,
5966,
2757,
15867,
27,
18011,
641,
652,
355,
16925,
2242,
8,
3742,
269,
9,
355,
6465,
4614,
59,
932,
61,
275,
1748,
8,
674,
4614,
59,
932,
467,
674,
4614,
59,
3742,
269,
566,
288,
916,
3182,
269,
315,
3464,
26,
355,
327,
314,
3182,
269,
365,
315,
314,
3464,
436,
19407,
315,
314,
1453,
30390,
8539,
3931,
334,
51,
2571,
9,
355,
6465,
4614,
59,
932,
61,
275,
1748,
8,
674,
4614,
59,
932,
467,
1080,
59,
3742,
269,
566,
398,
327,
982,
658,
932,
64,
365,
282,
1738,
1031,
12,
4560,
314,
3464,
436,
3550,
376,
428,
2571,
267,
340,
6465,
4614,
59,
932,
61,
508,
1478,
59,
932,
2189,
288,
8539,
63,
3173,
275,
942,
953,
1830,
715,
26,
355,
3182,
269,
275,
3464,
14,
1935,
342,
355,
8539,
63,
3173,
14,
740,
8,
3742,
269,
9,
355,
340,
3182,
269,
508,
1031,
26,
2059,
288,
3931,
275,
2008,
8,
7113,
63,
3173,
9,
288,
327,
16915,
314,
754,
288,
754,
14,
740,
8,
3173,
9,
339,
367,
1031,
315,
3343,
26,
267,
340,
1031,
440,
315,
6465,
4614,
26,
288,
16925,
2242,
8,
932,
9,
339,
372,
754,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
1013,
275,
30390,
63,
7113,
63,
4608,
8,
1875,
63,
2613,
63,
2180,
1012,
272,
367,
286,
315,
1013,
26,
267,
340,
822,
8,
67,
9,
1137,
413,
26,
288,
870,
8,
67,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
gregerts/debian-qpid-cpp
|
src/tests/legacystore/jrnl/jtt/jfile_chk.py
|
4
|
31827
|
#!/usr/bin/env python
#
# 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.
#
import sys
import getopt
import string
import xml.parsers.expat
from struct import unpack, calcsize
from time import gmtime, strftime
dblk_size = 128
sblk_size = 4 * dblk_size
jfsize = None
hdr_ver = 1
TEST_NUM_COL = 0
NUM_MSGS_COL = 5
MIN_MSG_SIZE_COL = 7
MAX_MSG_SIZE_COL = 8
MIN_XID_SIZE_COL = 9
MAX_XID_SIZE_COL = 10
AUTO_DEQ_COL = 11
TRANSIENT_COL = 12
EXTERN_COL = 13
COMMENT_COL = 20
owi_mask = 0x01
transient_mask = 0x10
extern_mask = 0x20
printchars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~ '
#== global functions ===========================================================
def load(f, klass):
args = load_args(f, klass)
subclass = klass.discriminate(args)
result = subclass(*args)
if subclass != klass:
result.init(f, *load_args(f, subclass))
result.skip(f)
return result;
def load_args(f, klass):
size = calcsize(klass.format)
foffs = f.tell(),
bin = f.read(size)
if len(bin) != size:
raise Exception("end of file")
return foffs + unpack(klass.format, bin)
def size_blks(size, blk_size):
return (size + blk_size - 1)/blk_size
def rem_in_blk(f, blk_size):
foffs = f.tell()
return (size_blks(f.tell(), blk_size) * blk_size) - foffs;
def file_full(f):
return f.tell() >= jfsize
def isprintable(s):
return s.strip(printchars) == ''
def print_xid(xidsize, xid):
if xid == None:
if xidsize > 0:
raise Exception('Inconsistent XID size: xidsize=%d, xid=None' % xidsize)
return ''
if isprintable(xid):
xidstr = split_str(xid)
else:
xidstr = hex_split_str(xid)
if xidsize != len(xid):
raise Exception('Inconsistent XID size: xidsize=%d, xid(%d)=\"%s\"' % (xidsize, len(xid), xidstr))
return 'xid(%d)=\"%s\" ' % (xidsize, xidstr)
def print_data(dsize, data):
if data == None:
return ''
if isprintable(data):
datastr = split_str(data)
else:
datastr = hex_split_str(data)
if dsize != len(data):
raise Exception('Inconsistent data size: dsize=%d, data(%d)=\"%s\"' % (dsize, len(data), datastr))
return 'data(%d)=\"%s\" ' % (dsize, datastr)
def hex_split_str(s, split_size = 50):
if len(s) <= split_size:
return hex_str(s, 0, len(s))
if len(s) > split_size + 25:
return hex_str(s, 0, 10) + ' ... ' + hex_str(s, 55, 65) + ' ... ' + hex_str(s, len(s)-10, len(s))
return hex_str(s, 0, 10) + ' ... ' + hex_str(s, len(s)-10, len(s))
def hex_str(s, b, e):
o = ''
for i in range(b, e):
if isprintable(s[i]):
o += s[i]
else:
o += '\\%02x' % ord(s[i])
return o
def split_str(s, split_size = 50):
if len(s) < split_size:
return s
return s[:25] + ' ... ' + s[-25:]
def inv_str(s):
si = ''
for i in range(0,len(s)):
si += chr(~ord(s[i]) & 0xff)
return si
def load_file_data(f, size, data):
if size == 0:
return (data, True)
if data == None:
loaded = 0
else:
loaded = len(data)
foverflow = f.tell() + size - loaded > jfsize
if foverflow:
rsize = jfsize - f.tell()
else:
rsize = size - loaded
bin = f.read(rsize)
if data == None:
data = unpack('%ds' % (rsize), bin)[0]
else:
data = data + unpack('%ds' % (rsize), bin)[0]
return (data, not foverflow)
def exit(code, qflag):
if code != 0 or not qflag:
print out.getvalue()
out.close()
sys.exit(code)
#== class Sizeable =============================================================
class Sizeable:
def size(self):
classes = [self.__class__]
size = 0
while classes:
cls = classes.pop()
if hasattr(cls, "format"):
size += calcsize(cls.format)
classes.extend(cls.__bases__)
return size
#== class Hdr ==================================================================
class Hdr(Sizeable):
format = '=4sBBHQ'
def discriminate(args):
return CLASSES.get(args[1][-1], Hdr)
discriminate = staticmethod(discriminate)
def __init__(self, foffs, magic, ver, end, flags, rid):
self.foffs = foffs
self.magic = magic
self.ver = ver
self.end = end
self.flags = flags
self.rid = rid
if self.magic[-1] not in ['0x00', 'a', 'c', 'd', 'e', 'f', 'x']:
error = 3
def __str__(self):
if self.empty():
return '0x%08x: <empty>' % (self.foffs)
if self.magic[-1] == 'x':
return '0x%08x: [\"%s\"]' % (self.foffs, self.magic)
if self.magic[-1] in ['a', 'c', 'd', 'e', 'f', 'x']:
return '0x%08x: [\"%s\" v=%d e=%d f=0x%04x rid=0x%x]' % (self.foffs, self.magic, self.ver, self.end, self.flags, self.rid)
return '0x%08x: <error, unknown magic \"%s\" (possible overwrite boundary?)>' % (self.foffs, self.magic)
def empty(self):
return self.magic == '\x00'*4
def owi(self):
return self.flags & owi_mask != 0
def skip(self, f):
f.read(rem_in_blk(f, dblk_size))
def check(self):
if self.empty() or self.magic[:3] != 'RHM' or self.magic[3] not in ['a', 'c', 'd', 'e', 'f', 'x']:
return True
if self.ver != hdr_ver and self.magic[-1] != 'x':
raise Exception('%s: Invalid header version: found %d, expected %d.' % (self, self.ver, hdr_ver))
return False
#== class FileHdr ==============================================================
class FileHdr(Hdr):
format = '=2H4x3Q'
def init(self, f, foffs, fid, lid, fro, time_sec, time_ns):
self.fid = fid
self.lid = lid
self.fro = fro
self.time_sec = time_sec
self.time_ns = time_ns
def __str__(self):
return '%s fid=%d lid=%d fro=0x%08x t=%s' % (Hdr.__str__(self), self.fid, self.lid, self.fro, self.timestamp_str())
def skip(self, f):
f.read(rem_in_blk(f, sblk_size))
def timestamp(self):
return (self.time_sec, self.time_ns)
def timestamp_str(self):
ts = gmtime(self.time_sec)
fstr = '%%a %%b %%d %%H:%%M:%%S.%09d %%Y' % (self.time_ns)
return strftime(fstr, ts)
#== class DeqHdr ===============================================================
class DeqHdr(Hdr):
format = '=QQ'
def init(self, f, foffs, deq_rid, xidsize):
self.deq_rid = deq_rid
self.xidsize = xidsize
self.xid = None
self.deq_tail = None
self.xid_complete = False
self.tail_complete = False
self.tail_bin = None
self.tail_offs = 0
self.load(f)
def load(self, f):
if self.xidsize == 0:
self.xid_complete = True
self.tail_complete = True
else:
if not self.xid_complete:
ret = load_file_data(f, self.xidsize, self.xid)
self.xid = ret[0]
self.xid_complete = ret[1]
if self.xid_complete and not self.tail_complete:
ret = load_file_data(f, calcsize(RecTail.format), self.tail_bin)
self.tail_bin = ret[0]
if ret[1]:
self.enq_tail = RecTail(self.tail_offs, *unpack(RecTail.format, self.tail_bin))
if self.enq_tail.magic_inv != inv_str(self.magic) or self.enq_tail.rid != self.rid:
print " > %s" % self
raise Exception('Invalid dequeue record tail (magic=%s; rid=%d) at 0x%08x' % (self.enq_tail, self.enq_tail.rid, self.enq_tail.foffs))
self.enq_tail.skip(f)
self.tail_complete = ret[1]
return self.complete()
def complete(self):
return self.xid_complete and self.tail_complete
def __str__(self):
return '%s %sdrid=0x%x' % (Hdr.__str__(self), print_xid(self.xidsize, self.xid), self.deq_rid)
#== class TxnHdr ===============================================================
class TxnHdr(Hdr):
format = '=Q'
def init(self, f, foffs, xidsize):
self.xidsize = xidsize
self.xid = None
self.tx_tail = None
self.xid_complete = False
self.tail_complete = False
self.tail_bin = None
self.tail_offs = 0
self.load(f)
def load(self, f):
if not self.xid_complete:
ret = load_file_data(f, self.xidsize, self.xid)
self.xid = ret[0]
self.xid_complete = ret[1]
if self.xid_complete and not self.tail_complete:
ret = load_file_data(f, calcsize(RecTail.format), self.tail_bin)
self.tail_bin = ret[0]
if ret[1]:
self.enq_tail = RecTail(self.tail_offs, *unpack(RecTail.format, self.tail_bin))
if self.enq_tail.magic_inv != inv_str(self.magic) or self.enq_tail.rid != self.rid:
print " > %s" % self
raise Exception('Invalid transaction record tail (magic=%s; rid=%d) at 0x%08x' % (self.enq_tail, self.enq_tail.rid, self.enq_tail.foffs))
self.enq_tail.skip(f)
self.tail_complete = ret[1]
return self.complete()
def complete(self):
return self.xid_complete and self.tail_complete
def __str__(self):
return '%s %s' % (Hdr.__str__(self), print_xid(self.xidsize, self.xid))
#== class RecTail ==============================================================
class RecTail(Sizeable):
format = '=4sQ'
def __init__(self, foffs, magic_inv, rid):
self.foffs = foffs
self.magic_inv = magic_inv
self.rid = rid
def __str__(self):
magic = inv_str(self.magic_inv)
return '[\"%s\" rid=0x%x]' % (magic, self.rid)
def skip(self, f):
f.read(rem_in_blk(f, dblk_size))
#== class EnqRec ===============================================================
class EnqRec(Hdr):
format = '=QQ'
def init(self, f, foffs, xidsize, dsize):
self.xidsize = xidsize
self.dsize = dsize
self.transient = self.flags & transient_mask > 0
self.extern = self.flags & extern_mask > 0
self.xid = None
self.data = None
self.enq_tail = None
self.xid_complete = False
self.data_complete = False
self.tail_complete = False
self.tail_bin = None
self.tail_offs = 0
self.load(f)
def load(self, f):
if not self.xid_complete:
ret = load_file_data(f, self.xidsize, self.xid)
self.xid = ret[0]
self.xid_complete = ret[1]
if self.xid_complete and not self.data_complete:
if self.extern:
self.data_complete = True
else:
ret = load_file_data(f, self.dsize, self.data)
self.data = ret[0]
self.data_complete = ret[1]
if self.data_complete and not self.tail_complete:
ret = load_file_data(f, calcsize(RecTail.format), self.tail_bin)
self.tail_bin = ret[0]
if ret[1]:
self.enq_tail = RecTail(self.tail_offs, *unpack(RecTail.format, self.tail_bin))
if self.enq_tail.magic_inv != inv_str(self.magic) or self.enq_tail.rid != self.rid:
print " > %s" % self
raise Exception('Invalid enqueue record tail (magic=%s; rid=%d) at 0x%08x' % (self.enq_tail, self.enq_tail.rid, self.enq_tail.foffs))
self.enq_tail.skip(f)
self.tail_complete = ret[1]
return self.complete()
def complete(self):
return self.xid_complete and self.data_complete and self.tail_complete
def print_flags(self):
s = ''
if self.transient:
s = '*TRANSIENT'
if self.extern:
if len(s) > 0:
s += ',EXTERNAL'
else:
s = '*EXTERNAL'
if len(s) > 0:
s += '*'
return s
def __str__(self):
return '%s %s%s %s %s' % (Hdr.__str__(self), print_xid(self.xidsize, self.xid), print_data(self.dsize, self.data), self.enq_tail, self.print_flags())
#== class Main =================================================================
class Main:
def __init__(self, argv):
self.bfn = None
self.csvfn = None
self.jdir = None
self.aflag = False
self.hflag = False
self.qflag = False
self.tnum = None
self.num_jfiles = None
self.num_msgs = None
self.msg_len = None
self.auto_deq = None
self.xid_len = None
self.transient = None
self.extern = None
self.file_start = 0
self.file_num = 0
self.fro = 0x200
self.emap = {}
self.tmap = {}
self.rec_cnt = 0
self.msg_cnt = 0
self.txn_msg_cnt = 0
self.fhdr = None
self.f = None
self.first_rec = False
self.last_file = False
self.last_rid = -1
self.fhdr_owi_at_msg_start = None
self.proc_args(argv)
self.proc_csv()
self.read_jinf()
def run(self):
try:
start_info = self.analyze_files()
stop = self.advance_file(*start_info)
except Exception:
print 'WARNING: All journal files are empty.'
if self.num_msgs > 0:
raise Exception('All journal files are empty, but %d msgs expectd.' % self.num_msgs)
else:
stop = True
while not stop:
warn = ''
if file_full(self.f):
stop = self.advance_file()
if stop:
break
hdr = load(self.f, Hdr)
if hdr.empty():
stop = True;
break
if hdr.check():
stop = True;
else:
self.rec_cnt += 1
self.fhdr_owi_at_msg_start = self.fhdr.owi()
if self.first_rec:
if self.fhdr.fro != hdr.foffs:
raise Exception('File header first record offset mismatch: fro=0x%08x; rec_offs=0x%08x' % (self.fhdr.fro, hdr.foffs))
else:
if not self.qflag: print ' * fro ok: 0x%08x' % self.fhdr.fro
self.first_rec = False
if isinstance(hdr, EnqRec) and not stop:
while not hdr.complete():
stop = self.advance_file()
if stop:
break
hdr.load(self.f)
if self.extern != None:
if hdr.extern:
if hdr.data != None:
raise Exception('Message data found on external record')
else:
if self.msg_len > 0 and len(hdr.data) != self.msg_len:
raise Exception('Message length (%d) incorrect; expected %d' % (len(hdr.data), self.msg_len))
else:
if self.msg_len > 0 and len(hdr.data) != self.msg_len:
raise Exception('Message length (%d) incorrect; expected %d' % (len(hdr.data), self.msg_len))
if self.xid_len > 0 and len(hdr.xid) != self.xid_len:
print ' ERROR: XID length (%d) incorrect; expected %d' % (len(hdr.xid), self.xid_len)
sys.exit(1)
#raise Exception('XID length (%d) incorrect; expected %d' % (len(hdr.xid), self.xid_len))
if self.transient != None:
if self.transient:
if not hdr.transient:
raise Exception('Expected transient record, found persistent')
else:
if hdr.transient:
raise Exception('Expected persistent record, found transient')
stop = not self.check_owi(hdr)
if stop:
warn = ' (WARNING: OWI mismatch - could be overwrite boundary.)'
else:
self.msg_cnt += 1
if self.aflag or self.auto_deq:
if hdr.xid == None:
self.emap[hdr.rid] = (self.fhdr.fid, hdr, False)
else:
self.txn_msg_cnt += 1
if hdr.xid in self.tmap:
self.tmap[hdr.xid].append((self.fhdr.fid, hdr)) #Append tuple to existing list
else:
self.tmap[hdr.xid] = [(self.fhdr.fid, hdr)] # Create new list
elif isinstance(hdr, DeqHdr) and not stop:
while not hdr.complete():
stop = self.advance_file()
if stop:
break
hdr.load(self.f)
stop = not self.check_owi(hdr)
if stop:
warn = ' (WARNING: OWI mismatch - could be overwrite boundary.)'
else:
if self.auto_deq != None:
if not self.auto_deq:
warn = ' WARNING: Dequeue record rid=%d found in non-dequeue test - ignoring.' % hdr.rid
if self.aflag or self.auto_deq:
if hdr.xid == None:
if hdr.deq_rid in self.emap:
if self.emap[hdr.deq_rid][2]:
warn = ' (WARNING: dequeue rid 0x%x dequeues locked enqueue record 0x%x)' % (hdr.rid, hdr.deq_rid)
del self.emap[hdr.deq_rid]
else:
warn = ' (WARNING: rid being dequeued 0x%x not found in enqueued records)' % hdr.deq_rid
else:
if hdr.deq_rid in self.emap:
t = self.emap[hdr.deq_rid]
self.emap[hdr.deq_rid] = (t[0], t[1], True) # Lock enq record
if hdr.xid in self.tmap:
self.tmap[hdr.xid].append((self.fhdr.fid, hdr)) #Append to existing list
else:
self.tmap[hdr.xid] = [(self.fhdr.fid, hdr)] # Create new list
elif isinstance(hdr, TxnHdr) and not stop:
while not hdr.complete():
stop = self.advance_file()
if stop:
break
hdr.load(self.f)
stop = not self.check_owi(hdr)
if stop:
warn = ' (WARNING: OWI mismatch - could be overwrite boundary.)'
else:
if hdr.xid in self.tmap:
mismatched_rids = []
if hdr.magic[-1] == 'c': # commit
for rec in self.tmap[hdr.xid]:
if isinstance(rec[1], EnqRec):
self.emap[rec[1].rid] = (rec[0], rec[1], False) # Transfer enq to emap
elif isinstance(rec[1], DeqHdr):
if rec[1].deq_rid in self.emap:
del self.emap[rec[1].deq_rid] # Delete from emap
else:
mismatched_rids.append('0x%x' % rec[1].deq_rid)
else:
raise Exception('Unknown header found in txn map: %s' % rec[1])
elif hdr.magic[-1] == 'a': # abort
for rec in self.tmap[hdr.xid]:
if isinstance(rec[1], DeqHdr):
if rec[1].deq_rid in self.emap:
t = self.emap[rec[1].deq_rid]
self.emap[rec[1].deq_rid] = (t[0], t[1], False) # Unlock enq record
del self.tmap[hdr.xid]
if len(mismatched_rids) > 0:
warn = ' (WARNING: transactional dequeues not found in enqueue map; rids=%s)' % mismatched_rids
else:
warn = ' (WARNING: %s not found in transaction map)' % print_xid(len(hdr.xid), hdr.xid)
if not self.qflag: print ' > %s%s' % (hdr, warn)
if not stop:
stop = (self.last_file and hdr.check()) or hdr.empty() or self.fhdr.empty()
def analyze_files(self):
fname = ''
fnum = -1
rid = -1
fro = -1
tss = ''
if not self.qflag: print 'Analyzing journal files:'
owi_found = False
for i in range(0, self.num_jfiles):
jfn = self.jdir + '/' + self.bfn + '.%04d.jdat' % i
f = open(jfn)
fhdr = load(f, Hdr)
if fhdr.empty():
if not self.qflag:
print ' %s: file empty' % jfn
break
if i == 0:
init_owi = fhdr.owi()
fname = jfn
fnum = i
rid = fhdr.rid
fro = fhdr.fro
tss = fhdr.timestamp_str()
elif fhdr.owi() != init_owi and not owi_found:
fname = jfn
fnum = i
rid = fhdr.rid
fro = fhdr.fro
tss = fhdr.timestamp_str()
owi_found = True
if not self.qflag:
print ' %s: owi=%s rid=0x%x, fro=0x%08x ts=%s' % (jfn, fhdr.owi(), fhdr.rid, fhdr.fro, fhdr.timestamp_str())
if fnum < 0 or rid < 0 or fro < 0:
raise Exception('All journal files empty')
if not self.qflag: print ' Oldest complete file: %s: rid=%d, fro=0x%08x ts=%s' % (fname, rid, fro, tss)
return (fnum, rid, fro)
def advance_file(self, *start_info):
seek_flag = False
if len(start_info) == 3:
self.file_start = self.file_num = start_info[0]
self.fro = start_info[2]
seek_flag = True
if self.f != None and file_full(self.f):
self.file_num = self.incr_fnum()
if self.file_num == self.file_start:
return True
if self.file_start == 0:
self.last_file = self.file_num == self.num_jfiles - 1
else:
self.last_file = self.file_num == self.file_start - 1
if self.file_num < 0 or self.file_num >= self.num_jfiles:
raise Exception('Bad file number %d' % self.file_num)
jfn = self.jdir + '/' + self.bfn + '.%04d.jdat' % self.file_num
self.f = open(jfn)
self.fhdr = load(self.f, Hdr)
if seek_flag and self.f.tell() != self.fro:
self.f.seek(self.fro)
self.first_rec = True
if not self.qflag: print jfn, ": ", self.fhdr
return False
def incr_fnum(self):
self.file_num += 1
if self.file_num >= self.num_jfiles:
self.file_num = 0;
return self.file_num
def check_owi(self, hdr):
return self.fhdr_owi_at_msg_start == hdr.owi()
def check_rid(self, hdr):
if self.last_rid != -1 and hdr.rid <= self.last_rid:
return False
self.last_rid = hdr.rid
return True
def read_jinf(self):
filename = self.jdir + '/' + self.bfn + '.jinf'
try:
f = open(filename, 'r')
except IOError:
print 'ERROR: Unable to open jinf file %s' % filename
sys.exit(1)
p = xml.parsers.expat.ParserCreate()
p.StartElementHandler = self.handleStartElement
p.CharacterDataHandler = self.handleCharData
p.EndElementHandler = self.handleEndElement
p.ParseFile(f)
if self.num_jfiles == None:
print 'ERROR: number_jrnl_files not found in jinf file "%s"!' % filename
if jfsize == None:
print 'ERROR: jrnl_file_size_sblks not found in jinf file "%s"!' % filename
if self.num_jfiles == None or jfsize == None:
sys.exit(1)
def handleStartElement(self, name, attrs):
global jfsize
if name == 'number_jrnl_files':
self.num_jfiles = int(attrs['value'])
if name == 'jrnl_file_size_sblks':
jfsize = (int(attrs['value']) + 1) * sblk_size
def handleCharData(self, data): pass
def handleEndElement(self, name): pass
def proc_csv(self):
if self.csvfn != None and self.tnum != None:
tparams = self.get_test(self.csvfn, self.tnum)
if tparams == None:
print 'ERROR: Test %d not found in CSV file "%s"' % (self.tnum, self.csvfn)
sys.exit(1)
self.num_msgs = tparams['num_msgs']
if tparams['min_size'] == tparams['max_size']:
self.msg_len = tparams['max_size']
else:
self.msg_len = 0
self.auto_deq = tparams['auto_deq']
if tparams['xid_min_size'] == tparams['xid_max_size']:
self.xid_len = tparams['xid_max_size']
else:
self.xid_len = 0
self.transient = tparams['transient']
self.extern = tparams['extern']
def get_test(self, filename, tnum):
try:
f=open(filename, 'r')
except IOError:
print 'ERROR: Unable to open CSV file "%s"' % filename
sys.exit(1)
for l in f:
sl = l.strip().split(',')
if len(sl[0]) > 0 and sl[0][0] != '"':
try:
if (int(sl[TEST_NUM_COL]) == tnum):
return { 'num_msgs':int(sl[NUM_MSGS_COL]),
'min_size':int(sl[MIN_MSG_SIZE_COL]),
'max_size':int(sl[MAX_MSG_SIZE_COL]),
'auto_deq':not (sl[AUTO_DEQ_COL] == 'FALSE' or sl[AUTO_DEQ_COL] == '0'),
'xid_min_size':int(sl[MIN_XID_SIZE_COL]),
'xid_max_size':int(sl[MAX_XID_SIZE_COL]),
'transient':not (sl[TRANSIENT_COL] == 'FALSE' or sl[TRANSIENT_COL] == '0'),
'extern':not (sl[EXTERN_COL] == 'FALSE' or sl[EXTERN_COL] == '0'),
'comment':sl[COMMENT_COL] }
except Exception:
pass
return None
def proc_args(self, argv):
try:
opts, args = getopt.getopt(sys.argv[1:], "ab:c:d:hqt:", ["analyse", "base-filename=", "csv-filename=", "dir=", "help", "quiet", "test-num="])
except getopt.GetoptError:
self.usage()
sys.exit(2)
for o, a in opts:
if o in ("-h", "--help"):
self.usage()
sys.exit()
if o in ("-a", "--analyze"):
self.aflag = True
if o in ("-b", "--base-filename"):
self.bfn = a
if o in ("-c", "--csv-filename"):
self.csvfn = a
if o in ("-d", "--dir"):
self.jdir = a
if o in ("-q", "--quiet"):
self.qflag = True
if o in ("-t", "--test-num"):
if not a.isdigit():
print 'ERROR: Illegal test-num argument. Must be a non-negative number'
sys.exit(2)
self.tnum = int(a)
if self.bfn == None or self.jdir == None:
print 'ERROR: Missing requred args.'
self.usage()
sys.exit(2)
if self.tnum != None and self.csvfn == None:
print 'ERROR: Test number specified, but not CSV file'
self.usage()
sys.exit(2)
def usage(self):
print 'Usage: %s opts' % sys.argv[0]
print ' where opts are in either short or long format (*=req\'d):'
print ' -a --analyze Analyze enqueue/dequeue records'
print ' -b --base-filename [string] * Base filename for journal files'
print ' -c --csv-filename [string] CSV filename containing test parameters'
print ' -d --dir [string] * Journal directory containing journal files'
print ' -h --help Print help'
print ' -q --quiet Quiet (reduced output)'
print ' -t --test-num [int] Test number from CSV file - only valid if CSV file named'
def report(self):
if not self.qflag:
print
print ' === REPORT ===='
if self.num_msgs > 0 and self.msg_cnt != self.num_msgs:
print 'WARNING: Found %d messages; %d expected.' % (self.msg_cnt, self.num_msgs)
if len(self.emap) > 0:
print
print 'Remaining enqueued records (sorted by rid): '
keys = sorted(self.emap.keys())
for k in keys:
if self.emap[k][2] == True: # locked
locked = ' (locked)'
else:
locked = ''
print " fid=%d %s%s" % (self.emap[k][0], self.emap[k][1], locked)
print 'WARNING: Enqueue-Dequeue mismatch, %d enqueued records remain.' % len(self.emap)
if len(self.tmap) > 0:
txn_rec_cnt = 0
print
print 'Remaining transactions: '
for t in self.tmap:
print_xid(len(t), t)
for r in self.tmap[t]:
print " fid=%d %s" % (r[0], r[1])
print " Total: %d records for xid %s" % (len(self.tmap[t]), t)
txn_rec_cnt += len(self.tmap[t])
print 'WARNING: Incomplete transactions, %d xids remain containing %d records.' % (len(self.tmap), txn_rec_cnt)
print '%d enqueues, %d journal records processed.' % (self.msg_cnt, self.rec_cnt)
#===============================================================================
CLASSES = {
"a": TxnHdr,
"c": TxnHdr,
"d": DeqHdr,
"e": EnqRec,
"f": FileHdr
}
m = Main(sys.argv)
m.run()
m.report()
sys.exit(None)
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
199,
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,
3,
199,
199,
646,
984,
199,
646,
12733,
199,
646,
1059,
199,
646,
2748,
14,
11531,
14,
27098,
199,
504,
2702,
492,
7787,
12,
12831,
890,
199,
504,
900,
492,
486,
8180,
12,
14053,
199,
199,
697,
23333,
63,
890,
275,
7960,
199,
83,
14023,
63,
890,
275,
841,
627,
1592,
23333,
63,
890,
199,
32008,
890,
275,
488,
199,
11244,
63,
422,
275,
413,
199,
199,
2864,
63,
7125,
63,
3978,
275,
378,
199,
7125,
63,
3053,
8021,
63,
3978,
275,
959,
199,
4896,
63,
9740,
63,
4305,
63,
3978,
275,
1520,
199,
4283,
63,
9740,
63,
4305,
63,
3978,
275,
1695,
199,
4896,
63,
56,
998,
63,
4305,
63,
3978,
275,
1749,
199,
4283,
63,
56,
998,
63,
4305,
63,
3978,
275,
1616,
199,
13883,
63,
1093,
49,
63,
3978,
275,
4119,
199,
17433,
2684,
1309,
63,
3978,
275,
3144,
199,
1438,
7689,
63,
3978,
275,
4944,
199,
10973,
63,
3978,
275,
3388,
199,
199,
583,
73,
63,
2629,
755,
275,
378,
88,
614,
199,
23387,
63,
2629,
275,
378,
88,
709,
199,
18587,
63,
2629,
259,
275,
378,
88,
1165,
199,
199,
1361,
6574,
275,
283,
11371,
23459,
28114,
9539,
3,
22074,
6,
3985,
25608,
11,
3057,
13186,
26,
27,
12932,
30,
31,
32,
59,
1103,
61,
62,
28116,
91,
92,
93,
94,
283,
4388,
199,
3,
389,
2288,
3423,
19691,
17575,
199,
199,
318,
2248,
8,
70,
12,
8531,
304,
272,
1249,
275,
2248,
63,
589,
8,
70,
12,
8531,
9,
272,
5516,
275,
8531,
14,
328,
20129,
323,
8,
589,
9,
272,
754,
275,
5516,
2031,
589,
9,
272,
340,
5516,
1137,
8531,
26,
267,
754,
14,
826,
8,
70,
12,
627,
912,
63,
589,
8,
70,
12,
5516,
430,
272,
754,
14,
2759,
8,
70,
9,
272,
372,
754,
27,
199,
199,
318,
2248,
63,
589,
8,
70,
12,
8531,
304,
272,
1568,
275,
12831,
890,
8,
11645,
14,
908,
9,
272,
289,
1997,
83,
275,
289,
14,
9974,
1062,
272,
2517,
275,
289,
14,
739,
8,
890,
9,
272,
340,
822,
8,
1393,
9,
1137,
1568,
26,
267,
746,
2186,
480,
500,
402,
570,
531,
272,
372,
289,
1997,
83,
435,
7787,
8,
11645,
14,
908,
12,
2517,
9,
199,
199,
318,
1568,
63,
3345,
6080,
8,
890,
12,
22742,
63,
890,
304,
272,
372,
334,
890,
435,
22742,
63,
890,
446,
413,
2447,
14023,
63,
890,
199,
199,
318,
18798,
63,
262,
63,
14023,
8,
70,
12,
22742,
63,
890,
304,
272,
289,
1997,
83,
275,
289,
14,
9974,
342,
272,
372,
334,
890,
63,
3345,
6080,
8,
70,
14,
9974,
1062,
22742,
63,
890,
9,
627,
22742,
63,
890,
9,
446,
289,
1997,
83,
27,
199,
199,
318,
570,
63,
2861,
8,
70,
304,
272,
372,
289,
14,
9974,
342,
2356,
1335,
70,
890,
199,
199,
318,
365,
20557,
8,
83,
304,
272,
372,
308,
14,
1913,
8,
1361,
6574,
9,
508,
2125,
199,
199,
318,
870,
63,
21352,
8,
21352,
890,
12,
23382,
304,
272,
340,
23382,
508,
488,
26,
267,
340,
23382,
890,
690,
378,
26,
288,
746,
2186,
360,
607,
15478,
1323,
998,
1568,
26,
23382,
890,
2458,
68,
12,
23382,
29,
403,
7,
450,
23382,
890,
9,
267,
372,
2125,
272,
340,
365,
20557,
8,
21352,
304,
267,
23382,
495,
275,
3715,
63,
495,
8,
21352,
9,
272,
587,
26,
267,
23382,
495,
275,
6318,
63,
1294,
63,
495,
8,
21352,
9,
272,
340,
23382,
890,
1137,
822,
8,
21352,
304,
267,
746,
2186,
360,
607,
15478,
1323,
998,
1568,
26,
23382,
890,
2458,
68,
12,
23382,
4042,
68,
9,
26766,
83,
4451,
7,
450,
334,
21352,
890,
12,
822,
8,
21352,
395,
23382,
495,
430,
272,
372,
283,
21352,
4042,
68,
9,
26766,
83,
4451,
283,
450,
334,
21352,
890,
12,
23382,
495,
9,
199,
199,
318,
870,
63,
576,
8,
68,
890,
12,
666,
304,
272,
340,
666,
508,
488,
26,
267,
372,
2125,
272,
340,
365,
20557,
8,
576,
304,
267,
666,
495,
275,
3715,
63,
495,
8,
576,
9,
272,
587,
26,
267,
666,
495,
275,
6318,
63,
1294,
63,
495,
8,
576,
9,
272,
340,
366,
890,
1137,
822,
8,
576,
304,
267,
746,
2186,
360,
607,
15478,
666,
1568,
26,
366,
890,
2458,
68,
12,
666,
4042,
68,
9,
26766,
83,
4451,
7,
450,
334,
68,
890,
12,
822,
8,
576,
395,
666,
495,
430,
272,
372,
283,
576,
4042,
68,
9,
26766,
83,
4451,
283,
450,
334,
68,
890,
12,
666,
495,
9,
199,
199,
318,
6318,
63,
1294,
63,
495,
8,
83,
12,
3715,
63,
890,
275,
5238,
304,
272,
340,
822,
8,
83,
9,
2695,
3715,
63,
890,
26,
267,
372,
6318,
63,
495,
8,
83,
12,
378,
12,
822,
8,
83,
430,
272,
340,
822,
8,
83,
9,
690,
3715,
63,
890,
435,
5661,
26,
267,
372,
6318,
63,
495,
8,
83,
12,
378,
12,
1616,
9,
435,
283,
2263,
283,
435,
6318,
63,
495,
8,
83,
12,
12766,
12,
11738,
9,
435,
283,
2263,
283,
435,
6318,
63
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
199,
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,
3,
199,
199,
646,
984,
199,
646,
12733,
199,
646,
1059,
199,
646,
2748,
14,
11531,
14,
27098,
199,
504,
2702,
492,
7787,
12,
12831,
890,
199,
504,
900,
492,
486,
8180,
12,
14053,
199,
199,
697,
23333,
63,
890,
275,
7960,
199,
83,
14023,
63,
890,
275,
841,
627,
1592,
23333,
63,
890,
199,
32008,
890,
275,
488,
199,
11244,
63,
422,
275,
413,
199,
199,
2864,
63,
7125,
63,
3978,
275,
378,
199,
7125,
63,
3053,
8021,
63,
3978,
275,
959,
199,
4896,
63,
9740,
63,
4305,
63,
3978,
275,
1520,
199,
4283,
63,
9740,
63,
4305,
63,
3978,
275,
1695,
199,
4896,
63,
56,
998,
63,
4305,
63,
3978,
275,
1749,
199,
4283,
63,
56,
998,
63,
4305,
63,
3978,
275,
1616,
199,
13883,
63,
1093,
49,
63,
3978,
275,
4119,
199,
17433,
2684,
1309,
63,
3978,
275,
3144,
199,
1438,
7689,
63,
3978,
275,
4944,
199,
10973,
63,
3978,
275,
3388,
199,
199,
583,
73,
63,
2629,
755,
275,
378,
88,
614,
199,
23387,
63,
2629,
275,
378,
88,
709,
199,
18587,
63,
2629,
259,
275,
378,
88,
1165,
199,
199,
1361,
6574,
275,
283,
11371,
23459,
28114,
9539,
3,
22074,
6,
3985,
25608,
11,
3057,
13186,
26,
27,
12932,
30,
31,
32,
59,
1103,
61,
62,
28116,
91,
92,
93,
94,
283,
4388,
199,
3,
389,
2288,
3423,
19691,
17575,
199,
199,
318,
2248,
8,
70,
12,
8531,
304,
272,
1249,
275,
2248,
63,
589,
8,
70,
12,
8531,
9,
272,
5516,
275,
8531,
14,
328,
20129,
323,
8,
589,
9,
272,
754,
275,
5516,
2031,
589,
9,
272,
340,
5516,
1137,
8531,
26,
267,
754,
14,
826,
8,
70,
12,
627,
912,
63,
589,
8,
70,
12,
5516,
430,
272,
754,
14,
2759,
8,
70,
9,
272,
372,
754,
27,
199,
199,
318,
2248,
63,
589,
8,
70,
12,
8531,
304,
272,
1568,
275,
12831,
890,
8,
11645,
14,
908,
9,
272,
289,
1997,
83,
275,
289,
14,
9974,
1062,
272,
2517,
275,
289,
14,
739,
8,
890,
9,
272,
340,
822,
8,
1393,
9,
1137,
1568,
26,
267,
746,
2186,
480,
500,
402,
570,
531,
272,
372,
289,
1997,
83,
435,
7787,
8,
11645,
14,
908,
12,
2517,
9,
199,
199,
318,
1568,
63,
3345,
6080,
8,
890,
12,
22742,
63,
890,
304,
272,
372,
334,
890,
435,
22742,
63,
890,
446,
413,
2447,
14023,
63,
890,
199,
199,
318,
18798,
63,
262,
63,
14023,
8,
70,
12,
22742,
63,
890,
304,
272,
289,
1997,
83,
275,
289,
14,
9974,
342,
272,
372,
334,
890,
63,
3345,
6080,
8,
70,
14,
9974,
1062,
22742,
63,
890,
9,
627,
22742,
63,
890,
9,
446,
289,
1997,
83,
27,
199,
199,
318,
570,
63,
2861,
8,
70,
304,
272,
372,
289,
14,
9974,
342,
2356,
1335,
70,
890,
199,
199,
318,
365,
20557,
8,
83,
304,
272,
372,
308,
14,
1913,
8,
1361,
6574,
9,
508,
2125,
199,
199,
318,
870,
63,
21352,
8,
21352,
890,
12,
23382,
304,
272,
340,
23382,
508,
488,
26,
267,
340,
23382,
890,
690,
378,
26,
288,
746,
2186,
360,
607,
15478,
1323,
998,
1568,
26,
23382,
890,
2458,
68,
12,
23382,
29,
403,
7,
450,
23382,
890,
9,
267,
372,
2125,
272,
340,
365,
20557,
8,
21352,
304,
267,
23382,
495,
275,
3715,
63,
495,
8,
21352,
9,
272,
587,
26,
267,
23382,
495,
275,
6318,
63,
1294,
63,
495,
8,
21352,
9,
272,
340,
23382,
890,
1137,
822,
8,
21352,
304,
267,
746,
2186,
360,
607,
15478,
1323,
998,
1568,
26,
23382,
890,
2458,
68,
12,
23382,
4042,
68,
9,
26766,
83,
4451,
7,
450,
334,
21352,
890,
12,
822,
8,
21352,
395,
23382,
495,
430,
272,
372,
283,
21352,
4042,
68,
9,
26766,
83,
4451,
283,
450,
334,
21352,
890,
12,
23382,
495,
9,
199,
199,
318,
870,
63,
576,
8,
68,
890,
12,
666,
304,
272,
340,
666,
508,
488,
26,
267,
372,
2125,
272,
340,
365,
20557,
8,
576,
304,
267,
666,
495,
275,
3715,
63,
495,
8,
576,
9,
272,
587,
26,
267,
666,
495,
275,
6318,
63,
1294,
63,
495,
8,
576,
9,
272,
340,
366,
890,
1137,
822,
8,
576,
304,
267,
746,
2186,
360,
607,
15478,
666,
1568,
26,
366,
890,
2458,
68,
12,
666,
4042,
68,
9,
26766,
83,
4451,
7,
450,
334,
68,
890,
12,
822,
8,
576,
395,
666,
495,
430,
272,
372,
283,
576,
4042,
68,
9,
26766,
83,
4451,
283,
450,
334,
68,
890,
12,
666,
495,
9,
199,
199,
318,
6318,
63,
1294,
63,
495,
8,
83,
12,
3715,
63,
890,
275,
5238,
304,
272,
340,
822,
8,
83,
9,
2695,
3715,
63,
890,
26,
267,
372,
6318,
63,
495,
8,
83,
12,
378,
12,
822,
8,
83,
430,
272,
340,
822,
8,
83,
9,
690,
3715,
63,
890,
435,
5661,
26,
267,
372,
6318,
63,
495,
8,
83,
12,
378,
12,
1616,
9,
435,
283,
2263,
283,
435,
6318,
63,
495,
8,
83,
12,
12766,
12,
11738,
9,
435,
283,
2263,
283,
435,
6318,
63,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
manishpatell/erpcustomizationssaiimpex123qwe
|
addons/stock_account/wizard/__init__.py
|
351
|
1105
|
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import stock_change_standard_price
import stock_invoice_onshipping
import stock_valuation_history
import stock_return_picking
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
646,
10952,
63,
1461,
63,
6807,
63,
4777,
199,
646,
10952,
63,
5404,
63,
265,
17801,
199,
646,
10952,
63,
27456,
63,
5570,
199,
646,
10952,
63,
1107,
63,
11463,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
646,
10952,
63,
1461,
63,
6807,
63,
4777,
199,
646,
10952,
63,
5404,
63,
265,
17801,
199,
646,
10952,
63,
27456,
63,
5570,
199,
646,
10952,
63,
1107,
63,
11463,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
ClaudeZoo/volatility
|
volatility/plugins/malware/idt.py
|
44
|
11570
|
# Volatility
# Copyright (C) 2007-2013 Volatility Foundation
# Copyright (c) 2010, 2011, 2012 Michael Ligh <michael.ligh@mnin.org>
#
# This file is part of Volatility.
#
# Volatility is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# Volatility is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Volatility. If not, see <http://www.gnu.org/licenses/>.
#
import volatility.utils as utils
import volatility.obj as obj
import volatility.plugins.common as common
import volatility.win32.modules as modules
import volatility.win32.tasks as tasks
import volatility.debug as debug
import volatility.plugins.malware.malfind as malfind
import volatility.exceptions as exceptions
#--------------------------------------------------------------------------------
# constants
#--------------------------------------------------------------------------------
GDT_DESCRIPTORS = dict(enumerate([
"Data RO",
"Data RO Ac",
"Data RW",
"Data RW Ac",
"Data RO E",
"Data RO EA",
"Data RW E",
"Data RW EA",
"Code EO",
"Code EO Ac",
"Code RE",
"Code RE Ac",
"Code EO C",
"Code EO CA",
"Code RE C",
"Code RE CA",
"<Reserved>",
"TSS16 Avl",
"LDT",
"TSS16 Busy",
"CallGate16",
"TaskGate",
"Int Gate16",
"TrapGate16",
"<Reserved>",
"TSS32 Avl",
"<Reserved>",
"TSS32 Busy",
"CallGate32",
"<Reserved>",
"Int Gate32",
"TrapGate32",
]))
#--------------------------------------------------------------------------------
# object classes
#--------------------------------------------------------------------------------
class _KIDTENTRY(obj.CType):
"""Class for interrupt descriptors"""
@property
def Address(self):
"""Return the address of the IDT entry handler"""
if self.ExtendedOffset == 0:
return 0
return (self.ExtendedOffset.v() << 16 | self.Offset.v())
class _KGDTENTRY(obj.CType):
"""A class for GDT entries"""
@property
def Type(self):
"""Get a string name of the descriptor type"""
flag = self.HighWord.Bits.Type.v() & 1 << 4
typeval = self.HighWord.Bits.Type.v() & ~(1 << 4)
if flag == 0:
typeval += 16
return GDT_DESCRIPTORS.get(typeval, "UNKNOWN")
@property
def Base(self):
"""Get the base (start) of memory for this GDT"""
return (self.BaseLow + ((self.HighWord.Bits.BaseMid +
(self.HighWord.Bits.BaseHi << 8)) << 16))
@property
def Limit(self):
"""Get the limit (end) of memory for this GDT"""
limit = (self.HighWord.Bits.LimitHi.v() << 16) | self.LimitLow.v()
if self.HighWord.Bits.Granularity == 1:
limit = (limit + 1) * 0x1000
limit -= 1
return limit
@property
def CallGate(self):
"""Get the call gate address"""
return self.HighWord.v() & 0xffff0000 | self.LimitLow.v()
@property
def Present(self):
"""Returns True if the entry is present"""
return self.HighWord.Bits.Pres == 1
@property
def Granularity(self):
"""Returns True if page granularity is used. Otherwise
returns False indicating byte granularity is used."""
return self.HighWord.Bits.Granularity == 1
@property
def Dpl(self):
"""Returns the descriptor privilege level"""
return self.HighWord.Bits.Dpl
#--------------------------------------------------------------------------------
# profile modifications
#--------------------------------------------------------------------------------
class MalwareIDTGDTx86(obj.ProfileModification):
before = ['WindowsObjectClasses', 'WindowsOverlay']
conditions = {'os': lambda x: x == 'windows',
'memory_model': lambda x: x == '32bit'}
def modification(self, profile):
profile.object_classes.update({
'_KIDTENTRY': _KIDTENTRY,
'_KGDTENTRY': _KGDTENTRY,
})
profile.merge_overlay({"_KPCR" : [None,
{'IDT': [None,
["pointer", ["array", 256, ['_KIDTENTRY']]]],
}]})
# Since the real GDT size is read from a register, we'll just assume
# that there are 128 entries (which is normal for most OS)
profile.merge_overlay({"_KPCR" : [None,
{'GDT': [None,
["pointer", ["array", 128, ['_KGDTENTRY']]]],
}]})
#--------------------------------------------------------------------------------
# GDT plugin
#--------------------------------------------------------------------------------
class GDT(common.AbstractWindowsCommand):
"Display Global Descriptor Table"
@staticmethod
def is_valid_profile(profile):
return (profile.metadata.get('os', 'unknown') == 'windows' and
profile.metadata.get('memory_model', '32bit') == '32bit')
def calculate(self):
addr_space = utils.load_as(self._config)
# Currently we only support x86. The x64 does still have a GDT
# but hooking is prohibited and results in bugcheck.
if not self.is_valid_profile(addr_space.profile):
debug.error("This command does not support the selected profile.")
for kpcr in tasks.get_kdbg(addr_space).kpcrs():
for i, entry in kpcr.gdt_entries():
yield i, entry
def render_text(self, outfd, data):
self.table_header(outfd, [('CPU', '>6'),
('Sel', '[addr]'),
('Base', '[addrpad]'),
('Limit', '[addrpad]'),
('Type', '<14'),
('DPL', '>6'),
('Gr', '<4'),
('Pr', '<4')
])
for n, entry in data:
selector = n * 8
# Is the entry present? This applies to all types of GDT entries
if entry.Present:
present = "P"
else:
present = "Np"
# The base, limit, and granularity is calculated differently
# for 32bit call gates than they are for all other types.
if entry.Type == 'CallGate32':
base = entry.CallGate
limit = 0
granularity = '-'
else:
base = entry.Base
limit = entry.Limit
if entry.Granularity:
granularity = "Pg"
else:
granularity = "By"
# The parent is GDT. The grand-parent is _KPCR
cpu_number = entry.obj_parent.obj_parent.ProcessorBlock.Number
self.table_row(outfd,
cpu_number,
selector,
base, limit,
entry.Type,
entry.Dpl,
granularity,
present)
#--------------------------------------------------------------------------------
# IDT plugin
#--------------------------------------------------------------------------------
class IDT(common.AbstractWindowsCommand):
"Display Interrupt Descriptor Table"
@staticmethod
def is_valid_profile(profile):
return (profile.metadata.get('os', 'unknown') == 'windows' and
profile.metadata.get('memory_model', '32bit') == '32bit')
@staticmethod
def get_section_name(mod, addr):
"""Get the name of the PE section containing
the specified address.
@param mod: an _LDR_DATA_TABLE_ENTRY
@param addr: virtual address to lookup
@returns string PE section name
"""
try:
dos_header = obj.Object("_IMAGE_DOS_HEADER",
offset = mod.DllBase, vm = mod.obj_vm)
nt_header = dos_header.get_nt_header()
except (ValueError, exceptions.SanityCheckException):
return ''
for sec in nt_header.get_sections(False):
if (addr > mod.DllBase + sec.VirtualAddress and
addr < sec.Misc.VirtualSize + (mod.DllBase + sec.VirtualAddress)):
return str(sec.Name or '')
return ''
def calculate(self):
addr_space = utils.load_as(self._config)
# Currently we only support x86. The x64 does still have a IDT
# but hooking is prohibited and results in bugcheck.
if not self.is_valid_profile(addr_space.profile):
debug.error("This command does not support the selected profile.")
mods = dict((addr_space.address_mask(mod.DllBase), mod) for mod in modules.lsmod(addr_space))
mod_addrs = sorted(mods.keys())
for kpcr in tasks.get_kdbg(addr_space).kpcrs():
# Get the GDT for access to selector bases
gdt = dict((i * 8, sd) for i, sd in kpcr.gdt_entries())
for i, entry in kpcr.idt_entries():
# Where the IDT entry points.
addr = entry.Address
# Per MITRE, add the GDT selector base if available.
# This allows us to detect sneaky attempts to hook IDT
# entries by changing the entry's GDT selector.
gdt_entry = gdt.get(entry.Selector.v())
if gdt_entry != None and "Code" in gdt_entry.Type:
addr += gdt_entry.Base
# Lookup the function's owner
module = tasks.find_module(mods, mod_addrs, addr_space.address_mask(addr))
yield i, entry, addr, module
def render_text(self, outfd, data):
self.table_header(outfd, [('CPU', '>6X'),
('Index', '>6X'),
('Selector', '[addr]'),
('Value', '[addrpad]'),
('Module', '20'),
('Section', '12'),
])
for n, entry, addr, module in data:
if module:
module_name = str(module.BaseDllName or '')
sect_name = self.get_section_name(module, addr)
else:
module_name = "UNKNOWN"
sect_name = ''
# The parent is IDT. The grand-parent is _KPCR.
cpu_number = entry.obj_parent.obj_parent.ProcessorBlock.Number
self.table_row(outfd,
cpu_number, n,
entry.Selector,
addr,
module_name,
sect_name)
if self._config.verbose:
data = entry.obj_vm.zread(addr, 32)
outfd.write("\n".join(
["{0:#x} {1:<16} {2}".format(o, h, i)
for o, i, h in malfind.Disassemble(data = data, start = addr, stoponret = True)
]))
outfd.write("\n")
|
gpl-2.0
|
[
3,
28367,
199,
3,
1898,
334,
35,
9,
10219,
13,
6965,
28367,
2752,
199,
3,
1898,
334,
67,
9,
7129,
12,
7760,
12,
6029,
16922,
491,
2056,
665,
22333,
14,
18975,
32,
10344,
262,
14,
1308,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
28367,
14,
199,
3,
199,
3,
28367,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
28367,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
28367,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
199,
646,
5236,
18783,
14,
1208,
465,
3778,
199,
646,
5236,
18783,
14,
1113,
465,
1559,
199,
646,
5236,
18783,
14,
5265,
14,
2330,
465,
2863,
199,
646,
5236,
18783,
14,
2676,
708,
14,
3112,
465,
4621,
199,
646,
5236,
18783,
14,
2676,
708,
14,
5054,
465,
6527,
199,
646,
5236,
18783,
14,
1757,
465,
3105,
199,
646,
5236,
18783,
14,
5265,
14,
2174,
1068,
14,
391,
276,
688,
465,
610,
276,
688,
199,
646,
5236,
18783,
14,
3924,
465,
4967,
199,
199,
7656,
777,
199,
3,
5262,
221,
199,
7656,
777,
199,
199,
39,
7438,
63,
6597,
4149,
275,
1211,
8,
26318,
779,
272,
298,
1451,
9769,
401,
272,
298,
1451,
9769,
4473,
401,
272,
298,
1451,
820,
55,
401,
272,
298,
1451,
820,
55,
4473,
401,
272,
298,
1451,
9769,
662,
401,
272,
298,
1451,
9769,
662,
33,
401,
272,
298,
1451,
820,
55,
662,
401,
272,
298,
1451,
820,
55,
662,
33,
401,
272,
298,
3034,
662,
47,
401,
272,
298,
3034,
662,
47,
4473,
401,
272,
298,
3034,
5363,
401,
272,
298,
3034,
5363,
4473,
401,
272,
298,
3034,
662,
47,
445,
401,
272,
298,
3034,
662,
47,
7240,
401,
272,
298,
3034,
5363,
445,
401,
272,
298,
3034,
5363,
7240,
401,
272,
3886,
10285,
7166,
272,
298,
52,
2300,
975,
437,
7300,
401,
272,
298,
6533,
52,
401,
272,
298,
52,
2300,
975,
18573,
89,
401,
272,
298,
2176,
13994,
975,
401,
272,
298,
4476,
13994,
401,
272,
298,
3241,
598,
323,
975,
401,
272,
298,
52,
1330,
13994,
975,
401,
272,
3886,
10285,
7166,
272,
298,
52,
2300,
708,
437,
7300,
401,
272,
3886,
10285,
7166,
272,
298,
52,
2300,
708,
18573,
89,
401,
272,
298,
2176,
13994,
708,
401,
272,
3886,
10285,
7166,
272,
298,
3241,
598,
323,
708,
401,
272,
298,
52,
1330,
13994,
708,
401,
199,
2459,
199,
199,
7656,
777,
199,
3,
909,
3992,
257,
199,
7656,
777,
199,
199,
533,
485,
43,
998,
52,
7285,
8,
1113,
14,
35,
804,
304,
272,
408,
2543,
367,
26791,
15428,
624,
339,
768,
1829,
272,
347,
9906,
8,
277,
304,
267,
408,
1767,
314,
2287,
402,
314,
2870,
52,
2397,
3016,
624,
398,
340,
291,
14,
14107,
6397,
508,
378,
26,
288,
372,
378,
398,
372,
334,
277,
14,
14107,
6397,
14,
86,
342,
5213,
3193,
1204,
291,
14,
6397,
14,
86,
1012,
199,
199,
533,
485,
14634,
7438,
7285,
8,
1113,
14,
35,
804,
304,
272,
408,
33,
1021,
367,
598,
7438,
4811,
624,
339,
768,
1829,
272,
347,
2434,
8,
277,
304,
267,
408,
1002,
282,
1059,
536,
402,
314,
5872,
730,
624,
398,
3305,
275,
291,
14,
11688,
10155,
14,
10787,
14,
804,
14,
86,
342,
1253,
413,
5213,
841,
267,
730,
637,
275,
291,
14,
11688,
10155,
14,
10787,
14,
804,
14,
86,
342,
1253,
6146,
8,
17,
5213,
841,
9,
398,
340,
3305,
508,
378,
26,
288,
730,
637,
847,
3193,
398,
372,
598,
7438,
63,
6597,
4149,
14,
362,
8,
466,
637,
12,
298,
11588,
531,
339,
768,
1829,
272,
347,
3523,
8,
277,
304,
267,
408,
1002,
314,
1300,
334,
928,
9,
402,
4402,
367,
642,
598,
7438,
624,
267,
372,
334,
277,
14,
1563,
10281,
435,
3666,
277,
14,
11688,
10155,
14,
10787,
14,
1563,
28735,
435,
2049,
334,
277,
14,
11688,
10155,
14,
10787,
14,
1563,
16106,
5213,
1695,
430,
5213,
3193,
430,
339,
768,
1829,
272,
347,
22672,
8,
277,
304,
267,
408,
1002,
314,
2304,
334,
500,
9,
402,
4402,
367,
642,
598,
7438,
624,
267,
2304,
275,
334,
277,
14,
11688,
10155,
14,
10787,
14,
8407,
16106,
14,
86,
342,
5213,
3193,
9,
1204,
291,
14,
8407,
10281,
14,
86,
342,
398,
340,
291,
14,
11688,
10155,
14,
10787,
14,
39,
1312,
22504,
508,
413,
26,
288,
2304,
275,
334,
3097,
435,
413,
9,
627,
378,
88,
5279,
288,
2304,
4862,
413,
398,
372,
2304,
339,
768,
1829,
272,
347,
6523,
13994,
8,
277,
304,
267,
408,
1002,
314,
1240,
17036,
2287,
624,
267,
372,
291,
14,
11688,
10155,
14,
86,
342,
1253,
378,
27581,
993,
1204,
291,
14,
8407,
10281,
14,
86,
342,
339,
768,
1829,
272,
347,
5543,
1150,
8,
277,
304,
267,
408,
3407,
715,
340,
314,
2397,
365,
3451,
624,
267,
372,
291,
14,
11688,
10155,
14,
10787,
14,
48,
470,
508,
413,
339,
768,
1829,
272,
347,
598,
1312,
22504,
8,
277,
304,
267,
408,
3407,
715,
340,
2034,
9202,
22504,
365,
1202,
14,
6630,
267,
2529,
756,
9297,
3696,
9202,
22504,
365,
1202,
1041,
267,
372,
291,
14,
11688,
10155,
14,
10787,
14,
39,
1312,
22504,
508,
413,
339,
768,
1829,
272,
347,
577,
1168,
8,
277,
304,
267,
408,
3407,
314,
5872,
1979,
17228,
2166,
624,
267,
372,
291,
14,
11688,
10155,
14,
10787,
14,
36,
1168,
199,
199,
7656,
777,
199,
3,
4690,
23070,
221,
199,
7656,
777,
199,
199,
533,
29936,
1068,
998,
6332,
7438,
88,
1184,
8,
1113,
14,
5736,
29188,
304,
272,
2544,
275
] |
[
28367,
199,
3,
1898,
334,
35,
9,
10219,
13,
6965,
28367,
2752,
199,
3,
1898,
334,
67,
9,
7129,
12,
7760,
12,
6029,
16922,
491,
2056,
665,
22333,
14,
18975,
32,
10344,
262,
14,
1308,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
28367,
14,
199,
3,
199,
3,
28367,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
28367,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
28367,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
199,
646,
5236,
18783,
14,
1208,
465,
3778,
199,
646,
5236,
18783,
14,
1113,
465,
1559,
199,
646,
5236,
18783,
14,
5265,
14,
2330,
465,
2863,
199,
646,
5236,
18783,
14,
2676,
708,
14,
3112,
465,
4621,
199,
646,
5236,
18783,
14,
2676,
708,
14,
5054,
465,
6527,
199,
646,
5236,
18783,
14,
1757,
465,
3105,
199,
646,
5236,
18783,
14,
5265,
14,
2174,
1068,
14,
391,
276,
688,
465,
610,
276,
688,
199,
646,
5236,
18783,
14,
3924,
465,
4967,
199,
199,
7656,
777,
199,
3,
5262,
221,
199,
7656,
777,
199,
199,
39,
7438,
63,
6597,
4149,
275,
1211,
8,
26318,
779,
272,
298,
1451,
9769,
401,
272,
298,
1451,
9769,
4473,
401,
272,
298,
1451,
820,
55,
401,
272,
298,
1451,
820,
55,
4473,
401,
272,
298,
1451,
9769,
662,
401,
272,
298,
1451,
9769,
662,
33,
401,
272,
298,
1451,
820,
55,
662,
401,
272,
298,
1451,
820,
55,
662,
33,
401,
272,
298,
3034,
662,
47,
401,
272,
298,
3034,
662,
47,
4473,
401,
272,
298,
3034,
5363,
401,
272,
298,
3034,
5363,
4473,
401,
272,
298,
3034,
662,
47,
445,
401,
272,
298,
3034,
662,
47,
7240,
401,
272,
298,
3034,
5363,
445,
401,
272,
298,
3034,
5363,
7240,
401,
272,
3886,
10285,
7166,
272,
298,
52,
2300,
975,
437,
7300,
401,
272,
298,
6533,
52,
401,
272,
298,
52,
2300,
975,
18573,
89,
401,
272,
298,
2176,
13994,
975,
401,
272,
298,
4476,
13994,
401,
272,
298,
3241,
598,
323,
975,
401,
272,
298,
52,
1330,
13994,
975,
401,
272,
3886,
10285,
7166,
272,
298,
52,
2300,
708,
437,
7300,
401,
272,
3886,
10285,
7166,
272,
298,
52,
2300,
708,
18573,
89,
401,
272,
298,
2176,
13994,
708,
401,
272,
3886,
10285,
7166,
272,
298,
3241,
598,
323,
708,
401,
272,
298,
52,
1330,
13994,
708,
401,
199,
2459,
199,
199,
7656,
777,
199,
3,
909,
3992,
257,
199,
7656,
777,
199,
199,
533,
485,
43,
998,
52,
7285,
8,
1113,
14,
35,
804,
304,
272,
408,
2543,
367,
26791,
15428,
624,
339,
768,
1829,
272,
347,
9906,
8,
277,
304,
267,
408,
1767,
314,
2287,
402,
314,
2870,
52,
2397,
3016,
624,
398,
340,
291,
14,
14107,
6397,
508,
378,
26,
288,
372,
378,
398,
372,
334,
277,
14,
14107,
6397,
14,
86,
342,
5213,
3193,
1204,
291,
14,
6397,
14,
86,
1012,
199,
199,
533,
485,
14634,
7438,
7285,
8,
1113,
14,
35,
804,
304,
272,
408,
33,
1021,
367,
598,
7438,
4811,
624,
339,
768,
1829,
272,
347,
2434,
8,
277,
304,
267,
408,
1002,
282,
1059,
536,
402,
314,
5872,
730,
624,
398,
3305,
275,
291,
14,
11688,
10155,
14,
10787,
14,
804,
14,
86,
342,
1253,
413,
5213,
841,
267,
730,
637,
275,
291,
14,
11688,
10155,
14,
10787,
14,
804,
14,
86,
342,
1253,
6146,
8,
17,
5213,
841,
9,
398,
340,
3305,
508,
378,
26,
288,
730,
637,
847,
3193,
398,
372,
598,
7438,
63,
6597,
4149,
14,
362,
8,
466,
637,
12,
298,
11588,
531,
339,
768,
1829,
272,
347,
3523,
8,
277,
304,
267,
408,
1002,
314,
1300,
334,
928,
9,
402,
4402,
367,
642,
598,
7438,
624,
267,
372,
334,
277,
14,
1563,
10281,
435,
3666,
277,
14,
11688,
10155,
14,
10787,
14,
1563,
28735,
435,
2049,
334,
277,
14,
11688,
10155,
14,
10787,
14,
1563,
16106,
5213,
1695,
430,
5213,
3193,
430,
339,
768,
1829,
272,
347,
22672,
8,
277,
304,
267,
408,
1002,
314,
2304,
334,
500,
9,
402,
4402,
367,
642,
598,
7438,
624,
267,
2304,
275,
334,
277,
14,
11688,
10155,
14,
10787,
14,
8407,
16106,
14,
86,
342,
5213,
3193,
9,
1204,
291,
14,
8407,
10281,
14,
86,
342,
398,
340,
291,
14,
11688,
10155,
14,
10787,
14,
39,
1312,
22504,
508,
413,
26,
288,
2304,
275,
334,
3097,
435,
413,
9,
627,
378,
88,
5279,
288,
2304,
4862,
413,
398,
372,
2304,
339,
768,
1829,
272,
347,
6523,
13994,
8,
277,
304,
267,
408,
1002,
314,
1240,
17036,
2287,
624,
267,
372,
291,
14,
11688,
10155,
14,
86,
342,
1253,
378,
27581,
993,
1204,
291,
14,
8407,
10281,
14,
86,
342,
339,
768,
1829,
272,
347,
5543,
1150,
8,
277,
304,
267,
408,
3407,
715,
340,
314,
2397,
365,
3451,
624,
267,
372,
291,
14,
11688,
10155,
14,
10787,
14,
48,
470,
508,
413,
339,
768,
1829,
272,
347,
598,
1312,
22504,
8,
277,
304,
267,
408,
3407,
715,
340,
2034,
9202,
22504,
365,
1202,
14,
6630,
267,
2529,
756,
9297,
3696,
9202,
22504,
365,
1202,
1041,
267,
372,
291,
14,
11688,
10155,
14,
10787,
14,
39,
1312,
22504,
508,
413,
339,
768,
1829,
272,
347,
577,
1168,
8,
277,
304,
267,
408,
3407,
314,
5872,
1979,
17228,
2166,
624,
267,
372,
291,
14,
11688,
10155,
14,
10787,
14,
36,
1168,
199,
199,
7656,
777,
199,
3,
4690,
23070,
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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
] |
Mzero2010/MaxZone
|
plugin.video.Mzero/servers/videowood.py
|
4
|
1962
|
# -*- coding: iso-8859-1 -*-
# ------------------------------------------------------------
# pelisalacarta - XBMC Plugin
# Conector for videowood.tv
# http://blog.tvalacarta.info/plugin-xbmc/pelisalacarta/
# by DrZ3r0
# ------------------------------------------------------------
import re
from core import logger
from core import scrapertools
def test_video_exists(page_url):
logger.info("pelisalacarta.servers.videowood test_video_exists(page_url='%s')" % page_url)
data = scrapertools.cache_page(page_url)
if "This video doesn't exist." in data:
return False, 'The requested video was not found.'
return True, ""
def get_video_url(page_url, premium=False, user="", password="", video_password=""):
logger.info("pelisalacarta.servers.videowood url=" + page_url)
video_urls = []
data = scrapertools.cache_page(page_url)
text_encode = scrapertools.find_single_match(data, "(eval\(function\(p,a,c,k,e,d.*?)</script>")
from aadecode import decode as aadecode
text_decode = aadecode(text_encode)
# URL del vídeo
patron = "'([^']+)'"
media_url = scrapertools.find_single_match(text_decode, patron)
video_urls.append([media_url[-4:] + " [Videowood]", media_url])
return video_urls
# Encuentra vídeos del servidor en el texto pasado
def find_videos(data):
encontrados = set()
devuelve = []
patronvideos = r"https?://(?:www.)?videowood.tv/(?:embed/|video/)[0-9a-z]+"
logger.info("pelisalacarta.servers.videowood find_videos #" + patronvideos + "#")
matches = re.compile(patronvideos, re.DOTALL).findall(data)
for url in matches:
titulo = "[Videowood]"
url = url.replace('/video/', '/embed/')
if url not in encontrados:
logger.info(" url=" + url)
devuelve.append([titulo, url, 'videowood'])
encontrados.add(url)
else:
logger.info(" url duplicada=" + url)
return devuelve
|
gpl-3.0
|
[
3,
1882,
2803,
26,
11601,
13,
4830,
13,
17,
1882,
199,
3,
9527,
4559,
199,
3,
4837,
317,
6327,
645,
29549,
446,
1323,
28994,
11349,
199,
3,
445,
368,
630,
367,
1321,
271,
583,
23521,
14,
6993,
199,
3,
1455,
921,
11486,
14,
84,
637,
645,
29549,
14,
815,
15,
2718,
13,
21382,
15,
321,
317,
6327,
645,
29549,
15,
199,
3,
701,
577,
82,
58,
19,
82,
16,
199,
3,
9527,
4559,
199,
199,
646,
295,
199,
504,
6170,
492,
2512,
199,
504,
6170,
492,
28348,
421,
199,
318,
511,
63,
3722,
63,
2444,
8,
1606,
63,
633,
304,
272,
2512,
14,
815,
480,
321,
317,
6327,
645,
29549,
14,
5871,
14,
5624,
583,
23521,
511,
63,
3722,
63,
2444,
8,
1606,
63,
633,
9569,
83,
19124,
450,
2034,
63,
633,
9,
339,
666,
275,
28348,
14,
1637,
63,
1606,
8,
1606,
63,
633,
9,
339,
340,
298,
2765,
3991,
3181,
1133,
2187,
2122,
315,
666,
26,
267,
372,
756,
12,
283,
1918,
5839,
3991,
1990,
440,
1911,
3530,
339,
372,
715,
12,
3087,
421,
199,
318,
664,
63,
3722,
63,
633,
8,
1606,
63,
633,
12,
876,
23481,
29,
797,
12,
922,
8772,
2505,
8772,
3991,
63,
2060,
17364,
272,
2512,
14,
815,
480,
321,
317,
6327,
645,
29549,
14,
5871,
14,
5624,
583,
23521,
1166,
628,
435,
2034,
63,
633,
9,
272,
3991,
63,
3603,
275,
942,
339,
666,
275,
28348,
14,
1637,
63,
1606,
8,
1606,
63,
633,
9,
272,
1318,
63,
2143,
275,
28348,
14,
1623,
63,
4780,
63,
1431,
8,
576,
12,
7340,
2579,
24805,
1593,
24805,
80,
12,
65,
12,
67,
12,
75,
12,
69,
12,
68,
6697,
15939,
1579,
9579,
339,
687,
18319,
2708,
492,
4849,
465,
18319,
2708,
272,
1318,
63,
2708,
275,
18319,
2708,
8,
505,
63,
2143,
9,
339,
327,
2851,
2150,
373,
13676,
2172,
272,
32500,
275,
3546,
7059,
21899,
3171,
2,
272,
5898,
63,
633,
275,
28348,
14,
1623,
63,
4780,
63,
1431,
8,
505,
63,
2708,
12,
32500,
9,
339,
3991,
63,
3603,
14,
740,
779,
4603,
63,
633,
1988,
20,
2938,
435,
298,
359,
2201,
271,
583,
23521,
11472,
5898,
63,
633,
566,
339,
372,
3991,
63,
3603,
421,
199,
3,
3447,
15140,
484,
345,
373,
13676,
18808,
2150,
8926,
5017,
269,
655,
579,
1318,
79,
19099,
5129,
199,
318,
2342,
63,
11418,
8,
576,
304,
272,
655,
17926,
18339,
275,
663,
342,
272,
4866,
13086,
432,
275,
942,
339,
32500,
11418,
275,
519,
2,
2859,
24524,
1544,
4959,
31,
5624,
583,
23521,
14,
6993,
32576,
6427,
15,
92,
3722,
15,
2788,
16,
13,
25,
65,
13,
90,
2807,
2,
272,
2512,
14,
815,
480,
321,
317,
6327,
645,
29549,
14,
5871,
14,
5624,
583,
23521,
2342,
63,
11418,
20383,
435,
32500,
11418,
435,
5426,
531,
339,
4450,
275,
295,
14,
2014,
8,
10853,
2641,
11418,
12,
295,
14,
16504,
680,
6452,
8,
576,
9,
339,
367,
1166,
315,
4450,
26,
267,
3367,
10963,
320,
275,
7369,
2201,
271,
583,
23521,
8480,
267,
1166,
275,
1166,
14,
1814,
2336,
3722,
3678,
1994,
6427,
6217,
267,
340,
1166,
440,
315,
655,
17926,
18339,
26,
288,
2512,
14,
815,
480,
221,
1166,
628,
435,
1166,
9,
288,
4866,
13086,
432,
14,
740,
779,
6403,
13957,
12,
1166,
12,
283,
5624,
583,
23521,
1105,
288,
655,
17926,
18339,
14,
525,
8,
633,
9,
267,
587,
26,
288,
2512,
14,
815,
480,
221,
1166,
366,
4230,
10641,
628,
435,
1166,
9,
339,
372,
4866,
13086,
432,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
3,
9527,
4559,
199,
3,
4837,
317,
6327,
645,
29549,
446,
1323,
28994,
11349,
199,
3,
445,
368,
630,
367,
1321,
271,
583,
23521,
14,
6993,
199,
3,
1455,
921,
11486,
14,
84,
637,
645,
29549,
14,
815,
15,
2718,
13,
21382,
15,
321,
317,
6327,
645,
29549,
15,
199,
3,
701,
577,
82,
58,
19,
82,
16,
199,
3,
9527,
4559,
199,
199,
646,
295,
199,
504,
6170,
492,
2512,
199,
504,
6170,
492,
28348,
421,
199,
318,
511,
63,
3722,
63,
2444,
8,
1606,
63,
633,
304,
272,
2512,
14,
815,
480,
321,
317,
6327,
645,
29549,
14,
5871,
14,
5624,
583,
23521,
511,
63,
3722,
63,
2444,
8,
1606,
63,
633,
9569,
83,
19124,
450,
2034,
63,
633,
9,
339,
666,
275,
28348,
14,
1637,
63,
1606,
8,
1606,
63,
633,
9,
339,
340,
298,
2765,
3991,
3181,
1133,
2187,
2122,
315,
666,
26,
267,
372,
756,
12,
283,
1918,
5839,
3991,
1990,
440,
1911,
3530,
339,
372,
715,
12,
3087,
421,
199,
318,
664,
63,
3722,
63,
633,
8,
1606,
63,
633,
12,
876,
23481,
29,
797,
12,
922,
8772,
2505,
8772,
3991,
63,
2060,
17364,
272,
2512,
14,
815,
480,
321,
317,
6327,
645,
29549,
14,
5871,
14,
5624,
583,
23521,
1166,
628,
435,
2034,
63,
633,
9,
272,
3991,
63,
3603,
275,
942,
339,
666,
275,
28348,
14,
1637,
63,
1606,
8,
1606,
63,
633,
9,
272,
1318,
63,
2143,
275,
28348,
14,
1623,
63,
4780,
63,
1431,
8,
576,
12,
7340,
2579,
24805,
1593,
24805,
80,
12,
65,
12,
67,
12,
75,
12,
69,
12,
68,
6697,
15939,
1579,
9579,
339,
687,
18319,
2708,
492,
4849,
465,
18319,
2708,
272,
1318,
63,
2708,
275,
18319,
2708,
8,
505,
63,
2143,
9,
339,
327,
2851,
2150,
373,
13676,
2172,
272,
32500,
275,
3546,
7059,
21899,
3171,
2,
272,
5898,
63,
633,
275,
28348,
14,
1623,
63,
4780,
63,
1431,
8,
505,
63,
2708,
12,
32500,
9,
339,
3991,
63,
3603,
14,
740,
779,
4603,
63,
633,
1988,
20,
2938,
435,
298,
359,
2201,
271,
583,
23521,
11472,
5898,
63,
633,
566,
339,
372,
3991,
63,
3603,
421,
199,
3,
3447,
15140,
484,
345,
373,
13676,
18808,
2150,
8926,
5017,
269,
655,
579,
1318,
79,
19099,
5129,
199,
318,
2342,
63,
11418,
8,
576,
304,
272,
655,
17926,
18339,
275,
663,
342,
272,
4866,
13086,
432,
275,
942,
339,
32500,
11418,
275,
519,
2,
2859,
24524,
1544,
4959,
31,
5624,
583,
23521,
14,
6993,
32576,
6427,
15,
92,
3722,
15,
2788,
16,
13,
25,
65,
13,
90,
2807,
2,
272,
2512,
14,
815,
480,
321,
317,
6327,
645,
29549,
14,
5871,
14,
5624,
583,
23521,
2342,
63,
11418,
20383,
435,
32500,
11418,
435,
5426,
531,
339,
4450,
275,
295,
14,
2014,
8,
10853,
2641,
11418,
12,
295,
14,
16504,
680,
6452,
8,
576,
9,
339,
367,
1166,
315,
4450,
26,
267,
3367,
10963,
320,
275,
7369,
2201,
271,
583,
23521,
8480,
267,
1166,
275,
1166,
14,
1814,
2336,
3722,
3678,
1994,
6427,
6217,
267,
340,
1166,
440,
315,
655,
17926,
18339,
26,
288,
2512,
14,
815,
480,
221,
1166,
628,
435,
1166,
9,
288,
4866,
13086,
432,
14,
740,
779,
6403,
13957,
12,
1166,
12,
283,
5624,
583,
23521,
1105,
288,
655,
17926,
18339,
14,
525,
8,
633,
9,
267,
587,
26,
288,
2512,
14,
815,
480,
221,
1166,
366,
4230,
10641,
628,
435,
1166,
9,
339,
372,
4866,
13086,
432,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
evamwangi/bc-7-Todo_List
|
venv/Lib/encodings/ptcp154.py
|
647
|
8950
|
""" Python Character Mapping Codec generated from 'PTCP154.txt' with gencodec.py.
Written by Marc-Andre Lemburg (mal@lemburg.com).
(c) Copyright CNRI, All Rights Reserved. NO WARRANTY.
(c) Copyright 2000 Guido van Rossum.
"""#"
import codecs
### Codec APIs
class Codec(codecs.Codec):
def encode(self,input,errors='strict'):
return codecs.charmap_encode(input,errors,encoding_map)
def decode(self,input,errors='strict'):
return codecs.charmap_decode(input,errors,decoding_map)
class IncrementalEncoder(codecs.IncrementalEncoder):
def encode(self, input, final=False):
return codecs.charmap_encode(input,self.errors,encoding_map)[0]
class IncrementalDecoder(codecs.IncrementalDecoder):
def decode(self, input, final=False):
return codecs.charmap_decode(input,self.errors,decoding_map)[0]
class StreamWriter(Codec,codecs.StreamWriter):
pass
class StreamReader(Codec,codecs.StreamReader):
pass
### encodings module API
def getregentry():
return codecs.CodecInfo(
name='ptcp154',
encode=Codec().encode,
decode=Codec().decode,
incrementalencoder=IncrementalEncoder,
incrementaldecoder=IncrementalDecoder,
streamreader=StreamReader,
streamwriter=StreamWriter,
)
### Decoding Map
decoding_map = codecs.make_identity_dict(range(256))
decoding_map.update({
0x0080: 0x0496, # CYRILLIC CAPITAL LETTER ZHE WITH DESCENDER
0x0081: 0x0492, # CYRILLIC CAPITAL LETTER GHE WITH STROKE
0x0082: 0x04ee, # CYRILLIC CAPITAL LETTER U WITH MACRON
0x0083: 0x0493, # CYRILLIC SMALL LETTER GHE WITH STROKE
0x0084: 0x201e, # DOUBLE LOW-9 QUOTATION MARK
0x0085: 0x2026, # HORIZONTAL ELLIPSIS
0x0086: 0x04b6, # CYRILLIC CAPITAL LETTER CHE WITH DESCENDER
0x0087: 0x04ae, # CYRILLIC CAPITAL LETTER STRAIGHT U
0x0088: 0x04b2, # CYRILLIC CAPITAL LETTER HA WITH DESCENDER
0x0089: 0x04af, # CYRILLIC SMALL LETTER STRAIGHT U
0x008a: 0x04a0, # CYRILLIC CAPITAL LETTER BASHKIR KA
0x008b: 0x04e2, # CYRILLIC CAPITAL LETTER I WITH MACRON
0x008c: 0x04a2, # CYRILLIC CAPITAL LETTER EN WITH DESCENDER
0x008d: 0x049a, # CYRILLIC CAPITAL LETTER KA WITH DESCENDER
0x008e: 0x04ba, # CYRILLIC CAPITAL LETTER SHHA
0x008f: 0x04b8, # CYRILLIC CAPITAL LETTER CHE WITH VERTICAL STROKE
0x0090: 0x0497, # CYRILLIC SMALL LETTER ZHE WITH DESCENDER
0x0091: 0x2018, # LEFT SINGLE QUOTATION MARK
0x0092: 0x2019, # RIGHT SINGLE QUOTATION MARK
0x0093: 0x201c, # LEFT DOUBLE QUOTATION MARK
0x0094: 0x201d, # RIGHT DOUBLE QUOTATION MARK
0x0095: 0x2022, # BULLET
0x0096: 0x2013, # EN DASH
0x0097: 0x2014, # EM DASH
0x0098: 0x04b3, # CYRILLIC SMALL LETTER HA WITH DESCENDER
0x0099: 0x04b7, # CYRILLIC SMALL LETTER CHE WITH DESCENDER
0x009a: 0x04a1, # CYRILLIC SMALL LETTER BASHKIR KA
0x009b: 0x04e3, # CYRILLIC SMALL LETTER I WITH MACRON
0x009c: 0x04a3, # CYRILLIC SMALL LETTER EN WITH DESCENDER
0x009d: 0x049b, # CYRILLIC SMALL LETTER KA WITH DESCENDER
0x009e: 0x04bb, # CYRILLIC SMALL LETTER SHHA
0x009f: 0x04b9, # CYRILLIC SMALL LETTER CHE WITH VERTICAL STROKE
0x00a1: 0x040e, # CYRILLIC CAPITAL LETTER SHORT U (Byelorussian)
0x00a2: 0x045e, # CYRILLIC SMALL LETTER SHORT U (Byelorussian)
0x00a3: 0x0408, # CYRILLIC CAPITAL LETTER JE
0x00a4: 0x04e8, # CYRILLIC CAPITAL LETTER BARRED O
0x00a5: 0x0498, # CYRILLIC CAPITAL LETTER ZE WITH DESCENDER
0x00a6: 0x04b0, # CYRILLIC CAPITAL LETTER STRAIGHT U WITH STROKE
0x00a8: 0x0401, # CYRILLIC CAPITAL LETTER IO
0x00aa: 0x04d8, # CYRILLIC CAPITAL LETTER SCHWA
0x00ad: 0x04ef, # CYRILLIC SMALL LETTER U WITH MACRON
0x00af: 0x049c, # CYRILLIC CAPITAL LETTER KA WITH VERTICAL STROKE
0x00b1: 0x04b1, # CYRILLIC SMALL LETTER STRAIGHT U WITH STROKE
0x00b2: 0x0406, # CYRILLIC CAPITAL LETTER BYELORUSSIAN-UKRAINIAN I
0x00b3: 0x0456, # CYRILLIC SMALL LETTER BYELORUSSIAN-UKRAINIAN I
0x00b4: 0x0499, # CYRILLIC SMALL LETTER ZE WITH DESCENDER
0x00b5: 0x04e9, # CYRILLIC SMALL LETTER BARRED O
0x00b8: 0x0451, # CYRILLIC SMALL LETTER IO
0x00b9: 0x2116, # NUMERO SIGN
0x00ba: 0x04d9, # CYRILLIC SMALL LETTER SCHWA
0x00bc: 0x0458, # CYRILLIC SMALL LETTER JE
0x00bd: 0x04aa, # CYRILLIC CAPITAL LETTER ES WITH DESCENDER
0x00be: 0x04ab, # CYRILLIC SMALL LETTER ES WITH DESCENDER
0x00bf: 0x049d, # CYRILLIC SMALL LETTER KA WITH VERTICAL STROKE
0x00c0: 0x0410, # CYRILLIC CAPITAL LETTER A
0x00c1: 0x0411, # CYRILLIC CAPITAL LETTER BE
0x00c2: 0x0412, # CYRILLIC CAPITAL LETTER VE
0x00c3: 0x0413, # CYRILLIC CAPITAL LETTER GHE
0x00c4: 0x0414, # CYRILLIC CAPITAL LETTER DE
0x00c5: 0x0415, # CYRILLIC CAPITAL LETTER IE
0x00c6: 0x0416, # CYRILLIC CAPITAL LETTER ZHE
0x00c7: 0x0417, # CYRILLIC CAPITAL LETTER ZE
0x00c8: 0x0418, # CYRILLIC CAPITAL LETTER I
0x00c9: 0x0419, # CYRILLIC CAPITAL LETTER SHORT I
0x00ca: 0x041a, # CYRILLIC CAPITAL LETTER KA
0x00cb: 0x041b, # CYRILLIC CAPITAL LETTER EL
0x00cc: 0x041c, # CYRILLIC CAPITAL LETTER EM
0x00cd: 0x041d, # CYRILLIC CAPITAL LETTER EN
0x00ce: 0x041e, # CYRILLIC CAPITAL LETTER O
0x00cf: 0x041f, # CYRILLIC CAPITAL LETTER PE
0x00d0: 0x0420, # CYRILLIC CAPITAL LETTER ER
0x00d1: 0x0421, # CYRILLIC CAPITAL LETTER ES
0x00d2: 0x0422, # CYRILLIC CAPITAL LETTER TE
0x00d3: 0x0423, # CYRILLIC CAPITAL LETTER U
0x00d4: 0x0424, # CYRILLIC CAPITAL LETTER EF
0x00d5: 0x0425, # CYRILLIC CAPITAL LETTER HA
0x00d6: 0x0426, # CYRILLIC CAPITAL LETTER TSE
0x00d7: 0x0427, # CYRILLIC CAPITAL LETTER CHE
0x00d8: 0x0428, # CYRILLIC CAPITAL LETTER SHA
0x00d9: 0x0429, # CYRILLIC CAPITAL LETTER SHCHA
0x00da: 0x042a, # CYRILLIC CAPITAL LETTER HARD SIGN
0x00db: 0x042b, # CYRILLIC CAPITAL LETTER YERU
0x00dc: 0x042c, # CYRILLIC CAPITAL LETTER SOFT SIGN
0x00dd: 0x042d, # CYRILLIC CAPITAL LETTER E
0x00de: 0x042e, # CYRILLIC CAPITAL LETTER YU
0x00df: 0x042f, # CYRILLIC CAPITAL LETTER YA
0x00e0: 0x0430, # CYRILLIC SMALL LETTER A
0x00e1: 0x0431, # CYRILLIC SMALL LETTER BE
0x00e2: 0x0432, # CYRILLIC SMALL LETTER VE
0x00e3: 0x0433, # CYRILLIC SMALL LETTER GHE
0x00e4: 0x0434, # CYRILLIC SMALL LETTER DE
0x00e5: 0x0435, # CYRILLIC SMALL LETTER IE
0x00e6: 0x0436, # CYRILLIC SMALL LETTER ZHE
0x00e7: 0x0437, # CYRILLIC SMALL LETTER ZE
0x00e8: 0x0438, # CYRILLIC SMALL LETTER I
0x00e9: 0x0439, # CYRILLIC SMALL LETTER SHORT I
0x00ea: 0x043a, # CYRILLIC SMALL LETTER KA
0x00eb: 0x043b, # CYRILLIC SMALL LETTER EL
0x00ec: 0x043c, # CYRILLIC SMALL LETTER EM
0x00ed: 0x043d, # CYRILLIC SMALL LETTER EN
0x00ee: 0x043e, # CYRILLIC SMALL LETTER O
0x00ef: 0x043f, # CYRILLIC SMALL LETTER PE
0x00f0: 0x0440, # CYRILLIC SMALL LETTER ER
0x00f1: 0x0441, # CYRILLIC SMALL LETTER ES
0x00f2: 0x0442, # CYRILLIC SMALL LETTER TE
0x00f3: 0x0443, # CYRILLIC SMALL LETTER U
0x00f4: 0x0444, # CYRILLIC SMALL LETTER EF
0x00f5: 0x0445, # CYRILLIC SMALL LETTER HA
0x00f6: 0x0446, # CYRILLIC SMALL LETTER TSE
0x00f7: 0x0447, # CYRILLIC SMALL LETTER CHE
0x00f8: 0x0448, # CYRILLIC SMALL LETTER SHA
0x00f9: 0x0449, # CYRILLIC SMALL LETTER SHCHA
0x00fa: 0x044a, # CYRILLIC SMALL LETTER HARD SIGN
0x00fb: 0x044b, # CYRILLIC SMALL LETTER YERU
0x00fc: 0x044c, # CYRILLIC SMALL LETTER SOFT SIGN
0x00fd: 0x044d, # CYRILLIC SMALL LETTER E
0x00fe: 0x044e, # CYRILLIC SMALL LETTER YU
0x00ff: 0x044f, # CYRILLIC SMALL LETTER YA
})
### Encoding Map
encoding_map = codecs.make_encoding_map(decoding_map)
|
mit
|
[
624,
2018,
17660,
12340,
13732,
4046,
687,
283,
4189,
2890,
10478,
14,
2424,
7,
543,
486,
2143,
67,
14,
647,
14,
199,
199,
32329,
701,
603,
9912,
13,
3325,
264,
7005,
32649,
334,
2174,
32,
274,
32649,
14,
957,
680,
199,
199,
8,
67,
9,
1898,
445,
46,
6129,
12,
2900,
5924,
5702,
14,
4825,
3408,
14,
199,
8,
67,
9,
1898,
12293,
598,
1535,
79,
20744,
6848,
385,
453,
14,
199,
199,
624,
23662,
199,
199,
646,
6010,
199,
199,
5680,
13732,
15913,
199,
199,
533,
13732,
8,
8933,
14,
8818,
304,
339,
347,
3752,
8,
277,
12,
1210,
12,
2550,
534,
4768,
735,
267,
372,
6010,
14,
13391,
63,
2143,
8,
1210,
12,
2550,
12,
2991,
63,
1130,
9,
339,
347,
4849,
8,
277,
12,
1210,
12,
2550,
534,
4768,
735,
267,
372,
6010,
14,
13391,
63,
2708,
8,
1210,
12,
2550,
12,
12796,
63,
1130,
9,
199,
199,
533,
24350,
8,
8933,
14,
17016,
304,
272,
347,
3752,
8,
277,
12,
1324,
12,
4242,
29,
797,
304,
267,
372,
6010,
14,
13391,
63,
2143,
8,
1210,
12,
277,
14,
2550,
12,
2991,
63,
1130,
2788,
16,
61,
199,
199,
533,
24385,
8,
8933,
14,
16703,
304,
272,
347,
4849,
8,
277,
12,
1324,
12,
4242,
29,
797,
304,
267,
372,
6010,
14,
13391,
63,
2708,
8,
1210,
12,
277,
14,
2550,
12,
12796,
63,
1130,
2788,
16,
61,
199,
199,
533,
24163,
8,
8818,
12,
8933,
14,
16551,
304,
272,
986,
199,
199,
533,
22970,
8,
8818,
12,
8933,
14,
16132,
304,
272,
986,
199,
199,
5680,
14134,
859,
3261,
199,
199,
318,
26116,
837,
272,
372,
6010,
14,
26375,
8,
267,
536,
534,
541,
1850,
10478,
297,
267,
3752,
29,
8818,
1252,
2143,
12,
267,
4849,
29,
8818,
1252,
2708,
12,
267,
26329,
29,
17016,
12,
267,
26317,
29,
16703,
12,
267,
26101,
29,
16132,
12,
267,
26112,
29,
16551,
12,
272,
776,
199,
199,
5680,
27368,
9672,
199,
199,
12796,
63,
1130,
275,
6010,
14,
1875,
63,
5582,
63,
807,
8,
1842,
8,
3912,
430,
199,
12796,
63,
1130,
14,
873,
2561,
267,
378,
88,
23686,
26,
378,
88,
966,
2534,
12,
327,
263,
6239,
2678,
1578,
3107,
1645,
1663,
23915,
21951,
267,
378,
88,
383,
2835,
26,
378,
88,
966,
2942,
12,
327,
263,
6239,
2678,
1578,
598,
1645,
1663,
22755,
267,
378,
88,
383,
2564,
26,
378,
88,
966,
1024,
12,
327,
263,
6239,
2678,
1578,
738,
1663,
22847,
267,
378,
88,
383,
2658,
26,
378,
88,
966,
3129,
12,
327,
263,
6239,
2516,
1578,
598,
1645,
1663,
22755,
267,
378,
88,
30935,
26,
378,
88,
1797,
69,
12,
327,
263,
5681,
21359,
13,
25,
11830,
8132,
267,
378,
88,
383,
2426,
26,
378,
88,
31171,
12,
327,
263,
8724,
662,
4464,
17772,
267,
378,
88,
31743,
26,
378,
88,
966,
66,
22,
12,
327,
263,
6239,
2678,
1578,
16071,
1663,
23915,
21951,
267,
378,
88,
383,
1555,
26,
378,
88,
966,
3624,
12,
327,
263,
6239,
2678,
1578,
7553,
33,
2830,
738,
267,
378,
88,
31419,
26,
378,
88,
966,
66,
18,
12,
327,
263,
6239,
2678,
1578,
16100,
1663,
23915,
21951,
267,
378,
88,
383,
1407,
26,
378,
88,
966,
2756,
12,
327,
263,
6239,
2516,
1578,
7553,
33,
2830,
738,
267,
378,
88,
8662,
65,
26,
378,
88,
966,
65,
16,
12,
327,
263,
6239,
2678,
1578,
4147,
40,
43,
3927,
1804,
33,
267,
378,
88,
8662,
66,
26,
378,
88,
966,
69,
18,
12,
327,
263,
6239,
2678,
1578,
473,
1663,
22847,
267,
378,
88,
8662,
67,
26,
378,
88,
966,
65,
18,
12,
327,
263,
6239,
2678,
1578,
5070,
1663,
23915,
21951,
267,
378,
88,
8662,
68,
26,
378,
88,
12809,
65,
12,
327,
263,
6239,
2678,
1578,
1804,
33,
1663,
23915,
21951,
267,
378,
88,
8662,
69,
26,
378,
88,
966,
2470,
12,
327,
263,
6239,
2678,
1578,
4410,
6294,
267,
378,
88,
8662,
70,
26,
378,
88,
966,
66,
24,
12,
327,
263,
6239,
2678,
1578,
16071,
1663,
8267,
22755,
267,
378,
88,
28875,
26,
378,
88,
966,
2576,
12,
327,
263,
6239,
2516,
1578,
3107,
1645,
1663,
23915,
21951,
267,
378,
88,
383,
3328,
26,
378,
88,
12682,
12,
327,
263,
6578,
8655,
11830,
8132,
267,
378,
88,
383,
2942,
26,
378,
88,
14982,
12,
327,
263,
7052,
8655,
11830,
8132,
267,
378,
88,
383,
3129,
26,
378,
88,
1797,
67,
12,
327,
263,
6578,
5681,
11830,
8132,
267,
378,
88,
383,
2635,
26,
378,
88,
1797,
68,
12,
327,
263,
7052,
5681,
11830,
8132,
267,
378,
88,
383,
2720,
26,
378,
88,
13859,
12,
327,
263,
699,
32243,
267,
378,
88,
383,
2534,
26,
378,
88,
6965,
12,
327,
263,
5070,
577,
8100,
267,
378,
88,
383,
2576,
26,
378,
88,
7280,
12,
327,
263,
26512,
577,
8100,
267,
378,
88,
383,
2905,
26,
378,
88,
966,
66,
19,
12,
327,
263,
6239,
2516,
1578,
16100,
1663,
23915,
21951,
267,
378,
88,
29660,
26,
378,
88,
966,
66,
23,
12,
327,
263,
6239,
2516,
1578,
16071,
1663,
23915,
21951,
267,
378,
88,
8581,
65,
26,
378,
88,
966,
65,
17,
12,
327,
263,
6239,
2516,
1578,
4147,
40,
43,
3927,
1804,
33,
267,
378,
88,
8581,
66,
26,
378,
88,
966,
69,
19,
12,
327,
263,
6239,
2516,
1578,
473,
1663,
22847,
267,
378,
88,
8581,
67,
26,
378,
88,
966,
65,
19,
12,
327,
263,
6239,
2516,
1578,
5070,
1663,
23915,
21951,
267,
378,
88,
8581,
68,
26,
378,
88,
12809,
66,
12,
327,
263,
6239,
2516,
1578,
1804,
33,
1663,
23915,
21951,
267,
378,
88,
8581,
69,
26,
378,
88,
966,
2501,
12,
327,
263,
6239,
2516,
1578,
4410,
6294,
267,
378,
88,
8581,
70,
26,
378,
88,
966,
66,
25,
12,
327,
263,
6239,
2516,
1578,
16071,
1663,
8267,
22755,
267,
378,
88,
383,
65,
17,
26,
378,
88,
11189,
69,
12,
327,
263,
6239,
2678,
1578,
26389,
738,
334,
2175,
352,
269,
8630,
9,
267,
378,
88,
383,
65,
18,
26,
378,
88,
12618,
69,
12,
327,
263,
6239,
2516,
1578,
26389,
738,
334,
2175,
352,
269,
8630,
9,
267,
378,
88,
383,
65,
19,
26,
378,
88,
966,
2036,
12,
327,
263,
6239
] |
[
2018,
17660,
12340,
13732,
4046,
687,
283,
4189,
2890,
10478,
14,
2424,
7,
543,
486,
2143,
67,
14,
647,
14,
199,
199,
32329,
701,
603,
9912,
13,
3325,
264,
7005,
32649,
334,
2174,
32,
274,
32649,
14,
957,
680,
199,
199,
8,
67,
9,
1898,
445,
46,
6129,
12,
2900,
5924,
5702,
14,
4825,
3408,
14,
199,
8,
67,
9,
1898,
12293,
598,
1535,
79,
20744,
6848,
385,
453,
14,
199,
199,
624,
23662,
199,
199,
646,
6010,
199,
199,
5680,
13732,
15913,
199,
199,
533,
13732,
8,
8933,
14,
8818,
304,
339,
347,
3752,
8,
277,
12,
1210,
12,
2550,
534,
4768,
735,
267,
372,
6010,
14,
13391,
63,
2143,
8,
1210,
12,
2550,
12,
2991,
63,
1130,
9,
339,
347,
4849,
8,
277,
12,
1210,
12,
2550,
534,
4768,
735,
267,
372,
6010,
14,
13391,
63,
2708,
8,
1210,
12,
2550,
12,
12796,
63,
1130,
9,
199,
199,
533,
24350,
8,
8933,
14,
17016,
304,
272,
347,
3752,
8,
277,
12,
1324,
12,
4242,
29,
797,
304,
267,
372,
6010,
14,
13391,
63,
2143,
8,
1210,
12,
277,
14,
2550,
12,
2991,
63,
1130,
2788,
16,
61,
199,
199,
533,
24385,
8,
8933,
14,
16703,
304,
272,
347,
4849,
8,
277,
12,
1324,
12,
4242,
29,
797,
304,
267,
372,
6010,
14,
13391,
63,
2708,
8,
1210,
12,
277,
14,
2550,
12,
12796,
63,
1130,
2788,
16,
61,
199,
199,
533,
24163,
8,
8818,
12,
8933,
14,
16551,
304,
272,
986,
199,
199,
533,
22970,
8,
8818,
12,
8933,
14,
16132,
304,
272,
986,
199,
199,
5680,
14134,
859,
3261,
199,
199,
318,
26116,
837,
272,
372,
6010,
14,
26375,
8,
267,
536,
534,
541,
1850,
10478,
297,
267,
3752,
29,
8818,
1252,
2143,
12,
267,
4849,
29,
8818,
1252,
2708,
12,
267,
26329,
29,
17016,
12,
267,
26317,
29,
16703,
12,
267,
26101,
29,
16132,
12,
267,
26112,
29,
16551,
12,
272,
776,
199,
199,
5680,
27368,
9672,
199,
199,
12796,
63,
1130,
275,
6010,
14,
1875,
63,
5582,
63,
807,
8,
1842,
8,
3912,
430,
199,
12796,
63,
1130,
14,
873,
2561,
267,
378,
88,
23686,
26,
378,
88,
966,
2534,
12,
327,
263,
6239,
2678,
1578,
3107,
1645,
1663,
23915,
21951,
267,
378,
88,
383,
2835,
26,
378,
88,
966,
2942,
12,
327,
263,
6239,
2678,
1578,
598,
1645,
1663,
22755,
267,
378,
88,
383,
2564,
26,
378,
88,
966,
1024,
12,
327,
263,
6239,
2678,
1578,
738,
1663,
22847,
267,
378,
88,
383,
2658,
26,
378,
88,
966,
3129,
12,
327,
263,
6239,
2516,
1578,
598,
1645,
1663,
22755,
267,
378,
88,
30935,
26,
378,
88,
1797,
69,
12,
327,
263,
5681,
21359,
13,
25,
11830,
8132,
267,
378,
88,
383,
2426,
26,
378,
88,
31171,
12,
327,
263,
8724,
662,
4464,
17772,
267,
378,
88,
31743,
26,
378,
88,
966,
66,
22,
12,
327,
263,
6239,
2678,
1578,
16071,
1663,
23915,
21951,
267,
378,
88,
383,
1555,
26,
378,
88,
966,
3624,
12,
327,
263,
6239,
2678,
1578,
7553,
33,
2830,
738,
267,
378,
88,
31419,
26,
378,
88,
966,
66,
18,
12,
327,
263,
6239,
2678,
1578,
16100,
1663,
23915,
21951,
267,
378,
88,
383,
1407,
26,
378,
88,
966,
2756,
12,
327,
263,
6239,
2516,
1578,
7553,
33,
2830,
738,
267,
378,
88,
8662,
65,
26,
378,
88,
966,
65,
16,
12,
327,
263,
6239,
2678,
1578,
4147,
40,
43,
3927,
1804,
33,
267,
378,
88,
8662,
66,
26,
378,
88,
966,
69,
18,
12,
327,
263,
6239,
2678,
1578,
473,
1663,
22847,
267,
378,
88,
8662,
67,
26,
378,
88,
966,
65,
18,
12,
327,
263,
6239,
2678,
1578,
5070,
1663,
23915,
21951,
267,
378,
88,
8662,
68,
26,
378,
88,
12809,
65,
12,
327,
263,
6239,
2678,
1578,
1804,
33,
1663,
23915,
21951,
267,
378,
88,
8662,
69,
26,
378,
88,
966,
2470,
12,
327,
263,
6239,
2678,
1578,
4410,
6294,
267,
378,
88,
8662,
70,
26,
378,
88,
966,
66,
24,
12,
327,
263,
6239,
2678,
1578,
16071,
1663,
8267,
22755,
267,
378,
88,
28875,
26,
378,
88,
966,
2576,
12,
327,
263,
6239,
2516,
1578,
3107,
1645,
1663,
23915,
21951,
267,
378,
88,
383,
3328,
26,
378,
88,
12682,
12,
327,
263,
6578,
8655,
11830,
8132,
267,
378,
88,
383,
2942,
26,
378,
88,
14982,
12,
327,
263,
7052,
8655,
11830,
8132,
267,
378,
88,
383,
3129,
26,
378,
88,
1797,
67,
12,
327,
263,
6578,
5681,
11830,
8132,
267,
378,
88,
383,
2635,
26,
378,
88,
1797,
68,
12,
327,
263,
7052,
5681,
11830,
8132,
267,
378,
88,
383,
2720,
26,
378,
88,
13859,
12,
327,
263,
699,
32243,
267,
378,
88,
383,
2534,
26,
378,
88,
6965,
12,
327,
263,
5070,
577,
8100,
267,
378,
88,
383,
2576,
26,
378,
88,
7280,
12,
327,
263,
26512,
577,
8100,
267,
378,
88,
383,
2905,
26,
378,
88,
966,
66,
19,
12,
327,
263,
6239,
2516,
1578,
16100,
1663,
23915,
21951,
267,
378,
88,
29660,
26,
378,
88,
966,
66,
23,
12,
327,
263,
6239,
2516,
1578,
16071,
1663,
23915,
21951,
267,
378,
88,
8581,
65,
26,
378,
88,
966,
65,
17,
12,
327,
263,
6239,
2516,
1578,
4147,
40,
43,
3927,
1804,
33,
267,
378,
88,
8581,
66,
26,
378,
88,
966,
69,
19,
12,
327,
263,
6239,
2516,
1578,
473,
1663,
22847,
267,
378,
88,
8581,
67,
26,
378,
88,
966,
65,
19,
12,
327,
263,
6239,
2516,
1578,
5070,
1663,
23915,
21951,
267,
378,
88,
8581,
68,
26,
378,
88,
12809,
66,
12,
327,
263,
6239,
2516,
1578,
1804,
33,
1663,
23915,
21951,
267,
378,
88,
8581,
69,
26,
378,
88,
966,
2501,
12,
327,
263,
6239,
2516,
1578,
4410,
6294,
267,
378,
88,
8581,
70,
26,
378,
88,
966,
66,
25,
12,
327,
263,
6239,
2516,
1578,
16071,
1663,
8267,
22755,
267,
378,
88,
383,
65,
17,
26,
378,
88,
11189,
69,
12,
327,
263,
6239,
2678,
1578,
26389,
738,
334,
2175,
352,
269,
8630,
9,
267,
378,
88,
383,
65,
18,
26,
378,
88,
12618,
69,
12,
327,
263,
6239,
2516,
1578,
26389,
738,
334,
2175,
352,
269,
8630,
9,
267,
378,
88,
383,
65,
19,
26,
378,
88,
966,
2036,
12,
327,
263,
6239,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
moisedo/azure-quickstart-templates
|
splunk-on-ubuntu/scripts/config.py
|
119
|
1408
|
# The MIT License (MIT)
#
# Copyright (c) 2016 Microsoft. 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, 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.
STORAGE_ACCOUNT_NAME = 'YOUR_STORAGE_ACCOUNT_NAME'
STORAGE_ACCOUNT_KEY = 'YOUR_STORAGE_ACCOUNT_KEY'
|
mit
|
[
3,
10619,
10619,
10619,
10619,
10619,
710,
10697,
844,
334,
13965,
9,
199,
3,
199,
3,
10619,
10619,
10619,
10619,
10619,
1898,
334,
67,
9,
7800,
15332,
14,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10619,
10619,
10619,
10619,
10619,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
1331,
199,
3,
10619,
10619,
10619,
10619,
10619,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
298,
10337,
1288,
370,
7962,
199,
3,
10619,
10619,
10619,
10619,
10619,
315,
314,
2290,
1928,
10588,
12,
5893,
1928,
12305,
314,
4481,
199,
3,
10619,
10619,
10619,
10619,
10619,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
11207,
12,
13473,
12,
436,
15,
269,
12743,
199,
3,
10619,
10619,
10619,
10619,
10619,
6866,
402,
314,
2290,
12,
436,
370,
11291,
12103,
370,
12676,
314,
2290,
365,
199,
3,
10619,
10619,
10619,
10619,
10619,
13985,
370,
886,
880,
12,
5420,
370,
314,
2569,
3704,
26,
199,
3,
199,
3,
10619,
10619,
10619,
10619,
10619,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
315,
199,
3,
10619,
10619,
10619,
10619,
10619,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
10619,
10619,
10619,
10619,
10619,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
1549,
199,
3,
10619,
10619,
10619,
10619,
10619,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
3169,
12,
199,
3,
10619,
10619,
10619,
10619,
10619,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
7000,
2334,
199,
3,
10619,
10619,
10619,
10619,
10619,
10610,
1549,
5877,
8164,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
199,
3,
10619,
10619,
10619,
10619,
10619,
5603,
12,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
199,
3,
10619,
10619,
10619,
10619,
10619,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
199,
3,
10619,
10619,
10619,
10619,
10619,
2334,
4141,
14,
199,
199,
17467,
63,
18928,
63,
2339,
275,
283,
57,
11237,
63,
17467,
63,
18928,
63,
2339,
7,
199,
17467,
63,
18928,
63,
3078,
221,
275,
283,
57,
11237,
63,
17467,
63,
18928,
63,
3078,
7,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
10619,
10619,
10619,
10619,
10619,
710,
10697,
844,
334,
13965,
9,
199,
3,
199,
3,
10619,
10619,
10619,
10619,
10619,
1898,
334,
67,
9,
7800,
15332,
14,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10619,
10619,
10619,
10619,
10619,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
1331,
199,
3,
10619,
10619,
10619,
10619,
10619,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
298,
10337,
1288,
370,
7962,
199,
3,
10619,
10619,
10619,
10619,
10619,
315,
314,
2290,
1928,
10588,
12,
5893,
1928,
12305,
314,
4481,
199,
3,
10619,
10619,
10619,
10619,
10619,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
11207,
12,
13473,
12,
436,
15,
269,
12743,
199,
3,
10619,
10619,
10619,
10619,
10619,
6866,
402,
314,
2290,
12,
436,
370,
11291,
12103,
370,
12676,
314,
2290,
365,
199,
3,
10619,
10619,
10619,
10619,
10619,
13985,
370,
886,
880,
12,
5420,
370,
314,
2569,
3704,
26,
199,
3,
199,
3,
10619,
10619,
10619,
10619,
10619,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
315,
199,
3,
10619,
10619,
10619,
10619,
10619,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
10619,
10619,
10619,
10619,
10619,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
1549,
199,
3,
10619,
10619,
10619,
10619,
10619,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
3169,
12,
199,
3,
10619,
10619,
10619,
10619,
10619,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
7000,
2334,
199,
3,
10619,
10619,
10619,
10619,
10619,
10610,
1549,
5877,
8164,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
199,
3,
10619,
10619,
10619,
10619,
10619,
5603,
12,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
199,
3,
10619,
10619,
10619,
10619,
10619,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
199,
3,
10619,
10619,
10619,
10619,
10619,
2334,
4141,
14,
199,
199,
17467,
63,
18928,
63,
2339,
275,
283,
57,
11237,
63,
17467,
63,
18928,
63,
2339,
7,
199,
17467,
63,
18928,
63,
3078,
221,
275,
283,
57,
11237,
63,
17467,
63,
18928,
63,
3078,
7,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32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0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
tailorian/Sick-Beard
|
lib/unidecode/x05a.py
|
252
|
4636
|
data = (
'Song ', # 0x00
'Wei ', # 0x01
'Hong ', # 0x02
'Wa ', # 0x03
'Lou ', # 0x04
'Ya ', # 0x05
'Rao ', # 0x06
'Jiao ', # 0x07
'Luan ', # 0x08
'Ping ', # 0x09
'Xian ', # 0x0a
'Shao ', # 0x0b
'Li ', # 0x0c
'Cheng ', # 0x0d
'Xiao ', # 0x0e
'Mang ', # 0x0f
'Fu ', # 0x10
'Suo ', # 0x11
'Wu ', # 0x12
'Wei ', # 0x13
'Ke ', # 0x14
'Lai ', # 0x15
'Chuo ', # 0x16
'Ding ', # 0x17
'Niang ', # 0x18
'Xing ', # 0x19
'Nan ', # 0x1a
'Yu ', # 0x1b
'Nuo ', # 0x1c
'Pei ', # 0x1d
'Nei ', # 0x1e
'Juan ', # 0x1f
'Shen ', # 0x20
'Zhi ', # 0x21
'Han ', # 0x22
'Di ', # 0x23
'Zhuang ', # 0x24
'E ', # 0x25
'Pin ', # 0x26
'Tui ', # 0x27
'Han ', # 0x28
'Mian ', # 0x29
'Wu ', # 0x2a
'Yan ', # 0x2b
'Wu ', # 0x2c
'Xi ', # 0x2d
'Yan ', # 0x2e
'Yu ', # 0x2f
'Si ', # 0x30
'Yu ', # 0x31
'Wa ', # 0x32
'[?] ', # 0x33
'Xian ', # 0x34
'Ju ', # 0x35
'Qu ', # 0x36
'Shui ', # 0x37
'Qi ', # 0x38
'Xian ', # 0x39
'Zhui ', # 0x3a
'Dong ', # 0x3b
'Chang ', # 0x3c
'Lu ', # 0x3d
'Ai ', # 0x3e
'E ', # 0x3f
'E ', # 0x40
'Lou ', # 0x41
'Mian ', # 0x42
'Cong ', # 0x43
'Pou ', # 0x44
'Ju ', # 0x45
'Po ', # 0x46
'Cai ', # 0x47
'Ding ', # 0x48
'Wan ', # 0x49
'Biao ', # 0x4a
'Xiao ', # 0x4b
'Shu ', # 0x4c
'Qi ', # 0x4d
'Hui ', # 0x4e
'Fu ', # 0x4f
'E ', # 0x50
'Wo ', # 0x51
'Tan ', # 0x52
'Fei ', # 0x53
'Wei ', # 0x54
'Jie ', # 0x55
'Tian ', # 0x56
'Ni ', # 0x57
'Quan ', # 0x58
'Jing ', # 0x59
'Hun ', # 0x5a
'Jing ', # 0x5b
'Qian ', # 0x5c
'Dian ', # 0x5d
'Xing ', # 0x5e
'Hu ', # 0x5f
'Wa ', # 0x60
'Lai ', # 0x61
'Bi ', # 0x62
'Yin ', # 0x63
'Chou ', # 0x64
'Chuo ', # 0x65
'Fu ', # 0x66
'Jing ', # 0x67
'Lun ', # 0x68
'Yan ', # 0x69
'Lan ', # 0x6a
'Kun ', # 0x6b
'Yin ', # 0x6c
'Ya ', # 0x6d
'Ju ', # 0x6e
'Li ', # 0x6f
'Dian ', # 0x70
'Xian ', # 0x71
'Hwa ', # 0x72
'Hua ', # 0x73
'Ying ', # 0x74
'Chan ', # 0x75
'Shen ', # 0x76
'Ting ', # 0x77
'Dang ', # 0x78
'Yao ', # 0x79
'Wu ', # 0x7a
'Nan ', # 0x7b
'Ruo ', # 0x7c
'Jia ', # 0x7d
'Tou ', # 0x7e
'Xu ', # 0x7f
'Yu ', # 0x80
'Wei ', # 0x81
'Ti ', # 0x82
'Rou ', # 0x83
'Mei ', # 0x84
'Dan ', # 0x85
'Ruan ', # 0x86
'Qin ', # 0x87
'Hui ', # 0x88
'Wu ', # 0x89
'Qian ', # 0x8a
'Chun ', # 0x8b
'Mao ', # 0x8c
'Fu ', # 0x8d
'Jie ', # 0x8e
'Duan ', # 0x8f
'Xi ', # 0x90
'Zhong ', # 0x91
'Mei ', # 0x92
'Huang ', # 0x93
'Mian ', # 0x94
'An ', # 0x95
'Ying ', # 0x96
'Xuan ', # 0x97
'Jie ', # 0x98
'Wei ', # 0x99
'Mei ', # 0x9a
'Yuan ', # 0x9b
'Zhen ', # 0x9c
'Qiu ', # 0x9d
'Ti ', # 0x9e
'Xie ', # 0x9f
'Tuo ', # 0xa0
'Lian ', # 0xa1
'Mao ', # 0xa2
'Ran ', # 0xa3
'Si ', # 0xa4
'Pian ', # 0xa5
'Wei ', # 0xa6
'Wa ', # 0xa7
'Jiu ', # 0xa8
'Hu ', # 0xa9
'Ao ', # 0xaa
'[?] ', # 0xab
'Bou ', # 0xac
'Xu ', # 0xad
'Tou ', # 0xae
'Gui ', # 0xaf
'Zou ', # 0xb0
'Yao ', # 0xb1
'Pi ', # 0xb2
'Xi ', # 0xb3
'Yuan ', # 0xb4
'Ying ', # 0xb5
'Rong ', # 0xb6
'Ru ', # 0xb7
'Chi ', # 0xb8
'Liu ', # 0xb9
'Mei ', # 0xba
'Pan ', # 0xbb
'Ao ', # 0xbc
'Ma ', # 0xbd
'Gou ', # 0xbe
'Kui ', # 0xbf
'Qin ', # 0xc0
'Jia ', # 0xc1
'Sao ', # 0xc2
'Zhen ', # 0xc3
'Yuan ', # 0xc4
'Cha ', # 0xc5
'Yong ', # 0xc6
'Ming ', # 0xc7
'Ying ', # 0xc8
'Ji ', # 0xc9
'Su ', # 0xca
'Niao ', # 0xcb
'Xian ', # 0xcc
'Tao ', # 0xcd
'Pang ', # 0xce
'Lang ', # 0xcf
'Nao ', # 0xd0
'Bao ', # 0xd1
'Ai ', # 0xd2
'Pi ', # 0xd3
'Pin ', # 0xd4
'Yi ', # 0xd5
'Piao ', # 0xd6
'Yu ', # 0xd7
'Lei ', # 0xd8
'Xuan ', # 0xd9
'Man ', # 0xda
'Yi ', # 0xdb
'Zhang ', # 0xdc
'Kang ', # 0xdd
'Yong ', # 0xde
'Ni ', # 0xdf
'Li ', # 0xe0
'Di ', # 0xe1
'Gui ', # 0xe2
'Yan ', # 0xe3
'Jin ', # 0xe4
'Zhuan ', # 0xe5
'Chang ', # 0xe6
'Ce ', # 0xe7
'Han ', # 0xe8
'Nen ', # 0xe9
'Lao ', # 0xea
'Mo ', # 0xeb
'Zhe ', # 0xec
'Hu ', # 0xed
'Hu ', # 0xee
'Ao ', # 0xef
'Nen ', # 0xf0
'Qiang ', # 0xf1
'Ma ', # 0xf2
'Pie ', # 0xf3
'Gu ', # 0xf4
'Wu ', # 0xf5
'Jiao ', # 0xf6
'Tuo ', # 0xf7
'Zhan ', # 0xf8
'Mao ', # 0xf9
'Xian ', # 0xfa
'Xian ', # 0xfb
'Mo ', # 0xfc
'Liao ', # 0xfd
'Lian ', # 0xfe
'Hua ', # 0xff
)
|
gpl-3.0
|
[
576,
275,
334,
199,
7,
51,
951,
1656,
259,
327,
378,
88,
383,
199,
7,
6004,
73,
1656,
259,
327,
378,
88,
614,
199,
7,
40,
951,
1656,
259,
327,
378,
88,
996,
199,
7,
24804,
1656,
259,
327,
378,
88,
1644,
199,
7,
44,
810,
1656,
259,
327,
378,
88,
966,
199,
7,
28786,
1656,
259,
327,
378,
88,
1717,
199,
7,
1537,
79,
1656,
259,
327,
378,
88,
1690,
199,
7,
42,
18939,
1656,
259,
327,
378,
88,
1780,
199,
7,
44,
7856,
1656,
259,
327,
378,
88,
2036,
199,
7,
22638,
1656,
259,
327,
378,
88,
1643,
199,
7,
56,
5653,
1656,
259,
327,
378,
88,
16,
65,
199,
7,
23527,
79,
1656,
259,
327,
378,
88,
16,
66,
199,
7,
13009,
1656,
259,
327,
378,
88,
16,
67,
199,
7,
1049,
7420,
1656,
259,
327,
378,
88,
16,
68,
199,
7,
56,
18939,
1656,
259,
327,
378,
88,
16,
69,
199,
7,
45,
621,
1656,
259,
327,
378,
88,
16,
70,
199,
7,
19590,
1656,
259,
327,
378,
88,
709,
199,
7,
51,
13780,
1656,
259,
327,
378,
88,
845,
199,
7,
25728,
1656,
259,
327,
378,
88,
713,
199,
7,
6004,
73,
1656,
259,
327,
378,
88,
969,
199,
7,
1136,
1656,
259,
327,
378,
88,
1079,
199,
7,
44,
5789,
1656,
259,
327,
378,
88,
1046,
199,
7,
1049,
13780,
1656,
259,
327,
378,
88,
975,
199,
7,
36,
316,
1656,
259,
327,
378,
88,
1196,
199,
7,
20959,
621,
1656,
259,
327,
378,
88,
1085,
199,
7,
56,
316,
1656,
259,
327,
378,
88,
1167,
199,
7,
27531,
1656,
259,
327,
378,
88,
17,
65,
199,
7,
24388,
1656,
259,
327,
378,
88,
17,
66,
199,
7,
46,
13780,
1656,
259,
327,
378,
88,
17,
67,
199,
7,
8070,
73,
1656,
259,
327,
378,
88,
17,
68,
199,
7,
4698,
73,
1656,
259,
327,
378,
88,
17,
69,
199,
7,
42,
7856,
1656,
259,
327,
378,
88,
17,
70,
199,
7,
2662,
287,
1656,
259,
327,
378,
88,
1165,
199,
7,
58,
5812,
1656,
259,
327,
378,
88,
2025,
199,
7,
40,
290,
1656,
259,
327,
378,
88,
1081,
199,
7,
1341,
1656,
259,
327,
378,
88,
1789,
199,
7,
31183,
621,
1656,
259,
327,
378,
88,
1194,
199,
7,
37,
1656,
259,
327,
378,
88,
821,
199,
7,
19909,
1656,
259,
327,
378,
88,
1479,
199,
7,
52,
1907,
1656,
259,
327,
378,
88,
1465,
199,
7,
40,
290,
1656,
259,
327,
378,
88,
1651,
199,
7,
45,
5653,
1656,
259,
327,
378,
88,
1398,
199,
7,
25728,
1656,
259,
327,
378,
88,
18,
65,
199,
7,
26797,
1656,
259,
327,
378,
88,
18,
66,
199,
7,
25728,
1656,
259,
327,
378,
88,
18,
67,
199,
7,
14828,
1656,
259,
327,
378,
88,
18,
68,
199,
7,
26797,
1656,
259,
327,
378,
88,
18,
69,
199,
7,
24388,
1656,
259,
327,
378,
88,
18,
70,
199,
7,
18934,
1656,
259,
327,
378,
88,
1216,
199,
7,
24388,
1656,
259,
327,
378,
88,
2192,
199,
7,
24804,
1656,
259,
327,
378,
88,
708,
199,
17892,
1656,
259,
327,
378,
88,
1153,
199,
7,
56,
5653,
1656,
259,
327,
378,
88,
1082,
199,
7,
24783,
1656,
259,
327,
378,
88,
1276,
199,
7,
2371,
1656,
259,
327,
378,
88,
1344,
199,
7,
2662,
1907,
1656,
259,
327,
378,
88,
1401,
199,
7,
19910,
1656,
259,
327,
378,
88,
1703,
199,
7,
56,
5653,
1656,
259,
327,
378,
88,
1355,
199,
7,
12674,
1907,
1656,
259,
327,
378,
88,
19,
65,
199,
7,
36,
951,
1656,
259,
327,
378,
88,
19,
66,
199,
7,
1049,
621,
1656,
259,
327,
378,
88,
19,
67,
199,
7,
18176,
1656,
259,
327,
378,
88,
19,
68,
199,
7,
28960,
1656,
259,
327,
378,
88,
19,
69,
199,
7,
37,
1656,
259,
327,
378,
88,
19,
70,
199,
7,
37,
1656,
259,
327,
378,
88,
2167,
199,
7,
44,
810,
1656,
259,
327,
378,
88,
2953,
199,
7,
45,
5653,
1656,
259,
327,
378,
88,
2260,
199,
7,
714,
71,
1656,
259,
327,
378,
88,
2824,
199,
7,
48,
810,
1656,
259,
327,
378,
88,
1602,
199,
7,
24783,
1656,
259,
327,
378,
88,
2322,
199,
7,
1575,
1656,
259,
327,
378,
88,
2466,
199,
7,
3630,
73,
1656,
259,
327,
378,
88,
2417,
199,
7,
36,
316,
1656,
259,
327,
378,
88,
2006,
199,
7,
55,
290,
1656,
259,
327,
378,
88,
1887,
199,
7,
34,
18939,
1656,
259,
327,
378,
88,
20,
65,
199,
7,
56,
18939,
1656,
259,
327,
378,
88,
20,
66,
199,
7,
2662,
85,
1656,
259,
327,
378,
88,
20,
67,
199,
7,
19910,
1656,
259,
327,
378,
88,
20,
68,
199,
7,
40,
1907,
1656,
259,
327,
378,
88,
20,
69,
199,
7,
19590,
1656,
259,
327,
378,
88,
20,
70,
199,
7,
37,
1656,
259,
327,
378,
88,
1400,
199,
7,
26724,
1656,
259,
327,
378,
88,
2869,
199,
7,
52,
290,
1656,
259,
327,
378,
88,
2528,
199,
7,
3456,
73,
1656,
259,
327,
378,
88,
2481,
199,
7,
6004,
73,
1656,
259,
327,
378,
88,
1477,
199,
7,
42,
1873,
1656,
259,
327,
378,
88,
1229,
199,
7,
52,
5653,
1656,
259,
327,
378,
88,
1367,
199,
7,
20959,
1656,
259,
327,
378,
88,
1641,
199,
7,
2371,
290,
1656,
259,
327,
378,
88,
2010,
199,
7,
42,
316,
1656,
259,
327,
378,
88,
1427,
199,
7,
40,
324,
1656,
259,
327,
378,
88,
21,
65,
199,
7,
42,
316,
1656,
259,
327,
378,
88,
21,
66,
199,
7,
49,
5653,
1656,
259,
327,
378,
88,
21,
67,
199,
7,
1341,
290,
1656,
259,
327,
378,
88,
21,
68,
199,
7,
56,
316,
1656,
259,
327,
378,
88,
21,
69,
199,
7,
25542,
1656,
259,
327,
378,
88,
21,
70,
199,
7,
24804,
1656,
259,
327,
378,
88,
2259,
199,
7,
44,
5789,
1656,
259,
327,
378,
88,
2976,
199,
7,
17975,
1656,
259,
327,
378,
88,
2789,
199,
7,
57,
262,
1656,
259,
327,
378,
88,
2766,
199,
7,
6209,
85,
1656,
259,
327,
378,
88,
772,
199,
7,
1049,
13780,
1656,
259,
327,
378,
88,
2182,
199,
7,
19590,
1656,
259
] |
[
275,
334,
199,
7,
51,
951,
1656,
259,
327,
378,
88,
383,
199,
7,
6004,
73,
1656,
259,
327,
378,
88,
614,
199,
7,
40,
951,
1656,
259,
327,
378,
88,
996,
199,
7,
24804,
1656,
259,
327,
378,
88,
1644,
199,
7,
44,
810,
1656,
259,
327,
378,
88,
966,
199,
7,
28786,
1656,
259,
327,
378,
88,
1717,
199,
7,
1537,
79,
1656,
259,
327,
378,
88,
1690,
199,
7,
42,
18939,
1656,
259,
327,
378,
88,
1780,
199,
7,
44,
7856,
1656,
259,
327,
378,
88,
2036,
199,
7,
22638,
1656,
259,
327,
378,
88,
1643,
199,
7,
56,
5653,
1656,
259,
327,
378,
88,
16,
65,
199,
7,
23527,
79,
1656,
259,
327,
378,
88,
16,
66,
199,
7,
13009,
1656,
259,
327,
378,
88,
16,
67,
199,
7,
1049,
7420,
1656,
259,
327,
378,
88,
16,
68,
199,
7,
56,
18939,
1656,
259,
327,
378,
88,
16,
69,
199,
7,
45,
621,
1656,
259,
327,
378,
88,
16,
70,
199,
7,
19590,
1656,
259,
327,
378,
88,
709,
199,
7,
51,
13780,
1656,
259,
327,
378,
88,
845,
199,
7,
25728,
1656,
259,
327,
378,
88,
713,
199,
7,
6004,
73,
1656,
259,
327,
378,
88,
969,
199,
7,
1136,
1656,
259,
327,
378,
88,
1079,
199,
7,
44,
5789,
1656,
259,
327,
378,
88,
1046,
199,
7,
1049,
13780,
1656,
259,
327,
378,
88,
975,
199,
7,
36,
316,
1656,
259,
327,
378,
88,
1196,
199,
7,
20959,
621,
1656,
259,
327,
378,
88,
1085,
199,
7,
56,
316,
1656,
259,
327,
378,
88,
1167,
199,
7,
27531,
1656,
259,
327,
378,
88,
17,
65,
199,
7,
24388,
1656,
259,
327,
378,
88,
17,
66,
199,
7,
46,
13780,
1656,
259,
327,
378,
88,
17,
67,
199,
7,
8070,
73,
1656,
259,
327,
378,
88,
17,
68,
199,
7,
4698,
73,
1656,
259,
327,
378,
88,
17,
69,
199,
7,
42,
7856,
1656,
259,
327,
378,
88,
17,
70,
199,
7,
2662,
287,
1656,
259,
327,
378,
88,
1165,
199,
7,
58,
5812,
1656,
259,
327,
378,
88,
2025,
199,
7,
40,
290,
1656,
259,
327,
378,
88,
1081,
199,
7,
1341,
1656,
259,
327,
378,
88,
1789,
199,
7,
31183,
621,
1656,
259,
327,
378,
88,
1194,
199,
7,
37,
1656,
259,
327,
378,
88,
821,
199,
7,
19909,
1656,
259,
327,
378,
88,
1479,
199,
7,
52,
1907,
1656,
259,
327,
378,
88,
1465,
199,
7,
40,
290,
1656,
259,
327,
378,
88,
1651,
199,
7,
45,
5653,
1656,
259,
327,
378,
88,
1398,
199,
7,
25728,
1656,
259,
327,
378,
88,
18,
65,
199,
7,
26797,
1656,
259,
327,
378,
88,
18,
66,
199,
7,
25728,
1656,
259,
327,
378,
88,
18,
67,
199,
7,
14828,
1656,
259,
327,
378,
88,
18,
68,
199,
7,
26797,
1656,
259,
327,
378,
88,
18,
69,
199,
7,
24388,
1656,
259,
327,
378,
88,
18,
70,
199,
7,
18934,
1656,
259,
327,
378,
88,
1216,
199,
7,
24388,
1656,
259,
327,
378,
88,
2192,
199,
7,
24804,
1656,
259,
327,
378,
88,
708,
199,
17892,
1656,
259,
327,
378,
88,
1153,
199,
7,
56,
5653,
1656,
259,
327,
378,
88,
1082,
199,
7,
24783,
1656,
259,
327,
378,
88,
1276,
199,
7,
2371,
1656,
259,
327,
378,
88,
1344,
199,
7,
2662,
1907,
1656,
259,
327,
378,
88,
1401,
199,
7,
19910,
1656,
259,
327,
378,
88,
1703,
199,
7,
56,
5653,
1656,
259,
327,
378,
88,
1355,
199,
7,
12674,
1907,
1656,
259,
327,
378,
88,
19,
65,
199,
7,
36,
951,
1656,
259,
327,
378,
88,
19,
66,
199,
7,
1049,
621,
1656,
259,
327,
378,
88,
19,
67,
199,
7,
18176,
1656,
259,
327,
378,
88,
19,
68,
199,
7,
28960,
1656,
259,
327,
378,
88,
19,
69,
199,
7,
37,
1656,
259,
327,
378,
88,
19,
70,
199,
7,
37,
1656,
259,
327,
378,
88,
2167,
199,
7,
44,
810,
1656,
259,
327,
378,
88,
2953,
199,
7,
45,
5653,
1656,
259,
327,
378,
88,
2260,
199,
7,
714,
71,
1656,
259,
327,
378,
88,
2824,
199,
7,
48,
810,
1656,
259,
327,
378,
88,
1602,
199,
7,
24783,
1656,
259,
327,
378,
88,
2322,
199,
7,
1575,
1656,
259,
327,
378,
88,
2466,
199,
7,
3630,
73,
1656,
259,
327,
378,
88,
2417,
199,
7,
36,
316,
1656,
259,
327,
378,
88,
2006,
199,
7,
55,
290,
1656,
259,
327,
378,
88,
1887,
199,
7,
34,
18939,
1656,
259,
327,
378,
88,
20,
65,
199,
7,
56,
18939,
1656,
259,
327,
378,
88,
20,
66,
199,
7,
2662,
85,
1656,
259,
327,
378,
88,
20,
67,
199,
7,
19910,
1656,
259,
327,
378,
88,
20,
68,
199,
7,
40,
1907,
1656,
259,
327,
378,
88,
20,
69,
199,
7,
19590,
1656,
259,
327,
378,
88,
20,
70,
199,
7,
37,
1656,
259,
327,
378,
88,
1400,
199,
7,
26724,
1656,
259,
327,
378,
88,
2869,
199,
7,
52,
290,
1656,
259,
327,
378,
88,
2528,
199,
7,
3456,
73,
1656,
259,
327,
378,
88,
2481,
199,
7,
6004,
73,
1656,
259,
327,
378,
88,
1477,
199,
7,
42,
1873,
1656,
259,
327,
378,
88,
1229,
199,
7,
52,
5653,
1656,
259,
327,
378,
88,
1367,
199,
7,
20959,
1656,
259,
327,
378,
88,
1641,
199,
7,
2371,
290,
1656,
259,
327,
378,
88,
2010,
199,
7,
42,
316,
1656,
259,
327,
378,
88,
1427,
199,
7,
40,
324,
1656,
259,
327,
378,
88,
21,
65,
199,
7,
42,
316,
1656,
259,
327,
378,
88,
21,
66,
199,
7,
49,
5653,
1656,
259,
327,
378,
88,
21,
67,
199,
7,
1341,
290,
1656,
259,
327,
378,
88,
21,
68,
199,
7,
56,
316,
1656,
259,
327,
378,
88,
21,
69,
199,
7,
25542,
1656,
259,
327,
378,
88,
21,
70,
199,
7,
24804,
1656,
259,
327,
378,
88,
2259,
199,
7,
44,
5789,
1656,
259,
327,
378,
88,
2976,
199,
7,
17975,
1656,
259,
327,
378,
88,
2789,
199,
7,
57,
262,
1656,
259,
327,
378,
88,
2766,
199,
7,
6209,
85,
1656,
259,
327,
378,
88,
772,
199,
7,
1049,
13780,
1656,
259,
327,
378,
88,
2182,
199,
7,
19590,
1656,
259,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
rajsadho/django
|
django/template/context_processors.py
|
187
|
2463
|
"""
A set of request processors that return dictionaries to be merged into a
template context. Each function takes the request object as its only parameter
and returns a dictionary to add to the context.
These are referenced from the 'context_processors' option of the configuration
of a DjangoTemplates backend and used by RequestContext.
"""
from __future__ import unicode_literals
from django.conf import settings
from django.middleware.csrf import get_token
from django.utils.encoding import smart_text
from django.utils.functional import SimpleLazyObject, lazy
def csrf(request):
"""
Context processor that provides a CSRF token, or the string 'NOTPROVIDED' if
it has not been provided by either a view decorator or the middleware
"""
def _get_val():
token = get_token(request)
if token is None:
# In order to be able to provide debugging info in the
# case of misconfiguration, we use a sentinel value
# instead of returning an empty dict.
return 'NOTPROVIDED'
else:
return smart_text(token)
return {'csrf_token': SimpleLazyObject(_get_val)}
def debug(request):
"""
Returns context variables helpful for debugging.
"""
context_extras = {}
if settings.DEBUG and request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS:
context_extras['debug'] = True
from django.db import connection
# Return a lazy reference that computes connection.queries on access,
# to ensure it contains queries triggered after this function runs.
context_extras['sql_queries'] = lazy(lambda: connection.queries, list)
return context_extras
def i18n(request):
from django.utils import translation
context_extras = {}
context_extras['LANGUAGES'] = settings.LANGUAGES
context_extras['LANGUAGE_CODE'] = translation.get_language()
context_extras['LANGUAGE_BIDI'] = translation.get_language_bidi()
return context_extras
def tz(request):
from django.utils import timezone
return {'TIME_ZONE': timezone.get_current_timezone_name()}
def static(request):
"""
Adds static-related context variables to the context.
"""
return {'STATIC_URL': settings.STATIC_URL}
def media(request):
"""
Adds media-related context variables to the context.
"""
return {'MEDIA_URL': settings.MEDIA_URL}
def request(request):
return {'request': request}
|
bsd-3-clause
|
[
624,
199,
33,
663,
402,
1056,
21620,
626,
372,
11196,
370,
506,
9545,
1901,
282,
199,
1160,
1067,
14,
7048,
805,
6181,
314,
1056,
909,
465,
2399,
1454,
2725,
199,
460,
2529,
282,
2600,
370,
1050,
370,
314,
1067,
14,
199,
199,
20676,
787,
11812,
687,
314,
283,
1100,
63,
10547,
7,
945,
402,
314,
2897,
199,
1618,
282,
5634,
17969,
4865,
436,
1202,
701,
22538,
14,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
5754,
14,
10088,
492,
664,
63,
1418,
199,
504,
1639,
14,
1208,
14,
2991,
492,
11179,
63,
505,
199,
504,
1639,
14,
1208,
14,
15481,
492,
5870,
14269,
1692,
12,
9617,
421,
199,
318,
19213,
8,
1069,
304,
272,
408,
272,
9470,
12495,
626,
6571,
282,
22468,
1526,
12,
503,
314,
1059,
283,
4609,
21403,
1149,
7,
340,
272,
652,
965,
440,
2757,
2741,
701,
1902,
282,
2455,
7531,
503,
314,
10816,
272,
408,
272,
347,
485,
362,
63,
637,
837,
267,
1526,
275,
664,
63,
1418,
8,
1069,
9,
267,
340,
1526,
365,
488,
26,
288,
327,
1010,
1865,
370,
506,
7688,
370,
5647,
10201,
2256,
315,
314,
288,
327,
1930,
402,
3201,
4758,
12,
781,
675,
282,
13792,
574,
288,
327,
3140,
402,
8152,
376,
2701,
1211,
14,
288,
372,
283,
4609,
21403,
1149,
7,
267,
587,
26,
288,
372,
11179,
63,
505,
8,
1418,
9,
339,
372,
791,
10088,
63,
1418,
356,
5870,
14269,
1692,
1547,
362,
63,
637,
6769,
421,
199,
318,
3105,
8,
1069,
304,
272,
408,
272,
1803,
1067,
2860,
24606,
367,
10201,
14,
272,
408,
272,
1067,
63,
9975,
275,
1052,
272,
340,
2202,
14,
5287,
436,
1056,
14,
10614,
14,
362,
360,
16058,
63,
7803,
358,
315,
2202,
14,
17681,
63,
12346,
26,
267,
1067,
63,
9975,
459,
1757,
418,
275,
715,
267,
687,
1639,
14,
697,
492,
1950,
267,
327,
1432,
282,
9617,
3659,
626,
21445,
1950,
14,
10590,
641,
2879,
12,
267,
327,
370,
4868,
652,
3509,
9212,
15572,
2410,
642,
805,
7858,
14,
267,
1067,
63,
9975,
459,
3009,
63,
10590,
418,
275,
9617,
8,
2734,
26,
1950,
14,
10590,
12,
769,
9,
272,
372,
1067,
63,
9975,
421,
199,
318,
284,
1085,
78,
8,
1069,
304,
272,
687,
1639,
14,
1208,
492,
7761,
339,
1067,
63,
9975,
275,
1052,
272,
1067,
63,
9975,
459,
26886,
418,
275,
2202,
14,
26886,
272,
1067,
63,
9975,
459,
13947,
63,
6012,
418,
275,
7761,
14,
362,
63,
3671,
342,
272,
1067,
63,
9975,
459,
13947,
63,
34,
28904,
418,
275,
7761,
14,
362,
63,
3671,
63,
21555,
342,
339,
372,
1067,
63,
9975,
421,
199,
318,
5823,
8,
1069,
304,
272,
687,
1639,
14,
1208,
492,
7137,
339,
372,
791,
4961,
63,
15353,
356,
7137,
14,
362,
63,
1818,
63,
7145,
63,
354,
12737,
421,
199,
318,
2955,
8,
1069,
304,
272,
408,
272,
15747,
2955,
13,
2407,
1067,
2860,
370,
314,
1067,
14,
272,
408,
272,
372,
791,
10449,
63,
2632,
356,
2202,
14,
10449,
63,
2632,
93,
421,
199,
318,
5898,
8,
1069,
304,
272,
408,
272,
15747,
5898,
13,
2407,
1067,
2860,
370,
314,
1067,
14,
272,
408,
272,
372,
791,
13669,
63,
2632,
356,
2202,
14,
13669,
63,
2632,
93,
421,
199,
318,
1056,
8,
1069,
304,
272,
372,
791,
1069,
356,
1056,
93,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
33,
663,
402,
1056,
21620,
626,
372,
11196,
370,
506,
9545,
1901,
282,
199,
1160,
1067,
14,
7048,
805,
6181,
314,
1056,
909,
465,
2399,
1454,
2725,
199,
460,
2529,
282,
2600,
370,
1050,
370,
314,
1067,
14,
199,
199,
20676,
787,
11812,
687,
314,
283,
1100,
63,
10547,
7,
945,
402,
314,
2897,
199,
1618,
282,
5634,
17969,
4865,
436,
1202,
701,
22538,
14,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
5754,
14,
10088,
492,
664,
63,
1418,
199,
504,
1639,
14,
1208,
14,
2991,
492,
11179,
63,
505,
199,
504,
1639,
14,
1208,
14,
15481,
492,
5870,
14269,
1692,
12,
9617,
421,
199,
318,
19213,
8,
1069,
304,
272,
408,
272,
9470,
12495,
626,
6571,
282,
22468,
1526,
12,
503,
314,
1059,
283,
4609,
21403,
1149,
7,
340,
272,
652,
965,
440,
2757,
2741,
701,
1902,
282,
2455,
7531,
503,
314,
10816,
272,
408,
272,
347,
485,
362,
63,
637,
837,
267,
1526,
275,
664,
63,
1418,
8,
1069,
9,
267,
340,
1526,
365,
488,
26,
288,
327,
1010,
1865,
370,
506,
7688,
370,
5647,
10201,
2256,
315,
314,
288,
327,
1930,
402,
3201,
4758,
12,
781,
675,
282,
13792,
574,
288,
327,
3140,
402,
8152,
376,
2701,
1211,
14,
288,
372,
283,
4609,
21403,
1149,
7,
267,
587,
26,
288,
372,
11179,
63,
505,
8,
1418,
9,
339,
372,
791,
10088,
63,
1418,
356,
5870,
14269,
1692,
1547,
362,
63,
637,
6769,
421,
199,
318,
3105,
8,
1069,
304,
272,
408,
272,
1803,
1067,
2860,
24606,
367,
10201,
14,
272,
408,
272,
1067,
63,
9975,
275,
1052,
272,
340,
2202,
14,
5287,
436,
1056,
14,
10614,
14,
362,
360,
16058,
63,
7803,
358,
315,
2202,
14,
17681,
63,
12346,
26,
267,
1067,
63,
9975,
459,
1757,
418,
275,
715,
267,
687,
1639,
14,
697,
492,
1950,
267,
327,
1432,
282,
9617,
3659,
626,
21445,
1950,
14,
10590,
641,
2879,
12,
267,
327,
370,
4868,
652,
3509,
9212,
15572,
2410,
642,
805,
7858,
14,
267,
1067,
63,
9975,
459,
3009,
63,
10590,
418,
275,
9617,
8,
2734,
26,
1950,
14,
10590,
12,
769,
9,
272,
372,
1067,
63,
9975,
421,
199,
318,
284,
1085,
78,
8,
1069,
304,
272,
687,
1639,
14,
1208,
492,
7761,
339,
1067,
63,
9975,
275,
1052,
272,
1067,
63,
9975,
459,
26886,
418,
275,
2202,
14,
26886,
272,
1067,
63,
9975,
459,
13947,
63,
6012,
418,
275,
7761,
14,
362,
63,
3671,
342,
272,
1067,
63,
9975,
459,
13947,
63,
34,
28904,
418,
275,
7761,
14,
362,
63,
3671,
63,
21555,
342,
339,
372,
1067,
63,
9975,
421,
199,
318,
5823,
8,
1069,
304,
272,
687,
1639,
14,
1208,
492,
7137,
339,
372,
791,
4961,
63,
15353,
356,
7137,
14,
362,
63,
1818,
63,
7145,
63,
354,
12737,
421,
199,
318,
2955,
8,
1069,
304,
272,
408,
272,
15747,
2955,
13,
2407,
1067,
2860,
370,
314,
1067,
14,
272,
408,
272,
372,
791,
10449,
63,
2632,
356,
2202,
14,
10449,
63,
2632,
93,
421,
199,
318,
5898,
8,
1069,
304,
272,
408,
272,
15747,
5898,
13,
2407,
1067,
2860,
370,
314,
1067,
14,
272,
408,
272,
372,
791,
13669,
63,
2632,
356,
2202,
14,
13669,
63,
2632,
93,
421,
199,
318,
1056,
8,
1069,
304,
272,
372,
791,
1069,
356,
1056,
93,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
mahim97/zulip
|
zerver/lib/test_classes.py
|
2
|
27055
|
from contextlib import contextmanager
from typing import (cast, Any, Callable, Dict, Iterable, Iterator, List, Mapping, Optional,
Sized, Tuple, Union, Text)
from django.core.urlresolvers import resolve
from django.conf import settings
from django.test import TestCase
from django.test.client import (
BOUNDARY, MULTIPART_CONTENT, encode_multipart,
)
from django.test.testcases import SerializeMixin
from django.http import HttpResponse
from django.db.utils import IntegrityError
from zerver.lib.initial_password import initial_password
from zerver.lib.utils import is_remote_server
from zerver.views.users import add_service
from zerver.lib.actions import (
check_send_message, create_stream_if_needed, bulk_add_subscriptions,
get_display_recipient, bulk_remove_subscriptions, do_create_user,
check_send_stream_message, gather_subscriptions
)
from zerver.lib.stream_subscription import (
get_stream_subscriptions_for_user,
)
from zerver.lib.test_helpers import (
instrument_url, find_key_by_email,
)
from zerver.models import (
get_stream,
get_user,
get_user,
get_realm,
Client,
Message,
Realm,
Recipient,
Service,
Stream,
Subscription,
UserProfile,
)
from zilencer.models import get_remote_server_by_uuid
import base64
import mock
import os
import re
import ujson
import urllib
from contextlib import contextmanager
API_KEYS = {} # type: Dict[Text, Text]
def flush_caches_for_testing() -> None:
global API_KEYS
API_KEYS = {}
class UploadSerializeMixin(SerializeMixin):
"""
We cannot use override_settings to change upload directory because
because settings.LOCAL_UPLOADS_DIR is used in url pattern and urls
are compiled only once. Otherwise using a different upload directory
for conflicting test cases would have provided better performance
while providing the required isolation.
"""
lockfile = 'var/upload_lock'
@classmethod
def setUpClass(cls: Any, *args: Any, **kwargs: Any) -> None:
if not os.path.exists(cls.lockfile):
with open(cls.lockfile, 'w'): # nocoverage - rare locking case
pass
super(UploadSerializeMixin, cls).setUpClass(*args, **kwargs)
class ZulipTestCase(TestCase):
# Ensure that the test system just shows us diffs
maxDiff = None # type: Optional[int]
'''
WRAPPER_COMMENT:
We wrap calls to self.client.{patch,put,get,post,delete} for various
reasons. Some of this has to do with fixing encodings before calling
into the Django code. Some of this has to do with providing a future
path for instrumentation. Some of it's just consistency.
The linter will prevent direct calls to self.client.foo, so the wrapper
functions have to fake out the linter by using a local variable called
django_client to fool the regext.
'''
DEFAULT_SUBDOMAIN = "zulip"
DEFAULT_REALM = Realm.objects.get(string_id='zulip')
def set_http_host(self, kwargs: Dict[str, Any]) -> None:
if 'subdomain' in kwargs:
kwargs['HTTP_HOST'] = Realm.host_for_subdomain(kwargs['subdomain'])
del kwargs['subdomain']
elif 'HTTP_HOST' not in kwargs:
kwargs['HTTP_HOST'] = Realm.host_for_subdomain(self.DEFAULT_SUBDOMAIN)
@instrument_url
def client_patch(self, url: Text, info: Dict[str, Any]={}, **kwargs: Any) -> HttpResponse:
"""
We need to urlencode, since Django's function won't do it for us.
"""
encoded = urllib.parse.urlencode(info)
django_client = self.client # see WRAPPER_COMMENT
self.set_http_host(kwargs)
return django_client.patch(url, encoded, **kwargs)
@instrument_url
def client_patch_multipart(self, url, info={}, **kwargs):
# type: (Text, Dict[str, Any], **Any) -> HttpResponse
"""
Use this for patch requests that have file uploads or
that need some sort of multi-part content. In the future
Django's test client may become a bit more flexible,
so we can hopefully eliminate this. (When you post
with the Django test client, it deals with MULTIPART_CONTENT
automatically, but not patch.)
"""
encoded = encode_multipart(BOUNDARY, info)
django_client = self.client # see WRAPPER_COMMENT
self.set_http_host(kwargs)
return django_client.patch(
url,
encoded,
content_type=MULTIPART_CONTENT,
**kwargs)
@instrument_url
def client_put(self, url: Text, info: Dict[str, Any]={}, **kwargs: Any) -> HttpResponse:
encoded = urllib.parse.urlencode(info)
django_client = self.client # see WRAPPER_COMMENT
self.set_http_host(kwargs)
return django_client.put(url, encoded, **kwargs)
@instrument_url
def client_delete(self, url: Text, info: Dict[str, Any]={}, **kwargs: Any) -> HttpResponse:
encoded = urllib.parse.urlencode(info)
django_client = self.client # see WRAPPER_COMMENT
self.set_http_host(kwargs)
return django_client.delete(url, encoded, **kwargs)
@instrument_url
def client_options(self, url: Text, info: Dict[str, Any]={}, **kwargs: Any) -> HttpResponse:
encoded = urllib.parse.urlencode(info)
django_client = self.client # see WRAPPER_COMMENT
self.set_http_host(kwargs)
return django_client.options(url, encoded, **kwargs)
@instrument_url
def client_head(self, url: Text, info: Dict[str, Any]={}, **kwargs: Any) -> HttpResponse:
encoded = urllib.parse.urlencode(info)
django_client = self.client # see WRAPPER_COMMENT
self.set_http_host(kwargs)
return django_client.head(url, encoded, **kwargs)
@instrument_url
def client_post(self, url: Text, info: Dict[str, Any]={}, **kwargs: Any) -> HttpResponse:
django_client = self.client # see WRAPPER_COMMENT
self.set_http_host(kwargs)
return django_client.post(url, info, **kwargs)
@instrument_url
def client_post_request(self, url: Text, req: Any) -> HttpResponse:
"""
We simulate hitting an endpoint here, although we
actually resolve the URL manually and hit the view
directly. We have this helper method to allow our
instrumentation to work for /notify_tornado and
future similar methods that require doing funny
things to a request object.
"""
match = resolve(url)
return match.func(req)
@instrument_url
def client_get(self, url: Text, info: Dict[str, Any]={}, **kwargs: Any) -> HttpResponse:
django_client = self.client # see WRAPPER_COMMENT
self.set_http_host(kwargs)
return django_client.get(url, info, **kwargs)
example_user_map = dict(
hamlet='hamlet@zulip.com',
cordelia='cordelia@zulip.com',
iago='iago@zulip.com',
prospero='prospero@zulip.com',
othello='othello@zulip.com',
AARON='AARON@zulip.com',
aaron='aaron@zulip.com',
ZOE='ZOE@zulip.com',
webhook_bot='webhook-bot@zulip.com',
welcome_bot='welcome-bot@zulip.com',
outgoing_webhook_bot='outgoing-webhook@zulip.com'
)
mit_user_map = dict(
sipbtest="sipbtest@mit.edu",
starnine="starnine@mit.edu",
espuser="espuser@mit.edu",
)
# Non-registered test users
nonreg_user_map = dict(
test='test@zulip.com',
test1='test1@zulip.com',
alice='alice@zulip.com',
newuser='newuser@zulip.com',
bob='bob@zulip.com',
cordelia='cordelia@zulip.com',
newguy='newguy@zulip.com',
me='me@zulip.com',
)
def nonreg_user(self, name: str) -> UserProfile:
email = self.nonreg_user_map[name]
return get_user(email, get_realm("zulip"))
def example_user(self, name: str) -> UserProfile:
email = self.example_user_map[name]
return get_user(email, get_realm('zulip'))
def mit_user(self, name: str) -> UserProfile:
email = self.mit_user_map[name]
return get_user(email, get_realm('zephyr'))
def nonreg_email(self, name: str) -> Text:
return self.nonreg_user_map[name]
def example_email(self, name: str) -> Text:
return self.example_user_map[name]
def mit_email(self, name: str) -> Text:
return self.mit_user_map[name]
def notification_bot(self) -> UserProfile:
return get_user('notification-bot@zulip.com', get_realm('zulip'))
def create_test_bot(self, email: Text, user_profile: UserProfile, full_name: Text,
short_name: Text, bot_type: int, service_name: str=None) -> UserProfile:
bot_profile = do_create_user(email=email, password='', realm=user_profile.realm,
full_name=full_name, short_name=short_name,
bot_type=bot_type, bot_owner=user_profile)
if bot_type in (UserProfile.OUTGOING_WEBHOOK_BOT, UserProfile.EMBEDDED_BOT):
add_service(name=service_name, user_profile=bot_profile,
base_url='', interface=Service.GENERIC,
token='abcdef')
return bot_profile
def login_with_return(self, email: Text, password: Optional[Text]=None,
**kwargs: Any) -> HttpResponse:
if password is None:
password = initial_password(email)
return self.client_post('/accounts/login/',
{'username': email, 'password': password},
**kwargs)
def login(self, email: Text, password: Optional[Text]=None, fails: bool=False,
realm: Optional[Realm]=None) -> HttpResponse:
if realm is None:
realm = get_realm("zulip")
if password is None:
password = initial_password(email)
if not fails:
self.assertTrue(self.client.login(username=email, password=password,
realm=realm))
else:
self.assertFalse(self.client.login(username=email, password=password,
realm=realm))
def logout(self) -> None:
self.client.logout()
def register(self, email: Text, password: Text, **kwargs: Any) -> HttpResponse:
self.client_post('/accounts/home/', {'email': email},
**kwargs)
return self.submit_reg_form_for_user(email, password, **kwargs)
def submit_reg_form_for_user(
self, email: Text, password: Text,
realm_name: Optional[Text]="Zulip Test",
realm_subdomain: Optional[Text]="zuliptest",
from_confirmation: Optional[Text]='', full_name: Optional[Text]=None,
timezone: Optional[Text]='', realm_in_root_domain: Optional[Text]=None,
default_stream_groups: Optional[List[Text]]=[], **kwargs: Any) -> HttpResponse:
"""
Stage two of the two-step registration process.
If things are working correctly the account should be fully
registered after this call.
You can pass the HTTP_HOST variable for subdomains via kwargs.
"""
if full_name is None:
full_name = email.replace("@", "_")
payload = {
'full_name': full_name,
'password': password,
'realm_name': realm_name,
'realm_subdomain': realm_subdomain,
'key': find_key_by_email(email),
'timezone': timezone,
'terms': True,
'from_confirmation': from_confirmation,
'default_stream_group': default_stream_groups,
}
if realm_in_root_domain is not None:
payload['realm_in_root_domain'] = realm_in_root_domain
return self.client_post('/accounts/register/', payload, **kwargs)
def get_confirmation_url_from_outbox(self, email_address: Text, *,
url_pattern: Text=None) -> Text:
from django.core.mail import outbox
if url_pattern is None:
# This is a bit of a crude heuristic, but good enough for most tests.
url_pattern = settings.EXTERNAL_HOST + "(\S+)>"
for message in reversed(outbox):
if email_address in message.to:
return re.search(url_pattern, message.body).groups()[0]
else:
raise AssertionError("Couldn't find a confirmation email.")
def api_auth(self, identifier: Text, realm: Text="zulip") -> Dict[str, Text]:
"""
identifier: Can be an email or a remote server uuid.
"""
if identifier in API_KEYS:
api_key = API_KEYS[identifier]
else:
if is_remote_server(identifier):
api_key = get_remote_server_by_uuid(identifier).api_key
else:
api_key = get_user(identifier, get_realm(realm)).api_key
API_KEYS[identifier] = api_key
credentials = "%s:%s" % (identifier, api_key)
return {
'HTTP_AUTHORIZATION': 'Basic ' + base64.b64encode(credentials.encode('utf-8')).decode('utf-8')
}
def get_streams(self, email: Text, realm: Realm) -> List[Text]:
"""
Helper function to get the stream names for a user
"""
user_profile = get_user(email, realm)
subs = get_stream_subscriptions_for_user(user_profile).filter(
active=True,
)
return [cast(Text, get_display_recipient(sub.recipient)) for sub in subs]
def send_personal_message(self, from_email: Text, to_email: Text, content: Text="test content",
sender_realm: Text="zulip") -> int:
sender = get_user(from_email, get_realm(sender_realm))
recipient_list = [to_email]
(sending_client, _) = Client.objects.get_or_create(name="test suite")
return check_send_message(
sender, sending_client, 'private', recipient_list, None,
content
)
def send_huddle_message(self, from_email: Text, to_emails: List[Text], content: Text="test content",
sender_realm: Text="zulip") -> int:
sender = get_user(from_email, get_realm(sender_realm))
assert(len(to_emails) >= 2)
(sending_client, _) = Client.objects.get_or_create(name="test suite")
return check_send_message(
sender, sending_client, 'private', to_emails, None,
content
)
def send_stream_message(self, sender_email: Text, stream_name: Text, content: Text="test content",
topic_name: Text="test", sender_realm: Text="zulip") -> int:
sender = get_user(sender_email, get_realm(sender_realm))
(sending_client, _) = Client.objects.get_or_create(name="test suite")
return check_send_stream_message(
sender=sender,
client=sending_client,
stream_name=stream_name,
topic=topic_name,
body=content,
)
def get_messages(self, anchor: int=1, num_before: int=100, num_after: int=100,
use_first_unread_anchor: bool=False) -> List[Dict[str, Any]]:
post_params = {"anchor": anchor, "num_before": num_before,
"num_after": num_after,
"use_first_unread_anchor": ujson.dumps(use_first_unread_anchor)}
result = self.client_get("/json/messages", dict(post_params))
data = result.json()
return data['messages']
def users_subscribed_to_stream(self, stream_name: Text, realm: Realm) -> List[UserProfile]:
stream = Stream.objects.get(name=stream_name, realm=realm)
recipient = Recipient.objects.get(type_id=stream.id, type=Recipient.STREAM)
subscriptions = Subscription.objects.filter(recipient=recipient, active=True)
return [subscription.user_profile for subscription in subscriptions]
def assert_url_serves_contents_of_file(self, url: str, result: bytes) -> None:
response = self.client_get(url)
data = b"".join(response.streaming_content)
self.assertEqual(result, data)
def assert_json_success(self, result: HttpResponse) -> Dict[str, Any]:
"""
Successful POSTs return a 200 and JSON of the form {"result": "success",
"msg": ""}.
"""
try:
json = ujson.loads(result.content)
except Exception: # nocoverage
json = {'msg': "Error parsing JSON in response!"}
self.assertEqual(result.status_code, 200, json['msg'])
self.assertEqual(json.get("result"), "success")
# We have a msg key for consistency with errors, but it typically has an
# empty value.
self.assertIn("msg", json)
self.assertNotEqual(json["msg"], "Error parsing JSON in response!")
return json
def get_json_error(self, result: HttpResponse, status_code: int=400) -> Dict[str, Any]:
try:
json = ujson.loads(result.content)
except Exception: # nocoverage
json = {'msg': "Error parsing JSON in response!"}
self.assertEqual(result.status_code, status_code, msg=json.get('msg'))
self.assertEqual(json.get("result"), "error")
return json['msg']
def assert_json_error(self, result: HttpResponse, msg: Text, status_code: int=400) -> None:
"""
Invalid POSTs return an error status code and JSON of the form
{"result": "error", "msg": "reason"}.
"""
self.assertEqual(self.get_json_error(result, status_code=status_code), msg)
def assert_length(self, items: List[Any], count: int) -> None:
actual_count = len(items)
if actual_count != count: # nocoverage
print('ITEMS:\n')
for item in items:
print(item)
print("\nexpected length: %s\nactual length: %s" % (count, actual_count))
raise AssertionError('List is unexpected size!')
def assert_json_error_contains(self, result: HttpResponse, msg_substring: Text,
status_code: int=400) -> None:
self.assertIn(msg_substring, self.get_json_error(result, status_code=status_code))
def assert_in_response(self, substring: Text, response: HttpResponse) -> None:
self.assertIn(substring, response.content.decode('utf-8'))
def assert_in_success_response(self, substrings: List[Text],
response: HttpResponse) -> None:
self.assertEqual(response.status_code, 200)
decoded = response.content.decode('utf-8')
for substring in substrings:
self.assertIn(substring, decoded)
def assert_not_in_success_response(self, substrings: List[Text],
response: HttpResponse) -> None:
self.assertEqual(response.status_code, 200)
decoded = response.content.decode('utf-8')
for substring in substrings:
self.assertNotIn(substring, decoded)
def fixture_data(self, type: Text, action: Text, file_type: Text='json') -> Text:
fn = os.path.join(
os.path.dirname(__file__),
"../webhooks/%s/fixtures/%s.%s" % (type, action, file_type)
)
return open(fn).read()
def make_stream(self, stream_name: Text, realm: Optional[Realm]=None,
invite_only: Optional[bool]=False) -> Stream:
if realm is None:
realm = self.DEFAULT_REALM
try:
stream = Stream.objects.create(
realm=realm,
name=stream_name,
invite_only=invite_only,
)
except IntegrityError: # nocoverage -- this is for bugs in the tests
raise Exception('''
%s already exists
Please call make_stream with a stream name
that is not already in use.''' % (stream_name,))
Recipient.objects.create(type_id=stream.id, type=Recipient.STREAM)
return stream
# Subscribe to a stream directly
def subscribe(self, user_profile: UserProfile, stream_name: Text) -> Stream:
try:
stream = get_stream(stream_name, user_profile.realm)
from_stream_creation = False
except Stream.DoesNotExist:
stream, from_stream_creation = create_stream_if_needed(user_profile.realm, stream_name)
bulk_add_subscriptions([stream], [user_profile], from_stream_creation=from_stream_creation)
return stream
def unsubscribe(self, user_profile: UserProfile, stream_name: Text) -> None:
stream = get_stream(stream_name, user_profile.realm)
bulk_remove_subscriptions([user_profile], [stream])
# Subscribe to a stream by making an API request
def common_subscribe_to_streams(self, email: Text, streams: Iterable[Text],
extra_post_data: Dict[str, Any]={}, invite_only: bool=False,
**kwargs: Any) -> HttpResponse:
post_data = {'subscriptions': ujson.dumps([{"name": stream} for stream in streams]),
'invite_only': ujson.dumps(invite_only)}
post_data.update(extra_post_data)
kw = kwargs.copy()
kw.update(self.api_auth(email, realm=kwargs.get('subdomain', 'zulip')))
result = self.client_post("/api/v1/users/me/subscriptions", post_data,
**kw)
return result
def check_user_subscribed_only_to_streams(self, user_name: Text,
streams: List[Stream]) -> None:
streams = sorted(streams, key=lambda x: x.name)
subscribed_streams = gather_subscriptions(self.nonreg_user(user_name))[0]
self.assertEqual(len(subscribed_streams), len(streams))
for x, y in zip(subscribed_streams, streams):
self.assertEqual(x["name"], y.name)
def send_json_payload(self, user_profile: UserProfile, url: Text,
payload: Union[Text, Dict[str, Any]],
stream_name: Optional[Text]=None, **post_params: Any) -> Message:
if stream_name is not None:
self.subscribe(user_profile, stream_name)
result = self.client_post(url, payload, **post_params)
self.assert_json_success(result)
# Check the correct message was sent
msg = self.get_last_message()
self.assertEqual(msg.sender.email, user_profile.email)
if stream_name is not None:
self.assertEqual(get_display_recipient(msg.recipient), stream_name)
# TODO: should also validate recipient for private messages
return msg
def get_last_message(self) -> Message:
return Message.objects.latest('id')
def get_second_to_last_message(self) -> Message:
return Message.objects.all().order_by('-id')[1]
@contextmanager
def simulated_markdown_failure(self) -> Iterator[None]:
'''
This raises a failure inside of the try/except block of
bugdown.__init__.do_convert.
'''
with \
self.settings(ERROR_BOT=None), \
mock.patch('zerver.lib.bugdown.timeout', side_effect=KeyError('foo')), \
mock.patch('zerver.lib.bugdown.log_bugdown_error'):
yield
class WebhookTestCase(ZulipTestCase):
"""
Common for all webhooks tests
Override below class attributes and run send_and_test_message
If you create your url in uncommon way you can override build_webhook_url method
In case that you need modify body or create it without using fixture you can also override get_body method
"""
STREAM_NAME = None # type: Optional[Text]
TEST_USER_EMAIL = 'webhook-bot@zulip.com'
URL_TEMPLATE = None # type: Optional[Text]
FIXTURE_DIR_NAME = None # type: Optional[Text]
@property
def test_user(self) -> UserProfile:
return get_user(self.TEST_USER_EMAIL, get_realm("zulip"))
def setUp(self) -> None:
self.url = self.build_webhook_url()
def send_and_test_stream_message(self, fixture_name: Text, expected_subject: Optional[Text]=None,
expected_message: Optional[Text]=None,
content_type: Optional[Text]="application/json", **kwargs: Any) -> Message:
payload = self.get_body(fixture_name)
if content_type is not None:
kwargs['content_type'] = content_type
msg = self.send_json_payload(self.test_user, self.url, payload,
self.STREAM_NAME, **kwargs)
self.do_test_subject(msg, expected_subject)
self.do_test_message(msg, expected_message)
return msg
def send_and_test_private_message(self, fixture_name: Text, expected_subject: Text=None,
expected_message: Text=None, content_type: str="application/json",
**kwargs: Any)-> Message:
payload = self.get_body(fixture_name)
if content_type is not None:
kwargs['content_type'] = content_type
msg = self.send_json_payload(self.test_user, self.url, payload,
stream_name=None, **kwargs)
self.do_test_message(msg, expected_message)
return msg
def build_webhook_url(self, *args: Any, **kwargs: Any) -> Text:
url = self.URL_TEMPLATE
if url.find("api_key") >= 0:
api_key = self.test_user.api_key
url = self.URL_TEMPLATE.format(api_key=api_key,
stream=self.STREAM_NAME)
else:
url = self.URL_TEMPLATE.format(stream=self.STREAM_NAME)
has_arguments = kwargs or args
if has_arguments and url.find('?') == -1:
url = "{}?".format(url)
else:
url = "{}&".format(url)
for key, value in kwargs.items():
url = "{}{}={}&".format(url, key, value)
for arg in args:
url = "{}{}&".format(url, arg)
return url[:-1] if has_arguments else url
def get_body(self, fixture_name: Text) -> Union[Text, Dict[str, Text]]:
"""Can be implemented either as returning a dictionary containing the
post parameters or as string containing the body of the request."""
return ujson.dumps(ujson.loads(self.fixture_data(self.FIXTURE_DIR_NAME, fixture_name)))
def do_test_subject(self, msg: Message, expected_subject: Optional[Text]) -> None:
if expected_subject is not None:
self.assertEqual(msg.topic_name(), expected_subject)
def do_test_message(self, msg: Message, expected_message: Optional[Text]) -> None:
if expected_message is not None:
self.assertEqual(msg.content, expected_message)
|
apache-2.0
|
[
504,
15502,
492,
27608,
199,
504,
14090,
492,
334,
2931,
12,
6184,
12,
16975,
12,
7448,
12,
19937,
12,
25769,
12,
3820,
12,
12340,
12,
4879,
12,
490,
428,
1759,
12,
11634,
12,
15961,
12,
4516,
9,
199,
199,
504,
1639,
14,
1018,
14,
16522,
492,
7512,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
396,
492,
7640,
199,
504,
1639,
14,
396,
14,
1258,
492,
334,
272,
4367,
6131,
4392,
12,
24895,
1772,
2294,
63,
9663,
12,
3752,
63,
10123,
12,
199,
9,
199,
504,
1639,
14,
396,
14,
396,
9403,
492,
11973,
794,
4256,
199,
504,
1639,
14,
1014,
492,
6183,
199,
504,
1639,
14,
697,
14,
1208,
492,
26864,
199,
199,
504,
19959,
14,
773,
14,
2747,
63,
2060,
492,
2536,
63,
2060,
199,
504,
19959,
14,
773,
14,
1208,
492,
365,
63,
3846,
63,
1000,
199,
504,
19959,
14,
4196,
14,
3707,
492,
1050,
63,
1364,
199,
199,
504,
19959,
14,
773,
14,
3723,
492,
334,
272,
1104,
63,
2254,
63,
1188,
12,
1218,
63,
1745,
63,
692,
63,
11368,
12,
13137,
63,
525,
63,
13233,
12,
272,
664,
63,
2918,
63,
10043,
12,
13137,
63,
2168,
63,
13233,
12,
886,
63,
981,
63,
751,
12,
272,
1104,
63,
2254,
63,
1745,
63,
1188,
12,
13082,
63,
13233,
199,
9,
199,
199,
504,
19959,
14,
773,
14,
1745,
63,
6645,
492,
334,
272,
664,
63,
1745,
63,
13233,
63,
509,
63,
751,
12,
199,
9,
199,
199,
504,
19959,
14,
773,
14,
396,
63,
7546,
492,
334,
272,
14498,
63,
633,
12,
2342,
63,
498,
63,
991,
63,
2123,
12,
199,
9,
199,
199,
504,
19959,
14,
992,
492,
334,
272,
664,
63,
1745,
12,
272,
664,
63,
751,
12,
272,
664,
63,
751,
12,
272,
664,
63,
7728,
12,
272,
6810,
12,
272,
6430,
12,
272,
27715,
12,
272,
799,
6157,
12,
272,
7591,
12,
272,
8271,
12,
272,
29763,
12,
272,
19037,
12,
199,
9,
199,
199,
504,
1315,
441,
78,
2247,
14,
992,
492,
664,
63,
3846,
63,
1000,
63,
991,
63,
2580,
421,
199,
646,
1300,
772,
199,
646,
1683,
199,
646,
747,
199,
646,
295,
199,
646,
399,
1001,
199,
646,
4011,
199,
199,
504,
15502,
492,
27608,
199,
199,
3735,
63,
17434,
275,
1052,
221,
327,
730,
26,
7448,
59,
1872,
12,
4516,
61,
199,
199,
318,
8976,
63,
17595,
63,
509,
63,
4776,
342,
1035,
488,
26,
272,
2288,
3261,
63,
17434,
272,
3261,
63,
17434,
275,
1052,
199,
199,
533,
19149,
6383,
4256,
8,
6383,
4256,
304,
272,
408,
272,
2136,
3913,
675,
4278,
63,
1751,
370,
1570,
5802,
2082,
2952,
272,
2952,
2202,
14,
7486,
63,
16418,
51,
63,
3022,
365,
1202,
315,
1166,
3851,
436,
8187,
272,
787,
10311,
1454,
5403,
14,
6630,
1808,
282,
3365,
5802,
2082,
272,
367,
28204,
511,
5560,
3955,
1172,
2741,
8034,
10238,
272,
1830,
13070,
314,
1415,
30567,
14,
272,
408,
272,
4650,
493,
275,
283,
1391,
15,
5064,
63,
831,
7,
339,
768,
3744,
272,
347,
18561,
8,
1886,
26,
6184,
12,
627,
589,
26,
6184,
12,
1011,
958,
26,
6184,
9,
1035,
488,
26,
267,
340,
440,
747,
14,
515,
14,
2444,
8,
1886,
14,
26204,
304,
288,
543,
1551,
8,
1886,
14,
26204,
12,
283,
87,
735,
221,
327,
949,
10828,
446,
24063,
27267,
1930,
355,
986,
398,
1613,
8,
10301,
6383,
4256,
12,
843,
680,
27777,
2031,
589,
12,
1011,
958,
9,
199,
199,
533,
3107,
11294,
1746,
8,
1746,
304,
272,
327,
7523,
626,
314,
511,
2656,
2951,
13703,
2739,
14981,
272,
1390,
10746,
275,
488,
221,
327,
730,
26,
4879,
59,
442,
61,
339,
1449,
272,
16573,
1282,
4227,
63,
10973,
26,
339,
2136,
4816,
4882,
370,
291,
14,
1258,
23379,
2068,
12,
524,
12,
362,
12,
1932,
12,
1807,
93,
367,
7750,
272,
14872,
14,
221,
6601,
402,
642,
965,
370,
886,
543,
5325,
316,
14134,
2544,
6358,
272,
1901,
314,
5634,
1233,
14,
221,
6601,
402,
642,
965,
370,
886,
543,
13070,
282,
6466,
272,
931,
367,
14498,
425,
14,
221,
6601,
402,
652,
1159,
2951,
17754,
14,
339,
710,
7403,
351,
911,
7981,
4125,
4882,
370,
291,
14,
1258,
14,
1421,
12,
880,
314,
4975,
272,
3423,
1172,
370,
4026,
734,
314,
7403,
351,
701,
1808,
282,
2257,
1750,
2797,
272,
1639,
63,
1258,
370,
7090,
393,
314,
295,
303,
400,
14,
272,
1449,
272,
6186,
63,
6348,
7378,
275,
298,
14548,
2,
272,
6186,
63,
15508,
45,
275,
27715,
14,
1462,
14,
362,
8,
875,
63,
344,
534,
14548,
358,
339,
347,
663,
63,
1014,
63,
1102,
8,
277,
12,
2074,
26,
7448,
59,
495,
12,
6184,
566,
1035,
488,
26,
267,
340,
283,
22806,
7,
315,
2074,
26,
288,
2074,
459,
2856,
63,
5449,
418,
275,
27715,
14,
1102,
63,
509,
63,
22806,
8,
958,
459,
22806,
1105,
288,
2150,
2074,
459,
22806,
418,
267,
916,
283,
2856,
63,
5449,
7,
440,
315,
2074,
26,
288,
2074,
459,
2856,
63,
5449,
418,
275,
27715,
14,
1102,
63,
509,
63,
22806,
8,
277,
14,
3472,
63,
6348,
7378,
9,
339,
768,
13321,
63,
633,
272,
347,
1890,
63,
2068,
8,
277,
12,
1166,
26,
4516,
12,
2256,
26,
7448,
59,
495,
12,
6184,
61,
10324,
1011,
958,
26,
6184,
9,
1035,
6183,
26,
267,
408,
267,
2136,
1929,
370,
16511,
12,
3967,
5634,
1159,
805,
7859,
1133,
886,
652,
367,
2739,
14,
267,
408,
267,
5737,
275,
4011,
14,
1122,
14,
10738,
8,
815,
9,
267,
1639,
63,
1258,
275,
291,
14,
1258,
221,
327,
1937,
16573,
1282,
4227,
63,
10973,
267,
291,
14,
409,
63,
1014,
63,
1102,
8,
958,
9,
267,
372,
1639,
63,
1258,
14,
2068,
8,
633,
12,
5737,
12,
1011,
958,
9,
339,
768,
13321,
63,
633,
272,
347,
1890,
63,
2068,
63,
10123,
8,
277,
12,
1166,
12,
2256,
10324,
1011,
958,
304,
267,
327,
730,
26,
334,
1872,
12,
7448,
59,
495,
12,
6184,
467,
1011,
9874,
9,
1035,
6183,
267,
408,
267,
3645,
642,
367,
3371,
4145,
626,
1172,
570,
26598,
503,
267,
626,
1929,
2005,
4069,
402,
3510,
13,
2064,
1564,
14,
221,
1010,
314,
6466,
267,
5634,
1159,
511,
1890,
1443
] |
[
15502,
492,
27608,
199,
504,
14090,
492,
334,
2931,
12,
6184,
12,
16975,
12,
7448,
12,
19937,
12,
25769,
12,
3820,
12,
12340,
12,
4879,
12,
490,
428,
1759,
12,
11634,
12,
15961,
12,
4516,
9,
199,
199,
504,
1639,
14,
1018,
14,
16522,
492,
7512,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
396,
492,
7640,
199,
504,
1639,
14,
396,
14,
1258,
492,
334,
272,
4367,
6131,
4392,
12,
24895,
1772,
2294,
63,
9663,
12,
3752,
63,
10123,
12,
199,
9,
199,
504,
1639,
14,
396,
14,
396,
9403,
492,
11973,
794,
4256,
199,
504,
1639,
14,
1014,
492,
6183,
199,
504,
1639,
14,
697,
14,
1208,
492,
26864,
199,
199,
504,
19959,
14,
773,
14,
2747,
63,
2060,
492,
2536,
63,
2060,
199,
504,
19959,
14,
773,
14,
1208,
492,
365,
63,
3846,
63,
1000,
199,
504,
19959,
14,
4196,
14,
3707,
492,
1050,
63,
1364,
199,
199,
504,
19959,
14,
773,
14,
3723,
492,
334,
272,
1104,
63,
2254,
63,
1188,
12,
1218,
63,
1745,
63,
692,
63,
11368,
12,
13137,
63,
525,
63,
13233,
12,
272,
664,
63,
2918,
63,
10043,
12,
13137,
63,
2168,
63,
13233,
12,
886,
63,
981,
63,
751,
12,
272,
1104,
63,
2254,
63,
1745,
63,
1188,
12,
13082,
63,
13233,
199,
9,
199,
199,
504,
19959,
14,
773,
14,
1745,
63,
6645,
492,
334,
272,
664,
63,
1745,
63,
13233,
63,
509,
63,
751,
12,
199,
9,
199,
199,
504,
19959,
14,
773,
14,
396,
63,
7546,
492,
334,
272,
14498,
63,
633,
12,
2342,
63,
498,
63,
991,
63,
2123,
12,
199,
9,
199,
199,
504,
19959,
14,
992,
492,
334,
272,
664,
63,
1745,
12,
272,
664,
63,
751,
12,
272,
664,
63,
751,
12,
272,
664,
63,
7728,
12,
272,
6810,
12,
272,
6430,
12,
272,
27715,
12,
272,
799,
6157,
12,
272,
7591,
12,
272,
8271,
12,
272,
29763,
12,
272,
19037,
12,
199,
9,
199,
199,
504,
1315,
441,
78,
2247,
14,
992,
492,
664,
63,
3846,
63,
1000,
63,
991,
63,
2580,
421,
199,
646,
1300,
772,
199,
646,
1683,
199,
646,
747,
199,
646,
295,
199,
646,
399,
1001,
199,
646,
4011,
199,
199,
504,
15502,
492,
27608,
199,
199,
3735,
63,
17434,
275,
1052,
221,
327,
730,
26,
7448,
59,
1872,
12,
4516,
61,
199,
199,
318,
8976,
63,
17595,
63,
509,
63,
4776,
342,
1035,
488,
26,
272,
2288,
3261,
63,
17434,
272,
3261,
63,
17434,
275,
1052,
199,
199,
533,
19149,
6383,
4256,
8,
6383,
4256,
304,
272,
408,
272,
2136,
3913,
675,
4278,
63,
1751,
370,
1570,
5802,
2082,
2952,
272,
2952,
2202,
14,
7486,
63,
16418,
51,
63,
3022,
365,
1202,
315,
1166,
3851,
436,
8187,
272,
787,
10311,
1454,
5403,
14,
6630,
1808,
282,
3365,
5802,
2082,
272,
367,
28204,
511,
5560,
3955,
1172,
2741,
8034,
10238,
272,
1830,
13070,
314,
1415,
30567,
14,
272,
408,
272,
4650,
493,
275,
283,
1391,
15,
5064,
63,
831,
7,
339,
768,
3744,
272,
347,
18561,
8,
1886,
26,
6184,
12,
627,
589,
26,
6184,
12,
1011,
958,
26,
6184,
9,
1035,
488,
26,
267,
340,
440,
747,
14,
515,
14,
2444,
8,
1886,
14,
26204,
304,
288,
543,
1551,
8,
1886,
14,
26204,
12,
283,
87,
735,
221,
327,
949,
10828,
446,
24063,
27267,
1930,
355,
986,
398,
1613,
8,
10301,
6383,
4256,
12,
843,
680,
27777,
2031,
589,
12,
1011,
958,
9,
199,
199,
533,
3107,
11294,
1746,
8,
1746,
304,
272,
327,
7523,
626,
314,
511,
2656,
2951,
13703,
2739,
14981,
272,
1390,
10746,
275,
488,
221,
327,
730,
26,
4879,
59,
442,
61,
339,
1449,
272,
16573,
1282,
4227,
63,
10973,
26,
339,
2136,
4816,
4882,
370,
291,
14,
1258,
23379,
2068,
12,
524,
12,
362,
12,
1932,
12,
1807,
93,
367,
7750,
272,
14872,
14,
221,
6601,
402,
642,
965,
370,
886,
543,
5325,
316,
14134,
2544,
6358,
272,
1901,
314,
5634,
1233,
14,
221,
6601,
402,
642,
965,
370,
886,
543,
13070,
282,
6466,
272,
931,
367,
14498,
425,
14,
221,
6601,
402,
652,
1159,
2951,
17754,
14,
339,
710,
7403,
351,
911,
7981,
4125,
4882,
370,
291,
14,
1258,
14,
1421,
12,
880,
314,
4975,
272,
3423,
1172,
370,
4026,
734,
314,
7403,
351,
701,
1808,
282,
2257,
1750,
2797,
272,
1639,
63,
1258,
370,
7090,
393,
314,
295,
303,
400,
14,
272,
1449,
272,
6186,
63,
6348,
7378,
275,
298,
14548,
2,
272,
6186,
63,
15508,
45,
275,
27715,
14,
1462,
14,
362,
8,
875,
63,
344,
534,
14548,
358,
339,
347,
663,
63,
1014,
63,
1102,
8,
277,
12,
2074,
26,
7448,
59,
495,
12,
6184,
566,
1035,
488,
26,
267,
340,
283,
22806,
7,
315,
2074,
26,
288,
2074,
459,
2856,
63,
5449,
418,
275,
27715,
14,
1102,
63,
509,
63,
22806,
8,
958,
459,
22806,
1105,
288,
2150,
2074,
459,
22806,
418,
267,
916,
283,
2856,
63,
5449,
7,
440,
315,
2074,
26,
288,
2074,
459,
2856,
63,
5449,
418,
275,
27715,
14,
1102,
63,
509,
63,
22806,
8,
277,
14,
3472,
63,
6348,
7378,
9,
339,
768,
13321,
63,
633,
272,
347,
1890,
63,
2068,
8,
277,
12,
1166,
26,
4516,
12,
2256,
26,
7448,
59,
495,
12,
6184,
61,
10324,
1011,
958,
26,
6184,
9,
1035,
6183,
26,
267,
408,
267,
2136,
1929,
370,
16511,
12,
3967,
5634,
1159,
805,
7859,
1133,
886,
652,
367,
2739,
14,
267,
408,
267,
5737,
275,
4011,
14,
1122,
14,
10738,
8,
815,
9,
267,
1639,
63,
1258,
275,
291,
14,
1258,
221,
327,
1937,
16573,
1282,
4227,
63,
10973,
267,
291,
14,
409,
63,
1014,
63,
1102,
8,
958,
9,
267,
372,
1639,
63,
1258,
14,
2068,
8,
633,
12,
5737,
12,
1011,
958,
9,
339,
768,
13321,
63,
633,
272,
347,
1890,
63,
2068,
63,
10123,
8,
277,
12,
1166,
12,
2256,
10324,
1011,
958,
304,
267,
327,
730,
26,
334,
1872,
12,
7448,
59,
495,
12,
6184,
467,
1011,
9874,
9,
1035,
6183,
267,
408,
267,
3645,
642,
367,
3371,
4145,
626,
1172,
570,
26598,
503,
267,
626,
1929,
2005,
4069,
402,
3510,
13,
2064,
1564,
14,
221,
1010,
314,
6466,
267,
5634,
1159,
511,
1890,
1443,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
AndreyPopovNew/asuswrt-merlin-rt-n
|
release/src/router/samba3/examples/scripts/shares/python/modify_samba_config.py
|
55
|
2452
|
#!/usr/bin/env python
######################################################################
##
## Simple add/delete/change share command script for Samba
##
## Copyright (C) Gerald Carter 2004.
##
## 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., 675 Mass Ave, Cambridge, MA 02139, USA.
##
######################################################################
import sys, os
from SambaConfig import SambaConf
## ##
## check the command line args ##
## ##
delete_mode = False
if len(sys.argv) == 3:
delete_mode = True
print "Deleting share..."
elif len(sys.argv) == 5:
print "Adding/Updating share..."
else:
print "Usage: %s configfile share [path] [comments]" % sys.argv[0]
sys.exit(1)
## ##
## read and parse the config file ##
## ##
confFile = SambaConf()
confFile.ReadConfig( sys.argv[1] )
if not confFile.valid:
exit( 1 )
if delete_mode:
if not confFile.isService( sys.argv[2] ):
sys.stderr.write( "Asked to delete non-existent service! [%s]\n" % sys.argv[2] )
sys.exit( 1 )
confFile.DelService( sys.argv[2] )
else:
## make the path if it doesn't exist. Bail out if that fails
if ( not os.path.isdir(sys.argv[3]) ):
try:
os.makedirs( sys.argv[3] )
os.chmod( sys.argv[3], 0777 )
except os.error:
sys.exit( 1 )
## only add a new service -- if it already exists, then
## just set the options
if not confFile.isService( sys.argv[2] ):
confFile.AddService( sys.argv[2], ['##', '## Added by modify_samba_config.py', '##'] )
confFile.SetServiceOption( sys.argv[2], "path", sys.argv[3] )
confFile.SetServiceOption( sys.argv[2], "comment", sys.argv[4] )
confFile.SetServiceOption( sys.argv[2], "read only", "no" )
ret = confFile.Flush()
sys.exit( ret )
|
gpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
18022,
199,
309,
199,
309,
221,
5870,
1050,
15,
1807,
15,
1461,
8663,
1414,
2884,
367,
428,
14310,
199,
309,
199,
309,
221,
1898,
334,
35,
9,
22261,
27075,
14243,
351,
1057,
755,
8353,
14,
199,
309,
199,
309,
221,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
309,
221,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
309,
221,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
309,
221,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
309,
199,
309,
221,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
309,
221,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
309,
221,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
309,
221,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
309,
199,
309,
221,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
309,
221,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
309,
221,
2752,
12,
3277,
2020,
1227,
2194,
603,
405,
437,
432,
12,
445,
455,
9528,
12,
4828,
12497,
7491,
12,
8217,
14,
199,
309,
199,
18022,
199,
199,
646,
984,
12,
747,
199,
504,
428,
14310,
2028,
492,
428,
14310,
8930,
421,
199,
309,
17907,
925,
199,
309,
1104,
314,
1414,
1004,
1249,
925,
199,
309,
17907,
925,
199,
1807,
63,
632,
275,
756,
199,
692,
822,
8,
1274,
14,
3020,
9,
508,
650,
26,
199,
198,
1807,
63,
632,
275,
715,
199,
198,
1361,
298,
22001,
8663,
11500,
199,
4164,
822,
8,
1274,
14,
3020,
9,
508,
959,
26,
199,
198,
1361,
298,
20897,
15,
24993,
8663,
11500,
199,
2836,
26,
199,
198,
1361,
298,
7692,
26,
450,
83,
1101,
493,
8663,
359,
515,
61,
359,
6223,
8480,
450,
984,
14,
3020,
59,
16,
61,
199,
198,
1274,
14,
2224,
8,
17,
9,
28550,
199,
309,
13293,
925,
199,
309,
1586,
436,
2198,
314,
1101,
570,
925,
199,
309,
13293,
925,
199,
199,
2190,
1173,
275,
428,
14310,
8930,
342,
199,
199,
2190,
1173,
14,
3284,
2028,
8,
984,
14,
3020,
59,
17,
61,
776,
199,
692,
440,
3743,
1173,
14,
1078,
26,
199,
198,
2224,
8,
413,
776,
507,
199,
692,
3145,
63,
632,
26,
199,
198,
692,
440,
3743,
1173,
14,
374,
3167,
8,
984,
14,
3020,
59,
18,
61,
3461,
507,
198,
1274,
14,
3083,
14,
952,
8,
298,
25525,
379,
370,
3145,
2222,
13,
15025,
2435,
1,
8978,
83,
7272,
78,
2,
450,
984,
14,
3020,
59,
18,
61,
776,
507,
198,
1274,
14,
2224,
8,
413,
776,
18118,
198,
2190,
1173,
14,
6994,
3167,
8,
984,
14,
3020,
59,
18,
61,
776,
199,
2836,
26,
199,
198,
309,
1852,
314,
931,
340,
652,
3181,
1133,
2187,
14,
221,
699,
1054,
734,
340,
626,
6918,
199,
198,
692,
334,
440,
747,
14,
515,
14,
6027,
8,
1274,
14,
3020,
59,
19,
566,
3461,
507,
198,
893,
26,
686,
198,
736,
14,
8347,
8,
984,
14,
3020,
59,
19,
61,
776,
686,
198,
736,
14,
11693,
8,
984,
14,
3020,
59,
19,
467,
378,
11956,
776,
507,
198,
2590,
747,
14,
705,
26,
686,
198,
1274,
14,
2224,
8,
413,
776,
421,
198,
309,
1454,
1050,
282,
892,
2435,
1553,
340,
652,
2575,
3495,
12,
2066,
9948,
198,
309,
2951,
663,
314,
1511,
199,
198,
692,
440,
3743,
1173,
14,
374,
3167,
8,
984,
14,
3020,
59,
18,
61,
3461,
507,
198,
2190,
1173,
14,
1123,
3167,
8,
984,
14,
3020,
59,
18,
467,
788,
309,
297,
283,
309,
16230,
701,
2811,
63,
21693,
63,
888,
14,
647,
297,
283,
309,
418,
221,
776,
199,
198,
2190,
1173,
14,
1084,
3167,
2602,
8,
984,
14,
3020,
59,
18,
467,
298,
515,
401,
984,
14,
3020,
59,
19,
61,
776,
199,
198,
2190,
1173,
14,
1084,
3167,
2602,
8,
984,
14,
3020,
59,
18,
467,
298,
3349,
401,
984,
14,
3020,
59,
20,
61,
776,
199,
198,
2190,
1173,
14,
1084,
3167,
2602,
8,
984,
14,
3020,
59,
18,
467,
298,
739,
1454,
401,
298,
889,
2,
776,
199,
199,
3292,
275,
3743,
1173,
14,
20053,
342,
199,
199,
1274,
14,
2224,
8,
2203,
776,
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
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
18022,
199,
309,
199,
309,
221,
5870,
1050,
15,
1807,
15,
1461,
8663,
1414,
2884,
367,
428,
14310,
199,
309,
199,
309,
221,
1898,
334,
35,
9,
22261,
27075,
14243,
351,
1057,
755,
8353,
14,
199,
309,
199,
309,
221,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
309,
221,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
309,
221,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
309,
221,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
309,
199,
309,
221,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
309,
221,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
309,
221,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
309,
221,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
309,
199,
309,
221,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
309,
221,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
309,
221,
2752,
12,
3277,
2020,
1227,
2194,
603,
405,
437,
432,
12,
445,
455,
9528,
12,
4828,
12497,
7491,
12,
8217,
14,
199,
309,
199,
18022,
199,
199,
646,
984,
12,
747,
199,
504,
428,
14310,
2028,
492,
428,
14310,
8930,
421,
199,
309,
17907,
925,
199,
309,
1104,
314,
1414,
1004,
1249,
925,
199,
309,
17907,
925,
199,
1807,
63,
632,
275,
756,
199,
692,
822,
8,
1274,
14,
3020,
9,
508,
650,
26,
199,
198,
1807,
63,
632,
275,
715,
199,
198,
1361,
298,
22001,
8663,
11500,
199,
4164,
822,
8,
1274,
14,
3020,
9,
508,
959,
26,
199,
198,
1361,
298,
20897,
15,
24993,
8663,
11500,
199,
2836,
26,
199,
198,
1361,
298,
7692,
26,
450,
83,
1101,
493,
8663,
359,
515,
61,
359,
6223,
8480,
450,
984,
14,
3020,
59,
16,
61,
199,
198,
1274,
14,
2224,
8,
17,
9,
28550,
199,
309,
13293,
925,
199,
309,
1586,
436,
2198,
314,
1101,
570,
925,
199,
309,
13293,
925,
199,
199,
2190,
1173,
275,
428,
14310,
8930,
342,
199,
199,
2190,
1173,
14,
3284,
2028,
8,
984,
14,
3020,
59,
17,
61,
776,
199,
692,
440,
3743,
1173,
14,
1078,
26,
199,
198,
2224,
8,
413,
776,
507,
199,
692,
3145,
63,
632,
26,
199,
198,
692,
440,
3743,
1173,
14,
374,
3167,
8,
984,
14,
3020,
59,
18,
61,
3461,
507,
198,
1274,
14,
3083,
14,
952,
8,
298,
25525,
379,
370,
3145,
2222,
13,
15025,
2435,
1,
8978,
83,
7272,
78,
2,
450,
984,
14,
3020,
59,
18,
61,
776,
507,
198,
1274,
14,
2224,
8,
413,
776,
18118,
198,
2190,
1173,
14,
6994,
3167,
8,
984,
14,
3020,
59,
18,
61,
776,
199,
2836,
26,
199,
198,
309,
1852,
314,
931,
340,
652,
3181,
1133,
2187,
14,
221,
699,
1054,
734,
340,
626,
6918,
199,
198,
692,
334,
440,
747,
14,
515,
14,
6027,
8,
1274,
14,
3020,
59,
19,
566,
3461,
507,
198,
893,
26,
686,
198,
736,
14,
8347,
8,
984,
14,
3020,
59,
19,
61,
776,
686,
198,
736,
14,
11693,
8,
984,
14,
3020,
59,
19,
467,
378,
11956,
776,
507,
198,
2590,
747,
14,
705,
26,
686,
198,
1274,
14,
2224,
8,
413,
776,
421,
198,
309,
1454,
1050,
282,
892,
2435,
1553,
340,
652,
2575,
3495,
12,
2066,
9948,
198,
309,
2951,
663,
314,
1511,
199,
198,
692,
440,
3743,
1173,
14,
374,
3167,
8,
984,
14,
3020,
59,
18,
61,
3461,
507,
198,
2190,
1173,
14,
1123,
3167,
8,
984,
14,
3020,
59,
18,
467,
788,
309,
297,
283,
309,
16230,
701,
2811,
63,
21693,
63,
888,
14,
647,
297,
283,
309,
418,
221,
776,
199,
198,
2190,
1173,
14,
1084,
3167,
2602,
8,
984,
14,
3020,
59,
18,
467,
298,
515,
401,
984,
14,
3020,
59,
19,
61,
776,
199,
198,
2190,
1173,
14,
1084,
3167,
2602,
8,
984,
14,
3020,
59,
18,
467,
298,
3349,
401,
984,
14,
3020,
59,
20,
61,
776,
199,
198,
2190,
1173,
14,
1084,
3167,
2602,
8,
984,
14,
3020,
59,
18,
467,
298,
739,
1454,
401,
298,
889,
2,
776,
199,
199,
3292,
275,
3743,
1173,
14,
20053,
342,
199,
199,
1274,
14,
2224,
8,
2203,
776,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
easytaxibr/kafka
|
system_test/system_test_runner.py
|
66
|
15030
|
# 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.
#!/usr/bin/evn python
# =================================================================
# system_test_runner.py
#
# - This script is the test driver for a distributed environment
# system testing framework. It is located at the top level of the
# framework hierachy (in this case - system_test/).
#
# - This test driver servers as an entry point to launch a series
# of test suites (module) with multiple functionally similar test
# cases which can be grouped together.
#
# - Please refer to system_test/README.txt for more details on
# how to add test suite and test case.
#
# - In most cases, it is not necessary to make any changes to this
# script.
# =================================================================
from optparse import OptionParser
from system_test_env import SystemTestEnv
from utils import system_test_utils
import logging.config
import os
import pprint
import sys
# load the config file for logging
logging.config.fileConfig('logging.conf')
# 'd' is an argument to be merged into the log message (see Python doc for logging).
# In this case, corresponding class name can be appended to the end of the logging
# message to facilitate debugging.
d = {'name_of_class': '(system_test_runner)'}
class report:
systemTestEnv = None
reportString = ""
reportFileName = "system_test_report.html"
systemTestReport = None
header = """<head>
<title>Kafka System Test Report</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
</head>"""
footer = """ """
def __init__(self, systemTestEnv):
self.totalSkipped = 0
self.totalPassed = 0
self.totalTests = 0
self.totalFailed = 0
self.systemTestEnv = systemTestEnv
self.systemTestReport = open(self.reportFileName, 'w')
def __del__(self):
self.systemTestReport.close()
self.systemTestReport = None
def writeHtmlPage(self, body):
html = """
<!DOCTYPE html>
<html lang="en">
"""
html += self.header
html += body
html += self.footer
html += """
</html>
"""
self.systemTestReport.write(html)
def wrapIn(self, tag, content):
html = "\n<" + tag + ">"
html += "\n " + content
html += "\n</" + tag.split(" ")[0] + ">"
return html
def genModal(self, className, caseName, systemTestResult):
key = "validation_status"
id = className + "_" + caseName
info = self.wrapIn("h4", "Validation Status")
for validatedItem in sorted(systemTestResult[key].iterkeys()):
testItemStatus = systemTestResult[key][validatedItem]
info += validatedItem + " : " + testItemStatus
return self.wrapIn("div class=\"modal fade\" id=\"" + id + "\" tabindex=\"-1\" role=\"dialog\" aria-labelledby=\"" + id + "Label\" aria-hidden=\"true\"",
self.wrapIn("div class=\"modal-dialog\"",
self.wrapIn("div class=\"modal-content\"",
self.wrapIn("div class=\"modal-header\"",
self.wrapIn("h4 class=\"modal-title\" id=\"" + id + "Label\"",
className + " - " + caseName)) +
self.wrapIn("div class=\"modal-body\"",
info) +
self.wrapIn("div class=\"modal-footer\"",
self.wrapIn("button type=\"button\" class=\"btn btn-default\" data-dismiss=\"modal\"", "Close")))))
def summarize(self):
testItemsTableHeader = self.wrapIn("thead",
self.wrapIn("tr",
self.wrapIn("th", "Test Class Name") +
self.wrapIn("th", "Test Case Name") +
self.wrapIn("th", "Validation Status")))
testItemsTableBody = ""
modals = ""
for systemTestResult in self.systemTestEnv.systemTestResultsList:
self.totalTests += 1
if "_test_class_name" in systemTestResult:
testClassName = systemTestResult["_test_class_name"]
else:
testClassName = ""
if "_test_case_name" in systemTestResult:
testCaseName = systemTestResult["_test_case_name"]
else:
testCaseName = ""
if "validation_status" in systemTestResult:
testItemStatus = "SKIPPED"
for key in systemTestResult["validation_status"].iterkeys():
testItemStatus = systemTestResult["validation_status"][key]
if "FAILED" == testItemStatus:
break;
if "FAILED" == testItemStatus:
self.totalFailed += 1
validationStatus = self.wrapIn("div class=\"text-danger\" data-toggle=\"modal\" data-target=\"#" + testClassName + "_" + testCaseName + "\"", "FAILED")
modals += self.genModal(testClassName, testCaseName, systemTestResult)
elif "PASSED" == testItemStatus:
self.totalPassed += 1
validationStatus = self.wrapIn("div class=\"text-success\"", "PASSED")
else:
self.totalSkipped += 1
validationStatus = self.wrapIn("div class=\"text-warning\"", "SKIPPED")
else:
self.reportString += "|"
testItemsTableBody += self.wrapIn("tr",
self.wrapIn("td", testClassName) +
self.wrapIn("td", testCaseName) +
self.wrapIn("td", validationStatus))
testItemsTableBody = self.wrapIn("tbody", testItemsTableBody)
testItemsTable = self.wrapIn("table class=\"table table-striped\"", testItemsTableHeader + testItemsTableBody)
statsTblBody = self.wrapIn("tr class=\"active\"", self.wrapIn("td", "Total tests") + self.wrapIn("td", str(self.totalTests)))
statsTblBody += self.wrapIn("tr class=\"success\"", self.wrapIn("td", "Total tests passed") + self.wrapIn("td", str(self.totalPassed)))
statsTblBody += self.wrapIn("tr class=\"danger\"", self.wrapIn("td", "Total tests failed") + self.wrapIn("td", str(self.totalFailed)))
statsTblBody += self.wrapIn("tr class=\"warning\"", self.wrapIn("td", "Total tests skipped") + self.wrapIn("td", str(self.totalSkipped)))
testStatsTable = self.wrapIn("table class=\"table\"", statsTblBody)
body = self.wrapIn("div class=\"container\"",
self.wrapIn("h2", "Kafka System Test Report") +
self.wrapIn("div class=\"row\"", self.wrapIn("div class=\"col-md-4\"", testStatsTable)) +
self.wrapIn("div class=\"row\"", self.wrapIn("div class=\"col-md-6\"", testItemsTable)) +
modals)
self.writeHtmlPage(self.wrapIn("body", body))
def main():
nLogger = logging.getLogger('namedLogger')
aLogger = logging.getLogger('anonymousLogger')
optionParser = OptionParser()
optionParser.add_option("-p", "--print-test-descriptions-only",
dest="printTestDescriptionsOnly",
default=False,
action="store_true",
help="print test descriptions only - don't run the test")
optionParser.add_option("-n", "--do-not-validate-remote-host",
dest="doNotValidateRemoteHost",
default=False,
action="store_true",
help="do not validate remote host (due to different kafka versions are installed)")
(options, args) = optionParser.parse_args()
print "\n"
aLogger.info("=================================================")
aLogger.info(" System Regression Test Framework")
aLogger.info("=================================================")
print "\n"
testSuiteClassDictList = []
# SystemTestEnv is a class to provide all environement settings for this session
# such as the SYSTEM_TEST_BASE_DIR, SYSTEM_TEST_UTIL_DIR, ...
systemTestEnv = SystemTestEnv()
if options.printTestDescriptionsOnly:
systemTestEnv.printTestDescriptionsOnly = True
if options.doNotValidateRemoteHost:
systemTestEnv.doNotValidateRemoteHost = True
if not systemTestEnv.printTestDescriptionsOnly:
if not systemTestEnv.doNotValidateRemoteHost:
if not system_test_utils.setup_remote_hosts(systemTestEnv):
nLogger.error("Remote hosts sanity check failed. Aborting test ...", extra=d)
print
sys.exit(1)
else:
nLogger.info("SKIPPING : checking remote machines", extra=d)
print
# get all defined names within a module:
definedItemList = dir(SystemTestEnv)
aLogger.debug("=================================================")
aLogger.debug("SystemTestEnv keys:")
for item in definedItemList:
aLogger.debug(" " + item)
aLogger.debug("=================================================")
aLogger.info("=================================================")
aLogger.info("looking up test suites ...")
aLogger.info("=================================================")
# find all test suites in SYSTEM_TEST_BASE_DIR
for dirName in os.listdir(systemTestEnv.SYSTEM_TEST_BASE_DIR):
# make sure this is a valid testsuite directory
if os.path.isdir(dirName) and dirName.endswith(systemTestEnv.SYSTEM_TEST_SUITE_SUFFIX):
print
nLogger.info("found a testsuite : " + dirName, extra=d)
testModulePathName = os.path.abspath(systemTestEnv.SYSTEM_TEST_BASE_DIR + "/" + dirName)
if not systemTestEnv.printTestDescriptionsOnly:
system_test_utils.setup_remote_hosts_with_testsuite_level_cluster_config(systemTestEnv, testModulePathName)
# go through all test modules file in this testsuite
for moduleFileName in os.listdir(testModulePathName):
# make sure it is a valid test module
if moduleFileName.endswith(systemTestEnv.SYSTEM_TEST_MODULE_EXT) \
and not moduleFileName.startswith("__"):
# found a test module file
nLogger.info("found a test module file : " + moduleFileName, extra=d)
testModuleClassName = system_test_utils.sys_call("grep ^class " + testModulePathName + "/" + \
moduleFileName + " | sed 's/^class //g' | sed 's/(.*):.*//g'")
testModuleClassName = testModuleClassName.rstrip('\n')
# collect the test suite class data
testSuiteClassDict = {}
testSuiteClassDict["suite"] = dirName
extLenToRemove = systemTestEnv.SYSTEM_TEST_MODULE_EXT.__len__() * -1
testSuiteClassDict["module"] = moduleFileName[:extLenToRemove]
testSuiteClassDict["class"] = testModuleClassName
testSuiteClassDictList.append(testSuiteClassDict)
suiteName = testSuiteClassDict["suite"]
moduleName = testSuiteClassDict["module"]
className = testSuiteClassDict["class"]
# add testsuite directory to sys.path such that the module can be loaded
sys.path.append(systemTestEnv.SYSTEM_TEST_BASE_DIR + "/" + suiteName)
if not systemTestEnv.printTestDescriptionsOnly:
aLogger.info("=================================================")
aLogger.info("Running Test for : ")
aLogger.info(" suite : " + suiteName)
aLogger.info(" module : " + moduleName)
aLogger.info(" class : " + className)
aLogger.info("=================================================")
# dynamically loading a module and starting the test class
mod = __import__(moduleName)
theClass = getattr(mod, className)
instance = theClass(systemTestEnv)
instance.runTest()
print
report(systemTestEnv).summarize()
if not systemTestEnv.printTestDescriptionsOnly:
totalFailureCount = 0
print
print "========================================================"
print " TEST REPORTS"
print "========================================================"
for systemTestResult in systemTestEnv.systemTestResultsList:
for key in sorted(systemTestResult.iterkeys()):
if key == "validation_status":
print key, " : "
testItemStatus = None
for validatedItem in sorted(systemTestResult[key].iterkeys()):
testItemStatus = systemTestResult[key][validatedItem]
print " ", validatedItem, " : ", testItemStatus
if "FAILED" == testItemStatus:
totalFailureCount += 1
else:
print key, " : ", systemTestResult[key]
print
print "========================================================"
print
print "========================================================"
print "Total failures count : " + str(totalFailureCount)
print "========================================================"
print
return totalFailureCount
return -1
# =========================
# main entry point
# =========================
sys.exit(main())
|
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,
3381,
2647,
15,
1393,
15,
69,
6002,
2366,
199,
199,
3,
7819,
199,
3,
2656,
63,
396,
63,
5933,
14,
647,
199,
3,
199,
3,
446,
961,
2884,
365,
314,
511,
5253,
367,
282,
1854,
3734,
199,
3,
257,
2656,
5343,
10059,
14,
2779,
365,
16180,
737,
314,
2746,
2166,
402,
314,
199,
3,
257,
10059,
394,
4446,
1225,
89,
334,
262,
642,
1930,
446,
2656,
63,
396,
15,
680,
199,
3,
199,
3,
446,
961,
511,
5253,
8037,
465,
376,
2397,
2376,
370,
10623,
282,
6779,
199,
3,
257,
402,
511,
24203,
334,
578,
9,
543,
3663,
805,
1183,
8545,
511,
199,
3,
257,
5560,
1314,
883,
506,
16251,
10451,
14,
199,
3,
199,
3,
446,
7754,
10618,
370,
2656,
63,
396,
15,
18195,
14,
2424,
367,
1655,
2436,
641,
199,
3,
257,
4212,
370,
1050,
511,
5241,
436,
511,
1930,
14,
199,
3,
199,
3,
446,
1010,
4750,
5560,
12,
652,
365,
440,
5784,
370,
1852,
1263,
4493,
370,
642,
199,
3,
257,
2884,
14,
199,
3,
7819,
199,
199,
504,
8691,
263,
492,
13491,
199,
504,
2656,
63,
396,
63,
1813,
492,
6187,
774,
7744,
199,
504,
3778,
3698,
492,
2656,
63,
396,
63,
1208,
199,
199,
646,
2050,
14,
888,
199,
646,
747,
199,
646,
10933,
199,
646,
984,
421,
199,
3,
2248,
314,
1101,
570,
367,
2050,
199,
4806,
14,
888,
14,
493,
2028,
360,
4806,
14,
2190,
358,
199,
199,
3,
283,
68,
7,
365,
376,
1423,
370,
506,
9545,
1901,
314,
943,
1245,
334,
3239,
2018,
1382,
367,
2050,
680,
199,
3,
1010,
642,
1930,
12,
5226,
1021,
536,
883,
506,
11544,
370,
314,
1284,
402,
314,
2050,
199,
3,
1245,
370,
30242,
1051,
323,
10201,
14,
199,
68,
275,
791,
354,
63,
1618,
63,
533,
356,
8189,
2253,
63,
396,
63,
5933,
9,
936,
199,
199,
533,
3622,
26,
523,
2656,
774,
7744,
275,
488,
523,
3622,
1558,
275,
3087,
523,
3622,
7733,
275,
298,
2253,
63,
396,
63,
3070,
14,
1360,
2,
523,
2656,
774,
7457,
275,
488,
523,
1406,
275,
8894,
2993,
30,
523,
665,
1213,
30,
43,
15294,
6187,
1379,
11774,
1108,
1213,
30,
523,
665,
2024,
5960,
628,
1624,
13,
24,
1743,
523,
665,
2024,
536,
628,
25484,
2,
1564,
628,
2063,
29,
1782,
13,
2063,
12,
2536,
13,
3467,
29,
17,
1743,
523,
665,
1073,
4668,
628,
15479,
2,
4369,
628,
1014,
921,
988,
23982,
14,
11146,
23982,
14,
957,
15,
11146,
15,
19,
14,
18,
14,
16,
15,
3919,
15,
11146,
14,
827,
14,
3919,
1743,
523,
665,
1579,
2928,
628,
2859,
921,
12774,
14,
17533,
14,
957,
15,
12774,
15,
8450,
15,
22324,
15,
17,
14,
845,
14,
18,
15,
22324,
14,
827,
14,
3596,
10070,
1579,
30,
523,
665,
1579,
2928,
628,
1014,
921,
988,
23982,
14,
11146,
23982,
14,
957,
15,
11146,
15,
19,
14,
19,
14,
18,
15,
3596,
15,
11146,
14,
827,
14,
3596,
10070,
1579,
30,
523,
3068,
2993,
11193,
523,
14178,
275,
408,
408,
819,
347,
636,
826,
721,
277,
12,
2656,
774,
7744,
304,
272,
291,
14,
2923,
30472,
275,
378,
272,
291,
14,
2923,
48,
2744,
275,
378,
272,
291,
14,
2923,
2925,
275,
378,
272,
291,
14,
2923,
4276,
275,
378,
272,
291,
14,
2253,
774,
7744,
275,
2656,
774,
7744,
272,
291,
14,
2253,
774,
7457,
275,
1551,
8,
277,
14,
3070,
7733,
12,
283,
87,
358,
819,
347,
636,
2264,
721,
277,
304,
272,
291,
14,
2253,
774,
7457,
14,
1600,
342,
272,
291,
14,
2253,
774,
7457,
275,
488,
819,
347,
2218,
12957,
3276,
8,
277,
12,
2396,
304,
272,
3517,
275,
408,
272,
31513,
16556,
3517,
30,
272,
665,
1360,
6339,
628,
287,
1743,
272,
408,
272,
3517,
847,
291,
14,
1291,
272,
3517,
847,
2396,
272,
3517,
847,
291,
14,
12781,
272,
3517,
847,
408,
272,
3068,
1360,
30,
272,
408,
272,
291,
14,
2253,
774,
7457,
14,
952,
8,
1360,
9,
819,
347,
4816,
607,
8,
277,
12,
1947,
12,
1564,
304,
272,
3517,
275,
1867,
78,
28,
2,
435,
1947,
435,
28192,
272,
3517,
847,
1867,
78,
221,
298,
435,
1564,
272,
3517,
847,
1867,
78,
1108,
2,
435,
1947,
14,
1294,
480,
298,
2788,
16,
61,
435,
28192,
272,
372,
3517,
819,
347,
3805,
23689,
8,
277,
12,
1021,
985,
12,
1930,
985,
12,
2656,
13120,
304,
272,
790,
275,
298,
6136,
63,
1205,
2,
272,
1305,
275,
1021,
985,
435,
14220,
435,
1930,
985,
272,
2256,
275,
291,
14,
3823,
607,
480,
72,
20,
401,
298,
13816,
9795,
531,
272,
367,
16468,
2081,
315,
3355,
8,
2253,
13120,
59,
498,
1055,
16007,
5109,
489,
511,
2081,
3694,
275,
2656,
13120,
59,
498,
1527,
24372,
2081,
61,
489,
2256,
847,
16468,
2081,
435,
298,
520,
298,
435,
511,
2081,
3694,
272,
372,
291,
14,
3823,
607,
480,
3015,
1021,
8178,
17713,
1433,
271,
4451,
1305,
9529,
341,
435,
1305,
435,
30768,
5174,
1080,
8178,
13,
17,
4451,
4719,
8178,
7196,
4451,
14554,
65,
13,
1302,
274,
28332,
9529,
341,
435,
1305,
435,
298,
4314,
4451,
14554,
65,
13,
5642,
8178,
2052
] |
[
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,
3381,
2647,
15,
1393,
15,
69,
6002,
2366,
199,
199,
3,
7819,
199,
3,
2656,
63,
396,
63,
5933,
14,
647,
199,
3,
199,
3,
446,
961,
2884,
365,
314,
511,
5253,
367,
282,
1854,
3734,
199,
3,
257,
2656,
5343,
10059,
14,
2779,
365,
16180,
737,
314,
2746,
2166,
402,
314,
199,
3,
257,
10059,
394,
4446,
1225,
89,
334,
262,
642,
1930,
446,
2656,
63,
396,
15,
680,
199,
3,
199,
3,
446,
961,
511,
5253,
8037,
465,
376,
2397,
2376,
370,
10623,
282,
6779,
199,
3,
257,
402,
511,
24203,
334,
578,
9,
543,
3663,
805,
1183,
8545,
511,
199,
3,
257,
5560,
1314,
883,
506,
16251,
10451,
14,
199,
3,
199,
3,
446,
7754,
10618,
370,
2656,
63,
396,
15,
18195,
14,
2424,
367,
1655,
2436,
641,
199,
3,
257,
4212,
370,
1050,
511,
5241,
436,
511,
1930,
14,
199,
3,
199,
3,
446,
1010,
4750,
5560,
12,
652,
365,
440,
5784,
370,
1852,
1263,
4493,
370,
642,
199,
3,
257,
2884,
14,
199,
3,
7819,
199,
199,
504,
8691,
263,
492,
13491,
199,
504,
2656,
63,
396,
63,
1813,
492,
6187,
774,
7744,
199,
504,
3778,
3698,
492,
2656,
63,
396,
63,
1208,
199,
199,
646,
2050,
14,
888,
199,
646,
747,
199,
646,
10933,
199,
646,
984,
421,
199,
3,
2248,
314,
1101,
570,
367,
2050,
199,
4806,
14,
888,
14,
493,
2028,
360,
4806,
14,
2190,
358,
199,
199,
3,
283,
68,
7,
365,
376,
1423,
370,
506,
9545,
1901,
314,
943,
1245,
334,
3239,
2018,
1382,
367,
2050,
680,
199,
3,
1010,
642,
1930,
12,
5226,
1021,
536,
883,
506,
11544,
370,
314,
1284,
402,
314,
2050,
199,
3,
1245,
370,
30242,
1051,
323,
10201,
14,
199,
68,
275,
791,
354,
63,
1618,
63,
533,
356,
8189,
2253,
63,
396,
63,
5933,
9,
936,
199,
199,
533,
3622,
26,
523,
2656,
774,
7744,
275,
488,
523,
3622,
1558,
275,
3087,
523,
3622,
7733,
275,
298,
2253,
63,
396,
63,
3070,
14,
1360,
2,
523,
2656,
774,
7457,
275,
488,
523,
1406,
275,
8894,
2993,
30,
523,
665,
1213,
30,
43,
15294,
6187,
1379,
11774,
1108,
1213,
30,
523,
665,
2024,
5960,
628,
1624,
13,
24,
1743,
523,
665,
2024,
536,
628,
25484,
2,
1564,
628,
2063,
29,
1782,
13,
2063,
12,
2536,
13,
3467,
29,
17,
1743,
523,
665,
1073,
4668,
628,
15479,
2,
4369,
628,
1014,
921,
988,
23982,
14,
11146,
23982,
14,
957,
15,
11146,
15,
19,
14,
18,
14,
16,
15,
3919,
15,
11146,
14,
827,
14,
3919,
1743,
523,
665,
1579,
2928,
628,
2859,
921,
12774,
14,
17533,
14,
957,
15,
12774,
15,
8450,
15,
22324,
15,
17,
14,
845,
14,
18,
15,
22324,
14,
827,
14,
3596,
10070,
1579,
30,
523,
665,
1579,
2928,
628,
1014,
921,
988,
23982,
14,
11146,
23982,
14,
957,
15,
11146,
15,
19,
14,
19,
14,
18,
15,
3596,
15,
11146,
14,
827,
14,
3596,
10070,
1579,
30,
523,
3068,
2993,
11193,
523,
14178,
275,
408,
408,
819,
347,
636,
826,
721,
277,
12,
2656,
774,
7744,
304,
272,
291,
14,
2923,
30472,
275,
378,
272,
291,
14,
2923,
48,
2744,
275,
378,
272,
291,
14,
2923,
2925,
275,
378,
272,
291,
14,
2923,
4276,
275,
378,
272,
291,
14,
2253,
774,
7744,
275,
2656,
774,
7744,
272,
291,
14,
2253,
774,
7457,
275,
1551,
8,
277,
14,
3070,
7733,
12,
283,
87,
358,
819,
347,
636,
2264,
721,
277,
304,
272,
291,
14,
2253,
774,
7457,
14,
1600,
342,
272,
291,
14,
2253,
774,
7457,
275,
488,
819,
347,
2218,
12957,
3276,
8,
277,
12,
2396,
304,
272,
3517,
275,
408,
272,
31513,
16556,
3517,
30,
272,
665,
1360,
6339,
628,
287,
1743,
272,
408,
272,
3517,
847,
291,
14,
1291,
272,
3517,
847,
2396,
272,
3517,
847,
291,
14,
12781,
272,
3517,
847,
408,
272,
3068,
1360,
30,
272,
408,
272,
291,
14,
2253,
774,
7457,
14,
952,
8,
1360,
9,
819,
347,
4816,
607,
8,
277,
12,
1947,
12,
1564,
304,
272,
3517,
275,
1867,
78,
28,
2,
435,
1947,
435,
28192,
272,
3517,
847,
1867,
78,
221,
298,
435,
1564,
272,
3517,
847,
1867,
78,
1108,
2,
435,
1947,
14,
1294,
480,
298,
2788,
16,
61,
435,
28192,
272,
372,
3517,
819,
347,
3805,
23689,
8,
277,
12,
1021,
985,
12,
1930,
985,
12,
2656,
13120,
304,
272,
790,
275,
298,
6136,
63,
1205,
2,
272,
1305,
275,
1021,
985,
435,
14220,
435,
1930,
985,
272,
2256,
275,
291,
14,
3823,
607,
480,
72,
20,
401,
298,
13816,
9795,
531,
272,
367,
16468,
2081,
315,
3355,
8,
2253,
13120,
59,
498,
1055,
16007,
5109,
489,
511,
2081,
3694,
275,
2656,
13120,
59,
498,
1527,
24372,
2081,
61,
489,
2256,
847,
16468,
2081,
435,
298,
520,
298,
435,
511,
2081,
3694,
272,
372,
291,
14,
3823,
607,
480,
3015,
1021,
8178,
17713,
1433,
271,
4451,
1305,
9529,
341,
435,
1305,
435,
30768,
5174,
1080,
8178,
13,
17,
4451,
4719,
8178,
7196,
4451,
14554,
65,
13,
1302,
274,
28332,
9529,
341,
435,
1305,
435,
298,
4314,
4451,
14554,
65,
13,
5642,
8178,
2052,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
sahiljain/catapult
|
third_party/gsutil/third_party/rsa/tests/test_common.py
|
34
|
2280
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import unittest2
import struct
from rsa._compat import byte, b
from rsa.common import byte_size, bit_size, _bit_size
class Test_byte(unittest2.TestCase):
def test_values(self):
self.assertEqual(byte(0), b('\x00'))
self.assertEqual(byte(255), b('\xff'))
def test_struct_error_when_out_of_bounds(self):
self.assertRaises(struct.error, byte, 256)
self.assertRaises(struct.error, byte, -1)
class Test_byte_size(unittest2.TestCase):
def test_values(self):
self.assertEqual(byte_size(1 << 1023), 128)
self.assertEqual(byte_size((1 << 1024) - 1), 128)
self.assertEqual(byte_size(1 << 1024), 129)
self.assertEqual(byte_size(255), 1)
self.assertEqual(byte_size(256), 2)
self.assertEqual(byte_size(0xffff), 2)
self.assertEqual(byte_size(0xffffff), 3)
self.assertEqual(byte_size(0xffffffff), 4)
self.assertEqual(byte_size(0xffffffffff), 5)
self.assertEqual(byte_size(0xffffffffffff), 6)
self.assertEqual(byte_size(0xffffffffffffff), 7)
self.assertEqual(byte_size(0xffffffffffffffff), 8)
def test_zero(self):
self.assertEqual(byte_size(0), 1)
def test_bad_type(self):
self.assertRaises(TypeError, byte_size, [])
self.assertRaises(TypeError, byte_size, ())
self.assertRaises(TypeError, byte_size, dict())
self.assertRaises(TypeError, byte_size, "")
self.assertRaises(TypeError, byte_size, None)
class Test_bit_size(unittest2.TestCase):
def test_zero(self):
self.assertEqual(bit_size(0), 0)
def test_values(self):
self.assertEqual(bit_size(1023), 10)
self.assertEqual(bit_size(1024), 11)
self.assertEqual(bit_size(1025), 11)
self.assertEqual(bit_size(1 << 1024), 1025)
self.assertEqual(bit_size((1 << 1024) + 1), 1025)
self.assertEqual(bit_size((1 << 1024) - 1), 1024)
self.assertEqual(_bit_size(1023), 10)
self.assertEqual(_bit_size(1024), 11)
self.assertEqual(_bit_size(1025), 11)
self.assertEqual(_bit_size(1 << 1024), 1025)
self.assertEqual(_bit_size((1 << 1024) + 1), 1025)
self.assertEqual(_bit_size((1 << 1024) - 1), 1024)
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
646,
2882,
18,
199,
646,
2702,
199,
504,
23609,
423,
5819,
492,
3696,
12,
330,
199,
504,
23609,
14,
2330,
492,
3696,
63,
890,
12,
4546,
63,
890,
12,
485,
2075,
63,
890,
421,
199,
533,
1379,
63,
4414,
8,
2796,
18,
14,
1746,
304,
272,
347,
511,
63,
1459,
8,
277,
304,
267,
291,
14,
629,
8,
4414,
8,
16,
395,
330,
2258,
88,
383,
1333,
267,
291,
14,
629,
8,
4414,
8,
2299,
395,
330,
2258,
3581,
1333,
339,
347,
511,
63,
1820,
63,
705,
63,
6526,
63,
548,
63,
1618,
63,
9632,
8,
277,
304,
267,
291,
14,
1855,
8,
1820,
14,
705,
12,
3696,
12,
7633,
9,
267,
291,
14,
1855,
8,
1820,
14,
705,
12,
3696,
12,
446,
17,
9,
199,
199,
533,
1379,
63,
4414,
63,
890,
8,
2796,
18,
14,
1746,
304,
272,
347,
511,
63,
1459,
8,
277,
304,
267,
291,
14,
629,
8,
4414,
63,
890,
8,
17,
5213,
12996,
19,
395,
7960,
9,
267,
291,
14,
629,
8,
4414,
63,
890,
1332,
17,
5213,
6619,
9,
446,
413,
395,
7960,
9,
267,
291,
14,
629,
8,
4414,
63,
890,
8,
17,
5213,
6619,
395,
25454,
9,
267,
291,
14,
629,
8,
4414,
63,
890,
8,
2299,
395,
413,
9,
267,
291,
14,
629,
8,
4414,
63,
890,
8,
3912,
395,
499,
9,
267,
291,
14,
629,
8,
4414,
63,
890,
8,
16,
27581,
395,
499,
9,
267,
291,
14,
629,
8,
4414,
63,
890,
8,
16,
3581,
4717,
395,
650,
9,
267,
291,
14,
629,
8,
4414,
63,
890,
8,
16,
21870,
395,
841,
9,
267,
291,
14,
629,
8,
4414,
63,
890,
8,
16,
3581,
15798,
395,
959,
9,
267,
291,
14,
629,
8,
4414,
63,
890,
8,
16,
3581,
4717,
12596,
395,
1227,
9,
267,
291,
14,
629,
8,
4414,
63,
890,
8,
16,
3581,
15798,
4717,
395,
1520,
9,
267,
291,
14,
629,
8,
4414,
63,
890,
8,
16,
3581,
15798,
12596,
395,
1695,
9,
339,
347,
511,
63,
4262,
8,
277,
304,
267,
291,
14,
629,
8,
4414,
63,
890,
8,
16,
395,
413,
9,
339,
347,
511,
63,
4087,
63,
466,
8,
277,
304,
267,
291,
14,
1855,
8,
4333,
12,
3696,
63,
890,
12,
3073,
267,
291,
14,
1855,
8,
4333,
12,
3696,
63,
890,
12,
14515,
267,
291,
14,
1855,
8,
4333,
12,
3696,
63,
890,
12,
1211,
1012,
267,
291,
14,
1855,
8,
4333,
12,
3696,
63,
890,
12,
6899,
267,
291,
14,
1855,
8,
4333,
12,
3696,
63,
890,
12,
488,
9,
199,
199,
533,
1379,
63,
2075,
63,
890,
8,
2796,
18,
14,
1746,
304,
272,
347,
511,
63,
4262,
8,
277,
304,
267,
291,
14,
629,
8,
2075,
63,
890,
8,
16,
395,
378,
9,
339,
347,
511,
63,
1459,
8,
277,
304,
267,
291,
14,
629,
8,
2075,
63,
890,
8,
31923,
395,
1616,
9,
267,
291,
14,
629,
8,
2075,
63,
890,
8,
7727,
395,
4119,
9,
267,
291,
14,
629,
8,
2075,
63,
890,
8,
32105,
395,
4119,
9,
267,
291,
14,
629,
8,
2075,
63,
890,
8,
17,
5213,
6619,
395,
1616,
821,
9,
267,
291,
14,
629,
8,
2075,
63,
890,
1332,
17,
5213,
6619,
9,
435,
413,
395,
1616,
821,
9,
267,
291,
14,
629,
8,
2075,
63,
890,
1332,
17,
5213,
6619,
9,
446,
413,
395,
6619,
9,
398,
291,
14,
629,
1547,
2075,
63,
890,
8,
31923,
395,
1616,
9,
267,
291,
14,
629,
1547,
2075,
63,
890,
8,
7727,
395,
4119,
9,
267,
291,
14,
629,
1547,
2075,
63,
890,
8,
32105,
395,
4119,
9,
267,
291,
14,
629,
1547,
2075,
63,
890,
8,
17,
5213,
6619,
395,
1616,
821,
9,
267,
291,
14,
629,
1547,
2075,
63,
890,
1332,
17,
5213,
6619,
9,
435,
413,
395,
1616,
821,
9,
267,
291,
14,
629,
1547,
2075,
63,
890,
1332,
17,
5213,
6619,
9,
446,
413,
395,
6619,
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
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
646,
2882,
18,
199,
646,
2702,
199,
504,
23609,
423,
5819,
492,
3696,
12,
330,
199,
504,
23609,
14,
2330,
492,
3696,
63,
890,
12,
4546,
63,
890,
12,
485,
2075,
63,
890,
421,
199,
533,
1379,
63,
4414,
8,
2796,
18,
14,
1746,
304,
272,
347,
511,
63,
1459,
8,
277,
304,
267,
291,
14,
629,
8,
4414,
8,
16,
395,
330,
2258,
88,
383,
1333,
267,
291,
14,
629,
8,
4414,
8,
2299,
395,
330,
2258,
3581,
1333,
339,
347,
511,
63,
1820,
63,
705,
63,
6526,
63,
548,
63,
1618,
63,
9632,
8,
277,
304,
267,
291,
14,
1855,
8,
1820,
14,
705,
12,
3696,
12,
7633,
9,
267,
291,
14,
1855,
8,
1820,
14,
705,
12,
3696,
12,
446,
17,
9,
199,
199,
533,
1379,
63,
4414,
63,
890,
8,
2796,
18,
14,
1746,
304,
272,
347,
511,
63,
1459,
8,
277,
304,
267,
291,
14,
629,
8,
4414,
63,
890,
8,
17,
5213,
12996,
19,
395,
7960,
9,
267,
291,
14,
629,
8,
4414,
63,
890,
1332,
17,
5213,
6619,
9,
446,
413,
395,
7960,
9,
267,
291,
14,
629,
8,
4414,
63,
890,
8,
17,
5213,
6619,
395,
25454,
9,
267,
291,
14,
629,
8,
4414,
63,
890,
8,
2299,
395,
413,
9,
267,
291,
14,
629,
8,
4414,
63,
890,
8,
3912,
395,
499,
9,
267,
291,
14,
629,
8,
4414,
63,
890,
8,
16,
27581,
395,
499,
9,
267,
291,
14,
629,
8,
4414,
63,
890,
8,
16,
3581,
4717,
395,
650,
9,
267,
291,
14,
629,
8,
4414,
63,
890,
8,
16,
21870,
395,
841,
9,
267,
291,
14,
629,
8,
4414,
63,
890,
8,
16,
3581,
15798,
395,
959,
9,
267,
291,
14,
629,
8,
4414,
63,
890,
8,
16,
3581,
4717,
12596,
395,
1227,
9,
267,
291,
14,
629,
8,
4414,
63,
890,
8,
16,
3581,
15798,
4717,
395,
1520,
9,
267,
291,
14,
629,
8,
4414,
63,
890,
8,
16,
3581,
15798,
12596,
395,
1695,
9,
339,
347,
511,
63,
4262,
8,
277,
304,
267,
291,
14,
629,
8,
4414,
63,
890,
8,
16,
395,
413,
9,
339,
347,
511,
63,
4087,
63,
466,
8,
277,
304,
267,
291,
14,
1855,
8,
4333,
12,
3696,
63,
890,
12,
3073,
267,
291,
14,
1855,
8,
4333,
12,
3696,
63,
890,
12,
14515,
267,
291,
14,
1855,
8,
4333,
12,
3696,
63,
890,
12,
1211,
1012,
267,
291,
14,
1855,
8,
4333,
12,
3696,
63,
890,
12,
6899,
267,
291,
14,
1855,
8,
4333,
12,
3696,
63,
890,
12,
488,
9,
199,
199,
533,
1379,
63,
2075,
63,
890,
8,
2796,
18,
14,
1746,
304,
272,
347,
511,
63,
4262,
8,
277,
304,
267,
291,
14,
629,
8,
2075,
63,
890,
8,
16,
395,
378,
9,
339,
347,
511,
63,
1459,
8,
277,
304,
267,
291,
14,
629,
8,
2075,
63,
890,
8,
31923,
395,
1616,
9,
267,
291,
14,
629,
8,
2075,
63,
890,
8,
7727,
395,
4119,
9,
267,
291,
14,
629,
8,
2075,
63,
890,
8,
32105,
395,
4119,
9,
267,
291,
14,
629,
8,
2075,
63,
890,
8,
17,
5213,
6619,
395,
1616,
821,
9,
267,
291,
14,
629,
8,
2075,
63,
890,
1332,
17,
5213,
6619,
9,
435,
413,
395,
1616,
821,
9,
267,
291,
14,
629,
8,
2075,
63,
890,
1332,
17,
5213,
6619,
9,
446,
413,
395,
6619,
9,
398,
291,
14,
629,
1547,
2075,
63,
890,
8,
31923,
395,
1616,
9,
267,
291,
14,
629,
1547,
2075,
63,
890,
8,
7727,
395,
4119,
9,
267,
291,
14,
629,
1547,
2075,
63,
890,
8,
32105,
395,
4119,
9,
267,
291,
14,
629,
1547,
2075,
63,
890,
8,
17,
5213,
6619,
395,
1616,
821,
9,
267,
291,
14,
629,
1547,
2075,
63,
890,
1332,
17,
5213,
6619,
9,
435,
413,
395,
1616,
821,
9,
267,
291,
14,
629,
1547,
2075,
63,
890,
1332,
17,
5213,
6619,
9,
446,
413,
395,
6619,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
avidas/festive.ly
|
festively/views.py
|
1
|
1213
|
from flask import Blueprint, render_template, jsonify, request, send_from_directory, redirect, url_for
import os
festivals = Blueprint('festivals', __name__, template_folder='templates')
@festivals.route('/')
def index():
return render_template('index.html')
@festivals.route('/search-results')
def featured():
return render_template('search_results.html')
"""
@festivals.route('/api/v1.0/festivals', methods=['GET'])
def get_festivals():
longitude = float(request.args.get('longitude', ''))
latitude = float(request.args.get('latitude', ''))
# Only get events with approved status within 50 km of location and cap at
# fifty results
festivals = FestivalEntry.objects(location__near=[
longitude, latitude], location__max_distance=50000)[:50]
return jsonify({'festivals': festivals})
"""
@festivals.route('/icon.ico')
def favicon():
return send_from_directory(os.path.join(foodtrucks.root_path, 'static', 'images'),
'icon.ico', mimetype='image/x-icon')
# Redirect to home for any other route
@festivals.app_errorhandler(404)
def page_not_found(error):
return redirect(url_for("festivals.index"), code=302)
|
mit
|
[
504,
7209,
492,
22447,
1361,
12,
3795,
63,
1160,
12,
23819,
12,
1056,
12,
3222,
63,
504,
63,
3619,
12,
4660,
12,
1166,
63,
509,
199,
646,
747,
199,
199,
70,
597,
73,
3643,
275,
22447,
1361,
360,
70,
597,
73,
3643,
297,
636,
354,
3108,
1978,
63,
3741,
534,
5876,
358,
199,
199,
32,
70,
597,
73,
3643,
14,
4449,
7825,
199,
318,
1478,
837,
272,
372,
3795,
63,
1160,
360,
1080,
14,
1360,
358,
199,
199,
32,
70,
597,
73,
3643,
14,
4449,
2336,
1733,
13,
2604,
358,
199,
318,
13953,
3297,
837,
272,
372,
3795,
63,
1160,
360,
1733,
63,
2604,
14,
1360,
358,
199,
199,
624,
199,
32,
70,
597,
73,
3643,
14,
4449,
2336,
1246,
15,
86,
17,
14,
16,
15,
70,
597,
73,
3643,
297,
3102,
2968,
2970,
1105,
199,
318,
664,
63,
70,
597,
73,
3643,
837,
272,
18154,
275,
2069,
8,
1069,
14,
589,
14,
362,
360,
13803,
297,
12381,
272,
18896,
275,
2069,
8,
1069,
14,
589,
14,
362,
360,
13331,
297,
12381,
272,
327,
5972,
664,
4474,
543,
30055,
2004,
4453,
5238,
16155,
402,
2909,
436,
4021,
737,
272,
327,
289,
692,
369,
2058,
272,
289,
597,
73,
3643,
275,
481,
597,
29156,
3900,
14,
1462,
8,
1985,
363,
21078,
1524,
3044,
18154,
12,
18896,
467,
2909,
363,
988,
63,
5590,
29,
21,
993,
18562,
1400,
61,
272,
372,
23819,
3252,
70,
597,
73,
3643,
356,
289,
597,
73,
3643,
1552,
199,
624,
199,
199,
32,
70,
597,
73,
3643,
14,
4449,
2336,
4677,
14,
12802,
358,
199,
318,
29139,
837,
272,
372,
3222,
63,
504,
63,
3619,
8,
736,
14,
515,
14,
904,
8,
22120,
454,
85,
5618,
14,
1231,
63,
515,
12,
283,
1986,
297,
283,
4782,
659,
3044,
283,
4677,
14,
12802,
297,
12200,
534,
1569,
15,
88,
13,
4677,
358,
199,
199,
3,
18532,
370,
5629,
367,
1263,
1163,
7475,
199,
32,
70,
597,
73,
3643,
14,
571,
63,
705,
2232,
8,
5188,
9,
199,
318,
2034,
63,
1397,
63,
4214,
8,
705,
304,
272,
372,
4660,
8,
633,
63,
509,
480,
70,
597,
73,
3643,
14,
1080,
1288,
1233,
29,
8551,
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
] |
[
7209,
492,
22447,
1361,
12,
3795,
63,
1160,
12,
23819,
12,
1056,
12,
3222,
63,
504,
63,
3619,
12,
4660,
12,
1166,
63,
509,
199,
646,
747,
199,
199,
70,
597,
73,
3643,
275,
22447,
1361,
360,
70,
597,
73,
3643,
297,
636,
354,
3108,
1978,
63,
3741,
534,
5876,
358,
199,
199,
32,
70,
597,
73,
3643,
14,
4449,
7825,
199,
318,
1478,
837,
272,
372,
3795,
63,
1160,
360,
1080,
14,
1360,
358,
199,
199,
32,
70,
597,
73,
3643,
14,
4449,
2336,
1733,
13,
2604,
358,
199,
318,
13953,
3297,
837,
272,
372,
3795,
63,
1160,
360,
1733,
63,
2604,
14,
1360,
358,
199,
199,
624,
199,
32,
70,
597,
73,
3643,
14,
4449,
2336,
1246,
15,
86,
17,
14,
16,
15,
70,
597,
73,
3643,
297,
3102,
2968,
2970,
1105,
199,
318,
664,
63,
70,
597,
73,
3643,
837,
272,
18154,
275,
2069,
8,
1069,
14,
589,
14,
362,
360,
13803,
297,
12381,
272,
18896,
275,
2069,
8,
1069,
14,
589,
14,
362,
360,
13331,
297,
12381,
272,
327,
5972,
664,
4474,
543,
30055,
2004,
4453,
5238,
16155,
402,
2909,
436,
4021,
737,
272,
327,
289,
692,
369,
2058,
272,
289,
597,
73,
3643,
275,
481,
597,
29156,
3900,
14,
1462,
8,
1985,
363,
21078,
1524,
3044,
18154,
12,
18896,
467,
2909,
363,
988,
63,
5590,
29,
21,
993,
18562,
1400,
61,
272,
372,
23819,
3252,
70,
597,
73,
3643,
356,
289,
597,
73,
3643,
1552,
199,
624,
199,
199,
32,
70,
597,
73,
3643,
14,
4449,
2336,
4677,
14,
12802,
358,
199,
318,
29139,
837,
272,
372,
3222,
63,
504,
63,
3619,
8,
736,
14,
515,
14,
904,
8,
22120,
454,
85,
5618,
14,
1231,
63,
515,
12,
283,
1986,
297,
283,
4782,
659,
3044,
283,
4677,
14,
12802,
297,
12200,
534,
1569,
15,
88,
13,
4677,
358,
199,
199,
3,
18532,
370,
5629,
367,
1263,
1163,
7475,
199,
32,
70,
597,
73,
3643,
14,
571,
63,
705,
2232,
8,
5188,
9,
199,
318,
2034,
63,
1397,
63,
4214,
8,
705,
304,
272,
372,
4660,
8,
633,
63,
509,
480,
70,
597,
73,
3643,
14,
1080,
1288,
1233,
29,
8551,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
blackPantherOS/packagemanagement
|
smartpm/smart/backends/deb/base.py
|
2
|
7689
|
#
# Copyright (c) 2005 Canonical
# Copyright (c) 2004 Conectiva, Inc.
#
# Written by Gustavo Niemeyer <niemeyer@conectiva.com>
#
# This file is part of Smart Package Manager.
#
# Smart Package Manager 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.
#
# Smart Package Manager 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 Smart Package Manager; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
import fnmatch
import string
import sys
import os
import re
from smart.backends.deb.debver import vercmp, checkdep, splitrelease
from smart.backends.deb.pm import DebPackageManager
from smart.util.strtools import isGlob
from smart.cache import *
__all__ = ["DebPackage", "DebProvides", "DebNameProvides", "DebPreRequires",
"DebRequires", "DebUpgrades", "DebConflicts", "DebBreaks",
"DebOrRequires", "DebOrPreRequires", "DEBARCH", "system_provides"]
def getArchitecture():
arch = sysconf.get("deb-arch")
if arch is not None:
return arch
arch = os.uname()[-1]
result = {"pentium": "i386",
"i86pc": "i386",
"sparc64": "sparc",
"ppc": "powerpc",
"mipseb": "mips",
"shel": "sh",
"x86_64": "amd64"}.get(arch)
if result:
arch = result
elif len(arch) == 4 and arch[0] == "i" and arch.endswith("86"):
arch = "i386"
elif arch.startswith("arm"):
from _base import arm_eabi
if arm_eabi():
arch = "armel"
else:
arch = "arm"
elif arch.startswith("hppa"):
arch = "hppa"
elif arch.startswith("alpha"):
arch = "alpha"
if sys.platform == "linux2":
return arch
elif sys.platform == "sunos5":
return "%s-%s" % ("solaris", arch)
else:
return "%s-%s" % (sys.platform, arch)
DEBARCH = getArchitecture()
class DebPackage(Package):
__slots__ = ()
packagemanager = DebPackageManager
def coexists(self, other):
if not isinstance(other, DebPackage):
return True
return False
def matches(self, relation, version):
if not relation:
return True
return checkdep(self.version, relation, version)
def search(self, searcher):
myname = self.name
myversion = self.version
ratio = 0
ic = searcher.ignorecase
for nameversion, cutoff in searcher.nameversion:
_, ratio1 = globdistance(nameversion, myname, cutoff, ic)
_, ratio2 = globdistance(nameversion,
"%s_%s" % (myname, myversion), cutoff, ic)
_, ratio3 = globdistance(nameversion, "%s_%s" %
(myname, splitrelease(myversion)[0]),
cutoff, ic)
ratio = max(ratio, ratio1, ratio2, ratio3)
if ratio:
searcher.addResult(self, ratio)
def __lt__(self, other):
rc = cmp(self.name, other.name)
if type(other) is DebPackage:
if rc == 0 and self.version != other.version:
rc = vercmp(self.version, other.version)
return rc == -1
def __str__(self):
return "%s_%s" % (self.name, self.version)
class DebProvides(Provides): __slots__ = ()
class DebNameProvides(DebProvides): __slots__ = ()
class DebDepends(Depends):
__slots__ = ()
def matches(self, prv):
if not isinstance(prv, DebProvides) and type(prv) is not Provides:
return False
if not self.version:
return True
if not prv.version:
return False
return checkdep(prv.version, self.relation, self.version)
class DebPreRequires(DebDepends,PreRequires): __slots__ = ()
class DebRequires(DebDepends,Requires): __slots__ = ()
class DebOrDepends(Depends):
__slots__ = ("_nrv",)
def __init__(self, nrv):
name = " | ".join([(x[2] and " ".join(x) or x[0]) for x in nrv])
Depends.__init__(self, name, None, None)
self._nrv = nrv
def getInitArgs(self):
return (self.__class__, self._nrv)
def getMatchNames(self):
return [x[0] for x in self._nrv]
def matches(self, prv):
if not isinstance(prv, DebProvides) and type(prv) is not Provides:
return False
for name, relation, version in self._nrv:
if name == prv.name:
if not version:
return True
if not prv.version:
continue
if checkdep(prv.version, relation, version):
return True
return False
def __reduce__(self):
return (self.__class__, (self._nrv,))
class DebOrRequires(DebOrDepends,Requires): __slots__ = ()
class DebOrPreRequires(DebOrDepends,PreRequires): __slots__ = ()
class DebUpgrades(DebDepends,Upgrades):
__slots__ = ()
def matches(self, prv):
if not isinstance(prv, DebNameProvides) and type(prv) is not Provides:
return False
if not self.version or not prv.version:
return True
return checkdep(prv.version, self.relation, self.version)
class DebConflicts(DebDepends,Conflicts): __slots__ = ()
class DebBreaks(DebDepends,Conflicts): __slots__ = ()
class NullSystemProvides(object):
def matches(self, requires):
return False
class FinkVirtualPkgs(object):
def __init__(self, path):
self._provides = {}
pkgs = []
info = {}
output = os.popen(path).readlines()
for line in output:
line = string.rstrip(line)
if line.startswith(' '):
continue
keyval = string.split(line, ':', 1)
if len(keyval) > 1:
val = string.lstrip(keyval[1])
info[keyval[0]] = val
else:
pkgs.append(info)
info = {}
for info in pkgs:
if info["Status"].endswith("not-installed"):
continue
name = info["Package"]
version = info["Version"]
self._provides.setdefault(name, DebNameProvides(name, version))
provides = string.split(info.get("provides", ""), ', ')
for provide in provides:
if provide:
self._provides.setdefault(provide, DebProvides(provide, None))
def matches(self, requires):
for name in requires.getMatchNames():
if name in self._provides:
prv = self._provides.get(name)
if requires.matches(prv):
return True
return False
system_provides = NullSystemProvides()
fink = sysconf.get("fink-virtual-pkgs", "/sw/bin/fink-virtual-pkgs")
if fink and os.path.exists(fink):
system_provides = FinkVirtualPkgs(fink)
def enablePsyco(psyco):
psyco.bind(DebPackage.coexists)
psyco.bind(DebPackage.matches)
psyco.bind(DebPackage.search)
psyco.bind(DebPackage.__lt__)
psyco.bind(DebDepends.matches)
psyco.bind(DebOrDepends.matches)
psyco.bind(DebUpgrades.matches)
hooks.register("enable-psyco", enablePsyco)
# vim:ts=4:sw=4:et
|
apache-2.0
|
[
3,
199,
3,
1898,
334,
67,
9,
11811,
6855,
7174,
199,
3,
1898,
334,
67,
9,
8353,
445,
368,
67,
280,
3042,
12,
3277,
14,
199,
3,
199,
3,
27694,
701,
598,
833,
1214,
79,
653,
1873,
278,
23009,
665,
78,
1873,
278,
23009,
32,
67,
368,
67,
280,
3042,
14,
957,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
26017,
15665,
13537,
14,
199,
3,
199,
3,
26017,
15665,
13537,
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,
3267,
199,
3,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
334,
292,
199,
3,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
26017,
15665,
13537,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
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,
26017,
15665,
13537,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
221,
15673,
13,
13421,
221,
8217,
199,
3,
199,
646,
15951,
199,
646,
1059,
199,
646,
984,
199,
646,
747,
199,
646,
295,
199,
199,
504,
11179,
14,
7765,
14,
16762,
14,
16762,
422,
492,
809,
5730,
12,
1104,
2601,
12,
3715,
3221,
199,
504,
11179,
14,
7765,
14,
16762,
14,
7073,
492,
1487,
66,
8599,
2988,
199,
504,
11179,
14,
1974,
14,
495,
2537,
492,
365,
25954,
199,
504,
11179,
14,
1637,
492,
627,
199,
199,
363,
452,
363,
275,
2097,
872,
66,
8599,
401,
298,
872,
66,
17473,
401,
298,
872,
66,
985,
17473,
401,
298,
872,
66,
2398,
18153,
401,
1779,
298,
872,
66,
18153,
401,
298,
872,
66,
1721,
18050,
401,
298,
872,
66,
8930,
13192,
401,
298,
872,
66,
13948,
83,
401,
1779,
298,
872,
66,
2844,
18153,
401,
298,
872,
66,
2844,
2398,
18153,
401,
298,
1093,
34,
7762,
401,
298,
2253,
63,
20121,
937,
199,
199,
318,
664,
8438,
10497,
837,
272,
3819,
275,
984,
2190,
14,
362,
480,
16762,
13,
1047,
531,
272,
340,
3819,
365,
440,
488,
26,
267,
372,
3819,
272,
3819,
275,
747,
14,
16040,
19105,
17,
61,
272,
754,
275,
2420,
897,
280,
453,
582,
298,
73,
8040,
401,
1598,
298,
73,
1184,
2352,
582,
298,
73,
8040,
401,
1598,
298,
22502,
67,
772,
582,
298,
22502,
67,
401,
1598,
298,
20638,
582,
298,
5652,
2352,
401,
1598,
298,
20496,
261,
66,
582,
198,
2,
77,
6142,
401,
1598,
298,
609,
352,
582,
298,
609,
401,
1598,
298,
88,
1184,
63,
772,
582,
298,
21778,
772,
3570,
14,
362,
8,
1047,
9,
272,
340,
754,
26,
267,
3819,
275,
754,
272,
916,
822,
8,
1047,
9,
508,
841,
436,
3819,
59,
16,
61,
508,
298,
73,
2,
436,
3819,
14,
4130,
480,
1184,
2349,
267,
3819,
275,
298,
73,
8040,
2,
272,
916,
3819,
14,
2460,
480,
5362,
2349,
267,
687,
485,
1095,
492,
30701,
63,
69,
14677,
267,
340,
30701,
63,
69,
14677,
837,
288,
3819,
275,
298,
285,
26908,
2,
267,
587,
26,
288,
3819,
275,
298,
5362,
2,
272,
916,
3819,
14,
2460,
480,
12025,
387,
2349,
267,
3819,
275,
298,
12025,
387,
2,
272,
916,
3819,
14,
2460,
480,
4468,
2349,
267,
3819,
275,
298,
4468,
2,
2286,
340,
984,
14,
3246,
508,
298,
5135,
18,
582,
267,
372,
3819,
272,
916,
984,
14,
3246,
508,
298,
11846,
736,
21,
582,
267,
372,
2071,
83,
3295,
83,
2,
450,
1689,
7873,
4663,
401,
3819,
9,
272,
587,
26,
267,
372,
2071,
83,
3295,
83,
2,
450,
334,
1274,
14,
3246,
12,
3819,
9,
199,
199,
1093,
34,
7762,
275,
664,
8438,
10497,
342,
199,
199,
533,
1487,
66,
8599,
8,
8599,
304,
339,
636,
7257,
363,
275,
6248,
339,
2559,
2609,
275,
1487,
66,
8599,
2988,
2286,
347,
512,
2444,
8,
277,
12,
1163,
304,
267,
340,
440,
1228,
8,
1848,
12,
1487,
66,
8599,
304,
288,
372,
715,
267,
372,
756,
339,
347,
4450,
8,
277,
12,
5850,
12,
1015,
304,
267,
340,
440,
5850,
26,
288,
372,
715,
267,
372,
1104,
2601,
8,
277,
14,
1023,
12,
5850,
12,
1015,
9,
339,
347,
2754,
8,
277,
12,
2754,
281,
304,
267,
3002,
354,
275,
291,
14,
354,
267,
3002,
1023,
275,
291,
14,
1023,
267,
10463,
275,
378,
267,
284,
67,
275,
2754,
281,
14,
4247,
2546,
267,
367,
536,
1023,
12,
17875,
315,
2754,
281,
14,
354,
1023,
26,
288,
5501,
10463,
17,
275,
5739,
5590,
8,
354,
1023,
12,
3002,
354,
12,
17875,
12,
284,
67,
9,
288,
5501,
10463,
18,
275,
5739,
5590,
8,
354,
1023,
12,
3660,
2071,
83,
4970,
83,
2,
450,
334,
1662,
354,
12,
3002,
1023,
395,
17875,
12,
284,
67,
9,
288,
5501,
10463,
19,
275,
5739,
5590,
8,
354,
1023,
12,
2071,
83,
4970,
83,
2,
450,
3660,
334,
1662,
354,
12,
3715,
3221,
8,
1662,
1023,
2788,
16,
2522,
3660,
17875,
12,
284,
67,
9,
288,
10463,
275,
1390,
8,
6884,
12,
10463,
17,
12,
10463,
18,
12,
10463,
19,
9,
267,
340,
10463,
26,
288,
2754,
281,
14,
525,
2889,
8,
277,
12,
10463,
9,
339,
347,
636,
4116,
721,
277,
12,
1163,
304,
267,
4819,
275,
10467,
8,
277,
14,
354,
12,
1163,
14,
354,
9,
267,
340,
730,
8,
1848,
9,
365,
1487,
66,
8599,
26,
288,
340,
4819,
508,
378,
436,
291,
14,
1023,
1137,
1163,
14,
1023,
26,
355,
4819,
275,
809,
5730,
8,
277,
14,
1023,
12,
1163,
14,
1023,
9,
267,
372,
4819,
508,
446,
17,
339,
347,
636,
495,
721,
277,
304,
267,
372,
2071,
83,
4970,
83,
2,
450,
334,
277,
14,
354,
12,
291,
14,
1023,
9,
199,
199,
533,
1487,
66,
17473,
8,
17473,
304,
263,
636,
7257,
363,
275,
6248,
199,
533,
1487,
66,
985,
17473
] |
[
199,
3,
1898,
334,
67,
9,
11811,
6855,
7174,
199,
3,
1898,
334,
67,
9,
8353,
445,
368,
67,
280,
3042,
12,
3277,
14,
199,
3,
199,
3,
27694,
701,
598,
833,
1214,
79,
653,
1873,
278,
23009,
665,
78,
1873,
278,
23009,
32,
67,
368,
67,
280,
3042,
14,
957,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
26017,
15665,
13537,
14,
199,
3,
199,
3,
26017,
15665,
13537,
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,
3267,
199,
3,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
334,
292,
199,
3,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
26017,
15665,
13537,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
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,
26017,
15665,
13537,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
221,
15673,
13,
13421,
221,
8217,
199,
3,
199,
646,
15951,
199,
646,
1059,
199,
646,
984,
199,
646,
747,
199,
646,
295,
199,
199,
504,
11179,
14,
7765,
14,
16762,
14,
16762,
422,
492,
809,
5730,
12,
1104,
2601,
12,
3715,
3221,
199,
504,
11179,
14,
7765,
14,
16762,
14,
7073,
492,
1487,
66,
8599,
2988,
199,
504,
11179,
14,
1974,
14,
495,
2537,
492,
365,
25954,
199,
504,
11179,
14,
1637,
492,
627,
199,
199,
363,
452,
363,
275,
2097,
872,
66,
8599,
401,
298,
872,
66,
17473,
401,
298,
872,
66,
985,
17473,
401,
298,
872,
66,
2398,
18153,
401,
1779,
298,
872,
66,
18153,
401,
298,
872,
66,
1721,
18050,
401,
298,
872,
66,
8930,
13192,
401,
298,
872,
66,
13948,
83,
401,
1779,
298,
872,
66,
2844,
18153,
401,
298,
872,
66,
2844,
2398,
18153,
401,
298,
1093,
34,
7762,
401,
298,
2253,
63,
20121,
937,
199,
199,
318,
664,
8438,
10497,
837,
272,
3819,
275,
984,
2190,
14,
362,
480,
16762,
13,
1047,
531,
272,
340,
3819,
365,
440,
488,
26,
267,
372,
3819,
272,
3819,
275,
747,
14,
16040,
19105,
17,
61,
272,
754,
275,
2420,
897,
280,
453,
582,
298,
73,
8040,
401,
1598,
298,
73,
1184,
2352,
582,
298,
73,
8040,
401,
1598,
298,
22502,
67,
772,
582,
298,
22502,
67,
401,
1598,
298,
20638,
582,
298,
5652,
2352,
401,
1598,
298,
20496,
261,
66,
582,
198,
2,
77,
6142,
401,
1598,
298,
609,
352,
582,
298,
609,
401,
1598,
298,
88,
1184,
63,
772,
582,
298,
21778,
772,
3570,
14,
362,
8,
1047,
9,
272,
340,
754,
26,
267,
3819,
275,
754,
272,
916,
822,
8,
1047,
9,
508,
841,
436,
3819,
59,
16,
61,
508,
298,
73,
2,
436,
3819,
14,
4130,
480,
1184,
2349,
267,
3819,
275,
298,
73,
8040,
2,
272,
916,
3819,
14,
2460,
480,
5362,
2349,
267,
687,
485,
1095,
492,
30701,
63,
69,
14677,
267,
340,
30701,
63,
69,
14677,
837,
288,
3819,
275,
298,
285,
26908,
2,
267,
587,
26,
288,
3819,
275,
298,
5362,
2,
272,
916,
3819,
14,
2460,
480,
12025,
387,
2349,
267,
3819,
275,
298,
12025,
387,
2,
272,
916,
3819,
14,
2460,
480,
4468,
2349,
267,
3819,
275,
298,
4468,
2,
2286,
340,
984,
14,
3246,
508,
298,
5135,
18,
582,
267,
372,
3819,
272,
916,
984,
14,
3246,
508,
298,
11846,
736,
21,
582,
267,
372,
2071,
83,
3295,
83,
2,
450,
1689,
7873,
4663,
401,
3819,
9,
272,
587,
26,
267,
372,
2071,
83,
3295,
83,
2,
450,
334,
1274,
14,
3246,
12,
3819,
9,
199,
199,
1093,
34,
7762,
275,
664,
8438,
10497,
342,
199,
199,
533,
1487,
66,
8599,
8,
8599,
304,
339,
636,
7257,
363,
275,
6248,
339,
2559,
2609,
275,
1487,
66,
8599,
2988,
2286,
347,
512,
2444,
8,
277,
12,
1163,
304,
267,
340,
440,
1228,
8,
1848,
12,
1487,
66,
8599,
304,
288,
372,
715,
267,
372,
756,
339,
347,
4450,
8,
277,
12,
5850,
12,
1015,
304,
267,
340,
440,
5850,
26,
288,
372,
715,
267,
372,
1104,
2601,
8,
277,
14,
1023,
12,
5850,
12,
1015,
9,
339,
347,
2754,
8,
277,
12,
2754,
281,
304,
267,
3002,
354,
275,
291,
14,
354,
267,
3002,
1023,
275,
291,
14,
1023,
267,
10463,
275,
378,
267,
284,
67,
275,
2754,
281,
14,
4247,
2546,
267,
367,
536,
1023,
12,
17875,
315,
2754,
281,
14,
354,
1023,
26,
288,
5501,
10463,
17,
275,
5739,
5590,
8,
354,
1023,
12,
3002,
354,
12,
17875,
12,
284,
67,
9,
288,
5501,
10463,
18,
275,
5739,
5590,
8,
354,
1023,
12,
3660,
2071,
83,
4970,
83,
2,
450,
334,
1662,
354,
12,
3002,
1023,
395,
17875,
12,
284,
67,
9,
288,
5501,
10463,
19,
275,
5739,
5590,
8,
354,
1023,
12,
2071,
83,
4970,
83,
2,
450,
3660,
334,
1662,
354,
12,
3715,
3221,
8,
1662,
1023,
2788,
16,
2522,
3660,
17875,
12,
284,
67,
9,
288,
10463,
275,
1390,
8,
6884,
12,
10463,
17,
12,
10463,
18,
12,
10463,
19,
9,
267,
340,
10463,
26,
288,
2754,
281,
14,
525,
2889,
8,
277,
12,
10463,
9,
339,
347,
636,
4116,
721,
277,
12,
1163,
304,
267,
4819,
275,
10467,
8,
277,
14,
354,
12,
1163,
14,
354,
9,
267,
340,
730,
8,
1848,
9,
365,
1487,
66,
8599,
26,
288,
340,
4819,
508,
378,
436,
291,
14,
1023,
1137,
1163,
14,
1023,
26,
355,
4819,
275,
809,
5730,
8,
277,
14,
1023,
12,
1163,
14,
1023,
9,
267,
372,
4819,
508,
446,
17,
339,
347,
636,
495,
721,
277,
304,
267,
372,
2071,
83,
4970,
83,
2,
450,
334,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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
] |
Tetpay/cjdns
|
node_build/dependencies/libuv/build/gyp/test/generator-output/gyptest-subdir2-deep.py
|
216
|
1034
|
#!/usr/bin/env python
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""
Verifies building a target from a .gyp file a few subdirectories
deep when the --generator-output= option is used to put the build
configuration files in a separate directory tree.
"""
import TestGyp
# Android doesn't support --generator-output.
test = TestGyp.TestGyp(formats=['!android'])
test.writable(test.workpath('src'), False)
test.writable(test.workpath('src/subdir2/deeper/build'), True)
test.run_gyp('deeper.gyp',
'-Dset_symroot=1',
'--generator-output=' + test.workpath('gypfiles'),
chdir='src/subdir2/deeper')
test.build('deeper.gyp', test.ALL, chdir='gypfiles')
chdir = 'gypfiles'
if test.format == 'xcode':
chdir = 'src/subdir2/deeper'
test.run_built_executable('deeper',
chdir=chdir,
stdout="Hello from deeper.c\n")
test.pass_test()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
1898,
334,
67,
9,
6029,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
199,
21168,
10015,
282,
1347,
687,
282,
1275,
6179,
570,
282,
9284,
24799,
199,
16131,
1380,
314,
1553,
4679,
13,
1199,
29,
945,
365,
1202,
370,
5324,
314,
1900,
199,
4758,
1584,
315,
282,
7396,
2082,
3123,
14,
199,
624,
199,
199,
646,
25688,
199,
199,
3,
14694,
3181,
1133,
2291,
1553,
4679,
13,
1199,
14,
199,
396,
275,
25688,
14,
774,
13899,
8,
6321,
2968,
1,
6238,
1105,
199,
199,
396,
14,
15053,
8,
396,
14,
800,
515,
360,
2164,
659,
756,
9,
199,
199,
396,
14,
15053,
8,
396,
14,
800,
515,
360,
2164,
15,
10622,
18,
15,
11192,
529,
15,
1506,
659,
715,
9,
199,
199,
396,
14,
1065,
63,
6179,
360,
11192,
529,
14,
6179,
297,
1467,
2475,
36,
409,
63,
3840,
1231,
29,
17,
297,
1467,
2850,
4679,
13,
1199,
534,
435,
511,
14,
800,
515,
360,
6179,
1725,
659,
1467,
13097,
534,
2164,
15,
10622,
18,
15,
11192,
529,
358,
199,
199,
396,
14,
1506,
360,
11192,
529,
14,
6179,
297,
511,
14,
1761,
12,
13097,
534,
6179,
1725,
358,
199,
199,
8563,
275,
283,
6179,
1725,
7,
199,
199,
692,
511,
14,
908,
508,
283,
8701,
356,
523,
13097,
275,
283,
2164,
15,
10622,
18,
15,
11192,
529,
7,
199,
396,
14,
1065,
63,
11730,
63,
5904,
360,
11192,
529,
297,
2079,
13097,
29,
8563,
12,
2079,
3839,
628,
6257,
687,
477,
15033,
14,
67,
60,
78,
531,
199,
199,
396,
14,
1529,
63,
396,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
3,
1898,
334,
67,
9,
6029,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
199,
21168,
10015,
282,
1347,
687,
282,
1275,
6179,
570,
282,
9284,
24799,
199,
16131,
1380,
314,
1553,
4679,
13,
1199,
29,
945,
365,
1202,
370,
5324,
314,
1900,
199,
4758,
1584,
315,
282,
7396,
2082,
3123,
14,
199,
624,
199,
199,
646,
25688,
199,
199,
3,
14694,
3181,
1133,
2291,
1553,
4679,
13,
1199,
14,
199,
396,
275,
25688,
14,
774,
13899,
8,
6321,
2968,
1,
6238,
1105,
199,
199,
396,
14,
15053,
8,
396,
14,
800,
515,
360,
2164,
659,
756,
9,
199,
199,
396,
14,
15053,
8,
396,
14,
800,
515,
360,
2164,
15,
10622,
18,
15,
11192,
529,
15,
1506,
659,
715,
9,
199,
199,
396,
14,
1065,
63,
6179,
360,
11192,
529,
14,
6179,
297,
1467,
2475,
36,
409,
63,
3840,
1231,
29,
17,
297,
1467,
2850,
4679,
13,
1199,
534,
435,
511,
14,
800,
515,
360,
6179,
1725,
659,
1467,
13097,
534,
2164,
15,
10622,
18,
15,
11192,
529,
358,
199,
199,
396,
14,
1506,
360,
11192,
529,
14,
6179,
297,
511,
14,
1761,
12,
13097,
534,
6179,
1725,
358,
199,
199,
8563,
275,
283,
6179,
1725,
7,
199,
199,
692,
511,
14,
908,
508,
283,
8701,
356,
523,
13097,
275,
283,
2164,
15,
10622,
18,
15,
11192,
529,
7,
199,
396,
14,
1065,
63,
11730,
63,
5904,
360,
11192,
529,
297,
2079,
13097,
29,
8563,
12,
2079,
3839,
628,
6257,
687,
477,
15033,
14,
67,
60,
78,
531,
199,
199,
396,
14,
1529,
63,
396,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
recklessromeo/otm-core
|
opentreemap/treemap/migrations/0001_initial.py
|
6
|
23222
|
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
import re
import django.contrib.gis.db.models.fields
import django_hstore.fields
import treemap.json_field
import treemap.instance
import django.contrib.auth.models
import treemap.audit
import django.utils.timezone
from django.conf import settings
import treemap.udf
import django.core.validators
import treemap.units
class Migration(migrations.Migration):
dependencies = [
('auth', '0006_require_contenttypes_0002'),
]
operations = [
migrations.CreateModel(
name='User',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('password', models.CharField(max_length=128, verbose_name='password')),
('last_login', models.DateTimeField(default=django.utils.timezone.now, verbose_name='last login')),
('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
('username', models.CharField(help_text='Required. 30 characters or fewer. Letters, numbers and @/./+/-/_ characters', unique=True, max_length=30, verbose_name='username', validators=[django.core.validators.RegexValidator(re.compile('^[\\w.@+-]+$'), 'Enter a valid username.', 'invalid')])),
('email', models.EmailField(unique=True, max_length=75, verbose_name='email address', blank=True)),
('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')),
('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')),
('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')),
('photo', models.ImageField(null=True, upload_to='users', blank=True)),
('thumbnail', models.ImageField(null=True, upload_to='users', blank=True)),
('first_name', models.CharField(default='', max_length=30, verbose_name='first name', blank=True)),
('last_name', models.CharField(default='', max_length=30, verbose_name='last name', blank=True)),
('organization', models.CharField(default='', max_length=255, blank=True)),
('make_info_public', models.BooleanField(default=False)),
('allow_email_contact', models.BooleanField(default=False)),
('groups', models.ManyToManyField(related_query_name='user', related_name='user_set', to='auth.Group', blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', verbose_name='groups')),
('user_permissions', models.ManyToManyField(related_query_name='user', related_name='user_set', to='auth.Permission', blank=True, help_text='Specific permissions for this user.', verbose_name='user permissions')),
],
options={
'abstract': False,
'verbose_name': 'user',
'verbose_name_plural': 'users',
},
bases=(models.Model, treemap.audit.Auditable),
managers=[
('objects', django.contrib.auth.models.UserManager()),
],
),
migrations.CreateModel(
name='Audit',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('model', models.CharField(max_length=255, null=True, db_index=True)),
('model_id', models.IntegerField(null=True, db_index=True)),
('field', models.CharField(max_length=255, null=True)),
('previous_value', models.TextField(null=True)),
('current_value', models.TextField(null=True, db_index=True)),
('action', models.IntegerField()),
('requires_auth', models.BooleanField(default=False)),
('created', models.DateTimeField(auto_now_add=True, db_index=True)),
('updated', models.DateTimeField(auto_now=True, db_index=True)),
],
),
migrations.CreateModel(
name='BenefitCurrencyConversion',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('currency_symbol', models.CharField(max_length=5)),
('electricity_kwh_to_currency', models.FloatField()),
('natural_gas_kbtu_to_currency', models.FloatField()),
('h20_gal_to_currency', models.FloatField()),
('co2_lb_to_currency', models.FloatField()),
('o3_lb_to_currency', models.FloatField()),
('nox_lb_to_currency', models.FloatField()),
('pm10_lb_to_currency', models.FloatField()),
('sox_lb_to_currency', models.FloatField()),
('voc_lb_to_currency', models.FloatField()),
],
bases=(treemap.audit.Dictable, models.Model),
),
migrations.CreateModel(
name='Boundary',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('geom', django.contrib.gis.db.models.fields.MultiPolygonField(srid=3857, db_column='the_geom_webmercator')),
('name', models.CharField(max_length=255)),
('category', models.CharField(max_length=255)),
('sort_order', models.IntegerField()),
('updated_at', models.DateTimeField(db_index=True, auto_now=True, null=True)),
],
),
migrations.CreateModel(
name='Favorite',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('created', models.DateTimeField(auto_now_add=True)),
],
),
migrations.CreateModel(
name='FieldPermission',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('model_name', models.CharField(max_length=255)),
('field_name', models.CharField(max_length=255)),
('permission_level', models.IntegerField(default=0, choices=[(0, 'None'), (1, 'Read Only'), (2, 'Write with Audit'), (3, 'Write Directly')])),
],
),
migrations.CreateModel(
name='Instance',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('name', models.CharField(unique=True, max_length=255)),
('url_name', models.CharField(unique=True, max_length=255, validators=[treemap.instance.reserved_name_validator, django.core.validators.RegexValidator('^[a-zA-Z]+[a-zA-Z0-9\\-]*$', 'Must start with a letter and may only contain letters, numbers, or dashes ("-")', 'Invalid URL name')])),
('basemap_type', models.CharField(default='google', max_length=255, choices=[('google', 'Google'), ('bing', 'Bing'), ('tms', 'Tile Map Service')])),
('basemap_data', models.CharField(max_length=255, null=True, blank=True)),
('geo_rev', models.IntegerField(default=1)),
('bounds', django.contrib.gis.db.models.fields.MultiPolygonField(srid=3857)),
('center_override', django.contrib.gis.db.models.fields.PointField(srid=3857, null=True, blank=True)),
('config', treemap.json_field.JSONField(blank=True)),
('is_public', models.BooleanField(default=False)),
('logo', models.ImageField(null=True, upload_to='logos', blank=True)),
('itree_region_default', models.CharField(blank=True, max_length=20, null=True, choices=[(b'TpIntWBOI', b'Temperate Interior West'), (b'NoEastXXX', b'Northeast'), (b'CaNCCoJBK', b'Northern California Coast'), (b'InterWABQ', b'Interior West'), (b'InlEmpCLM', b'Inland Empire'), (b'LoMidWXXX', b'Lower Midwest'), (b'MidWstMSP', b'Midwest'), (b'NMtnPrFNL', b'North'), (b'PacfNWLOG', b'Pacific Northwest'), (b'PiedmtCLT', b'South'), (b'SoCalCSMA', b'Southern California Coast'), (b'GulfCoCHS', b'Coastal Plain'), (b'SWDsrtGDL', b'Southwest Desert'), (b'InlValMOD', b'Inland Valleys'), (b'CenFlaXXX', b'Central Florida'), (b'TropicPacXXX', b'Tropical')])),
('adjuncts_timestamp', models.BigIntegerField(default=0)),
('non_admins_can_export', models.BooleanField(default=True)),
('boundaries', models.ManyToManyField(to='treemap.Boundary', null=True, blank=True)),
],
),
migrations.CreateModel(
name='InstanceUser',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('reputation', models.IntegerField(default=0)),
('admin', models.BooleanField(default=False)),
('instance', models.ForeignKey(to='treemap.Instance')),
],
bases=(treemap.audit.Auditable, models.Model),
),
migrations.CreateModel(
name='ITreeCodeOverride',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('itree_code', models.CharField(max_length=100)),
],
bases=(models.Model, treemap.audit.Auditable),
),
migrations.CreateModel(
name='ITreeRegion',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('code', models.CharField(unique=True, max_length=40)),
('geometry', django.contrib.gis.db.models.fields.MultiPolygonField(srid=3857)),
],
),
migrations.CreateModel(
name='MapFeature',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('udfs', treemap.udf.UDFField(db_index=True, blank=True)),
('geom', django.contrib.gis.db.models.fields.PointField(srid=3857, db_column='the_geom_webmercator')),
('address_street', models.CharField(help_text='Address', max_length=255, null=True, blank=True)),
('address_city', models.CharField(help_text='City', max_length=255, null=True, blank=True)),
('address_zip', models.CharField(help_text='Postal Code', max_length=30, null=True, blank=True)),
('readonly', models.BooleanField(default=False)),
('updated_at', models.DateTimeField(default=django.utils.timezone.now, help_text='Last Updated')),
('feature_type', models.CharField(max_length=255)),
],
options={
'abstract': False,
},
bases=(treemap.units.Convertible, treemap.audit.PendingAuditable, treemap.audit.UserTrackable, models.Model),
),
migrations.CreateModel(
name='MapFeaturePhoto',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('image', models.ImageField(upload_to='trees/%Y/%m/%d', editable=False)),
('thumbnail', models.ImageField(upload_to='trees_thumbs/%Y/%m/%d', editable=False)),
('created_at', models.DateTimeField(auto_now_add=True)),
],
bases=(models.Model, treemap.audit.PendingAuditable),
),
migrations.CreateModel(
name='ReputationMetric',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('model_name', models.CharField(max_length=255)),
('action', models.CharField(max_length=255)),
('direct_write_score', models.IntegerField(null=True, blank=True)),
('approval_score', models.IntegerField(null=True, blank=True)),
('denial_score', models.IntegerField(null=True, blank=True)),
('instance', models.ForeignKey(to='treemap.Instance')),
],
),
migrations.CreateModel(
name='Role',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('name', models.CharField(max_length=255)),
('default_permission', models.IntegerField(default=0, choices=[(0, 'None'), (1, 'Read Only'), (2, 'Write with Audit'), (3, 'Write Directly')])),
('rep_thresh', models.IntegerField()),
('instance', models.ForeignKey(blank=True, to='treemap.Instance', null=True)),
],
),
migrations.CreateModel(
name='Species',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('udfs', treemap.udf.UDFField(db_index=True, blank=True)),
('otm_code', models.CharField(max_length=255)),
('common_name', models.CharField(max_length=255)),
('genus', models.CharField(max_length=255)),
('species', models.CharField(max_length=255, blank=True)),
('cultivar', models.CharField(max_length=255, blank=True)),
('other_part_of_name', models.CharField(max_length=255, blank=True)),
('is_native', models.NullBooleanField()),
('flowering_period', models.CharField(max_length=255, blank=True)),
('fruit_or_nut_period', models.CharField(max_length=255, blank=True)),
('fall_conspicuous', models.NullBooleanField()),
('flower_conspicuous', models.NullBooleanField()),
('palatable_human', models.NullBooleanField()),
('has_wildlife_value', models.NullBooleanField()),
('fact_sheet_url', models.URLField(max_length=255, blank=True)),
('plant_guide_url', models.URLField(max_length=255, blank=True)),
('max_diameter', models.IntegerField(default=200)),
('max_height', models.IntegerField(default=800)),
('updated_at', models.DateTimeField(db_index=True, auto_now=True, null=True)),
('instance', models.ForeignKey(to='treemap.Instance')),
],
options={
'verbose_name_plural': 'Species',
},
bases=(treemap.audit.PendingAuditable, treemap.audit.UserTrackable, models.Model),
),
migrations.CreateModel(
name='StaticPage',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('name', models.CharField(max_length=100)),
('content', models.TextField()),
('instance', models.ForeignKey(to='treemap.Instance')),
],
),
migrations.CreateModel(
name='Tree',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('udfs', treemap.udf.UDFField(db_index=True, blank=True)),
('readonly', models.BooleanField(default=False)),
('diameter', models.FloatField(help_text='Tree Diameter', null=True, blank=True)),
('height', models.FloatField(help_text='Tree Height', null=True, blank=True)),
('canopy_height', models.FloatField(help_text='Canopy Height', null=True, blank=True)),
('date_planted', models.DateField(help_text='Date Planted', null=True, blank=True)),
('date_removed', models.DateField(help_text='Date Removed', null=True, blank=True)),
('instance', models.ForeignKey(to='treemap.Instance')),
('species', models.ForeignKey(blank=True, to='treemap.Species', help_text='Species', null=True)),
],
options={
'abstract': False,
},
bases=(treemap.units.Convertible, treemap.audit.PendingAuditable, treemap.audit.UserTrackable, models.Model),
),
migrations.CreateModel(
name='UserDefinedCollectionValue',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('model_id', models.IntegerField()),
('data', django_hstore.fields.DictionaryField()),
],
bases=(treemap.audit.UserTrackable, models.Model),
),
migrations.CreateModel(
name='UserDefinedFieldDefinition',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('model_type', models.CharField(max_length=255)),
('datatype', models.TextField()),
('iscollection', models.BooleanField()),
('name', models.CharField(max_length=255)),
('instance', models.ForeignKey(to='treemap.Instance')),
],
),
migrations.CreateModel(
name='Plot',
fields=[
('mapfeature_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='treemap.MapFeature')),
('width', models.FloatField(help_text='Plot Width', null=True, blank=True)),
('length', models.FloatField(help_text='Plot Length', null=True, blank=True)),
('owner_orig_id', models.CharField(max_length=255, null=True, blank=True)),
],
options={
'abstract': False,
},
bases=('treemap.mapfeature',),
),
migrations.CreateModel(
name='TreePhoto',
fields=[
('mapfeaturephoto_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='treemap.MapFeaturePhoto')),
('tree', models.ForeignKey(to='treemap.Tree')),
],
bases=('treemap.mapfeaturephoto',),
),
migrations.AddField(
model_name='userdefinedcollectionvalue',
name='field_definition',
field=models.ForeignKey(to='treemap.UserDefinedFieldDefinition'),
),
migrations.AddField(
model_name='mapfeaturephoto',
name='instance',
field=models.ForeignKey(to='treemap.Instance'),
),
migrations.AddField(
model_name='mapfeaturephoto',
name='map_feature',
field=models.ForeignKey(to='treemap.MapFeature'),
),
migrations.AddField(
model_name='mapfeature',
name='instance',
field=models.ForeignKey(to='treemap.Instance'),
),
migrations.AddField(
model_name='itreecodeoverride',
name='instance_species',
field=models.ForeignKey(to='treemap.Species'),
),
migrations.AddField(
model_name='itreecodeoverride',
name='region',
field=models.ForeignKey(to='treemap.ITreeRegion'),
),
migrations.AddField(
model_name='instanceuser',
name='role',
field=models.ForeignKey(to='treemap.Role'),
),
migrations.AddField(
model_name='instanceuser',
name='user',
field=models.ForeignKey(to=settings.AUTH_USER_MODEL),
),
migrations.AddField(
model_name='instance',
name='default_role',
field=models.ForeignKey(related_name='default_role', to='treemap.Role'),
),
migrations.AddField(
model_name='instance',
name='eco_benefits_conversion',
field=models.ForeignKey(blank=True, to='treemap.BenefitCurrencyConversion', null=True),
),
migrations.AddField(
model_name='instance',
name='users',
field=models.ManyToManyField(to=settings.AUTH_USER_MODEL, null=True, through='treemap.InstanceUser', blank=True),
),
migrations.AddField(
model_name='fieldpermission',
name='instance',
field=models.ForeignKey(to='treemap.Instance'),
),
migrations.AddField(
model_name='fieldpermission',
name='role',
field=models.ForeignKey(to='treemap.Role'),
),
migrations.AddField(
model_name='favorite',
name='map_feature',
field=models.ForeignKey(to='treemap.MapFeature'),
),
migrations.AddField(
model_name='favorite',
name='user',
field=models.ForeignKey(to=settings.AUTH_USER_MODEL),
),
migrations.AddField(
model_name='audit',
name='instance',
field=models.ForeignKey(blank=True, to='treemap.Instance', null=True),
),
migrations.AddField(
model_name='audit',
name='ref',
field=models.ForeignKey(to='treemap.Audit', null=True),
),
migrations.AddField(
model_name='audit',
name='user',
field=models.ForeignKey(to=settings.AUTH_USER_MODEL),
),
migrations.AddField(
model_name='tree',
name='plot',
field=models.ForeignKey(to='treemap.Plot'),
),
migrations.AlterUniqueTogether(
name='species',
unique_together=set([('instance', 'common_name', 'genus', 'species', 'cultivar', 'other_part_of_name')]),
),
migrations.AlterUniqueTogether(
name='itreecodeoverride',
unique_together=set([('instance_species', 'region')]),
),
migrations.AlterUniqueTogether(
name='instanceuser',
unique_together=set([('instance', 'user')]),
),
migrations.AlterUniqueTogether(
name='fieldpermission',
unique_together=set([('model_name', 'field_name', 'role', 'instance')]),
),
migrations.AlterUniqueTogether(
name='favorite',
unique_together=set([('user', 'map_feature')]),
),
migrations.AlterIndexTogether(
name='audit',
index_together=set([('instance', 'user', 'updated')]),
),
]
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
697,
492,
1709,
12,
6180,
199,
646,
295,
199,
646,
1639,
14,
2828,
14,
5668,
14,
697,
14,
992,
14,
955,
199,
646,
1639,
63,
72,
1617,
14,
955,
199,
646,
3123,
1130,
14,
1001,
63,
698,
199,
646,
3123,
1130,
14,
842,
199,
646,
1639,
14,
2828,
14,
1178,
14,
992,
199,
646,
3123,
1130,
14,
14274,
199,
646,
1639,
14,
1208,
14,
7145,
199,
504,
1639,
14,
2190,
492,
2202,
199,
646,
3123,
1130,
14,
10031,
199,
646,
1639,
14,
1018,
14,
11346,
199,
646,
3123,
1130,
14,
5260,
421,
199,
533,
12090,
8,
7685,
14,
9816,
304,
339,
5124,
275,
359,
267,
661,
1178,
297,
283,
20965,
63,
4365,
63,
10778,
63,
9425,
659,
272,
1622,
339,
5331,
275,
359,
267,
6180,
14,
14907,
8,
288,
536,
534,
1899,
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,
2060,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
3933,
12,
3376,
63,
354,
534,
2060,
3855,
355,
661,
2019,
63,
2886,
297,
1709,
14,
4626,
8,
885,
29,
1176,
14,
1208,
14,
7145,
14,
2131,
12,
3376,
63,
354,
534,
2019,
4676,
3855,
355,
661,
374,
63,
11434,
297,
1709,
14,
5036,
8,
885,
29,
797,
12,
1720,
63,
505,
534,
20924,
2335,
626,
642,
922,
965,
1006,
3443,
1928,
7662,
26694,
3062,
3130,
3376,
63,
354,
534,
11434,
2004,
3855,
355,
661,
2473,
297,
1709,
14,
2183,
8,
3437,
63,
505,
534,
8030,
14,
4233,
4110,
503,
27392,
14,
12230,
878,
12,
5579,
436,
768,
8083,
15,
19616,
13,
15607,
4110,
297,
3747,
29,
549,
12,
1390,
63,
1267,
29,
1216,
12,
3376,
63,
354,
534,
2473,
297,
14370,
1524,
1176,
14,
1018,
14,
11346,
14,
5103,
8640,
8,
264,
14,
2014,
9097,
59,
1103,
87,
14,
32,
16341,
2807,
26712,
283,
8468,
282,
1686,
3434,
3130,
283,
3197,
2023,
395,
355,
661,
2123,
297,
1709,
14,
16577,
8,
3235,
29,
549,
12,
1390,
63,
1267,
29,
2194,
12,
3376,
63,
354,
534,
2123,
2287,
297,
4596,
29,
549,
1826,
355,
661,
374,
63,
7018,
297,
1709,
14,
5036,
8,
885,
29,
797,
12,
1720,
63,
505,
534,
20924,
2335,
3775,
314,
922,
883,
943,
1901,
642,
4628,
4770,
3130,
3376,
63,
354,
534,
7018,
2004,
3855,
355,
661,
374,
63,
2682,
297,
1709,
14,
5036,
8,
885,
29,
549,
12,
1720,
63,
505,
534,
20924,
2335,
3775,
642,
922,
1077,
506,
10184,
465,
4702,
14,
1910,
2416,
642,
3140,
402,
13794,
12639,
3130,
3376,
63,
354,
534,
2682,
3855,
355,
661,
602,
63,
11806,
297,
1709,
14,
4626,
8,
885,
29,
1176,
14,
1208,
14,
7145,
14,
2131,
12,
3376,
63,
354,
534,
602,
16538,
3855,
355,
661,
13834,
297,
1709,
14,
21910,
8,
2307,
29,
549,
12,
5802,
63,
475,
534,
3707,
297,
4596,
29,
549,
1826,
355,
661,
8311,
297,
1709,
14,
21910,
8,
2307,
29,
549,
12,
5802,
63,
475,
534,
3707,
297,
4596,
29,
549,
1826,
355,
661,
2246,
63,
354,
297,
1709,
14,
2183,
8,
885,
4581,
1390,
63,
1267,
29,
1216,
12,
3376,
63,
354,
534,
2246,
536,
297,
4596,
29,
549,
1826,
355,
661,
2019,
63,
354,
297,
1709,
14,
2183,
8,
885,
4581,
1390,
63,
1267,
29,
1216,
12,
3376,
63,
354,
534,
2019,
536,
297,
4596,
29,
549,
1826,
355,
661,
9071,
297,
1709,
14,
2183,
8,
885,
4581,
1390,
63,
1267,
29,
2299,
12,
4596,
29,
549,
1826,
355,
661,
1875,
63,
815,
63,
3455,
297,
1709,
14,
5036,
8,
885,
29,
797,
1826,
355,
661,
3306,
63,
2123,
63,
7811,
297,
1709,
14,
5036,
8,
885,
29,
797,
1826,
355,
661,
2634,
297,
1709,
14,
7624,
8,
2407,
63,
1131,
63,
354,
534,
751,
297,
4048,
63,
354,
534,
751,
63,
409,
297,
370,
534,
1178,
14,
2448,
297,
4596,
29,
549,
12,
1720,
63,
505,
534,
1918,
4652,
642,
922,
15006,
370,
14,
437,
922,
911,
664,
1006,
3443,
10009,
370,
1924,
402,
3932,
4652,
3130,
3376,
63,
354,
534,
2634,
3855,
355,
661,
751,
63,
6060,
297,
1709,
14,
7624,
8,
2407,
63,
1131,
63,
354,
534,
751,
297,
4048,
63,
354,
534,
751,
63,
409,
297,
370,
534,
1178,
14,
7980,
297,
4596,
29,
549,
12,
1720,
63,
505,
534,
16786,
3443,
367,
642,
922,
3130,
3376,
63,
354,
534,
751,
3443,
3855,
288,
2156,
288,
1511,
3126,
355,
283,
6198,
356,
756,
12,
355,
283,
3832,
63,
354,
356,
283,
751,
297,
355,
283,
3832,
63,
354,
63,
10019,
356,
283,
3707,
297,
288,
1660,
288,
9768,
2687,
992,
14,
1685,
12,
3123,
1130,
14,
14274,
14,
33,
14525,
1224,
395,
288,
19680,
1524,
355,
661,
1462,
297,
1639,
14,
2828,
14,
1178,
14,
992,
14,
1899,
2988,
4000,
288,
2156,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
23601,
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,
1238,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
2299,
12,
2973,
29,
549,
12,
1592,
63,
1080,
29,
549,
1826,
355,
661,
1238,
63,
344,
297,
1709,
14,
3901,
8,
2307,
29,
549,
12,
1592,
63,
1080,
29,
549,
1826,
355,
661,
698,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
2299,
12,
2973,
29,
549,
1826,
355,
661,
6352,
63,
585,
297,
1709,
14,
6254,
8,
2307,
29,
549,
1826,
355,
661,
1818,
63,
585,
297,
1709,
14,
6254,
8,
2307,
29,
549,
12,
1592,
63,
1080,
29,
549,
1826,
355,
661,
1287,
297,
1709,
14,
3901,
4000,
355,
661,
6537,
63,
1178,
297,
1709,
14,
5036,
8,
885,
29,
797,
1826,
355,
661,
3966,
297,
1709,
14,
4626,
8,
2495,
63,
2131,
63,
525,
29,
549,
12,
1592,
63,
1080,
29,
549,
1826,
355,
661,
5334,
297,
1709,
14,
4626,
8,
2495
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
697,
492,
1709,
12,
6180,
199,
646,
295,
199,
646,
1639,
14,
2828,
14,
5668,
14,
697,
14,
992,
14,
955,
199,
646,
1639,
63,
72,
1617,
14,
955,
199,
646,
3123,
1130,
14,
1001,
63,
698,
199,
646,
3123,
1130,
14,
842,
199,
646,
1639,
14,
2828,
14,
1178,
14,
992,
199,
646,
3123,
1130,
14,
14274,
199,
646,
1639,
14,
1208,
14,
7145,
199,
504,
1639,
14,
2190,
492,
2202,
199,
646,
3123,
1130,
14,
10031,
199,
646,
1639,
14,
1018,
14,
11346,
199,
646,
3123,
1130,
14,
5260,
421,
199,
533,
12090,
8,
7685,
14,
9816,
304,
339,
5124,
275,
359,
267,
661,
1178,
297,
283,
20965,
63,
4365,
63,
10778,
63,
9425,
659,
272,
1622,
339,
5331,
275,
359,
267,
6180,
14,
14907,
8,
288,
536,
534,
1899,
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,
2060,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
3933,
12,
3376,
63,
354,
534,
2060,
3855,
355,
661,
2019,
63,
2886,
297,
1709,
14,
4626,
8,
885,
29,
1176,
14,
1208,
14,
7145,
14,
2131,
12,
3376,
63,
354,
534,
2019,
4676,
3855,
355,
661,
374,
63,
11434,
297,
1709,
14,
5036,
8,
885,
29,
797,
12,
1720,
63,
505,
534,
20924,
2335,
626,
642,
922,
965,
1006,
3443,
1928,
7662,
26694,
3062,
3130,
3376,
63,
354,
534,
11434,
2004,
3855,
355,
661,
2473,
297,
1709,
14,
2183,
8,
3437,
63,
505,
534,
8030,
14,
4233,
4110,
503,
27392,
14,
12230,
878,
12,
5579,
436,
768,
8083,
15,
19616,
13,
15607,
4110,
297,
3747,
29,
549,
12,
1390,
63,
1267,
29,
1216,
12,
3376,
63,
354,
534,
2473,
297,
14370,
1524,
1176,
14,
1018,
14,
11346,
14,
5103,
8640,
8,
264,
14,
2014,
9097,
59,
1103,
87,
14,
32,
16341,
2807,
26712,
283,
8468,
282,
1686,
3434,
3130,
283,
3197,
2023,
395,
355,
661,
2123,
297,
1709,
14,
16577,
8,
3235,
29,
549,
12,
1390,
63,
1267,
29,
2194,
12,
3376,
63,
354,
534,
2123,
2287,
297,
4596,
29,
549,
1826,
355,
661,
374,
63,
7018,
297,
1709,
14,
5036,
8,
885,
29,
797,
12,
1720,
63,
505,
534,
20924,
2335,
3775,
314,
922,
883,
943,
1901,
642,
4628,
4770,
3130,
3376,
63,
354,
534,
7018,
2004,
3855,
355,
661,
374,
63,
2682,
297,
1709,
14,
5036,
8,
885,
29,
549,
12,
1720,
63,
505,
534,
20924,
2335,
3775,
642,
922,
1077,
506,
10184,
465,
4702,
14,
1910,
2416,
642,
3140,
402,
13794,
12639,
3130,
3376,
63,
354,
534,
2682,
3855,
355,
661,
602,
63,
11806,
297,
1709,
14,
4626,
8,
885,
29,
1176,
14,
1208,
14,
7145,
14,
2131,
12,
3376,
63,
354,
534,
602,
16538,
3855,
355,
661,
13834,
297,
1709,
14,
21910,
8,
2307,
29,
549,
12,
5802,
63,
475,
534,
3707,
297,
4596,
29,
549,
1826,
355,
661,
8311,
297,
1709,
14,
21910,
8,
2307,
29,
549,
12,
5802,
63,
475,
534,
3707,
297,
4596,
29,
549,
1826,
355,
661,
2246,
63,
354,
297,
1709,
14,
2183,
8,
885,
4581,
1390,
63,
1267,
29,
1216,
12,
3376,
63,
354,
534,
2246,
536,
297,
4596,
29,
549,
1826,
355,
661,
2019,
63,
354,
297,
1709,
14,
2183,
8,
885,
4581,
1390,
63,
1267,
29,
1216,
12,
3376,
63,
354,
534,
2019,
536,
297,
4596,
29,
549,
1826,
355,
661,
9071,
297,
1709,
14,
2183,
8,
885,
4581,
1390,
63,
1267,
29,
2299,
12,
4596,
29,
549,
1826,
355,
661,
1875,
63,
815,
63,
3455,
297,
1709,
14,
5036,
8,
885,
29,
797,
1826,
355,
661,
3306,
63,
2123,
63,
7811,
297,
1709,
14,
5036,
8,
885,
29,
797,
1826,
355,
661,
2634,
297,
1709,
14,
7624,
8,
2407,
63,
1131,
63,
354,
534,
751,
297,
4048,
63,
354,
534,
751,
63,
409,
297,
370,
534,
1178,
14,
2448,
297,
4596,
29,
549,
12,
1720,
63,
505,
534,
1918,
4652,
642,
922,
15006,
370,
14,
437,
922,
911,
664,
1006,
3443,
10009,
370,
1924,
402,
3932,
4652,
3130,
3376,
63,
354,
534,
2634,
3855,
355,
661,
751,
63,
6060,
297,
1709,
14,
7624,
8,
2407,
63,
1131,
63,
354,
534,
751,
297,
4048,
63,
354,
534,
751,
63,
409,
297,
370,
534,
1178,
14,
7980,
297,
4596,
29,
549,
12,
1720,
63,
505,
534,
16786,
3443,
367,
642,
922,
3130,
3376,
63,
354,
534,
751,
3443,
3855,
288,
2156,
288,
1511,
3126,
355,
283,
6198,
356,
756,
12,
355,
283,
3832,
63,
354,
356,
283,
751,
297,
355,
283,
3832,
63,
354,
63,
10019,
356,
283,
3707,
297,
288,
1660,
288,
9768,
2687,
992,
14,
1685,
12,
3123,
1130,
14,
14274,
14,
33,
14525,
1224,
395,
288,
19680,
1524,
355,
661,
1462,
297,
1639,
14,
2828,
14,
1178,
14,
992,
14,
1899,
2988,
4000,
288,
2156,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
23601,
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,
1238,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
2299,
12,
2973,
29,
549,
12,
1592,
63,
1080,
29,
549,
1826,
355,
661,
1238,
63,
344,
297,
1709,
14,
3901,
8,
2307,
29,
549,
12,
1592,
63,
1080,
29,
549,
1826,
355,
661,
698,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
2299,
12,
2973,
29,
549,
1826,
355,
661,
6352,
63,
585,
297,
1709,
14,
6254,
8,
2307,
29,
549,
1826,
355,
661,
1818,
63,
585,
297,
1709,
14,
6254,
8,
2307,
29,
549,
12,
1592,
63,
1080,
29,
549,
1826,
355,
661,
1287,
297,
1709,
14,
3901,
4000,
355,
661,
6537,
63,
1178,
297,
1709,
14,
5036,
8,
885,
29,
797,
1826,
355,
661,
3966,
297,
1709,
14,
4626,
8,
2495,
63,
2131,
63,
525,
29,
549,
12,
1592,
63,
1080,
29,
549,
1826,
355,
661,
5334,
297,
1709,
14,
4626,
8,
2495,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
metabrainz/picard
|
picard/ui/options/interface.py
|
3
|
16508
|
# -*- coding: utf-8 -*-
#
# Picard, the next-generation MusicBrainz tagger
#
# Copyright (C) 2007-2008 Lukáš Lalinský
# Copyright (C) 2008 Will
# Copyright (C) 2009, 2019-2021 Philipp Wolfer
# Copyright (C) 2011, 2013 Michael Wiencek
# Copyright (C) 2013, 2019 Wieland Hoffmann
# Copyright (C) 2013-2014, 2018, 2020-2021 Laurent Monin
# Copyright (C) 2016 Rahul Raturi
# Copyright (C) 2016-2018 Sambhav Kothari
# Copyright (C) 2017 Antonio Larrosa
# Copyright (C) 2018 Bob Swift
# Copyright (C) 2021 Gabriel Ferreira
#
# 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.
from functools import partial
import locale
import os.path
from PyQt5 import (
QtCore,
QtWidgets,
)
from PyQt5.QtCore import QStandardPaths
from picard.config import (
BoolOption,
ListOption,
TextOption,
get_config,
)
from picard.const import UI_LANGUAGES
from picard.util import icontheme
from picard.ui import PicardDialog
from picard.ui.moveable_list_view import MoveableListView
from picard.ui.options import (
OptionsPage,
register_options_page,
)
from picard.ui.theme import (
AVAILABLE_UI_THEMES,
OS_SUPPORTS_THEMES,
UiTheme,
)
from picard.ui.ui_options_interface import Ui_InterfaceOptionsPage
from picard.ui.util import enabledSlot
_default_starting_dir = QStandardPaths.writableLocation(QStandardPaths.HomeLocation)
class InterfaceOptionsPage(OptionsPage):
NAME = "interface"
TITLE = N_("User Interface")
PARENT = None
SORT_ORDER = 80
ACTIVE = True
HELP_URL = '/config/options_interface.html'
SEPARATOR = '—' * 5
TOOLBAR_BUTTONS = {
'add_directory_action': {
'label': N_('Add Folder'),
'icon': 'folder'
},
'add_files_action': {
'label': N_('Add Files'),
'icon': 'document-open'
},
'cluster_action': {
'label': N_('Cluster'),
'icon': 'picard-cluster'
},
'autotag_action': {
'label': N_('Lookup'),
'icon': 'picard-auto-tag'
},
'analyze_action': {
'label': N_('Scan'),
'icon': 'picard-analyze'
},
'browser_lookup_action': {
'label': N_('Lookup in Browser'),
'icon': 'lookup-musicbrainz'
},
'save_action': {
'label': N_('Save'),
'icon': 'document-save'
},
'view_info_action': {
'label': N_('Info'),
'icon': 'picard-edit-tags'
},
'remove_action': {
'label': N_('Remove'),
'icon': 'list-remove'
},
'submit_acoustid_action': {
'label': N_('Submit AcoustIDs'),
'icon': 'acoustid-fingerprinter'
},
'generate_fingerprints_action': {
'label': N_("Generate Fingerprints"),
'icon': 'fingerprint'
},
'play_file_action': {
'label': N_('Open in Player'),
'icon': 'play-music'
},
'cd_lookup_action': {
'label': N_('Lookup CD...'),
'icon': 'media-optical'
},
'tags_from_filenames_action': {
'label': N_('Parse File Names...'),
'icon': 'picard-tags-from-filename'
},
}
ACTION_NAMES = set(TOOLBAR_BUTTONS.keys())
options = [
BoolOption("setting", "toolbar_show_labels", True),
BoolOption("setting", "toolbar_multiselect", False),
BoolOption("setting", "builtin_search", True),
BoolOption("setting", "use_adv_search_syntax", False),
BoolOption("setting", "quit_confirmation", True),
TextOption("setting", "ui_language", ""),
TextOption("setting", "ui_theme", str(UiTheme.DEFAULT)),
BoolOption("setting", "filebrowser_horizontal_autoscroll", True),
BoolOption("setting", "starting_directory", False),
TextOption("setting", "starting_directory_path", _default_starting_dir),
TextOption("setting", "load_image_behavior", "append"),
ListOption("setting", "toolbar_layout", [
'add_directory_action',
'add_files_action',
'separator',
'cluster_action',
'separator',
'autotag_action',
'analyze_action',
'browser_lookup_action',
'separator',
'save_action',
'view_info_action',
'remove_action',
'separator',
'cd_lookup_action',
'separator',
'submit_acoustid_action',
]),
]
# Those are labels for theme display
_UI_THEME_LABELS = {
UiTheme.DEFAULT: {
'label': N_('Default'),
'desc': N_('The default color scheme based on the operating system display settings'),
},
UiTheme.DARK: {
'label': N_('Dark'),
'desc': N_('A dark display theme'),
},
UiTheme.LIGHT: {
'label': N_('Light'),
'desc': N_('A light display theme'),
},
UiTheme.SYSTEM: {
'label': N_('System'),
'desc': N_('The Qt5 theme configured in the desktop environment'),
},
}
def __init__(self, parent=None):
super().__init__(parent)
self.ui = Ui_InterfaceOptionsPage()
self.ui.setupUi(self)
self.ui.ui_theme.clear()
for theme in AVAILABLE_UI_THEMES:
label = self._UI_THEME_LABELS[theme]['label']
desc = self._UI_THEME_LABELS[theme]['desc']
self.ui.ui_theme.addItem(_(label), theme)
idx = self.ui.ui_theme.findData(theme)
self.ui.ui_theme.setItemData(idx, _(desc), QtCore.Qt.ToolTipRole)
self.ui.ui_theme.setCurrentIndex(self.ui.ui_theme.findData(UiTheme.DEFAULT))
self.ui.ui_language.addItem(_('System default'), '')
language_list = [(lang[0], lang[1], _(lang[2])) for lang in UI_LANGUAGES]
def fcmp(x):
return locale.strxfrm(x[2])
for lang_code, native, translation in sorted(language_list, key=fcmp):
if native and native != translation:
name = '%s (%s)' % (translation, native)
else:
name = translation
self.ui.ui_language.addItem(name, lang_code)
self.ui.starting_directory.stateChanged.connect(
partial(
enabledSlot,
self.ui.starting_directory_path.setEnabled
)
)
self.ui.starting_directory.stateChanged.connect(
partial(
enabledSlot,
self.ui.starting_directory_browse.setEnabled
)
)
self.ui.starting_directory_browse.clicked.connect(self.starting_directory_browse)
self.ui.add_button.clicked.connect(self.add_to_toolbar)
self.ui.insert_separator_button.clicked.connect(self.insert_separator)
self.ui.remove_button.clicked.connect(self.remove_action)
self.move_view = MoveableListView(self.ui.toolbar_layout_list, self.ui.up_button,
self.ui.down_button, self.update_action_buttons)
self.update_buttons = self.move_view.update_buttons
if not OS_SUPPORTS_THEMES:
self.ui.ui_theme_container.hide()
def load(self):
config = get_config()
self.ui.toolbar_show_labels.setChecked(config.setting["toolbar_show_labels"])
self.ui.toolbar_multiselect.setChecked(config.setting["toolbar_multiselect"])
self.ui.builtin_search.setChecked(config.setting["builtin_search"])
self.ui.use_adv_search_syntax.setChecked(config.setting["use_adv_search_syntax"])
self.ui.quit_confirmation.setChecked(config.setting["quit_confirmation"])
current_ui_language = config.setting["ui_language"]
self.ui.ui_language.setCurrentIndex(self.ui.ui_language.findData(current_ui_language))
self.ui.filebrowser_horizontal_autoscroll.setChecked(config.setting["filebrowser_horizontal_autoscroll"])
self.ui.starting_directory.setChecked(config.setting["starting_directory"])
self.ui.starting_directory_path.setText(config.setting["starting_directory_path"])
self.populate_action_list()
self.ui.toolbar_layout_list.setCurrentRow(0)
current_theme = UiTheme(config.setting["ui_theme"])
self.ui.ui_theme.setCurrentIndex(self.ui.ui_theme.findData(current_theme))
self.update_buttons()
def save(self):
config = get_config()
config.setting["toolbar_show_labels"] = self.ui.toolbar_show_labels.isChecked()
config.setting["toolbar_multiselect"] = self.ui.toolbar_multiselect.isChecked()
config.setting["builtin_search"] = self.ui.builtin_search.isChecked()
config.setting["use_adv_search_syntax"] = self.ui.use_adv_search_syntax.isChecked()
config.setting["quit_confirmation"] = self.ui.quit_confirmation.isChecked()
self.tagger.window.update_toolbar_style()
new_theme_setting = str(self.ui.ui_theme.itemData(self.ui.ui_theme.currentIndex()))
new_language = self.ui.ui_language.itemData(self.ui.ui_language.currentIndex())
restart_warning = None
if new_theme_setting != config.setting["ui_theme"]:
restart_warning_title = _('Theme changed')
restart_warning = _('You have changed the application theme. You have to restart Picard in order for the change to take effect.')
if new_theme_setting == str(UiTheme.SYSTEM):
restart_warning += '\n\n' + _(
'Please note that using the system theme might cause the user interface to be not shown correctly. '
'If this is the case select the "Default" theme option to use Picard\'s default theme again.'
)
elif new_language != config.setting["ui_language"]:
restart_warning_title = _('Language changed')
restart_warning = _('You have changed the interface language. You have to restart Picard in order for the change to take effect.')
if restart_warning:
dialog = QtWidgets.QMessageBox(
QtWidgets.QMessageBox.Information,
restart_warning_title,
restart_warning,
QtWidgets.QMessageBox.Ok,
self)
dialog.exec_()
config.setting["ui_theme"] = new_theme_setting
config.setting["ui_language"] = self.ui.ui_language.itemData(self.ui.ui_language.currentIndex())
config.setting["filebrowser_horizontal_autoscroll"] = self.ui.filebrowser_horizontal_autoscroll.isChecked()
config.setting["starting_directory"] = self.ui.starting_directory.isChecked()
config.setting["starting_directory_path"] = os.path.normpath(self.ui.starting_directory_path.text())
self.update_layout_config()
def restore_defaults(self):
super().restore_defaults()
self.update_buttons()
def starting_directory_browse(self):
item = self.ui.starting_directory_path
path = QtWidgets.QFileDialog.getExistingDirectory(self, "", item.text())
if path:
path = os.path.normpath(path)
item.setText(path)
def _get_icon_from_name(self, name):
return self.TOOLBAR_BUTTONS[name]['icon']
def _insert_item(self, action, index=None):
list_item = ToolbarListItem(action)
list_item.setToolTip(_('Drag and Drop to re-order'))
if action in self.TOOLBAR_BUTTONS:
# TODO: Remove temporary workaround once https://github.com/python-babel/babel/issues/415 has been resolved.
babel_415_workaround = self.TOOLBAR_BUTTONS[action]['label']
list_item.setText(_(babel_415_workaround))
list_item.setIcon(icontheme.lookup(self._get_icon_from_name(action), icontheme.ICON_SIZE_MENU))
else:
list_item.setText(self.SEPARATOR)
if index is not None:
self.ui.toolbar_layout_list.insertItem(index, list_item)
else:
self.ui.toolbar_layout_list.addItem(list_item)
return list_item
def _all_list_items(self):
return [self.ui.toolbar_layout_list.item(i).action_name
for i in range(self.ui.toolbar_layout_list.count())]
def _added_actions(self):
actions = self._all_list_items()
return set(action for action in actions if action != 'separator')
def populate_action_list(self):
self.ui.toolbar_layout_list.clear()
config = get_config()
for name in config.setting['toolbar_layout']:
if name in self.ACTION_NAMES or name == 'separator':
self._insert_item(name)
def update_action_buttons(self):
self.ui.add_button.setEnabled(self._added_actions() != self.ACTION_NAMES)
def add_to_toolbar(self):
display_list = set.difference(self.ACTION_NAMES, self._added_actions())
selected_action, ok = AddActionDialog.get_selected_action(display_list, self)
if ok:
list_item = self._insert_item(selected_action, self.ui.toolbar_layout_list.currentRow() + 1)
self.ui.toolbar_layout_list.setCurrentItem(list_item)
self.update_buttons()
def insert_separator(self):
insert_index = self.ui.toolbar_layout_list.currentRow() + 1
self._insert_item('separator', insert_index)
def remove_action(self):
item = self.ui.toolbar_layout_list.takeItem(self.ui.toolbar_layout_list.currentRow())
del item
self.update_buttons()
def update_layout_config(self):
config = get_config()
config.setting['toolbar_layout'] = self._all_list_items()
self._update_toolbar()
def _update_toolbar(self):
widget = self.parent()
while not isinstance(widget, QtWidgets.QMainWindow):
widget = widget.parent()
# Call the main window's create toolbar method
widget.create_action_toolbar()
widget.set_tab_order()
class ToolbarListItem(QtWidgets.QListWidgetItem):
def __init__(self, action_name, *args, **kwargs):
super().__init__(*args, **kwargs)
self.action_name = action_name
class AddActionDialog(PicardDialog):
def __init__(self, action_list, *args, **kwargs):
super().__init__(*args, **kwargs)
self.setWindowModality(QtCore.Qt.WindowModal)
layout = QtWidgets.QVBoxLayout(self)
layout.setSizeConstraint(QtWidgets.QLayout.SetFixedSize)
# TODO: Remove temporary workaround once https://github.com/python-babel/babel/issues/415 has been resolved.
babel_415_workaround_list = []
for action in action_list:
babel_415_workaround = self.parent().TOOLBAR_BUTTONS[action]['label']
babel_415_workaround_list.append([_(babel_415_workaround), action])
self.action_list = sorted(babel_415_workaround_list)
self.combo_box = QtWidgets.QComboBox(self)
self.combo_box.addItems([label for label, action in self.action_list])
layout.addWidget(self.combo_box)
buttons = QtWidgets.QDialogButtonBox(
QtWidgets.QDialogButtonBox.Ok | QtWidgets.QDialogButtonBox.Cancel,
QtCore.Qt.Horizontal, self)
buttons.accepted.connect(self.accept)
buttons.rejected.connect(self.reject)
layout.addWidget(buttons)
def selected_action(self):
return self.action_list[self.combo_box.currentIndex()][1]
@staticmethod
def get_selected_action(action_list, parent=None):
dialog = AddActionDialog(action_list, parent)
result = dialog.exec_()
selected_action = dialog.selected_action()
return (selected_action, result == QtWidgets.QDialog.Accepted)
register_options_page(InterfaceOptionsPage)
|
gpl-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
510,
530,
1005,
12,
314,
2163,
13,
15043,
28919,
9916,
34,
6322,
90,
1947,
836,
199,
3,
199,
3,
1898,
334,
35,
9,
10219,
13,
9300,
491,
3210,
11302,
27273,
491,
279,
262,
1339,
128,
122,
199,
3,
1898,
334,
35,
9,
9079,
12823,
199,
3,
1898,
334,
35,
9,
8937,
12,
20312,
13,
22150,
11308,
1638,
802,
644,
79,
276,
281,
199,
3,
1898,
334,
35,
9,
7760,
12,
6171,
16922,
644,
12837,
75,
199,
3,
1898,
334,
35,
9,
6171,
12,
20312,
644,
14769,
460,
869,
1997,
20059,
199,
3,
1898,
334,
35,
9,
6171,
13,
7280,
12,
14894,
12,
25455,
13,
22150,
7964,
608,
343,
10953,
262,
199,
3,
1898,
334,
35,
9,
7800,
3898,
72,
348,
820,
292,
2302,
199,
3,
1898,
334,
35,
9,
7800,
13,
12682,
428,
11020,
72,
1214,
1804,
79,
273,
759,
199,
3,
1898,
334,
35,
9,
9708,
437,
343,
265,
2308,
491,
285,
293,
2231,
199,
3,
1898,
334,
35,
9,
14894,
699,
2873,
16666,
2949,
199,
3,
1898,
334,
35,
9,
499,
15385,
598,
371,
322,
352,
481,
281,
264,
20936,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
199,
3,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
199,
3,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
11315,
13,
10067,
12,
8217,
14,
421,
199,
504,
9143,
492,
7417,
199,
646,
5867,
199,
646,
747,
14,
515,
199,
199,
504,
14084,
21,
492,
334,
272,
10565,
12,
272,
17113,
12,
199,
9,
199,
504,
14084,
21,
14,
10901,
492,
1413,
9232,
11804,
199,
199,
504,
26559,
1005,
14,
888,
492,
334,
272,
19287,
2602,
12,
272,
3820,
2602,
12,
272,
4516,
2602,
12,
272,
664,
63,
888,
12,
199,
9,
199,
504,
26559,
1005,
14,
1297,
492,
14041,
63,
26886,
199,
504,
26559,
1005,
14,
1974,
492,
7016,
7915,
199,
199,
504,
26559,
1005,
14,
1907,
492,
510,
530,
1005,
5619,
199,
504,
26559,
1005,
14,
1907,
14,
1185,
461,
63,
513,
63,
1345,
492,
14171,
461,
23239,
199,
504,
26559,
1005,
14,
1907,
14,
1419,
492,
334,
272,
8394,
3276,
12,
272,
2274,
63,
1419,
63,
1606,
12,
199,
9,
199,
504,
26559,
1005,
14,
1907,
14,
7915,
492,
334,
272,
437,
54,
6593,
2617,
63,
6379,
63,
18061,
22076,
12,
272,
4403,
63,
10640,
51,
63,
18061,
22076,
12,
272,
32471,
16849,
12,
199,
9,
199,
504,
26559,
1005,
14,
1907,
14,
1907,
63,
1419,
63,
3266,
492,
32471,
63,
4267,
4558,
3276,
199,
504,
26559,
1005,
14,
1907,
14,
1974,
492,
5223,
15183,
421,
199,
63,
885,
63,
15769,
63,
694,
275,
1413,
9232,
11804,
14,
15053,
6592,
8,
49,
9232,
11804,
14,
12054,
6592,
9,
421,
199,
533,
14816,
4558,
3276,
8,
4558,
3276,
304,
339,
13637,
275,
298,
3266,
2,
272,
377,
16507,
275,
653,
14332,
1899,
14816,
531,
272,
19499,
275,
488,
272,
428,
2596,
63,
12125,
275,
5939,
272,
26577,
275,
715,
272,
29269,
63,
2632,
275,
1994,
888,
15,
1419,
63,
3266,
14,
1360,
7,
272,
14782,
275,
283,
20292,
7,
627,
959,
272,
2296,
2228,
13895,
63,
13272,
51,
275,
469,
267,
283,
525,
63,
3619,
63,
1287,
356,
469,
288,
283,
1302,
356,
653,
11252,
1123,
29121,
659,
288,
283,
4677,
356,
283,
3741,
7,
267,
1660,
267,
283,
525,
63,
1725,
63,
1287,
356,
469,
288,
283,
1302,
356,
653,
11252,
1123,
16920,
659,
288,
283,
4677,
356,
283,
3554,
13,
1490,
7,
267,
1660,
267,
283,
4201,
63,
1287,
356,
469,
288,
283,
1302,
356,
653,
11252,
9581,
659,
288,
283,
4677,
356,
283,
12475,
1005,
13,
4201,
7,
267,
1660,
267,
283,
6898,
357,
643,
63,
1287,
356,
469,
288,
283,
1302,
356,
653,
11252,
7521,
659,
288,
283,
4677,
356,
283,
12475,
1005,
13,
2495,
13,
1450,
7,
267,
1660,
267,
283,
21184,
63,
1287,
356,
469,
288,
283,
1302,
356,
653,
11252,
15936,
659,
288,
283,
4677,
356,
283,
12475,
1005,
13,
21184,
7,
267,
1660,
267,
283,
5750,
63,
3892,
63,
1287,
356,
469,
288,
283,
1302,
356,
653,
11252,
7521,
315,
27620,
659,
288,
283,
4677,
356,
283,
3892,
13,
6553,
338,
2894,
6322,
90,
7,
267,
1660,
267,
283,
2117,
63,
1287,
356,
469,
288,
283,
1302,
356,
653,
11252,
8229,
659,
288,
283,
4677,
356,
283,
3554,
13,
2117,
7,
267,
1660,
267,
283,
1345,
63,
815,
63,
1287,
356,
469,
288,
283,
1302,
356,
653,
11252,
2354,
659,
288,
283,
4677,
356,
283,
12475,
1005,
13,
3773,
13,
2969,
7,
267,
1660,
267,
283,
2168,
63,
1287,
356,
469,
288,
283,
1302,
356,
653,
11252,
5587,
659,
288,
283,
4677,
356,
283,
513,
13,
2168,
7,
267,
1660,
267,
283,
7275,
63,
13286,
833,
344,
63,
1287,
356,
469,
288,
283,
1302,
356,
653,
11252,
17187,
437,
331,
833,
12818,
659,
288,
283,
4677,
356,
283,
13286,
833,
344,
13,
70,
7886,
11835,
7,
267,
1660,
267,
283,
4208,
63,
15077,
83,
63,
1287,
356,
469,
288,
283,
1302,
356,
653,
14332,
6864,
481,
9429,
83,
1288,
288,
283,
4677,
356,
283,
15077,
7,
267,
1660,
267,
283,
2802,
63,
493,
63,
1287,
356,
469,
288,
283,
1302,
356,
653,
11252,
4299,
315,
25610,
659,
288,
283,
4677,
356,
283,
2802,
13,
20544,
7,
267,
1660,
267,
283,
2866,
63,
3892,
63,
1287,
356,
469,
288,
283,
1302
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
510,
530,
1005,
12,
314,
2163,
13,
15043,
28919,
9916,
34,
6322,
90,
1947,
836,
199,
3,
199,
3,
1898,
334,
35,
9,
10219,
13,
9300,
491,
3210,
11302,
27273,
491,
279,
262,
1339,
128,
122,
199,
3,
1898,
334,
35,
9,
9079,
12823,
199,
3,
1898,
334,
35,
9,
8937,
12,
20312,
13,
22150,
11308,
1638,
802,
644,
79,
276,
281,
199,
3,
1898,
334,
35,
9,
7760,
12,
6171,
16922,
644,
12837,
75,
199,
3,
1898,
334,
35,
9,
6171,
12,
20312,
644,
14769,
460,
869,
1997,
20059,
199,
3,
1898,
334,
35,
9,
6171,
13,
7280,
12,
14894,
12,
25455,
13,
22150,
7964,
608,
343,
10953,
262,
199,
3,
1898,
334,
35,
9,
7800,
3898,
72,
348,
820,
292,
2302,
199,
3,
1898,
334,
35,
9,
7800,
13,
12682,
428,
11020,
72,
1214,
1804,
79,
273,
759,
199,
3,
1898,
334,
35,
9,
9708,
437,
343,
265,
2308,
491,
285,
293,
2231,
199,
3,
1898,
334,
35,
9,
14894,
699,
2873,
16666,
2949,
199,
3,
1898,
334,
35,
9,
499,
15385,
598,
371,
322,
352,
481,
281,
264,
20936,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
199,
3,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
199,
3,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
11315,
13,
10067,
12,
8217,
14,
421,
199,
504,
9143,
492,
7417,
199,
646,
5867,
199,
646,
747,
14,
515,
199,
199,
504,
14084,
21,
492,
334,
272,
10565,
12,
272,
17113,
12,
199,
9,
199,
504,
14084,
21,
14,
10901,
492,
1413,
9232,
11804,
199,
199,
504,
26559,
1005,
14,
888,
492,
334,
272,
19287,
2602,
12,
272,
3820,
2602,
12,
272,
4516,
2602,
12,
272,
664,
63,
888,
12,
199,
9,
199,
504,
26559,
1005,
14,
1297,
492,
14041,
63,
26886,
199,
504,
26559,
1005,
14,
1974,
492,
7016,
7915,
199,
199,
504,
26559,
1005,
14,
1907,
492,
510,
530,
1005,
5619,
199,
504,
26559,
1005,
14,
1907,
14,
1185,
461,
63,
513,
63,
1345,
492,
14171,
461,
23239,
199,
504,
26559,
1005,
14,
1907,
14,
1419,
492,
334,
272,
8394,
3276,
12,
272,
2274,
63,
1419,
63,
1606,
12,
199,
9,
199,
504,
26559,
1005,
14,
1907,
14,
7915,
492,
334,
272,
437,
54,
6593,
2617,
63,
6379,
63,
18061,
22076,
12,
272,
4403,
63,
10640,
51,
63,
18061,
22076,
12,
272,
32471,
16849,
12,
199,
9,
199,
504,
26559,
1005,
14,
1907,
14,
1907,
63,
1419,
63,
3266,
492,
32471,
63,
4267,
4558,
3276,
199,
504,
26559,
1005,
14,
1907,
14,
1974,
492,
5223,
15183,
421,
199,
63,
885,
63,
15769,
63,
694,
275,
1413,
9232,
11804,
14,
15053,
6592,
8,
49,
9232,
11804,
14,
12054,
6592,
9,
421,
199,
533,
14816,
4558,
3276,
8,
4558,
3276,
304,
339,
13637,
275,
298,
3266,
2,
272,
377,
16507,
275,
653,
14332,
1899,
14816,
531,
272,
19499,
275,
488,
272,
428,
2596,
63,
12125,
275,
5939,
272,
26577,
275,
715,
272,
29269,
63,
2632,
275,
1994,
888,
15,
1419,
63,
3266,
14,
1360,
7,
272,
14782,
275,
283,
20292,
7,
627,
959,
272,
2296,
2228,
13895,
63,
13272,
51,
275,
469,
267,
283,
525,
63,
3619,
63,
1287,
356,
469,
288,
283,
1302,
356,
653,
11252,
1123,
29121,
659,
288,
283,
4677,
356,
283,
3741,
7,
267,
1660,
267,
283,
525,
63,
1725,
63,
1287,
356,
469,
288,
283,
1302,
356,
653,
11252,
1123,
16920,
659,
288,
283,
4677,
356,
283,
3554,
13,
1490,
7,
267,
1660,
267,
283,
4201,
63,
1287,
356,
469,
288,
283,
1302,
356,
653,
11252,
9581,
659,
288,
283,
4677,
356,
283,
12475,
1005,
13,
4201,
7,
267,
1660,
267,
283,
6898,
357,
643,
63,
1287,
356,
469,
288,
283,
1302,
356,
653,
11252,
7521,
659,
288,
283,
4677,
356,
283,
12475,
1005,
13,
2495,
13,
1450,
7,
267,
1660,
267,
283,
21184,
63,
1287,
356,
469,
288,
283,
1302,
356,
653,
11252,
15936,
659,
288,
283,
4677,
356,
283,
12475,
1005,
13,
21184,
7,
267,
1660,
267,
283,
5750,
63,
3892,
63,
1287,
356,
469,
288,
283,
1302,
356,
653,
11252,
7521,
315,
27620,
659,
288,
283,
4677,
356,
283,
3892,
13,
6553,
338,
2894,
6322,
90,
7,
267,
1660,
267,
283,
2117,
63,
1287,
356,
469,
288,
283,
1302,
356,
653,
11252,
8229,
659,
288,
283,
4677,
356,
283,
3554,
13,
2117,
7,
267,
1660,
267,
283,
1345,
63,
815,
63,
1287,
356,
469,
288,
283,
1302,
356,
653,
11252,
2354,
659,
288,
283,
4677,
356,
283,
12475,
1005,
13,
3773,
13,
2969,
7,
267,
1660,
267,
283,
2168,
63,
1287,
356,
469,
288,
283,
1302,
356,
653,
11252,
5587,
659,
288,
283,
4677,
356,
283,
513,
13,
2168,
7,
267,
1660,
267,
283,
7275,
63,
13286,
833,
344,
63,
1287,
356,
469,
288,
283,
1302,
356,
653,
11252,
17187,
437,
331,
833,
12818,
659,
288,
283,
4677,
356,
283,
13286,
833,
344,
13,
70,
7886,
11835,
7,
267,
1660,
267,
283,
4208,
63,
15077,
83,
63,
1287,
356,
469,
288,
283,
1302,
356,
653,
14332,
6864,
481,
9429,
83,
1288,
288,
283,
4677,
356,
283,
15077,
7,
267,
1660,
267,
283,
2802,
63,
493,
63,
1287,
356,
469,
288,
283,
1302,
356,
653,
11252,
4299,
315,
25610,
659,
288,
283,
4677,
356,
283,
2802,
13,
20544,
7,
267,
1660,
267,
283,
2866,
63,
3892,
63,
1287,
356,
469,
288,
283,
1302,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ESILV-CFR-2016/ros_raspi_pkg
|
devel_isolated/rostestm/_setup_util.py
|
2
|
12353
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Software License Agreement (BSD License)
#
# Copyright (c) 2012, Willow Garage, 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 Willow Garage, 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 generates shell code for the setup.SHELL scripts to set environment variables'''
from __future__ import print_function
import argparse
import copy
import errno
import os
import platform
import sys
CATKIN_MARKER_FILE = '.catkin'
system = platform.system()
IS_DARWIN = (system == 'Darwin')
IS_WINDOWS = (system == 'Windows')
# subfolder of workspace prepended to CMAKE_PREFIX_PATH
ENV_VAR_SUBFOLDERS = {
'CMAKE_PREFIX_PATH': '',
'CPATH': 'include',
'LD_LIBRARY_PATH' if not IS_DARWIN else 'DYLD_LIBRARY_PATH': ['lib', os.path.join('lib', 'x86_64-linux-gnu')],
'PATH': 'bin',
'PKG_CONFIG_PATH': [os.path.join('lib', 'pkgconfig'), os.path.join('lib', 'x86_64-linux-gnu', 'pkgconfig')],
'PYTHONPATH': 'lib/python2.7/dist-packages',
}
def rollback_env_variables(environ, env_var_subfolders):
'''
Generate shell code to reset environment variables
by unrolling modifications based on all workspaces in CMAKE_PREFIX_PATH.
This does not cover modifications performed by environment hooks.
'''
lines = []
unmodified_environ = copy.copy(environ)
for key in sorted(env_var_subfolders.keys()):
subfolders = env_var_subfolders[key]
if not isinstance(subfolders, list):
subfolders = [subfolders]
for subfolder in subfolders:
value = _rollback_env_variable(unmodified_environ, key, subfolder)
if value is not None:
environ[key] = value
lines.append(assignment(key, value))
if lines:
lines.insert(0, comment('reset environment variables by unrolling modifications based on all workspaces in CMAKE_PREFIX_PATH'))
return lines
def _rollback_env_variable(environ, name, subfolder):
'''
For each catkin workspace in CMAKE_PREFIX_PATH remove the first entry from env[NAME] matching workspace + subfolder.
:param subfolder: str '' or subfoldername that may start with '/'
:returns: the updated value of the environment variable.
'''
value = environ[name] if name in environ else ''
env_paths = [path for path in value.split(os.pathsep) if path]
value_modified = False
if subfolder:
if subfolder.startswith(os.path.sep) or (os.path.altsep and subfolder.startswith(os.path.altsep)):
subfolder = subfolder[1:]
if subfolder.endswith(os.path.sep) or (os.path.altsep and subfolder.endswith(os.path.altsep)):
subfolder = subfolder[:-1]
for ws_path in _get_workspaces(environ, include_fuerte=True, include_non_existing=True):
path_to_find = os.path.join(ws_path, subfolder) if subfolder else ws_path
path_to_remove = None
for env_path in env_paths:
env_path_clean = env_path[:-1] if env_path and env_path[-1] in [os.path.sep, os.path.altsep] else env_path
if env_path_clean == path_to_find:
path_to_remove = env_path
break
if path_to_remove:
env_paths.remove(path_to_remove)
value_modified = True
new_value = os.pathsep.join(env_paths)
return new_value if value_modified else None
def _get_workspaces(environ, include_fuerte=False, include_non_existing=False):
'''
Based on CMAKE_PREFIX_PATH return all catkin workspaces.
:param include_fuerte: The flag if paths starting with '/opt/ros/fuerte' should be considered workspaces, ``bool``
'''
# get all cmake prefix paths
env_name = 'CMAKE_PREFIX_PATH'
value = environ[env_name] if env_name in environ else ''
paths = [path for path in value.split(os.pathsep) if path]
# remove non-workspace paths
workspaces = [path for path in paths if os.path.isfile(os.path.join(path, CATKIN_MARKER_FILE)) or (include_fuerte and path.startswith('/opt/ros/fuerte')) or (include_non_existing and not os.path.exists(path))]
return workspaces
def prepend_env_variables(environ, env_var_subfolders, workspaces):
'''
Generate shell code to prepend environment variables
for the all workspaces.
'''
lines = []
lines.append(comment('prepend folders of workspaces to environment variables'))
paths = [path for path in workspaces.split(os.pathsep) if path]
prefix = _prefix_env_variable(environ, 'CMAKE_PREFIX_PATH', paths, '')
lines.append(prepend(environ, 'CMAKE_PREFIX_PATH', prefix))
for key in sorted([key for key in env_var_subfolders.keys() if key != 'CMAKE_PREFIX_PATH']):
subfolder = env_var_subfolders[key]
prefix = _prefix_env_variable(environ, key, paths, subfolder)
lines.append(prepend(environ, key, prefix))
return lines
def _prefix_env_variable(environ, name, paths, subfolders):
'''
Return the prefix to prepend to the environment variable NAME, adding any path in NEW_PATHS_STR without creating duplicate or empty items.
'''
value = environ[name] if name in environ else ''
environ_paths = [path for path in value.split(os.pathsep) if path]
checked_paths = []
for path in paths:
if not isinstance(subfolders, list):
subfolders = [subfolders]
for subfolder in subfolders:
path_tmp = path
if subfolder:
path_tmp = os.path.join(path_tmp, subfolder)
# exclude any path already in env and any path we already added
if path_tmp not in environ_paths and path_tmp not in checked_paths:
checked_paths.append(path_tmp)
prefix_str = os.pathsep.join(checked_paths)
if prefix_str != '' and environ_paths:
prefix_str += os.pathsep
return prefix_str
def assignment(key, value):
if not IS_WINDOWS:
return 'export %s="%s"' % (key, value)
else:
return 'set %s=%s' % (key, value)
def comment(msg):
if not IS_WINDOWS:
return '# %s' % msg
else:
return 'REM %s' % msg
def prepend(environ, key, prefix):
if key not in environ or not environ[key]:
return assignment(key, prefix)
if not IS_WINDOWS:
return 'export %s="%s$%s"' % (key, prefix, key)
else:
return 'set %s=%s%%%s%%' % (key, prefix, key)
def find_env_hooks(environ, cmake_prefix_path):
'''
Generate shell code with found environment hooks
for the all workspaces.
'''
lines = []
lines.append(comment('found environment hooks in workspaces'))
generic_env_hooks = []
generic_env_hooks_workspace = []
specific_env_hooks = []
specific_env_hooks_workspace = []
generic_env_hooks_by_filename = {}
specific_env_hooks_by_filename = {}
generic_env_hook_ext = 'bat' if IS_WINDOWS else 'sh'
specific_env_hook_ext = environ['CATKIN_SHELL'] if not IS_WINDOWS and 'CATKIN_SHELL' in environ and environ['CATKIN_SHELL'] else None
# remove non-workspace paths
workspaces = [path for path in cmake_prefix_path.split(os.pathsep) if path and os.path.isfile(os.path.join(path, CATKIN_MARKER_FILE))]
for workspace in reversed(workspaces):
env_hook_dir = os.path.join(workspace, 'etc', 'catkin', 'profile.d')
if os.path.isdir(env_hook_dir):
for filename in sorted(os.listdir(env_hook_dir)):
if filename.endswith('.%s' % generic_env_hook_ext):
# remove previous env hook with same name if present
if filename in generic_env_hooks_by_filename:
i = generic_env_hooks.index(generic_env_hooks_by_filename[filename])
generic_env_hooks.pop(i)
generic_env_hooks_workspace.pop(i)
# append env hook
generic_env_hooks.append(os.path.join(env_hook_dir, filename))
generic_env_hooks_workspace.append(workspace)
generic_env_hooks_by_filename[filename] = generic_env_hooks[-1]
elif specific_env_hook_ext is not None and filename.endswith('.%s' % specific_env_hook_ext):
# remove previous env hook with same name if present
if filename in specific_env_hooks_by_filename:
i = specific_env_hooks.index(specific_env_hooks_by_filename[filename])
specific_env_hooks.pop(i)
specific_env_hooks_workspace.pop(i)
# append env hook
specific_env_hooks.append(os.path.join(env_hook_dir, filename))
specific_env_hooks_workspace.append(workspace)
specific_env_hooks_by_filename[filename] = specific_env_hooks[-1]
env_hooks = generic_env_hooks + specific_env_hooks
env_hooks_workspace = generic_env_hooks_workspace + specific_env_hooks_workspace
count = len(env_hooks)
lines.append(assignment('_CATKIN_ENVIRONMENT_HOOKS_COUNT', count))
for i in range(count):
lines.append(assignment('_CATKIN_ENVIRONMENT_HOOKS_%d' % i, env_hooks[i]))
lines.append(assignment('_CATKIN_ENVIRONMENT_HOOKS_%d_WORKSPACE' % i, env_hooks_workspace[i]))
return lines
def _parse_arguments(args=None):
parser = argparse.ArgumentParser(description='Generates code blocks for the setup.SHELL script.')
parser.add_argument('--extend', action='store_true', help='Skip unsetting previous environment variables to extend context')
return parser.parse_known_args(args=args)[0]
if __name__ == '__main__':
try:
try:
args = _parse_arguments()
except Exception as e:
print(e, file=sys.stderr)
sys.exit(1)
# environment at generation time
CMAKE_PREFIX_PATH = '/home/viki/catkin_ws/devel_isolated/beginner_tutorials;/home/viki/catkin_ws/devel;/opt/ros/indigo'.split(';')
# prepend current workspace if not already part of CPP
base_path = os.path.dirname(__file__)
if base_path not in CMAKE_PREFIX_PATH:
CMAKE_PREFIX_PATH.insert(0, base_path)
CMAKE_PREFIX_PATH = os.pathsep.join(CMAKE_PREFIX_PATH)
environ = dict(os.environ)
lines = []
if not args.extend:
lines += rollback_env_variables(environ, ENV_VAR_SUBFOLDERS)
lines += prepend_env_variables(environ, ENV_VAR_SUBFOLDERS, CMAKE_PREFIX_PATH)
lines += find_env_hooks(environ, CMAKE_PREFIX_PATH)
print('\n'.join(lines))
# need to explicitly flush the output
sys.stdout.flush()
except IOError as e:
# and catch potantial "broken pipe" if stdout is not writable
# which can happen when piping the output to a file but the disk is full
if e.errno == errno.EPIPE:
print(e, file=sys.stderr)
sys.exit(2)
raise
sys.exit(0)
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
2290,
844,
28629,
334,
15400,
844,
9,
199,
3,
199,
3,
1898,
334,
67,
9,
6029,
12,
644,
382,
674,
598,
285,
474,
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,
199,
3,
787,
7647,
26,
199,
3,
199,
3,
221,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
259,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
221,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
199,
3,
259,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
199,
3,
259,
6450,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
199,
3,
259,
543,
314,
4084,
14,
199,
3,
221,
627,
11443,
314,
536,
402,
644,
382,
674,
598,
285,
474,
12,
3277,
14,
6590,
314,
1561,
402,
2399,
199,
3,
259,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
199,
3,
259,
687,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
199,
3,
2381,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
199,
3,
5877,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
199,
3,
9716,
12,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
199,
3,
5400,
2845,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
199,
3,
9102,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
199,
3,
9817,
2401,
5258,
1821,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
199,
3,
5603,
12,
1549,
7056,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
199,
3,
1821,
9683,
5738,
1634,
2334,
4815,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
199,
3,
9726,
1634,
9712,
9784,
14,
199,
199,
2344,
2765,
570,
12821,
5218,
1233,
367,
314,
3272,
14,
29085,
10554,
370,
663,
3734,
2860,
2344,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
646,
7534,
199,
646,
1331,
199,
646,
7554,
199,
646,
747,
199,
646,
4298,
199,
646,
984,
199,
199,
11206,
43,
568,
63,
18997,
63,
3817,
275,
1987,
3385,
19269,
7,
199,
199,
2253,
275,
4298,
14,
2253,
342,
199,
1311,
63,
36,
689,
7941,
275,
334,
2253,
508,
283,
31065,
358,
199,
1311,
63,
20509,
275,
334,
2253,
508,
283,
8647,
358,
199,
199,
3,
1007,
3741,
402,
14466,
20247,
370,
445,
18421,
63,
6351,
63,
3243,
199,
9984,
63,
5568,
63,
6348,
38,
5104,
3960,
275,
469,
272,
283,
30250,
63,
6351,
63,
3243,
356,
3260,
272,
283,
35,
3243,
356,
283,
2613,
297,
272,
283,
6533,
63,
16983,
63,
3243,
7,
340,
440,
2281,
63,
36,
689,
7941,
587,
283,
11446,
6533,
63,
16983,
63,
3243,
356,
788,
773,
297,
747,
14,
515,
14,
904,
360,
773,
297,
283,
88,
1184,
63,
772,
13,
5135,
13,
3689,
2665,
272,
283,
3243,
356,
283,
1393,
297,
272,
283,
18150,
63,
5569,
63,
3243,
356,
359,
736,
14,
515,
14,
904,
360,
773,
297,
283,
4600,
888,
659,
747,
14,
515,
14,
904,
360,
773,
297,
283,
88,
1184,
63,
772,
13,
5135,
13,
3689,
297,
283,
4600,
888,
2665,
272,
283,
29266,
356,
283,
773,
15,
1548,
18,
14,
23,
15,
2686,
13,
5154,
297,
199,
93,
421,
199,
318,
16475,
63,
1813,
63,
3669,
8,
2314,
12,
2589,
63,
1391,
63,
954,
15171,
304,
272,
1449,
272,
7958,
5218,
1233,
370,
5305,
3734,
2860,
272,
701,
625,
31562,
23070,
4079,
641,
1006,
1736,
10749,
315,
445,
18421,
63,
6351,
63,
3243,
14,
272,
961,
1630,
440,
8486,
23070,
10585,
701,
3734,
12604,
14,
272,
1449,
272,
2385,
275,
942,
272,
24214,
63,
2314,
275,
1331,
14,
1574,
8,
2314,
9,
272,
367,
790,
315,
3355,
8,
1813,
63,
1391,
63,
954,
15171,
14,
1612,
5109,
267,
1007,
15171,
275,
2589,
63,
1391,
63,
954,
15171,
59,
498,
61,
267,
340,
440,
1228,
8,
954,
15171,
12,
769,
304,
288,
1007,
15171,
275,
359,
954,
15171,
61,
267,
367,
1007,
3741,
315,
1007,
15171,
26,
288,
574,
275,
485,
10437,
63,
1813,
63,
1975,
8,
324,
5540,
63,
2314,
12,
790,
12,
1007,
3741,
9,
288,
340,
574,
365,
440,
488,
26,
355,
6160,
59,
498,
61,
275,
574,
355,
2385,
14,
740,
8,
10861,
8,
498,
12,
574,
430,
272,
340,
2385,
26,
267,
2385,
14,
3176,
8,
16,
12,
3721,
360,
3958,
3734,
2860,
701,
625,
31562,
23070,
4079,
641,
1006,
1736,
10749,
315,
445,
18421,
63,
6351,
63,
3243,
1333,
272,
372,
2385,
421,
199,
318,
485,
10437,
63,
1813,
63,
1975,
8,
2314,
12,
536,
12,
1007,
3741,
304,
272,
1449,
272,
2104,
1924,
6230,
19269,
14466,
315,
445,
18421,
63,
6351,
63,
3243,
2813,
314,
1642,
2397,
687,
2589,
59,
2339,
61,
4877,
14466,
435,
1007,
3741,
14,
339,
520,
635,
1007,
3741,
26,
620,
2125,
503,
1007,
3741,
354,
626,
1443,
1343,
543,
7324,
272,
520,
5808,
26,
314,
4588,
574,
402,
314,
3734,
1750,
14,
272,
1449,
272,
574,
275,
6160,
59,
354,
61,
340,
536,
315,
6160,
587,
2125,
272,
2589,
63,
3771,
275,
359,
515,
367,
931,
315,
574,
14,
1294,
8,
736,
14,
17843,
9,
340,
931,
61,
272,
574,
63,
5540,
275,
756,
272,
340,
1007,
3741,
26,
267,
340,
1007,
3741,
14,
2460,
8,
736,
14,
515,
14,
4127,
9,
503,
334,
736,
14,
515,
14,
4478,
4127,
436,
1007,
3741,
14,
2460,
8,
736,
14,
515,
14,
4478,
4127,
2298,
288,
1007,
3741,
275,
1007,
3741,
59,
17,
2938,
267,
340,
1007,
3741,
14,
4130,
8,
736,
14,
515,
14,
4127,
9,
503,
334,
736,
14,
515,
14,
4478,
4127,
436,
1007,
3741,
14,
4130,
8,
736,
14
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
2290,
844,
28629,
334,
15400,
844,
9,
199,
3,
199,
3,
1898,
334,
67,
9,
6029,
12,
644,
382,
674,
598,
285,
474,
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,
199,
3,
787,
7647,
26,
199,
3,
199,
3,
221,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
259,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
221,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
199,
3,
259,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
199,
3,
259,
6450,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
199,
3,
259,
543,
314,
4084,
14,
199,
3,
221,
627,
11443,
314,
536,
402,
644,
382,
674,
598,
285,
474,
12,
3277,
14,
6590,
314,
1561,
402,
2399,
199,
3,
259,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
199,
3,
259,
687,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
199,
3,
2381,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
199,
3,
5877,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
199,
3,
9716,
12,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
199,
3,
5400,
2845,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
199,
3,
9102,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
199,
3,
9817,
2401,
5258,
1821,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
199,
3,
5603,
12,
1549,
7056,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
199,
3,
1821,
9683,
5738,
1634,
2334,
4815,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
199,
3,
9726,
1634,
9712,
9784,
14,
199,
199,
2344,
2765,
570,
12821,
5218,
1233,
367,
314,
3272,
14,
29085,
10554,
370,
663,
3734,
2860,
2344,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
646,
7534,
199,
646,
1331,
199,
646,
7554,
199,
646,
747,
199,
646,
4298,
199,
646,
984,
199,
199,
11206,
43,
568,
63,
18997,
63,
3817,
275,
1987,
3385,
19269,
7,
199,
199,
2253,
275,
4298,
14,
2253,
342,
199,
1311,
63,
36,
689,
7941,
275,
334,
2253,
508,
283,
31065,
358,
199,
1311,
63,
20509,
275,
334,
2253,
508,
283,
8647,
358,
199,
199,
3,
1007,
3741,
402,
14466,
20247,
370,
445,
18421,
63,
6351,
63,
3243,
199,
9984,
63,
5568,
63,
6348,
38,
5104,
3960,
275,
469,
272,
283,
30250,
63,
6351,
63,
3243,
356,
3260,
272,
283,
35,
3243,
356,
283,
2613,
297,
272,
283,
6533,
63,
16983,
63,
3243,
7,
340,
440,
2281,
63,
36,
689,
7941,
587,
283,
11446,
6533,
63,
16983,
63,
3243,
356,
788,
773,
297,
747,
14,
515,
14,
904,
360,
773,
297,
283,
88,
1184,
63,
772,
13,
5135,
13,
3689,
2665,
272,
283,
3243,
356,
283,
1393,
297,
272,
283,
18150,
63,
5569,
63,
3243,
356,
359,
736,
14,
515,
14,
904,
360,
773,
297,
283,
4600,
888,
659,
747,
14,
515,
14,
904,
360,
773,
297,
283,
88,
1184,
63,
772,
13,
5135,
13,
3689,
297,
283,
4600,
888,
2665,
272,
283,
29266,
356,
283,
773,
15,
1548,
18,
14,
23,
15,
2686,
13,
5154,
297,
199,
93,
421,
199,
318,
16475,
63,
1813,
63,
3669,
8,
2314,
12,
2589,
63,
1391,
63,
954,
15171,
304,
272,
1449,
272,
7958,
5218,
1233,
370,
5305,
3734,
2860,
272,
701,
625,
31562,
23070,
4079,
641,
1006,
1736,
10749,
315,
445,
18421,
63,
6351,
63,
3243,
14,
272,
961,
1630,
440,
8486,
23070,
10585,
701,
3734,
12604,
14,
272,
1449,
272,
2385,
275,
942,
272,
24214,
63,
2314,
275,
1331,
14,
1574,
8,
2314,
9,
272,
367,
790,
315,
3355,
8,
1813,
63,
1391,
63,
954,
15171,
14,
1612,
5109,
267,
1007,
15171,
275,
2589,
63,
1391,
63,
954,
15171,
59,
498,
61,
267,
340,
440,
1228,
8,
954,
15171,
12,
769,
304,
288,
1007,
15171,
275,
359,
954,
15171,
61,
267,
367,
1007,
3741,
315,
1007,
15171,
26,
288,
574,
275,
485,
10437,
63,
1813,
63,
1975,
8,
324,
5540,
63,
2314,
12,
790,
12,
1007,
3741,
9,
288,
340,
574,
365,
440,
488,
26,
355,
6160,
59,
498,
61,
275,
574,
355,
2385,
14,
740,
8,
10861,
8,
498,
12,
574,
430,
272,
340,
2385,
26,
267,
2385,
14,
3176,
8,
16,
12,
3721,
360,
3958,
3734,
2860,
701,
625,
31562,
23070,
4079,
641,
1006,
1736,
10749,
315,
445,
18421,
63,
6351,
63,
3243,
1333,
272,
372,
2385,
421,
199,
318,
485,
10437,
63,
1813,
63,
1975,
8,
2314,
12,
536,
12,
1007,
3741,
304,
272,
1449,
272,
2104,
1924,
6230,
19269,
14466,
315,
445,
18421,
63,
6351,
63,
3243,
2813,
314,
1642,
2397,
687,
2589,
59,
2339,
61,
4877,
14466,
435,
1007,
3741,
14,
339,
520,
635,
1007,
3741,
26,
620,
2125,
503,
1007,
3741,
354,
626,
1443,
1343,
543,
7324,
272,
520,
5808,
26,
314,
4588,
574,
402,
314,
3734,
1750,
14,
272,
1449,
272,
574,
275,
6160,
59,
354,
61,
340,
536,
315,
6160,
587,
2125,
272,
2589,
63,
3771,
275,
359,
515,
367,
931,
315,
574,
14,
1294,
8,
736,
14,
17843,
9,
340,
931,
61,
272,
574,
63,
5540,
275,
756,
272,
340,
1007,
3741,
26,
267,
340,
1007,
3741,
14,
2460,
8,
736,
14,
515,
14,
4127,
9,
503,
334,
736,
14,
515,
14,
4478,
4127,
436,
1007,
3741,
14,
2460,
8,
736,
14,
515,
14,
4478,
4127,
2298,
288,
1007,
3741,
275,
1007,
3741,
59,
17,
2938,
267,
340,
1007,
3741,
14,
4130,
8,
736,
14,
515,
14,
4127,
9,
503,
334,
736,
14,
515,
14,
4478,
4127,
436,
1007,
3741,
14,
4130,
8,
736,
14,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
riteshshrv/django
|
django/contrib/auth/views.py
|
154
|
12383
|
import functools
import warnings
from django.conf import settings
# Avoid shadowing the login() and logout() views below.
from django.contrib.auth import (
REDIRECT_FIELD_NAME, get_user_model, login as auth_login,
logout as auth_logout, update_session_auth_hash,
)
from django.contrib.auth.decorators import login_required
from django.contrib.auth.forms import (
AuthenticationForm, PasswordChangeForm, PasswordResetForm, SetPasswordForm,
)
from django.contrib.auth.tokens import default_token_generator
from django.contrib.sites.shortcuts import get_current_site
from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect, QueryDict
from django.shortcuts import resolve_url
from django.template.response import TemplateResponse
from django.utils.deprecation import (
RemovedInDjango20Warning, RemovedInDjango110Warning,
)
from django.utils.encoding import force_text
from django.utils.http import is_safe_url, urlsafe_base64_decode
from django.utils.six.moves.urllib.parse import urlparse, urlunparse
from django.utils.translation import ugettext as _
from django.views.decorators.cache import never_cache
from django.views.decorators.csrf import csrf_protect
from django.views.decorators.debug import sensitive_post_parameters
def deprecate_current_app(func):
"""
Handle deprecation of the current_app parameter of the views.
"""
@functools.wraps(func)
def inner(*args, **kwargs):
if 'current_app' in kwargs:
warnings.warn(
"Passing `current_app` as a keyword argument is deprecated. "
"Instead the caller of `{0}` should set "
"`request.current_app`.".format(func.__name__),
RemovedInDjango20Warning
)
current_app = kwargs.pop('current_app')
request = kwargs.get('request', None)
if request and current_app is not None:
request.current_app = current_app
return func(*args, **kwargs)
return inner
@deprecate_current_app
@sensitive_post_parameters()
@csrf_protect
@never_cache
def login(request, template_name='registration/login.html',
redirect_field_name=REDIRECT_FIELD_NAME,
authentication_form=AuthenticationForm,
extra_context=None):
"""
Displays the login form and handles the login action.
"""
redirect_to = request.POST.get(redirect_field_name,
request.GET.get(redirect_field_name, ''))
if request.method == "POST":
form = authentication_form(request, data=request.POST)
if form.is_valid():
# Ensure the user-originating redirection url is safe.
if not is_safe_url(url=redirect_to, host=request.get_host()):
redirect_to = resolve_url(settings.LOGIN_REDIRECT_URL)
# Okay, security check complete. Log the user in.
auth_login(request, form.get_user())
return HttpResponseRedirect(redirect_to)
else:
form = authentication_form(request)
current_site = get_current_site(request)
context = {
'form': form,
redirect_field_name: redirect_to,
'site': current_site,
'site_name': current_site.name,
}
if extra_context is not None:
context.update(extra_context)
return TemplateResponse(request, template_name, context)
@deprecate_current_app
def logout(request, next_page=None,
template_name='registration/logged_out.html',
redirect_field_name=REDIRECT_FIELD_NAME,
extra_context=None):
"""
Logs out the user and displays 'You are logged out' message.
"""
auth_logout(request)
if next_page is not None:
next_page = resolve_url(next_page)
if (redirect_field_name in request.POST or
redirect_field_name in request.GET):
next_page = request.POST.get(redirect_field_name,
request.GET.get(redirect_field_name))
# Security check -- don't allow redirection to a different host.
if not is_safe_url(url=next_page, host=request.get_host()):
next_page = request.path
if next_page:
# Redirect to this page until the session has been cleared.
return HttpResponseRedirect(next_page)
current_site = get_current_site(request)
context = {
'site': current_site,
'site_name': current_site.name,
'title': _('Logged out')
}
if extra_context is not None:
context.update(extra_context)
return TemplateResponse(request, template_name, context)
@deprecate_current_app
def logout_then_login(request, login_url=None, extra_context=None):
"""
Logs out the user if they are logged in. Then redirects to the log-in page.
"""
if not login_url:
login_url = settings.LOGIN_URL
login_url = resolve_url(login_url)
return logout(request, login_url, extra_context=extra_context)
def redirect_to_login(next, login_url=None,
redirect_field_name=REDIRECT_FIELD_NAME):
"""
Redirects the user to the login page, passing the given 'next' page
"""
resolved_url = resolve_url(login_url or settings.LOGIN_URL)
login_url_parts = list(urlparse(resolved_url))
if redirect_field_name:
querystring = QueryDict(login_url_parts[4], mutable=True)
querystring[redirect_field_name] = next
login_url_parts[4] = querystring.urlencode(safe='/')
return HttpResponseRedirect(urlunparse(login_url_parts))
# 4 views for password reset:
# - password_reset sends the mail
# - password_reset_done shows a success message for the above
# - password_reset_confirm checks the link the user clicked and
# prompts for a new password
# - password_reset_complete shows a success message for the above
@deprecate_current_app
@csrf_protect
def password_reset(request, is_admin_site=False,
template_name='registration/password_reset_form.html',
email_template_name='registration/password_reset_email.html',
subject_template_name='registration/password_reset_subject.txt',
password_reset_form=PasswordResetForm,
token_generator=default_token_generator,
post_reset_redirect=None,
from_email=None,
extra_context=None,
html_email_template_name=None):
if post_reset_redirect is None:
post_reset_redirect = reverse('password_reset_done')
else:
post_reset_redirect = resolve_url(post_reset_redirect)
if request.method == "POST":
form = password_reset_form(request.POST)
if form.is_valid():
opts = {
'use_https': request.is_secure(),
'token_generator': token_generator,
'from_email': from_email,
'email_template_name': email_template_name,
'subject_template_name': subject_template_name,
'request': request,
'html_email_template_name': html_email_template_name,
}
if is_admin_site:
warnings.warn(
"The is_admin_site argument to "
"django.contrib.auth.views.password_reset() is deprecated "
"and will be removed in Django 1.10.",
RemovedInDjango110Warning, 3
)
opts = dict(opts, domain_override=request.get_host())
form.save(**opts)
return HttpResponseRedirect(post_reset_redirect)
else:
form = password_reset_form()
context = {
'form': form,
'title': _('Password reset'),
}
if extra_context is not None:
context.update(extra_context)
return TemplateResponse(request, template_name, context)
@deprecate_current_app
def password_reset_done(request,
template_name='registration/password_reset_done.html',
extra_context=None):
context = {
'title': _('Password reset sent'),
}
if extra_context is not None:
context.update(extra_context)
return TemplateResponse(request, template_name, context)
# Doesn't need csrf_protect since no-one can guess the URL
@sensitive_post_parameters()
@never_cache
@deprecate_current_app
def password_reset_confirm(request, uidb64=None, token=None,
template_name='registration/password_reset_confirm.html',
token_generator=default_token_generator,
set_password_form=SetPasswordForm,
post_reset_redirect=None,
extra_context=None):
"""
View that checks the hash in a password reset link and presents a
form for entering a new password.
"""
UserModel = get_user_model()
assert uidb64 is not None and token is not None # checked by URLconf
if post_reset_redirect is None:
post_reset_redirect = reverse('password_reset_complete')
else:
post_reset_redirect = resolve_url(post_reset_redirect)
try:
# urlsafe_base64_decode() decodes to bytestring on Python 3
uid = force_text(urlsafe_base64_decode(uidb64))
user = UserModel._default_manager.get(pk=uid)
except (TypeError, ValueError, OverflowError, UserModel.DoesNotExist):
user = None
if user is not None and token_generator.check_token(user, token):
validlink = True
title = _('Enter new password')
if request.method == 'POST':
form = set_password_form(user, request.POST)
if form.is_valid():
form.save()
return HttpResponseRedirect(post_reset_redirect)
else:
form = set_password_form(user)
else:
validlink = False
form = None
title = _('Password reset unsuccessful')
context = {
'form': form,
'title': title,
'validlink': validlink,
}
if extra_context is not None:
context.update(extra_context)
return TemplateResponse(request, template_name, context)
@deprecate_current_app
def password_reset_complete(request,
template_name='registration/password_reset_complete.html',
extra_context=None):
context = {
'login_url': resolve_url(settings.LOGIN_URL),
'title': _('Password reset complete'),
}
if extra_context is not None:
context.update(extra_context)
return TemplateResponse(request, template_name, context)
@sensitive_post_parameters()
@csrf_protect
@login_required
@deprecate_current_app
def password_change(request,
template_name='registration/password_change_form.html',
post_change_redirect=None,
password_change_form=PasswordChangeForm,
extra_context=None):
if post_change_redirect is None:
post_change_redirect = reverse('password_change_done')
else:
post_change_redirect = resolve_url(post_change_redirect)
if request.method == "POST":
form = password_change_form(user=request.user, data=request.POST)
if form.is_valid():
form.save()
# Updating the password logs out all other sessions for the user
# except the current one if
# django.contrib.auth.middleware.SessionAuthenticationMiddleware
# is enabled.
update_session_auth_hash(request, form.user)
return HttpResponseRedirect(post_change_redirect)
else:
form = password_change_form(user=request.user)
context = {
'form': form,
'title': _('Password change'),
}
if extra_context is not None:
context.update(extra_context)
return TemplateResponse(request, template_name, context)
@login_required
@deprecate_current_app
def password_change_done(request,
template_name='registration/password_change_done.html',
extra_context=None):
context = {
'title': _('Password change successful'),
}
if extra_context is not None:
context.update(extra_context)
return TemplateResponse(request, template_name, context)
|
bsd-3-clause
|
[
646,
9143,
199,
646,
3598,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
3,
19503,
15084,
316,
314,
4676,
342,
436,
22079,
342,
6858,
5084,
14,
199,
504,
1639,
14,
2828,
14,
1178,
492,
334,
272,
820,
7458,
4168,
63,
8609,
63,
2339,
12,
664,
63,
751,
63,
1238,
12,
4676,
465,
1790,
63,
2886,
12,
272,
22079,
465,
1790,
63,
11646,
12,
1678,
63,
1730,
63,
1178,
63,
2227,
12,
199,
9,
199,
504,
1639,
14,
2828,
14,
1178,
14,
11582,
492,
4676,
63,
2427,
199,
504,
1639,
14,
2828,
14,
1178,
14,
3351,
492,
334,
272,
15995,
2821,
12,
13635,
32523,
12,
13635,
9637,
2821,
12,
2494,
6139,
2821,
12,
199,
9,
199,
504,
1639,
14,
2828,
14,
1178,
14,
4504,
492,
849,
63,
1418,
63,
4679,
199,
504,
1639,
14,
2828,
14,
8619,
14,
17469,
492,
664,
63,
1818,
63,
2124,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
504,
1639,
14,
1014,
492,
14935,
12,
8133,
2141,
199,
504,
1639,
14,
17469,
492,
7512,
63,
633,
199,
504,
1639,
14,
1160,
14,
1310,
492,
29264,
199,
504,
1639,
14,
1208,
14,
15383,
492,
334,
272,
23687,
1165,
3849,
12,
23687,
6019,
3849,
12,
199,
9,
199,
504,
1639,
14,
1208,
14,
2991,
492,
3542,
63,
505,
199,
504,
1639,
14,
1208,
14,
1014,
492,
365,
63,
3489,
63,
633,
12,
8187,
6504,
63,
1095,
772,
63,
2708,
199,
504,
1639,
14,
1208,
14,
4174,
14,
4912,
14,
4078,
14,
1122,
492,
7097,
12,
30111,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
465,
485,
199,
504,
1639,
14,
4196,
14,
11582,
14,
1637,
492,
7078,
63,
1637,
199,
504,
1639,
14,
4196,
14,
11582,
14,
10088,
492,
19213,
63,
18292,
199,
504,
1639,
14,
4196,
14,
11582,
14,
1757,
492,
18423,
63,
1932,
63,
3214,
421,
199,
318,
477,
21826,
63,
1818,
63,
571,
8,
1532,
304,
272,
408,
272,
8690,
17831,
402,
314,
1453,
63,
571,
2725,
402,
314,
6858,
14,
272,
408,
272,
768,
17869,
14,
13582,
8,
1532,
9,
272,
347,
6506,
2031,
589,
12,
1011,
958,
304,
267,
340,
283,
1818,
63,
571,
7,
315,
2074,
26,
288,
3598,
14,
4050,
8,
355,
298,
4986,
316,
658,
1818,
63,
571,
64,
465,
282,
4252,
1423,
365,
5906,
14,
298,
355,
298,
13962,
13558,
314,
8025,
402,
658,
91,
16,
23485,
1077,
663,
298,
355,
24505,
1069,
14,
1818,
63,
571,
2313,
1674,
908,
8,
1532,
855,
354,
10139,
355,
23687,
1165,
3849,
288,
776,
288,
1453,
63,
571,
275,
2074,
14,
1935,
360,
1818,
63,
571,
358,
288,
1056,
275,
2074,
14,
362,
360,
1069,
297,
488,
9,
288,
340,
1056,
436,
1453,
63,
571,
365,
440,
488,
26,
355,
1056,
14,
1818,
63,
571,
275,
1453,
63,
571,
267,
372,
2562,
2031,
589,
12,
1011,
958,
9,
272,
372,
6506,
421,
199,
32,
27891,
63,
1818,
63,
571,
199,
32,
7361,
63,
1932,
63,
3214,
342,
199,
32,
10088,
63,
18292,
199,
32,
18178,
63,
1637,
199,
318,
4676,
8,
1069,
12,
1978,
63,
354,
534,
8054,
15,
2886,
14,
1360,
297,
881,
4660,
63,
698,
63,
354,
29,
19747,
63,
8609,
63,
2339,
12,
881,
6299,
63,
964,
29,
10348,
2821,
12,
881,
2402,
63,
1100,
29,
403,
304,
272,
408,
272,
28750,
314,
4676,
1824,
436,
10022,
314,
4676,
1595,
14,
272,
408,
272,
4660,
63,
475,
275,
1056,
14,
4030,
14,
362,
8,
4876,
63,
698,
63,
354,
12,
3521,
1056,
14,
2970,
14,
362,
8,
4876,
63,
698,
63,
354,
12,
12381,
339,
340,
1056,
14,
765,
508,
298,
4030,
582,
267,
1824,
275,
6299,
63,
964,
8,
1069,
12,
666,
29,
1069,
14,
4030,
9,
267,
340,
1824,
14,
374,
63,
1078,
837,
953,
327,
7523,
314,
922,
13,
6493,
1958,
23713,
1166,
365,
5048,
14,
288,
340,
440,
365,
63,
3489,
63,
633,
8,
633,
29,
4876,
63,
475,
12,
1591,
29,
1069,
14,
362,
63,
1102,
5109,
355,
4660,
63,
475,
275,
7512,
63,
633,
8,
1751,
14,
17208,
63,
19747,
63,
2632,
9,
953,
327,
32123,
12,
6391,
1104,
4890,
14,
5297,
314,
922,
315,
14,
288,
1790,
63,
2886,
8,
1069,
12,
1824,
14,
362,
63,
751,
1012,
953,
372,
14935,
8,
4876,
63,
475,
9,
272,
587,
26,
267,
1824,
275,
6299,
63,
964,
8,
1069,
9,
339,
1453,
63,
2124,
275,
664,
63,
1818,
63,
2124,
8,
1069,
9,
339,
1067,
275,
469,
267,
283,
964,
356,
1824,
12,
267,
4660,
63,
698,
63,
354,
26,
4660,
63,
475,
12,
267,
283,
2124,
356,
1453,
63,
2124,
12,
267,
283,
2124,
63,
354,
356,
1453,
63,
2124,
14,
354,
12,
272,
789,
272,
340,
2402,
63,
1100,
365,
440,
488,
26,
267,
1067,
14,
873,
8,
2911,
63,
1100,
9,
339,
372,
29264,
8,
1069,
12,
1978,
63,
354,
12,
1067,
9,
421,
199,
32,
27891,
63,
1818,
63,
571,
199,
318,
22079,
8,
1069,
12,
2163,
63,
1606,
29,
403,
12,
1779,
1978,
63,
354,
534,
8054,
15,
12419,
63,
548,
14,
1360,
297,
1779,
4660,
63,
698,
63,
354,
29,
19747,
63,
8609,
63,
2339,
12,
1779,
2402,
63,
1100,
29,
403,
304,
272,
408,
272,
3835,
458,
734,
314,
922,
436,
17561,
283,
5556,
787,
10367,
734,
7,
1245,
14,
272,
408,
272,
1790,
63,
11646,
8,
1069,
9,
339,
340,
2163,
63,
1606,
365,
440,
488,
26,
267,
2163,
63,
1606,
275,
7512,
63,
633,
8,
2184,
63,
1606,
9,
339,
340,
334,
4876,
63,
698,
63,
354,
315,
1056,
14,
4030,
503,
288,
4660,
63,
698,
63,
354,
315,
1056,
14,
2970,
304,
267,
2163,
63,
1606,
275,
1056,
14,
4030,
14,
362,
8,
4876,
63,
698,
63,
354,
12,
3660,
1056,
14,
2970,
14,
362,
8,
4876,
63,
698,
63,
354,
430,
267,
327,
13863,
1104,
1553,
2793,
1133,
2040,
23713,
370,
282,
3365,
1591,
14,
267,
340,
440,
365,
63,
3489,
63,
633,
8,
633,
29,
2184,
63,
1606,
12,
1591,
29,
1069,
14,
362,
63,
1102,
5109,
288,
2163,
63,
1606,
275,
1056,
14,
515,
339,
340,
2163,
63,
1606,
26,
267,
327,
18532,
370,
642,
2034,
5133,
314,
2351,
965,
2757
] |
[
9143,
199,
646,
3598,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
3,
19503,
15084,
316,
314,
4676,
342,
436,
22079,
342,
6858,
5084,
14,
199,
504,
1639,
14,
2828,
14,
1178,
492,
334,
272,
820,
7458,
4168,
63,
8609,
63,
2339,
12,
664,
63,
751,
63,
1238,
12,
4676,
465,
1790,
63,
2886,
12,
272,
22079,
465,
1790,
63,
11646,
12,
1678,
63,
1730,
63,
1178,
63,
2227,
12,
199,
9,
199,
504,
1639,
14,
2828,
14,
1178,
14,
11582,
492,
4676,
63,
2427,
199,
504,
1639,
14,
2828,
14,
1178,
14,
3351,
492,
334,
272,
15995,
2821,
12,
13635,
32523,
12,
13635,
9637,
2821,
12,
2494,
6139,
2821,
12,
199,
9,
199,
504,
1639,
14,
2828,
14,
1178,
14,
4504,
492,
849,
63,
1418,
63,
4679,
199,
504,
1639,
14,
2828,
14,
8619,
14,
17469,
492,
664,
63,
1818,
63,
2124,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
504,
1639,
14,
1014,
492,
14935,
12,
8133,
2141,
199,
504,
1639,
14,
17469,
492,
7512,
63,
633,
199,
504,
1639,
14,
1160,
14,
1310,
492,
29264,
199,
504,
1639,
14,
1208,
14,
15383,
492,
334,
272,
23687,
1165,
3849,
12,
23687,
6019,
3849,
12,
199,
9,
199,
504,
1639,
14,
1208,
14,
2991,
492,
3542,
63,
505,
199,
504,
1639,
14,
1208,
14,
1014,
492,
365,
63,
3489,
63,
633,
12,
8187,
6504,
63,
1095,
772,
63,
2708,
199,
504,
1639,
14,
1208,
14,
4174,
14,
4912,
14,
4078,
14,
1122,
492,
7097,
12,
30111,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
465,
485,
199,
504,
1639,
14,
4196,
14,
11582,
14,
1637,
492,
7078,
63,
1637,
199,
504,
1639,
14,
4196,
14,
11582,
14,
10088,
492,
19213,
63,
18292,
199,
504,
1639,
14,
4196,
14,
11582,
14,
1757,
492,
18423,
63,
1932,
63,
3214,
421,
199,
318,
477,
21826,
63,
1818,
63,
571,
8,
1532,
304,
272,
408,
272,
8690,
17831,
402,
314,
1453,
63,
571,
2725,
402,
314,
6858,
14,
272,
408,
272,
768,
17869,
14,
13582,
8,
1532,
9,
272,
347,
6506,
2031,
589,
12,
1011,
958,
304,
267,
340,
283,
1818,
63,
571,
7,
315,
2074,
26,
288,
3598,
14,
4050,
8,
355,
298,
4986,
316,
658,
1818,
63,
571,
64,
465,
282,
4252,
1423,
365,
5906,
14,
298,
355,
298,
13962,
13558,
314,
8025,
402,
658,
91,
16,
23485,
1077,
663,
298,
355,
24505,
1069,
14,
1818,
63,
571,
2313,
1674,
908,
8,
1532,
855,
354,
10139,
355,
23687,
1165,
3849,
288,
776,
288,
1453,
63,
571,
275,
2074,
14,
1935,
360,
1818,
63,
571,
358,
288,
1056,
275,
2074,
14,
362,
360,
1069,
297,
488,
9,
288,
340,
1056,
436,
1453,
63,
571,
365,
440,
488,
26,
355,
1056,
14,
1818,
63,
571,
275,
1453,
63,
571,
267,
372,
2562,
2031,
589,
12,
1011,
958,
9,
272,
372,
6506,
421,
199,
32,
27891,
63,
1818,
63,
571,
199,
32,
7361,
63,
1932,
63,
3214,
342,
199,
32,
10088,
63,
18292,
199,
32,
18178,
63,
1637,
199,
318,
4676,
8,
1069,
12,
1978,
63,
354,
534,
8054,
15,
2886,
14,
1360,
297,
881,
4660,
63,
698,
63,
354,
29,
19747,
63,
8609,
63,
2339,
12,
881,
6299,
63,
964,
29,
10348,
2821,
12,
881,
2402,
63,
1100,
29,
403,
304,
272,
408,
272,
28750,
314,
4676,
1824,
436,
10022,
314,
4676,
1595,
14,
272,
408,
272,
4660,
63,
475,
275,
1056,
14,
4030,
14,
362,
8,
4876,
63,
698,
63,
354,
12,
3521,
1056,
14,
2970,
14,
362,
8,
4876,
63,
698,
63,
354,
12,
12381,
339,
340,
1056,
14,
765,
508,
298,
4030,
582,
267,
1824,
275,
6299,
63,
964,
8,
1069,
12,
666,
29,
1069,
14,
4030,
9,
267,
340,
1824,
14,
374,
63,
1078,
837,
953,
327,
7523,
314,
922,
13,
6493,
1958,
23713,
1166,
365,
5048,
14,
288,
340,
440,
365,
63,
3489,
63,
633,
8,
633,
29,
4876,
63,
475,
12,
1591,
29,
1069,
14,
362,
63,
1102,
5109,
355,
4660,
63,
475,
275,
7512,
63,
633,
8,
1751,
14,
17208,
63,
19747,
63,
2632,
9,
953,
327,
32123,
12,
6391,
1104,
4890,
14,
5297,
314,
922,
315,
14,
288,
1790,
63,
2886,
8,
1069,
12,
1824,
14,
362,
63,
751,
1012,
953,
372,
14935,
8,
4876,
63,
475,
9,
272,
587,
26,
267,
1824,
275,
6299,
63,
964,
8,
1069,
9,
339,
1453,
63,
2124,
275,
664,
63,
1818,
63,
2124,
8,
1069,
9,
339,
1067,
275,
469,
267,
283,
964,
356,
1824,
12,
267,
4660,
63,
698,
63,
354,
26,
4660,
63,
475,
12,
267,
283,
2124,
356,
1453,
63,
2124,
12,
267,
283,
2124,
63,
354,
356,
1453,
63,
2124,
14,
354,
12,
272,
789,
272,
340,
2402,
63,
1100,
365,
440,
488,
26,
267,
1067,
14,
873,
8,
2911,
63,
1100,
9,
339,
372,
29264,
8,
1069,
12,
1978,
63,
354,
12,
1067,
9,
421,
199,
32,
27891,
63,
1818,
63,
571,
199,
318,
22079,
8,
1069,
12,
2163,
63,
1606,
29,
403,
12,
1779,
1978,
63,
354,
534,
8054,
15,
12419,
63,
548,
14,
1360,
297,
1779,
4660,
63,
698,
63,
354,
29,
19747,
63,
8609,
63,
2339,
12,
1779,
2402,
63,
1100,
29,
403,
304,
272,
408,
272,
3835,
458,
734,
314,
922,
436,
17561,
283,
5556,
787,
10367,
734,
7,
1245,
14,
272,
408,
272,
1790,
63,
11646,
8,
1069,
9,
339,
340,
2163,
63,
1606,
365,
440,
488,
26,
267,
2163,
63,
1606,
275,
7512,
63,
633,
8,
2184,
63,
1606,
9,
339,
340,
334,
4876,
63,
698,
63,
354,
315,
1056,
14,
4030,
503,
288,
4660,
63,
698,
63,
354,
315,
1056,
14,
2970,
304,
267,
2163,
63,
1606,
275,
1056,
14,
4030,
14,
362,
8,
4876,
63,
698,
63,
354,
12,
3660,
1056,
14,
2970,
14,
362,
8,
4876,
63,
698,
63,
354,
430,
267,
327,
13863,
1104,
1553,
2793,
1133,
2040,
23713,
370,
282,
3365,
1591,
14,
267,
340,
440,
365,
63,
3489,
63,
633,
8,
633,
29,
2184,
63,
1606,
12,
1591,
29,
1069,
14,
362,
63,
1102,
5109,
288,
2163,
63,
1606,
275,
1056,
14,
515,
339,
340,
2163,
63,
1606,
26,
267,
327,
18532,
370,
642,
2034,
5133,
314,
2351,
965,
2757,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
jteehan/cfme_tests
|
artifactor/__init__.py
|
2
|
12258
|
"""
Artifactor
Artifactor is used to collect artifacts from a number of different plugins and put them into
one place. Artifactor works around a series of events and is geared towards unit testing, though
it is extensible and customizable enough that it can be used for a variety of purposes.
The main guts of Artifactor is around the plugins. Before Artifactor can do anything it must have
a configured plugin. This plugin is then configured to bind certain functions inside itself
to certain events. When Artifactor is triggered to handle a certain event, it will tell the plugin
that that particular event has happened and the plugin will respond accordingly.
In addition to the plugins, Artifactor can also run certain callback functions before and after
the hook function itself. These are call pre and post hook callbacks. Artifactor allows multiple
pre and post hook callbacks to be defined per event, but does not guarantee the order that they
are executed in.
To allow data to be passed to and from hooks, Artifactor has the idea of global and event local
values. The global values persist in the Artifactor instance for its lifetime, but the event local
values are destroyed at the end of each event.
Let's take the example of using the unit testing suite py.test as an example for Artifactor.
Suppose we have a number of tests that run as part of a test suite and we wish to store a text
file that holds the time the test was run and its result. This information is required to reside
in a folder that is relevant to the test itself. This type of job is what Artifactor was designed
for.
To begin with, we need to create a plugin for Artifactor. Consider the following piece of code::
from artifactor import ArtifactorBasePlugin
import time
class Test(ArtifactorBasePlugin):
def plugin_initialize(self):
self.register_plugin_hook('start_test', self.start_test)
self.register_plugin_hook('finish_test', self.finish_test)
def start_test(self, test_name, test_location, artifact_path):
filename = artifact_path + "-" + self.ident + ".log"
with open(filename, "w") as f:
f.write(test_name + "\n")
f.write(str(time.time()) + "\n")
def finish_test(self, test_name, artifact_path, test_result):
filename = artifact_path + "-" + self.ident + ".log"
with open(filename, "w+") as f:
f.write(test_result)
This is a typical plugin in Artifactor, it consists of 2 things. The first item is
the special function called ``plugin_initialize()``. This is important
and is equivilent to the ``__init__()`` that would usually be found in a class definition.
Artifactor calls ``plugin_initialize()`` for each plugin as it loads it.
Inside this section we register the hook functions to their associated events. Each event
can only have a single function associated with it. Event names are able to be freely assigned
so you can customize plugins to work to specific events for your use case.
The ``register_plugin_hook()`` takes an event name as a string and a function to callback when
that event is experienced.
Next we have the hook functions themselves, ``start_test()`` and ``finish_test()``. These
have arguments in their prototypes and these arguments are supplied by Artifactor and are
created either as arguments to the ``fire_hook()`` function, which is responsible for actually
telling Artifactor that an even has occured, or they are created in the pre hook script.
Artifactor uses the global and local values referenced earlier to store these argument values.
When a pre, post or hook callback finishes, it has the opportunity to supply updates to both
the global and local values dictionaries. In doing this, a pre-hook script can prepare data,
which will could be stored in the locals dictionary and then passed to the actual plugin hook
as a keyword argument. local values override global values.
We need to look at an example of this, but first we must configure artifactor and the plugin::
log_dir: /home/me/artiout
per_run: run #test, run, None
overwrite: True
artifacts:
test:
enabled: True
plugin: test
Here we have defined a ``log_dir`` which will be the root of all of our artifacts. We have asked
Artifactor to group the artifacts by run, which means that it will try to create a directory
under the ``log_dir`` which indicates which test "run" this was. We can also specify a value of
"test" here, which will move the test run identifying folder up to the leaf in the tree.
The ``log_dir`` and contents of the config are stored in global values as ``log_dir`` and
``artifactor_config`` respectively. These are the only two global values which are setup by
Artifactor.
This data is then passed to artifactor as a dict, we will assume a variable name of ``config`` here.
Let's consider how we would run this test
art = artifactor.artifactor
art.set_config(config)
art.register_plugin(test.Test, "test")
artifactor.initialize()
a.fire_hook('start_session', run_id=2235)
a.fire_hook('start_test', test_name="my_test", test_location="tests/mytest.py")
a.fire_hook('finish_test', test_name="my_test", test_location="tests/mytest.py",
test_result="FAILED")
a.fire_hook('finish_session')
The art.register_plugin is used to bind a plugin name to a class definition. Notice in the config
section earlier, we have a ``plugin: test`` field. This name ``test`` is what Artifactor will
look for when trying to find the appropriate plugin. When we register the plugin with the
``register_plugin`` function, we take the ``test.Test`` class and essentially give it the name
``test`` so that the names will tie up and the plugin will be used.
Notice that we have sent some information to along with the request to fire the hook. Ignoring the
``start_session`` event for a minute, the ``start_test`` event sends a ``test_name`` and a
``test_location``. However, the ``start_test`` hook also required an argument called
``argument_path``. This is not supplied by the hook, and isn't setup as a global value, so how does
it get there?
Inside Artifactor, by default, a pre_hook callback called ``start_test()`` is bound to the
``start_test`` event. This callback returns a local values update which includes ``artifact_path``.
This is how the artifact_path is returned. This hook can be removed, by running a
``unregister_hook_callback`` with the name of the hook callback.
"""
import logging
import os
import re
import sys
from py.path import local
from riggerlib import Rigger, RiggerBasePlugin, RiggerClient
from utils.net import random_port
from utils.path import log_path
class Artifactor(Rigger):
"""A sub from Rigger"""
def set_config(self, config):
self.config = config
def parse_config(self):
"""
Reads the config data and sets up values
"""
if not self.config:
return False
self.log_dir = local(self.config.get('log_dir', log_path))
self.log_dir.ensure(dir=True)
self.artifact_dir = local(self.config.get('artifact_dir', log_path.join('artifacts')))
self.artifact_dir.ensure(dir=True)
self.logger = create_logger('artifactor', self.log_dir.join('artifactor.log').strpath)
self.squash_exceptions = self.config.get('squash_exceptions', False)
if not self.log_dir:
print("!!! Log dir must be specified in yaml")
sys.exit(127)
if not self.artifact_dir:
print("!!! Artifact dir must be specified in yaml")
sys.exit(127)
self.config['zmq_socket_address'] = 'tcp://127.0.0.1:{}'.format(random_port())
self.setup_plugin_instances()
self.start_server()
self.global_data = {
'artifactor_config': self.config,
'log_dir': self.log_dir.strpath,
'artifact_dir': self.artifact_dir.strpath,
'artifacts': dict(),
'old_artifacts': dict()
}
def handle_failure(self, exc):
self.logger.error("exception", exc_info=exc)
def log_message(self, message):
self.logger.debug(message)
class ArtifactorClient(RiggerClient):
pass
class ArtifactorBasePlugin(RiggerBasePlugin):
"""A sub from RiggerBasePlugin"""
@property
def store(self):
if not hasattr(self, '_store'):
self._store = {}
return self._store
def initialize(artifactor):
artifactor.parse_config()
artifactor.register_hook_callback('pre_start_test', 'pre', parse_setup_dir,
name="default_start_test")
artifactor.register_hook_callback('start_test', 'pre', parse_setup_dir,
name="default_start_test")
artifactor.register_hook_callback('finish_test', 'pre', parse_setup_dir,
name="default_finish_test")
artifactor.register_hook_callback('start_session', 'pre', start_session,
name="default_start_session")
artifactor.register_hook_callback('build_report', 'pre', merge_artifacts,
name="merge_artifacts")
artifactor.register_hook_callback('finish_session', 'pre', merge_artifacts,
name="merge_artifacts")
artifactor.initialized = True
def start_session(run_id=None):
"""
Convenience fire_hook for built in hook
"""
return None, {'run_id': run_id}
def merge_artifacts(old_artifacts, artifacts):
"""
This is extremely important and merges the old_Artifacts from a composite-uncollect build
with the new artifacts for this run
"""
old_artifacts.update(artifacts)
return {'old_artifacts': old_artifacts}, None
def parse_setup_dir(test_name, test_location, artifactor_config, artifact_dir, run_id):
"""
Convenience fire_hook for built in hook
"""
if test_name and test_location:
run_type = artifactor_config.get('per_run')
overwrite = artifactor_config.get('reuse_dir', False)
path = setup_artifact_dir(root_dir=artifact_dir, test_name=test_name,
test_location=test_location, run_type=run_type,
run_id=run_id, overwrite=overwrite)
else:
raise Exception('Not enough information to create artifact')
return {'artifact_path': path}, None
def setup_artifact_dir(root_dir=None, test_name=None, test_location=None,
run_type=None, run_id=None, overwrite=True):
"""
Sets up the artifact dir and returns it.
"""
test_name = re.sub(r"[^a-zA-Z0-9_.\-\[\]]", "_", test_name)
test_name = re.sub(r"[/]", "_", test_name)
test_name = re.sub(r"__+", "_", test_name)
orig_path = os.path.abspath(root_dir)
if run_id:
run_id = str(run_id)
if run_type == "run" and run_id:
path = os.path.join(orig_path, run_id, test_location, test_name)
elif run_type == "test" and run_id:
path = os.path.join(orig_path, test_location, test_name, run_id)
else:
path = os.path.join(orig_path, test_location, test_name)
try:
os.makedirs(path)
except OSError as e:
if e.errno == 17:
if overwrite:
pass
else:
print("Directories already existed and overwrite is set to False")
sys.exit(127)
else:
raise
return path
def create_logger(logger_name, filename):
"""Creates and returns the named logger
If the logger already exists, it will be destroyed and recreated
with the current config in env.yaml
"""
# If the logger already exists, reset its handlers
logger = logging.getLogger(logger_name)
for handler in logger.handlers:
logger.removeHandler(handler)
log_file = filename
file_formatter = logging.Formatter('%(asctime)-15s [%(levelname).1s] %(message)s')
file_handler = logging.FileHandler(log_file)
file_handler.setFormatter(file_formatter)
logger.addHandler(file_handler)
logger.setLevel('DEBUG')
return logger
|
gpl-2.0
|
[
624,
199,
1596,
280,
4778,
199,
199,
1596,
280,
4778,
365,
1202,
370,
8775,
27990,
687,
282,
1329,
402,
3365,
8963,
436,
5324,
3062,
1901,
199,
368,
4192,
14,
1952,
280,
4778,
5419,
6818,
282,
6779,
402,
4474,
436,
365,
2312,
2899,
28354,
4137,
5343,
12,
10617,
199,
390,
365,
2178,
1164,
436,
3537,
14065,
8321,
626,
652,
883,
506,
1202,
367,
282,
32246,
402,
12901,
14,
199,
199,
1918,
2446,
486,
14608,
402,
1952,
280,
4778,
365,
6818,
314,
8963,
14,
21467,
1952,
280,
4778,
883,
886,
7003,
652,
1471,
1172,
199,
65,
7526,
3589,
14,
961,
3589,
365,
2066,
7526,
370,
5398,
9842,
3423,
6272,
6337,
199,
475,
9842,
4474,
14,
3979,
1952,
280,
4778,
365,
15572,
370,
2429,
282,
9842,
1566,
12,
652,
911,
11480,
314,
3589,
199,
9099,
626,
6770,
1566,
965,
21056,
436,
314,
3589,
911,
22722,
24137,
14,
199,
199,
607,
10234,
370,
314,
8963,
12,
1952,
280,
4778,
883,
2597,
1255,
9842,
3233,
3423,
2544,
436,
2410,
199,
1589,
5759,
805,
6337,
14,
5723,
787,
1240,
876,
436,
2963,
5759,
13484,
14,
1952,
280,
4778,
6127,
3663,
199,
657,
436,
2963,
5759,
13484,
370,
506,
3247,
1126,
1566,
12,
1325,
1630,
440,
24197,
314,
1865,
626,
2985,
199,
1530,
7934,
315,
14,
199,
199,
1378,
2040,
666,
370,
506,
3032,
370,
436,
687,
12604,
12,
1952,
280,
4778,
965,
314,
16819,
402,
2288,
436,
1566,
2257,
199,
1459,
14,
710,
2288,
1338,
22400,
315,
314,
1952,
280,
4778,
1256,
367,
2399,
30097,
12,
1325,
314,
1566,
2257,
199,
1459,
787,
28924,
737,
314,
1284,
402,
1924,
1566,
14,
199,
199,
15314,
1159,
5452,
314,
2893,
402,
1808,
314,
4137,
5343,
5241,
1134,
14,
396,
465,
376,
2893,
367,
1952,
280,
4778,
14,
199,
4710,
4070,
781,
1172,
282,
1329,
402,
2295,
626,
1255,
465,
1777,
402,
282,
511,
5241,
436,
781,
13809,
370,
3877,
282,
1318,
199,
493,
626,
15164,
314,
900,
314,
511,
1990,
1255,
436,
2399,
754,
14,
961,
2556,
365,
1415,
370,
295,
2441,
199,
262,
282,
4922,
626,
365,
12082,
370,
314,
511,
6337,
14,
961,
730,
402,
3906,
365,
4052,
1952,
280,
4778,
1990,
19829,
199,
509,
14,
199,
199,
1378,
5386,
543,
12,
781,
1929,
370,
1218,
282,
3589,
367,
1952,
280,
4778,
14,
24413,
314,
2569,
14854,
402,
1233,
447,
339,
687,
601,
280,
4778,
492,
1952,
280,
4778,
1563,
5061,
272,
492,
900,
2378,
1021,
1379,
8,
1596,
280,
4778,
1563,
5061,
304,
398,
347,
3589,
63,
8489,
8,
277,
304,
288,
291,
14,
2683,
63,
2718,
63,
3664,
360,
928,
63,
396,
297,
291,
14,
928,
63,
396,
9,
288,
291,
14,
2683,
63,
2718,
63,
3664,
360,
8192,
63,
396,
297,
291,
14,
8192,
63,
396,
9,
398,
347,
1343,
63,
396,
8,
277,
12,
511,
63,
354,
12,
511,
63,
1985,
12,
18115,
63,
515,
304,
288,
1788,
275,
18115,
63,
515,
435,
17155,
435,
291,
14,
5425,
435,
3680,
793,
2,
288,
543,
1551,
8,
1501,
12,
298,
87,
531,
465,
289,
26,
355,
289,
14,
952,
8,
396,
63,
354,
435,
1867,
78,
531,
355,
289,
14,
952,
8,
495,
8,
521,
14,
521,
1012,
435,
1867,
78,
531,
398,
347,
9578,
63,
396,
8,
277,
12,
511,
63,
354,
12,
18115,
63,
515,
12,
511,
63,
1099,
304,
288,
1788,
275,
18115,
63,
515,
435,
17155,
435,
291,
14,
5425,
435,
3680,
793,
2,
288,
543,
1551,
8,
1501,
12,
298,
87,
21425,
465,
289,
26,
355,
289,
14,
952,
8,
396,
63,
1099,
9,
199,
199,
2765,
365,
282,
25780,
3589,
315,
1952,
280,
4778,
12,
652,
18581,
402,
499,
7645,
14,
710,
1642,
1242,
365,
199,
1589,
4539,
805,
2797,
1124,
2718,
63,
8489,
28566,
961,
365,
11012,
199,
460,
365,
325,
783,
8657,
343,
370,
314,
9035,
826,
12352,
626,
3955,
9987,
506,
1911,
315,
282,
1021,
5492,
14,
199,
1596,
280,
4778,
4882,
1124,
2718,
63,
8489,
8497,
367,
1924,
3589,
465,
652,
14404,
652,
14,
199,
607,
2441,
642,
3420,
781,
2274,
314,
5759,
3423,
370,
3932,
4568,
4474,
14,
7048,
1566,
199,
2425,
1454,
1172,
282,
2849,
805,
4568,
543,
652,
14,
6763,
1561,
787,
7688,
370,
506,
20673,
7742,
7943,
199,
1152,
1265,
883,
17551,
8963,
370,
1736,
370,
2488,
4474,
367,
2195,
675,
1930,
14,
199,
1918,
1124,
2683,
63,
2718,
63,
3664,
8497,
6181,
376,
1566,
536,
465,
282,
1059,
436,
282,
805,
370,
3233,
1380,
199,
9099,
1566,
365,
444,
24242,
68,
14,
199,
199,
5765,
781,
1172,
314,
5759,
3423,
17279,
12,
1124,
928,
63,
396,
8497,
436,
1124,
8192,
63,
396,
28566,
5723,
199,
7804,
2368,
315,
3932,
19393,
83,
436,
3520,
2368,
787,
6841,
701,
1952,
280,
4778,
436,
787,
199,
3966,
1902,
465,
2368,
370,
314,
1124,
8935,
63,
3664,
8497,
805,
12,
1314,
365,
17845,
367,
5965,
199,
9974,
316,
1952,
280,
4778,
626,
376,
2755,
965,
28408,
12,
503,
2985,
787,
2737,
315,
314,
876,
5759,
2884,
14,
199,
199,
1596,
280,
4778,
4440,
314,
2288,
436,
2257,
1338,
11812,
14119,
370,
3877,
3520,
1423,
1338,
14,
199,
11423,
282,
876,
12,
2963,
503,
5759,
3233,
9578,
397,
12,
652,
965,
314,
30914,
370,
17169,
7029,
370,
3865,
199,
1589,
2288,
436,
2257,
1338,
11196,
14,
1010,
9689,
642,
12,
282,
876,
13,
3664,
2884,
883,
9275,
666,
12,
199,
6777,
911,
4293,
506,
5489,
315,
314,
9480,
2600,
436,
2066,
3032,
370,
314,
3503,
3589,
5759,
199,
305,
282,
4252,
1423,
14,
2257,
1338,
4278,
2288,
1338,
14,
199,
199,
6004,
1929,
370,
3648,
737,
376,
2893,
402,
642,
12,
1325,
1642,
781,
1471,
7908,
601,
280,
4778,
436,
314,
3589,
447,
339,
943,
63,
694,
26,
1182,
4219,
15,
278,
15,
285,
280,
548,
272,
1126,
63,
1065,
26,
1255,
327,
396,
12,
1255,
12,
488,
272,
8970,
26,
715,
272,
27990,
26,
267,
511,
26,
288,
5223,
26,
715,
288,
3589,
26,
511,
199,
199,
21741,
781,
1172,
3247,
282,
1124,
793,
63,
694,
1040,
1314,
911,
506,
314,
1738,
402,
1006,
402,
4154,
27990,
14,
2136,
1172,
20864,
199,
1596,
280,
4778,
370,
1572,
314,
27990,
701,
1255,
12,
1314,
4910,
626,
652
] |
[
199,
1596,
280,
4778,
199,
199,
1596,
280,
4778,
365,
1202,
370,
8775,
27990,
687,
282,
1329,
402,
3365,
8963,
436,
5324,
3062,
1901,
199,
368,
4192,
14,
1952,
280,
4778,
5419,
6818,
282,
6779,
402,
4474,
436,
365,
2312,
2899,
28354,
4137,
5343,
12,
10617,
199,
390,
365,
2178,
1164,
436,
3537,
14065,
8321,
626,
652,
883,
506,
1202,
367,
282,
32246,
402,
12901,
14,
199,
199,
1918,
2446,
486,
14608,
402,
1952,
280,
4778,
365,
6818,
314,
8963,
14,
21467,
1952,
280,
4778,
883,
886,
7003,
652,
1471,
1172,
199,
65,
7526,
3589,
14,
961,
3589,
365,
2066,
7526,
370,
5398,
9842,
3423,
6272,
6337,
199,
475,
9842,
4474,
14,
3979,
1952,
280,
4778,
365,
15572,
370,
2429,
282,
9842,
1566,
12,
652,
911,
11480,
314,
3589,
199,
9099,
626,
6770,
1566,
965,
21056,
436,
314,
3589,
911,
22722,
24137,
14,
199,
199,
607,
10234,
370,
314,
8963,
12,
1952,
280,
4778,
883,
2597,
1255,
9842,
3233,
3423,
2544,
436,
2410,
199,
1589,
5759,
805,
6337,
14,
5723,
787,
1240,
876,
436,
2963,
5759,
13484,
14,
1952,
280,
4778,
6127,
3663,
199,
657,
436,
2963,
5759,
13484,
370,
506,
3247,
1126,
1566,
12,
1325,
1630,
440,
24197,
314,
1865,
626,
2985,
199,
1530,
7934,
315,
14,
199,
199,
1378,
2040,
666,
370,
506,
3032,
370,
436,
687,
12604,
12,
1952,
280,
4778,
965,
314,
16819,
402,
2288,
436,
1566,
2257,
199,
1459,
14,
710,
2288,
1338,
22400,
315,
314,
1952,
280,
4778,
1256,
367,
2399,
30097,
12,
1325,
314,
1566,
2257,
199,
1459,
787,
28924,
737,
314,
1284,
402,
1924,
1566,
14,
199,
199,
15314,
1159,
5452,
314,
2893,
402,
1808,
314,
4137,
5343,
5241,
1134,
14,
396,
465,
376,
2893,
367,
1952,
280,
4778,
14,
199,
4710,
4070,
781,
1172,
282,
1329,
402,
2295,
626,
1255,
465,
1777,
402,
282,
511,
5241,
436,
781,
13809,
370,
3877,
282,
1318,
199,
493,
626,
15164,
314,
900,
314,
511,
1990,
1255,
436,
2399,
754,
14,
961,
2556,
365,
1415,
370,
295,
2441,
199,
262,
282,
4922,
626,
365,
12082,
370,
314,
511,
6337,
14,
961,
730,
402,
3906,
365,
4052,
1952,
280,
4778,
1990,
19829,
199,
509,
14,
199,
199,
1378,
5386,
543,
12,
781,
1929,
370,
1218,
282,
3589,
367,
1952,
280,
4778,
14,
24413,
314,
2569,
14854,
402,
1233,
447,
339,
687,
601,
280,
4778,
492,
1952,
280,
4778,
1563,
5061,
272,
492,
900,
2378,
1021,
1379,
8,
1596,
280,
4778,
1563,
5061,
304,
398,
347,
3589,
63,
8489,
8,
277,
304,
288,
291,
14,
2683,
63,
2718,
63,
3664,
360,
928,
63,
396,
297,
291,
14,
928,
63,
396,
9,
288,
291,
14,
2683,
63,
2718,
63,
3664,
360,
8192,
63,
396,
297,
291,
14,
8192,
63,
396,
9,
398,
347,
1343,
63,
396,
8,
277,
12,
511,
63,
354,
12,
511,
63,
1985,
12,
18115,
63,
515,
304,
288,
1788,
275,
18115,
63,
515,
435,
17155,
435,
291,
14,
5425,
435,
3680,
793,
2,
288,
543,
1551,
8,
1501,
12,
298,
87,
531,
465,
289,
26,
355,
289,
14,
952,
8,
396,
63,
354,
435,
1867,
78,
531,
355,
289,
14,
952,
8,
495,
8,
521,
14,
521,
1012,
435,
1867,
78,
531,
398,
347,
9578,
63,
396,
8,
277,
12,
511,
63,
354,
12,
18115,
63,
515,
12,
511,
63,
1099,
304,
288,
1788,
275,
18115,
63,
515,
435,
17155,
435,
291,
14,
5425,
435,
3680,
793,
2,
288,
543,
1551,
8,
1501,
12,
298,
87,
21425,
465,
289,
26,
355,
289,
14,
952,
8,
396,
63,
1099,
9,
199,
199,
2765,
365,
282,
25780,
3589,
315,
1952,
280,
4778,
12,
652,
18581,
402,
499,
7645,
14,
710,
1642,
1242,
365,
199,
1589,
4539,
805,
2797,
1124,
2718,
63,
8489,
28566,
961,
365,
11012,
199,
460,
365,
325,
783,
8657,
343,
370,
314,
9035,
826,
12352,
626,
3955,
9987,
506,
1911,
315,
282,
1021,
5492,
14,
199,
1596,
280,
4778,
4882,
1124,
2718,
63,
8489,
8497,
367,
1924,
3589,
465,
652,
14404,
652,
14,
199,
607,
2441,
642,
3420,
781,
2274,
314,
5759,
3423,
370,
3932,
4568,
4474,
14,
7048,
1566,
199,
2425,
1454,
1172,
282,
2849,
805,
4568,
543,
652,
14,
6763,
1561,
787,
7688,
370,
506,
20673,
7742,
7943,
199,
1152,
1265,
883,
17551,
8963,
370,
1736,
370,
2488,
4474,
367,
2195,
675,
1930,
14,
199,
1918,
1124,
2683,
63,
2718,
63,
3664,
8497,
6181,
376,
1566,
536,
465,
282,
1059,
436,
282,
805,
370,
3233,
1380,
199,
9099,
1566,
365,
444,
24242,
68,
14,
199,
199,
5765,
781,
1172,
314,
5759,
3423,
17279,
12,
1124,
928,
63,
396,
8497,
436,
1124,
8192,
63,
396,
28566,
5723,
199,
7804,
2368,
315,
3932,
19393,
83,
436,
3520,
2368,
787,
6841,
701,
1952,
280,
4778,
436,
787,
199,
3966,
1902,
465,
2368,
370,
314,
1124,
8935,
63,
3664,
8497,
805,
12,
1314,
365,
17845,
367,
5965,
199,
9974,
316,
1952,
280,
4778,
626,
376,
2755,
965,
28408,
12,
503,
2985,
787,
2737,
315,
314,
876,
5759,
2884,
14,
199,
199,
1596,
280,
4778,
4440,
314,
2288,
436,
2257,
1338,
11812,
14119,
370,
3877,
3520,
1423,
1338,
14,
199,
11423,
282,
876,
12,
2963,
503,
5759,
3233,
9578,
397,
12,
652,
965,
314,
30914,
370,
17169,
7029,
370,
3865,
199,
1589,
2288,
436,
2257,
1338,
11196,
14,
1010,
9689,
642,
12,
282,
876,
13,
3664,
2884,
883,
9275,
666,
12,
199,
6777,
911,
4293,
506,
5489,
315,
314,
9480,
2600,
436,
2066,
3032,
370,
314,
3503,
3589,
5759,
199,
305,
282,
4252,
1423,
14,
2257,
1338,
4278,
2288,
1338,
14,
199,
199,
6004,
1929,
370,
3648,
737,
376,
2893,
402,
642,
12,
1325,
1642,
781,
1471,
7908,
601,
280,
4778,
436,
314,
3589,
447,
339,
943,
63,
694,
26,
1182,
4219,
15,
278,
15,
285,
280,
548,
272,
1126,
63,
1065,
26,
1255,
327,
396,
12,
1255,
12,
488,
272,
8970,
26,
715,
272,
27990,
26,
267,
511,
26,
288,
5223,
26,
715,
288,
3589,
26,
511,
199,
199,
21741,
781,
1172,
3247,
282,
1124,
793,
63,
694,
1040,
1314,
911,
506,
314,
1738,
402,
1006,
402,
4154,
27990,
14,
2136,
1172,
20864,
199,
1596,
280,
4778,
370,
1572,
314,
27990,
701,
1255,
12,
1314,
4910,
626,
652,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
wunderlins/learning
|
python/django/lib/python2.7/site-packages/django/contrib/redirects/migrations/0001_initial.py
|
308
|
1561
|
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('sites', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='Redirect',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('site', models.ForeignKey(
to='sites.Site',
to_field='id',
on_delete=models.CASCADE,
verbose_name='site',
)),
('old_path', models.CharField(
help_text=(
"This should be an absolute path, excluding the domain name. Example: '/events/search/'."
), max_length=200, verbose_name='redirect from', db_index=True
)),
('new_path', models.CharField(
help_text="This can be either an absolute path (as above) or a full URL starting with 'http://'.",
max_length=200, verbose_name='redirect to', blank=True
)),
],
options={
'ordering': ('old_path',),
'unique_together': set([('site', 'old_path')]),
'db_table': 'django_redirect',
'verbose_name': 'redirect',
'verbose_name_plural': 'redirects',
},
bases=(models.Model,),
),
]
|
gpl-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
697,
492,
6180,
12,
1709,
421,
199,
533,
12090,
8,
7685,
14,
9816,
304,
339,
5124,
275,
359,
267,
661,
8619,
297,
283,
4183,
63,
2747,
659,
272,
1622,
339,
5331,
275,
359,
267,
6180,
14,
14907,
8,
288,
536,
534,
7071,
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,
2124,
297,
1709,
14,
3190,
8,
490,
370,
534,
8619,
14,
8972,
297,
490,
370,
63,
698,
534,
344,
297,
490,
641,
63,
1807,
29,
992,
14,
10855,
12,
490,
3376,
63,
354,
534,
2124,
297,
355,
22583,
355,
661,
1753,
63,
515,
297,
1709,
14,
2183,
8,
490,
1720,
63,
505,
2687,
717,
298,
2765,
1077,
506,
376,
3679,
931,
12,
28529,
314,
2881,
536,
14,
5679,
26,
1994,
4368,
15,
1733,
15,
16669,
490,
2318,
1390,
63,
1267,
29,
1840,
12,
3376,
63,
354,
534,
4876,
687,
297,
1592,
63,
1080,
29,
549,
355,
22583,
355,
661,
1222,
63,
515,
297,
1709,
14,
2183,
8,
490,
1720,
63,
505,
628,
2765,
883,
506,
1902,
376,
3679,
931,
334,
305,
3432,
9,
503,
282,
2615,
2851,
6617,
543,
283,
1014,
921,
30532,
490,
1390,
63,
1267,
29,
1840,
12,
3376,
63,
354,
534,
4876,
370,
297,
4596,
29,
549,
355,
22583,
288,
2156,
288,
1511,
3126,
355,
283,
7128,
356,
661,
1753,
63,
515,
5529,
355,
283,
3235,
63,
6314,
356,
663,
8318,
2124,
297,
283,
1753,
63,
515,
22864,
355,
283,
697,
63,
1224,
356,
283,
1176,
63,
4876,
297,
355,
283,
3832,
63,
354,
356,
283,
4876,
297,
355,
283,
3832,
63,
354,
63,
10019,
356,
283,
13607,
297,
288,
1660,
288,
9768,
2687,
992,
14,
1685,
4706,
267,
2318,
272,
1622,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
697,
492,
6180,
12,
1709,
421,
199,
533,
12090,
8,
7685,
14,
9816,
304,
339,
5124,
275,
359,
267,
661,
8619,
297,
283,
4183,
63,
2747,
659,
272,
1622,
339,
5331,
275,
359,
267,
6180,
14,
14907,
8,
288,
536,
534,
7071,
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,
2124,
297,
1709,
14,
3190,
8,
490,
370,
534,
8619,
14,
8972,
297,
490,
370,
63,
698,
534,
344,
297,
490,
641,
63,
1807,
29,
992,
14,
10855,
12,
490,
3376,
63,
354,
534,
2124,
297,
355,
22583,
355,
661,
1753,
63,
515,
297,
1709,
14,
2183,
8,
490,
1720,
63,
505,
2687,
717,
298,
2765,
1077,
506,
376,
3679,
931,
12,
28529,
314,
2881,
536,
14,
5679,
26,
1994,
4368,
15,
1733,
15,
16669,
490,
2318,
1390,
63,
1267,
29,
1840,
12,
3376,
63,
354,
534,
4876,
687,
297,
1592,
63,
1080,
29,
549,
355,
22583,
355,
661,
1222,
63,
515,
297,
1709,
14,
2183,
8,
490,
1720,
63,
505,
628,
2765,
883,
506,
1902,
376,
3679,
931,
334,
305,
3432,
9,
503,
282,
2615,
2851,
6617,
543,
283,
1014,
921,
30532,
490,
1390,
63,
1267,
29,
1840,
12,
3376,
63,
354,
534,
4876,
370,
297,
4596,
29,
549,
355,
22583,
288,
2156,
288,
1511,
3126,
355,
283,
7128,
356,
661,
1753,
63,
515,
5529,
355,
283,
3235,
63,
6314,
356,
663,
8318,
2124,
297,
283,
1753,
63,
515,
22864,
355,
283,
697,
63,
1224,
356,
283,
1176,
63,
4876,
297,
355,
283,
3832,
63,
354,
356,
283,
4876,
297,
355,
283,
3832,
63,
354,
63,
10019,
356,
283,
13607,
297,
288,
1660,
288,
9768,
2687,
992,
14,
1685,
4706,
267,
2318,
272,
1622,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
TGITS/programming-workouts
|
exercism/python/raindrops/raindrops_test.py
|
5
|
2283
|
import unittest
from raindrops import convert
# Tests adapted from `problem-specifications//canonical-data.json` @ v1.1.0
class RaindropsTest(unittest.TestCase):
def test_the_sound_for_1_is_1(self):
self.assertEqual(convert(1), "1")
def test_the_sound_for_3_is_pling(self):
self.assertEqual(convert(3), "Pling")
def test_the_sound_for_5_is_plang(self):
self.assertEqual(convert(5), "Plang")
def test_the_sound_for_7_is_plong(self):
self.assertEqual(convert(7), "Plong")
def test_the_sound_for_6_is_pling_as_it_has_a_factor_3(self):
self.assertEqual(convert(6), "Pling")
def test_2_to_the_power_3_does_not_make_a_raindrop_sound_as_3_is_the_exponent_not_the_base(
self
):
self.assertEqual(convert(8), "8")
def test_the_sound_for_9_is_pling_as_it_has_a_factor_3(self):
self.assertEqual(convert(9), "Pling")
def test_the_sound_for_10_is_plang_as_it_has_a_factor_5(self):
self.assertEqual(convert(10), "Plang")
def test_the_sound_for_14_is_plong_as_it_has_a_factor_of_7(self):
self.assertEqual(convert(14), "Plong")
def test_the_sound_for_15_is_pling_plang_as_it_has_factors_3_and_5(self):
self.assertEqual(convert(15), "PlingPlang")
def test_the_sound_for_21_is_pling_plong_as_it_has_factors_3_and_7(self):
self.assertEqual(convert(21), "PlingPlong")
def test_the_sound_for_25_is_plang_as_it_has_a_factor_5(self):
self.assertEqual(convert(25), "Plang")
def test_the_sound_for_27_is_pling_as_it_has_a_factor_3(self):
self.assertEqual(convert(27), "Pling")
def test_the_sound_for_35_is_plang_plong_as_it_has_factors_5_and_7(self):
self.assertEqual(convert(35), "PlangPlong")
def test_the_sound_for_49_is_plong_as_it_has_a_factor_7(self):
self.assertEqual(convert(49), "Plong")
def test_the_sound_for_52_is_52(self):
self.assertEqual(convert(52), "52")
def test_the_sound_for_105_is_pling_plang_plong_as_it_has_factors_3_5_and_7(self):
self.assertEqual(convert(105), "PlingPlangPlong")
def test_the_sound_for_3125_is_plang_as_it_has_a_factor_5(self):
self.assertEqual(convert(3125), "Plang")
if __name__ == "__main__":
unittest.main()
|
mit
|
[
646,
2882,
199,
199,
504,
660,
688,
26307,
492,
3957,
199,
199,
3,
6496,
26266,
687,
658,
6462,
13,
22271,
83,
501,
13109,
13,
576,
14,
1001,
64,
768,
373,
17,
14,
17,
14,
16,
421,
199,
533,
3898,
688,
26307,
774,
8,
2796,
14,
1746,
304,
272,
347,
511,
63,
1589,
63,
14990,
63,
509,
63,
17,
63,
374,
63,
17,
8,
277,
304,
267,
291,
14,
629,
8,
3916,
8,
17,
395,
298,
17,
531,
339,
347,
511,
63,
1589,
63,
14990,
63,
509,
63,
19,
63,
374,
63,
1168,
316,
8,
277,
304,
267,
291,
14,
629,
8,
3916,
8,
19,
395,
298,
48,
2983,
531,
339,
347,
511,
63,
1589,
63,
14990,
63,
509,
63,
21,
63,
374,
63,
1168,
621,
8,
277,
304,
267,
291,
14,
629,
8,
3916,
8,
21,
395,
298,
3714,
621,
531,
339,
347,
511,
63,
1589,
63,
14990,
63,
509,
63,
23,
63,
374,
63,
1168,
951,
8,
277,
304,
267,
291,
14,
629,
8,
3916,
8,
23,
395,
298,
48,
2809,
531,
339,
347,
511,
63,
1589,
63,
14990,
63,
509,
63,
22,
63,
374,
63,
1168,
316,
63,
305,
63,
390,
63,
1989,
63,
65,
63,
4778,
63,
19,
8,
277,
304,
267,
291,
14,
629,
8,
3916,
8,
22,
395,
298,
48,
2983,
531,
339,
347,
511,
63,
18,
63,
475,
63,
1589,
63,
5652,
63,
19,
63,
9105,
63,
1397,
63,
1875,
63,
65,
63,
345,
688,
2675,
63,
14990,
63,
305,
63,
19,
63,
374,
63,
1589,
63,
23475,
63,
1397,
63,
1589,
63,
1095,
8,
267,
291,
272,
3461,
267,
291,
14,
629,
8,
3916,
8,
24,
395,
298,
24,
531,
339,
347,
511,
63,
1589,
63,
14990,
63,
509,
63,
25,
63,
374,
63,
1168,
316,
63,
305,
63,
390,
63,
1989,
63,
65,
63,
4778,
63,
19,
8,
277,
304,
267,
291,
14,
629,
8,
3916,
8,
25,
395,
298,
48,
2983,
531,
339,
347,
511,
63,
1589,
63,
14990,
63,
509,
63,
709,
63,
374,
63,
1168,
621,
63,
305,
63,
390,
63,
1989,
63,
65,
63,
4778,
63,
21,
8,
277,
304,
267,
291,
14,
629,
8,
3916,
8,
709,
395,
298,
3714,
621,
531,
339,
347,
511,
63,
1589,
63,
14990,
63,
509,
63,
1079,
63,
374,
63,
1168,
951,
63,
305,
63,
390,
63,
1989,
63,
65,
63,
4778,
63,
1618,
63,
23,
8,
277,
304,
267,
291,
14,
629,
8,
3916,
8,
1079,
395,
298,
48,
2809,
531,
339,
347,
511,
63,
1589,
63,
14990,
63,
509,
63,
1046,
63,
374,
63,
1168,
316,
63,
1168,
621,
63,
305,
63,
390,
63,
1989,
63,
16125,
63,
19,
63,
460,
63,
21,
8,
277,
304,
267,
291,
14,
629,
8,
3916,
8,
1046,
395,
298,
48,
2983,
3714,
621,
531,
339,
347,
511,
63,
1589,
63,
14990,
63,
509,
63,
2025,
63,
374,
63,
1168,
316,
63,
1168,
951,
63,
305,
63,
390,
63,
1989,
63,
16125,
63,
19,
63,
460,
63,
23,
8,
277,
304,
267,
291,
14,
629,
8,
3916,
8,
2025,
395,
298,
48,
2983,
48,
2809,
531,
339,
347,
511,
63,
1589,
63,
14990,
63,
509,
63,
821,
63,
374,
63,
1168,
621,
63,
305,
63,
390,
63,
1989,
63,
65,
63,
4778,
63,
21,
8,
277,
304,
267,
291,
14,
629,
8,
3916,
8,
821,
395,
298,
3714,
621,
531,
339,
347,
511,
63,
1589,
63,
14990,
63,
509,
63,
1465,
63,
374,
63,
1168,
316,
63,
305,
63,
390,
63,
1989,
63,
65,
63,
4778,
63,
19,
8,
277,
304,
267,
291,
14,
629,
8,
3916,
8,
1465,
395,
298,
48,
2983,
531,
339,
347,
511,
63,
1589,
63,
14990,
63,
509,
63,
1276,
63,
374,
63,
1168,
621,
63,
1168,
951,
63,
305,
63,
390,
63,
1989,
63,
16125,
63,
21,
63,
460,
63,
23,
8,
277,
304,
267,
291,
14,
629,
8,
3916,
8,
1276,
395,
298,
3714,
621,
48,
2809,
531,
339,
347,
511,
63,
1589,
63,
14990,
63,
509,
63,
1887,
63,
374,
63,
1168,
951,
63,
305,
63,
390,
63,
1989,
63,
65,
63,
4778,
63,
23,
8,
277,
304,
267,
291,
14,
629,
8,
3916,
8,
1887,
395,
298,
48,
2809,
531,
339,
347,
511,
63,
1589,
63,
14990,
63,
509,
63,
2528,
63,
374,
63,
2528,
8,
277,
304,
267,
291,
14,
629,
8,
3916,
8,
2528,
395,
298,
2528,
531,
339,
347,
511,
63,
1589,
63,
14990,
63,
509,
63,
7320,
63,
374,
63,
1168,
316,
63,
1168,
621,
63,
1168,
951,
63,
305,
63,
390,
63,
1989,
63,
16125,
63,
19,
63,
21,
63,
460,
63,
23,
8,
277,
304,
267,
291,
14,
629,
8,
3916,
8,
7320,
395,
298,
48,
2983,
3714,
621,
48,
2809,
531,
339,
347,
511,
63,
1589,
63,
14990,
63,
509,
63,
19,
6889,
63,
374,
63,
1168,
621,
63,
305,
63,
390,
63,
1989,
63,
65,
63,
4778,
63,
21,
8,
277,
304,
267,
291,
14,
629,
8,
3916,
8,
19,
6889,
395,
298,
3714,
621,
531,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
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
] |
[
2882,
199,
199,
504,
660,
688,
26307,
492,
3957,
199,
199,
3,
6496,
26266,
687,
658,
6462,
13,
22271,
83,
501,
13109,
13,
576,
14,
1001,
64,
768,
373,
17,
14,
17,
14,
16,
421,
199,
533,
3898,
688,
26307,
774,
8,
2796,
14,
1746,
304,
272,
347,
511,
63,
1589,
63,
14990,
63,
509,
63,
17,
63,
374,
63,
17,
8,
277,
304,
267,
291,
14,
629,
8,
3916,
8,
17,
395,
298,
17,
531,
339,
347,
511,
63,
1589,
63,
14990,
63,
509,
63,
19,
63,
374,
63,
1168,
316,
8,
277,
304,
267,
291,
14,
629,
8,
3916,
8,
19,
395,
298,
48,
2983,
531,
339,
347,
511,
63,
1589,
63,
14990,
63,
509,
63,
21,
63,
374,
63,
1168,
621,
8,
277,
304,
267,
291,
14,
629,
8,
3916,
8,
21,
395,
298,
3714,
621,
531,
339,
347,
511,
63,
1589,
63,
14990,
63,
509,
63,
23,
63,
374,
63,
1168,
951,
8,
277,
304,
267,
291,
14,
629,
8,
3916,
8,
23,
395,
298,
48,
2809,
531,
339,
347,
511,
63,
1589,
63,
14990,
63,
509,
63,
22,
63,
374,
63,
1168,
316,
63,
305,
63,
390,
63,
1989,
63,
65,
63,
4778,
63,
19,
8,
277,
304,
267,
291,
14,
629,
8,
3916,
8,
22,
395,
298,
48,
2983,
531,
339,
347,
511,
63,
18,
63,
475,
63,
1589,
63,
5652,
63,
19,
63,
9105,
63,
1397,
63,
1875,
63,
65,
63,
345,
688,
2675,
63,
14990,
63,
305,
63,
19,
63,
374,
63,
1589,
63,
23475,
63,
1397,
63,
1589,
63,
1095,
8,
267,
291,
272,
3461,
267,
291,
14,
629,
8,
3916,
8,
24,
395,
298,
24,
531,
339,
347,
511,
63,
1589,
63,
14990,
63,
509,
63,
25,
63,
374,
63,
1168,
316,
63,
305,
63,
390,
63,
1989,
63,
65,
63,
4778,
63,
19,
8,
277,
304,
267,
291,
14,
629,
8,
3916,
8,
25,
395,
298,
48,
2983,
531,
339,
347,
511,
63,
1589,
63,
14990,
63,
509,
63,
709,
63,
374,
63,
1168,
621,
63,
305,
63,
390,
63,
1989,
63,
65,
63,
4778,
63,
21,
8,
277,
304,
267,
291,
14,
629,
8,
3916,
8,
709,
395,
298,
3714,
621,
531,
339,
347,
511,
63,
1589,
63,
14990,
63,
509,
63,
1079,
63,
374,
63,
1168,
951,
63,
305,
63,
390,
63,
1989,
63,
65,
63,
4778,
63,
1618,
63,
23,
8,
277,
304,
267,
291,
14,
629,
8,
3916,
8,
1079,
395,
298,
48,
2809,
531,
339,
347,
511,
63,
1589,
63,
14990,
63,
509,
63,
1046,
63,
374,
63,
1168,
316,
63,
1168,
621,
63,
305,
63,
390,
63,
1989,
63,
16125,
63,
19,
63,
460,
63,
21,
8,
277,
304,
267,
291,
14,
629,
8,
3916,
8,
1046,
395,
298,
48,
2983,
3714,
621,
531,
339,
347,
511,
63,
1589,
63,
14990,
63,
509,
63,
2025,
63,
374,
63,
1168,
316,
63,
1168,
951,
63,
305,
63,
390,
63,
1989,
63,
16125,
63,
19,
63,
460,
63,
23,
8,
277,
304,
267,
291,
14,
629,
8,
3916,
8,
2025,
395,
298,
48,
2983,
48,
2809,
531,
339,
347,
511,
63,
1589,
63,
14990,
63,
509,
63,
821,
63,
374,
63,
1168,
621,
63,
305,
63,
390,
63,
1989,
63,
65,
63,
4778,
63,
21,
8,
277,
304,
267,
291,
14,
629,
8,
3916,
8,
821,
395,
298,
3714,
621,
531,
339,
347,
511,
63,
1589,
63,
14990,
63,
509,
63,
1465,
63,
374,
63,
1168,
316,
63,
305,
63,
390,
63,
1989,
63,
65,
63,
4778,
63,
19,
8,
277,
304,
267,
291,
14,
629,
8,
3916,
8,
1465,
395,
298,
48,
2983,
531,
339,
347,
511,
63,
1589,
63,
14990,
63,
509,
63,
1276,
63,
374,
63,
1168,
621,
63,
1168,
951,
63,
305,
63,
390,
63,
1989,
63,
16125,
63,
21,
63,
460,
63,
23,
8,
277,
304,
267,
291,
14,
629,
8,
3916,
8,
1276,
395,
298,
3714,
621,
48,
2809,
531,
339,
347,
511,
63,
1589,
63,
14990,
63,
509,
63,
1887,
63,
374,
63,
1168,
951,
63,
305,
63,
390,
63,
1989,
63,
65,
63,
4778,
63,
23,
8,
277,
304,
267,
291,
14,
629,
8,
3916,
8,
1887,
395,
298,
48,
2809,
531,
339,
347,
511,
63,
1589,
63,
14990,
63,
509,
63,
2528,
63,
374,
63,
2528,
8,
277,
304,
267,
291,
14,
629,
8,
3916,
8,
2528,
395,
298,
2528,
531,
339,
347,
511,
63,
1589,
63,
14990,
63,
509,
63,
7320,
63,
374,
63,
1168,
316,
63,
1168,
621,
63,
1168,
951,
63,
305,
63,
390,
63,
1989,
63,
16125,
63,
19,
63,
21,
63,
460,
63,
23,
8,
277,
304,
267,
291,
14,
629,
8,
3916,
8,
7320,
395,
298,
48,
2983,
3714,
621,
48,
2809,
531,
339,
347,
511,
63,
1589,
63,
14990,
63,
509,
63,
19,
6889,
63,
374,
63,
1168,
621,
63,
305,
63,
390,
63,
1989,
63,
65,
63,
4778,
63,
21,
8,
277,
304,
267,
291,
14,
629,
8,
3916,
8,
19,
6889,
395,
298,
3714,
621,
531,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
lpirl/ansible
|
lib/ansible/executor/task_queue_manager.py
|
1
|
14192
|
# (c) 2012-2014, Michael DeHaan <michael.dehaan@gmail.com>
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import multiprocessing
import os
import tempfile
from ansible import constants as C
from ansible.errors import AnsibleError
from ansible.executor.play_iterator import PlayIterator
from ansible.executor.process.result import ResultProcess
from ansible.executor.stats import AggregateStats
from ansible.playbook.block import Block
from ansible.playbook.play_context import PlayContext
from ansible.plugins import callback_loader, strategy_loader, module_loader
from ansible.template import Templar
from ansible.vars.hostvars import HostVars
from ansible.plugins.callback import CallbackBase
from ansible.utils.unicode import to_unicode
from ansible.compat.six import string_types
try:
from __main__ import display
except ImportError:
from ansible.utils.display import Display
display = Display()
__all__ = ['TaskQueueManager']
class TaskQueueManager:
'''
This class handles the multiprocessing requirements of Ansible by
creating a pool of worker forks, a result handler fork, and a
manager object with shared datastructures/queues for coordinating
work between all processes.
The queue manager is responsible for loading the play strategy plugin,
which dispatches the Play's tasks to hosts.
'''
RUN_OK = 0
RUN_ERROR = 1
RUN_FAILED_HOSTS = 2
RUN_UNREACHABLE_HOSTS = 3
RUN_FAILED_BREAK_PLAY = 4
RUN_UNKNOWN_ERROR = 255
def __init__(self, inventory, variable_manager, loader, options, passwords, stdout_callback=None, run_additional_callbacks=True, run_tree=False):
self._inventory = inventory
self._variable_manager = variable_manager
self._loader = loader
self._options = options
self._stats = AggregateStats()
self.passwords = passwords
self._stdout_callback = stdout_callback
self._run_additional_callbacks = run_additional_callbacks
self._run_tree = run_tree
self._callbacks_loaded = False
self._callback_plugins = []
self._start_at_done = False
self._result_prc = None
# make sure the module path (if specified) is parsed and
# added to the module_loader object
if options.module_path is not None:
for path in options.module_path.split(os.pathsep):
module_loader.add_directory(path)
# a special flag to help us exit cleanly
self._terminated = False
# this dictionary is used to keep track of notified handlers
self._notified_handlers = dict()
# dictionaries to keep track of failed/unreachable hosts
self._failed_hosts = dict()
self._unreachable_hosts = dict()
self._final_q = multiprocessing.Queue()
# A temporary file (opened pre-fork) used by connection
# plugins for inter-process locking.
self._connection_lockfile = tempfile.TemporaryFile()
def _initialize_processes(self, num):
self._workers = []
for i in range(num):
rslt_q = multiprocessing.Queue()
self._workers.append([None, rslt_q])
self._result_prc = ResultProcess(self._final_q, self._workers)
self._result_prc.start()
def _initialize_notified_handlers(self, handlers):
'''
Clears and initializes the shared notified handlers dict with entries
for each handler in the play, which is an empty array that will contain
inventory hostnames for those hosts triggering the handler.
'''
# Zero the dictionary first by removing any entries there.
# Proxied dicts don't support iteritems, so we have to use keys()
for key in self._notified_handlers.keys():
del self._notified_handlers[key]
def _process_block(b):
temp_list = []
for t in b.block:
if isinstance(t, Block):
temp_list.extend(_process_block(t))
else:
temp_list.append(t)
return temp_list
handler_list = []
for handler_block in handlers:
handler_list.extend(_process_block(handler_block))
# then initialize it with the handler names from the handler list
for handler in handler_list:
self._notified_handlers[handler.get_name()] = []
def load_callbacks(self):
'''
Loads all available callbacks, with the exception of those which
utilize the CALLBACK_TYPE option. When CALLBACK_TYPE is set to 'stdout',
only one such callback plugin will be loaded.
'''
if self._callbacks_loaded:
return
stdout_callback_loaded = False
if self._stdout_callback is None:
self._stdout_callback = C.DEFAULT_STDOUT_CALLBACK
if isinstance(self._stdout_callback, CallbackBase):
stdout_callback_loaded = True
elif isinstance(self._stdout_callback, string_types):
if self._stdout_callback not in callback_loader:
raise AnsibleError("Invalid callback for stdout specified: %s" % self._stdout_callback)
else:
self._stdout_callback = callback_loader.get(self._stdout_callback)
stdout_callback_loaded = True
else:
raise AnsibleError("callback must be an instance of CallbackBase or the name of a callback plugin")
for callback_plugin in callback_loader.all(class_only=True):
if hasattr(callback_plugin, 'CALLBACK_VERSION') and callback_plugin.CALLBACK_VERSION >= 2.0:
# we only allow one callback of type 'stdout' to be loaded, so check
# the name of the current plugin and type to see if we need to skip
# loading this callback plugin
callback_type = getattr(callback_plugin, 'CALLBACK_TYPE', None)
callback_needs_whitelist = getattr(callback_plugin, 'CALLBACK_NEEDS_WHITELIST', False)
(callback_name, _) = os.path.splitext(os.path.basename(callback_plugin._original_path))
if callback_type == 'stdout':
if callback_name != self._stdout_callback or stdout_callback_loaded:
continue
stdout_callback_loaded = True
elif callback_name == 'tree' and self._run_tree:
pass
elif not self._run_additional_callbacks or (callback_needs_whitelist and (C.DEFAULT_CALLBACK_WHITELIST is None or callback_name not in C.DEFAULT_CALLBACK_WHITELIST)):
continue
self._callback_plugins.append(callback_plugin())
self._callbacks_loaded = True
def run(self, play):
'''
Iterates over the roles/tasks in a play, using the given (or default)
strategy for queueing tasks. The default is the linear strategy, which
operates like classic Ansible by keeping all hosts in lock-step with
a given task (meaning no hosts move on to the next task until all hosts
are done with the current task).
'''
if not self._callbacks_loaded:
self.load_callbacks()
all_vars = self._variable_manager.get_vars(loader=self._loader, play=play)
templar = Templar(loader=self._loader, variables=all_vars)
new_play = play.copy()
new_play.post_validate(templar)
self.hostvars = HostVars(
inventory=self._inventory,
variable_manager=self._variable_manager,
loader=self._loader,
)
# Fork # of forks, # of hosts or serial, whichever is lowest
contenders = [self._options.forks, play.serial, len(self._inventory.get_hosts(new_play.hosts))]
contenders = [ v for v in contenders if v is not None and v > 0 ]
self._initialize_processes(min(contenders))
play_context = PlayContext(new_play, self._options, self.passwords, self._connection_lockfile.fileno())
for callback_plugin in self._callback_plugins:
if hasattr(callback_plugin, 'set_play_context'):
callback_plugin.set_play_context(play_context)
self.send_callback('v2_playbook_on_play_start', new_play)
# initialize the shared dictionary containing the notified handlers
self._initialize_notified_handlers(new_play.handlers)
# load the specified strategy (or the default linear one)
strategy = strategy_loader.get(new_play.strategy, self)
if strategy is None:
raise AnsibleError("Invalid play strategy specified: %s" % new_play.strategy, obj=play._ds)
# build the iterator
iterator = PlayIterator(
inventory=self._inventory,
play=new_play,
play_context=play_context,
variable_manager=self._variable_manager,
all_vars=all_vars,
start_at_done = self._start_at_done,
)
# Because the TQM may survive multiple play runs, we start by marking
# any hosts as failed in the iterator here which may have been marked
# as failed in previous runs. Then we clear the internal list of failed
# hosts so we know what failed this round.
for host_name in self._failed_hosts.keys():
host = self._inventory.get_host(host_name)
iterator.mark_host_failed(host)
self.clear_failed_hosts()
# during initialization, the PlayContext will clear the start_at_task
# field to signal that a matching task was found, so check that here
# and remember it so we don't try to skip tasks on future plays
if getattr(self._options, 'start_at_task', None) is not None and play_context.start_at_task is None:
self._start_at_done = True
# and run the play using the strategy and cleanup on way out
play_return = strategy.run(iterator, play_context)
# now re-save the hosts that failed from the iterator to our internal list
for host_name in iterator.get_failed_hosts():
self._failed_hosts[host_name] = True
self._cleanup_processes()
return play_return
def cleanup(self):
display.debug("RUNNING CLEANUP")
self.terminate()
self._final_q.close()
self._cleanup_processes()
def _cleanup_processes(self):
if self._result_prc:
self._result_prc.terminate()
for (worker_prc, rslt_q) in self._workers:
rslt_q.close()
if worker_prc and worker_prc.is_alive():
try:
worker_prc.terminate()
except AttributeError:
pass
def clear_failed_hosts(self):
self._failed_hosts = dict()
def get_inventory(self):
return self._inventory
def get_variable_manager(self):
return self._variable_manager
def get_loader(self):
return self._loader
def get_notified_handlers(self):
return self._notified_handlers
def get_workers(self):
return self._workers[:]
def terminate(self):
self._terminated = True
def send_callback(self, method_name, *args, **kwargs):
for callback_plugin in [self._stdout_callback] + self._callback_plugins:
# a plugin that set self.disabled to True will not be called
# see osx_say.py example for such a plugin
if getattr(callback_plugin, 'disabled', False):
continue
# try to find v2 method, fallback to v1 method, ignore callback if no method found
methods = []
for possible in [method_name, 'v2_on_any']:
gotit = getattr(callback_plugin, possible, None)
if gotit is None:
gotit = getattr(callback_plugin, possible.replace('v2_',''), None)
if gotit is not None:
methods.append(gotit)
for method in methods:
try:
# temporary hack, required due to a change in the callback API, so
# we don't break backwards compatibility with callbacks which were
# designed to use the original API
# FIXME: target for removal and revert to the original code here after a year (2017-01-14)
if method_name == 'v2_playbook_on_start':
import inspect
(f_args, f_varargs, f_keywords, f_defaults) = inspect.getargspec(method)
if 'playbook' in f_args:
method(*args, **kwargs)
else:
method()
else:
method(*args, **kwargs)
except Exception as e:
#TODO: add config toggle to make this fatal or not?
display.warning(u"Failure using method (%s) in callback plugin (%s): %s" % (to_unicode(method_name), to_unicode(callback_plugin), to_unicode(e)))
from traceback import format_tb
from sys import exc_info
display.debug('Callback Exception: \n' + ' '.join(format_tb(exc_info()[2])))
|
gpl-3.0
|
[
3,
334,
67,
9,
6029,
13,
7280,
12,
16922,
22453,
665,
22333,
14,
24247,
32,
6799,
14,
957,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
3,
4155,
2803,
1655,
2366,
19,
13,
2453,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
646,
12866,
199,
646,
747,
199,
646,
5549,
199,
199,
504,
3242,
492,
5262,
465,
445,
199,
504,
3242,
14,
2550,
492,
13358,
199,
504,
3242,
14,
13471,
14,
2802,
63,
5778,
492,
16527,
3585,
199,
504,
3242,
14,
13471,
14,
1412,
14,
1099,
492,
10695,
3498,
199,
504,
3242,
14,
13471,
14,
3200,
492,
29397,
8257,
199,
504,
3242,
14,
14205,
14,
1457,
492,
8651,
199,
504,
3242,
14,
14205,
14,
2802,
63,
1100,
492,
16527,
2998,
199,
504,
3242,
14,
5265,
492,
3233,
63,
3422,
12,
10054,
63,
3422,
12,
859,
63,
3422,
199,
504,
3242,
14,
1160,
492,
12540,
9828,
199,
504,
3242,
14,
2936,
14,
23265,
492,
10891,
16270,
199,
504,
3242,
14,
5265,
14,
3058,
492,
17555,
1563,
199,
504,
3242,
14,
1208,
14,
2975,
492,
370,
63,
2975,
199,
504,
3242,
14,
5819,
14,
4174,
492,
1059,
63,
1313,
199,
199,
893,
26,
272,
687,
636,
973,
363,
492,
2929,
199,
2590,
3545,
26,
272,
687,
3242,
14,
1208,
14,
2918,
492,
12175,
272,
2929,
275,
12175,
342,
199,
199,
363,
452,
363,
275,
788,
4476,
3737,
2988,
418,
421,
199,
533,
8495,
3737,
2988,
26,
339,
1449,
272,
961,
1021,
10022,
314,
12866,
9760,
402,
2622,
701,
272,
6425,
282,
4203,
402,
7239,
367,
6080,
12,
282,
754,
3016,
14926,
12,
436,
282,
272,
5256,
909,
543,
5709,
666,
13547,
15,
18849,
367,
5970,
1958,
272,
1736,
3382,
1006,
10358,
14,
339,
710,
4126,
5256,
365,
17845,
367,
8697,
314,
5232,
10054,
3589,
12,
272,
1314,
7634,
397,
314,
16527,
1159,
6527,
370,
7057,
14,
272,
1449,
339,
21277,
63,
3593,
4483,
275,
378,
272,
21277,
63,
3170,
3777,
275,
413,
272,
21277,
63,
12299,
63,
23775,
420,
275,
499,
272,
21277,
63,
1734,
24345,
1244,
2617,
63,
23775,
275,
650,
272,
21277,
63,
12299,
63,
14731,
63,
11625,
275,
841,
272,
21277,
63,
11588,
63,
3170,
258,
275,
5450,
339,
347,
636,
826,
721,
277,
12,
8200,
12,
1750,
63,
2609,
12,
5077,
12,
1511,
12,
19572,
12,
3839,
63,
3058,
29,
403,
12,
1255,
63,
8460,
63,
11948,
29,
549,
12,
1255,
63,
2350,
29,
797,
304,
398,
291,
423,
7212,
263,
275,
8200,
267,
291,
423,
1975,
63,
2609,
275,
1750,
63,
2609,
267,
291,
423,
3422,
3698,
275,
5077,
267,
291,
423,
1419,
3515,
275,
1511,
267,
291,
423,
3200,
3322,
275,
29397,
8257,
342,
267,
291,
14,
28608,
260,
275,
19572,
267,
291,
423,
2703,
63,
3058,
221,
275,
3839,
63,
3058,
267,
291,
423,
1065,
63,
8460,
63,
11948,
275,
1255,
63,
8460,
63,
11948,
267,
291,
423,
1065,
63,
2350,
260,
275,
1255,
63,
2350,
398,
291,
423,
11948,
63,
4591,
275,
756,
267,
291,
423,
3058,
63,
5265,
275,
942,
267,
291,
423,
928,
63,
292,
63,
4456,
259,
275,
756,
267,
291,
423,
1099,
63,
80,
1195,
755,
275,
488,
398,
327,
1852,
3238,
314,
859,
931,
334,
692,
2013,
9,
365,
4565,
436,
267,
327,
3483,
370,
314,
859,
63,
3422,
909,
267,
340,
1511,
14,
578,
63,
515,
365,
440,
488,
26,
288,
367,
931,
315,
1511,
14,
578,
63,
515,
14,
1294,
8,
736,
14,
17843,
304,
355,
859,
63,
3422,
14,
525,
63,
3619,
8,
515,
9,
398,
327,
282,
4539,
3305,
370,
1720,
2739,
4458,
3633,
590,
267,
291,
423,
18375,
275,
756,
398,
327,
642,
2600,
365,
1202,
370,
4215,
4426,
402,
29535,
8297,
267,
291,
423,
889,
8981,
63,
5586,
275,
1211,
342,
398,
327,
11196,
370,
4215,
4426,
402,
3405,
15,
26522,
7057,
267,
291,
423,
4892,
63,
5146,
420,
275,
1211,
342,
267,
291,
423,
26522,
63,
5146,
275,
1211,
342,
398,
291,
423,
5094,
63,
81,
275,
12866,
14,
3737,
342,
398,
327,
437,
7937,
570,
334,
19234,
876,
13,
11796,
9,
1202,
701,
1950,
267,
327,
8963,
367,
1640,
13,
1412,
27267,
14,
267,
291,
423,
2105,
63,
26204,
275,
5549,
14,
13271,
342,
339,
347,
485,
8489,
63,
11816,
8,
277,
12,
1967,
304,
267,
291,
423,
11009,
275,
942,
398,
367,
284,
315,
1425,
8,
1507,
304,
288,
519,
2482,
84,
63,
81,
275,
12866,
14,
3737,
342,
288,
291,
423,
11009,
14,
740,
779,
403,
12,
519,
2482,
84,
63,
81,
566,
398,
291,
423,
1099,
63,
80,
1195,
275,
10695,
3498,
8,
277,
423,
5094,
63,
81,
12,
291,
423,
11009,
9,
267,
291,
423,
1099,
63,
80,
1195,
14,
928,
342,
339,
347,
485,
8489,
63,
889,
8981,
63,
5586,
8,
277,
12,
8297,
304,
267,
1449,
267,
14836,
83,
436,
2536,
6491,
314,
5709,
29535,
8297,
1211,
543,
4811,
267,
367,
1924,
3016,
315,
314,
5232,
12,
1314,
365,
376,
2701,
1625,
626,
911,
1395,
267,
8200,
1591,
1247,
367,
5204,
7057,
6804,
316,
314,
3016,
14,
267,
1449,
398,
327,
15708,
314,
2600,
1642,
701,
12881,
1263,
4811,
2337,
14,
267,
327,
2165,
88,
5299,
10809,
2793,
1133
] |
[
334,
67,
9,
6029,
13,
7280,
12,
16922,
22453,
665,
22333,
14,
24247,
32,
6799,
14,
957,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
3,
4155,
2803,
1655,
2366,
19,
13,
2453,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
646,
12866,
199,
646,
747,
199,
646,
5549,
199,
199,
504,
3242,
492,
5262,
465,
445,
199,
504,
3242,
14,
2550,
492,
13358,
199,
504,
3242,
14,
13471,
14,
2802,
63,
5778,
492,
16527,
3585,
199,
504,
3242,
14,
13471,
14,
1412,
14,
1099,
492,
10695,
3498,
199,
504,
3242,
14,
13471,
14,
3200,
492,
29397,
8257,
199,
504,
3242,
14,
14205,
14,
1457,
492,
8651,
199,
504,
3242,
14,
14205,
14,
2802,
63,
1100,
492,
16527,
2998,
199,
504,
3242,
14,
5265,
492,
3233,
63,
3422,
12,
10054,
63,
3422,
12,
859,
63,
3422,
199,
504,
3242,
14,
1160,
492,
12540,
9828,
199,
504,
3242,
14,
2936,
14,
23265,
492,
10891,
16270,
199,
504,
3242,
14,
5265,
14,
3058,
492,
17555,
1563,
199,
504,
3242,
14,
1208,
14,
2975,
492,
370,
63,
2975,
199,
504,
3242,
14,
5819,
14,
4174,
492,
1059,
63,
1313,
199,
199,
893,
26,
272,
687,
636,
973,
363,
492,
2929,
199,
2590,
3545,
26,
272,
687,
3242,
14,
1208,
14,
2918,
492,
12175,
272,
2929,
275,
12175,
342,
199,
199,
363,
452,
363,
275,
788,
4476,
3737,
2988,
418,
421,
199,
533,
8495,
3737,
2988,
26,
339,
1449,
272,
961,
1021,
10022,
314,
12866,
9760,
402,
2622,
701,
272,
6425,
282,
4203,
402,
7239,
367,
6080,
12,
282,
754,
3016,
14926,
12,
436,
282,
272,
5256,
909,
543,
5709,
666,
13547,
15,
18849,
367,
5970,
1958,
272,
1736,
3382,
1006,
10358,
14,
339,
710,
4126,
5256,
365,
17845,
367,
8697,
314,
5232,
10054,
3589,
12,
272,
1314,
7634,
397,
314,
16527,
1159,
6527,
370,
7057,
14,
272,
1449,
339,
21277,
63,
3593,
4483,
275,
378,
272,
21277,
63,
3170,
3777,
275,
413,
272,
21277,
63,
12299,
63,
23775,
420,
275,
499,
272,
21277,
63,
1734,
24345,
1244,
2617,
63,
23775,
275,
650,
272,
21277,
63,
12299,
63,
14731,
63,
11625,
275,
841,
272,
21277,
63,
11588,
63,
3170,
258,
275,
5450,
339,
347,
636,
826,
721,
277,
12,
8200,
12,
1750,
63,
2609,
12,
5077,
12,
1511,
12,
19572,
12,
3839,
63,
3058,
29,
403,
12,
1255,
63,
8460,
63,
11948,
29,
549,
12,
1255,
63,
2350,
29,
797,
304,
398,
291,
423,
7212,
263,
275,
8200,
267,
291,
423,
1975,
63,
2609,
275,
1750,
63,
2609,
267,
291,
423,
3422,
3698,
275,
5077,
267,
291,
423,
1419,
3515,
275,
1511,
267,
291,
423,
3200,
3322,
275,
29397,
8257,
342,
267,
291,
14,
28608,
260,
275,
19572,
267,
291,
423,
2703,
63,
3058,
221,
275,
3839,
63,
3058,
267,
291,
423,
1065,
63,
8460,
63,
11948,
275,
1255,
63,
8460,
63,
11948,
267,
291,
423,
1065,
63,
2350,
260,
275,
1255,
63,
2350,
398,
291,
423,
11948,
63,
4591,
275,
756,
267,
291,
423,
3058,
63,
5265,
275,
942,
267,
291,
423,
928,
63,
292,
63,
4456,
259,
275,
756,
267,
291,
423,
1099,
63,
80,
1195,
755,
275,
488,
398,
327,
1852,
3238,
314,
859,
931,
334,
692,
2013,
9,
365,
4565,
436,
267,
327,
3483,
370,
314,
859,
63,
3422,
909,
267,
340,
1511,
14,
578,
63,
515,
365,
440,
488,
26,
288,
367,
931,
315,
1511,
14,
578,
63,
515,
14,
1294,
8,
736,
14,
17843,
304,
355,
859,
63,
3422,
14,
525,
63,
3619,
8,
515,
9,
398,
327,
282,
4539,
3305,
370,
1720,
2739,
4458,
3633,
590,
267,
291,
423,
18375,
275,
756,
398,
327,
642,
2600,
365,
1202,
370,
4215,
4426,
402,
29535,
8297,
267,
291,
423,
889,
8981,
63,
5586,
275,
1211,
342,
398,
327,
11196,
370,
4215,
4426,
402,
3405,
15,
26522,
7057,
267,
291,
423,
4892,
63,
5146,
420,
275,
1211,
342,
267,
291,
423,
26522,
63,
5146,
275,
1211,
342,
398,
291,
423,
5094,
63,
81,
275,
12866,
14,
3737,
342,
398,
327,
437,
7937,
570,
334,
19234,
876,
13,
11796,
9,
1202,
701,
1950,
267,
327,
8963,
367,
1640,
13,
1412,
27267,
14,
267,
291,
423,
2105,
63,
26204,
275,
5549,
14,
13271,
342,
339,
347,
485,
8489,
63,
11816,
8,
277,
12,
1967,
304,
267,
291,
423,
11009,
275,
942,
398,
367,
284,
315,
1425,
8,
1507,
304,
288,
519,
2482,
84,
63,
81,
275,
12866,
14,
3737,
342,
288,
291,
423,
11009,
14,
740,
779,
403,
12,
519,
2482,
84,
63,
81,
566,
398,
291,
423,
1099,
63,
80,
1195,
275,
10695,
3498,
8,
277,
423,
5094,
63,
81,
12,
291,
423,
11009,
9,
267,
291,
423,
1099,
63,
80,
1195,
14,
928,
342,
339,
347,
485,
8489,
63,
889,
8981,
63,
5586,
8,
277,
12,
8297,
304,
267,
1449,
267,
14836,
83,
436,
2536,
6491,
314,
5709,
29535,
8297,
1211,
543,
4811,
267,
367,
1924,
3016,
315,
314,
5232,
12,
1314,
365,
376,
2701,
1625,
626,
911,
1395,
267,
8200,
1591,
1247,
367,
5204,
7057,
6804,
316,
314,
3016,
14,
267,
1449,
398,
327,
15708,
314,
2600,
1642,
701,
12881,
1263,
4811,
2337,
14,
267,
327,
2165,
88,
5299,
10809,
2793,
1133,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
brianjgeiger/osf.io
|
api_tests/actions/views/test_action_list.py
|
11
|
9890
|
import pytest
from api.base.settings.defaults import API_BASE
from osf_tests.factories import (
PreprintFactory,
AuthUserFactory,
PreprintProviderFactory,
)
from osf.utils import permissions as osf_permissions
@pytest.mark.django_db
@pytest.mark.enable_quickfiles_creation
class TestReviewActionCreateRoot(object):
def create_payload(self, reviewable_id=None, **attrs):
payload = {
'data': {
'attributes': attrs,
'relationships': {},
'type': 'actions'
}
}
if reviewable_id:
payload['data']['relationships']['target'] = {
'data': {
'type': 'preprints',
'id': reviewable_id
}
}
return payload
@pytest.fixture()
def url(self, preprint):
return '/{}actions/reviews/'.format(API_BASE)
@pytest.fixture()
def provider(self):
return PreprintProviderFactory(reviews_workflow='pre-moderation')
@pytest.fixture()
def node_admin(self):
return AuthUserFactory()
@pytest.fixture()
def preprint(self, node_admin, provider):
preprint = PreprintFactory(
provider=provider,
is_published=False
)
preprint.add_contributor(
node_admin, permissions=osf_permissions.ADMIN
)
return preprint
@pytest.fixture()
def moderator(self, provider):
moderator = AuthUserFactory()
moderator.groups.add(provider.get_group('moderator'))
return moderator
def test_create_permissions(
self, app, url, preprint, node_admin, moderator
):
assert preprint.machine_state == 'initial'
submit_payload = self.create_payload(preprint._id, trigger='submit')
# Unauthorized user can't submit
res = app.post_json_api(url, submit_payload, expect_errors=True)
assert res.status_code == 401
# A random user can't submit
some_rando = AuthUserFactory()
res = app.post_json_api(
url, submit_payload,
auth=some_rando.auth,
expect_errors=True
)
assert res.status_code == 403
# Node admin can submit
res = app.post_json_api(url, submit_payload, auth=node_admin.auth)
assert res.status_code == 201
preprint.refresh_from_db()
assert preprint.machine_state == 'pending'
assert not preprint.is_published
accept_payload = self.create_payload(
preprint._id, trigger='accept', comment='This is good.'
)
# Unauthorized user can't accept
res = app.post_json_api(url, accept_payload, expect_errors=True)
assert res.status_code == 401
# A random user can't accept
res = app.post_json_api(
url, accept_payload,
auth=some_rando.auth,
expect_errors=True
)
assert res.status_code == 403
# Moderator from another provider can't accept
another_moderator = AuthUserFactory()
another_moderator.groups.add(
PreprintProviderFactory().get_group('moderator')
)
res = app.post_json_api(
url, accept_payload,
auth=another_moderator.auth,
expect_errors=True
)
assert res.status_code == 403
# Node admin can't accept
res = app.post_json_api(
url, accept_payload,
auth=node_admin.auth,
expect_errors=True
)
assert res.status_code == 403
# Still unchanged after all those tries
preprint.refresh_from_db()
assert preprint.machine_state == 'pending'
assert not preprint.is_published
# Moderator can accept
res = app.post_json_api(url, accept_payload, auth=moderator.auth)
assert res.status_code == 201
preprint.refresh_from_db()
assert preprint.machine_state == 'accepted'
assert preprint.is_published
def test_cannot_create_actions_for_unmoderated_provider(
self, app, url, preprint, provider, node_admin
):
provider.reviews_workflow = None
provider.save()
submit_payload = self.create_payload(preprint._id, trigger='submit')
res = app.post_json_api(
url, submit_payload,
auth=node_admin.auth,
expect_errors=True
)
assert res.status_code == 409
def test_bad_requests(self, app, url, preprint, provider, moderator):
invalid_transitions = {
'post-moderation': [
('accepted', 'accept'),
('accepted', 'submit'),
('initial', 'accept'),
('initial', 'edit_comment'),
('initial', 'reject'),
('initial', 'withdraw'),
('pending', 'submit'),
('rejected', 'reject'),
('rejected', 'submit'),
('rejected', 'withdraw'),
('withdrawn', 'submit'),
('withdrawn', 'accept'),
('withdrawn', 'reject'),
('withdrawn', 'edit_comment'),
('withdrawn', 'withdraw'),
],
'pre-moderation': [
('accepted', 'accept'),
('accepted', 'submit'),
('initial', 'accept'),
('initial', 'edit_comment'),
('initial', 'reject'),
('initial', 'withdraw'),
('rejected', 'reject'),
('rejected', 'withdraw'),
('withdrawn', 'submit'),
('withdrawn', 'accept'),
('withdrawn', 'reject'),
('withdrawn', 'edit_comment'),
('withdrawn', 'withdraw'),
]
}
for workflow, transitions in invalid_transitions.items():
provider.reviews_workflow = workflow
provider.save()
for state, trigger in transitions:
preprint.machine_state = state
preprint.save()
bad_payload = self.create_payload(
preprint._id, trigger=trigger
)
res = app.post_json_api(
url, bad_payload,
auth=moderator.auth, expect_errors=True
)
assert res.status_code == 409
# test invalid trigger
bad_payload = self.create_payload(
preprint._id, trigger='badtriggerbad'
)
res = app.post_json_api(
url, bad_payload,
auth=moderator.auth,
expect_errors=True
)
assert res.status_code == 400
# test target is required
bad_payload = self.create_payload(trigger='accept')
res = app.post_json_api(
url, bad_payload,
auth=moderator.auth,
expect_errors=True
)
assert res.status_code == 400
def test_valid_transitions(
self, app, url, preprint, provider, moderator
):
valid_transitions = {
'post-moderation': [
('accepted', 'edit_comment', 'accepted'),
('accepted', 'reject', 'rejected'),
('accepted', 'withdraw', 'withdrawn'),
('initial', 'submit', 'pending'),
('pending', 'accept', 'accepted'),
('pending', 'edit_comment', 'pending'),
('pending', 'reject', 'rejected'),
('pending', 'withdraw', 'withdrawn'),
('rejected', 'accept', 'accepted'),
('rejected', 'edit_comment', 'rejected'),
],
'pre-moderation': [
('accepted', 'edit_comment', 'accepted'),
('accepted', 'reject', 'rejected'),
('accepted', 'withdraw', 'withdrawn'),
('initial', 'submit', 'pending'),
('pending', 'accept', 'accepted'),
('pending', 'edit_comment', 'pending'),
('pending', 'reject', 'rejected'),
('pending', 'submit', 'pending'),
('pending', 'withdraw', 'withdrawn'),
('rejected', 'accept', 'accepted'),
('rejected', 'edit_comment', 'rejected'),
('rejected', 'submit', 'pending'),
],
}
for workflow, transitions in list(valid_transitions.items()):
provider.reviews_workflow = workflow
provider.save()
for from_state, trigger, to_state in transitions:
preprint.machine_state = from_state
preprint.is_published = False
preprint.date_published = None
preprint.date_withdrawn = None
preprint.date_last_transitioned = None
preprint.save()
payload = self.create_payload(preprint._id, trigger=trigger)
res = app.post_json_api(url, payload, auth=moderator.auth)
assert res.status_code == 201
action = preprint.actions.order_by('-created').first()
assert action.trigger == trigger
preprint.refresh_from_db()
assert preprint.machine_state == to_state
if preprint.in_public_reviews_state:
assert preprint.is_published
assert preprint.date_published == action.created
else:
assert not preprint.is_published
assert preprint.date_published is None
if trigger == 'edit_comment':
assert preprint.date_last_transitioned is None
else:
assert preprint.date_last_transitioned == action.created
|
apache-2.0
|
[
646,
4613,
199,
199,
504,
2986,
14,
1095,
14,
1751,
14,
4322,
492,
3261,
63,
5825,
199,
504,
747,
70,
63,
2219,
14,
15406,
492,
334,
272,
510,
1155,
672,
2927,
12,
272,
3590,
24594,
12,
272,
510,
1155,
672,
6663,
2927,
12,
199,
9,
199,
504,
747,
70,
14,
1208,
492,
3443,
465,
747,
70,
63,
6060,
421,
199,
32,
4462,
14,
1657,
14,
1176,
63,
697,
199,
32,
4462,
14,
1657,
14,
4296,
63,
13239,
1725,
63,
8782,
199,
533,
1379,
21000,
3310,
2499,
6405,
8,
785,
304,
272,
347,
1218,
63,
4749,
8,
277,
12,
11248,
461,
63,
344,
29,
403,
12,
1011,
3288,
304,
267,
4886,
275,
469,
288,
283,
576,
356,
469,
355,
283,
2987,
356,
3290,
12,
355,
283,
24034,
356,
5479,
355,
283,
466,
356,
283,
3723,
7,
288,
789,
267,
789,
267,
340,
11248,
461,
63,
344,
26,
288,
4886,
459,
576,
2545,
24034,
2545,
1375,
418,
275,
469,
355,
283,
576,
356,
469,
490,
283,
466,
356,
283,
657,
29593,
297,
490,
283,
344,
356,
11248,
461,
63,
344,
355,
789,
288,
789,
267,
372,
4886,
339,
768,
4462,
14,
5997,
342,
272,
347,
1166,
8,
277,
12,
876,
1361,
304,
267,
372,
1994,
2440,
3723,
15,
24169,
15,
1370,
908,
8,
3735,
63,
5825,
9,
339,
768,
4462,
14,
5997,
342,
272,
347,
5022,
8,
277,
304,
267,
372,
510,
1155,
672,
6663,
2927,
8,
24169,
63,
8856,
534,
657,
13,
632,
1754,
358,
339,
768,
4462,
14,
5997,
342,
272,
347,
1031,
63,
2113,
8,
277,
304,
267,
372,
3590,
24594,
342,
339,
768,
4462,
14,
5997,
342,
272,
347,
876,
1361,
8,
277,
12,
1031,
63,
2113,
12,
5022,
304,
267,
876,
1361,
275,
510,
1155,
672,
2927,
8,
288,
5022,
29,
3780,
12,
288,
365,
63,
8987,
29,
797,
267,
776,
267,
876,
1361,
14,
525,
63,
16833,
8,
288,
1031,
63,
2113,
12,
3443,
29,
20923,
63,
6060,
14,
14288,
267,
776,
267,
372,
876,
1361,
339,
768,
4462,
14,
5997,
342,
272,
347,
818,
9043,
8,
277,
12,
5022,
304,
267,
818,
9043,
275,
3590,
24594,
342,
267,
818,
9043,
14,
2634,
14,
525,
8,
3780,
14,
362,
63,
923,
360,
25597,
1333,
267,
372,
818,
9043,
339,
347,
511,
63,
981,
63,
6060,
8,
288,
291,
12,
1145,
12,
1166,
12,
876,
1361,
12,
1031,
63,
2113,
12,
818,
9043,
272,
3461,
267,
702,
876,
1361,
14,
6744,
63,
929,
508,
283,
2747,
7,
398,
11482,
63,
4749,
275,
291,
14,
981,
63,
4749,
8,
657,
1361,
423,
344,
12,
6804,
534,
7275,
358,
398,
327,
1910,
11497,
922,
883,
1133,
11482,
267,
522,
275,
1145,
14,
1932,
63,
1001,
63,
1246,
8,
633,
12,
11482,
63,
4749,
12,
4282,
63,
2550,
29,
549,
9,
267,
702,
522,
14,
1205,
63,
600,
508,
13952,
398,
327,
437,
2196,
922,
883,
1133,
11482,
267,
2005,
63,
3759,
79,
275,
3590,
24594,
342,
267,
522,
275,
1145,
14,
1932,
63,
1001,
63,
1246,
8,
288,
1166,
12,
11482,
63,
4749,
12,
288,
1790,
29,
3972,
63,
3759,
79,
14,
1178,
12,
288,
4282,
63,
2550,
29,
549,
267,
776,
267,
702,
522,
14,
1205,
63,
600,
508,
13269,
398,
327,
5013,
4628,
883,
11482,
267,
522,
275,
1145,
14,
1932,
63,
1001,
63,
1246,
8,
633,
12,
11482,
63,
4749,
12,
1790,
29,
932,
63,
2113,
14,
1178,
9,
267,
702,
522,
14,
1205,
63,
600,
508,
1784,
267,
876,
1361,
14,
6635,
63,
504,
63,
697,
342,
267,
702,
876,
1361,
14,
6744,
63,
929,
508,
283,
6455,
7,
267,
702,
440,
876,
1361,
14,
374,
63,
8987,
398,
4729,
63,
4749,
275,
291,
14,
981,
63,
4749,
8,
288,
876,
1361,
423,
344,
12,
6804,
534,
5694,
297,
3721,
534,
2765,
365,
6954,
3530,
267,
776,
398,
327,
1910,
11497,
922,
883,
1133,
4729,
267,
522,
275,
1145,
14,
1932,
63,
1001,
63,
1246,
8,
633,
12,
4729,
63,
4749,
12,
4282,
63,
2550,
29,
549,
9,
267,
702,
522,
14,
1205,
63,
600,
508,
13952,
398,
327,
437,
2196,
922,
883,
1133,
4729,
267,
522,
275,
1145,
14,
1932,
63,
1001,
63,
1246,
8,
288,
1166,
12,
4729,
63,
4749,
12,
288,
1790,
29,
3972,
63,
3759,
79,
14,
1178,
12,
288,
4282,
63,
2550,
29,
549,
267,
776,
267,
702,
522,
14,
1205,
63,
600,
508,
13269,
398,
327,
4900,
9043,
687,
4573,
5022,
883,
1133,
4729,
267,
4573,
63,
25597,
275,
3590,
24594,
342,
267,
4573,
63,
25597,
14,
2634,
14,
525,
8,
288,
510,
1155,
672,
6663,
2927,
1252,
362,
63,
923,
360,
25597,
358,
267,
776,
267,
522,
275,
1145,
14,
1932,
63,
1001,
63,
1246,
8,
288,
1166,
12,
4729,
63,
4749,
12,
288,
1790,
29,
13565,
63,
25597,
14,
1178,
12,
288,
4282,
63,
2550,
29,
549,
267,
776,
267,
702,
522,
14,
1205,
63,
600,
508,
13269,
398,
327,
5013,
4628,
883,
1133,
4729,
267,
522,
275,
1145,
14,
1932,
63,
1001,
63,
1246,
8,
288,
1166,
12,
4729,
63,
4749,
12,
288,
1790,
29,
932,
63,
2113,
14,
1178,
12,
288,
4282,
63,
2550,
29,
549,
267,
776,
267,
702,
522,
14,
1205,
63,
600,
508,
13269,
398,
327,
428,
12587,
14874,
2410,
1006,
5204,
11275,
267,
876,
1361,
14,
6635,
63,
504,
63,
697,
342,
267,
702,
876,
1361,
14,
6744,
63,
929,
508,
283,
6455,
7,
267,
702,
440,
876,
1361,
14,
374,
63,
8987,
398,
327,
4900,
9043,
883,
4729,
267,
522,
275,
1145,
14,
1932,
63,
1001,
63,
1246,
8,
633,
12,
4729,
63,
4749,
12,
1790,
29,
25597,
14,
1178,
9,
267,
702,
522,
14,
1205,
63,
600,
508,
1784,
267,
876,
1361,
14,
6635,
63,
504,
63,
697,
342,
267,
702,
876,
1361,
14,
6744,
63,
929,
508,
283,
16121,
7,
267,
702,
876,
1361,
14,
374,
63,
8987,
339,
347,
511,
63,
11250,
63,
981,
63,
3723,
63,
509,
63,
324,
632,
12601,
63,
3780,
8,
288,
291,
12,
1145,
12,
1166,
12,
876,
1361,
12,
5022,
12,
1031,
63,
2113,
272,
3461,
267,
5022,
14,
24169,
63,
8856,
275,
488,
267,
5022,
14,
2117,
342,
267,
11482,
63,
4749,
275,
291
] |
[
4613,
199,
199,
504,
2986,
14,
1095,
14,
1751,
14,
4322,
492,
3261,
63,
5825,
199,
504,
747,
70,
63,
2219,
14,
15406,
492,
334,
272,
510,
1155,
672,
2927,
12,
272,
3590,
24594,
12,
272,
510,
1155,
672,
6663,
2927,
12,
199,
9,
199,
504,
747,
70,
14,
1208,
492,
3443,
465,
747,
70,
63,
6060,
421,
199,
32,
4462,
14,
1657,
14,
1176,
63,
697,
199,
32,
4462,
14,
1657,
14,
4296,
63,
13239,
1725,
63,
8782,
199,
533,
1379,
21000,
3310,
2499,
6405,
8,
785,
304,
272,
347,
1218,
63,
4749,
8,
277,
12,
11248,
461,
63,
344,
29,
403,
12,
1011,
3288,
304,
267,
4886,
275,
469,
288,
283,
576,
356,
469,
355,
283,
2987,
356,
3290,
12,
355,
283,
24034,
356,
5479,
355,
283,
466,
356,
283,
3723,
7,
288,
789,
267,
789,
267,
340,
11248,
461,
63,
344,
26,
288,
4886,
459,
576,
2545,
24034,
2545,
1375,
418,
275,
469,
355,
283,
576,
356,
469,
490,
283,
466,
356,
283,
657,
29593,
297,
490,
283,
344,
356,
11248,
461,
63,
344,
355,
789,
288,
789,
267,
372,
4886,
339,
768,
4462,
14,
5997,
342,
272,
347,
1166,
8,
277,
12,
876,
1361,
304,
267,
372,
1994,
2440,
3723,
15,
24169,
15,
1370,
908,
8,
3735,
63,
5825,
9,
339,
768,
4462,
14,
5997,
342,
272,
347,
5022,
8,
277,
304,
267,
372,
510,
1155,
672,
6663,
2927,
8,
24169,
63,
8856,
534,
657,
13,
632,
1754,
358,
339,
768,
4462,
14,
5997,
342,
272,
347,
1031,
63,
2113,
8,
277,
304,
267,
372,
3590,
24594,
342,
339,
768,
4462,
14,
5997,
342,
272,
347,
876,
1361,
8,
277,
12,
1031,
63,
2113,
12,
5022,
304,
267,
876,
1361,
275,
510,
1155,
672,
2927,
8,
288,
5022,
29,
3780,
12,
288,
365,
63,
8987,
29,
797,
267,
776,
267,
876,
1361,
14,
525,
63,
16833,
8,
288,
1031,
63,
2113,
12,
3443,
29,
20923,
63,
6060,
14,
14288,
267,
776,
267,
372,
876,
1361,
339,
768,
4462,
14,
5997,
342,
272,
347,
818,
9043,
8,
277,
12,
5022,
304,
267,
818,
9043,
275,
3590,
24594,
342,
267,
818,
9043,
14,
2634,
14,
525,
8,
3780,
14,
362,
63,
923,
360,
25597,
1333,
267,
372,
818,
9043,
339,
347,
511,
63,
981,
63,
6060,
8,
288,
291,
12,
1145,
12,
1166,
12,
876,
1361,
12,
1031,
63,
2113,
12,
818,
9043,
272,
3461,
267,
702,
876,
1361,
14,
6744,
63,
929,
508,
283,
2747,
7,
398,
11482,
63,
4749,
275,
291,
14,
981,
63,
4749,
8,
657,
1361,
423,
344,
12,
6804,
534,
7275,
358,
398,
327,
1910,
11497,
922,
883,
1133,
11482,
267,
522,
275,
1145,
14,
1932,
63,
1001,
63,
1246,
8,
633,
12,
11482,
63,
4749,
12,
4282,
63,
2550,
29,
549,
9,
267,
702,
522,
14,
1205,
63,
600,
508,
13952,
398,
327,
437,
2196,
922,
883,
1133,
11482,
267,
2005,
63,
3759,
79,
275,
3590,
24594,
342,
267,
522,
275,
1145,
14,
1932,
63,
1001,
63,
1246,
8,
288,
1166,
12,
11482,
63,
4749,
12,
288,
1790,
29,
3972,
63,
3759,
79,
14,
1178,
12,
288,
4282,
63,
2550,
29,
549,
267,
776,
267,
702,
522,
14,
1205,
63,
600,
508,
13269,
398,
327,
5013,
4628,
883,
11482,
267,
522,
275,
1145,
14,
1932,
63,
1001,
63,
1246,
8,
633,
12,
11482,
63,
4749,
12,
1790,
29,
932,
63,
2113,
14,
1178,
9,
267,
702,
522,
14,
1205,
63,
600,
508,
1784,
267,
876,
1361,
14,
6635,
63,
504,
63,
697,
342,
267,
702,
876,
1361,
14,
6744,
63,
929,
508,
283,
6455,
7,
267,
702,
440,
876,
1361,
14,
374,
63,
8987,
398,
4729,
63,
4749,
275,
291,
14,
981,
63,
4749,
8,
288,
876,
1361,
423,
344,
12,
6804,
534,
5694,
297,
3721,
534,
2765,
365,
6954,
3530,
267,
776,
398,
327,
1910,
11497,
922,
883,
1133,
4729,
267,
522,
275,
1145,
14,
1932,
63,
1001,
63,
1246,
8,
633,
12,
4729,
63,
4749,
12,
4282,
63,
2550,
29,
549,
9,
267,
702,
522,
14,
1205,
63,
600,
508,
13952,
398,
327,
437,
2196,
922,
883,
1133,
4729,
267,
522,
275,
1145,
14,
1932,
63,
1001,
63,
1246,
8,
288,
1166,
12,
4729,
63,
4749,
12,
288,
1790,
29,
3972,
63,
3759,
79,
14,
1178,
12,
288,
4282,
63,
2550,
29,
549,
267,
776,
267,
702,
522,
14,
1205,
63,
600,
508,
13269,
398,
327,
4900,
9043,
687,
4573,
5022,
883,
1133,
4729,
267,
4573,
63,
25597,
275,
3590,
24594,
342,
267,
4573,
63,
25597,
14,
2634,
14,
525,
8,
288,
510,
1155,
672,
6663,
2927,
1252,
362,
63,
923,
360,
25597,
358,
267,
776,
267,
522,
275,
1145,
14,
1932,
63,
1001,
63,
1246,
8,
288,
1166,
12,
4729,
63,
4749,
12,
288,
1790,
29,
13565,
63,
25597,
14,
1178,
12,
288,
4282,
63,
2550,
29,
549,
267,
776,
267,
702,
522,
14,
1205,
63,
600,
508,
13269,
398,
327,
5013,
4628,
883,
1133,
4729,
267,
522,
275,
1145,
14,
1932,
63,
1001,
63,
1246,
8,
288,
1166,
12,
4729,
63,
4749,
12,
288,
1790,
29,
932,
63,
2113,
14,
1178,
12,
288,
4282,
63,
2550,
29,
549,
267,
776,
267,
702,
522,
14,
1205,
63,
600,
508,
13269,
398,
327,
428,
12587,
14874,
2410,
1006,
5204,
11275,
267,
876,
1361,
14,
6635,
63,
504,
63,
697,
342,
267,
702,
876,
1361,
14,
6744,
63,
929,
508,
283,
6455,
7,
267,
702,
440,
876,
1361,
14,
374,
63,
8987,
398,
327,
4900,
9043,
883,
4729,
267,
522,
275,
1145,
14,
1932,
63,
1001,
63,
1246,
8,
633,
12,
4729,
63,
4749,
12,
1790,
29,
25597,
14,
1178,
9,
267,
702,
522,
14,
1205,
63,
600,
508,
1784,
267,
876,
1361,
14,
6635,
63,
504,
63,
697,
342,
267,
702,
876,
1361,
14,
6744,
63,
929,
508,
283,
16121,
7,
267,
702,
876,
1361,
14,
374,
63,
8987,
339,
347,
511,
63,
11250,
63,
981,
63,
3723,
63,
509,
63,
324,
632,
12601,
63,
3780,
8,
288,
291,
12,
1145,
12,
1166,
12,
876,
1361,
12,
5022,
12,
1031,
63,
2113,
272,
3461,
267,
5022,
14,
24169,
63,
8856,
275,
488,
267,
5022,
14,
2117,
342,
267,
11482,
63,
4749,
275,
291,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
CCI-Tools/ect-core
|
test/core/test_cdm.py
|
2
|
1639
|
import json
from unittest import TestCase
from cate.core.cdm import Schema
class SchemaTest(TestCase):
@staticmethod
def _test_schema() -> Schema:
return Schema('test',
dimensions=[Schema.Dimension('lon', length=720),
Schema.Dimension('lat', length=360),
Schema.Dimension('time', length=12)],
variables=[Schema.Variable('SST', float, dimension_names=['lon', 'lat', 'time']),
Schema.Variable('qc_flags', int, dimension_names=['lon', 'lat', 'time'])],
attributes=[Schema.Attribute('title', str, 'Sea Surface Temperature')])
def test_rank_and_dim(self):
schema = self._test_schema()
self.assertEqual(schema.dimension(2).name, 'time')
self.assertEqual(schema.dimension('lat').name, 'lat')
sst = schema.variables[0]
self.assertEqual(sst.rank, 3)
self.assertEqual(sst.dimension(schema, 0).name, 'lon')
self.assertEqual(sst.dimension(schema, 1).name, 'lat')
self.assertEqual(sst.dimension(schema, 2).name, 'time')
def test_to_and_from_json(self):
schema_1 = self._test_schema()
json_dict_1 = schema_1.to_json_dict()
json_text_1 = json.dumps(json_dict_1, indent=2)
# print(json_text_1)
schema_2 = Schema.from_json_dict(json_dict_1)
json_dict_2 = schema_2.to_json_dict()
json_text_2 = json.dumps(json_dict_2, indent=2)
# print(json_text_2)
self.maxDiff = None
self.assertEqual(json_text_1, json_text_2)
|
mit
|
[
646,
2022,
199,
504,
2882,
492,
7640,
199,
199,
504,
286,
323,
14,
1018,
14,
2866,
77,
492,
13268,
421,
199,
533,
13268,
774,
8,
1746,
304,
272,
768,
4639,
272,
347,
485,
396,
63,
3629,
342,
1035,
13268,
26,
267,
372,
13268,
360,
396,
297,
1993,
7365,
1524,
6700,
14,
17905,
360,
5298,
297,
2582,
29,
18386,
395,
3303,
13268,
14,
17905,
360,
4452,
297,
2582,
29,
11197,
395,
3303,
13268,
14,
17905,
360,
521,
297,
2582,
29,
713,
4360,
1993,
2860,
1524,
6700,
14,
2773,
360,
51,
840,
297,
2069,
12,
6240,
63,
1247,
2968,
5298,
297,
283,
4452,
297,
283,
521,
3815,
639,
13268,
14,
2773,
360,
21882,
63,
2469,
297,
1109,
12,
6240,
63,
1247,
2968,
5298,
297,
283,
4452,
297,
283,
521,
1105,
467,
1993,
3004,
1524,
6700,
14,
1646,
360,
1213,
297,
620,
12,
283,
1513,
65,
29564,
12540,
7899,
2023,
339,
347,
511,
63,
4648,
63,
460,
63,
3572,
8,
277,
304,
267,
4177,
275,
291,
423,
396,
63,
3629,
342,
398,
291,
14,
629,
8,
3629,
14,
7430,
8,
18,
680,
354,
12,
283,
521,
358,
267,
291,
14,
629,
8,
3629,
14,
7430,
360,
4452,
1959,
354,
12,
283,
4452,
358,
398,
308,
270,
275,
4177,
14,
3669,
59,
16,
61,
267,
291,
14,
629,
8,
83,
270,
14,
4648,
12,
650,
9,
267,
291,
14,
629,
8,
83,
270,
14,
7430,
8,
3629,
12,
378,
680,
354,
12,
283,
5298,
358,
267,
291,
14,
629,
8,
83,
270,
14,
7430,
8,
3629,
12,
413,
680,
354,
12,
283,
4452,
358,
267,
291,
14,
629,
8,
83,
270,
14,
7430,
8,
3629,
12,
499,
680,
354,
12,
283,
521,
358,
339,
347,
511,
63,
475,
63,
460,
63,
504,
63,
1001,
8,
277,
304,
267,
4177,
63,
17,
275,
291,
423,
396,
63,
3629,
342,
398,
2022,
63,
807,
63,
17,
275,
4177,
63,
17,
14,
475,
63,
1001,
63,
807,
342,
267,
2022,
63,
505,
63,
17,
275,
2022,
14,
4180,
8,
1001,
63,
807,
63,
17,
12,
4363,
29,
18,
9,
267,
327,
870,
8,
1001,
63,
505,
63,
17,
9,
398,
4177,
63,
18,
275,
13268,
14,
504,
63,
1001,
63,
807,
8,
1001,
63,
807,
63,
17,
9,
267,
2022,
63,
807,
63,
18,
275,
4177,
63,
18,
14,
475,
63,
1001,
63,
807,
342,
267,
2022,
63,
505,
63,
18,
275,
2022,
14,
4180,
8,
1001,
63,
807,
63,
18,
12,
4363,
29,
18,
9,
267,
327,
870,
8,
1001,
63,
505,
63,
18,
9,
398,
291,
14,
988,
10746,
275,
488,
267,
291,
14,
629,
8,
1001,
63,
505,
63,
17,
12,
2022,
63,
505,
63,
18,
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
] |
[
2022,
199,
504,
2882,
492,
7640,
199,
199,
504,
286,
323,
14,
1018,
14,
2866,
77,
492,
13268,
421,
199,
533,
13268,
774,
8,
1746,
304,
272,
768,
4639,
272,
347,
485,
396,
63,
3629,
342,
1035,
13268,
26,
267,
372,
13268,
360,
396,
297,
1993,
7365,
1524,
6700,
14,
17905,
360,
5298,
297,
2582,
29,
18386,
395,
3303,
13268,
14,
17905,
360,
4452,
297,
2582,
29,
11197,
395,
3303,
13268,
14,
17905,
360,
521,
297,
2582,
29,
713,
4360,
1993,
2860,
1524,
6700,
14,
2773,
360,
51,
840,
297,
2069,
12,
6240,
63,
1247,
2968,
5298,
297,
283,
4452,
297,
283,
521,
3815,
639,
13268,
14,
2773,
360,
21882,
63,
2469,
297,
1109,
12,
6240,
63,
1247,
2968,
5298,
297,
283,
4452,
297,
283,
521,
1105,
467,
1993,
3004,
1524,
6700,
14,
1646,
360,
1213,
297,
620,
12,
283,
1513,
65,
29564,
12540,
7899,
2023,
339,
347,
511,
63,
4648,
63,
460,
63,
3572,
8,
277,
304,
267,
4177,
275,
291,
423,
396,
63,
3629,
342,
398,
291,
14,
629,
8,
3629,
14,
7430,
8,
18,
680,
354,
12,
283,
521,
358,
267,
291,
14,
629,
8,
3629,
14,
7430,
360,
4452,
1959,
354,
12,
283,
4452,
358,
398,
308,
270,
275,
4177,
14,
3669,
59,
16,
61,
267,
291,
14,
629,
8,
83,
270,
14,
4648,
12,
650,
9,
267,
291,
14,
629,
8,
83,
270,
14,
7430,
8,
3629,
12,
378,
680,
354,
12,
283,
5298,
358,
267,
291,
14,
629,
8,
83,
270,
14,
7430,
8,
3629,
12,
413,
680,
354,
12,
283,
4452,
358,
267,
291,
14,
629,
8,
83,
270,
14,
7430,
8,
3629,
12,
499,
680,
354,
12,
283,
521,
358,
339,
347,
511,
63,
475,
63,
460,
63,
504,
63,
1001,
8,
277,
304,
267,
4177,
63,
17,
275,
291,
423,
396,
63,
3629,
342,
398,
2022,
63,
807,
63,
17,
275,
4177,
63,
17,
14,
475,
63,
1001,
63,
807,
342,
267,
2022,
63,
505,
63,
17,
275,
2022,
14,
4180,
8,
1001,
63,
807,
63,
17,
12,
4363,
29,
18,
9,
267,
327,
870,
8,
1001,
63,
505,
63,
17,
9,
398,
4177,
63,
18,
275,
13268,
14,
504,
63,
1001,
63,
807,
8,
1001,
63,
807,
63,
17,
9,
267,
2022,
63,
807,
63,
18,
275,
4177,
63,
18,
14,
475,
63,
1001,
63,
807,
342,
267,
2022,
63,
505,
63,
18,
275,
2022,
14,
4180,
8,
1001,
63,
807,
63,
18,
12,
4363,
29,
18,
9,
267,
327,
870,
8,
1001,
63,
505,
63,
18,
9,
398,
291,
14,
988,
10746,
275,
488,
267,
291,
14,
629,
8,
1001,
63,
505,
63,
17,
12,
2022,
63,
505,
63,
18,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
curtisstpierre/django
|
tests/get_or_create/models.py
|
276
|
1429
|
from __future__ import unicode_literals
from django.db import models
from django.utils.encoding import python_2_unicode_compatible
@python_2_unicode_compatible
class Person(models.Model):
first_name = models.CharField(max_length=100)
last_name = models.CharField(max_length=100)
birthday = models.DateField()
defaults = models.TextField()
def __str__(self):
return '%s %s' % (self.first_name, self.last_name)
class DefaultPerson(models.Model):
first_name = models.CharField(max_length=100, default="Anonymous")
class ManualPrimaryKeyTest(models.Model):
id = models.IntegerField(primary_key=True)
data = models.CharField(max_length=100)
class Profile(models.Model):
person = models.ForeignKey(Person, models.CASCADE, primary_key=True)
class Tag(models.Model):
text = models.CharField(max_length=255, unique=True)
class Thing(models.Model):
name = models.CharField(max_length=256)
tags = models.ManyToManyField(Tag)
class Publisher(models.Model):
name = models.CharField(max_length=100)
class Author(models.Model):
name = models.CharField(max_length=100)
class Book(models.Model):
name = models.CharField(max_length=100)
authors = models.ManyToManyField(Author, related_name='books')
publisher = models.ForeignKey(
Publisher,
models.CASCADE,
related_name='books',
db_column="publisher_id_column",
)
|
bsd-3-clause
|
[
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
697,
492,
1709,
199,
504,
1639,
14,
1208,
14,
2991,
492,
2366,
63,
18,
63,
2975,
63,
6490,
421,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
533,
8028,
8,
992,
14,
1685,
304,
272,
1642,
63,
354,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1960,
9,
272,
2061,
63,
354,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1960,
9,
272,
21036,
2977,
275,
1709,
14,
14071,
342,
272,
4243,
275,
1709,
14,
6254,
342,
339,
347,
636,
495,
721,
277,
304,
267,
372,
1543,
83,
450,
83,
7,
450,
334,
277,
14,
2246,
63,
354,
12,
291,
14,
2019,
63,
354,
9,
421,
199,
533,
3758,
7344,
8,
992,
14,
1685,
304,
272,
1642,
63,
354,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1960,
12,
849,
628,
23902,
531,
421,
199,
533,
30247,
29457,
774,
8,
992,
14,
1685,
304,
272,
1305,
275,
1709,
14,
3901,
8,
3327,
63,
498,
29,
549,
9,
272,
666,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1960,
9,
421,
199,
533,
14386,
8,
992,
14,
1685,
304,
272,
4954,
275,
1709,
14,
3190,
8,
7344,
12,
1709,
14,
10855,
12,
5062,
63,
498,
29,
549,
9,
421,
199,
533,
8053,
8,
992,
14,
1685,
304,
272,
1318,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
2299,
12,
3747,
29,
549,
9,
421,
199,
533,
3868,
316,
8,
992,
14,
1685,
304,
272,
536,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
3912,
9,
272,
3762,
275,
1709,
14,
7624,
8,
1931,
9,
421,
199,
533,
19952,
281,
8,
992,
14,
1685,
304,
272,
536,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1960,
9,
421,
199,
533,
6529,
8,
992,
14,
1685,
304,
272,
536,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1960,
9,
421,
199,
533,
8944,
8,
992,
14,
1685,
304,
272,
536,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1960,
9,
272,
11462,
275,
1709,
14,
7624,
8,
5949,
12,
4048,
63,
354,
534,
8858,
358,
272,
19704,
275,
1709,
14,
3190,
8,
267,
19952,
281,
12,
267,
1709,
14,
10855,
12,
267,
4048,
63,
354,
534,
8858,
297,
267,
1592,
63,
2301,
628,
12789,
63,
344,
63,
2301,
401,
272,
776,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
697,
492,
1709,
199,
504,
1639,
14,
1208,
14,
2991,
492,
2366,
63,
18,
63,
2975,
63,
6490,
421,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
533,
8028,
8,
992,
14,
1685,
304,
272,
1642,
63,
354,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1960,
9,
272,
2061,
63,
354,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1960,
9,
272,
21036,
2977,
275,
1709,
14,
14071,
342,
272,
4243,
275,
1709,
14,
6254,
342,
339,
347,
636,
495,
721,
277,
304,
267,
372,
1543,
83,
450,
83,
7,
450,
334,
277,
14,
2246,
63,
354,
12,
291,
14,
2019,
63,
354,
9,
421,
199,
533,
3758,
7344,
8,
992,
14,
1685,
304,
272,
1642,
63,
354,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1960,
12,
849,
628,
23902,
531,
421,
199,
533,
30247,
29457,
774,
8,
992,
14,
1685,
304,
272,
1305,
275,
1709,
14,
3901,
8,
3327,
63,
498,
29,
549,
9,
272,
666,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1960,
9,
421,
199,
533,
14386,
8,
992,
14,
1685,
304,
272,
4954,
275,
1709,
14,
3190,
8,
7344,
12,
1709,
14,
10855,
12,
5062,
63,
498,
29,
549,
9,
421,
199,
533,
8053,
8,
992,
14,
1685,
304,
272,
1318,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
2299,
12,
3747,
29,
549,
9,
421,
199,
533,
3868,
316,
8,
992,
14,
1685,
304,
272,
536,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
3912,
9,
272,
3762,
275,
1709,
14,
7624,
8,
1931,
9,
421,
199,
533,
19952,
281,
8,
992,
14,
1685,
304,
272,
536,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1960,
9,
421,
199,
533,
6529,
8,
992,
14,
1685,
304,
272,
536,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1960,
9,
421,
199,
533,
8944,
8,
992,
14,
1685,
304,
272,
536,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1960,
9,
272,
11462,
275,
1709,
14,
7624,
8,
5949,
12,
4048,
63,
354,
534,
8858,
358,
272,
19704,
275,
1709,
14,
3190,
8,
267,
19952,
281,
12,
267,
1709,
14,
10855,
12,
267,
4048,
63,
354,
534,
8858,
297,
267,
1592,
63,
2301,
628,
12789,
63,
344,
63,
2301,
401,
272,
776,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
mclois/iteexe
|
twisted/manhole/ui/gtk2manhole.py
|
14
|
12391
|
# -*- Python -*-
# $Id: gtk2manhole.py,v 1.9 2003/09/07 19:58:09 acapnotic Exp $
# Copyright (c) 2001-2004 Twisted Matrix Laboratories.
# See LICENSE for details.
"""Manhole client with a GTK v2.x front-end.
"""
__version__ = '$Revision: 1.9 $'[11:-2]
from twisted import copyright
from twisted.internet import reactor
from twisted.python import components, failure, log, util
from twisted.spread import pb
from twisted.spread.ui import gtk2util
from twisted.manhole.service import IManholeClient
from zope.interface import implements
# The pygtk.require for version 2.0 has already been done by the reactor.
import gtk
import code, types, inspect
# TODO:
# Make wrap-mode a run-time option.
# Explorer.
# Code doesn't cleanly handle opening a second connection. Fix that.
# Make some acknowledgement of when a command has completed, even if
# it has no return value so it doesn't print anything to the console.
class OfflineError(Exception):
pass
class ManholeWindow(components.Componentized, gtk2util.GladeKeeper):
gladefile = util.sibpath(__file__, "gtk2manhole.glade")
_widgets = ('input','output','manholeWindow')
def __init__(self):
self.defaults = {}
gtk2util.GladeKeeper.__init__(self)
components.Componentized.__init__(self)
self.input = ConsoleInput(self._input)
self.input.toplevel = self
self.output = ConsoleOutput(self._output)
# Ugh. GladeKeeper actually isn't so good for composite objects.
# I want this connected to the ConsoleInput's handler, not something
# on this class.
self._input.connect("key_press_event", self.input._on_key_press_event)
def setDefaults(self, defaults):
self.defaults = defaults
def login(self):
client = self.getComponent(IManholeClient)
d = gtk2util.login(client, **self.defaults)
d.addCallback(self._cbLogin)
d.addCallback(client._cbLogin)
d.addErrback(self._ebLogin)
def _cbDisconnected(self, perspective):
self.output.append("%s went away. :(\n" % (perspective,), "local")
self._manholeWindow.set_title("Manhole")
def _cbLogin(self, perspective):
peer = perspective.broker.transport.getPeer()
self.output.append("Connected to %s\n" % (peer,), "local")
perspective.notifyOnDisconnect(self._cbDisconnected)
self._manholeWindow.set_title("Manhole - %s" % (peer))
return perspective
def _ebLogin(self, reason):
self.output.append("Login FAILED %s\n" % (reason.value,), "exception")
def _on_aboutMenuItem_activate(self, widget, *unused):
import sys
from os import path
self.output.append("""\
a Twisted Manhole client
Versions:
%(twistedVer)s
Python %(pythonVer)s on %(platform)s
GTK %(gtkVer)s / PyGTK %(pygtkVer)s
%(module)s %(modVer)s
http://twistedmatrix.com/
""" % {'twistedVer': copyright.longversion,
'pythonVer': sys.version.replace('\n', '\n '),
'platform': sys.platform,
'gtkVer': ".".join(map(str, gtk.gtk_version)),
'pygtkVer': ".".join(map(str, gtk.pygtk_version)),
'module': path.basename(__file__),
'modVer': __version__,
}, "local")
def _on_openMenuItem_activate(self, widget, userdata=None):
self.login()
def _on_manholeWindow_delete_event(self, widget, *unused):
reactor.stop()
def _on_quitMenuItem_activate(self, widget, *unused):
reactor.stop()
def on_reload_self_activate(self, *unused):
from twisted.python import rebuild
rebuild.rebuild(inspect.getmodule(self.__class__))
tagdefs = {
'default': {"family": "monospace"},
# These are message types we get from the server.
'stdout': {"foreground": "black"},
'stderr': {"foreground": "#AA8000"},
'result': {"foreground": "blue"},
'exception': {"foreground": "red"},
# Messages generate locally.
'local': {"foreground": "#008000"},
'log': {"foreground": "#000080"},
'command': {"foreground": "#666666"},
}
# TODO: Factor Python console stuff back out to pywidgets.
class ConsoleOutput:
_willScroll = None
def __init__(self, textView):
self.textView = textView
self.buffer = textView.get_buffer()
# TODO: Make this a singleton tag table.
for name, props in tagdefs.iteritems():
tag = self.buffer.create_tag(name)
# This can be done in the constructor in newer pygtk (post 1.99.14)
for k, v in props.iteritems():
tag.set_property(k, v)
self.buffer.tag_table.lookup("default").set_priority(0)
self._captureLocalLog()
def _captureLocalLog(self):
return log.startLogging(_Notafile(self, "log"), setStdout=False)
def append(self, text, kind=None):
# XXX: It seems weird to have to do this thing with always applying
# a 'default' tag. Can't we change the fundamental look instead?
tags = ["default"]
if kind is not None:
tags.append(kind)
self.buffer.insert_with_tags_by_name(self.buffer.get_end_iter(),
text, *tags)
# Silly things, the TextView needs to update itself before it knows
# where the bottom is.
if self._willScroll is None:
self._willScroll = gtk.idle_add(self._scrollDown)
def _scrollDown(self, *unused):
self.textView.scroll_to_iter(self.buffer.get_end_iter(), 0,
True, 1.0, 1.0)
self._willScroll = None
return False
class History:
def __init__(self, maxhist=10000):
self.ringbuffer = ['']
self.maxhist = maxhist
self.histCursor = 0
def append(self, htext):
self.ringbuffer.insert(-1, htext)
if len(self.ringbuffer) > self.maxhist:
self.ringbuffer.pop(0)
self.histCursor = len(self.ringbuffer) - 1
self.ringbuffer[-1] = ''
def move(self, prevnext=1):
'''
Return next/previous item in the history, stopping at top/bottom.
'''
hcpn = self.histCursor + prevnext
if hcpn >= 0 and hcpn < len(self.ringbuffer):
self.histCursor = hcpn
return self.ringbuffer[hcpn]
else:
return None
def histup(self, textbuffer):
if self.histCursor == len(self.ringbuffer) - 1:
si, ei = textbuffer.get_start_iter(), textbuffer.get_end_iter()
self.ringbuffer[-1] = textbuffer.get_text(si,ei)
newtext = self.move(-1)
if newtext is None:
return
textbuffer.set_text(newtext)
def histdown(self, textbuffer):
newtext = self.move(1)
if newtext is None:
return
textbuffer.set_text(newtext)
class ConsoleInput:
toplevel, rkeymap = None, None
__debug = False
def __init__(self, textView):
self.textView=textView
self.rkeymap = {}
self.history = History()
for name in dir(gtk.keysyms):
try:
self.rkeymap[getattr(gtk.keysyms, name)] = name
except TypeError:
pass
def _on_key_press_event(self, entry, event):
stopSignal = False
ksym = self.rkeymap.get(event.keyval, None)
mods = []
for prefix, mask in [('ctrl', gtk.gdk.CONTROL_MASK), ('shift', gtk.gdk.SHIFT_MASK)]:
if event.state & mask:
mods.append(prefix)
if mods:
ksym = '_'.join(mods + [ksym])
if ksym:
rvalue = getattr(
self, 'key_%s' % ksym, lambda *a, **kw: None)(entry, event)
if self.__debug:
print ksym
return rvalue
def getText(self):
buffer = self.textView.get_buffer()
iter1, iter2 = buffer.get_bounds()
text = buffer.get_text(iter1, iter2, False)
return text
def setText(self, text):
self.textView.get_buffer().set_text(text)
def key_Return(self, entry, event):
text = self.getText()
# Figure out if that Return meant "next line" or "execute."
try:
c = code.compile_command(text)
except SyntaxError, e:
# This could conceivably piss you off if the client's python
# doesn't accept keywords that are known to the manhole's
# python.
point = buffer.get_iter_at_line_offset(e.lineno, e.offset)
buffer.place(point)
# TODO: Componentize!
self.toplevel.output.append(str(e), "exception")
except (OverflowError, ValueError), e:
self.toplevel.output.append(str(e), "exception")
else:
if c is not None:
self.sendMessage()
# Don't insert Return as a newline in the buffer.
self.history.append(text)
self.clear()
# entry.emit_stop_by_name("key_press_event")
return True
else:
# not a complete code block
return False
return False
def key_Up(self, entry, event):
# if I'm at the top, previous history item.
textbuffer = self.textView.get_buffer()
if textbuffer.get_iter_at_mark(textbuffer.get_insert()).get_line() == 0:
self.history.histup(textbuffer)
return True
return False
def key_Down(self, entry, event):
textbuffer = self.textView.get_buffer()
if textbuffer.get_iter_at_mark(textbuffer.get_insert()).get_line() == (
textbuffer.get_line_count() - 1):
self.history.histdown(textbuffer)
return True
return False
key_ctrl_p = key_Up
key_ctrl_n = key_Down
def key_ctrl_shift_F9(self, entry, event):
if self.__debug:
import pdb; pdb.set_trace()
def clear(self):
buffer = self.textView.get_buffer()
buffer.delete(*buffer.get_bounds())
def sendMessage(self):
buffer = self.textView.get_buffer()
iter1, iter2 = buffer.get_bounds()
text = buffer.get_text(iter1, iter2, False)
self.toplevel.output.append(pythonify(text), 'command')
# TODO: Componentize better!
try:
return self.toplevel.getComponent(IManholeClient).do(text)
except OfflineError:
self.toplevel.output.append("Not connected, command not sent.\n",
"exception")
def pythonify(text):
'''
Make some text appear as though it was typed in at a Python prompt.
'''
lines = text.split('\n')
lines[0] = '>>> ' + lines[0]
return '\n... '.join(lines) + '\n'
class _Notafile:
"""Curry to make failure.printTraceback work with the output widget."""
def __init__(self, output, kind):
self.output = output
self.kind = kind
def write(self, txt):
self.output.append(txt, self.kind)
def flush(self):
pass
class ManholeClient(components.Adapter, pb.Referenceable):
implements(IManholeClient)
capabilities = {
# "Explorer": 'Set',
"Failure": 'Set'
}
def _cbLogin(self, perspective):
self.perspective = perspective
perspective.notifyOnDisconnect(self._cbDisconnected)
return perspective
def remote_console(self, messages):
for kind, content in messages:
if isinstance(content, types.StringTypes):
self.original.output.append(content, kind)
elif (kind == "exception") and isinstance(content, failure.Failure):
content.printTraceback(_Notafile(self.original.output,
"exception"))
else:
self.original.output.append(str(content), kind)
def remote_receiveExplorer(self, xplorer):
pass
def remote_listCapabilities(self):
return self.capabilities
def _cbDisconnected(self, perspective):
self.perspective = None
def do(self, text):
if self.perspective is None:
raise OfflineError
return self.perspective.callRemote("do", text)
components.backwardsCompatImplements(ManholeClient)
components.registerAdapter(ManholeClient, ManholeWindow, IManholeClient)
|
gpl-2.0
|
[
3,
1882,
2018,
1882,
199,
3,
2672,
1304,
26,
8116,
18,
1237,
16668,
14,
647,
12,
86,
413,
14,
25,
13004,
15,
1643,
15,
1780,
5851,
26,
2010,
26,
1643,
1066,
439,
889,
764,
7910,
2672,
199,
3,
1898,
334,
67,
9,
12521,
13,
15431,
17078,
8449,
26640,
14,
199,
3,
1666,
5113,
367,
2436,
14,
421,
199,
624,
2395,
16668,
1890,
543,
282,
598,
15263,
373,
18,
14,
88,
13738,
13,
500,
14,
199,
624,
199,
199,
363,
1023,
363,
275,
4505,
12714,
26,
413,
14,
25,
2672,
3894,
845,
6809,
18,
61,
199,
199,
504,
7390,
492,
4248,
199,
504,
7390,
14,
4901,
492,
9655,
199,
504,
7390,
14,
1548,
492,
7323,
12,
5988,
12,
943,
12,
4884,
199,
504,
7390,
14,
29889,
492,
10446,
199,
504,
7390,
14,
29889,
14,
1907,
492,
8116,
18,
1974,
199,
199,
504,
7390,
14,
1237,
16668,
14,
1364,
492,
473,
2395,
16668,
3041,
199,
504,
20110,
14,
3266,
492,
9031,
199,
199,
3,
710,
1134,
12275,
14,
4365,
367,
1015,
499,
14,
16,
965,
2575,
2757,
4224,
701,
314,
9655,
14,
199,
646,
8116,
199,
199,
646,
1233,
12,
2943,
12,
6485,
199,
199,
3,
3254,
26,
199,
3,
221,
4155,
4816,
13,
632,
282,
1255,
13,
521,
945,
14,
199,
3,
221,
7910,
22732,
14,
199,
3,
221,
5495,
3181,
1133,
3633,
590,
2429,
13618,
282,
3499,
1950,
14,
221,
14811,
626,
14,
199,
3,
221,
4155,
2005,
19807,
23504,
434,
402,
1380,
282,
1414,
965,
9709,
12,
2755,
340,
199,
3,
258,
652,
965,
949,
372,
574,
880,
652,
3181,
1133,
870,
7003,
370,
314,
8559,
14,
199,
199,
533,
28856,
604,
547,
8,
1726,
304,
272,
986,
199,
199,
533,
4688,
16668,
4301,
8,
4608,
14,
2404,
265,
287,
22927,
12,
8116,
18,
1974,
14,
39,
17236,
43,
1024,
529,
304,
272,
486,
416,
318,
441,
275,
4884,
14,
6637,
515,
3460,
493,
3108,
298,
12275,
18,
1237,
16668,
14,
31589,
531,
339,
485,
8583,
275,
661,
1210,
1673,
1199,
1673,
1237,
16668,
4301,
358,
339,
347,
636,
826,
721,
277,
304,
267,
291,
14,
4322,
275,
1052,
267,
8116,
18,
1974,
14,
39,
17236,
43,
1024,
529,
855,
826,
721,
277,
9,
267,
7323,
14,
2404,
265,
287,
22927,
855,
826,
721,
277,
9,
398,
291,
14,
1210,
275,
19809,
3205,
8,
277,
423,
1210,
9,
267,
291,
14,
1210,
14,
13517,
275,
291,
267,
291,
14,
1199,
275,
19809,
2959,
8,
277,
423,
1199,
9,
398,
327,
738,
3561,
14,
221,
598,
17236,
43,
1024,
529,
5965,
5712,
1133,
880,
6954,
367,
19306,
2251,
14,
267,
327,
473,
2934,
642,
8539,
370,
314,
19809,
3205,
1159,
3016,
12,
440,
6020,
267,
327,
641,
642,
1021,
14,
267,
291,
423,
1210,
14,
2242,
480,
498,
63,
2915,
63,
1430,
401,
291,
14,
1210,
423,
265,
63,
498,
63,
2915,
63,
1430,
9,
339,
347,
663,
16986,
8,
277,
12,
4243,
304,
267,
291,
14,
4322,
275,
4243,
339,
347,
4676,
8,
277,
304,
267,
1890,
275,
291,
14,
362,
7004,
8,
1469,
290,
16668,
3041,
9,
267,
366,
275,
8116,
18,
1974,
14,
2886,
8,
1258,
12,
1011,
277,
14,
4322,
9,
267,
366,
14,
10053,
8,
277,
423,
2894,
8880,
9,
267,
366,
14,
10053,
8,
1258,
423,
2894,
8880,
9,
267,
366,
14,
31554,
8,
277,
423,
2871,
8880,
9,
339,
347,
485,
2894,
2825,
7113,
8,
277,
12,
1126,
16657,
304,
267,
291,
14,
1199,
14,
740,
3647,
83,
22396,
13437,
14,
520,
2961,
78,
2,
450,
334,
529,
16657,
4706,
298,
1832,
531,
267,
291,
423,
1237,
16668,
4301,
14,
409,
63,
1213,
480,
2395,
16668,
531,
339,
347,
485,
2894,
8880,
8,
277,
12,
1126,
16657,
304,
267,
9104,
275,
1126,
16657,
14,
16620,
14,
5545,
14,
362,
12566,
342,
267,
291,
14,
1199,
14,
740,
480,
16382,
370,
450,
83,
60,
78,
2,
450,
334,
7866,
4706,
298,
1832,
531,
267,
1126,
16657,
14,
6814,
3314,
16761,
8,
277,
423,
2894,
2825,
7113,
9,
267,
291,
423,
1237,
16668,
4301,
14,
409,
63,
1213,
480,
2395,
16668,
446,
450,
83,
2,
450,
334,
7866,
430,
267,
372,
1126,
16657,
339,
347,
485,
2871,
8880,
8,
277,
12,
4499,
304,
267,
291,
14,
1199,
14,
740,
480,
8880,
26892,
450,
83,
60,
78,
2,
450,
334,
5764,
14,
585,
4706,
298,
1971,
531,
339,
347,
485,
265,
63,
10254,
20973,
63,
8222,
8,
277,
12,
3938,
12,
627,
8618,
304,
267,
492,
984,
267,
687,
747,
492,
931,
267,
291,
14,
1199,
14,
740,
21723,
199,
65,
17078,
4688,
16668,
1890,
523,
5444,
1356,
26,
272,
2818,
12145,
3673,
9,
83,
272,
2018,
2818,
1548,
3673,
9,
83,
641,
2818,
3246,
9,
83,
272,
598,
15263,
2818,
12275,
3673,
9,
83,
1182,
1611,
8391,
43,
2818,
647,
12275,
3673,
9,
83,
272,
2818,
578,
9,
83,
2818,
1494,
3673,
9,
83,
199,
1014,
921,
12145,
3642,
14,
957,
15,
199,
624,
450,
791,
12145,
3673,
356,
4248,
14,
2809,
1023,
12,
2126,
283,
1548,
3673,
356,
984,
14,
1023,
14,
1814,
2258,
78,
297,
1557,
78,
420,
17748,
2126,
283,
3246,
356,
984,
14,
3246,
12,
2126,
283,
12275,
3673,
356,
32443,
904,
8,
1130,
8,
495,
12,
8116,
14,
12275,
63,
1023,
1826,
2126,
283,
647,
12275,
3673,
356,
32443,
904,
8,
1130,
8,
495,
12,
8116,
14,
647,
12275,
63,
1023,
1826,
2126,
283,
578,
356,
931,
14,
4846,
3460,
493,
10139,
2126,
283,
1494,
3673,
356,
636,
1023,
3108,
2126,
1660,
298,
1832,
531,
339,
347,
485,
265,
63,
1490,
20973,
63,
8222,
8,
277,
12,
3938,
12,
922,
576,
29,
403,
304,
267,
291,
14,
2886,
342,
339,
347,
485,
265,
63,
1237,
16668,
4301,
63,
1807,
63,
1430,
8,
277,
12,
3938,
12,
627,
8618,
304,
267,
9655,
14,
2379,
342,
339,
347,
485,
265,
63,
10589,
20973,
63,
8222,
8,
277,
12,
3938,
12,
627,
8618,
304,
267,
9655,
14,
2379,
342,
339,
347,
641,
63,
9233,
63,
277,
63,
8222,
8,
277,
12,
627,
8618,
304,
267,
687,
7390,
14,
1548,
492,
22110,
267,
22110,
14,
19278,
8,
10955,
14,
362,
578,
8,
277,
855,
533,
8964,
421,
199
] |
[
1882,
2018,
1882,
199,
3,
2672,
1304,
26,
8116,
18,
1237,
16668,
14,
647,
12,
86,
413,
14,
25,
13004,
15,
1643,
15,
1780,
5851,
26,
2010,
26,
1643,
1066,
439,
889,
764,
7910,
2672,
199,
3,
1898,
334,
67,
9,
12521,
13,
15431,
17078,
8449,
26640,
14,
199,
3,
1666,
5113,
367,
2436,
14,
421,
199,
624,
2395,
16668,
1890,
543,
282,
598,
15263,
373,
18,
14,
88,
13738,
13,
500,
14,
199,
624,
199,
199,
363,
1023,
363,
275,
4505,
12714,
26,
413,
14,
25,
2672,
3894,
845,
6809,
18,
61,
199,
199,
504,
7390,
492,
4248,
199,
504,
7390,
14,
4901,
492,
9655,
199,
504,
7390,
14,
1548,
492,
7323,
12,
5988,
12,
943,
12,
4884,
199,
504,
7390,
14,
29889,
492,
10446,
199,
504,
7390,
14,
29889,
14,
1907,
492,
8116,
18,
1974,
199,
199,
504,
7390,
14,
1237,
16668,
14,
1364,
492,
473,
2395,
16668,
3041,
199,
504,
20110,
14,
3266,
492,
9031,
199,
199,
3,
710,
1134,
12275,
14,
4365,
367,
1015,
499,
14,
16,
965,
2575,
2757,
4224,
701,
314,
9655,
14,
199,
646,
8116,
199,
199,
646,
1233,
12,
2943,
12,
6485,
199,
199,
3,
3254,
26,
199,
3,
221,
4155,
4816,
13,
632,
282,
1255,
13,
521,
945,
14,
199,
3,
221,
7910,
22732,
14,
199,
3,
221,
5495,
3181,
1133,
3633,
590,
2429,
13618,
282,
3499,
1950,
14,
221,
14811,
626,
14,
199,
3,
221,
4155,
2005,
19807,
23504,
434,
402,
1380,
282,
1414,
965,
9709,
12,
2755,
340,
199,
3,
258,
652,
965,
949,
372,
574,
880,
652,
3181,
1133,
870,
7003,
370,
314,
8559,
14,
199,
199,
533,
28856,
604,
547,
8,
1726,
304,
272,
986,
199,
199,
533,
4688,
16668,
4301,
8,
4608,
14,
2404,
265,
287,
22927,
12,
8116,
18,
1974,
14,
39,
17236,
43,
1024,
529,
304,
272,
486,
416,
318,
441,
275,
4884,
14,
6637,
515,
3460,
493,
3108,
298,
12275,
18,
1237,
16668,
14,
31589,
531,
339,
485,
8583,
275,
661,
1210,
1673,
1199,
1673,
1237,
16668,
4301,
358,
339,
347,
636,
826,
721,
277,
304,
267,
291,
14,
4322,
275,
1052,
267,
8116,
18,
1974,
14,
39,
17236,
43,
1024,
529,
855,
826,
721,
277,
9,
267,
7323,
14,
2404,
265,
287,
22927,
855,
826,
721,
277,
9,
398,
291,
14,
1210,
275,
19809,
3205,
8,
277,
423,
1210,
9,
267,
291,
14,
1210,
14,
13517,
275,
291,
267,
291,
14,
1199,
275,
19809,
2959,
8,
277,
423,
1199,
9,
398,
327,
738,
3561,
14,
221,
598,
17236,
43,
1024,
529,
5965,
5712,
1133,
880,
6954,
367,
19306,
2251,
14,
267,
327,
473,
2934,
642,
8539,
370,
314,
19809,
3205,
1159,
3016,
12,
440,
6020,
267,
327,
641,
642,
1021,
14,
267,
291,
423,
1210,
14,
2242,
480,
498,
63,
2915,
63,
1430,
401,
291,
14,
1210,
423,
265,
63,
498,
63,
2915,
63,
1430,
9,
339,
347,
663,
16986,
8,
277,
12,
4243,
304,
267,
291,
14,
4322,
275,
4243,
339,
347,
4676,
8,
277,
304,
267,
1890,
275,
291,
14,
362,
7004,
8,
1469,
290,
16668,
3041,
9,
267,
366,
275,
8116,
18,
1974,
14,
2886,
8,
1258,
12,
1011,
277,
14,
4322,
9,
267,
366,
14,
10053,
8,
277,
423,
2894,
8880,
9,
267,
366,
14,
10053,
8,
1258,
423,
2894,
8880,
9,
267,
366,
14,
31554,
8,
277,
423,
2871,
8880,
9,
339,
347,
485,
2894,
2825,
7113,
8,
277,
12,
1126,
16657,
304,
267,
291,
14,
1199,
14,
740,
3647,
83,
22396,
13437,
14,
520,
2961,
78,
2,
450,
334,
529,
16657,
4706,
298,
1832,
531,
267,
291,
423,
1237,
16668,
4301,
14,
409,
63,
1213,
480,
2395,
16668,
531,
339,
347,
485,
2894,
8880,
8,
277,
12,
1126,
16657,
304,
267,
9104,
275,
1126,
16657,
14,
16620,
14,
5545,
14,
362,
12566,
342,
267,
291,
14,
1199,
14,
740,
480,
16382,
370,
450,
83,
60,
78,
2,
450,
334,
7866,
4706,
298,
1832,
531,
267,
1126,
16657,
14,
6814,
3314,
16761,
8,
277,
423,
2894,
2825,
7113,
9,
267,
291,
423,
1237,
16668,
4301,
14,
409,
63,
1213,
480,
2395,
16668,
446,
450,
83,
2,
450,
334,
7866,
430,
267,
372,
1126,
16657,
339,
347,
485,
2871,
8880,
8,
277,
12,
4499,
304,
267,
291,
14,
1199,
14,
740,
480,
8880,
26892,
450,
83,
60,
78,
2,
450,
334,
5764,
14,
585,
4706,
298,
1971,
531,
339,
347,
485,
265,
63,
10254,
20973,
63,
8222,
8,
277,
12,
3938,
12,
627,
8618,
304,
267,
492,
984,
267,
687,
747,
492,
931,
267,
291,
14,
1199,
14,
740,
21723,
199,
65,
17078,
4688,
16668,
1890,
523,
5444,
1356,
26,
272,
2818,
12145,
3673,
9,
83,
272,
2018,
2818,
1548,
3673,
9,
83,
641,
2818,
3246,
9,
83,
272,
598,
15263,
2818,
12275,
3673,
9,
83,
1182,
1611,
8391,
43,
2818,
647,
12275,
3673,
9,
83,
272,
2818,
578,
9,
83,
2818,
1494,
3673,
9,
83,
199,
1014,
921,
12145,
3642,
14,
957,
15,
199,
624,
450,
791,
12145,
3673,
356,
4248,
14,
2809,
1023,
12,
2126,
283,
1548,
3673,
356,
984,
14,
1023,
14,
1814,
2258,
78,
297,
1557,
78,
420,
17748,
2126,
283,
3246,
356,
984,
14,
3246,
12,
2126,
283,
12275,
3673,
356,
32443,
904,
8,
1130,
8,
495,
12,
8116,
14,
12275,
63,
1023,
1826,
2126,
283,
647,
12275,
3673,
356,
32443,
904,
8,
1130,
8,
495,
12,
8116,
14,
647,
12275,
63,
1023,
1826,
2126,
283,
578,
356,
931,
14,
4846,
3460,
493,
10139,
2126,
283,
1494,
3673,
356,
636,
1023,
3108,
2126,
1660,
298,
1832,
531,
339,
347,
485,
265,
63,
1490,
20973,
63,
8222,
8,
277,
12,
3938,
12,
922,
576,
29,
403,
304,
267,
291,
14,
2886,
342,
339,
347,
485,
265,
63,
1237,
16668,
4301,
63,
1807,
63,
1430,
8,
277,
12,
3938,
12,
627,
8618,
304,
267,
9655,
14,
2379,
342,
339,
347,
485,
265,
63,
10589,
20973,
63,
8222,
8,
277,
12,
3938,
12,
627,
8618,
304,
267,
9655,
14,
2379,
342,
339,
347,
641,
63,
9233,
63,
277,
63,
8222,
8,
277,
12,
627,
8618,
304,
267,
687,
7390,
14,
1548,
492,
22110,
267,
22110,
14,
19278,
8,
10955,
14,
362,
578,
8,
277,
855,
533,
8964,
421,
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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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
] |
dpetzold/django
|
tests/utils_tests/test_baseconv.py
|
326
|
1787
|
from unittest import TestCase
from django.utils.baseconv import (
BaseConverter, base2, base16, base36, base56, base62, base64,
)
from django.utils.six.moves import range
class TestBaseConv(TestCase):
def test_baseconv(self):
nums = [-10 ** 10, 10 ** 10] + list(range(-100, 100))
for converter in [base2, base16, base36, base56, base62, base64]:
for i in nums:
self.assertEqual(i, converter.decode(converter.encode(i)))
def test_base11(self):
base11 = BaseConverter('0123456789-', sign='$')
self.assertEqual(base11.encode(1234), '-22')
self.assertEqual(base11.decode('-22'), 1234)
self.assertEqual(base11.encode(-1234), '$-22')
self.assertEqual(base11.decode('$-22'), -1234)
def test_base20(self):
base20 = BaseConverter('0123456789abcdefghij')
self.assertEqual(base20.encode(1234), '31e')
self.assertEqual(base20.decode('31e'), 1234)
self.assertEqual(base20.encode(-1234), '-31e')
self.assertEqual(base20.decode('-31e'), -1234)
def test_base64(self):
self.assertEqual(base64.encode(1234), 'JI')
self.assertEqual(base64.decode('JI'), 1234)
self.assertEqual(base64.encode(-1234), '$JI')
self.assertEqual(base64.decode('$JI'), -1234)
def test_base7(self):
base7 = BaseConverter('cjdhel3', sign='g')
self.assertEqual(base7.encode(1234), 'hejd')
self.assertEqual(base7.decode('hejd'), 1234)
self.assertEqual(base7.encode(-1234), 'ghejd')
self.assertEqual(base7.decode('ghejd'), -1234)
def test_exception(self):
self.assertRaises(ValueError, BaseConverter, 'abc', sign='a')
self.assertIsInstance(BaseConverter('abc', sign='d'), BaseConverter)
|
bsd-3-clause
|
[
504,
2882,
492,
7640,
199,
199,
504,
1639,
14,
1208,
14,
1095,
5598,
492,
334,
272,
3523,
11907,
12,
1300,
18,
12,
1300,
975,
12,
1300,
1344,
12,
1300,
1367,
12,
1300,
2789,
12,
1300,
772,
12,
199,
9,
199,
504,
1639,
14,
1208,
14,
4174,
14,
4912,
492,
1425,
421,
199,
533,
1379,
1563,
11596,
8,
1746,
304,
339,
347,
511,
63,
1095,
5598,
8,
277,
304,
267,
24047,
275,
5243,
709,
1011,
1616,
12,
1616,
1011,
1616,
61,
435,
769,
8,
1842,
2801,
1960,
12,
2948,
430,
267,
367,
11109,
315,
359,
1095,
18,
12,
1300,
975,
12,
1300,
1344,
12,
1300,
1367,
12,
1300,
2789,
12,
1300,
772,
2189,
288,
367,
284,
315,
24047,
26,
355,
291,
14,
629,
8,
73,
12,
11109,
14,
2708,
8,
11256,
14,
2143,
8,
73,
1724,
339,
347,
511,
63,
1095,
845,
8,
277,
304,
267,
1300,
845,
275,
3523,
11907,
360,
11371,
14382,
2070,
534,
9988,
267,
291,
14,
629,
8,
1095,
845,
14,
2143,
8,
4321,
395,
2475,
1081,
358,
267,
291,
14,
629,
8,
1095,
845,
14,
2708,
3654,
1081,
659,
14763,
9,
267,
291,
14,
629,
8,
1095,
845,
14,
2143,
2801,
4321,
395,
4505,
13,
1081,
358,
267,
291,
14,
629,
8,
1095,
845,
14,
2708,
14676,
13,
1081,
659,
446,
4321,
9,
339,
347,
511,
63,
1095,
1165,
8,
277,
304,
267,
1300,
1165,
275,
3523,
11907,
360,
11371,
18677,
358,
267,
291,
14,
629,
8,
1095,
1165,
14,
2143,
8,
4321,
395,
283,
2192,
69,
358,
267,
291,
14,
629,
8,
1095,
1165,
14,
2708,
360,
2192,
69,
659,
14763,
9,
267,
291,
14,
629,
8,
1095,
1165,
14,
2143,
2801,
4321,
395,
2475,
2192,
69,
358,
267,
291,
14,
629,
8,
1095,
1165,
14,
2708,
3654,
2192,
69,
659,
446,
4321,
9,
339,
347,
511,
63,
1095,
772,
8,
277,
304,
267,
291,
14,
629,
8,
1095,
772,
14,
2143,
8,
4321,
395,
283,
32126,
358,
267,
291,
14,
629,
8,
1095,
772,
14,
2708,
360,
32126,
659,
14763,
9,
267,
291,
14,
629,
8,
1095,
772,
14,
2143,
2801,
4321,
395,
4505,
32126,
358,
267,
291,
14,
629,
8,
1095,
772,
14,
2708,
14676,
32126,
659,
446,
4321,
9,
339,
347,
511,
63,
1095,
23,
8,
277,
304,
267,
1300,
23,
275,
3523,
11907,
360,
24862,
7821,
352,
19,
297,
2070,
534,
71,
358,
267,
291,
14,
629,
8,
1095,
23,
14,
2143,
8,
4321,
395,
283,
426,
17694,
358,
267,
291,
14,
629,
8,
1095,
23,
14,
2708,
360,
426,
17694,
659,
14763,
9,
267,
291,
14,
629,
8,
1095,
23,
14,
2143,
2801,
4321,
395,
283,
71,
426,
17694,
358,
267,
291,
14,
629,
8,
1095,
23,
14,
2708,
360,
71,
426,
17694,
659,
446,
4321,
9,
339,
347,
511,
63,
1971,
8,
277,
304,
267,
291,
14,
1855,
8,
3393,
12,
3523,
11907,
12,
283,
3175,
297,
2070,
534,
65,
358,
267,
291,
14,
6926,
8,
1563,
11907,
360,
3175,
297,
2070,
534,
68,
659,
3523,
11907,
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
] |
[
2882,
492,
7640,
199,
199,
504,
1639,
14,
1208,
14,
1095,
5598,
492,
334,
272,
3523,
11907,
12,
1300,
18,
12,
1300,
975,
12,
1300,
1344,
12,
1300,
1367,
12,
1300,
2789,
12,
1300,
772,
12,
199,
9,
199,
504,
1639,
14,
1208,
14,
4174,
14,
4912,
492,
1425,
421,
199,
533,
1379,
1563,
11596,
8,
1746,
304,
339,
347,
511,
63,
1095,
5598,
8,
277,
304,
267,
24047,
275,
5243,
709,
1011,
1616,
12,
1616,
1011,
1616,
61,
435,
769,
8,
1842,
2801,
1960,
12,
2948,
430,
267,
367,
11109,
315,
359,
1095,
18,
12,
1300,
975,
12,
1300,
1344,
12,
1300,
1367,
12,
1300,
2789,
12,
1300,
772,
2189,
288,
367,
284,
315,
24047,
26,
355,
291,
14,
629,
8,
73,
12,
11109,
14,
2708,
8,
11256,
14,
2143,
8,
73,
1724,
339,
347,
511,
63,
1095,
845,
8,
277,
304,
267,
1300,
845,
275,
3523,
11907,
360,
11371,
14382,
2070,
534,
9988,
267,
291,
14,
629,
8,
1095,
845,
14,
2143,
8,
4321,
395,
2475,
1081,
358,
267,
291,
14,
629,
8,
1095,
845,
14,
2708,
3654,
1081,
659,
14763,
9,
267,
291,
14,
629,
8,
1095,
845,
14,
2143,
2801,
4321,
395,
4505,
13,
1081,
358,
267,
291,
14,
629,
8,
1095,
845,
14,
2708,
14676,
13,
1081,
659,
446,
4321,
9,
339,
347,
511,
63,
1095,
1165,
8,
277,
304,
267,
1300,
1165,
275,
3523,
11907,
360,
11371,
18677,
358,
267,
291,
14,
629,
8,
1095,
1165,
14,
2143,
8,
4321,
395,
283,
2192,
69,
358,
267,
291,
14,
629,
8,
1095,
1165,
14,
2708,
360,
2192,
69,
659,
14763,
9,
267,
291,
14,
629,
8,
1095,
1165,
14,
2143,
2801,
4321,
395,
2475,
2192,
69,
358,
267,
291,
14,
629,
8,
1095,
1165,
14,
2708,
3654,
2192,
69,
659,
446,
4321,
9,
339,
347,
511,
63,
1095,
772,
8,
277,
304,
267,
291,
14,
629,
8,
1095,
772,
14,
2143,
8,
4321,
395,
283,
32126,
358,
267,
291,
14,
629,
8,
1095,
772,
14,
2708,
360,
32126,
659,
14763,
9,
267,
291,
14,
629,
8,
1095,
772,
14,
2143,
2801,
4321,
395,
4505,
32126,
358,
267,
291,
14,
629,
8,
1095,
772,
14,
2708,
14676,
32126,
659,
446,
4321,
9,
339,
347,
511,
63,
1095,
23,
8,
277,
304,
267,
1300,
23,
275,
3523,
11907,
360,
24862,
7821,
352,
19,
297,
2070,
534,
71,
358,
267,
291,
14,
629,
8,
1095,
23,
14,
2143,
8,
4321,
395,
283,
426,
17694,
358,
267,
291,
14,
629,
8,
1095,
23,
14,
2708,
360,
426,
17694,
659,
14763,
9,
267,
291,
14,
629,
8,
1095,
23,
14,
2143,
2801,
4321,
395,
283,
71,
426,
17694,
358,
267,
291,
14,
629,
8,
1095,
23,
14,
2708,
360,
71,
426,
17694,
659,
446,
4321,
9,
339,
347,
511,
63,
1971,
8,
277,
304,
267,
291,
14,
1855,
8,
3393,
12,
3523,
11907,
12,
283,
3175,
297,
2070,
534,
65,
358,
267,
291,
14,
6926,
8,
1563,
11907,
360,
3175,
297,
2070,
534,
68,
659,
3523,
11907,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Cadene/pretrained-models.pytorch
|
pretrainedmodels/models/wideresnet.py
|
1
|
2830
|
from __future__ import print_function, division, absolute_import
import os
from os.path import expanduser
import hickle as hkl
import torch
import torch.nn.functional as F
from torch.autograd import Variable
__all__ = ['wideresnet50']
model_urls = {
'wideresnet152': 'https://s3.amazonaws.com/pytorch/h5models/wide-resnet-50-2-export.hkl'
}
def define_model(params):
def conv2d(input, params, base, stride=1, pad=0):
return F.conv2d(input, params[base + '.weight'],
params[base + '.bias'], stride, pad)
def group(input, params, base, stride, n):
o = input
for i in range(0,n):
b_base = ('%s.block%d.conv') % (base, i)
x = o
o = conv2d(x, params, b_base + '0')
o = F.relu(o)
o = conv2d(o, params, b_base + '1', stride=i==0 and stride or 1, pad=1)
o = F.relu(o)
o = conv2d(o, params, b_base + '2')
if i == 0:
o += conv2d(x, params, b_base + '_dim', stride=stride)
else:
o += x
o = F.relu(o)
return o
# determine network size by parameters
blocks = [sum([re.match('group%d.block\d+.conv0.weight'%j, k) is not None
for k in params.keys()]) for j in range(4)]
def f(input, params, pooling_classif=True):
o = F.conv2d(input, params['conv0.weight'], params['conv0.bias'], 2, 3)
o = F.relu(o)
o = F.max_pool2d(o, 3, 2, 1)
o_g0 = group(o, params, 'group0', 1, blocks[0])
o_g1 = group(o_g0, params, 'group1', 2, blocks[1])
o_g2 = group(o_g1, params, 'group2', 2, blocks[2])
o_g3 = group(o_g2, params, 'group3', 2, blocks[3])
if pooling_classif:
o = F.avg_pool2d(o_g3, 7, 1, 0)
o = o.view(o.size(0), -1)
o = F.linear(o, params['fc.weight'], params['fc.bias'])
return o
return f
class WideResNet(nn.Module):
def __init__(self, pooling):
super(WideResNet, self).__init__()
self.pooling = pooling
self.params = params
def forward(self, x):
x = f(x, self.params, self.pooling)
return x
def wideresnet50(pooling):
dir_models = os.path.join(expanduser("~"), '.torch/wideresnet')
path_hkl = os.path.join(dir_models, 'wideresnet50.hkl')
if os.path.isfile(path_hkl):
params = hkl.load(path_hkl)
# convert numpy arrays to torch Variables
for k,v in sorted(params.items()):
print(k, v.shape)
params[k] = Variable(torch.from_numpy(v), requires_grad=True)
else:
os.system('mkdir -p ' + dir_models)
os.system('wget {} -O {}'.format(model_urls['wideresnet50'], path_hkl))
f = define_model(params)
model = WideResNet(pooling)
return model
|
bsd-3-clause
|
[
504,
636,
2443,
363,
492,
870,
63,
1593,
12,
4629,
12,
3679,
63,
646,
199,
646,
747,
199,
504,
747,
14,
515,
492,
6544,
751,
199,
646,
394,
2000,
274,
465,
394,
9503,
199,
646,
21416,
199,
646,
21416,
14,
4411,
14,
15481,
465,
481,
199,
504,
21416,
14,
2495,
6017,
492,
4905,
199,
199,
363,
452,
363,
275,
788,
13062,
28998,
1400,
418,
199,
199,
1238,
63,
3603,
275,
469,
272,
283,
13062,
28998,
11024,
356,
283,
2859,
921,
83,
19,
14,
21442,
14,
957,
15,
647,
29676,
15,
72,
21,
992,
15,
13062,
13,
28998,
13,
1400,
13,
18,
13,
3790,
14,
72,
9503,
7,
199,
93,
199,
199,
318,
5627,
63,
1238,
8,
1162,
304,
272,
347,
8260,
18,
68,
8,
1210,
12,
1862,
12,
1300,
12,
7345,
29,
17,
12,
6567,
29,
16,
304,
267,
372,
481,
14,
5598,
18,
68,
8,
1210,
12,
1862,
59,
1095,
435,
1987,
3463,
995,
717,
1862,
59,
1095,
435,
1987,
8160,
995,
7345,
12,
6567,
9,
339,
347,
1572,
8,
1210,
12,
1862,
12,
1300,
12,
7345,
12,
302,
304,
267,
312,
275,
1324,
267,
367,
284,
315,
1425,
8,
16,
12,
78,
304,
288,
330,
63,
1095,
275,
16651,
83,
14,
1457,
5,
68,
14,
5598,
358,
450,
334,
1095,
12,
284,
9,
288,
671,
275,
312,
288,
312,
275,
8260,
18,
68,
8,
88,
12,
1862,
12,
330,
63,
1095,
435,
283,
16,
358,
288,
312,
275,
481,
14,
12833,
8,
79,
9,
288,
312,
275,
8260,
18,
68,
8,
79,
12,
1862,
12,
330,
63,
1095,
435,
283,
17,
297,
7345,
29,
73,
389,
16,
436,
7345,
503,
413,
12,
6567,
29,
17,
9,
288,
312,
275,
481,
14,
12833,
8,
79,
9,
288,
312,
275,
8260,
18,
68,
8,
79,
12,
1862,
12,
330,
63,
1095,
435,
283,
18,
358,
288,
340,
284,
508,
378,
26,
355,
312,
847,
8260,
18,
68,
8,
88,
12,
1862,
12,
330,
63,
1095,
435,
2513,
3572,
297,
7345,
29,
12318,
9,
288,
587,
26,
355,
312,
847,
671,
288,
312,
275,
481,
14,
12833,
8,
79,
9,
267,
372,
312,
339,
327,
6705,
2784,
1568,
701,
2633,
272,
5664,
275,
359,
1838,
779,
264,
14,
1431,
360,
923,
5,
68,
14,
1457,
60,
68,
26240,
5598,
16,
14,
3463,
5956,
74,
12,
1022,
9,
365,
440,
488,
673,
367,
1022,
315,
1862,
14,
1612,
9383,
367,
1335,
315,
1425,
8,
20,
1874,
339,
347,
289,
8,
1210,
12,
1862,
12,
20699,
63,
12334,
70,
29,
549,
304,
267,
312,
275,
481,
14,
5598,
18,
68,
8,
1210,
12,
1862,
459,
5598,
16,
14,
3463,
995,
1862,
459,
5598,
16,
14,
8160,
995,
499,
12,
650,
9,
267,
312,
275,
481,
14,
12833,
8,
79,
9,
267,
312,
275,
481,
14,
988,
63,
2293,
18,
68,
8,
79,
12,
650,
12,
499,
12,
413,
9,
267,
312,
63,
71,
16,
275,
1572,
8,
79,
12,
1862,
12,
283,
923,
16,
297,
413,
12,
5664,
59,
16,
566,
267,
312,
63,
71,
17,
275,
1572,
8,
79,
63,
71,
16,
12,
1862,
12,
283,
923,
17,
297,
499,
12,
5664,
59,
17,
566,
267,
312,
63,
71,
18,
275,
1572,
8,
79,
63,
71,
17,
12,
1862,
12,
283,
923,
18,
297,
499,
12,
5664,
59,
18,
566,
267,
312,
63,
71,
19,
275,
1572,
8,
79,
63,
71,
18,
12,
1862,
12,
283,
923,
19,
297,
499,
12,
5664,
59,
19,
566,
267,
340,
20699,
63,
12334,
70,
26,
288,
312,
275,
481,
14,
8595,
63,
2293,
18,
68,
8,
79,
63,
71,
19,
12,
1520,
12,
413,
12,
378,
9,
288,
312,
275,
312,
14,
1345,
8,
79,
14,
890,
8,
16,
395,
446,
17,
9,
288,
312,
275,
481,
14,
6676,
8,
79,
12,
1862,
459,
3003,
14,
3463,
995,
1862,
459,
3003,
14,
8160,
1105,
267,
372,
312,
339,
372,
289,
421,
199,
533,
32612,
1322,
2480,
8,
4411,
14,
2377,
304,
339,
347,
636,
826,
721,
277,
12,
20699,
304,
267,
1613,
8,
55,
2655,
1322,
2480,
12,
291,
2843,
826,
4533,
267,
291,
14,
28624,
275,
20699,
267,
291,
14,
1162,
275,
1862,
339,
347,
7568,
8,
277,
12,
671,
304,
267,
671,
275,
289,
8,
88,
12,
291,
14,
1162,
12,
291,
14,
28624,
9,
267,
372,
671,
421,
199,
318,
20239,
28998,
1400,
8,
28624,
304,
272,
2935,
63,
992,
275,
747,
14,
515,
14,
904,
8,
12131,
20793,
1288,
1987,
29676,
15,
13062,
28998,
358,
272,
931,
63,
72,
9503,
275,
747,
14,
515,
14,
904,
8,
694,
63,
992,
12,
283,
13062,
28998,
1400,
14,
72,
9503,
358,
272,
340,
747,
14,
515,
14,
6292,
8,
515,
63,
72,
9503,
304,
267,
1862,
275,
394,
9503,
14,
912,
8,
515,
63,
72,
9503,
9,
267,
327,
3957,
2680,
6572,
370,
21416,
17198,
267,
367,
1022,
12,
86,
315,
3355,
8,
1162,
14,
1744,
5109,
288,
870,
8,
75,
12,
373,
14,
1392,
9,
288,
1862,
59,
75,
61,
275,
4905,
8,
29676,
14,
504,
63,
4714,
8,
86,
395,
5074,
63,
6017,
29,
549,
9,
272,
587,
26,
267,
747,
14,
2253,
360,
8215,
446,
80,
283,
435,
2935,
63,
992,
9,
267,
747,
14,
2253,
360,
87,
362,
1052,
446,
47,
9499,
908,
8,
1238,
63,
3603,
459,
13062,
28998,
1400,
995,
931,
63,
72,
9503,
430,
272,
289,
275,
5627,
63,
1238,
8,
1162,
9,
272,
1402,
275,
32612,
1322,
2480,
8,
28624,
9,
272,
372,
1402,
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
] |
[
636,
2443,
363,
492,
870,
63,
1593,
12,
4629,
12,
3679,
63,
646,
199,
646,
747,
199,
504,
747,
14,
515,
492,
6544,
751,
199,
646,
394,
2000,
274,
465,
394,
9503,
199,
646,
21416,
199,
646,
21416,
14,
4411,
14,
15481,
465,
481,
199,
504,
21416,
14,
2495,
6017,
492,
4905,
199,
199,
363,
452,
363,
275,
788,
13062,
28998,
1400,
418,
199,
199,
1238,
63,
3603,
275,
469,
272,
283,
13062,
28998,
11024,
356,
283,
2859,
921,
83,
19,
14,
21442,
14,
957,
15,
647,
29676,
15,
72,
21,
992,
15,
13062,
13,
28998,
13,
1400,
13,
18,
13,
3790,
14,
72,
9503,
7,
199,
93,
199,
199,
318,
5627,
63,
1238,
8,
1162,
304,
272,
347,
8260,
18,
68,
8,
1210,
12,
1862,
12,
1300,
12,
7345,
29,
17,
12,
6567,
29,
16,
304,
267,
372,
481,
14,
5598,
18,
68,
8,
1210,
12,
1862,
59,
1095,
435,
1987,
3463,
995,
717,
1862,
59,
1095,
435,
1987,
8160,
995,
7345,
12,
6567,
9,
339,
347,
1572,
8,
1210,
12,
1862,
12,
1300,
12,
7345,
12,
302,
304,
267,
312,
275,
1324,
267,
367,
284,
315,
1425,
8,
16,
12,
78,
304,
288,
330,
63,
1095,
275,
16651,
83,
14,
1457,
5,
68,
14,
5598,
358,
450,
334,
1095,
12,
284,
9,
288,
671,
275,
312,
288,
312,
275,
8260,
18,
68,
8,
88,
12,
1862,
12,
330,
63,
1095,
435,
283,
16,
358,
288,
312,
275,
481,
14,
12833,
8,
79,
9,
288,
312,
275,
8260,
18,
68,
8,
79,
12,
1862,
12,
330,
63,
1095,
435,
283,
17,
297,
7345,
29,
73,
389,
16,
436,
7345,
503,
413,
12,
6567,
29,
17,
9,
288,
312,
275,
481,
14,
12833,
8,
79,
9,
288,
312,
275,
8260,
18,
68,
8,
79,
12,
1862,
12,
330,
63,
1095,
435,
283,
18,
358,
288,
340,
284,
508,
378,
26,
355,
312,
847,
8260,
18,
68,
8,
88,
12,
1862,
12,
330,
63,
1095,
435,
2513,
3572,
297,
7345,
29,
12318,
9,
288,
587,
26,
355,
312,
847,
671,
288,
312,
275,
481,
14,
12833,
8,
79,
9,
267,
372,
312,
339,
327,
6705,
2784,
1568,
701,
2633,
272,
5664,
275,
359,
1838,
779,
264,
14,
1431,
360,
923,
5,
68,
14,
1457,
60,
68,
26240,
5598,
16,
14,
3463,
5956,
74,
12,
1022,
9,
365,
440,
488,
673,
367,
1022,
315,
1862,
14,
1612,
9383,
367,
1335,
315,
1425,
8,
20,
1874,
339,
347,
289,
8,
1210,
12,
1862,
12,
20699,
63,
12334,
70,
29,
549,
304,
267,
312,
275,
481,
14,
5598,
18,
68,
8,
1210,
12,
1862,
459,
5598,
16,
14,
3463,
995,
1862,
459,
5598,
16,
14,
8160,
995,
499,
12,
650,
9,
267,
312,
275,
481,
14,
12833,
8,
79,
9,
267,
312,
275,
481,
14,
988,
63,
2293,
18,
68,
8,
79,
12,
650,
12,
499,
12,
413,
9,
267,
312,
63,
71,
16,
275,
1572,
8,
79,
12,
1862,
12,
283,
923,
16,
297,
413,
12,
5664,
59,
16,
566,
267,
312,
63,
71,
17,
275,
1572,
8,
79,
63,
71,
16,
12,
1862,
12,
283,
923,
17,
297,
499,
12,
5664,
59,
17,
566,
267,
312,
63,
71,
18,
275,
1572,
8,
79,
63,
71,
17,
12,
1862,
12,
283,
923,
18,
297,
499,
12,
5664,
59,
18,
566,
267,
312,
63,
71,
19,
275,
1572,
8,
79,
63,
71,
18,
12,
1862,
12,
283,
923,
19,
297,
499,
12,
5664,
59,
19,
566,
267,
340,
20699,
63,
12334,
70,
26,
288,
312,
275,
481,
14,
8595,
63,
2293,
18,
68,
8,
79,
63,
71,
19,
12,
1520,
12,
413,
12,
378,
9,
288,
312,
275,
312,
14,
1345,
8,
79,
14,
890,
8,
16,
395,
446,
17,
9,
288,
312,
275,
481,
14,
6676,
8,
79,
12,
1862,
459,
3003,
14,
3463,
995,
1862,
459,
3003,
14,
8160,
1105,
267,
372,
312,
339,
372,
289,
421,
199,
533,
32612,
1322,
2480,
8,
4411,
14,
2377,
304,
339,
347,
636,
826,
721,
277,
12,
20699,
304,
267,
1613,
8,
55,
2655,
1322,
2480,
12,
291,
2843,
826,
4533,
267,
291,
14,
28624,
275,
20699,
267,
291,
14,
1162,
275,
1862,
339,
347,
7568,
8,
277,
12,
671,
304,
267,
671,
275,
289,
8,
88,
12,
291,
14,
1162,
12,
291,
14,
28624,
9,
267,
372,
671,
421,
199,
318,
20239,
28998,
1400,
8,
28624,
304,
272,
2935,
63,
992,
275,
747,
14,
515,
14,
904,
8,
12131,
20793,
1288,
1987,
29676,
15,
13062,
28998,
358,
272,
931,
63,
72,
9503,
275,
747,
14,
515,
14,
904,
8,
694,
63,
992,
12,
283,
13062,
28998,
1400,
14,
72,
9503,
358,
272,
340,
747,
14,
515,
14,
6292,
8,
515,
63,
72,
9503,
304,
267,
1862,
275,
394,
9503,
14,
912,
8,
515,
63,
72,
9503,
9,
267,
327,
3957,
2680,
6572,
370,
21416,
17198,
267,
367,
1022,
12,
86,
315,
3355,
8,
1162,
14,
1744,
5109,
288,
870,
8,
75,
12,
373,
14,
1392,
9,
288,
1862,
59,
75,
61,
275,
4905,
8,
29676,
14,
504,
63,
4714,
8,
86,
395,
5074,
63,
6017,
29,
549,
9,
272,
587,
26,
267,
747,
14,
2253,
360,
8215,
446,
80,
283,
435,
2935,
63,
992,
9,
267,
747,
14,
2253,
360,
87,
362,
1052,
446,
47,
9499,
908,
8,
1238,
63,
3603,
459,
13062,
28998,
1400,
995,
931,
63,
72,
9503,
430,
272,
289,
275,
5627,
63,
1238,
8,
1162,
9,
272,
1402,
275,
32612,
1322,
2480,
8,
28624,
9,
272,
372,
1402,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
infoxchange/lettuce
|
tests/integration/lib/Django-1.2.5/django/contrib/gis/admin/options.py
|
45
|
5095
|
from django.conf import settings
from django.contrib.admin import ModelAdmin
from django.contrib.gis.admin.widgets import OpenLayersWidget
from django.contrib.gis.gdal import OGRGeomType
from django.contrib.gis.db import models
class GeoModelAdmin(ModelAdmin):
"""
The administration options class for Geographic models. Map settings
may be overloaded from their defaults to create custom maps.
"""
# The default map settings that may be overloaded -- still subject
# to API changes.
default_lon = 0
default_lat = 0
default_zoom = 4
display_wkt = False
display_srid = False
extra_js = []
num_zoom = 18
max_zoom = False
min_zoom = False
units = False
max_resolution = False
max_extent = False
modifiable = True
mouse_position = True
scale_text = True
layerswitcher = True
scrollable = True
map_width = 600
map_height = 400
map_srid = 4326
map_template = 'gis/admin/openlayers.html'
openlayers_url = 'http://openlayers.org/api/2.8/OpenLayers.js'
point_zoom = num_zoom - 6
wms_url = 'http://labs.metacarta.com/wms/vmap0'
wms_layer = 'basic'
wms_name = 'OpenLayers WMS'
debug = False
widget = OpenLayersWidget
def _media(self):
"Injects OpenLayers JavaScript into the admin."
media = super(GeoModelAdmin, self)._media()
media.add_js([self.openlayers_url])
media.add_js(self.extra_js)
return media
media = property(_media)
def formfield_for_dbfield(self, db_field, **kwargs):
"""
Overloaded from ModelAdmin so that an OpenLayersWidget is used
for viewing/editing GeometryFields.
"""
if isinstance(db_field, models.GeometryField):
request = kwargs.pop('request', None)
# Setting the widget with the newly defined widget.
kwargs['widget'] = self.get_map_widget(db_field)
return db_field.formfield(**kwargs)
else:
return super(GeoModelAdmin, self).formfield_for_dbfield(db_field, **kwargs)
def get_map_widget(self, db_field):
"""
Returns a subclass of the OpenLayersWidget (or whatever was specified
in the `widget` attribute) using the settings from the attributes set
in this class.
"""
is_collection = db_field.geom_type in ('MULTIPOINT', 'MULTILINESTRING', 'MULTIPOLYGON', 'GEOMETRYCOLLECTION')
if is_collection:
if db_field.geom_type == 'GEOMETRYCOLLECTION': collection_type = 'Any'
else: collection_type = OGRGeomType(db_field.geom_type.replace('MULTI', ''))
else:
collection_type = 'None'
class OLMap(self.widget):
template = self.map_template
geom_type = db_field.geom_type
params = {'default_lon' : self.default_lon,
'default_lat' : self.default_lat,
'default_zoom' : self.default_zoom,
'display_wkt' : self.debug or self.display_wkt,
'geom_type' : OGRGeomType(db_field.geom_type),
'field_name' : db_field.name,
'is_collection' : is_collection,
'scrollable' : self.scrollable,
'layerswitcher' : self.layerswitcher,
'collection_type' : collection_type,
'is_linestring' : db_field.geom_type in ('LINESTRING', 'MULTILINESTRING'),
'is_polygon' : db_field.geom_type in ('POLYGON', 'MULTIPOLYGON'),
'is_point' : db_field.geom_type in ('POINT', 'MULTIPOINT'),
'num_zoom' : self.num_zoom,
'max_zoom' : self.max_zoom,
'min_zoom' : self.min_zoom,
'units' : self.units, #likely shoud get from object
'max_resolution' : self.max_resolution,
'max_extent' : self.max_extent,
'modifiable' : self.modifiable,
'mouse_position' : self.mouse_position,
'scale_text' : self.scale_text,
'map_width' : self.map_width,
'map_height' : self.map_height,
'point_zoom' : self.point_zoom,
'srid' : self.map_srid,
'display_srid' : self.display_srid,
'wms_url' : self.wms_url,
'wms_layer' : self.wms_layer,
'wms_name' : self.wms_name,
'debug' : self.debug,
}
return OLMap
from django.contrib.gis import gdal
if gdal.HAS_GDAL:
class OSMGeoAdmin(GeoModelAdmin):
map_template = 'gis/admin/osm.html'
extra_js = ['http://openstreetmap.org/openlayers/OpenStreetMap.js']
num_zoom = 20
map_srid = 900913
max_extent = '-20037508,-20037508,20037508,20037508'
max_resolution = '156543.0339'
point_zoom = num_zoom - 6
units = 'm'
|
gpl-3.0
|
[
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
2828,
14,
2113,
492,
30093,
199,
504,
1639,
14,
2828,
14,
5668,
14,
2113,
14,
8583,
492,
3232,
16862,
3339,
199,
504,
1639,
14,
2828,
14,
5668,
14,
11600,
492,
25756,
199,
504,
1639,
14,
2828,
14,
5668,
14,
697,
492,
1709,
199,
199,
533,
8875,
12976,
8,
12976,
304,
272,
408,
272,
710,
4628,
4633,
1511,
1021,
367,
8875,
9770,
1709,
14,
9672,
2202,
272,
1443,
506,
1806,
4591,
687,
3932,
4243,
370,
1218,
3537,
9033,
14,
272,
408,
272,
327,
710,
849,
2341,
2202,
626,
1443,
506,
1806,
4591,
1553,
5139,
5420,
272,
327,
370,
3261,
4493,
14,
272,
849,
63,
5298,
275,
378,
272,
849,
63,
4452,
275,
378,
272,
849,
63,
10598,
275,
841,
272,
2929,
63,
11412,
275,
756,
272,
2929,
63,
10498,
275,
756,
272,
2402,
63,
3596,
275,
942,
272,
1967,
63,
10598,
275,
6155,
272,
1390,
63,
10598,
275,
756,
272,
1748,
63,
10598,
275,
756,
272,
6204,
275,
756,
272,
1390,
63,
12588,
275,
756,
272,
1390,
63,
11599,
275,
756,
272,
1953,
24183,
275,
715,
272,
12817,
63,
3124,
275,
715,
272,
4666,
63,
505,
275,
715,
272,
9393,
3111,
281,
275,
715,
272,
13704,
461,
275,
715,
272,
2341,
63,
2063,
275,
11624,
272,
2341,
63,
3333,
275,
8290,
272,
2341,
63,
10498,
275,
26719,
272,
2341,
63,
1160,
275,
283,
5668,
15,
2113,
15,
1490,
4359,
14,
1360,
7,
272,
1551,
4359,
63,
633,
275,
283,
1014,
921,
1490,
4359,
14,
1308,
15,
1246,
15,
18,
14,
24,
15,
4299,
16862,
14,
3596,
7,
272,
2376,
63,
10598,
275,
1967,
63,
10598,
446,
1227,
272,
336,
706,
63,
633,
275,
283,
1014,
921,
76,
2101,
14,
2024,
7007,
502,
14,
957,
15,
30297,
15,
86,
1130,
16,
7,
272,
336,
706,
63,
1897,
275,
283,
4316,
7,
272,
336,
706,
63,
354,
275,
283,
4299,
16862,
644,
3053,
7,
272,
3105,
275,
756,
272,
3938,
275,
3232,
16862,
3339,
339,
347,
485,
4603,
8,
277,
304,
267,
298,
607,
963,
83,
3232,
16862,
15250,
1901,
314,
4628,
2122,
267,
5898,
275,
1613,
8,
10748,
12976,
12,
291,
10445,
4603,
342,
267,
5898,
14,
525,
63,
3596,
779,
277,
14,
1490,
4359,
63,
633,
566,
267,
5898,
14,
525,
63,
3596,
8,
277,
14,
2911,
63,
3596,
9,
267,
372,
5898,
272,
5898,
275,
3324,
1547,
4603,
9,
339,
347,
21388,
63,
509,
63,
697,
698,
8,
277,
12,
1592,
63,
698,
12,
1011,
958,
304,
267,
408,
267,
7259,
4591,
687,
30093,
880,
626,
376,
3232,
16862,
3339,
365,
1202,
267,
367,
2455,
316,
15,
27057,
10579,
7304,
14,
267,
408,
267,
340,
1228,
8,
697,
63,
698,
12,
1709,
14,
6831,
792,
304,
288,
1056,
275,
2074,
14,
1935,
360,
1069,
297,
488,
9,
288,
327,
13510,
314,
3938,
543,
314,
13903,
3247,
3938,
14,
288,
2074,
459,
3440,
418,
275,
291,
14,
362,
63,
1130,
63,
3440,
8,
697,
63,
698,
9,
288,
372,
1592,
63,
698,
14,
20015,
3682,
958,
9,
267,
587,
26,
288,
372,
1613,
8,
10748,
12976,
12,
291,
680,
20015,
63,
509,
63,
697,
698,
8,
697,
63,
698,
12,
1011,
958,
9,
339,
347,
664,
63,
1130,
63,
3440,
8,
277,
12,
1592,
63,
698,
304,
267,
408,
267,
1803,
282,
5516,
402,
314,
3232,
16862,
3339,
334,
269,
15685,
1990,
2013,
267,
315,
314,
658,
3440,
64,
2225,
9,
1808,
314,
2202,
687,
314,
3004,
663,
267,
315,
642,
1021,
14,
267,
408,
267,
365,
63,
3627,
275,
1592,
63,
698,
14,
6481,
63,
466,
315,
661,
21389,
7217,
297,
283,
15635,
568,
29780,
297,
283,
21389,
23602,
297,
283,
28472,
29374,
358,
267,
340,
365,
63,
3627,
26,
288,
340,
1592,
63,
698,
14,
6481,
63,
466,
508,
283,
28472,
29374,
356,
3245,
63,
466,
275,
283,
9874,
7,
288,
587,
26,
3245,
63,
466,
275,
25756,
8,
697,
63,
698,
14,
6481,
63,
466,
14,
1814,
360,
21389,
297,
12381,
267,
587,
26,
288,
3245,
63,
466,
275,
283,
403,
7,
398,
1021,
593,
44,
2956,
8,
277,
14,
3440,
304,
288,
1978,
275,
291,
14,
1130,
63,
1160,
288,
9671,
63,
466,
275,
1592,
63,
698,
14,
6481,
63,
466,
288,
1862,
275,
791,
885,
63,
5298,
7,
520,
291,
14,
885,
63,
5298,
12,
1993,
283,
885,
63,
4452,
7,
520,
291,
14,
885,
63,
4452,
12,
1993,
283,
885,
63,
10598,
7,
520,
291,
14,
885,
63,
10598,
12,
1993,
283,
2918,
63,
11412,
7,
520,
291,
14,
1757,
503,
291,
14,
2918,
63,
11412,
12,
1993,
283,
6481,
63,
466,
7,
520,
25756,
8,
697,
63,
698,
14,
6481,
63,
466,
395,
1993,
283,
698,
63,
354,
7,
520,
1592,
63,
698,
14,
354,
12,
1993,
283,
374,
63,
3627,
7,
520,
365,
63,
3627,
12,
1993,
283,
6755,
461,
7,
520,
291,
14,
6755,
461,
12,
1993,
283,
4359,
3111,
281,
7,
520,
291,
14,
4359,
3111,
281,
12,
1993,
283,
3627,
63,
466,
7,
520,
3245,
63,
466,
12,
1993,
283,
374,
63,
604,
875,
7,
520,
1592,
63,
698,
14,
6481,
63,
466,
315,
661,
6143,
29780,
297,
283,
15635,
568,
29780,
659,
1993,
283,
374,
63,
16295,
7,
520,
1592,
63,
698,
14,
6481,
63,
466,
315,
661,
23602,
297,
283,
21389,
23602,
659,
1993,
283,
374,
63,
1403,
7,
520,
1592,
63,
698,
14,
6481,
63,
466,
315,
661,
7217,
297,
283,
21389,
7217,
659,
1993,
283,
1507,
63,
10598,
7,
520,
291,
14,
1507,
63,
10598,
12,
1993,
283,
988,
63,
10598,
7,
520,
291,
14,
988,
63,
10598,
12,
1993,
283,
827,
63,
10598,
7,
520,
291,
14,
827,
63,
10598,
12,
1993,
283,
5260,
7,
520,
291,
14,
5260,
12,
327,
24227,
930,
1181,
664,
687,
909,
1993,
283,
988,
63,
12588,
7,
520,
291,
14,
988,
63,
12588,
12,
1993,
283,
988,
63,
11599,
7,
520,
291,
14,
988,
63,
11599,
12,
1993,
283,
3729,
24183,
7,
520,
291,
14,
3729,
24183,
12,
1993,
283,
10544,
63,
3124,
7,
520,
291,
14,
10544,
63,
3124,
12,
1993,
283,
3467,
63,
505,
7,
520,
291,
14,
3467,
63,
505
] |
[
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
2828,
14,
2113,
492,
30093,
199,
504,
1639,
14,
2828,
14,
5668,
14,
2113,
14,
8583,
492,
3232,
16862,
3339,
199,
504,
1639,
14,
2828,
14,
5668,
14,
11600,
492,
25756,
199,
504,
1639,
14,
2828,
14,
5668,
14,
697,
492,
1709,
199,
199,
533,
8875,
12976,
8,
12976,
304,
272,
408,
272,
710,
4628,
4633,
1511,
1021,
367,
8875,
9770,
1709,
14,
9672,
2202,
272,
1443,
506,
1806,
4591,
687,
3932,
4243,
370,
1218,
3537,
9033,
14,
272,
408,
272,
327,
710,
849,
2341,
2202,
626,
1443,
506,
1806,
4591,
1553,
5139,
5420,
272,
327,
370,
3261,
4493,
14,
272,
849,
63,
5298,
275,
378,
272,
849,
63,
4452,
275,
378,
272,
849,
63,
10598,
275,
841,
272,
2929,
63,
11412,
275,
756,
272,
2929,
63,
10498,
275,
756,
272,
2402,
63,
3596,
275,
942,
272,
1967,
63,
10598,
275,
6155,
272,
1390,
63,
10598,
275,
756,
272,
1748,
63,
10598,
275,
756,
272,
6204,
275,
756,
272,
1390,
63,
12588,
275,
756,
272,
1390,
63,
11599,
275,
756,
272,
1953,
24183,
275,
715,
272,
12817,
63,
3124,
275,
715,
272,
4666,
63,
505,
275,
715,
272,
9393,
3111,
281,
275,
715,
272,
13704,
461,
275,
715,
272,
2341,
63,
2063,
275,
11624,
272,
2341,
63,
3333,
275,
8290,
272,
2341,
63,
10498,
275,
26719,
272,
2341,
63,
1160,
275,
283,
5668,
15,
2113,
15,
1490,
4359,
14,
1360,
7,
272,
1551,
4359,
63,
633,
275,
283,
1014,
921,
1490,
4359,
14,
1308,
15,
1246,
15,
18,
14,
24,
15,
4299,
16862,
14,
3596,
7,
272,
2376,
63,
10598,
275,
1967,
63,
10598,
446,
1227,
272,
336,
706,
63,
633,
275,
283,
1014,
921,
76,
2101,
14,
2024,
7007,
502,
14,
957,
15,
30297,
15,
86,
1130,
16,
7,
272,
336,
706,
63,
1897,
275,
283,
4316,
7,
272,
336,
706,
63,
354,
275,
283,
4299,
16862,
644,
3053,
7,
272,
3105,
275,
756,
272,
3938,
275,
3232,
16862,
3339,
339,
347,
485,
4603,
8,
277,
304,
267,
298,
607,
963,
83,
3232,
16862,
15250,
1901,
314,
4628,
2122,
267,
5898,
275,
1613,
8,
10748,
12976,
12,
291,
10445,
4603,
342,
267,
5898,
14,
525,
63,
3596,
779,
277,
14,
1490,
4359,
63,
633,
566,
267,
5898,
14,
525,
63,
3596,
8,
277,
14,
2911,
63,
3596,
9,
267,
372,
5898,
272,
5898,
275,
3324,
1547,
4603,
9,
339,
347,
21388,
63,
509,
63,
697,
698,
8,
277,
12,
1592,
63,
698,
12,
1011,
958,
304,
267,
408,
267,
7259,
4591,
687,
30093,
880,
626,
376,
3232,
16862,
3339,
365,
1202,
267,
367,
2455,
316,
15,
27057,
10579,
7304,
14,
267,
408,
267,
340,
1228,
8,
697,
63,
698,
12,
1709,
14,
6831,
792,
304,
288,
1056,
275,
2074,
14,
1935,
360,
1069,
297,
488,
9,
288,
327,
13510,
314,
3938,
543,
314,
13903,
3247,
3938,
14,
288,
2074,
459,
3440,
418,
275,
291,
14,
362,
63,
1130,
63,
3440,
8,
697,
63,
698,
9,
288,
372,
1592,
63,
698,
14,
20015,
3682,
958,
9,
267,
587,
26,
288,
372,
1613,
8,
10748,
12976,
12,
291,
680,
20015,
63,
509,
63,
697,
698,
8,
697,
63,
698,
12,
1011,
958,
9,
339,
347,
664,
63,
1130,
63,
3440,
8,
277,
12,
1592,
63,
698,
304,
267,
408,
267,
1803,
282,
5516,
402,
314,
3232,
16862,
3339,
334,
269,
15685,
1990,
2013,
267,
315,
314,
658,
3440,
64,
2225,
9,
1808,
314,
2202,
687,
314,
3004,
663,
267,
315,
642,
1021,
14,
267,
408,
267,
365,
63,
3627,
275,
1592,
63,
698,
14,
6481,
63,
466,
315,
661,
21389,
7217,
297,
283,
15635,
568,
29780,
297,
283,
21389,
23602,
297,
283,
28472,
29374,
358,
267,
340,
365,
63,
3627,
26,
288,
340,
1592,
63,
698,
14,
6481,
63,
466,
508,
283,
28472,
29374,
356,
3245,
63,
466,
275,
283,
9874,
7,
288,
587,
26,
3245,
63,
466,
275,
25756,
8,
697,
63,
698,
14,
6481,
63,
466,
14,
1814,
360,
21389,
297,
12381,
267,
587,
26,
288,
3245,
63,
466,
275,
283,
403,
7,
398,
1021,
593,
44,
2956,
8,
277,
14,
3440,
304,
288,
1978,
275,
291,
14,
1130,
63,
1160,
288,
9671,
63,
466,
275,
1592,
63,
698,
14,
6481,
63,
466,
288,
1862,
275,
791,
885,
63,
5298,
7,
520,
291,
14,
885,
63,
5298,
12,
1993,
283,
885,
63,
4452,
7,
520,
291,
14,
885,
63,
4452,
12,
1993,
283,
885,
63,
10598,
7,
520,
291,
14,
885,
63,
10598,
12,
1993,
283,
2918,
63,
11412,
7,
520,
291,
14,
1757,
503,
291,
14,
2918,
63,
11412,
12,
1993,
283,
6481,
63,
466,
7,
520,
25756,
8,
697,
63,
698,
14,
6481,
63,
466,
395,
1993,
283,
698,
63,
354,
7,
520,
1592,
63,
698,
14,
354,
12,
1993,
283,
374,
63,
3627,
7,
520,
365,
63,
3627,
12,
1993,
283,
6755,
461,
7,
520,
291,
14,
6755,
461,
12,
1993,
283,
4359,
3111,
281,
7,
520,
291,
14,
4359,
3111,
281,
12,
1993,
283,
3627,
63,
466,
7,
520,
3245,
63,
466,
12,
1993,
283,
374,
63,
604,
875,
7,
520,
1592,
63,
698,
14,
6481,
63,
466,
315,
661,
6143,
29780,
297,
283,
15635,
568,
29780,
659,
1993,
283,
374,
63,
16295,
7,
520,
1592,
63,
698,
14,
6481,
63,
466,
315,
661,
23602,
297,
283,
21389,
23602,
659,
1993,
283,
374,
63,
1403,
7,
520,
1592,
63,
698,
14,
6481,
63,
466,
315,
661,
7217,
297,
283,
21389,
7217,
659,
1993,
283,
1507,
63,
10598,
7,
520,
291,
14,
1507,
63,
10598,
12,
1993,
283,
988,
63,
10598,
7,
520,
291,
14,
988,
63,
10598,
12,
1993,
283,
827,
63,
10598,
7,
520,
291,
14,
827,
63,
10598,
12,
1993,
283,
5260,
7,
520,
291,
14,
5260,
12,
327,
24227,
930,
1181,
664,
687,
909,
1993,
283,
988,
63,
12588,
7,
520,
291,
14,
988,
63,
12588,
12,
1993,
283,
988,
63,
11599,
7,
520,
291,
14,
988,
63,
11599,
12,
1993,
283,
3729,
24183,
7,
520,
291,
14,
3729,
24183,
12,
1993,
283,
10544,
63,
3124,
7,
520,
291,
14,
10544,
63,
3124,
12,
1993,
283,
3467,
63,
505,
7,
520,
291,
14,
3467,
63,
505,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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|
# -*- test-case-name: twisted.trial._dist.test.test_workerreporter -*-
#
# Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.
"""
Test reporter forwarding test results over trial distributed AMP commands.
@since: 12.3
"""
from twisted.python.failure import Failure
from twisted.python.reflect import qual
from twisted.trial.reporter import TestResult
from twisted.trial._dist import managercommands
class WorkerReporter(TestResult):
"""
Reporter for trial's distributed workers. We send things not through a
stream, but through an C{AMP} protocol's C{callRemote} method.
"""
def __init__(self, ampProtocol):
"""
@param ampProtocol: The communication channel with the trial
distributed manager which collects all test results.
@type ampProtocol: C{AMP}
"""
super(WorkerReporter, self).__init__()
self.ampProtocol = ampProtocol
def _getFailure(self, error):
"""
Convert a C{sys.exc_info()}-style tuple to a L{Failure}, if necessary.
"""
if isinstance(error, tuple):
return Failure(error[1], error[0], error[2])
return error
def _getFrames(self, failure):
"""
Extract frames from a C{Failure} instance.
"""
frames = []
for frame in failure.frames:
frames.extend([frame[0], frame[1], str(frame[2])])
return frames
def addSuccess(self, test):
"""
Send a success over.
"""
super(WorkerReporter, self).addSuccess(test)
self.ampProtocol.callRemote(managercommands.AddSuccess,
testName=test.id())
def addError(self, test, error):
"""
Send an error over.
"""
super(WorkerReporter, self).addError(test, error)
failure = self._getFailure(error)
frames = self._getFrames(failure)
self.ampProtocol.callRemote(managercommands.AddError,
testName=test.id(),
error=failure.getErrorMessage(),
errorClass=qual(failure.type),
frames=frames)
def addFailure(self, test, fail):
"""
Send a Failure over.
"""
super(WorkerReporter, self).addFailure(test, fail)
failure = self._getFailure(fail)
frames = self._getFrames(failure)
self.ampProtocol.callRemote(managercommands.AddFailure,
testName=test.id(),
fail=failure.getErrorMessage(),
failClass=qual(failure.type),
frames=frames)
def addSkip(self, test, reason):
"""
Send a skip over.
"""
super(WorkerReporter, self).addSkip(test, reason)
self.ampProtocol.callRemote(managercommands.AddSkip,
testName=test.id(), reason=str(reason))
def addExpectedFailure(self, test, error, todo):
"""
Send an expected failure over.
"""
super(WorkerReporter, self).addExpectedFailure(test, error, todo)
self.ampProtocol.callRemote(managercommands.AddExpectedFailure,
testName=test.id(),
error=error.getErrorMessage(),
todo=todo.reason)
def addUnexpectedSuccess(self, test, todo):
"""
Send an unexpected success over.
"""
super(WorkerReporter, self).addUnexpectedSuccess(test, todo)
self.ampProtocol.callRemote(managercommands.AddUnexpectedSuccess,
testName=test.id(), todo=todo.reason)
def printSummary(self):
"""
I{Don't} print a summary
"""
|
gpl-3.0
|
[
3,
1882,
511,
13,
2546,
13,
354,
26,
7390,
14,
14443,
423,
2686,
14,
396,
14,
396,
63,
6599,
12222,
1882,
199,
3,
199,
3,
1898,
334,
67,
9,
17078,
8449,
26640,
14,
199,
3,
1666,
5113,
367,
2436,
14,
199,
199,
624,
199,
774,
17663,
24119,
511,
2058,
1806,
16324,
1854,
25986,
3718,
14,
199,
199,
32,
8585,
26,
3144,
14,
19,
199,
624,
199,
199,
504,
7390,
14,
1548,
14,
5328,
492,
20367,
199,
504,
7390,
14,
1548,
14,
21963,
492,
6420,
199,
504,
7390,
14,
14443,
14,
12222,
492,
23795,
199,
504,
7390,
14,
14443,
423,
2686,
492,
5256,
4405,
4388,
199,
533,
23886,
15891,
8,
13120,
304,
272,
408,
272,
23786,
367,
16324,
1159,
1854,
14123,
14,
2136,
3222,
7645,
440,
4012,
282,
272,
2547,
12,
1325,
4012,
376,
445,
91,
7089,
93,
4113,
1159,
445,
91,
1250,
6713,
93,
1083,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
15204,
3658,
304,
267,
408,
267,
768,
635,
15204,
3658,
26,
710,
23506,
3623,
543,
314,
16324,
288,
1854,
5256,
1314,
8775,
83,
1006,
511,
2058,
14,
267,
768,
466,
15204,
3658,
26,
445,
91,
7089,
93,
267,
408,
267,
1613,
8,
12678,
15891,
12,
291,
2843,
826,
4533,
267,
291,
14,
5282,
3658,
275,
15204,
3658,
2378,
347,
485,
362,
6782,
8,
277,
12,
1125,
304,
267,
408,
267,
7905,
282,
445,
91,
1274,
14,
2804,
63,
815,
12737,
13,
2487,
2008,
370,
282,
491,
91,
6782,
1386,
340,
5784,
14,
267,
408,
267,
340,
1228,
8,
705,
12,
2008,
304,
288,
372,
20367,
8,
705,
59,
17,
467,
1125,
59,
16,
467,
1125,
59,
18,
566,
267,
372,
1125,
2378,
347,
485,
362,
22024,
8,
277,
12,
5988,
304,
267,
408,
267,
12892,
11223,
687,
282,
445,
91,
6782,
93,
1256,
14,
267,
408,
267,
11223,
275,
942,
267,
367,
2787,
315,
5988,
14,
8444,
26,
288,
11223,
14,
2880,
779,
1943,
59,
16,
467,
2787,
59,
17,
467,
620,
8,
1943,
59,
18,
24310,
267,
372,
11223,
2378,
347,
1050,
8300,
8,
277,
12,
511,
304,
267,
408,
267,
10217,
282,
3182,
1806,
14,
267,
408,
267,
1613,
8,
12678,
15891,
12,
291,
680,
525,
8300,
8,
396,
9,
267,
291,
14,
5282,
3658,
14,
1250,
6713,
8,
2609,
4405,
14,
1123,
8300,
12,
2511,
511,
985,
29,
396,
14,
344,
1012,
2378,
347,
1050,
547,
8,
277,
12,
511,
12,
1125,
304,
267,
408,
267,
10217,
376,
1125,
1806,
14,
267,
408,
267,
1613,
8,
12678,
15891,
12,
291,
680,
30787,
8,
396,
12,
1125,
9,
267,
5988,
275,
291,
423,
362,
6782,
8,
705,
9,
267,
11223,
275,
291,
423,
362,
22024,
8,
5328,
9,
267,
291,
14,
5282,
3658,
14,
1250,
6713,
8,
2609,
4405,
14,
1123,
547,
12,
2511,
511,
985,
29,
396,
14,
344,
1062,
2511,
1125,
29,
5328,
14,
362,
547,
2209,
1062,
2511,
1125,
2543,
29,
537,
8,
5328,
14,
466,
395,
2511,
11223,
29,
8444,
9,
2378,
347,
1050,
6782,
8,
277,
12,
511,
12,
2449,
304,
267,
408,
267,
10217,
282,
20367,
1806,
14,
267,
408,
267,
1613,
8,
12678,
15891,
12,
291,
680,
525,
6782,
8,
396,
12,
2449,
9,
267,
5988,
275,
291,
423,
362,
6782,
8,
1633,
9,
267,
11223,
275,
291,
423,
362,
22024,
8,
5328,
9,
267,
291,
14,
5282,
3658,
14,
1250,
6713,
8,
2609,
4405,
14,
1123,
6782,
12,
2511,
511,
985,
29,
396,
14,
344,
1062,
2511,
2449,
29,
5328,
14,
362,
547,
2209,
1062,
2511,
2449,
2543,
29,
537,
8,
5328,
14,
466,
395,
2511,
11223,
29,
8444,
9,
2378,
347,
1050,
7738,
8,
277,
12,
511,
12,
4499,
304,
267,
408,
267,
10217,
282,
3372,
1806,
14,
267,
408,
267,
1613,
8,
12678,
15891,
12,
291,
680,
525,
7738,
8,
396,
12,
4499,
9,
267,
291,
14,
5282,
3658,
14,
1250,
6713,
8,
2609,
4405,
14,
1123,
7738,
12,
2511,
511,
985,
29,
396,
14,
344,
1062,
4499,
29,
495,
8,
5764,
430,
2378,
347,
1050,
6964,
6782,
8,
277,
12,
511,
12,
1125,
12,
11386,
304,
267,
408,
267,
10217,
376,
1420,
5988,
1806,
14,
267,
408,
267,
1613,
8,
12678,
15891,
12,
291,
680,
525,
6964,
6782,
8,
396,
12,
1125,
12,
11386,
9,
267,
291,
14,
5282,
3658,
14,
1250,
6713,
8,
2609,
4405,
14,
1123,
6964,
6782,
12,
2511,
511,
985,
29,
396,
14,
344,
1062,
2511,
1125,
29,
705,
14,
362,
547,
2209,
1062,
2511,
11386,
29,
11396,
14,
5764,
9,
2378,
347,
1050,
8708,
8300,
8,
277,
12,
511,
12,
11386,
304,
267,
408,
267,
10217,
376,
10537,
3182,
1806,
14,
267,
408,
267,
1613,
8,
12678,
15891,
12,
291,
680,
525,
8708,
8300,
8,
396,
12,
11386,
9,
267,
291,
14,
5282,
3658,
14,
1250,
6713,
8,
2609,
4405,
14,
1123,
8708,
8300,
12,
2511,
511,
985,
29,
396,
14,
344,
1062,
11386,
29,
11396,
14,
5764,
9,
2378,
347,
870,
10407,
8,
277,
304,
267,
408,
267,
473,
91,
16932,
1133,
93,
870,
282,
6212,
267,
408,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
511,
13,
2546,
13,
354,
26,
7390,
14,
14443,
423,
2686,
14,
396,
14,
396,
63,
6599,
12222,
1882,
199,
3,
199,
3,
1898,
334,
67,
9,
17078,
8449,
26640,
14,
199,
3,
1666,
5113,
367,
2436,
14,
199,
199,
624,
199,
774,
17663,
24119,
511,
2058,
1806,
16324,
1854,
25986,
3718,
14,
199,
199,
32,
8585,
26,
3144,
14,
19,
199,
624,
199,
199,
504,
7390,
14,
1548,
14,
5328,
492,
20367,
199,
504,
7390,
14,
1548,
14,
21963,
492,
6420,
199,
504,
7390,
14,
14443,
14,
12222,
492,
23795,
199,
504,
7390,
14,
14443,
423,
2686,
492,
5256,
4405,
4388,
199,
533,
23886,
15891,
8,
13120,
304,
272,
408,
272,
23786,
367,
16324,
1159,
1854,
14123,
14,
2136,
3222,
7645,
440,
4012,
282,
272,
2547,
12,
1325,
4012,
376,
445,
91,
7089,
93,
4113,
1159,
445,
91,
1250,
6713,
93,
1083,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
15204,
3658,
304,
267,
408,
267,
768,
635,
15204,
3658,
26,
710,
23506,
3623,
543,
314,
16324,
288,
1854,
5256,
1314,
8775,
83,
1006,
511,
2058,
14,
267,
768,
466,
15204,
3658,
26,
445,
91,
7089,
93,
267,
408,
267,
1613,
8,
12678,
15891,
12,
291,
2843,
826,
4533,
267,
291,
14,
5282,
3658,
275,
15204,
3658,
2378,
347,
485,
362,
6782,
8,
277,
12,
1125,
304,
267,
408,
267,
7905,
282,
445,
91,
1274,
14,
2804,
63,
815,
12737,
13,
2487,
2008,
370,
282,
491,
91,
6782,
1386,
340,
5784,
14,
267,
408,
267,
340,
1228,
8,
705,
12,
2008,
304,
288,
372,
20367,
8,
705,
59,
17,
467,
1125,
59,
16,
467,
1125,
59,
18,
566,
267,
372,
1125,
2378,
347,
485,
362,
22024,
8,
277,
12,
5988,
304,
267,
408,
267,
12892,
11223,
687,
282,
445,
91,
6782,
93,
1256,
14,
267,
408,
267,
11223,
275,
942,
267,
367,
2787,
315,
5988,
14,
8444,
26,
288,
11223,
14,
2880,
779,
1943,
59,
16,
467,
2787,
59,
17,
467,
620,
8,
1943,
59,
18,
24310,
267,
372,
11223,
2378,
347,
1050,
8300,
8,
277,
12,
511,
304,
267,
408,
267,
10217,
282,
3182,
1806,
14,
267,
408,
267,
1613,
8,
12678,
15891,
12,
291,
680,
525,
8300,
8,
396,
9,
267,
291,
14,
5282,
3658,
14,
1250,
6713,
8,
2609,
4405,
14,
1123,
8300,
12,
2511,
511,
985,
29,
396,
14,
344,
1012,
2378,
347,
1050,
547,
8,
277,
12,
511,
12,
1125,
304,
267,
408,
267,
10217,
376,
1125,
1806,
14,
267,
408,
267,
1613,
8,
12678,
15891,
12,
291,
680,
30787,
8,
396,
12,
1125,
9,
267,
5988,
275,
291,
423,
362,
6782,
8,
705,
9,
267,
11223,
275,
291,
423,
362,
22024,
8,
5328,
9,
267,
291,
14,
5282,
3658,
14,
1250,
6713,
8,
2609,
4405,
14,
1123,
547,
12,
2511,
511,
985,
29,
396,
14,
344,
1062,
2511,
1125,
29,
5328,
14,
362,
547,
2209,
1062,
2511,
1125,
2543,
29,
537,
8,
5328,
14,
466,
395,
2511,
11223,
29,
8444,
9,
2378,
347,
1050,
6782,
8,
277,
12,
511,
12,
2449,
304,
267,
408,
267,
10217,
282,
20367,
1806,
14,
267,
408,
267,
1613,
8,
12678,
15891,
12,
291,
680,
525,
6782,
8,
396,
12,
2449,
9,
267,
5988,
275,
291,
423,
362,
6782,
8,
1633,
9,
267,
11223,
275,
291,
423,
362,
22024,
8,
5328,
9,
267,
291,
14,
5282,
3658,
14,
1250,
6713,
8,
2609,
4405,
14,
1123,
6782,
12,
2511,
511,
985,
29,
396,
14,
344,
1062,
2511,
2449,
29,
5328,
14,
362,
547,
2209,
1062,
2511,
2449,
2543,
29,
537,
8,
5328,
14,
466,
395,
2511,
11223,
29,
8444,
9,
2378,
347,
1050,
7738,
8,
277,
12,
511,
12,
4499,
304,
267,
408,
267,
10217,
282,
3372,
1806,
14,
267,
408,
267,
1613,
8,
12678,
15891,
12,
291,
680,
525,
7738,
8,
396,
12,
4499,
9,
267,
291,
14,
5282,
3658,
14,
1250,
6713,
8,
2609,
4405,
14,
1123,
7738,
12,
2511,
511,
985,
29,
396,
14,
344,
1062,
4499,
29,
495,
8,
5764,
430,
2378,
347,
1050,
6964,
6782,
8,
277,
12,
511,
12,
1125,
12,
11386,
304,
267,
408,
267,
10217,
376,
1420,
5988,
1806,
14,
267,
408,
267,
1613,
8,
12678,
15891,
12,
291,
680,
525,
6964,
6782,
8,
396,
12,
1125,
12,
11386,
9,
267,
291,
14,
5282,
3658,
14,
1250,
6713,
8,
2609,
4405,
14,
1123,
6964,
6782,
12,
2511,
511,
985,
29,
396,
14,
344,
1062,
2511,
1125,
29,
705,
14,
362,
547,
2209,
1062,
2511,
11386,
29,
11396,
14,
5764,
9,
2378,
347,
1050,
8708,
8300,
8,
277,
12,
511,
12,
11386,
304,
267,
408,
267,
10217,
376,
10537,
3182,
1806,
14,
267,
408,
267,
1613,
8,
12678,
15891,
12,
291,
680,
525,
8708,
8300,
8,
396,
12,
11386,
9,
267,
291,
14,
5282,
3658,
14,
1250,
6713,
8,
2609,
4405,
14,
1123,
8708,
8300,
12,
2511,
511,
985,
29,
396,
14,
344,
1062,
11386,
29,
11396,
14,
5764,
9,
2378,
347,
870,
10407,
8,
277,
304,
267,
408,
267,
473,
91,
16932,
1133,
93,
870,
282,
6212,
267,
408,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
toenuff/treadmill
|
tests/services/cgroup_service_test.py
|
1
|
6103
|
"""
Unit test for cgroup_service - Treadmill cgroup service
"""
import os
import tempfile
import unittest
import select
import shutil
# Disable W0611: Unused import
import tests.treadmill_test_deps # pylint: disable=W0611
import mock
import treadmill
from treadmill.services import cgroup_service
class CGroupServiceTest(unittest.TestCase):
"""Unit tests for the cgroup service implementation.
"""
def setUp(self):
self.root = tempfile.mkdtemp()
self.cgroup_svc = os.path.join(self.root, 'cgroup_svc')
self.running = os.path.join(self.root, 'running')
def tearDown(self):
if self.root and os.path.isdir(self.root):
shutil.rmtree(self.root)
def test_initialize(self):
"""Test service initialization.
"""
svc = cgroup_service.CgroupResourceService(self.running)
svc.initialize(self.cgroup_svc)
def test_report_status(self):
"""Test processing of status request.
"""
svc = cgroup_service.CgroupResourceService(self.running)
status = svc.report_status()
self.assertEqual(
status,
{'ready': True}
)
def test_event_handlers(self):
"""Test event_handlers request.
"""
svc = cgroup_service.CgroupResourceService(self.running)
handlers = svc.event_handlers()
self.assertEqual(
handlers,
[]
)
@mock.patch('treadmill.cgroups.create', mock.Mock())
@mock.patch('treadmill.cgroups.get_value', mock.Mock(return_value=10000))
@mock.patch('treadmill.cgroups.join', mock.Mock())
@mock.patch('treadmill.cgroups.set_value', mock.Mock())
@mock.patch('treadmill.services.cgroup_service.CgroupResourceService.'
'_register_oom_handler', mock.Mock())
def test_on_create_request(self):
"""Test processing of a cgroups create request.
"""
# Access to a protected member _register_oom_handler of a client class
# pylint: disable=W0212
svc = cgroup_service.CgroupResourceService(self.running)
request = {
'memory': '100M',
'cpu': '100%',
}
request_id = 'myproid.test-0-ID1234'
svc.on_create_request(request_id, request)
cgrp = os.path.join('treadmill/apps', request_id)
svc._register_oom_handler.assert_called_with(cgrp, request_id)
treadmill.cgroups.create.assert_has_calls(
[
mock.call(ss, cgrp)
for ss in ['cpu', 'cpuacct', 'memory', 'blkio']
]
)
# Memory calculation:
#
# (demand * virtual cpu bmips / total bmips) * treadmill.cpu.shares
# (100% * 5000 / (24000 * 0.9 ) * 10000) = 2314
treadmill.cgroups.set_value.assert_has_calls([
mock.call('blkio', cgrp, 'blkio.weight', 100),
mock.call('memory', cgrp, 'memory.soft_limit_in_bytes', '100M'),
mock.call('memory', cgrp, 'memory.limit_in_bytes', '100M'),
mock.call('memory', cgrp, 'memory.memsw.limit_in_bytes', '100M'),
mock.call('cpu', cgrp, 'cpu.shares',
treadmill.sysinfo.BMIPS_PER_CPU)
])
@mock.patch('treadmill.cgroups.delete', mock.Mock())
@mock.patch('treadmill.services.cgroup_service.CgroupResourceService.'
'_unregister_oom_handler', mock.Mock())
def test_on_delete_request(self):
"""Test processing of a cgroups delete request.
"""
# Access to a protected member _unregister_oom_handler of a client
# class
# pylint: disable=W0212
svc = cgroup_service.CgroupResourceService(self.running)
request_id = 'myproid.test-0-ID1234'
svc.on_delete_request(request_id)
cgrp = os.path.join('treadmill/apps', request_id)
treadmill.cgroups.delete.assert_has_calls(
[
mock.call(ss, cgrp)
for ss in ['cpu', 'cpuacct', 'memory', 'blkio']
]
)
svc._unregister_oom_handler.assert_called_with(cgrp)
@mock.patch('treadmill.cgutils.get_memory_oom_eventfd',
mock.Mock(return_value='fake_efd'))
def test__register_oom_handler(self):
"""Test registration of OOM handler.
"""
# Access to a protected member _register_oom_handler of a client class
# pylint: disable=W0212
svc = cgroup_service.CgroupResourceService(self.running)
registered_handlers = svc.event_handlers()
self.assertNotIn(
('fake_efd', select.POLLIN, mock.ANY),
registered_handlers
)
cgrp = 'treadmill/apps/myproid.test-42-ID1234'
svc._register_oom_handler(cgrp, 'myproid.test-42-ID1234')
treadmill.cgutils.get_memory_oom_eventfd.assert_called_with(cgrp)
registered_handlers = svc.event_handlers()
self.assertIn(
('fake_efd', select.POLLIN, mock.ANY),
registered_handlers
)
@mock.patch('os.close', mock.Mock())
@mock.patch('treadmill.cgutils.get_memory_oom_eventfd',
mock.Mock(return_value='fake_efd'))
def test__unregister_oom_handler(self):
"""Test unregistration of OOM handler.
"""
# Access to a protected member _unregister_oom_handler of a client
# class
# pylint: disable=W0212
svc = cgroup_service.CgroupResourceService(self.running)
cgrp = 'treadmill/apps/myproid.test-42-ID1234'
svc._register_oom_handler(cgrp, 'myproid.test-42-ID1234')
registered_handlers = svc.event_handlers()
self.assertIn(
('fake_efd', select.POLLIN, mock.ANY),
registered_handlers
)
svc._unregister_oom_handler(cgrp)
registered_handlers = svc.event_handlers()
self.assertNotIn(
('fake_efd', select.POLLIN, mock.ANY),
registered_handlers
)
os.close.assert_called_with('fake_efd')
if __name__ == '__main__':
unittest.main()
|
apache-2.0
|
[
624,
199,
5072,
511,
367,
286,
923,
63,
1364,
446,
377,
739,
77,
778,
286,
923,
2435,
199,
624,
199,
199,
646,
747,
199,
646,
5549,
199,
646,
2882,
199,
646,
3504,
199,
646,
5145,
199,
199,
3,
17534,
644,
1690,
845,
26,
1910,
2972,
492,
199,
646,
2295,
14,
84,
739,
77,
778,
63,
396,
63,
5846,
221,
327,
4287,
26,
3507,
29,
55,
1690,
845,
199,
199,
646,
1683,
199,
199,
646,
307,
739,
77,
778,
199,
504,
307,
739,
77,
778,
14,
5950,
492,
286,
923,
63,
1364,
421,
199,
533,
445,
2448,
3167,
774,
8,
2796,
14,
1746,
304,
272,
408,
5072,
2295,
367,
314,
286,
923,
2435,
4514,
14,
272,
408,
272,
347,
3613,
8,
277,
304,
267,
291,
14,
1231,
275,
5549,
14,
11983,
342,
267,
291,
14,
24483,
63,
10599,
275,
747,
14,
515,
14,
904,
8,
277,
14,
1231,
12,
283,
24483,
63,
10599,
358,
267,
291,
14,
5720,
275,
747,
14,
515,
14,
904,
8,
277,
14,
1231,
12,
283,
5720,
358,
339,
347,
6766,
8,
277,
304,
267,
340,
291,
14,
1231,
436,
747,
14,
515,
14,
6027,
8,
277,
14,
1231,
304,
288,
5145,
14,
9242,
8,
277,
14,
1231,
9,
339,
347,
511,
63,
8489,
8,
277,
304,
267,
408,
774,
2435,
11097,
14,
267,
408,
267,
19257,
275,
286,
923,
63,
1364,
14,
35,
923,
4031,
3167,
8,
277,
14,
5720,
9,
267,
19257,
14,
8489,
8,
277,
14,
24483,
63,
10599,
9,
339,
347,
511,
63,
3070,
63,
1205,
8,
277,
304,
267,
408,
774,
6661,
402,
2004,
1056,
14,
267,
408,
267,
19257,
275,
286,
923,
63,
1364,
14,
35,
923,
4031,
3167,
8,
277,
14,
5720,
9,
267,
2004,
275,
19257,
14,
3070,
63,
1205,
342,
398,
291,
14,
629,
8,
288,
2004,
12,
288,
791,
2179,
356,
715,
93,
267,
776,
339,
347,
511,
63,
1430,
63,
5586,
8,
277,
304,
267,
408,
774,
1566,
63,
5586,
1056,
14,
267,
408,
267,
19257,
275,
286,
923,
63,
1364,
14,
35,
923,
4031,
3167,
8,
277,
14,
5720,
9,
267,
8297,
275,
19257,
14,
1430,
63,
5586,
342,
398,
291,
14,
629,
8,
288,
8297,
12,
288,
942,
267,
776,
339,
768,
1805,
14,
2068,
360,
84,
739,
77,
778,
14,
67,
2634,
14,
981,
297,
1683,
14,
3346,
1012,
272,
768,
1805,
14,
2068,
360,
84,
739,
77,
778,
14,
67,
2634,
14,
362,
63,
585,
297,
1683,
14,
3346,
8,
1107,
63,
585,
29,
9943,
430,
272,
768,
1805,
14,
2068,
360,
84,
739,
77,
778,
14,
67,
2634,
14,
904,
297,
1683,
14,
3346,
1012,
272,
768,
1805,
14,
2068,
360,
84,
739,
77,
778,
14,
67,
2634,
14,
409,
63,
585,
297,
1683,
14,
3346,
1012,
272,
768,
1805,
14,
2068,
360,
84,
739,
77,
778,
14,
5950,
14,
24483,
63,
1364,
14,
35,
923,
4031,
3167,
3530,
355,
2513,
2683,
63,
7501,
63,
2232,
297,
1683,
14,
3346,
1012,
272,
347,
511,
63,
265,
63,
981,
63,
1069,
8,
277,
304,
267,
408,
774,
6661,
402,
282,
286,
2634,
1218,
1056,
14,
267,
408,
267,
327,
11003,
370,
282,
17819,
3653,
485,
2683,
63,
7501,
63,
2232,
402,
282,
1890,
1021,
267,
327,
4287,
26,
3507,
29,
55,
996,
713,
267,
19257,
275,
286,
923,
63,
1364,
14,
35,
923,
4031,
3167,
8,
277,
14,
5720,
9,
398,
1056,
275,
469,
288,
283,
4844,
356,
283,
1960,
45,
297,
288,
283,
3541,
356,
283,
1960,
28575,
267,
789,
267,
1056,
63,
344,
275,
283,
1662,
496,
344,
14,
396,
13,
16,
13,
998,
4321,
7,
398,
19257,
14,
265,
63,
981,
63,
1069,
8,
1069,
63,
344,
12,
1056,
9,
398,
286,
12599,
275,
747,
14,
515,
14,
904,
360,
84,
739,
77,
778,
15,
5181,
297,
1056,
63,
344,
9,
267,
19257,
423,
2683,
63,
7501,
63,
2232,
14,
479,
63,
3527,
63,
1045,
8,
67,
12599,
12,
1056,
63,
344,
9,
267,
307,
739,
77,
778,
14,
67,
2634,
14,
981,
14,
479,
63,
1989,
63,
5352,
8,
288,
359,
355,
1683,
14,
1250,
8,
385,
12,
286,
12599,
9,
355,
367,
10110,
315,
788,
3541,
297,
283,
3541,
23015,
297,
283,
4844,
297,
283,
14023,
2308,
418,
288,
1622,
267,
776,
398,
327,
15825,
15232,
26,
267,
327,
267,
327,
334,
24152,
221,
627,
5791,
5033,
25425,
6142,
1182,
3141,
25425,
6142,
9,
627,
307,
739,
77,
778,
14,
3541,
14,
18318,
267,
327,
334,
1960,
5,
259,
627,
22369,
4519,
1182,
334,
1194,
1493,
627,
378,
14,
25,
776,
627,
11630,
9,
275,
6546,
1079,
267,
307,
739,
77,
778,
14,
67,
2634,
14,
409,
63,
585,
14,
479,
63,
1989,
63,
5352,
779,
288,
1683,
14,
1250,
360,
14023,
2308,
297,
286,
12599,
12,
283,
14023,
2308,
14,
3463,
297,
2948,
395,
288,
1683,
14,
1250,
360,
4844,
297,
286,
12599,
12,
283,
4844,
14,
4617,
63,
3097,
63,
262,
63,
2394,
297,
283,
1960,
45,
659,
288,
1683,
14,
1250,
360,
4844,
297,
286,
12599,
12,
283,
4844,
14,
3097,
63,
262,
63,
2394,
297,
283,
1960,
45,
659,
288,
1683,
14,
1250,
360,
4844,
297,
286,
12599,
12,
283,
4844,
14,
278,
706,
87,
14,
3097,
63,
262,
63,
2394,
297,
283,
1960,
45,
659,
288,
1683,
14,
1250,
360,
3541,
297,
286,
12599,
12,
283,
3541,
14,
18318,
297,
1993,
307,
739,
77,
778,
14,
1274,
815,
14,
15225,
12346,
63,
4227,
63,
11011,
9,
267,
4794,
339,
768,
1805,
14,
2068,
360,
84,
739,
77,
778,
14,
67,
2634,
14,
1807,
297,
1683,
14,
3346,
1012,
272,
768,
1805,
14,
2068,
360,
84,
739,
77,
778,
14,
5950,
14,
24483,
63,
1364,
14,
35,
923,
4031,
3167,
3530,
355,
2513,
18408,
63,
7501,
63,
2232,
297,
1683,
14,
3346,
1012,
272,
347,
511,
63,
265,
63,
1807,
63,
1069,
8,
277,
304,
267,
408,
774,
6661,
402,
282,
286,
2634,
3145,
1056,
14,
267,
408,
267,
327,
11003,
370,
282,
17819,
3653,
485,
18408,
63,
7501,
63,
2232,
402,
282,
1890,
267,
327,
1021,
267,
327,
4287,
26,
3507,
29,
55,
996,
713,
267,
19257,
275,
286,
923,
63,
1364,
14,
35,
923,
4031
] |
[
199,
5072,
511,
367,
286,
923,
63,
1364,
446,
377,
739,
77,
778,
286,
923,
2435,
199,
624,
199,
199,
646,
747,
199,
646,
5549,
199,
646,
2882,
199,
646,
3504,
199,
646,
5145,
199,
199,
3,
17534,
644,
1690,
845,
26,
1910,
2972,
492,
199,
646,
2295,
14,
84,
739,
77,
778,
63,
396,
63,
5846,
221,
327,
4287,
26,
3507,
29,
55,
1690,
845,
199,
199,
646,
1683,
199,
199,
646,
307,
739,
77,
778,
199,
504,
307,
739,
77,
778,
14,
5950,
492,
286,
923,
63,
1364,
421,
199,
533,
445,
2448,
3167,
774,
8,
2796,
14,
1746,
304,
272,
408,
5072,
2295,
367,
314,
286,
923,
2435,
4514,
14,
272,
408,
272,
347,
3613,
8,
277,
304,
267,
291,
14,
1231,
275,
5549,
14,
11983,
342,
267,
291,
14,
24483,
63,
10599,
275,
747,
14,
515,
14,
904,
8,
277,
14,
1231,
12,
283,
24483,
63,
10599,
358,
267,
291,
14,
5720,
275,
747,
14,
515,
14,
904,
8,
277,
14,
1231,
12,
283,
5720,
358,
339,
347,
6766,
8,
277,
304,
267,
340,
291,
14,
1231,
436,
747,
14,
515,
14,
6027,
8,
277,
14,
1231,
304,
288,
5145,
14,
9242,
8,
277,
14,
1231,
9,
339,
347,
511,
63,
8489,
8,
277,
304,
267,
408,
774,
2435,
11097,
14,
267,
408,
267,
19257,
275,
286,
923,
63,
1364,
14,
35,
923,
4031,
3167,
8,
277,
14,
5720,
9,
267,
19257,
14,
8489,
8,
277,
14,
24483,
63,
10599,
9,
339,
347,
511,
63,
3070,
63,
1205,
8,
277,
304,
267,
408,
774,
6661,
402,
2004,
1056,
14,
267,
408,
267,
19257,
275,
286,
923,
63,
1364,
14,
35,
923,
4031,
3167,
8,
277,
14,
5720,
9,
267,
2004,
275,
19257,
14,
3070,
63,
1205,
342,
398,
291,
14,
629,
8,
288,
2004,
12,
288,
791,
2179,
356,
715,
93,
267,
776,
339,
347,
511,
63,
1430,
63,
5586,
8,
277,
304,
267,
408,
774,
1566,
63,
5586,
1056,
14,
267,
408,
267,
19257,
275,
286,
923,
63,
1364,
14,
35,
923,
4031,
3167,
8,
277,
14,
5720,
9,
267,
8297,
275,
19257,
14,
1430,
63,
5586,
342,
398,
291,
14,
629,
8,
288,
8297,
12,
288,
942,
267,
776,
339,
768,
1805,
14,
2068,
360,
84,
739,
77,
778,
14,
67,
2634,
14,
981,
297,
1683,
14,
3346,
1012,
272,
768,
1805,
14,
2068,
360,
84,
739,
77,
778,
14,
67,
2634,
14,
362,
63,
585,
297,
1683,
14,
3346,
8,
1107,
63,
585,
29,
9943,
430,
272,
768,
1805,
14,
2068,
360,
84,
739,
77,
778,
14,
67,
2634,
14,
904,
297,
1683,
14,
3346,
1012,
272,
768,
1805,
14,
2068,
360,
84,
739,
77,
778,
14,
67,
2634,
14,
409,
63,
585,
297,
1683,
14,
3346,
1012,
272,
768,
1805,
14,
2068,
360,
84,
739,
77,
778,
14,
5950,
14,
24483,
63,
1364,
14,
35,
923,
4031,
3167,
3530,
355,
2513,
2683,
63,
7501,
63,
2232,
297,
1683,
14,
3346,
1012,
272,
347,
511,
63,
265,
63,
981,
63,
1069,
8,
277,
304,
267,
408,
774,
6661,
402,
282,
286,
2634,
1218,
1056,
14,
267,
408,
267,
327,
11003,
370,
282,
17819,
3653,
485,
2683,
63,
7501,
63,
2232,
402,
282,
1890,
1021,
267,
327,
4287,
26,
3507,
29,
55,
996,
713,
267,
19257,
275,
286,
923,
63,
1364,
14,
35,
923,
4031,
3167,
8,
277,
14,
5720,
9,
398,
1056,
275,
469,
288,
283,
4844,
356,
283,
1960,
45,
297,
288,
283,
3541,
356,
283,
1960,
28575,
267,
789,
267,
1056,
63,
344,
275,
283,
1662,
496,
344,
14,
396,
13,
16,
13,
998,
4321,
7,
398,
19257,
14,
265,
63,
981,
63,
1069,
8,
1069,
63,
344,
12,
1056,
9,
398,
286,
12599,
275,
747,
14,
515,
14,
904,
360,
84,
739,
77,
778,
15,
5181,
297,
1056,
63,
344,
9,
267,
19257,
423,
2683,
63,
7501,
63,
2232,
14,
479,
63,
3527,
63,
1045,
8,
67,
12599,
12,
1056,
63,
344,
9,
267,
307,
739,
77,
778,
14,
67,
2634,
14,
981,
14,
479,
63,
1989,
63,
5352,
8,
288,
359,
355,
1683,
14,
1250,
8,
385,
12,
286,
12599,
9,
355,
367,
10110,
315,
788,
3541,
297,
283,
3541,
23015,
297,
283,
4844,
297,
283,
14023,
2308,
418,
288,
1622,
267,
776,
398,
327,
15825,
15232,
26,
267,
327,
267,
327,
334,
24152,
221,
627,
5791,
5033,
25425,
6142,
1182,
3141,
25425,
6142,
9,
627,
307,
739,
77,
778,
14,
3541,
14,
18318,
267,
327,
334,
1960,
5,
259,
627,
22369,
4519,
1182,
334,
1194,
1493,
627,
378,
14,
25,
776,
627,
11630,
9,
275,
6546,
1079,
267,
307,
739,
77,
778,
14,
67,
2634,
14,
409,
63,
585,
14,
479,
63,
1989,
63,
5352,
779,
288,
1683,
14,
1250,
360,
14023,
2308,
297,
286,
12599,
12,
283,
14023,
2308,
14,
3463,
297,
2948,
395,
288,
1683,
14,
1250,
360,
4844,
297,
286,
12599,
12,
283,
4844,
14,
4617,
63,
3097,
63,
262,
63,
2394,
297,
283,
1960,
45,
659,
288,
1683,
14,
1250,
360,
4844,
297,
286,
12599,
12,
283,
4844,
14,
3097,
63,
262,
63,
2394,
297,
283,
1960,
45,
659,
288,
1683,
14,
1250,
360,
4844,
297,
286,
12599,
12,
283,
4844,
14,
278,
706,
87,
14,
3097,
63,
262,
63,
2394,
297,
283,
1960,
45,
659,
288,
1683,
14,
1250,
360,
3541,
297,
286,
12599,
12,
283,
3541,
14,
18318,
297,
1993,
307,
739,
77,
778,
14,
1274,
815,
14,
15225,
12346,
63,
4227,
63,
11011,
9,
267,
4794,
339,
768,
1805,
14,
2068,
360,
84,
739,
77,
778,
14,
67,
2634,
14,
1807,
297,
1683,
14,
3346,
1012,
272,
768,
1805,
14,
2068,
360,
84,
739,
77,
778,
14,
5950,
14,
24483,
63,
1364,
14,
35,
923,
4031,
3167,
3530,
355,
2513,
18408,
63,
7501,
63,
2232,
297,
1683,
14,
3346,
1012,
272,
347,
511,
63,
265,
63,
1807,
63,
1069,
8,
277,
304,
267,
408,
774,
6661,
402,
282,
286,
2634,
3145,
1056,
14,
267,
408,
267,
327,
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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
fast90/youtube-dl
|
youtube_dl/extractor/naver.py
|
8
|
5031
|
# encoding: utf-8
from __future__ import unicode_literals
import re
from .common import InfoExtractor
from ..utils import (
ExtractorError,
int_or_none,
update_url_query,
)
class NaverIE(InfoExtractor):
_VALID_URL = r'https?://(?:m\.)?tvcast\.naver\.com/v/(?P<id>\d+)'
_TESTS = [{
'url': 'http://tvcast.naver.com/v/81652',
'info_dict': {
'id': '81652',
'ext': 'mp4',
'title': '[9월 모의고사 해설강의][수학_김상희] 수학 A형 16~20번',
'description': '합격불변의 법칙 메가스터디 | 메가스터디 수학 김상희 선생님이 9월 모의고사 수학A형 16번에서 20번까지 해설강의를 공개합니다.',
'upload_date': '20130903',
},
}, {
'url': 'http://tvcast.naver.com/v/395837',
'md5': '638ed4c12012c458fefcddfd01f173cd',
'info_dict': {
'id': '395837',
'ext': 'mp4',
'title': '9년이 지나도 아픈 기억, 전효성의 아버지',
'description': 'md5:5bf200dcbf4b66eb1b350d1eb9c753f7',
'upload_date': '20150519',
},
'skip': 'Georestricted',
}]
def _real_extract(self, url):
video_id = self._match_id(url)
webpage = self._download_webpage(url, video_id)
m_id = re.search(r'var rmcPlayer = new nhn.rmcnmv.RMCVideoPlayer\("(.+?)", "(.+?)"',
webpage)
if m_id is None:
error = self._html_search_regex(
r'(?s)<div class="(?:nation_error|nation_box|error_box)">\s*(?:<!--.*?-->)?\s*<p class="[^"]+">(?P<msg>.+?)</p>\s*</div>',
webpage, 'error', default=None)
if error:
raise ExtractorError(error, expected=True)
raise ExtractorError('couldn\'t extract vid and key')
video_data = self._download_json(
'http://play.rmcnmv.naver.com/vod/play/v2.0/' + m_id.group(1),
video_id, query={
'key': m_id.group(2),
})
meta = video_data['meta']
title = meta['subject']
formats = []
def extract_formats(streams, stream_type, query={}):
for stream in streams:
stream_url = stream.get('source')
if not stream_url:
continue
stream_url = update_url_query(stream_url, query)
encoding_option = stream.get('encodingOption', {})
bitrate = stream.get('bitrate', {})
formats.append({
'format_id': '%s_%s' % (stream.get('type') or stream_type, encoding_option.get('id') or encoding_option.get('name')),
'url': stream_url,
'width': int_or_none(encoding_option.get('width')),
'height': int_or_none(encoding_option.get('height')),
'vbr': int_or_none(bitrate.get('video')),
'abr': int_or_none(bitrate.get('audio')),
'filesize': int_or_none(stream.get('size')),
'protocol': 'm3u8_native' if stream_type == 'HLS' else None,
})
extract_formats(video_data.get('videos', {}).get('list', []), 'H264')
for stream_set in video_data.get('streams', []):
query = {}
for param in stream_set.get('keys', []):
query[param['name']] = param['value']
stream_type = stream_set.get('type')
videos = stream_set.get('videos')
if videos:
extract_formats(videos, stream_type, query)
elif stream_type == 'HLS':
stream_url = stream_set.get('source')
if not stream_url:
continue
formats.extend(self._extract_m3u8_formats(
update_url_query(stream_url, query), video_id,
'mp4', 'm3u8_native', m3u8_id=stream_type, fatal=False))
self._sort_formats(formats)
subtitles = {}
for caption in video_data.get('captions', {}).get('list', []):
caption_url = caption.get('source')
if not caption_url:
continue
subtitles.setdefault(caption.get('language') or caption.get('locale'), []).append({
'url': caption_url,
})
upload_date = self._search_regex(
r'<span[^>]+class="date".*?(\d{4}\.\d{2}\.\d{2})',
webpage, 'upload date', fatal=False)
if upload_date:
upload_date = upload_date.replace('.', '')
return {
'id': video_id,
'title': title,
'formats': formats,
'subtitles': subtitles,
'description': self._og_search_description(webpage),
'thumbnail': meta.get('cover', {}).get('source') or self._og_search_thumbnail(webpage),
'view_count': int_or_none(meta.get('count')),
'upload_date': upload_date,
}
|
unlicense
|
[
3,
2644,
26,
2774,
13,
24,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
295,
199,
199,
504,
1275,
2330,
492,
21298,
199,
504,
2508,
1208,
492,
334,
272,
19783,
12,
272,
1109,
63,
269,
63,
3592,
12,
272,
1678,
63,
633,
63,
1131,
12,
199,
9,
421,
199,
533,
11290,
422,
4332,
8,
18283,
304,
272,
485,
5600,
63,
2632,
275,
519,
7,
2859,
24524,
77,
20316,
6993,
2931,
4537,
3540,
422,
4537,
957,
15,
86,
9448,
48,
28,
344,
3072,
68,
29600,
339,
485,
7569,
275,
8910,
267,
283,
633,
356,
283,
1014,
921,
6993,
2931,
14,
3540,
422,
14,
957,
15,
86,
15,
31104,
2528,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
31104,
2528,
297,
288,
283,
832,
356,
283,
311,
20,
297,
288,
283,
1213,
356,
6730,
25,
169,
250,
243,
16002,
104,
102,
16439,
247,
167,
112,
255,
169,
225,
106,
221,
17272,
113,
28790,
98,
22247,
244,
16439,
247,
1527,
169,
231,
247,
17272,
248,
63,
167,
118,
223,
169,
226,
224,
170,
252,
106,
61,
10148,
231,
247,
17272,
248,
437,
170,
247,
244,
3193,
94,
1165,
168,
111,
231,
297,
288,
283,
1802,
356,
283,
17272,
103,
167,
111,
103,
168,
115,
231,
168,
112,
223,
16439,
247,
16002,
111,
244,
169,
118,
248,
16002,
103,
243,
28733,
169,
233,
98,
170,
227,
109,
168,
243,
243,
1204,
16002,
103,
243,
28733,
169,
233,
98,
170,
227,
109,
168,
243,
243,
10148,
231,
247,
17272,
248,
28962,
118,
223,
169,
226,
224,
170,
252,
106,
10148,
227,
255,
169,
226,
252,
21048,
247,
31888,
1749,
169,
250,
243,
16002,
104,
102,
16439,
247,
167,
112,
255,
169,
225,
106,
10148,
231,
247,
17272,
248,
33,
170,
247,
244,
3193,
168,
111,
231,
28739,
239,
28790,
251,
3388,
168,
111,
231,
167,
118,
235,
32704,
223,
221,
17272,
113,
28790,
98,
22247,
244,
16439,
247,
168,
99,
121,
28962,
112,
114,
22247,
251,
17272,
103,
21048,
231,
31503,
3130,
288,
283,
5064,
63,
602,
356,
283,
1797,
10556,
1644,
297,
267,
1660,
272,
1660,
469,
267,
283,
633,
356,
283,
1014,
921,
6993,
2931,
14,
3540,
422,
14,
957,
15,
86,
15,
1355,
2010,
1401,
297,
267,
283,
1064,
21,
356,
283,
22,
1703,
379,
20,
67,
713,
11533,
67,
28645,
771,
3003,
617,
2592,
614,
70,
12478,
2866,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
1355,
2010,
1401,
297,
288,
283,
832,
356,
283,
311,
20,
297,
288,
283,
1213,
356,
283,
25,
168,
228,
227,
31888,
10148,
101,
223,
168,
225,
247,
168,
238,
227,
10148,
244,
227,
170,
243,
231,
28962,
117,
109,
169,
245,
114,
12,
10148,
255,
227,
170,
249,
102,
28790,
110,
16439,
247,
10148,
244,
227,
168,
111,
227,
32704,
223,
297,
288,
283,
1802,
356,
283,
1064,
21,
26,
21,
4361,
1840,
68,
2894,
70,
20,
66,
1272,
2871,
17,
66,
13595,
68,
17,
2871,
25,
67,
22566,
70,
23,
297,
288,
283,
5064,
63,
602,
356,
283,
1797,
13938,
1167,
297,
267,
1660,
267,
283,
2759,
356,
283,
4240,
720,
816,
1522,
297,
272,
14877,
339,
347,
485,
3093,
63,
5005,
8,
277,
12,
1166,
304,
267,
3991,
63,
344,
275,
291,
423,
1431,
63,
344,
8,
633,
9,
267,
9248,
275,
291,
423,
4249,
63,
12022,
8,
633,
12,
3991,
63,
344,
9,
398,
333,
63,
344,
275,
295,
14,
1733,
8,
82,
7,
1391,
519,
5466,
10921,
275,
892,
302,
6164,
14,
82,
5466,
10756,
86,
14,
50,
7608,
9166,
10921,
60,
18353,
11198,
4186,
7340,
11198,
32691,
586,
9248,
9,
267,
340,
333,
63,
344,
365,
488,
26,
288,
1125,
275,
291,
423,
1360,
63,
1733,
63,
3821,
8,
355,
519,
10120,
83,
21528,
3015,
1021,
628,
5169,
78,
425,
63,
705,
92,
78,
425,
63,
1977,
92,
705,
63,
1977,
9,
14559,
83,
10,
5169,
25273,
6697,
31647,
5547,
60,
83,
10,
28,
80,
1021,
628,
25153,
11,
1743,
2229,
48,
28,
1328,
29587,
15939,
80,
3072,
83,
10,
1108,
3015,
4206,
355,
9248,
12,
283,
705,
297,
849,
29,
403,
9,
288,
340,
1125,
26,
355,
746,
19783,
8,
705,
12,
1420,
29,
549,
9,
288,
746,
19783,
360,
15153,
78,
3985,
84,
5536,
27767,
436,
790,
358,
267,
3991,
63,
576,
275,
291,
423,
4249,
63,
1001,
8,
288,
283,
1014,
921,
2802,
14,
82,
5466,
10756,
86,
14,
3540,
422,
14,
957,
15,
86,
364,
15,
2802,
15,
86,
18,
14,
16,
4805,
435,
333,
63,
344,
14,
923,
8,
17,
395,
288,
3991,
63,
344,
12,
1827,
3126,
355,
283,
498,
356,
333,
63,
344,
14,
923,
8,
18,
395,
288,
3828,
267,
3404,
275,
3991,
63,
576,
459,
2024,
418,
267,
2538,
275,
3404,
459,
5875,
418,
267,
6752,
275,
942,
398,
347,
5536,
63,
6321,
8,
11231,
12,
2547,
63,
466,
12,
1827,
16420,
288,
367,
2547,
315,
13788,
26,
355,
2547,
63,
633,
275,
2547,
14,
362,
360,
1365,
358,
355,
340,
440,
2547,
63,
633,
26,
490,
1980,
355,
2547,
63,
633,
275,
1678,
63,
633,
63,
1131,
8,
1745,
63,
633,
12,
1827,
9,
355,
2644,
63,
1422,
275,
2547,
14,
362,
360,
2991,
2602,
297,
5009,
355,
4546,
1866,
275,
2547,
14,
362,
360,
24484,
297,
5009,
355,
6752,
14,
740,
2561,
490,
283,
908,
63,
344,
356,
1543,
83,
4970,
83,
7,
450,
334,
1745,
14,
362,
360,
466,
358,
503,
2547,
63,
466,
12,
2644,
63,
1422,
14,
362,
360,
344,
358,
503,
2644,
63,
1422,
14,
362,
360,
354,
3855,
490,
283,
633,
356,
2547,
63,
633,
12,
490,
283,
2063,
356,
1109,
63,
269,
63,
3592,
8,
2991,
63,
1422,
14,
362,
360,
2063,
3855,
490,
283,
3333,
356,
1109,
63,
269,
63,
3592,
8,
2991,
63,
1422,
14,
362,
360,
3333,
3855,
490,
283,
86,
3289,
356,
1109,
63,
269,
63,
3592,
8,
24484,
14,
362,
360,
3722,
3855,
490,
283,
371,
82,
356,
1109,
63,
269,
63,
3592,
8,
24484,
14,
362,
360,
8130,
3855,
490,
283,
19233,
356,
1109,
63,
269,
63,
3592,
8,
1745,
14,
362,
360,
890,
3855,
490
] |
[
2644,
26,
2774,
13,
24,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
295,
199,
199,
504,
1275,
2330,
492,
21298,
199,
504,
2508,
1208,
492,
334,
272,
19783,
12,
272,
1109,
63,
269,
63,
3592,
12,
272,
1678,
63,
633,
63,
1131,
12,
199,
9,
421,
199,
533,
11290,
422,
4332,
8,
18283,
304,
272,
485,
5600,
63,
2632,
275,
519,
7,
2859,
24524,
77,
20316,
6993,
2931,
4537,
3540,
422,
4537,
957,
15,
86,
9448,
48,
28,
344,
3072,
68,
29600,
339,
485,
7569,
275,
8910,
267,
283,
633,
356,
283,
1014,
921,
6993,
2931,
14,
3540,
422,
14,
957,
15,
86,
15,
31104,
2528,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
31104,
2528,
297,
288,
283,
832,
356,
283,
311,
20,
297,
288,
283,
1213,
356,
6730,
25,
169,
250,
243,
16002,
104,
102,
16439,
247,
167,
112,
255,
169,
225,
106,
221,
17272,
113,
28790,
98,
22247,
244,
16439,
247,
1527,
169,
231,
247,
17272,
248,
63,
167,
118,
223,
169,
226,
224,
170,
252,
106,
61,
10148,
231,
247,
17272,
248,
437,
170,
247,
244,
3193,
94,
1165,
168,
111,
231,
297,
288,
283,
1802,
356,
283,
17272,
103,
167,
111,
103,
168,
115,
231,
168,
112,
223,
16439,
247,
16002,
111,
244,
169,
118,
248,
16002,
103,
243,
28733,
169,
233,
98,
170,
227,
109,
168,
243,
243,
1204,
16002,
103,
243,
28733,
169,
233,
98,
170,
227,
109,
168,
243,
243,
10148,
231,
247,
17272,
248,
28962,
118,
223,
169,
226,
224,
170,
252,
106,
10148,
227,
255,
169,
226,
252,
21048,
247,
31888,
1749,
169,
250,
243,
16002,
104,
102,
16439,
247,
167,
112,
255,
169,
225,
106,
10148,
231,
247,
17272,
248,
33,
170,
247,
244,
3193,
168,
111,
231,
28739,
239,
28790,
251,
3388,
168,
111,
231,
167,
118,
235,
32704,
223,
221,
17272,
113,
28790,
98,
22247,
244,
16439,
247,
168,
99,
121,
28962,
112,
114,
22247,
251,
17272,
103,
21048,
231,
31503,
3130,
288,
283,
5064,
63,
602,
356,
283,
1797,
10556,
1644,
297,
267,
1660,
272,
1660,
469,
267,
283,
633,
356,
283,
1014,
921,
6993,
2931,
14,
3540,
422,
14,
957,
15,
86,
15,
1355,
2010,
1401,
297,
267,
283,
1064,
21,
356,
283,
22,
1703,
379,
20,
67,
713,
11533,
67,
28645,
771,
3003,
617,
2592,
614,
70,
12478,
2866,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
1355,
2010,
1401,
297,
288,
283,
832,
356,
283,
311,
20,
297,
288,
283,
1213,
356,
283,
25,
168,
228,
227,
31888,
10148,
101,
223,
168,
225,
247,
168,
238,
227,
10148,
244,
227,
170,
243,
231,
28962,
117,
109,
169,
245,
114,
12,
10148,
255,
227,
170,
249,
102,
28790,
110,
16439,
247,
10148,
244,
227,
168,
111,
227,
32704,
223,
297,
288,
283,
1802,
356,
283,
1064,
21,
26,
21,
4361,
1840,
68,
2894,
70,
20,
66,
1272,
2871,
17,
66,
13595,
68,
17,
2871,
25,
67,
22566,
70,
23,
297,
288,
283,
5064,
63,
602,
356,
283,
1797,
13938,
1167,
297,
267,
1660,
267,
283,
2759,
356,
283,
4240,
720,
816,
1522,
297,
272,
14877,
339,
347,
485,
3093,
63,
5005,
8,
277,
12,
1166,
304,
267,
3991,
63,
344,
275,
291,
423,
1431,
63,
344,
8,
633,
9,
267,
9248,
275,
291,
423,
4249,
63,
12022,
8,
633,
12,
3991,
63,
344,
9,
398,
333,
63,
344,
275,
295,
14,
1733,
8,
82,
7,
1391,
519,
5466,
10921,
275,
892,
302,
6164,
14,
82,
5466,
10756,
86,
14,
50,
7608,
9166,
10921,
60,
18353,
11198,
4186,
7340,
11198,
32691,
586,
9248,
9,
267,
340,
333,
63,
344,
365,
488,
26,
288,
1125,
275,
291,
423,
1360,
63,
1733,
63,
3821,
8,
355,
519,
10120,
83,
21528,
3015,
1021,
628,
5169,
78,
425,
63,
705,
92,
78,
425,
63,
1977,
92,
705,
63,
1977,
9,
14559,
83,
10,
5169,
25273,
6697,
31647,
5547,
60,
83,
10,
28,
80,
1021,
628,
25153,
11,
1743,
2229,
48,
28,
1328,
29587,
15939,
80,
3072,
83,
10,
1108,
3015,
4206,
355,
9248,
12,
283,
705,
297,
849,
29,
403,
9,
288,
340,
1125,
26,
355,
746,
19783,
8,
705,
12,
1420,
29,
549,
9,
288,
746,
19783,
360,
15153,
78,
3985,
84,
5536,
27767,
436,
790,
358,
267,
3991,
63,
576,
275,
291,
423,
4249,
63,
1001,
8,
288,
283,
1014,
921,
2802,
14,
82,
5466,
10756,
86,
14,
3540,
422,
14,
957,
15,
86,
364,
15,
2802,
15,
86,
18,
14,
16,
4805,
435,
333,
63,
344,
14,
923,
8,
17,
395,
288,
3991,
63,
344,
12,
1827,
3126,
355,
283,
498,
356,
333,
63,
344,
14,
923,
8,
18,
395,
288,
3828,
267,
3404,
275,
3991,
63,
576,
459,
2024,
418,
267,
2538,
275,
3404,
459,
5875,
418,
267,
6752,
275,
942,
398,
347,
5536,
63,
6321,
8,
11231,
12,
2547,
63,
466,
12,
1827,
16420,
288,
367,
2547,
315,
13788,
26,
355,
2547,
63,
633,
275,
2547,
14,
362,
360,
1365,
358,
355,
340,
440,
2547,
63,
633,
26,
490,
1980,
355,
2547,
63,
633,
275,
1678,
63,
633,
63,
1131,
8,
1745,
63,
633,
12,
1827,
9,
355,
2644,
63,
1422,
275,
2547,
14,
362,
360,
2991,
2602,
297,
5009,
355,
4546,
1866,
275,
2547,
14,
362,
360,
24484,
297,
5009,
355,
6752,
14,
740,
2561,
490,
283,
908,
63,
344,
356,
1543,
83,
4970,
83,
7,
450,
334,
1745,
14,
362,
360,
466,
358,
503,
2547,
63,
466,
12,
2644,
63,
1422,
14,
362,
360,
344,
358,
503,
2644,
63,
1422,
14,
362,
360,
354,
3855,
490,
283,
633,
356,
2547,
63,
633,
12,
490,
283,
2063,
356,
1109,
63,
269,
63,
3592,
8,
2991,
63,
1422,
14,
362,
360,
2063,
3855,
490,
283,
3333,
356,
1109,
63,
269,
63,
3592,
8,
2991,
63,
1422,
14,
362,
360,
3333,
3855,
490,
283,
86,
3289,
356,
1109,
63,
269,
63,
3592,
8,
24484,
14,
362,
360,
3722,
3855,
490,
283,
371,
82,
356,
1109,
63,
269,
63,
3592,
8,
24484,
14,
362,
360,
8130,
3855,
490,
283,
19233,
356,
1109,
63,
269,
63,
3592,
8,
1745,
14,
362,
360,
890,
3855,
490,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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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
] |
pietroquaglio/elephant
|
elephant/test/test_pandas_bridge.py
|
2
|
113211
|
# -*- coding: utf-8 -*-
"""
Unit tests for the pandas bridge module.
:copyright: Copyright 2014-2016 by the Elephant team, see AUTHORS.txt.
:license: Modified BSD, see LICENSE.txt for details.
"""
from __future__ import division, print_function
import unittest
from itertools import chain
from neo.test.generate_datasets import fake_neo
import numpy as np
from numpy.testing import assert_array_equal
import quantities as pq
try:
import pandas as pd
from pandas.util.testing import assert_frame_equal, assert_index_equal
except ImportError:
HAVE_PANDAS = False
else:
import elephant.pandas_bridge as ep
HAVE_PANDAS = True
if HAVE_PANDAS:
# Currying, otherwise the unittest will break with pandas>=0.16.0
# parameter check_names is introduced in a newer versions than 0.14.0
# this test is written for pandas 0.14.0
def assert_index_equal(left, right):
try:
# pandas>=0.16.0
return pd.util.testing.assert_index_equal(left, right,
check_names=False)
except TypeError:
# pandas older version
return pd.util.testing.assert_index_equal(left, right)
@unittest.skipUnless(HAVE_PANDAS, 'requires pandas')
class MultiindexFromDictTestCase(unittest.TestCase):
def test__multiindex_from_dict(self):
inds = {'test1': 6.5,
'test2': 5,
'test3': 'test'}
targ = pd.MultiIndex(levels=[[6.5], [5], ['test']],
labels=[[0], [0], [0]],
names=['test1', 'test2', 'test3'])
res0 = ep._multiindex_from_dict(inds)
self.assertEqual(targ.levels, res0.levels)
self.assertEqual(targ.names, res0.names)
self.assertEqual(targ.labels, res0.labels)
def _convert_levels(levels):
"""Convert a list of levels to the format pandas returns for a MultiIndex.
Parameters
----------
levels : list
The list of levels to convert.
Returns
-------
list
The the level in `list` converted to values like what pandas will give.
"""
levels = list(levels)
for i, level in enumerate(levels):
if hasattr(level, 'lower'):
try:
level = unicode(level)
except NameError:
pass
elif hasattr(level, 'date'):
levels[i] = pd.DatetimeIndex(data=[level])
continue
elif level is None:
levels[i] = pd.Index([])
continue
# pd.Index around pd.Index to convert to Index structure if MultiIndex
levels[i] = pd.Index(pd.Index([level]))
return levels
@unittest.skipUnless(HAVE_PANDAS, 'requires pandas')
class ConvertValueSafeTestCase(unittest.TestCase):
def test__convert_value_safe__float(self):
targ = 5.5
value = targ
res = ep._convert_value_safe(value)
self.assertIs(res, targ)
def test__convert_value_safe__str(self):
targ = 'test'
value = targ
res = ep._convert_value_safe(value)
self.assertIs(res, targ)
def test__convert_value_safe__bytes(self):
targ = 'test'
value = b'test'
res = ep._convert_value_safe(value)
self.assertEqual(res, targ)
def test__convert_value_safe__numpy_int_scalar(self):
targ = 5
value = np.array(5)
res = ep._convert_value_safe(value)
self.assertEqual(res, targ)
self.assertFalse(hasattr(res, 'dtype'))
def test__convert_value_safe__numpy_float_scalar(self):
targ = 5.
value = np.array(5.)
res = ep._convert_value_safe(value)
self.assertEqual(res, targ)
self.assertFalse(hasattr(res, 'dtype'))
def test__convert_value_safe__numpy_unicode_scalar(self):
targ = u'test'
value = np.array('test', dtype='U')
res = ep._convert_value_safe(value)
self.assertEqual(res, targ)
self.assertFalse(hasattr(res, 'dtype'))
def test__convert_value_safe__numpy_str_scalar(self):
targ = u'test'
value = np.array('test', dtype='S')
res = ep._convert_value_safe(value)
self.assertEqual(res, targ)
self.assertFalse(hasattr(res, 'dtype'))
def test__convert_value_safe__quantity_scalar(self):
targ = (10., 'ms')
value = 10. * pq.ms
res = ep._convert_value_safe(value)
self.assertEqual(res, targ)
self.assertFalse(hasattr(res[0], 'dtype'))
self.assertFalse(hasattr(res[0], 'units'))
@unittest.skipUnless(HAVE_PANDAS, 'requires pandas')
class SpiketrainToDataframeTestCase(unittest.TestCase):
def test__spiketrain_to_dataframe__parents_empty(self):
obj = fake_neo('SpikeTrain', seed=0)
res0 = ep.spiketrain_to_dataframe(obj)
res1 = ep.spiketrain_to_dataframe(obj, child_first=True)
res2 = ep.spiketrain_to_dataframe(obj, child_first=False)
res3 = ep.spiketrain_to_dataframe(obj, parents=True)
res4 = ep.spiketrain_to_dataframe(obj, parents=True,
child_first=True)
res5 = ep.spiketrain_to_dataframe(obj, parents=True,
child_first=False)
res6 = ep.spiketrain_to_dataframe(obj, parents=False)
res7 = ep.spiketrain_to_dataframe(obj, parents=False, child_first=True)
res8 = ep.spiketrain_to_dataframe(obj, parents=False,
child_first=False)
targvalues = pq.Quantity(obj.magnitude, units=obj.units)
targvalues = targvalues.rescale('s').magnitude[np.newaxis].T
targindex = np.arange(len(targvalues))
attrs = ep._extract_neo_attrs_safe(obj, parents=True, child_first=True)
keys, values = zip(*sorted(attrs.items()))
values = _convert_levels(values)
self.assertEqual(1, len(res0.columns))
self.assertEqual(1, len(res1.columns))
self.assertEqual(1, len(res2.columns))
self.assertEqual(1, len(res3.columns))
self.assertEqual(1, len(res4.columns))
self.assertEqual(1, len(res5.columns))
self.assertEqual(1, len(res6.columns))
self.assertEqual(1, len(res7.columns))
self.assertEqual(1, len(res8.columns))
self.assertEqual(len(obj), len(res0.index))
self.assertEqual(len(obj), len(res1.index))
self.assertEqual(len(obj), len(res2.index))
self.assertEqual(len(obj), len(res3.index))
self.assertEqual(len(obj), len(res4.index))
self.assertEqual(len(obj), len(res5.index))
self.assertEqual(len(obj), len(res6.index))
self.assertEqual(len(obj), len(res7.index))
self.assertEqual(len(obj), len(res8.index))
assert_array_equal(targvalues, res0.values)
assert_array_equal(targvalues, res1.values)
assert_array_equal(targvalues, res2.values)
assert_array_equal(targvalues, res3.values)
assert_array_equal(targvalues, res4.values)
assert_array_equal(targvalues, res5.values)
assert_array_equal(targvalues, res6.values)
assert_array_equal(targvalues, res7.values)
assert_array_equal(targvalues, res8.values)
assert_array_equal(targindex, res0.index)
assert_array_equal(targindex, res1.index)
assert_array_equal(targindex, res2.index)
assert_array_equal(targindex, res3.index)
assert_array_equal(targindex, res4.index)
assert_array_equal(targindex, res5.index)
assert_array_equal(targindex, res6.index)
assert_array_equal(targindex, res7.index)
assert_array_equal(targindex, res8.index)
self.assertEqual(['spike_number'], res0.index.names)
self.assertEqual(['spike_number'], res1.index.names)
self.assertEqual(['spike_number'], res2.index.names)
self.assertEqual(['spike_number'], res3.index.names)
self.assertEqual(['spike_number'], res4.index.names)
self.assertEqual(['spike_number'], res5.index.names)
self.assertEqual(['spike_number'], res6.index.names)
self.assertEqual(['spike_number'], res7.index.names)
self.assertEqual(['spike_number'], res8.index.names)
self.assertEqual(keys, res0.columns.names)
self.assertEqual(keys, res1.columns.names)
self.assertEqual(keys, res2.columns.names)
self.assertEqual(keys, res3.columns.names)
self.assertEqual(keys, res4.columns.names)
self.assertEqual(keys, res5.columns.names)
self.assertEqual(keys, res6.columns.names)
self.assertEqual(keys, res7.columns.names)
self.assertEqual(keys, res8.columns.names)
for value, level in zip(values, res0.columns.levels):
assert_index_equal(value, level)
for value, level in zip(values, res1.columns.levels):
assert_index_equal(value, level)
for value, level in zip(values, res2.columns.levels):
assert_index_equal(value, level)
for value, level in zip(values, res3.columns.levels):
assert_index_equal(value, level)
for value, level in zip(values, res4.columns.levels):
assert_index_equal(value, level)
for value, level in zip(values, res5.columns.levels):
assert_index_equal(value, level)
for value, level in zip(values, res6.columns.levels):
assert_index_equal(value, level)
for value, level in zip(values, res7.columns.levels):
assert_index_equal(value, level)
for value, level in zip(values, res8.columns.levels):
assert_index_equal(value, level)
def test__spiketrain_to_dataframe__noparents(self):
blk = fake_neo('Block', seed=0)
obj = blk.list_children_by_class('SpikeTrain')[0]
res0 = ep.spiketrain_to_dataframe(obj, parents=False)
res1 = ep.spiketrain_to_dataframe(obj, parents=False,
child_first=True)
res2 = ep.spiketrain_to_dataframe(obj, parents=False,
child_first=False)
targvalues = pq.Quantity(obj.magnitude, units=obj.units)
targvalues = targvalues.rescale('s').magnitude[np.newaxis].T
targindex = np.arange(len(targvalues))
attrs = ep._extract_neo_attrs_safe(obj, parents=False,
child_first=True)
keys, values = zip(*sorted(attrs.items()))
values = _convert_levels(values)
self.assertEqual(1, len(res0.columns))
self.assertEqual(1, len(res1.columns))
self.assertEqual(1, len(res2.columns))
self.assertEqual(len(obj), len(res0.index))
self.assertEqual(len(obj), len(res1.index))
self.assertEqual(len(obj), len(res2.index))
assert_array_equal(targvalues, res0.values)
assert_array_equal(targvalues, res1.values)
assert_array_equal(targvalues, res2.values)
assert_array_equal(targindex, res0.index)
assert_array_equal(targindex, res1.index)
assert_array_equal(targindex, res2.index)
self.assertEqual(['spike_number'], res0.index.names)
self.assertEqual(['spike_number'], res1.index.names)
self.assertEqual(['spike_number'], res2.index.names)
self.assertEqual(keys, res0.columns.names)
self.assertEqual(keys, res1.columns.names)
self.assertEqual(keys, res2.columns.names)
for value, level in zip(values, res0.columns.levels):
assert_index_equal(value, level)
for value, level in zip(values, res1.columns.levels):
assert_index_equal(value, level)
for value, level in zip(values, res2.columns.levels):
assert_index_equal(value, level)
def test__spiketrain_to_dataframe__parents_childfirst(self):
blk = fake_neo('Block', seed=0)
obj = blk.list_children_by_class('SpikeTrain')[0]
res0 = ep.spiketrain_to_dataframe(obj)
res1 = ep.spiketrain_to_dataframe(obj, child_first=True)
res2 = ep.spiketrain_to_dataframe(obj, parents=True)
res3 = ep.spiketrain_to_dataframe(obj, parents=True, child_first=True)
targvalues = pq.Quantity(obj.magnitude, units=obj.units)
targvalues = targvalues.rescale('s').magnitude[np.newaxis].T
targindex = np.arange(len(targvalues))
attrs = ep._extract_neo_attrs_safe(obj, parents=True, child_first=True)
keys, values = zip(*sorted(attrs.items()))
values = _convert_levels(values)
self.assertEqual(1, len(res0.columns))
self.assertEqual(1, len(res1.columns))
self.assertEqual(1, len(res2.columns))
self.assertEqual(1, len(res3.columns))
self.assertEqual(len(obj), len(res0.index))
self.assertEqual(len(obj), len(res1.index))
self.assertEqual(len(obj), len(res2.index))
self.assertEqual(len(obj), len(res3.index))
assert_array_equal(targvalues, res0.values)
assert_array_equal(targvalues, res1.values)
assert_array_equal(targvalues, res2.values)
assert_array_equal(targvalues, res3.values)
assert_array_equal(targindex, res0.index)
assert_array_equal(targindex, res1.index)
assert_array_equal(targindex, res2.index)
assert_array_equal(targindex, res3.index)
self.assertEqual(['spike_number'], res0.index.names)
self.assertEqual(['spike_number'], res1.index.names)
self.assertEqual(['spike_number'], res2.index.names)
self.assertEqual(['spike_number'], res3.index.names)
self.assertEqual(keys, res0.columns.names)
self.assertEqual(keys, res1.columns.names)
self.assertEqual(keys, res2.columns.names)
self.assertEqual(keys, res3.columns.names)
for value, level in zip(values, res0.columns.levels):
assert_index_equal(value, level)
for value, level in zip(values, res1.columns.levels):
assert_index_equal(value, level)
for value, level in zip(values, res2.columns.levels):
assert_index_equal(value, level)
for value, level in zip(values, res3.columns.levels):
assert_index_equal(value, level)
def test__spiketrain_to_dataframe__parents_parentfirst(self):
blk = fake_neo('Block', seed=0)
obj = blk.list_children_by_class('SpikeTrain')[0]
res0 = ep.spiketrain_to_dataframe(obj, child_first=False)
res1 = ep.spiketrain_to_dataframe(obj, parents=True, child_first=False)
targvalues = pq.Quantity(obj.magnitude, units=obj.units)
targvalues = targvalues.rescale('s').magnitude[np.newaxis].T
targindex = np.arange(len(targvalues))
attrs = ep._extract_neo_attrs_safe(obj, parents=True,
child_first=False)
keys, values = zip(*sorted(attrs.items()))
values = _convert_levels(values)
self.assertEqual(1, len(res0.columns))
self.assertEqual(1, len(res1.columns))
self.assertEqual(len(obj), len(res0.index))
self.assertEqual(len(obj), len(res1.index))
assert_array_equal(targvalues, res0.values)
assert_array_equal(targvalues, res1.values)
assert_array_equal(targindex, res0.index)
assert_array_equal(targindex, res1.index)
self.assertEqual(['spike_number'], res0.index.names)
self.assertEqual(['spike_number'], res1.index.names)
self.assertEqual(keys, res0.columns.names)
self.assertEqual(keys, res1.columns.names)
for value, level in zip(values, res0.columns.levels):
assert_index_equal(value, level)
for value, level in zip(values, res1.columns.levels):
assert_index_equal(value, level)
@unittest.skipUnless(HAVE_PANDAS, 'requires pandas')
class EventToDataframeTestCase(unittest.TestCase):
def test__event_to_dataframe__parents_empty(self):
obj = fake_neo('Event', seed=42)
res0 = ep.event_to_dataframe(obj)
res1 = ep.event_to_dataframe(obj, child_first=True)
res2 = ep.event_to_dataframe(obj, child_first=False)
res3 = ep.event_to_dataframe(obj, parents=True)
res4 = ep.event_to_dataframe(obj, parents=True, child_first=True)
res5 = ep.event_to_dataframe(obj, parents=True, child_first=False)
res6 = ep.event_to_dataframe(obj, parents=False)
res7 = ep.event_to_dataframe(obj, parents=False, child_first=True)
res8 = ep.event_to_dataframe(obj, parents=False, child_first=False)
targvalues = obj.labels[:len(obj.times)][np.newaxis].T.astype('U')
targindex = obj.times[:len(obj.labels)].rescale('s').magnitude
attrs = ep._extract_neo_attrs_safe(obj, parents=True, child_first=True)
keys, values = zip(*sorted(attrs.items()))
values = _convert_levels(values)
self.assertEqual(1, len(res0.columns))
self.assertEqual(1, len(res1.columns))
self.assertEqual(1, len(res2.columns))
self.assertEqual(1, len(res3.columns))
self.assertEqual(1, len(res4.columns))
self.assertEqual(1, len(res5.columns))
self.assertEqual(1, len(res6.columns))
self.assertEqual(1, len(res7.columns))
self.assertEqual(1, len(res8.columns))
self.assertEqual(min(len(obj.times), len(obj.labels)),
len(res0.index))
self.assertEqual(min(len(obj.times), len(obj.labels)),
len(res1.index))
self.assertEqual(min(len(obj.times), len(obj.labels)),
len(res2.index))
self.assertEqual(min(len(obj.times), len(obj.labels)),
len(res3.index))
self.assertEqual(min(len(obj.times), len(obj.labels)),
len(res4.index))
self.assertEqual(min(len(obj.times), len(obj.labels)),
len(res5.index))
self.assertEqual(min(len(obj.times), len(obj.labels)),
len(res6.index))
self.assertEqual(min(len(obj.times), len(obj.labels)),
len(res7.index))
self.assertEqual(min(len(obj.times), len(obj.labels)),
len(res8.index))
assert_array_equal(targvalues, res0.values)
assert_array_equal(targvalues, res1.values)
assert_array_equal(targvalues, res2.values)
assert_array_equal(targvalues, res3.values)
assert_array_equal(targvalues, res4.values)
assert_array_equal(targvalues, res5.values)
assert_array_equal(targvalues, res6.values)
assert_array_equal(targvalues, res7.values)
assert_array_equal(targvalues, res8.values)
assert_array_equal(targindex, res0.index)
assert_array_equal(targindex, res1.index)
assert_array_equal(targindex, res2.index)
assert_array_equal(targindex, res3.index)
assert_array_equal(targindex, res4.index)
assert_array_equal(targindex, res5.index)
assert_array_equal(targindex, res6.index)
assert_array_equal(targindex, res7.index)
assert_array_equal(targindex, res8.index)
self.assertEqual(['times'], res0.index.names)
self.assertEqual(['times'], res1.index.names)
self.assertEqual(['times'], res2.index.names)
self.assertEqual(['times'], res3.index.names)
self.assertEqual(['times'], res4.index.names)
self.assertEqual(['times'], res5.index.names)
self.assertEqual(['times'], res6.index.names)
self.assertEqual(['times'], res7.index.names)
self.assertEqual(['times'], res8.index.names)
self.assertEqual(keys, res0.columns.names)
self.assertEqual(keys, res1.columns.names)
self.assertEqual(keys, res2.columns.names)
self.assertEqual(keys, res3.columns.names)
self.assertEqual(keys, res4.columns.names)
self.assertEqual(keys, res5.columns.names)
self.assertEqual(keys, res6.columns.names)
self.assertEqual(keys, res7.columns.names)
self.assertEqual(keys, res8.columns.names)
for value, level in zip(values, res0.columns.levels):
assert_index_equal(value, level)
for value, level in zip(values, res1.columns.levels):
assert_index_equal(value, level)
for value, level in zip(values, res2.columns.levels):
assert_index_equal(value, level)
for value, level in zip(values, res3.columns.levels):
assert_index_equal(value, level)
for value, level in zip(values, res4.columns.levels):
assert_index_equal(value, level)
for value, level in zip(values, res5.columns.levels):
assert_index_equal(value, level)
for value, level in zip(values, res6.columns.levels):
assert_index_equal(value, level)
for value, level in zip(values, res7.columns.levels):
assert_index_equal(value, level)
for value, level in zip(values, res8.columns.levels):
assert_index_equal(value, level)
def test__event_to_dataframe__noparents(self):
blk = fake_neo('Block', seed=42)
obj = blk.list_children_by_class('Event')[0]
res0 = ep.event_to_dataframe(obj, parents=False)
res1 = ep.event_to_dataframe(obj, parents=False, child_first=False)
res2 = ep.event_to_dataframe(obj, parents=False, child_first=True)
targvalues = obj.labels[:len(obj.times)][np.newaxis].T.astype('U')
targindex = obj.times[:len(obj.labels)].rescale('s').magnitude
attrs = ep._extract_neo_attrs_safe(obj, parents=False,
child_first=True)
keys, values = zip(*sorted(attrs.items()))
values = _convert_levels(values)
self.assertEqual(1, len(res0.columns))
self.assertEqual(1, len(res1.columns))
self.assertEqual(1, len(res2.columns))
self.assertEqual(min(len(obj.times), len(obj.labels)),
len(res0.index))
self.assertEqual(min(len(obj.times), len(obj.labels)),
len(res1.index))
self.assertEqual(min(len(obj.times), len(obj.labels)),
len(res2.index))
assert_array_equal(targvalues, res0.values)
assert_array_equal(targvalues, res1.values)
assert_array_equal(targvalues, res2.values)
assert_array_equal(targindex, res0.index)
assert_array_equal(targindex, res1.index)
assert_array_equal(targindex, res2.index)
self.assertEqual(['times'], res0.index.names)
self.assertEqual(['times'], res1.index.names)
self.assertEqual(['times'], res2.index.names)
self.assertEqual(keys, res0.columns.names)
self.assertEqual(keys, res1.columns.names)
self.assertEqual(keys, res2.columns.names)
for value, level in zip(values, res0.columns.levels):
assert_index_equal(value, level)
for value, level in zip(values, res1.columns.levels):
assert_index_equal(value, level)
for value, level in zip(values, res2.columns.levels):
assert_index_equal(value, level)
def test__event_to_dataframe__parents_childfirst(self):
blk = fake_neo('Block', seed=42)
obj = blk.list_children_by_class('Event')[0]
res0 = ep.event_to_dataframe(obj)
res1 = ep.event_to_dataframe(obj, child_first=True)
res2 = ep.event_to_dataframe(obj, parents=True)
res3 = ep.event_to_dataframe(obj, parents=True, child_first=True)
targvalues = obj.labels[:len(obj.times)][np.newaxis].T.astype('U')
targindex = obj.times[:len(obj.labels)].rescale('s').magnitude
attrs = ep._extract_neo_attrs_safe(obj, parents=True, child_first=True)
keys, values = zip(*sorted(attrs.items()))
values = _convert_levels(values)
self.assertEqual(1, len(res0.columns))
self.assertEqual(1, len(res1.columns))
self.assertEqual(1, len(res2.columns))
self.assertEqual(1, len(res3.columns))
self.assertEqual(min(len(obj.times), len(obj.labels)),
len(res0.index))
self.assertEqual(min(len(obj.times), len(obj.labels)),
len(res1.index))
self.assertEqual(min(len(obj.times), len(obj.labels)),
len(res2.index))
self.assertEqual(min(len(obj.times), len(obj.labels)),
len(res3.index))
assert_array_equal(targvalues, res0.values)
assert_array_equal(targvalues, res1.values)
assert_array_equal(targvalues, res2.values)
assert_array_equal(targvalues, res3.values)
assert_array_equal(targindex, res0.index)
assert_array_equal(targindex, res1.index)
assert_array_equal(targindex, res2.index)
assert_array_equal(targindex, res3.index)
self.assertEqual(['times'], res0.index.names)
self.assertEqual(['times'], res1.index.names)
self.assertEqual(['times'], res2.index.names)
self.assertEqual(['times'], res3.index.names)
self.assertEqual(keys, res0.columns.names)
self.assertEqual(keys, res1.columns.names)
self.assertEqual(keys, res2.columns.names)
self.assertEqual(keys, res3.columns.names)
for value, level in zip(values, res0.columns.levels):
assert_index_equal(value, level)
for value, level in zip(values, res1.columns.levels):
assert_index_equal(value, level)
for value, level in zip(values, res2.columns.levels):
assert_index_equal(value, level)
for value, level in zip(values, res3.columns.levels):
assert_index_equal(value, level)
def test__event_to_dataframe__parents_parentfirst(self):
blk = fake_neo('Block', seed=42)
obj = blk.list_children_by_class('Event')[0]
res0 = ep.event_to_dataframe(obj, child_first=False)
res1 = ep.event_to_dataframe(obj, parents=True, child_first=False)
targvalues = obj.labels[:len(obj.times)][np.newaxis].T.astype('U')
targindex = obj.times[:len(obj.labels)].rescale('s').magnitude
attrs = ep._extract_neo_attrs_safe(obj, parents=True,
child_first=False)
keys, values = zip(*sorted(attrs.items()))
values = _convert_levels(values)
self.assertEqual(1, len(res0.columns))
self.assertEqual(1, len(res1.columns))
self.assertEqual(min(len(obj.times), len(obj.labels)),
len(res0.index))
self.assertEqual(min(len(obj.times), len(obj.labels)),
len(res1.index))
assert_array_equal(targvalues, res0.values)
assert_array_equal(targvalues, res1.values)
assert_array_equal(targindex, res0.index)
assert_array_equal(targindex, res1.index)
self.assertEqual(['times'], res0.index.names)
self.assertEqual(['times'], res1.index.names)
self.assertEqual(keys, res0.columns.names)
self.assertEqual(keys, res1.columns.names)
for value, level in zip(values, res0.columns.levels):
assert_index_equal(value, level)
for value, level in zip(values, res1.columns.levels):
assert_index_equal(value, level)
@unittest.skipUnless(HAVE_PANDAS, 'requires pandas')
class EpochToDataframeTestCase(unittest.TestCase):
def test__epoch_to_dataframe__parents_empty(self):
obj = fake_neo('Epoch', seed=42)
res0 = ep.epoch_to_dataframe(obj)
res1 = ep.epoch_to_dataframe(obj, child_first=True)
res2 = ep.epoch_to_dataframe(obj, child_first=False)
res3 = ep.epoch_to_dataframe(obj, parents=True)
res4 = ep.epoch_to_dataframe(obj, parents=True, child_first=True)
res5 = ep.epoch_to_dataframe(obj, parents=True, child_first=False)
res6 = ep.epoch_to_dataframe(obj, parents=False)
res7 = ep.epoch_to_dataframe(obj, parents=False, child_first=True)
res8 = ep.epoch_to_dataframe(obj, parents=False, child_first=False)
minlen = min([len(obj.times), len(obj.durations), len(obj.labels)])
targvalues = obj.labels[:minlen][np.newaxis].T.astype('U')
targindex = np.vstack([obj.durations[:minlen].rescale('s').magnitude,
obj.times[:minlen].rescale('s').magnitude])
targvalues = targvalues[targindex.argsort()[0], :]
targindex.sort()
attrs = ep._extract_neo_attrs_safe(obj, parents=True,
child_first=True)
keys, values = zip(*sorted(attrs.items()))
values = _convert_levels(values)
self.assertEqual(1, len(res0.columns))
self.assertEqual(1, len(res1.columns))
self.assertEqual(1, len(res2.columns))
self.assertEqual(1, len(res3.columns))
self.assertEqual(1, len(res4.columns))
self.assertEqual(1, len(res5.columns))
self.assertEqual(1, len(res6.columns))
self.assertEqual(1, len(res7.columns))
self.assertEqual(1, len(res8.columns))
self.assertEqual(min(len(obj.times), len(obj.durations),
len(obj.labels)),
len(res0.index))
self.assertEqual(min(len(obj.times), len(obj.durations),
len(obj.labels)),
len(res1.index))
self.assertEqual(min(len(obj.times), len(obj.durations),
len(obj.labels)),
len(res2.index))
self.assertEqual(min(len(obj.times), len(obj.durations),
len(obj.labels)),
len(res3.index))
self.assertEqual(min(len(obj.times), len(obj.durations),
len(obj.labels)),
len(res4.index))
self.assertEqual(min(len(obj.times), len(obj.durations),
len(obj.labels)),
len(res5.index))
self.assertEqual(min(len(obj.times), len(obj.durations),
len(obj.labels)),
len(res6.index))
self.assertEqual(min(len(obj.times), len(obj.durations),
len(obj.labels)),
len(res7.index))
self.assertEqual(min(len(obj.times), len(obj.durations),
len(obj.labels)),
len(res8.index))
assert_array_equal(targvalues, res0.values)
assert_array_equal(targvalues, res1.values)
assert_array_equal(targvalues, res2.values)
assert_array_equal(targvalues, res3.values)
assert_array_equal(targvalues, res4.values)
assert_array_equal(targvalues, res5.values)
assert_array_equal(targvalues, res6.values)
assert_array_equal(targvalues, res7.values)
assert_array_equal(targvalues, res8.values)
self.assertEqual(keys, res0.columns.names)
self.assertEqual(keys, res1.columns.names)
self.assertEqual(keys, res2.columns.names)
self.assertEqual(keys, res3.columns.names)
self.assertEqual(keys, res4.columns.names)
self.assertEqual(keys, res5.columns.names)
self.assertEqual(keys, res6.columns.names)
self.assertEqual(keys, res7.columns.names)
self.assertEqual(keys, res8.columns.names)
self.assertEqual([u'durations', u'times'], res0.index.names)
self.assertEqual([u'durations', u'times'], res1.index.names)
self.assertEqual([u'durations', u'times'], res2.index.names)
self.assertEqual([u'durations', u'times'], res3.index.names)
self.assertEqual([u'durations', u'times'], res4.index.names)
self.assertEqual([u'durations', u'times'], res5.index.names)
self.assertEqual([u'durations', u'times'], res6.index.names)
self.assertEqual([u'durations', u'times'], res7.index.names)
self.assertEqual([u'durations', u'times'], res8.index.names)
self.assertEqual(2, len(res0.index.levels))
self.assertEqual(2, len(res1.index.levels))
self.assertEqual(2, len(res2.index.levels))
self.assertEqual(2, len(res3.index.levels))
self.assertEqual(2, len(res4.index.levels))
self.assertEqual(2, len(res5.index.levels))
self.assertEqual(2, len(res6.index.levels))
self.assertEqual(2, len(res7.index.levels))
self.assertEqual(2, len(res8.index.levels))
assert_array_equal(targindex, res0.index.levels)
assert_array_equal(targindex, res1.index.levels)
assert_array_equal(targindex, res2.index.levels)
assert_array_equal(targindex, res3.index.levels)
assert_array_equal(targindex, res4.index.levels)
assert_array_equal(targindex, res5.index.levels)
assert_array_equal(targindex, res6.index.levels)
assert_array_equal(targindex, res7.index.levels)
assert_array_equal(targindex, res8.index.levels)
for value, level in zip(values, res0.columns.levels):
assert_index_equal(value, level)
for value, level in zip(values, res1.columns.levels):
assert_index_equal(value, level)
for value, level in zip(values, res2.columns.levels):
assert_index_equal(value, level)
for value, level in zip(values, res3.columns.levels):
assert_index_equal(value, level)
for value, level in zip(values, res4.columns.levels):
assert_index_equal(value, level)
for value, level in zip(values, res5.columns.levels):
assert_index_equal(value, level)
for value, level in zip(values, res6.columns.levels):
assert_index_equal(value, level)
for value, level in zip(values, res7.columns.levels):
assert_index_equal(value, level)
for value, level in zip(values, res8.columns.levels):
assert_index_equal(value, level)
def test__epoch_to_dataframe__noparents(self):
blk = fake_neo('Block', seed=42)
obj = blk.list_children_by_class('Epoch')[0]
res0 = ep.epoch_to_dataframe(obj, parents=False)
res1 = ep.epoch_to_dataframe(obj, parents=False, child_first=True)
res2 = ep.epoch_to_dataframe(obj, parents=False, child_first=False)
minlen = min([len(obj.times), len(obj.durations), len(obj.labels)])
targvalues = obj.labels[:minlen][np.newaxis].T.astype('U')
targindex = np.vstack([obj.durations[:minlen].rescale('s').magnitude,
obj.times[:minlen].rescale('s').magnitude])
targvalues = targvalues[targindex.argsort()[0], :]
targindex.sort()
attrs = ep._extract_neo_attrs_safe(obj, parents=False,
child_first=True)
keys, values = zip(*sorted(attrs.items()))
values = _convert_levels(values)
self.assertEqual(1, len(res0.columns))
self.assertEqual(1, len(res1.columns))
self.assertEqual(1, len(res2.columns))
self.assertEqual(min(len(obj.times), len(obj.durations),
len(obj.labels)),
len(res0.index))
self.assertEqual(min(len(obj.times), len(obj.durations),
len(obj.labels)),
len(res1.index))
self.assertEqual(min(len(obj.times), len(obj.durations),
len(obj.labels)),
len(res2.index))
assert_array_equal(targvalues, res0.values)
assert_array_equal(targvalues, res1.values)
assert_array_equal(targvalues, res2.values)
self.assertEqual(keys, res0.columns.names)
self.assertEqual(keys, res1.columns.names)
self.assertEqual(keys, res2.columns.names)
self.assertEqual([u'durations', u'times'], res0.index.names)
self.assertEqual([u'durations', u'times'], res1.index.names)
self.assertEqual([u'durations', u'times'], res2.index.names)
self.assertEqual(2, len(res0.index.levels))
self.assertEqual(2, len(res1.index.levels))
self.assertEqual(2, len(res2.index.levels))
assert_array_equal(targindex, res0.index.levels)
assert_array_equal(targindex, res1.index.levels)
assert_array_equal(targindex, res2.index.levels)
for value, level in zip(values, res0.columns.levels):
assert_index_equal(value, level)
for value, level in zip(values, res1.columns.levels):
assert_index_equal(value, level)
for value, level in zip(values, res2.columns.levels):
assert_index_equal(value, level)
def test__epoch_to_dataframe__parents_childfirst(self):
blk = fake_neo('Block', seed=42)
obj = blk.list_children_by_class('Epoch')[0]
res0 = ep.epoch_to_dataframe(obj)
res1 = ep.epoch_to_dataframe(obj, child_first=True)
res2 = ep.epoch_to_dataframe(obj, parents=True)
res3 = ep.epoch_to_dataframe(obj, parents=True, child_first=True)
minlen = min([len(obj.times), len(obj.durations), len(obj.labels)])
targvalues = obj.labels[:minlen][np.newaxis].T.astype('U')
targindex = np.vstack([obj.durations[:minlen].rescale('s').magnitude,
obj.times[:minlen].rescale('s').magnitude])
targvalues = targvalues[targindex.argsort()[0], :]
targindex.sort()
attrs = ep._extract_neo_attrs_safe(obj, parents=True, child_first=True)
keys, values = zip(*sorted(attrs.items()))
values = _convert_levels(values)
self.assertEqual(1, len(res0.columns))
self.assertEqual(1, len(res1.columns))
self.assertEqual(1, len(res2.columns))
self.assertEqual(1, len(res3.columns))
self.assertEqual(min(len(obj.times), len(obj.durations),
len(obj.labels)),
len(res0.index))
self.assertEqual(min(len(obj.times), len(obj.durations),
len(obj.labels)),
len(res1.index))
self.assertEqual(min(len(obj.times), len(obj.durations),
len(obj.labels)),
len(res2.index))
self.assertEqual(min(len(obj.times), len(obj.durations),
len(obj.labels)),
len(res3.index))
assert_array_equal(targvalues, res0.values)
assert_array_equal(targvalues, res1.values)
assert_array_equal(targvalues, res2.values)
assert_array_equal(targvalues, res3.values)
self.assertEqual(keys, res0.columns.names)
self.assertEqual(keys, res1.columns.names)
self.assertEqual(keys, res2.columns.names)
self.assertEqual(keys, res3.columns.names)
self.assertEqual([u'durations', u'times'], res0.index.names)
self.assertEqual([u'durations', u'times'], res1.index.names)
self.assertEqual([u'durations', u'times'], res2.index.names)
self.assertEqual([u'durations', u'times'], res3.index.names)
self.assertEqual(2, len(res0.index.levels))
self.assertEqual(2, len(res1.index.levels))
self.assertEqual(2, len(res2.index.levels))
self.assertEqual(2, len(res3.index.levels))
assert_array_equal(targindex, res0.index.levels)
assert_array_equal(targindex, res1.index.levels)
assert_array_equal(targindex, res2.index.levels)
assert_array_equal(targindex, res3.index.levels)
for value, level in zip(values, res0.columns.levels):
assert_index_equal(value, level)
for value, level in zip(values, res1.columns.levels):
assert_index_equal(value, level)
for value, level in zip(values, res2.columns.levels):
assert_index_equal(value, level)
for value, level in zip(values, res3.columns.levels):
assert_index_equal(value, level)
def test__epoch_to_dataframe__parents_parentfirst(self):
blk = fake_neo('Block', seed=42)
obj = blk.list_children_by_class('Epoch')[0]
res0 = ep.epoch_to_dataframe(obj, child_first=False)
res1 = ep.epoch_to_dataframe(obj, parents=True, child_first=False)
minlen = min([len(obj.times), len(obj.durations), len(obj.labels)])
targvalues = obj.labels[:minlen][np.newaxis].T.astype('U')
targindex = np.vstack([obj.durations[:minlen].rescale('s').magnitude,
obj.times[:minlen].rescale('s').magnitude])
targvalues = targvalues[targindex.argsort()[0], :]
targindex.sort()
attrs = ep._extract_neo_attrs_safe(obj, parents=True,
child_first=False)
keys, values = zip(*sorted(attrs.items()))
values = _convert_levels(values)
self.assertEqual(1, len(res0.columns))
self.assertEqual(1, len(res1.columns))
self.assertEqual(min(len(obj.times), len(obj.durations),
len(obj.labels)),
len(res0.index))
self.assertEqual(min(len(obj.times), len(obj.durations),
len(obj.labels)),
len(res1.index))
assert_array_equal(targvalues, res0.values)
assert_array_equal(targvalues, res1.values)
self.assertEqual(keys, res0.columns.names)
self.assertEqual(keys, res1.columns.names)
self.assertEqual([u'durations', u'times'], res0.index.names)
self.assertEqual([u'durations', u'times'], res1.index.names)
self.assertEqual(2, len(res0.index.levels))
self.assertEqual(2, len(res1.index.levels))
assert_array_equal(targindex, res0.index.levels)
assert_array_equal(targindex, res1.index.levels)
for value, level in zip(values, res0.columns.levels):
assert_index_equal(value, level)
for value, level in zip(values, res1.columns.levels):
assert_index_equal(value, level)
@unittest.skipUnless(HAVE_PANDAS, 'requires pandas')
class MultiSpiketrainsToDataframeTestCase(unittest.TestCase):
def setUp(self):
if hasattr(self, 'assertItemsEqual'):
self.assertCountEqual = self.assertItemsEqual
def test__multi_spiketrains_to_dataframe__single(self):
obj = fake_neo('SpikeTrain', seed=0, n=5)
res0 = ep.multi_spiketrains_to_dataframe(obj)
res1 = ep.multi_spiketrains_to_dataframe(obj, parents=False)
res2 = ep.multi_spiketrains_to_dataframe(obj, parents=True)
res3 = ep.multi_spiketrains_to_dataframe(obj, child_first=True)
res4 = ep.multi_spiketrains_to_dataframe(obj, parents=False,
child_first=True)
res5 = ep.multi_spiketrains_to_dataframe(obj, parents=True,
child_first=True)
res6 = ep.multi_spiketrains_to_dataframe(obj, child_first=False)
res7 = ep.multi_spiketrains_to_dataframe(obj, parents=False,
child_first=False)
res8 = ep.multi_spiketrains_to_dataframe(obj, parents=True,
child_first=False)
targ = ep.spiketrain_to_dataframe(obj)
keys = ep._extract_neo_attrs_safe(obj, parents=True,
child_first=True).keys()
keys = list(keys)
targwidth = 1
targlen = len(obj)
self.assertEqual(targwidth, len(targ.columns))
self.assertEqual(targwidth, len(res0.columns))
self.assertEqual(targwidth, len(res1.columns))
self.assertEqual(targwidth, len(res2.columns))
self.assertEqual(targwidth, len(res3.columns))
self.assertEqual(targwidth, len(res4.columns))
self.assertEqual(targwidth, len(res5.columns))
self.assertEqual(targwidth, len(res6.columns))
self.assertEqual(targwidth, len(res7.columns))
self.assertEqual(targwidth, len(res8.columns))
self.assertEqual(targlen, len(targ.index))
self.assertEqual(targlen, len(res0.index))
self.assertEqual(targlen, len(res1.index))
self.assertEqual(targlen, len(res2.index))
self.assertEqual(targlen, len(res3.index))
self.assertEqual(targlen, len(res4.index))
self.assertEqual(targlen, len(res5.index))
self.assertEqual(targlen, len(res6.index))
self.assertEqual(targlen, len(res7.index))
self.assertEqual(targlen, len(res8.index))
self.assertCountEqual(keys, targ.columns.names)
self.assertCountEqual(keys, res0.columns.names)
self.assertCountEqual(keys, res1.columns.names)
self.assertCountEqual(keys, res2.columns.names)
self.assertCountEqual(keys, res3.columns.names)
self.assertCountEqual(keys, res4.columns.names)
self.assertCountEqual(keys, res5.columns.names)
self.assertCountEqual(keys, res6.columns.names)
self.assertCountEqual(keys, res7.columns.names)
self.assertCountEqual(keys, res8.columns.names)
assert_array_equal(targ.values, res0.values)
assert_array_equal(targ.values, res1.values)
assert_array_equal(targ.values, res2.values)
assert_array_equal(targ.values, res3.values)
assert_array_equal(targ.values, res4.values)
assert_array_equal(targ.values, res5.values)
assert_array_equal(targ.values, res6.values)
assert_array_equal(targ.values, res7.values)
assert_array_equal(targ.values, res8.values)
assert_frame_equal(targ, res0)
assert_frame_equal(targ, res0)
assert_frame_equal(targ, res1)
assert_frame_equal(targ, res2)
assert_frame_equal(targ, res3)
assert_frame_equal(targ, res4)
assert_frame_equal(targ, res5)
assert_frame_equal(targ, res6)
assert_frame_equal(targ, res7)
assert_frame_equal(targ, res8)
def test__multi_spiketrains_to_dataframe__unit_default(self):
obj = fake_neo('Unit', seed=0, n=5)
res0 = ep.multi_spiketrains_to_dataframe(obj)
objs = obj.spiketrains
targ = [ep.spiketrain_to_dataframe(iobj) for iobj in objs]
targ = ep._sort_inds(pd.concat(targ, axis=1), axis=1)
keys = ep._extract_neo_attrs_safe(objs[0], parents=True,
child_first=True).keys()
keys = list(keys)
targwidth = len(objs)
targlen = max(len(iobj) for iobj in objs)
self.assertGreater(len(objs), 0)
self.assertEqual(targwidth, len(targ.columns))
self.assertEqual(targwidth, len(res0.columns))
self.assertEqual(targlen, len(targ.index))
self.assertEqual(targlen, len(res0.index))
self.assertCountEqual(keys, targ.columns.names)
self.assertCountEqual(keys, res0.columns.names)
assert_array_equal(targ.values, res0.values)
assert_frame_equal(targ, res0)
def test__multi_spiketrains_to_dataframe__segment_default(self):
obj = fake_neo('Segment', seed=0, n=5)
res0 = ep.multi_spiketrains_to_dataframe(obj)
objs = obj.spiketrains
targ = [ep.spiketrain_to_dataframe(iobj) for iobj in objs]
targ = ep._sort_inds(pd.concat(targ, axis=1), axis=1)
keys = ep._extract_neo_attrs_safe(objs[0], parents=True,
child_first=True).keys()
keys = list(keys)
targwidth = len(objs)
targlen = max(len(iobj) for iobj in objs)
self.assertGreater(len(objs), 0)
self.assertEqual(targwidth, len(targ.columns))
self.assertEqual(targwidth, len(res0.columns))
self.assertEqual(targlen, len(targ.index))
self.assertEqual(targlen, len(res0.index))
self.assertCountEqual(keys, targ.columns.names)
self.assertCountEqual(keys, res0.columns.names)
assert_array_equal(targ.values, res0.values)
assert_frame_equal(targ, res0)
def test__multi_spiketrains_to_dataframe__block_noparents(self):
obj = fake_neo('Block', seed=0, n=3)
res0 = ep.multi_spiketrains_to_dataframe(obj, parents=False)
res1 = ep.multi_spiketrains_to_dataframe(obj, parents=False,
child_first=True)
res2 = ep.multi_spiketrains_to_dataframe(obj, parents=False,
child_first=False)
objs = obj.list_children_by_class('SpikeTrain')
targ = [ep.spiketrain_to_dataframe(iobj,
parents=False, child_first=True)
for iobj in objs]
targ = ep._sort_inds(pd.concat(targ, axis=1), axis=1)
keys = ep._extract_neo_attrs_safe(objs[0], parents=False,
child_first=True).keys()
keys = list(keys)
targwidth = len(objs)
targlen = max(len(iobj) for iobj in objs)
self.assertGreater(len(objs), 0)
self.assertEqual(targwidth, len(targ.columns))
self.assertEqual(targwidth, len(res0.columns))
self.assertEqual(targwidth, len(res1.columns))
self.assertEqual(targwidth, len(res2.columns))
self.assertEqual(targlen, len(targ.index))
self.assertEqual(targlen, len(res0.index))
self.assertEqual(targlen, len(res1.index))
self.assertEqual(targlen, len(res2.index))
self.assertCountEqual(keys, targ.columns.names)
self.assertCountEqual(keys, res0.columns.names)
self.assertCountEqual(keys, res1.columns.names)
self.assertCountEqual(keys, res2.columns.names)
assert_array_equal(targ.values, res0.values)
assert_array_equal(targ.values, res1.values)
assert_array_equal(targ.values, res2.values)
assert_frame_equal(targ, res0)
assert_frame_equal(targ, res1)
assert_frame_equal(targ, res2)
def test__multi_spiketrains_to_dataframe__block_parents_childfirst(self):
obj = fake_neo('Block', seed=0, n=3)
res0 = ep.multi_spiketrains_to_dataframe(obj)
res1 = ep.multi_spiketrains_to_dataframe(obj, parents=True)
res2 = ep.multi_spiketrains_to_dataframe(obj, child_first=True)
res3 = ep.multi_spiketrains_to_dataframe(obj, parents=True,
child_first=True)
objs = obj.list_children_by_class('SpikeTrain')
targ = [ep.spiketrain_to_dataframe(iobj,
parents=True, child_first=True)
for iobj in objs]
targ = ep._sort_inds(pd.concat(targ, axis=1), axis=1)
keys = ep._extract_neo_attrs_safe(objs[0], parents=True,
child_first=True).keys()
keys = list(keys)
targwidth = len(objs)
targlen = max(len(iobj) for iobj in objs)
self.assertGreater(len(objs), 0)
self.assertEqual(targwidth, len(targ.columns))
self.assertEqual(targwidth, len(res0.columns))
self.assertEqual(targwidth, len(res1.columns))
self.assertEqual(targwidth, len(res2.columns))
self.assertEqual(targwidth, len(res3.columns))
self.assertEqual(targlen, len(targ.index))
self.assertEqual(targlen, len(res0.index))
self.assertEqual(targlen, len(res1.index))
self.assertEqual(targlen, len(res2.index))
self.assertEqual(targlen, len(res3.index))
self.assertCountEqual(keys, targ.columns.names)
self.assertCountEqual(keys, res0.columns.names)
self.assertCountEqual(keys, res1.columns.names)
self.assertCountEqual(keys, res2.columns.names)
self.assertCountEqual(keys, res3.columns.names)
assert_array_equal(targ.values, res0.values)
assert_array_equal(targ.values, res1.values)
assert_array_equal(targ.values, res2.values)
assert_array_equal(targ.values, res3.values)
assert_frame_equal(targ, res0)
assert_frame_equal(targ, res1)
assert_frame_equal(targ, res2)
assert_frame_equal(targ, res3)
def test__multi_spiketrains_to_dataframe__block_parents_parentfirst(self):
obj = fake_neo('Block', seed=0, n=3)
res0 = ep.multi_spiketrains_to_dataframe(obj, child_first=False)
res1 = ep.multi_spiketrains_to_dataframe(obj, parents=True,
child_first=False)
objs = obj.list_children_by_class('SpikeTrain')
targ = [ep.spiketrain_to_dataframe(iobj,
parents=True, child_first=False)
for iobj in objs]
targ = ep._sort_inds(pd.concat(targ, axis=1), axis=1)
keys = ep._extract_neo_attrs_safe(objs[0], parents=True,
child_first=False).keys()
keys = list(keys)
targwidth = len(objs)
targlen = max(len(iobj) for iobj in objs)
self.assertGreater(len(objs), 0)
self.assertEqual(targwidth, len(targ.columns))
self.assertEqual(targwidth, len(res0.columns))
self.assertEqual(targwidth, len(res1.columns))
self.assertEqual(targlen, len(targ.index))
self.assertEqual(targlen, len(res0.index))
self.assertEqual(targlen, len(res1.index))
self.assertCountEqual(keys, targ.columns.names)
self.assertCountEqual(keys, res0.columns.names)
self.assertCountEqual(keys, res1.columns.names)
assert_array_equal(targ.values, res0.values)
assert_array_equal(targ.values, res1.values)
assert_frame_equal(targ, res0)
assert_frame_equal(targ, res1)
def test__multi_spiketrains_to_dataframe__list_noparents(self):
obj = [fake_neo('Block', seed=i, n=3) for i in range(3)]
res0 = ep.multi_spiketrains_to_dataframe(obj, parents=False)
res1 = ep.multi_spiketrains_to_dataframe(obj, parents=False,
child_first=True)
res2 = ep.multi_spiketrains_to_dataframe(obj, parents=False,
child_first=False)
objs = (iobj.list_children_by_class('SpikeTrain') for iobj in obj)
objs = list(chain.from_iterable(objs))
targ = [ep.spiketrain_to_dataframe(iobj,
parents=False, child_first=True)
for iobj in objs]
targ = ep._sort_inds(pd.concat(targ, axis=1), axis=1)
keys = ep._extract_neo_attrs_safe(objs[0], parents=False,
child_first=True).keys()
keys = list(keys)
targwidth = len(objs)
targlen = max(len(iobj) for iobj in objs)
self.assertGreater(len(objs), 0)
self.assertEqual(targwidth, len(targ.columns))
self.assertEqual(targwidth, len(res0.columns))
self.assertEqual(targwidth, len(res1.columns))
self.assertEqual(targwidth, len(res2.columns))
self.assertEqual(targlen, len(targ.index))
self.assertEqual(targlen, len(res0.index))
self.assertEqual(targlen, len(res1.index))
self.assertEqual(targlen, len(res2.index))
self.assertCountEqual(keys, targ.columns.names)
self.assertCountEqual(keys, res0.columns.names)
self.assertCountEqual(keys, res1.columns.names)
self.assertCountEqual(keys, res2.columns.names)
assert_array_equal(targ.values, res0.values)
assert_array_equal(targ.values, res1.values)
assert_array_equal(targ.values, res2.values)
assert_frame_equal(targ, res0)
assert_frame_equal(targ, res1)
assert_frame_equal(targ, res2)
def test__multi_spiketrains_to_dataframe__list_parents_childfirst(self):
obj = [fake_neo('Block', seed=i, n=3) for i in range(3)]
res0 = ep.multi_spiketrains_to_dataframe(obj)
res1 = ep.multi_spiketrains_to_dataframe(obj, parents=True)
res2 = ep.multi_spiketrains_to_dataframe(obj, child_first=True)
res3 = ep.multi_spiketrains_to_dataframe(obj, parents=True,
child_first=True)
objs = (iobj.list_children_by_class('SpikeTrain') for iobj in obj)
objs = list(chain.from_iterable(objs))
targ = [ep.spiketrain_to_dataframe(iobj,
parents=True, child_first=True)
for iobj in objs]
targ = ep._sort_inds(pd.concat(targ, axis=1), axis=1)
keys = ep._extract_neo_attrs_safe(objs[0], parents=True,
child_first=True).keys()
keys = list(keys)
targwidth = len(objs)
targlen = max(len(iobj) for iobj in objs)
self.assertGreater(len(objs), 0)
self.assertEqual(targwidth, len(targ.columns))
self.assertEqual(targwidth, len(res0.columns))
self.assertEqual(targwidth, len(res1.columns))
self.assertEqual(targwidth, len(res2.columns))
self.assertEqual(targwidth, len(res3.columns))
self.assertEqual(targlen, len(targ.index))
self.assertEqual(targlen, len(res0.index))
self.assertEqual(targlen, len(res1.index))
self.assertEqual(targlen, len(res2.index))
self.assertEqual(targlen, len(res3.index))
self.assertCountEqual(keys, targ.columns.names)
self.assertCountEqual(keys, res0.columns.names)
self.assertCountEqual(keys, res1.columns.names)
self.assertCountEqual(keys, res2.columns.names)
self.assertCountEqual(keys, res3.columns.names)
assert_array_equal(targ.values, res0.values)
assert_array_equal(targ.values, res1.values)
assert_array_equal(targ.values, res2.values)
assert_array_equal(targ.values, res3.values)
assert_frame_equal(targ, res0)
assert_frame_equal(targ, res1)
assert_frame_equal(targ, res2)
assert_frame_equal(targ, res3)
def test__multi_spiketrains_to_dataframe__list_parents_parentfirst(self):
obj = [fake_neo('Block', seed=i, n=3) for i in range(3)]
res0 = ep.multi_spiketrains_to_dataframe(obj, child_first=False)
res1 = ep.multi_spiketrains_to_dataframe(obj, parents=True,
child_first=False)
objs = (iobj.list_children_by_class('SpikeTrain') for iobj in obj)
objs = list(chain.from_iterable(objs))
targ = [ep.spiketrain_to_dataframe(iobj,
parents=True, child_first=False)
for iobj in objs]
targ = ep._sort_inds(pd.concat(targ, axis=1), axis=1)
keys = ep._extract_neo_attrs_safe(objs[0], parents=True,
child_first=False).keys()
keys = list(keys)
targwidth = len(objs)
targlen = max(len(iobj) for iobj in objs)
self.assertGreater(len(objs), 0)
self.assertEqual(targwidth, len(targ.columns))
self.assertEqual(targwidth, len(res0.columns))
self.assertEqual(targwidth, len(res1.columns))
self.assertEqual(targlen, len(targ.index))
self.assertEqual(targlen, len(res0.index))
self.assertEqual(targlen, len(res1.index))
self.assertCountEqual(keys, targ.columns.names)
self.assertCountEqual(keys, res0.columns.names)
self.assertCountEqual(keys, res1.columns.names)
assert_array_equal(targ.values, res0.values)
assert_array_equal(targ.values, res1.values)
assert_frame_equal(targ, res0)
assert_frame_equal(targ, res1)
def test__multi_spiketrains_to_dataframe__tuple_default(self):
obj = tuple(fake_neo('Block', seed=i, n=3) for i in range(3))
res0 = ep.multi_spiketrains_to_dataframe(obj)
objs = (iobj.list_children_by_class('SpikeTrain') for iobj in obj)
objs = list(chain.from_iterable(objs))
targ = [ep.spiketrain_to_dataframe(iobj) for iobj in objs]
targ = ep._sort_inds(pd.concat(targ, axis=1), axis=1)
keys = ep._extract_neo_attrs_safe(objs[0], parents=True,
child_first=True).keys()
keys = list(keys)
targwidth = len(objs)
targlen = max(len(iobj) for iobj in objs)
self.assertGreater(len(objs), 0)
self.assertEqual(targwidth, len(targ.columns))
self.assertEqual(targwidth, len(res0.columns))
self.assertEqual(targlen, len(targ.index))
self.assertEqual(targlen, len(res0.index))
self.assertCountEqual(keys, targ.columns.names)
self.assertCountEqual(keys, res0.columns.names)
assert_array_equal(targ.values, res0.values)
assert_frame_equal(targ, res0)
def test__multi_spiketrains_to_dataframe__iter_default(self):
obj = [fake_neo('Block', seed=i, n=3) for i in range(3)]
res0 = ep.multi_spiketrains_to_dataframe(iter(obj))
objs = (iobj.list_children_by_class('SpikeTrain') for iobj in obj)
objs = list(chain.from_iterable(objs))
targ = [ep.spiketrain_to_dataframe(iobj) for iobj in objs]
targ = ep._sort_inds(pd.concat(targ, axis=1), axis=1)
keys = ep._extract_neo_attrs_safe(objs[0], parents=True,
child_first=True).keys()
keys = list(keys)
targwidth = len(objs)
targlen = max(len(iobj) for iobj in objs)
self.assertGreater(len(objs), 0)
self.assertEqual(targwidth, len(targ.columns))
self.assertEqual(targwidth, len(res0.columns))
self.assertEqual(targlen, len(targ.index))
self.assertEqual(targlen, len(res0.index))
self.assertCountEqual(keys, targ.columns.names)
self.assertCountEqual(keys, res0.columns.names)
assert_array_equal(targ.values, res0.values)
assert_frame_equal(targ, res0)
def test__multi_spiketrains_to_dataframe__dict_default(self):
obj = dict((i, fake_neo('Block', seed=i, n=3)) for i in range(3))
res0 = ep.multi_spiketrains_to_dataframe(obj)
objs = (iobj.list_children_by_class('SpikeTrain') for iobj in
obj.values())
objs = list(chain.from_iterable(objs))
targ = [ep.spiketrain_to_dataframe(iobj) for iobj in objs]
targ = ep._sort_inds(pd.concat(targ, axis=1), axis=1)
keys = ep._extract_neo_attrs_safe(objs[0], parents=True,
child_first=True).keys()
keys = list(keys)
targwidth = len(objs)
targlen = max(len(iobj) for iobj in objs)
self.assertGreater(len(objs), 0)
self.assertEqual(targwidth, len(targ.columns))
self.assertEqual(targwidth, len(res0.columns))
self.assertEqual(targlen, len(targ.index))
self.assertEqual(targlen, len(res0.index))
self.assertCountEqual(keys, targ.columns.names)
self.assertCountEqual(keys, res0.columns.names)
assert_array_equal(targ.values, res0.values)
assert_frame_equal(targ, res0)
@unittest.skipUnless(HAVE_PANDAS, 'requires pandas')
class MultiEventsToDataframeTestCase(unittest.TestCase):
def setUp(self):
if hasattr(self, 'assertItemsEqual'):
self.assertCountEqual = self.assertItemsEqual
def test__multi_events_to_dataframe__single(self):
obj = fake_neo('Event', seed=0, n=5)
res0 = ep.multi_events_to_dataframe(obj)
res1 = ep.multi_events_to_dataframe(obj, parents=False)
res2 = ep.multi_events_to_dataframe(obj, parents=True)
res3 = ep.multi_events_to_dataframe(obj, child_first=True)
res4 = ep.multi_events_to_dataframe(obj, parents=False,
child_first=True)
res5 = ep.multi_events_to_dataframe(obj, parents=True,
child_first=True)
res6 = ep.multi_events_to_dataframe(obj, child_first=False)
res7 = ep.multi_events_to_dataframe(obj, parents=False,
child_first=False)
res8 = ep.multi_events_to_dataframe(obj, parents=True,
child_first=False)
targ = ep.event_to_dataframe(obj)
keys = ep._extract_neo_attrs_safe(obj, parents=True,
child_first=True).keys()
keys = list(keys)
targwidth = 1
targlen = min(len(obj.times), len(obj.labels))
self.assertEqual(targwidth, len(targ.columns))
self.assertEqual(targwidth, len(res0.columns))
self.assertEqual(targwidth, len(res1.columns))
self.assertEqual(targwidth, len(res2.columns))
self.assertEqual(targwidth, len(res3.columns))
self.assertEqual(targwidth, len(res4.columns))
self.assertEqual(targwidth, len(res5.columns))
self.assertEqual(targwidth, len(res6.columns))
self.assertEqual(targwidth, len(res7.columns))
self.assertEqual(targwidth, len(res8.columns))
self.assertEqual(targlen, len(targ.index))
self.assertEqual(targlen, len(res0.index))
self.assertEqual(targlen, len(res1.index))
self.assertEqual(targlen, len(res2.index))
self.assertEqual(targlen, len(res3.index))
self.assertEqual(targlen, len(res4.index))
self.assertEqual(targlen, len(res5.index))
self.assertEqual(targlen, len(res6.index))
self.assertEqual(targlen, len(res7.index))
self.assertEqual(targlen, len(res8.index))
self.assertCountEqual(keys, targ.columns.names)
self.assertCountEqual(keys, res0.columns.names)
self.assertCountEqual(keys, res1.columns.names)
self.assertCountEqual(keys, res2.columns.names)
self.assertCountEqual(keys, res3.columns.names)
self.assertCountEqual(keys, res4.columns.names)
self.assertCountEqual(keys, res5.columns.names)
self.assertCountEqual(keys, res6.columns.names)
self.assertCountEqual(keys, res7.columns.names)
self.assertCountEqual(keys, res8.columns.names)
assert_array_equal(targ.values, res0.values)
assert_array_equal(targ.values, res1.values)
assert_array_equal(targ.values, res2.values)
assert_array_equal(targ.values, res3.values)
assert_array_equal(targ.values, res4.values)
assert_array_equal(targ.values, res5.values)
assert_array_equal(targ.values, res6.values)
assert_array_equal(targ.values, res7.values)
assert_array_equal(targ.values, res8.values)
assert_frame_equal(targ, res0)
assert_frame_equal(targ, res1)
assert_frame_equal(targ, res2)
assert_frame_equal(targ, res3)
assert_frame_equal(targ, res4)
assert_frame_equal(targ, res5)
assert_frame_equal(targ, res6)
assert_frame_equal(targ, res7)
assert_frame_equal(targ, res8)
def test__multi_events_to_dataframe__segment_default(self):
obj = fake_neo('Segment', seed=0, n=5)
res0 = ep.multi_events_to_dataframe(obj)
objs = obj.events
targ = [ep.event_to_dataframe(iobj) for iobj in objs]
targ = ep._sort_inds(pd.concat(targ, axis=1), axis=1)
keys = ep._extract_neo_attrs_safe(objs[0], parents=True,
child_first=True).keys()
keys = list(keys)
targwidth = len(objs)
targlen = [iobj.times[:min(len(iobj.times), len(iobj.labels))]
for iobj in objs]
targlen = len(np.unique(np.hstack(targlen)))
self.assertGreater(len(objs), 0)
self.assertEqual(targwidth, len(targ.columns))
self.assertEqual(targwidth, len(res0.columns))
self.assertEqual(targlen, len(targ.index))
self.assertEqual(targlen, len(res0.index))
self.assertCountEqual(keys, targ.columns.names)
self.assertCountEqual(keys, res0.columns.names)
assert_array_equal(
np.array(targ.values, dtype=np.float),
np.array(res0.values, dtype=np.float))
assert_frame_equal(targ, res0)
def test__multi_events_to_dataframe__block_noparents(self):
obj = fake_neo('Block', seed=0, n=3)
res0 = ep.multi_events_to_dataframe(obj, parents=False)
res1 = ep.multi_events_to_dataframe(obj, parents=False,
child_first=True)
res2 = ep.multi_events_to_dataframe(obj, parents=False,
child_first=False)
objs = obj.list_children_by_class('Event')
targ = [ep.event_to_dataframe(iobj, parents=False, child_first=True)
for iobj in objs]
targ = ep._sort_inds(pd.concat(targ, axis=1), axis=1)
keys = ep._extract_neo_attrs_safe(objs[0], parents=False,
child_first=True).keys()
keys = list(keys)
targwidth = len(objs)
targlen = [iobj.times[:min(len(iobj.times), len(iobj.labels))]
for iobj in objs]
targlen = len(np.unique(np.hstack(targlen)))
self.assertGreater(len(objs), 0)
self.assertEqual(targwidth, len(targ.columns))
self.assertEqual(targwidth, len(res0.columns))
self.assertEqual(targwidth, len(res1.columns))
self.assertEqual(targwidth, len(res2.columns))
self.assertEqual(targlen, len(targ.index))
self.assertEqual(targlen, len(res0.index))
self.assertEqual(targlen, len(res1.index))
self.assertEqual(targlen, len(res2.index))
self.assertCountEqual(keys, targ.columns.names)
self.assertCountEqual(keys, res0.columns.names)
self.assertCountEqual(keys, res1.columns.names)
self.assertCountEqual(keys, res2.columns.names)
assert_array_equal(
np.array(targ.values, dtype=np.float),
np.array(res0.values, dtype=np.float))
assert_array_equal(
np.array(targ.values, dtype=np.float),
np.array(res1.values, dtype=np.float))
assert_array_equal(
np.array(targ.values, dtype=np.float),
np.array(res2.values, dtype=np.float))
assert_frame_equal(targ, res0)
assert_frame_equal(targ, res1)
assert_frame_equal(targ, res2)
def test__multi_events_to_dataframe__block_parents_childfirst(self):
obj = fake_neo('Block', seed=0, n=3)
res0 = ep.multi_events_to_dataframe(obj)
res1 = ep.multi_events_to_dataframe(obj, parents=True)
res2 = ep.multi_events_to_dataframe(obj, child_first=True)
res3 = ep.multi_events_to_dataframe(obj, parents=True,
child_first=True)
objs = obj.list_children_by_class('Event')
targ = [ep.event_to_dataframe(iobj, parents=True, child_first=True)
for iobj in objs]
targ = ep._sort_inds(pd.concat(targ, axis=1), axis=1)
keys = ep._extract_neo_attrs_safe(objs[0], parents=True,
child_first=True).keys()
keys = list(keys)
targwidth = len(objs)
targlen = [iobj.times[:min(len(iobj.times), len(iobj.labels))]
for iobj in objs]
targlen = len(np.unique(np.hstack(targlen)))
self.assertGreater(len(objs), 0)
self.assertEqual(targwidth, len(targ.columns))
self.assertEqual(targwidth, len(res0.columns))
self.assertEqual(targwidth, len(res1.columns))
self.assertEqual(targwidth, len(res2.columns))
self.assertEqual(targwidth, len(res3.columns))
self.assertEqual(targlen, len(targ.index))
self.assertEqual(targlen, len(res0.index))
self.assertEqual(targlen, len(res1.index))
self.assertEqual(targlen, len(res2.index))
self.assertEqual(targlen, len(res3.index))
self.assertCountEqual(keys, targ.columns.names)
self.assertCountEqual(keys, res0.columns.names)
self.assertCountEqual(keys, res1.columns.names)
self.assertCountEqual(keys, res2.columns.names)
self.assertCountEqual(keys, res3.columns.names)
assert_array_equal(
np.array(targ.values, dtype=np.float),
np.array(res0.values, dtype=np.float))
assert_array_equal(
np.array(targ.values, dtype=np.float),
np.array(res1.values, dtype=np.float))
assert_array_equal(
np.array(targ.values, dtype=np.float),
np.array(res2.values, dtype=np.float))
assert_array_equal(
np.array(targ.values, dtype=np.float),
np.array(res3.values, dtype=np.float))
assert_frame_equal(targ, res0)
assert_frame_equal(targ, res1)
assert_frame_equal(targ, res2)
assert_frame_equal(targ, res3)
def test__multi_events_to_dataframe__block_parents_parentfirst(self):
obj = fake_neo('Block', seed=0, n=3)
res0 = ep.multi_events_to_dataframe(obj, child_first=False)
res1 = ep.multi_events_to_dataframe(obj, parents=True,
child_first=False)
objs = obj.list_children_by_class('Event')
targ = [ep.event_to_dataframe(iobj, parents=True, child_first=False)
for iobj in objs]
targ = ep._sort_inds(pd.concat(targ, axis=1), axis=1)
keys = ep._extract_neo_attrs_safe(objs[0], parents=True,
child_first=False).keys()
keys = list(keys)
targwidth = len(objs)
targlen = [iobj.times[:min(len(iobj.times), len(iobj.labels))]
for iobj in objs]
targlen = len(np.unique(np.hstack(targlen)))
self.assertGreater(len(objs), 0)
self.assertEqual(targwidth, len(targ.columns))
self.assertEqual(targwidth, len(res0.columns))
self.assertEqual(targwidth, len(res1.columns))
self.assertEqual(targlen, len(targ.index))
self.assertEqual(targlen, len(res0.index))
self.assertEqual(targlen, len(res1.index))
self.assertCountEqual(keys, targ.columns.names)
self.assertCountEqual(keys, res0.columns.names)
self.assertCountEqual(keys, res1.columns.names)
assert_array_equal(
np.array(targ.values, dtype=np.float),
np.array(res0.values, dtype=np.float))
assert_array_equal(
np.array(targ.values, dtype=np.float),
np.array(res1.values, dtype=np.float))
assert_frame_equal(targ, res0)
assert_frame_equal(targ, res1)
def test__multi_events_to_dataframe__list_noparents(self):
obj = [fake_neo('Block', seed=i, n=3) for i in range(3)]
res0 = ep.multi_events_to_dataframe(obj, parents=False)
res1 = ep.multi_events_to_dataframe(obj, parents=False,
child_first=True)
res2 = ep.multi_events_to_dataframe(obj, parents=False,
child_first=False)
objs = (iobj.list_children_by_class('Event') for iobj in obj)
objs = list(chain.from_iterable(objs))
targ = [ep.event_to_dataframe(iobj, parents=False, child_first=True)
for iobj in objs]
targ = ep._sort_inds(pd.concat(targ, axis=1), axis=1)
keys = ep._extract_neo_attrs_safe(objs[0], parents=False,
child_first=True).keys()
keys = list(keys)
targwidth = len(objs)
targlen = [iobj.times[:min(len(iobj.times), len(iobj.labels))]
for iobj in objs]
targlen = len(np.unique(np.hstack(targlen)))
self.assertGreater(len(objs), 0)
self.assertEqual(targwidth, len(targ.columns))
self.assertEqual(targwidth, len(res0.columns))
self.assertEqual(targwidth, len(res1.columns))
self.assertEqual(targwidth, len(res2.columns))
self.assertEqual(targlen, len(targ.index))
self.assertEqual(targlen, len(res0.index))
self.assertEqual(targlen, len(res1.index))
self.assertEqual(targlen, len(res2.index))
self.assertCountEqual(keys, targ.columns.names)
self.assertCountEqual(keys, res0.columns.names)
self.assertCountEqual(keys, res1.columns.names)
self.assertCountEqual(keys, res2.columns.names)
assert_array_equal(
np.array(targ.values, dtype=np.float),
np.array(res0.values, dtype=np.float))
assert_array_equal(
np.array(targ.values, dtype=np.float),
np.array(res1.values, dtype=np.float))
assert_array_equal(
np.array(targ.values, dtype=np.float),
np.array(res2.values, dtype=np.float))
assert_frame_equal(targ, res0)
assert_frame_equal(targ, res1)
assert_frame_equal(targ, res2)
def test__multi_events_to_dataframe__list_parents_childfirst(self):
obj = [fake_neo('Block', seed=i, n=3) for i in range(3)]
res0 = ep.multi_events_to_dataframe(obj)
res1 = ep.multi_events_to_dataframe(obj, parents=True)
res2 = ep.multi_events_to_dataframe(obj, child_first=True)
res3 = ep.multi_events_to_dataframe(obj, parents=True,
child_first=True)
objs = (iobj.list_children_by_class('Event') for iobj in obj)
objs = list(chain.from_iterable(objs))
targ = [ep.event_to_dataframe(iobj, parents=True, child_first=True)
for iobj in objs]
targ = ep._sort_inds(pd.concat(targ, axis=1), axis=1)
keys = ep._extract_neo_attrs_safe(objs[0], parents=True,
child_first=True).keys()
keys = list(keys)
targwidth = len(objs)
targlen = [iobj.times[:min(len(iobj.times), len(iobj.labels))]
for iobj in objs]
targlen = len(np.unique(np.hstack(targlen)))
self.assertGreater(len(objs), 0)
self.assertEqual(targwidth, len(targ.columns))
self.assertEqual(targwidth, len(res0.columns))
self.assertEqual(targwidth, len(res1.columns))
self.assertEqual(targwidth, len(res2.columns))
self.assertEqual(targwidth, len(res3.columns))
self.assertEqual(targlen, len(targ.index))
self.assertEqual(targlen, len(res0.index))
self.assertEqual(targlen, len(res1.index))
self.assertEqual(targlen, len(res2.index))
self.assertEqual(targlen, len(res3.index))
self.assertCountEqual(keys, targ.columns.names)
self.assertCountEqual(keys, res0.columns.names)
self.assertCountEqual(keys, res1.columns.names)
self.assertCountEqual(keys, res2.columns.names)
self.assertCountEqual(keys, res3.columns.names)
assert_array_equal(
np.array(targ.values, dtype=np.float),
np.array(res0.values, dtype=np.float))
assert_array_equal(
np.array(targ.values, dtype=np.float),
np.array(res1.values, dtype=np.float))
assert_array_equal(
np.array(targ.values, dtype=np.float),
np.array(res2.values, dtype=np.float))
assert_array_equal(
np.array(targ.values, dtype=np.float),
np.array(res3.values, dtype=np.float))
assert_frame_equal(targ, res0)
assert_frame_equal(targ, res1)
assert_frame_equal(targ, res2)
assert_frame_equal(targ, res3)
def test__multi_events_to_dataframe__list_parents_parentfirst(self):
obj = [fake_neo('Block', seed=i, n=3) for i in range(3)]
res0 = ep.multi_events_to_dataframe(obj, child_first=False)
res1 = ep.multi_events_to_dataframe(obj, parents=True,
child_first=False)
objs = (iobj.list_children_by_class('Event') for iobj in obj)
objs = list(chain.from_iterable(objs))
targ = [ep.event_to_dataframe(iobj, parents=True, child_first=False)
for iobj in objs]
targ = ep._sort_inds(pd.concat(targ, axis=1), axis=1)
keys = ep._extract_neo_attrs_safe(objs[0], parents=True,
child_first=False).keys()
keys = list(keys)
targwidth = len(objs)
targlen = [iobj.times[:min(len(iobj.times), len(iobj.labels))]
for iobj in objs]
targlen = len(np.unique(np.hstack(targlen)))
self.assertGreater(len(objs), 0)
self.assertEqual(targwidth, len(targ.columns))
self.assertEqual(targwidth, len(res0.columns))
self.assertEqual(targwidth, len(res1.columns))
self.assertEqual(targlen, len(targ.index))
self.assertEqual(targlen, len(res0.index))
self.assertEqual(targlen, len(res1.index))
self.assertCountEqual(keys, targ.columns.names)
self.assertCountEqual(keys, res0.columns.names)
self.assertCountEqual(keys, res1.columns.names)
assert_array_equal(
np.array(targ.values, dtype=np.float),
np.array(res0.values, dtype=np.float))
assert_array_equal(
np.array(targ.values, dtype=np.float),
np.array(res1.values, dtype=np.float))
assert_frame_equal(targ, res0)
assert_frame_equal(targ, res1)
def test__multi_events_to_dataframe__tuple_default(self):
obj = tuple(fake_neo('Block', seed=i, n=3) for i in range(3))
res0 = ep.multi_events_to_dataframe(obj)
objs = (iobj.list_children_by_class('Event') for iobj in obj)
objs = list(chain.from_iterable(objs))
targ = [ep.event_to_dataframe(iobj) for iobj in objs]
targ = ep._sort_inds(pd.concat(targ, axis=1), axis=1)
keys = ep._extract_neo_attrs_safe(objs[0], parents=True,
child_first=True).keys()
keys = list(keys)
targwidth = len(objs)
targlen = [iobj.times[:min(len(iobj.times), len(iobj.labels))]
for iobj in objs]
targlen = len(np.unique(np.hstack(targlen)))
self.assertGreater(len(objs), 0)
self.assertEqual(targwidth, len(targ.columns))
self.assertEqual(targwidth, len(res0.columns))
self.assertEqual(targlen, len(targ.index))
self.assertEqual(targlen, len(res0.index))
self.assertCountEqual(keys, targ.columns.names)
self.assertCountEqual(keys, res0.columns.names)
assert_array_equal(
np.array(targ.values, dtype=np.float),
np.array(res0.values, dtype=np.float))
assert_frame_equal(targ, res0)
def test__multi_events_to_dataframe__iter_default(self):
obj = [fake_neo('Block', seed=i, n=3) for i in range(3)]
res0 = ep.multi_events_to_dataframe(iter(obj))
objs = (iobj.list_children_by_class('Event') for iobj in obj)
objs = list(chain.from_iterable(objs))
targ = [ep.event_to_dataframe(iobj) for iobj in objs]
targ = ep._sort_inds(pd.concat(targ, axis=1), axis=1)
keys = ep._extract_neo_attrs_safe(objs[0], parents=True,
child_first=True).keys()
keys = list(keys)
targwidth = len(objs)
targlen = [iobj.times[:min(len(iobj.times), len(iobj.labels))]
for iobj in objs]
targlen = len(np.unique(np.hstack(targlen)))
self.assertGreater(len(objs), 0)
self.assertEqual(targwidth, len(targ.columns))
self.assertEqual(targwidth, len(res0.columns))
self.assertEqual(targlen, len(targ.index))
self.assertEqual(targlen, len(res0.index))
self.assertCountEqual(keys, targ.columns.names)
self.assertCountEqual(keys, res0.columns.names)
assert_array_equal(
np.array(targ.values, dtype=np.float),
np.array(res0.values, dtype=np.float))
assert_frame_equal(targ, res0)
def test__multi_events_to_dataframe__dict_default(self):
obj = dict((i, fake_neo('Block', seed=i, n=3)) for i in range(3))
res0 = ep.multi_events_to_dataframe(obj)
objs = (iobj.list_children_by_class('Event') for iobj in
obj.values())
objs = list(chain.from_iterable(objs))
targ = [ep.event_to_dataframe(iobj) for iobj in objs]
targ = ep._sort_inds(pd.concat(targ, axis=1), axis=1)
keys = ep._extract_neo_attrs_safe(objs[0], parents=True,
child_first=True).keys()
keys = list(keys)
targwidth = len(objs)
targlen = [iobj.times[:min(len(iobj.times), len(iobj.labels))]
for iobj in objs]
targlen = len(np.unique(np.hstack(targlen)))
self.assertGreater(len(objs), 0)
self.assertEqual(targwidth, len(targ.columns))
self.assertEqual(targwidth, len(res0.columns))
self.assertEqual(targlen, len(targ.index))
self.assertEqual(targlen, len(res0.index))
self.assertCountEqual(keys, targ.columns.names)
self.assertCountEqual(keys, res0.columns.names)
assert_array_equal(
np.array(targ.values, dtype=np.float),
np.array(res0.values, dtype=np.float))
assert_frame_equal(targ, res0)
@unittest.skipUnless(HAVE_PANDAS, 'requires pandas')
class MultiEpochsToDataframeTestCase(unittest.TestCase):
def setUp(self):
if hasattr(self, 'assertItemsEqual'):
self.assertCountEqual = self.assertItemsEqual
def test__multi_epochs_to_dataframe__single(self):
obj = fake_neo('Epoch', seed=0, n=5)
res0 = ep.multi_epochs_to_dataframe(obj)
res1 = ep.multi_epochs_to_dataframe(obj, parents=False)
res2 = ep.multi_epochs_to_dataframe(obj, parents=True)
res3 = ep.multi_epochs_to_dataframe(obj, child_first=True)
res4 = ep.multi_epochs_to_dataframe(obj, parents=False,
child_first=True)
res5 = ep.multi_epochs_to_dataframe(obj, parents=True,
child_first=True)
res6 = ep.multi_epochs_to_dataframe(obj, child_first=False)
res7 = ep.multi_epochs_to_dataframe(obj, parents=False,
child_first=False)
res8 = ep.multi_epochs_to_dataframe(obj, parents=True,
child_first=False)
targ = ep.epoch_to_dataframe(obj)
keys = ep._extract_neo_attrs_safe(obj, parents=True,
child_first=True).keys()
keys = list(keys)
targwidth = 1
targlen = min(len(obj.times), len(obj.durations), len(obj.labels))
self.assertEqual(targwidth, len(targ.columns))
self.assertEqual(targwidth, len(res0.columns))
self.assertEqual(targwidth, len(res1.columns))
self.assertEqual(targwidth, len(res2.columns))
self.assertEqual(targwidth, len(res3.columns))
self.assertEqual(targwidth, len(res4.columns))
self.assertEqual(targwidth, len(res5.columns))
self.assertEqual(targwidth, len(res6.columns))
self.assertEqual(targwidth, len(res7.columns))
self.assertEqual(targwidth, len(res8.columns))
self.assertEqual(targlen, len(targ.index))
self.assertEqual(targlen, len(res0.index))
self.assertEqual(targlen, len(res1.index))
self.assertEqual(targlen, len(res2.index))
self.assertEqual(targlen, len(res3.index))
self.assertEqual(targlen, len(res4.index))
self.assertEqual(targlen, len(res5.index))
self.assertEqual(targlen, len(res6.index))
self.assertEqual(targlen, len(res7.index))
self.assertEqual(targlen, len(res8.index))
self.assertCountEqual(keys, targ.columns.names)
self.assertCountEqual(keys, res0.columns.names)
self.assertCountEqual(keys, res1.columns.names)
self.assertCountEqual(keys, res2.columns.names)
self.assertCountEqual(keys, res3.columns.names)
self.assertCountEqual(keys, res4.columns.names)
self.assertCountEqual(keys, res5.columns.names)
self.assertCountEqual(keys, res6.columns.names)
self.assertCountEqual(keys, res7.columns.names)
self.assertCountEqual(keys, res8.columns.names)
assert_array_equal(targ.values, res0.values)
assert_array_equal(targ.values, res1.values)
assert_array_equal(targ.values, res2.values)
assert_array_equal(targ.values, res3.values)
assert_array_equal(targ.values, res4.values)
assert_array_equal(targ.values, res5.values)
assert_array_equal(targ.values, res6.values)
assert_array_equal(targ.values, res7.values)
assert_array_equal(targ.values, res8.values)
assert_frame_equal(targ, res0)
assert_frame_equal(targ, res1)
assert_frame_equal(targ, res2)
assert_frame_equal(targ, res3)
assert_frame_equal(targ, res4)
assert_frame_equal(targ, res5)
assert_frame_equal(targ, res6)
assert_frame_equal(targ, res7)
assert_frame_equal(targ, res8)
def test__multi_epochs_to_dataframe__segment_default(self):
obj = fake_neo('Segment', seed=0, n=5)
res0 = ep.multi_epochs_to_dataframe(obj)
objs = obj.epochs
targ = [ep.epoch_to_dataframe(iobj) for iobj in objs]
targ = ep._sort_inds(pd.concat(targ, axis=1), axis=1)
keys = ep._extract_neo_attrs_safe(objs[0], parents=True,
child_first=True).keys()
keys = list(keys)
targwidth = len(objs)
targlen = [iobj.times[:min(len(iobj.times), len(iobj.durations),
len(iobj.labels))] for iobj in objs]
targlen = len(np.unique(np.hstack(targlen)))
self.assertGreater(len(objs), 0)
self.assertEqual(targwidth, len(targ.columns))
self.assertEqual(targwidth, len(res0.columns))
self.assertEqual(targlen, len(targ.index))
self.assertEqual(targlen, len(res0.index))
self.assertCountEqual(keys, targ.columns.names)
self.assertCountEqual(keys, res0.columns.names)
assert_array_equal(
np.array(targ.values, dtype=np.float),
np.array(res0.values, dtype=np.float))
assert_frame_equal(targ, res0)
def test__multi_epochs_to_dataframe__block_noparents(self):
obj = fake_neo('Block', seed=0, n=3)
res0 = ep.multi_epochs_to_dataframe(obj, parents=False)
res1 = ep.multi_epochs_to_dataframe(obj, parents=False,
child_first=True)
res2 = ep.multi_epochs_to_dataframe(obj, parents=False,
child_first=False)
objs = obj.list_children_by_class('Epoch')
targ = [ep.epoch_to_dataframe(iobj, parents=False, child_first=True)
for iobj in objs]
targ = ep._sort_inds(pd.concat(targ, axis=1), axis=1)
keys = ep._extract_neo_attrs_safe(objs[0], parents=False,
child_first=True).keys()
keys = list(keys)
targwidth = len(objs)
targlen = [iobj.times[:min(len(iobj.times), len(iobj.durations),
len(iobj.labels))] for iobj in objs]
targlen = len(np.unique(np.hstack(targlen)))
self.assertGreater(len(objs), 0)
self.assertEqual(targwidth, len(targ.columns))
self.assertEqual(targwidth, len(res0.columns))
self.assertEqual(targwidth, len(res1.columns))
self.assertEqual(targwidth, len(res2.columns))
self.assertEqual(targlen, len(targ.index))
self.assertEqual(targlen, len(res0.index))
self.assertEqual(targlen, len(res1.index))
self.assertEqual(targlen, len(res2.index))
self.assertCountEqual(keys, targ.columns.names)
self.assertCountEqual(keys, res0.columns.names)
self.assertCountEqual(keys, res1.columns.names)
self.assertCountEqual(keys, res2.columns.names)
assert_array_equal(
np.array(targ.values, dtype=np.float),
np.array(res0.values, dtype=np.float))
assert_array_equal(
np.array(targ.values, dtype=np.float),
np.array(res1.values, dtype=np.float))
assert_array_equal(
np.array(targ.values, dtype=np.float),
np.array(res2.values, dtype=np.float))
assert_frame_equal(targ, res0)
assert_frame_equal(targ, res1)
assert_frame_equal(targ, res2)
def test__multi_epochs_to_dataframe__block_parents_childfirst(self):
obj = fake_neo('Block', seed=0, n=3)
res0 = ep.multi_epochs_to_dataframe(obj)
res1 = ep.multi_epochs_to_dataframe(obj, parents=True)
res2 = ep.multi_epochs_to_dataframe(obj, child_first=True)
res3 = ep.multi_epochs_to_dataframe(obj, parents=True,
child_first=True)
objs = obj.list_children_by_class('Epoch')
targ = [ep.epoch_to_dataframe(iobj, parents=True, child_first=True)
for iobj in objs]
targ = ep._sort_inds(pd.concat(targ, axis=1), axis=1)
keys = ep._extract_neo_attrs_safe(objs[0], parents=True,
child_first=True).keys()
keys = list(keys)
targwidth = len(objs)
targlen = [iobj.times[:min(len(iobj.times), len(iobj.durations),
len(iobj.labels))] for iobj in objs]
targlen = len(np.unique(np.hstack(targlen)))
self.assertGreater(len(objs), 0)
self.assertEqual(targwidth, len(targ.columns))
self.assertEqual(targwidth, len(res0.columns))
self.assertEqual(targwidth, len(res1.columns))
self.assertEqual(targwidth, len(res2.columns))
self.assertEqual(targwidth, len(res3.columns))
self.assertEqual(targlen, len(targ.index))
self.assertEqual(targlen, len(res0.index))
self.assertEqual(targlen, len(res1.index))
self.assertEqual(targlen, len(res2.index))
self.assertEqual(targlen, len(res3.index))
self.assertCountEqual(keys, targ.columns.names)
self.assertCountEqual(keys, res0.columns.names)
self.assertCountEqual(keys, res1.columns.names)
self.assertCountEqual(keys, res2.columns.names)
self.assertCountEqual(keys, res3.columns.names)
assert_array_equal(
np.array(targ.values, dtype=np.float),
np.array(res0.values, dtype=np.float))
assert_array_equal(
np.array(targ.values, dtype=np.float),
np.array(res1.values, dtype=np.float))
assert_array_equal(
np.array(targ.values, dtype=np.float),
np.array(res2.values, dtype=np.float))
assert_array_equal(
np.array(targ.values, dtype=np.float),
np.array(res3.values, dtype=np.float))
assert_frame_equal(targ, res0)
assert_frame_equal(targ, res1)
assert_frame_equal(targ, res2)
assert_frame_equal(targ, res3)
def test__multi_epochs_to_dataframe__block_parents_parentfirst(self):
obj = fake_neo('Block', seed=0, n=3)
res0 = ep.multi_epochs_to_dataframe(obj, child_first=False)
res1 = ep.multi_epochs_to_dataframe(obj, parents=True,
child_first=False)
objs = obj.list_children_by_class('Epoch')
targ = [ep.epoch_to_dataframe(iobj, parents=True, child_first=False)
for iobj in objs]
targ = ep._sort_inds(pd.concat(targ, axis=1), axis=1)
keys = ep._extract_neo_attrs_safe(objs[0], parents=True,
child_first=False).keys()
keys = list(keys)
targwidth = len(objs)
targlen = [iobj.times[:min(len(iobj.times), len(iobj.durations),
len(iobj.labels))] for iobj in objs]
targlen = len(np.unique(np.hstack(targlen)))
self.assertGreater(len(objs), 0)
self.assertEqual(targwidth, len(targ.columns))
self.assertEqual(targwidth, len(res0.columns))
self.assertEqual(targwidth, len(res1.columns))
self.assertEqual(targlen, len(targ.index))
self.assertEqual(targlen, len(res0.index))
self.assertEqual(targlen, len(res1.index))
self.assertCountEqual(keys, targ.columns.names)
self.assertCountEqual(keys, res0.columns.names)
self.assertCountEqual(keys, res1.columns.names)
assert_array_equal(
np.array(targ.values, dtype=np.float),
np.array(res0.values, dtype=np.float))
assert_array_equal(
np.array(targ.values, dtype=np.float),
np.array(res1.values, dtype=np.float))
assert_frame_equal(targ, res0)
assert_frame_equal(targ, res1)
def test__multi_epochs_to_dataframe__list_noparents(self):
obj = [fake_neo('Block', seed=i, n=3) for i in range(3)]
res0 = ep.multi_epochs_to_dataframe(obj, parents=False)
res1 = ep.multi_epochs_to_dataframe(obj, parents=False,
child_first=True)
res2 = ep.multi_epochs_to_dataframe(obj, parents=False,
child_first=False)
objs = (iobj.list_children_by_class('Epoch') for iobj in obj)
objs = list(chain.from_iterable(objs))
targ = [ep.epoch_to_dataframe(iobj, parents=False, child_first=True)
for iobj in objs]
targ = ep._sort_inds(pd.concat(targ, axis=1), axis=1)
keys = ep._extract_neo_attrs_safe(objs[0], parents=False,
child_first=True).keys()
keys = list(keys)
targwidth = len(objs)
targlen = [iobj.times[:min(len(iobj.times), len(iobj.durations),
len(iobj.labels))] for iobj in objs]
targlen = len(np.unique(np.hstack(targlen)))
self.assertGreater(len(objs), 0)
self.assertEqual(targwidth, len(targ.columns))
self.assertEqual(targwidth, len(res0.columns))
self.assertEqual(targwidth, len(res1.columns))
self.assertEqual(targwidth, len(res2.columns))
self.assertEqual(targlen, len(targ.index))
self.assertEqual(targlen, len(res0.index))
self.assertEqual(targlen, len(res1.index))
self.assertEqual(targlen, len(res2.index))
self.assertCountEqual(keys, targ.columns.names)
self.assertCountEqual(keys, res0.columns.names)
self.assertCountEqual(keys, res1.columns.names)
self.assertCountEqual(keys, res2.columns.names)
assert_array_equal(
np.array(targ.values, dtype=np.float),
np.array(res0.values, dtype=np.float))
assert_array_equal(
np.array(targ.values, dtype=np.float),
np.array(res1.values, dtype=np.float))
assert_array_equal(
np.array(targ.values, dtype=np.float),
np.array(res2.values, dtype=np.float))
assert_frame_equal(targ, res0)
assert_frame_equal(targ, res1)
assert_frame_equal(targ, res2)
def test__multi_epochs_to_dataframe__list_parents_childfirst(self):
obj = [fake_neo('Block', seed=i, n=3) for i in range(3)]
res0 = ep.multi_epochs_to_dataframe(obj)
res1 = ep.multi_epochs_to_dataframe(obj, parents=True)
res2 = ep.multi_epochs_to_dataframe(obj, child_first=True)
res3 = ep.multi_epochs_to_dataframe(obj, parents=True,
child_first=True)
objs = (iobj.list_children_by_class('Epoch') for iobj in obj)
objs = list(chain.from_iterable(objs))
targ = [ep.epoch_to_dataframe(iobj, parents=True, child_first=True)
for iobj in objs]
targ = ep._sort_inds(pd.concat(targ, axis=1), axis=1)
keys = ep._extract_neo_attrs_safe(objs[0], parents=True,
child_first=True).keys()
keys = list(keys)
targwidth = len(objs)
targlen = [iobj.times[:min(len(iobj.times), len(iobj.durations),
len(iobj.labels))] for iobj in objs]
targlen = len(np.unique(np.hstack(targlen)))
self.assertGreater(len(objs), 0)
self.assertEqual(targwidth, len(targ.columns))
self.assertEqual(targwidth, len(res0.columns))
self.assertEqual(targwidth, len(res1.columns))
self.assertEqual(targwidth, len(res2.columns))
self.assertEqual(targwidth, len(res3.columns))
self.assertEqual(targlen, len(targ.index))
self.assertEqual(targlen, len(res0.index))
self.assertEqual(targlen, len(res1.index))
self.assertEqual(targlen, len(res2.index))
self.assertEqual(targlen, len(res3.index))
self.assertCountEqual(keys, targ.columns.names)
self.assertCountEqual(keys, res0.columns.names)
self.assertCountEqual(keys, res1.columns.names)
self.assertCountEqual(keys, res2.columns.names)
self.assertCountEqual(keys, res3.columns.names)
assert_array_equal(
np.array(targ.values, dtype=np.float),
np.array(res0.values, dtype=np.float))
assert_array_equal(
np.array(targ.values, dtype=np.float),
np.array(res1.values, dtype=np.float))
assert_array_equal(
np.array(targ.values, dtype=np.float),
np.array(res2.values, dtype=np.float))
assert_array_equal(
np.array(targ.values, dtype=np.float),
np.array(res3.values, dtype=np.float))
assert_frame_equal(targ, res0)
assert_frame_equal(targ, res1)
assert_frame_equal(targ, res2)
assert_frame_equal(targ, res3)
def test__multi_epochs_to_dataframe__list_parents_parentfirst(self):
obj = [fake_neo('Block', seed=i, n=3) for i in range(3)]
res0 = ep.multi_epochs_to_dataframe(obj, child_first=False)
res1 = ep.multi_epochs_to_dataframe(obj, parents=True,
child_first=False)
objs = (iobj.list_children_by_class('Epoch') for iobj in obj)
objs = list(chain.from_iterable(objs))
targ = [ep.epoch_to_dataframe(iobj, parents=True, child_first=False)
for iobj in objs]
targ = ep._sort_inds(pd.concat(targ, axis=1), axis=1)
keys = ep._extract_neo_attrs_safe(objs[0], parents=True,
child_first=False).keys()
keys = list(keys)
targwidth = len(objs)
targlen = [iobj.times[:min(len(iobj.times), len(iobj.durations),
len(iobj.labels))] for iobj in objs]
targlen = len(np.unique(np.hstack(targlen)))
self.assertGreater(len(objs), 0)
self.assertEqual(targwidth, len(targ.columns))
self.assertEqual(targwidth, len(res0.columns))
self.assertEqual(targwidth, len(res1.columns))
self.assertEqual(targlen, len(targ.index))
self.assertEqual(targlen, len(res0.index))
self.assertEqual(targlen, len(res1.index))
self.assertCountEqual(keys, targ.columns.names)
self.assertCountEqual(keys, res0.columns.names)
self.assertCountEqual(keys, res1.columns.names)
assert_array_equal(
np.array(targ.values, dtype=np.float),
np.array(res0.values, dtype=np.float))
assert_array_equal(
np.array(targ.values, dtype=np.float),
np.array(res1.values, dtype=np.float))
assert_frame_equal(targ, res0)
assert_frame_equal(targ, res1)
def test__multi_epochs_to_dataframe__tuple_default(self):
obj = tuple(fake_neo('Block', seed=i, n=3) for i in range(3))
res0 = ep.multi_epochs_to_dataframe(obj)
objs = (iobj.list_children_by_class('Epoch') for iobj in obj)
objs = list(chain.from_iterable(objs))
targ = [ep.epoch_to_dataframe(iobj) for iobj in objs]
targ = ep._sort_inds(pd.concat(targ, axis=1), axis=1)
keys = ep._extract_neo_attrs_safe(objs[0], parents=True,
child_first=True).keys()
keys = list(keys)
targwidth = len(objs)
targlen = [iobj.times[:min(len(iobj.times), len(iobj.durations),
len(iobj.labels))] for iobj in objs]
targlen = len(np.unique(np.hstack(targlen)))
self.assertGreater(len(objs), 0)
self.assertEqual(targwidth, len(targ.columns))
self.assertEqual(targwidth, len(res0.columns))
self.assertEqual(targlen, len(targ.index))
self.assertEqual(targlen, len(res0.index))
self.assertCountEqual(keys, targ.columns.names)
self.assertCountEqual(keys, res0.columns.names)
assert_array_equal(
np.array(targ.values, dtype=np.float),
np.array(res0.values, dtype=np.float))
assert_frame_equal(targ, res0)
def test__multi_epochs_to_dataframe__iter_default(self):
obj = [fake_neo('Block', seed=i, n=3) for i in range(3)]
res0 = ep.multi_epochs_to_dataframe(iter(obj))
objs = (iobj.list_children_by_class('Epoch') for iobj in obj)
objs = list(chain.from_iterable(objs))
targ = [ep.epoch_to_dataframe(iobj) for iobj in objs]
targ = ep._sort_inds(pd.concat(targ, axis=1), axis=1)
keys = ep._extract_neo_attrs_safe(objs[0], parents=True,
child_first=True).keys()
keys = list(keys)
targwidth = len(objs)
targlen = [iobj.times[:min(len(iobj.times), len(iobj.durations),
len(iobj.labels))] for iobj in objs]
targlen = len(np.unique(np.hstack(targlen)))
self.assertGreater(len(objs), 0)
self.assertEqual(targwidth, len(targ.columns))
self.assertEqual(targwidth, len(res0.columns))
self.assertEqual(targlen, len(targ.index))
self.assertEqual(targlen, len(res0.index))
self.assertCountEqual(keys, targ.columns.names)
self.assertCountEqual(keys, res0.columns.names)
assert_array_equal(
np.array(targ.values, dtype=np.float),
np.array(res0.values, dtype=np.float))
assert_frame_equal(targ, res0)
def test__multi_epochs_to_dataframe__dict_default(self):
obj = dict((i, fake_neo('Block', seed=i, n=3)) for i in range(3))
res0 = ep.multi_epochs_to_dataframe(obj)
objs = (iobj.list_children_by_class('Epoch') for iobj in
obj.values())
objs = list(chain.from_iterable(objs))
targ = [ep.epoch_to_dataframe(iobj) for iobj in objs]
targ = ep._sort_inds(pd.concat(targ, axis=1), axis=1)
keys = ep._extract_neo_attrs_safe(objs[0], parents=True,
child_first=True).keys()
keys = list(keys)
targwidth = len(objs)
targlen = [iobj.times[:min(len(iobj.times), len(iobj.durations),
len(iobj.labels))] for iobj in objs]
targlen = len(np.unique(np.hstack(targlen)))
self.assertGreater(len(objs), 0)
self.assertEqual(targwidth, len(targ.columns))
self.assertEqual(targwidth, len(res0.columns))
self.assertEqual(targlen, len(targ.index))
self.assertEqual(targlen, len(res0.index))
self.assertCountEqual(keys, targ.columns.names)
self.assertCountEqual(keys, res0.columns.names)
assert_array_equal(
np.array(targ.values, dtype=np.float),
np.array(res0.values, dtype=np.float))
assert_frame_equal(targ, res0)
@unittest.skipUnless(HAVE_PANDAS, 'requires pandas')
class SliceSpiketrainTestCase(unittest.TestCase):
def setUp(self):
obj = [fake_neo('SpikeTrain', seed=i, n=3) for i in range(10)]
self.obj = ep.multi_spiketrains_to_dataframe(obj)
def test_single_none(self):
targ_start = self.obj.columns.get_level_values('t_start').values
targ_stop = self.obj.columns.get_level_values('t_stop').values
res0 = ep.slice_spiketrain(self.obj)
res1 = ep.slice_spiketrain(self.obj, t_start=None)
res2 = ep.slice_spiketrain(self.obj, t_stop=None)
res3 = ep.slice_spiketrain(self.obj, t_start=None, t_stop=None)
res0_start = res0.columns.get_level_values('t_start').values
res1_start = res1.columns.get_level_values('t_start').values
res2_start = res2.columns.get_level_values('t_start').values
res3_start = res3.columns.get_level_values('t_start').values
res0_stop = res0.columns.get_level_values('t_stop').values
res1_stop = res1.columns.get_level_values('t_stop').values
res2_stop = res2.columns.get_level_values('t_stop').values
res3_stop = res3.columns.get_level_values('t_stop').values
targ = self.obj
self.assertFalse(res0 is targ)
self.assertFalse(res1 is targ)
self.assertFalse(res2 is targ)
self.assertFalse(res3 is targ)
assert_frame_equal(targ, res0)
assert_frame_equal(targ, res1)
assert_frame_equal(targ, res2)
assert_frame_equal(targ, res3)
assert_array_equal(targ_start, res0_start)
assert_array_equal(targ_start, res1_start)
assert_array_equal(targ_start, res2_start)
assert_array_equal(targ_start, res3_start)
assert_array_equal(targ_stop, res0_stop)
assert_array_equal(targ_stop, res1_stop)
assert_array_equal(targ_stop, res2_stop)
assert_array_equal(targ_stop, res3_stop)
def test_single_t_start(self):
targ_start = .0001
targ_stop = self.obj.columns.get_level_values('t_stop').values
res0 = ep.slice_spiketrain(self.obj, t_start=targ_start)
res1 = ep.slice_spiketrain(self.obj, t_start=targ_start, t_stop=None)
res0_start = res0.columns.get_level_values('t_start').unique().tolist()
res1_start = res1.columns.get_level_values('t_start').unique().tolist()
res0_stop = res0.columns.get_level_values('t_stop').values
res1_stop = res1.columns.get_level_values('t_stop').values
targ = self.obj.values
targ[targ < targ_start] = np.nan
self.assertFalse(res0 is targ)
self.assertFalse(res1 is targ)
assert_array_equal(targ, res0.values)
assert_array_equal(targ, res1.values)
self.assertEqual([targ_start], res0_start)
self.assertEqual([targ_start], res1_start)
assert_array_equal(targ_stop, res0_stop)
assert_array_equal(targ_stop, res1_stop)
def test_single_t_stop(self):
targ_start = self.obj.columns.get_level_values('t_start').values
targ_stop = .0009
res0 = ep.slice_spiketrain(self.obj, t_stop=targ_stop)
res1 = ep.slice_spiketrain(self.obj, t_stop=targ_stop, t_start=None)
res0_start = res0.columns.get_level_values('t_start').values
res1_start = res1.columns.get_level_values('t_start').values
res0_stop = res0.columns.get_level_values('t_stop').unique().tolist()
res1_stop = res1.columns.get_level_values('t_stop').unique().tolist()
targ = self.obj.values
targ[targ > targ_stop] = np.nan
self.assertFalse(res0 is targ)
self.assertFalse(res1 is targ)
assert_array_equal(targ, res0.values)
assert_array_equal(targ, res1.values)
assert_array_equal(targ_start, res0_start)
assert_array_equal(targ_start, res1_start)
self.assertEqual([targ_stop], res0_stop)
self.assertEqual([targ_stop], res1_stop)
def test_single_both(self):
targ_start = .0001
targ_stop = .0009
res0 = ep.slice_spiketrain(self.obj,
t_stop=targ_stop, t_start=targ_start)
res0_start = res0.columns.get_level_values('t_start').unique().tolist()
res0_stop = res0.columns.get_level_values('t_stop').unique().tolist()
targ = self.obj.values
targ[targ < targ_start] = np.nan
targ[targ > targ_stop] = np.nan
self.assertFalse(res0 is targ)
assert_array_equal(targ, res0.values)
self.assertEqual([targ_start], res0_start)
self.assertEqual([targ_stop], res0_stop)
if __name__ == '__main__':
unittest.main()
|
bsd-3-clause
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
199,
5072,
2295,
367,
314,
10634,
13928,
859,
14,
199,
199,
26,
7307,
26,
1898,
6927,
13,
9261,
701,
314,
662,
274,
838,
867,
8099,
12,
1937,
10610,
14,
2424,
14,
199,
26,
1682,
26,
22016,
6289,
12,
1937,
5113,
14,
2424,
367,
2436,
14,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
4629,
12,
870,
63,
1593,
199,
199,
646,
2882,
199,
504,
7975,
492,
6036,
199,
199,
504,
1279,
79,
14,
396,
14,
4208,
63,
12281,
492,
4026,
63,
685,
79,
199,
646,
2680,
465,
980,
199,
504,
2680,
14,
4776,
492,
702,
63,
1144,
63,
1452,
199,
646,
13621,
1417,
465,
29158,
199,
199,
893,
26,
272,
492,
10634,
465,
6454,
272,
687,
10634,
14,
1974,
14,
4776,
492,
702,
63,
1943,
63,
1452,
12,
702,
63,
1080,
63,
1452,
199,
2590,
3545,
26,
272,
25227,
63,
48,
3649,
1179,
275,
756,
199,
2836,
26,
272,
492,
12993,
838,
867,
14,
15718,
63,
9528,
465,
5442,
272,
25227,
63,
48,
3649,
1179,
275,
715,
199,
199,
692,
25227,
63,
48,
3649,
1179,
26,
272,
327,
7319,
651,
316,
12,
4257,
314,
2882,
911,
2059,
543,
10634,
8119,
16,
14,
975,
14,
16,
272,
327,
2725,
1104,
63,
1247,
365,
21399,
315,
282,
15666,
5459,
2419,
378,
14,
1079,
14,
16,
272,
327,
642,
511,
365,
5313,
367,
10634,
378,
14,
1079,
14,
16,
272,
347,
702,
63,
1080,
63,
1452,
8,
3039,
12,
2451,
304,
267,
862,
26,
288,
327,
10634,
8119,
16,
14,
975,
14,
16,
288,
372,
6454,
14,
1974,
14,
4776,
14,
479,
63,
1080,
63,
1452,
8,
3039,
12,
2451,
12,
10028,
1104,
63,
1247,
29,
797,
9,
267,
871,
3146,
26,
288,
327,
10634,
12731,
1015,
288,
372,
6454,
14,
1974,
14,
4776,
14,
479,
63,
1080,
63,
1452,
8,
3039,
12,
2451,
9,
421,
199,
32,
2796,
14,
11278,
8,
10767,
63,
48,
3649,
1179,
12,
283,
6537,
10634,
358,
199,
533,
6879,
1080,
2532,
2141,
1746,
8,
2796,
14,
1746,
304,
272,
347,
511,
363,
3029,
1080,
63,
504,
63,
807,
8,
277,
304,
267,
315,
795,
275,
791,
396,
17,
356,
1227,
14,
21,
12,
355,
283,
396,
18,
356,
959,
12,
355,
283,
396,
19,
356,
283,
396,
936,
267,
26483,
275,
6454,
14,
3947,
2681,
8,
11402,
16025,
22,
14,
21,
467,
359,
21,
467,
788,
396,
2157,
2490,
3628,
16025,
16,
467,
359,
16,
467,
359,
16,
2365,
2490,
1561,
2968,
396,
17,
297,
283,
396,
18,
297,
283,
396,
19,
1105,
267,
522,
16,
275,
5442,
423,
3029,
1080,
63,
504,
63,
807,
8,
18212,
9,
267,
291,
14,
629,
8,
29919,
14,
11402,
12,
522,
16,
14,
11402,
9,
267,
291,
14,
629,
8,
29919,
14,
1247,
12,
522,
16,
14,
1247,
9,
267,
291,
14,
629,
8,
29919,
14,
3512,
12,
522,
16,
14,
3512,
9,
421,
199,
318,
485,
3916,
63,
11402,
8,
11402,
304,
272,
408,
7306,
282,
769,
402,
11106,
370,
314,
1475,
10634,
2529,
367,
282,
6879,
2681,
14,
339,
3897,
272,
4143,
339,
11106,
520,
769,
1467,
710,
769,
402,
11106,
370,
3957,
14,
339,
1803,
272,
5514,
339,
769,
267,
710,
314,
2166,
315,
658,
513,
64,
6702,
370,
1338,
2839,
4052,
10634,
911,
8120,
14,
339,
408,
272,
11106,
275,
769,
8,
11402,
9,
272,
367,
284,
12,
2166,
315,
3874,
8,
11402,
304,
267,
340,
2688,
8,
1896,
12,
283,
2325,
735,
288,
862,
26,
355,
2166,
275,
2649,
8,
1896,
9,
288,
871,
12746,
26,
355,
986,
267,
916,
2688,
8,
1896,
12,
283,
602,
735,
288,
11106,
59,
73,
61,
275,
6454,
14,
19636,
2681,
8,
576,
1524,
1896,
566,
288,
1980,
267,
916,
2166,
365,
488,
26,
288,
11106,
59,
73,
61,
275,
6454,
14,
2681,
4157,
288,
1980,
398,
327,
6454,
14,
2681,
6818,
6454,
14,
2681,
370,
3957,
370,
5499,
5523,
340,
6879,
2681,
267,
11106,
59,
73,
61,
275,
6454,
14,
2681,
8,
8961,
14,
2681,
779,
1896,
2459,
272,
372,
11106,
421,
199,
32,
2796,
14,
11278,
8,
10767,
63,
48,
3649,
1179,
12,
283,
6537,
10634,
358,
199,
533,
7905,
1110,
11090,
1746,
8,
2796,
14,
1746,
304,
272,
347,
511,
363,
3916,
63,
585,
63,
3489,
363,
1609,
8,
277,
304,
267,
26483,
275,
959,
14,
21,
267,
574,
275,
26483,
398,
522,
275,
5442,
423,
3916,
63,
585,
63,
3489,
8,
585,
9,
398,
291,
14,
3436,
8,
470,
12,
26483,
9,
339,
347,
511,
363,
3916,
63,
585,
63,
3489,
363,
495,
8,
277,
304,
267,
26483,
275,
283,
396,
7,
267,
574,
275,
26483,
398,
522,
275,
5442,
423,
3916,
63,
585,
63,
3489,
8,
585,
9,
398,
291,
14,
3436,
8,
470,
12,
26483,
9,
339,
347,
511,
363,
3916,
63,
585,
63,
3489,
363,
2394,
8,
277,
304,
267,
26483,
275,
283,
396,
7,
267,
574,
275,
330,
1133,
597,
7,
398,
522,
275,
5442,
423,
3916,
63,
585,
63,
3489,
8,
585,
9,
398,
291,
14,
629,
8,
470,
12,
26483,
9,
339,
347,
511,
363,
3916,
63,
585,
63,
3489,
363,
4714,
63,
442,
63,
7033,
8,
277,
304,
267,
26483,
275,
959,
267,
574,
275,
980,
14,
1144,
8,
21,
9,
398,
522,
275,
5442,
423,
3916,
63,
585,
63,
3489,
8,
585,
9,
398,
291,
14,
629,
8,
470,
12,
26483,
9,
267,
291,
14,
3334,
8,
11161,
8,
470,
12,
283,
2271,
1333,
339,
347,
511,
363,
3916,
63,
585,
63,
3489,
363,
4714,
63,
1609,
63,
7033,
8,
277,
304,
267,
26483,
275,
959,
14,
267,
574,
275,
980,
14,
1144,
8,
21,
4959,
398,
522,
275,
5442,
423,
3916,
63,
585,
63,
3489,
8,
585,
9,
398,
291,
14,
629,
8,
470,
12,
26483,
9,
267,
291,
14,
3334,
8,
11161,
8,
470,
12,
283,
2271,
1333,
339,
347,
511,
363,
3916,
63,
585,
63,
3489,
363,
4714,
63,
2975,
63,
7033,
8,
277,
304,
267,
26483,
275,
399,
1133,
597,
7,
267,
574,
275,
980,
14,
1144,
360,
396,
297,
2152,
534,
53,
358,
398,
522,
275,
5442,
423,
3916,
63,
585,
63,
3489,
8,
585
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
199,
5072,
2295,
367,
314,
10634,
13928,
859,
14,
199,
199,
26,
7307,
26,
1898,
6927,
13,
9261,
701,
314,
662,
274,
838,
867,
8099,
12,
1937,
10610,
14,
2424,
14,
199,
26,
1682,
26,
22016,
6289,
12,
1937,
5113,
14,
2424,
367,
2436,
14,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
4629,
12,
870,
63,
1593,
199,
199,
646,
2882,
199,
504,
7975,
492,
6036,
199,
199,
504,
1279,
79,
14,
396,
14,
4208,
63,
12281,
492,
4026,
63,
685,
79,
199,
646,
2680,
465,
980,
199,
504,
2680,
14,
4776,
492,
702,
63,
1144,
63,
1452,
199,
646,
13621,
1417,
465,
29158,
199,
199,
893,
26,
272,
492,
10634,
465,
6454,
272,
687,
10634,
14,
1974,
14,
4776,
492,
702,
63,
1943,
63,
1452,
12,
702,
63,
1080,
63,
1452,
199,
2590,
3545,
26,
272,
25227,
63,
48,
3649,
1179,
275,
756,
199,
2836,
26,
272,
492,
12993,
838,
867,
14,
15718,
63,
9528,
465,
5442,
272,
25227,
63,
48,
3649,
1179,
275,
715,
199,
199,
692,
25227,
63,
48,
3649,
1179,
26,
272,
327,
7319,
651,
316,
12,
4257,
314,
2882,
911,
2059,
543,
10634,
8119,
16,
14,
975,
14,
16,
272,
327,
2725,
1104,
63,
1247,
365,
21399,
315,
282,
15666,
5459,
2419,
378,
14,
1079,
14,
16,
272,
327,
642,
511,
365,
5313,
367,
10634,
378,
14,
1079,
14,
16,
272,
347,
702,
63,
1080,
63,
1452,
8,
3039,
12,
2451,
304,
267,
862,
26,
288,
327,
10634,
8119,
16,
14,
975,
14,
16,
288,
372,
6454,
14,
1974,
14,
4776,
14,
479,
63,
1080,
63,
1452,
8,
3039,
12,
2451,
12,
10028,
1104,
63,
1247,
29,
797,
9,
267,
871,
3146,
26,
288,
327,
10634,
12731,
1015,
288,
372,
6454,
14,
1974,
14,
4776,
14,
479,
63,
1080,
63,
1452,
8,
3039,
12,
2451,
9,
421,
199,
32,
2796,
14,
11278,
8,
10767,
63,
48,
3649,
1179,
12,
283,
6537,
10634,
358,
199,
533,
6879,
1080,
2532,
2141,
1746,
8,
2796,
14,
1746,
304,
272,
347,
511,
363,
3029,
1080,
63,
504,
63,
807,
8,
277,
304,
267,
315,
795,
275,
791,
396,
17,
356,
1227,
14,
21,
12,
355,
283,
396,
18,
356,
959,
12,
355,
283,
396,
19,
356,
283,
396,
936,
267,
26483,
275,
6454,
14,
3947,
2681,
8,
11402,
16025,
22,
14,
21,
467,
359,
21,
467,
788,
396,
2157,
2490,
3628,
16025,
16,
467,
359,
16,
467,
359,
16,
2365,
2490,
1561,
2968,
396,
17,
297,
283,
396,
18,
297,
283,
396,
19,
1105,
267,
522,
16,
275,
5442,
423,
3029,
1080,
63,
504,
63,
807,
8,
18212,
9,
267,
291,
14,
629,
8,
29919,
14,
11402,
12,
522,
16,
14,
11402,
9,
267,
291,
14,
629,
8,
29919,
14,
1247,
12,
522,
16,
14,
1247,
9,
267,
291,
14,
629,
8,
29919,
14,
3512,
12,
522,
16,
14,
3512,
9,
421,
199,
318,
485,
3916,
63,
11402,
8,
11402,
304,
272,
408,
7306,
282,
769,
402,
11106,
370,
314,
1475,
10634,
2529,
367,
282,
6879,
2681,
14,
339,
3897,
272,
4143,
339,
11106,
520,
769,
1467,
710,
769,
402,
11106,
370,
3957,
14,
339,
1803,
272,
5514,
339,
769,
267,
710,
314,
2166,
315,
658,
513,
64,
6702,
370,
1338,
2839,
4052,
10634,
911,
8120,
14,
339,
408,
272,
11106,
275,
769,
8,
11402,
9,
272,
367,
284,
12,
2166,
315,
3874,
8,
11402,
304,
267,
340,
2688,
8,
1896,
12,
283,
2325,
735,
288,
862,
26,
355,
2166,
275,
2649,
8,
1896,
9,
288,
871,
12746,
26,
355,
986,
267,
916,
2688,
8,
1896,
12,
283,
602,
735,
288,
11106,
59,
73,
61,
275,
6454,
14,
19636,
2681,
8,
576,
1524,
1896,
566,
288,
1980,
267,
916,
2166,
365,
488,
26,
288,
11106,
59,
73,
61,
275,
6454,
14,
2681,
4157,
288,
1980,
398,
327,
6454,
14,
2681,
6818,
6454,
14,
2681,
370,
3957,
370,
5499,
5523,
340,
6879,
2681,
267,
11106,
59,
73,
61,
275,
6454,
14,
2681,
8,
8961,
14,
2681,
779,
1896,
2459,
272,
372,
11106,
421,
199,
32,
2796,
14,
11278,
8,
10767,
63,
48,
3649,
1179,
12,
283,
6537,
10634,
358,
199,
533,
7905,
1110,
11090,
1746,
8,
2796,
14,
1746,
304,
272,
347,
511,
363,
3916,
63,
585,
63,
3489,
363,
1609,
8,
277,
304,
267,
26483,
275,
959,
14,
21,
267,
574,
275,
26483,
398,
522,
275,
5442,
423,
3916,
63,
585,
63,
3489,
8,
585,
9,
398,
291,
14,
3436,
8,
470,
12,
26483,
9,
339,
347,
511,
363,
3916,
63,
585,
63,
3489,
363,
495,
8,
277,
304,
267,
26483,
275,
283,
396,
7,
267,
574,
275,
26483,
398,
522,
275,
5442,
423,
3916,
63,
585,
63,
3489,
8,
585,
9,
398,
291,
14,
3436,
8,
470,
12,
26483,
9,
339,
347,
511,
363,
3916,
63,
585,
63,
3489,
363,
2394,
8,
277,
304,
267,
26483,
275,
283,
396,
7,
267,
574,
275,
330,
1133,
597,
7,
398,
522,
275,
5442,
423,
3916,
63,
585,
63,
3489,
8,
585,
9,
398,
291,
14,
629,
8,
470,
12,
26483,
9,
339,
347,
511,
363,
3916,
63,
585,
63,
3489,
363,
4714,
63,
442,
63,
7033,
8,
277,
304,
267,
26483,
275,
959,
267,
574,
275,
980,
14,
1144,
8,
21,
9,
398,
522,
275,
5442,
423,
3916,
63,
585,
63,
3489,
8,
585,
9,
398,
291,
14,
629,
8,
470,
12,
26483,
9,
267,
291,
14,
3334,
8,
11161,
8,
470,
12,
283,
2271,
1333,
339,
347,
511,
363,
3916,
63,
585,
63,
3489,
363,
4714,
63,
1609,
63,
7033,
8,
277,
304,
267,
26483,
275,
959,
14,
267,
574,
275,
980,
14,
1144,
8,
21,
4959,
398,
522,
275,
5442,
423,
3916,
63,
585,
63,
3489,
8,
585,
9,
398,
291,
14,
629,
8,
470,
12,
26483,
9,
267,
291,
14,
3334,
8,
11161,
8,
470,
12,
283,
2271,
1333,
339,
347,
511,
363,
3916,
63,
585,
63,
3489,
363,
4714,
63,
2975,
63,
7033,
8,
277,
304,
267,
26483,
275,
399,
1133,
597,
7,
267,
574,
275,
980,
14,
1144,
360,
396,
297,
2152,
534,
53,
358,
398,
522,
275,
5442,
423,
3916,
63,
585,
63,
3489,
8,
585,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# Urwid web site: http://excess.org/urwid/
from operator import attrgetter
from urwid.util import (MetaSuper, decompose_tagmarkup, calc_width,
is_wide_char, move_prev_char, move_next_char)
from urwid.text_layout import calc_pos, calc_coords, shift_line
from urwid import signals
from urwid import text_layout
from urwid.canvas import (CanvasCache, CompositeCanvas, SolidCanvas,
apply_text_layout)
from urwid.command_map import (command_map, CURSOR_LEFT, CURSOR_RIGHT,
CURSOR_UP, CURSOR_DOWN, CURSOR_MAX_LEFT, CURSOR_MAX_RIGHT)
from urwid.split_repr import split_repr, remove_defaults, python3_repr
# define some names for these constants to avoid misspellings in the source
# and to document the constant strings we are using
# Widget sizing methods
FLOW = 'flow'
BOX = 'box'
FIXED = 'fixed'
# Text alignment modes
LEFT = 'left'
RIGHT = 'right'
CENTER = 'center'
# Filler alignment
TOP = 'top'
MIDDLE = 'middle'
BOTTOM = 'bottom'
# Text wrapping modes
SPACE = 'space'
ANY = 'any'
CLIP = 'clip'
# Width and Height settings
PACK = 'pack'
GIVEN = 'given'
RELATIVE = 'relative'
RELATIVE_100 = (RELATIVE, 100)
WEIGHT = 'weight'
class WidgetMeta(MetaSuper, signals.MetaSignals):
"""
Bases: :class:`MetaSuper`, :class:`MetaSignals`
Automatic caching of render and rows methods.
Class variable *no_cache* is a list of names of methods to not cache
automatically. Valid method names for *no_cache* are ``'render'`` and
``'rows'``.
Class variable *ignore_focus* if defined and set to ``True`` indicates
that the canvas this widget renders is not affected by the focus
parameter, so it may be ignored when caching.
"""
def __init__(cls, name, bases, d):
no_cache = d.get("no_cache", [])
super(WidgetMeta, cls).__init__(name, bases, d)
if "render" in d:
if "render" not in no_cache:
render_fn = cache_widget_render(cls)
else:
render_fn = nocache_widget_render(cls)
cls.render = render_fn
if "rows" in d and "rows" not in no_cache:
cls.rows = cache_widget_rows(cls)
if "no_cache" in d:
del cls.no_cache
if "ignore_focus" in d:
del cls.ignore_focus
class WidgetError(Exception):
pass
def validate_size(widget, size, canv):
"""
Raise a WidgetError if a canv does not match size size.
"""
if (size and size[1:] != (0,) and size[0] != canv.cols()) or \
(len(size)>1 and size[1] != canv.rows()):
raise WidgetError("Widget %r rendered (%d x %d) canvas"
" when passed size %r!" % (widget, canv.cols(),
canv.rows(), size))
def update_wrapper(new_fn, fn):
"""
Copy as much of the function detail from fn to new_fn
as we can.
"""
try:
new_fn.__name__ = fn.__name__
new_fn.__dict__.update(fn.__dict__)
new_fn.__doc__ = fn.__doc__
new_fn.__module__ = fn.__module__
except TypeError:
pass # python2.3 ignore read-only attributes
def cache_widget_render(cls):
"""
Return a function that wraps the cls.render() method
and fetches and stores canvases with CanvasCache.
"""
ignore_focus = bool(getattr(cls, "ignore_focus", False))
fn = cls.render
def cached_render(self, size, focus=False):
focus = focus and not ignore_focus
canv = CanvasCache.fetch(self, cls, size, focus)
if canv:
return canv
canv = fn(self, size, focus=focus)
validate_size(self, size, canv)
if canv.widget_info:
canv = CompositeCanvas(canv)
canv.finalize(self, size, focus)
CanvasCache.store(cls, canv)
return canv
cached_render.original_fn = fn
update_wrapper(cached_render, fn)
return cached_render
def nocache_widget_render(cls):
"""
Return a function that wraps the cls.render() method
and finalizes the canvas that it returns.
"""
fn = cls.render
if hasattr(fn, "original_fn"):
fn = fn.original_fn
def finalize_render(self, size, focus=False):
canv = fn(self, size, focus=focus)
if canv.widget_info:
canv = CompositeCanvas(canv)
validate_size(self, size, canv)
canv.finalize(self, size, focus)
return canv
finalize_render.original_fn = fn
update_wrapper(finalize_render, fn)
return finalize_render
def nocache_widget_render_instance(self):
"""
Return a function that wraps the cls.render() method
and finalizes the canvas that it returns, but does not
cache the canvas.
"""
fn = self.render.original_fn
def finalize_render(size, focus=False):
canv = fn(self, size, focus=focus)
if canv.widget_info:
canv = CompositeCanvas(canv)
canv.finalize(self, size, focus)
return canv
finalize_render.original_fn = fn
update_wrapper(finalize_render, fn)
return finalize_render
def cache_widget_rows(cls):
"""
Return a function that wraps the cls.rows() method
and returns rows from the CanvasCache if available.
"""
ignore_focus = bool(getattr(cls, "ignore_focus", False))
fn = cls.rows
def cached_rows(self, size, focus=False):
focus = focus and not ignore_focus
canv = CanvasCache.fetch(self, cls, size, focus)
if canv:
return canv.rows()
return fn(self, size, focus)
update_wrapper(cached_rows, fn)
return cached_rows
class Widget(object):
"""
Widget base class
.. attribute:: __metaclass__
:annotation: = urwid.WidgetMeta
See :class:`urwid.WidgetMeta` definition
.. attribute:: _selectable
:annotation: = False
The default :meth:`.selectable` method returns this
value.
.. attribute:: _sizing
:annotation: = frozenset(['flow', 'box', 'fixed'])
The default :meth:`.sizing` method returns this value.
.. attribute:: _command_map
:annotation: = urwid.command_map
A shared :class:`CommandMap` instance. May be redefined
in subclasses or widget instances.
.. method:: render(size, focus=False)
.. note::
This method is not implemented in :class:`.Widget` but
must be implemented by any concrete subclass
:param size: One of the following,
*maxcol* and *maxrow* are integers > 0:
(*maxcol*, *maxrow*)
for box sizing -- the parent chooses the exact
size of this widget
(*maxcol*,)
for flow sizing -- the parent chooses only the
number of columns for this widget
()
for fixed sizing -- this widget is a fixed size
which can't be adjusted by the parent
:type size: widget size
:param focus: set to ``True`` if this widget or one of its children
is in focus
:type focus: bool
:returns: A :class:`Canvas` subclass instance containing the
rendered content of this widget
:class:`Text` widgets return a :class:`TextCanvas` (arbitrary text and
display attributes), :class:`SolidFill` widgets return a
:class:`SolidCanvas` (a single character repeated across
the whole surface) and container widgets return a
:class:`CompositeCanvas` (one or more other canvases
arranged arbitrarily).
If *focus* is ``False``, the returned canvas may not have a cursor
position set.
There is some metaclass magic defined in the :class:`Widget`
metaclass :class:`WidgetMeta` that causes the
result of this method to be cached by :class:`CanvasCache`.
Later calls will automatically look up the value in the cache first.
As a small optimization the class variable :attr:`ignore_focus`
may be defined and set to ``True`` if this widget renders the same
canvas regardless of the value of the *focus* parameter.
Any time the content of a widget changes it should call
:meth:`_invalidate` to remove any cached canvases, or the widget
may render the cached canvas instead of creating a new one.
.. method:: rows(size, focus=False)
.. note::
This method is not implemented in :class:`.Widget` but
must be implemented by any flow widget. See :meth:`.sizing`.
See :meth:`Widget.render` for parameter details.
:returns: The number of rows required for this widget given a number
of columns in *size*
This is the method flow widgets use to communicate their size to other
widgets without having to render a canvas. This should be a quick
calculation as this function may be called a number of times in normal
operation. If your implementation may take a long time you should add
your own caching here.
There is some metaclass magic defined in the :class:`Widget`
metaclass :class:`WidgetMeta` that causes the
result of this function to be retrieved from any
canvas cached by :class:`CanvasCache`, so if your widget
has been rendered you may not receive calls to this function. The class
variable :attr:`ignore_focus` may be defined and set to ``True`` if this
widget renders the same size regardless of the value of the *focus*
parameter.
.. method:: keypress(size, key)
.. note::
This method is not implemented in :class:`.Widget` but
must be implemented by any selectable widget.
See :meth:`.selectable`.
:param size: See :meth:`Widget.render` for details
:type size: widget size
:param key: a single keystroke value; see :ref:`keyboard-input`
:type key: bytes or unicode
:returns: ``None`` if *key* was handled by this widget or
*key* (the same value passed) if *key* was not handled
by this widget
Container widgets will typically call the :meth:`keypress` method on
whichever of their children is set as the focus.
The standard widgets use :attr:`_command_map` to
determine what action should be performed for a given *key*. You may
modify these values to your liking globally, at some level in the
widget hierarchy or on individual widgets. See :class:`CommandMap`
for the defaults.
In your own widgets you may use whatever logic you like: filtering or
translating keys, selectively passing along events etc.
.. method:: mouse_event(size, event, button, col, row, focus)
.. note::
This method is not implemented in :class:`.Widget` but
may be implemented by a subclass. Not implementing this
method is equivalent to having a method that always returns
``False``.
:param size: See :meth:`Widget.render` for details.
:type size: widget size
:param event: Values such as ``'mouse press'``, ``'ctrl mouse press'``,
``'mouse release'``, ``'meta mouse release'``,
``'mouse drag'``; see :ref:`mouse-input`
:type event: mouse event
:param button: 1 through 5 for press events, often 0 for release events
(which button was released is often not known)
:type button: int
:param col: Column of the event, 0 is the left edge of this widget
:type col: int
:param row: Row of the event, 0 it the top row of this widget
:type row: int
:param focus: Set to ``True`` if this widget or one of its children
is in focus
:type focus: bool
:returns: ``True`` if the event was handled by this widget, ``False``
otherwise
Container widgets will typically call the :meth:`mouse_event` method on
whichever of their children is at the position (*col*, *row*).
.. method:: get_cursor_coords(size)
.. note::
This method is not implemented in :class:`.Widget` but
must be implemented by any widget that may return cursor
coordinates as part of the canvas that :meth:`render` returns.
:param size: See :meth:`Widget.render` for details.
:type size: widget size
:returns: (*col*, *row*) if this widget has a cursor, ``None`` otherwise
Return the cursor coordinates (*col*, *row*) of a cursor that will appear
as part of the canvas rendered by this widget when in focus, or ``None``
if no cursor is displayed.
The :class:`ListBox` widget
uses this method to make sure a cursor in the focus widget is not
scrolled out of view. It is a separate method to avoid having to render
the whole widget while calculating layout.
Container widgets will typically call the :meth:`.get_cursor_coords`
method on their focus widget.
.. method:: get_pref_col(size)
.. note::
This method is not implemented in :class:`.Widget` but
may be implemented by a subclass.
:param size: See :meth:`Widget.render` for details.
:type size: widget size
:returns: a column number or ``'left'`` for the leftmost available
column or ``'right'`` for the rightmost available column
Return the preferred column for the cursor to be displayed in this
widget. This value might not be the same as the column returned from
:meth:`get_cursor_coords`.
The :class:`ListBox` and :class:`Pile`
widgets call this method on a widget losing focus and use the value
returned to call :meth:`.move_cursor_to_coords` on the widget becoming
the focus. This allows the focus to move up and down through widgets
while keeping the cursor in approximately the same column on screen.
.. method:: move_cursor_to_coords(size, col, row)
.. note::
This method is not implemented in :class:`.Widget` but
may be implemented by a subclass. Not implementing this
method is equivalent to having a method that always returns
``False``.
:param size: See :meth:`Widget.render` for details.
:type size: widget size
:param col: new column for the cursor, 0 is the left edge of this widget
:type col: int
:param row: new row for the cursor, 0 it the top row of this widget
:type row: int
:returns: ``True`` if the position was set successfully anywhere on
*row*, ``False`` otherwise
"""
__metaclass__ = WidgetMeta
_selectable = False
_sizing = frozenset([FLOW, BOX, FIXED])
_command_map = command_map
def _invalidate(self):
"""
Mark cached canvases rendered by this widget as dirty so that
they will not be used again.
"""
CanvasCache.invalidate(self)
def _emit(self, name, *args):
"""
Convenience function to emit signals with self as first
argument.
"""
signals.emit_signal(self, name, self, *args)
def selectable(self):
"""
:returns: ``True`` if this is a widget that is designed to take the
focus, i.e. it contains something the user might want to
interact with, ``False`` otherwise,
This default implementation returns :attr:`._selectable`.
Subclasses may leave these is if the are not selectable,
or if they are always selectable they may
set the :attr:`_selectable` class variable to ``True``.
If this method returns ``True`` then the :meth:`.keypress` method
must be implemented.
Returning ``False`` does not guarantee that this widget will never be in
focus, only that this widget will usually be skipped over when changing
focus. It is still possible for non selectable widgets to have the focus
(typically when there are no other selectable widgets visible).
"""
return self._selectable
def sizing(self):
"""
:returns: A frozenset including one or more of ``'box'``, ``'flow'`` and
``'fixed'``. Default implementation returns the value of
:attr:`._sizing`, which for this class includes all three.
The sizing modes returned indicate the modes that may be
supported by this widget, but is not sufficient to know
that using that sizing mode will work. Subclasses should
make an effort to remove sizing modes they know will not
work given the state of the widget, but many do not yet
do this.
If a sizing mode is missing from the set then the widget
should fail when used in that mode.
If ``'flow'`` is among the values returned then the other
methods in this widget must be able to accept a
single-element tuple (*maxcol*,) to their ``size``
parameter, and the :meth:`rows` method must be defined.
If ``'box'`` is among the values returned then the other
methods must be able to accept a two-element tuple
(*maxcol*, *maxrow*) to their size paramter.
If ``'fixed'`` is among the values returned then the other
methods must be able to accept an empty tuple () to
their size parameter, and the :meth:`pack` method must
be defined.
"""
return self._sizing
def pack(self, size, focus=False):
"""
See :meth:`Widget.render` for parameter details.
:returns: A "packed" size (*maxcol*, *maxrow*) for this widget
Calculate and return a minimum
size where all content could still be displayed. Fixed widgets must
implement this method and return their size when ``()`` is passed as the
*size* parameter.
This default implementation returns the *size* passed, or the *maxcol*
passed and the value of :meth:`rows` as the *maxrow* when (*maxcol*,)
is passed as the *size* parameter.
.. note::
This is a new method that hasn't been fully implemented across the
standard widget types. In particular it has not yet been
implemented for container widgets.
:class:`Text` widgets have implemented this method.
You can use :meth:`Text.pack` to calculate the minumum
columns and rows required to display a text widget without wrapping,
or call it iteratively to calculate the minimum number of columns
required to display the text wrapped into a target number of rows.
"""
if not size:
if FIXED in self.sizing():
raise NotImplementedError('Fixed widgets must override'
' Widget.pack()')
raise WidgetError('Cannot pack () size, this is not a fixed'
' widget: %s' % repr(self))
elif len(size) == 1:
if FLOW in self.sizing():
return size + (self.rows(size, focus),)
raise WidgetError('Cannot pack (maxcol,) size, this is not a'
' flow widget: %s' % repr(self))
return size
base_widget = property(lambda self:self, doc="""
Read-only property that steps through decoration widgets
and returns the one at the base. This default implementation
returns self.
""")
focus = property(lambda self:None, doc="""
Read-only property returning the child widget in focus for
container widgets. This default implementation
always returns ``None``, indicating that this widget has no children.
""")
def _not_a_container(self, val=None):
raise IndexError(
"No focus_position, %r is not a container widget" % self)
focus_position = property(_not_a_container, _not_a_container, doc="""
Property for reading and setting the focus position for
container widgets. This default implementation raises
:exc:`IndexError`, making normal widgets fail the same way
accessing :attr:`.focus_position` on an empty container widget would.
""")
def __repr__(self):
"""
A friendly __repr__ for widgets, designed to be extended
by subclasses with _repr_words and _repr_attr methods.
"""
return split_repr(self)
def _repr_words(self):
words = []
if self.selectable():
words = ["selectable"] + words
if self.sizing() and self.sizing() != frozenset([FLOW, BOX, FIXED]):
sizing_modes = list(self.sizing())
sizing_modes.sort()
words.append("/".join(sizing_modes))
return words + ["widget"]
def _repr_attrs(self):
return {}
class FlowWidget(Widget):
"""
Deprecated. Inherit from Widget and add:
_sizing = frozenset(['flow'])
at the top of your class definition instead.
Base class of widgets that determine their rows from the number of
columns available.
"""
_sizing = frozenset([FLOW])
def rows(self, size, focus=False):
"""
All flow widgets must implement this function.
"""
raise NotImplementedError()
def render(self, size, focus=False):
"""
All widgets must implement this function.
"""
raise NotImplementedError()
class BoxWidget(Widget):
"""
Deprecated. Inherit from Widget and add:
_sizing = frozenset(['box'])
_selectable = True
at the top of your class definition instead.
Base class of width and height constrained widgets such as
the top level widget attached to the display object
"""
_selectable = True
_sizing = frozenset([BOX])
def render(self, size, focus=False):
"""
All widgets must implement this function.
"""
raise NotImplementedError()
def fixed_size(size):
"""
raise ValueError if size != ().
Used by FixedWidgets to test size parameter.
"""
if size != ():
raise ValueError("FixedWidget takes only () for size." \
"passed: %r" % (size,))
class FixedWidget(Widget):
"""
Deprecated. Inherit from Widget and add:
_sizing = frozenset(['fixed'])
at the top of your class definition instead.
Base class of widgets that know their width and height and
cannot be resized
"""
_sizing = frozenset([FIXED])
def render(self, size, focus=False):
"""
All widgets must implement this function.
"""
raise NotImplementedError()
def pack(self, size=None, focus=False):
"""
All fixed widgets must implement this function.
"""
raise NotImplementedError()
class Divider(Widget):
"""
Horizontal divider widget
"""
_sizing = frozenset([FLOW])
ignore_focus = True
def __init__(self,div_char=u" ",top=0,bottom=0):
"""
:param div_char: character to repeat across line
:type div_char: bytes or unicode
:param top: number of blank lines above
:type top: int
:param bottom: number of blank lines below
:type bottom: int
>>> Divider()
<Divider flow widget>
>>> Divider(u'-')
<Divider flow widget '-'>
>>> Divider(u'x', 1, 2)
<Divider flow widget 'x' bottom=2 top=1>
"""
self.__super.__init__()
self.div_char = div_char
self.top = top
self.bottom = bottom
def _repr_words(self):
return self.__super._repr_words() + [
python3_repr(self.div_char)] * (self.div_char != u" ")
def _repr_attrs(self):
attrs = dict(self.__super._repr_attrs())
if self.top: attrs['top'] = self.top
if self.bottom: attrs['bottom'] = self.bottom
return attrs
def rows(self, size, focus=False):
"""
Return the number of lines that will be rendered.
>>> Divider().rows((10,))
1
>>> Divider(u'x', 1, 2).rows((10,))
4
"""
(maxcol,) = size
return self.top + 1 + self.bottom
def render(self, size, focus=False):
"""
Render the divider as a canvas and return it.
>>> Divider().render((10,)).text # ... = b in Python 3
[...' ']
>>> Divider(u'-', top=1).render((10,)).text
[...' ', ...'----------']
>>> Divider(u'x', bottom=2).render((5,)).text
[...'xxxxx', ...' ', ...' ']
"""
(maxcol,) = size
canv = SolidCanvas(self.div_char, maxcol, 1)
canv = CompositeCanvas(canv)
if self.top or self.bottom:
canv.pad_trim_top_bottom(self.top, self.bottom)
return canv
class SolidFill(BoxWidget):
"""
A box widget that fills an area with a single character
"""
_selectable = False
ignore_focus = True
def __init__(self, fill_char=" "):
"""
:param fill_char: character to fill area with
:type fill_char: bytes or unicode
>>> SolidFill(u'8')
<SolidFill box widget '8'>
"""
self.__super.__init__()
self.fill_char = fill_char
def _repr_words(self):
return self.__super._repr_words() + [python3_repr(self.fill_char)]
def render(self, size, focus=False ):
"""
Render the Fill as a canvas and return it.
>>> SolidFill().render((4,2)).text # ... = b in Python 3
[...' ', ...' ']
>>> SolidFill('#').render((5,3)).text
[...'#####', ...'#####', ...'#####']
"""
maxcol, maxrow = size
return SolidCanvas(self.fill_char, maxcol, maxrow)
class TextError(Exception):
pass
class Text(Widget):
"""
a horizontally resizeable text widget
"""
_sizing = frozenset([FLOW])
ignore_focus = True
_repr_content_length_max = 140
def __init__(self, markup, align=LEFT, wrap=SPACE, layout=None):
"""
:param markup: content of text widget, one of:
bytes or unicode
text to be displayed
(*display attribute*, *text markup*)
*text markup* with *display attribute* applied to all parts
of *text markup* with no display attribute already applied
[*text markup*, *text markup*, ... ]
all *text markup* in the list joined together
:type markup: :ref:`text-markup`
:param align: typically ``'left'``, ``'center'`` or ``'right'``
:type align: text alignment mode
:param wrap: typically ``'space'``, ``'any'`` or ``'clip'``
:type wrap: text wrapping mode
:param layout: defaults to a shared :class:`StandardTextLayout` instance
:type layout: text layout instance
>>> Text(u"Hello")
<Text flow widget 'Hello'>
>>> t = Text(('bold', u"stuff"), 'right', 'any')
>>> t
<Text flow widget 'stuff' align='right' wrap='any'>
>>> print t.text
stuff
>>> t.attrib
[('bold', 5)]
"""
self.__super.__init__()
self._cache_maxcol = None
self.set_text(markup)
self.set_layout(align, wrap, layout)
def _repr_words(self):
"""
Show the text in the repr in python3 format (b prefix for byte
strings) and truncate if it's too long
"""
first = self.__super._repr_words()
text = self.get_text()[0]
rest = python3_repr(text)
if len(rest) > self._repr_content_length_max:
rest = (rest[:self._repr_content_length_max * 2 // 3 - 3] +
'...' + rest[-self._repr_content_length_max // 3:])
return first + [rest]
def _repr_attrs(self):
attrs = dict(self.__super._repr_attrs(),
align=self._align_mode,
wrap=self._wrap_mode)
return remove_defaults(attrs, Text.__init__)
def _invalidate(self):
self._cache_maxcol = None
self.__super._invalidate()
def set_text(self,markup):
"""
Set content of text widget.
:param markup: see :class:`Text` for description.
:type markup: text markup
>>> t = Text(u"foo")
>>> print t.text
foo
>>> t.set_text(u"bar")
>>> print t.text
bar
>>> t.text = u"baz" # not supported because text stores text but set_text() takes markup
Traceback (most recent call last):
AttributeError: can't set attribute
"""
self._text, self._attrib = decompose_tagmarkup(markup)
self._invalidate()
def get_text(self):
"""
:returns: (*text*, *display attributes*)
*text*
complete bytes/unicode content of text widget
*display attributes*
run length encoded display attributes for *text*, eg.
``[('attr1', 10), ('attr2', 5)]``
>>> Text(u"Hello").get_text() # ... = u in Python 2
(...'Hello', [])
>>> Text(('bright', u"Headline")).get_text()
(...'Headline', [('bright', 8)])
>>> Text([('a', u"one"), u"two", ('b', u"three")]).get_text()
(...'onetwothree', [('a', 3), (None, 3), ('b', 5)])
"""
return self._text, self._attrib
text = property(lambda self:self.get_text()[0], doc="""
Read-only property returning the complete bytes/unicode content
of this widget
""")
attrib = property(lambda self:self.get_text()[1], doc="""
Read-only property returning the run-length encoded display
attributes of this widget
""")
def set_align_mode(self, mode):
"""
Set text alignment mode. Supported modes depend on text layout
object in use but defaults to a :class:`StandardTextLayout` instance
:param mode: typically ``'left'``, ``'center'`` or ``'right'``
:type mode: text alignment mode
>>> t = Text(u"word")
>>> t.set_align_mode('right')
>>> t.align
'right'
>>> t.render((10,)).text # ... = b in Python 3
[...' word']
>>> t.align = 'center'
>>> t.render((10,)).text
[...' word ']
>>> t.align = 'somewhere'
Traceback (most recent call last):
TextError: Alignment mode 'somewhere' not supported.
"""
if not self.layout.supports_align_mode(mode):
raise TextError("Alignment mode %r not supported."%
(mode,))
self._align_mode = mode
self._invalidate()
def set_wrap_mode(self, mode):
"""
Set text wrapping mode. Supported modes depend on text layout
object in use but defaults to a :class:`StandardTextLayout` instance
:param mode: typically ``'space'``, ``'any'`` or ``'clip'``
:type mode: text wrapping mode
>>> t = Text(u"some words")
>>> t.render((6,)).text # ... = b in Python 3
[...'some ', ...'words ']
>>> t.set_wrap_mode('clip')
>>> t.wrap
'clip'
>>> t.render((6,)).text
[...'some w']
>>> t.wrap = 'any' # Urwid 0.9.9 or later
>>> t.render((6,)).text
[...'some w', ...'ords ']
>>> t.wrap = 'somehow'
Traceback (most recent call last):
TextError: Wrap mode 'somehow' not supported.
"""
if not self.layout.supports_wrap_mode(mode):
raise TextError("Wrap mode %r not supported."%(mode,))
self._wrap_mode = mode
self._invalidate()
def set_layout(self, align, wrap, layout=None):
"""
Set the text layout object, alignment and wrapping modes at
the same time.
:type align: text alignment mode
:param wrap: typically 'space', 'any' or 'clip'
:type wrap: text wrapping mode
:param layout: defaults to a shared :class:`StandardTextLayout` instance
:type layout: text layout instance
>>> t = Text(u"hi")
>>> t.set_layout('right', 'clip')
>>> t
<Text flow widget 'hi' align='right' wrap='clip'>
"""
if layout is None:
layout = text_layout.default_layout
self._layout = layout
self.set_align_mode(align)
self.set_wrap_mode(wrap)
align = property(lambda self:self._align_mode, set_align_mode)
wrap = property(lambda self:self._wrap_mode, set_wrap_mode)
layout = property(lambda self:self._layout)
def render(self, size, focus=False):
"""
Render contents with wrapping and alignment. Return canvas.
See :meth:`Widget.render` for parameter details.
>>> Text(u"important things").render((18,)).text # ... = b in Python 3
[...'important things ']
>>> Text(u"important things").render((11,)).text
[...'important ', ...'things ']
"""
(maxcol,) = size
text, attr = self.get_text()
#assert isinstance(text, unicode)
trans = self.get_line_translation( maxcol, (text,attr) )
return apply_text_layout(text, attr, trans, maxcol)
def rows(self, size, focus=False):
"""
Return the number of rows the rendered text requires.
See :meth:`Widget.rows` for parameter details.
>>> Text(u"important things").rows((18,))
1
>>> Text(u"important things").rows((11,))
2
"""
(maxcol,) = size
return len(self.get_line_translation(maxcol))
def get_line_translation(self, maxcol, ta=None):
"""
Return layout structure used to map self.text to a canvas.
This method is used internally, but may be useful for
debugging custom layout classes.
:param maxcol: columns available for display
:type maxcol: int
:param ta: ``None`` or the (*text*, *display attributes*) tuple
returned from :meth:`.get_text`
:type ta: text and display attributes
"""
if not self._cache_maxcol or self._cache_maxcol != maxcol:
self._update_cache_translation(maxcol, ta)
return self._cache_translation
def _update_cache_translation(self,maxcol, ta):
if ta:
text, attr = ta
else:
text, attr = self.get_text()
self._cache_maxcol = maxcol
self._cache_translation = self._calc_line_translation(
text, maxcol )
def _calc_line_translation(self, text, maxcol ):
return self.layout.layout(
text, self._cache_maxcol,
self._align_mode, self._wrap_mode )
def pack(self, size=None, focus=False):
"""
Return the number of screen columns and rows required for
this Text widget to be displayed without wrapping or
clipping, as a single element tuple.
:param size: ``None`` for unlimited screen columns or (*maxcol*,) to
specify a maximum column size
:type size: widget size
>>> Text(u"important things").pack()
(16, 1)
>>> Text(u"important things").pack((15,))
(9, 2)
>>> Text(u"important things").pack((8,))
(8, 2)
"""
text, attr = self.get_text()
if size is not None:
(maxcol,) = size
if not hasattr(self.layout, "pack"):
return size
trans = self.get_line_translation( maxcol, (text,attr))
cols = self.layout.pack( maxcol, trans )
return (cols, len(trans))
i = 0
cols = 0
while i < len(text):
j = text.find('\n', i)
if j == -1:
j = len(text)
c = calc_width(text, i, j)
if c>cols:
cols = c
i = j+1
return (cols, text.count('\n') + 1)
class EditError(TextError):
pass
class Edit(Text):
"""
Text editing widget implements cursor movement, text insertion and
deletion. A caption may prefix the editing area. Uses text class
for text layout.
Users of this class to listen for ``"change"`` events
sent when the value of edit_text changes. See :func:``connect_signal``.
"""
# (this variable is picked up by the MetaSignals metaclass)
signals = ["change"]
def valid_char(self, ch):
"""
Filter for text that may be entered into this widget by the user
:param ch: character to be inserted
:type ch: bytes or unicode
This implementation returns True for all printable characters.
"""
return is_wide_char(ch,0) or (len(ch)==1 and ord(ch) >= 32)
def selectable(self): return True
def __init__(self, caption=u"", edit_text=u"", multiline=False,
align=LEFT, wrap=SPACE, allow_tab=False,
edit_pos=None, layout=None, mask=None):
"""
:param caption: markup for caption preceeding edit_text, see
:class:`Text` for description of text markup.
:type caption: text markup
:param edit_text: initial text for editing, type (bytes or unicode)
must match the text in the caption
:type edit_text: bytes or unicode
:param multiline: True: 'enter' inserts newline False: return it
:type multiline: bool
:param align: typically 'left', 'center' or 'right'
:type align: text alignment mode
:param wrap: typically 'space', 'any' or 'clip'
:type wrap: text wrapping mode
:param allow_tab: True: 'tab' inserts 1-8 spaces False: return it
:type allow_tab: bool
:param edit_pos: initial position for cursor, None:end of edit_text
:type edit_pos: int
:param layout: defaults to a shared :class:`StandardTextLayout` instance
:type layout: text layout instance
:param mask: hide text entered with this character, None:disable mask
:type mask: bytes or unicode
>>> Edit()
<Edit selectable flow widget '' edit_pos=0>
>>> Edit(u"Y/n? ", u"yes")
<Edit selectable flow widget 'yes' caption='Y/n? ' edit_pos=3>
>>> Edit(u"Name ", u"Smith", edit_pos=1)
<Edit selectable flow widget 'Smith' caption='Name ' edit_pos=1>
>>> Edit(u"", u"3.14", align='right')
<Edit selectable flow widget '3.14' align='right' edit_pos=4>
"""
self.__super.__init__("", align, wrap, layout)
self.multiline = multiline
self.allow_tab = allow_tab
self._edit_pos = 0
self.set_caption(caption)
self.set_edit_text(edit_text)
if edit_pos is None:
edit_pos = len(edit_text)
self.set_edit_pos(edit_pos)
self.set_mask(mask)
self._shift_view_to_cursor = False
def _repr_words(self):
return self.__super._repr_words()[:-1] + [
python3_repr(self._edit_text)] + [
'caption=' + python3_repr(self._caption)] * bool(self._caption) + [
'multiline'] * (self.multiline is True)
def _repr_attrs(self):
attrs = dict(self.__super._repr_attrs(),
edit_pos=self._edit_pos)
return remove_defaults(attrs, Edit.__init__)
def get_text(self):
"""
Returns ``(text, display attributes)``. See :meth:`Text.get_text`
for details.
Text returned includes the caption and edit_text, possibly masked.
>>> Edit(u"What? ","oh, nothing.").get_text() # ... = u in Python 2
(...'What? oh, nothing.', [])
>>> Edit(('bright',u"user@host:~$ "),"ls").get_text()
(...'user@host:~$ ls', [('bright', 13)])
>>> Edit(u"password:", u"seekrit", mask=u"*").get_text()
(...'password:*******', [])
"""
if self._mask is None:
return self._caption + self._edit_text, self._attrib
else:
return self._caption + (self._mask * len(self._edit_text)), self._attrib
def set_text(self, markup):
"""
Not supported by Edit widget.
>>> Edit().set_text("test")
Traceback (most recent call last):
EditError: set_text() not supported. Use set_caption() or set_edit_text() instead.
"""
# FIXME: this smells. reimplement Edit as a WidgetWrap subclass to
# clean this up
# hack to let Text.__init__() work
if not hasattr(self, '_text') and markup == "":
self._text = None
return
raise EditError("set_text() not supported. Use set_caption()"
" or set_edit_text() instead.")
def get_pref_col(self, size):
"""
Return the preferred column for the cursor, or the
current cursor x value. May also return ``'left'`` or ``'right'``
to indicate the leftmost or rightmost column available.
This method is used internally and by other widgets when
moving the cursor up or down between widgets so that the
column selected is one that the user would expect.
>>> size = (10,)
>>> Edit().get_pref_col(size)
0
>>> e = Edit(u"", u"word")
>>> e.get_pref_col(size)
4
>>> e.keypress(size, 'left')
>>> e.get_pref_col(size)
3
>>> e.keypress(size, 'end')
>>> e.get_pref_col(size)
'right'
>>> e = Edit(u"", u"2\\nwords")
>>> e.keypress(size, 'left')
>>> e.keypress(size, 'up')
>>> e.get_pref_col(size)
4
>>> e.keypress(size, 'left')
>>> e.get_pref_col(size)
0
"""
(maxcol,) = size
pref_col, then_maxcol = self.pref_col_maxcol
if then_maxcol != maxcol:
return self.get_cursor_coords((maxcol,))[0]
else:
return pref_col
def update_text(self):
"""
No longer supported.
>>> Edit().update_text()
Traceback (most recent call last):
EditError: update_text() has been removed. Use set_caption() or set_edit_text() instead.
"""
raise EditError("update_text() has been removed. Use "
"set_caption() or set_edit_text() instead.")
def set_caption(self, caption):
"""
Set the caption markup for this widget.
:param caption: markup for caption preceeding edit_text, see
:meth:`Text.__init__` for description of text markup.
>>> e = Edit("")
>>> e.set_caption("cap1")
>>> print e.caption
cap1
>>> e.set_caption(('bold', "cap2"))
>>> print e.caption
cap2
>>> e.attrib
[('bold', 4)]
>>> e.caption = "cap3" # not supported because caption stores text but set_caption() takes markup
Traceback (most recent call last):
AttributeError: can't set attribute
"""
self._caption, self._attrib = decompose_tagmarkup(caption)
self._invalidate()
caption = property(lambda self:self._caption)
def set_edit_pos(self, pos):
"""
Set the cursor position with a self.edit_text offset.
Clips pos to [0, len(edit_text)].
:param pos: cursor position
:type pos: int
>>> e = Edit(u"", u"word")
>>> e.edit_pos
4
>>> e.set_edit_pos(2)
>>> e.edit_pos
2
>>> e.edit_pos = -1 # Urwid 0.9.9 or later
>>> e.edit_pos
0
>>> e.edit_pos = 20
>>> e.edit_pos
4
"""
if pos < 0:
pos = 0
if pos > len(self._edit_text):
pos = len(self._edit_text)
self.highlight = None
self.pref_col_maxcol = None, None
self._edit_pos = pos
self._invalidate()
edit_pos = property(lambda self:self._edit_pos, set_edit_pos)
def set_mask(self, mask):
"""
Set the character for masking text away.
:param mask: hide text entered with this character, None:disable mask
:type mask: bytes or unicode
"""
self._mask = mask
self._invalidate()
def set_edit_text(self, text):
"""
Set the edit text for this widget.
:param text: text for editing, type (bytes or unicode)
must match the text in the caption
:type text: bytes or unicode
>>> e = Edit()
>>> e.set_edit_text(u"yes")
>>> print e.edit_text
yes
>>> e
<Edit selectable flow widget 'yes' edit_pos=0>
>>> e.edit_text = u"no" # Urwid 0.9.9 or later
>>> print e.edit_text
no
"""
text = self._normalize_to_caption(text)
self.highlight = None
self._emit("change", text)
self._edit_text = text
if self.edit_pos > len(text):
self.edit_pos = len(text)
self._invalidate()
def get_edit_text(self):
"""
Return the edit text for this widget.
>>> e = Edit(u"What? ", u"oh, nothing.")
>>> print e.get_edit_text()
oh, nothing.
>>> print e.edit_text
oh, nothing.
"""
return self._edit_text
edit_text = property(get_edit_text, set_edit_text, doc="""
Read-only property returning the edit text for this widget.
""")
def insert_text(self, text):
"""
Insert text at the cursor position and update cursor.
This method is used by the keypress() method when inserting
one or more characters into edit_text.
:param text: text for inserting, type (bytes or unicode)
must match the text in the caption
:type text: bytes or unicode
>>> e = Edit(u"", u"42")
>>> e.insert_text(u".5")
>>> e
<Edit selectable flow widget '42.5' edit_pos=4>
>>> e.set_edit_pos(2)
>>> e.insert_text(u"a")
>>> print e.edit_text
42a.5
"""
text = self._normalize_to_caption(text)
result_text, result_pos = self.insert_text_result(text)
self.set_edit_text(result_text)
self.set_edit_pos(result_pos)
self.highlight = None
def _normalize_to_caption(self, text):
"""
Return text converted to the same type as self.caption
(bytes or unicode)
"""
tu = isinstance(text, unicode)
cu = isinstance(self._caption, unicode)
if tu == cu:
return text
if tu:
return text.encode('ascii') # follow python2's implicit conversion
return text.decode('ascii')
def insert_text_result(self, text):
"""
Return result of insert_text(text) without actually performing the
insertion. Handy for pre-validation.
:param text: text for inserting, type (bytes or unicode)
must match the text in the caption
:type text: bytes or unicode
"""
# if there's highlighted text, it'll get replaced by the new text
text = self._normalize_to_caption(text)
if self.highlight:
start, stop = self.highlight
btext, etext = self.edit_text[:start], self.edit_text[stop:]
result_text = btext + etext
result_pos = start
else:
result_text = self.edit_text
result_pos = self.edit_pos
try:
result_text = (result_text[:result_pos] + text +
result_text[result_pos:])
except:
assert 0, repr((self.edit_text, result_text, text))
result_pos += len(text)
return (result_text, result_pos)
def keypress(self, size, key):
"""
Handle editing keystrokes, return others.
>>> e, size = Edit(), (20,)
>>> e.keypress(size, 'x')
>>> e.keypress(size, 'left')
>>> e.keypress(size, '1')
>>> print e.edit_text
1x
>>> e.keypress(size, 'backspace')
>>> e.keypress(size, 'end')
>>> e.keypress(size, '2')
>>> print e.edit_text
x2
>>> e.keypress(size, 'shift f1')
'shift f1'
"""
(maxcol,) = size
p = self.edit_pos
if self.valid_char(key):
if (isinstance(key, unicode) and not
isinstance(self._caption, unicode)):
# screen is sending us unicode input, must be using utf-8
# encoding because that's all we support, so convert it
# to bytes to match our caption's type
key = key.encode('utf-8')
self.insert_text(key)
elif key=="tab" and self.allow_tab:
key = " "*(8-(self.edit_pos%8))
self.insert_text(key)
elif key=="enter" and self.multiline:
key = "\n"
self.insert_text(key)
elif self._command_map[key] == CURSOR_LEFT:
if p==0: return key
p = move_prev_char(self.edit_text,0,p)
self.set_edit_pos(p)
elif self._command_map[key] == CURSOR_RIGHT:
if p >= len(self.edit_text): return key
p = move_next_char(self.edit_text,p,len(self.edit_text))
self.set_edit_pos(p)
elif self._command_map[key] in (CURSOR_UP, CURSOR_DOWN):
self.highlight = None
x,y = self.get_cursor_coords((maxcol,))
pref_col = self.get_pref_col((maxcol,))
assert pref_col is not None
#if pref_col is None:
# pref_col = x
if self._command_map[key] == CURSOR_UP: y -= 1
else: y += 1
if not self.move_cursor_to_coords((maxcol,),pref_col,y):
return key
elif key=="backspace":
self.pref_col_maxcol = None, None
if not self._delete_highlighted():
if p == 0: return key
p = move_prev_char(self.edit_text,0,p)
self.set_edit_text( self.edit_text[:p] +
self.edit_text[self.edit_pos:] )
self.set_edit_pos( p )
elif key=="delete":
self.pref_col_maxcol = None, None
if not self._delete_highlighted():
if p >= len(self.edit_text):
return key
p = move_next_char(self.edit_text,p,len(self.edit_text))
self.set_edit_text( self.edit_text[:self.edit_pos] +
self.edit_text[p:] )
elif self._command_map[key] in (CURSOR_MAX_LEFT, CURSOR_MAX_RIGHT):
self.highlight = None
self.pref_col_maxcol = None, None
x,y = self.get_cursor_coords((maxcol,))
if self._command_map[key] == CURSOR_MAX_LEFT:
self.move_cursor_to_coords((maxcol,), LEFT, y)
else:
self.move_cursor_to_coords((maxcol,), RIGHT, y)
return
else:
# key wasn't handled
return key
def move_cursor_to_coords(self, size, x, y):
"""
Set the cursor position with (x,y) coordinates.
Returns True if move succeeded, False otherwise.
>>> size = (10,)
>>> e = Edit("","edit\\ntext")
>>> e.move_cursor_to_coords(size, 5, 0)
True
>>> e.edit_pos
4
>>> e.move_cursor_to_coords(size, 5, 3)
False
>>> e.move_cursor_to_coords(size, 0, 1)
True
>>> e.edit_pos
5
"""
(maxcol,) = size
trans = self.get_line_translation(maxcol)
top_x, top_y = self.position_coords(maxcol, 0)
if y < top_y or y >= len(trans):
return False
pos = calc_pos( self.get_text()[0], trans, x, y )
e_pos = pos - len(self.caption)
if e_pos < 0: e_pos = 0
if e_pos > len(self.edit_text): e_pos = len(self.edit_text)
self.edit_pos = e_pos
self.pref_col_maxcol = x, maxcol
self._invalidate()
return True
def mouse_event(self, size, event, button, x, y, focus):
"""
Move the cursor to the location clicked for button 1.
>>> size = (20,)
>>> e = Edit("","words here")
>>> e.mouse_event(size, 'mouse press', 1, 2, 0, True)
True
>>> e.edit_pos
2
"""
(maxcol,) = size
if button==1:
return self.move_cursor_to_coords( (maxcol,), x, y )
def _delete_highlighted(self):
"""
Delete all highlighted text and update cursor position, if any
text is highlighted.
"""
if not self.highlight: return
start, stop = self.highlight
btext, etext = self.edit_text[:start], self.edit_text[stop:]
self.set_edit_text( btext + etext )
self.edit_pos = start
self.highlight = None
return True
def render(self, size, focus=False):
"""
Render edit widget and return canvas. Include cursor when in
focus.
>>> c = Edit("? ","yes").render((10,), focus=True)
>>> c.text # ... = b in Python 3
[...'? yes ']
>>> c.cursor
(5, 0)
"""
(maxcol,) = size
self._shift_view_to_cursor = bool(focus)
canv = Text.render(self,(maxcol,))
if focus:
canv = CompositeCanvas(canv)
canv.cursor = self.get_cursor_coords((maxcol,))
# .. will need to FIXME if I want highlight to work again
#if self.highlight:
# hstart, hstop = self.highlight_coords()
# d.coords['highlight'] = [ hstart, hstop ]
return canv
def get_line_translation(self, maxcol, ta=None ):
trans = Text.get_line_translation(self, maxcol, ta)
if not self._shift_view_to_cursor:
return trans
text, ignore = self.get_text()
x,y = calc_coords( text, trans,
self.edit_pos + len(self.caption) )
if x < 0:
return ( trans[:y]
+ [shift_line(trans[y],-x)]
+ trans[y+1:] )
elif x >= maxcol:
return ( trans[:y]
+ [shift_line(trans[y],-(x-maxcol+1))]
+ trans[y+1:] )
return trans
def get_cursor_coords(self, size):
"""
Return the (*x*, *y*) coordinates of cursor within widget.
>>> Edit("? ","yes").get_cursor_coords((10,))
(5, 0)
"""
(maxcol,) = size
self._shift_view_to_cursor = True
return self.position_coords(maxcol,self.edit_pos)
def position_coords(self,maxcol,pos):
"""
Return (*x*, *y*) coordinates for an offset into self.edit_text.
"""
p = pos + len(self.caption)
trans = self.get_line_translation(maxcol)
x,y = calc_coords(self.get_text()[0], trans,p)
return x,y
class IntEdit(Edit):
"""Edit widget for integer values"""
def valid_char(self, ch):
"""
Return true for decimal digits.
"""
return len(ch)==1 and ch in "0123456789"
def __init__(self,caption="",default=None):
"""
caption -- caption markup
default -- default edit value
>>> IntEdit(u"", 42)
<IntEdit selectable flow widget '42' edit_pos=2>
"""
if default is not None: val = str(default)
else: val = ""
self.__super.__init__(caption,val)
def keypress(self, size, key):
"""
Handle editing keystrokes. Remove leading zeros.
>>> e, size = IntEdit(u"", 5002), (10,)
>>> e.keypress(size, 'home')
>>> e.keypress(size, 'delete')
>>> print e.edit_text
002
>>> e.keypress(size, 'end')
>>> print e.edit_text
2
"""
(maxcol,) = size
unhandled = Edit.keypress(self,(maxcol,),key)
if not unhandled:
# trim leading zeros
while self.edit_pos > 0 and self.edit_text[:1] == "0":
self.set_edit_pos( self.edit_pos - 1)
self.set_edit_text(self.edit_text[1:])
return unhandled
def value(self):
"""
Return the numeric value of self.edit_text.
>>> e, size = IntEdit(), (10,)
>>> e.keypress(size, '5')
>>> e.keypress(size, '1')
>>> e.value() == 51
True
"""
if self.edit_text:
return long(self.edit_text)
else:
return 0
def delegate_to_widget_mixin(attribute_name):
"""
Return a mixin class that delegates all standard widget methods
to an attribute given by attribute_name.
This mixin is designed to be used as a superclass of another widget.
"""
# FIXME: this is so common, let's add proper support for it
# when layout and rendering are separated
get_delegate = attrgetter(attribute_name)
class DelegateToWidgetMixin(Widget):
no_cache = ["rows"] # crufty metaclass work-around
def render(self, size, focus=False):
canv = get_delegate(self).render(size, focus=focus)
return CompositeCanvas(canv)
selectable = property(lambda self:get_delegate(self).selectable)
get_cursor_coords = property(
lambda self:get_delegate(self).get_cursor_coords)
get_pref_col = property(lambda self:get_delegate(self).get_pref_col)
keypress = property(lambda self:get_delegate(self).keypress)
move_cursor_to_coords = property(
lambda self:get_delegate(self).move_cursor_to_coords)
rows = property(lambda self:get_delegate(self).rows)
mouse_event = property(lambda self:get_delegate(self).mouse_event)
sizing = property(lambda self:get_delegate(self).sizing)
pack = property(lambda self:get_delegate(self).pack)
return DelegateToWidgetMixin
class WidgetWrapError(Exception):
pass
class WidgetWrap(delegate_to_widget_mixin('_wrapped_widget'), Widget):
def __init__(self, w):
"""
w -- widget to wrap, stored as self._w
This object will pass the functions defined in Widget interface
definition to self._w.
The purpose of this widget is to provide a base class for
widgets that compose other widgets for their display and
behaviour. The details of that composition should not affect
users of the subclass. The subclass may decide to expose some
of the wrapped widgets by behaving like a ContainerWidget or
WidgetDecoration, or it may hide them from outside access.
"""
self._wrapped_widget = w
def _set_w(self, w):
"""
Change the wrapped widget. This is meant to be called
only by subclasses.
>>> size = (10,)
>>> ww = WidgetWrap(Edit("hello? ","hi"))
>>> ww.render(size).text # ... = b in Python 3
[...'hello? hi ']
>>> ww.selectable()
True
>>> ww._w = Text("goodbye") # calls _set_w()
>>> ww.render(size).text
[...'goodbye ']
>>> ww.selectable()
False
"""
self._wrapped_widget = w
self._invalidate()
_w = property(lambda self:self._wrapped_widget, _set_w)
def _raise_old_name_error(self, val=None):
raise WidgetWrapError("The WidgetWrap.w member variable has "
"been renamed to WidgetWrap._w (not intended for use "
"outside the class and its subclasses). "
"Please update your code to use self._w "
"instead of self.w.")
w = property(_raise_old_name_error, _raise_old_name_error)
def _test():
import doctest
doctest.testmod()
if __name__=='__main__':
_test()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
738,
13057,
344,
5678,
3938,
3992,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
7409,
221,
473,
290,
644,
1005,
199,
3,
199,
3,
259,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
259,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
259,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
199,
3,
259,
1015,
499,
14,
17,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
3555,
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,
1664,
199,
3,
259,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
259,
844,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
259,
2752,
12,
3277,
2020,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
221,
15673,
13,
13421,
221,
8217,
199,
3,
199,
3,
738,
13057,
344,
3330,
4770,
26,
1455,
921,
476,
670,
14,
1308,
15,
300,
19686,
15,
199,
199,
504,
4182,
492,
21829,
199,
199,
504,
7629,
19686,
14,
1974,
492,
334,
3396,
11823,
12,
477,
12607,
63,
1450,
10131,
12,
12831,
63,
2063,
12,
272,
365,
63,
13062,
63,
1560,
12,
4057,
63,
5701,
63,
1560,
12,
4057,
63,
2184,
63,
1560,
9,
199,
504,
7629,
19686,
14,
505,
63,
4209,
492,
12831,
63,
1712,
12,
12831,
63,
8032,
12,
7706,
63,
604,
199,
504,
7629,
19686,
492,
10166,
199,
504,
7629,
19686,
492,
1318,
63,
4209,
199,
504,
7629,
19686,
14,
7682,
492,
334,
15174,
4437,
12,
27506,
2124,
15174,
12,
2002,
7401,
15174,
12,
272,
4838,
63,
505,
63,
4209,
9,
199,
504,
7629,
19686,
14,
1531,
63,
1130,
492,
334,
1531,
63,
1130,
12,
18715,
26508,
63,
9894,
12,
18715,
26508,
63,
12811,
12,
272,
18715,
26508,
63,
2160,
12,
18715,
26508,
63,
8819,
12,
18715,
26508,
63,
4283,
63,
9894,
12,
18715,
26508,
63,
4283,
63,
12811,
9,
199,
504,
7629,
19686,
14,
1294,
63,
2722,
492,
3715,
63,
2722,
12,
2813,
63,
4322,
12,
2366,
19,
63,
2722,
421,
199,
3,
5627,
2005,
1561,
367,
3520,
5262,
370,
5126,
3201,
32252,
780,
315,
314,
1350,
199,
3,
436,
370,
2213,
314,
4413,
3326,
781,
787,
1808,
199,
199,
3,
16905,
308,
9147,
3102,
199,
199,
17114,
275,
283,
1659,
7,
199,
15694,
275,
283,
1977,
7,
199,
23837,
275,
283,
5964,
7,
199,
199,
3,
4516,
13177,
12404,
199,
9894,
275,
283,
3039,
7,
199,
12811,
275,
283,
1019,
7,
199,
17611,
275,
283,
4218,
7,
199,
199,
3,
17887,
1435,
13177,
199,
11422,
275,
283,
2119,
7,
199,
45,
13016,
275,
283,
14885,
7,
199,
27838,
275,
283,
8305,
7,
199,
199,
3,
4516,
19696,
12404,
199,
11658,
275,
283,
2638,
7,
199,
8974,
275,
283,
1629,
7,
199,
1981,
1772,
275,
283,
7548,
7,
199,
199,
3,
644,
1466,
436,
5311,
1070,
2202,
199,
6961,
275,
283,
1389,
7,
199,
39,
6882,
742,
275,
283,
11809,
7,
199,
13604,
14277,
275,
283,
6188,
7,
199,
13604,
14277,
63,
1960,
275,
334,
13604,
14277,
12,
2948,
9,
199,
25100,
275,
283,
3463,
7,
421,
199,
533,
16905,
3396,
8,
3396,
11823,
12,
10166,
14,
3396,
28536,
304,
272,
408,
272,
699,
3274,
26,
520,
533,
1705,
3396,
11823,
3559,
520,
533,
1705,
3396,
28536,
64,
339,
9195,
3889,
13627,
402,
3795,
436,
4730,
3102,
14,
339,
8089,
1750,
627,
889,
63,
1637,
10,
365,
282,
769,
402,
1561,
402,
3102,
370,
440,
2581,
272,
5847,
14,
221,
4821,
1083,
1561,
367,
627,
889,
63,
1637,
10,
787,
12692,
3352,
14700,
436,
272,
12692,
3838,
26809,
339,
8089,
1750,
627,
4247,
63,
12283,
10,
340,
3247,
436,
663,
370,
1124,
549,
1040,
9126,
272,
626,
314,
10218,
642,
3938,
3795,
83,
365,
440,
16955,
701,
314,
16470,
272,
2725,
12,
880,
652,
1443,
506,
5525,
1380,
13627,
14,
272,
408,
272,
347,
636,
826,
721,
1886,
12,
536,
12,
9768,
12,
366,
304,
267,
949,
63,
1637,
275,
366,
14,
362,
480,
889,
63,
1637,
401,
3073,
398,
1613,
8,
3339,
3396,
12,
843,
2843,
826,
721,
354,
12,
9768,
12,
366,
9,
398,
340,
298,
3352,
2,
315,
366,
26,
288,
340,
298,
3352,
2,
440,
315,
949,
63,
1637,
26,
355,
3795,
63,
2324,
275,
2581,
63,
3440,
63,
3352,
8,
1886,
9,
288,
587,
26,
355,
3795,
63,
2324,
275,
302,
679,
21481,
63,
3440,
63,
3352,
8,
1886,
9,
288,
843,
14,
3352,
275,
3795,
63,
2324,
398,
340,
298,
3838,
2,
315,
366,
436,
298,
3838,
2,
440,
315,
949,
63,
1637,
26,
288,
843,
14,
3838,
275,
2581,
63,
3440,
63,
3838,
8,
1886,
9,
267,
340,
298,
889,
63,
1637,
2,
315,
366,
26,
288,
2150,
843,
14,
889,
63,
1637,
267,
340,
298,
4247,
63,
12283,
2,
315,
366,
26,
288,
2150,
843,
14,
4247,
63,
12283,
199,
199,
533,
16905,
547,
8,
1726,
304,
272,
986,
199,
199,
318,
4107,
63,
890,
8,
3440,
12,
1568,
12,
883,
86,
304,
272,
408,
272,
14771,
282,
16905,
547,
340,
282,
883,
86,
1630,
440,
1336,
1568,
1568,
14,
272,
408,
272,
340,
334,
890,
436,
1568,
59,
17,
2938,
1137,
334,
16,
4258,
436,
1568,
59,
16,
61,
1137,
883,
86,
14,
4574,
1012,
503,
971,
267,
334,
552,
8,
890,
13032,
17,
436,
1568,
59,
17,
61,
1137,
883,
86,
14,
3838,
5109,
267,
746,
16905,
547,
480,
3339,
450,
82,
8018,
4366,
68,
671,
450,
68,
9,
10218,
2,
288,
298,
1380,
3032,
1568,
450,
82,
9539,
450,
334,
3440,
12,
883,
86,
14,
4574,
1062,
288,
883,
86,
14,
3838,
1062,
1568,
430,
199,
199,
318,
1678,
63,
5029,
8,
1222,
63,
2324,
12,
4325,
304,
272,
408,
272,
11247,
465,
8298
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
738,
13057,
344,
5678,
3938,
3992,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
7409,
221,
473,
290,
644,
1005,
199,
3,
199,
3,
259,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
259,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
259,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
199,
3,
259,
1015,
499,
14,
17,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
3555,
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,
1664,
199,
3,
259,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
259,
844,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
259,
2752,
12,
3277,
2020,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
221,
15673,
13,
13421,
221,
8217,
199,
3,
199,
3,
738,
13057,
344,
3330,
4770,
26,
1455,
921,
476,
670,
14,
1308,
15,
300,
19686,
15,
199,
199,
504,
4182,
492,
21829,
199,
199,
504,
7629,
19686,
14,
1974,
492,
334,
3396,
11823,
12,
477,
12607,
63,
1450,
10131,
12,
12831,
63,
2063,
12,
272,
365,
63,
13062,
63,
1560,
12,
4057,
63,
5701,
63,
1560,
12,
4057,
63,
2184,
63,
1560,
9,
199,
504,
7629,
19686,
14,
505,
63,
4209,
492,
12831,
63,
1712,
12,
12831,
63,
8032,
12,
7706,
63,
604,
199,
504,
7629,
19686,
492,
10166,
199,
504,
7629,
19686,
492,
1318,
63,
4209,
199,
504,
7629,
19686,
14,
7682,
492,
334,
15174,
4437,
12,
27506,
2124,
15174,
12,
2002,
7401,
15174,
12,
272,
4838,
63,
505,
63,
4209,
9,
199,
504,
7629,
19686,
14,
1531,
63,
1130,
492,
334,
1531,
63,
1130,
12,
18715,
26508,
63,
9894,
12,
18715,
26508,
63,
12811,
12,
272,
18715,
26508,
63,
2160,
12,
18715,
26508,
63,
8819,
12,
18715,
26508,
63,
4283,
63,
9894,
12,
18715,
26508,
63,
4283,
63,
12811,
9,
199,
504,
7629,
19686,
14,
1294,
63,
2722,
492,
3715,
63,
2722,
12,
2813,
63,
4322,
12,
2366,
19,
63,
2722,
421,
199,
3,
5627,
2005,
1561,
367,
3520,
5262,
370,
5126,
3201,
32252,
780,
315,
314,
1350,
199,
3,
436,
370,
2213,
314,
4413,
3326,
781,
787,
1808,
199,
199,
3,
16905,
308,
9147,
3102,
199,
199,
17114,
275,
283,
1659,
7,
199,
15694,
275,
283,
1977,
7,
199,
23837,
275,
283,
5964,
7,
199,
199,
3,
4516,
13177,
12404,
199,
9894,
275,
283,
3039,
7,
199,
12811,
275,
283,
1019,
7,
199,
17611,
275,
283,
4218,
7,
199,
199,
3,
17887,
1435,
13177,
199,
11422,
275,
283,
2119,
7,
199,
45,
13016,
275,
283,
14885,
7,
199,
27838,
275,
283,
8305,
7,
199,
199,
3,
4516,
19696,
12404,
199,
11658,
275,
283,
2638,
7,
199,
8974,
275,
283,
1629,
7,
199,
1981,
1772,
275,
283,
7548,
7,
199,
199,
3,
644,
1466,
436,
5311,
1070,
2202,
199,
6961,
275,
283,
1389,
7,
199,
39,
6882,
742,
275,
283,
11809,
7,
199,
13604,
14277,
275,
283,
6188,
7,
199,
13604,
14277,
63,
1960,
275,
334,
13604,
14277,
12,
2948,
9,
199,
25100,
275,
283,
3463,
7,
421,
199,
533,
16905,
3396,
8,
3396,
11823,
12,
10166,
14,
3396,
28536,
304,
272,
408,
272,
699,
3274,
26,
520,
533,
1705,
3396,
11823,
3559,
520,
533,
1705,
3396,
28536,
64,
339,
9195,
3889,
13627,
402,
3795,
436,
4730,
3102,
14,
339,
8089,
1750,
627,
889,
63,
1637,
10,
365,
282,
769,
402,
1561,
402,
3102,
370,
440,
2581,
272,
5847,
14,
221,
4821,
1083,
1561,
367,
627,
889,
63,
1637,
10,
787,
12692,
3352,
14700,
436,
272,
12692,
3838,
26809,
339,
8089,
1750,
627,
4247,
63,
12283,
10,
340,
3247,
436,
663,
370,
1124,
549,
1040,
9126,
272,
626,
314,
10218,
642,
3938,
3795,
83,
365,
440,
16955,
701,
314,
16470,
272,
2725,
12,
880,
652,
1443,
506,
5525,
1380,
13627,
14,
272,
408,
272,
347,
636,
826,
721,
1886,
12,
536,
12,
9768,
12,
366,
304,
267,
949,
63,
1637,
275,
366,
14,
362,
480,
889,
63,
1637,
401,
3073,
398,
1613,
8,
3339,
3396,
12,
843,
2843,
826,
721,
354,
12,
9768,
12,
366,
9,
398,
340,
298,
3352,
2,
315,
366,
26,
288,
340,
298,
3352,
2,
440,
315,
949,
63,
1637,
26,
355,
3795,
63,
2324,
275,
2581,
63,
3440,
63,
3352,
8,
1886,
9,
288,
587,
26,
355,
3795,
63,
2324,
275,
302,
679,
21481,
63,
3440,
63,
3352,
8,
1886,
9,
288,
843,
14,
3352,
275,
3795,
63,
2324,
398,
340,
298,
3838,
2,
315,
366,
436,
298,
3838,
2,
440,
315,
949,
63,
1637,
26,
288,
843,
14,
3838,
275,
2581,
63,
3440,
63,
3838,
8,
1886,
9,
267,
340,
298,
889,
63,
1637,
2,
315,
366,
26,
288,
2150,
843,
14,
889,
63,
1637,
267,
340,
298,
4247,
63,
12283,
2,
315,
366,
26,
288,
2150,
843,
14,
4247,
63,
12283,
199,
199,
533,
16905,
547,
8,
1726,
304,
272,
986,
199,
199,
318,
4107,
63,
890,
8,
3440,
12,
1568,
12,
883,
86,
304,
272,
408,
272,
14771,
282,
16905,
547,
340,
282,
883,
86,
1630,
440,
1336,
1568,
1568,
14,
272,
408,
272,
340,
334,
890,
436,
1568,
59,
17,
2938,
1137,
334,
16,
4258,
436,
1568,
59,
16,
61,
1137,
883,
86,
14,
4574,
1012,
503,
971,
267,
334,
552,
8,
890,
13032,
17,
436,
1568,
59,
17,
61,
1137,
883,
86,
14,
3838,
5109,
267,
746,
16905,
547,
480,
3339,
450,
82,
8018,
4366,
68,
671,
450,
68,
9,
10218,
2,
288,
298,
1380,
3032,
1568,
450,
82,
9539,
450,
334,
3440,
12,
883,
86,
14,
4574,
1062,
288,
883,
86,
14,
3838,
1062,
1568,
430,
199,
199,
318,
1678,
63,
5029,
8,
1222,
63,
2324,
12,
4325,
304,
272,
408,
272,
11247,
465,
8298,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ImmobilienScout24/succubus
|
src/main/python/succubus/daemonize.py
|
1
|
7987
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function, absolute_import, division
from logging.handlers import SysLogHandler
import logging
import os
import signal
import sys
import time
import atexit
import psutil
from pwd import getpwnam
from grp import getgrnam
from signal import SIGTERM, SIGKILL
class Daemon(object):
"""Subclass this Daemon class and override the run() method"""
def __init__(self,
pid_file=None,
stdin='/dev/null',
stdout='/dev/null',
stderr='/dev/null'):
if len(sys.argv) == 1:
self.param1 = None
return
self.param1 = sys.argv.pop(1)
self.stdin = os.path.abspath(stdin)
self.stdout = os.path.abspath(stdout)
self.stderr = os.path.abspath(stderr)
self.config = {}
self.load_configuration()
self.user = self.config.get('user')
self.group = self.config.get('group')
if not pid_file:
raise Exception("You did not provide a pid file")
self.pid_file = os.path.abspath(pid_file)
self.pid = None
self.shutdown_timeout = 10
def set_gid(self):
"""Change the group of the running process"""
if self.group:
gid = getgrnam(self.group).gr_gid
try:
os.setgid(gid)
except Exception:
message = ("Unable to switch ownership to {0}:{1}. " +
"Did you start the daemon as root?")
print(message.format(self.user, self.group))
sys.exit(1)
def set_uid(self):
"""Change the user of the running process"""
if self.user:
uid = getpwnam(self.user).pw_uid
try:
os.setuid(uid)
except Exception:
message = ('Unable to switch ownership to {0}:{1}. ' +
'Did you start the daemon as root?')
print(message.format(self.user, self.group))
sys.exit(1)
@staticmethod
def usage():
sys.stdout.write("Usage: %s {start|stop|restart|status}\n" % sys.argv[0])
return 2
def action(self):
if self.param1 == 'start':
return self.start()
elif self.param1 == 'stop':
return self.stop()
elif self.param1 == 'restart':
return self.restart()
elif self.param1 == 'status':
return self.status()
else:
return self.usage()
def load_configuration(self):
"""Set up self.config if needed"""
pass
def setup_logging(self):
"""Set up self.logger
This function is called after load_configuration() and after changing
to new user/group IDs (if configured). Logging to syslog using the
root logger is configured by default, you can override this method if
you want something else.
"""
self.logger = logging.getLogger()
if os.path.exists('/dev/log'):
handler = SysLogHandler('/dev/log')
else:
handler = SysLogHandler()
self.logger.addHandler(handler)
def shutdown(self):
"""Clean up when daemon is about to terminate
This function allows your daemon to perform cleanup work just before
terminating. It is called no matter why the daemon terminates (calling
"stop" on the init script, self.run() raising an exception....).
"""
pass
def _shutdown(self):
try:
self.shutdown()
except Exception:
self.logger.exception("Error in daemon shutdown:")
self.delpid()
def daemonize(self):
"""
Do the UNIX double-fork magic, see Stevens' "Advanced
Programming in the UNIX Environment" for details (ISBN 0201563177)
http://www.erlenstar.demon.co.uk/unix/faq_2.html#SEC16
"""
try:
pid = os.fork()
if pid > 0:
sys.exit(0)
except OSError as e:
sys.stderr.write('fork #1 failed: %d (%s)\n' %
(e.errno, e.strerror))
sys.exit(1)
os.chdir('/')
os.setsid()
os.umask(0)
try:
pid = os.fork()
if pid > 0:
sys.exit(0)
except OSError as e:
sys.stderr.write('fork #2 failed: %d (%s)\n' %
(e.errno, e.strerror))
sys.exit(1)
# to properly close the fd's, we need to use sys and os:
# http://chromano.me/2011/05/23/starting-python-daemons-via-ssh.html
sys.stdin.close()
sys.stdout.close()
sys.stderr.close()
os.closerange(0, 3)
pid = os.getpid()
with open(self.pid_file, 'w+') as fp:
fp.write("%s\n" % pid)
def handler(*args):
raise BaseException("SIGTERM was caught")
signal.signal(signal.SIGTERM, handler)
# atexit functions are "not called when the program is killed by a
# signal not handled by Python". But since SIGTERM is now handled, the
# atexit functions do get called.
atexit.register(self._shutdown)
def delpid(self):
"""Remove the pid_file from filesystem"""
os.remove(self.pid_file)
def _already_running(self):
try:
self.pid = int(open(self.pid_file).read().strip())
except IOError:
self.pid = None
return False
if psutil.pid_exists(self.pid):
return True
return False
def start(self):
"""Start the daemon"""
if self._already_running():
message = 'pid file %s already exists. Daemon already running?\n'
sys.stderr.write(message % self.pid_file)
return 0
self.set_gid()
self.set_uid()
# Create log files (if configured) with the new user/group. Creating
# them as root would allow symlink exploits.
self.setup_logging()
# Create pid file with new user/group. This ensures we will be able
# to delete the file when shutting down.
self.daemonize()
try:
self.run()
except Exception:
self.logger.exception('Exception while running the daemon:')
return 1
return 0
def reliable_kill(self):
try:
os.kill(self.pid, SIGTERM)
for _ in range(int(self.shutdown_timeout * 10)):
os.kill(self.pid, 0)
time.sleep(0.1)
except OSError as err:
err = str(err)
if 'No such process' in err:
if os.path.exists(self.pid_file):
self.delpid()
return 0
else:
print(err)
return 1
# No 'no such process' exception -> process is still running.
sys.stderr.write('Had to kill the process with SIGKILL')
os.kill(self.pid, SIGKILL)
return 0
def stop(self):
"""Stop the daemon"""
if self._already_running():
return self.reliable_kill()
else:
# FIXME: misleading error message
message = 'Daemon not running, nothing to do.\n'
sys.stderr.write(message)
return 0
def restart(self):
"""Restart the daemon"""
self.stop()
self.start()
def run(self):
"""Placeholder for later overwriting"""
raise NotImplementedError
def status(self):
"""Determine the status of the daemon"""
my_name = os.path.basename(sys.argv[0])
if self._already_running():
message = "{0} (pid {1}) is running...\n".format(my_name, self.pid)
sys.stdout.write(message)
return 0
sys.stdout.write("{0} is stopped\n".format(my_name))
return 3
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
12,
3679,
63,
646,
12,
4629,
199,
199,
504,
2050,
14,
5586,
492,
28766,
2445,
2461,
199,
646,
2050,
199,
646,
747,
199,
646,
4673,
199,
646,
984,
199,
646,
900,
199,
646,
19840,
199,
646,
22214,
199,
199,
504,
14374,
492,
664,
80,
3501,
455,
199,
504,
18598,
492,
664,
2587,
17811,
199,
504,
4673,
492,
15522,
16718,
12,
15522,
30691,
421,
199,
533,
577,
8770,
8,
785,
304,
272,
408,
23636,
642,
577,
8770,
1021,
436,
4278,
314,
1255,
342,
1083,
624,
339,
347,
636,
826,
721,
277,
12,
326,
4422,
63,
493,
29,
403,
12,
326,
9009,
8805,
2374,
15,
2307,
297,
326,
3839,
8805,
2374,
15,
2307,
297,
326,
4635,
8805,
2374,
15,
2307,
735,
267,
340,
822,
8,
1274,
14,
3020,
9,
508,
413,
26,
288,
291,
14,
635,
17,
275,
488,
288,
372,
267,
291,
14,
635,
17,
275,
984,
14,
3020,
14,
1935,
8,
17,
9,
398,
291,
14,
6626,
275,
747,
14,
515,
14,
4832,
8,
6626,
9,
267,
291,
14,
2703,
275,
747,
14,
515,
14,
4832,
8,
2703,
9,
267,
291,
14,
3083,
275,
747,
14,
515,
14,
4832,
8,
3083,
9,
267,
291,
14,
888,
275,
1052,
267,
291,
14,
912,
63,
4758,
342,
267,
291,
14,
751,
275,
291,
14,
888,
14,
362,
360,
751,
358,
267,
291,
14,
923,
275,
291,
14,
888,
14,
362,
360,
923,
358,
267,
340,
440,
4422,
63,
493,
26,
288,
746,
2186,
480,
5556,
8103,
440,
5647,
282,
4422,
570,
531,
267,
291,
14,
3150,
63,
493,
275,
747,
14,
515,
14,
4832,
8,
3150,
63,
493,
9,
267,
291,
14,
3150,
275,
488,
267,
291,
14,
8831,
63,
2593,
275,
1616,
339,
347,
663,
63,
8787,
8,
277,
304,
267,
408,
4001,
314,
1572,
402,
314,
3879,
2112,
624,
267,
340,
291,
14,
923,
26,
288,
15122,
275,
664,
2587,
17811,
8,
277,
14,
923,
680,
2587,
63,
8787,
288,
862,
26,
355,
747,
14,
409,
8787,
8,
8787,
9,
288,
871,
2186,
26,
355,
1245,
275,
1689,
6005,
370,
6258,
12715,
370,
469,
16,
16495,
17,
5565,
298,
435,
2574,
298,
17366,
1265,
1343,
314,
11128,
465,
1738,
18582,
355,
870,
8,
1188,
14,
908,
8,
277,
14,
751,
12,
291,
14,
923,
430,
355,
984,
14,
2224,
8,
17,
9,
339,
347,
663,
63,
1535,
8,
277,
304,
267,
408,
4001,
314,
922,
402,
314,
3879,
2112,
624,
267,
340,
291,
14,
751,
26,
288,
1747,
275,
664,
80,
3501,
455,
8,
277,
14,
751,
680,
8796,
63,
1535,
288,
862,
26,
355,
747,
14,
409,
1535,
8,
1535,
9,
288,
871,
2186,
26,
355,
1245,
275,
661,
6005,
370,
6258,
12715,
370,
469,
16,
16495,
17,
5565,
283,
435,
2574,
283,
17366,
1265,
1343,
314,
11128,
465,
1738,
18478,
355,
870,
8,
1188,
14,
908,
8,
277,
14,
751,
12,
291,
14,
923,
430,
355,
984,
14,
2224,
8,
17,
9,
339,
768,
4639,
272,
347,
4503,
837,
267,
984,
14,
2703,
14,
952,
480,
7692,
26,
450,
83,
469,
928,
92,
2379,
92,
10506,
92,
1205,
4988,
78,
2,
450,
984,
14,
3020,
59,
16,
566,
267,
372,
499,
339,
347,
1595,
8,
277,
304,
267,
340,
291,
14,
635,
17,
508,
283,
928,
356,
288,
372,
291,
14,
928,
342,
267,
916,
291,
14,
635,
17,
508,
283,
2379,
356,
288,
372,
291,
14,
2379,
342,
267,
916,
291,
14,
635,
17,
508,
283,
10506,
356,
288,
372,
291,
14,
10506,
342,
267,
916,
291,
14,
635,
17,
508,
283,
1205,
356,
288,
372,
291,
14,
1205,
342,
267,
587,
26,
288,
372,
291,
14,
3807,
342,
339,
347,
2248,
63,
4758,
8,
277,
304,
267,
408,
1084,
1536,
291,
14,
888,
340,
4346,
624,
267,
986,
339,
347,
3272,
63,
4806,
8,
277,
304,
267,
408,
1084,
1536,
291,
14,
2921,
398,
961,
805,
365,
2797,
2410,
2248,
63,
4758,
342,
436,
2410,
13729,
267,
370,
892,
922,
15,
923,
11449,
334,
692,
7526,
680,
19928,
370,
22112,
1808,
314,
267,
1738,
2512,
365,
7526,
701,
849,
12,
1265,
883,
4278,
642,
1083,
340,
267,
1265,
2934,
6020,
587,
14,
267,
408,
267,
291,
14,
2921,
275,
2050,
14,
5572,
342,
398,
340,
747,
14,
515,
14,
2444,
2336,
2374,
15,
793,
735,
288,
3016,
275,
28766,
2445,
2461,
2336,
2374,
15,
793,
358,
267,
587,
26,
288,
3016,
275,
28766,
2445,
2461,
342,
267,
291,
14,
2921,
14,
18826,
8,
2232,
9,
339,
347,
12842,
8,
277,
304,
267,
408,
6580,
1536,
1380,
11128,
365,
3595,
370,
15095,
398,
961,
805,
6127,
2195,
11128,
370,
5147,
9058,
1736,
2951,
2544,
267,
5537,
1958,
14,
2779,
365,
2797,
949,
17247,
10842,
314,
11128,
26751,
334,
25566,
267,
298,
2379,
2,
641,
314,
4205,
2884,
12,
291,
14,
1065,
342,
17026,
376,
1919,
4496,
680,
267,
408,
267,
986,
339,
347,
485,
8831,
8,
277,
304,
267,
862,
26,
288,
291,
14,
8831,
342,
267,
871,
2186,
26,
288,
291,
14,
2921,
14,
1971,
480,
547,
315,
11128,
12842,
9107,
267,
291,
14,
2264,
3150,
342,
339,
347,
11128,
794,
8,
277,
304,
267,
408,
267,
4226,
314,
22242,
4270,
13,
11796,
10628,
12,
1937,
17854,
1856,
83,
7,
298,
23613,
267,
2165,
9258,
315,
314,
22242,
9711,
2,
367,
2436,
334,
1311,
18273,
378,
1797,
1367,
2192,
1138,
9,
267,
1455,
921,
1544,
14,
281,
552,
7848,
14,
271,
2106,
14,
331,
14,
3210,
15,
11864,
15,
667,
81,
63,
18,
14,
1360,
3,
15048,
975,
267,
408,
267,
862,
26,
288,
4422,
275,
747,
14,
11796,
342,
288,
340,
4422,
690,
378,
26,
355,
984,
14,
2224,
8,
16,
9,
267,
871,
6440,
465,
325,
26,
288,
984,
14,
3083,
14,
952,
360,
11796,
327,
17,
3405,
26,
450,
68,
4366,
83,
2862,
78,
7,
450,
2490,
334,
69,
14,
7931,
12,
325,
14,
20395,
430,
288,
984,
14,
2224,
8,
17,
9,
267,
747,
14,
8563,
7825,
267,
747,
14,
409,
4148,
342,
267,
747,
14,
18315,
8,
16,
9
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
12,
3679,
63,
646,
12,
4629,
199,
199,
504,
2050,
14,
5586,
492,
28766,
2445,
2461,
199,
646,
2050,
199,
646,
747,
199,
646,
4673,
199,
646,
984,
199,
646,
900,
199,
646,
19840,
199,
646,
22214,
199,
199,
504,
14374,
492,
664,
80,
3501,
455,
199,
504,
18598,
492,
664,
2587,
17811,
199,
504,
4673,
492,
15522,
16718,
12,
15522,
30691,
421,
199,
533,
577,
8770,
8,
785,
304,
272,
408,
23636,
642,
577,
8770,
1021,
436,
4278,
314,
1255,
342,
1083,
624,
339,
347,
636,
826,
721,
277,
12,
326,
4422,
63,
493,
29,
403,
12,
326,
9009,
8805,
2374,
15,
2307,
297,
326,
3839,
8805,
2374,
15,
2307,
297,
326,
4635,
8805,
2374,
15,
2307,
735,
267,
340,
822,
8,
1274,
14,
3020,
9,
508,
413,
26,
288,
291,
14,
635,
17,
275,
488,
288,
372,
267,
291,
14,
635,
17,
275,
984,
14,
3020,
14,
1935,
8,
17,
9,
398,
291,
14,
6626,
275,
747,
14,
515,
14,
4832,
8,
6626,
9,
267,
291,
14,
2703,
275,
747,
14,
515,
14,
4832,
8,
2703,
9,
267,
291,
14,
3083,
275,
747,
14,
515,
14,
4832,
8,
3083,
9,
267,
291,
14,
888,
275,
1052,
267,
291,
14,
912,
63,
4758,
342,
267,
291,
14,
751,
275,
291,
14,
888,
14,
362,
360,
751,
358,
267,
291,
14,
923,
275,
291,
14,
888,
14,
362,
360,
923,
358,
267,
340,
440,
4422,
63,
493,
26,
288,
746,
2186,
480,
5556,
8103,
440,
5647,
282,
4422,
570,
531,
267,
291,
14,
3150,
63,
493,
275,
747,
14,
515,
14,
4832,
8,
3150,
63,
493,
9,
267,
291,
14,
3150,
275,
488,
267,
291,
14,
8831,
63,
2593,
275,
1616,
339,
347,
663,
63,
8787,
8,
277,
304,
267,
408,
4001,
314,
1572,
402,
314,
3879,
2112,
624,
267,
340,
291,
14,
923,
26,
288,
15122,
275,
664,
2587,
17811,
8,
277,
14,
923,
680,
2587,
63,
8787,
288,
862,
26,
355,
747,
14,
409,
8787,
8,
8787,
9,
288,
871,
2186,
26,
355,
1245,
275,
1689,
6005,
370,
6258,
12715,
370,
469,
16,
16495,
17,
5565,
298,
435,
2574,
298,
17366,
1265,
1343,
314,
11128,
465,
1738,
18582,
355,
870,
8,
1188,
14,
908,
8,
277,
14,
751,
12,
291,
14,
923,
430,
355,
984,
14,
2224,
8,
17,
9,
339,
347,
663,
63,
1535,
8,
277,
304,
267,
408,
4001,
314,
922,
402,
314,
3879,
2112,
624,
267,
340,
291,
14,
751,
26,
288,
1747,
275,
664,
80,
3501,
455,
8,
277,
14,
751,
680,
8796,
63,
1535,
288,
862,
26,
355,
747,
14,
409,
1535,
8,
1535,
9,
288,
871,
2186,
26,
355,
1245,
275,
661,
6005,
370,
6258,
12715,
370,
469,
16,
16495,
17,
5565,
283,
435,
2574,
283,
17366,
1265,
1343,
314,
11128,
465,
1738,
18478,
355,
870,
8,
1188,
14,
908,
8,
277,
14,
751,
12,
291,
14,
923,
430,
355,
984,
14,
2224,
8,
17,
9,
339,
768,
4639,
272,
347,
4503,
837,
267,
984,
14,
2703,
14,
952,
480,
7692,
26,
450,
83,
469,
928,
92,
2379,
92,
10506,
92,
1205,
4988,
78,
2,
450,
984,
14,
3020,
59,
16,
566,
267,
372,
499,
339,
347,
1595,
8,
277,
304,
267,
340,
291,
14,
635,
17,
508,
283,
928,
356,
288,
372,
291,
14,
928,
342,
267,
916,
291,
14,
635,
17,
508,
283,
2379,
356,
288,
372,
291,
14,
2379,
342,
267,
916,
291,
14,
635,
17,
508,
283,
10506,
356,
288,
372,
291,
14,
10506,
342,
267,
916,
291,
14,
635,
17,
508,
283,
1205,
356,
288,
372,
291,
14,
1205,
342,
267,
587,
26,
288,
372,
291,
14,
3807,
342,
339,
347,
2248,
63,
4758,
8,
277,
304,
267,
408,
1084,
1536,
291,
14,
888,
340,
4346,
624,
267,
986,
339,
347,
3272,
63,
4806,
8,
277,
304,
267,
408,
1084,
1536,
291,
14,
2921,
398,
961,
805,
365,
2797,
2410,
2248,
63,
4758,
342,
436,
2410,
13729,
267,
370,
892,
922,
15,
923,
11449,
334,
692,
7526,
680,
19928,
370,
22112,
1808,
314,
267,
1738,
2512,
365,
7526,
701,
849,
12,
1265,
883,
4278,
642,
1083,
340,
267,
1265,
2934,
6020,
587,
14,
267,
408,
267,
291,
14,
2921,
275,
2050,
14,
5572,
342,
398,
340,
747,
14,
515,
14,
2444,
2336,
2374,
15,
793,
735,
288,
3016,
275,
28766,
2445,
2461,
2336,
2374,
15,
793,
358,
267,
587,
26,
288,
3016,
275,
28766,
2445,
2461,
342,
267,
291,
14,
2921,
14,
18826,
8,
2232,
9,
339,
347,
12842,
8,
277,
304,
267,
408,
6580,
1536,
1380,
11128,
365,
3595,
370,
15095,
398,
961,
805,
6127,
2195,
11128,
370,
5147,
9058,
1736,
2951,
2544,
267,
5537,
1958,
14,
2779,
365,
2797,
949,
17247,
10842,
314,
11128,
26751,
334,
25566,
267,
298,
2379,
2,
641,
314,
4205,
2884,
12,
291,
14,
1065,
342,
17026,
376,
1919,
4496,
680,
267,
408,
267,
986,
339,
347,
485,
8831,
8,
277,
304,
267,
862,
26,
288,
291,
14,
8831,
342,
267,
871,
2186,
26,
288,
291,
14,
2921,
14,
1971,
480,
547,
315,
11128,
12842,
9107,
267,
291,
14,
2264,
3150,
342,
339,
347,
11128,
794,
8,
277,
304,
267,
408,
267,
4226,
314,
22242,
4270,
13,
11796,
10628,
12,
1937,
17854,
1856,
83,
7,
298,
23613,
267,
2165,
9258,
315,
314,
22242,
9711,
2,
367,
2436,
334,
1311,
18273,
378,
1797,
1367,
2192,
1138,
9,
267,
1455,
921,
1544,
14,
281,
552,
7848,
14,
271,
2106,
14,
331,
14,
3210,
15,
11864,
15,
667,
81,
63,
18,
14,
1360,
3,
15048,
975,
267,
408,
267,
862,
26,
288,
4422,
275,
747,
14,
11796,
342,
288,
340,
4422,
690,
378,
26,
355,
984,
14,
2224,
8,
16,
9,
267,
871,
6440,
465,
325,
26,
288,
984,
14,
3083,
14,
952,
360,
11796,
327,
17,
3405,
26,
450,
68,
4366,
83,
2862,
78,
7,
450,
2490,
334,
69,
14,
7931,
12,
325,
14,
20395,
430,
288,
984,
14,
2224,
8,
17,
9,
267,
747,
14,
8563,
7825,
267,
747,
14,
409,
4148,
342,
267,
747,
14,
18315,
8,
16,
9,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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.patterns
~~~~~~~~~~~~~~~~~~
Bindings for the various types of pattern objects.
:copyright: Copyright 2013 by Simon Sapin
:license: BSD, see LICENSE for details.
"""
from . import ffi, cairo, _check_status, constants
from .matrix import Matrix
from .surfaces import Surface
from .compat import xrange
class Pattern(object):
"""The base class for all pattern types.
Should not be instantiated directly, but see :doc:`cffi_api`.
An instance may be returned for cairo pattern types
that are not (yet) defined in cairocffi.
A :class:`Pattern` represents a source when drawing onto a surface.
There are different sub-classes of :class:`Pattern`,
for different types of sources;
for example, :class:`SolidPattern` is a pattern for a solid color.
Other than instantiating the various :class:`Pattern` sub-classes,
some of the pattern types can be implicitly created
using various :class:`Context`; for example :meth:`Context.set_source_rgb`.
"""
def __init__(self, pointer):
self._pointer = ffi.gc(pointer, cairo.cairo_pattern_destroy)
self._check_status()
def _check_status(self):
_check_status(cairo.cairo_pattern_status(self._pointer))
@staticmethod
def _from_pointer(pointer, incref):
"""Wrap an existing :c:type:`cairo_pattern_t *` cdata pointer.
:type incref: bool
:param incref:
Whether increase the :ref:`reference count <refcounting>` now.
:return:
A new instance of :class:`Pattern` or one of its sub-classes,
depending on the pattern’s type.
"""
if pointer == ffi.NULL:
raise ValueError('Null pointer')
if incref:
cairo.cairo_pattern_reference(pointer)
self = object.__new__(PATTERN_TYPE_TO_CLASS.get(
cairo.cairo_pattern_get_type(pointer), Pattern))
Pattern.__init__(self, pointer) # Skip the subclass’s __init__
return self
def set_extend(self, extend):
"""
Sets the mode to be used for drawing outside the area of this pattern.
See :ref:`EXTEND` for details on the semantics of each extend strategy.
The default extend mode is
:obj:`NONE <EXTEND_NONE>` for :class:`SurfacePattern`
and :obj:`PAD <EXTEND_PAD>` for :class:`Gradient` patterns.
"""
cairo.cairo_pattern_set_extend(self._pointer, extend)
self._check_status()
def get_extend(self):
"""Gets the current extend mode for this pattern.
:returns: A :ref:`EXTEND` string.
"""
return cairo.cairo_pattern_get_extend(self._pointer)
# pycairo only has filters on SurfacePattern,
# but cairo seems to accept it on any pattern.
def set_filter(self, filter):
"""Sets the filter to be used for resizing when using this pattern.
See :ref:`FILTER` for details on each filter.
Note that you might want to control filtering
even when you do not have an explicit :class:`Pattern`,
(for example when using :meth:`Context.set_source_surface`).
In these cases, it is convenient to use :meth:`Context.get_source`
to get access to the pattern that cairo creates implicitly.
For example::
context.get_source().set_filter(cairocffi.FILTER_NEAREST)
"""
cairo.cairo_pattern_set_filter(self._pointer, filter)
self._check_status()
def get_filter(self):
"""Return the current filter string for this pattern.
See :ref:`FILTER` for details on each filter.
"""
return cairo.cairo_pattern_get_filter(self._pointer)
def set_matrix(self, matrix):
"""Sets the pattern’s transformation matrix to :obj:`matrix`.
This matrix is a transformation from user space to pattern space.
When a pattern is first created
it always has the identity matrix for its transformation matrix,
which means that pattern space is initially identical to user space.
**Important:**
Please note that the direction of this transformation matrix
is from user space to pattern space.
This means that if you imagine the flow
from a pattern to user space (and on to device space),
then coordinates in that flow will be transformed
by the inverse of the pattern matrix.
For example, if you want to make a pattern appear twice as large
as it does by default the correct code to use is::
pattern.set_matrix(Matrix(xx=0.5, yy=0.5))
Meanwhile, using values of 2 rather than 0.5 in the code above
would cause the pattern to appear at half of its default size.
Also, please note the discussion of the user-space locking semantics
of :meth:`Context.set_source`.
:param matrix: A :class:`Matrix` to be copied into the pattern.
"""
cairo.cairo_pattern_set_matrix(self._pointer, matrix._pointer)
self._check_status()
def get_matrix(self):
"""Copies the pattern’s transformation matrix.
:retuns: A new :class:`Matrix` object.
"""
matrix = Matrix()
cairo.cairo_pattern_get_matrix(self._pointer, matrix._pointer)
self._check_status()
return matrix
class SolidPattern(Pattern):
"""Creates a new pattern corresponding to a solid color.
The color and alpha components are in the range 0 to 1.
If the values passed in are outside that range, they will be clamped.
:param red: Red component of the color.
:param green: Green component of the color.
:param blue: Blue component of the color.
:param alpha:
Alpha component of the color.
1 (the default) is opaque, 0 fully transparent.
:type red: float
:type green: float
:type blue: float
:type alpha: float
"""
def __init__(self, red, green, blue, alpha=1):
Pattern.__init__(
self, cairo.cairo_pattern_create_rgba(red, green, blue, alpha))
def get_rgba(self):
"""Returns the solid pattern’s color.
:returns: a ``(red, green, blue, alpha)`` tuple of floats.
"""
rgba = ffi.new('double[4]')
_check_status(cairo.cairo_pattern_get_rgba(
self._pointer, rgba + 0, rgba + 1, rgba + 2, rgba + 3))
return tuple(rgba)
class SurfacePattern(Pattern):
"""Create a new pattern for the given surface.
:param surface: A :class:`Surface` object.
"""
def __init__(self, surface):
Pattern.__init__(
self, cairo.cairo_pattern_create_for_surface(surface._pointer))
def get_surface(self):
"""Return this :class:`SurfacePattern`’s surface.
:returns:
An instance of :class:`Surface` or one of its sub-classes,
a new Python object referencing the existing cairo surface.
"""
surface_p = ffi.new('cairo_surface_t **')
_check_status(cairo.cairo_pattern_get_surface(
self._pointer, surface_p))
return Surface._from_pointer(surface_p[0], incref=True)
class Gradient(Pattern):
"""
The common parent of :class:`LinearGradient` and :class:`RadialGradient`.
Should not be instantiated directly.
"""
def add_color_stop_rgba(self, offset, red, green, blue, alpha=1):
"""Adds a translucent color stop to a gradient pattern.
The offset specifies the location along the gradient's control vector.
For example,
a linear gradient's control vector is from (x0,y0) to (x1,y1)
while a radial gradient's control vector is
from any point on the start circle
to the corresponding point on the end circle.
If two (or more) stops are specified with identical offset values,
they will be sorted
according to the order in which the stops are added
(stops added earlier before stops added later).
This can be useful for reliably making sharp color transitions
instead of the typical blend.
The color components and offset are in the range 0 to 1.
If the values passed in are outside that range, they will be clamped.
:param offset: Location along the gradient's control vector
:param red: Red component of the color.
:param green: Green component of the color.
:param blue: Blue component of the color.
:param alpha:
Alpha component of the color.
1 (the default) is opaque, 0 fully transparent.
:type offset: float
:type red: float
:type green: float
:type blue: float
:type alpha: float
"""
cairo.cairo_pattern_add_color_stop_rgba(
self._pointer, offset, red, green, blue, alpha)
self._check_status()
def add_color_stop_rgb(self, offset, red, green, blue):
"""Same as :meth:`add_color_stop_rgba` with ``alpha=1``.
Kept for compatibility with pycairo.
"""
cairo.cairo_pattern_add_color_stop_rgb(
self._pointer, offset, red, green, blue)
self._check_status()
def get_color_stops(self):
"""Return this gradient’s color stops so far.
:returns:
A list of ``(offset, red, green, blue, alpha)`` tuples of floats.
"""
count = ffi.new('int *')
_check_status(cairo.cairo_pattern_get_color_stop_count(
self._pointer, count))
stops = []
stop = ffi.new('double[5]')
for i in xrange(count[0]):
_check_status(cairo.cairo_pattern_get_color_stop_rgba(
self._pointer, i,
stop + 0, stop + 1, stop + 2, stop + 3, stop + 4))
stops.append(tuple(stop))
return stops
class LinearGradient(Gradient):
"""Create a new linear gradient
along the line defined by (x0, y0) and (x1, y1).
Before using the gradient pattern, a number of color stops
should be defined using :meth:`~Gradient.add_color_stop_rgba`.
Note: The coordinates here are in pattern space.
For a new pattern, pattern space is identical to user space,
but the relationship between the spaces can be changed
with :meth:`~Pattern.set_matrix`.
:param x0: X coordinate of the start point.
:param y0: Y coordinate of the start point.
:param x1: X coordinate of the end point.
:param y1: Y coordinate of the end point.
:type x0: float
:type y0: float
:type x1: float
:type y1: float
"""
def __init__(self, x0, y0, x1, y1):
Pattern.__init__(
self, cairo.cairo_pattern_create_linear(x0, y0, x1, y1))
def get_linear_points(self):
"""Return this linear gradient’s endpoints.
:returns: A ``(x0, y0, x1, y1)`` tuple of floats.
"""
points = ffi.new('double[4]')
_check_status(cairo.cairo_pattern_get_linear_points(
self._pointer, points + 0, points + 1, points + 2, points + 3))
return tuple(points)
class RadialGradient(Gradient):
"""Creates a new radial gradient pattern between the two circles
defined by (cx0, cy0, radius0) and (cx1, cy1, radius1).
Before using the gradient pattern, a number of color stops
should be defined using :meth:`~Gradient.add_color_stop_rgba`.
Note: The coordinates here are in pattern space.
For a new pattern, pattern space is identical to user space,
but the relationship between the spaces can be changed
with :meth:`~Pattern.set_matrix`.
:param cx0: X coordinate of the start circle.
:param cy0: Y coordinate of the start circle.
:param radius0: Radius of the start circle.
:param cx1: X coordinate of the end circle.
:param cy1: Y coordinate of the end circle.
:param radius1: Y coordinate of the end circle.
:type cx0: float
:type cy0: float
:type radius0: float
:type cx1: float
:type cy1: float
:type radius1: float
"""
def __init__(self, cx0, cy0, radius0, cx1, cy1, radius1):
Pattern.__init__(self, cairo.cairo_pattern_create_radial(
cx0, cy0, radius0, cx1, cy1, radius1))
def get_radial_circles(self):
"""Return this radial gradient’s endpoint circles,
each specified as a center coordinate and a radius.
:returns: A ``(cx0, cy0, radius0, cx1, cy1, radius1)`` tuple of floats.
"""
circles = ffi.new('double[6]')
_check_status(cairo.cairo_pattern_get_radial_circles(
self._pointer, circles + 0, circles + 1, circles + 2,
circles + 3, circles + 4, circles + 5))
return tuple(circles)
PATTERN_TYPE_TO_CLASS = {
constants.PATTERN_TYPE_SOLID: SolidPattern,
constants.PATTERN_TYPE_SURFACE: SurfacePattern,
constants.PATTERN_TYPE_LINEAR: LinearGradient,
constants.PATTERN_TYPE_RADIAL: RadialGradient,
}
|
bsd-3-clause
|
[
3,
2803,
26,
2774,
24,
199,
624,
272,
1704,
14352,
32407,
14,
7435,
272,
18294,
1714,
339,
22630,
780,
367,
314,
7750,
2943,
402,
3851,
2251,
14,
339,
520,
7307,
26,
1898,
6171,
701,
10751,
265,
428,
439,
262,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
2436,
14,
199,
199,
624,
199,
199,
504,
1275,
492,
30865,
12,
1704,
14352,
12,
485,
1074,
63,
1205,
12,
5262,
199,
504,
1275,
3642,
492,
8449,
199,
504,
1275,
5105,
4309,
492,
29564,
199,
504,
1275,
5819,
492,
4945,
421,
199,
533,
27019,
8,
785,
304,
272,
408,
1918,
1300,
1021,
367,
1006,
3851,
2943,
14,
339,
7719,
440,
506,
17544,
5370,
12,
1325,
1937,
520,
1301,
1705,
32407,
63,
1246,
2313,
272,
1626,
1256,
1443,
506,
2138,
367,
1704,
14352,
3851,
2943,
272,
626,
787,
440,
334,
28064,
9,
3247,
315,
1704,
14352,
32407,
14,
339,
437,
520,
533,
1705,
9959,
64,
8469,
282,
1350,
1380,
17455,
14602,
282,
13195,
14,
272,
6006,
787,
3365,
1007,
13,
2888,
402,
520,
533,
1705,
9959,
3559,
272,
367,
3365,
2943,
402,
5274,
27,
272,
367,
2893,
12,
520,
533,
1705,
5158,
7401,
9959,
64,
365,
282,
3851,
367,
282,
18609,
3164,
14,
339,
5439,
2419,
9034,
1958,
314,
7750,
520,
533,
1705,
9959,
64,
1007,
13,
2888,
12,
272,
2005,
402,
314,
3851,
2943,
883,
506,
19796,
2737,
272,
1808,
7750,
520,
533,
1705,
2998,
64,
27,
367,
2893,
520,
5247,
1705,
2998,
14,
409,
63,
1365,
63,
10090,
2313,
339,
408,
272,
347,
636,
826,
721,
277,
12,
7849,
304,
267,
291,
423,
3929,
275,
30865,
14,
9493,
8,
3929,
12,
1704,
14352,
14,
21562,
63,
3401,
63,
7237,
9,
267,
291,
423,
1074,
63,
1205,
342,
339,
347,
485,
1074,
63,
1205,
8,
277,
304,
267,
485,
1074,
63,
1205,
8,
21562,
14,
21562,
63,
3401,
63,
1205,
8,
277,
423,
3929,
430,
339,
768,
4639,
272,
347,
485,
504,
63,
3929,
8,
3929,
12,
12864,
1121,
304,
267,
408,
15991,
376,
3411,
520,
67,
26,
466,
1705,
21562,
63,
3401,
63,
84,
627,
64,
286,
576,
7849,
14,
398,
520,
466,
12864,
1121,
26,
2155,
267,
520,
635,
12864,
1121,
26,
288,
7480,
19781,
314,
520,
1121,
1705,
4443,
2338,
665,
16497,
316,
8637,
3063,
14,
267,
520,
1107,
26,
288,
437,
892,
1256,
402,
520,
533,
1705,
9959,
64,
503,
1373,
402,
2399,
1007,
13,
2888,
12,
288,
10298,
641,
314,
3851,
21045,
83,
730,
14,
398,
408,
267,
340,
7849,
508,
30865,
14,
8084,
26,
288,
746,
1722,
360,
8849,
7849,
358,
267,
340,
12864,
1121,
26,
288,
1704,
14352,
14,
21562,
63,
3401,
63,
4443,
8,
3929,
9,
267,
291,
275,
909,
855,
1222,
721,
10764,
63,
2711,
63,
2566,
63,
6885,
14,
362,
8,
288,
1704,
14352,
14,
21562,
63,
3401,
63,
362,
63,
466,
8,
3929,
395,
27019,
430,
267,
27019,
855,
826,
721,
277,
12,
7849,
9,
221,
327,
8232,
314,
5516,
21045,
83,
636,
826,
363,
267,
372,
291,
339,
347,
663,
63,
2880,
8,
277,
12,
12247,
304,
267,
408,
267,
10729,
314,
818,
370,
506,
1202,
367,
17455,
9682,
314,
9150,
402,
642,
3851,
14,
267,
1666,
520,
1121,
1705,
2472,
3902,
64,
367,
2436,
641,
314,
19002,
402,
1924,
12247,
10054,
14,
398,
710,
849,
12247,
818,
365,
267,
520,
1113,
1705,
9185,
665,
2472,
3902,
63,
9185,
8637,
367,
520,
533,
1705,
16923,
9959,
64,
267,
436,
520,
1113,
1705,
32420,
665,
2472,
3902,
63,
32420,
8637,
367,
520,
533,
1705,
9942,
64,
7970,
14,
398,
408,
267,
1704,
14352,
14,
21562,
63,
3401,
63,
409,
63,
2880,
8,
277,
423,
3929,
12,
12247,
9,
267,
291,
423,
1074,
63,
1205,
342,
339,
347,
664,
63,
2880,
8,
277,
304,
267,
408,
14426,
314,
1453,
12247,
818,
367,
642,
3851,
14,
398,
520,
5808,
26,
437,
520,
1121,
1705,
2472,
3902,
64,
1059,
14,
398,
408,
267,
372,
1704,
14352,
14,
21562,
63,
3401,
63,
362,
63,
2880,
8,
277,
423,
3929,
9,
339,
327,
1134,
21562,
1454,
965,
4766,
641,
29564,
9959,
12,
272,
327,
1325,
1704,
14352,
12237,
370,
4729,
652,
641,
1263,
3851,
14,
272,
347,
663,
63,
1541,
8,
277,
12,
2457,
304,
267,
408,
9899,
314,
2457,
370,
506,
1202,
367,
295,
30639,
1380,
1808,
642,
3851,
14,
267,
1666,
520,
1121,
1705,
9905,
64,
367,
2436,
641,
1924,
2457,
14,
398,
3390,
626,
1265,
5594,
2934,
370,
3304,
14545,
267,
2755,
1380,
1265,
886,
440,
1172,
376,
5027,
520,
533,
1705,
9959,
3559,
267,
334,
509,
2893,
1380,
1808,
520,
5247,
1705,
2998,
14,
409,
63,
1365,
63,
10992,
14963,
267,
1010,
3520,
5560,
12,
652,
365,
22700,
370,
675,
520,
5247,
1705,
2998,
14,
362,
63,
1365,
64,
267,
370,
664,
2879,
370,
314,
3851,
626,
1704,
14352,
8491,
19796,
14,
398,
2104,
2893,
447,
953,
1067,
14,
362,
63,
1365,
1252,
409,
63,
1541,
8,
21562,
32407,
14,
9905,
63,
6388,
689,
1719,
9,
398,
408,
267,
1704,
14352,
14,
21562,
63,
3401,
63,
409,
63,
1541,
8,
277,
423,
3929,
12,
2457,
9,
267,
291,
423,
1074,
63,
1205,
342,
339,
347,
664,
63,
1541,
8,
277,
304,
267,
408,
1767,
314,
1453,
2457,
1059,
367,
642,
3851,
14,
267,
1666,
520,
1121,
1705,
9905,
64,
367,
2436,
641,
1924,
2457,
14,
398,
408,
267,
372,
1704,
14352,
14,
21562,
63,
3401,
63,
362,
63,
1541,
8,
277,
423,
3929,
9,
339,
347,
663,
63,
3642,
8,
277,
12,
3634,
304,
267,
408,
9899,
314,
3851,
21045,
83,
13315,
3634,
370,
520,
1113,
1705,
3642,
2313,
267,
961,
3634,
365,
282,
13315,
687,
922,
4601,
370,
3851,
4601,
14,
398,
3979,
282,
3851,
365,
1642,
2737,
267,
652,
3544,
965,
314,
8503,
3634,
367,
2399,
13315,
3634,
12,
267,
1314,
4910,
626,
3851,
4601,
365,
22801,
13130,
370,
922,
4601,
14,
398,
1011,
6295,
867,
19003,
267,
7754,
5317,
626,
314,
7581,
402,
642,
13315,
3634,
267,
365,
687,
922,
4601,
370,
3851,
4601,
14,
267,
961,
4910,
626,
340,
1265,
18884,
2598,
314,
6369,
267,
687,
282,
3851,
370,
922,
4601,
334,
460,
641,
370,
2243,
4601,
395,
267,
2066,
8983,
315
] |
[
2803,
26,
2774,
24,
199,
624,
272,
1704,
14352,
32407,
14,
7435,
272,
18294,
1714,
339,
22630,
780,
367,
314,
7750,
2943,
402,
3851,
2251,
14,
339,
520,
7307,
26,
1898,
6171,
701,
10751,
265,
428,
439,
262,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
2436,
14,
199,
199,
624,
199,
199,
504,
1275,
492,
30865,
12,
1704,
14352,
12,
485,
1074,
63,
1205,
12,
5262,
199,
504,
1275,
3642,
492,
8449,
199,
504,
1275,
5105,
4309,
492,
29564,
199,
504,
1275,
5819,
492,
4945,
421,
199,
533,
27019,
8,
785,
304,
272,
408,
1918,
1300,
1021,
367,
1006,
3851,
2943,
14,
339,
7719,
440,
506,
17544,
5370,
12,
1325,
1937,
520,
1301,
1705,
32407,
63,
1246,
2313,
272,
1626,
1256,
1443,
506,
2138,
367,
1704,
14352,
3851,
2943,
272,
626,
787,
440,
334,
28064,
9,
3247,
315,
1704,
14352,
32407,
14,
339,
437,
520,
533,
1705,
9959,
64,
8469,
282,
1350,
1380,
17455,
14602,
282,
13195,
14,
272,
6006,
787,
3365,
1007,
13,
2888,
402,
520,
533,
1705,
9959,
3559,
272,
367,
3365,
2943,
402,
5274,
27,
272,
367,
2893,
12,
520,
533,
1705,
5158,
7401,
9959,
64,
365,
282,
3851,
367,
282,
18609,
3164,
14,
339,
5439,
2419,
9034,
1958,
314,
7750,
520,
533,
1705,
9959,
64,
1007,
13,
2888,
12,
272,
2005,
402,
314,
3851,
2943,
883,
506,
19796,
2737,
272,
1808,
7750,
520,
533,
1705,
2998,
64,
27,
367,
2893,
520,
5247,
1705,
2998,
14,
409,
63,
1365,
63,
10090,
2313,
339,
408,
272,
347,
636,
826,
721,
277,
12,
7849,
304,
267,
291,
423,
3929,
275,
30865,
14,
9493,
8,
3929,
12,
1704,
14352,
14,
21562,
63,
3401,
63,
7237,
9,
267,
291,
423,
1074,
63,
1205,
342,
339,
347,
485,
1074,
63,
1205,
8,
277,
304,
267,
485,
1074,
63,
1205,
8,
21562,
14,
21562,
63,
3401,
63,
1205,
8,
277,
423,
3929,
430,
339,
768,
4639,
272,
347,
485,
504,
63,
3929,
8,
3929,
12,
12864,
1121,
304,
267,
408,
15991,
376,
3411,
520,
67,
26,
466,
1705,
21562,
63,
3401,
63,
84,
627,
64,
286,
576,
7849,
14,
398,
520,
466,
12864,
1121,
26,
2155,
267,
520,
635,
12864,
1121,
26,
288,
7480,
19781,
314,
520,
1121,
1705,
4443,
2338,
665,
16497,
316,
8637,
3063,
14,
267,
520,
1107,
26,
288,
437,
892,
1256,
402,
520,
533,
1705,
9959,
64,
503,
1373,
402,
2399,
1007,
13,
2888,
12,
288,
10298,
641,
314,
3851,
21045,
83,
730,
14,
398,
408,
267,
340,
7849,
508,
30865,
14,
8084,
26,
288,
746,
1722,
360,
8849,
7849,
358,
267,
340,
12864,
1121,
26,
288,
1704,
14352,
14,
21562,
63,
3401,
63,
4443,
8,
3929,
9,
267,
291,
275,
909,
855,
1222,
721,
10764,
63,
2711,
63,
2566,
63,
6885,
14,
362,
8,
288,
1704,
14352,
14,
21562,
63,
3401,
63,
362,
63,
466,
8,
3929,
395,
27019,
430,
267,
27019,
855,
826,
721,
277,
12,
7849,
9,
221,
327,
8232,
314,
5516,
21045,
83,
636,
826,
363,
267,
372,
291,
339,
347,
663,
63,
2880,
8,
277,
12,
12247,
304,
267,
408,
267,
10729,
314,
818,
370,
506,
1202,
367,
17455,
9682,
314,
9150,
402,
642,
3851,
14,
267,
1666,
520,
1121,
1705,
2472,
3902,
64,
367,
2436,
641,
314,
19002,
402,
1924,
12247,
10054,
14,
398,
710,
849,
12247,
818,
365,
267,
520,
1113,
1705,
9185,
665,
2472,
3902,
63,
9185,
8637,
367,
520,
533,
1705,
16923,
9959,
64,
267,
436,
520,
1113,
1705,
32420,
665,
2472,
3902,
63,
32420,
8637,
367,
520,
533,
1705,
9942,
64,
7970,
14,
398,
408,
267,
1704,
14352,
14,
21562,
63,
3401,
63,
409,
63,
2880,
8,
277,
423,
3929,
12,
12247,
9,
267,
291,
423,
1074,
63,
1205,
342,
339,
347,
664,
63,
2880,
8,
277,
304,
267,
408,
14426,
314,
1453,
12247,
818,
367,
642,
3851,
14,
398,
520,
5808,
26,
437,
520,
1121,
1705,
2472,
3902,
64,
1059,
14,
398,
408,
267,
372,
1704,
14352,
14,
21562,
63,
3401,
63,
362,
63,
2880,
8,
277,
423,
3929,
9,
339,
327,
1134,
21562,
1454,
965,
4766,
641,
29564,
9959,
12,
272,
327,
1325,
1704,
14352,
12237,
370,
4729,
652,
641,
1263,
3851,
14,
272,
347,
663,
63,
1541,
8,
277,
12,
2457,
304,
267,
408,
9899,
314,
2457,
370,
506,
1202,
367,
295,
30639,
1380,
1808,
642,
3851,
14,
267,
1666,
520,
1121,
1705,
9905,
64,
367,
2436,
641,
1924,
2457,
14,
398,
3390,
626,
1265,
5594,
2934,
370,
3304,
14545,
267,
2755,
1380,
1265,
886,
440,
1172,
376,
5027,
520,
533,
1705,
9959,
3559,
267,
334,
509,
2893,
1380,
1808,
520,
5247,
1705,
2998,
14,
409,
63,
1365,
63,
10992,
14963,
267,
1010,
3520,
5560,
12,
652,
365,
22700,
370,
675,
520,
5247,
1705,
2998,
14,
362,
63,
1365,
64,
267,
370,
664,
2879,
370,
314,
3851,
626,
1704,
14352,
8491,
19796,
14,
398,
2104,
2893,
447,
953,
1067,
14,
362,
63,
1365,
1252,
409,
63,
1541,
8,
21562,
32407,
14,
9905,
63,
6388,
689,
1719,
9,
398,
408,
267,
1704,
14352,
14,
21562,
63,
3401,
63,
409,
63,
1541,
8,
277,
423,
3929,
12,
2457,
9,
267,
291,
423,
1074,
63,
1205,
342,
339,
347,
664,
63,
1541,
8,
277,
304,
267,
408,
1767,
314,
1453,
2457,
1059,
367,
642,
3851,
14,
267,
1666,
520,
1121,
1705,
9905,
64,
367,
2436,
641,
1924,
2457,
14,
398,
408,
267,
372,
1704,
14352,
14,
21562,
63,
3401,
63,
362,
63,
1541,
8,
277,
423,
3929,
9,
339,
347,
663,
63,
3642,
8,
277,
12,
3634,
304,
267,
408,
9899,
314,
3851,
21045,
83,
13315,
3634,
370,
520,
1113,
1705,
3642,
2313,
267,
961,
3634,
365,
282,
13315,
687,
922,
4601,
370,
3851,
4601,
14,
398,
3979,
282,
3851,
365,
1642,
2737,
267,
652,
3544,
965,
314,
8503,
3634,
367,
2399,
13315,
3634,
12,
267,
1314,
4910,
626,
3851,
4601,
365,
22801,
13130,
370,
922,
4601,
14,
398,
1011,
6295,
867,
19003,
267,
7754,
5317,
626,
314,
7581,
402,
642,
13315,
3634,
267,
365,
687,
922,
4601,
370,
3851,
4601,
14,
267,
961,
4910,
626,
340,
1265,
18884,
2598,
314,
6369,
267,
687,
282,
3851,
370,
922,
4601,
334,
460,
641,
370,
2243,
4601,
395,
267,
2066,
8983,
315,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
leotrubach/sourceforge-allura
|
ForgeWiki/forgewiki/tests/test_wiki_roles.py
|
3
|
1248
|
from pylons import c, g
from nose.tools import assert_equal
from alluratest.controller import setup_basic_test, setup_global_objects
from allura import model as M
from allura.lib import security
from allura.tests import decorators as td
def setUp():
setup_basic_test()
setup_with_tools()
@td.with_wiki
def setup_with_tools():
setup_global_objects()
g.set_app('wiki')
def test_role_assignments():
admin = M.User.by_username('test-admin')
user = M.User.by_username('test-user')
anon = M.User.anonymous()
def check_access(perm):
pred = security.has_access(c.app, perm)
return pred(user=admin), pred(user=user), pred(user=anon)
assert_equal(check_access('configure'), (True, False, False))
assert_equal(check_access('read'), (True, True, True))
assert_equal(check_access('create'), (True, False, False))
assert_equal(check_access('edit'), (True, False, False))
assert_equal(check_access('delete'), (True, False, False))
assert_equal(check_access('unmoderated_post'), (True, True, False))
assert_equal(check_access('post'), (True, True, False))
assert_equal(check_access('moderate'), (True, False, False))
assert_equal(check_access('admin'), (True, False, False))
|
apache-2.0
|
[
504,
1134,
76,
4654,
492,
286,
12,
486,
199,
199,
504,
11354,
14,
2537,
492,
702,
63,
1452,
199,
199,
504,
1006,
300,
27126,
14,
5538,
492,
3272,
63,
4316,
63,
396,
12,
3272,
63,
2966,
63,
1462,
199,
504,
1006,
12417,
492,
1402,
465,
603,
199,
504,
1006,
12417,
14,
773,
492,
6391,
199,
504,
1006,
12417,
14,
2219,
492,
20419,
465,
12749,
199,
199,
318,
3613,
837,
272,
3272,
63,
4316,
63,
396,
342,
272,
3272,
63,
1045,
63,
2537,
342,
199,
199,
32,
2076,
14,
1045,
63,
6797,
199,
318,
3272,
63,
1045,
63,
2537,
837,
272,
3272,
63,
2966,
63,
1462,
342,
272,
486,
14,
409,
63,
571,
360,
6797,
358,
199,
199,
318,
511,
63,
3756,
63,
18922,
837,
272,
4628,
275,
603,
14,
1899,
14,
991,
63,
2473,
360,
396,
13,
2113,
358,
272,
922,
275,
603,
14,
1899,
14,
991,
63,
2473,
360,
396,
13,
751,
358,
272,
24757,
275,
603,
14,
1899,
14,
12628,
342,
272,
347,
1104,
63,
2732,
8,
8220,
304,
267,
8869,
275,
6391,
14,
1989,
63,
2732,
8,
67,
14,
571,
12,
10869,
9,
267,
372,
8869,
8,
751,
29,
2113,
395,
8869,
8,
751,
29,
751,
395,
8869,
8,
751,
29,
21009,
9,
272,
702,
63,
1452,
8,
1074,
63,
2732,
360,
6472,
659,
334,
549,
12,
756,
12,
756,
430,
272,
702,
63,
1452,
8,
1074,
63,
2732,
360,
739,
659,
334,
549,
12,
715,
12,
715,
430,
272,
702,
63,
1452,
8,
1074,
63,
2732,
360,
981,
659,
334,
549,
12,
756,
12,
756,
430,
272,
702,
63,
1452,
8,
1074,
63,
2732,
360,
3773,
659,
334,
549,
12,
756,
12,
756,
430,
272,
702,
63,
1452,
8,
1074,
63,
2732,
360,
1807,
659,
334,
549,
12,
756,
12,
756,
430,
272,
702,
63,
1452,
8,
1074,
63,
2732,
360,
324,
632,
12601,
63,
1932,
659,
334,
549,
12,
715,
12,
756,
430,
272,
702,
63,
1452,
8,
1074,
63,
2732,
360,
1932,
659,
334,
549,
12,
715,
12,
756,
430,
272,
702,
63,
1452,
8,
1074,
63,
2732,
360,
632,
1866,
659,
334,
549,
12,
756,
12,
756,
430,
272,
702,
63,
1452,
8,
1074,
63,
2732,
360,
2113,
659,
334,
549,
12,
756,
12,
756,
430,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1134,
76,
4654,
492,
286,
12,
486,
199,
199,
504,
11354,
14,
2537,
492,
702,
63,
1452,
199,
199,
504,
1006,
300,
27126,
14,
5538,
492,
3272,
63,
4316,
63,
396,
12,
3272,
63,
2966,
63,
1462,
199,
504,
1006,
12417,
492,
1402,
465,
603,
199,
504,
1006,
12417,
14,
773,
492,
6391,
199,
504,
1006,
12417,
14,
2219,
492,
20419,
465,
12749,
199,
199,
318,
3613,
837,
272,
3272,
63,
4316,
63,
396,
342,
272,
3272,
63,
1045,
63,
2537,
342,
199,
199,
32,
2076,
14,
1045,
63,
6797,
199,
318,
3272,
63,
1045,
63,
2537,
837,
272,
3272,
63,
2966,
63,
1462,
342,
272,
486,
14,
409,
63,
571,
360,
6797,
358,
199,
199,
318,
511,
63,
3756,
63,
18922,
837,
272,
4628,
275,
603,
14,
1899,
14,
991,
63,
2473,
360,
396,
13,
2113,
358,
272,
922,
275,
603,
14,
1899,
14,
991,
63,
2473,
360,
396,
13,
751,
358,
272,
24757,
275,
603,
14,
1899,
14,
12628,
342,
272,
347,
1104,
63,
2732,
8,
8220,
304,
267,
8869,
275,
6391,
14,
1989,
63,
2732,
8,
67,
14,
571,
12,
10869,
9,
267,
372,
8869,
8,
751,
29,
2113,
395,
8869,
8,
751,
29,
751,
395,
8869,
8,
751,
29,
21009,
9,
272,
702,
63,
1452,
8,
1074,
63,
2732,
360,
6472,
659,
334,
549,
12,
756,
12,
756,
430,
272,
702,
63,
1452,
8,
1074,
63,
2732,
360,
739,
659,
334,
549,
12,
715,
12,
715,
430,
272,
702,
63,
1452,
8,
1074,
63,
2732,
360,
981,
659,
334,
549,
12,
756,
12,
756,
430,
272,
702,
63,
1452,
8,
1074,
63,
2732,
360,
3773,
659,
334,
549,
12,
756,
12,
756,
430,
272,
702,
63,
1452,
8,
1074,
63,
2732,
360,
1807,
659,
334,
549,
12,
756,
12,
756,
430,
272,
702,
63,
1452,
8,
1074,
63,
2732,
360,
324,
632,
12601,
63,
1932,
659,
334,
549,
12,
715,
12,
756,
430,
272,
702,
63,
1452,
8,
1074,
63,
2732,
360,
1932,
659,
334,
549,
12,
715,
12,
756,
430,
272,
702,
63,
1452,
8,
1074,
63,
2732,
360,
632,
1866,
659,
334,
549,
12,
756,
12,
756,
430,
272,
702,
63,
1452,
8,
1074,
63,
2732,
360,
2113,
659,
334,
549,
12,
756,
12,
756,
430,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
standage/AEGeAn
|
data/scripts/seq-reg.py
|
2
|
1768
|
#!/usr/bin/env python
# Copyright (c) 2010-2015, Daniel S. Standage and CONTRIBUTORS
#
# The AEGeAn Toolkit is distributed under the ISC License. See
# the 'LICENSE' file in the AEGeAn source code distribution or
# online at https://github.com/standage/AEGeAn/blob/master/LICENSE.
from __future__ import print_function
import argparse
import os
import re
import subprocess
import sys
def parse_fasta(fp):
"""Stolen shamelessly from http://stackoverflow.com/a/7655072/459780."""
name, seq = None, []
for line in fp:
line = line.rstrip()
if line.startswith('>'):
if name:
yield (name, ''.join(seq))
name, seq = line, []
else:
seq.append(line)
if name:
yield (name, ''.join(seq))
def seq_len(fp):
for defline, seq in parse_fasta(fp):
seqid = defline[1:].split(" ")[0]
yield seqid, len(seq)
def parse_gff3(fp):
for line in fp:
if line.startswith('##gff-version') or \
line.startswith('##sequence-region'):
continue
yield line.rstrip()
if __name__ == '__main__':
desc = 'Correct a GFF3\'s sequence-region entries with Fasta sequences'
parser = argparse.ArgumentParser(description=desc)
parser.add_argument('gff3', type=argparse.FileType('r'),
help='Annotation in GFF3 format; use - for stdin')
parser.add_argument('fasta', type=argparse.FileType('r'),
help='Corresponding sequences in Fasta format')
args = parser.parse_args()
print('##gff-version 3')
for seqid, seqlen in seq_len(args.fasta):
print('##sequence-region %s 1 %d' % (seqid, seqlen))
for entry in parse_gff3(args.gff3):
print(entry)
|
isc
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
1898,
334,
67,
9,
7129,
13,
7806,
12,
24747,
14769,
428,
14,
1933,
460,
474,
436,
6483,
199,
3,
199,
3,
710,
24475,
4240,
2493,
15650,
6065,
365,
1854,
1334,
314,
2281,
35,
844,
14,
1666,
199,
3,
314,
283,
3961,
7,
570,
315,
314,
24475,
4240,
2493,
1350,
1233,
4084,
503,
199,
3,
18470,
737,
4178,
921,
5031,
14,
957,
15,
7935,
474,
15,
12500,
4240,
2493,
15,
6582,
15,
4133,
15,
3961,
14,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
646,
7534,
199,
646,
747,
199,
646,
295,
199,
646,
3873,
199,
646,
984,
421,
199,
318,
2198,
63,
20309,
8,
3997,
304,
272,
408,
4759,
552,
1033,
313,
2003,
590,
687,
1455,
921,
23153,
14,
957,
15,
65,
15,
2114,
1229,
20281,
15,
20,
15459,
1257,
1041,
272,
536,
12,
5412,
275,
488,
12,
942,
272,
367,
1004,
315,
4090,
26,
267,
1004,
275,
1004,
14,
6735,
342,
267,
340,
1004,
14,
2460,
16099,
735,
288,
340,
536,
26,
355,
1995,
334,
354,
12,
6522,
904,
8,
3610,
430,
288,
536,
12,
5412,
275,
1004,
12,
942,
267,
587,
26,
288,
5412,
14,
740,
8,
604,
9,
272,
340,
536,
26,
267,
1995,
334,
354,
12,
6522,
904,
8,
3610,
430,
421,
199,
318,
5412,
63,
552,
8,
3997,
304,
272,
367,
347,
604,
12,
5412,
315,
2198,
63,
20309,
8,
3997,
304,
267,
25995,
275,
347,
604,
59,
17,
11455,
1294,
480,
298,
2788,
16,
61,
267,
1995,
25995,
12,
822,
8,
3610,
9,
421,
199,
318,
2198,
63,
71,
556,
19,
8,
3997,
304,
272,
367,
1004,
315,
4090,
26,
267,
340,
1004,
14,
2460,
360,
309,
71,
556,
13,
1023,
358,
503,
971,
1779,
1004,
14,
2460,
360,
309,
4041,
13,
4551,
735,
288,
1980,
267,
1995,
1004,
14,
6735,
342,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
4328,
275,
283,
19993,
282,
598,
1665,
19,
3985,
83,
3414,
13,
4551,
4811,
543,
10859,
1207,
8013,
7,
272,
1798,
275,
7534,
14,
10730,
8,
1802,
29,
3257,
9,
272,
1798,
14,
525,
63,
2094,
360,
71,
556,
19,
297,
730,
29,
18978,
14,
20683,
360,
82,
659,
717,
1720,
534,
16768,
315,
598,
1665,
19,
1475,
27,
675,
446,
367,
9009,
358,
272,
1798,
14,
525,
63,
2094,
360,
20309,
297,
730,
29,
18978,
14,
20683,
360,
82,
659,
717,
1720,
534,
8380,
31137,
8013,
315,
10859,
1207,
1475,
358,
272,
1249,
275,
1798,
14,
1122,
63,
589,
342,
339,
870,
360,
309,
71,
556,
13,
1023,
257,
650,
358,
272,
367,
25995,
12,
5412,
552,
315,
5412,
63,
552,
8,
589,
14,
20309,
304,
267,
870,
360,
309,
4041,
13,
4551,
258,
450,
83,
413,
450,
68,
7,
450,
334,
26693,
12,
5412,
552,
430,
339,
367,
2397,
315,
2198,
63,
71,
556,
19,
8,
589,
14,
71,
556,
19,
304,
267,
870,
8,
2373,
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
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
1898,
334,
67,
9,
7129,
13,
7806,
12,
24747,
14769,
428,
14,
1933,
460,
474,
436,
6483,
199,
3,
199,
3,
710,
24475,
4240,
2493,
15650,
6065,
365,
1854,
1334,
314,
2281,
35,
844,
14,
1666,
199,
3,
314,
283,
3961,
7,
570,
315,
314,
24475,
4240,
2493,
1350,
1233,
4084,
503,
199,
3,
18470,
737,
4178,
921,
5031,
14,
957,
15,
7935,
474,
15,
12500,
4240,
2493,
15,
6582,
15,
4133,
15,
3961,
14,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
646,
7534,
199,
646,
747,
199,
646,
295,
199,
646,
3873,
199,
646,
984,
421,
199,
318,
2198,
63,
20309,
8,
3997,
304,
272,
408,
4759,
552,
1033,
313,
2003,
590,
687,
1455,
921,
23153,
14,
957,
15,
65,
15,
2114,
1229,
20281,
15,
20,
15459,
1257,
1041,
272,
536,
12,
5412,
275,
488,
12,
942,
272,
367,
1004,
315,
4090,
26,
267,
1004,
275,
1004,
14,
6735,
342,
267,
340,
1004,
14,
2460,
16099,
735,
288,
340,
536,
26,
355,
1995,
334,
354,
12,
6522,
904,
8,
3610,
430,
288,
536,
12,
5412,
275,
1004,
12,
942,
267,
587,
26,
288,
5412,
14,
740,
8,
604,
9,
272,
340,
536,
26,
267,
1995,
334,
354,
12,
6522,
904,
8,
3610,
430,
421,
199,
318,
5412,
63,
552,
8,
3997,
304,
272,
367,
347,
604,
12,
5412,
315,
2198,
63,
20309,
8,
3997,
304,
267,
25995,
275,
347,
604,
59,
17,
11455,
1294,
480,
298,
2788,
16,
61,
267,
1995,
25995,
12,
822,
8,
3610,
9,
421,
199,
318,
2198,
63,
71,
556,
19,
8,
3997,
304,
272,
367,
1004,
315,
4090,
26,
267,
340,
1004,
14,
2460,
360,
309,
71,
556,
13,
1023,
358,
503,
971,
1779,
1004,
14,
2460,
360,
309,
4041,
13,
4551,
735,
288,
1980,
267,
1995,
1004,
14,
6735,
342,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
4328,
275,
283,
19993,
282,
598,
1665,
19,
3985,
83,
3414,
13,
4551,
4811,
543,
10859,
1207,
8013,
7,
272,
1798,
275,
7534,
14,
10730,
8,
1802,
29,
3257,
9,
272,
1798,
14,
525,
63,
2094,
360,
71,
556,
19,
297,
730,
29,
18978,
14,
20683,
360,
82,
659,
717,
1720,
534,
16768,
315,
598,
1665,
19,
1475,
27,
675,
446,
367,
9009,
358,
272,
1798,
14,
525,
63,
2094,
360,
20309,
297,
730,
29,
18978,
14,
20683,
360,
82,
659,
717,
1720,
534,
8380,
31137,
8013,
315,
10859,
1207,
1475,
358,
272,
1249,
275,
1798,
14,
1122,
63,
589,
342,
339,
870,
360,
309,
71,
556,
13,
1023,
257,
650,
358,
272,
367,
25995,
12,
5412,
552,
315,
5412,
63,
552,
8,
589,
14,
20309,
304,
267,
870,
360,
309,
4041,
13,
4551,
258,
450,
83,
413,
450,
68,
7,
450,
334,
26693,
12,
5412,
552,
430,
339,
367,
2397,
315,
2198,
63,
71,
556,
19,
8,
589,
14,
71,
556,
19,
304,
267,
870,
8,
2373,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ramitsurana/boto
|
boto/cloudformation/__init__.py
|
131
|
2157
|
# Copyright (c) 2010-2011 Mitch Garnaat http://garnaat.org/
# Copyright (c) 2010-2011, Eucalyptus Systems, Inc.
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish, dis-
# tribute, sublicense, and/or sell copies of the Software, and to permit
# persons to whom the Software is furnished to do so, subject to the fol-
# lowing conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
from boto.cloudformation.connection import CloudFormationConnection
from boto.regioninfo import RegionInfo, get_regions, load_regions
RegionData = load_regions().get('cloudformation')
def regions():
"""
Get all available regions for the CloudFormation service.
:rtype: list
:return: A list of :class:`boto.RegionInfo` instances
"""
return get_regions(
'cloudformation',
connection_cls=CloudFormationConnection
)
def connect_to_region(region_name, **kw_params):
"""
Given a valid region name, return a
:class:`boto.cloudformation.CloudFormationConnection`.
:param str region_name: The name of the region to connect to.
:rtype: :class:`boto.cloudformation.CloudFormationConnection` or ``None``
:return: A connection to the given region, or None if an invalid region
name is given
"""
for region in regions():
if region.name == region_name:
return region.connect(**kw_params)
return None
|
mit
|
[
3,
1898,
334,
67,
9,
7129,
13,
8128,
603,
9414,
598,
26272,
1455,
921,
71,
26272,
14,
1308,
15,
199,
3,
1898,
334,
67,
9,
7129,
13,
8128,
12,
662,
85,
915,
89,
541,
527,
15285,
12,
3277,
14,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
199,
3,
1331,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
199,
3,
298,
10337,
1288,
370,
7962,
315,
314,
2290,
1928,
10588,
12,
5893,
199,
3,
1928,
12305,
314,
4481,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
2153,
13,
199,
3,
28420,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
314,
2290,
12,
436,
370,
11291,
199,
3,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
880,
12,
5420,
370,
314,
1699,
13,
199,
3,
28486,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
199,
3,
315,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
199,
3,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
28471,
13,
199,
3,
28463,
12,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
199,
3,
7000,
2334,
17632,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
199,
3,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
199,
3,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
199,
3,
1621,
2334,
4141,
14,
199,
199,
504,
6055,
14,
4091,
1869,
14,
2105,
492,
8142,
1858,
1615,
3225,
199,
504,
6055,
14,
4551,
815,
492,
22240,
2354,
12,
664,
63,
11963,
12,
2248,
63,
11963,
199,
199,
10708,
1451,
275,
2248,
63,
11963,
1252,
362,
360,
4091,
1869,
358,
421,
199,
318,
16150,
837,
272,
408,
272,
2372,
1006,
2808,
16150,
367,
314,
8142,
1858,
1615,
2435,
14,
339,
520,
4500,
26,
769,
272,
520,
1107,
26,
437,
769,
402,
520,
533,
1705,
10914,
14,
10708,
2354,
64,
4454,
272,
408,
272,
372,
664,
63,
11963,
8,
267,
283,
4091,
1869,
297,
267,
1950,
63,
1886,
29,
9089,
1858,
1615,
3225,
272,
776,
421,
199,
318,
4907,
63,
475,
63,
4551,
8,
4551,
63,
354,
12,
1011,
829,
63,
1162,
304,
272,
408,
272,
9138,
282,
1686,
4897,
536,
12,
372,
282,
272,
520,
533,
1705,
10914,
14,
4091,
1869,
14,
9089,
1858,
1615,
3225,
2313,
339,
520,
635,
620,
4897,
63,
354,
26,
710,
536,
402,
314,
4897,
370,
4907,
370,
14,
339,
520,
4500,
26,
520,
533,
1705,
10914,
14,
4091,
1869,
14,
9089,
1858,
1615,
3225,
64,
503,
1124,
403,
1040,
272,
520,
1107,
26,
437,
1950,
370,
314,
1627,
4897,
12,
503,
488,
340,
376,
3866,
4897,
267,
536,
365,
1627,
272,
408,
272,
367,
4897,
315,
16150,
837,
267,
340,
4897,
14,
354,
508,
4897,
63,
354,
26,
288,
372,
4897,
14,
2242,
3682,
829,
63,
1162,
9,
272,
372,
488,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
7129,
13,
8128,
603,
9414,
598,
26272,
1455,
921,
71,
26272,
14,
1308,
15,
199,
3,
1898,
334,
67,
9,
7129,
13,
8128,
12,
662,
85,
915,
89,
541,
527,
15285,
12,
3277,
14,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
199,
3,
1331,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
199,
3,
298,
10337,
1288,
370,
7962,
315,
314,
2290,
1928,
10588,
12,
5893,
199,
3,
1928,
12305,
314,
4481,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
2153,
13,
199,
3,
28420,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
314,
2290,
12,
436,
370,
11291,
199,
3,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
880,
12,
5420,
370,
314,
1699,
13,
199,
3,
28486,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
199,
3,
315,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
199,
3,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
28471,
13,
199,
3,
28463,
12,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
199,
3,
7000,
2334,
17632,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
199,
3,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
199,
3,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
199,
3,
1621,
2334,
4141,
14,
199,
199,
504,
6055,
14,
4091,
1869,
14,
2105,
492,
8142,
1858,
1615,
3225,
199,
504,
6055,
14,
4551,
815,
492,
22240,
2354,
12,
664,
63,
11963,
12,
2248,
63,
11963,
199,
199,
10708,
1451,
275,
2248,
63,
11963,
1252,
362,
360,
4091,
1869,
358,
421,
199,
318,
16150,
837,
272,
408,
272,
2372,
1006,
2808,
16150,
367,
314,
8142,
1858,
1615,
2435,
14,
339,
520,
4500,
26,
769,
272,
520,
1107,
26,
437,
769,
402,
520,
533,
1705,
10914,
14,
10708,
2354,
64,
4454,
272,
408,
272,
372,
664,
63,
11963,
8,
267,
283,
4091,
1869,
297,
267,
1950,
63,
1886,
29,
9089,
1858,
1615,
3225,
272,
776,
421,
199,
318,
4907,
63,
475,
63,
4551,
8,
4551,
63,
354,
12,
1011,
829,
63,
1162,
304,
272,
408,
272,
9138,
282,
1686,
4897,
536,
12,
372,
282,
272,
520,
533,
1705,
10914,
14,
4091,
1869,
14,
9089,
1858,
1615,
3225,
2313,
339,
520,
635,
620,
4897,
63,
354,
26,
710,
536,
402,
314,
4897,
370,
4907,
370,
14,
339,
520,
4500,
26,
520,
533,
1705,
10914,
14,
4091,
1869,
14,
9089,
1858,
1615,
3225,
64,
503,
1124,
403,
1040,
272,
520,
1107,
26,
437,
1950,
370,
314,
1627,
4897,
12,
503,
488,
340,
376,
3866,
4897,
267,
536,
365,
1627,
272,
408,
272,
367,
4897,
315,
16150,
837,
267,
340,
4897,
14,
354,
508,
4897,
63,
354,
26,
288,
372,
4897,
14,
2242,
3682,
829,
63,
1162,
9,
272,
372,
488,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
vmax-feihu/hue
|
desktop/core/ext-py/django-openid-auth-0.5/django_openid_auth/store.py
|
45
|
4822
|
# django-openid-auth - OpenID integration for django.contrib.auth
#
# Copyright (C) 2007 Simon Willison
# Copyright (C) 2008-2013 Canonical Ltd.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
import base64
import time
from openid.association import Association as OIDAssociation
from openid.store.interface import OpenIDStore
from openid.store.nonce import SKEW
from django_openid_auth.models import Association, Nonce
class DjangoOpenIDStore(OpenIDStore):
def __init__(self):
self.max_nonce_age = 6 * 60 * 60 # Six hours
def storeAssociation(self, server_url, association):
try:
assoc = Association.objects.get(
server_url=server_url, handle=association.handle)
except Association.DoesNotExist:
assoc = Association(
server_url=server_url,
handle=association.handle,
secret=base64.encodestring(association.secret),
issued=association.issued,
lifetime=association.lifetime,
assoc_type=association.assoc_type)
else:
assoc.secret = base64.encodestring(association.secret)
assoc.issued = association.issued
assoc.lifetime = association.lifetime
assoc.assoc_type = association.assoc_type
assoc.save()
def getAssociation(self, server_url, handle=None):
assocs = []
if handle is not None:
assocs = Association.objects.filter(
server_url=server_url, handle=handle)
else:
assocs = Association.objects.filter(server_url=server_url)
associations = []
expired = []
for assoc in assocs:
association = OIDAssociation(
assoc.handle, base64.decodestring(assoc.secret), assoc.issued,
assoc.lifetime, assoc.assoc_type
)
if association.getExpiresIn() == 0:
expired.append(assoc)
else:
associations.append((association.issued, association))
for assoc in expired:
assoc.delete()
if not associations:
return None
associations.sort()
return associations[-1][1]
def removeAssociation(self, server_url, handle):
assocs = list(Association.objects.filter(
server_url=server_url, handle=handle))
assocs_exist = len(assocs) > 0
for assoc in assocs:
assoc.delete()
return assocs_exist
def useNonce(self, server_url, timestamp, salt):
if abs(timestamp - time.time()) > SKEW:
return False
try:
ononce = Nonce.objects.get(
server_url__exact=server_url,
timestamp__exact=timestamp,
salt__exact=salt)
except Nonce.DoesNotExist:
ononce = Nonce(
server_url=server_url,
timestamp=timestamp,
salt=salt)
ononce.save()
return True
return False
def cleanupNonces(self, _now=None):
if _now is None:
_now = int(time.time())
expired = Nonce.objects.filter(timestamp__lt=_now - SKEW)
count = expired.count()
if count:
expired.delete()
return count
def cleanupAssociations(self):
now = int(time.time())
expired = Association.objects.extra(
where=['issued + lifetime < %d' % now])
count = expired.count()
if count:
expired.delete()
return count
|
apache-2.0
|
[
3,
1639,
13,
15403,
13,
1178,
446,
221,
25463,
13150,
367,
1639,
14,
2828,
14,
1178,
199,
3,
199,
3,
1898,
334,
35,
9,
10219,
10751,
265,
644,
8148,
834,
199,
3,
1898,
334,
35,
9,
9079,
13,
6965,
6855,
7174,
12126,
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,
199,
3,
787,
7647,
26,
199,
3,
199,
3,
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,
199,
3,
627,
6823,
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,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
199,
3,
2381,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
199,
3,
5877,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
199,
3,
9716,
12,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
199,
3,
5400,
2845,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
199,
3,
9102,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
199,
3,
9817,
2401,
5258,
1821,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
199,
3,
5603,
12,
1549,
7056,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
199,
3,
1821,
9683,
5738,
1634,
2334,
4815,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
199,
3,
9726,
1634,
9712,
9784,
14,
199,
199,
646,
1300,
772,
199,
646,
900,
199,
199,
504,
24494,
14,
20252,
492,
24207,
425,
465,
593,
998,
18662,
199,
504,
24494,
14,
1617,
14,
3266,
492,
25463,
5502,
199,
504,
24494,
14,
1617,
14,
10667,
492,
428,
2430,
55,
199,
199,
504,
1639,
63,
15403,
63,
1178,
14,
992,
492,
24207,
425,
12,
653,
5089,
421,
199,
533,
5634,
30244,
5502,
8,
30244,
5502,
304,
272,
347,
636,
826,
721,
277,
304,
267,
291,
14,
988,
63,
10667,
63,
474,
275,
1227,
627,
5212,
627,
5212,
327,
428,
1148,
10857,
339,
347,
3877,
18662,
8,
277,
12,
1654,
63,
633,
12,
20640,
304,
267,
862,
26,
288,
22149,
275,
24207,
425,
14,
1462,
14,
362,
8,
355,
1654,
63,
633,
29,
1000,
63,
633,
12,
2429,
29,
20252,
14,
2479,
9,
267,
871,
24207,
425,
14,
7400,
26,
288,
22149,
275,
24207,
425,
8,
355,
1654,
63,
633,
29,
1000,
63,
633,
12,
355,
2429,
29,
20252,
14,
2479,
12,
355,
7565,
29,
1095,
772,
14,
2143,
875,
8,
20252,
14,
4731,
395,
355,
21117,
29,
20252,
14,
5237,
68,
12,
355,
30097,
29,
20252,
14,
27674,
12,
355,
22149,
63,
466,
29,
20252,
14,
16824,
63,
466,
9,
267,
587,
26,
288,
22149,
14,
4731,
275,
1300,
772,
14,
2143,
875,
8,
20252,
14,
4731,
9,
288,
22149,
14,
5237,
68,
275,
20640,
14,
5237,
68,
288,
22149,
14,
27674,
275,
20640,
14,
27674,
288,
22149,
14,
16824,
63,
466,
275,
20640,
14,
16824,
63,
466,
267,
22149,
14,
2117,
342,
339,
347,
664,
18662,
8,
277,
12,
1654,
63,
633,
12,
2429,
29,
403,
304,
267,
2661,
14851,
275,
942,
267,
340,
2429,
365,
440,
488,
26,
288,
2661,
14851,
275,
24207,
425,
14,
1462,
14,
1541,
8,
355,
1654,
63,
633,
29,
1000,
63,
633,
12,
2429,
29,
2479,
9,
267,
587,
26,
288,
2661,
14851,
275,
24207,
425,
14,
1462,
14,
1541,
8,
1000,
63,
633,
29,
1000,
63,
633,
9,
267,
4035,
1298,
275,
942,
267,
14721,
275,
942,
267,
367,
22149,
315,
2661,
14851,
26,
288,
20640,
275,
593,
998,
18662,
8,
355,
22149,
14,
2479,
12,
1300,
772,
14,
2708,
875,
8,
16824,
14,
4731,
395,
22149,
14,
5237,
68,
12,
355,
22149,
14,
27674,
12,
22149,
14,
16824,
63,
466,
288,
776,
288,
340,
20640,
14,
362,
14000,
470,
607,
342,
508,
378,
26,
355,
14721,
14,
740,
8,
16824,
9,
288,
587,
26,
355,
4035,
1298,
14,
740,
1332,
20252,
14,
5237,
68,
12,
20640,
430,
267,
367,
22149,
315,
14721,
26,
288,
22149,
14,
1807,
342,
267,
340,
440,
4035,
1298,
26,
288,
372,
488,
267,
4035,
1298,
14,
3191,
342,
267,
372,
4035,
1298,
1988,
17,
1527,
17,
61,
339,
347,
2813,
18662,
8,
277,
12,
1654,
63,
633,
12,
2429,
304,
267,
2661,
14851,
275,
769,
8,
18662,
14,
1462,
14,
1541,
8,
288,
1654,
63,
633,
29,
1000,
63,
633,
12,
2429,
29,
2479,
430,
267,
2661,
14851,
63,
4494,
275,
822,
8,
405,
14851,
9,
690,
378,
267,
367,
22149,
315,
2661,
14851,
26,
288,
22149,
14,
1807,
342,
267,
372,
2661,
14851,
63,
4494,
339,
347,
675,
46,
5089,
8,
277,
12,
1654,
63,
633,
12,
4913,
12,
10105,
304,
267,
340,
2853,
8,
3954,
446,
900,
14,
521,
1012,
690,
428,
2430,
55,
26,
288,
372,
756,
398,
862,
26,
288,
641,
5089,
275,
653,
5089,
14,
1462,
14,
362,
8,
355,
1654,
63,
633,
363,
7327,
29,
1000,
63,
633,
12,
355,
4913,
363,
7327,
29,
3954,
12,
355,
10105,
363,
7327,
29,
12597,
9,
267,
871,
653,
5089,
14,
7400,
26,
288,
641,
5089,
275,
653,
5089,
8,
355,
1654,
63,
633,
29,
1000,
63,
633,
12,
355,
4913,
29,
3954,
12,
355,
10105,
29,
12597,
9,
288,
641,
5089,
14,
2117,
342,
288,
372,
715,
398,
372,
756,
339,
347,
9058,
6932,
823,
8,
277,
12,
485,
2131,
29,
403,
304,
267,
340,
485,
2131,
365,
488,
26,
288,
485,
2131,
275,
1109,
8,
521,
14,
521,
1012,
267,
14721,
275,
653,
5089,
14,
1462,
14,
1541,
8,
3954,
363,
4116,
3699,
2131,
446,
428,
2430,
55,
9,
267,
2338,
275,
14721,
14,
835,
342,
267,
340,
2338,
26,
288,
14721,
14,
1807,
342,
267,
372,
2338,
339,
347,
9058,
14889
] |
[
1639,
13,
15403,
13,
1178,
446,
221,
25463,
13150,
367,
1639,
14,
2828,
14,
1178,
199,
3,
199,
3,
1898,
334,
35,
9,
10219,
10751,
265,
644,
8148,
834,
199,
3,
1898,
334,
35,
9,
9079,
13,
6965,
6855,
7174,
12126,
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,
199,
3,
787,
7647,
26,
199,
3,
199,
3,
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,
199,
3,
627,
6823,
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,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
199,
3,
2381,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
199,
3,
5877,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
199,
3,
9716,
12,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
199,
3,
5400,
2845,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
199,
3,
9102,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
199,
3,
9817,
2401,
5258,
1821,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
199,
3,
5603,
12,
1549,
7056,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
199,
3,
1821,
9683,
5738,
1634,
2334,
4815,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
199,
3,
9726,
1634,
9712,
9784,
14,
199,
199,
646,
1300,
772,
199,
646,
900,
199,
199,
504,
24494,
14,
20252,
492,
24207,
425,
465,
593,
998,
18662,
199,
504,
24494,
14,
1617,
14,
3266,
492,
25463,
5502,
199,
504,
24494,
14,
1617,
14,
10667,
492,
428,
2430,
55,
199,
199,
504,
1639,
63,
15403,
63,
1178,
14,
992,
492,
24207,
425,
12,
653,
5089,
421,
199,
533,
5634,
30244,
5502,
8,
30244,
5502,
304,
272,
347,
636,
826,
721,
277,
304,
267,
291,
14,
988,
63,
10667,
63,
474,
275,
1227,
627,
5212,
627,
5212,
327,
428,
1148,
10857,
339,
347,
3877,
18662,
8,
277,
12,
1654,
63,
633,
12,
20640,
304,
267,
862,
26,
288,
22149,
275,
24207,
425,
14,
1462,
14,
362,
8,
355,
1654,
63,
633,
29,
1000,
63,
633,
12,
2429,
29,
20252,
14,
2479,
9,
267,
871,
24207,
425,
14,
7400,
26,
288,
22149,
275,
24207,
425,
8,
355,
1654,
63,
633,
29,
1000,
63,
633,
12,
355,
2429,
29,
20252,
14,
2479,
12,
355,
7565,
29,
1095,
772,
14,
2143,
875,
8,
20252,
14,
4731,
395,
355,
21117,
29,
20252,
14,
5237,
68,
12,
355,
30097,
29,
20252,
14,
27674,
12,
355,
22149,
63,
466,
29,
20252,
14,
16824,
63,
466,
9,
267,
587,
26,
288,
22149,
14,
4731,
275,
1300,
772,
14,
2143,
875,
8,
20252,
14,
4731,
9,
288,
22149,
14,
5237,
68,
275,
20640,
14,
5237,
68,
288,
22149,
14,
27674,
275,
20640,
14,
27674,
288,
22149,
14,
16824,
63,
466,
275,
20640,
14,
16824,
63,
466,
267,
22149,
14,
2117,
342,
339,
347,
664,
18662,
8,
277,
12,
1654,
63,
633,
12,
2429,
29,
403,
304,
267,
2661,
14851,
275,
942,
267,
340,
2429,
365,
440,
488,
26,
288,
2661,
14851,
275,
24207,
425,
14,
1462,
14,
1541,
8,
355,
1654,
63,
633,
29,
1000,
63,
633,
12,
2429,
29,
2479,
9,
267,
587,
26,
288,
2661,
14851,
275,
24207,
425,
14,
1462,
14,
1541,
8,
1000,
63,
633,
29,
1000,
63,
633,
9,
267,
4035,
1298,
275,
942,
267,
14721,
275,
942,
267,
367,
22149,
315,
2661,
14851,
26,
288,
20640,
275,
593,
998,
18662,
8,
355,
22149,
14,
2479,
12,
1300,
772,
14,
2708,
875,
8,
16824,
14,
4731,
395,
22149,
14,
5237,
68,
12,
355,
22149,
14,
27674,
12,
22149,
14,
16824,
63,
466,
288,
776,
288,
340,
20640,
14,
362,
14000,
470,
607,
342,
508,
378,
26,
355,
14721,
14,
740,
8,
16824,
9,
288,
587,
26,
355,
4035,
1298,
14,
740,
1332,
20252,
14,
5237,
68,
12,
20640,
430,
267,
367,
22149,
315,
14721,
26,
288,
22149,
14,
1807,
342,
267,
340,
440,
4035,
1298,
26,
288,
372,
488,
267,
4035,
1298,
14,
3191,
342,
267,
372,
4035,
1298,
1988,
17,
1527,
17,
61,
339,
347,
2813,
18662,
8,
277,
12,
1654,
63,
633,
12,
2429,
304,
267,
2661,
14851,
275,
769,
8,
18662,
14,
1462,
14,
1541,
8,
288,
1654,
63,
633,
29,
1000,
63,
633,
12,
2429,
29,
2479,
430,
267,
2661,
14851,
63,
4494,
275,
822,
8,
405,
14851,
9,
690,
378,
267,
367,
22149,
315,
2661,
14851,
26,
288,
22149,
14,
1807,
342,
267,
372,
2661,
14851,
63,
4494,
339,
347,
675,
46,
5089,
8,
277,
12,
1654,
63,
633,
12,
4913,
12,
10105,
304,
267,
340,
2853,
8,
3954,
446,
900,
14,
521,
1012,
690,
428,
2430,
55,
26,
288,
372,
756,
398,
862,
26,
288,
641,
5089,
275,
653,
5089,
14,
1462,
14,
362,
8,
355,
1654,
63,
633,
363,
7327,
29,
1000,
63,
633,
12,
355,
4913,
363,
7327,
29,
3954,
12,
355,
10105,
363,
7327,
29,
12597,
9,
267,
871,
653,
5089,
14,
7400,
26,
288,
641,
5089,
275,
653,
5089,
8,
355,
1654,
63,
633,
29,
1000,
63,
633,
12,
355,
4913,
29,
3954,
12,
355,
10105,
29,
12597,
9,
288,
641,
5089,
14,
2117,
342,
288,
372,
715,
398,
372,
756,
339,
347,
9058,
6932,
823,
8,
277,
12,
485,
2131,
29,
403,
304,
267,
340,
485,
2131,
365,
488,
26,
288,
485,
2131,
275,
1109,
8,
521,
14,
521,
1012,
267,
14721,
275,
653,
5089,
14,
1462,
14,
1541,
8,
3954,
363,
4116,
3699,
2131,
446,
428,
2430,
55,
9,
267,
2338,
275,
14721,
14,
835,
342,
267,
340,
2338,
26,
288,
14721,
14,
1807,
342,
267,
372,
2338,
339,
347,
9058,
14889,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ElectronicWar/obs-studio
|
CI/install/osx/package_util.py
|
24
|
3406
|
def cmd(cmd):
import subprocess
import shlex
return subprocess.check_output(shlex.split(cmd)).rstrip('\r\n')
def get_tag_info(tag):
rev = cmd('git rev-parse {0}'.format(latest_tag))
anno = cmd('git cat-file -p {0}'.format(rev))
tag_info = []
for i, v in enumerate(anno.splitlines()):
if i <= 4:
continue
tag_info.append(v.lstrip())
return tag_info
def gen_html(github_user, latest_tag):
url = 'https://github.com/{0}/obs-studio/commit/%H'.format(github_user)
with open('readme.html', 'w') as f:
f.write("<html><body>")
log_cmd = """git log {0}...HEAD --pretty=format:'<li>• <a href="{1}">(view)</a> %s</li>'"""
log_res = cmd(log_cmd.format(latest_tag, url))
if len(log_res.splitlines()):
f.write('<p>Changes since {0}: (Newest to oldest)</p>'.format(latest_tag))
f.write(log_res)
ul = False
f.write('<p>')
import re
for l in get_tag_info(latest_tag):
if not len(l):
continue
if l.startswith('*'):
ul = True
if not ul:
f.write('<ul>')
f.write('<li>• {0}</li>'.format(re.sub(r'^(\s*)?[*](\s*)?', '', l)))
else:
if ul:
f.write('</ul><p/>')
ul = False
f.write('<p>{0}</p>'.format(l))
if ul:
f.write('</ul>')
f.write('</p></body></html>')
cmd('textutil -convert rtf readme.html -output readme.rtf')
cmd("""sed -i '' 's/Times-Roman/Verdana/g' readme.rtf""")
def save_manifest(latest_tag, user, jenkins_build, branch, stable):
log = cmd('git log --pretty=oneline {0}...HEAD'.format(latest_tag))
manifest = {}
manifest['commits'] = []
for v in log.splitlines():
manifest['commits'].append(v)
manifest['tag'] = {
'name': latest_tag,
'description': get_tag_info(latest_tag)
}
manifest['version'] = cmd('git rev-list HEAD --count')
manifest['sha1'] = cmd('git rev-parse HEAD')
manifest['jenkins_build'] = jenkins_build
manifest['user'] = user
manifest['branch'] = branch
manifest['stable'] = stable
import cPickle
with open('manifest', 'w') as f:
cPickle.dump(manifest, f)
def prepare_pkg(project, package_id):
cmd('packagesutil --file "{0}" set package-1 identifier {1}'.format(project, package_id))
cmd('packagesutil --file "{0}" set package-1 version {1}'.format(project, '1.0'))
import argparse
parser = argparse.ArgumentParser(description='obs-studio package util')
parser.add_argument('-u', '--user', dest='user', default='jp9000')
parser.add_argument('-p', '--package-id', dest='package_id', default='org.obsproject.pkg.obs-studio')
parser.add_argument('-f', '--project-file', dest='project', default='OBS.pkgproj')
parser.add_argument('-j', '--jenkins-build', dest='jenkins_build', default='0')
parser.add_argument('-b', '--branch', dest='branch', default='master')
parser.add_argument('-s', '--stable', dest='stable', required=False, action='store_true', default=False)
args = parser.parse_args()
latest_tag = cmd('git describe --tags --abbrev=0')
gen_html(args.user, latest_tag)
prepare_pkg(args.project, args.package_id)
save_manifest(latest_tag, args.user, args.jenkins_build, args.branch, args.stable)
|
gpl-2.0
|
[
318,
2088,
8,
1760,
304,
272,
492,
3873,
272,
492,
16701,
272,
372,
3873,
14,
1074,
63,
1199,
8,
32507,
14,
1294,
8,
1760,
4992,
6735,
2258,
82,
60,
78,
358,
199,
199,
318,
664,
63,
1450,
63,
815,
8,
1450,
304,
272,
6822,
275,
2088,
360,
3187,
6822,
13,
1122,
469,
16,
5285,
908,
8,
7410,
63,
1450,
430,
272,
22984,
275,
2088,
360,
3187,
6230,
13,
493,
446,
80,
469,
16,
5285,
908,
8,
4964,
430,
272,
1947,
63,
815,
275,
942,
272,
367,
284,
12,
373,
315,
3874,
8,
25264,
14,
7644,
5109,
267,
340,
284,
2695,
841,
26,
288,
1980,
267,
1947,
63,
815,
14,
740,
8,
86,
14,
10124,
1012,
339,
372,
1947,
63,
815,
199,
199,
318,
3805,
63,
1360,
8,
5031,
63,
751,
12,
8839,
63,
1450,
304,
339,
1166,
275,
283,
2859,
921,
5031,
14,
957,
5321,
16,
5995,
11226,
13,
19806,
15,
3543,
3149,
40,
1370,
908,
8,
5031,
63,
751,
9,
339,
543,
1551,
360,
32709,
14,
1360,
297,
283,
87,
358,
465,
289,
26,
267,
289,
14,
952,
6757,
1360,
2535,
2030,
9579,
267,
943,
63,
1760,
275,
408,
3187,
943,
469,
16,
93,
1396,
5211,
1553,
9118,
29,
908,
4881,
28,
317,
18181,
66,
979,
27,
665,
65,
4369,
18448,
17,
93,
1743,
8,
1345,
15939,
65,
30,
450,
83,
1108,
317,
3524,
624,
267,
943,
63,
470,
275,
2088,
8,
793,
63,
1760,
14,
908,
8,
7410,
63,
1450,
12,
1166,
430,
267,
340,
822,
8,
793,
63,
470,
14,
7644,
5109,
288,
289,
14,
952,
4827,
80,
30,
13907,
3967,
469,
16,
9160,
334,
4665,
597,
370,
29493,
15939,
80,
22936,
908,
8,
7410,
63,
1450,
430,
288,
289,
14,
952,
8,
793,
63,
470,
9,
398,
12581,
275,
756,
267,
289,
14,
952,
4827,
80,
5971,
267,
492,
295,
398,
367,
634,
315,
664,
63,
1450,
63,
815,
8,
7410,
63,
1450,
304,
288,
340,
440,
822,
8,
76,
304,
355,
1980,
288,
340,
634,
14,
2460,
18225,
735,
355,
12581,
275,
715,
355,
340,
440,
12581,
26,
490,
289,
14,
952,
4827,
348,
5971,
355,
289,
14,
952,
4827,
317,
18181,
66,
979,
27,
469,
16,
17890,
317,
22936,
908,
8,
264,
14,
954,
8,
82,
31344,
83,
10,
5547,
59,
30431,
2961,
83,
10,
5547,
297,
3260,
634,
1724,
288,
587,
26,
355,
340,
12581,
26,
490,
289,
14,
952,
14264,
348,
2535,
80,
3133,
358,
355,
12581,
275,
756,
355,
289,
14,
952,
4827,
80,
22266,
16,
17890,
80,
22936,
908,
8,
76,
430,
267,
340,
12581,
26,
288,
289,
14,
952,
14264,
348,
5971,
267,
289,
14,
952,
14264,
80,
2957,
2030,
2957,
1360,
5971,
339,
2088,
360,
505,
1974,
446,
3916,
519,
3249,
1586,
278,
14,
1360,
446,
1199,
1586,
278,
14,
2591,
70,
358,
272,
2088,
4852,
939,
446,
73,
2125,
283,
83,
15,
17687,
13,
50,
21604,
15,
3673,
68,
6738,
15,
71,
7,
1586,
278,
14,
2591,
70,
6141,
199,
199,
318,
3354,
63,
6418,
8,
7410,
63,
1450,
12,
922,
12,
29537,
63,
1506,
12,
5246,
12,
17830,
304,
272,
943,
275,
2088,
360,
3187,
943,
1553,
9118,
29,
265,
32347,
469,
16,
93,
1396,
5211,
1370,
908,
8,
7410,
63,
1450,
430,
272,
7712,
275,
1052,
272,
7712,
459,
18679,
418,
275,
942,
272,
367,
373,
315,
943,
14,
7644,
837,
267,
7712,
459,
18679,
2278,
740,
8,
86,
9,
272,
7712,
459,
1450,
418,
275,
469,
267,
283,
354,
356,
8839,
63,
1450,
12,
267,
283,
1802,
356,
664,
63,
1450,
63,
815,
8,
7410,
63,
1450,
9,
272,
789,
339,
7712,
459,
1023,
418,
275,
2088,
360,
3187,
6822,
13,
513,
13053,
1553,
835,
358,
272,
7712,
459,
4835,
17,
418,
275,
2088,
360,
3187,
6822,
13,
1122,
13053,
358,
272,
7712,
459,
25622,
63,
1506,
418,
275,
29537,
63,
1506,
339,
7712,
459,
751,
418,
275,
922,
272,
7712,
459,
4694,
418,
275,
5246,
272,
7712,
459,
11989,
418,
275,
17830,
339,
492,
17572,
272,
543,
1551,
360,
6418,
297,
283,
87,
358,
465,
289,
26,
267,
17572,
14,
2724,
8,
6418,
12,
289,
9,
199,
199,
318,
9275,
63,
4600,
8,
1715,
12,
2559,
63,
344,
304,
272,
2088,
360,
5154,
1974,
1553,
493,
5310,
16,
7063,
663,
2559,
13,
17,
5148,
469,
17,
5285,
908,
8,
1715,
12,
2559,
63,
344,
430,
272,
2088,
360,
5154,
1974,
1553,
493,
5310,
16,
7063,
663,
2559,
13,
17,
1015,
469,
17,
5285,
908,
8,
1715,
12,
283,
17,
14,
16,
1333,
421,
199,
646,
7534,
199,
2087,
275,
7534,
14,
10730,
8,
1802,
534,
11226,
13,
19806,
2559,
4884,
358,
199,
2087,
14,
525,
63,
2094,
3654,
85,
297,
2850,
751,
297,
2053,
534,
751,
297,
849,
534,
11538,
25,
1493,
358,
199,
2087,
14,
525,
63,
2094,
3654,
80,
297,
2850,
2491,
13,
344,
297,
2053,
534,
2491,
63,
344,
297,
849,
534,
1308,
14,
11226,
1715,
14,
4600,
14,
11226,
13,
19806,
358,
199,
2087,
14,
525,
63,
2094,
3654,
70,
297,
2850,
1715,
13,
493,
297,
2053,
534,
1715,
297,
849,
534,
5488,
51,
14,
4600,
5468,
358,
199,
2087,
14,
525,
63,
2094,
3654,
74,
297,
2850,
25622,
13,
1506,
297,
2053,
534,
25622,
63,
1506,
297,
849,
534,
16,
358,
199,
2087,
14,
525,
63,
2094,
3654,
66,
297,
2850,
4694,
297,
2053,
534,
4694,
297,
849,
534,
4133,
358,
199,
2087,
14,
525,
63,
2094,
3654,
83,
297,
2850,
11989,
297,
2053,
534,
11989,
297,
1415,
29,
797,
12,
1595,
534,
1617,
63,
2052,
297,
849,
29,
797,
9,
199,
589,
275,
1798,
14,
1122,
63,
589,
342,
199,
199,
7410,
63,
1450,
275,
2088,
360,
3187,
13743,
1553,
2969,
1553,
31349,
29,
16,
358,
199,
2268,
63,
1360,
8,
589,
14,
751,
12,
8839,
63,
1450,
9,
199,
6726,
63,
4600,
8,
589,
14,
1715,
12,
1249,
14,
2491,
63,
344,
9,
199,
2117,
63,
6418,
8,
7410,
63,
1450,
12,
1249,
14,
751,
12,
1249,
14,
25622,
63,
1506,
12,
1249,
14,
4694,
12,
1249,
14,
11989,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2088,
8,
1760,
304,
272,
492,
3873,
272,
492,
16701,
272,
372,
3873,
14,
1074,
63,
1199,
8,
32507,
14,
1294,
8,
1760,
4992,
6735,
2258,
82,
60,
78,
358,
199,
199,
318,
664,
63,
1450,
63,
815,
8,
1450,
304,
272,
6822,
275,
2088,
360,
3187,
6822,
13,
1122,
469,
16,
5285,
908,
8,
7410,
63,
1450,
430,
272,
22984,
275,
2088,
360,
3187,
6230,
13,
493,
446,
80,
469,
16,
5285,
908,
8,
4964,
430,
272,
1947,
63,
815,
275,
942,
272,
367,
284,
12,
373,
315,
3874,
8,
25264,
14,
7644,
5109,
267,
340,
284,
2695,
841,
26,
288,
1980,
267,
1947,
63,
815,
14,
740,
8,
86,
14,
10124,
1012,
339,
372,
1947,
63,
815,
199,
199,
318,
3805,
63,
1360,
8,
5031,
63,
751,
12,
8839,
63,
1450,
304,
339,
1166,
275,
283,
2859,
921,
5031,
14,
957,
5321,
16,
5995,
11226,
13,
19806,
15,
3543,
3149,
40,
1370,
908,
8,
5031,
63,
751,
9,
339,
543,
1551,
360,
32709,
14,
1360,
297,
283,
87,
358,
465,
289,
26,
267,
289,
14,
952,
6757,
1360,
2535,
2030,
9579,
267,
943,
63,
1760,
275,
408,
3187,
943,
469,
16,
93,
1396,
5211,
1553,
9118,
29,
908,
4881,
28,
317,
18181,
66,
979,
27,
665,
65,
4369,
18448,
17,
93,
1743,
8,
1345,
15939,
65,
30,
450,
83,
1108,
317,
3524,
624,
267,
943,
63,
470,
275,
2088,
8,
793,
63,
1760,
14,
908,
8,
7410,
63,
1450,
12,
1166,
430,
267,
340,
822,
8,
793,
63,
470,
14,
7644,
5109,
288,
289,
14,
952,
4827,
80,
30,
13907,
3967,
469,
16,
9160,
334,
4665,
597,
370,
29493,
15939,
80,
22936,
908,
8,
7410,
63,
1450,
430,
288,
289,
14,
952,
8,
793,
63,
470,
9,
398,
12581,
275,
756,
267,
289,
14,
952,
4827,
80,
5971,
267,
492,
295,
398,
367,
634,
315,
664,
63,
1450,
63,
815,
8,
7410,
63,
1450,
304,
288,
340,
440,
822,
8,
76,
304,
355,
1980,
288,
340,
634,
14,
2460,
18225,
735,
355,
12581,
275,
715,
355,
340,
440,
12581,
26,
490,
289,
14,
952,
4827,
348,
5971,
355,
289,
14,
952,
4827,
317,
18181,
66,
979,
27,
469,
16,
17890,
317,
22936,
908,
8,
264,
14,
954,
8,
82,
31344,
83,
10,
5547,
59,
30431,
2961,
83,
10,
5547,
297,
3260,
634,
1724,
288,
587,
26,
355,
340,
12581,
26,
490,
289,
14,
952,
14264,
348,
2535,
80,
3133,
358,
355,
12581,
275,
756,
355,
289,
14,
952,
4827,
80,
22266,
16,
17890,
80,
22936,
908,
8,
76,
430,
267,
340,
12581,
26,
288,
289,
14,
952,
14264,
348,
5971,
267,
289,
14,
952,
14264,
80,
2957,
2030,
2957,
1360,
5971,
339,
2088,
360,
505,
1974,
446,
3916,
519,
3249,
1586,
278,
14,
1360,
446,
1199,
1586,
278,
14,
2591,
70,
358,
272,
2088,
4852,
939,
446,
73,
2125,
283,
83,
15,
17687,
13,
50,
21604,
15,
3673,
68,
6738,
15,
71,
7,
1586,
278,
14,
2591,
70,
6141,
199,
199,
318,
3354,
63,
6418,
8,
7410,
63,
1450,
12,
922,
12,
29537,
63,
1506,
12,
5246,
12,
17830,
304,
272,
943,
275,
2088,
360,
3187,
943,
1553,
9118,
29,
265,
32347,
469,
16,
93,
1396,
5211,
1370,
908,
8,
7410,
63,
1450,
430,
272,
7712,
275,
1052,
272,
7712,
459,
18679,
418,
275,
942,
272,
367,
373,
315,
943,
14,
7644,
837,
267,
7712,
459,
18679,
2278,
740,
8,
86,
9,
272,
7712,
459,
1450,
418,
275,
469,
267,
283,
354,
356,
8839,
63,
1450,
12,
267,
283,
1802,
356,
664,
63,
1450,
63,
815,
8,
7410,
63,
1450,
9,
272,
789,
339,
7712,
459,
1023,
418,
275,
2088,
360,
3187,
6822,
13,
513,
13053,
1553,
835,
358,
272,
7712,
459,
4835,
17,
418,
275,
2088,
360,
3187,
6822,
13,
1122,
13053,
358,
272,
7712,
459,
25622,
63,
1506,
418,
275,
29537,
63,
1506,
339,
7712,
459,
751,
418,
275,
922,
272,
7712,
459,
4694,
418,
275,
5246,
272,
7712,
459,
11989,
418,
275,
17830,
339,
492,
17572,
272,
543,
1551,
360,
6418,
297,
283,
87,
358,
465,
289,
26,
267,
17572,
14,
2724,
8,
6418,
12,
289,
9,
199,
199,
318,
9275,
63,
4600,
8,
1715,
12,
2559,
63,
344,
304,
272,
2088,
360,
5154,
1974,
1553,
493,
5310,
16,
7063,
663,
2559,
13,
17,
5148,
469,
17,
5285,
908,
8,
1715,
12,
2559,
63,
344,
430,
272,
2088,
360,
5154,
1974,
1553,
493,
5310,
16,
7063,
663,
2559,
13,
17,
1015,
469,
17,
5285,
908,
8,
1715,
12,
283,
17,
14,
16,
1333,
421,
199,
646,
7534,
199,
2087,
275,
7534,
14,
10730,
8,
1802,
534,
11226,
13,
19806,
2559,
4884,
358,
199,
2087,
14,
525,
63,
2094,
3654,
85,
297,
2850,
751,
297,
2053,
534,
751,
297,
849,
534,
11538,
25,
1493,
358,
199,
2087,
14,
525,
63,
2094,
3654,
80,
297,
2850,
2491,
13,
344,
297,
2053,
534,
2491,
63,
344,
297,
849,
534,
1308,
14,
11226,
1715,
14,
4600,
14,
11226,
13,
19806,
358,
199,
2087,
14,
525,
63,
2094,
3654,
70,
297,
2850,
1715,
13,
493,
297,
2053,
534,
1715,
297,
849,
534,
5488,
51,
14,
4600,
5468,
358,
199,
2087,
14,
525,
63,
2094,
3654,
74,
297,
2850,
25622,
13,
1506,
297,
2053,
534,
25622,
63,
1506,
297,
849,
534,
16,
358,
199,
2087,
14,
525,
63,
2094,
3654,
66,
297,
2850,
4694,
297,
2053,
534,
4694,
297,
849,
534,
4133,
358,
199,
2087,
14,
525,
63,
2094,
3654,
83,
297,
2850,
11989,
297,
2053,
534,
11989,
297,
1415,
29,
797,
12,
1595,
534,
1617,
63,
2052,
297,
849,
29,
797,
9,
199,
589,
275,
1798,
14,
1122,
63,
589,
342,
199,
199,
7410,
63,
1450,
275,
2088,
360,
3187,
13743,
1553,
2969,
1553,
31349,
29,
16,
358,
199,
2268,
63,
1360,
8,
589,
14,
751,
12,
8839,
63,
1450,
9,
199,
6726,
63,
4600,
8,
589,
14,
1715,
12,
1249,
14,
2491,
63,
344,
9,
199,
2117,
63,
6418,
8,
7410,
63,
1450,
12,
1249,
14,
751,
12,
1249,
14,
25622,
63,
1506,
12,
1249,
14,
4694,
12,
1249,
14,
11989,
9,
199,
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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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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
ployground/ploy_fabric
|
setup.py
|
1
|
1176
|
from setuptools import setup
import os
here = os.path.abspath(os.path.dirname(__file__))
README = open(os.path.join(here, 'README.rst')).read()
HISTORY = open(os.path.join(here, 'HISTORY.rst')).read()
version = "1.1.2.dev0"
install_requires = [
'setuptools',
'ploy >= 1.0.0, < 2dev',
'Fabric>=1.4.0,!=1.8.3,<2dev']
setup(
version=version,
description="Plugin to integrate Fabric with ploy.",
long_description=README + "\n\n" + HISTORY,
name="ploy_fabric",
author='Florian Schulze',
author_email='florian.schulze@gmx.net',
license="BSD 3-Clause License",
url='http://github.com/ployground/ploy_fabric',
classifiers=[
'Environment :: Console',
'Intended Audience :: System Administrators',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 2 :: Only',
'Topic :: System :: Installation/Setup',
'Topic :: System :: Systems Administration'],
include_package_data=True,
zip_safe=False,
packages=['ploy_fabric'],
install_requires=install_requires,
entry_points="""
[ploy.plugins]
fabric = ploy_fabric:plugin
""")
|
bsd-3-clause
|
[
504,
9116,
492,
3272,
199,
646,
747,
421,
199,
1681,
275,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
3475,
3460,
493,
8964,
199,
18195,
275,
1551,
8,
736,
14,
515,
14,
904,
8,
1681,
12,
283,
18195,
14,
8332,
11103,
739,
342,
199,
30895,
275,
1551,
8,
736,
14,
515,
14,
904,
8,
1681,
12,
283,
30895,
14,
8332,
11103,
739,
342,
421,
199,
1023,
275,
298,
17,
14,
17,
14,
18,
14,
2374,
16,
2,
421,
199,
3174,
63,
6537,
275,
359,
272,
283,
13623,
297,
272,
283,
80,
3374,
2356,
413,
14,
16,
14,
16,
12,
665,
499,
2374,
297,
272,
283,
38,
2129,
8119,
17,
14,
20,
14,
16,
12,
1111,
17,
14,
24,
14,
19,
30027,
18,
2374,
418,
421,
199,
2758,
8,
272,
1015,
29,
1023,
12,
272,
1369,
628,
5061,
370,
21494,
481,
2129,
543,
299,
3374,
4765,
272,
1846,
63,
1802,
29,
18195,
435,
1867,
78,
60,
78,
2,
435,
869,
6225,
5347,
12,
272,
536,
628,
80,
3374,
63,
4991,
401,
272,
4132,
534,
7579,
269,
5653,
22985,
348,
806,
297,
272,
4132,
63,
2123,
534,
2327,
269,
5653,
14,
15820,
348,
806,
32,
71,
9457,
14,
846,
297,
272,
4190,
628,
15400,
650,
13,
16009,
844,
401,
272,
1166,
534,
1014,
921,
5031,
14,
957,
15,
80,
3374,
3928,
15,
80,
3374,
63,
4991,
297,
272,
19137,
1524,
267,
283,
8263,
3800,
19809,
297,
267,
283,
23910,
23975,
3800,
6187,
9516,
3075,
2750,
297,
267,
283,
11411,
8466,
3800,
2018,
3800,
499,
14,
23,
297,
267,
283,
11411,
8466,
3800,
2018,
3800,
499,
3800,
5972,
297,
267,
283,
12157,
3800,
6187,
3800,
26866,
15,
8555,
297,
267,
283,
12157,
3800,
6187,
3800,
15285,
9516,
4633,
995,
272,
2387,
63,
2491,
63,
576,
29,
549,
12,
272,
3482,
63,
3489,
29,
797,
12,
272,
6117,
2968,
80,
3374,
63,
4991,
995,
272,
3907,
63,
6537,
29,
3174,
63,
6537,
12,
272,
2397,
63,
3438,
11916,
267,
359,
80,
3374,
14,
5265,
61,
267,
2630,
275,
299,
3374,
63,
4991,
26,
2718,
272,
7857,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
9116,
492,
3272,
199,
646,
747,
421,
199,
1681,
275,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
3475,
3460,
493,
8964,
199,
18195,
275,
1551,
8,
736,
14,
515,
14,
904,
8,
1681,
12,
283,
18195,
14,
8332,
11103,
739,
342,
199,
30895,
275,
1551,
8,
736,
14,
515,
14,
904,
8,
1681,
12,
283,
30895,
14,
8332,
11103,
739,
342,
421,
199,
1023,
275,
298,
17,
14,
17,
14,
18,
14,
2374,
16,
2,
421,
199,
3174,
63,
6537,
275,
359,
272,
283,
13623,
297,
272,
283,
80,
3374,
2356,
413,
14,
16,
14,
16,
12,
665,
499,
2374,
297,
272,
283,
38,
2129,
8119,
17,
14,
20,
14,
16,
12,
1111,
17,
14,
24,
14,
19,
30027,
18,
2374,
418,
421,
199,
2758,
8,
272,
1015,
29,
1023,
12,
272,
1369,
628,
5061,
370,
21494,
481,
2129,
543,
299,
3374,
4765,
272,
1846,
63,
1802,
29,
18195,
435,
1867,
78,
60,
78,
2,
435,
869,
6225,
5347,
12,
272,
536,
628,
80,
3374,
63,
4991,
401,
272,
4132,
534,
7579,
269,
5653,
22985,
348,
806,
297,
272,
4132,
63,
2123,
534,
2327,
269,
5653,
14,
15820,
348,
806,
32,
71,
9457,
14,
846,
297,
272,
4190,
628,
15400,
650,
13,
16009,
844,
401,
272,
1166,
534,
1014,
921,
5031,
14,
957,
15,
80,
3374,
3928,
15,
80,
3374,
63,
4991,
297,
272,
19137,
1524,
267,
283,
8263,
3800,
19809,
297,
267,
283,
23910,
23975,
3800,
6187,
9516,
3075,
2750,
297,
267,
283,
11411,
8466,
3800,
2018,
3800,
499,
14,
23,
297,
267,
283,
11411,
8466,
3800,
2018,
3800,
499,
3800,
5972,
297,
267,
283,
12157,
3800,
6187,
3800,
26866,
15,
8555,
297,
267,
283,
12157,
3800,
6187,
3800,
15285,
9516,
4633,
995,
272,
2387,
63,
2491,
63,
576,
29,
549,
12,
272,
3482,
63,
3489,
29,
797,
12,
272,
6117,
2968,
80,
3374,
63,
4991,
995,
272,
3907,
63,
6537,
29,
3174,
63,
6537,
12,
272,
2397,
63,
3438,
11916,
267,
359,
80,
3374,
14,
5265,
61,
267,
2630,
275,
299,
3374,
63,
4991,
26,
2718,
272,
7857,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
ThreatConnect-Inc/tcex
|
tcex/bin/validate.py
|
1
|
23337
|
#!/usr/bin/env python
"""TcEx Framework Validate Module."""
# standard library
import ast
import importlib
import json
import os
import sys
import traceback
from collections import deque
# third-party
import colorama as c
from jsonschema import SchemaError, ValidationError, validate
from stdlib_list import stdlib_list
from .bin import Bin
try:
# third-party
import pkg_resources
except PermissionError:
# this module is only required for certain CLI commands
pass
try:
# standard library
import sqlite3
except ModuleNotFoundError:
# this module is only required for certain CLI commands
pass
class Validate(Bin):
"""Validate syntax, imports, and schemas.
* Python and JSON file syntax
* Python import modules
* install.json schema
* layout.json schema
Args:
_args (namespace): The argparser args Namespace.
"""
def __init__(self, _args):
"""Init Class properties.
Args:
_args (namespace): The argparser args Namespace.
"""
super().__init__(_args)
# class properties
self._app_packages = []
self._install_json_schema = None
self._layout_json_schema = None
self.config = {}
if 'pkg_resources' in sys.modules:
# only set these if pkg_resource module is available
pkg_path = pkg_resources.resource_filename(__name__, '').rstrip('bin')
self.install_json_schema_file = os.path.join(
pkg_path, 'schemas', 'install-json-schema.json'
)
self.layout_json_schema_file = os.path.join(
pkg_path, 'schemas', 'layout-json-schema.json'
)
else:
self.install_json_schema_file = None
self.layout_json_schema_file = None
self.validation_data = self._validation_data
@property
def _validation_data(self):
"""Return structure for validation data."""
return {
'errors': [],
'fileSyntax': [],
'layouts': [],
'moduleImports': [],
'schema': [],
'feeds': [],
}
def _check_node_import(self, node, filename):
if isinstance(node, ast.Import):
for n in node.names:
m = n.name.split('.')[0]
if not self.check_import_stdlib(m):
m_status = self.check_imported(m)
if not m_status:
self.validation_data['errors'].append(
f"""Module validation failed for {filename} """
f"""(module "{m}" could not be imported)."""
)
self.validation_data['moduleImports'].append(
{'filename': filename, 'module': m, 'status': m_status}
)
elif isinstance(node, ast.ImportFrom):
m = node.module.split('.')[0]
if not self.check_import_stdlib(m):
m_status = self.check_imported(m)
if not m_status:
self.validation_data['errors'].append(
f"""Module validation failed for {filename} """
f"""(module "{m}" could not be imported)."""
)
self.validation_data['moduleImports'].append(
{'filename': filename, 'module': m, 'status': m_status}
)
def check_imports(self):
"""Check the projects top level directory for missing imports.
This method will check only files ending in **.py** and does not handle imports validation
for sub-directories.
"""
for filename in sorted(os.listdir(self.app_path)):
if not filename.endswith('.py'):
continue
fq_path = os.path.join(self.app_path, filename)
with open(fq_path, 'rb') as f:
# TODO: fix this
code_lines = deque([(f.read(), 1)])
while code_lines:
code, lineno = code_lines.popleft() # pylint: disable=unused-variable
try:
parsed_code = ast.parse(code)
for node in ast.walk(parsed_code):
self._check_node_import(node, filename)
except SyntaxError:
pass
def check_feed_files(self):
"""Validate feed files for feed job apps."""
package_name = f'{self.tj.package_app_name}_v{self.ij.program_version.split(".")[0]}'
package_name = package_name.replace('_', ' ')
if self.ij.runtime_level == 'Organization':
for i, feed in enumerate(self.ij.feeds):
passed = True
feed_name = f'(feeds[{i}]) {feed.get("sourceName")}'
job_file = feed.get('jobFile')
if not os.path.isfile(feed.get('jobFile')):
self.validation_data['errors'].append(
f'Feed validation failed '
f'(Feed {i} references non-existent job-file {job_file})'
)
passed = False
else:
try:
job = json.load(open(job_file))
if 'programName' not in job:
self.validation_data['errors'].append(
f'Feed file validation failed for {job_file} '
f'({job_file} does not contain required field \'programNme\')'
)
passed = False
else:
job_program_name = job.get('programName')
if job_program_name != package_name:
self.validation_data['errors'].append(
f'Feed file validation failed for {job_file} '
f'(programName in file name does not match package name '
f'{package_name})'
)
passed = False
except json.decoder.JSONDecodeError as j:
self.validation_data['errors'].append(
f'Feed file validation failed for {job_file} '
f'({job_file} is not valid JSON: {j})'
)
passed = False
if feed.get('attributesFile') and not os.path.isfile(feed.get('attributesFile')):
self.validation_data['errors'].append(
f'Feed validation failed '
f'(Feed {i} references non-existent attributes file '
f'{feed.get("attributesFile")})'
)
passed = False
self.validation_data['feeds'].append({'name': feed_name, 'status': passed})
@staticmethod
def check_import_stdlib(module):
"""Check if module is in Python stdlib.
Args:
module (str): The name of the module to check.
Returns:
bool: Returns True if the module is in the stdlib or template.
"""
if (
module in stdlib_list('3.6')
or module in stdlib_list('3.7')
or module in stdlib_list('3.8')
or module in ['app', 'args', 'job_app', 'playbook_app', 'run', 'service_app']
):
return True
return False
@staticmethod
def check_imported(module):
"""Check whether the provide module can be imported (package installed).
Args:
module (str): The name of the module to check availability.
Returns:
bool: True if the module can be imported, False otherwise.
"""
try:
del sys.modules[module]
except (AttributeError, KeyError):
pass
# https://docs.python.org/3/library/importlib.html#checking-if-a-module-can-be-imported
find_spec = importlib.util.find_spec(module)
found = find_spec is not None
if found is True:
# if dist-packages|site-packages in module_path the import doesn't count
if 'dist-packages' in find_spec.origin:
found = False
if 'site-packages' in find_spec.origin:
found = False
return found
def check_install_json(self):
"""Check all install.json files for valid schema."""
if self.install_json_schema is None:
return
contents = os.listdir(self.app_path)
if self.args.install_json is not None:
contents = [self.args.install_json]
for install_json in sorted(contents):
# skip files that are not install.json files
if 'install.json' not in install_json:
continue
error = None
status = True
try:
# loading explicitly here to keep all error catching in this file
with open(install_json) as fh:
data = json.loads(fh.read())
validate(data, self.install_json_schema)
except SchemaError as e:
status = False
error = e
except ValidationError as e:
status = False
error = e.message
except ValueError:
# any JSON decode error will be caught during syntax validation
return
if error:
# update validation data errors
self.validation_data['errors'].append(
f'Schema validation failed for {install_json} ({error}).'
)
# update validation data for module
self.validation_data['schema'].append({'filename': install_json, 'status': status})
def check_layout_json(self):
"""Check all layout.json files for valid schema."""
# the install.json files can't be validates if the schema file is not present
layout_json_file = 'layout.json'
if self.layout_json_schema is None or not os.path.isfile(layout_json_file):
return
error = None
status = True
try:
# loading explicitly here to keep all error catching in this file
with open(layout_json_file) as fh:
data = json.loads(fh.read())
validate(data, self.layout_json_schema)
except SchemaError as e:
status = False
error = e
except ValidationError as e:
status = False
error = e.message
except ValueError:
# any JSON decode error will be caught during syntax validation
return
# update validation data for module
self.validation_data['schema'].append({'filename': layout_json_file, 'status': status})
if error:
# update validation data errors
self.validation_data['errors'].append(
f'Schema validation failed for {layout_json_file} ({error}).'
)
else:
self.check_layout_params()
def check_layout_params(self):
"""Check that the layout.json is consistent with install.json.
The layout.json files references the params.name from the install.json file. The method
will validate that no reference appear for inputs in install.json that don't exist.
"""
# do not track hidden or serviceConfig inputs as they should not be in layouts.json
ij_input_names = [
p.get('name')
for p in self.ij.filter_params_dict(service_config=False, hidden=False).values()
]
ij_output_names = [o.get('name') for o in self.ij.output_variables]
# Check for duplicate inputs
for name in self.ij.validate_duplicate_input_names():
self.validation_data['errors'].append(
f'Duplicate input name found in install.json ({name})'
)
status = False
# Check for duplicate sequence numbers
for sequence in self.ij.validate_duplicate_sequences():
self.validation_data['errors'].append(
f'Duplicate sequence number found in install.json ({sequence})'
)
status = False
# Check for duplicate outputs variables
for output in self.ij.validate_duplicate_outputs():
self.validation_data['errors'].append(
f'Duplicate output variable name found in install.json ({output})'
)
status = False
if 'sqlite3' in sys.modules:
# create temporary inputs tables
self.permutations.db_create_table(self.permutations.input_table, ij_input_names)
# inputs
status = True
for i in self.lj.inputs:
for p in i.get('parameters'):
if p.get('name') not in ij_input_names:
# update validation data errors
self.validation_data['errors'].append(
'Layouts input.parameters[].name validations failed '
f"""("{p.get('name')}" is defined in layout.json, """
'but hidden or not found in install.json).'
)
status = False
else:
# any item in list afterwards is a problem
ij_input_names.remove(p.get('name'))
if 'sqlite3' in sys.modules:
if p.get('display'):
display_query = (
f'''SELECT * FROM {self.permutations.input_table}''' # nosec
f''' WHERE {p.get('display')}'''
)
try:
self.permutations.db_conn.execute(display_query.replace('"', ''))
except sqlite3.Error:
self.validation_data['errors'].append(
'''Layouts input.parameters[].display validations failed '''
f'''("{p.get('display')}" query is an invalid statement).'''
)
status = False
# update validation data for module
self.validation_data['layouts'].append({'params': 'inputs', 'status': status})
if ij_input_names:
input_names = ','.join(ij_input_names)
# update validation data errors
self.validation_data['errors'].append(
f'Layouts input.parameters[].name validations failed ("{input_names}" '
'values from install.json were not included in layout.json.'
)
status = False
# outputs
status = True
for o in self.lj.outputs:
if o.get('name') not in ij_output_names:
# update validation data errors
self.validation_data['errors'].append(
f'''Layouts output validations failed ({o.get('name')} is defined '''
'''in layout.json, but not found in install.json).'''
)
status = False
if 'sqlite3' in sys.modules:
if o.get('display'):
display_query = (
f'''SELECT * FROM {self.permutations.input_table} ''' # nosec
f'''WHERE {o.get('display')}'''
)
try:
self.permutations.db_conn.execute(display_query.replace('"', ''))
except sqlite3.Error:
self.validation_data['errors'].append(
f"""Layouts outputs.display validations failed ("{o.get('display')}" """
f"""query is an invalid statement)."""
)
status = False
# update validation data for module
self.validation_data['layouts'].append({'params': 'outputs', 'status': status})
def check_syntax(self, app_path=None):
"""Run syntax on each ".py" and ".json" file.
Args:
app_path (str, optional): Defaults to None. The path of Python files.
"""
app_path = app_path or '.'
for filename in sorted(os.listdir(app_path)):
error = None
status = True
if filename.endswith('.py'):
try:
with open(filename, 'rb') as f:
ast.parse(f.read(), filename=filename)
except SyntaxError:
status = False
# cleanup output
e = []
for line in traceback.format_exc().split('\n')[-5:-2]:
e.append(line.strip())
error = ' '.join(e)
elif filename.endswith('.json'):
try:
with open(filename) as fh:
json.load(fh)
except ValueError as e:
status = False
error = e
else:
# skip unsupported file types
continue
if error:
# update validation data errors
self.validation_data['errors'].append(
f'Syntax validation failed for {filename} ({error}).'
)
# store status for this file
self.validation_data['fileSyntax'].append({'filename': filename, 'status': status})
@property
def install_json_schema(self):
"""Load install.json schema file."""
if self._install_json_schema is None and self.install_json_schema_file is not None:
# remove old schema file
if os.path.isfile('tcex_json_schema.json'):
# this file is now part of tcex.
os.remove('tcex_json_schema.json')
if os.path.isfile(self.install_json_schema_file):
with open(self.install_json_schema_file) as fh:
self._install_json_schema = json.load(fh)
return self._install_json_schema
def interactive(self):
"""Run in interactive mode."""
while True:
line = sys.stdin.readline().strip()
if line == 'quit':
sys.exit()
elif line == 'validate':
self.check_syntax()
self.check_imports()
self.check_install_json()
self.check_layout_json()
self.check_feed_files()
self.print_json()
# reset validation_data
self.validation_data = self._validation_data
@property
def layout_json_schema(self):
"""Load layout.json schema file."""
if self._layout_json_schema is None and self.layout_json_schema_file is not None:
if os.path.isfile(self.layout_json_schema_file):
with open(self.layout_json_schema_file) as fh:
self._layout_json_schema = json.load(fh)
return self._layout_json_schema
def print_json(self):
"""Print JSON output."""
print(json.dumps({'validation_data': self.validation_data}))
def _print_file_syntax_results(self):
if self.validation_data.get('fileSyntax'):
print(f'\n{c.Style.BRIGHT}{c.Fore.BLUE}Validated File Syntax:')
print(f"{c.Style.BRIGHT}{'File:'!s:<60}{'Status:'!s:<25}")
for f in self.validation_data.get('fileSyntax'):
status_color = self.status_color(f.get('status'))
status_value = self.status_value(f.get('status'))
print(f"{f.get('filename')!s:<60}{status_color}{status_value!s:<25}")
def _print_imports_results(self):
if self.validation_data.get('moduleImports'):
print(f'\n{c.Style.BRIGHT}{c.Fore.BLUE}Validated Imports:')
print(f"{c.Style.BRIGHT}{'File:'!s:<30}{'Module:'!s:<30}{'Status:'!s:<25}")
for f in self.validation_data.get('moduleImports'):
status_color = self.status_color(f.get('status'))
status_value = self.status_value(f.get('status'))
print(
f"{f.get('filename')!s:<30}{c.Fore.WHITE}"
f"{f.get('module')!s:<30}{status_color}{status_value!s:<25}"
)
def _print_schema_results(self):
if self.validation_data.get('schema'):
print(f'\n{c.Style.BRIGHT}{c.Fore.BLUE}Validated Schema:')
print(f"{c.Style.BRIGHT}{'File:'!s:<60}{'Status:'!s:<25}")
for f in self.validation_data.get('schema'):
status_color = self.status_color(f.get('status'))
status_value = self.status_value(f.get('status'))
print(f"{f.get('filename')!s:<60}{status_color}{status_value!s:<25}")
def _print_layouts_results(self):
if self.validation_data.get('layouts'):
print(f'\n{c.Style.BRIGHT}{c.Fore.BLUE}Validated Layouts:')
print(f"{c.Style.BRIGHT}{'Params:'!s:<60}{'Status:'!s:<25}")
for f in self.validation_data.get('layouts'):
status_color = self.status_color(f.get('status'))
status_value = self.status_value(f.get('status'))
print(f"{f.get('params')!s:<60}{status_color}{status_value!s:<25}")
def _print_feed_results(self):
if self.validation_data.get('feeds'):
print(f'\n{c.Style.BRIGHT}{c.Fore.BLUE}Validated Feed Jobs:')
print(f"{c.Style.BRIGHT}{'Feeds:'!s:<60}{'Status:'!s:<25}")
for f in self.validation_data.get('feeds'):
status_color = self.status_color(f.get('status'))
status_value = self.status_value(f.get('status'))
print(f"{f.get('name')!s:<60}{status_color}{status_value!s:<25}")
def _print_errors(self):
if self.validation_data.get('errors'):
print('\n') # separate errors from normal output
for error in self.validation_data.get('errors'):
# print all errors
print(f'* {c.Fore.RED}{error}')
# ignore exit code
if not self.args.ignore_validation:
self.exit_code = 1
def print_results(self):
"""Print results."""
# Validating Syntax
self._print_file_syntax_results()
# Validating Imports
self._print_imports_results()
# Validating Schema
self._print_schema_results()
# Validating Layouts
self._print_layouts_results()
# Validating Feed Job Definition Files
self._print_feed_results()
self._print_errors()
@staticmethod
def status_color(status):
"""Return the appropriate status color."""
return c.Fore.GREEN if status else c.Fore.RED
@staticmethod
def status_value(status):
"""Return the appropriate status color."""
return 'passed' if status else 'failed'
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
624,
52,
67,
920,
22545,
12134,
5673,
1041,
199,
3,
4465,
3555,
199,
646,
6073,
199,
646,
14802,
199,
646,
2022,
199,
646,
747,
199,
646,
984,
199,
646,
5190,
199,
504,
5055,
492,
15782,
199,
199,
3,
10919,
13,
7522,
199,
646,
3164,
14541,
465,
286,
199,
504,
2022,
3629,
492,
13268,
547,
12,
8505,
12,
4107,
199,
504,
26678,
63,
513,
492,
26678,
63,
513,
199,
199,
504,
1275,
1393,
492,
32613,
199,
199,
893,
26,
272,
327,
10919,
13,
7522,
272,
492,
5496,
63,
4435,
199,
2590,
8779,
547,
26,
272,
327,
642,
859,
365,
1454,
1415,
367,
9842,
14214,
3718,
272,
986,
199,
199,
893,
26,
272,
327,
4465,
3555,
272,
492,
11723,
19,
199,
2590,
5673,
10870,
26,
272,
327,
642,
859,
365,
1454,
1415,
367,
9842,
14214,
3718,
272,
986,
421,
199,
533,
12134,
8,
13394,
304,
272,
408,
12584,
6302,
12,
8925,
12,
436,
32536,
14,
339,
627,
2018,
436,
4840,
570,
6302,
272,
627,
2018,
492,
4621,
272,
627,
3907,
14,
1001,
4177,
272,
627,
7054,
14,
1001,
4177,
339,
3033,
26,
267,
485,
589,
334,
3251,
304,
710,
1680,
2087,
1249,
19317,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
485,
589,
304,
267,
408,
9346,
8089,
4382,
14,
398,
3033,
26,
288,
485,
589,
334,
3251,
304,
710,
1680,
2087,
1249,
19317,
14,
267,
408,
267,
1613,
11027,
826,
721,
63,
589,
9,
398,
327,
1021,
4382,
267,
291,
423,
571,
63,
5154,
275,
942,
267,
291,
423,
3174,
63,
1001,
63,
3629,
275,
488,
267,
291,
423,
4209,
63,
1001,
63,
3629,
275,
488,
267,
291,
14,
888,
275,
1052,
398,
340,
283,
4600,
63,
4435,
7,
315,
984,
14,
3112,
26,
288,
327,
1454,
663,
3520,
340,
5496,
63,
1927,
859,
365,
2808,
288,
5496,
63,
515,
275,
5496,
63,
4435,
14,
1927,
63,
1501,
3460,
354,
3108,
12548,
6735,
360,
1393,
358,
288,
291,
14,
3174,
63,
1001,
63,
3629,
63,
493,
275,
747,
14,
515,
14,
904,
8,
355,
5496,
63,
515,
12,
283,
9482,
297,
283,
3174,
13,
1001,
13,
3629,
14,
1001,
7,
288,
776,
288,
291,
14,
4209,
63,
1001,
63,
3629,
63,
493,
275,
747,
14,
515,
14,
904,
8,
355,
5496,
63,
515,
12,
283,
9482,
297,
283,
4209,
13,
1001,
13,
3629,
14,
1001,
7,
288,
776,
267,
587,
26,
288,
291,
14,
3174,
63,
1001,
63,
3629,
63,
493,
275,
488,
288,
291,
14,
4209,
63,
1001,
63,
3629,
63,
493,
275,
488,
267,
291,
14,
6136,
63,
576,
275,
291,
423,
6136,
63,
576,
339,
768,
1829,
272,
347,
485,
6136,
63,
576,
8,
277,
304,
267,
408,
1767,
5523,
367,
6411,
666,
1041,
267,
372,
469,
288,
283,
2550,
356,
990,
288,
283,
493,
16626,
356,
990,
288,
283,
4209,
83,
356,
990,
288,
283,
578,
32447,
356,
990,
288,
283,
3629,
356,
990,
288,
283,
11522,
356,
990,
267,
789,
339,
347,
485,
1074,
63,
932,
63,
646,
8,
277,
12,
1031,
12,
1788,
304,
267,
340,
1228,
8,
932,
12,
6073,
14,
6295,
304,
288,
367,
302,
315,
1031,
14,
1247,
26,
355,
333,
275,
302,
14,
354,
14,
1294,
19237,
16,
61,
355,
340,
440,
291,
14,
1074,
63,
646,
63,
28683,
8,
77,
304,
490,
333,
63,
1205,
275,
291,
14,
1074,
63,
17932,
8,
77,
9,
490,
340,
440,
333,
63,
1205,
26,
717,
291,
14,
6136,
63,
576,
459,
2550,
2278,
740,
8,
1169,
289,
624,
2377,
6411,
3405,
367,
469,
1501,
93,
408,
1169,
289,
624,
8,
578,
5310,
77,
7063,
4293,
440,
506,
8439,
10477,
717,
776,
490,
291,
14,
6136,
63,
576,
459,
578,
32447,
2278,
740,
8,
717,
791,
1501,
356,
1788,
12,
283,
578,
356,
333,
12,
283,
1205,
356,
333,
63,
1205,
93,
490,
776,
267,
916,
1228,
8,
932,
12,
6073,
14,
6295,
2532,
304,
288,
333,
275,
1031,
14,
578,
14,
1294,
19237,
16,
61,
288,
340,
440,
291,
14,
1074,
63,
646,
63,
28683,
8,
77,
304,
355,
333,
63,
1205,
275,
291,
14,
1074,
63,
17932,
8,
77,
9,
355,
340,
440,
333,
63,
1205,
26,
490,
291,
14,
6136,
63,
576,
459,
2550,
2278,
740,
8,
717,
289,
624,
2377,
6411,
3405,
367,
469,
1501,
93,
408,
717,
289,
624,
8,
578,
5310,
77,
7063,
4293,
440,
506,
8439,
10477,
490,
776,
355,
291,
14,
6136,
63,
576,
459,
578,
32447,
2278,
740,
8,
490,
791,
1501,
356,
1788,
12,
283,
578,
356,
333,
12,
283,
1205,
356,
333,
63,
1205,
93,
355,
776,
339,
347,
1104,
63,
12775,
8,
277,
304,
267,
408,
1799,
314,
11336,
2746,
2166,
2082,
367,
4124,
8925,
14,
398,
961,
1083,
911,
1104,
1454,
1584,
13401,
315,
1011,
14,
647,
538,
436,
1630,
440,
2429,
8925,
6411,
267,
367,
1007,
13,
12629,
14,
267,
408,
267,
367,
1788,
315,
3355,
8,
736,
14,
7374,
8,
277,
14,
571,
63,
515,
2298,
288,
340,
440,
1788,
14,
4130,
5175,
647,
735,
355,
1980,
953,
19632,
63,
515,
275,
747,
14,
515,
14,
904,
8,
277,
14,
571,
63,
515,
12,
1788,
9,
288,
543,
1551,
8,
11878,
63,
515,
12,
283,
4848,
358,
465,
289,
26,
355,
327,
3254,
26,
5325,
642,
355,
1233,
63,
1278,
275,
15782,
7694,
70,
14,
739,
1062,
413,
3948,
2234,
1830,
1233,
63,
1278,
26,
490,
1233,
12,
5874,
275,
1233,
63,
1278,
14,
25704,
342,
221,
327,
4287,
26,
3507,
29,
8618,
13,
1975,
490,
862,
26,
717,
4565,
63,
600,
275,
6073,
14,
1122,
8,
600,
9,
717,
367,
1031,
315,
6073,
14,
7757,
8,
6751,
63,
600,
304,
1169,
291,
423,
1074,
63,
932,
63,
646,
8,
932,
12,
1788,
9,
490,
871,
12053,
26,
717,
986,
339,
347,
1104,
63,
3871,
63,
1725,
8,
277,
304,
267,
408,
12584,
4733,
1584,
367,
4733,
3906,
8686,
1041,
267,
2559,
63,
354,
275,
289,
16019,
277,
14,
84,
74,
14,
2491,
63,
571,
63,
354,
12585,
86,
91,
277,
14,
7879,
14,
6815,
63,
1023,
14,
1294,
15857,
59,
16,
61,
6834,
267,
2559,
63,
354,
275,
2559,
63,
354,
14
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
624,
52,
67,
920,
22545,
12134,
5673,
1041,
199,
3,
4465,
3555,
199,
646,
6073,
199,
646,
14802,
199,
646,
2022,
199,
646,
747,
199,
646,
984,
199,
646,
5190,
199,
504,
5055,
492,
15782,
199,
199,
3,
10919,
13,
7522,
199,
646,
3164,
14541,
465,
286,
199,
504,
2022,
3629,
492,
13268,
547,
12,
8505,
12,
4107,
199,
504,
26678,
63,
513,
492,
26678,
63,
513,
199,
199,
504,
1275,
1393,
492,
32613,
199,
199,
893,
26,
272,
327,
10919,
13,
7522,
272,
492,
5496,
63,
4435,
199,
2590,
8779,
547,
26,
272,
327,
642,
859,
365,
1454,
1415,
367,
9842,
14214,
3718,
272,
986,
199,
199,
893,
26,
272,
327,
4465,
3555,
272,
492,
11723,
19,
199,
2590,
5673,
10870,
26,
272,
327,
642,
859,
365,
1454,
1415,
367,
9842,
14214,
3718,
272,
986,
421,
199,
533,
12134,
8,
13394,
304,
272,
408,
12584,
6302,
12,
8925,
12,
436,
32536,
14,
339,
627,
2018,
436,
4840,
570,
6302,
272,
627,
2018,
492,
4621,
272,
627,
3907,
14,
1001,
4177,
272,
627,
7054,
14,
1001,
4177,
339,
3033,
26,
267,
485,
589,
334,
3251,
304,
710,
1680,
2087,
1249,
19317,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
485,
589,
304,
267,
408,
9346,
8089,
4382,
14,
398,
3033,
26,
288,
485,
589,
334,
3251,
304,
710,
1680,
2087,
1249,
19317,
14,
267,
408,
267,
1613,
11027,
826,
721,
63,
589,
9,
398,
327,
1021,
4382,
267,
291,
423,
571,
63,
5154,
275,
942,
267,
291,
423,
3174,
63,
1001,
63,
3629,
275,
488,
267,
291,
423,
4209,
63,
1001,
63,
3629,
275,
488,
267,
291,
14,
888,
275,
1052,
398,
340,
283,
4600,
63,
4435,
7,
315,
984,
14,
3112,
26,
288,
327,
1454,
663,
3520,
340,
5496,
63,
1927,
859,
365,
2808,
288,
5496,
63,
515,
275,
5496,
63,
4435,
14,
1927,
63,
1501,
3460,
354,
3108,
12548,
6735,
360,
1393,
358,
288,
291,
14,
3174,
63,
1001,
63,
3629,
63,
493,
275,
747,
14,
515,
14,
904,
8,
355,
5496,
63,
515,
12,
283,
9482,
297,
283,
3174,
13,
1001,
13,
3629,
14,
1001,
7,
288,
776,
288,
291,
14,
4209,
63,
1001,
63,
3629,
63,
493,
275,
747,
14,
515,
14,
904,
8,
355,
5496,
63,
515,
12,
283,
9482,
297,
283,
4209,
13,
1001,
13,
3629,
14,
1001,
7,
288,
776,
267,
587,
26,
288,
291,
14,
3174,
63,
1001,
63,
3629,
63,
493,
275,
488,
288,
291,
14,
4209,
63,
1001,
63,
3629,
63,
493,
275,
488,
267,
291,
14,
6136,
63,
576,
275,
291,
423,
6136,
63,
576,
339,
768,
1829,
272,
347,
485,
6136,
63,
576,
8,
277,
304,
267,
408,
1767,
5523,
367,
6411,
666,
1041,
267,
372,
469,
288,
283,
2550,
356,
990,
288,
283,
493,
16626,
356,
990,
288,
283,
4209,
83,
356,
990,
288,
283,
578,
32447,
356,
990,
288,
283,
3629,
356,
990,
288,
283,
11522,
356,
990,
267,
789,
339,
347,
485,
1074,
63,
932,
63,
646,
8,
277,
12,
1031,
12,
1788,
304,
267,
340,
1228,
8,
932,
12,
6073,
14,
6295,
304,
288,
367,
302,
315,
1031,
14,
1247,
26,
355,
333,
275,
302,
14,
354,
14,
1294,
19237,
16,
61,
355,
340,
440,
291,
14,
1074,
63,
646,
63,
28683,
8,
77,
304,
490,
333,
63,
1205,
275,
291,
14,
1074,
63,
17932,
8,
77,
9,
490,
340,
440,
333,
63,
1205,
26,
717,
291,
14,
6136,
63,
576,
459,
2550,
2278,
740,
8,
1169,
289,
624,
2377,
6411,
3405,
367,
469,
1501,
93,
408,
1169,
289,
624,
8,
578,
5310,
77,
7063,
4293,
440,
506,
8439,
10477,
717,
776,
490,
291,
14,
6136,
63,
576,
459,
578,
32447,
2278,
740,
8,
717,
791,
1501,
356,
1788,
12,
283,
578,
356,
333,
12,
283,
1205,
356,
333,
63,
1205,
93,
490,
776,
267,
916,
1228,
8,
932,
12,
6073,
14,
6295,
2532,
304,
288,
333,
275,
1031,
14,
578,
14,
1294,
19237,
16,
61,
288,
340,
440,
291,
14,
1074,
63,
646,
63,
28683,
8,
77,
304,
355,
333,
63,
1205,
275,
291,
14,
1074,
63,
17932,
8,
77,
9,
355,
340,
440,
333,
63,
1205,
26,
490,
291,
14,
6136,
63,
576,
459,
2550,
2278,
740,
8,
717,
289,
624,
2377,
6411,
3405,
367,
469,
1501,
93,
408,
717,
289,
624,
8,
578,
5310,
77,
7063,
4293,
440,
506,
8439,
10477,
490,
776,
355,
291,
14,
6136,
63,
576,
459,
578,
32447,
2278,
740,
8,
490,
791,
1501,
356,
1788,
12,
283,
578,
356,
333,
12,
283,
1205,
356,
333,
63,
1205,
93,
355,
776,
339,
347,
1104,
63,
12775,
8,
277,
304,
267,
408,
1799,
314,
11336,
2746,
2166,
2082,
367,
4124,
8925,
14,
398,
961,
1083,
911,
1104,
1454,
1584,
13401,
315,
1011,
14,
647,
538,
436,
1630,
440,
2429,
8925,
6411,
267,
367,
1007,
13,
12629,
14,
267,
408,
267,
367,
1788,
315,
3355,
8,
736,
14,
7374,
8,
277,
14,
571,
63,
515,
2298,
288,
340,
440,
1788,
14,
4130,
5175,
647,
735,
355,
1980,
953,
19632,
63,
515,
275,
747,
14,
515,
14,
904,
8,
277,
14,
571,
63,
515,
12,
1788,
9,
288,
543,
1551,
8,
11878,
63,
515,
12,
283,
4848,
358,
465,
289,
26,
355,
327,
3254,
26,
5325,
642,
355,
1233,
63,
1278,
275,
15782,
7694,
70,
14,
739,
1062,
413,
3948,
2234,
1830,
1233,
63,
1278,
26,
490,
1233,
12,
5874,
275,
1233,
63,
1278,
14,
25704,
342,
221,
327,
4287,
26,
3507,
29,
8618,
13,
1975,
490,
862,
26,
717,
4565,
63,
600,
275,
6073,
14,
1122,
8,
600,
9,
717,
367,
1031,
315,
6073,
14,
7757,
8,
6751,
63,
600,
304,
1169,
291,
423,
1074,
63,
932,
63,
646,
8,
932,
12,
1788,
9,
490,
871,
12053,
26,
717,
986,
339,
347,
1104,
63,
3871,
63,
1725,
8,
277,
304,
267,
408,
12584,
4733,
1584,
367,
4733,
3906,
8686,
1041,
267,
2559,
63,
354,
275,
289,
16019,
277,
14,
84,
74,
14,
2491,
63,
571,
63,
354,
12585,
86,
91,
277,
14,
7879,
14,
6815,
63,
1023,
14,
1294,
15857,
59,
16,
61,
6834,
267,
2559,
63,
354,
275,
2559,
63,
354,
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,
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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
] |
ritchyteam/odoo
|
addons/website_certification/__init__.py
|
385
|
1030
|
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-TODAY OpenERP S.A. <http://www.openerp.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import certification
import controllers
|
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,
2566,
11655,
7653,
428,
14,
33,
14,
665,
1014,
921,
1544,
14,
11267,
14,
957,
30,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
646,
3361,
3793,
199,
646,
27325,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2644,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
2566,
11655,
7653,
428,
14,
33,
14,
665,
1014,
921,
1544,
14,
11267,
14,
957,
30,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
646,
3361,
3793,
199,
646,
27325,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
SublimeLinter/SublimeLinter3
|
highlight_view.py
|
1
|
32846
|
from collections import defaultdict
import html
from itertools import chain
from functools import partial
import re
import textwrap
import threading
import uuid
import sublime
import sublime_plugin
from .lint import persist, events, style, util, queue, quick_fix
from .lint.const import PROTECTED_REGIONS_KEY, ERROR, WARNING
flatten = chain.from_iterable
MYPY = False
if MYPY:
from typing import (
Callable, DefaultDict, Dict, FrozenSet, Hashable, Iterable, List,
Optional, Set, Tuple, TypeVar, Union
)
from mypy_extensions import TypedDict
T = TypeVar('T')
LintError = persist.LintError
LinterName = persist.LinterName
Flags = int
Icon = str
Scope = str
Squiggles = Dict['Squiggle', List[sublime.Region]]
GutterIcons = Dict['GutterIcon', List[sublime.Region]]
ProtectedRegions = List[sublime.Region]
RegionKey = Union['GutterIcon', 'Squiggle']
State_ = TypedDict('State_', {
'active_view': Optional[sublime.View],
'current_sel': Tuple[sublime.Region, ...],
'idle_views': Set[sublime.ViewId],
'quiet_views': Set[sublime.ViewId],
'views': Set[sublime.ViewId]
})
DemotePredicate = Callable[[LintError], bool]
UNDERLINE_FLAGS = (
sublime.DRAW_NO_FILL |
sublime.DRAW_NO_OUTLINE
)
MARK_STYLES = {
'outline': sublime.DRAW_NO_FILL,
'fill': sublime.DRAW_NO_OUTLINE,
'solid_underline': sublime.DRAW_SOLID_UNDERLINE | UNDERLINE_FLAGS,
'squiggly_underline': sublime.DRAW_SQUIGGLY_UNDERLINE | UNDERLINE_FLAGS,
'stippled_underline': sublime.DRAW_STIPPLED_UNDERLINE | UNDERLINE_FLAGS,
'none': sublime.HIDDEN
}
UNDERLINE_STYLES = (
'solid_underline', 'squiggly_underline', 'stippled_underline'
)
SOME_WS = re.compile(r'\s')
FALLBACK_MARK_STYLE = 'outline'
WS_ONLY = re.compile(r'^\s+$')
MULTILINES = re.compile('\n(?=.)')
# Sublime >= 4074 supports underline styles on white space
# https://github.com/sublimehq/sublime_text/issues/137
SUBLIME_SUPPORTS_WS_SQUIGGLES = int(sublime.version()) >= 4074
State = {
'active_view': None,
'current_sel': tuple(),
'idle_views': set(),
'quiet_views': set(),
'views': set()
} # type: State_
def plugin_loaded():
State.update({
'active_view': sublime.active_window().active_view(),
'idle_views': set()
})
def plugin_unloaded():
events.off(on_lint_result)
for window in sublime.windows():
for view in window.views():
undraw(view)
@events.on(events.LINT_RESULT)
def on_lint_result(filename, linter_name, **kwargs):
# type: (str, LinterName, object) -> None
views = list(all_views_into_file(filename))
if not views:
return
highlight_linter_errors(views, filename, linter_name)
class UpdateOnLoadController(sublime_plugin.EventListener):
def on_load_async(self, view):
# type: (sublime.View) -> None
# update this new view with any errors it currently has
filename = util.get_filename(view)
errors = persist.file_errors.get(filename)
if errors:
set_idle(view, True) # show errors immediately
linter_names = set(error['linter'] for error in errors)
for linter_name in linter_names:
highlight_linter_errors([view], filename, linter_name)
on_clone_async = on_load_async
def highlight_linter_errors(views, filename, linter_name):
# type: (List[sublime.View], str, LinterName) -> None
demote_predicate = get_demote_predicate()
demote_scope = get_demote_scope()
errors = persist.file_errors[filename]
update_error_priorities_inline(errors)
errors_for_the_highlights, errors_for_the_gutter = prepare_data(errors)
view = views[0] # to calculate regions we can take any of the views
protected_regions = prepare_protected_regions(errors_for_the_gutter)
# `prepare_data` returns the state of the view as we would like to draw it.
# But we cannot *redraw* regions as soon as the buffer changed, in fact
# Sublime already moved all the regions for us.
# So for the next step, we filter for errors from the current finished
# lint, namely from linter_name. All other errors are already UP-TO-DATE.
errors_for_the_highlights = [error for error in errors_for_the_highlights
if error['linter'] == linter_name]
errors_for_the_gutter = [error for error in errors_for_the_gutter
if error['linter'] == linter_name]
gutter_regions = prepare_gutter_data(linter_name, errors_for_the_gutter)
for view in views:
vid = view.id()
if (
persist.settings.get('highlights.start_hidden') and
vid not in State['quiet_views'] and
vid not in State['views']
):
State['quiet_views'].add(vid)
if vid not in State['views']:
State['views'].add(vid)
highlight_regions = prepare_highlights_data(
errors_for_the_highlights,
demote_predicate=demote_predicate,
demote_scope=demote_scope,
quiet=vid in State['quiet_views'],
idle=vid in State['idle_views']
)
draw(
view,
linter_name,
highlight_regions,
gutter_regions,
protected_regions,
)
def update_error_priorities_inline(errors):
# type: (List[LintError]) -> None
# We need to update `prioritiy` here (although a user will rarely change
# this setting that often) for correctness. Generally, on views with
# multiple linters running, we compare new lint results from the
# 'fast' linters with old results from the 'slower' linters. The below
# `filter_errors` produces wrong results with outdated priorities.
#
# ATT: inline, so this change propagates throughout the system
for error in errors:
error['priority'] = style.get_value('priority', error, 0)
def prepare_data(errors):
# type: (List[LintError]) -> Tuple[List[LintError], List[LintError]]
# We need to filter the errors, bc we cannot draw multiple regions
# on the same position. E.g. we can only draw one gutter icon per line,
# and we can only 'underline' a word once.
return (
filter_errors(errors, by_position), # highlights
filter_errors(errors, by_line) # gutter icons
)
def filter_errors(errors, group_fn):
# type: (List[LintError], Callable[[LintError], Hashable]) -> List[LintError]
grouped = defaultdict(list) # type: DefaultDict[Hashable, List[LintError]]
for error in errors:
grouped[group_fn(error)].append(error)
filtered_errors = []
for errors in grouped.values():
head = sorted(
errors,
key=lambda e: (-e['priority'], e['error_type'], e['linter'])
)[0]
filtered_errors.append(head)
return filtered_errors
def by_position(error):
# type: (LintError) -> Hashable
return (error['line'], error['start'], error['end'])
def by_line(error):
# type: (LintError) -> Hashable
return error['line']
def prepare_protected_regions(errors):
# type: (List[LintError]) -> ProtectedRegions
return list(flatten(prepare_gutter_data('_', errors).values()))
def prepare_gutter_data(
linter_name, # type: LinterName
errors # type: List[LintError]
):
# type: (...) -> GutterIcons
# Compute the icon and scope for the gutter mark from the error.
# Drop lines for which we don't get a value or for which the user
# specified 'none'
by_id = defaultdict(list) # type: DefaultDict[Tuple[str, str], List[sublime.Region]]
for error in errors:
icon = style.get_icon(error)
if icon == 'none':
continue
scope = style.get_icon_scope(error)
# We draw gutter icons with `flag=sublime.HIDDEN`. The actual width
# of the region doesn't matter bc Sublime will draw an icon only
# on the beginning line, which is exactly what we want.
region = error['region']
# We group towards the optimal sublime API usage:
# view.add_regions(uuid(), [region], scope, icon)
id = (scope, icon)
by_id[id].append(region)
# Exchange the `id` with a regular region_id which is a unique string, so
# uuid() would be candidate here, that can be reused for efficient updates.
by_region_id = {}
for (scope, icon), regions in by_id.items():
region_id = GutterIcon(linter_name, scope, icon)
by_region_id[region_id] = regions
return by_region_id
def prepare_highlights_data(
errors, # type: List[LintError]
demote_predicate, # type: DemotePredicate
demote_scope, # type: str
quiet, # type: bool
idle, # type: bool
):
# type: (...) -> Squiggles
by_region_id = {}
for error in errors:
scope = style.get_value('scope', error)
flags = _compute_flags(error)
demote_while_busy = demote_predicate(error)
alt_scope = scope
if quiet:
scope = HIDDEN_SCOPE
elif not idle and demote_while_busy:
scope = demote_scope
uid = error['uid']
linter_name = error['linter']
key = Squiggle(linter_name, uid, scope, flags, demote_while_busy, alt_scope)
by_region_id[key] = [error['region']]
return by_region_id
def _compute_flags(error):
# type: (LintError) -> int
mark_style = style.get_value('mark_style', error, 'none')
selected_text = error['offending_text']
if SUBLIME_SUPPORTS_WS_SQUIGGLES:
regex = MULTILINES
else:
regex = SOME_WS
if mark_style in UNDERLINE_STYLES and regex.search(selected_text):
mark_style = FALLBACK_MARK_STYLE
flags = MARK_STYLES[mark_style]
if not persist.settings.get('show_marks_in_minimap'):
flags |= sublime.HIDE_ON_MINIMAP
return flags
def undraw(view):
# type: (sublime.View) -> None
for key in get_regions_keys(view):
erase_view_region(view, key)
def draw(
view, # type: sublime.View
linter_name, # type: LinterName
highlight_regions, # type: Squiggles
gutter_regions, # type: GutterIcons
protected_regions, # type: ProtectedRegions
):
# type: (...) -> None
"""
Draw code and gutter marks in the given view.
Error, warning and gutter marks are drawn with separate regions,
since each one potentially needs a different color.
"""
current_region_keys = get_regions_keys(view)
current_linter_keys = {
key
for key in current_region_keys
if key.linter_name == linter_name
}
new_linter_keys = set(highlight_regions.keys()) | set(gutter_regions.keys())
# remove unused regions
for key in current_linter_keys - new_linter_keys:
erase_view_region(view, key)
# overlaying all gutter regions with common invisible one,
# to create unified handle for GitGutter and other plugins
view.add_regions(PROTECTED_REGIONS_KEY, protected_regions)
# otherwise update (or create) regions
for squiggle, regions in highlight_regions.items():
draw_view_region(view, squiggle, regions)
for icon, regions in gutter_regions.items():
draw_view_region(view, icon, regions)
class GutterIcon(str):
namespace = 'SL.Gutter' # type: str
scope = '' # type: str
icon = '' # type: str
flags = sublime.HIDDEN # type: int
linter_name = '' # type: str
def __new__(cls, linter_name, scope, icon):
# type: (str, str, str) -> GutterIcon
key = 'SL.{}.Gutter.|{}|{}'.format(linter_name, scope, icon)
self = super().__new__(cls, key)
self.linter_name = linter_name
self.scope = scope
self.icon = icon
return self
class Squiggle(str):
namespace = 'SL.Squiggle' # type: str
scope = '' # type: str
alt_scope = '' # type: str
icon = '' # type: str
flags = 0 # type: int
linter_name = '' # type: str
uid = '' # type: str
demotable = False # type: bool
def __new__(cls, linter_name, uid, scope, flags, demotable=False, alt_scope=None):
# type: (str, str, str, int, bool, str) -> Squiggle
key = (
'SL.{}.Highlights.|{}|{}|{}'
.format(linter_name, uid, scope, flags)
)
self = super().__new__(cls, key)
self.scope = scope
if alt_scope is None:
self.alt_scope = scope
else:
self.alt_scope = alt_scope
self.flags = flags
self.linter_name = linter_name
self.uid = uid
self.demotable = demotable
return self
def _replace(self, **overrides):
# type: (...) -> Squiggle
base = {
name: overrides.pop(name, getattr(self, name))
for name in {
'linter_name', 'uid', 'scope', 'flags', 'demotable', 'alt_scope'
}
}
return Squiggle(**base)
def visible(self):
# type: () -> bool
return bool(self.icon or (self.scope and not self.flags == sublime.HIDDEN))
def get_demote_scope():
return persist.settings.get('highlights.demote_scope')
def get_demote_predicate():
# type: () -> DemotePredicate
setting = persist.settings.get('highlights.demote_while_editing')
return getattr(DemotePredicates, setting, DemotePredicates.none)
class DemotePredicates:
@staticmethod
def none(error):
# type: (LintError) -> bool
return False
@staticmethod
def all(error):
# type: (LintError) -> bool
return True
@staticmethod
def ws_only(error):
# type: (LintError) -> bool
return bool(WS_ONLY.search(error['offending_text']))
@staticmethod
def some_ws(error):
# type: (LintError) -> bool
return bool(SOME_WS.search(error['offending_text']))
ws_regions = some_ws
@staticmethod
def multilines(error):
# type: (LintError) -> bool
return bool(MULTILINES.search(error['offending_text']))
@staticmethod
def warnings(error):
# type: (LintError) -> bool
return error['error_type'] == WARNING
# --------------- ZOMBIE PROTECTION ---------------- #
# [¬º°]¬ [¬º°]¬ [¬º˚]¬ [¬º˙]* ─ ─ ─ ─ ─ ─ ─╦╤︻ #
StorageLock = threading.Lock()
# Just trying and catching `NameError` reuses the previous value or
# "version" of this variable when hot-reloading
try:
CURRENTSTORE
except NameError:
CURRENTSTORE = defaultdict(set) # type: Dict[sublime.ViewId, Set[RegionKey]]
try:
EVERSTORE
except NameError:
EVERSTORE = defaultdict(set) # type: DefaultDict[sublime.ViewId, Set[RegionKey]]
else:
# Assign the newly loaded classes to the old regions.
# On each reload the `id` of our classes change and any
# `isinstance(x, Y)` would fail.
# Holy moly, *in-place* mutation.
def _reload_everstore(store):
for regions in store.values():
for r in regions:
if '.Highlights' in r:
r.__class__ = Squiggle
elif '.Gutter' in r:
r.__class__ = GutterIcon
try:
_reload_everstore(EVERSTORE)
except TypeError:
# On initial migration the `EVERSTORE` only holds native strings.
# These are not compatible, so we initialize to a fresh state.
EVERSTORE = defaultdict(set)
def draw_view_region(view, key, regions):
# type: (sublime.View, RegionKey, List[sublime.Region]) -> None
with StorageLock:
view.add_regions(key, regions, key.scope, key.icon, key.flags)
vid = view.id()
CURRENTSTORE[vid].add(key)
EVERSTORE[vid].add(key)
def erase_view_region(view, key):
# type: (sublime.View, RegionKey) -> None
with StorageLock:
view.erase_regions(key)
CURRENTSTORE[view.id()].discard(key)
def get_regions_keys(view):
# type: (sublime.View) -> FrozenSet[RegionKey]
return frozenset(CURRENTSTORE.get(view.id(), set()))
def restore_from_everstore(view):
# type: (sublime.View) -> None
with StorageLock:
vid = view.id()
CURRENTSTORE[vid] = EVERSTORE[vid].copy()
class ZombieController(sublime_plugin.EventListener):
def on_text_command(self, view, cmd, args):
# type: (sublime.View, str, Dict) -> None
if cmd in ['undo', 'redo_or_repeat']:
restore_from_everstore(view)
def on_close(self, view):
# type: (sublime.View) -> None
sublime.set_timeout_async(lambda: EVERSTORE.pop(view.id(), None))
# ----------------------------------------------------- #
class ViewListCleanupController(sublime_plugin.EventListener):
def on_pre_close(self, view):
vid = view.id()
State['idle_views'].discard(vid)
State['quiet_views'].discard(vid)
State['views'].discard(vid)
class RevisitErrorRegions(sublime_plugin.EventListener):
@util.distinct_until_buffer_changed
def on_modified(self, view):
if not util.is_lintable(view):
return
active_view = State['active_view']
if active_view and view.buffer_id() == active_view.buffer_id():
view = active_view
revalidate_regions(view)
# Run `maybe_update_error_store` on the worker because it
# potentially wants to mutate the store. We do this always
# on the worker queue to avoid using locks.
sublime.set_timeout_async(lambda: maybe_update_error_store(view))
def revalidate_regions(view):
# type: (sublime.View) -> None
vid = view.id()
if vid in State['quiet_views']:
return
selections = get_current_sel(view) # frozen sel() for this operation
region_keys = get_regions_keys(view)
for key in region_keys:
if isinstance(key, Squiggle) and key.visible():
# We can have keys without any region drawn for example
# if we loaded the `EVERSTORE`.
region = head(view.get_regions(key))
if region is None:
continue
# Draw squiggles *under* the cursor invisible because
# we don't want the visual noise exactly where we edit
# our code.
# Note that this also immeditaley **hides** empty regions
# (dangles) for example if you delete a line with a squiggle
# on it. Removing dangles is thus a two step process. We
# first, immediately and on the UI thread, hide them, later
# in `maybe_update_error_store` we actually erase the region
# and remove the error from the store.
if any(region.contains(s) for s in selections):
draw_squiggle_invisible(view, key, [region])
elif isinstance(key, GutterIcon):
# Remove gutter icon if its region is empty,
# e.g. the user deleted the squiggled word.
regions = view.get_regions(key)
filtered_regions = [
region
for region in regions
if not region.empty()
]
if len(filtered_regions) != len(regions):
draw_view_region(view, key, filtered_regions)
def maybe_update_error_store(view):
# type: (sublime.View) -> None
filename = util.get_filename(view)
errors = persist.file_errors.get(filename)
if not errors:
return
region_keys = get_regions_keys(view)
uid_key_map = {
key.uid: key
for key in region_keys
if isinstance(key, Squiggle)
}
changed = False
new_errors = []
for error in errors:
uid = error['uid']
# XXX: Why keep the error in the store when we don't have
# a region key for it in the store?
key = uid_key_map.get(uid, None)
region = head(view.get_regions(key)) if key else None
if region is None or region == error['region']:
new_errors.append(error)
continue
else:
changed = True
if region.empty():
# Either the user edited away our region (and the error)
# or: Dangle! Sublime has invalidated our region, it has
# zero length (and moved to a different line at col 0).
# It is useless now so we remove the error by not
# copying it.
erase_view_region(view, key) # type: ignore
continue
line, start = view.rowcol(region.begin())
endLine, end = view.rowcol(region.end())
error = error.copy()
error.update({
'region': region,
'line': line,
'start': start,
'endLine': endLine,
'end': end
})
new_errors.append(error)
if changed:
persist.file_errors[filename] = new_errors
events.broadcast('updated_error_positions', {'filename': filename})
class IdleViewController(sublime_plugin.EventListener):
def on_activated_async(self, active_view):
previous_view = State['active_view']
State.update({
'active_view': active_view,
'current_sel': get_current_sel(active_view)
})
if previous_view and previous_view.id() != active_view.id():
set_idle(previous_view, True)
set_idle(active_view, True)
@util.distinct_until_buffer_changed
def on_modified_async(self, view):
active_view = State['active_view']
if active_view and view.buffer_id() == active_view.buffer_id():
set_idle(active_view, False)
@util.distinct_until_buffer_changed
def on_post_save_async(self, view):
active_view = State['active_view']
if active_view and view.buffer_id() == active_view.buffer_id():
set_idle(active_view, True)
def on_selection_modified_async(self, view):
active_view = State['active_view']
# Do not race between `plugin_loaded` and this event handler
if active_view is None:
return
if view.buffer_id() != active_view.buffer_id():
return
current_sel = get_current_sel(active_view)
if current_sel != State['current_sel']:
State.update({'current_sel': current_sel})
time_to_idle = persist.settings.get('highlights.time_to_idle')
queue.debounce(
partial(set_idle, active_view, True),
delay=time_to_idle,
key='highlights.{}'.format(active_view.id())
)
def set_idle(view, idle):
vid = view.id()
current_idle = vid in State['idle_views']
if idle != current_idle:
if idle:
State['idle_views'].add(vid)
else:
State['idle_views'].discard(vid)
toggle_demoted_regions(view, idle)
def toggle_demoted_regions(view, show):
# type: (sublime.View, bool) -> None
vid = view.id()
if vid in State['quiet_views']:
return
region_keys = get_regions_keys(view)
demote_scope = get_demote_scope()
for key in region_keys:
if isinstance(key, Squiggle) and key.demotable:
regions = view.get_regions(key)
if show:
redraw_squiggle(view, key, regions)
else:
draw_squiggle_with_different_scope(view, key, regions, demote_scope)
class SublimeLinterToggleHighlights(sublime_plugin.WindowCommand):
def run(self):
view = self.window.active_view()
if not view:
return
vid = view.id()
hidden = vid in State['quiet_views']
if hidden:
State['quiet_views'].discard(vid)
else:
State['quiet_views'].add(vid)
toggle_all_regions(view, show=hidden)
HIDDEN_SCOPE = ''
def toggle_all_regions(view, show):
# type: (sublime.View, bool) -> None
region_keys = get_regions_keys(view)
for key in region_keys:
if isinstance(key, Squiggle):
regions = view.get_regions(key)
if show:
redraw_squiggle(view, key, regions)
else:
draw_squiggle_invisible(view, key, regions)
def draw_squiggle_invisible(view, key, regions):
# type: (sublime.View, Squiggle, List[sublime.Region]) -> Squiggle
return draw_squiggle_with_different_scope(view, key, regions, HIDDEN_SCOPE)
def draw_squiggle_with_different_scope(view, key, regions, scope):
# type: (sublime.View, Squiggle, List[sublime.Region], str) -> Squiggle
new_key = key._replace(scope=scope, alt_scope=key.scope)
erase_view_region(view, key)
draw_view_region(view, new_key, regions)
return new_key
def redraw_squiggle(view, key, regions):
# type: (sublime.View, Squiggle, List[sublime.Region]) -> Squiggle
new_key = key._replace(scope=key.alt_scope)
erase_view_region(view, key)
draw_view_region(view, new_key, regions)
return new_key
# --------------- UTIL FUNCTIONS ------------------- #
def get_current_sel(view):
# type: (sublime.View) -> Tuple[sublime.Region, ...]
return tuple(s for s in view.sel())
def head(iterable):
# type: (Iterable[T]) -> Optional[T]
return next(iter(iterable), None)
def all_views_into_file(filename):
for window in sublime.windows():
for view in window.views():
if util.get_filename(view) == filename:
yield view
# --------------- TOOLTIP HANDLING ----------------- #
class TooltipController(sublime_plugin.EventListener):
def on_hover(self, view, point, hover_zone):
if hover_zone == sublime.HOVER_GUTTER:
if persist.settings.get('show_hover_line_report'):
line_region = view.line(point)
if any(
region.intersects(line_region)
for key in get_regions_keys(view)
if isinstance(key, GutterIcon)
for region in view.get_regions(key)
):
open_tooltip(view, point, line_report=True)
elif hover_zone == sublime.HOVER_TEXT:
if persist.settings.get('show_hover_region_report'):
if any(
region.contains(point)
for key in get_regions_keys(view)
if isinstance(key, Squiggle) and key.visible()
for region in view.get_regions(key)
):
open_tooltip(view, point, line_report=False)
class SublimeLinterLineReportCommand(sublime_plugin.WindowCommand):
def run(self):
view = self.window.active_view()
if not view:
return
point = view.sel()[0].begin()
open_tooltip(view, point, line_report=True)
TOOLTIP_STYLES = '''
body {
word-wrap: break-word;
}
.error {
color: var(--redish);
font-weight: bold;
}
.warning {
color: var(--yellowish);
font-weight: bold;
}
.footer {
margin-top: 0.5em;
font-size: .92em;
color: color(var(--background) blend(var(--foreground) 50%));
}
.action {
text-decoration: none;
}
.icon {
font-family: sans-serif;
margin-top: 0.5em;
}
'''
TOOLTIP_TEMPLATE = '''
<body id="sublimelinter-tooltip">
<style>{stylesheet}</style>
<div>{content}</div>
<div class="footer"><a href="copy">Copy</a><span>{help_text}</div>
</body>
'''
QUICK_FIX_HELP = " | Click <span class='icon'>⌦</span> to trigger a quick action"
def get_errors_where(filename, fn):
# type: (str, Callable[[sublime.Region], bool]) -> List[LintError]
return [
error for error in persist.file_errors[filename]
if fn(error['region'])
]
def open_tooltip(view, point, line_report=False):
# type: (sublime.View, int, bool) -> None
"""Show a tooltip containing all linting errors on a given line."""
# Leave any existing popup open without replacing it
# don't let the popup flicker / fight with other packages
if view.is_popup_visible():
return
filename = util.get_filename(view)
if line_report:
line = view.full_line(point)
errors = get_errors_where(
filename, lambda region: region.intersects(line))
else:
errors = get_errors_where(
filename, lambda region: region.contains(point))
if not errors:
return
tooltip_message, quick_actions = join_msgs(errors, show_count=line_report, width=80, pt=point)
def on_navigate(href: str) -> None:
if href == "copy":
sublime.set_clipboard(join_msgs_raw(errors))
window = view.window()
if window:
window.status_message("SublimeLinter: info copied to clipboard")
else:
fixer = quick_actions[href]
quick_fix.apply_fix(fixer, view)
view.hide_popup()
help_text = QUICK_FIX_HELP if quick_actions else ""
view.show_popup(
TOOLTIP_TEMPLATE.format(
stylesheet=TOOLTIP_STYLES, content=tooltip_message, help_text=help_text
),
flags=sublime.HIDE_ON_MOUSE_MOVE_AWAY,
location=point,
max_width=1000,
on_navigate=on_navigate
)
def join_msgs_raw(errors):
# Take an `errors` iterable and reduce it to a string without HTML tags.
sorted_errors = sorted(errors, key=lambda e: (e["linter"], e["error_type"]))
return "\n\n".join(
"{}: {}\n{}{}".format(
error["linter"],
error["error_type"],
error["code"] + " - " if error["code"] else "",
error["msg"]
) for error in sorted_errors
)
def join_msgs(errors, show_count, width, pt):
# type: (List[LintError], bool, int, int) -> Tuple[str, Dict[str, quick_fix.Fix]]
if show_count:
part = '''
<div class="{classname}">{count} {heading}</div>
<div>{messages}</div>
'''
else:
part = '''
<div>{messages}</div>
'''
grouped_by_type = defaultdict(list)
for error in errors:
grouped_by_type[error["error_type"]].append(error)
def sort_by_type(error_type):
if error_type == WARNING:
return "0"
elif error_type == ERROR:
return "1"
else:
return error_type
all_msgs = ""
quick_actions = {} # type: Dict[str, quick_fix.Fix]
for error_type in sorted(grouped_by_type.keys(), key=sort_by_type):
errors_by_type = sorted(
grouped_by_type[error_type],
key=lambda e: (e["linter"], e["start"], e["end"])
)
filled_templates = []
for error in errors_by_type:
first_line_prefix = "{linter}: ".format(**error)
hanging_indent = len(first_line_prefix)
first_line_indent = hanging_indent
if error.get("code"):
action = quick_fix.best_action_for_error(error)
if action:
id = uuid.uuid4().hex
quick_actions[id] = action.fn
first_line_prefix += (
'<a class="action icon" href="{action_id}">⌦</a> '
'{code} — '
.format(action_id=id, **error)
)
first_line_indent += len(error["code"]) + 3
else:
first_line_prefix += "{code} - ".format(**error)
first_line_indent += len(error["code"]) + 3
lines = list(flatten(
textwrap.wrap(
msg_line,
width=width,
initial_indent=(
" " * first_line_indent
if n == 0
else " " * hanging_indent
),
subsequent_indent=" " * hanging_indent
)
for n, msg_line in enumerate(error['msg'].splitlines())
))
lines[0] = lines[0].lstrip()
lines = list(map(escape_text, lines))
lines[0] = first_line_prefix + lines[0]
filled_templates += lines
heading = error_type
count = len(errors_by_type)
if count > 1: # pluralize
heading += "s"
all_msgs += part.format(
classname=error_type,
count=count,
heading=heading,
messages='<br />'.join(filled_templates)
)
return all_msgs, quick_actions
def escape_text(text):
# type: (str) -> str
return html.escape(text, quote=False).replace(' ', ' ')
|
mit
|
[
504,
5055,
492,
10018,
199,
646,
3517,
199,
504,
7975,
492,
6036,
199,
504,
9143,
492,
7417,
199,
646,
295,
199,
646,
13390,
199,
646,
5796,
199,
646,
5377,
199,
199,
646,
1007,
18687,
199,
646,
1007,
18687,
63,
2718,
199,
199,
504,
1275,
3854,
492,
22400,
12,
4474,
12,
3449,
12,
4884,
12,
4126,
12,
12530,
63,
970,
199,
504,
1275,
3854,
14,
1297,
492,
3611,
52,
3582,
1149,
63,
5616,
2823,
63,
3078,
12,
12539,
12,
14750,
199,
8487,
275,
6036,
14,
504,
63,
8147,
421,
199,
12339,
4521,
275,
756,
199,
692,
603,
57,
4521,
26,
272,
687,
14090,
492,
334,
267,
16975,
12,
3758,
2141,
12,
7448,
12,
481,
5775,
1084,
12,
16101,
461,
12,
19937,
12,
3820,
12,
267,
4879,
12,
2494,
12,
11634,
12,
2434,
5894,
12,
15961,
272,
776,
272,
687,
3002,
647,
63,
5359,
492,
31906,
2141,
272,
377,
275,
2434,
5894,
360,
52,
358,
272,
491,
442,
547,
275,
22400,
14,
44,
442,
547,
272,
491,
1058,
985,
275,
22400,
14,
44,
1058,
985,
339,
24870,
275,
1109,
272,
473,
388,
275,
620,
272,
20488,
275,
620,
272,
428,
392,
528,
27033,
275,
7448,
459,
51,
392,
528,
3845,
297,
3820,
59,
954,
18687,
14,
10708,
2677,
272,
598,
18404,
41,
8704,
275,
7448,
459,
39,
18404,
8954,
297,
3820,
59,
954,
18687,
14,
10708,
2677,
272,
2165,
4530,
10708,
83,
275,
3820,
59,
954,
18687,
14,
10708,
61,
272,
22240,
1197,
275,
15961,
459,
39,
18404,
8954,
297,
283,
51,
392,
528,
3845,
418,
339,
8511,
63,
275,
31906,
2141,
360,
2223,
14474,
469,
267,
283,
2682,
63,
1345,
356,
4879,
59,
954,
18687,
14,
2768,
467,
267,
283,
1818,
63,
5891,
356,
11634,
59,
954,
18687,
14,
10708,
12,
2263,
467,
267,
283,
12000,
63,
4196,
356,
2494,
59,
954,
18687,
14,
2768,
1304,
467,
267,
283,
10243,
63,
4196,
356,
2494,
59,
954,
18687,
14,
2768,
1304,
467,
267,
283,
4196,
356,
2494,
59,
954,
18687,
14,
2768,
1304,
61,
272,
3828,
339,
1487,
2137,
22236,
275,
16975,
9046,
44,
442,
547,
467,
2155,
61,
421,
199,
6131,
540,
6174,
63,
4831,
275,
334,
272,
1007,
18687,
14,
12118,
63,
2826,
63,
5110,
44,
1204,
272,
1007,
18687,
14,
12118,
63,
2826,
63,
1877,
6174,
199,
9,
199,
199,
10520,
63,
12307,
11344,
275,
469,
272,
283,
11550,
356,
1007,
18687,
14,
12118,
63,
2826,
63,
5110,
44,
12,
272,
283,
4498,
356,
1007,
18687,
14,
12118,
63,
2826,
63,
1877,
6174,
12,
272,
283,
18533,
63,
24396,
356,
1007,
18687,
14,
12118,
63,
15096,
998,
63,
6131,
540,
6174,
1204,
6778,
11733,
6174,
63,
4831,
12,
272,
283,
8471,
528,
20984,
63,
24396,
356,
1007,
18687,
14,
12118,
63,
51,
2328,
1277,
2226,
57,
63,
6131,
540,
6174,
1204,
6778,
11733,
6174,
63,
4831,
12,
272,
283,
270,
31112,
1146,
63,
24396,
356,
1007,
18687,
14,
12118,
63,
840,
1772,
48,
5290,
63,
6131,
540,
6174,
1204,
6778,
11733,
6174,
63,
4831,
12,
272,
283,
3592,
356,
1007,
18687,
14,
40,
22436,
199,
93,
199,
6131,
540,
6174,
63,
12307,
11344,
275,
334,
272,
283,
18533,
63,
24396,
297,
283,
8471,
528,
20984,
63,
24396,
297,
283,
270,
31112,
1146,
63,
24396,
7,
199,
9,
199,
199,
4118,
3635,
63,
5035,
275,
295,
14,
2014,
8,
82,
1154,
83,
358,
199,
38,
1761,
7111,
63,
10520,
63,
18466,
275,
283,
11550,
7,
199,
199,
5035,
63,
10452,
275,
295,
14,
2014,
8,
82,
15542,
83,
11,
9988,
199,
15635,
568,
654,
275,
295,
14,
2014,
2258,
78,
2229,
29,
4959,
358,
199,
199,
3,
4804,
18687,
2356,
6335,
1342,
5171,
25735,
15725,
641,
10424,
4601,
199,
3,
4178,
921,
5031,
14,
957,
15,
954,
18687,
21550,
15,
954,
18687,
63,
505,
15,
10115,
15,
7498,
199,
6348,
44,
3465,
63,
10640,
51,
63,
5035,
63,
51,
2328,
1277,
2226,
654,
275,
1109,
8,
954,
18687,
14,
1023,
1012,
2356,
6335,
1342,
199,
199,
2223,
275,
469,
272,
283,
2682,
63,
1345,
356,
488,
12,
272,
283,
1818,
63,
5891,
356,
2008,
1062,
272,
283,
12000,
63,
4196,
356,
663,
1062,
272,
283,
10243,
63,
4196,
356,
663,
1062,
272,
283,
4196,
356,
663,
342,
199,
93,
221,
327,
730,
26,
8511,
63,
421,
199,
318,
3589,
63,
4591,
837,
272,
8511,
14,
873,
2561,
267,
283,
2682,
63,
1345,
356,
1007,
18687,
14,
2682,
63,
3806,
1252,
2682,
63,
1345,
1062,
267,
283,
12000,
63,
4196,
356,
663,
342,
272,
3828,
421,
199,
318,
3589,
63,
324,
4591,
837,
272,
4474,
14,
1997,
8,
265,
63,
3854,
63,
1099,
9,
272,
367,
4353,
315,
1007,
18687,
14,
8258,
837,
267,
367,
2455,
315,
4353,
14,
4196,
837,
288,
625,
5485,
8,
1345,
9,
421,
199,
32,
4368,
14,
265,
8,
4368,
14,
44,
2919,
63,
9517,
9,
199,
318,
641,
63,
3854,
63,
1099,
8,
1501,
12,
7403,
351,
63,
354,
12,
1011,
958,
304,
272,
327,
730,
26,
334,
495,
12,
491,
1058,
985,
12,
909,
9,
1035,
488,
272,
6858,
275,
769,
8,
452,
63,
4196,
63,
9924,
63,
493,
8,
1501,
430,
272,
340,
440,
6858,
26,
267,
372,
339,
11850,
63,
25240,
63,
2550,
8,
4196,
12,
1788,
12,
7403,
351,
63,
354,
9,
421,
199,
533,
6162,
3314,
6200,
7506,
8,
954,
18687,
63,
2718,
14,
2390,
10464,
304,
272,
347,
641,
63,
912,
63,
4146,
8,
277,
12,
2455,
304,
267,
327,
730,
26,
334,
954,
18687,
14,
2768,
9,
1035,
488,
267,
327,
1678,
642,
892,
2455,
543,
1263,
2552,
652,
5544,
965,
267,
1788,
275,
4884,
14,
362,
63,
1501,
8,
1345,
9,
267,
2552,
275,
22400,
14,
493,
63,
2550,
14,
362,
8,
1501,
9,
267,
340,
2552,
26,
288,
663,
63,
12000,
8,
1345,
12,
715,
9,
221,
327,
2498,
2552,
9939,
288,
7403,
351,
63,
1247,
275,
663,
8,
705,
459,
25240,
418,
367,
1125,
315,
2552,
9,
288,
367,
7403,
351,
63,
354,
315,
7403,
351,
63,
1247,
26,
355,
11850,
63,
25240,
63,
2550,
779,
1345,
467,
1788,
12,
7403,
351,
63,
354,
9,
339,
641,
63,
6311,
63,
4146,
275,
641,
63,
912,
63,
4146,
421,
199
] |
[
5055,
492,
10018,
199,
646,
3517,
199,
504,
7975,
492,
6036,
199,
504,
9143,
492,
7417,
199,
646,
295,
199,
646,
13390,
199,
646,
5796,
199,
646,
5377,
199,
199,
646,
1007,
18687,
199,
646,
1007,
18687,
63,
2718,
199,
199,
504,
1275,
3854,
492,
22400,
12,
4474,
12,
3449,
12,
4884,
12,
4126,
12,
12530,
63,
970,
199,
504,
1275,
3854,
14,
1297,
492,
3611,
52,
3582,
1149,
63,
5616,
2823,
63,
3078,
12,
12539,
12,
14750,
199,
8487,
275,
6036,
14,
504,
63,
8147,
421,
199,
12339,
4521,
275,
756,
199,
692,
603,
57,
4521,
26,
272,
687,
14090,
492,
334,
267,
16975,
12,
3758,
2141,
12,
7448,
12,
481,
5775,
1084,
12,
16101,
461,
12,
19937,
12,
3820,
12,
267,
4879,
12,
2494,
12,
11634,
12,
2434,
5894,
12,
15961,
272,
776,
272,
687,
3002,
647,
63,
5359,
492,
31906,
2141,
272,
377,
275,
2434,
5894,
360,
52,
358,
272,
491,
442,
547,
275,
22400,
14,
44,
442,
547,
272,
491,
1058,
985,
275,
22400,
14,
44,
1058,
985,
339,
24870,
275,
1109,
272,
473,
388,
275,
620,
272,
20488,
275,
620,
272,
428,
392,
528,
27033,
275,
7448,
459,
51,
392,
528,
3845,
297,
3820,
59,
954,
18687,
14,
10708,
2677,
272,
598,
18404,
41,
8704,
275,
7448,
459,
39,
18404,
8954,
297,
3820,
59,
954,
18687,
14,
10708,
2677,
272,
2165,
4530,
10708,
83,
275,
3820,
59,
954,
18687,
14,
10708,
61,
272,
22240,
1197,
275,
15961,
459,
39,
18404,
8954,
297,
283,
51,
392,
528,
3845,
418,
339,
8511,
63,
275,
31906,
2141,
360,
2223,
14474,
469,
267,
283,
2682,
63,
1345,
356,
4879,
59,
954,
18687,
14,
2768,
467,
267,
283,
1818,
63,
5891,
356,
11634,
59,
954,
18687,
14,
10708,
12,
2263,
467,
267,
283,
12000,
63,
4196,
356,
2494,
59,
954,
18687,
14,
2768,
1304,
467,
267,
283,
10243,
63,
4196,
356,
2494,
59,
954,
18687,
14,
2768,
1304,
467,
267,
283,
4196,
356,
2494,
59,
954,
18687,
14,
2768,
1304,
61,
272,
3828,
339,
1487,
2137,
22236,
275,
16975,
9046,
44,
442,
547,
467,
2155,
61,
421,
199,
6131,
540,
6174,
63,
4831,
275,
334,
272,
1007,
18687,
14,
12118,
63,
2826,
63,
5110,
44,
1204,
272,
1007,
18687,
14,
12118,
63,
2826,
63,
1877,
6174,
199,
9,
199,
199,
10520,
63,
12307,
11344,
275,
469,
272,
283,
11550,
356,
1007,
18687,
14,
12118,
63,
2826,
63,
5110,
44,
12,
272,
283,
4498,
356,
1007,
18687,
14,
12118,
63,
2826,
63,
1877,
6174,
12,
272,
283,
18533,
63,
24396,
356,
1007,
18687,
14,
12118,
63,
15096,
998,
63,
6131,
540,
6174,
1204,
6778,
11733,
6174,
63,
4831,
12,
272,
283,
8471,
528,
20984,
63,
24396,
356,
1007,
18687,
14,
12118,
63,
51,
2328,
1277,
2226,
57,
63,
6131,
540,
6174,
1204,
6778,
11733,
6174,
63,
4831,
12,
272,
283,
270,
31112,
1146,
63,
24396,
356,
1007,
18687,
14,
12118,
63,
840,
1772,
48,
5290,
63,
6131,
540,
6174,
1204,
6778,
11733,
6174,
63,
4831,
12,
272,
283,
3592,
356,
1007,
18687,
14,
40,
22436,
199,
93,
199,
6131,
540,
6174,
63,
12307,
11344,
275,
334,
272,
283,
18533,
63,
24396,
297,
283,
8471,
528,
20984,
63,
24396,
297,
283,
270,
31112,
1146,
63,
24396,
7,
199,
9,
199,
199,
4118,
3635,
63,
5035,
275,
295,
14,
2014,
8,
82,
1154,
83,
358,
199,
38,
1761,
7111,
63,
10520,
63,
18466,
275,
283,
11550,
7,
199,
199,
5035,
63,
10452,
275,
295,
14,
2014,
8,
82,
15542,
83,
11,
9988,
199,
15635,
568,
654,
275,
295,
14,
2014,
2258,
78,
2229,
29,
4959,
358,
199,
199,
3,
4804,
18687,
2356,
6335,
1342,
5171,
25735,
15725,
641,
10424,
4601,
199,
3,
4178,
921,
5031,
14,
957,
15,
954,
18687,
21550,
15,
954,
18687,
63,
505,
15,
10115,
15,
7498,
199,
6348,
44,
3465,
63,
10640,
51,
63,
5035,
63,
51,
2328,
1277,
2226,
654,
275,
1109,
8,
954,
18687,
14,
1023,
1012,
2356,
6335,
1342,
199,
199,
2223,
275,
469,
272,
283,
2682,
63,
1345,
356,
488,
12,
272,
283,
1818,
63,
5891,
356,
2008,
1062,
272,
283,
12000,
63,
4196,
356,
663,
1062,
272,
283,
10243,
63,
4196,
356,
663,
1062,
272,
283,
4196,
356,
663,
342,
199,
93,
221,
327,
730,
26,
8511,
63,
421,
199,
318,
3589,
63,
4591,
837,
272,
8511,
14,
873,
2561,
267,
283,
2682,
63,
1345,
356,
1007,
18687,
14,
2682,
63,
3806,
1252,
2682,
63,
1345,
1062,
267,
283,
12000,
63,
4196,
356,
663,
342,
272,
3828,
421,
199,
318,
3589,
63,
324,
4591,
837,
272,
4474,
14,
1997,
8,
265,
63,
3854,
63,
1099,
9,
272,
367,
4353,
315,
1007,
18687,
14,
8258,
837,
267,
367,
2455,
315,
4353,
14,
4196,
837,
288,
625,
5485,
8,
1345,
9,
421,
199,
32,
4368,
14,
265,
8,
4368,
14,
44,
2919,
63,
9517,
9,
199,
318,
641,
63,
3854,
63,
1099,
8,
1501,
12,
7403,
351,
63,
354,
12,
1011,
958,
304,
272,
327,
730,
26,
334,
495,
12,
491,
1058,
985,
12,
909,
9,
1035,
488,
272,
6858,
275,
769,
8,
452,
63,
4196,
63,
9924,
63,
493,
8,
1501,
430,
272,
340,
440,
6858,
26,
267,
372,
339,
11850,
63,
25240,
63,
2550,
8,
4196,
12,
1788,
12,
7403,
351,
63,
354,
9,
421,
199,
533,
6162,
3314,
6200,
7506,
8,
954,
18687,
63,
2718,
14,
2390,
10464,
304,
272,
347,
641,
63,
912,
63,
4146,
8,
277,
12,
2455,
304,
267,
327,
730,
26,
334,
954,
18687,
14,
2768,
9,
1035,
488,
267,
327,
1678,
642,
892,
2455,
543,
1263,
2552,
652,
5544,
965,
267,
1788,
275,
4884,
14,
362,
63,
1501,
8,
1345,
9,
267,
2552,
275,
22400,
14,
493,
63,
2550,
14,
362,
8,
1501,
9,
267,
340,
2552,
26,
288,
663,
63,
12000,
8,
1345,
12,
715,
9,
221,
327,
2498,
2552,
9939,
288,
7403,
351,
63,
1247,
275,
663,
8,
705,
459,
25240,
418,
367,
1125,
315,
2552,
9,
288,
367,
7403,
351,
63,
354,
315,
7403,
351,
63,
1247,
26,
355,
11850,
63,
25240,
63,
2550,
779,
1345,
467,
1788,
12,
7403,
351,
63,
354,
9,
339,
641,
63,
6311,
63,
4146,
275,
641,
63,
912,
63,
4146,
421,
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,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
python/performance
|
pyperformance/benchmarks/bm_tornado_http.py
|
1
|
2910
|
"""Test the performance of simple HTTP serving and client using the Tornado
framework.
A trivial "application" is generated which generates a number of chunks of
data as a HTTP response's body.
"""
import sys
import socket
import pyperf
from tornado.httpclient import AsyncHTTPClient
from tornado.httpserver import HTTPServer
from tornado.gen import coroutine
from tornado.ioloop import IOLoop
from tornado.netutil import bind_sockets
from tornado.web import RequestHandler, Application
HOST = "127.0.0.1"
FAMILY = socket.AF_INET
CHUNK = b"Hello world\n" * 1000
NCHUNKS = 5
CONCURRENCY = 150
class MainHandler(RequestHandler):
@coroutine
def get(self):
for i in range(NCHUNKS):
self.write(CHUNK)
yield self.flush()
def compute_etag(self):
# Overriden to avoid stressing hashlib in this benchmark
return None
def make_application():
return Application([
(r"/", MainHandler),
])
def make_http_server(request_handler):
server = HTTPServer(request_handler)
sockets = bind_sockets(0, HOST, family=FAMILY)
assert len(sockets) == 1
server.add_sockets(sockets)
sock = sockets[0]
return server, sock
def bench_tornado(loops):
server, sock = make_http_server(make_application())
host, port = sock.getsockname()
url = "http://%s:%s/" % (host, port)
namespace = {}
@coroutine
def run_client():
client = AsyncHTTPClient()
range_it = range(loops)
t0 = pyperf.perf_counter()
for _ in range_it:
futures = [client.fetch(url) for j in range(CONCURRENCY)]
for fut in futures:
resp = yield fut
buf = resp.buffer
buf.seek(0, 2)
assert buf.tell() == len(CHUNK) * NCHUNKS
namespace['dt'] = pyperf.perf_counter() - t0
client.close()
IOLoop.current().run_sync(run_client)
server.stop()
return namespace['dt']
if __name__ == "__main__":
# 3.8 changed the default event loop to ProactorEventLoop which doesn't
# implement everything required by tornado and breaks this benchmark.
# Restore the old WindowsSelectorEventLoop default for now.
# https://bugs.python.org/issue37373
# https://github.com/python/pyperformance/issues/61
# https://github.com/tornadoweb/tornado/pull/2686
if sys.platform == 'win32' and sys.version_info[:2] >= (3, 8):
import asyncio
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
kw = {}
if pyperf.python_has_jit():
# PyPy needs to compute more warmup values to warmup its JIT
kw['warmups'] = 30
runner = pyperf.Runner(**kw)
runner.metadata['description'] = ("Test the performance of HTTP requests "
"with Tornado.")
runner.bench_time_func('tornado_http', bench_tornado)
|
mit
|
[
199,
624,
774,
314,
10238,
402,
3486,
3101,
22701,
436,
1890,
1808,
314,
377,
8622,
199,
4857,
14,
199,
199,
33,
28586,
298,
3578,
2,
365,
4046,
1314,
12821,
282,
1329,
402,
8291,
402,
199,
576,
465,
282,
3101,
1177,
1159,
2396,
14,
199,
624,
199,
199,
646,
984,
199,
646,
2838,
199,
199,
646,
1134,
9452,
199,
199,
504,
12148,
14,
1014,
1258,
492,
15223,
27757,
199,
504,
12148,
14,
1014,
1000,
492,
3101,
3120,
199,
504,
12148,
14,
2268,
492,
1970,
13242,
199,
504,
12148,
14,
27212,
492,
25584,
199,
504,
12148,
14,
846,
1974,
492,
5398,
63,
20517,
199,
504,
12148,
14,
2520,
492,
4784,
2461,
12,
13515,
421,
199,
5449,
275,
298,
4195,
14,
16,
14,
16,
14,
17,
2,
199,
38,
1156,
1193,
57,
275,
2838,
14,
5699,
63,
11367,
199,
199,
20512,
275,
330,
2,
6257,
6701,
60,
78,
2,
627,
5198,
199,
17940,
8019,
51,
275,
959,
199,
199,
1864,
7013,
24861,
275,
14711,
421,
199,
533,
11298,
2461,
8,
11149,
304,
339,
768,
16675,
272,
347,
664,
8,
277,
304,
267,
367,
284,
315,
1425,
8,
17940,
8019,
51,
304,
288,
291,
14,
952,
8,
20512,
9,
288,
1995,
291,
14,
4939,
342,
339,
347,
4526,
63,
11304,
8,
277,
304,
267,
327,
7259,
25045,
370,
5126,
31692,
316,
8337,
315,
642,
12338,
267,
372,
488,
421,
199,
318,
1852,
63,
3578,
837,
272,
372,
13515,
779,
267,
334,
82,
2,
10665,
11298,
2461,
395,
272,
4794,
421,
199,
318,
1852,
63,
1014,
63,
1000,
8,
1069,
63,
2232,
304,
272,
1654,
275,
3101,
3120,
8,
1069,
63,
2232,
9,
272,
18772,
275,
5398,
63,
20517,
8,
16,
12,
25741,
12,
9614,
29,
38,
1156,
1193,
57,
9,
272,
702,
822,
8,
20517,
9,
508,
413,
272,
1654,
14,
525,
63,
20517,
8,
20517,
9,
272,
6771,
275,
18772,
59,
16,
61,
272,
372,
1654,
12,
6771,
421,
199,
318,
26456,
63,
18443,
8,
22412,
304,
272,
1654,
12,
6771,
275,
1852,
63,
1014,
63,
1000,
8,
1875,
63,
3578,
1012,
272,
1591,
12,
1844,
275,
6771,
14,
27886,
342,
272,
1166,
275,
298,
1014,
13827,
83,
2689,
83,
6687,
450,
334,
1102,
12,
1844,
9,
272,
3231,
275,
1052,
339,
768,
16675,
272,
347,
1255,
63,
1258,
837,
267,
1890,
275,
15223,
27757,
342,
267,
1425,
63,
390,
275,
1425,
8,
22412,
9,
267,
307,
16,
275,
1134,
9452,
14,
9452,
63,
5337,
342,
398,
367,
485,
315,
1425,
63,
390,
26,
288,
27471,
275,
359,
1258,
14,
3535,
8,
633,
9,
367,
1335,
315,
1425,
8,
1864,
7013,
24861,
1874,
288,
367,
289,
337,
315,
27471,
26,
355,
3085,
275,
1995,
289,
337,
355,
4123,
275,
3085,
14,
2738,
355,
4123,
14,
5507,
8,
16,
12,
499,
9,
355,
702,
4123,
14,
9974,
342,
508,
822,
8,
20512,
9,
627,
653,
20512,
51,
398,
3231,
459,
3583,
418,
275,
1134,
9452,
14,
9452,
63,
5337,
342,
446,
307,
16,
267,
1890,
14,
1600,
342,
339,
25584,
14,
1818,
1252,
1065,
63,
5186,
8,
1065,
63,
1258,
9,
272,
1654,
14,
2379,
342,
339,
372,
3231,
459,
3583,
418,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
327,
650,
14,
24,
2896,
314,
849,
1566,
4438,
370,
2165,
5021,
2390,
7382,
1314,
3181,
1133,
272,
327,
5669,
8137,
1415,
701,
12148,
436,
18277,
642,
12338,
14,
272,
327,
22379,
314,
2269,
5417,
11212,
2390,
7382,
849,
367,
3063,
14,
272,
327,
4178,
921,
13017,
14,
1548,
14,
1308,
15,
5237,
1401,
14539,
272,
327,
4178,
921,
5031,
14,
957,
15,
1548,
15,
647,
20576,
15,
10115,
15,
2976,
272,
327,
4178,
921,
5031,
14,
957,
15,
84,
6161,
8369,
2871,
15,
18443,
15,
9302,
15,
1479,
1184,
272,
340,
984,
14,
3246,
508,
283,
2676,
708,
7,
436,
984,
14,
1023,
63,
815,
1491,
18,
61,
2356,
334,
19,
12,
1695,
304,
267,
492,
16195,
267,
16195,
14,
409,
63,
1430,
63,
3813,
63,
3185,
8,
19343,
14,
8647,
11212,
2390,
7382,
4845,
1012,
339,
4775,
275,
1052,
272,
340,
1134,
9452,
14,
1548,
63,
1989,
63,
17676,
837,
267,
327,
1611,
2713,
4839,
370,
4526,
1655,
20060,
384,
1338,
370,
20060,
384,
2399,
1603,
649,
267,
4775,
459,
10669,
15203,
418,
275,
4233,
272,
7876,
275,
1134,
9452,
14,
7446,
3682,
829,
9,
272,
7876,
14,
2343,
459,
1802,
418,
275,
1689,
774,
314,
10238,
402,
3101,
4145,
298,
4228,
298,
1045,
377,
8622,
2685,
272,
7876,
14,
16571,
63,
521,
63,
1532,
360,
18443,
63,
1014,
297,
26456,
63,
18443,
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
] |
[
624,
774,
314,
10238,
402,
3486,
3101,
22701,
436,
1890,
1808,
314,
377,
8622,
199,
4857,
14,
199,
199,
33,
28586,
298,
3578,
2,
365,
4046,
1314,
12821,
282,
1329,
402,
8291,
402,
199,
576,
465,
282,
3101,
1177,
1159,
2396,
14,
199,
624,
199,
199,
646,
984,
199,
646,
2838,
199,
199,
646,
1134,
9452,
199,
199,
504,
12148,
14,
1014,
1258,
492,
15223,
27757,
199,
504,
12148,
14,
1014,
1000,
492,
3101,
3120,
199,
504,
12148,
14,
2268,
492,
1970,
13242,
199,
504,
12148,
14,
27212,
492,
25584,
199,
504,
12148,
14,
846,
1974,
492,
5398,
63,
20517,
199,
504,
12148,
14,
2520,
492,
4784,
2461,
12,
13515,
421,
199,
5449,
275,
298,
4195,
14,
16,
14,
16,
14,
17,
2,
199,
38,
1156,
1193,
57,
275,
2838,
14,
5699,
63,
11367,
199,
199,
20512,
275,
330,
2,
6257,
6701,
60,
78,
2,
627,
5198,
199,
17940,
8019,
51,
275,
959,
199,
199,
1864,
7013,
24861,
275,
14711,
421,
199,
533,
11298,
2461,
8,
11149,
304,
339,
768,
16675,
272,
347,
664,
8,
277,
304,
267,
367,
284,
315,
1425,
8,
17940,
8019,
51,
304,
288,
291,
14,
952,
8,
20512,
9,
288,
1995,
291,
14,
4939,
342,
339,
347,
4526,
63,
11304,
8,
277,
304,
267,
327,
7259,
25045,
370,
5126,
31692,
316,
8337,
315,
642,
12338,
267,
372,
488,
421,
199,
318,
1852,
63,
3578,
837,
272,
372,
13515,
779,
267,
334,
82,
2,
10665,
11298,
2461,
395,
272,
4794,
421,
199,
318,
1852,
63,
1014,
63,
1000,
8,
1069,
63,
2232,
304,
272,
1654,
275,
3101,
3120,
8,
1069,
63,
2232,
9,
272,
18772,
275,
5398,
63,
20517,
8,
16,
12,
25741,
12,
9614,
29,
38,
1156,
1193,
57,
9,
272,
702,
822,
8,
20517,
9,
508,
413,
272,
1654,
14,
525,
63,
20517,
8,
20517,
9,
272,
6771,
275,
18772,
59,
16,
61,
272,
372,
1654,
12,
6771,
421,
199,
318,
26456,
63,
18443,
8,
22412,
304,
272,
1654,
12,
6771,
275,
1852,
63,
1014,
63,
1000,
8,
1875,
63,
3578,
1012,
272,
1591,
12,
1844,
275,
6771,
14,
27886,
342,
272,
1166,
275,
298,
1014,
13827,
83,
2689,
83,
6687,
450,
334,
1102,
12,
1844,
9,
272,
3231,
275,
1052,
339,
768,
16675,
272,
347,
1255,
63,
1258,
837,
267,
1890,
275,
15223,
27757,
342,
267,
1425,
63,
390,
275,
1425,
8,
22412,
9,
267,
307,
16,
275,
1134,
9452,
14,
9452,
63,
5337,
342,
398,
367,
485,
315,
1425,
63,
390,
26,
288,
27471,
275,
359,
1258,
14,
3535,
8,
633,
9,
367,
1335,
315,
1425,
8,
1864,
7013,
24861,
1874,
288,
367,
289,
337,
315,
27471,
26,
355,
3085,
275,
1995,
289,
337,
355,
4123,
275,
3085,
14,
2738,
355,
4123,
14,
5507,
8,
16,
12,
499,
9,
355,
702,
4123,
14,
9974,
342,
508,
822,
8,
20512,
9,
627,
653,
20512,
51,
398,
3231,
459,
3583,
418,
275,
1134,
9452,
14,
9452,
63,
5337,
342,
446,
307,
16,
267,
1890,
14,
1600,
342,
339,
25584,
14,
1818,
1252,
1065,
63,
5186,
8,
1065,
63,
1258,
9,
272,
1654,
14,
2379,
342,
339,
372,
3231,
459,
3583,
418,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
327,
650,
14,
24,
2896,
314,
849,
1566,
4438,
370,
2165,
5021,
2390,
7382,
1314,
3181,
1133,
272,
327,
5669,
8137,
1415,
701,
12148,
436,
18277,
642,
12338,
14,
272,
327,
22379,
314,
2269,
5417,
11212,
2390,
7382,
849,
367,
3063,
14,
272,
327,
4178,
921,
13017,
14,
1548,
14,
1308,
15,
5237,
1401,
14539,
272,
327,
4178,
921,
5031,
14,
957,
15,
1548,
15,
647,
20576,
15,
10115,
15,
2976,
272,
327,
4178,
921,
5031,
14,
957,
15,
84,
6161,
8369,
2871,
15,
18443,
15,
9302,
15,
1479,
1184,
272,
340,
984,
14,
3246,
508,
283,
2676,
708,
7,
436,
984,
14,
1023,
63,
815,
1491,
18,
61,
2356,
334,
19,
12,
1695,
304,
267,
492,
16195,
267,
16195,
14,
409,
63,
1430,
63,
3813,
63,
3185,
8,
19343,
14,
8647,
11212,
2390,
7382,
4845,
1012,
339,
4775,
275,
1052,
272,
340,
1134,
9452,
14,
1548,
63,
1989,
63,
17676,
837,
267,
327,
1611,
2713,
4839,
370,
4526,
1655,
20060,
384,
1338,
370,
20060,
384,
2399,
1603,
649,
267,
4775,
459,
10669,
15203,
418,
275,
4233,
272,
7876,
275,
1134,
9452,
14,
7446,
3682,
829,
9,
272,
7876,
14,
2343,
459,
1802,
418,
275,
1689,
774,
314,
10238,
402,
3101,
4145,
298,
4228,
298,
1045,
377,
8622,
2685,
272,
7876,
14,
16571,
63,
521,
63,
1532,
360,
18443,
63,
1014,
297,
26456,
63,
18443,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
BehavioralInsightsTeam/edx-platform
|
openedx/core/djangoapps/credentials/utils.py
|
9
|
2901
|
"""Helper functions for working with Credentials."""
from __future__ import unicode_literals
from django.conf import settings
from edx_rest_api_client.client import EdxRestApiClient
from openedx.core.djangoapps.credentials.models import CredentialsApiConfig
from openedx.core.lib.edx_api_utils import get_edx_api_data
from openedx.core.lib.token_utils import JwtBuilder
def get_credentials_records_url(program_uuid=None):
"""
Returns a URL for a given records page (or general records list if given no UUID).
May return None if this feature is disabled.
"""
base_url = CredentialsApiConfig.current().public_records_url
if base_url is None:
return None
if program_uuid:
return base_url + 'programs/{}/'.format(program_uuid)
return base_url
def get_credentials_api_client(user, org=None):
"""
Returns an authenticated Credentials API client.
Arguments:
user (User): The user to authenticate as when requesting credentials.
org (str): Optional organization to look up the site config for, rather than the current request
"""
scopes = ['email', 'profile']
expires_in = settings.OAUTH_ID_TOKEN_EXPIRATION
jwt = JwtBuilder(user).build_token(scopes, expires_in)
if org is None:
url = CredentialsApiConfig.current().internal_api_url # by current request
else:
url = CredentialsApiConfig.get_internal_api_url_for_org(org) # by org
return EdxRestApiClient(url, jwt=jwt)
def get_credentials(user, program_uuid=None, credential_type=None):
"""
Given a user, get credentials earned from the credentials service.
Arguments:
user (User): The user to authenticate as when requesting credentials.
Keyword Arguments:
program_uuid (str): UUID of the program whose credential to retrieve.
credential_type (str): Which type of credentials to return (course-run or program)
Returns:
list of dict, representing credentials returned by the Credentials
service.
"""
credential_configuration = CredentialsApiConfig.current()
querystring = {'username': user.username, 'status': 'awarded'}
if program_uuid:
querystring['program_uuid'] = program_uuid
if credential_type:
querystring['type'] = credential_type
# Bypass caching for staff users, who may be generating credentials and
# want to see them displayed immediately.
use_cache = credential_configuration.is_cache_enabled and not user.is_staff
cache_key = '{}.{}'.format(credential_configuration.CACHE_KEY, user.username) if use_cache else None
if cache_key and program_uuid:
cache_key = '{}.{}'.format(cache_key, program_uuid)
api = get_credentials_api_client(user)
return get_edx_api_data(
credential_configuration, 'credentials', api=api, querystring=querystring, cache_key=cache_key
)
|
agpl-3.0
|
[
624,
4433,
3423,
367,
6449,
543,
23934,
1041,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
22435,
63,
3911,
63,
1246,
63,
1258,
14,
1258,
492,
662,
8373,
13726,
7394,
3041,
199,
199,
504,
22709,
14,
1018,
14,
16432,
14,
6942,
14,
992,
492,
23934,
7394,
2028,
199,
504,
22709,
14,
1018,
14,
773,
14,
8268,
63,
1246,
63,
1208,
492,
664,
63,
8268,
63,
1246,
63,
576,
199,
504,
22709,
14,
1018,
14,
773,
14,
1418,
63,
1208,
492,
1603,
9115,
6437,
421,
199,
318,
664,
63,
6942,
63,
6502,
63,
633,
8,
6815,
63,
2580,
29,
403,
304,
272,
408,
272,
1803,
282,
2851,
367,
282,
1627,
5767,
2034,
334,
269,
8605,
5767,
769,
340,
1627,
949,
11134,
680,
272,
10162,
372,
488,
340,
642,
3878,
365,
6980,
14,
272,
408,
272,
1300,
63,
633,
275,
23934,
7394,
2028,
14,
1818,
1252,
3455,
63,
6502,
63,
633,
272,
340,
1300,
63,
633,
365,
488,
26,
267,
372,
488,
272,
340,
2240,
63,
2580,
26,
267,
372,
1300,
63,
633,
435,
283,
28464,
19655,
1370,
908,
8,
6815,
63,
2580,
9,
272,
372,
1300,
63,
633,
421,
199,
318,
664,
63,
6942,
63,
1246,
63,
1258,
8,
751,
12,
5981,
29,
403,
304,
272,
408,
272,
1803,
376,
15082,
23934,
3261,
1890,
14,
339,
7628,
26,
267,
922,
334,
1899,
304,
710,
922,
370,
12895,
465,
1380,
23502,
6235,
14,
267,
5981,
334,
495,
304,
4879,
13237,
370,
3648,
1536,
314,
4770,
1101,
367,
12,
7830,
2419,
314,
1453,
1056,
339,
408,
339,
14570,
275,
788,
2123,
297,
283,
2913,
418,
272,
12261,
63,
262,
275,
2202,
14,
24041,
63,
998,
63,
8803,
63,
25632,
23743,
272,
1335,
9115,
275,
1603,
9115,
6437,
8,
751,
680,
1506,
63,
1418,
8,
14129,
12,
12261,
63,
262,
9,
339,
340,
5981,
365,
488,
26,
267,
1166,
275,
23934,
7394,
2028,
14,
1818,
1252,
4672,
63,
1246,
63,
633,
221,
327,
701,
1453,
1056,
272,
587,
26,
267,
1166,
275,
23934,
7394,
2028,
14,
362,
63,
4672,
63,
1246,
63,
633,
63,
509,
63,
1308,
8,
1308,
9,
221,
327,
701,
5981,
272,
372,
662,
8373,
13726,
7394,
3041,
8,
633,
12,
1335,
9115,
29,
30033,
9,
421,
199,
318,
664,
63,
6942,
8,
751,
12,
2240,
63,
2580,
29,
403,
12,
16338,
63,
466,
29,
403,
304,
272,
408,
272,
9138,
282,
922,
12,
664,
6235,
325,
31772,
687,
314,
6235,
2435,
14,
339,
7628,
26,
267,
922,
334,
1899,
304,
710,
922,
370,
12895,
465,
1380,
23502,
6235,
14,
339,
6431,
7628,
26,
267,
2240,
63,
2580,
334,
495,
304,
11134,
402,
314,
2240,
7447,
16338,
370,
8044,
14,
267,
16338,
63,
466,
334,
495,
304,
26058,
730,
402,
6235,
370,
372,
334,
1972,
13,
1065,
503,
2240,
9,
339,
1803,
26,
267,
769,
402,
1211,
12,
6144,
6235,
2138,
701,
314,
23934,
267,
2435,
14,
272,
408,
272,
16338,
63,
4758,
275,
23934,
7394,
2028,
14,
1818,
342,
339,
1827,
875,
275,
791,
2473,
356,
922,
14,
2473,
12,
283,
1205,
356,
283,
65,
15295,
936,
339,
340,
2240,
63,
2580,
26,
267,
1827,
875,
459,
6815,
63,
2580,
418,
275,
2240,
63,
2580,
339,
340,
16338,
63,
466,
26,
267,
1827,
875,
459,
466,
418,
275,
16338,
63,
466,
339,
327,
4885,
1529,
13627,
367,
12622,
4390,
12,
3963,
1443,
506,
12999,
6235,
436,
272,
327,
2934,
370,
1937,
3062,
9080,
9939,
14,
272,
675,
63,
1637,
275,
16338,
63,
4758,
14,
374,
63,
1637,
63,
3827,
436,
440,
922,
14,
374,
63,
7018,
272,
2581,
63,
498,
275,
9005,
14,
11123,
908,
8,
15591,
63,
4758,
14,
8677,
63,
3078,
12,
922,
14,
2473,
9,
340,
675,
63,
1637,
587,
488,
272,
340,
2581,
63,
498,
436,
2240,
63,
2580,
26,
267,
2581,
63,
498,
275,
9005,
14,
11123,
908,
8,
1637,
63,
498,
12,
2240,
63,
2580,
9,
272,
2986,
275,
664,
63,
6942,
63,
1246,
63,
1258,
8,
751,
9,
339,
372,
664,
63,
8268,
63,
1246,
63,
576,
8,
267,
16338,
63,
4758,
12,
283,
6942,
297,
2986,
29,
1246,
12,
1827,
875,
29,
1131,
875,
12,
2581,
63,
498,
29,
1637,
63,
498,
272,
776,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
4433,
3423,
367,
6449,
543,
23934,
1041,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
22435,
63,
3911,
63,
1246,
63,
1258,
14,
1258,
492,
662,
8373,
13726,
7394,
3041,
199,
199,
504,
22709,
14,
1018,
14,
16432,
14,
6942,
14,
992,
492,
23934,
7394,
2028,
199,
504,
22709,
14,
1018,
14,
773,
14,
8268,
63,
1246,
63,
1208,
492,
664,
63,
8268,
63,
1246,
63,
576,
199,
504,
22709,
14,
1018,
14,
773,
14,
1418,
63,
1208,
492,
1603,
9115,
6437,
421,
199,
318,
664,
63,
6942,
63,
6502,
63,
633,
8,
6815,
63,
2580,
29,
403,
304,
272,
408,
272,
1803,
282,
2851,
367,
282,
1627,
5767,
2034,
334,
269,
8605,
5767,
769,
340,
1627,
949,
11134,
680,
272,
10162,
372,
488,
340,
642,
3878,
365,
6980,
14,
272,
408,
272,
1300,
63,
633,
275,
23934,
7394,
2028,
14,
1818,
1252,
3455,
63,
6502,
63,
633,
272,
340,
1300,
63,
633,
365,
488,
26,
267,
372,
488,
272,
340,
2240,
63,
2580,
26,
267,
372,
1300,
63,
633,
435,
283,
28464,
19655,
1370,
908,
8,
6815,
63,
2580,
9,
272,
372,
1300,
63,
633,
421,
199,
318,
664,
63,
6942,
63,
1246,
63,
1258,
8,
751,
12,
5981,
29,
403,
304,
272,
408,
272,
1803,
376,
15082,
23934,
3261,
1890,
14,
339,
7628,
26,
267,
922,
334,
1899,
304,
710,
922,
370,
12895,
465,
1380,
23502,
6235,
14,
267,
5981,
334,
495,
304,
4879,
13237,
370,
3648,
1536,
314,
4770,
1101,
367,
12,
7830,
2419,
314,
1453,
1056,
339,
408,
339,
14570,
275,
788,
2123,
297,
283,
2913,
418,
272,
12261,
63,
262,
275,
2202,
14,
24041,
63,
998,
63,
8803,
63,
25632,
23743,
272,
1335,
9115,
275,
1603,
9115,
6437,
8,
751,
680,
1506,
63,
1418,
8,
14129,
12,
12261,
63,
262,
9,
339,
340,
5981,
365,
488,
26,
267,
1166,
275,
23934,
7394,
2028,
14,
1818,
1252,
4672,
63,
1246,
63,
633,
221,
327,
701,
1453,
1056,
272,
587,
26,
267,
1166,
275,
23934,
7394,
2028,
14,
362,
63,
4672,
63,
1246,
63,
633,
63,
509,
63,
1308,
8,
1308,
9,
221,
327,
701,
5981,
272,
372,
662,
8373,
13726,
7394,
3041,
8,
633,
12,
1335,
9115,
29,
30033,
9,
421,
199,
318,
664,
63,
6942,
8,
751,
12,
2240,
63,
2580,
29,
403,
12,
16338,
63,
466,
29,
403,
304,
272,
408,
272,
9138,
282,
922,
12,
664,
6235,
325,
31772,
687,
314,
6235,
2435,
14,
339,
7628,
26,
267,
922,
334,
1899,
304,
710,
922,
370,
12895,
465,
1380,
23502,
6235,
14,
339,
6431,
7628,
26,
267,
2240,
63,
2580,
334,
495,
304,
11134,
402,
314,
2240,
7447,
16338,
370,
8044,
14,
267,
16338,
63,
466,
334,
495,
304,
26058,
730,
402,
6235,
370,
372,
334,
1972,
13,
1065,
503,
2240,
9,
339,
1803,
26,
267,
769,
402,
1211,
12,
6144,
6235,
2138,
701,
314,
23934,
267,
2435,
14,
272,
408,
272,
16338,
63,
4758,
275,
23934,
7394,
2028,
14,
1818,
342,
339,
1827,
875,
275,
791,
2473,
356,
922,
14,
2473,
12,
283,
1205,
356,
283,
65,
15295,
936,
339,
340,
2240,
63,
2580,
26,
267,
1827,
875,
459,
6815,
63,
2580,
418,
275,
2240,
63,
2580,
339,
340,
16338,
63,
466,
26,
267,
1827,
875,
459,
466,
418,
275,
16338,
63,
466,
339,
327,
4885,
1529,
13627,
367,
12622,
4390,
12,
3963,
1443,
506,
12999,
6235,
436,
272,
327,
2934,
370,
1937,
3062,
9080,
9939,
14,
272,
675,
63,
1637,
275,
16338,
63,
4758,
14,
374,
63,
1637,
63,
3827,
436,
440,
922,
14,
374,
63,
7018,
272,
2581,
63,
498,
275,
9005,
14,
11123,
908,
8,
15591,
63,
4758,
14,
8677,
63,
3078,
12,
922,
14,
2473,
9,
340,
675,
63,
1637,
587,
488,
272,
340,
2581,
63,
498,
436,
2240,
63,
2580,
26,
267,
2581,
63,
498,
275,
9005,
14,
11123,
908,
8,
1637,
63,
498,
12,
2240,
63,
2580,
9,
272,
2986,
275,
664,
63,
6942,
63,
1246,
63,
1258,
8,
751,
9,
339,
372,
664,
63,
8268,
63,
1246,
63,
576,
8,
267,
16338,
63,
4758,
12,
283,
6942,
297,
2986,
29,
1246,
12,
1827,
875,
29,
1131,
875,
12,
2581,
63,
498,
29,
1637,
63,
498,
272,
776,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
AuyaJackie/odoo
|
addons/base_geolocalize/models/res_partner.py
|
239
|
3743
|
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2013_Today OpenERP SA (<http://www.openerp.com>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
try:
import simplejson as json
except ImportError:
import json # noqa
import urllib
from openerp.osv import osv, fields
from openerp import tools
from openerp.tools.translate import _
def geo_find(addr):
url = 'https://maps.googleapis.com/maps/api/geocode/json?sensor=false&address='
url += urllib.quote(addr.encode('utf8'))
try:
result = json.load(urllib.urlopen(url))
except Exception, e:
raise osv.except_osv(_('Network error'),
_('Cannot contact geolocation servers. Please make sure that your internet connection is up and running (%s).') % e)
if result['status'] != 'OK':
return None
try:
geo = result['results'][0]['geometry']['location']
return float(geo['lat']), float(geo['lng'])
except (KeyError, ValueError):
return None
def geo_query_address(street=None, zip=None, city=None, state=None, country=None):
if country and ',' in country and (country.endswith(' of') or country.endswith(' of the')):
# put country qualifier in front, otherwise GMap gives wrong results,
# e.g. 'Congo, Democratic Republic of the' => 'Democratic Republic of the Congo'
country = '{1} {0}'.format(*country.split(',', 1))
return tools.ustr(', '.join(filter(None, [street,
("%s %s" % (zip or '', city or '')).strip(),
state,
country])))
class res_partner(osv.osv):
_inherit = "res.partner"
_columns = {
'partner_latitude': fields.float('Geo Latitude', digits=(16, 5)),
'partner_longitude': fields.float('Geo Longitude', digits=(16, 5)),
'date_localization': fields.date('Geo Localization Date'),
}
def geo_localize(self, cr, uid, ids, context=None):
# Don't pass context to browse()! We need country names in english below
for partner in self.browse(cr, uid, ids):
if not partner:
continue
result = geo_find(geo_query_address(street=partner.street,
zip=partner.zip,
city=partner.city,
state=partner.state_id.name,
country=partner.country_id.name))
if result:
self.write(cr, uid, [partner.id], {
'partner_latitude': result[0],
'partner_longitude': result[1],
'date_localization': fields.date.context_today(self, cr, uid, context=context)
}, context=context)
return True
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
6171,
63,
31982,
7653,
13950,
8642,
1014,
921,
1544,
14,
11267,
14,
957,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
893,
26,
272,
492,
13804,
465,
2022,
199,
2590,
3545,
26,
272,
492,
2022,
258,
327,
8151,
199,
646,
4011,
199,
199,
504,
5166,
14,
4795,
492,
9506,
12,
1504,
199,
504,
5166,
492,
7249,
199,
504,
5166,
14,
2537,
14,
5275,
492,
485,
421,
199,
318,
8509,
63,
1623,
8,
2697,
304,
272,
1166,
275,
283,
2859,
921,
8919,
14,
17533,
14,
957,
15,
8919,
15,
1246,
15,
6721,
600,
15,
1001,
31,
8956,
29,
3910,
6,
1562,
534,
272,
1166,
847,
4011,
14,
3513,
8,
2697,
14,
2143,
360,
1624,
24,
1333,
339,
862,
26,
267,
754,
275,
2022,
14,
912,
8,
4078,
14,
10890,
8,
633,
430,
272,
871,
2186,
12,
325,
26,
267,
746,
9506,
14,
2590,
63,
4795,
6723,
4491,
1125,
659,
2490,
4018,
6612,
8966,
8509,
1985,
8037,
14,
7754,
1852,
3238,
626,
2195,
21408,
1950,
365,
1536,
436,
3879,
4366,
83,
28583,
450,
325,
9,
272,
340,
754,
459,
1205,
418,
1137,
283,
3593,
356,
267,
372,
488,
339,
862,
26,
267,
8509,
275,
754,
459,
2604,
3488,
16,
2733,
7660,
2545,
1985,
418,
267,
372,
2069,
8,
6721,
459,
4452,
3815,
2069,
8,
6721,
459,
23829,
1105,
272,
871,
334,
10230,
12,
1722,
304,
267,
372,
488,
421,
199,
318,
8509,
63,
1131,
63,
1562,
8,
20451,
29,
403,
12,
3482,
29,
403,
12,
14492,
29,
403,
12,
1174,
29,
403,
12,
9023,
29,
403,
304,
272,
340,
9023,
436,
13647,
315,
9023,
436,
334,
6063,
14,
4130,
360,
402,
358,
503,
9023,
14,
4130,
360,
402,
314,
8109,
267,
327,
5324,
9023,
6420,
9893,
315,
13738,
12,
4257,
598,
2956,
10557,
6835,
2058,
12,
267,
327,
325,
14,
71,
14,
283,
714,
1939,
12,
28939,
67,
19826,
799,
3455,
402,
314,
7,
9265,
283,
21493,
67,
19826,
799,
3455,
402,
314,
445,
5774,
7,
267,
9023,
275,
5041,
17,
93,
469,
16,
5285,
908,
2031,
6063,
14,
1294,
32718,
413,
430,
272,
372,
7249,
14,
11409,
5102,
1987,
904,
8,
1541,
8,
403,
12,
359,
20451,
12,
6343,
19426,
83,
450,
83,
2,
450,
334,
3065,
503,
3260,
14492,
503,
4074,
680,
1913,
1062,
6343,
1174,
12,
6343,
9023,
11845,
421,
199,
533,
522,
63,
3899,
8,
4795,
14,
4795,
304,
272,
485,
6486,
275,
298,
470,
14,
3899,
2,
339,
485,
3406,
275,
469,
267,
283,
3899,
63,
13331,
356,
1504,
14,
1609,
360,
10748,
491,
31429,
3786,
297,
7576,
2687,
975,
12,
959,
1826,
267,
283,
3899,
63,
13803,
356,
1504,
14,
1609,
360,
10748,
19944,
7779,
297,
7576,
2687,
975,
12,
959,
1826,
267,
283,
602,
63,
1832,
2072,
356,
1504,
14,
602,
360,
10748,
10111,
2072,
6148,
659,
272,
789,
339,
347,
8509,
63,
21279,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
1067,
29,
403,
304,
267,
327,
7529,
1133,
986,
1067,
370,
19249,
342,
1,
2136,
1929,
9023,
1561,
315,
20171,
1891,
5084,
267,
367,
5854,
315,
291,
14,
4570,
8,
1556,
12,
1747,
12,
2762,
304,
288,
340,
440,
5854,
26,
355,
1980,
288,
754,
275,
8509,
63,
1623,
8,
6721,
63,
1131,
63,
1562,
8,
20451,
29,
3899,
14,
20451,
12,
6059,
3482,
29,
3899,
14,
3065,
12,
6059,
14492,
29,
3899,
14,
3690,
12,
6059,
1174,
29,
3899,
14,
929,
63,
344,
14,
354,
12,
6059,
9023,
29,
3899,
14,
6063,
63,
344,
14,
354,
430,
288,
340,
754,
26,
355,
291,
14,
952,
8,
1556,
12,
1747,
12,
359,
3899,
14,
344,
467,
469,
490,
283,
3899,
63,
13331,
356,
754,
59,
16,
467,
490,
283,
3899,
63,
13803,
356,
754,
59,
17,
467,
490,
283,
602,
63,
1832,
2072,
356,
1504,
14,
602,
14,
1100,
63,
8136,
8,
277,
12,
2467,
12,
1747,
12,
1067,
29,
1100,
9,
355,
1660,
1067,
29,
1100,
9,
267,
372,
715,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
6171,
63,
31982,
7653,
13950,
8642,
1014,
921,
1544,
14,
11267,
14,
957,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
893,
26,
272,
492,
13804,
465,
2022,
199,
2590,
3545,
26,
272,
492,
2022,
258,
327,
8151,
199,
646,
4011,
199,
199,
504,
5166,
14,
4795,
492,
9506,
12,
1504,
199,
504,
5166,
492,
7249,
199,
504,
5166,
14,
2537,
14,
5275,
492,
485,
421,
199,
318,
8509,
63,
1623,
8,
2697,
304,
272,
1166,
275,
283,
2859,
921,
8919,
14,
17533,
14,
957,
15,
8919,
15,
1246,
15,
6721,
600,
15,
1001,
31,
8956,
29,
3910,
6,
1562,
534,
272,
1166,
847,
4011,
14,
3513,
8,
2697,
14,
2143,
360,
1624,
24,
1333,
339,
862,
26,
267,
754,
275,
2022,
14,
912,
8,
4078,
14,
10890,
8,
633,
430,
272,
871,
2186,
12,
325,
26,
267,
746,
9506,
14,
2590,
63,
4795,
6723,
4491,
1125,
659,
2490,
4018,
6612,
8966,
8509,
1985,
8037,
14,
7754,
1852,
3238,
626,
2195,
21408,
1950,
365,
1536,
436,
3879,
4366,
83,
28583,
450,
325,
9,
272,
340,
754,
459,
1205,
418,
1137,
283,
3593,
356,
267,
372,
488,
339,
862,
26,
267,
8509,
275,
754,
459,
2604,
3488,
16,
2733,
7660,
2545,
1985,
418,
267,
372,
2069,
8,
6721,
459,
4452,
3815,
2069,
8,
6721,
459,
23829,
1105,
272,
871,
334,
10230,
12,
1722,
304,
267,
372,
488,
421,
199,
318,
8509,
63,
1131,
63,
1562,
8,
20451,
29,
403,
12,
3482,
29,
403,
12,
14492,
29,
403,
12,
1174,
29,
403,
12,
9023,
29,
403,
304,
272,
340,
9023,
436,
13647,
315,
9023,
436,
334,
6063,
14,
4130,
360,
402,
358,
503,
9023,
14,
4130,
360,
402,
314,
8109,
267,
327,
5324,
9023,
6420,
9893,
315,
13738,
12,
4257,
598,
2956,
10557,
6835,
2058,
12,
267,
327,
325,
14,
71,
14,
283,
714,
1939,
12,
28939,
67,
19826,
799,
3455,
402,
314,
7,
9265,
283,
21493,
67,
19826,
799,
3455,
402,
314,
445,
5774,
7,
267,
9023,
275,
5041,
17,
93,
469,
16,
5285,
908,
2031,
6063,
14,
1294,
32718,
413,
430,
272,
372,
7249,
14,
11409,
5102,
1987,
904,
8,
1541,
8,
403,
12,
359,
20451,
12,
6343,
19426,
83,
450,
83,
2,
450,
334,
3065,
503,
3260,
14492,
503,
4074,
680,
1913,
1062,
6343,
1174,
12,
6343,
9023,
11845,
421,
199,
533,
522,
63,
3899,
8,
4795,
14,
4795,
304,
272,
485,
6486,
275,
298,
470,
14,
3899,
2,
339,
485,
3406,
275,
469,
267,
283,
3899,
63,
13331,
356,
1504,
14,
1609,
360,
10748,
491,
31429,
3786,
297,
7576,
2687,
975,
12,
959,
1826,
267,
283,
3899,
63,
13803,
356,
1504,
14,
1609,
360,
10748,
19944,
7779,
297,
7576,
2687,
975,
12,
959,
1826,
267,
283,
602,
63,
1832,
2072,
356,
1504,
14,
602,
360,
10748,
10111,
2072,
6148,
659,
272,
789,
339,
347,
8509,
63,
21279,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
1067,
29,
403,
304,
267,
327,
7529,
1133,
986,
1067,
370,
19249,
342,
1,
2136,
1929,
9023,
1561,
315,
20171,
1891,
5084,
267,
367,
5854,
315,
291,
14,
4570,
8,
1556,
12,
1747,
12,
2762,
304,
288,
340,
440,
5854,
26,
355,
1980,
288,
754,
275,
8509,
63,
1623,
8,
6721,
63,
1131,
63,
1562,
8,
20451,
29,
3899,
14,
20451,
12,
6059,
3482,
29,
3899,
14,
3065,
12,
6059,
14492,
29,
3899,
14,
3690,
12,
6059,
1174,
29,
3899,
14,
929,
63,
344,
14,
354,
12,
6059,
9023,
29,
3899,
14,
6063,
63,
344,
14,
354,
430,
288,
340,
754,
26,
355,
291,
14,
952,
8,
1556,
12,
1747,
12,
359,
3899,
14,
344,
467,
469,
490,
283,
3899,
63,
13331,
356,
754,
59,
16,
467,
490,
283,
3899,
63,
13803,
356,
754,
59,
17,
467,
490,
283,
602,
63,
1832,
2072,
356,
1504,
14,
602,
14,
1100,
63,
8136,
8,
277,
12,
2467,
12,
1747,
12,
1067,
29,
1100,
9,
355,
1660,
1067,
29,
1100,
9,
267,
372,
715,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
minhphung171093/OpenERP_V8
|
openerp/addons/mail/res_partner.py
|
379
|
2454
|
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp.tools.translate import _
from openerp.osv import fields, osv
class res_partner_mail(osv.Model):
""" Update partner to add a field about notification preferences """
_name = "res.partner"
_inherit = ['res.partner', 'mail.thread']
_mail_flat_thread = False
_mail_mass_mailing = _('Customers')
_columns = {
'notify_email': fields.selection([
('none', 'Never'),
('always', 'All Messages'),
], 'Receive Inbox Notifications by Email', required=True,
oldname='notification_email_send',
help="Policy to receive emails for new messages pushed to your personal Inbox:\n"
"- Never: no emails are sent\n"
"- All Messages: for every notification you receive in your Inbox"),
}
_defaults = {
'notify_email': lambda *args: 'always'
}
def message_get_suggested_recipients(self, cr, uid, ids, context=None):
recipients = super(res_partner_mail, self).message_get_suggested_recipients(cr, uid, ids, context=context)
for partner in self.browse(cr, uid, ids, context=context):
self._message_add_suggested_recipient(cr, uid, recipients, partner, partner=partner, reason=_('Partner Profile'))
return recipients
def message_get_default_recipients(self, cr, uid, ids, context=None):
return dict((id, {'partner_ids': [id], 'email_to': False, 'email_cc': False}) for id in ids)
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
504,
5166,
14,
2537,
14,
5275,
492,
485,
199,
504,
5166,
14,
4795,
492,
1504,
12,
9506,
421,
199,
533,
522,
63,
3899,
63,
1198,
8,
4795,
14,
1685,
304,
272,
408,
6162,
5854,
370,
1050,
282,
901,
3595,
6955,
23453,
408,
272,
485,
354,
275,
298,
470,
14,
3899,
2,
272,
485,
6486,
275,
788,
470,
14,
3899,
297,
283,
1198,
14,
2671,
418,
272,
485,
1198,
63,
7088,
63,
2671,
275,
756,
272,
485,
1198,
63,
11535,
63,
22989,
275,
4018,
35,
28078,
358,
339,
485,
3406,
275,
469,
267,
283,
6814,
63,
2123,
356,
1504,
14,
5592,
779,
288,
661,
3592,
297,
283,
4698,
422,
659,
288,
661,
9223,
297,
283,
2422,
27377,
659,
288,
2156,
283,
14235,
1010,
1977,
23362,
83,
701,
11426,
297,
1415,
29,
549,
12,
288,
2269,
354,
534,
6761,
63,
2123,
63,
2254,
297,
288,
1720,
628,
4845,
370,
9128,
14931,
367,
892,
3788,
22319,
370,
2195,
25994,
1010,
1977,
3427,
78,
2,
490,
3905,
5612,
422,
26,
949,
14931,
787,
4847,
60,
78,
2,
490,
3905,
2900,
27377,
26,
367,
4036,
6955,
1265,
9128,
315,
2195,
1010,
1977,
1288,
272,
789,
339,
485,
4322,
275,
469,
267,
283,
6814,
63,
2123,
356,
2400,
627,
589,
26,
283,
9223,
7,
272,
789,
339,
347,
1245,
63,
362,
63,
29833,
63,
18323,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
1067,
29,
403,
304,
267,
19255,
275,
1613,
8,
470,
63,
3899,
63,
1198,
12,
291,
680,
1188,
63,
362,
63,
29833,
63,
18323,
8,
1556,
12,
1747,
12,
2762,
12,
1067,
29,
1100,
9,
267,
367,
5854,
315,
291,
14,
4570,
8,
1556,
12,
1747,
12,
2762,
12,
1067,
29,
1100,
304,
288,
291,
423,
1188,
63,
525,
63,
29833,
63,
10043,
8,
1556,
12,
1747,
12,
19255,
12,
5854,
12,
5854,
29,
3899,
12,
4499,
12397,
24120,
14386,
1333,
267,
372,
19255,
339,
347,
1245,
63,
362,
63,
885,
63,
18323,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
1067,
29,
403,
304,
267,
372,
1211,
1332,
344,
12,
791,
3899,
63,
1580,
356,
359,
344,
467,
283,
2123,
63,
475,
356,
756,
12,
283,
2123,
63,
2055,
356,
756,
1552,
367,
1305,
315,
2762,
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
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
504,
5166,
14,
2537,
14,
5275,
492,
485,
199,
504,
5166,
14,
4795,
492,
1504,
12,
9506,
421,
199,
533,
522,
63,
3899,
63,
1198,
8,
4795,
14,
1685,
304,
272,
408,
6162,
5854,
370,
1050,
282,
901,
3595,
6955,
23453,
408,
272,
485,
354,
275,
298,
470,
14,
3899,
2,
272,
485,
6486,
275,
788,
470,
14,
3899,
297,
283,
1198,
14,
2671,
418,
272,
485,
1198,
63,
7088,
63,
2671,
275,
756,
272,
485,
1198,
63,
11535,
63,
22989,
275,
4018,
35,
28078,
358,
339,
485,
3406,
275,
469,
267,
283,
6814,
63,
2123,
356,
1504,
14,
5592,
779,
288,
661,
3592,
297,
283,
4698,
422,
659,
288,
661,
9223,
297,
283,
2422,
27377,
659,
288,
2156,
283,
14235,
1010,
1977,
23362,
83,
701,
11426,
297,
1415,
29,
549,
12,
288,
2269,
354,
534,
6761,
63,
2123,
63,
2254,
297,
288,
1720,
628,
4845,
370,
9128,
14931,
367,
892,
3788,
22319,
370,
2195,
25994,
1010,
1977,
3427,
78,
2,
490,
3905,
5612,
422,
26,
949,
14931,
787,
4847,
60,
78,
2,
490,
3905,
2900,
27377,
26,
367,
4036,
6955,
1265,
9128,
315,
2195,
1010,
1977,
1288,
272,
789,
339,
485,
4322,
275,
469,
267,
283,
6814,
63,
2123,
356,
2400,
627,
589,
26,
283,
9223,
7,
272,
789,
339,
347,
1245,
63,
362,
63,
29833,
63,
18323,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
1067,
29,
403,
304,
267,
19255,
275,
1613,
8,
470,
63,
3899,
63,
1198,
12,
291,
680,
1188,
63,
362,
63,
29833,
63,
18323,
8,
1556,
12,
1747,
12,
2762,
12,
1067,
29,
1100,
9,
267,
367,
5854,
315,
291,
14,
4570,
8,
1556,
12,
1747,
12,
2762,
12,
1067,
29,
1100,
304,
288,
291,
423,
1188,
63,
525,
63,
29833,
63,
10043,
8,
1556,
12,
1747,
12,
19255,
12,
5854,
12,
5854,
29,
3899,
12,
4499,
12397,
24120,
14386,
1333,
267,
372,
19255,
339,
347,
1245,
63,
362,
63,
885,
63,
18323,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
1067,
29,
403,
304,
267,
372,
1211,
1332,
344,
12,
791,
3899,
63,
1580,
356,
359,
344,
467,
283,
2123,
63,
475,
356,
756,
12,
283,
2123,
63,
2055,
356,
756,
1552,
367,
1305,
315,
2762,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
leogulus/pisco_pipeline
|
pisco_photometry_all_2019.py
|
1
|
76497
|
import sys, os, re, yaml, subprocess, shlex, FITS_tools
import pandas as pd
import numpy as np
import pickle
import matplotlib
import matplotlib.pyplot as plt
from matplotlib import image
import matplotlib.cm as cm
import matplotlib.image as mpimg
from scipy.optimize import curve_fit
import scipy.integrate as integrate
from scipy import interpolate
from scipy.interpolate import interp1d
import scipy.stats
from astropy.io import fits
from astropy.table import Table, join
from astropy import units as u
from astropy.coordinates import SkyCoord
from astropy.cosmology import FlatLambdaCDM
cosmo = FlatLambdaCDM(H0=71, Om0=0.3, Tcmb0=2.725)
import extra_program as ex
from PIL import Image as Image_PIL
import ebvpy #Galactic Reddening
"""
Example:
python pisco_pipeline/pisco_photometry_all_2019.py PKS1353 psf allslr 2mass
python pisco_pipeline/pisco_photometry_all_2019.py PKS1353 psf allslr no2mass
python pisco_pipeline/pisco_photometry_all_2019.py PKS1353 psf noslr no2mass
python pisco_pipeline/pisco_photometry_all_2019.py PKS1353 auto noslr no2mass
field: name of the fields
mode: psf, auto, aper, hybrid, model
allslr:
- allslr: run everything including photometry_v4, cut_frame, SLR
- slr: run just SLR and update the color
- noslr: don't run slr, just update the color with different modes
2mass
- 2mass: run SLR with 2MASS to match
- no2mass: run SLR without 2MASS
"""
###--------------------------------------------------------------------------###
def find_seeing(field,band):
df_see=pd.read_csv('/Users/taweewat/Documents/red_sequence/total_chips_field_seeing.csv',index_col=0)
if field[0:5]=='CHIPS':
seeing = df_see[df_see.chips==field]['seeing_q25_%s'%band].values[0] #_%s'%band
return seeing
elif (field[0:5]=='Field')|(field[0:3]=='PKS')|(field[0:4]=='SDSS'):
seeing = df_see[df_see.name==field]['seeing_q25_%s'%band].values[0] #_%s'%band
return seeing
def find_seeing_new(dir,field):
myReg3=re.compile(r'(CHIPS)[^\_]*\_[^\_]*')
seeing = float(fits.open(list_file_name(dir,myReg3.search(field).group())[0])[0].header['FWHM1'])
return seeing
def find_seeing_fits(field):
home='/Users/taweewat/Documents/pisco_code/'
dirs=['ut170103/','ut170104/','ut170619/','ut170621/','ut170624/','ut171208/',\
'ut171209/','ut171212/','ut190412/','ut190413/']
myReg=re.compile(r'(%s_A).*'%field)
for di in dirs:
dir=home+di
for text in os.listdir(dir):
if myReg.search(text) != None:
seeing=float(fits.open(dir+myReg.search(text).group())[0].header['FWHM1'])
return seeing
def read_param():
with open("pisco_pipeline/params.yaml", 'r') as stream:
try:
param=yaml.load(stream, Loader=yaml.FullLoader)
return param
except yaml.YAMLError as exc:
print(exc)
def read_param_izp(mode):
if mode=='psf':
mode_izp=''
elif mode=='model':
mode_izp='' #'_model'
else:
mode_izp=''
# print "/Users/taweewat/Documents/pisco_code/pisco_pipeline/params_izeropoint%s.yaml" % mode_izp
with open("/Users/taweewat/Documents/pisco_code/pisco_pipeline/params_izeropoint%s.yaml"%mode_izp, 'r') as stream:
try:
param=yaml.load(stream, Loader=yaml.FullLoader)
return param
except yaml.YAMLError as exc:
print(exc)
def star_galaxy_bleem(field):
sg_dir = 'star_galaxy'
if not os.path.exists(sg_dir):
os.makedirs(sg_dir)
param=read_param()
# seeing=find_seeing(field,'i')
# seeing=find_seeing_fits(field)
seeing = 1.0
# seeing=1.5
# seeing=0.95
minarea=1.7
data, header = fits.getdata('final/coadd_c%s_i.fits'%field, header=True)
data2=data**2
# pxscale=0.11
pxscale=0.22
fits.writeto('final/coadd_c%s_sq_i.fits'%field, data2, header=header, overwrite=True)
cmd='sex final/coadd_c%s_i.fits -c pisco_pipeline/config.sex -PARAMETERS_NAME pisco_pipeline/%s -CATALOG_NAME %s -CATALOG_TYPE FITS_1.0 -SEEING_FWHM %s -SATUR_LEVEL %s -PHOT_APERTURES 15 -PIXEL_SCALE %s -DETECT_MINAREA %s -CHECKIMAGE_NAME checki.fits,segmenti.fits'%\
(field,'sex.param',sg_dir+'/%s_catalog.fits'%(field),str(seeing),str(param['satur_level_i_psf']),str(pxscale),str(1.1/minarea*np.pi*(seeing/pxscale)**2)); print cmd
subprocess.check_call(shlex.split(cmd))
cmd='sex final/coadd_c%s_i.fits,final/coadd_c%s_sq_i.fits -c pisco_pipeline/config.sex -PARAMETERS_NAME pisco_pipeline/%s -CATALOG_NAME %s -CATALOG_TYPE FITS_1.0 -SEEING_FWHM %s -SATUR_LEVEL %s -PHOT_APERTURES 15 -PIXEL_SCALE %s -DETECT_MINAREA %s'%\
(field,field,'sex.param',sg_dir+'/%s_sq_catalog.fits'%(field),str(seeing),str(param['satur_level_i_sq_psf']),str(pxscale),str(1.1/minarea*np.pi*(seeing/pxscale)**2)); print cmd
subprocess.check_call(shlex.split(cmd))
def pisco_photometry_v4(field):
def aperature_proj(field,band):
param=read_param()
seeing=find_seeing(field,band)
# seeing=find_seeing_fits(field)
# seeing = 1.1
# seeing=1.5
slrdir = 'slr_output'
to_be_projected = 'final/coadd_c%s_%s.fits'%(field,band)
reference_fits = 'final/coadd_c%s_i.fits'%field
im1,im2, header = FITS_tools.match_fits(to_be_projected,reference_fits,return_header=True)
outname = 'final/proj_coadd_c%s_%s.fits'%(field,band)
print 'projecting from %s band to i band the fits file '%band + outname
fits.writeto(outname, im1, header, overwrite=True)
minarea=1.7 #1.7
pxscale=0.22
# pxscale=0.11
cmd='sex final/coadd_c%s_%s.fits -c pisco_pipeline/config.sex -PARAMETERS_NAME pisco_pipeline/%s -CATALOG_NAME %s -SEEING_FWHM %s -SATUR_LEVEL %s -PHOT_APERTURES 23 -PIXEL_SCALE %s -DETECT_MINAREA %s -CHECKIMAGE_NAME check_psf_%s.fits,segment_psf_%s.fits'%\
(field,band,'sex_psf.param','psfex_output/psf_%s_%s.fits'%(field,band),str(seeing),str(param['satur_level_%s_psf'%band]),str(pxscale),str(1.1/minarea*np.pi*(seeing/pxscale)**2), band, band)
print cmd
subprocess.check_call(shlex.split(cmd))
Tf=Table(fits.open('psfex_output/psf_%s_%s.fits'%(field,band))[2].data)
# Tfcut = Tf[(Tf['CLASS_STAR'] > 0.97) & (Tf['FLAGS'] == 0)].copy() #0.97 Field292
if len(Tf[(Tf['CLASS_STAR'] > 0.95) & (Tf['FLAGS'] < 5)]) > 0:
Tfcut = Tf[(Tf['CLASS_STAR'] > 0.95) & (Tf['FLAGS'] < 5)].copy()
else:
Tfcut = Tf[(Tf['CLASS_STAR'] > 0.9) & (Tf['FLAGS'] < 5)].copy()
# Tfcut = Tf[(Tf['CLASS_STAR'] > 0.9) & (Tf['FLAGS'] < 5)].copy() #0.97 Field292
Tfcut_edge=Tfcut[(Tfcut['XWIN_IMAGE']<np.max(Tfcut['XWIN_IMAGE'])-60)&(Tfcut['XWIN_IMAGE']>np.min(Tfcut['XWIN_IMAGE'])+60)&\
(Tfcut['YWIN_IMAGE']<np.max(Tfcut['YWIN_IMAGE'])-60)&(Tfcut['YWIN_IMAGE']>np.min(Tfcut['YWIN_IMAGE'])+60)].copy()
Tfcut_more=Tfcut_edge[(np.abs(Tfcut_edge['FLUX_RADIUS']-np.mean(Tfcut_edge['FLUX_RADIUS']))<2*np.std(Tfcut_edge['FLUX_RADIUS']))]
Tfcut_more2=Tfcut_more[(np.abs(Tfcut_more['ELONGATION']-np.mean(Tfcut_more['ELONGATION']))<2*np.std(Tfcut_more['ELONGATION']))].copy()
print "length of Tf: all: {}, CS>0.97: {}, edges: {}, flux_radius: {}, elong: {}".format(len(Tf), len(Tfcut), len(Tfcut_edge), len(Tfcut_more), len(Tfcut_more2))
hdu = fits.open('psfex_output/psf_%s_%s.fits'%(field,band))
hdu[2].data = hdu[2].data[Tfcut_more2['NUMBER']-1]
# hdu[2].data = hdu[2].data[Tfcut['NUMBER']-1]
hdu.writeto('psfex_output/psf_%s_%s.fits'%(field,band), overwrite=True)
cmd='psfex %s -c pisco_pipeline/pisco.psfex' % ('psfex_output/psf_%s_%s.fits'%(field,band))
print cmd
subprocess.check_call(shlex.split(cmd))
# minarea=3.0
cmd='sex final/coadd_c%s_i.fits,final/proj_coadd_c%s_%s.fits -c pisco_pipeline/config.sex -PSF_NAME %s -PARAMETERS_NAME pisco_pipeline/%s -CATALOG_NAME %s -SEEING_FWHM %s -SATUR_LEVEL %s -PIXEL_SCALE %s -CATALOG_TYPE FITS_1.0 -PHOT_APERTURES 23 -DETECT_MINAREA %s -CHECKIMAGE_NAME check%s.fits,segment%s.fits'%\
(field, field, band, 'psfex_output/psf_%s_%s.psf' % (field, band), 'sex_after_psf.param', '%s/a_psf_%s_%s.fits' % (slrdir, field, band),
str(seeing), str(param['satur_level_%s_psf' % band]), str(pxscale), str(1.1 / minarea * np.pi * (seeing / pxscale)**2), band, band)
print cmd
subprocess.check_call(shlex.split(cmd))
table=Table.read('%s/a_psf_%s_%s.fits'%(slrdir,field,band))
for name in table.colnames[:]:
table.rename_column(name, name + '_%s' % band)
return table
slrdir = 'slr_output'
if not os.path.exists(slrdir):
os.makedirs(slrdir)
tableg=aperature_proj(field,'g')
tablei=aperature_proj(field,'i')
tabler=aperature_proj(field,'r')
tablez=aperature_proj(field,'z')
print 'len of all table', len(tableg), len(tablei), len(tabler), len(tablez)
ci=SkyCoord(ra=np.array(tablei['ALPHA_J2000_i'])*u.degree, dec=np.array(tablei['DELTA_J2000_i'])*u.degree)# print len(ci)
cg=SkyCoord(ra=np.array(tableg['ALPHA_J2000_g'])*u.degree, dec=np.array(tableg['DELTA_J2000_g'])*u.degree)# print len(cg)
cr=SkyCoord(ra=np.array(tabler['ALPHA_J2000_r'])*u.degree, dec=np.array(tabler['DELTA_J2000_r'])*u.degree)# print len(cr)
cz=SkyCoord(ra=np.array(tablez['ALPHA_J2000_z'])*u.degree, dec=np.array(tablez['DELTA_J2000_z'])*u.degree)# print len(cz)
idxn, d2dn, d3dn=cg.match_to_catalog_sky(ci)
# Table_I=tablei[idxn][['NUMBER_i','XWIN_IMAGE_i','YWIN_IMAGE_i','ALPHA_J2000_i','DELTA_J2000_i','MAG_APER_i','MAGERR_APER_i','MAG_AUTO_i','MAGERR_AUTO_i','MAG_HYBRID_i','MAGERR_HYBRID_i',\
# 'CLASS_STAR_i','FLAGS_i','MAG_PSF_i','MAGERR_PSF_i','MAG_MODEL_i','MAGERR_MODEL_i','SPREAD_MODEL_i']]
Table_I=tablei[idxn][['NUMBER_i','XWIN_IMAGE_i','YWIN_IMAGE_i','ALPHA_J2000_i','DELTA_J2000_i','MAG_APER_i','MAGERR_APER_i','MAG_AUTO_i','MAGERR_AUTO_i','MAG_SPHEROID_i','MAGERR_SPHEROID_i',\
'CLASS_STAR_i','FLAGS_i','MAG_PSF_i','MAGERR_PSF_i','MAG_MODEL_i','MAGERR_MODEL_i','SPREAD_MODEL_i','SPREADERR_MODEL_i','MAG_ISO_i','MAGERR_ISO_i']]
Table_I.rename_column('ALPHA_J2000_i','ALPHA_J2000')
Table_I.rename_column('DELTA_J2000_i','DELTA_J2000')
idxn, d2dn, d3dn=cg.match_to_catalog_sky(cr)
# Table_R=tabler[idxn][['NUMBER_r','ALPHA_J2000_r','DELTA_J2000_r','MAG_APER_r','MAGERR_APER_r','MAG_AUTO_r','MAGERR_AUTO_r','MAG_HYBRID_r','MAGERR_HYBRID_r',\
# 'CLASS_STAR_r','FLAGS_r','MAG_PSF_r','MAGERR_PSF_r','MAG_MODEL_r','MAGERR_MODEL_r','SPREAD_MODEL_r']]
Table_R=tabler[idxn][['NUMBER_r','ALPHA_J2000_r','DELTA_J2000_r','MAG_APER_r','MAGERR_APER_r','MAG_AUTO_r','MAGERR_AUTO_r','MAG_SPHEROID_r','MAGERR_SPHEROID_r',\
'CLASS_STAR_r','FLAGS_r','MAG_PSF_r','MAGERR_PSF_r','MAG_MODEL_r','MAGERR_MODEL_r','SPREAD_MODEL_r','SPREADERR_MODEL_r','MAG_ISO_r','MAGERR_ISO_r']]
Table_R.rename_column('ALPHA_J2000_r','ALPHA_J2000')
Table_R.rename_column('DELTA_J2000_r','DELTA_J2000')
idxn, d2dn, d3dn=cg.match_to_catalog_sky(cz)
# Table_Z=tablez[idxn][['NUMBER_z','ALPHA_J2000_z','DELTA_J2000_z','MAG_APER_z','MAGERR_APER_z','MAG_AUTO_z','MAGERR_AUTO_z','MAG_HYBRID_z','MAGERR_HYBRID_z',\
# 'CLASS_STAR_z','FLAGS_z','MAG_PSF_z','MAGERR_PSF_z','MAG_MODEL_z','MAGERR_MODEL_z','SPREAD_MODEL_z']]
Table_Z=tablez[idxn][['NUMBER_z','ALPHA_J2000_z','DELTA_J2000_z','MAG_APER_z','MAGERR_APER_z','MAG_AUTO_z','MAGERR_AUTO_z','MAG_SPHEROID_z','MAGERR_SPHEROID_z',\
'CLASS_STAR_z','FLAGS_z','MAG_PSF_z','MAGERR_PSF_z','MAG_MODEL_z','MAGERR_MODEL_z','SPREAD_MODEL_z','SPREADERR_MODEL_z','MAG_ISO_z','MAGERR_ISO_z']]
Table_Z.rename_column('ALPHA_J2000_z','ALPHA_J2000')
Table_Z.rename_column('DELTA_J2000_z','DELTA_J2000')
# Table_G=tableg[['NUMBER_g','ALPHA_J2000_g','DELTA_J2000_g','MAG_APER_g','MAGERR_APER_g','MAG_AUTO_g','MAGERR_AUTO_g','MAG_HYBRID_g','MAGERR_HYBRID_g',\
# 'CLASS_STAR_g','FLAGS_g','MAG_PSF_g','MAGERR_PSF_g','MAG_MODEL_g','MAGERR_MODEL_g','SPREAD_MODEL_g']]
Table_G = tableg[['NUMBER_g', 'ALPHA_J2000_g', 'DELTA_J2000_g', 'MAG_APER_g', 'MAGERR_APER_g', 'MAG_AUTO_g', 'MAGERR_AUTO_g', 'MAG_SPHEROID_g', 'MAGERR_SPHEROID_g',
'CLASS_STAR_g','FLAGS_g','MAG_PSF_g','MAGERR_PSF_g','MAG_MODEL_g','MAGERR_MODEL_g','SPREAD_MODEL_g','SPREADERR_MODEL_g','MAG_ISO_g','MAGERR_ISO_g']]
Table_G.rename_column('ALPHA_J2000_g','ALPHA_J2000')
Table_G.rename_column('DELTA_J2000_g','DELTA_J2000')
print 'len of all new table', len(Table_G), len(Table_I), len(Table_R), len(Table_Z)
total=join(join(join(Table_I,Table_G,keys=['ALPHA_J2000','DELTA_J2000']),Table_R,keys=['ALPHA_J2000','DELTA_J2000']),\
Table_Z,keys=['ALPHA_J2000','DELTA_J2000'])
# total=join(join(join(mag_ii,mag_ig,keys='NUMBER'), mag_ir,keys='NUMBER'),\
# mag_iz,keys='NUMBER')
# total2=total[['ALPHA_J2000','DELTA_J2000','NUMBER_i','NUMBER_r','NUMBER_g','XWIN_IMAGE_i','YWIN_IMAGE_i',\
# 'MAG_APER_i','MAGERR_APER_i','MAG_APER_g','MAGERR_APER_g','MAG_APER_r',\
# 'MAGERR_APER_r','MAG_APER_z','MAGERR_APER_z','MAG_AUTO_i','MAGERR_AUTO_i',\
# 'MAG_AUTO_g','MAGERR_AUTO_g','MAG_AUTO_r','MAGERR_AUTO_r','MAG_AUTO_z',\
# 'MAGERR_AUTO_z','MAG_HYBRID_i','MAGERR_HYBRID_i','MAG_HYBRID_g',\
# 'MAGERR_HYBRID_g','MAG_HYBRID_r','MAGERR_HYBRID_r','MAG_HYBRID_z',\
# 'MAGERR_HYBRID_z','CLASS_STAR_i','CLASS_STAR_g','CLASS_STAR_r',\
# 'CLASS_STAR_z','FLAGS_g','FLAGS_r','FLAGS_i','FLAGS_z','MAG_PSF_g',\
# 'MAG_PSF_r','MAG_PSF_i','MAG_PSF_z','MAGERR_PSF_g','MAGERR_PSF_r',\
# 'MAGERR_PSF_i','MAGERR_PSF_z','MAG_MODEL_g','MAG_MODEL_r',\
# 'MAG_MODEL_i','MAG_MODEL_z','MAGERR_MODEL_g','MAGERR_MODEL_r',\
# 'MAGERR_MODEL_i','MAGERR_MODEL_z','SPREAD_MODEL_g','SPREAD_MODEL_r',\
# 'SPREAD_MODEL_i','SPREAD_MODEL_z',]]
total.write(os.path.join(slrdir, 'total0_psf_%s.csv' % field), overwrite=True)
total2=total[['ALPHA_J2000','DELTA_J2000','NUMBER_i','NUMBER_r','NUMBER_g','XWIN_IMAGE_i','YWIN_IMAGE_i',\
'MAG_APER_i','MAGERR_APER_i','MAG_APER_g','MAGERR_APER_g','MAG_APER_r',\
'MAGERR_APER_r','MAG_APER_z','MAGERR_APER_z','MAG_AUTO_i','MAGERR_AUTO_i',\
'MAG_AUTO_g','MAGERR_AUTO_g','MAG_AUTO_r','MAGERR_AUTO_r','MAG_AUTO_z',\
'MAGERR_AUTO_z','MAG_ISO_g','MAGERR_ISO_g','MAG_ISO_r','MAGERR_ISO_r',\
'MAG_ISO_i','MAGERR_ISO_i','MAG_ISO_z','MAGERR_ISO_z',\
'MAG_SPHEROID_i','MAGERR_SPHEROID_i','MAG_SPHEROID_g',\
'MAGERR_SPHEROID_g','MAG_SPHEROID_r','MAGERR_SPHEROID_r','MAG_SPHEROID_z',\
'MAGERR_SPHEROID_z','CLASS_STAR_i','CLASS_STAR_g','CLASS_STAR_r',\
'CLASS_STAR_z','FLAGS_g','FLAGS_r','FLAGS_i','FLAGS_z','MAG_PSF_g',\
'MAG_PSF_r','MAG_PSF_i','MAG_PSF_z','MAGERR_PSF_g','MAGERR_PSF_r',\
'MAGERR_PSF_i','MAGERR_PSF_z','MAG_MODEL_g','MAG_MODEL_r',\
'MAG_MODEL_i','MAG_MODEL_z','MAGERR_MODEL_g','MAGERR_MODEL_r',\
'MAGERR_MODEL_i','MAGERR_MODEL_z','SPREAD_MODEL_g','SPREAD_MODEL_r',\
'SPREAD_MODEL_i','SPREAD_MODEL_z','SPREADERR_MODEL_g','SPREADERR_MODEL_r',\
'SPREADERR_MODEL_i','SPREADERR_MODEL_z']]
total2.write(os.path.join(slrdir, 'total_psf_%s.csv' % field), overwrite=True)
# total2.write(slrdir+'/all_psf_%s.fits' % field, overwrite=True)
def pisco_cut_star(field,c_a,c_b,c_d,c_delta):
seeing=find_seeing_fits(field)
true_seeing=find_seeing(field,'i')
df_i=Table(fits.open('/Users/taweewat/Documents/pisco_code/star_galaxy/%s_catalog.fits'%field)[1].data).to_pandas()
df_isq=Table(fits.open('/Users/taweewat/Documents/pisco_code/star_galaxy/%s_sq_catalog.fits'%field)[1].data).to_pandas()
#cut the object out so that it has the same number of object between the sq catalog list and the psf mag list.
fname = "/Users/taweewat/Documents/pisco_code/slr_output/total_psf_%s.csv"%field
df0 = pd.read_csv(fname)
df0['NUMBER'] = np.arange(0, len(df0), 1).tolist()
cf_i=SkyCoord(ra=np.array(df_i['ALPHA_J2000'])*u.degree, dec=np.array(df_i['DELTA_J2000'])*u.degree)
cf_isq=SkyCoord(ra=np.array(df_isq['ALPHA_J2000'])*u.degree, dec=np.array(df_isq['DELTA_J2000'])*u.degree)
cf0=SkyCoord(ra=np.array(df0['ALPHA_J2000'])*u.degree, dec=np.array(df0['DELTA_J2000'])*u.degree)
df0.rename(columns={'ALPHA_J2000': 'ALPHA_J2000_i'}, inplace=True)
df0.rename(columns={'DELTA_J2000': 'DELTA_J2000_i'}, inplace=True)
idxn, d2dn, d3dn=cf0.match_to_catalog_sky(cf_i)
df_i_cut0=df_i.loc[idxn].copy()
df_i_cut0['NUMBER']=np.arange(0,len(df0),1).tolist()
df_i_cut=pd.merge(df_i_cut0,df0,on='NUMBER')
idxn, d2dn, d3dn=cf0.match_to_catalog_sky(cf_isq)
df_isq_cut0=df_isq.loc[idxn].copy()
df_isq_cut0['NUMBER']=np.arange(0,len(df0),1).tolist()
df_isq_cut=pd.merge(df_isq_cut0,df0,on='NUMBER')
fig,ax=plt.subplots(2,3,figsize=(15,10))
df_i0=df_i_cut[(df_i_cut.MAG_APER<0)&(df_isq_cut.MAG_APER<0)]
df_isq0=df_isq_cut[(df_i_cut.MAG_APER<0)&(df_isq_cut.MAG_APER<0)]# print len(df_i), len(df_isq)
# c_d=-7.5
df_i2=df_i0[(df_i0.CLASS_STAR>c_a) & (df_i0.MAG_APER<c_d)]# & (df_i0.MAG_APER>c_c)]
df_isq2=df_isq0[(df_i0.CLASS_STAR>c_a) & (df_i0.MAG_APER<c_d)]# & (df_i0.MAG_APER>c_c)];# print len(df_i2), len(df_isq2)
icut_per=np.percentile(df_i2.MAG_APER,35) #35
df_i3=df_i2[df_i2.MAG_APER>icut_per]
df_isq3=df_isq2[df_i2.MAG_APER>icut_per]
fit=np.polyfit(df_i3.MAG_APER, df_i3.MAG_APER-df_isq3.MAG_APER, 1)
f=np.poly1d(fit)
ax[0,0].plot(df_i2.MAG_APER,f(df_i2.MAG_APER),'--')
res=(df_i3.MAG_APER-df_isq3.MAG_APER)-f(df_i3.MAG_APER)
aa=np.abs(res)<1.5*np.std(res)
# outl=np.abs(res)>=1.5*np.std(res)
fit=np.polyfit(df_i3.MAG_APER[aa], df_i3.MAG_APER[aa]-df_isq3.MAG_APER[aa], 1)
f=np.poly1d(fit)
ax[0,0].axvline(icut_per,color='blue',label='35th quantile')
ax[0,0].errorbar(df_i2.MAG_APER,df_i2.MAG_APER-df_isq2.MAG_APER,yerr=np.sqrt(df_i2.MAGERR_APER**2+df_isq2.MAGERR_APER**2),fmt='o')
ax[0,0].set_title('only for star')
ax[0,0].plot(df_i2.MAG_APER,f(df_i2.MAG_APER),'--',label='no outlier')
ax[0,0].set_ylabel('MAG_APER-MAG_APER_sq')
ax[0,0].set_xlabel('MAG APER i')
#---> #0.1 default, 0.2
c_c=df_i2[f(df_i2.MAG_APER)-(df_i2.MAG_APER-df_isq2.MAG_APER)<0.1]['MAG_APER'].values\
[np.argmin(df_i2[f(df_i2.MAG_APER)-(df_i2.MAG_APER-df_isq2.MAG_APER)<0.1]['MAG_APER'].values)] #edit10/30 (previous 0.1)
#--->
ax[0,0].axvline(c_c,color='red',label='new upper cut')
ax[0,0].legend(loc='best')
# color_axis='CLASS_STAR'
color_axis='SPREAD_MODEL_i'
ax[0,1].scatter(df_i0.MAG_APER,df_i0.MAG_APER-df_isq0.MAG_APER,marker='.',c=df_i0[color_axis],vmin=0., vmax=0.005)
ax[0,1].plot(df_i3.MAG_APER,df_i3.MAG_APER-df_isq3.MAG_APER,'x')
ax[0,1].set_title('for all objects')
ax[0,1].set_ylabel('MAG_APER-MAG_APER_sq')
ax[0,1].set_xlabel('MAG APER i')
ax[0,1].axvline(c_b,ls='--')
ax[0,1].axvline(c_c,ls='--')
delta=(df_i0.MAG_APER-df_isq0.MAG_APER) - f(df_i0.MAG_APER)
ax[0,2].scatter(df_i0.MAG_APER,delta,marker='.',c=df_i0[color_axis],vmin=0., vmax=0.005)
ax[0,2].axhline(0,ls='--')
ax[0,2].axvline(c_c,ls='--')
ax[0,2].axvline(c_b,ls='--')
ax[0,2].set_ylabel('Delta')
ax[0,2].set_xlabel('MAG APER i')
ax[0,2].set_ylim(0.5,-1.2)
df_i1=df_i0[(df_i0.MAG_APER>c_c)&(df_i0.MAG_APER<c_b)].copy()
df_isq1=df_isq0[(df_i0.MAG_APER>c_c)&(df_i0.MAG_APER<c_b)].copy()
delta1=(df_i1.MAG_APER-df_isq1.MAG_APER) - f(df_i1.MAG_APER)
ax[1,0].scatter(df_i1.MAG_APER, delta1, marker='o', c=df_i1[color_axis],vmin=0., vmax=0.005)
ax[1,0].axhline(0,ls='--')
ax[1,0].axhline(c_delta, ls='--')
ax[1,0].set_ylabel('Delta')
ax[1,0].set_xlabel('MAG APER i')
ax[1,0].set_ylim(0.5,-2)
# deltag=delta1[delta1<c_delta] #galaxy 0.1, 0.2 (0.005), 0.5 ()
deltas=delta1[(delta1>=c_delta)&(delta1<3.)] #star
def gauss(x, *p):
A, mu, sigma = p
return A*np.exp(-(x-mu)**2/(2.*sigma**2))
p0 = [1., 0., 0.1]
# def gauss(x, *p):
# A, sigma = p
# return A*np.exp(-(x-0)**2/(2.*sigma**2))
# p0 = [1., 0.1]
#galaxy
# hist, bin_edges = np.histogram(deltag,bins=np.arange(-1.2,0.5,0.02))
hist, bin_edges = np.histogram(delta1,bins=np.arange(-1.2,0.5,0.02))
bin_centres = (bin_edges[:-1] + bin_edges[1:])/2
ax[1,1].plot(bin_centres, hist, label='galaxies',linestyle='steps')
#stars
hist, bin_edges = np.histogram(deltas,bins=np.arange(-1,0.5,0.02)) #(0 vs -1,0.5,0.02)
# hist, bin_edges = np.histogram(delta1, bins=np.arange(c_delta, 0.5, 0.02))
bin_centres = (bin_edges[:-1] + bin_edges[1:])/2
coeff2, var_matrix = curve_fit(gauss, bin_centres, hist, p0=p0)
ax[1,1].plot(bin_centres, hist, label='stars',linestyle='steps')
# hist, bin_edges = np.histogram(delta1,bins=np.arange(-1.2,0.5,0.02)) #added for right gaussian fitting
# bin_centres = (bin_edges[:-1] + bin_edges[1:])/2 # added for right gaussian fitting
x=np.arange(-1.25,0.5,0.02)
# hist_fit2 = gauss(x, *coeff2)
hist_fit2 = gauss(x, *coeff2)
hist_fit3 = gauss(x, *coeff2)/np.max(gauss(x, *coeff2)) #added for right gaussian fitting
ax[1,1].plot(x, hist_fit2, label='stars_fit')
ax[1,1].plot(x, hist_fit3, label='stars_fit_norm') #added for right gaussian fitting
ax[1,1].axvline(x[hist_fit3>star_cut][0],c='tab:pink',label='cut:%.3f'%x[hist_fit3>star_cut][0]) #added for right gaussian fitting
ax[1,1].legend(loc='best')
ax[1,1].set_xlabel('Delta')
ax[1,1].set_ylabel('Histogram')
ax[0,2].axhline(x[hist_fit3>star_cut][0],c='tab:pink') #added for right gaussian fitting
ax[1,0].axhline(x[hist_fit3>star_cut][0],c='tab:pink') #added for right gaussian fitting
ax[1,2].axhline(star_cut, c='tab:red') # added for right gaussian fitting
maxi=np.max(gauss(delta,*coeff2))
def prob_SG(delta,maxi,*coeff2):
if delta>0.:
return 0.
elif delta<=0.:
return 1. - (gauss(delta, *coeff2) / maxi)
vprob_SG= np.vectorize(prob_SG)
SG=1.-vprob_SG(delta1,maxi,*coeff2)
df_i1.loc[:,'SG']=SG
param_izp=read_param_izp('psf')
mag0=param_izp['i_zp_day%i'%dir_dict[find_fits_dir(field)[-9:]]]
axi = ax[1, 2].scatter(df_i1.MAG_APER + mag0, SG,
marker='.', c=df_i1[color_axis], vmin=0., vmax=0.005)
ax[1,2].axvline(aper_cut, ls='--', c='tab:blue')
ax[1,2].axhline(SG_upper, ls='--', c='tab:blue')
ax[1,2].set_ylim(-0.02,1.02)
ax[1,2].set_xlabel('MAG APER i')
ax[1,2].set_ylabel('SG (probability to be a star)')
plt.suptitle(field+' seeing vs true_seeing: '+str(seeing)+','+str(true_seeing))
fig.colorbar(axi)
plt.tight_layout(rect=[0, 0., 1, 0.98])
plt.savefig('/Users/taweewat/Documents/red_sequence/pisco_color_plots/star_galaxy_sep_12_all%s.png' % field, dpi=120)
plt.close(fig)
return df_i_cut, df_i1
def pisco_cut_frame(field):
# df_i=Table(fits.open('/Users/taweewat/Documents/pisco_code/star_galaxy/'+
# '%s_catalog.fits'%field)[1].data).to_pandas()
"""
c_a: CLASS_STAR lower limit for stars used for the linear fit
c_b, c_c: upper and lower limit for all objects selection
c_c can be moved with the for loop to include more objects until the confusion limit
c_d: Faintest magnitude for stars used for the linear fit
c_delta: lower limit for Delta to consider stars before fitting the gaussian and find SG (Star/Galaxy) factor
"""
seeing=find_seeing_fits(field)
true_seeing=find_seeing(field,'i')
##Using SPREAD_MODEL to seperate star/galaxies
fname = "/Users/taweewat/Documents/pisco_code/slr_output/total_psf_%s.csv"%field
df0 = pd.read_csv(fname)
df0['NUMBER'] = np.arange(0, len(df0), 1).tolist()
df0.rename(columns={'ALPHA_J2000': 'ALPHA_J2000_i'}, inplace=True)
df0.rename(columns={'DELTA_J2000': 'DELTA_J2000_i'}, inplace=True)
#EXTENDED_COADD: 0 star, 1 likely star, 2 mostly galaxies, 3 galaxies
# df0['EXTENDED_COADD']=np.array(((df0['SPREAD_MODEL_i']+ 3*df0['SPREADERR_MODEL_i'])>0.005).values, dtype=int)+\
# np.array(((df0['SPREAD_MODEL_i']+df0['SPREADERR_MODEL_i'])>0.003).values, dtype=int)+\
# np.array(((df0['SPREAD_MODEL_i']-df0['SPREADERR_MODEL_i'])>0.003).values, dtype=int)
# dff=df0[df0['EXTENDED_COADD']>1]
# dff_star=df0[df0['EXTENDED_COADD']<2]
dfi=df0[df0['MAG_AUTO_i']<-16]
x=dfi['MAG_AUTO_i']
y=dfi['SPREAD_MODEL_i']
p_spread=np.poly1d(np.polyfit(x,y,1))
xs=np.arange(np.min(df0['MAG_AUTO_i']),np.max(df0['MAG_AUTO_i']),0.01)
df0['SPREAD_MODEL_i2']=df0['SPREAD_MODEL_i']-p_spread(df0['MAG_AUTO_i'])
dff=df0[(df0['SPREAD_MODEL_i']>0.005)]
# dff_star=df0[np.abs(df0['SPREAD_MODEL_i'])<0.004] #+5/3.*df0['SPREADERR_MODEL_i'] <0.002
dff_star=df0[(df0['SPREAD_MODEL_i']<0.004)]#&(df0['FLAGS_i']<4)]
fig=plt.figure(figsize=(4,4))
plt.plot(df0['MAG_AUTO_i'],df0['SPREAD_MODEL_i'],'.',c='grey',alpha=0.1)
plt.plot(dff['MAG_AUTO_i'],dff['SPREAD_MODEL_i'],'.',alpha=1,label='galaxies')
plt.plot(dff_star['MAG_AUTO_i'],dff_star['SPREAD_MODEL_i'],'.',alpha=1,label='stars')
plt.ylim(-0.08,0.08)
plt.xlim(-19,-10.5)
plt.axhline(0.005,color='tab:orange')
plt.legend(loc='best')
plt.savefig('/Users/taweewat/Documents/red_sequence/pisco_color_plots/spread_model_real_i_fit_%s_%s.png' %
(mode, field), dpi=120)
plt.close(fig)
dff0=dff
dff0.to_csv("/Users/taweewat/Documents/pisco_code/slr_output/"+\
"galaxy_psf_total_%s.csv"%field)
# dff_star0=pd.merge(dff_star, df0, on='NUMBER') # for non-SPREAD_MODEL
dff_star0=dff_star #for SPREAD_MODEL
dff_star0.to_csv("/Users/taweewat/Documents/pisco_code/slr_output/"+\
"star_psf_total_%s.csv"%field)
def pisco_photometry_psf_v4(field, mode='psf', mode2mass='', slr=True): #mode2mass: '' vs '_no2mass'
def slr_running_psf(field, infile="None", mode="psf", mode2mass='', bigmacs="pisco_pipeline/big-macs-calibrate-master"):
"""
slr_running: running SLR script from github.com/patkel/big-macs-calibrate to get a calibrated magnitude
INPUT:
- field: object of interset e.g., 'Field026'
- bigmacs: the location for "big-macs-calibrate" directoty
OUTPUT:
- a new table with added columns with name MAG_g,...,MAGERR_g,...
"""
slrdir = 'slr_output'
pyfile = os.path.join(bigmacs, 'fit_locus.py')
# cmd = "python %s --file %s --columns %s --extension 1 --bootstrap 15 -l -r ALPHA_J2000_i -d DELTA_J2000_i -j --plot=PLOTS_%s_%s" \
# % (pyfile, infile, os.path.join(bigmacs, "coadd_mag_sex_%s%s.columns"%(mode,'')), mode, field)
if mode2mass=='':
cmd = "python %s --file %s --columns %s --extension 1 --bootstrap 15 -l -r ALPHA_J2000_i -d DELTA_J2000_i -j --plot=PLOTS_%s_%s" \
% (pyfile, infile, os.path.join(bigmacs, "coadd_mag_sex_%s%s.columns"%(mode,mode2mass)), mode, field) #'' vs '_no2mass'
elif mode2mass=='_no2mass':
cmd = "python %s --file %s --columns %s --extension 1 --bootstrap 15 -l -r ALPHA_J2000_i -d DELTA_J2000_i --plot=PLOTS_%s_%s" \
% (pyfile, infile, os.path.join(bigmacs, "coadd_mag_sex_%s%s.columns"%(mode,mode2mass)), mode, field) #'' vs '_no2mass'
print cmd
subprocess.check_call(shlex.split(cmd))
def update_color(fname, table, mode='psf'):
"""
update_color: using the output from SLR, update to the correct magnitude
INPUT:
- fname: input file from SLR output (...offsets.list)
- table: the table that we want to update the value (from column magg,etc to MAG_g,etc)
OUTPUT:
- a new table with added columns with name MAG_g,...,MAGERR_g,...
"""
print fname
with open(fname) as f:
content = f.readlines()
content = [x.strip() for x in content]
# print content
if len(content)==8:
red_content=content[4:]
elif len(content)==10:
red_content=content[5:-1]
# if len(content)==7:
# red_content=content[4:]
# elif len(content)==9:
# red_content=content[5:-1]
band = [x.split(' ')[0][-1] for x in red_content]
corr = [float(x.split(' ')[1]) for x in red_content]
ecorr = [float(x.split(' ')[3]) for x in red_content]
print 'bands = ', band
if mode=='psf':
MODE1='PSF'
elif mode=='model':
MODE1='MODEL'
elif mode=='auto':
MODE1='AUTO'
elif mode=='aper':
MODE1='APER'
elif mode=='hybrid':
MODE1='HYBRID'
elif mode=='iso':
MODE1='ISO'
table['MAG_' + band[0]] = table['MAG_%s_'%MODE1 + band[0]] + corr[0]
table['MAG_' + band[1]] = table['MAG_%s_'%MODE1 + band[1]] + corr[1]
table['MAG_' + band[2]] = table['MAG_%s_'%MODE1 + band[2]] + corr[2]
table['MAG_' + band[3]] = table['MAG_%s_'%MODE1 + band[3]] + corr[3]
table['MAGERR_' + band[0]] = (table['MAGERR_%s_'%MODE1 + band[0]]**2)**0.5# + ecorr[0]**2)**0.5
table['MAGERR_' + band[1]] = (table['MAGERR_%s_'%MODE1 + band[1]]**2)**0.5# + ecorr[1]**2)**0.5
table['MAGERR_' + band[2]] = (table['MAGERR_%s_'%MODE1 + band[2]]**2)**0.5# + ecorr[2]**2)**0.5
table['MAGERR_' + band[3]] = (table['MAGERR_%s_'%MODE1 + band[3]]**2)**0.5# + ecorr[3]**2)**0.5
return table
slrdir = 'slr_output'
df0=pd.read_csv("/Users/taweewat/Documents/pisco_code/slr_output/star_psf_total_%s.csv" % field,index_col=0)
# if field=='SDSS603':
# df0=df0.drop([399,258,357,157,381,310,86,81,31,66,422,232,208,19,10])
# elif field=='SDSS501':
# df0=df0.drop([265,108,196,213,160])
# elif field=='SDSS123':
# df0=df0.drop([68,5,61])
# else:
# df0=df0
total3 = Table.from_pandas(df0)
total3=total3[['NUMBER','ALPHA_J2000_i','DELTA_J2000_i','XWIN_IMAGE_i','YWIN_IMAGE_i',\
'MAG_APER_i','MAGERR_APER_i','MAG_APER_g','MAGERR_APER_g','MAG_APER_r',\
'MAGERR_APER_r','MAG_APER_z','MAGERR_APER_z','MAG_AUTO_i','MAGERR_AUTO_i',\
'MAG_AUTO_g','MAGERR_AUTO_g','MAG_AUTO_r','MAGERR_AUTO_r','MAG_AUTO_z',\
'MAGERR_AUTO_z','MAG_ISO_i','MAGERR_ISO_i','MAG_ISO_g','MAGERR_ISO_g','MAG_ISO_r',\
'MAGERR_ISO_r','MAG_ISO_z','MAGERR_ISO_z',\
'MAG_SPHEROID_i','MAGERR_SPHEROID_i','MAG_SPHEROID_g',\
'MAGERR_SPHEROID_g','MAG_SPHEROID_r','MAGERR_SPHEROID_r','MAG_SPHEROID_z',\
'MAGERR_SPHEROID_z','CLASS_STAR_i','CLASS_STAR_g','CLASS_STAR_r',\
'CLASS_STAR_z','FLAGS_g','FLAGS_r','FLAGS_i','FLAGS_z','MAG_PSF_g',\
'MAG_PSF_r','MAG_PSF_i','MAG_PSF_z','MAGERR_PSF_g','MAGERR_PSF_r',\
'MAGERR_PSF_i','MAGERR_PSF_z','MAG_MODEL_g','MAG_MODEL_r',\
'MAG_MODEL_i','MAG_MODEL_z','MAGERR_MODEL_g','MAGERR_MODEL_r',\
'MAGERR_MODEL_i','MAGERR_MODEL_z','SPREAD_MODEL_g','SPREAD_MODEL_r',\
'SPREAD_MODEL_i','SPREAD_MODEL_z','SPREADERR_MODEL_g','SPREADERR_MODEL_r',\
'SPREADERR_MODEL_i','SPREADERR_MODEL_z']]
print 'number of stars =', len(total3)
if (mode2mass==''):
starpsfmode = '_psf'
elif (mode2mass=='_no2mass'):
starpsfmode ='_no2mass'
# total3.write(slrdir+'/star_psf%s_%s_%i.fits' % ('_psf',field,0), overwrite=True) #with 2MASS stars: star_psf_psf_%s_%i.fits
total3.write(slrdir+'/star_psf%s_%s_%i.fits'%(starpsfmode,field,0),overwrite=True)
# no 2MASS star mode vs , '_psf' vs '_no2mass'
if slr:
slr_running_psf(field, infile=slrdir + '/star_psf%s_%s_%i.fits' %
(starpsfmode, field, 0), mode='psf', mode2mass=mode2mass) # '_psf' vs '_no2mass'
print 'mode=', mode, '/star_psf%s_%s_%i.fits.offsets.list' % (starpsfmode, field, 0)
total_gal=Table.from_pandas(pd.read_csv("/Users/taweewat/Documents/pisco_code/slr_output/galaxy_psf_total_%s.csv"%(field)))
ntotal_gal = update_color(slrdir+'/star_psf%s_%s_%i.fits.offsets.list' %
(starpsfmode, field, 0), total_gal, mode=mode)
ntotal_gal.write(os.path.join(
slrdir, 'galaxy_%s%s_ntotal_%s.csv'%(mode,mode2mass,field)), overwrite=True)
total_star=Table.from_pandas(pd.read_csv("/Users/taweewat/Documents/pisco_code/slr_output/star_psf_total_%s.csv"%(field)))
ntotal_star = update_color(slrdir+'/star_psf%s_%s_%i.fits.offsets.list'%
(starpsfmode, field, 0), total_star, mode=mode)
ntotal_star.write(os.path.join(
slrdir, 'star_%s%s_ntotal_%s.csv'%(mode,mode2mass,field)), overwrite=True)
def make_images(field,ax=None):
dir='/Users/taweewat/Documents/pisco_code/Chips_images/'
try:
ax.imshow(image.imread(dir+"aplpy4_%s_img4.jpeg"%field))
except:
ax.imshow(image.imread(dir+"aplpy4_%s_img.jpeg"%field))
# ax.imshow(image.imread(dir+"aplpy4_%s_img4.jpeg"%field))
ax.axes.get_xaxis().set_visible(False)
ax.axes.get_yaxis().set_visible(False)
ax.axis('off')
return None
# def sur_pro(r): #Mpc
# def fn(x):
# if x>=1:
# return 1.-(2/np.sqrt(x**2-1)*np.arctan(np.sqrt((x-1.)/(x+1.))))
# elif x<1:
# return 1.-(2/np.sqrt(1-x**2)*np.arctanh(np.sqrt((1.-x)/(x+1.))))
# rs=0.15/0.71 #Mpc
# if r>=(0.1/0.71):
# return 1/((r/rs)**2-1)*fn(r/rs)
# elif r<(0.1/0.71):
# return 1./(((0.1/0.71)/rs)**2-1)*fn((0.1/0.71)/rs)
# def k_NFW():
# def integrated(y):
# return 1./integrate.quad(lambda r: 2*np.pi*r*sur_pro(r),0,y)[0]
# xy=np.logspace(-3,3,num=30)
# X = np.log(xy)
# Y = np.log([integrated(np.e**(y)) for y in X])
# Z=np.polyfit(X,Y,6)
# k_NFW = np.poly1d(Z)
# return k_NFW
# def sur_pro_prob(r,rc,k_NFW): #(Mpc,Mpc) # Weighted based on the distance from the center (Rykoff+12)
# return np.e**(k_NFW(np.log(rc)))*sur_pro(r)
name=['z','dist','age','mass','Abs_g','App_g','kcorr_g','Abs_r',\
'App_r','kcorr_r','Abs_i','App_i','kcorr_i','Abs_z','App_z','kcorr_z']
df=pd.read_csv('/Users/taweewat/Documents/red_sequence/rsz/model/'+\
# 'ezmodel2_bc03_zf2.5_chab_0.016_exp_0.1.txt',
'ezmodel2_bc03_zf2.5_chab_0.02_exp_0.1.txt',
# 'ezmodel2_c09_zf3.0_chab_0.02_exp_0.1.txt',
skiprows=27,delim_whitespace=True,names=name)
df=df[(df.z>=0.1) & (df.z<1.)]
z_new=np.arange(0.1, 0.95, 0.0025)
Appi_new = interpolate.splev(z_new, interpolate.splrep(df.z, df.App_i, s=0), der=0)
Appi_f = interpolate.interp1d(df.z, df.App_i, kind='cubic')
#all extra options
extra_name= 'gnorm_zf2.5_bc03_noebv_auto_bin1.0_root15_sur0.25' #'gremove_lum_silk_zf2.5_c09_11', 'gremove_silk_zf3_c09_noebv_model_complete_no2mass'
core_radius=0.25
gremove = False # remove non-detect g objects from the list
duplicate = False # remove duplicate redshift (uncertain)
colorerr = True # add redshift with color_error taken into account
transparent = True # make transparent plot for flip book
img_filp = False # make image flip from transparent
img_redshift = True # make image with redshift for each object
def linear_rmi(x0,redshift):
x=df.z[:-11] #-12
y=(df.App_r-df.App_i)[:-11] #-12
yhat = np.polyfit(x, y, 5) #5 vs 9
f_rmi = np.poly1d(yhat)
slope=-0.0222174237562*1.007
# Appi0=Appi_new[np.where(abs(z_new-redshift)<=1e-9)[0][0]]
Appi0=Appi_f(redshift)
return slope*(x0-Appi0)+f_rmi(redshift)
def linear_gmr(x0,redshift):
x=df.z[:-24] #-25
y=(df.App_g-df.App_r)[:-24] #-25
yhat = np.polyfit(x, y, 5)
f_gmr = np.poly1d(yhat)
slope=-0.0133824600874*1.646
# Appi0=Appi_new[np.where(abs(z_new-redshift)<=1e-9)[0][0]]
Appi0=Appi_f(redshift)
return slope*(x0-Appi0)+f_gmr(redshift)
def linear_gmi(x0,redshift):
x=df.z[:-9]
y=(df.App_g-df.App_i)[:-9]
yhat = np.polyfit(x, y, 5)
f_gmi = np.poly1d(yhat)
Appi0=Appi_f(redshift)
slope = -0.04589707934164738 * 1.481
return slope*(x0-Appi0)+f_gmi(redshift)
def find_fits_dir(field):
home = '/Users/taweewat/Documents/pisco_code/'
dirs = ['ut170103/', 'ut170104/', 'ut170619/', 'ut170621/',\
'ut170624/', 'ut171208/', 'ut171209/', 'ut171212/']
myReg = re.compile(r'(%s_A).*' % field)
for di in dirs:
diri = home + di
for text in os.listdir(diri):
if myReg.search(text) != None:
# filename = myReg.search(text).group()
allfilename = diri
return allfilename
dir_dict = dict(zip(['ut170103/','ut170104/','ut170619/',\
'ut170621/','ut170624/','ut171208/','ut171209/','ut171212/'], np.arange(1, 9)))
def find_ra_dec(field):
if field == 'PKS1353':
RA = 209.0225
DEC = -34.3530556
redshift = 0.223
elif field == 'CHIPS2249-2808': #CHIPS2227-4333
# RA = 336.99975202151825
# DEC = -43.57623068466675
RA = 336.98001
DEC = -43.56472
redshift = -1
elif field == 'CHIPS2246-2854': #'CHIPS2223-3455'
# RA = 335.7855174238757
# DEC = -34.934569299688185
RA = 335.78
DEC = -34.9275
redshift = -1
elif field[0:5] == 'Field':
base = pd.read_csv(
'/Users/taweewat/Dropbox/Documents/MIT/Observation/2017_1/all_objs.csv')
RA = base[base.name == field].ra.values[0]
DEC = base[base.name == field].dec.values[0]
redshift = base[base.name == field].redshift.values[0]
elif field[0:5] == 'CHIPS':
base = pd.read_csv(
'/Users/taweewat/Documents/red_sequence/chips_all_obj.csv', index_col=0)
RA = base[base.chips == field].ra.values[0]
DEC = base[base.chips == field].dec.values[0]
redshift = base[base.chips == field].redshift.values[0]
elif field[0:4] == 'SDSS':
base = pd.read_csv(
'/Users/taweewat/Documents/xray_project/ned-result/final_sdss_cut5.csv', index_col=0)
RA = base[base.name == field].RA.values[0]
DEC = base[base.name == field].DEC.values[0]
redshift = base[base.name == field].redshift.values[0]
return RA, DEC, redshift
def pisco_tilt_resequence(field, mode='psf', mode2mass=''):
RA, DEC, redshift = find_ra_dec(field)
if redshift!=-1:
qso_redshift=redshift
else:
qso_redshift=0.2
print 'RA', RA
print 'DEC', DEC
ebv = ebvpy.calc_ebv(ra=[RA],dec=[DEC]); print 'ebv:', ebv[0]
# ebv_g=ebvpy.calc_color_correction('g', ebv)[0]
# ebv_r=ebvpy.calc_color_correction('r', ebv)[0]
# ebv_i=ebvpy.calc_color_correction('i', ebv)[0]
# ebv_z=0.0
ebv_g,ebv_r,ebv_i,ebv_z=0.0,0.0,0.0,0.0 #no longer use reddening correction because it is already included in SLR
print 'ebv_g:', ebv_g, 'ebv_r:', ebv_r, 'ebv_i:', ebv_i
param_izp=read_param_izp(mode) #i zero point
# fname = "/Users/taweewat/Documents/pisco_code/slr_output/galaxy_ntotal_%s.csv"%field
dir_slrout='/Users/taweewat/Documents/pisco_code/slr_output/'
fname = dir_slrout+"galaxy_%s%s_ntotal_%s.csv" % (
mode, mode2mass, field) # '' vs '_no2mass'
df0 = pd.read_csv(fname,index_col=0)
if gremove:
nog=len(df0[df0['MAG_PSF_g'] >= 50.]); print "no g detected:", nog
df0 = df0[df0['MAG_PSF_g'] < 50.].copy() # cut out not detected objects in g band
else:
nog=0
c5 = SkyCoord(ra=df0['ALPHA_J2000_i'].values*u.degree, dec=df0['DELTA_J2000_i'].values*u.degree)
c0 = SkyCoord(ra=RA*u.degree, dec=DEC*u.degree)
sep = c5.separation(c0)
df0['sep(deg)']=sep
df0['sep(Mpc)']=sep*60.*cosmo.kpc_proper_per_arcmin(qso_redshift).value/1e3
cut=df0
dfi = cut#.drop_duplicates(subset=['XWIN_WORLD', 'YWIN_WORLD'], keep='first').copy()
print 'duplicates:', len(df0), len(dfi)
# Added Galactic Reddening (6/16/18)
if mode2mass == '':
dfi['MAG_i']=dfi['MAG_i']-ebv_i
dfi['MAG_g']=dfi['MAG_g']-ebv_g
dfi['MAG_r']=dfi['MAG_r']-ebv_r
# Use i Zero Point from each day and g,r zero point fron the color (6/22/18)
elif mode2mass == '_no2mass':
mag0 = param_izp['i_zp_day%i'%dir_dict[find_fits_dir(field)[-9:]]]
print 'i_zp_day', find_fits_dir(field), mag0
dfi['MAG_i']=dfi['MAG_i']-ebv_i+mag0
dfi['MAG_g']=dfi['MAG_g']-ebv_g+mag0
dfi['MAG_r']=dfi['MAG_r']-ebv_r+mag0
dfi['MAG_z']=dfi['MAG_z']-ebv_z+mag0
dfi.to_csv(dir_slrout+"galaxy_%s_final_%s.csv"%(mode,field))
fname=dir_slrout+"star_%s%s_ntotal_%s.csv" % (mode, mode2mass, field)
df0=pd.read_csv(fname,index_col=0)
dfi=df0
# Added Galactic Reddening (6/16/18)
if mode2mass == '':
dfi['MAG_i']=dfi['MAG_i']-ebv_i
dfi['MAG_g']=dfi['MAG_g']-ebv_g
dfi['MAG_r']=dfi['MAG_r']-ebv_r
# Use i Zero Point from each day and g,r zero point fron the color (6/22/18)
elif mode2mass == '_no2mass':
mag0 = param_izp['i_zp_day%i'%dir_dict[find_fits_dir(field)[-9:]]]
print 'i_zp_day', find_fits_dir(field), mag0
dfi['MAG_i']=dfi['MAG_i']-ebv_i+mag0
dfi['MAG_g']=dfi['MAG_g']-ebv_g+mag0
dfi['MAG_r']=dfi['MAG_r']-ebv_r+mag0
dfi['MAG_z']=dfi['MAG_z']-ebv_z+mag0
dfi.to_csv(dir_slrout+"star_%s_final_%s.csv"%(mode,field))
return None
# dfi=dfi[dfi['MAG_i']<21.5].copy()
# dfi=dfi[dfi.MAGERR_g<0.5]
# dfi=dfi[(dfi.MAG_g<100)&(dfi.MAG_i<100)&(dfi.MAG_r<100)]
# dfi=dfi[(dfi.FLAGS_g<5)&(dfi.FLAGS_r<5)&(dfi.FLAGS_i<5)&(dfi.FLAGS_z<5)]
def xxx(x):
dfi=dfi[np.sqrt(dfi['MAGERR_r']**2+dfi['MAGERR_i']**2)<0.3].copy() #0.5
x=dfi['MAG_i']
y=np.sqrt(dfi['MAGERR_r']**2+dfi['MAGERR_i']**2)
p=np.poly1d(np.polyfit(x,np.log(y),1, w=np.sqrt(y)))
Mag_cut=(p-np.log(0.067*1.5)).roots;
print "Mag_cut: %.2f"%(Mag_cut)
xs=np.arange(np.min(x),np.max(x),0.01)
fig,ax=plt.subplots(figsize=(5,5))
plt.plot(x,y,'.',label='r-i')
plt.plot(xs,np.exp(p(xs)),label='exp({:.1f}+{:.1f}x)'.format(p[0],p[1]))
plt.xlabel('Mag_i'); plt.ylabel('$\Delta r-i$ err')
plt.ylim(-0.05,0.35)
plt.axvline(Mag_cut,label='Mag_cut')
plt.legend(loc='best')
plt.savefig('/Users/taweewat/Documents/red_sequence/pisco_color_plots/uncer_%s_%s.png' %
(mode, field), dpi=120)
# plt.tight_layout()
plt.close(fig)
#Magnitude cut
print field, qso_redshift, df0.shape, cut.shape, dfi.shape, dfi['sep(deg)'].max(), dfi['sep(Mpc)'].max()
norm = matplotlib.colors.Normalize(vmin=0.10,vmax=0.675)
c_m = matplotlib.cm.cool
s_m = matplotlib.cm.ScalarMappable(cmap=c_m, norm=norm)
s_m.set_array([])
I=np.arange(16,24,0.01)
dfi.loc[:,"z_gmr"] = np.nan
dfi.loc[:,"z_rmi"] = np.nan
dfi.loc[:,"w_gmr"] = np.nan
dfi.loc[:,"w_rmi"] = np.nan
dfi.loc[:,"w_col_gmr"] = np.nan
dfi.loc[:,"w_col_rmi"] = np.nan
# dfi.loc[:,"z_gmi"] = np.nan
# dfi.loc[:,"w_gmi"] = np.nan
# dfi.loc[:,"w_col_gmi"] = np.nan
# k_NFW0=k_NFW()
bin_width=0.035 #0.025
# bins_gmr_cen = np.arange(0.15815-0.0175, 0.33315-0.0175+0.01, bin_width)
# bins_gmr_edge = np.arange(0.14065-0.0175, 0.35065-0.0175+0.01, bin_width)
# bins_gmr_cen = np.arange(0.12315+0.0175, 0.33315+0.0175+0.01, bin_width)
# bins_gmr_edge = np.arange(0.10565+0.0175, 0.35065+0.0175+0.01, bin_width)
# bins_rmi_cen = np.arange(0.36815-0.0175, 0.64815-0.0175+0.01, bin_width)
# bins_rmi_edge = np.arange(0.35065-0.0175, 0.66565-0.0175+0.01, bin_width)
#new one: combine last gmr with "new" rmi
bins_gmr_cen = np.arange(0.12315, 0.33315+0.01, bin_width)
bins_gmr_edge = np.arange(0.10565, 0.35065+0.01, bin_width)
bins_rmi_cen = np.arange(0.36815-bin_width, 0.64815+0.01, bin_width)
bins_rmi_edge = np.arange(0.35065-bin_width, 0.66565+0.01, bin_width)
z_rmi,w_rmi,w_col_rmi=[],[],[]
for i, row in dfi.iterrows():
for z in bins_rmi_cen:
# if row['MAG_i'] < -18+5.*np.log10(ex.d_L(z)*1e6)-5.:
# if row['MAG_i'] < magi_cut_rmi:
# if np.sqrt(row['MAGERR_r']**2+row['MAGERR_i']**2)<0.134: #np.mean(f_rmi(x+0.07)-f_rmi(x))
# if np.sqrt(row['MAGERR_r']**2+row['MAGERR_i']**2)<0.067*1.5: #0.067*1.5
if row['MAG_i'] < Mag_cut:
rmi=row['MAG_r']-row['MAG_i']
# rmierr=np.sqrt(row['MAGERR_r']**2+row['MAGERR_i']**2)
low_edge=linear_rmi(row['MAG_i'],round(z-0.0175,4)) #0.0125
high_edge=linear_rmi(row['MAG_i'],round(z+0.0175,4)) #0.0125
if (rmi > low_edge) & (rmi <= high_edge):
# if (np.sqrt(row['MAGERR_r']**2+row['MAGERR_i']**2) < 3.5*(high_edge-low_edge)):
z_rmi.append(round(z,3))
# wrmi0=sur_pro_prob(row['sep(Mpc)'],1.,k_NFW0)
wrmi0=ex.sur_pro_prob_ang(row['sep(deg)']*60, core_radius); w_rmi.append(wrmi0) #arcmin
# w_col_rmi0=scipy.stats.norm(rmi,rmierr).cdf(high_edge)-scipy.stats.norm(rmi,rmierr).cdf(low_edge); w_col_rmi.append(w_col_rmi0)
w_col_rmi0=1.; w_col_rmi.append(w_col_rmi0)
dfi.loc[i,"z_rmi"]=z
dfi.loc[i,"w_rmi"]=wrmi0
dfi.loc[i,"w_col_rmi"]=w_col_rmi0
z_gmr,w_gmr,w_col_gmr=[],[],[]
for i, row in dfi.iterrows():
for z in bins_gmr_cen:
# if row['MAG_i'] < -18+5.*np.log10(ex.d_L(z)*1e6)-5.:
# if row['MAG_i'] < magi_cut_gmr:
# if np.sqrt(row['MAGERR_g']**2+row['MAGERR_r']**2)<0.165: #np.mean(f_gmr(x+0.07)-f_gmr(x))
# if np.sqrt(row['MAGERR_g']**2+row['MAGERR_r']**2)<0.0825*1.5: #0.0825*1.5
if row['MAG_i'] < Mag_cut:
gmr=row['MAG_g']-row['MAG_r']
# gmrerr=np.sqrt((row['MAGERR_g'])**2+row['MAGERR_r']**2) #add factor 2.2 to reduce the g error to be similar to other bands
low_edge=linear_gmr(row['MAG_i'],round(z-0.0175,4)) #0.0125
high_edge=linear_gmr(row['MAG_i'],round(z+0.0175,4)) #0.0125
if (gmr > low_edge) & (gmr <= high_edge):
# if (np.sqrt(row['MAGERR_g']**2+row['MAGERR_r']**2) < 3.5*(high_edge-low_edge)):
z_gmr.append(round(z,3))
# w_col_gmr0=scipy.stats.norm(gmr,gmrerr).cdf(high_edge)-scipy.stats.norm(gmr,gmrerr).cdf(low_edge); w_col_gmr.append(w_col_gmr0)
w_col_gmr0=1.; w_col_gmr.append(w_col_gmr0)
# wgmr0=sur_pro_prob(row['sep(Mpc)'],1.,k_NFW0); w_gmr.append(wgmr0)
wgmr0 = ex.sur_pro_prob_ang(row['sep(deg)'] * 60, core_radius); w_gmr.append(wgmr0) # arcmin
dfi.loc[i,"z_gmr"]=z
dfi.loc[i,"w_gmr"]=wgmr0
dfi.loc[i,"w_col_gmr"]=w_col_gmr0
ns1,xs1=np.histogram(z_gmr,bins=bins_gmr_edge,weights=np.array(w_gmr)*np.array(w_col_gmr)) #0.15-0.325
bin_cen1 = (xs1[:-1] + xs1[1:])/2
ns2,xs2=np.histogram(z_rmi,bins=bins_rmi_edge,weights=np.array(w_rmi)*np.array(w_col_rmi)) #0.36-0.675
bin_cen2 = (xs2[:-1] + xs2[1:])/2
# z_total=np.append(bin_cen1, bin_cen2)
# n_total=np.append(ns1,ns2)
z_total=np.append(bin_cen1, bin_cen2[1:])
n_total=np.append(np.append(ns1[:-1],np.array(ns1[-1]+ns2[0])),np.array(ns2[1:]))
z_max=z_total[np.where(n_total==np.max(n_total))[0][0]]
n_median = np.median(n_total[n_total != 0])
n_mean = np.mean(n_total)
n_bkg = np.mean(sorted(n_total)[2:-2]);
z_total_added = np.insert(
np.append(z_total, z_total[-1] + bin_width), 0, z_total[0] - bin_width)
n_total_added = np.insert(np.append(n_total, 0), 0, 0) - n_bkg
# print 'n_total_added', n_total_added
lumfn=pd.read_csv('/Users/taweewat/Documents/red_sequence/coma_cluster_luminosity_function/schecter_fn.csv',\
names=['M_r','theta(M)Mpc^-3'])
h=0.7
x=lumfn['M_r']+5*np.log10(h);
y=lumfn['theta(M)Mpc^-3']*(h**3)
f1d=interp1d(x, y,kind='cubic')
def lum_function(M):
alpha = -1.20
Nb = np.log(10) / 2.5 * 0.002 * (70 / 50.)**3
Mb_s = -21. + 5 * np.log10(70 / 50.)
return Nb * (10.**(0.4 * (alpha + 1) * (Mb_s - M))) * np.exp(-10.**(0.4 * (Mb_s - M)))
lum_fn = lambda z: integrate.quad( f1d, -23.455, ex.abs_mag(22.25, z))[0]
lum_vfn = np.vectorize(lum_fn)
dense_fn = lambda z: integrate.quad(ex.NFW_profile,0.001,cosmo.kpc_proper_per_arcmin(z).value/1e3)[0]
dense_vfn = np.vectorize(dense_fn)
n_total_adj=n_total_added #/(lum_vfn(z_total_added)*dense_vfn(z_total_added)) (adjusted the peak before picking it)
print 'n_total_added:', n_total_added
print 'n_total_adj:', n_total_adj
indi = np.where(n_total_adj == np.max(n_total_adj))[0][0]
# indi = np.where(n_total_added == np.max(n_total_added))[0][0]
z_fit = z_total_added[[indi - 1, indi, indi + 1]]; print 'z_fit', z_fit
n_fit = n_total_added[[indi - 1, indi, indi + 1]]; print 'n_fit', n_fit
def gaussian_func(x, a, mu):
sigma=0.035
return a * np.exp(-(x-mu)**2/(2*(sigma**2)))
if (n_fit[0]<0.) and (n_fit[2]<0.):
popt, pcov = curve_fit(gaussian_func, z_fit, [0,n_fit[1],0], p0=[n_fit[1],z_fit[1]])
else:
popt, pcov = curve_fit(gaussian_func, z_fit,
n_fit, p0=[n_fit[1], z_fit[1]])
# signal=tuple(popt)[0]
# def v_func(z):
# return (z**2+2*z)/(z**2+2*z+2)
# signal=((np.max(n_total)-np.mean(n_total))*(v_func(z_max)*(4000))**2)/5.3e6 #normalization for r~1 at z~0.15
# signal = (
# (tuple(popt)[0]) * (cosmo.luminosity_distance(tuple(popt)[1]).value)**1.5) / 5.3e5 # normalization for r~1 at z~0.15
def lum_function(M):
alpha = -1.20
Nb = np.log(10) / 2.5 * 0.002 * (70 / 50.)**3
Mb_s = -21. + 5 * np.log10(70 / 50.)
return Nb * (10.**(0.4 * (alpha + 1) * (Mb_s - M))) * np.exp(-10.**(0.4 * (Mb_s - M)))
lumfn=pd.read_csv('/Users/taweewat/Documents/red_sequence/coma_cluster_luminosity_function/schecter_fn.csv',\
names=['M_r','theta(M)Mpc^-3'])
h=0.7
x=lumfn['M_r']+5*np.log10(h);
y=lumfn['theta(M)Mpc^-3']*(h**3)
f1d=interp1d(x, y,kind='cubic')
z_max_fit = tuple(popt)[1]
# lum_factor = integrate.quad(lum_function, -24, abs_mag(21.60, tuple(popt)[1]))[0]
# lum_factor = cosmo.luminosity_distance(tuple(popt)[1]).value**-1.5*100
lum_factor = integrate.quad( f1d, -23.455, ex.abs_mag(22.25, z_max_fit))[0]
#-23.455: min abs Mag from schecter_fn.csv, 22.25: median of Mag r
density_factor=integrate.quad(ex.NFW_profile, 0.001, core_radius*cosmo.kpc_proper_per_arcmin(z_max_fit).value/1e3)[0]
signal = tuple(popt)[0] / (lum_factor * density_factor)
print 'z_max_fit', z_max_fit
print 'lum_factor:', lum_factor
print 'density_factor', density_factor
# duplicate=False ## set duplication
n_total_dup=0
## Plot the figure
cmap=matplotlib.cm.RdYlGn
if duplicate or colorerr:
fig,ax=plt.subplots(1,5,figsize=(25,5))
else:
fig,ax=plt.subplots(1,4,figsize=(20,5))
make_images(field,ax[0])
norm = matplotlib.colors.Normalize(vmin=0.01,vmax=2)
dfi_ri=dfi.loc[dfi['z_rmi'].dropna().index]
ax[1].scatter(dfi['MAG_i'],dfi['MAG_r']-dfi['MAG_i'],c='black',alpha=0.1)#dfi['w_rmi'],cmap=cmap)
ax[1].scatter(dfi_ri['MAG_i'],dfi_ri['MAG_r']-dfi_ri['MAG_i'],c=dfi_ri['w_rmi'],cmap=cmap)#,norm=norm)
ax[1].errorbar(dfi_ri['MAG_i'],dfi_ri['MAG_r']-dfi_ri['MAG_i'],xerr=dfi_ri['MAGERR_i'],yerr=np.sqrt(dfi_ri['MAGERR_r']**2+dfi_ri['MAGERR_i']**2),fmt='none',c='k',alpha=0.05)
# plt.plot(df.App_i,df.App_r-df.App_i,'.')
# ax[1].axhline(xs[:-1][(xs[:-1]<1.33) & (xs[:-1]>0.6)][0],lw=0.7,color='green')
for z in bins_rmi_cen:
ax[1].plot(I,linear_rmi(I,round(z,4)),color=s_m.to_rgba(z))
ax[1].set_ylim(0.25,1.5)
ax[1].set_xlim(16,24)
# cbar=plt.colorbar(s_m)
ax[1].set_xlabel('I')
ax[1].set_ylabel('R-I')
ax[1].set_title('z=0.35-0.675')#, icut:'+str(magi_cut_rmi))
# plt.plot([corr_f(z) for z in df.z.values[5:-12]],df.App_r[5:-12]-df.App_i[5:-12],'-')
dfi_gr=dfi.loc[dfi['z_gmr'].dropna().index]
ax[2].scatter(dfi['MAG_i'],dfi['MAG_g']-dfi['MAG_r'],c='black',alpha=0.1)#,c=dfi['w_gmr'],cmap=cmap)
ax[2].scatter(dfi_gr['MAG_i'],dfi_gr['MAG_g']-dfi_gr['MAG_r'],c=dfi_gr['w_gmr'],cmap=cmap)#,norm=norm)
ax[2].errorbar(dfi_gr['MAG_i'],dfi_gr['MAG_g']-dfi_gr['MAG_r'],xerr=dfi_gr['MAGERR_i'],yerr=np.sqrt(dfi_gr['MAGERR_g']**2+dfi_gr['MAGERR_r']**2),fmt='none',c='k',alpha=0.05)
# plt.plot(df.App_i,df.App_g-df.App_r,'.')
# ax[2].axhline(xs[:-1][(xs[:-1]<1.65) & (xs[:-1]>np.min(x2))][0],lw=0.7,color='green')
for z in bins_gmr_cen:
ax[2].plot(I,linear_gmr(I,round(z,4)),color=s_m.to_rgba(z))
ax[2].set_ylim(0.75,2)
ax[2].set_xlim(16,24)
# cbar=plt.colorbar(s_m)
ax[2].set_xlabel('I')
ax[2].set_ylabel('G-R')
ax[2].set_title('z=0.15-0.325')
# plt.plot([corr_f(z) for z in df.z.values[:-25]],df.App_g[:-25]-df.App_r[:-25],'-')
xs=np.arange(np.min(z_fit)-0.1,np.max(z_fit)+0.1,0.001)
ax[3].bar(bin_cen2, ns2, width=bin_width, color='#1f77b4', alpha=1.0)
ax[3].bar(bin_cen1, ns1, width=bin_width, color='#ff7f0e', alpha=1.0)
ax[3].bar(z_total, n_total, width=bin_width, color='grey', alpha=0.5)
ax[3].axvline(0.3525,ls='--')
ax[3].axvline(z_max,ls='--',color='purple',label='z_max:%.2f'%z_max)
ax[3].axvline(redshift,color='red',label='z:%.2f'%redshift)
ax[3].plot(z_fit,n_fit+n_bkg,'o',c='tab:purple')
ax[3].plot(xs, gaussian_func(xs, *popt)+n_bkg, c='tab:green', ls='--', label='fit: a=%.2f, mu=%.4f'% tuple(popt))
ax[3].axhline(n_median,color='tab:green',label='median:%.2f'%n_median)
ax[3].axhline(n_mean,color='tab:red',label='mean:%.2f'%n_mean)
ax[3].legend(loc='best')
ax[3].set_xlabel('z')
ax[3].set_xlim(0.1,0.7)
ax[3].set_title('ebv:%.3f,ebv_g-r:-%.3f,ebv_r-i:-%.3f'%(ebv[0],ebv_g-ebv_r,ebv_r-ebv_i))
if np.max(n_total)<30:
ax[3].set_ylim(0,30)
if duplicate:
xs = np.arange(np.min(z_fit_dup) - 0.1, np.max(z_fit_dup) + 0.1, 0.001)
ax[4].bar(bin_cen2, ns2-ns_dup2, width=bin_width, color='#1f77b4') #widht = 0.025
ax[4].bar(bin_cen1, ns1-ns_dup1, width=bin_width, color='#ff7f0e') #width = 0.025
ax[4].axvline(z_max,ls='--',color='purple',label='z_max:%.2f'%z_max)
ax[4].axvline(redshift,color='red',label='z:%.2f'%redshift)
ax[4].plot(z_fit_dup,n_fit_dup+n_bkg_dup,'o',c='tab:purple')
ax[4].plot(xs, gaussian_func(xs, *popt_dup)+n_bkg_dup, c='tab:green', ls='--', label='fit: a=%.2f, mu=%.4f'% tuple(popt))
ax[4].legend(loc='best')
ax[4].set_xlabel('z')
ax[4].set_xlim(0.1,0.7)
if np.max(n_total)<30:
ax[4].set_ylim(0,30)
if colorerr:
dfi_rmi = dfi[~np.isnan(dfi['z_rmi'])]
dfi_gmr = dfi[~np.isnan(dfi['z_gmr'])]
zs_gmr = np.arange(0.11, 0.3425, 0.002)
zs_rmi = np.arange(0.3425, 0.65, 0.002)
ntot_rmi = np.repeat(0, len(zs_rmi))
ntot_gmr = np.repeat(0, len(zs_gmr))
for i, row in dfi_rmi.iterrows():
# for i, row in dfi.iterrows():
i0 = row['MAG_i']
rmi = row['MAG_r'] - row['MAG_i']
rmierr = np.sqrt((row['MAGERR_r'])**2 + row['MAGERR_i']**2)
ntot_rmi0 = scipy.stats.norm(rmi, rmierr).pdf(
linear_rmi(i0, zs_rmi))
ntot_rmi = ntot_rmi + ntot_rmi0 * row['w_rmi']
ax[4].plot(zs_rmi,ntot_rmi0*row['w_rmi'],'-',color='tab:red',alpha=0.2)
for i, row in dfi_gmr.iterrows():
# for i, row in dfi.iterrows():
i0 = row['MAG_i']
gmr = row['MAG_g'] - row['MAG_r']
gmrerr = np.sqrt((row['MAGERR_g'])**2 + row['MAGERR_r']**2)
ntot_gmr0 = scipy.stats.norm(gmr, gmrerr).pdf(
linear_gmr(i0, zs_gmr))
ntot_gmr = ntot_gmr + ntot_gmr0 * row['w_gmr']
ax[4].plot(zs_gmr,ntot_gmr0*row['w_gmr'],'-',color='tab:cyan',alpha=0.2)
ax[4].plot(zs_gmr, ntot_gmr, '.')
ax[4].plot(zs_rmi, ntot_rmi, '.')
ax[4].axvline(z_max,ls='--',color='purple',label='z_max:%.2f'%z_max)
ax[4].axvline(redshift,color='red',label='z:%.2f'%redshift)
ax[4].legend(loc='best')
ax[4].set_xlabel('z')
ax[4].set_xlim(0.1, 0.7)
if np.max(np.append(ntot_gmr,ntot_rmi)) < 200:
ax[4].set_ylim(0, 200)
n_total_cerr=np.append(ntot_gmr,ntot_rmi)
else:
n_total_cerr=0
signal_final = signal_dup if duplicate else signal
plt.tight_layout(rect=[0, 0., 1, 0.98])
purge('/Users/taweewat/Documents/red_sequence/pisco_color_plots/',
'redsq_richg%s_%s_all_.*_%s_tilted.png' % ('', mode, field))
plt.savefig('/Users/taweewat/Documents/red_sequence/pisco_color_plots/redsq_richg%s_%s_all_%.3f_%s_tilted.png' % ('',mode,signal_final,field), dpi=120)
plt.close(fig)
# fig,ax=plt.subplots(1,4,figsize=(20,5))
# make_images(field,ax[0])
# dfi_gmi=dfi[~np.isnan(dfi['z_gmi'])]
# zs_gmi=np.arange(0.115,0.69,0.002)
# ntot_gmi=np.repeat(0,len(zs_gmi))
# for i, row in dfi_gmi.iterrows():
# i0 = row['MAG_i']
# gmi = row['MAG_g'] - row['MAG_i']
# gmierr = np.sqrt((row['MAGERR_g'])**2 + row['MAGERR_i']**2)
# ntot_gmi0 = scipy.stats.norm(gmi, gmierr).pdf(
# linear_gmi(i0, zs_gmi))
# ntot_gmi = ntot_gmi + ntot_gmi0 * row['w_gmi']
# ax[3].plot(zs_gmi,ntot_gmi0*row['w_gmi'],'-',color='tab:cyan',alpha=0.2)
# ax[1].scatter(dfi['MAG_i'],dfi['MAG_g']-dfi['MAG_i'],c='black',alpha=0.1)#dfi['w_rmi'],cmap=cmap)
# ax[1].scatter(dfi_gmi['MAG_i'],dfi_gmi['MAG_g']-dfi_gmi['MAG_i'],c=dfi_gmi['w_gmi'],cmap=cmap)
# ax[1].errorbar(dfi_gmi['MAG_i'], dfi_gmi['MAG_g'] - dfi_gmi['MAG_i'], xerr=dfi_gmi['MAGERR_i'],
# yerr=np.sqrt(dfi_gmi['MAGERR_g']**2 + dfi_gmi['MAGERR_i']**2), fmt='none', c='k', alpha=0.05)
# for z in np.arange(0.15, 0.71, bin_width):
# ax[1].plot(I,linear_gmi(I,z),color=s_m.to_rgba(z))
# ax[1].set_ylim(1.0,3.5)
# ax[1].set_xlim(16,24)
# ax[1].set_xlabel('I')
# ax[1].set_ylabel('G-I')
# ax[1].set_title('z=0.15-0.675')
# ns3,xs3=np.histogram(z_gmi,bins=np.arange(0.1325,0.7,0.035),weights=np.array(w_gmi)*np.array(w_col_gmi))
# bin_cen3 = (xs3[:-1] + xs3[1:])/2
# z_max_gmi = bin_cen3[np.where(ns3 == np.max(ns3))[0][0]]
# n_bkg = np.mean(sorted(ns3)[2:-2]);
# z_total_added = np.insert(
# np.append(bin_cen3, bin_cen3[-1] + bin_width), 0, bin_cen3[0] - bin_width)
# n_total_added = np.insert(np.append(ns3, 0), 0, 0) - n_bkg
# indi = np.where(n_total_added == np.max(n_total_added))[0][0]
# z_fit = z_total_added[[indi - 1, indi, indi + 1]]; print 'z_fit', z_fit
# n_fit = n_total_added[[indi - 1, indi, indi + 1]]; print 'n_fit', n_fit
# if (n_fit[0]<0.) and (n_fit[2]<0.):
# popt_gmi, pcov_gmi = curve_fit(gaussian_func, z_fit, [0,n_fit[1],0], p0=[n_fit[1],z_fit[1]])
# else:
# popt_gmi, pcov_gmi = curve_fit(gaussian_func, z_fit,
# n_fit, p0=[n_fit[1], z_fit[1]])
# lum_factor2 = integrate.quad( f1d, -23.455, abs_mag(22.25, tuple(popt_gmi)[1]))[0]
# density_factor2=integrate.quad(NFW_profile,0.001,cosmo.kpc_proper_per_arcmin(tuple(popt_gmi)[1]).value/1e3)[0]
# signal_gmi = tuple(popt_gmi)[0] / (lum_factor2 * density_factor2)
# z_max_fit_gmi = tuple(popt_gmi)[1]
# ax[2].bar(bin_cen3, ns3, width = 0.035, color='#1f77b4')#, alpha=0.5)
# ax[2].axvline(z_max_gmi, ls='--', color='purple',
# label='z_max=%.3f'%z_max_gmi)
# ax[2].axvline(z_max_fit_gmi, ls='--', color='tab:green',
# label='z_max_fit=%.3f'%z_max_fit_gmi)
# ax[2].axvline(redshift,color='red',label='z:%.3f'%redshift)
# ax[2].plot(z_fit,n_fit+n_bkg,'o',c='tab:purple')
# xs=np.arange(np.min(z_fit)-0.1,np.max(z_fit)+0.1,0.001)
# ax[2].plot(xs, gaussian_func(xs, *popt_gmi) + n_bkg, c='tab:green',
# ls='--', label='fit: a=%.2f, mu=%.4f' % tuple(popt_gmi))
# ax[2].legend(loc='best')
# ax[2].set_xlabel('z')
# ax[2].set_xlim(0.1,0.7)
# if np.max(n_total)<30:
# ax[2].set_ylim(0,30)
# ax[3].plot(zs_gmi,ntot_gmi,'.')
# ax[3].set_xlabel('z')
# ax[3].set_xlim(0.1,0.7)
# ax[3].axvline(z_max_fit_gmi,ls='--',color='purple',label='z_max_fit:%.2f'%z_max_fit_gmi)
# ax[3].axvline(redshift,color='red',label='z:%.2f'%redshift)
# if np.max(ntot_gmi)<70:
# ax[3].set_ylim(0,70)
# ntot_gmi_max=np.max(ntot_gmi)
# zs_gmi_max=zs_gmi[np.argmax(ntot_gmi)]
# ax[3].axvline(zs_gmi_max,ls='--',color='pink',label='zs_gmi_max:%.2f'%zs_gmi_max)
# plt.tight_layout(rect=[0, 0., 1, 0.98])
# plt.savefig('/Users/taweewat/Documents/red_sequence/pisco_color_plots/redsq_gmi_%s_all_%.3f_%s_tilted.png' %
# (mode, signal_gmi, field), dpi=120)
# plt.close(fig)
# transparent=False
if transparent:
fig,ax=plt.subplots(figsize=(7,4))
ax.bar(bin_cen2, ns2, width=0.035, color='#1f77b4') #widht = 0.025
ax.bar(bin_cen1, ns1, width = 0.035, color='#ff7f0e') #width = 0.025
ax.axvline(z_max,ls='--',color='purple',label='z_max:%.2f'%z_max)
ax.set_xlabel('z')
ax.set_xlim(0.1,0.7)
if np.max(n_total)<30:
ax.set_ylim(0,30)
for axp in ax.spines:
ax.spines[axp].set_color('white')
ax.xaxis.label.set_color('white')
ax.yaxis.label.set_color('white')
ax.tick_params(axis='x', colors='white')
ax.tick_params(axis='y', colors='white')
purge('/Users/taweewat/Documents/red_sequence/pisco_color_plots/',
'redsq_transparent_%.3f_%s_tilted.png' % (signal_final,field))
plt.savefig('/Users/taweewat/Documents/red_sequence/pisco_color_plots/redsq_transparent_%.3f_%s_tilted.png' % (signal_final,field), dpi=120, transparent=True)
plt.close(fig)
# red_dir='/Users/taweewat/Documents/red_sequence/'
# rich_filename = 'all_richness_%s.csv'%extra_name
# if not os.path.isfile(red_dir + rich_filename):
# os.system("cp %s %s"%(red_dir+'all_richness_gremove_lum_silk_zf2.5.csv',red_dir+rich_filename))
# df_richness=pd.read_csv(red_dir+rich_filename)
# df_richness[['Nmax','Nbkg_mean','Nbkg_median','zmax','amp','zmax_fit','gremove','lum_factor','density_factor']]=np.nan
# df_richness.to_csv(red_dir+rich_filename)
# df_richness=pd.read_csv(red_dir+rich_filename)
# df_richness=df_richness.copy()
# df_richness.loc[df_richness['name'] == field, 'Nmax'] = np.max(n_total)
# df_richness.loc[df_richness['name'] == field, 'Nbkg_mean'] = np.mean(n_total)
# df_richness.loc[df_richness['name'] == field, 'Nbkg_median'] = np.median(n_total)
# df_richness.loc[df_richness['name'] == field, 'zmax'] = z_max
# df_richness.loc[df_richness['name'] == field, 'amp'] = signal_final
# df_richness.loc[df_richness['name'] == field, 'zmax_fit'] = z_max_fit
# df_richness.loc[df_richness['name'] == field, 'gremove'] = nog
# df_richness.loc[df_richness['name'] == field, 'lum_factor'] = lum_factor
# df_richness.loc[df_richness['name'] == field, 'density_factor'] = density_factor
# df_richness.to_csv(red_dir+rich_filename,index=0)
red_dir='/Users/taweewat/Documents/red_sequence/'
rich_filename = 'all_richness_%s.csv'%extra_name
if not os.path.isfile(red_dir + rich_filename):
df_richness=pd.DataFrame(columns=['name','Nmax','Nbkg_mean','Nbkg_median','zmax','amp','zmax_fit','gremove','lum_factor','density_factor'])
df_richness.to_csv(red_dir+rich_filename)
df_richness=pd.read_csv(red_dir+rich_filename,index_col=0)
dic={'name':field, 'Nmax':np.max(n_total), 'Nbkg_mean':np.mean(n_total), 'Nbkg_median':np.median(n_total), 'zmax':z_max,\
'amp':signal_final, 'zmax_fit':z_max_fit, 'gremove':nog, 'lum_factor':lum_factor, 'density_factor':density_factor}
if field in df_richness['name'].values:
df_richness=df_richness[df_richness['name']!=field]
df_richness=df_richness.append(pd.Series(dic),ignore_index=True).copy()
df_richness.to_csv(red_dir+rich_filename)
# get member redshfit in the figure
if img_redshift:
image_redshift(field,signal,tuple(popt)[1],mode)
# get total images with red-sequence
if img_filp:
image_flip(field,signal,tuple(popt)[1],mode)
if colorerr:
return z_total, n_total, n_total_cerr
else:
return z_total, n_total, n_total_dup
def pisco_combine_imgs(fields, mode='psf', mode2mass=''):
dir1='/Users/taweewat/Documents/red_sequence/pisco_color_plots/psf_est/'
dir2='/Users/taweewat/Documents/red_sequence/pisco_color_plots/'
dir3='/Users/taweewat/Documents/red_sequence/pisco_color_plots/'
dirout='/Users/taweewat/Documents/red_sequence/pisco_all/'
myReg = re.compile(r'(redsq_richg_%s_all_.*%s.*png)' % (mode, field))
myReg2=re.compile(r'(\d{1,3}\.\d{1,3})')
names=[]
for text in os.listdir(dir3):
if myReg.search(text) != None:
names.append(myReg.search(text).group())
if names==[]:
print 'no files', field
signal=myReg2.search(names[0]).group()
img1=dir1+'psf_est3_'+field+'_i.png'
img15='/Users/taweewat/Documents/red_sequence/pisco_color_plots/uncer_%s_%s.png'%(mode,field)
# img2=dir2+'star_galaxy_sep_12_all'+field+'.png'
img2='/Users/taweewat/Documents/red_sequence/pisco_image_redshift/img_redshift_%s_%.3f_%s.png' %(mode,float(signal),field)
print img2
img3=dir3+names[0]
images_list=[img1, img2, img3, img15]
imgs=[]
try:
imgs = [ Image_PIL.open(i) for i in images_list ]
except:
print 'no image file', field
mw = imgs[2].width/2
h = imgs[0].height+imgs[1].height/1+imgs[2].height/2
result = Image_PIL.new("RGBA", (mw, h))
y,index=0,0
for i in imgs:
if index<3:
if (index==2):# or (index==1):
i=i.resize((i.width/2,i.height/2))
result.paste(i, (0, y))
y += i.size[1]
index+=1
elif index==3:
i=i.resize((i.width/2,i.height/2))
result.paste(i, (imgs[0].width,0))
result.save(dirout + 'all_combine_%s_%s_%s_%s_%s.png' %
(extra_name, mode2mass, myReg2.search(names[0]).group(), mode, field))
def purge(dir, pattern):
for f in os.listdir(dir):
if re.search(pattern, f):
print 'remove', f
os.remove(os.path.join(dir, f))
def image_redshift(field,signal,redshift,mode):
df_total=pd.read_csv('/Users/taweewat/Documents/pisco_code/slr_output/galaxy_%s_final_%s.csv'%(mode,field),index_col=0)
df_star=pd.read_csv('/Users/taweewat/Documents/pisco_code/slr_output/star_psf_total_%s.csv'%field,index_col=0)
# df_star=df_star[df_star['SG']>0.95]
hdu=fits.open('/Users/taweewat/Documents/pisco_code/final/coadd_c%s_i.fits'%field)
img=hdu[0].data.astype(float)
img -= np.median(img)
df_total['redshift_m']=df_total.apply(lambda row: ex.redshift_f(row), axis=1)
def size_f(row):
if not np.isnan(row['w_gmr']):
size=row['w_gmr']
if not np.isnan(row['w_rmi']):
size=row['w_rmi']
if np.isnan(row['w_rmi']) and np.isnan(row['w_gmr']):
size=0
return size
df_total['size_m']=df_total.apply(lambda row: size_f(row), axis=1)
df_total=df_total[df_total['redshift_m'] > 0].copy()
norm = matplotlib.colors.Normalize(vmin=0,vmax=500)
c_m = matplotlib.cm.Greys_r
s_m = matplotlib.cm.ScalarMappable(cmap=c_m, norm=norm)
s_m.set_array([])
normalize = matplotlib.colors.Normalize(vmin=0.1, vmax=0.7)
fig, (a0, a1) = plt.subplots(1,2, figsize=(30,18), gridspec_kw = {'width_ratios':[0.8, 1]})
# a0.imshow(img, cmap=c_m, norm=norm, origin='lower')
# a0.scatter(df_star['XWIN_IMAGE_i'].values,df_star['YWIN_IMAGE_i'].values,s=100, marker='*', facecolors='none', edgecolors='yellow', label='star')
# df1i=df_total[df_total['w_rmi']>0.1]
# df2i=df_total[df_total['w_rmi']<=0.1]
# # a0.scatter(df1i['XWIN_IMAGE_i'].values,df1i['YWIN_IMAGE_i'].values,s=100, facecolors='none', edgecolors='blue')
# a0.scatter(df1i['XWIN_IMAGE_i'].values, df1i['YWIN_IMAGE_i'].values, s=100, c=df1i['size_m'].values, cmap='RdYlGn')
# a0.scatter(df2i['XWIN_IMAGE_i'].values,df2i['YWIN_IMAGE_i'].values, s=100, facecolors='none', edgecolors='white')
# a0.set_xlim(0,1600)
# a0.set_ylim(0, 2250)
try:
img2 = mpimg.imread('/Users/taweewat/Documents/pisco_code/Chips_images/aplpy4_%s_img4.jpeg' % field)
except:
img2 = mpimg.imread('/Users/taweewat/Documents/pisco_code/Chips_images/aplpy4_%s_img.jpeg' % field)
imgplot = a0.imshow(img2)
a0.axis('off')
a0.annotate('Redshift: %.3f\nRichness: %.2f' %
(redshift, signal), xy=(150, 100), color='white')
a1.imshow(img, cmap=c_m, norm=norm, origin='lower')
a1.scatter(df_star['XWIN_IMAGE_i'].values,df_star['YWIN_IMAGE_i'].values, s=300,edgecolor='orange', facecolor='none',lw=3)
#,s=100, marker='*', facecolors='none', edgecolors='yellow', label='star')
axi = a1.scatter(df_total['XWIN_IMAGE_i'].values, df_total['YWIN_IMAGE_i'].values,
s=(df_total['size_m'].values * 200)+30, c=df_total['redshift_m'].values, cmap='tab20b', norm=normalize)
plt.colorbar(axi) # df_total['size_m'].values*300
a1.set_xlim(0, 1600)
a1.set_ylim(0, 2250)
plt.tight_layout()
left, bottom, width, height = [0.05, 0.24, 0.3, 0.2]
ax2 = fig.add_axes([left, bottom, width, height])
ax2.imshow(mpimg.imread(
'/Users/taweewat/Documents/red_sequence/pisco_color_plots/redsq_transparent_%.3f_%s_tilted.png' % (signal, field)))
ax2.axes.get_xaxis().set_visible(False)
ax2.axes.get_yaxis().set_visible(False)
ax2.axis('off')
plt.savefig('/Users/taweewat/Documents/red_sequence/pisco_image_redshift/img_redshift_%s_%.3f_%s.png' %
(mode,signal,field), dpi=50)
plt.close(fig)
def image_flip(field, signal, redshift, mode):
img = mpimg.imread(
'/Users/taweewat/Documents/pisco_code/Chips_images/aplpy4_%s_img.jpeg' % field)
fig, ax = plt.subplots(figsize=(7, 7))
imgplot = ax.imshow(img)
ax.axis('off')
ax.annotate('Redshift: %.3f\nRichness: %.2f' %
(redshift, signal), xy=(150, 100), color='white')
left, bottom, width, height = [0.2, 0.18, 0.3, 0.2]
ax2 = fig.add_axes([left, bottom, width, height])
ax2.imshow(mpimg.imread(
'/Users/taweewat/Documents/red_sequence/pisco_color_plots/redsq_transparent_%.3f_%s_tilted.png' % (signal, field)))
ax2.axes.get_xaxis().set_visible(False)
ax2.axes.get_yaxis().set_visible(False)
ax2.axis('off')
# plt.tight_layout()
plt.savefig('/Users/taweewat/Documents/red_sequence/pisco_image_redshift/image_flip_%s_%.3f_%s.png' %
(mode, signal, field), dpi=200)
plt.close(fig)
if __name__ == "__main__":
"""
execute:
python pisco_pipeline/pisco_photometry_all.py CHIPS111 psf slr
#updated version with no2mass option for no more comparison with known 2mass stars
python pisco_pipeline/pisco_photometry_all.py CHIPS111 psf allslr no2mass
"""
print 'Number of arguments:', len(sys.argv), 'arguments.'
print 'Argument List:', str(sys.argv)
field = str(sys.argv[1])
mode = str(sys.argv[2]) #aper, psf, auto, hybrid
all_argv=sys.argv[3:] #allslr, slr, noslr
if (all_argv[0]=='allslr') | (all_argv[0]=='slr'):
slr=str(all_argv[0])
slr_param=True
elif all_argv[0]=='noslr':
slr='no_slr'
slr_param=False
if all_argv[1]=='2mass':
mode2mass=''
elif all_argv[1]=='no2mass':
mode2mass='_no2mass'
home='/Users/taweewat/Documents/pisco_code/' #09, 171208
# dirs=['ut170103/','ut170104/','ut170619/','ut170621/','ut170624/','ut171208/','ut171209/','ut171212/']
dirs=['ut190412','ut190413']
# 'ut171208/', 'ut171209/','ut171212/', 'ut170621/', 'ut170624/'
# dirs = ['ut170621/','ut170624/']
# dirs = ['ut170619/']
# dirs = ['ut170103/']
names=[]
myReg=re.compile(r'(CHIPS\d{4}[+-]\d{4})|(Field\d{3})')
for di in dirs:
dir=home+di
for text in os.listdir(dir):
if myReg.search(text) != None:
names.append(myReg.search(text).group())
all_fields=list(set(names))
# print all_fields
infile = open('/Users/taweewat/Documents/xray_project/code_github/allremove_chips.txt', 'r')
exception = [i.strip() for i in infile.readlines()]
all_fields_cut = all_fields[:]
all_fields_cut = ['SDSS603','SDSS501','SDSS123']
print all_fields_cut
# all_fields_cut = ['CHIPS1422-2728']
notgoflag=True
z_total_all,n_total_all,n_total_dup_all=[],[],[]
for index, field in enumerate(all_fields_cut):
print field, '%i/%i' % (index, len(all_fields_cut))
# if field == 'CHIPS0122-2646':
# notgoflag = False; continue
# if notgoflag:
# continue
if field in exception:
continue
if field in ['CHIPS1933-1511']:
continue
if slr=='allslr':
print 'allslr'
pisco_photometry_v4(field)
elif slr=='slr':
# star_galaxy_bleem(field)
pisco_cut_frame(field)
pisco_photometry_psf_v4(field, mode=mode, mode2mass=mode2mass, slr=slr_param)
purge('/Users/taweewat/Documents/red_sequence/pisco_color_plots/'\
,r'(redsq_%s_all_.*%s.*png)'%(mode,field))
# pisco_tilt_resequence(field, mode='psf', mode2mass='')
z_total=pisco_tilt_resequence(field, mode=mode, mode2mass=mode2mass)
# z_total_all.append(z_total)
# n_total_all.append(n_total)
# n_total_dup_all.append(n_total_dup)
# pisco_combine_imgs(field, mode=mode, mode2mass=mode2mass)
# pickle.dump( [z_total_all,n_total_all,n_total_dup_all], open( "pickle_all_richness_%s.pickle"%extra_name, "wb" ) )
# print 'save pickle fie at', "pickle_all_richness_%s.pickle" % extra_name
elif slr == 'no_slr':
pisco_cut_frame(field)
pisco_photometry_psf_v4(field, mode=mode, mode2mass=mode2mass, slr=slr_param)
purge('/Users/taweewat/Documents/red_sequence/pisco_color_plots/'\
,r'(redsq_%s_all_.*%s.*png)'%(mode,field))
z_total=pisco_tilt_resequence(field, mode=mode, mode2mass=mode2mass)
# z_total_all.append(z_total)
# n_total_all.append(n_total)
# n_total_dup_all.append(n_total_dup)
# pisco_combine_imgs(field, mode=mode, mode2mass=mode2mass)
# pickle.dump( [z_total_all,n_total_all,n_total_dup_all], open( "pickle_all_richness_%s.pickle"%extra_name, "wb" ) )
# print 'save pickle fie at', "pickle_all_richness_%s.pickle" % extra_name
purge('final', "proj_coadd_c%s_.*\.fits" % field)
purge('.', "proto_psf_%s_.*\.fits" % field)
purge('.', "samp_psf_%s_.*\.fits" % field)
purge('.', "resi_psf_%s_.*\.fits" % field)
purge('.', "snap_psf_%s_.*\.fits" % field)
purge('.', "chi_psf_%s_.*\.fits" % field)
# purge('psfex_output', "psf_%s_.*\.fits" % field)
# purge('slr_output', "a_psf_%s_.*\.fits" % field)
purge('final', "coadd_c%s_sq_.*\.fits" % field)
|
mit
|
[
646,
984,
12,
747,
12,
295,
12,
8864,
12,
3873,
12,
16701,
12,
481,
5930,
63,
2537,
199,
646,
10634,
465,
6454,
199,
646,
2680,
465,
980,
199,
199,
646,
5927,
199,
199,
646,
8027,
199,
646,
8027,
14,
13563,
465,
4488,
199,
504,
8027,
492,
1834,
199,
646,
8027,
14,
4400,
465,
6904,
199,
646,
8027,
14,
1569,
465,
6118,
4060,
199,
199,
504,
7026,
14,
13416,
492,
15318,
63,
3269,
199,
646,
7026,
14,
26248,
465,
21494,
199,
504,
7026,
492,
28884,
199,
504,
7026,
14,
21294,
492,
23716,
17,
68,
199,
646,
7026,
14,
3200,
199,
199,
504,
28753,
14,
2308,
492,
20147,
199,
504,
28753,
14,
1224,
492,
6957,
12,
4263,
199,
504,
28753,
492,
6204,
465,
399,
199,
504,
28753,
14,
12924,
492,
428,
10562,
14957,
199,
504,
28753,
14,
5197,
573,
4956,
492,
19005,
21350,
7695,
45,
199,
5197,
573,
275,
19005,
21350,
7695,
45,
8,
40,
16,
29,
3172,
12,
593,
77,
16,
29,
16,
14,
19,
12,
377,
18892,
16,
29,
18,
14,
31304,
9,
199,
199,
646,
2402,
63,
6815,
465,
444,
199,
504,
14937,
492,
6047,
465,
6047,
63,
48,
1193,
199,
646,
325,
23064,
647,
221,
327,
39,
279,
27296,
9572,
848,
316,
199,
199,
624,
199,
9846,
26,
221,
199,
1548,
299,
10081,
63,
7379,
15,
80,
10081,
63,
838,
357,
2358,
63,
452,
63,
14982,
14,
647,
18368,
51,
969,
2481,
7347,
70,
1006,
2482,
82,
499,
11535,
199,
1548,
299,
10081,
63,
7379,
15,
80,
10081,
63,
838,
357,
2358,
63,
452,
63,
14982,
14,
647,
18368,
51,
969,
2481,
7347,
70,
1006,
2482,
82,
949,
18,
11535,
199,
1548,
299,
10081,
63,
7379,
15,
80,
10081,
63,
838,
357,
2358,
63,
452,
63,
14982,
14,
647,
18368,
51,
969,
2481,
7347,
70,
302,
736,
7493,
949,
18,
11535,
199,
1548,
299,
10081,
63,
7379,
15,
80,
10081,
63,
838,
357,
2358,
63,
452,
63,
14982,
14,
647,
18368,
51,
969,
2481,
2599,
302,
736,
7493,
949,
18,
11535,
199,
199,
698,
26,
536,
402,
314,
1504,
199,
632,
26,
7347,
70,
12,
2599,
12,
282,
529,
12,
7188,
14601,
12,
1402,
199,
452,
2482,
82,
26,
523,
446,
1006,
2482,
82,
26,
1255,
8137,
5893,
3945,
357,
2358,
63,
86,
20,
12,
10415,
63,
1943,
12,
428,
17665,
523,
446,
5340,
82,
26,
1255,
2951,
428,
17665,
436,
1678,
314,
3164,
523,
446,
302,
736,
7493,
26,
2793,
1133,
1255,
5340,
82,
12,
2951,
1678,
314,
3164,
543,
3365,
12404,
199,
18,
11535,
523,
446,
499,
11535,
26,
1255,
428,
17665,
543,
499,
45,
3755,
370,
1336,
523,
446,
949,
18,
11535,
26,
1255,
428,
17665,
1928,
499,
45,
3755,
199,
624,
199,
199,
5680,
3606,
9460,
5680,
199,
318,
2342,
63,
3239,
316,
8,
698,
12,
7877,
304,
272,
4051,
63,
3239,
29,
8961,
14,
739,
63,
4737,
2336,
12117,
15,
502,
1129,
546,
292,
15,
26872,
15,
581,
63,
4041,
15,
2923,
63,
335,
6142,
63,
698,
63,
3239,
316,
14,
4737,
297,
1080,
63,
761,
29,
16,
9,
272,
340,
901,
59,
16,
26,
21,
22954,
1244,
12346,
356,
267,
1937,
316,
275,
4051,
63,
3239,
59,
1587,
63,
3239,
14,
335,
6142,
389,
698,
2733,
3239,
316,
63,
81,
821,
4970,
83,
5956,
7877,
1055,
1459,
59,
16,
61,
327,
4970,
83,
5956,
7877,
267,
372,
1937,
316,
272,
916,
334,
698,
59,
16,
26,
21,
22954,
792,
358,
92,
8,
698,
59,
16,
26,
19,
22954,
8884,
51,
358,
92,
8,
698,
59,
16,
26,
20,
22954,
3693,
2300,
735,
267,
1937,
316,
275,
4051,
63,
3239,
59,
1587,
63,
3239,
14,
354,
389,
698,
2733,
3239,
316,
63,
81,
821,
4970,
83,
5956,
7877,
1055,
1459,
59,
16,
61,
327,
4970,
83,
5956,
7877,
267,
372,
1937,
316,
199,
199,
318,
2342,
63,
3239,
316,
63,
1222,
8,
694,
12,
698,
304,
272,
3002,
2872,
19,
29,
264,
14,
2014,
8,
82,
6774,
1244,
12346,
2788,
12773,
15555,
60,
63,
16045,
15555,
358,
272,
1937,
316,
275,
2069,
8,
14948,
14,
1490,
8,
513,
63,
493,
63,
354,
8,
694,
12,
1662,
2872,
19,
14,
1733,
8,
698,
680,
923,
18756,
16,
11057,
16,
1055,
1291,
459,
38,
9792,
45,
17,
1105,
272,
372,
1937,
316,
199,
199,
318,
2342,
63,
3239,
316,
63,
14948,
8,
698,
304,
272,
5629,
8805,
12117,
15,
502,
1129,
546,
292,
15,
26872,
15,
80,
10081,
63,
600,
4805,
272,
7606,
2968,
337,
1196,
28399,
15,
1673,
337,
1196,
614,
966,
15,
1673,
337,
1196,
1690,
1167,
15,
1673,
337,
1196,
1690,
2025,
15,
1673,
337,
1196,
1690,
1194,
15,
1673,
337,
1196,
713,
2036,
3678,
60,
272,
283,
337,
1196,
713,
1643,
15,
1673,
337,
1196,
25481,
15,
1673,
337,
1167,
31720,
15,
1673,
337,
1167,
966,
969,
15,
418,
272,
3002,
2872,
29,
264,
14,
2014,
8,
82,
29113,
83,
63,
33,
680,
10,
5956,
698,
9,
272,
367,
487,
315,
7606,
26,
267,
2935,
29,
4219,
11,
328,
267,
367,
1318,
315,
747,
14,
7374,
8,
694,
304,
288,
340,
3002,
2872,
14,
1733,
8,
505,
9,
1137,
488,
26,
355,
1937,
316,
29,
1609,
8,
14948,
14,
1490,
8,
694,
11,
1662,
2872,
14,
1733,
8,
505,
680,
923,
18756,
16,
1055,
1291,
459,
38,
9792,
45,
17,
1105,
272,
372,
1937,
316,
199,
318,
1586,
63,
635,
837,
272,
543,
1551,
480,
80,
10081,
63,
7379,
15,
1162,
14,
5963,
401,
283,
82,
358,
465,
2547,
26,
267,
862,
26,
288,
1215,
29,
5963,
14,
912,
8,
1745,
12,
22865,
29,
5963,
14,
9042,
5455,
9,
288,
372,
1215,
267,
871,
8864,
14,
23103,
547,
465,
3178,
26,
288,
870,
8,
2804,
9,
199,
318,
1586,
63,
635,
63,
565,
80,
8,
632,
304,
272,
340,
818,
6803,
1190,
70,
356,
267,
818,
63,
565,
80,
19070,
272,
916,
818,
6803,
1238,
356,
267,
818,
63,
565,
80,
19070,
17384,
63,
1238,
7,
272,
587,
26,
267,
818,
63,
565,
80,
19070,
272,
327,
870,
3286,
12117,
15,
502,
1129,
546,
292,
15,
26872,
15,
80,
10081,
63,
600,
15,
80,
10081,
63,
7379,
15,
1162,
63,
1793,
27826,
442,
5,
83
] |
[
984,
12,
747,
12,
295,
12,
8864,
12,
3873,
12,
16701,
12,
481,
5930,
63,
2537,
199,
646,
10634,
465,
6454,
199,
646,
2680,
465,
980,
199,
199,
646,
5927,
199,
199,
646,
8027,
199,
646,
8027,
14,
13563,
465,
4488,
199,
504,
8027,
492,
1834,
199,
646,
8027,
14,
4400,
465,
6904,
199,
646,
8027,
14,
1569,
465,
6118,
4060,
199,
199,
504,
7026,
14,
13416,
492,
15318,
63,
3269,
199,
646,
7026,
14,
26248,
465,
21494,
199,
504,
7026,
492,
28884,
199,
504,
7026,
14,
21294,
492,
23716,
17,
68,
199,
646,
7026,
14,
3200,
199,
199,
504,
28753,
14,
2308,
492,
20147,
199,
504,
28753,
14,
1224,
492,
6957,
12,
4263,
199,
504,
28753,
492,
6204,
465,
399,
199,
504,
28753,
14,
12924,
492,
428,
10562,
14957,
199,
504,
28753,
14,
5197,
573,
4956,
492,
19005,
21350,
7695,
45,
199,
5197,
573,
275,
19005,
21350,
7695,
45,
8,
40,
16,
29,
3172,
12,
593,
77,
16,
29,
16,
14,
19,
12,
377,
18892,
16,
29,
18,
14,
31304,
9,
199,
199,
646,
2402,
63,
6815,
465,
444,
199,
504,
14937,
492,
6047,
465,
6047,
63,
48,
1193,
199,
646,
325,
23064,
647,
221,
327,
39,
279,
27296,
9572,
848,
316,
199,
199,
624,
199,
9846,
26,
221,
199,
1548,
299,
10081,
63,
7379,
15,
80,
10081,
63,
838,
357,
2358,
63,
452,
63,
14982,
14,
647,
18368,
51,
969,
2481,
7347,
70,
1006,
2482,
82,
499,
11535,
199,
1548,
299,
10081,
63,
7379,
15,
80,
10081,
63,
838,
357,
2358,
63,
452,
63,
14982,
14,
647,
18368,
51,
969,
2481,
7347,
70,
1006,
2482,
82,
949,
18,
11535,
199,
1548,
299,
10081,
63,
7379,
15,
80,
10081,
63,
838,
357,
2358,
63,
452,
63,
14982,
14,
647,
18368,
51,
969,
2481,
7347,
70,
302,
736,
7493,
949,
18,
11535,
199,
1548,
299,
10081,
63,
7379,
15,
80,
10081,
63,
838,
357,
2358,
63,
452,
63,
14982,
14,
647,
18368,
51,
969,
2481,
2599,
302,
736,
7493,
949,
18,
11535,
199,
199,
698,
26,
536,
402,
314,
1504,
199,
632,
26,
7347,
70,
12,
2599,
12,
282,
529,
12,
7188,
14601,
12,
1402,
199,
452,
2482,
82,
26,
523,
446,
1006,
2482,
82,
26,
1255,
8137,
5893,
3945,
357,
2358,
63,
86,
20,
12,
10415,
63,
1943,
12,
428,
17665,
523,
446,
5340,
82,
26,
1255,
2951,
428,
17665,
436,
1678,
314,
3164,
523,
446,
302,
736,
7493,
26,
2793,
1133,
1255,
5340,
82,
12,
2951,
1678,
314,
3164,
543,
3365,
12404,
199,
18,
11535,
523,
446,
499,
11535,
26,
1255,
428,
17665,
543,
499,
45,
3755,
370,
1336,
523,
446,
949,
18,
11535,
26,
1255,
428,
17665,
1928,
499,
45,
3755,
199,
624,
199,
199,
5680,
3606,
9460,
5680,
199,
318,
2342,
63,
3239,
316,
8,
698,
12,
7877,
304,
272,
4051,
63,
3239,
29,
8961,
14,
739,
63,
4737,
2336,
12117,
15,
502,
1129,
546,
292,
15,
26872,
15,
581,
63,
4041,
15,
2923,
63,
335,
6142,
63,
698,
63,
3239,
316,
14,
4737,
297,
1080,
63,
761,
29,
16,
9,
272,
340,
901,
59,
16,
26,
21,
22954,
1244,
12346,
356,
267,
1937,
316,
275,
4051,
63,
3239,
59,
1587,
63,
3239,
14,
335,
6142,
389,
698,
2733,
3239,
316,
63,
81,
821,
4970,
83,
5956,
7877,
1055,
1459,
59,
16,
61,
327,
4970,
83,
5956,
7877,
267,
372,
1937,
316,
272,
916,
334,
698,
59,
16,
26,
21,
22954,
792,
358,
92,
8,
698,
59,
16,
26,
19,
22954,
8884,
51,
358,
92,
8,
698,
59,
16,
26,
20,
22954,
3693,
2300,
735,
267,
1937,
316,
275,
4051,
63,
3239,
59,
1587,
63,
3239,
14,
354,
389,
698,
2733,
3239,
316,
63,
81,
821,
4970,
83,
5956,
7877,
1055,
1459,
59,
16,
61,
327,
4970,
83,
5956,
7877,
267,
372,
1937,
316,
199,
199,
318,
2342,
63,
3239,
316,
63,
1222,
8,
694,
12,
698,
304,
272,
3002,
2872,
19,
29,
264,
14,
2014,
8,
82,
6774,
1244,
12346,
2788,
12773,
15555,
60,
63,
16045,
15555,
358,
272,
1937,
316,
275,
2069,
8,
14948,
14,
1490,
8,
513,
63,
493,
63,
354,
8,
694,
12,
1662,
2872,
19,
14,
1733,
8,
698,
680,
923,
18756,
16,
11057,
16,
1055,
1291,
459,
38,
9792,
45,
17,
1105,
272,
372,
1937,
316,
199,
199,
318,
2342,
63,
3239,
316,
63,
14948,
8,
698,
304,
272,
5629,
8805,
12117,
15,
502,
1129,
546,
292,
15,
26872,
15,
80,
10081,
63,
600,
4805,
272,
7606,
2968,
337,
1196,
28399,
15,
1673,
337,
1196,
614,
966,
15,
1673,
337,
1196,
1690,
1167,
15,
1673,
337,
1196,
1690,
2025,
15,
1673,
337,
1196,
1690,
1194,
15,
1673,
337,
1196,
713,
2036,
3678,
60,
272,
283,
337,
1196,
713,
1643,
15,
1673,
337,
1196,
25481,
15,
1673,
337,
1167,
31720,
15,
1673,
337,
1167,
966,
969,
15,
418,
272,
3002,
2872,
29,
264,
14,
2014,
8,
82,
29113,
83,
63,
33,
680,
10,
5956,
698,
9,
272,
367,
487,
315,
7606,
26,
267,
2935,
29,
4219,
11,
328,
267,
367,
1318,
315,
747,
14,
7374,
8,
694,
304,
288,
340,
3002,
2872,
14,
1733,
8,
505,
9,
1137,
488,
26,
355,
1937,
316,
29,
1609,
8,
14948,
14,
1490,
8,
694,
11,
1662,
2872,
14,
1733,
8,
505,
680,
923,
18756,
16,
1055,
1291,
459,
38,
9792,
45,
17,
1105,
272,
372,
1937,
316,
199,
318,
1586,
63,
635,
837,
272,
543,
1551,
480,
80,
10081,
63,
7379,
15,
1162,
14,
5963,
401,
283,
82,
358,
465,
2547,
26,
267,
862,
26,
288,
1215,
29,
5963,
14,
912,
8,
1745,
12,
22865,
29,
5963,
14,
9042,
5455,
9,
288,
372,
1215,
267,
871,
8864,
14,
23103,
547,
465,
3178,
26,
288,
870,
8,
2804,
9,
199,
318,
1586,
63,
635,
63,
565,
80,
8,
632,
304,
272,
340,
818,
6803,
1190,
70,
356,
267,
818,
63,
565,
80,
19070,
272,
916,
818,
6803,
1238,
356,
267,
818,
63,
565,
80,
19070,
17384,
63,
1238,
7,
272,
587,
26,
267,
818,
63,
565,
80,
19070,
272,
327,
870,
3286,
12117,
15,
502,
1129,
546,
292,
15,
26872,
15,
80,
10081,
63,
600,
15,
80,
10081,
63,
7379,
15,
1162,
63,
1793,
27826,
442,
5,
83,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
jmartu/testing
|
venv/lib/python3.6/site-packages/pip/_vendor/requests/packages/urllib3/_collections.py
|
666
|
10553
|
from __future__ import absolute_import
from collections import Mapping, MutableMapping
try:
from threading import RLock
except ImportError: # Platform-specific: No threads available
class RLock:
def __enter__(self):
pass
def __exit__(self, exc_type, exc_value, traceback):
pass
try: # Python 2.7+
from collections import OrderedDict
except ImportError:
from .packages.ordered_dict import OrderedDict
from .packages.six import iterkeys, itervalues, PY3
__all__ = ['RecentlyUsedContainer', 'HTTPHeaderDict']
_Null = object()
class RecentlyUsedContainer(MutableMapping):
"""
Provides a thread-safe dict-like container which maintains up to
``maxsize`` keys while throwing away the least-recently-used keys beyond
``maxsize``.
:param maxsize:
Maximum number of recent elements to retain.
:param dispose_func:
Every time an item is evicted from the container,
``dispose_func(value)`` is called. Callback which will get called
"""
ContainerCls = OrderedDict
def __init__(self, maxsize=10, dispose_func=None):
self._maxsize = maxsize
self.dispose_func = dispose_func
self._container = self.ContainerCls()
self.lock = RLock()
def __getitem__(self, key):
# Re-insert the item, moving it to the end of the eviction line.
with self.lock:
item = self._container.pop(key)
self._container[key] = item
return item
def __setitem__(self, key, value):
evicted_value = _Null
with self.lock:
# Possibly evict the existing value of 'key'
evicted_value = self._container.get(key, _Null)
self._container[key] = value
# If we didn't evict an existing value, we might have to evict the
# least recently used item from the beginning of the container.
if len(self._container) > self._maxsize:
_key, evicted_value = self._container.popitem(last=False)
if self.dispose_func and evicted_value is not _Null:
self.dispose_func(evicted_value)
def __delitem__(self, key):
with self.lock:
value = self._container.pop(key)
if self.dispose_func:
self.dispose_func(value)
def __len__(self):
with self.lock:
return len(self._container)
def __iter__(self):
raise NotImplementedError('Iteration over this class is unlikely to be threadsafe.')
def clear(self):
with self.lock:
# Copy pointers to all values, then wipe the mapping
values = list(itervalues(self._container))
self._container.clear()
if self.dispose_func:
for value in values:
self.dispose_func(value)
def keys(self):
with self.lock:
return list(iterkeys(self._container))
class HTTPHeaderDict(MutableMapping):
"""
:param headers:
An iterable of field-value pairs. Must not contain multiple field names
when compared case-insensitively.
:param kwargs:
Additional field-value pairs to pass in to ``dict.update``.
A ``dict`` like container for storing HTTP Headers.
Field names are stored and compared case-insensitively in compliance with
RFC 7230. Iteration provides the first case-sensitive key seen for each
case-insensitive pair.
Using ``__setitem__`` syntax overwrites fields that compare equal
case-insensitively in order to maintain ``dict``'s api. For fields that
compare equal, instead create a new ``HTTPHeaderDict`` and use ``.add``
in a loop.
If multiple fields that are equal case-insensitively are passed to the
constructor or ``.update``, the behavior is undefined and some will be
lost.
>>> headers = HTTPHeaderDict()
>>> headers.add('Set-Cookie', 'foo=bar')
>>> headers.add('set-cookie', 'baz=quxx')
>>> headers['content-length'] = '7'
>>> headers['SET-cookie']
'foo=bar, baz=quxx'
>>> headers['Content-Length']
'7'
"""
def __init__(self, headers=None, **kwargs):
super(HTTPHeaderDict, self).__init__()
self._container = OrderedDict()
if headers is not None:
if isinstance(headers, HTTPHeaderDict):
self._copy_from(headers)
else:
self.extend(headers)
if kwargs:
self.extend(kwargs)
def __setitem__(self, key, val):
self._container[key.lower()] = (key, val)
return self._container[key.lower()]
def __getitem__(self, key):
val = self._container[key.lower()]
return ', '.join(val[1:])
def __delitem__(self, key):
del self._container[key.lower()]
def __contains__(self, key):
return key.lower() in self._container
def __eq__(self, other):
if not isinstance(other, Mapping) and not hasattr(other, 'keys'):
return False
if not isinstance(other, type(self)):
other = type(self)(other)
return (dict((k.lower(), v) for k, v in self.itermerged()) ==
dict((k.lower(), v) for k, v in other.itermerged()))
def __ne__(self, other):
return not self.__eq__(other)
if not PY3: # Python 2
iterkeys = MutableMapping.iterkeys
itervalues = MutableMapping.itervalues
__marker = object()
def __len__(self):
return len(self._container)
def __iter__(self):
# Only provide the originally cased names
for vals in self._container.values():
yield vals[0]
def pop(self, key, default=__marker):
'''D.pop(k[,d]) -> v, remove specified key and return the corresponding value.
If key is not found, d is returned if given, otherwise KeyError is raised.
'''
# Using the MutableMapping function directly fails due to the private marker.
# Using ordinary dict.pop would expose the internal structures.
# So let's reinvent the wheel.
try:
value = self[key]
except KeyError:
if default is self.__marker:
raise
return default
else:
del self[key]
return value
def discard(self, key):
try:
del self[key]
except KeyError:
pass
def add(self, key, val):
"""Adds a (name, value) pair, doesn't overwrite the value if it already
exists.
>>> headers = HTTPHeaderDict(foo='bar')
>>> headers.add('Foo', 'baz')
>>> headers['foo']
'bar, baz'
"""
key_lower = key.lower()
new_vals = key, val
# Keep the common case aka no item present as fast as possible
vals = self._container.setdefault(key_lower, new_vals)
if new_vals is not vals:
# new_vals was not inserted, as there was a previous one
if isinstance(vals, list):
# If already several items got inserted, we have a list
vals.append(val)
else:
# vals should be a tuple then, i.e. only one item so far
# Need to convert the tuple to list for further extension
self._container[key_lower] = [vals[0], vals[1], val]
def extend(self, *args, **kwargs):
"""Generic import function for any type of header-like object.
Adapted version of MutableMapping.update in order to insert items
with self.add instead of self.__setitem__
"""
if len(args) > 1:
raise TypeError("extend() takes at most 1 positional "
"arguments ({0} given)".format(len(args)))
other = args[0] if len(args) >= 1 else ()
if isinstance(other, HTTPHeaderDict):
for key, val in other.iteritems():
self.add(key, val)
elif isinstance(other, Mapping):
for key in other:
self.add(key, other[key])
elif hasattr(other, "keys"):
for key in other.keys():
self.add(key, other[key])
else:
for key, value in other:
self.add(key, value)
for key, value in kwargs.items():
self.add(key, value)
def getlist(self, key):
"""Returns a list of all the values for the named field. Returns an
empty list if the key doesn't exist."""
try:
vals = self._container[key.lower()]
except KeyError:
return []
else:
if isinstance(vals, tuple):
return [vals[1]]
else:
return vals[1:]
# Backwards compatibility for httplib
getheaders = getlist
getallmatchingheaders = getlist
iget = getlist
def __repr__(self):
return "%s(%s)" % (type(self).__name__, dict(self.itermerged()))
def _copy_from(self, other):
for key in other:
val = other.getlist(key)
if isinstance(val, list):
# Don't need to convert tuples
val = list(val)
self._container[key.lower()] = [key] + val
def copy(self):
clone = type(self)()
clone._copy_from(self)
return clone
def iteritems(self):
"""Iterate over all header lines, including duplicate ones."""
for key in self:
vals = self._container[key.lower()]
for val in vals[1:]:
yield vals[0], val
def itermerged(self):
"""Iterate over all headers, merging duplicate ones together."""
for key in self:
val = self._container[key.lower()]
yield val[0], ', '.join(val[1:])
def items(self):
return list(self.iteritems())
@classmethod
def from_httplib(cls, message): # Python 2
"""Read headers from a Python 2 httplib message object."""
# python2.7 does not expose a proper API for exporting multiheaders
# efficiently. This function re-reads raw lines from the message
# object and extracts the multiheaders properly.
headers = []
for line in message.headers:
if line.startswith((' ', '\t')):
key, value = headers[-1]
headers[-1] = (key, value + '\r\n' + line.rstrip())
continue
key, value = line.split(':', 1)
headers.append((key, value.strip()))
return cls(headers)
|
mit
|
[
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
5055,
492,
12340,
12,
29396,
199,
893,
26,
272,
687,
5796,
492,
820,
6432,
199,
2590,
3545,
26,
221,
327,
16078,
13,
6100,
26,
3091,
7183,
2808,
272,
1021,
820,
6432,
26,
267,
347,
636,
4200,
721,
277,
304,
288,
986,
398,
347,
636,
2224,
721,
277,
12,
3178,
63,
466,
12,
3178,
63,
585,
12,
5190,
304,
288,
986,
421,
199,
893,
26,
221,
327,
2018,
499,
14,
23,
11,
272,
687,
5055,
492,
8773,
199,
2590,
3545,
26,
272,
687,
1275,
5154,
14,
8235,
63,
807,
492,
8773,
199,
504,
1275,
5154,
14,
4174,
492,
25706,
12,
24451,
12,
7843,
19,
421,
199,
363,
452,
363,
275,
788,
29574,
590,
9167,
4076,
297,
283,
2856,
2567,
2141,
418,
421,
199,
63,
8849,
275,
909,
342,
421,
199,
533,
799,
2946,
590,
9167,
4076,
8,
17707,
7674,
304,
272,
408,
272,
21552,
282,
2462,
13,
3489,
1211,
13,
2930,
3970,
1314,
11075,
83,
1536,
370,
272,
1124,
13634,
1040,
2883,
1830,
7978,
316,
13437,
314,
5210,
13,
14951,
590,
13,
2972,
2883,
20561,
272,
1124,
13634,
4345,
339,
520,
635,
19791,
26,
267,
14212,
1329,
402,
8058,
4008,
370,
8074,
14,
339,
520,
635,
2153,
4070,
63,
1532,
26,
267,
18414,
900,
376,
1242,
365,
24656,
1522,
687,
314,
3970,
12,
267,
1124,
29842,
63,
1532,
8,
585,
9719,
365,
2797,
14,
221,
17555,
1314,
911,
664,
2797,
272,
408,
339,
15395,
24342,
275,
8773,
339,
347,
636,
826,
721,
277,
12,
19791,
29,
709,
12,
2153,
4070,
63,
1532,
29,
403,
304,
267,
291,
423,
13634,
275,
19791,
267,
291,
14,
29842,
63,
1532,
275,
2153,
4070,
63,
1532,
398,
291,
423,
3600,
275,
291,
14,
4076,
24342,
342,
267,
291,
14,
831,
275,
820,
6432,
342,
339,
347,
636,
6095,
721,
277,
12,
790,
304,
267,
327,
799,
13,
3176,
314,
1242,
12,
12876,
652,
370,
314,
1284,
402,
314,
24656,
414,
1004,
14,
267,
543,
291,
14,
831,
26,
288,
1242,
275,
291,
423,
3600,
14,
1935,
8,
498,
9,
288,
291,
423,
3600,
59,
498,
61,
275,
1242,
288,
372,
1242,
339,
347,
636,
8617,
721,
277,
12,
790,
12,
574,
304,
267,
24656,
1522,
63,
585,
275,
485,
8849,
267,
543,
291,
14,
831,
26,
288,
327,
25987,
9312,
24656,
319,
314,
3411,
574,
402,
283,
498,
7,
288,
24656,
1522,
63,
585,
275,
291,
423,
3600,
14,
362,
8,
498,
12,
485,
8849,
9,
288,
291,
423,
3600,
59,
498,
61,
275,
574,
953,
327,
982,
781,
9980,
1133,
24656,
319,
376,
3411,
574,
12,
781,
5594,
1172,
370,
24656,
319,
314,
288,
327,
5210,
23568,
1202,
1242,
687,
314,
9608,
402,
314,
3970,
14,
288,
340,
822,
8,
277,
423,
3600,
9,
690,
291,
423,
13634,
26,
355,
485,
498,
12,
24656,
1522,
63,
585,
275,
291,
423,
3600,
14,
24882,
8,
2019,
29,
797,
9,
398,
340,
291,
14,
29842,
63,
1532,
436,
24656,
1522,
63,
585,
365,
440,
485,
8849,
26,
288,
291,
14,
29842,
63,
1532,
8,
69,
433,
1522,
63,
585,
9,
339,
347,
636,
13228,
721,
277,
12,
790,
304,
267,
543,
291,
14,
831,
26,
288,
574,
275,
291,
423,
3600,
14,
1935,
8,
498,
9,
398,
340,
291,
14,
29842,
63,
1532,
26,
288,
291,
14,
29842,
63,
1532,
8,
585,
9,
339,
347,
636,
552,
721,
277,
304,
267,
543,
291,
14,
831,
26,
288,
372,
822,
8,
277,
423,
3600,
9,
339,
347,
636,
1661,
721,
277,
304,
267,
746,
4279,
360,
8666,
1806,
642,
1021,
365,
625,
24227,
370,
506,
2462,
3489,
2659,
339,
347,
5436,
8,
277,
304,
267,
543,
291,
14,
831,
26,
288,
327,
11247,
21116,
370,
1006,
1338,
12,
2066,
336,
3662,
314,
4412,
288,
1338,
275,
769,
8,
13012,
8,
277,
423,
3600,
430,
288,
291,
423,
3600,
14,
3584,
342,
398,
340,
291,
14,
29842,
63,
1532,
26,
288,
367,
574,
315,
1338,
26,
355,
291,
14,
29842,
63,
1532,
8,
585,
9,
339,
347,
2883,
8,
277,
304,
267,
543,
291,
14,
831,
26,
288,
372,
769,
8,
16007,
8,
277,
423,
3600,
430,
421,
199,
533,
3101,
2567,
2141,
8,
17707,
7674,
304,
272,
408,
272,
520,
635,
2323,
26,
267,
1626,
6076,
402,
901,
13,
585,
6342,
14,
9498,
440,
1395,
3663,
901,
1561,
267,
1380,
13524,
1930,
13,
262,
2464,
338,
9462,
14,
339,
520,
635,
2074,
26,
267,
10961,
901,
13,
585,
6342,
370,
986,
315,
370,
1124,
807,
14,
873,
4345,
339,
437,
1124,
807,
1040,
2839,
3970,
367,
16915,
3101,
21391,
14,
339,
5024,
1561,
787,
5489,
436,
13524,
1930,
13,
262,
2464,
338,
9462,
315,
4151,
543,
272,
7329,
1520,
9687,
14,
473,
5388,
6571,
314,
1642,
1930,
13,
7361,
790,
6775,
367,
1924,
272,
1930,
13,
15851,
4092,
14,
339,
11719,
9035,
8617,
18762,
6302,
1806,
16334,
1504,
626,
6540,
4472,
272,
1930,
13,
262,
2464,
338,
9462,
315,
1865,
370,
11075,
1124,
807,
1040,
7,
83,
2986,
14,
2104,
1504,
626,
272,
6540,
4472,
12,
3140,
1218,
282,
892,
1124,
2856,
2567,
2141,
1040,
436,
675,
21502,
525,
1040,
272,
315,
282,
4438,
14,
339,
982,
3663,
1504,
626,
787,
4472,
1930,
13,
262,
2464,
338,
9462,
787,
3032,
370,
314,
272,
3787,
503,
21502,
873,
4542,
314,
5953,
365,
10942,
436,
2005,
911,
506,
272,
14669,
14,
339,
1306,
2323,
275,
3101,
2567,
2141,
342,
272,
1306,
2323,
14,
525,
360,
1084,
13,
7810,
297,
283,
1421,
29,
1700,
358,
272,
1306,
2323,
14,
525,
360,
409,
13,
5306,
297,
283,
6185,
29,
392,
2154,
358,
272,
1306,
2323,
459,
1317,
13,
1267,
418,
275,
283,
23,
7,
272,
1306,
2323,
459,
3597,
13,
5306,
418,
272,
283,
1421,
29,
1700,
12,
15507,
29,
392,
2154,
7,
272,
1306,
2323,
459,
2714,
13,
4625,
418,
272,
283,
23,
7,
272,
408,
339,
347,
636,
826,
721,
277,
12,
2323,
29,
403,
12,
1011,
958,
304,
267,
1613,
8,
2856,
2567,
2141,
12,
291,
2843,
826,
4533,
267,
291,
423,
3600,
275,
8773,
342,
267,
340,
2323,
365,
440,
488,
26,
288,
340,
1228,
8,
2139,
12,
3101,
2567,
2141
] |
[
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
5055,
492,
12340,
12,
29396,
199,
893,
26,
272,
687,
5796,
492,
820,
6432,
199,
2590,
3545,
26,
221,
327,
16078,
13,
6100,
26,
3091,
7183,
2808,
272,
1021,
820,
6432,
26,
267,
347,
636,
4200,
721,
277,
304,
288,
986,
398,
347,
636,
2224,
721,
277,
12,
3178,
63,
466,
12,
3178,
63,
585,
12,
5190,
304,
288,
986,
421,
199,
893,
26,
221,
327,
2018,
499,
14,
23,
11,
272,
687,
5055,
492,
8773,
199,
2590,
3545,
26,
272,
687,
1275,
5154,
14,
8235,
63,
807,
492,
8773,
199,
504,
1275,
5154,
14,
4174,
492,
25706,
12,
24451,
12,
7843,
19,
421,
199,
363,
452,
363,
275,
788,
29574,
590,
9167,
4076,
297,
283,
2856,
2567,
2141,
418,
421,
199,
63,
8849,
275,
909,
342,
421,
199,
533,
799,
2946,
590,
9167,
4076,
8,
17707,
7674,
304,
272,
408,
272,
21552,
282,
2462,
13,
3489,
1211,
13,
2930,
3970,
1314,
11075,
83,
1536,
370,
272,
1124,
13634,
1040,
2883,
1830,
7978,
316,
13437,
314,
5210,
13,
14951,
590,
13,
2972,
2883,
20561,
272,
1124,
13634,
4345,
339,
520,
635,
19791,
26,
267,
14212,
1329,
402,
8058,
4008,
370,
8074,
14,
339,
520,
635,
2153,
4070,
63,
1532,
26,
267,
18414,
900,
376,
1242,
365,
24656,
1522,
687,
314,
3970,
12,
267,
1124,
29842,
63,
1532,
8,
585,
9719,
365,
2797,
14,
221,
17555,
1314,
911,
664,
2797,
272,
408,
339,
15395,
24342,
275,
8773,
339,
347,
636,
826,
721,
277,
12,
19791,
29,
709,
12,
2153,
4070,
63,
1532,
29,
403,
304,
267,
291,
423,
13634,
275,
19791,
267,
291,
14,
29842,
63,
1532,
275,
2153,
4070,
63,
1532,
398,
291,
423,
3600,
275,
291,
14,
4076,
24342,
342,
267,
291,
14,
831,
275,
820,
6432,
342,
339,
347,
636,
6095,
721,
277,
12,
790,
304,
267,
327,
799,
13,
3176,
314,
1242,
12,
12876,
652,
370,
314,
1284,
402,
314,
24656,
414,
1004,
14,
267,
543,
291,
14,
831,
26,
288,
1242,
275,
291,
423,
3600,
14,
1935,
8,
498,
9,
288,
291,
423,
3600,
59,
498,
61,
275,
1242,
288,
372,
1242,
339,
347,
636,
8617,
721,
277,
12,
790,
12,
574,
304,
267,
24656,
1522,
63,
585,
275,
485,
8849,
267,
543,
291,
14,
831,
26,
288,
327,
25987,
9312,
24656,
319,
314,
3411,
574,
402,
283,
498,
7,
288,
24656,
1522,
63,
585,
275,
291,
423,
3600,
14,
362,
8,
498,
12,
485,
8849,
9,
288,
291,
423,
3600,
59,
498,
61,
275,
574,
953,
327,
982,
781,
9980,
1133,
24656,
319,
376,
3411,
574,
12,
781,
5594,
1172,
370,
24656,
319,
314,
288,
327,
5210,
23568,
1202,
1242,
687,
314,
9608,
402,
314,
3970,
14,
288,
340,
822,
8,
277,
423,
3600,
9,
690,
291,
423,
13634,
26,
355,
485,
498,
12,
24656,
1522,
63,
585,
275,
291,
423,
3600,
14,
24882,
8,
2019,
29,
797,
9,
398,
340,
291,
14,
29842,
63,
1532,
436,
24656,
1522,
63,
585,
365,
440,
485,
8849,
26,
288,
291,
14,
29842,
63,
1532,
8,
69,
433,
1522,
63,
585,
9,
339,
347,
636,
13228,
721,
277,
12,
790,
304,
267,
543,
291,
14,
831,
26,
288,
574,
275,
291,
423,
3600,
14,
1935,
8,
498,
9,
398,
340,
291,
14,
29842,
63,
1532,
26,
288,
291,
14,
29842,
63,
1532,
8,
585,
9,
339,
347,
636,
552,
721,
277,
304,
267,
543,
291,
14,
831,
26,
288,
372,
822,
8,
277,
423,
3600,
9,
339,
347,
636,
1661,
721,
277,
304,
267,
746,
4279,
360,
8666,
1806,
642,
1021,
365,
625,
24227,
370,
506,
2462,
3489,
2659,
339,
347,
5436,
8,
277,
304,
267,
543,
291,
14,
831,
26,
288,
327,
11247,
21116,
370,
1006,
1338,
12,
2066,
336,
3662,
314,
4412,
288,
1338,
275,
769,
8,
13012,
8,
277,
423,
3600,
430,
288,
291,
423,
3600,
14,
3584,
342,
398,
340,
291,
14,
29842,
63,
1532,
26,
288,
367,
574,
315,
1338,
26,
355,
291,
14,
29842,
63,
1532,
8,
585,
9,
339,
347,
2883,
8,
277,
304,
267,
543,
291,
14,
831,
26,
288,
372,
769,
8,
16007,
8,
277,
423,
3600,
430,
421,
199,
533,
3101,
2567,
2141,
8,
17707,
7674,
304,
272,
408,
272,
520,
635,
2323,
26,
267,
1626,
6076,
402,
901,
13,
585,
6342,
14,
9498,
440,
1395,
3663,
901,
1561,
267,
1380,
13524,
1930,
13,
262,
2464,
338,
9462,
14,
339,
520,
635,
2074,
26,
267,
10961,
901,
13,
585,
6342,
370,
986,
315,
370,
1124,
807,
14,
873,
4345,
339,
437,
1124,
807,
1040,
2839,
3970,
367,
16915,
3101,
21391,
14,
339,
5024,
1561,
787,
5489,
436,
13524,
1930,
13,
262,
2464,
338,
9462,
315,
4151,
543,
272,
7329,
1520,
9687,
14,
473,
5388,
6571,
314,
1642,
1930,
13,
7361,
790,
6775,
367,
1924,
272,
1930,
13,
15851,
4092,
14,
339,
11719,
9035,
8617,
18762,
6302,
1806,
16334,
1504,
626,
6540,
4472,
272,
1930,
13,
262,
2464,
338,
9462,
315,
1865,
370,
11075,
1124,
807,
1040,
7,
83,
2986,
14,
2104,
1504,
626,
272,
6540,
4472,
12,
3140,
1218,
282,
892,
1124,
2856,
2567,
2141,
1040,
436,
675,
21502,
525,
1040,
272,
315,
282,
4438,
14,
339,
982,
3663,
1504,
626,
787,
4472,
1930,
13,
262,
2464,
338,
9462,
787,
3032,
370,
314,
272,
3787,
503,
21502,
873,
4542,
314,
5953,
365,
10942,
436,
2005,
911,
506,
272,
14669,
14,
339,
1306,
2323,
275,
3101,
2567,
2141,
342,
272,
1306,
2323,
14,
525,
360,
1084,
13,
7810,
297,
283,
1421,
29,
1700,
358,
272,
1306,
2323,
14,
525,
360,
409,
13,
5306,
297,
283,
6185,
29,
392,
2154,
358,
272,
1306,
2323,
459,
1317,
13,
1267,
418,
275,
283,
23,
7,
272,
1306,
2323,
459,
3597,
13,
5306,
418,
272,
283,
1421,
29,
1700,
12,
15507,
29,
392,
2154,
7,
272,
1306,
2323,
459,
2714,
13,
4625,
418,
272,
283,
23,
7,
272,
408,
339,
347,
636,
826,
721,
277,
12,
2323,
29,
403,
12,
1011,
958,
304,
267,
1613,
8,
2856,
2567,
2141,
12,
291,
2843,
826,
4533,
267,
291,
423,
3600,
275,
8773,
342,
267,
340,
2323,
365,
440,
488,
26,
288,
340,
1228,
8,
2139,
12,
3101,
2567,
2141,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
yiheng/BigDL
|
pyspark/test/bigdl/test_pickler.py
|
6
|
2568
|
#
# Copyright 2016 The BigDL Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
from bigdl.nn.layer import *
from bigdl.nn.initialization_method import *
from bigdl.nn.criterion import *
from bigdl.optim.optimizer import *
from bigdl.util.common import *
from bigdl.util.common import _py2java
from bigdl.nn.initialization_method import *
from bigdl.dataset import movielens
import numpy as np
import tempfile
import pytest
from numpy.testing import assert_allclose, assert_array_equal
from bigdl.util.engine import compare_version
np.random.seed(1337) # for reproducibility
class TestPickler():
def setup_method(self, method):
""" setup any state tied to the execution of the given method in a
class. setup_method is invoked for every test method of a class.
"""
JavaCreator.add_creator_class("com.intel.analytics.bigdl.python.api.PythonBigDLValidator")
sparkConf = create_spark_conf().setMaster("local[4]").setAppName("test model")
self.sc = get_spark_context(sparkConf)
init_engine()
def teardown_method(self, method):
""" teardown any state that was previously setup with a setup_method
call.
"""
self.sc.stop()
def test_activity_with_jtensor(self):
back = callBigDlFunc("float", "testActivityWithTensor")
assert isinstance(back.value, JTensor)
def test_activity_with_table_of_tensor(self):
back = callBigDlFunc("float", "testActivityWithTableOfTensor")
assert isinstance(back.value, list)
assert isinstance(back.value[0], JTensor)
assert back.value[0].to_ndarray()[0] < back.value[1].to_ndarray()[0]
assert back.value[1].to_ndarray()[0] < back.value[2].to_ndarray()[0]
def test_activity_with_table_of_table(self):
back = callBigDlFunc("float", "testActivityWithTableOfTable")
assert isinstance(back.value, list)
assert isinstance(back.value[0], list)
assert isinstance(back.value[0][0], JTensor)
if __name__ == "__main__":
pytest.main([__file__])
|
apache-2.0
|
[
3,
199,
3,
1898,
7800,
710,
13123,
8045,
6642,
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,
199,
199,
504,
7282,
5030,
14,
4411,
14,
1897,
492,
627,
199,
504,
7282,
5030,
14,
4411,
14,
27876,
63,
765,
492,
627,
199,
504,
7282,
5030,
14,
4411,
14,
21418,
492,
627,
199,
504,
7282,
5030,
14,
6433,
14,
12290,
492,
627,
199,
504,
7282,
5030,
14,
1974,
14,
2330,
492,
627,
199,
504,
7282,
5030,
14,
1974,
14,
2330,
492,
485,
647,
18,
6138,
199,
504,
7282,
5030,
14,
4411,
14,
27876,
63,
765,
492,
627,
199,
504,
7282,
5030,
14,
5214,
492,
14360,
25057,
199,
646,
2680,
465,
980,
199,
646,
5549,
199,
646,
4613,
199,
504,
2680,
14,
4776,
492,
702,
63,
7520,
12,
702,
63,
1144,
63,
1452,
199,
504,
7282,
5030,
14,
1974,
14,
3908,
492,
6540,
63,
1023,
199,
1590,
14,
2355,
14,
5176,
8,
969,
1401,
9,
221,
327,
367,
295,
496,
2033,
559,
3195,
421,
199,
533,
1379,
8587,
1435,
837,
272,
347,
3272,
63,
765,
8,
277,
12,
1083,
304,
267,
408,
3272,
1263,
1174,
29142,
370,
314,
6451,
402,
314,
1627,
1083,
315,
282,
267,
1021,
14,
221,
3272,
63,
765,
365,
10302,
367,
4036,
511,
1083,
402,
282,
1021,
14,
267,
408,
267,
9586,
17523,
14,
525,
63,
9986,
63,
533,
480,
957,
14,
22264,
14,
20211,
14,
5076,
5030,
14,
1548,
14,
1246,
14,
4718,
7279,
8045,
8640,
531,
267,
15442,
8930,
275,
1218,
63,
9852,
63,
2190,
1252,
409,
12288,
480,
1832,
59,
20,
61,
3471,
409,
28258,
480,
396,
1402,
531,
267,
291,
14,
551,
275,
664,
63,
9852,
63,
1100,
8,
9852,
8930,
9,
267,
4205,
63,
3908,
342,
339,
347,
17558,
63,
765,
8,
277,
12,
1083,
304,
267,
408,
17558,
1263,
1174,
626,
1990,
10889,
3272,
543,
282,
3272,
63,
765,
267,
1240,
14,
267,
408,
267,
291,
14,
551,
14,
2379,
342,
339,
347,
511,
63,
8240,
63,
1045,
63,
74,
3128,
8,
277,
304,
267,
1771,
275,
1240,
7279,
22904,
7465,
480,
1609,
401,
298,
396,
14350,
3007,
3861,
531,
267,
702,
1228,
8,
894,
14,
585,
12,
1603,
3861,
9,
339,
347,
511,
63,
8240,
63,
1045,
63,
1224,
63,
1618,
63,
3128,
8,
277,
304,
267,
1771,
275,
1240,
7279,
22904,
7465,
480,
1609,
401,
298,
396,
14350,
3007,
3186,
3466,
3861,
531,
267,
702,
1228,
8,
894,
14,
585,
12,
769,
9,
267,
702,
1228,
8,
894,
14,
585,
59,
16,
467,
1603,
3861,
9,
267,
702,
1771,
14,
585,
59,
16,
1055,
475,
63,
8237,
3430,
16,
61,
665,
1771,
14,
585,
59,
17,
1055,
475,
63,
8237,
3430,
16,
61,
267,
702,
1771,
14,
585,
59,
17,
1055,
475,
63,
8237,
3430,
16,
61,
665,
1771,
14,
585,
59,
18,
1055,
475,
63,
8237,
3430,
16,
61,
339,
347,
511,
63,
8240,
63,
1045,
63,
1224,
63,
1618,
63,
1224,
8,
277,
304,
267,
1771,
275,
1240,
7279,
22904,
7465,
480,
1609,
401,
298,
396,
14350,
3007,
3186,
3466,
3186,
531,
267,
702,
1228,
8,
894,
14,
585,
12,
769,
9,
267,
702,
1228,
8,
894,
14,
585,
59,
16,
467,
769,
9,
267,
702,
1228,
8,
894,
14,
585,
59,
16,
1527,
16,
467,
1603,
3861,
9,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
4613,
14,
973,
779,
363,
493,
363,
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
] |
[
199,
3,
1898,
7800,
710,
13123,
8045,
6642,
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,
199,
199,
504,
7282,
5030,
14,
4411,
14,
1897,
492,
627,
199,
504,
7282,
5030,
14,
4411,
14,
27876,
63,
765,
492,
627,
199,
504,
7282,
5030,
14,
4411,
14,
21418,
492,
627,
199,
504,
7282,
5030,
14,
6433,
14,
12290,
492,
627,
199,
504,
7282,
5030,
14,
1974,
14,
2330,
492,
627,
199,
504,
7282,
5030,
14,
1974,
14,
2330,
492,
485,
647,
18,
6138,
199,
504,
7282,
5030,
14,
4411,
14,
27876,
63,
765,
492,
627,
199,
504,
7282,
5030,
14,
5214,
492,
14360,
25057,
199,
646,
2680,
465,
980,
199,
646,
5549,
199,
646,
4613,
199,
504,
2680,
14,
4776,
492,
702,
63,
7520,
12,
702,
63,
1144,
63,
1452,
199,
504,
7282,
5030,
14,
1974,
14,
3908,
492,
6540,
63,
1023,
199,
1590,
14,
2355,
14,
5176,
8,
969,
1401,
9,
221,
327,
367,
295,
496,
2033,
559,
3195,
421,
199,
533,
1379,
8587,
1435,
837,
272,
347,
3272,
63,
765,
8,
277,
12,
1083,
304,
267,
408,
3272,
1263,
1174,
29142,
370,
314,
6451,
402,
314,
1627,
1083,
315,
282,
267,
1021,
14,
221,
3272,
63,
765,
365,
10302,
367,
4036,
511,
1083,
402,
282,
1021,
14,
267,
408,
267,
9586,
17523,
14,
525,
63,
9986,
63,
533,
480,
957,
14,
22264,
14,
20211,
14,
5076,
5030,
14,
1548,
14,
1246,
14,
4718,
7279,
8045,
8640,
531,
267,
15442,
8930,
275,
1218,
63,
9852,
63,
2190,
1252,
409,
12288,
480,
1832,
59,
20,
61,
3471,
409,
28258,
480,
396,
1402,
531,
267,
291,
14,
551,
275,
664,
63,
9852,
63,
1100,
8,
9852,
8930,
9,
267,
4205,
63,
3908,
342,
339,
347,
17558,
63,
765,
8,
277,
12,
1083,
304,
267,
408,
17558,
1263,
1174,
626,
1990,
10889,
3272,
543,
282,
3272,
63,
765,
267,
1240,
14,
267,
408,
267,
291,
14,
551,
14,
2379,
342,
339,
347,
511,
63,
8240,
63,
1045,
63,
74,
3128,
8,
277,
304,
267,
1771,
275,
1240,
7279,
22904,
7465,
480,
1609,
401,
298,
396,
14350,
3007,
3861,
531,
267,
702,
1228,
8,
894,
14,
585,
12,
1603,
3861,
9,
339,
347,
511,
63,
8240,
63,
1045,
63,
1224,
63,
1618,
63,
3128,
8,
277,
304,
267,
1771,
275,
1240,
7279,
22904,
7465,
480,
1609,
401,
298,
396,
14350,
3007,
3186,
3466,
3861,
531,
267,
702,
1228,
8,
894,
14,
585,
12,
769,
9,
267,
702,
1228,
8,
894,
14,
585,
59,
16,
467,
1603,
3861,
9,
267,
702,
1771,
14,
585,
59,
16,
1055,
475,
63,
8237,
3430,
16,
61,
665,
1771,
14,
585,
59,
17,
1055,
475,
63,
8237,
3430,
16,
61,
267,
702,
1771,
14,
585,
59,
17,
1055,
475,
63,
8237,
3430,
16,
61,
665,
1771,
14,
585,
59,
18,
1055,
475,
63,
8237,
3430,
16,
61,
339,
347,
511,
63,
8240,
63,
1045,
63,
1224,
63,
1618,
63,
1224,
8,
277,
304,
267,
1771,
275,
1240,
7279,
22904,
7465,
480,
1609,
401,
298,
396,
14350,
3007,
3186,
3466,
3186,
531,
267,
702,
1228,
8,
894,
14,
585,
12,
769,
9,
267,
702,
1228,
8,
894,
14,
585,
59,
16,
467,
769,
9,
267,
702,
1228,
8,
894,
14,
585,
59,
16,
1527,
16,
467,
1603,
3861,
9,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
4613,
14,
973,
779,
363,
493,
363,
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,
0
] |
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
] |
4eek/edx-platform
|
common/djangoapps/third_party_auth/management/commands/saml.py
|
80
|
1410
|
# -*- coding: utf-8 -*-
"""
Management commands for third_party_auth
"""
from django.core.management.base import BaseCommand, CommandError
import logging
from third_party_auth.models import SAMLConfiguration
from third_party_auth.tasks import fetch_saml_metadata
class Command(BaseCommand):
""" manage.py commands to manage SAML/Shibboleth SSO """
help = '''Configure/maintain/update SAML-based SSO'''
def handle(self, *args, **options):
if len(args) != 1:
raise CommandError("saml requires one argument: pull")
if not SAMLConfiguration.is_enabled():
raise CommandError("SAML support is disabled via SAMLConfiguration.")
subcommand = args[0]
if subcommand == "pull":
log_handler = logging.StreamHandler(self.stdout)
log_handler.setLevel(logging.DEBUG)
log = logging.getLogger('third_party_auth.tasks')
log.propagate = False
log.addHandler(log_handler)
num_changed, num_failed, num_total = fetch_saml_metadata()
self.stdout.write(
"\nDone. Fetched {num_total} total. {num_changed} were updated and {num_failed} failed.\n".format(
num_changed=num_changed, num_failed=num_failed, num_total=num_total
)
)
else:
raise CommandError("Unknown argment: {}".format(subcommand))
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
199,
14552,
3718,
367,
10919,
63,
7522,
63,
1178,
199,
624,
199,
504,
1639,
14,
1018,
14,
8110,
14,
1095,
492,
22239,
12,
14393,
199,
646,
2050,
199,
504,
10919,
63,
7522,
63,
1178,
14,
992,
492,
428,
10107,
5688,
199,
504,
10919,
63,
7522,
63,
1178,
14,
5054,
492,
5267,
63,
29338,
63,
2343,
421,
199,
533,
5817,
8,
25150,
304,
272,
408,
9635,
14,
647,
3718,
370,
9635,
428,
10107,
15,
2662,
1892,
656,
274,
273,
428,
4118,
408,
272,
1720,
275,
1449,
17324,
15,
20180,
15,
873,
428,
10107,
13,
6788,
428,
4118,
2344,
339,
347,
2429,
8,
277,
12,
627,
589,
12,
1011,
1419,
304,
267,
340,
822,
8,
589,
9,
1137,
413,
26,
288,
746,
14393,
480,
29338,
5074,
1373,
1423,
26,
10299,
531,
398,
340,
440,
428,
10107,
5688,
14,
374,
63,
3827,
837,
288,
746,
14393,
480,
26986,
2291,
365,
6980,
4799,
428,
10107,
5688,
2685,
398,
21474,
275,
1249,
59,
16,
61,
398,
340,
21474,
508,
298,
9302,
582,
288,
943,
63,
2232,
275,
2050,
14,
22482,
8,
277,
14,
2703,
9,
288,
943,
63,
2232,
14,
13548,
8,
4806,
14,
5287,
9,
288,
943,
275,
2050,
14,
5572,
360,
11470,
63,
7522,
63,
1178,
14,
5054,
358,
288,
943,
14,
19432,
275,
756,
288,
943,
14,
18826,
8,
793,
63,
2232,
9,
288,
1967,
63,
2489,
12,
1967,
63,
4892,
12,
1967,
63,
2923,
275,
5267,
63,
29338,
63,
2343,
342,
288,
291,
14,
2703,
14,
952,
8,
355,
1867,
78,
10759,
14,
481,
13534,
469,
1507,
63,
2923,
93,
3141,
14,
469,
1507,
63,
2489,
93,
4898,
4588,
436,
469,
1507,
63,
4892,
93,
3405,
3134,
78,
1674,
908,
8,
490,
1967,
63,
2489,
29,
1507,
63,
2489,
12,
1967,
63,
4892,
29,
1507,
63,
4892,
12,
1967,
63,
2923,
29,
1507,
63,
2923,
355,
776,
288,
776,
267,
587,
26,
288,
746,
14393,
480,
5912,
1680,
434,
26,
8352,
908,
8,
954,
1531,
430,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
199,
14552,
3718,
367,
10919,
63,
7522,
63,
1178,
199,
624,
199,
504,
1639,
14,
1018,
14,
8110,
14,
1095,
492,
22239,
12,
14393,
199,
646,
2050,
199,
504,
10919,
63,
7522,
63,
1178,
14,
992,
492,
428,
10107,
5688,
199,
504,
10919,
63,
7522,
63,
1178,
14,
5054,
492,
5267,
63,
29338,
63,
2343,
421,
199,
533,
5817,
8,
25150,
304,
272,
408,
9635,
14,
647,
3718,
370,
9635,
428,
10107,
15,
2662,
1892,
656,
274,
273,
428,
4118,
408,
272,
1720,
275,
1449,
17324,
15,
20180,
15,
873,
428,
10107,
13,
6788,
428,
4118,
2344,
339,
347,
2429,
8,
277,
12,
627,
589,
12,
1011,
1419,
304,
267,
340,
822,
8,
589,
9,
1137,
413,
26,
288,
746,
14393,
480,
29338,
5074,
1373,
1423,
26,
10299,
531,
398,
340,
440,
428,
10107,
5688,
14,
374,
63,
3827,
837,
288,
746,
14393,
480,
26986,
2291,
365,
6980,
4799,
428,
10107,
5688,
2685,
398,
21474,
275,
1249,
59,
16,
61,
398,
340,
21474,
508,
298,
9302,
582,
288,
943,
63,
2232,
275,
2050,
14,
22482,
8,
277,
14,
2703,
9,
288,
943,
63,
2232,
14,
13548,
8,
4806,
14,
5287,
9,
288,
943,
275,
2050,
14,
5572,
360,
11470,
63,
7522,
63,
1178,
14,
5054,
358,
288,
943,
14,
19432,
275,
756,
288,
943,
14,
18826,
8,
793,
63,
2232,
9,
288,
1967,
63,
2489,
12,
1967,
63,
4892,
12,
1967,
63,
2923,
275,
5267,
63,
29338,
63,
2343,
342,
288,
291,
14,
2703,
14,
952,
8,
355,
1867,
78,
10759,
14,
481,
13534,
469,
1507,
63,
2923,
93,
3141,
14,
469,
1507,
63,
2489,
93,
4898,
4588,
436,
469,
1507,
63,
4892,
93,
3405,
3134,
78,
1674,
908,
8,
490,
1967,
63,
2489,
29,
1507,
63,
2489,
12,
1967,
63,
4892,
29,
1507,
63,
4892,
12,
1967,
63,
2923,
29,
1507,
63,
2923,
355,
776,
288,
776,
267,
587,
26,
288,
746,
14393,
480,
5912,
1680,
434,
26,
8352,
908,
8,
954,
1531,
430,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
kslundberg/pants
|
src/python/pants/scm/scm.py
|
16
|
3749
|
# coding=utf-8
# Copyright 2014 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).
from __future__ import (absolute_import, division, generators, nested_scopes, print_function,
unicode_literals, with_statement)
from abc import abstractmethod, abstractproperty
from pants.util.meta import AbstractClass
class Scm(AbstractClass):
"""Abstracts high-level scm operations needed by pants core and pants tasks."""
class ScmException(Exception):
"""Indicates a problem interacting with the scm."""
class RemoteException(ScmException):
"""Indicates a problem performing a remote scm operation."""
class LocalException(ScmException):
"""Indicates a problem performing a local scm operation."""
@abstractproperty
def current_rev_identifier(self):
"""Identifier for the tip/head of the current branch eg. "HEAD" in git"""
@abstractproperty
def commit_id(self):
"""Returns the id of the current commit."""
@abstractproperty
def server_url(self):
"""Returns the url of the (default) remote server."""
@abstractproperty
def tag_name(self):
"""Returns the name of the current tag if any."""
@abstractproperty
def branch_name(self):
"""Returns the name of the current branch if any."""
@abstractmethod
def commit_date(self, commit_reference):
"""Returns the commit date of the referenced commit."""
@abstractmethod
def changed_files(self, from_commit=None, include_untracked=False, relative_to=None):
"""Returns a list of files with uncommitted changes or else files changed since from_commit.
If include_untracked=True then any workspace files that are un-tracked by the scm and not
ignored will be included as well.
If relative_to is None, then the paths will be relative to the working tree of the SCM
implementation (which might NOT match the buildroot.)
"""
@abstractmethod
def changes_in(self, diffspec, relative_to=None):
"""Returns a list of files changed by some diffspec (eg sha, range, ref, etc)
:param str diffspec: Some diffspec meaningful to the SCM.
:param str relative_to: a path to which results should be relative (instead of SCM root)
"""
@abstractmethod
def changelog(self, from_commit=None, files=None):
"""Produces a changelog from the given commit or the 1st commit if none is specified until the
present workspace commit for the changes affecting the given files.
If no files are given then the full change log should be produced.
"""
@abstractmethod
def refresh(self):
"""Refreshes the local workspace with any changes on the server.
Subclasses should raise some form of ScmException to indicate a refresh error whether it be
a conflict or a communication channel error.
"""
@abstractmethod
def tag(self, name, message=None):
"""Tags the state in the local workspace and ensures this tag is on the server.
Subclasses should raise RemoteException if there is a problem getting the tag to the server.
"""
@abstractmethod
def commit(self, message):
"""Commits all the changes for tracked files in the local workspace.
Subclasses should raise LocalException if there is a problem making the commit.
"""
@abstractmethod
def add(self, *paths):
"""Add paths to the set of tracked files.
Subclasses should raise LocalException if there is a problem adding the paths.
"""
@abstractmethod
def push(self):
"""Push the current branch of the local repository to the corresponding local branch
on the server
Subclasses should raise RemoteException if there is a problem getting the commit to the
server.
"""
|
apache-2.0
|
[
3,
2803,
29,
1624,
13,
24,
199,
3,
1898,
6927,
510,
2285,
2199,
8417,
334,
3239,
6483,
14,
1064,
680,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
3239,
5113,
680,
199,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
16952,
12,
6032,
63,
14129,
12,
870,
63,
1593,
12,
717,
2649,
63,
5955,
12,
543,
63,
6242,
9,
199,
199,
504,
13022,
492,
9006,
765,
12,
9006,
1829,
199,
199,
504,
18081,
14,
1974,
14,
2024,
492,
11836,
2543,
421,
199,
533,
428,
4400,
8,
8458,
2543,
304,
523,
408,
8458,
83,
4721,
13,
1896,
25811,
5331,
4346,
701,
18081,
6170,
436,
18081,
6527,
1041,
819,
1021,
428,
4400,
1726,
8,
1726,
304,
272,
408,
607,
16292,
282,
5160,
17232,
316,
543,
314,
25811,
1041,
819,
1021,
17283,
1726,
8,
51,
4400,
1726,
304,
272,
408,
607,
16292,
282,
5160,
19203,
282,
3982,
25811,
3439,
1041,
819,
1021,
10111,
1726,
8,
51,
4400,
1726,
304,
272,
408,
607,
16292,
282,
5160,
19203,
282,
2257,
25811,
3439,
1041,
819,
768,
6198,
1829,
523,
347,
1453,
63,
4964,
63,
5364,
8,
277,
304,
272,
408,
7544,
367,
314,
19201,
15,
2993,
402,
314,
1453,
5246,
11837,
14,
298,
5211,
2,
315,
6135,
624,
819,
768,
6198,
1829,
523,
347,
5532,
63,
344,
8,
277,
304,
272,
408,
3407,
314,
1305,
402,
314,
1453,
5532,
1041,
819,
768,
6198,
1829,
523,
347,
1654,
63,
633,
8,
277,
304,
272,
408,
3407,
314,
1166,
402,
314,
334,
885,
9,
3982,
1654,
1041,
819,
768,
6198,
1829,
523,
347,
1947,
63,
354,
8,
277,
304,
272,
408,
3407,
314,
536,
402,
314,
1453,
1947,
340,
1263,
1041,
819,
768,
6198,
1829,
523,
347,
5246,
63,
354,
8,
277,
304,
272,
408,
3407,
314,
536,
402,
314,
1453,
5246,
340,
1263,
1041,
819,
768,
10315,
523,
347,
5532,
63,
602,
8,
277,
12,
5532,
63,
4443,
304,
272,
408,
3407,
314,
5532,
1434,
402,
314,
11812,
5532,
1041,
819,
768,
10315,
523,
347,
2896,
63,
1725,
8,
277,
12,
687,
63,
3543,
29,
403,
12,
2387,
63,
638,
8085,
379,
29,
797,
12,
3847,
63,
475,
29,
403,
304,
272,
408,
3407,
282,
769,
402,
1584,
543,
625,
20300,
4493,
503,
587,
1584,
2896,
3967,
687,
63,
3543,
14,
339,
982,
2387,
63,
638,
8085,
379,
29,
549,
2066,
1263,
14466,
1584,
626,
787,
625,
13,
22586,
701,
314,
25811,
436,
440,
272,
5525,
911,
506,
5120,
465,
5521,
14,
339,
982,
3847,
63,
475,
365,
488,
12,
2066,
314,
3792,
911,
506,
3847,
370,
314,
6449,
3123,
402,
314,
428,
9249,
272,
4514,
334,
6777,
5594,
2845,
1336,
314,
1900,
1231,
4959,
272,
408,
819,
768,
10315,
523,
347,
4493,
63,
262,
8,
277,
12,
3915,
1650,
12,
3847,
63,
475,
29,
403,
304,
272,
408,
3407,
282,
769,
402,
1584,
2896,
701,
2005,
3915,
1650,
334,
5902,
7793,
12,
1425,
12,
2984,
12,
5423,
9,
339,
520,
635,
620,
3915,
1650,
26,
6601,
3915,
1650,
26562,
370,
314,
428,
9249,
14,
272,
520,
635,
620,
3847,
63,
475,
26,
282,
931,
370,
1314,
2058,
1077,
506,
3847,
334,
23145,
402,
428,
9249,
1738,
9,
272,
408,
819,
768,
10315,
523,
347,
1570,
793,
8,
277,
12,
687,
63,
3543,
29,
403,
12,
1584,
29,
403,
304,
272,
408,
919,
10569,
282,
1570,
793,
687,
314,
1627,
5532,
503,
314,
413,
270,
5532,
340,
7179,
365,
2013,
5133,
314,
272,
3451,
14466,
5532,
367,
314,
4493,
12787,
316,
314,
1627,
1584,
14,
339,
982,
949,
1584,
787,
1627,
2066,
314,
2615,
1570,
943,
1077,
506,
13584,
14,
272,
408,
819,
768,
10315,
523,
347,
9236,
8,
277,
304,
272,
408,
18730,
397,
314,
2257,
14466,
543,
1263,
4493,
641,
314,
1654,
14,
339,
20196,
1077,
746,
2005,
1824,
402,
428,
4400,
1726,
370,
6623,
282,
9236,
1125,
3775,
652,
506,
272,
282,
12395,
503,
282,
23506,
3623,
1125,
14,
272,
408,
819,
768,
10315,
523,
347,
1947,
8,
277,
12,
536,
12,
1245,
29,
403,
304,
272,
408,
9440,
314,
1174,
315,
314,
2257,
14466,
436,
15620,
642,
1947,
365,
641,
314,
1654,
14,
339,
20196,
1077,
746,
17283,
1726,
340,
2337,
365,
282,
5160,
10232,
314,
1947,
370,
314,
1654,
14,
272,
408,
819,
768,
10315,
523,
347,
5532,
8,
277,
12,
1245,
304,
272,
408,
5150,
1405,
1006,
314,
4493,
367,
23268,
1584,
315,
314,
2257,
14466,
14,
339,
20196,
1077,
746,
10111,
1726,
340,
2337,
365,
282,
5160,
10663,
314,
5532,
14,
272,
408,
819,
768,
10315,
523,
347,
1050,
8,
277,
12,
627,
3771,
304,
272,
408,
1123,
3792,
370,
314,
663,
402,
23268,
1584,
14,
339,
20196,
1077,
746,
10111,
1726,
340,
2337,
365,
282,
5160,
7791,
314,
3792,
14,
272,
408,
819,
768,
10315,
523,
347,
6675,
8,
277,
304,
272,
408,
10731,
314,
1453,
5246,
402,
314,
2257,
7611,
370,
314,
5226,
2257,
5246,
272,
641,
314,
1654,
339,
20196,
1077,
746,
17283,
1726,
340,
2337,
365,
282,
5160,
10232,
314,
5532,
370,
314,
272,
1654,
14,
272,
408,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2803,
29,
1624,
13,
24,
199,
3,
1898,
6927,
510,
2285,
2199,
8417,
334,
3239,
6483,
14,
1064,
680,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
3239,
5113,
680,
199,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
16952,
12,
6032,
63,
14129,
12,
870,
63,
1593,
12,
717,
2649,
63,
5955,
12,
543,
63,
6242,
9,
199,
199,
504,
13022,
492,
9006,
765,
12,
9006,
1829,
199,
199,
504,
18081,
14,
1974,
14,
2024,
492,
11836,
2543,
421,
199,
533,
428,
4400,
8,
8458,
2543,
304,
523,
408,
8458,
83,
4721,
13,
1896,
25811,
5331,
4346,
701,
18081,
6170,
436,
18081,
6527,
1041,
819,
1021,
428,
4400,
1726,
8,
1726,
304,
272,
408,
607,
16292,
282,
5160,
17232,
316,
543,
314,
25811,
1041,
819,
1021,
17283,
1726,
8,
51,
4400,
1726,
304,
272,
408,
607,
16292,
282,
5160,
19203,
282,
3982,
25811,
3439,
1041,
819,
1021,
10111,
1726,
8,
51,
4400,
1726,
304,
272,
408,
607,
16292,
282,
5160,
19203,
282,
2257,
25811,
3439,
1041,
819,
768,
6198,
1829,
523,
347,
1453,
63,
4964,
63,
5364,
8,
277,
304,
272,
408,
7544,
367,
314,
19201,
15,
2993,
402,
314,
1453,
5246,
11837,
14,
298,
5211,
2,
315,
6135,
624,
819,
768,
6198,
1829,
523,
347,
5532,
63,
344,
8,
277,
304,
272,
408,
3407,
314,
1305,
402,
314,
1453,
5532,
1041,
819,
768,
6198,
1829,
523,
347,
1654,
63,
633,
8,
277,
304,
272,
408,
3407,
314,
1166,
402,
314,
334,
885,
9,
3982,
1654,
1041,
819,
768,
6198,
1829,
523,
347,
1947,
63,
354,
8,
277,
304,
272,
408,
3407,
314,
536,
402,
314,
1453,
1947,
340,
1263,
1041,
819,
768,
6198,
1829,
523,
347,
5246,
63,
354,
8,
277,
304,
272,
408,
3407,
314,
536,
402,
314,
1453,
5246,
340,
1263,
1041,
819,
768,
10315,
523,
347,
5532,
63,
602,
8,
277,
12,
5532,
63,
4443,
304,
272,
408,
3407,
314,
5532,
1434,
402,
314,
11812,
5532,
1041,
819,
768,
10315,
523,
347,
2896,
63,
1725,
8,
277,
12,
687,
63,
3543,
29,
403,
12,
2387,
63,
638,
8085,
379,
29,
797,
12,
3847,
63,
475,
29,
403,
304,
272,
408,
3407,
282,
769,
402,
1584,
543,
625,
20300,
4493,
503,
587,
1584,
2896,
3967,
687,
63,
3543,
14,
339,
982,
2387,
63,
638,
8085,
379,
29,
549,
2066,
1263,
14466,
1584,
626,
787,
625,
13,
22586,
701,
314,
25811,
436,
440,
272,
5525,
911,
506,
5120,
465,
5521,
14,
339,
982,
3847,
63,
475,
365,
488,
12,
2066,
314,
3792,
911,
506,
3847,
370,
314,
6449,
3123,
402,
314,
428,
9249,
272,
4514,
334,
6777,
5594,
2845,
1336,
314,
1900,
1231,
4959,
272,
408,
819,
768,
10315,
523,
347,
4493,
63,
262,
8,
277,
12,
3915,
1650,
12,
3847,
63,
475,
29,
403,
304,
272,
408,
3407,
282,
769,
402,
1584,
2896,
701,
2005,
3915,
1650,
334,
5902,
7793,
12,
1425,
12,
2984,
12,
5423,
9,
339,
520,
635,
620,
3915,
1650,
26,
6601,
3915,
1650,
26562,
370,
314,
428,
9249,
14,
272,
520,
635,
620,
3847,
63,
475,
26,
282,
931,
370,
1314,
2058,
1077,
506,
3847,
334,
23145,
402,
428,
9249,
1738,
9,
272,
408,
819,
768,
10315,
523,
347,
1570,
793,
8,
277,
12,
687,
63,
3543,
29,
403,
12,
1584,
29,
403,
304,
272,
408,
919,
10569,
282,
1570,
793,
687,
314,
1627,
5532,
503,
314,
413,
270,
5532,
340,
7179,
365,
2013,
5133,
314,
272,
3451,
14466,
5532,
367,
314,
4493,
12787,
316,
314,
1627,
1584,
14,
339,
982,
949,
1584,
787,
1627,
2066,
314,
2615,
1570,
943,
1077,
506,
13584,
14,
272,
408,
819,
768,
10315,
523,
347,
9236,
8,
277,
304,
272,
408,
18730,
397,
314,
2257,
14466,
543,
1263,
4493,
641,
314,
1654,
14,
339,
20196,
1077,
746,
2005,
1824,
402,
428,
4400,
1726,
370,
6623,
282,
9236,
1125,
3775,
652,
506,
272,
282,
12395,
503,
282,
23506,
3623,
1125,
14,
272,
408,
819,
768,
10315,
523,
347,
1947,
8,
277,
12,
536,
12,
1245,
29,
403,
304,
272,
408,
9440,
314,
1174,
315,
314,
2257,
14466,
436,
15620,
642,
1947,
365,
641,
314,
1654,
14,
339,
20196,
1077,
746,
17283,
1726,
340,
2337,
365,
282,
5160,
10232,
314,
1947,
370,
314,
1654,
14,
272,
408,
819,
768,
10315,
523,
347,
5532,
8,
277,
12,
1245,
304,
272,
408,
5150,
1405,
1006,
314,
4493,
367,
23268,
1584,
315,
314,
2257,
14466,
14,
339,
20196,
1077,
746,
10111,
1726,
340,
2337,
365,
282,
5160,
10663,
314,
5532,
14,
272,
408,
819,
768,
10315,
523,
347,
1050,
8,
277,
12,
627,
3771,
304,
272,
408,
1123,
3792,
370,
314,
663,
402,
23268,
1584,
14,
339,
20196,
1077,
746,
10111,
1726,
340,
2337,
365,
282,
5160,
7791,
314,
3792,
14,
272,
408,
819,
768,
10315,
523,
347,
6675,
8,
277,
304,
272,
408,
10731,
314,
1453,
5246,
402,
314,
2257,
7611,
370,
314,
5226,
2257,
5246,
272,
641,
314,
1654,
339,
20196,
1077,
746,
17283,
1726,
340,
2337,
365,
282,
5160,
10232,
314,
5532,
370,
314,
272,
1654,
14,
272,
408,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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
] |
dropbox/changes
|
changes/api/cached_snapshot_details.py
|
1
|
1182
|
from __future__ import absolute_import
from changes.api.base import APIView
from changes.models.snapshot import Snapshot
import changes.lib.snapshot_garbage_collection as gc
class CachedSnapshotDetailsAPIView(APIView):
def unpack_snapshot_ids(self, cluster_map):
return {cluster: [i.id.hex for i in images] for cluster, images in cluster_map.iteritems()}
def post(self, snapshot_id):
"""
Add the snapshot images of a given snapshot to the cache and respond
with sync updates for all of the clusters associated with the snapshot
that was just updated.
"""
snapshot = Snapshot.query.get(snapshot_id)
if snapshot is None:
return '', 404
# Add the snapshot to the cache, giving it no expiration
gc.cache_snapshot(snapshot)
# Send back the sync information for all clusters which require
# an update. Because this response is intended to be used for
# syncing we don't need to send anything but the snapshot
# image ids.
response = gc.get_relevant_snapshot_images(snapshot.id)
return self.respond(self.unpack_snapshot_ids(response))
|
apache-2.0
|
[
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
504,
4493,
14,
1246,
14,
1095,
492,
3261,
2768,
199,
504,
4493,
14,
992,
14,
4753,
492,
23896,
199,
646,
4493,
14,
773,
14,
4753,
63,
28737,
63,
3627,
465,
9486,
421,
199,
533,
445,
4583,
12038,
11347,
25778,
8,
25778,
304,
272,
347,
7787,
63,
4753,
63,
1580,
8,
277,
12,
4350,
63,
1130,
304,
267,
372,
469,
4201,
26,
359,
73,
14,
344,
14,
4097,
367,
284,
315,
5935,
61,
367,
4350,
12,
5935,
315,
4350,
63,
1130,
14,
4611,
12737,
339,
347,
2963,
8,
277,
12,
5740,
63,
344,
304,
267,
408,
267,
2654,
314,
5740,
5935,
402,
282,
1627,
5740,
370,
314,
2581,
436,
22722,
267,
543,
7604,
7029,
367,
1006,
402,
314,
13865,
4568,
543,
314,
5740,
267,
626,
1990,
2951,
4588,
14,
267,
408,
267,
5740,
275,
23896,
14,
1131,
14,
362,
8,
4753,
63,
344,
9,
267,
340,
5740,
365,
488,
26,
288,
372,
3260,
7901,
398,
327,
2654,
314,
5740,
370,
314,
2581,
12,
15131,
652,
949,
15399,
267,
9486,
14,
1637,
63,
4753,
8,
4753,
9,
398,
327,
10217,
1771,
314,
7604,
2556,
367,
1006,
13865,
1314,
4409,
267,
327,
376,
1678,
14,
13821,
642,
1177,
365,
11619,
370,
506,
1202,
367,
267,
327,
7604,
316,
781,
2793,
1133,
1929,
370,
3222,
7003,
1325,
314,
5740,
267,
327,
1834,
2762,
14,
267,
1177,
275,
9486,
14,
362,
63,
21906,
63,
4753,
63,
4782,
8,
4753,
14,
344,
9,
267,
372,
291,
14,
22720,
8,
277,
14,
5301,
63,
4753,
63,
1580,
8,
1310,
430,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
504,
4493,
14,
1246,
14,
1095,
492,
3261,
2768,
199,
504,
4493,
14,
992,
14,
4753,
492,
23896,
199,
646,
4493,
14,
773,
14,
4753,
63,
28737,
63,
3627,
465,
9486,
421,
199,
533,
445,
4583,
12038,
11347,
25778,
8,
25778,
304,
272,
347,
7787,
63,
4753,
63,
1580,
8,
277,
12,
4350,
63,
1130,
304,
267,
372,
469,
4201,
26,
359,
73,
14,
344,
14,
4097,
367,
284,
315,
5935,
61,
367,
4350,
12,
5935,
315,
4350,
63,
1130,
14,
4611,
12737,
339,
347,
2963,
8,
277,
12,
5740,
63,
344,
304,
267,
408,
267,
2654,
314,
5740,
5935,
402,
282,
1627,
5740,
370,
314,
2581,
436,
22722,
267,
543,
7604,
7029,
367,
1006,
402,
314,
13865,
4568,
543,
314,
5740,
267,
626,
1990,
2951,
4588,
14,
267,
408,
267,
5740,
275,
23896,
14,
1131,
14,
362,
8,
4753,
63,
344,
9,
267,
340,
5740,
365,
488,
26,
288,
372,
3260,
7901,
398,
327,
2654,
314,
5740,
370,
314,
2581,
12,
15131,
652,
949,
15399,
267,
9486,
14,
1637,
63,
4753,
8,
4753,
9,
398,
327,
10217,
1771,
314,
7604,
2556,
367,
1006,
13865,
1314,
4409,
267,
327,
376,
1678,
14,
13821,
642,
1177,
365,
11619,
370,
506,
1202,
367,
267,
327,
7604,
316,
781,
2793,
1133,
1929,
370,
3222,
7003,
1325,
314,
5740,
267,
327,
1834,
2762,
14,
267,
1177,
275,
9486,
14,
362,
63,
21906,
63,
4753,
63,
4782,
8,
4753,
14,
344,
9,
267,
372,
291,
14,
22720,
8,
277,
14,
5301,
63,
4753,
63,
1580,
8,
1310,
430,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
smurfix/pybble
|
pybble/manager/populate.py
|
1
|
12264
|
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, division, unicode_literals
##
## This is part of Pybble, a WMS (Whatever Management System) based on
## Jinja2/Haml, Werkzeug, Flask, and Optimism.
##
## Pybble is Copyright © 2009-2014 by Matthias Urlichs <matthias@urlichs.de>,
## it is licensed under the GPLv3. See the file `README.md` for details,
## including an optimistic statements by the author.
##
## This paragraph is auto-generated and may self-destruct at any time,
## courtesy of "make update". The original is in ‘utils/_boilerplate.py’.
## Thus, please do not remove the next line, or insert any blank lines.
##BP
import os
import logging
import re
from traceback import print_exc,format_exc
from flask import request, _app_ctx_stack
from flask._compat import text_type,string_types
from .. import TEMPLATE_PATH, STATIC_PATH
from ..utils import random_string,NotGiven
from ..core import config
from ..core.db import db, NoData
from ..core.add import process_module
from . import Command,Option
logger = logging.getLogger('pybble.manager.populate')
_metadata = re.compile('##:?(\S+) *[ :] *(.*)\n') # re.U ?
upload_content_types = [
## MIME type,subtype, file extension, name, description
('text','html','html','Web page',"A complete HTML-rendered web page"),
('text','plain','txt','Plain text',"raw text, no formatting"),
('text','javascript','js',"JavaScript",None),
('text','css','css',"CSS",None),
('image','png','png',"PNG image",None),
('image','jpeg',('jpg','jpeg'),"JPEG image",None),
('image','gif','gif',"GIF image",None),
('application','binary','bin',"raw data",None),
('application','pdf','pdf',"PDF document",None),
]
MIME = upload_content_types+[
('application','rss+xml','rss',"RSS feed",None),
('text','xml','xml',"XML data",None),
('message','rfc822',None,"Email message",None),
('pybble','_empty',None,"no data",None),
('pybble','*',None,"any pybble data",None),
('html','*',None,"any html data",None),
('text','*',None,"any text data",None),
('html','subpage',None,NotGiven,"a (main) part of a webpage"),
('html','string',None,NotGiven,"a short string describing an object"),
('html','detail',None,NotGiven,"a tabular view of an object's internal state"),
('html','snippet',None,NotGiven,"a fragment for the explore view"),
('html','hierarchy',None,NotGiven,"a fragment for hierarchical view within a page"),
('html','preview',None,NotGiven,"a view for previewing"),
('html','edit',None,NotGiven,"the form for editing"),
('xml','rss',None,NotGiven,"a fragment for the RSS feed"),
]
MODEL = (
'pybble.core.models.objtyp.ObjType',
'pybble.core.models.config.ConfigVar',
'pybble.core.models.config.ConfigData',
'pybble.core.models.config.SiteConfigVar',
'pybble.core.models.site.App',
'pybble.core.models.site.Blueprint',
'pybble.core.models.site.Site',
'pybble.core.models.site.SiteBlueprint',
'pybble.core.models.user.User',
'pybble.core.models.user.Group',
'pybble.core.models.user.Member',
'pybble.core.models.tracking.TrackingObject',
'pybble.core.models.tracking.Breadcrumb',
'pybble.core.models.tracking.Change',
'pybble.core.models.tracking.Delete',
'pybble.core.models.tracking.Tracker',
'pybble.core.models.tracking.WantTracking',
'pybble.core.models.tracking.UserTracker',
'pybble.core.models.permit.Permission',
'pybble.core.models.types.MIMEtype',
'pybble.core.models.types.MIMEext',
'pybble.core.models.types.MIMEtranslator',
'pybble.core.models.types.MIMEadapter',
'pybble.core.models.template.Template',
'pybble.core.models.template.TemplateMatch',
'pybble.core.models.storage.Storage',
'pybble.core.models.files.BinData',
'pybble.core.models.files.StaticFile',
'pybble.core.models.verifier.VerifierBase',
'pybble.core.models.verifier.Verifier',
)
VAR = []
APP = []
BLUEPRINT = []
VERIFIER = []
TEMPLATE = []
class PopulateCommand(Command):
"""Add minimal basic data to the database"""
def __init__(self):
super(PopulateCommand,self).__init__()
self.add_option(Option("-f","--force", dest="force",action="store_true",help="Override all database changes"))
def __call__(self,app, force=False):
with app.test_request_context('/'):
self.main(app,force)
def main(self,app, force=False):
from ..core.models.site import Site,App,Blueprint,SiteBlueprint
from ..core.models.storage import Storage
from ..core.models.files import StaticFile
from ..core.models.user import User
from ..core.models.permit import Permission,permit
from ..core.models.types import MIMEtype
from ..core.models._const import PERM_ADD
from ..translator import list_translators
from ..verifier import list_verifiers
from .. import ROOT_SITE_NAME,ROOT_USER_NAME
from ..app import list_apps
from ..blueprint import list_blueprints
if 'MEDIA_PATH' not in config:
raise RuntimeError("You have to set MEDIA_PATH so that I can store my files somewhere")
global VAR
def gen_vars():
from pybble.core import default_settings as DS
for k,v in DS.__dict__.items():
if k != k.upper(): continue
if k in app.config: # add overrides
v = app.config[k]
yield text_type(k),v,getattr(DS,'d_'+k,None)
VAR = gen_vars()
global APP
def gen_apps():
for name in list_apps():
name = text_type(name)
yield ("pybble.app.{}.App".format(name),name)
APP = list(gen_apps()) # required twice
global BLUEPRINT
def gen_bps():
for name in list_blueprints():
name = text_type(name)
yield ("pybble.blueprint.{}.Blueprint".format(name),name)
BLUEPRINT = gen_bps()
global TRANSLATOR
def gen_translators():
for name in list_translators():
name = text_type(name)
yield ("pybble.translator.{}.Translator".format(name),name)
TRANSLATOR = gen_translators()
global VERIFIER
def gen_translators():
for name in list_verifiers():
name = text_type(name)
yield ("pybble.verifier.{}.Verifier".format(name),name)
VERIFIER = gen_translators()
## Bootstrapping is tricky.
process_module({'MODEL':MODEL, 'MIME':MIME, 'APP':APP}, force=force)
## main site
rapp = App.q.get_by(name='_root')
try:
try:
root = Site.q.get_by(parent=None)
except NoData:
root = Site.q.get_by(name=ROOT_SITE_NAME)
except NoData:
root = Site.new(domain="localhost", name=ROOT_SITE_NAME, app=rapp)
logger.debug("The root site has been created.")
else:
if root.app is None or force:
if root.app != rapp:
root.app = rapp
logger.debug("Root site's app set.")
if root.parent is not None:
if force:
root.parent = None
logger.warning("The root site is not actually root. This has been corrected.")
else:
logger.error("The root site is not actually root. This is a problem.")
db.session.flush()
_app_ctx_stack.top.site = root
_app_ctx_stack.top.app.app = root.app
## Default storage
try:
try:
st = Storage.q.get_by(name=u"Pybble")
except NoData:
st = Storage.q.get_by(name=u"Test")
except NoData:
st = Storage.new("Test",app.config.MEDIA_PATH,"/static", site=root)
if Storage.q.filter_by(site=root,default=True).count() == 0:
st.default = True
else:
st.site = root
db.session.flush()
## main user
try:
superuser = User.q.get_by(username=ROOT_USER_NAME)
except NoData:
password = random_string()
superuser = User.new(site=root,username=ROOT_USER_NAME,password=password)
db.session.flush()
logger.info(u"The root user has been created. Password: ‘{}’.".format(password))
else:
if superuser.site != root:
logger.warning(u"The root user's site is {}, not {}.".format(superuser.site,root))
if force:
superuser.site = root
db.session.flush()
if superuser.email is None or (force and superuser.email != config.ADMIN_EMAIL):
if superuser.email is not None:
logger.info(u"The main admin email changed from ‘{}’ to ‘{}’".format(superuser.email,config.ADMIN_EMAIL))
superuser.email = text_type(config.ADMIN_EMAIL)
db.session.flush()
request.user = superuser
root.initial_permissions(superuser)
global STATIC
STATIC = ((STATIC_PATH,''),)
def find_templates(dirpath,webpath="",mapper=""):
if not os.path.isdir(dirpath):
return
for fn in os.listdir(dirpath):
if fn.startswith("."):
continue
newdirpath = os.path.join(dirpath,fn)
newwebpath = "{}/{}".format(webpath,fn) if webpath else fn
m=mapper
if os.path.isdir(newdirpath):
if m: m=m.do_dir(fn)
for r in find_templates(newdirpath,newwebpath,m):
yield r
else:
if m: m=m.do_file(fn)
yield (newdirpath,newwebpath,m)
class M(object):
"""Infer template metadata from the file name"""
def __init__(self,path=()):
self.path=path
def do_dir(self,fn):
return M(self.path+(fn,))
def do_file(self,fn):
if len(self.path) != 1: return ""
fn,ext = fn.split('.',1)
if ext == "html": ext = "jinja"
elif ext != "haml": return ""
p = self.path[0]
if p == "details": p = "html/detail"
elif p == "email": p = "text/plain"
elif p == "linktext": p = "html/string"
elif p == "rss": p = "xml/rss"
elif p == "preview": p = "html/preview"
elif p == "hierarchy": p = "html/hierarchy"
elif p == "snippet": p = "html/snippet"
elif p == "edit": p = "html/edit"
else: return ""
return """\
##src pybble/{}
##dst {}
##typ template/{}
##named 1
##inherit -
##match root
##weight 0
""".format(fn,p,ext)
global TEMPLATE
TEMPLATE = find_templates(TEMPLATE_PATH,mapper=M())
# APP is here again because of attached templates which might not
# have loaded the first time because of missing translators
process_module({'MODEL':MODEL}, force=True)
process_module({'VAR':VAR, 'BLUEPRINT':BLUEPRINT, 'APP':APP, 'TRANSLATOR':TRANSLATOR, 'VERIFIER':VERIFIER, 'STATIC':STATIC, 'TEMPLATE':TEMPLATE}, force=force)
## possible root app fix-ups
aapp = App.q.get_by(name="_alias")
import socket
hostname = text_type(socket.gethostname())
try:
asite = Site.q.get_by(name="root alias",parent=root)
except NoData:
asite = Site.new(name="root alias", domain=hostname, app=aapp)
logger.info("Root site aliased ‘{}’ created.".format(hostname))
else:
if asite.domain != hostname:
logger.warn("Root site alias is {}, not {}".format(asite.domain,hostname))
if force:
logger.warn("This is NOT aut-corrected.")
db.session.flush()
try:
root_bp = Blueprint.q.get_by(name='_root')
except NoData:
logger.error("The ‘_root’ blueprint is not present. Setup is incomplete!")
else:
try:
rbp = SiteBlueprint.q.get_by(site=root,blueprint=root_bp,path="")
except NoData:
rbp = SiteBlueprint.new(site=root,blueprint=root_bp,path="",name="pybble")
logger.debug("Root site's content blueprint created.")
else:
if rbp.name != "pybble" and force:
logger.warn("Root site's blueprint name changed from ‘{}’ to ‘pybble’.".format(rbp.name))
rbp.name = "pybble"
if rbp.endpoint != "pybble" and force:
logger.warn("Root site's static blueprint endpoint changed from ‘{}’ to ‘pybble’.".format(rbp.name))
rbp.endpoint = "pybble"
db.session.flush()
try:
static_bp = Blueprint.q.get_by(name='static')
except NoData:
logger.error("The ‘static’ blueprint is not present. Setup is incomplete!")
else:
try:
rbp = SiteBlueprint.q.get_by(site=root,blueprint=static_bp,path="")
except NoData:
rbp = SiteBlueprint.new(site=root,blueprint=static_bp,path="",name="static",endpoint="")
logger.debug("Root site's static blueprint created.")
else:
if rbp.name != "static" and force:
logger.warn("Root site's static blueprint name changed from ‘{}’ to ‘static’.".format(rbp.name))
rbp.name = "static"
if rbp.endpoint != "" and force:
logger.warn("Root site's static blueprint endpoint changed from ‘{}’ to ‘static’.".format(rbp.name))
rbp.endpoint = ""
db.session.flush()
# Add file types that may be uploaded
for typ,subtyp,ext,name,doc in upload_content_types:
mt = MIMEtype.q.get_by(typ=typ,subtyp=subtyp)
permit(root,root, right=PERM_ADD, new_objtyp=StaticFile.type, new_mimetyp=mt)
## All done!
logger.debug("Setup finished.")
db.session.commit()
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
870,
63,
1593,
12,
4629,
12,
2649,
63,
5955,
199,
309,
199,
309,
961,
365,
1777,
402,
1611,
20541,
12,
282,
644,
3053,
334,
5879,
12359,
8259,
6187,
9,
4079,
641,
199,
309,
17300,
18,
15,
40,
3935,
12,
22798,
12,
16704,
12,
436,
9319,
280,
1292,
77,
14,
199,
309,
199,
309,
1611,
20541,
365,
1898,
22405,
103,
8937,
13,
7280,
701,
18619,
273,
2241,
738,
82,
317,
32556,
665,
569,
273,
2241,
32,
300,
317,
32556,
14,
271,
6244,
199,
309,
652,
365,
18233,
1334,
314,
14629,
86,
19,
14,
1666,
314,
570,
658,
18195,
14,
1064,
64,
367,
2436,
12,
199,
309,
5893,
376,
5323,
6937,
9834,
701,
314,
4132,
14,
199,
309,
199,
309,
961,
13168,
365,
2599,
13,
10176,
436,
1443,
291,
13,
271,
1820,
737,
1263,
900,
12,
199,
309,
512,
300,
744,
89,
402,
298,
1875,
1678,
1674,
710,
3379,
365,
315,
27430,
247,
1208,
15607,
656,
27025,
14,
647,
21045,
14,
199,
309,
20227,
12,
8749,
886,
440,
2813,
314,
2163,
1004,
12,
503,
5518,
1263,
4596,
2385,
14,
199,
309,
24408,
199,
199,
646,
747,
199,
646,
2050,
199,
646,
295,
199,
504,
5190,
492,
870,
63,
2804,
12,
908,
63,
2804,
199,
199,
504,
7209,
492,
1056,
12,
485,
571,
63,
3799,
63,
2340,
199,
504,
7209,
423,
5819,
492,
1318,
63,
466,
12,
875,
63,
1313,
199,
199,
504,
2508,
492,
24877,
63,
3243,
12,
27815,
63,
3243,
199,
504,
2508,
1208,
492,
2196,
63,
875,
12,
1763,
13735,
199,
504,
2508,
1018,
492,
1101,
199,
504,
2508,
1018,
14,
697,
492,
1592,
12,
3091,
1451,
199,
504,
2508,
1018,
14,
525,
492,
2112,
63,
578,
199,
504,
1275,
492,
5817,
12,
2602,
199,
199,
2921,
275,
2050,
14,
5572,
360,
647,
20541,
14,
2609,
14,
13817,
358,
199,
199,
63,
2343,
275,
295,
14,
2014,
360,
309,
26,
31,
2961,
51,
8771,
627,
59,
12228,
627,
19276,
2862,
78,
358,
327,
295,
14,
53,
5805,
199,
199,
5064,
63,
1317,
63,
1313,
275,
359,
199,
198,
309,
14735,
730,
12,
10512,
12,
570,
3329,
12,
536,
12,
1369,
199,
198,
360,
505,
1673,
1360,
1673,
1360,
1673,
5926,
2034,
297,
2,
33,
4890,
4163,
13,
16841,
3330,
2034,
1288,
199,
198,
360,
505,
1673,
6104,
1673,
2424,
1673,
20711,
1318,
297,
2,
1773,
1318,
12,
949,
10803,
1288,
199,
198,
360,
505,
1673,
9554,
1673,
3596,
297,
2,
21986,
401,
403,
395,
199,
198,
360,
505,
1673,
3919,
1673,
3919,
297,
2,
14391,
401,
403,
395,
199,
198,
360,
1569,
1673,
4524,
1673,
4524,
297,
2,
24454,
1834,
401,
403,
395,
199,
198,
360,
1569,
1673,
14230,
297,
360,
8476,
1673,
14230,
659,
2,
28412,
1834,
401,
403,
395,
199,
198,
360,
1569,
1673,
14513,
1673,
14513,
297,
2,
39,
4656,
1834,
401,
403,
395,
199,
198,
360,
3578,
1673,
3008,
1673,
1393,
297,
2,
1773,
666,
401,
403,
395,
199,
198,
360,
3578,
1673,
5607,
1673,
5607,
297,
2,
7638,
2213,
401,
403,
395,
199,
61,
199,
17057,
275,
5802,
63,
1317,
63,
1313,
21324,
199,
198,
360,
3578,
1673,
13614,
11,
1652,
1673,
13614,
297,
2,
22786,
4733,
401,
403,
395,
199,
198,
360,
505,
1673,
1652,
1673,
1652,
297,
2,
4317,
666,
401,
403,
395,
199,
198,
360,
1188,
1673,
8973,
10228,
297,
403,
4589,
7035,
1245,
401,
403,
395,
421,
198,
360,
647,
20541,
1673,
63,
1667,
297,
403,
4589,
889,
666,
401,
403,
395,
421,
198,
360,
647,
20541,
1673,
7693,
403,
4589,
1629,
1134,
20541,
666,
401,
403,
395,
199,
198,
360,
1360,
1673,
7693,
403,
4589,
1629,
3517,
666,
401,
403,
395,
199,
198,
360,
505,
1673,
7693,
403,
4589,
1629,
1318,
666,
401,
403,
395,
421,
198,
360,
1360,
1673,
954,
1606,
297,
403,
12,
1763,
13735,
4589,
65,
334,
973,
9,
1777,
402,
282,
9248,
1288,
199,
198,
360,
1360,
1673,
875,
297,
403,
12,
1763,
13735,
4589,
65,
3974,
1059,
13660,
376,
909,
1288,
199,
198,
360,
1360,
1673,
5506,
297,
403,
12,
1763,
13735,
4589,
65,
5174,
2238,
2455,
402,
376,
909,
1159,
5007,
1174,
1288,
199,
198,
360,
1360,
1673,
18547,
297,
403,
12,
1763,
13735,
4589,
65,
7956,
367,
314,
15868,
264,
2455,
1288,
199,
198,
360,
1360,
1673,
14861,
297,
403,
12,
1763,
13735,
4589,
65,
7956,
367,
24787,
2455,
4453,
282,
2034,
1288,
199,
198,
360,
1360,
1673,
7780,
297,
403,
12,
1763,
13735,
4589,
65,
2455,
367,
19653,
316,
1288,
199,
198,
360,
1360,
1673,
3773,
297,
403,
12,
1763,
13735,
4589,
1589,
1824,
367,
20401,
1288,
199,
198,
360,
1652,
1673,
13614,
297,
403,
12,
1763,
13735,
4589,
65,
7956,
367,
314,
30331,
4733,
1288,
199,
61,
199,
199,
11429,
275,
334,
199,
198,
7,
647,
20541,
14,
1018,
14,
992,
14,
1113,
9749,
14,
5665,
804,
297,
199,
198,
7,
647,
20541,
14,
1018,
14,
992,
14,
888,
14,
2028,
5894,
297,
199,
198,
7,
647,
20541,
14,
1018,
14,
992,
14,
888,
14,
2028,
1451,
297,
199,
198,
7,
647,
20541,
14,
1018,
14,
992,
14,
888,
14,
8972,
2028,
5894,
297,
199,
198,
7,
647,
20541,
14,
1018,
14,
992,
14,
2124,
14,
2640,
297,
199,
198,
7,
647,
20541,
14,
1018,
14,
992,
14,
2124,
14,
15617,
1361,
297,
199,
198,
7,
647,
20541,
14,
1018,
14,
992,
14,
2124,
14,
8972,
297,
199,
198,
7,
647,
20541,
14,
1018,
14,
992,
14,
2124,
14,
8972,
15617,
1361,
297,
199,
198,
7,
647,
20541,
14,
1018,
14,
992,
14,
751,
14,
1899,
297,
199,
198,
7,
647,
20541,
14,
1018,
14,
992,
14,
751,
14,
2448,
297,
199,
198,
7,
647,
20541,
14,
1018,
14,
992,
14,
751,
14,
7021,
297,
199,
198,
7,
647,
20541,
14,
1018,
14,
992,
14,
14428,
14,
23785,
1692,
297,
199,
198,
7,
647,
20541,
14,
1018,
14,
992,
14,
14428,
14,
34,
25972,
4295,
297,
199,
198,
7,
647,
20541,
14,
1018,
14,
992,
14,
14428,
14,
4001,
297,
199,
198,
7,
647,
20541,
14,
1018,
14,
992,
14,
14428,
14,
5392,
297,
199,
198,
7
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
870,
63,
1593,
12,
4629,
12,
2649,
63,
5955,
199,
309,
199,
309,
961,
365,
1777,
402,
1611,
20541,
12,
282,
644,
3053,
334,
5879,
12359,
8259,
6187,
9,
4079,
641,
199,
309,
17300,
18,
15,
40,
3935,
12,
22798,
12,
16704,
12,
436,
9319,
280,
1292,
77,
14,
199,
309,
199,
309,
1611,
20541,
365,
1898,
22405,
103,
8937,
13,
7280,
701,
18619,
273,
2241,
738,
82,
317,
32556,
665,
569,
273,
2241,
32,
300,
317,
32556,
14,
271,
6244,
199,
309,
652,
365,
18233,
1334,
314,
14629,
86,
19,
14,
1666,
314,
570,
658,
18195,
14,
1064,
64,
367,
2436,
12,
199,
309,
5893,
376,
5323,
6937,
9834,
701,
314,
4132,
14,
199,
309,
199,
309,
961,
13168,
365,
2599,
13,
10176,
436,
1443,
291,
13,
271,
1820,
737,
1263,
900,
12,
199,
309,
512,
300,
744,
89,
402,
298,
1875,
1678,
1674,
710,
3379,
365,
315,
27430,
247,
1208,
15607,
656,
27025,
14,
647,
21045,
14,
199,
309,
20227,
12,
8749,
886,
440,
2813,
314,
2163,
1004,
12,
503,
5518,
1263,
4596,
2385,
14,
199,
309,
24408,
199,
199,
646,
747,
199,
646,
2050,
199,
646,
295,
199,
504,
5190,
492,
870,
63,
2804,
12,
908,
63,
2804,
199,
199,
504,
7209,
492,
1056,
12,
485,
571,
63,
3799,
63,
2340,
199,
504,
7209,
423,
5819,
492,
1318,
63,
466,
12,
875,
63,
1313,
199,
199,
504,
2508,
492,
24877,
63,
3243,
12,
27815,
63,
3243,
199,
504,
2508,
1208,
492,
2196,
63,
875,
12,
1763,
13735,
199,
504,
2508,
1018,
492,
1101,
199,
504,
2508,
1018,
14,
697,
492,
1592,
12,
3091,
1451,
199,
504,
2508,
1018,
14,
525,
492,
2112,
63,
578,
199,
504,
1275,
492,
5817,
12,
2602,
199,
199,
2921,
275,
2050,
14,
5572,
360,
647,
20541,
14,
2609,
14,
13817,
358,
199,
199,
63,
2343,
275,
295,
14,
2014,
360,
309,
26,
31,
2961,
51,
8771,
627,
59,
12228,
627,
19276,
2862,
78,
358,
327,
295,
14,
53,
5805,
199,
199,
5064,
63,
1317,
63,
1313,
275,
359,
199,
198,
309,
14735,
730,
12,
10512,
12,
570,
3329,
12,
536,
12,
1369,
199,
198,
360,
505,
1673,
1360,
1673,
1360,
1673,
5926,
2034,
297,
2,
33,
4890,
4163,
13,
16841,
3330,
2034,
1288,
199,
198,
360,
505,
1673,
6104,
1673,
2424,
1673,
20711,
1318,
297,
2,
1773,
1318,
12,
949,
10803,
1288,
199,
198,
360,
505,
1673,
9554,
1673,
3596,
297,
2,
21986,
401,
403,
395,
199,
198,
360,
505,
1673,
3919,
1673,
3919,
297,
2,
14391,
401,
403,
395,
199,
198,
360,
1569,
1673,
4524,
1673,
4524,
297,
2,
24454,
1834,
401,
403,
395,
199,
198,
360,
1569,
1673,
14230,
297,
360,
8476,
1673,
14230,
659,
2,
28412,
1834,
401,
403,
395,
199,
198,
360,
1569,
1673,
14513,
1673,
14513,
297,
2,
39,
4656,
1834,
401,
403,
395,
199,
198,
360,
3578,
1673,
3008,
1673,
1393,
297,
2,
1773,
666,
401,
403,
395,
199,
198,
360,
3578,
1673,
5607,
1673,
5607,
297,
2,
7638,
2213,
401,
403,
395,
199,
61,
199,
17057,
275,
5802,
63,
1317,
63,
1313,
21324,
199,
198,
360,
3578,
1673,
13614,
11,
1652,
1673,
13614,
297,
2,
22786,
4733,
401,
403,
395,
199,
198,
360,
505,
1673,
1652,
1673,
1652,
297,
2,
4317,
666,
401,
403,
395,
199,
198,
360,
1188,
1673,
8973,
10228,
297,
403,
4589,
7035,
1245,
401,
403,
395,
421,
198,
360,
647,
20541,
1673,
63,
1667,
297,
403,
4589,
889,
666,
401,
403,
395,
421,
198,
360,
647,
20541,
1673,
7693,
403,
4589,
1629,
1134,
20541,
666,
401,
403,
395,
199,
198,
360,
1360,
1673,
7693,
403,
4589,
1629,
3517,
666,
401,
403,
395,
199,
198,
360,
505,
1673,
7693,
403,
4589,
1629,
1318,
666,
401,
403,
395,
421,
198,
360,
1360,
1673,
954,
1606,
297,
403,
12,
1763,
13735,
4589,
65,
334,
973,
9,
1777,
402,
282,
9248,
1288,
199,
198,
360,
1360,
1673,
875,
297,
403,
12,
1763,
13735,
4589,
65,
3974,
1059,
13660,
376,
909,
1288,
199,
198,
360,
1360,
1673,
5506,
297,
403,
12,
1763,
13735,
4589,
65,
5174,
2238,
2455,
402,
376,
909,
1159,
5007,
1174,
1288,
199,
198,
360,
1360,
1673,
18547,
297,
403,
12,
1763,
13735,
4589,
65,
7956,
367,
314,
15868,
264,
2455,
1288,
199,
198,
360,
1360,
1673,
14861,
297,
403,
12,
1763,
13735,
4589,
65,
7956,
367,
24787,
2455,
4453,
282,
2034,
1288,
199,
198,
360,
1360,
1673,
7780,
297,
403,
12,
1763,
13735,
4589,
65,
2455,
367,
19653,
316,
1288,
199,
198,
360,
1360,
1673,
3773,
297,
403,
12,
1763,
13735,
4589,
1589,
1824,
367,
20401,
1288,
199,
198,
360,
1652,
1673,
13614,
297,
403,
12,
1763,
13735,
4589,
65,
7956,
367,
314,
30331,
4733,
1288,
199,
61,
199,
199,
11429,
275,
334,
199,
198,
7,
647,
20541,
14,
1018,
14,
992,
14,
1113,
9749,
14,
5665,
804,
297,
199,
198,
7,
647,
20541,
14,
1018,
14,
992,
14,
888,
14,
2028,
5894,
297,
199,
198,
7,
647,
20541,
14,
1018,
14,
992,
14,
888,
14,
2028,
1451,
297,
199,
198,
7,
647,
20541,
14,
1018,
14,
992,
14,
888,
14,
8972,
2028,
5894,
297,
199,
198,
7,
647,
20541,
14,
1018,
14,
992,
14,
2124,
14,
2640,
297,
199,
198,
7,
647,
20541,
14,
1018,
14,
992,
14,
2124,
14,
15617,
1361,
297,
199,
198,
7,
647,
20541,
14,
1018,
14,
992,
14,
2124,
14,
8972,
297,
199,
198,
7,
647,
20541,
14,
1018,
14,
992,
14,
2124,
14,
8972,
15617,
1361,
297,
199,
198,
7,
647,
20541,
14,
1018,
14,
992,
14,
751,
14,
1899,
297,
199,
198,
7,
647,
20541,
14,
1018,
14,
992,
14,
751,
14,
2448,
297,
199,
198,
7,
647,
20541,
14,
1018,
14,
992,
14,
751,
14,
7021,
297,
199,
198,
7,
647,
20541,
14,
1018,
14,
992,
14,
14428,
14,
23785,
1692,
297,
199,
198,
7,
647,
20541,
14,
1018,
14,
992,
14,
14428,
14,
34,
25972,
4295,
297,
199,
198,
7,
647,
20541,
14,
1018,
14,
992,
14,
14428,
14,
4001,
297,
199,
198,
7,
647,
20541,
14,
1018,
14,
992,
14,
14428,
14,
5392,
297,
199,
198,
7,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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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
] |
mank319/elementaryPlus
|
scripts/custom/core_icon_theme.py
|
2
|
1605
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# core.py core icon theme custom install script
#
# Copyright (C) 2015 Stefan Ric (cybre)
#
# 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, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
import sys
import os
from os import symlink
from os.path import expanduser
import shutil
themeDir = os.getcwd() + "/elementaryPlus"
home = expanduser("~")
destDir = home + "/.icons/"
destDir2 = home + "/.local/share/icons/"
def installCoreIconTheme():
if not os.path.exists(destDir):
os.makedirs(destDir)
try:
shutil.copytree(themeDir, destDir + "elementaryPlus")
except:
exit(1)
def removeCoreIconTheme():
if os.path.exists(destDir):
try:
shutil.rmtree(destDir + "elementaryPlus")
shutil.rmtree(destDir2 + "elementaryPlus")
except OSError:
pass
if sys.argv[1] == "--install":
installCoreIconTheme()
elif sys.argv[1] == "--remove":
removeCoreIconTheme()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
6170,
14,
647,
6170,
7016,
8879,
3537,
3907,
2884,
199,
3,
199,
3,
1898,
334,
35,
9,
6900,
221,
17854,
12269,
820,
530,
334,
1480,
10205,
9,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
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,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
2752,
12,
199,
3,
3277,
2020,
8026,
11236,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
11315,
13,
10067,
221,
8217,
199,
646,
984,
199,
646,
747,
199,
504,
747,
492,
15296,
199,
504,
747,
14,
515,
492,
6544,
751,
199,
646,
5145,
199,
199,
7915,
3567,
275,
747,
14,
9458,
342,
435,
3286,
2108,
695,
25800,
2,
199,
4219,
275,
6544,
751,
20793,
531,
199,
2614,
3567,
275,
5629,
435,
3286,
14,
16471,
6687,
199,
2614,
3567,
18,
275,
5629,
435,
3286,
14,
1832,
15,
6251,
15,
16471,
6687,
421,
199,
318,
3907,
5402,
8954,
16849,
837,
272,
340,
440,
747,
14,
515,
14,
2444,
8,
2614,
3567,
304,
267,
747,
14,
8347,
8,
2614,
3567,
9,
272,
862,
26,
267,
5145,
14,
29296,
8,
7915,
3567,
12,
2053,
3567,
435,
298,
2108,
695,
25800,
531,
272,
871,
26,
267,
4458,
8,
17,
9,
421,
199,
318,
2813,
5402,
8954,
16849,
837,
272,
340,
747,
14,
515,
14,
2444,
8,
2614,
3567,
304,
267,
862,
26,
288,
5145,
14,
9242,
8,
2614,
3567,
435,
298,
2108,
695,
25800,
531,
288,
5145,
14,
9242,
8,
2614,
3567,
18,
435,
298,
2108,
695,
25800,
531,
267,
871,
6440,
26,
288,
986,
199,
199,
692,
984,
14,
3020,
59,
17,
61,
508,
4320,
3174,
582,
272,
3907,
5402,
8954,
16849,
342,
199,
4164,
984,
14,
3020,
59,
17,
61,
508,
4320,
2168,
582,
272,
2813,
5402,
8954,
16849,
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
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
6170,
14,
647,
6170,
7016,
8879,
3537,
3907,
2884,
199,
3,
199,
3,
1898,
334,
35,
9,
6900,
221,
17854,
12269,
820,
530,
334,
1480,
10205,
9,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
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,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
2752,
12,
199,
3,
3277,
2020,
8026,
11236,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
11315,
13,
10067,
221,
8217,
199,
646,
984,
199,
646,
747,
199,
504,
747,
492,
15296,
199,
504,
747,
14,
515,
492,
6544,
751,
199,
646,
5145,
199,
199,
7915,
3567,
275,
747,
14,
9458,
342,
435,
3286,
2108,
695,
25800,
2,
199,
4219,
275,
6544,
751,
20793,
531,
199,
2614,
3567,
275,
5629,
435,
3286,
14,
16471,
6687,
199,
2614,
3567,
18,
275,
5629,
435,
3286,
14,
1832,
15,
6251,
15,
16471,
6687,
421,
199,
318,
3907,
5402,
8954,
16849,
837,
272,
340,
440,
747,
14,
515,
14,
2444,
8,
2614,
3567,
304,
267,
747,
14,
8347,
8,
2614,
3567,
9,
272,
862,
26,
267,
5145,
14,
29296,
8,
7915,
3567,
12,
2053,
3567,
435,
298,
2108,
695,
25800,
531,
272,
871,
26,
267,
4458,
8,
17,
9,
421,
199,
318,
2813,
5402,
8954,
16849,
837,
272,
340,
747,
14,
515,
14,
2444,
8,
2614,
3567,
304,
267,
862,
26,
288,
5145,
14,
9242,
8,
2614,
3567,
435,
298,
2108,
695,
25800,
531,
288,
5145,
14,
9242,
8,
2614,
3567,
18,
435,
298,
2108,
695,
25800,
531,
267,
871,
6440,
26,
288,
986,
199,
199,
692,
984,
14,
3020,
59,
17,
61,
508,
4320,
3174,
582,
272,
3907,
5402,
8954,
16849,
342,
199,
4164,
984,
14,
3020,
59,
17,
61,
508,
4320,
2168,
582,
272,
2813,
5402,
8954,
16849,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
godLoveLucifer/viewfinder
|
backend/services/test/itunes_store_test.py
|
13
|
11379
|
# Copyright 2012 Viewfinder Inc. All rights reserved.
__author__ = 'ben@emailscrubbed.com (Ben Darnell)'
import base64
import datetime
import functools
import json
import time
from tornado import options
from viewfinder.backend.base import base_options, secrets
from viewfinder.backend.base.testing import BaseTestCase, MockAsyncHTTPClient
from viewfinder.backend.services.itunes_store import ITunesStoreClient, ITunesStoreError
# Constants for expected values of various fields for our test data.
kProductId = 'vf_sub1_month'
kTransactionId = '1000000056588946'
kTransactionId2 = '1000000056589752'
kExpirationTime = 1349159462.502
kExpirationTime2 = 1349160962.000
# Sample receipt data for testing. Note that while receipts are currently
# json, apple's docs warn that it is to be treated as an opaque blob,
# and decoded only by passing it to the store for verification.
# None of the tests care about this data, but it's here for reference.
# Verifying this data results in kVerifyResponseExpired.
kReceiptData = """\
{
"signature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oJInByb2R1Y3QtaWQiID0gInRlc3Rfc3ViMV9tb250aCI7CgkicHVyY2hhc2UtZGF0ZSIgPSAiMjAxMi0xMC0wMiAwNjoyNjowMiBFdGMvR01UIjsKCSJvcmlnaW5hbC1wdXJjaGFzZS1kYXRlIiA9ICIyMDEyLTEwLTAyIDA2OjI2OjAzIEV0Yy9HTVQiOwoJImJpZCIgPSAiY28udmlld2ZpbmRlci5WaWV3ZmluZGVyIjsKCSJwdXJjaGFzZS1kYXRlLXBzdCIgPSAiMjAxMi0xMC0wMSAyMzoyNjowMiBBbWVyaWNhL0xvc19BbmdlbGVzIjsKCSJxdWFudGl0eSIgPSAiMSI7Cn0=";
"environment" = "Sandbox";
"pod" = "100";
"signing-status" = "0";
}"""
# Sample responses from the server.
# A receipt which was valid, renewed at least once, then expired.
kVerifyResponseRenewedExpired = """\
{
"status": 21006,
"receipt": {
"purchase_date_pst": "2012-10-01 23:26:02 America/Los_Angeles",
"expires_date": "1349159462502",
"product_id": "vf_sub1_month",
"original_transaction_id": "1000000056588946",
"unique_identifier": "b84eaad25ddc084faecca09c44f7d63ade7a46a2",
"original_purchase_date_pst": "2012-10-01 23:26:03 America/Los_Angeles",
"expires_date_formatted_pst": "2012-10-01 23:31:02 America/Los_Angeles",
"original_purchase_date": "2012-10-02 06:26:03 Etc/GMT",
"expires_date_formatted": "2012-10-02 06:31:02 Etc/GMT",
"bvrs": "3",
"original_purchase_date_ms": "1349159163313",
"purchase_date": "2012-10-02 06:26:02 Etc/GMT",
"web_order_line_item_id": "1000000026273315",
"purchase_date_ms": "1349159162502",
"item_id": "564959566",
"bid": "co.viewfinder.Viewfinder",
"transaction_id": "1000000056588946",
"quantity": "1"
},
"latest_expired_receipt_info": {
"purchase_date_pst": "2012-10-01 23:51:02 America/Los_Angeles",
"expires_date": "1349160962000",
"product_id": "vf_sub1_month",
"original_transaction_id": "1000000056588946",
"unique_identifier": "b84eaad25ddc084faecca09c44f7d63ade7a46a2",
"original_purchase_date_pst": "2012-10-01 23:26:03 America/Los_Angeles",
"expires_date_formatted_pst": "2012-10-01 23:56:02 America/Los_Angeles",
"original_purchase_date": "2012-10-02 06:26:03 Etc/GMT",
"expires_date_formatted": "2012-10-02 06:56:02 Etc/GMT",
"bvrs": "3",
"original_purchase_date_ms": "1349159163000",
"purchase_date": "2012-10-02 06:51:02 Etc/GMT",
"web_order_line_item_id": "1000000026273346",
"purchase_date_ms": "1349160662000",
"item_id": "564959566",
"bid": "co.viewfinder.Viewfinder",
"transaction_id": "1000000056589752",
"quantity": "1"
}
}
"""
# Construct several different responses using kVerifyResponseRenewedExpired
# as a reference.
def MakeRenewedExpiredResponse():
"""Returns a response for a subscription which expired after at least one
renewal.
"""
return kVerifyResponseRenewedExpired
def MakeNewResponse():
"""Returns a response for a subscription which has not been renewed
or expired. This is the expected case for subscriptions sent up by
the client.
"""
reference = json.loads(kVerifyResponseRenewedExpired)
return json.dumps({'status': 0, 'receipt': reference['receipt']})
def MakeFreshResponse():
"""Returns a response for a subscription which has an expiration date in
the future. Note that the metadata here may be inconsistent, since only
the expiration date is changed from an old receipt template.
"""
reference = json.loads(kVerifyResponseRenewedExpired)
new = {'status': 0, 'receipt': reference['receipt']}
new['receipt']['expires_date'] = 1000.0 * (time.time() + datetime.timedelta(days=28).total_seconds())
return json.dumps(new)
def MakeRenewedResponse():
"""Returns a response with an unexpired renewal."""
reference = json.loads(kVerifyResponseRenewedExpired)
return json.dumps({
'status': 0,
'receipt': reference['receipt'],
'latest_receipt': base64.b64encode("fake encoded receipt"),
'latest_expired_receipt_info': reference['latest_expired_receipt_info'],
})
def MakeExpiredResponse():
"""Returns a response that expired without ever being renewed."""
reference = json.loads(kVerifyResponseRenewedExpired)
# just like the original, but no 'latest_expired_receipt_info'
return json.dumps({'status': reference['status'], 'receipt': reference['receipt']})
def MakeBadSignatureResponse():
"""Returns a status code indicating an invalid signature."""
return '{"status": 21003}'
def MakeServerErrorResponse():
"""Returns a status code indicating a (possibly transient) server error."""
return '{"status": 21005}'
def MakeSandboxOnProdResponse():
"""Returns a status code indicating a sandbox receipt on the production
iTunes server.
"""
return '{"status": 21007}'
def MakeOtherAppResponse():
"""Make a response for a valid receipt from another app.
iTunes just verifies that the receipt was issued by Apple; we need to
verify that it came from our own app.
"""
reference = json.loads(kVerifyResponseRenewedExpired)
new = {'status': 0, 'receipt': reference['receipt']}
new['receipt']['bid'] = 'com.angrybirds.AngryBirds'
return json.dumps(new)
class ITunesStoreTest(BaseTestCase):
def setUp(self):
super(ITunesStoreTest, self).setUp()
options.options.domain = 'goviewfinder.com'
secrets.InitSecretsForTest()
def VerifyReceipt(self, response, request):
request_data = json.loads(request.body)
self.assertEqual(sorted(request_data.keys()), ['password', 'receipt-data'])
return response
def GetResponse(self, raw_response):
mock_http = MockAsyncHTTPClient()
mock_http.map(r"https://.*\.itunes\.apple\.com/verifyReceipt",
functools.partial(self.VerifyReceipt, raw_response))
client = ITunesStoreClient(http_client=mock_http)
client.VerifyReceipt(kReceiptData, self.stop)
response = self.wait()
return response
def test_verify_renewed_expired(self):
response = self.GetResponse(MakeRenewedExpiredResponse())
self.assertTrue(response.IsValid())
self.assertEqual(response.GetProductId(), kProductId)
# expiration time comes from the second receipt
self.assertEqual(response.GetExpirationTime(), kExpirationTime2)
self.assertTrue(response.IsExpired())
self.assertFalse(response.IsRenewable())
self.assertEqual(response.GetOriginalTransactionId(), kTransactionId)
self.assertEqual(response.GetRenewalTransactionId(), kTransactionId2)
def test_verify_new(self):
response = self.GetResponse(MakeNewResponse())
self.assertTrue(response.IsValid())
self.assertEqual(response.GetProductId(), kProductId)
self.assertEqual(response.GetExpirationTime(), kExpirationTime)
self.assertTrue(response.IsRenewable())
self.assertEqual(response.GetRenewalData(), kReceiptData)
self.assertEqual(response.GetOriginalTransactionId(), kTransactionId)
self.assertEqual(response.GetRenewalTransactionId(), kTransactionId)
def test_verify_renewed(self):
response = self.GetResponse(MakeRenewedResponse())
self.assertTrue(response.IsValid())
self.assertEqual(response.GetProductId(), kProductId)
self.assertEqual(response.GetExpirationTime(), kExpirationTime2)
self.assertTrue(response.IsRenewable())
self.assertEqual(response.GetRenewalData(), "fake encoded receipt")
self.assertEqual(response.GetOriginalTransactionId(), kTransactionId)
self.assertEqual(response.GetRenewalTransactionId(), kTransactionId2)
def test_verify_expired(self):
response = self.GetResponse(MakeExpiredResponse())
self.assertTrue(response.IsValid())
self.assertEqual(response.GetProductId(), kProductId)
self.assertEqual(response.GetExpirationTime(), kExpirationTime)
self.assertTrue(response.IsExpired())
self.assertFalse(response.IsRenewable())
self.assertEqual(response.GetOriginalTransactionId(), kTransactionId)
self.assertEqual(response.GetRenewalTransactionId(), kTransactionId)
def test_verify_bad_signature(self):
response = self.GetResponse(MakeBadSignatureResponse())
self.assertFalse(response.IsValid())
def test_verify_server_error(self):
response = self.GetResponse(MakeServerErrorResponse())
self.assertRaises(ITunesStoreError, response.IsValid)
def test_verify_other_app(self):
response = self.GetResponse(MakeOtherAppResponse())
self.assertFalse(response.IsValid())
|
apache-2.0
|
[
3,
1898,
6029,
10935,
11681,
3277,
14,
2900,
4481,
4644,
14,
199,
199,
363,
2502,
363,
275,
283,
18486,
32,
2123,
11047,
456,
6123,
14,
957,
334,
31231,
577,
1060,
1697,
3171,
199,
199,
646,
1300,
772,
199,
646,
2197,
199,
646,
9143,
199,
646,
2022,
199,
646,
900,
199,
199,
504,
12148,
492,
1511,
199,
504,
2455,
11681,
14,
4620,
14,
1095,
492,
1300,
63,
1419,
12,
25563,
199,
504,
2455,
11681,
14,
4620,
14,
1095,
14,
4776,
492,
3523,
1746,
12,
4420,
12807,
27757,
199,
504,
2455,
11681,
14,
4620,
14,
5950,
14,
390,
324,
397,
63,
1617,
492,
473,
22664,
397,
5502,
3041,
12,
473,
22664,
397,
5502,
547,
199,
199,
3,
22296,
367,
1420,
1338,
402,
7750,
1504,
367,
4154,
511,
666,
14,
199,
75,
5884,
1304,
275,
283,
19963,
63,
954,
17,
63,
4482,
7,
199,
75,
10161,
1304,
275,
283,
17,
9084,
15670,
13976,
2466,
7,
199,
75,
10161,
1304,
18,
275,
283,
17,
9084,
15670,
1407,
18778,
7,
199,
75,
14000,
1754,
1366,
275,
413,
11991,
9327,
24509,
14,
24653,
199,
75,
14000,
1754,
1366,
18,
275,
413,
11991,
975,
1643,
2789,
14,
1493,
199,
199,
3,
15227,
31594,
666,
367,
5343,
14,
221,
3390,
626,
1830,
295,
301,
73,
8382,
787,
5544,
199,
3,
2022,
12,
1145,
274,
1159,
9149,
7987,
626,
652,
365,
370,
506,
10184,
465,
376,
15058,
9182,
12,
199,
3,
436,
11203,
1454,
701,
9476,
652,
370,
314,
3877,
367,
14786,
14,
199,
3,
488,
402,
314,
2295,
10296,
3595,
642,
666,
12,
1325,
652,
1159,
2348,
367,
3659,
14,
199,
3,
7635,
316,
642,
666,
2058,
315,
1022,
7496,
2364,
20898,
14,
199,
75,
497,
13866,
1451,
275,
9638,
199,
91,
1362,
198,
2,
5233,
2,
275,
298,
24566,
23,
33,
845,
4323,
65,
25620,
1165,
85,
54,
17,
87,
7872,
42,
28808,
5466,
18,
53,
40,
17,
10343,
19,
55,
67,
20,
23215,
72,
23,
25606,
33,
4622,
40,
23,
3596,
37,
65,
19,
1668,
83,
25,
18926,
87,
16,
39,
21,
74,
2371,
87,
48,
1812,
88,
41,
21,
11,
42,
67,
51,
18,
35,
1949,
53,
55,
9741,
16,
66,
9745,
18505,
49,
75,
16,
16596,
39,
2411,
46,
82,
35,
81,
19,
2944,
54,
1407,
66,
25,
54,
16,
45,
2709,
89,
34,
22,
2533,
33,
7697,
1079,
87,
1587,
58,
23298,
56,
71,
723,
75,
18256,
42,
58,
517,
2177,
42,
75,
7308,
87,
37,
15,
25,
66,
42,
86,
19,
13860,
18,
15,
19445,
1440,
58,
11821,
38,
7862,
21,
41,
1352,
2276,
1554,
54,
90,
2571,
33,
17,
45,
87,
2721,
41,
23,
79,
1156,
3263,
49,
948,
4064,
4622,
75,
53,
19,
14324,
1179,
17,
2054,
16,
39,
3298,
81,
39,
2684,
66,
19,
11888,
37,
5342,
2328,
1156,
40,
24,
8163,
6353,
42,
23571,
7312,
34,
3448,
52,
2439,
8156,
45,
11026,
87,
17420,
57,
6741,
12917,
43,
8980,
80,
34,
67,
25262,
30587,
12463,
42,
12648,
16215,
3053,
57,
87,
42,
3448,
6741,
49,
2940,
2846,
17,
34,
67,
25262,
83,
26697,
11156,
15473,
42,
16,
19098,
58,
80,
57,
18,
38,
16,
19098,
25,
85,
4332,
38,
17,
28929,
72,
6737,
757,
16,
69,
3727,
90,
45,
1093,
9741,
17,
4187,
33,
978,
81,
49,
20806,
6603,
17188,
5294,
20271,
17,
12648,
54,
90,
4656,
46,
16,
66,
19,
31182,
41,
742,
76,
6413,
50,
80,
58,
757,
74,
57,
12297,
3317,
1194,
71,
49,
56,
54,
16,
65,
39,
25,
11552,
12297,
21,
4567,
20,
18184,
6166,
21,
5127,
57,
88,
12460,
41,
89,
45,
4980,
17,
46,
320,
18184,
3727,
16,
5127,
57,
31985,
1914,
89,
45,
4980,
17,
46,
674,
58,
1093,
74,
45,
2089,
9741,
17,
4187,
26917,
758,
53,
16566,
89,
57,
18,
12156,
67,
18,
7428,
58,
3705,
416,
20806,
16,
49,
18,
54,
24503,
17541,
391,
3705,
7952,
17188,
88,
39,
6353,
58,
23571,
7312,
34,
2822,
3635,
75,
38,
13683,
39,
15455,
1277,
76,
53,
68,
55,
21,
76,
1480,
19162,
28929,
25,
89,
58,
52,
775,
4567,
4680,
33,
17,
4187,
35,
8392,
24817,
20806,
6603,
17188,
71,
8745,
21,
74,
15573,
2901,
2054,
75,
9741,
17,
4187,
34,
72,
7608,
54,
6849,
23596,
58,
24,
87,
11888,
57,
25575,
79,
58,
41,
72,
6737,
7170,
31668,
5342,
49,
1554,
71,
57,
16,
1156,
1277,
29849,
79,
6487,
1156,
82,
50,
74,
38,
18,
319,
20,
32602,
51,
328,
52,
1049,
65,
41,
16,
71,
24,
8796,
86,
15,
4400,
40,
83,
24,
80,
15,
50,
87,
54,
15,
2591,
15,
3328,
56,
43,
54,
72,
25940,
20,
56,
2100,
1017,
43,
74,
12917,
46,
9681,
40,
83,
26606,
22,
89,
27764,
4176,
21733,
43,
25074,
23,
85,
43,
7616,
45,
617,
32640,
70,
5100,
21,
82,
39,
56,
83,
2767,
6773,
74,
34,
87,
6129,
88,
476,
6301,
18843,
19,
40,
906,
27453,
1271,
17,
573,
43,
88,
6576,
7821,
88,
280,
1304,
36,
71,
42,
86,
18,
28786,
20343,
1887,
34,
16,
85,
42,
86,
46,
8161,
22,
4029,
81,
7178,
44,
40,
83,
8045,
90,
3177,
25,
79,
58,
40,
5676,
45,
4134,
1254,
22760,
74,
34,
87,
2054,
87,
9741,
17,
53,
68,
37,
87,
14138,
15,
87,
49,
35,
2054,
26917,
24482,
57,
6741,
50,
16,
74,
5342,
8392,
15563,
33,
1734,
72,
19,
79,
20,
80,
18,
35,
16,
71,
8682,
84,
52,
42,
82,
36,
2076,
5196,
21,
18114,
49,
90,
583,
36,
71,
57,
6741,
50,
16,
8470,
27088,
15,
4134,
49,
8980,
303,
1156,
34,
16,
9741,
17,
53,
68,
36,
71,
49,
55,
5342,
51,
4198,
20,
2713,
17188,
74,
38,
5663,
42,
56,
9956,
20690,
8076,
46,
11,
25489,
24,
75,
25,
6166,
31893,
1939,
81,
72,
8810,
39,
2942,
46,
75,
23571,
2533,
4134,
4656,
1554,
879,
23571,
75,
81,
72,
8810,
39,
25,
87,
16,
4134,
2328,
2078,
23320,
3263,
49,
11765,
37,
65,
51,
66,
48,
74,
7574,
46,
20,
35,
15,
2100,
19,
49,
14057,
43,
708,
50,
10104,
7695,
56,
68,
28493,
33,
27786,
497,
51,
21,
1906,
58,
1812,
11,
84,
1299,
80,
31208,
3129,
17975,
28000,
11549,
55,
15,
19,
69,
52,
4029
] |
[
1898,
6029,
10935,
11681,
3277,
14,
2900,
4481,
4644,
14,
199,
199,
363,
2502,
363,
275,
283,
18486,
32,
2123,
11047,
456,
6123,
14,
957,
334,
31231,
577,
1060,
1697,
3171,
199,
199,
646,
1300,
772,
199,
646,
2197,
199,
646,
9143,
199,
646,
2022,
199,
646,
900,
199,
199,
504,
12148,
492,
1511,
199,
504,
2455,
11681,
14,
4620,
14,
1095,
492,
1300,
63,
1419,
12,
25563,
199,
504,
2455,
11681,
14,
4620,
14,
1095,
14,
4776,
492,
3523,
1746,
12,
4420,
12807,
27757,
199,
504,
2455,
11681,
14,
4620,
14,
5950,
14,
390,
324,
397,
63,
1617,
492,
473,
22664,
397,
5502,
3041,
12,
473,
22664,
397,
5502,
547,
199,
199,
3,
22296,
367,
1420,
1338,
402,
7750,
1504,
367,
4154,
511,
666,
14,
199,
75,
5884,
1304,
275,
283,
19963,
63,
954,
17,
63,
4482,
7,
199,
75,
10161,
1304,
275,
283,
17,
9084,
15670,
13976,
2466,
7,
199,
75,
10161,
1304,
18,
275,
283,
17,
9084,
15670,
1407,
18778,
7,
199,
75,
14000,
1754,
1366,
275,
413,
11991,
9327,
24509,
14,
24653,
199,
75,
14000,
1754,
1366,
18,
275,
413,
11991,
975,
1643,
2789,
14,
1493,
199,
199,
3,
15227,
31594,
666,
367,
5343,
14,
221,
3390,
626,
1830,
295,
301,
73,
8382,
787,
5544,
199,
3,
2022,
12,
1145,
274,
1159,
9149,
7987,
626,
652,
365,
370,
506,
10184,
465,
376,
15058,
9182,
12,
199,
3,
436,
11203,
1454,
701,
9476,
652,
370,
314,
3877,
367,
14786,
14,
199,
3,
488,
402,
314,
2295,
10296,
3595,
642,
666,
12,
1325,
652,
1159,
2348,
367,
3659,
14,
199,
3,
7635,
316,
642,
666,
2058,
315,
1022,
7496,
2364,
20898,
14,
199,
75,
497,
13866,
1451,
275,
9638,
199,
91,
1362,
198,
2,
5233,
2,
275,
298,
24566,
23,
33,
845,
4323,
65,
25620,
1165,
85,
54,
17,
87,
7872,
42,
28808,
5466,
18,
53,
40,
17,
10343,
19,
55,
67,
20,
23215,
72,
23,
25606,
33,
4622,
40,
23,
3596,
37,
65,
19,
1668,
83,
25,
18926,
87,
16,
39,
21,
74,
2371,
87,
48,
1812,
88,
41,
21,
11,
42,
67,
51,
18,
35,
1949,
53,
55,
9741,
16,
66,
9745,
18505,
49,
75,
16,
16596,
39,
2411,
46,
82,
35,
81,
19,
2944,
54,
1407,
66,
25,
54,
16,
45,
2709,
89,
34,
22,
2533,
33,
7697,
1079,
87,
1587,
58,
23298,
56,
71,
723,
75,
18256,
42,
58,
517,
2177,
42,
75,
7308,
87,
37,
15,
25,
66,
42,
86,
19,
13860,
18,
15,
19445,
1440,
58,
11821,
38,
7862,
21,
41,
1352,
2276,
1554,
54,
90,
2571,
33,
17,
45,
87,
2721,
41,
23,
79,
1156,
3263,
49,
948,
4064,
4622,
75,
53,
19,
14324,
1179,
17,
2054,
16,
39,
3298,
81,
39,
2684,
66,
19,
11888,
37,
5342,
2328,
1156,
40,
24,
8163,
6353,
42,
23571,
7312,
34,
3448,
52,
2439,
8156,
45,
11026,
87,
17420,
57,
6741,
12917,
43,
8980,
80,
34,
67,
25262,
30587,
12463,
42,
12648,
16215,
3053,
57,
87,
42,
3448,
6741,
49,
2940,
2846,
17,
34,
67,
25262,
83,
26697,
11156,
15473,
42,
16,
19098,
58,
80,
57,
18,
38,
16,
19098,
25,
85,
4332,
38,
17,
28929,
72,
6737,
757,
16,
69,
3727,
90,
45,
1093,
9741,
17,
4187,
33,
978,
81,
49,
20806,
6603,
17188,
5294,
20271,
17,
12648,
54,
90,
4656,
46,
16,
66,
19,
31182,
41,
742,
76,
6413,
50,
80,
58,
757,
74,
57,
12297,
3317,
1194,
71,
49,
56,
54,
16,
65,
39,
25,
11552,
12297,
21,
4567,
20,
18184,
6166,
21,
5127,
57,
88,
12460,
41,
89,
45,
4980,
17,
46,
320,
18184,
3727,
16,
5127,
57,
31985,
1914,
89,
45,
4980,
17,
46,
674,
58,
1093,
74,
45,
2089,
9741,
17,
4187,
26917,
758,
53,
16566,
89,
57,
18,
12156,
67,
18,
7428,
58,
3705,
416,
20806,
16,
49,
18,
54,
24503,
17541,
391,
3705,
7952,
17188,
88,
39,
6353,
58,
23571,
7312,
34,
2822,
3635,
75,
38,
13683,
39,
15455,
1277,
76,
53,
68,
55,
21,
76,
1480,
19162,
28929,
25,
89,
58,
52,
775,
4567,
4680,
33,
17,
4187,
35,
8392,
24817,
20806,
6603,
17188,
71,
8745,
21,
74,
15573,
2901,
2054,
75,
9741,
17,
4187,
34,
72,
7608,
54,
6849,
23596,
58,
24,
87,
11888,
57,
25575,
79,
58,
41,
72,
6737,
7170,
31668,
5342,
49,
1554,
71,
57,
16,
1156,
1277,
29849,
79,
6487,
1156,
82,
50,
74,
38,
18,
319,
20,
32602,
51,
328,
52,
1049,
65,
41,
16,
71,
24,
8796,
86,
15,
4400,
40,
83,
24,
80,
15,
50,
87,
54,
15,
2591,
15,
3328,
56,
43,
54,
72,
25940,
20,
56,
2100,
1017,
43,
74,
12917,
46,
9681,
40,
83,
26606,
22,
89,
27764,
4176,
21733,
43,
25074,
23,
85,
43,
7616,
45,
617,
32640,
70,
5100,
21,
82,
39,
56,
83,
2767,
6773,
74,
34,
87,
6129,
88,
476,
6301,
18843,
19,
40,
906,
27453,
1271,
17,
573,
43,
88,
6576,
7821,
88,
280,
1304,
36,
71,
42,
86,
18,
28786,
20343,
1887,
34,
16,
85,
42,
86,
46,
8161,
22,
4029,
81,
7178,
44,
40,
83,
8045,
90,
3177,
25,
79,
58,
40,
5676,
45,
4134,
1254,
22760,
74,
34,
87,
2054,
87,
9741,
17,
53,
68,
37,
87,
14138,
15,
87,
49,
35,
2054,
26917,
24482,
57,
6741,
50,
16,
74,
5342,
8392,
15563,
33,
1734,
72,
19,
79,
20,
80,
18,
35,
16,
71,
8682,
84,
52,
42,
82,
36,
2076,
5196,
21,
18114,
49,
90,
583,
36,
71,
57,
6741,
50,
16,
8470,
27088,
15,
4134,
49,
8980,
303,
1156,
34,
16,
9741,
17,
53,
68,
36,
71,
49,
55,
5342,
51,
4198,
20,
2713,
17188,
74,
38,
5663,
42,
56,
9956,
20690,
8076,
46,
11,
25489,
24,
75,
25,
6166,
31893,
1939,
81,
72,
8810,
39,
2942,
46,
75,
23571,
2533,
4134,
4656,
1554,
879,
23571,
75,
81,
72,
8810,
39,
25,
87,
16,
4134,
2328,
2078,
23320,
3263,
49,
11765,
37,
65,
51,
66,
48,
74,
7574,
46,
20,
35,
15,
2100,
19,
49,
14057,
43,
708,
50,
10104,
7695,
56,
68,
28493,
33,
27786,
497,
51,
21,
1906,
58,
1812,
11,
84,
1299,
80,
31208,
3129,
17975,
28000,
11549,
55,
15,
19,
69,
52,
4029,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
srinathv/bokeh
|
examples/plotting/file/histogram.py
|
43
|
3876
|
# -*- coding: utf-8 -*-
import numpy as np
import scipy.special
from bokeh.plotting import figure, show, output_file, vplot
output_file('histogram.html')
p1 = figure(title="Normal Distribution (μ=0, σ=0.5)",tools="save",
background_fill="#E8DDCB")
mu, sigma = 0, 0.5
measured = np.random.normal(mu, sigma, 1000)
hist, edges = np.histogram(measured, density=True, bins=50)
x = np.linspace(-2, 2, 1000)
pdf = 1/(sigma * np.sqrt(2*np.pi)) * np.exp(-(x-mu)**2 / (2*sigma**2))
cdf = (1+scipy.special.erf((x-mu)/np.sqrt(2*sigma**2)))/2
p1.quad(top=hist, bottom=0, left=edges[:-1], right=edges[1:],
fill_color="#036564", line_color="#033649",\
)
p1.line(x, pdf, line_color="#D95B43", line_width=8, alpha=0.7, legend="PDF")
p1.line(x, cdf, line_color="white", line_width=2, alpha=0.7, legend="CDF")
p1.legend.orientation = "top_left"
p1.xaxis.axis_label = 'x'
p1.yaxis.axis_label = 'Pr(x)'
p2 = figure(title="Log Normal Distribution (μ=0, σ=0.5)", tools="save",
background_fill="#E8DDCB")
mu, sigma = 0, 0.5
measured = np.random.lognormal(mu, sigma, 1000)
hist, edges = np.histogram(measured, density=True, bins=50)
x = np.linspace(0, 8.0, 1000)
pdf = 1/(x* sigma * np.sqrt(2*np.pi)) * np.exp(-(np.log(x)-mu)**2 / (2*sigma**2))
cdf = (1+scipy.special.erf((np.log(x)-mu)/(np.sqrt(2)*sigma)))/2
p2.quad(top=hist, bottom=0, left=edges[:-1], right=edges[1:],
fill_color="#036564", line_color="#033649")
p2.line(x, pdf, line_color="#D95B43", line_width=8, alpha=0.7, legend="PDF")
p2.line(x, cdf, line_color="white", line_width=2, alpha=0.7, legend="CDF")
p2.legend.orientation = "bottom_right"
p2.xaxis.axis_label = 'x'
p2.yaxis.axis_label = 'Pr(x)'
p3 = figure(title="Gamma Distribution (k=1, θ=2)", tools="save",
background_fill="#E8DDCB")
k, theta = 1.0, 2.0
measured = np.random.gamma(k, theta, 1000)
hist, edges = np.histogram(measured, density=True, bins=50)
x = np.linspace(0, 20.0, 1000)
pdf = x**(k-1) * np.exp(-x/theta) / (theta**k * scipy.special.gamma(k))
cdf = scipy.special.gammainc(k, x/theta) / scipy.special.gamma(k)
p3.quad(top=hist, bottom=0, left=edges[:-1], right=edges[1:],
fill_color="#036564", line_color="#033649")
p3.line(x, pdf, line_color="#D95B43", line_width=8, alpha=0.7, legend="PDF")
p3.line(x, cdf, line_color="white", line_width=2, alpha=0.7, legend="CDF")
p3.legend.orientation = "top_left"
p3.xaxis.axis_label = 'x'
p3.yaxis.axis_label = 'Pr(x)'
p4 = figure(title="Beta Distribution (α=2, β=2)", tools="save",
background_fill="#E8DDCB")
alpha, beta = 2.0, 2.0
measured = np.random.beta(alpha, beta, 1000)
hist, edges = np.histogram(measured, density=True, bins=50)
x = np.linspace(0, 1, 1000)
pdf = x**(alpha-1) * (1-x)**(beta-1) / scipy.special.beta(alpha, beta)
cdf = scipy.special.btdtr(alpha, beta, x)
p4.quad(top=hist, bottom=0, left=edges[:-1], right=edges[1:],
fill_color="#036564", line_color="#033649")
p4.line(x, pdf, line_color="#D95B43", line_width=8, alpha=0.7, legend="PDF")
p4.line(x, cdf, line_color="white", line_width=2, alpha=0.7, legend="CDF")
p4.xaxis.axis_label = 'x'
p4.yaxis.axis_label = 'Pr(x)'
p5 = figure(title="Weibull Distribution (λ=1, k=1.25)", tools="save",
background_fill="#E8DDCB")
lam, k = 1, 1.25
measured = lam*(-np.log(np.random.uniform(0, 1, 1000)))**(1/k)
hist, edges = np.histogram(measured, density=True, bins=50)
x = np.linspace(0, 8, 1000)
pdf = (k/lam)*(x/lam)**(k-1) * np.exp(-(x/lam)**k)
cdf = 1 - np.exp(-(x/lam)**k)
p5.quad(top=hist, bottom=0, left=edges[:-1], right=edges[1:],
fill_color="#036564", line_color="#033649")
p5.line(x, pdf, line_color="#D95B43", line_width=8, alpha=0.7, legend="PDF")
p5.line(x, cdf, line_color="white", line_width=2, alpha=0.7, legend="CDF")
p5.legend.orientation = "top_left"
p5.xaxis.axis_label = 'x'
p5.yaxis.axis_label = 'Pr(x)'
show(vplot(p1,p2,p3,p4,p5))
|
bsd-3-clause
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
646,
2680,
465,
980,
199,
646,
7026,
14,
6664,
199,
199,
504,
25214,
14,
2798,
1337,
492,
9658,
12,
2498,
12,
1072,
63,
493,
12,
373,
2798,
199,
199,
1199,
63,
493,
360,
14805,
14,
1360,
358,
199,
199,
80,
17,
275,
9658,
8,
1213,
628,
6241,
11839,
334,
24461,
29,
16,
12,
221,
20136,
29,
16,
14,
21,
4186,
2537,
628,
2117,
401,
2126,
8020,
63,
4498,
13476,
37,
24,
36,
5196,
34,
531,
199,
199,
6553,
12,
10819,
275,
378,
12,
378,
14,
21,
199,
199,
19116,
3297,
275,
980,
14,
2355,
14,
3302,
8,
6553,
12,
10819,
12,
5198,
9,
199,
11141,
12,
8207,
275,
980,
14,
14805,
8,
19116,
3297,
12,
13650,
29,
549,
12,
13341,
29,
1400,
9,
199,
199,
88,
275,
980,
14,
11649,
2801,
18,
12,
499,
12,
5198,
9,
199,
5607,
275,
413,
7985,
9412,
627,
980,
14,
5079,
8,
18,
10,
1590,
14,
1038,
430,
627,
980,
14,
1474,
2801,
8,
88,
13,
6553,
6422,
18,
1182,
334,
18,
10,
9412,
538,
18,
430,
199,
10790,
275,
334,
17,
11,
14248,
14,
6664,
14,
31740,
1332,
88,
13,
6553,
2447,
1590,
14,
5079,
8,
18,
10,
9412,
538,
18,
1724,
15,
18,
199,
199,
80,
17,
14,
14567,
8,
2119,
29,
11141,
12,
9048,
29,
16,
12,
3602,
29,
6929,
4439,
17,
467,
2451,
29,
6929,
59,
17,
8429,
1362,
5554,
63,
2326,
13476,
16,
12664,
772,
401,
1004,
63,
2326,
13476,
8762,
11228,
22260,
199,
9,
199,
80,
17,
14,
604,
8,
88,
12,
11249,
12,
1004,
63,
2326,
13476,
36,
2720,
34,
2824,
401,
1004,
63,
2063,
29,
24,
12,
5131,
29,
16,
14,
23,
12,
15906,
628,
7638,
531,
199,
80,
17,
14,
604,
8,
88,
12,
26037,
12,
1004,
63,
2326,
628,
7510,
401,
1004,
63,
2063,
29,
18,
12,
5131,
29,
16,
14,
23,
12,
15906,
628,
18967,
531,
199,
199,
80,
17,
14,
10231,
14,
17001,
275,
298,
2119,
63,
3039,
2,
199,
80,
17,
14,
21854,
14,
3127,
63,
1302,
275,
283,
88,
7,
199,
80,
17,
14,
23876,
14,
3127,
63,
1302,
275,
283,
9779,
8,
88,
3171,
4388,
199,
80,
18,
275,
9658,
8,
1213,
628,
2445,
11514,
11839,
334,
24461,
29,
16,
12,
221,
20136,
29,
16,
14,
21,
4186,
7249,
628,
2117,
401,
2126,
8020,
63,
4498,
13476,
37,
24,
36,
5196,
34,
531,
199,
199,
6553,
12,
10819,
275,
378,
12,
378,
14,
21,
199,
199,
19116,
3297,
275,
980,
14,
2355,
14,
320,
784,
1783,
8,
6553,
12,
10819,
12,
5198,
9,
199,
11141,
12,
8207,
275,
980,
14,
14805,
8,
19116,
3297,
12,
13650,
29,
549,
12,
13341,
29,
1400,
9,
199,
199,
88,
275,
980,
14,
11649,
8,
16,
12,
1695,
14,
16,
12,
5198,
9,
199,
5607,
275,
413,
7985,
88,
10,
10819,
627,
980,
14,
5079,
8,
18,
10,
1590,
14,
1038,
430,
627,
980,
14,
1474,
2801,
8,
1590,
14,
793,
8,
88,
7216,
6553,
6422,
18,
1182,
334,
18,
10,
9412,
538,
18,
430,
199,
10790,
275,
334,
17,
11,
14248,
14,
6664,
14,
31740,
1332,
1590,
14,
793,
8,
88,
7216,
6553,
15136,
1590,
14,
5079,
8,
18,
3342,
9412,
1724,
15,
18,
199,
199,
80,
18,
14,
14567,
8,
2119,
29,
11141,
12,
9048,
29,
16,
12,
3602,
29,
6929,
4439,
17,
467,
2451,
29,
6929,
59,
17,
8429,
272,
5554,
63,
2326,
13476,
16,
12664,
772,
401,
1004,
63,
2326,
13476,
8762,
11228,
531,
199,
80,
18,
14,
604,
8,
88,
12,
11249,
12,
1004,
63,
2326,
13476,
36,
2720,
34,
2824,
401,
1004,
63,
2063,
29,
24,
12,
5131,
29,
16,
14,
23,
12,
15906,
628,
7638,
531,
199,
80,
18,
14,
604,
8,
88,
12,
26037,
12,
1004,
63,
2326,
628,
7510,
401,
1004,
63,
2063,
29,
18,
12,
5131,
29,
16,
14,
23,
12,
15906,
628,
18967,
531,
199,
199,
80,
18,
14,
10231,
14,
17001,
275,
298,
8305,
63,
1019,
2,
199,
80,
18,
14,
21854,
14,
3127,
63,
1302,
275,
283,
88,
7,
199,
80,
18,
14,
23876,
14,
3127,
63,
1302,
275,
283,
9779,
8,
88,
3171,
4388,
199,
80,
19,
275,
9658,
8,
1213,
628,
15091,
11839,
334,
75,
29,
17,
12,
19123,
117,
29,
18,
4186,
7249,
628,
2117,
401,
2126,
8020,
63,
4498,
13476,
37,
24,
36,
5196,
34,
531,
199,
199,
75,
12,
12724,
275,
413,
14,
16,
12,
499,
14,
16,
199,
199,
19116,
3297,
275,
980,
14,
2355,
14,
7325,
8,
75,
12,
12724,
12,
5198,
9,
199,
11141,
12,
8207,
275,
980,
14,
14805,
8,
19116,
3297,
12,
13650,
29,
549,
12,
13341,
29,
1400,
9,
199,
199,
88,
275,
980,
14,
11649,
8,
16,
12,
3388,
14,
16,
12,
5198,
9,
199,
5607,
275,
671,
14192,
75,
13,
17,
9,
627,
980,
14,
1474,
2801,
88,
15,
9337,
9,
1182,
334,
9337,
538,
75,
627,
7026,
14,
6664,
14,
7325,
8,
75,
430,
199,
10790,
275,
7026,
14,
6664,
14,
17740,
973,
67,
8,
75,
12,
671,
15,
9337,
9,
1182,
7026,
14,
6664,
14,
7325,
8,
75,
9,
199,
199,
80,
19,
14,
14567,
8,
2119,
29,
11141,
12,
9048,
29,
16,
12,
3602,
29,
6929,
4439,
17,
467,
2451,
29,
6929,
59,
17,
8429,
272,
5554,
63,
2326,
13476,
16,
12664,
772,
401,
1004,
63,
2326,
13476,
8762,
11228,
531,
199,
80,
19,
14,
604,
8,
88,
12,
11249,
12,
1004,
63,
2326,
13476,
36,
2720,
34,
2824,
401,
1004,
63,
2063,
29,
24,
12,
5131,
29,
16,
14,
23,
12,
15906,
628,
7638,
531,
199,
80,
19,
14,
604,
8,
88,
12,
26037,
12,
1004,
63,
2326,
628,
7510,
401,
1004,
63,
2063,
29,
18,
12,
5131,
29,
16,
14,
23,
12,
15906,
628,
18967,
531,
199,
199,
80,
19,
14,
10231,
14,
17001,
275,
298,
2119,
63,
3039,
2,
199,
80,
19,
14,
21854,
14,
3127,
63,
1302,
275,
283,
88,
7,
199,
80,
19,
14,
23876,
14,
3127,
63,
1302,
275,
283,
9779,
8,
88,
3171,
4388,
199,
80,
20,
275,
9658,
8,
1213,
628,
21732,
11839,
334,
13500,
29,
18,
12,
19123,
111
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
646,
2680,
465,
980,
199,
646,
7026,
14,
6664,
199,
199,
504,
25214,
14,
2798,
1337,
492,
9658,
12,
2498,
12,
1072,
63,
493,
12,
373,
2798,
199,
199,
1199,
63,
493,
360,
14805,
14,
1360,
358,
199,
199,
80,
17,
275,
9658,
8,
1213,
628,
6241,
11839,
334,
24461,
29,
16,
12,
221,
20136,
29,
16,
14,
21,
4186,
2537,
628,
2117,
401,
2126,
8020,
63,
4498,
13476,
37,
24,
36,
5196,
34,
531,
199,
199,
6553,
12,
10819,
275,
378,
12,
378,
14,
21,
199,
199,
19116,
3297,
275,
980,
14,
2355,
14,
3302,
8,
6553,
12,
10819,
12,
5198,
9,
199,
11141,
12,
8207,
275,
980,
14,
14805,
8,
19116,
3297,
12,
13650,
29,
549,
12,
13341,
29,
1400,
9,
199,
199,
88,
275,
980,
14,
11649,
2801,
18,
12,
499,
12,
5198,
9,
199,
5607,
275,
413,
7985,
9412,
627,
980,
14,
5079,
8,
18,
10,
1590,
14,
1038,
430,
627,
980,
14,
1474,
2801,
8,
88,
13,
6553,
6422,
18,
1182,
334,
18,
10,
9412,
538,
18,
430,
199,
10790,
275,
334,
17,
11,
14248,
14,
6664,
14,
31740,
1332,
88,
13,
6553,
2447,
1590,
14,
5079,
8,
18,
10,
9412,
538,
18,
1724,
15,
18,
199,
199,
80,
17,
14,
14567,
8,
2119,
29,
11141,
12,
9048,
29,
16,
12,
3602,
29,
6929,
4439,
17,
467,
2451,
29,
6929,
59,
17,
8429,
1362,
5554,
63,
2326,
13476,
16,
12664,
772,
401,
1004,
63,
2326,
13476,
8762,
11228,
22260,
199,
9,
199,
80,
17,
14,
604,
8,
88,
12,
11249,
12,
1004,
63,
2326,
13476,
36,
2720,
34,
2824,
401,
1004,
63,
2063,
29,
24,
12,
5131,
29,
16,
14,
23,
12,
15906,
628,
7638,
531,
199,
80,
17,
14,
604,
8,
88,
12,
26037,
12,
1004,
63,
2326,
628,
7510,
401,
1004,
63,
2063,
29,
18,
12,
5131,
29,
16,
14,
23,
12,
15906,
628,
18967,
531,
199,
199,
80,
17,
14,
10231,
14,
17001,
275,
298,
2119,
63,
3039,
2,
199,
80,
17,
14,
21854,
14,
3127,
63,
1302,
275,
283,
88,
7,
199,
80,
17,
14,
23876,
14,
3127,
63,
1302,
275,
283,
9779,
8,
88,
3171,
4388,
199,
80,
18,
275,
9658,
8,
1213,
628,
2445,
11514,
11839,
334,
24461,
29,
16,
12,
221,
20136,
29,
16,
14,
21,
4186,
7249,
628,
2117,
401,
2126,
8020,
63,
4498,
13476,
37,
24,
36,
5196,
34,
531,
199,
199,
6553,
12,
10819,
275,
378,
12,
378,
14,
21,
199,
199,
19116,
3297,
275,
980,
14,
2355,
14,
320,
784,
1783,
8,
6553,
12,
10819,
12,
5198,
9,
199,
11141,
12,
8207,
275,
980,
14,
14805,
8,
19116,
3297,
12,
13650,
29,
549,
12,
13341,
29,
1400,
9,
199,
199,
88,
275,
980,
14,
11649,
8,
16,
12,
1695,
14,
16,
12,
5198,
9,
199,
5607,
275,
413,
7985,
88,
10,
10819,
627,
980,
14,
5079,
8,
18,
10,
1590,
14,
1038,
430,
627,
980,
14,
1474,
2801,
8,
1590,
14,
793,
8,
88,
7216,
6553,
6422,
18,
1182,
334,
18,
10,
9412,
538,
18,
430,
199,
10790,
275,
334,
17,
11,
14248,
14,
6664,
14,
31740,
1332,
1590,
14,
793,
8,
88,
7216,
6553,
15136,
1590,
14,
5079,
8,
18,
3342,
9412,
1724,
15,
18,
199,
199,
80,
18,
14,
14567,
8,
2119,
29,
11141,
12,
9048,
29,
16,
12,
3602,
29,
6929,
4439,
17,
467,
2451,
29,
6929,
59,
17,
8429,
272,
5554,
63,
2326,
13476,
16,
12664,
772,
401,
1004,
63,
2326,
13476,
8762,
11228,
531,
199,
80,
18,
14,
604,
8,
88,
12,
11249,
12,
1004,
63,
2326,
13476,
36,
2720,
34,
2824,
401,
1004,
63,
2063,
29,
24,
12,
5131,
29,
16,
14,
23,
12,
15906,
628,
7638,
531,
199,
80,
18,
14,
604,
8,
88,
12,
26037,
12,
1004,
63,
2326,
628,
7510,
401,
1004,
63,
2063,
29,
18,
12,
5131,
29,
16,
14,
23,
12,
15906,
628,
18967,
531,
199,
199,
80,
18,
14,
10231,
14,
17001,
275,
298,
8305,
63,
1019,
2,
199,
80,
18,
14,
21854,
14,
3127,
63,
1302,
275,
283,
88,
7,
199,
80,
18,
14,
23876,
14,
3127,
63,
1302,
275,
283,
9779,
8,
88,
3171,
4388,
199,
80,
19,
275,
9658,
8,
1213,
628,
15091,
11839,
334,
75,
29,
17,
12,
19123,
117,
29,
18,
4186,
7249,
628,
2117,
401,
2126,
8020,
63,
4498,
13476,
37,
24,
36,
5196,
34,
531,
199,
199,
75,
12,
12724,
275,
413,
14,
16,
12,
499,
14,
16,
199,
199,
19116,
3297,
275,
980,
14,
2355,
14,
7325,
8,
75,
12,
12724,
12,
5198,
9,
199,
11141,
12,
8207,
275,
980,
14,
14805,
8,
19116,
3297,
12,
13650,
29,
549,
12,
13341,
29,
1400,
9,
199,
199,
88,
275,
980,
14,
11649,
8,
16,
12,
3388,
14,
16,
12,
5198,
9,
199,
5607,
275,
671,
14192,
75,
13,
17,
9,
627,
980,
14,
1474,
2801,
88,
15,
9337,
9,
1182,
334,
9337,
538,
75,
627,
7026,
14,
6664,
14,
7325,
8,
75,
430,
199,
10790,
275,
7026,
14,
6664,
14,
17740,
973,
67,
8,
75,
12,
671,
15,
9337,
9,
1182,
7026,
14,
6664,
14,
7325,
8,
75,
9,
199,
199,
80,
19,
14,
14567,
8,
2119,
29,
11141,
12,
9048,
29,
16,
12,
3602,
29,
6929,
4439,
17,
467,
2451,
29,
6929,
59,
17,
8429,
272,
5554,
63,
2326,
13476,
16,
12664,
772,
401,
1004,
63,
2326,
13476,
8762,
11228,
531,
199,
80,
19,
14,
604,
8,
88,
12,
11249,
12,
1004,
63,
2326,
13476,
36,
2720,
34,
2824,
401,
1004,
63,
2063,
29,
24,
12,
5131,
29,
16,
14,
23,
12,
15906,
628,
7638,
531,
199,
80,
19,
14,
604,
8,
88,
12,
26037,
12,
1004,
63,
2326,
628,
7510,
401,
1004,
63,
2063,
29,
18,
12,
5131,
29,
16,
14,
23,
12,
15906,
628,
18967,
531,
199,
199,
80,
19,
14,
10231,
14,
17001,
275,
298,
2119,
63,
3039,
2,
199,
80,
19,
14,
21854,
14,
3127,
63,
1302,
275,
283,
88,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
chainer/chainercv
|
chainercv/links/model/light_head_rcnn/light_head_rcnn_resnet101.py
|
2
|
10946
|
from __future__ import division
import numpy as np
import chainer
import chainer.functions as F
import chainer.links as L
from chainercv.functions import ps_roi_max_align_2d
from chainercv.links.connection.conv_2d_bn_activ import Conv2DBNActiv
from chainercv.links.model.faster_rcnn.region_proposal_network import \
RegionProposalNetwork
from chainercv.links.model.light_head_rcnn.global_context_module import \
GlobalContextModule
from chainercv.links.model.light_head_rcnn.light_head_rcnn import \
LightHeadRCNN
from chainercv.links.model.resnet.resblock import ResBlock
from chainercv.links.model.resnet.resnet import ResNet101
from chainercv import utils
class LightHeadRCNNResNet101(LightHeadRCNN):
"""Light-Head R-CNN based on ResNet101.
When you specify the path of a pre-trained chainer model serialized as
a :obj:`.npz` file in the constructor, this chain model automatically
initializes all the parameters with it.
When a string in prespecified set is provided, a pretrained model is
loaded from weights distributed on the Internet.
The list of pretrained models supported are as follows:
* :obj:`coco`: Loads weights trained with the trainval split of \
COCO Detection Dataset.
* :obj:`imagenet`: Loads weights trained with ImageNet Classfication \
task for the feature extractor and the head modules. \
Weights that do not have a corresponding layer in ResNet101 \
will be randomly initialized.
For descriptions on the interface of this model, please refer to
:class:`~light_head_rcnn.links.model.light_head_rcnn_base.LightHeadRCNN`
:class:`~light_head_rcnn.links.model.light_head_rcnn_base.LightHeadRCNN`
supports finer control on random initializations of weights by arguments
:obj:`resnet_initialW`, :obj:`rpn_initialW`, :obj:`loc_initialW` and
:obj:`score_initialW`.
It accepts a callable that takes an array and edits its values.
If :obj:`None` is passed as an initializer, the default initializer is
used.
Args:
n_fg_class (int): The number of classes excluding the background.
pretrained_model (string): The destination of the pre-trained
chainer model serialized as a :obj:`.npz` file.
If this is one of the strings described
above, it automatically loads weights stored under a directory
:obj:`$CHAINER_DATASET_ROOT/pfnet/chainercv/models/`,
where :obj:`$CHAINER_DATASET_ROOT` is set as
:obj:`$HOME/.chainer/dataset` unless you specify another value
by modifying the environment variable.
min_size (int): A preprocessing paramter for :meth:`prepare`.
max_size (int): A preprocessing paramter for :meth:`prepare`.
ratios (list of floats): This is ratios of width to height of
the anchors.
anchor_scales (list of numbers): This is areas of anchors.
Those areas will be the product of the square of an element in
:obj:`anchor_scales` and the original area of the reference
window.
resnet_initialW (callable): Initializer for the layers corresponding to
the ResNet101 layers.
rpn_initialW (callable): Initializer for Region Proposal Network
layers.
loc_initialW (callable): Initializer for the localization head.
score_initialW (callable): Initializer for the score head.
proposal_creator_params (dict): Key valued paramters for
:class:`~chainercv.links.model.faster_rcnn.ProposalCreator`.
"""
_models = {
'coco': {
'param': {'n_fg_class': 80},
'url': 'https://chainercv-models.preferred.jp/'
'light_head_rcnn_resnet101_trained_2019_06_13.npz',
'cv2': True
},
}
feat_stride = 16
proposal_creator_params = {
'nms_thresh': 0.7,
'n_train_pre_nms': 12000,
'n_train_post_nms': 2000,
'n_test_pre_nms': 6000,
'n_test_post_nms': 1000,
'force_cpu_nms': False,
'min_size': 0,
}
def __init__(
self,
n_fg_class=None,
pretrained_model=None,
min_size=800, max_size=1333, roi_size=7,
ratios=[0.5, 1, 2], anchor_scales=[2, 4, 8, 16, 32],
loc_normalize_mean=(0., 0., 0., 0.),
loc_normalize_std=(0.1, 0.1, 0.2, 0.2),
resnet_initialW=None, rpn_initialW=None,
global_module_initialW=None,
loc_initialW=None, score_initialW=None,
proposal_creator_params=None,
):
param, path = utils.prepare_pretrained_model(
{'n_fg_class': n_fg_class}, pretrained_model, self._models)
if resnet_initialW is None and pretrained_model:
resnet_initialW = chainer.initializers.HeNormal()
if rpn_initialW is None:
rpn_initialW = chainer.initializers.Normal(0.01)
if global_module_initialW is None:
global_module_initialW = chainer.initializers.Normal(0.01)
if loc_initialW is None:
loc_initialW = chainer.initializers.Normal(0.001)
if score_initialW is None:
score_initialW = chainer.initializers.Normal(0.01)
if proposal_creator_params is not None:
self.proposal_creator_params = proposal_creator_params
extractor = ResNet101Extractor(
initialW=resnet_initialW)
rpn = RegionProposalNetwork(
1024, 512,
ratios=ratios,
anchor_scales=anchor_scales,
feat_stride=self.feat_stride,
initialW=rpn_initialW,
proposal_creator_params=self.proposal_creator_params,
)
head = LightHeadRCNNResNet101Head(
param['n_fg_class'] + 1,
roi_size=roi_size,
spatial_scale=1. / self.feat_stride,
global_module_initialW=global_module_initialW,
loc_initialW=loc_initialW,
score_initialW=score_initialW
)
mean = np.array([122.7717, 115.9465, 102.9801],
dtype=np.float32)[:, None, None]
super(LightHeadRCNNResNet101, self).__init__(
extractor, rpn, head, mean, min_size, max_size,
loc_normalize_mean, loc_normalize_std)
if path == 'imagenet':
self._copy_imagenet_pretrained_resnet()
elif path:
chainer.serializers.load_npz(path, self)
def _copy_imagenet_pretrained_resnet(self):
def _copy_conv2dbn(src, dst):
dst.conv.W.array = src.conv.W.array
if src.conv.b is not None and dst.conv.b is not None:
dst.conv.b.array = src.conv.b.array
dst.bn.gamma.array = src.bn.gamma.array
dst.bn.beta.array = src.bn.beta.array
dst.bn.avg_var = src.bn.avg_var
dst.bn.avg_mean = src.bn.avg_mean
def _copy_bottleneck(src, dst):
if hasattr(src, 'residual_conv'):
_copy_conv2dbn(src.residual_conv, dst.residual_conv)
_copy_conv2dbn(src.conv1, dst.conv1)
_copy_conv2dbn(src.conv2, dst.conv2)
_copy_conv2dbn(src.conv3, dst.conv3)
def _copy_resblock(src, dst):
for layer_name in src.layer_names:
_copy_bottleneck(
getattr(src, layer_name), getattr(dst, layer_name))
pretrained_model = ResNet101(arch='he', pretrained_model='imagenet')
_copy_conv2dbn(pretrained_model.conv1, self.extractor.conv1)
_copy_resblock(pretrained_model.res2, self.extractor.res2)
_copy_resblock(pretrained_model.res3, self.extractor.res3)
_copy_resblock(pretrained_model.res4, self.extractor.res4)
_copy_resblock(pretrained_model.res5, self.extractor.res5)
class ResNet101Extractor(chainer.Chain):
"""ResNet101 Extractor for Light-Head R-CNN ResNet101 implementation.
This class is used as an extractor for LightHeadRCNNResNet101.
This outputs feature maps.
Args:
initialW: Initializer for ResNet101 extractor.
"""
def __init__(self, initialW=None):
super(ResNet101Extractor, self).__init__()
if initialW is None:
initialW = chainer.initializers.HeNormal()
kwargs = {
'initialW': initialW,
'bn_kwargs': {'eps': 1e-5, 'decay': 0.997},
'stride_first': True
}
with self.init_scope():
# ResNet
self.conv1 = Conv2DBNActiv(
3, 64, 7, 2, 3, nobias=True, initialW=initialW)
self.pool1 = lambda x: F.max_pooling_2d(
x, ksize=3, stride=2, pad=1, cover_all=False)
self.res2 = ResBlock(3, 64, 64, 256, 1, **kwargs)
self.res3 = ResBlock(4, 256, 128, 512, 2, **kwargs)
self.res4 = ResBlock(23, 512, 256, 1024, 2, **kwargs)
self.res5 = ResBlock(3, 1024, 512, 2048, 1, 2, **kwargs)
def __call__(self, x):
"""Forward the chain.
Args:
x (~chainer.Variable): 4D image variable.
"""
with chainer.using_config('train', False):
h = self.pool1(self.conv1(x))
h = self.res2(h)
h.unchain_backward()
h = self.res3(h)
res4 = self.res4(h)
res5 = self.res5(res4)
return res4, res5
class LightHeadRCNNResNet101Head(chainer.Chain):
def __init__(
self, n_class, roi_size, spatial_scale,
global_module_initialW=None,
loc_initialW=None, score_initialW=None
):
super(LightHeadRCNNResNet101Head, self).__init__()
self.n_class = n_class
self.spatial_scale = spatial_scale
self.roi_size = roi_size
with self.init_scope():
self.global_context_module = GlobalContextModule(
2048, 256, self.roi_size * self.roi_size * 10, 15,
initialW=global_module_initialW)
self.fc1 = L.Linear(
self.roi_size * self.roi_size * 10, 2048,
initialW=score_initialW)
self.score = L.Linear(2048, n_class, initialW=score_initialW)
self.cls_loc = L.Linear(2048, 4 * n_class, initialW=loc_initialW)
def __call__(self, x, rois, roi_indices):
# global context module
h = self.global_context_module(x)
# psroi max align
pool = ps_roi_max_align_2d(
h, rois, roi_indices,
(10, self.roi_size, self.roi_size),
self.spatial_scale, self.roi_size,
sampling_ratio=2)
pool = F.where(
self.xp.isinf(pool.array),
self.xp.zeros(pool.shape, dtype=pool.dtype), pool)
# fc
fc1 = F.relu(self.fc1(pool))
roi_cls_locs = self.cls_loc(fc1)
roi_scores = self.score(fc1)
return roi_cls_locs, roi_scores
|
mit
|
[
504,
636,
2443,
363,
492,
4629,
199,
199,
646,
2680,
465,
980,
199,
199,
646,
20333,
199,
646,
20333,
14,
5777,
465,
481,
199,
646,
20333,
14,
4614,
465,
491,
199,
199,
504,
20333,
5107,
14,
5777,
492,
7347,
63,
20581,
63,
988,
63,
5743,
63,
18,
68,
199,
504,
20333,
5107,
14,
4614,
14,
2105,
14,
5598,
63,
18,
68,
63,
10472,
63,
5416,
86,
492,
19140,
18,
2846,
46,
13767,
86,
199,
504,
20333,
5107,
14,
4614,
14,
1238,
14,
70,
2311,
63,
1195,
4411,
14,
4551,
63,
25700,
63,
1200,
492,
971,
272,
22240,
919,
14506,
4491,
199,
504,
20333,
5107,
14,
4614,
14,
1238,
14,
4040,
63,
2993,
63,
1195,
4411,
14,
2966,
63,
1100,
63,
578,
492,
971,
272,
13641,
2998,
2377,
199,
504,
20333,
5107,
14,
4614,
14,
1238,
14,
4040,
63,
2993,
63,
1195,
4411,
14,
4040,
63,
2993,
63,
1195,
4411,
492,
971,
272,
29684,
11664,
8205,
7178,
199,
504,
20333,
5107,
14,
4614,
14,
1238,
14,
28998,
14,
470,
1457,
492,
3591,
3142,
199,
504,
20333,
5107,
14,
4614,
14,
1238,
14,
28998,
14,
28998,
492,
3591,
2480,
4893,
199,
504,
20333,
5107,
492,
3778,
421,
199,
533,
29684,
11664,
8205,
7178,
1322,
2480,
4893,
8,
16393,
11664,
8205,
7178,
304,
339,
408,
16393,
13,
11664,
820,
13,
35,
7178,
4079,
641,
3591,
2480,
4893,
14,
339,
3979,
1265,
4165,
314,
931,
402,
282,
876,
13,
23782,
20333,
1402,
6380,
465,
272,
282,
520,
1113,
5026,
1590,
90,
64,
570,
315,
314,
3787,
12,
642,
6036,
1402,
5847,
272,
2536,
6491,
1006,
314,
2633,
543,
652,
14,
272,
3979,
282,
1059,
315,
25210,
28387,
663,
365,
2741,
12,
282,
876,
23782,
1402,
365,
272,
6511,
687,
4931,
1854,
641,
314,
22026,
14,
272,
710,
769,
402,
876,
23782,
1709,
3748,
787,
465,
11924,
26,
339,
627,
520,
1113,
1705,
331,
331,
8340,
30367,
4931,
28161,
543,
314,
3560,
637,
3715,
402,
971,
267,
5099,
1439,
1487,
5860,
20284,
14,
272,
627,
520,
1113,
1705,
11744,
2268,
386,
8340,
30367,
4931,
28161,
543,
6047,
2480,
8089,
3477,
971,
267,
2120,
367,
314,
3878,
31295,
436,
314,
4854,
4621,
14,
971,
267,
2136,
2492,
626,
886,
440,
1172,
282,
5226,
4045,
315,
3591,
2480,
4893,
971,
267,
911,
506,
19311,
10038,
14,
339,
2104,
18714,
641,
314,
3217,
402,
642,
1402,
12,
8749,
10618,
370,
272,
520,
533,
6054,
4040,
63,
2993,
63,
1195,
4411,
14,
4614,
14,
1238,
14,
4040,
63,
2993,
63,
1195,
4411,
63,
1095,
14,
16393,
11664,
8205,
7178,
64,
339,
520,
533,
6054,
4040,
63,
2993,
63,
1195,
4411,
14,
4614,
14,
1238,
14,
4040,
63,
2993,
63,
1195,
4411,
63,
1095,
14,
16393,
11664,
8205,
7178,
64,
272,
5171,
2583,
281,
3304,
641,
2196,
2536,
12270,
402,
4931,
701,
2368,
272,
520,
1113,
1705,
28998,
63,
2747,
55,
3559,
520,
1113,
1705,
4599,
78,
63,
2747,
55,
3559,
520,
1113,
1705,
2102,
63,
2747,
55,
64,
436,
272,
520,
1113,
1705,
3397,
63,
2747,
55,
2313,
272,
2779,
11479,
282,
4550,
626,
6181,
376,
1625,
436,
7860,
1086,
2399,
1338,
14,
272,
982,
520,
1113,
1705,
403,
64,
365,
3032,
465,
376,
11130,
12,
314,
849,
11130,
365,
272,
1202,
14,
339,
3033,
26,
267,
302,
63,
9681,
63,
533,
334,
442,
304,
710,
1329,
402,
3992,
28529,
314,
8020,
14,
267,
876,
23782,
63,
1238,
334,
875,
304,
710,
5724,
402,
314,
876,
13,
23782,
288,
20333,
1402,
6380,
465,
282,
520,
1113,
5026,
1590,
90,
64,
570,
14,
288,
982,
642,
365,
1373,
402,
314,
3326,
11736,
288,
3432,
12,
652,
5847,
14404,
4931,
5489,
1334,
282,
2082,
288,
520,
1113,
1705,
4,
25256,
540,
63,
28231,
775,
63,
5441,
15,
9928,
846,
15,
27243,
5107,
15,
992,
15,
3559,
288,
2382,
520,
1113,
1705,
4,
25256,
540,
63,
28231,
775,
63,
5441,
64,
365,
663,
465,
288,
520,
1113,
1705,
4,
9524,
8083,
27243,
15,
5214,
64,
7444,
1265,
4165,
4573,
574,
288,
701,
24662,
314,
3734,
1750,
14,
267,
1748,
63,
890,
334,
442,
304,
437,
26471,
1215,
351,
367,
520,
5247,
1705,
6726,
2313,
267,
1390,
63,
890,
334,
442,
304,
437,
26471,
1215,
351,
367,
520,
5247,
1705,
6726,
2313,
267,
660,
9636,
334,
513,
402,
15657,
304,
961,
365,
660,
9636,
402,
3462,
370,
4569,
402,
288,
314,
32682,
14,
267,
12514,
63,
30832,
334,
513,
402,
5579,
304,
961,
365,
787,
305,
402,
32682,
14,
288,
18049,
261,
787,
305,
911,
506,
314,
3336,
402,
314,
12386,
402,
376,
1819,
315,
288,
520,
1113,
1705,
11498,
63,
30832,
64,
436,
314,
3379,
9150,
402,
314,
3659,
288,
4353,
14,
267,
522,
846,
63,
2747,
55,
334,
8296,
304,
6026,
1793,
367,
314,
9393,
5226,
370,
288,
314,
3591,
2480,
4893,
9393,
14,
267,
519,
4812,
63,
2747,
55,
334,
8296,
304,
6026,
1793,
367,
22240,
2165,
14506,
7220,
288,
9393,
14,
267,
4355,
63,
2747,
55,
334,
8296,
304,
6026,
1793,
367,
314,
2257,
2072,
4854,
14,
267,
5396,
63,
2747,
55,
334,
8296,
304,
6026,
1793,
367,
314,
5396,
4854,
14,
267,
28315,
63,
9986,
63,
1162,
334,
807,
304,
2606,
574,
68,
1215,
878,
367,
288,
520,
533,
6054,
27243,
5107,
14,
4614,
14,
1238,
14,
70,
2311,
63,
1195,
4411,
14,
919,
14506,
17523,
2313,
339,
408,
339,
485,
992,
275,
469,
267,
283,
331,
331,
356,
469,
288,
283,
635,
356,
791,
78,
63,
9681,
63,
533,
356,
5939,
1386,
288,
283,
633,
356,
283,
2859,
921,
27243,
5107,
13,
992,
14,
17477,
14,
11538,
4805,
288,
283,
4040,
63,
2993,
63,
1195,
4411,
63,
28998,
4893,
63,
23782,
63,
14982,
63,
1690,
63,
969,
14,
1590,
90,
297,
288,
283,
5107,
18,
356,
715,
267,
1660,
272,
789,
272,
13953,
63,
12318,
275,
3193,
272,
28315,
63,
9986,
63,
1162,
275,
469,
267,
283,
78,
706,
63,
14898,
356,
378,
14,
23,
12,
267,
283,
78,
63,
2834,
63,
657,
63,
78,
706,
356,
3144,
1493,
12,
267,
283,
78,
63,
2834,
63,
1932,
63,
78,
706,
356,
12293,
12,
267,
283,
78,
63,
396,
63,
657,
63,
78,
706,
356,
1227,
1493,
12,
267,
283,
78,
63
] |
[
636,
2443,
363,
492,
4629,
199,
199,
646,
2680,
465,
980,
199,
199,
646,
20333,
199,
646,
20333,
14,
5777,
465,
481,
199,
646,
20333,
14,
4614,
465,
491,
199,
199,
504,
20333,
5107,
14,
5777,
492,
7347,
63,
20581,
63,
988,
63,
5743,
63,
18,
68,
199,
504,
20333,
5107,
14,
4614,
14,
2105,
14,
5598,
63,
18,
68,
63,
10472,
63,
5416,
86,
492,
19140,
18,
2846,
46,
13767,
86,
199,
504,
20333,
5107,
14,
4614,
14,
1238,
14,
70,
2311,
63,
1195,
4411,
14,
4551,
63,
25700,
63,
1200,
492,
971,
272,
22240,
919,
14506,
4491,
199,
504,
20333,
5107,
14,
4614,
14,
1238,
14,
4040,
63,
2993,
63,
1195,
4411,
14,
2966,
63,
1100,
63,
578,
492,
971,
272,
13641,
2998,
2377,
199,
504,
20333,
5107,
14,
4614,
14,
1238,
14,
4040,
63,
2993,
63,
1195,
4411,
14,
4040,
63,
2993,
63,
1195,
4411,
492,
971,
272,
29684,
11664,
8205,
7178,
199,
504,
20333,
5107,
14,
4614,
14,
1238,
14,
28998,
14,
470,
1457,
492,
3591,
3142,
199,
504,
20333,
5107,
14,
4614,
14,
1238,
14,
28998,
14,
28998,
492,
3591,
2480,
4893,
199,
504,
20333,
5107,
492,
3778,
421,
199,
533,
29684,
11664,
8205,
7178,
1322,
2480,
4893,
8,
16393,
11664,
8205,
7178,
304,
339,
408,
16393,
13,
11664,
820,
13,
35,
7178,
4079,
641,
3591,
2480,
4893,
14,
339,
3979,
1265,
4165,
314,
931,
402,
282,
876,
13,
23782,
20333,
1402,
6380,
465,
272,
282,
520,
1113,
5026,
1590,
90,
64,
570,
315,
314,
3787,
12,
642,
6036,
1402,
5847,
272,
2536,
6491,
1006,
314,
2633,
543,
652,
14,
272,
3979,
282,
1059,
315,
25210,
28387,
663,
365,
2741,
12,
282,
876,
23782,
1402,
365,
272,
6511,
687,
4931,
1854,
641,
314,
22026,
14,
272,
710,
769,
402,
876,
23782,
1709,
3748,
787,
465,
11924,
26,
339,
627,
520,
1113,
1705,
331,
331,
8340,
30367,
4931,
28161,
543,
314,
3560,
637,
3715,
402,
971,
267,
5099,
1439,
1487,
5860,
20284,
14,
272,
627,
520,
1113,
1705,
11744,
2268,
386,
8340,
30367,
4931,
28161,
543,
6047,
2480,
8089,
3477,
971,
267,
2120,
367,
314,
3878,
31295,
436,
314,
4854,
4621,
14,
971,
267,
2136,
2492,
626,
886,
440,
1172,
282,
5226,
4045,
315,
3591,
2480,
4893,
971,
267,
911,
506,
19311,
10038,
14,
339,
2104,
18714,
641,
314,
3217,
402,
642,
1402,
12,
8749,
10618,
370,
272,
520,
533,
6054,
4040,
63,
2993,
63,
1195,
4411,
14,
4614,
14,
1238,
14,
4040,
63,
2993,
63,
1195,
4411,
63,
1095,
14,
16393,
11664,
8205,
7178,
64,
339,
520,
533,
6054,
4040,
63,
2993,
63,
1195,
4411,
14,
4614,
14,
1238,
14,
4040,
63,
2993,
63,
1195,
4411,
63,
1095,
14,
16393,
11664,
8205,
7178,
64,
272,
5171,
2583,
281,
3304,
641,
2196,
2536,
12270,
402,
4931,
701,
2368,
272,
520,
1113,
1705,
28998,
63,
2747,
55,
3559,
520,
1113,
1705,
4599,
78,
63,
2747,
55,
3559,
520,
1113,
1705,
2102,
63,
2747,
55,
64,
436,
272,
520,
1113,
1705,
3397,
63,
2747,
55,
2313,
272,
2779,
11479,
282,
4550,
626,
6181,
376,
1625,
436,
7860,
1086,
2399,
1338,
14,
272,
982,
520,
1113,
1705,
403,
64,
365,
3032,
465,
376,
11130,
12,
314,
849,
11130,
365,
272,
1202,
14,
339,
3033,
26,
267,
302,
63,
9681,
63,
533,
334,
442,
304,
710,
1329,
402,
3992,
28529,
314,
8020,
14,
267,
876,
23782,
63,
1238,
334,
875,
304,
710,
5724,
402,
314,
876,
13,
23782,
288,
20333,
1402,
6380,
465,
282,
520,
1113,
5026,
1590,
90,
64,
570,
14,
288,
982,
642,
365,
1373,
402,
314,
3326,
11736,
288,
3432,
12,
652,
5847,
14404,
4931,
5489,
1334,
282,
2082,
288,
520,
1113,
1705,
4,
25256,
540,
63,
28231,
775,
63,
5441,
15,
9928,
846,
15,
27243,
5107,
15,
992,
15,
3559,
288,
2382,
520,
1113,
1705,
4,
25256,
540,
63,
28231,
775,
63,
5441,
64,
365,
663,
465,
288,
520,
1113,
1705,
4,
9524,
8083,
27243,
15,
5214,
64,
7444,
1265,
4165,
4573,
574,
288,
701,
24662,
314,
3734,
1750,
14,
267,
1748,
63,
890,
334,
442,
304,
437,
26471,
1215,
351,
367,
520,
5247,
1705,
6726,
2313,
267,
1390,
63,
890,
334,
442,
304,
437,
26471,
1215,
351,
367,
520,
5247,
1705,
6726,
2313,
267,
660,
9636,
334,
513,
402,
15657,
304,
961,
365,
660,
9636,
402,
3462,
370,
4569,
402,
288,
314,
32682,
14,
267,
12514,
63,
30832,
334,
513,
402,
5579,
304,
961,
365,
787,
305,
402,
32682,
14,
288,
18049,
261,
787,
305,
911,
506,
314,
3336,
402,
314,
12386,
402,
376,
1819,
315,
288,
520,
1113,
1705,
11498,
63,
30832,
64,
436,
314,
3379,
9150,
402,
314,
3659,
288,
4353,
14,
267,
522,
846,
63,
2747,
55,
334,
8296,
304,
6026,
1793,
367,
314,
9393,
5226,
370,
288,
314,
3591,
2480,
4893,
9393,
14,
267,
519,
4812,
63,
2747,
55,
334,
8296,
304,
6026,
1793,
367,
22240,
2165,
14506,
7220,
288,
9393,
14,
267,
4355,
63,
2747,
55,
334,
8296,
304,
6026,
1793,
367,
314,
2257,
2072,
4854,
14,
267,
5396,
63,
2747,
55,
334,
8296,
304,
6026,
1793,
367,
314,
5396,
4854,
14,
267,
28315,
63,
9986,
63,
1162,
334,
807,
304,
2606,
574,
68,
1215,
878,
367,
288,
520,
533,
6054,
27243,
5107,
14,
4614,
14,
1238,
14,
70,
2311,
63,
1195,
4411,
14,
919,
14506,
17523,
2313,
339,
408,
339,
485,
992,
275,
469,
267,
283,
331,
331,
356,
469,
288,
283,
635,
356,
791,
78,
63,
9681,
63,
533,
356,
5939,
1386,
288,
283,
633,
356,
283,
2859,
921,
27243,
5107,
13,
992,
14,
17477,
14,
11538,
4805,
288,
283,
4040,
63,
2993,
63,
1195,
4411,
63,
28998,
4893,
63,
23782,
63,
14982,
63,
1690,
63,
969,
14,
1590,
90,
297,
288,
283,
5107,
18,
356,
715,
267,
1660,
272,
789,
272,
13953,
63,
12318,
275,
3193,
272,
28315,
63,
9986,
63,
1162,
275,
469,
267,
283,
78,
706,
63,
14898,
356,
378,
14,
23,
12,
267,
283,
78,
63,
2834,
63,
657,
63,
78,
706,
356,
3144,
1493,
12,
267,
283,
78,
63,
2834,
63,
1932,
63,
78,
706,
356,
12293,
12,
267,
283,
78,
63,
396,
63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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
hughsie/fwupd
|
data/device-tests/hardware.py
|
2
|
5214
|
#!/usr/bin/python3
# pylint: disable=wrong-import-position,too-many-locals,unused-argument,wrong-import-order
#
# Copyright (C) 2017 Richard Hughes <richard@hughsie.com>
#
# SPDX-License-Identifier: LGPL-2.1+
import gi
import os
import requests
import time
import sys
import glob
import json
from termcolor import colored
gi.require_version('Fwupd', '2.0')
from gi.repository import Fwupd
from gi.repository import Gio
from gi.repository import GLib
def _get_cache_file(fn):
cachedir = os.path.expanduser('~/.cache/fwupdmgr')
if not os.path.exists(cachedir):
os.makedirs(cachedir)
cachefn = os.path.join(cachedir, fn)
if not os.path.exists(cachefn):
url = 'https://fwupd.org/downloads/' + fn
print("Downloading", url)
r = requests.get(url)
r.raise_for_status()
f = open(cachefn, 'wb')
f.write(r.content)
f.close()
return cachefn
class DeviceTest:
def __init__(self, obj):
self.client = Fwupd.Client.new()
self.name = obj.get('name', 'Unknown')
self.guids = obj.get('guids', [])
self.releases = obj.get('releases', [])
self.has_runtime = obj.get('runtime', True)
self.interactive = obj.get('interactive', False)
self.disabled = obj.get('disabled', False)
self.protocol = obj.get('protocol', None)
def _info(self, msg):
print(colored('[INFO]'.ljust(10), 'blue'), msg)
def _warn(self, msg):
print(colored('[WARN]'.ljust(10), 'yellow'), msg)
def _failed(self, msg):
print(colored('[FAILED]'.ljust(10), 'red'), msg)
def _success(self, msg):
print(colored('[SUCCESS]'.ljust(10), 'green'), msg)
def _get_by_device_guids(self):
cancellable = Gio.Cancellable.new()
for d in self.client.get_devices(cancellable):
for guid in self.guids:
if d.has_guid(guid):
if self.protocol and self.protocol != d.get_protocol():
continue
return d
return None
def run(self):
print('Running test on {}'.format(self.name))
dev = self._get_by_device_guids()
if not dev:
self._warn('no {} attached'.format(self.name))
return
self._info('Current version {}'.format(dev.get_version()))
# apply each file
for obj in self.releases:
ver = obj.get('version')
fn = obj.get('file')
repeat = obj.get('repeat', 1)
try:
fn_cache = _get_cache_file(fn)
except requests.exceptions.HTTPError as e:
self._failed('Failed to download: {}'.format(str(e)))
return
# some hardware updates more than one partition with the same firmware
for cnt in range(0, repeat):
if dev.get_version() == ver:
flags = Fwupd.InstallFlags.ALLOW_REINSTALL
self._info('Reinstalling version {}'.format(ver))
else:
flags = Fwupd.InstallFlags.ALLOW_OLDER
self._info('Installing version {}'.format(ver))
cancellable = Gio.Cancellable.new()
try:
self.client.install(dev.get_id(), fn_cache, flags, cancellable)
except GLib.Error as e:
if str(e).find('no HWIDs matched') != -1:
self._info('Skipping as {}'.format(e))
continue
self._failed('Could not install: {}'.format(e))
return
# verify version
if self.has_runtime:
dev = self._get_by_device_guids()
if not dev:
self._failed('Device did not come back: ' + self.name)
return
if not dev.get_version():
self._failed('No version set after flash for: ' + self.name)
return
if cnt == repeat - 1 and dev.get_version() != ver:
self._failed('Got: ' + dev.get_version() + ', expected: ' + ver)
return
self._success('Installed {}'.format(dev.get_version()))
else:
self._success('Assumed success (no runtime)')
# wait for device to settle?
time.sleep(2)
if __name__ == '__main__':
# get manifests to parse
device_fns = []
if len(sys.argv) == 1:
device_fns.extend(glob.glob('devices/*.json'))
else:
for fn in sys.argv[1:]:
device_fns.append(fn)
# run each test
for fn in sorted(device_fns):
print('{}:'.format(fn))
with open(fn, 'r') as f:
try:
obj = json.load(f)
except json.decoder.JSONDecodeError as e:
print('Failed to parse {}: {}'.format(fn, e))
continue
t = DeviceTest(obj)
if t.disabled:
continue
if t.interactive and len(device_fns) > 1:
continue
t.run()
sys.exit(0)
|
lgpl-2.1
|
[
3381,
2647,
15,
1393,
15,
1548,
19,
199,
3,
4287,
26,
3507,
29,
10603,
13,
646,
13,
3124,
12,
7354,
13,
3479,
13,
9350,
12,
8618,
13,
2094,
12,
10603,
13,
646,
13,
1648,
199,
3,
199,
3,
1898,
334,
35,
9,
9708,
30846,
1005,
869,
3080,
397,
665,
10399,
1005,
32,
72,
3080,
23994,
14,
957,
30,
199,
3,
199,
3,
6988,
19596,
13,
3761,
13,
7544,
26,
32426,
13,
18,
14,
17,
11,
199,
199,
646,
18895,
199,
646,
747,
199,
646,
4145,
199,
646,
900,
199,
646,
984,
199,
646,
5739,
199,
646,
2022,
199,
504,
6707,
2326,
492,
32076,
199,
199,
6153,
14,
4365,
63,
1023,
360,
38,
87,
27517,
297,
283,
18,
14,
16,
358,
199,
199,
504,
18895,
14,
8421,
492,
481,
87,
27517,
199,
504,
18895,
14,
8421,
492,
598,
2308,
199,
504,
18895,
14,
8421,
492,
3563,
1892,
421,
199,
318,
485,
362,
63,
1637,
63,
493,
8,
2324,
304,
272,
2581,
694,
275,
747,
14,
515,
14,
12131,
21114,
8083,
1637,
15,
8835,
384,
6428,
2587,
358,
272,
340,
440,
747,
14,
515,
14,
2444,
8,
1637,
694,
304,
267,
747,
14,
8347,
8,
1637,
694,
9,
272,
2581,
2324,
275,
747,
14,
515,
14,
904,
8,
1637,
694,
12,
4325,
9,
272,
340,
440,
747,
14,
515,
14,
2444,
8,
1637,
2324,
304,
267,
1166,
275,
283,
2859,
921,
8835,
27517,
14,
1308,
15,
20373,
4805,
435,
4325,
267,
870,
480,
18085,
401,
1166,
9,
267,
519,
275,
4145,
14,
362,
8,
633,
9,
267,
519,
14,
3730,
63,
509,
63,
1205,
342,
267,
289,
275,
1551,
8,
1637,
2324,
12,
283,
6603,
358,
267,
289,
14,
952,
8,
82,
14,
1317,
9,
267,
289,
14,
1600,
342,
272,
372,
2581,
2324,
421,
199,
533,
12272,
774,
26,
272,
347,
636,
826,
721,
277,
12,
1559,
304,
267,
291,
14,
1258,
275,
481,
87,
27517,
14,
3041,
14,
1222,
342,
267,
291,
14,
354,
275,
1559,
14,
362,
360,
354,
297,
283,
5912,
358,
267,
291,
14,
9473,
83,
275,
1559,
14,
362,
360,
9473,
83,
297,
3073,
267,
291,
14,
11840,
275,
1559,
14,
362,
360,
11840,
297,
3073,
267,
291,
14,
1989,
63,
7726,
275,
1559,
14,
362,
360,
7726,
297,
715,
9,
267,
291,
14,
13543,
275,
1559,
14,
362,
360,
13543,
297,
756,
9,
267,
291,
14,
7011,
275,
1559,
14,
362,
360,
7011,
297,
756,
9,
267,
291,
14,
3922,
275,
1559,
14,
362,
360,
3922,
297,
488,
9,
339,
347,
485,
815,
8,
277,
12,
1499,
304,
267,
870,
8,
331,
21252,
11894,
4531,
61,
1370,
19996,
8,
709,
395,
283,
6304,
659,
1499,
9,
339,
347,
485,
4050,
8,
277,
12,
1499,
304,
267,
870,
8,
331,
21252,
11894,
17449,
61,
1370,
19996,
8,
709,
395,
283,
14514,
659,
1499,
9,
339,
347,
485,
4892,
8,
277,
12,
1499,
304,
267,
870,
8,
331,
21252,
11894,
12299,
61,
1370,
19996,
8,
709,
395,
283,
581,
659,
1499,
9,
339,
347,
485,
3742,
8,
277,
12,
1499,
304,
267,
870,
8,
331,
21252,
11894,
12779,
61,
1370,
19996,
8,
709,
395,
283,
7731,
659,
1499,
9,
339,
347,
485,
362,
63,
991,
63,
1782,
63,
9473,
83,
8,
277,
304,
267,
286,
554,
914,
461,
275,
598,
2308,
14,
35,
554,
914,
461,
14,
1222,
342,
267,
367,
366,
315,
291,
14,
1258,
14,
362,
63,
6410,
8,
67,
554,
914,
461,
304,
288,
367,
15593,
315,
291,
14,
9473,
83,
26,
355,
340,
366,
14,
1989,
63,
9473,
8,
9473,
304,
490,
340,
291,
14,
3922,
436,
291,
14,
3922,
1137,
366,
14,
362,
63,
3922,
837,
717,
1980,
490,
372,
366,
267,
372,
488,
339,
347,
1255,
8,
277,
304,
398,
870,
360,
9602,
511,
641,
9499,
908,
8,
277,
14,
354,
430,
267,
4866,
275,
291,
423,
362,
63,
991,
63,
1782,
63,
9473,
83,
342,
267,
340,
440,
4866,
26,
288,
291,
423,
4050,
360,
889,
1052,
10102,
1370,
908,
8,
277,
14,
354,
430,
288,
372,
398,
291,
423,
815,
360,
5639,
1015,
9499,
908,
8,
2374,
14,
362,
63,
1023,
4059,
398,
327,
4838,
1924,
570,
267,
367,
1559,
315,
291,
14,
11840,
26,
288,
809,
275,
1559,
14,
362,
360,
1023,
358,
288,
4325,
275,
1559,
14,
362,
360,
493,
358,
288,
11982,
275,
1559,
14,
362,
360,
8755,
297,
413,
9,
288,
862,
26,
355,
4325,
63,
1637,
275,
485,
362,
63,
1637,
63,
493,
8,
2324,
9,
288,
871,
4145,
14,
3924,
14,
12815,
465,
325,
26,
355,
291,
423,
4892,
360,
4276,
370,
5235,
26,
9499,
908,
8,
495,
8,
69,
1724,
355,
372,
953,
327,
2005,
14991,
7029,
1655,
2419,
1373,
6484,
543,
314,
2011,
27969,
288,
367,
12703,
315,
1425,
8,
16,
12,
11982,
304,
355,
340,
4866,
14,
362,
63,
1023,
342,
508,
809,
26,
490,
3285,
275,
481,
87,
27517,
14,
8154,
6381,
14,
12231,
63,
907,
16811,
490,
291,
423,
815,
360,
497,
3174,
316,
1015,
9499,
908,
8,
422,
430,
355,
587,
26,
490,
3285,
275,
481,
87,
27517,
14,
8154,
6381,
14,
12231,
63,
15744,
490,
291,
423,
815,
360,
31376,
1015,
9499,
908,
8,
422,
430,
355,
286,
554,
914,
461,
275,
598,
2308,
14,
35,
554,
914,
461,
14,
1222,
342,
2234,
862,
26,
490,
291,
14,
1258,
14,
3174,
8,
2374,
14,
362,
63,
344,
1062,
4325,
63,
1637,
12,
3285,
12,
286,
554,
914,
461,
9,
355,
871,
3563,
1892,
14,
547,
465,
325,
26,
490,
340,
620,
8,
69,
680,
1623,
360,
889,
869,
9845,
83,
7838,
358,
1137,
446,
17,
26,
717,
291,
423,
815,
360,
18297,
465,
9499,
908,
8,
69,
430,
717,
1980,
490,
291,
423,
4892,
360,
6531,
440,
3907,
26,
9499,
908,
8,
69,
430,
490,
372,
2234,
327,
4911,
1015,
355,
340,
291,
14,
1989,
63,
7726,
26,
490,
4866,
275,
291,
423,
362,
63,
991,
63,
1782,
63,
9473,
83,
342,
490,
340,
440,
4866,
26,
717,
291,
423,
4892,
360,
2510,
8103,
440,
11492,
1771,
26,
283,
435,
291,
14,
354,
9,
717,
372,
490,
340,
440,
4866,
14,
362,
63,
1023,
837,
717,
291,
423,
4892,
360
] |
[
2647,
15,
1393,
15,
1548,
19,
199,
3,
4287,
26,
3507,
29,
10603,
13,
646,
13,
3124,
12,
7354,
13,
3479,
13,
9350,
12,
8618,
13,
2094,
12,
10603,
13,
646,
13,
1648,
199,
3,
199,
3,
1898,
334,
35,
9,
9708,
30846,
1005,
869,
3080,
397,
665,
10399,
1005,
32,
72,
3080,
23994,
14,
957,
30,
199,
3,
199,
3,
6988,
19596,
13,
3761,
13,
7544,
26,
32426,
13,
18,
14,
17,
11,
199,
199,
646,
18895,
199,
646,
747,
199,
646,
4145,
199,
646,
900,
199,
646,
984,
199,
646,
5739,
199,
646,
2022,
199,
504,
6707,
2326,
492,
32076,
199,
199,
6153,
14,
4365,
63,
1023,
360,
38,
87,
27517,
297,
283,
18,
14,
16,
358,
199,
199,
504,
18895,
14,
8421,
492,
481,
87,
27517,
199,
504,
18895,
14,
8421,
492,
598,
2308,
199,
504,
18895,
14,
8421,
492,
3563,
1892,
421,
199,
318,
485,
362,
63,
1637,
63,
493,
8,
2324,
304,
272,
2581,
694,
275,
747,
14,
515,
14,
12131,
21114,
8083,
1637,
15,
8835,
384,
6428,
2587,
358,
272,
340,
440,
747,
14,
515,
14,
2444,
8,
1637,
694,
304,
267,
747,
14,
8347,
8,
1637,
694,
9,
272,
2581,
2324,
275,
747,
14,
515,
14,
904,
8,
1637,
694,
12,
4325,
9,
272,
340,
440,
747,
14,
515,
14,
2444,
8,
1637,
2324,
304,
267,
1166,
275,
283,
2859,
921,
8835,
27517,
14,
1308,
15,
20373,
4805,
435,
4325,
267,
870,
480,
18085,
401,
1166,
9,
267,
519,
275,
4145,
14,
362,
8,
633,
9,
267,
519,
14,
3730,
63,
509,
63,
1205,
342,
267,
289,
275,
1551,
8,
1637,
2324,
12,
283,
6603,
358,
267,
289,
14,
952,
8,
82,
14,
1317,
9,
267,
289,
14,
1600,
342,
272,
372,
2581,
2324,
421,
199,
533,
12272,
774,
26,
272,
347,
636,
826,
721,
277,
12,
1559,
304,
267,
291,
14,
1258,
275,
481,
87,
27517,
14,
3041,
14,
1222,
342,
267,
291,
14,
354,
275,
1559,
14,
362,
360,
354,
297,
283,
5912,
358,
267,
291,
14,
9473,
83,
275,
1559,
14,
362,
360,
9473,
83,
297,
3073,
267,
291,
14,
11840,
275,
1559,
14,
362,
360,
11840,
297,
3073,
267,
291,
14,
1989,
63,
7726,
275,
1559,
14,
362,
360,
7726,
297,
715,
9,
267,
291,
14,
13543,
275,
1559,
14,
362,
360,
13543,
297,
756,
9,
267,
291,
14,
7011,
275,
1559,
14,
362,
360,
7011,
297,
756,
9,
267,
291,
14,
3922,
275,
1559,
14,
362,
360,
3922,
297,
488,
9,
339,
347,
485,
815,
8,
277,
12,
1499,
304,
267,
870,
8,
331,
21252,
11894,
4531,
61,
1370,
19996,
8,
709,
395,
283,
6304,
659,
1499,
9,
339,
347,
485,
4050,
8,
277,
12,
1499,
304,
267,
870,
8,
331,
21252,
11894,
17449,
61,
1370,
19996,
8,
709,
395,
283,
14514,
659,
1499,
9,
339,
347,
485,
4892,
8,
277,
12,
1499,
304,
267,
870,
8,
331,
21252,
11894,
12299,
61,
1370,
19996,
8,
709,
395,
283,
581,
659,
1499,
9,
339,
347,
485,
3742,
8,
277,
12,
1499,
304,
267,
870,
8,
331,
21252,
11894,
12779,
61,
1370,
19996,
8,
709,
395,
283,
7731,
659,
1499,
9,
339,
347,
485,
362,
63,
991,
63,
1782,
63,
9473,
83,
8,
277,
304,
267,
286,
554,
914,
461,
275,
598,
2308,
14,
35,
554,
914,
461,
14,
1222,
342,
267,
367,
366,
315,
291,
14,
1258,
14,
362,
63,
6410,
8,
67,
554,
914,
461,
304,
288,
367,
15593,
315,
291,
14,
9473,
83,
26,
355,
340,
366,
14,
1989,
63,
9473,
8,
9473,
304,
490,
340,
291,
14,
3922,
436,
291,
14,
3922,
1137,
366,
14,
362,
63,
3922,
837,
717,
1980,
490,
372,
366,
267,
372,
488,
339,
347,
1255,
8,
277,
304,
398,
870,
360,
9602,
511,
641,
9499,
908,
8,
277,
14,
354,
430,
267,
4866,
275,
291,
423,
362,
63,
991,
63,
1782,
63,
9473,
83,
342,
267,
340,
440,
4866,
26,
288,
291,
423,
4050,
360,
889,
1052,
10102,
1370,
908,
8,
277,
14,
354,
430,
288,
372,
398,
291,
423,
815,
360,
5639,
1015,
9499,
908,
8,
2374,
14,
362,
63,
1023,
4059,
398,
327,
4838,
1924,
570,
267,
367,
1559,
315,
291,
14,
11840,
26,
288,
809,
275,
1559,
14,
362,
360,
1023,
358,
288,
4325,
275,
1559,
14,
362,
360,
493,
358,
288,
11982,
275,
1559,
14,
362,
360,
8755,
297,
413,
9,
288,
862,
26,
355,
4325,
63,
1637,
275,
485,
362,
63,
1637,
63,
493,
8,
2324,
9,
288,
871,
4145,
14,
3924,
14,
12815,
465,
325,
26,
355,
291,
423,
4892,
360,
4276,
370,
5235,
26,
9499,
908,
8,
495,
8,
69,
1724,
355,
372,
953,
327,
2005,
14991,
7029,
1655,
2419,
1373,
6484,
543,
314,
2011,
27969,
288,
367,
12703,
315,
1425,
8,
16,
12,
11982,
304,
355,
340,
4866,
14,
362,
63,
1023,
342,
508,
809,
26,
490,
3285,
275,
481,
87,
27517,
14,
8154,
6381,
14,
12231,
63,
907,
16811,
490,
291,
423,
815,
360,
497,
3174,
316,
1015,
9499,
908,
8,
422,
430,
355,
587,
26,
490,
3285,
275,
481,
87,
27517,
14,
8154,
6381,
14,
12231,
63,
15744,
490,
291,
423,
815,
360,
31376,
1015,
9499,
908,
8,
422,
430,
355,
286,
554,
914,
461,
275,
598,
2308,
14,
35,
554,
914,
461,
14,
1222,
342,
2234,
862,
26,
490,
291,
14,
1258,
14,
3174,
8,
2374,
14,
362,
63,
344,
1062,
4325,
63,
1637,
12,
3285,
12,
286,
554,
914,
461,
9,
355,
871,
3563,
1892,
14,
547,
465,
325,
26,
490,
340,
620,
8,
69,
680,
1623,
360,
889,
869,
9845,
83,
7838,
358,
1137,
446,
17,
26,
717,
291,
423,
815,
360,
18297,
465,
9499,
908,
8,
69,
430,
717,
1980,
490,
291,
423,
4892,
360,
6531,
440,
3907,
26,
9499,
908,
8,
69,
430,
490,
372,
2234,
327,
4911,
1015,
355,
340,
291,
14,
1989,
63,
7726,
26,
490,
4866,
275,
291,
423,
362,
63,
991,
63,
1782,
63,
9473,
83,
342,
490,
340,
440,
4866,
26,
717,
291,
423,
4892,
360,
2510,
8103,
440,
11492,
1771,
26,
283,
435,
291,
14,
354,
9,
717,
372,
490,
340,
440,
4866,
14,
362,
63,
1023,
837,
717,
291,
423,
4892,
360,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
birsoyo/conan
|
conans/client/rest/auth_manager.py
|
1
|
8686
|
"""
Collaborate with RestApiClient to make remote anonymous and authenticated calls.
Uses user_io to request user's login and password and obtain a token for calling authenticated
methods if receives AuthenticationException from RestApiClient.
Flow:
Directly invoke a REST method in RestApiClient, example: get_conan.
if receives AuthenticationException (not open method) will ask user for login and password
and will invoke RestApiClient.get_token() (with LOGIN_RETRIES retries) and retry to call
get_conan with the new token.
"""
from conans.errors import AuthenticationException, ForbiddenException, ConanException
from uuid import getnode as get_mac
import hashlib
from conans.util.log import logger
from conans.client.cmd.user import update_localdb
def input_credentials_if_unauthorized(func):
"""Decorator. Handles AuthenticationException and request user
to input a user and a password"""
LOGIN_RETRIES = 3
def wrapper(self, *args, **kwargs):
try:
# Set custom headers of mac_digest and username
self.set_custom_headers(self.user)
ret = func(self, *args, **kwargs)
return ret
except ForbiddenException:
raise ForbiddenException("Permission denied for user: '%s'" % self.user)
except AuthenticationException:
# User valid but not enough permissions
if self.user is None or self._rest_client.token is None:
# token is None when you change user with user command
# Anonymous is not enough, ask for a user
remote = self.remote
self._user_io.out.info('Please log in to "%s" to perform this action. '
'Execute "conan user" command.' % remote.name)
if "bintray" in remote.url:
self._user_io.out.info('If you don\'t have an account sign up here: '
'https://bintray.com/signup/oss')
return retry_with_new_token(self, *args, **kwargs)
else:
# Token expired or not valid, so clean the token and repeat the call
# (will be anonymous call but exporting who is calling)
logger.info("Token expired or not valid, cleaning the saved token and retrying")
self._store_login((self.user, None))
self._rest_client.token = None
# Set custom headers of mac_digest and username
self.set_custom_headers(self.user)
return wrapper(self, *args, **kwargs)
def retry_with_new_token(self, *args, **kwargs):
"""Try LOGIN_RETRIES to obtain a password from user input for which
we can get a valid token from api_client. If a token is returned,
credentials are stored in localdb and rest method is called"""
for _ in range(LOGIN_RETRIES):
user, password = self._user_io.request_login(self._remote.name, self.user)
try:
token, _, _, _ = self.authenticate(user, password)
except AuthenticationException:
if self.user is None:
self._user_io.out.error('Wrong user or password')
else:
self._user_io.out.error(
'Wrong password for user "%s"' % self.user)
self._user_io.out.info(
'You can change username with "conan user <username>"')
else:
logger.debug("Got token: %s" % str(token))
self._rest_client.token = token
self.user = user
# Set custom headers of mac_digest and username
self.set_custom_headers(user)
return wrapper(self, *args, **kwargs)
raise AuthenticationException("Too many failed login attempts, bye!")
return wrapper
class ConanApiAuthManager(object):
def __init__(self, rest_client, user_io, localdb):
self._user_io = user_io
self._rest_client = rest_client
self._localdb = localdb
self._remote = None
@property
def remote(self):
return self._remote
@remote.setter
def remote(self, remote):
self._remote = remote
self._rest_client.remote_url = remote.url
self._rest_client.verify_ssl = remote.verify_ssl
self.user, self._rest_client.token = self._localdb.get_login(remote.url)
def _store_login(self, login):
try:
self._localdb.set_login(login, self._remote.url)
except Exception as e:
self._user_io.out.error(
'Your credentials could not be stored in local cache\n')
self._user_io.out.debug(str(e) + '\n')
@staticmethod
def get_mac_digest():
sha1 = hashlib.sha1()
sha1.update(str(get_mac()).encode())
return str(sha1.hexdigest())
def set_custom_headers(self, username):
# First identifies our machine, second the username even if it was not
# authenticated
custom_headers = self._rest_client.custom_headers
custom_headers['X-Client-Anonymous-Id'] = self.get_mac_digest()
custom_headers['X-Client-Id'] = str(username or "")
# ######### CONAN API METHODS ##########
@input_credentials_if_unauthorized
def upload_recipe(self, conan_reference, the_files, retry, retry_wait, ignore_deleted_file,
no_overwrite):
return self._rest_client.upload_recipe(conan_reference, the_files, retry, retry_wait,
ignore_deleted_file, no_overwrite)
@input_credentials_if_unauthorized
def upload_package(self, package_reference, the_files, retry, retry_wait, no_overwrite):
return self._rest_client.upload_package(package_reference, the_files, retry, retry_wait,
no_overwrite)
@input_credentials_if_unauthorized
def get_conan_manifest(self, conan_reference):
return self._rest_client.get_conan_manifest(conan_reference)
@input_credentials_if_unauthorized
def get_package_manifest(self, package_reference):
return self._rest_client.get_package_manifest(package_reference)
@input_credentials_if_unauthorized
def get_package(self, package_reference, dest_folder):
return self._rest_client.get_package(package_reference, dest_folder)
@input_credentials_if_unauthorized
def get_recipe(self, reference, dest_folder):
return self._rest_client.get_recipe(reference, dest_folder)
@input_credentials_if_unauthorized
def get_recipe_sources(self, reference, dest_folder):
return self._rest_client.get_recipe_sources(reference, dest_folder)
@input_credentials_if_unauthorized
def download_files_to_folder(self, urls, dest_folder):
return self._rest_client.download_files_to_folder(urls, dest_folder)
@input_credentials_if_unauthorized
def get_package_info(self, package_reference):
return self._rest_client.get_package_info(package_reference)
@input_credentials_if_unauthorized
def search(self, pattern, ignorecase):
return self._rest_client.search(pattern, ignorecase)
@input_credentials_if_unauthorized
def search_packages(self, reference, query):
return self._rest_client.search_packages(reference, query)
@input_credentials_if_unauthorized
def remove(self, conan_refernce):
return self._rest_client.remove_conanfile(conan_refernce)
@input_credentials_if_unauthorized
def remove_packages(self, conan_reference, package_ids):
return self._rest_client.remove_packages(conan_reference, package_ids)
@input_credentials_if_unauthorized
def get_path(self, conan_reference, path, package_id):
return self._rest_client.get_path(conan_reference, path, package_id)
def authenticate(self, user, password):
if user is None: # The user is already in DB, just need the passwd
prev_user = self._localdb.get_username(self._remote.url)
if prev_user is None:
raise ConanException("User for remote '%s' is not defined" % self._remote.name)
else:
user = prev_user
try:
token = self._rest_client.authenticate(user, password)
except UnicodeDecodeError:
raise ConanException("Password contains not allowed symbols")
# Store result in DB
remote_name, prev_user, user = update_localdb(self._localdb, user, token, self._remote)
return token, remote_name, prev_user, user
|
mit
|
[
624,
199,
2001,
5561,
269,
323,
543,
30417,
7394,
3041,
370,
1852,
3982,
16535,
436,
15082,
4882,
14,
199,
21896,
922,
63,
2308,
370,
1056,
922,
1159,
4676,
436,
2505,
436,
3332,
282,
1526,
367,
6358,
15082,
199,
2474,
340,
23192,
15995,
1726,
687,
30417,
7394,
3041,
14,
421,
199,
5060,
26,
339,
21128,
590,
12677,
282,
14880,
1083,
315,
30417,
7394,
3041,
12,
2893,
26,
664,
63,
388,
290,
14,
272,
340,
23192,
15995,
1726,
334,
1397,
1551,
1083,
9,
911,
7198,
922,
367,
4676,
436,
2505,
272,
436,
911,
12677,
30417,
7394,
3041,
14,
362,
63,
1418,
342,
334,
1045,
5051,
568,
63,
32528,
10086,
9,
436,
7269,
370,
1240,
272,
664,
63,
388,
290,
543,
314,
892,
1526,
14,
199,
624,
199,
199,
504,
406,
796,
14,
2550,
492,
15995,
1726,
12,
2104,
10912,
1726,
12,
1448,
290,
1726,
199,
504,
5377,
492,
664,
932,
465,
664,
63,
3088,
199,
646,
8337,
199,
504,
406,
796,
14,
1974,
14,
793,
492,
2512,
199,
504,
406,
796,
14,
1258,
14,
1760,
14,
751,
492,
1678,
63,
1832,
697,
421,
199,
318,
1324,
63,
6942,
63,
692,
63,
324,
11497,
8,
1532,
304,
272,
408,
14946,
14,
23873,
15995,
1726,
436,
1056,
922,
272,
370,
1324,
282,
922,
436,
282,
2505,
624,
272,
5051,
568,
63,
32528,
275,
650,
339,
347,
4975,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
862,
26,
288,
327,
2494,
3537,
2323,
402,
4497,
63,
5671,
436,
3434,
288,
291,
14,
409,
63,
4229,
63,
2139,
8,
277,
14,
751,
9,
288,
2203,
275,
2562,
8,
277,
12,
627,
589,
12,
1011,
958,
9,
288,
372,
2203,
267,
871,
2104,
10912,
1726,
26,
288,
746,
2104,
10912,
1726,
480,
7980,
23355,
367,
922,
26,
1543,
83,
4065,
450,
291,
14,
751,
9,
267,
871,
15995,
1726,
26,
288,
327,
2876,
1686,
1325,
440,
8321,
3443,
288,
340,
291,
14,
751,
365,
488,
503,
291,
423,
3911,
63,
1258,
14,
1418,
365,
488,
26,
355,
327,
1526,
365,
488,
1380,
1265,
1570,
922,
543,
922,
1414,
355,
327,
24523,
365,
440,
8321,
12,
7198,
367,
282,
922,
355,
3982,
275,
291,
14,
3846,
355,
291,
423,
751,
63,
2308,
14,
548,
14,
815,
360,
8254,
943,
315,
370,
2071,
83,
2,
370,
5147,
642,
1595,
14,
283,
4318,
283,
12049,
298,
388,
290,
922,
2,
1414,
3530,
450,
3982,
14,
354,
9,
355,
340,
298,
66,
442,
803,
2,
315,
3982,
14,
633,
26,
490,
291,
423,
751,
63,
2308,
14,
548,
14,
815,
360,
3917,
1265,
2793,
3985,
84,
1172,
376,
2933,
2070,
1536,
2348,
26,
283,
5644,
283,
2859,
921,
66,
442,
803,
14,
957,
15,
19799,
15,
26890,
358,
355,
372,
7269,
63,
1045,
63,
1222,
63,
1418,
8,
277,
12,
627,
589,
12,
1011,
958,
9,
288,
587,
26,
355,
327,
8767,
14721,
503,
440,
1686,
12,
880,
3633,
314,
1526,
436,
11982,
314,
1240,
355,
327,
334,
14117,
506,
16535,
1240,
1325,
4843,
316,
3963,
365,
6358,
9,
355,
2512,
14,
815,
480,
3264,
14721,
503,
440,
1686,
12,
29579,
314,
6290,
1526,
436,
7269,
316,
531,
355,
291,
423,
1617,
63,
2886,
1332,
277,
14,
751,
12,
488,
430,
355,
291,
423,
3911,
63,
1258,
14,
1418,
275,
488,
355,
327,
2494,
3537,
2323,
402,
4497,
63,
5671,
436,
3434,
355,
291,
14,
409,
63,
4229,
63,
2139,
8,
277,
14,
751,
9,
355,
372,
4975,
8,
277,
12,
627,
589,
12,
1011,
958,
9,
339,
347,
7269,
63,
1045,
63,
1222,
63,
1418,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
408,
12357,
5051,
568,
63,
32528,
370,
3332,
282,
2505,
687,
922,
1324,
367,
1314,
267,
781,
883,
664,
282,
1686,
1526,
687,
2986,
63,
1258,
14,
982,
282,
1526,
365,
2138,
12,
267,
6235,
787,
5489,
315,
2257,
697,
436,
4618,
1083,
365,
2797,
624,
267,
367,
485,
315,
1425,
8,
17208,
63,
32528,
304,
288,
922,
12,
2505,
275,
291,
423,
751,
63,
2308,
14,
1069,
63,
2886,
8,
277,
423,
3846,
14,
354,
12,
291,
14,
751,
9,
288,
862,
26,
355,
1526,
12,
5501,
5501,
485,
275,
291,
14,
13975,
8,
751,
12,
2505,
9,
288,
871,
15995,
1726,
26,
355,
340,
291,
14,
751,
365,
488,
26,
490,
291,
423,
751,
63,
2308,
14,
548,
14,
705,
360,
14858,
922,
503,
2505,
358,
355,
587,
26,
490,
291,
423,
751,
63,
2308,
14,
548,
14,
705,
8,
717,
283,
14858,
2505,
367,
922,
2071,
83,
4507,
450,
291,
14,
751,
9,
490,
291,
423,
751,
63,
2308,
14,
548,
14,
815,
8,
717,
283,
5556,
883,
1570,
3434,
543,
298,
388,
290,
922,
665,
2473,
4335,
358,
288,
587,
26,
355,
2512,
14,
1757,
480,
13662,
1526,
26,
450,
83,
2,
450,
620,
8,
1418,
430,
355,
291,
423,
3911,
63,
1258,
14,
1418,
275,
1526,
355,
291,
14,
751,
275,
922,
355,
327,
2494,
3537,
2323,
402,
4497,
63,
5671,
436,
3434,
355,
291,
14,
409,
63,
4229,
63,
2139,
8,
751,
9,
355,
372,
4975,
8,
277,
12,
627,
589,
12,
1011,
958,
9,
398,
746,
15995,
1726,
480,
13749,
5002,
3405,
4676,
12454,
12,
701,
69,
9124,
272,
372,
4975,
421,
199,
533,
1448,
290,
7394,
2817,
2988,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
4618,
63,
1258,
12,
922,
63,
2308,
12,
2257,
697,
304,
267,
291,
423,
751,
63,
2308,
275,
922,
63,
2308,
267,
291,
423,
3911,
63,
1258,
275,
4618,
63,
1258,
267,
291,
423,
1832,
697,
275,
2257,
697,
267,
291,
423,
3846,
275,
488,
339,
768,
1829,
272,
347,
3982,
8,
277,
304,
267,
372,
291,
423,
3846,
339,
768,
3846,
14,
8345,
272,
347,
3982,
8,
277,
12,
3982,
304,
267,
291,
423,
3846,
275,
3982,
267,
291,
423,
3911,
63,
1258,
14,
3846,
63,
633,
275,
3982,
14,
633,
267,
291,
423,
3911,
63,
1258,
14,
4712,
63,
4266,
275,
3982,
14,
4712,
63,
4266,
267,
291,
14,
751,
12,
291,
423,
3911,
63,
1258,
14,
1418,
275,
291,
423,
1832,
697,
14,
362,
63,
2886,
8,
3846,
14,
633,
9,
339,
347,
485,
1617,
63,
2886,
8
] |
[
199,
2001,
5561,
269,
323,
543,
30417,
7394,
3041,
370,
1852,
3982,
16535,
436,
15082,
4882,
14,
199,
21896,
922,
63,
2308,
370,
1056,
922,
1159,
4676,
436,
2505,
436,
3332,
282,
1526,
367,
6358,
15082,
199,
2474,
340,
23192,
15995,
1726,
687,
30417,
7394,
3041,
14,
421,
199,
5060,
26,
339,
21128,
590,
12677,
282,
14880,
1083,
315,
30417,
7394,
3041,
12,
2893,
26,
664,
63,
388,
290,
14,
272,
340,
23192,
15995,
1726,
334,
1397,
1551,
1083,
9,
911,
7198,
922,
367,
4676,
436,
2505,
272,
436,
911,
12677,
30417,
7394,
3041,
14,
362,
63,
1418,
342,
334,
1045,
5051,
568,
63,
32528,
10086,
9,
436,
7269,
370,
1240,
272,
664,
63,
388,
290,
543,
314,
892,
1526,
14,
199,
624,
199,
199,
504,
406,
796,
14,
2550,
492,
15995,
1726,
12,
2104,
10912,
1726,
12,
1448,
290,
1726,
199,
504,
5377,
492,
664,
932,
465,
664,
63,
3088,
199,
646,
8337,
199,
504,
406,
796,
14,
1974,
14,
793,
492,
2512,
199,
504,
406,
796,
14,
1258,
14,
1760,
14,
751,
492,
1678,
63,
1832,
697,
421,
199,
318,
1324,
63,
6942,
63,
692,
63,
324,
11497,
8,
1532,
304,
272,
408,
14946,
14,
23873,
15995,
1726,
436,
1056,
922,
272,
370,
1324,
282,
922,
436,
282,
2505,
624,
272,
5051,
568,
63,
32528,
275,
650,
339,
347,
4975,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
862,
26,
288,
327,
2494,
3537,
2323,
402,
4497,
63,
5671,
436,
3434,
288,
291,
14,
409,
63,
4229,
63,
2139,
8,
277,
14,
751,
9,
288,
2203,
275,
2562,
8,
277,
12,
627,
589,
12,
1011,
958,
9,
288,
372,
2203,
267,
871,
2104,
10912,
1726,
26,
288,
746,
2104,
10912,
1726,
480,
7980,
23355,
367,
922,
26,
1543,
83,
4065,
450,
291,
14,
751,
9,
267,
871,
15995,
1726,
26,
288,
327,
2876,
1686,
1325,
440,
8321,
3443,
288,
340,
291,
14,
751,
365,
488,
503,
291,
423,
3911,
63,
1258,
14,
1418,
365,
488,
26,
355,
327,
1526,
365,
488,
1380,
1265,
1570,
922,
543,
922,
1414,
355,
327,
24523,
365,
440,
8321,
12,
7198,
367,
282,
922,
355,
3982,
275,
291,
14,
3846,
355,
291,
423,
751,
63,
2308,
14,
548,
14,
815,
360,
8254,
943,
315,
370,
2071,
83,
2,
370,
5147,
642,
1595,
14,
283,
4318,
283,
12049,
298,
388,
290,
922,
2,
1414,
3530,
450,
3982,
14,
354,
9,
355,
340,
298,
66,
442,
803,
2,
315,
3982,
14,
633,
26,
490,
291,
423,
751,
63,
2308,
14,
548,
14,
815,
360,
3917,
1265,
2793,
3985,
84,
1172,
376,
2933,
2070,
1536,
2348,
26,
283,
5644,
283,
2859,
921,
66,
442,
803,
14,
957,
15,
19799,
15,
26890,
358,
355,
372,
7269,
63,
1045,
63,
1222,
63,
1418,
8,
277,
12,
627,
589,
12,
1011,
958,
9,
288,
587,
26,
355,
327,
8767,
14721,
503,
440,
1686,
12,
880,
3633,
314,
1526,
436,
11982,
314,
1240,
355,
327,
334,
14117,
506,
16535,
1240,
1325,
4843,
316,
3963,
365,
6358,
9,
355,
2512,
14,
815,
480,
3264,
14721,
503,
440,
1686,
12,
29579,
314,
6290,
1526,
436,
7269,
316,
531,
355,
291,
423,
1617,
63,
2886,
1332,
277,
14,
751,
12,
488,
430,
355,
291,
423,
3911,
63,
1258,
14,
1418,
275,
488,
355,
327,
2494,
3537,
2323,
402,
4497,
63,
5671,
436,
3434,
355,
291,
14,
409,
63,
4229,
63,
2139,
8,
277,
14,
751,
9,
355,
372,
4975,
8,
277,
12,
627,
589,
12,
1011,
958,
9,
339,
347,
7269,
63,
1045,
63,
1222,
63,
1418,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
408,
12357,
5051,
568,
63,
32528,
370,
3332,
282,
2505,
687,
922,
1324,
367,
1314,
267,
781,
883,
664,
282,
1686,
1526,
687,
2986,
63,
1258,
14,
982,
282,
1526,
365,
2138,
12,
267,
6235,
787,
5489,
315,
2257,
697,
436,
4618,
1083,
365,
2797,
624,
267,
367,
485,
315,
1425,
8,
17208,
63,
32528,
304,
288,
922,
12,
2505,
275,
291,
423,
751,
63,
2308,
14,
1069,
63,
2886,
8,
277,
423,
3846,
14,
354,
12,
291,
14,
751,
9,
288,
862,
26,
355,
1526,
12,
5501,
5501,
485,
275,
291,
14,
13975,
8,
751,
12,
2505,
9,
288,
871,
15995,
1726,
26,
355,
340,
291,
14,
751,
365,
488,
26,
490,
291,
423,
751,
63,
2308,
14,
548,
14,
705,
360,
14858,
922,
503,
2505,
358,
355,
587,
26,
490,
291,
423,
751,
63,
2308,
14,
548,
14,
705,
8,
717,
283,
14858,
2505,
367,
922,
2071,
83,
4507,
450,
291,
14,
751,
9,
490,
291,
423,
751,
63,
2308,
14,
548,
14,
815,
8,
717,
283,
5556,
883,
1570,
3434,
543,
298,
388,
290,
922,
665,
2473,
4335,
358,
288,
587,
26,
355,
2512,
14,
1757,
480,
13662,
1526,
26,
450,
83,
2,
450,
620,
8,
1418,
430,
355,
291,
423,
3911,
63,
1258,
14,
1418,
275,
1526,
355,
291,
14,
751,
275,
922,
355,
327,
2494,
3537,
2323,
402,
4497,
63,
5671,
436,
3434,
355,
291,
14,
409,
63,
4229,
63,
2139,
8,
751,
9,
355,
372,
4975,
8,
277,
12,
627,
589,
12,
1011,
958,
9,
398,
746,
15995,
1726,
480,
13749,
5002,
3405,
4676,
12454,
12,
701,
69,
9124,
272,
372,
4975,
421,
199,
533,
1448,
290,
7394,
2817,
2988,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
4618,
63,
1258,
12,
922,
63,
2308,
12,
2257,
697,
304,
267,
291,
423,
751,
63,
2308,
275,
922,
63,
2308,
267,
291,
423,
3911,
63,
1258,
275,
4618,
63,
1258,
267,
291,
423,
1832,
697,
275,
2257,
697,
267,
291,
423,
3846,
275,
488,
339,
768,
1829,
272,
347,
3982,
8,
277,
304,
267,
372,
291,
423,
3846,
339,
768,
3846,
14,
8345,
272,
347,
3982,
8,
277,
12,
3982,
304,
267,
291,
423,
3846,
275,
3982,
267,
291,
423,
3911,
63,
1258,
14,
3846,
63,
633,
275,
3982,
14,
633,
267,
291,
423,
3911,
63,
1258,
14,
4712,
63,
4266,
275,
3982,
14,
4712,
63,
4266,
267,
291,
14,
751,
12,
291,
423,
3911,
63,
1258,
14,
1418,
275,
291,
423,
1832,
697,
14,
362,
63,
2886,
8,
3846,
14,
633,
9,
339,
347,
485,
1617,
63,
2886,
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,
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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
] |
kvar/ansible
|
test/units/modules/cloud/amazon/test_ec2_vpc_vpn.py
|
8
|
15110
|
# (c) 2017 Red Hat Inc.
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
import pytest
import os
from units.utils.amazon_placebo_fixtures import placeboify, maybe_sleep
from ansible.modules.cloud.amazon import ec2_vpc_vpn
from ansible.module_utils.ec2 import get_aws_connection_info, boto3_conn, boto3_tag_list_to_ansible_dict
class FakeModule(object):
def __init__(self, **kwargs):
self.params = kwargs
def fail_json(self, *args, **kwargs):
self.exit_args = args
self.exit_kwargs = kwargs
raise Exception('FAIL')
def exit_json(self, *args, **kwargs):
self.exit_args = args
self.exit_kwargs = kwargs
def get_vgw(connection):
# see if two vgw exist and return them if so
vgw = connection.describe_vpn_gateways(Filters=[{'Name': 'tag:Ansible_VPN', 'Values': ['Test']}])
if len(vgw['VpnGateways']) >= 2:
return [vgw['VpnGateways'][0]['VpnGatewayId'], vgw['VpnGateways'][1]['VpnGatewayId']]
# otherwise create two and return them
vgw_1 = connection.create_vpn_gateway(Type='ipsec.1')
vgw_2 = connection.create_vpn_gateway(Type='ipsec.1')
for resource in (vgw_1, vgw_2):
connection.create_tags(Resources=[resource['VpnGateway']['VpnGatewayId']], Tags=[{'Key': 'Ansible_VPN', 'Value': 'Test'}])
return [vgw_1['VpnGateway']['VpnGatewayId'], vgw_2['VpnGateway']['VpnGatewayId']]
def get_cgw(connection):
# see if two cgw exist and return them if so
cgw = connection.describe_customer_gateways(DryRun=False, Filters=[{'Name': 'state', 'Values': ['available']},
{'Name': 'tag:Name', 'Values': ['Ansible-CGW']}])
if len(cgw['CustomerGateways']) >= 2:
return [cgw['CustomerGateways'][0]['CustomerGatewayId'], cgw['CustomerGateways'][1]['CustomerGatewayId']]
# otherwise create and return them
cgw_1 = connection.create_customer_gateway(DryRun=False, Type='ipsec.1', PublicIp='9.8.7.6', BgpAsn=65000)
cgw_2 = connection.create_customer_gateway(DryRun=False, Type='ipsec.1', PublicIp='5.4.3.2', BgpAsn=65000)
for resource in (cgw_1, cgw_2):
connection.create_tags(Resources=[resource['CustomerGateway']['CustomerGatewayId']], Tags=[{'Key': 'Ansible-CGW', 'Value': 'Test'}])
return [cgw_1['CustomerGateway']['CustomerGatewayId'], cgw_2['CustomerGateway']['CustomerGatewayId']]
def get_dependencies():
if os.getenv('PLACEBO_RECORD'):
module = FakeModule(**{})
region, ec2_url, aws_connect_kwargs = get_aws_connection_info(module, boto3=True)
connection = boto3_conn(module, conn_type='client', resource='ec2', region=region, endpoint=ec2_url, **aws_connect_kwargs)
vgw = get_vgw(connection)
cgw = get_cgw(connection)
else:
vgw = ["vgw-35d70c2b", "vgw-32d70c2c"]
cgw = ["cgw-6113c87f", "cgw-9e13c880"]
return cgw, vgw
def setup_mod_conn(placeboify, params):
conn = placeboify.client('ec2')
m = FakeModule(**params)
return m, conn
def make_params(cgw, vgw, tags=None, filters=None, routes=None):
tags = {} if tags is None else tags
filters = {} if filters is None else filters
routes = [] if routes is None else routes
return {'customer_gateway_id': cgw,
'static_only': True,
'vpn_gateway_id': vgw,
'connection_type': 'ipsec.1',
'purge_tags': True,
'tags': tags,
'filters': filters,
'routes': routes,
'delay': 15,
'wait_timeout': 600}
def make_conn(placeboify, module, connection):
customer_gateway_id = module.params['customer_gateway_id']
static_only = module.params['static_only']
vpn_gateway_id = module.params['vpn_gateway_id']
connection_type = module.params['connection_type']
check_mode = module.params['check_mode']
changed = True
vpn = ec2_vpc_vpn.create_connection(connection, customer_gateway_id, static_only, vpn_gateway_id, connection_type)
return changed, vpn
def tear_down_conn(placeboify, connection, vpn_connection_id):
ec2_vpc_vpn.delete_connection(connection, vpn_connection_id, delay=15, max_attempts=40)
def test_find_connection_vpc_conn_id(placeboify, maybe_sleep):
# setup dependencies for 2 vpn connections
dependencies = setup_req(placeboify, 2)
dep1, dep2 = dependencies[0], dependencies[1]
params1, vpn1, m1, conn1 = dep1['params'], dep1['vpn'], dep1['module'], dep1['connection']
params2, vpn2, m2, conn2 = dep2['params'], dep2['vpn'], dep2['module'], dep2['connection']
# find the connection with a vpn_connection_id and assert it is the expected one
assert vpn1['VpnConnectionId'] == ec2_vpc_vpn.find_connection(conn1, params1, vpn1['VpnConnectionId'])['VpnConnectionId']
tear_down_conn(placeboify, conn1, vpn1['VpnConnectionId'])
tear_down_conn(placeboify, conn2, vpn2['VpnConnectionId'])
def test_find_connection_filters(placeboify, maybe_sleep):
# setup dependencies for 2 vpn connections
dependencies = setup_req(placeboify, 2)
dep1, dep2 = dependencies[0], dependencies[1]
params1, vpn1, m1, conn1 = dep1['params'], dep1['vpn'], dep1['module'], dep1['connection']
params2, vpn2, m2, conn2 = dep2['params'], dep2['vpn'], dep2['module'], dep2['connection']
# update to different tags
params1.update(tags={'Wrong': 'Tag'})
params2.update(tags={'Correct': 'Tag'})
ec2_vpc_vpn.ensure_present(conn1, params1)
ec2_vpc_vpn.ensure_present(conn2, params2)
# create some new parameters for a filter
params = {'filters': {'tags': {'Correct': 'Tag'}}}
# find the connection that has the parameters above
found = ec2_vpc_vpn.find_connection(conn1, params)
# assert the correct connection was found
assert found['VpnConnectionId'] == vpn2['VpnConnectionId']
# delete the connections
tear_down_conn(placeboify, conn1, vpn1['VpnConnectionId'])
tear_down_conn(placeboify, conn2, vpn2['VpnConnectionId'])
def test_find_connection_insufficient_filters(placeboify, maybe_sleep):
# get list of customer gateways and virtual private gateways
cgw, vgw = get_dependencies()
# create two connections with the same tags
params = make_params(cgw[0], vgw[0], tags={'Correct': 'Tag'})
params2 = make_params(cgw[1], vgw[1], tags={'Correct': 'Tag'})
m, conn = setup_mod_conn(placeboify, params)
m2, conn2 = setup_mod_conn(placeboify, params2)
_, vpn1 = ec2_vpc_vpn.ensure_present(conn, m.params)
_, vpn2 = ec2_vpc_vpn.ensure_present(conn2, m2.params)
# reset the parameters so only filtering by tags will occur
m.params = {'filters': {'tags': {'Correct': 'Tag'}}}
# assert that multiple matching connections have been found
with pytest.raises(Exception) as error_message:
ec2_vpc_vpn.find_connection(conn, m.params)
assert error_message == "More than one matching VPN connection was found.To modify or delete a VPN please specify vpn_connection_id or add filters."
# delete the connections
tear_down_conn(placeboify, conn, vpn1['VpnConnectionId'])
tear_down_conn(placeboify, conn, vpn2['VpnConnectionId'])
def test_find_connection_nonexistent(placeboify, maybe_sleep):
# create parameters but don't create a connection with them
params = {'filters': {'tags': {'Correct': 'Tag'}}}
m, conn = setup_mod_conn(placeboify, params)
# try to find a connection with matching parameters and assert None are found
assert ec2_vpc_vpn.find_connection(conn, m.params) is None
def test_create_connection(placeboify, maybe_sleep):
# get list of customer gateways and virtual private gateways
cgw, vgw = get_dependencies()
# create a connection
params = make_params(cgw[0], vgw[0])
m, conn = setup_mod_conn(placeboify, params)
changed, vpn = ec2_vpc_vpn.ensure_present(conn, m.params)
# assert that changed is true and that there is a connection id
assert changed is True
assert 'VpnConnectionId' in vpn
# delete connection
tear_down_conn(placeboify, conn, vpn['VpnConnectionId'])
def test_create_connection_that_exists(placeboify, maybe_sleep):
# setup dependencies for 1 vpn connection
dependencies = setup_req(placeboify, 1)
params, vpn, m, conn = dependencies['params'], dependencies['vpn'], dependencies['module'], dependencies['connection']
# try to recreate the same connection
changed, vpn2 = ec2_vpc_vpn.ensure_present(conn, params)
# nothing should have changed
assert changed is False
assert vpn['VpnConnectionId'] == vpn2['VpnConnectionId']
# delete connection
tear_down_conn(placeboify, conn, vpn['VpnConnectionId'])
def test_modify_deleted_connection(placeboify, maybe_sleep):
# setup dependencies for 1 vpn connection
dependencies = setup_req(placeboify, 1)
params, vpn, m, conn = dependencies['params'], dependencies['vpn'], dependencies['module'], dependencies['connection']
# delete it
tear_down_conn(placeboify, conn, vpn['VpnConnectionId'])
# try to update the deleted connection
m.params.update(vpn_connection_id=vpn['VpnConnectionId'])
with pytest.raises(Exception) as error_message:
ec2_vpc_vpn.ensure_present(conn, m.params)
assert error_message == "There is no VPN connection available or pending with that id. Did you delete it?"
def test_delete_connection(placeboify, maybe_sleep):
# setup dependencies for 1 vpn connection
dependencies = setup_req(placeboify, 1)
params, vpn, m, conn = dependencies['params'], dependencies['vpn'], dependencies['module'], dependencies['connection']
# delete it
changed, vpn = ec2_vpc_vpn.ensure_absent(conn, m.params)
assert changed is True
assert vpn == {}
def test_delete_nonexistent_connection(placeboify, maybe_sleep):
# create parameters and ensure any connection matching (None) is deleted
params = {'filters': {'tags': {'ThisConnection': 'DoesntExist'}}, 'delay': 15, 'wait_timeout': 600}
m, conn = setup_mod_conn(placeboify, params)
changed, vpn = ec2_vpc_vpn.ensure_absent(conn, m.params)
assert changed is False
assert vpn == {}
def test_check_for_update_tags(placeboify, maybe_sleep):
# setup dependencies for 1 vpn connection
dependencies = setup_req(placeboify, 1)
params, vpn, m, conn = dependencies['params'], dependencies['vpn'], dependencies['module'], dependencies['connection']
# add and remove a number of tags
m.params['tags'] = {'One': 'one', 'Two': 'two'}
ec2_vpc_vpn.ensure_present(conn, m.params)
m.params['tags'] = {'Two': 'two', 'Three': 'three', 'Four': 'four'}
changes = ec2_vpc_vpn.check_for_update(conn, m.params, vpn['VpnConnectionId'])
flat_dict_changes = boto3_tag_list_to_ansible_dict(changes['tags_to_add'])
correct_changes = boto3_tag_list_to_ansible_dict([{'Key': 'Three', 'Value': 'three'}, {'Key': 'Four', 'Value': 'four'}])
assert flat_dict_changes == correct_changes
assert changes['tags_to_remove'] == ['One']
# delete connection
tear_down_conn(placeboify, conn, vpn['VpnConnectionId'])
def test_check_for_update_nonmodifiable_attr(placeboify, maybe_sleep):
# setup dependencies for 1 vpn connection
dependencies = setup_req(placeboify, 1)
params, vpn, m, conn = dependencies['params'], dependencies['vpn'], dependencies['module'], dependencies['connection']
current_vgw = params['vpn_gateway_id']
# update a parameter that isn't modifiable
m.params.update(vpn_gateway_id="invalidchange")
err = 'You cannot modify vpn_gateway_id, the current value of which is {0}. Modifiable VPN connection attributes are tags.'.format(current_vgw)
with pytest.raises(Exception) as error_message:
ec2_vpc_vpn.check_for_update(m, conn, vpn['VpnConnectionId'])
assert error_message == err
# delete connection
tear_down_conn(placeboify, conn, vpn['VpnConnectionId'])
def test_add_tags(placeboify, maybe_sleep):
# setup dependencies for 1 vpn connection
dependencies = setup_req(placeboify, 1)
params, vpn, m, conn = dependencies['params'], dependencies['vpn'], dependencies['module'], dependencies['connection']
# add a tag to the connection
ec2_vpc_vpn.add_tags(conn, vpn['VpnConnectionId'], add=[{'Key': 'Ansible-Test', 'Value': 'VPN'}])
# assert tag is there
current_vpn = ec2_vpc_vpn.find_connection(conn, params)
assert current_vpn['Tags'] == [{'Key': 'Ansible-Test', 'Value': 'VPN'}]
# delete connection
tear_down_conn(placeboify, conn, vpn['VpnConnectionId'])
def test_remove_tags(placeboify, maybe_sleep):
# setup dependencies for 1 vpn connection
dependencies = setup_req(placeboify, 1)
params, vpn, m, conn = dependencies['params'], dependencies['vpn'], dependencies['module'], dependencies['connection']
# remove a tag from the connection
ec2_vpc_vpn.remove_tags(conn, vpn['VpnConnectionId'], remove=['Ansible-Test'])
# assert the tag is gone
current_vpn = ec2_vpc_vpn.find_connection(conn, params)
assert 'Tags' not in current_vpn
# delete connection
tear_down_conn(placeboify, conn, vpn['VpnConnectionId'])
def test_add_routes(placeboify, maybe_sleep):
# setup dependencies for 1 vpn connection
dependencies = setup_req(placeboify, 1)
params, vpn, m, conn = dependencies['params'], dependencies['vpn'], dependencies['module'], dependencies['connection']
# create connection with a route
ec2_vpc_vpn.add_routes(conn, vpn['VpnConnectionId'], ['195.168.2.0/24', '196.168.2.0/24'])
# assert both routes are there
current_vpn = ec2_vpc_vpn.find_connection(conn, params)
assert set(each['DestinationCidrBlock'] for each in current_vpn['Routes']) == set(['195.168.2.0/24', '196.168.2.0/24'])
# delete connection
tear_down_conn(placeboify, conn, vpn['VpnConnectionId'])
def setup_req(placeboify, number_of_results=1):
''' returns dependencies for VPN connections '''
assert number_of_results in (1, 2)
results = []
cgw, vgw = get_dependencies()
for each in range(0, number_of_results):
params = make_params(cgw[each], vgw[each])
m, conn = setup_mod_conn(placeboify, params)
_, vpn = ec2_vpc_vpn.ensure_present(conn, params)
results.append({'module': m, 'connection': conn, 'vpn': vpn, 'params': params})
if number_of_results == 1:
return results[0]
else:
return results[0], results[1]
|
gpl-3.0
|
[
3,
334,
67,
9,
9708,
9572,
13002,
3277,
14,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
646,
4613,
199,
646,
747,
199,
504,
6204,
14,
1208,
14,
15144,
63,
2778,
656,
63,
8769,
492,
4192,
656,
2021,
12,
11703,
63,
4532,
199,
504,
3242,
14,
3112,
14,
4091,
14,
15144,
492,
7062,
18,
63,
11742,
63,
9702,
199,
504,
3242,
14,
578,
63,
1208,
14,
825,
18,
492,
664,
63,
7231,
63,
2105,
63,
815,
12,
6055,
19,
63,
1631,
12,
6055,
19,
63,
1450,
63,
513,
63,
475,
63,
4853,
63,
807,
421,
199,
533,
7777,
2377,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
1011,
958,
304,
267,
291,
14,
1162,
275,
2074,
339,
347,
2449,
63,
1001,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
291,
14,
2224,
63,
589,
275,
1249,
267,
291,
14,
2224,
63,
958,
275,
2074,
267,
746,
2186,
360,
8784,
358,
339,
347,
4458,
63,
1001,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
291,
14,
2224,
63,
589,
275,
1249,
267,
291,
14,
2224,
63,
958,
275,
2074,
421,
199,
318,
664,
63,
26408,
8,
2105,
304,
272,
327,
1937,
340,
2877,
373,
8392,
2187,
436,
372,
3062,
340,
880,
272,
373,
8392,
275,
1950,
14,
11935,
63,
9702,
63,
3237,
2885,
8,
18053,
1524,
1445,
985,
356,
283,
1450,
26,
10047,
63,
54,
9060,
297,
283,
6550,
356,
788,
774,
12074,
566,
272,
340,
822,
8,
26408,
459,
20975,
13994,
2885,
1105,
2356,
499,
26,
267,
372,
359,
26408,
459,
20975,
13994,
2885,
3488,
16,
2733,
20975,
12455,
1304,
995,
373,
8392,
459,
20975,
13994,
2885,
3488,
17,
2733,
20975,
12455,
1304,
6538,
272,
327,
4257,
1218,
2877,
436,
372,
3062,
272,
373,
8392,
63,
17,
275,
1950,
14,
981,
63,
9702,
63,
7019,
8,
804,
534,
19867,
14,
17,
358,
272,
373,
8392,
63,
18,
275,
1950,
14,
981,
63,
9702,
63,
7019,
8,
804,
534,
19867,
14,
17,
358,
272,
367,
2073,
315,
334,
26408,
63,
17,
12,
373,
8392,
63,
18,
304,
267,
1950,
14,
981,
63,
2969,
8,
13745,
1524,
1927,
459,
20975,
12455,
2545,
20975,
12455,
1304,
2157,
25204,
1524,
1445,
1197,
356,
283,
10047,
63,
54,
9060,
297,
283,
1110,
356,
283,
774,
936,
566,
272,
372,
359,
26408,
63,
17,
459,
20975,
12455,
2545,
20975,
12455,
1304,
995,
373,
8392,
63,
18,
459,
20975,
12455,
2545,
20975,
12455,
1304,
6538,
421,
199,
318,
664,
63,
67,
8392,
8,
2105,
304,
272,
327,
1937,
340,
2877,
286,
8392,
2187,
436,
372,
3062,
340,
880,
272,
286,
8392,
275,
1950,
14,
11935,
63,
10178,
63,
3237,
2885,
8,
36,
651,
2540,
29,
797,
12,
21240,
1524,
1445,
985,
356,
283,
929,
297,
283,
6550,
356,
788,
4561,
14949,
6684,
755,
791,
985,
356,
283,
1450,
26,
985,
297,
283,
6550,
356,
788,
10047,
13,
4064,
55,
12074,
566,
272,
340,
822,
8,
67,
8392,
459,
17025,
13994,
2885,
1105,
2356,
499,
26,
267,
372,
359,
67,
8392,
459,
17025,
13994,
2885,
3488,
16,
2733,
17025,
12455,
1304,
995,
286,
8392,
459,
17025,
13994,
2885,
3488,
17,
2733,
17025,
12455,
1304,
6538,
272,
327,
4257,
1218,
436,
372,
3062,
272,
286,
8392,
63,
17,
275,
1950,
14,
981,
63,
10178,
63,
7019,
8,
36,
651,
2540,
29,
797,
12,
2434,
534,
19867,
14,
17,
297,
1684,
6583,
534,
25,
14,
24,
14,
23,
14,
22,
297,
699,
4927,
2822,
78,
29,
2182,
1493,
9,
272,
286,
8392,
63,
18,
275,
1950,
14,
981,
63,
10178,
63,
7019,
8,
36,
651,
2540,
29,
797,
12,
2434,
534,
19867,
14,
17,
297,
1684,
6583,
534,
21,
14,
20,
14,
19,
14,
18,
297,
699,
4927,
2822,
78,
29,
2182,
1493,
9,
272,
367,
2073,
315,
334,
67,
8392,
63,
17,
12,
286,
8392,
63,
18,
304,
267,
1950,
14,
981,
63,
2969,
8,
13745,
1524,
1927,
459,
17025,
12455,
2545,
17025,
12455,
1304,
2157,
25204,
1524,
1445,
1197,
356,
283,
10047,
13,
4064,
55,
297,
283,
1110,
356,
283,
774,
936,
566,
272,
372,
359,
67,
8392,
63,
17,
459,
17025,
12455,
2545,
17025,
12455,
1304,
995,
286,
8392,
63,
18,
459,
17025,
12455,
2545,
17025,
12455,
1304,
6538,
421,
199,
318,
664,
63,
5714,
837,
272,
340,
747,
14,
12959,
360,
23068,
3973,
63,
15060,
735,
267,
859,
275,
7777,
2377,
25679,
1552,
267,
4897,
12,
7062,
18,
63,
633,
12,
11488,
63,
2242,
63,
958,
275,
664,
63,
7231,
63,
2105,
63,
815,
8,
578,
12,
6055,
19,
29,
549,
9,
267,
1950,
275,
6055,
19,
63,
1631,
8,
578,
12,
2557,
63,
466,
534,
1258,
297,
2073,
534,
825,
18,
297,
4897,
29,
4551,
12,
6037,
29,
825,
18,
63,
633,
12,
1011,
7231,
63,
2242,
63,
958,
9,
267,
373,
8392,
275,
664,
63,
26408,
8,
2105,
9,
267,
286,
8392,
275,
664,
63,
67,
8392,
8,
2105,
9,
272,
587,
26,
267,
373,
8392,
275,
2097,
26408,
13,
1276,
68,
2760,
67,
18,
66,
401,
298,
26408,
13,
708,
68,
2760,
67,
18,
67,
937,
267,
286,
8392,
275,
2097,
67,
8392,
13,
22,
9225,
67,
1555,
70,
401,
298,
67,
8392,
13,
25,
69,
969,
67,
30321,
937,
339,
372,
286,
8392,
12,
373,
8392,
421,
199
] |
[
334,
67,
9,
9708,
9572,
13002,
3277,
14,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
646,
4613,
199,
646,
747,
199,
504,
6204,
14,
1208,
14,
15144,
63,
2778,
656,
63,
8769,
492,
4192,
656,
2021,
12,
11703,
63,
4532,
199,
504,
3242,
14,
3112,
14,
4091,
14,
15144,
492,
7062,
18,
63,
11742,
63,
9702,
199,
504,
3242,
14,
578,
63,
1208,
14,
825,
18,
492,
664,
63,
7231,
63,
2105,
63,
815,
12,
6055,
19,
63,
1631,
12,
6055,
19,
63,
1450,
63,
513,
63,
475,
63,
4853,
63,
807,
421,
199,
533,
7777,
2377,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
1011,
958,
304,
267,
291,
14,
1162,
275,
2074,
339,
347,
2449,
63,
1001,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
291,
14,
2224,
63,
589,
275,
1249,
267,
291,
14,
2224,
63,
958,
275,
2074,
267,
746,
2186,
360,
8784,
358,
339,
347,
4458,
63,
1001,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
291,
14,
2224,
63,
589,
275,
1249,
267,
291,
14,
2224,
63,
958,
275,
2074,
421,
199,
318,
664,
63,
26408,
8,
2105,
304,
272,
327,
1937,
340,
2877,
373,
8392,
2187,
436,
372,
3062,
340,
880,
272,
373,
8392,
275,
1950,
14,
11935,
63,
9702,
63,
3237,
2885,
8,
18053,
1524,
1445,
985,
356,
283,
1450,
26,
10047,
63,
54,
9060,
297,
283,
6550,
356,
788,
774,
12074,
566,
272,
340,
822,
8,
26408,
459,
20975,
13994,
2885,
1105,
2356,
499,
26,
267,
372,
359,
26408,
459,
20975,
13994,
2885,
3488,
16,
2733,
20975,
12455,
1304,
995,
373,
8392,
459,
20975,
13994,
2885,
3488,
17,
2733,
20975,
12455,
1304,
6538,
272,
327,
4257,
1218,
2877,
436,
372,
3062,
272,
373,
8392,
63,
17,
275,
1950,
14,
981,
63,
9702,
63,
7019,
8,
804,
534,
19867,
14,
17,
358,
272,
373,
8392,
63,
18,
275,
1950,
14,
981,
63,
9702,
63,
7019,
8,
804,
534,
19867,
14,
17,
358,
272,
367,
2073,
315,
334,
26408,
63,
17,
12,
373,
8392,
63,
18,
304,
267,
1950,
14,
981,
63,
2969,
8,
13745,
1524,
1927,
459,
20975,
12455,
2545,
20975,
12455,
1304,
2157,
25204,
1524,
1445,
1197,
356,
283,
10047,
63,
54,
9060,
297,
283,
1110,
356,
283,
774,
936,
566,
272,
372,
359,
26408,
63,
17,
459,
20975,
12455,
2545,
20975,
12455,
1304,
995,
373,
8392,
63,
18,
459,
20975,
12455,
2545,
20975,
12455,
1304,
6538,
421,
199,
318,
664,
63,
67,
8392,
8,
2105,
304,
272,
327,
1937,
340,
2877,
286,
8392,
2187,
436,
372,
3062,
340,
880,
272,
286,
8392,
275,
1950,
14,
11935,
63,
10178,
63,
3237,
2885,
8,
36,
651,
2540,
29,
797,
12,
21240,
1524,
1445,
985,
356,
283,
929,
297,
283,
6550,
356,
788,
4561,
14949,
6684,
755,
791,
985,
356,
283,
1450,
26,
985,
297,
283,
6550,
356,
788,
10047,
13,
4064,
55,
12074,
566,
272,
340,
822,
8,
67,
8392,
459,
17025,
13994,
2885,
1105,
2356,
499,
26,
267,
372,
359,
67,
8392,
459,
17025,
13994,
2885,
3488,
16,
2733,
17025,
12455,
1304,
995,
286,
8392,
459,
17025,
13994,
2885,
3488,
17,
2733,
17025,
12455,
1304,
6538,
272,
327,
4257,
1218,
436,
372,
3062,
272,
286,
8392,
63,
17,
275,
1950,
14,
981,
63,
10178,
63,
7019,
8,
36,
651,
2540,
29,
797,
12,
2434,
534,
19867,
14,
17,
297,
1684,
6583,
534,
25,
14,
24,
14,
23,
14,
22,
297,
699,
4927,
2822,
78,
29,
2182,
1493,
9,
272,
286,
8392,
63,
18,
275,
1950,
14,
981,
63,
10178,
63,
7019,
8,
36,
651,
2540,
29,
797,
12,
2434,
534,
19867,
14,
17,
297,
1684,
6583,
534,
21,
14,
20,
14,
19,
14,
18,
297,
699,
4927,
2822,
78,
29,
2182,
1493,
9,
272,
367,
2073,
315,
334,
67,
8392,
63,
17,
12,
286,
8392,
63,
18,
304,
267,
1950,
14,
981,
63,
2969,
8,
13745,
1524,
1927,
459,
17025,
12455,
2545,
17025,
12455,
1304,
2157,
25204,
1524,
1445,
1197,
356,
283,
10047,
13,
4064,
55,
297,
283,
1110,
356,
283,
774,
936,
566,
272,
372,
359,
67,
8392,
63,
17,
459,
17025,
12455,
2545,
17025,
12455,
1304,
995,
286,
8392,
63,
18,
459,
17025,
12455,
2545,
17025,
12455,
1304,
6538,
421,
199,
318,
664,
63,
5714,
837,
272,
340,
747,
14,
12959,
360,
23068,
3973,
63,
15060,
735,
267,
859,
275,
7777,
2377,
25679,
1552,
267,
4897,
12,
7062,
18,
63,
633,
12,
11488,
63,
2242,
63,
958,
275,
664,
63,
7231,
63,
2105,
63,
815,
8,
578,
12,
6055,
19,
29,
549,
9,
267,
1950,
275,
6055,
19,
63,
1631,
8,
578,
12,
2557,
63,
466,
534,
1258,
297,
2073,
534,
825,
18,
297,
4897,
29,
4551,
12,
6037,
29,
825,
18,
63,
633,
12,
1011,
7231,
63,
2242,
63,
958,
9,
267,
373,
8392,
275,
664,
63,
26408,
8,
2105,
9,
267,
286,
8392,
275,
664,
63,
67,
8392,
8,
2105,
9,
272,
587,
26,
267,
373,
8392,
275,
2097,
26408,
13,
1276,
68,
2760,
67,
18,
66,
401,
298,
26408,
13,
708,
68,
2760,
67,
18,
67,
937,
267,
286,
8392,
275,
2097,
67,
8392,
13,
22,
9225,
67,
1555,
70,
401,
298,
67,
8392,
13,
25,
69,
969,
67,
30321,
937,
339,
372,
286,
8392,
12,
373,
8392,
421,
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,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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
] |
Suwings/Yeinw
|
src/Crypto/SelfTest/Random/Fortuna/test_SHAd256.py
|
119
|
2419
|
# -*- coding: utf-8 -*-
#
# SelfTest/Random/Fortuna/test_SHAd256.py: Self-test for the SHAd256 hash function
#
# Written in 2008 by Dwayne C. Litzenberger <dlitz@dlitz.net>
#
# ===================================================================
# The contents of this file are dedicated to the public domain. To
# the extent that dedication to the public domain is not available,
# everyone is granted a worldwide, perpetual, royalty-free,
# non-exclusive license to exercise all rights associated with the
# contents of this file for any purpose whatsoever.
# No rights are reserved.
#
# 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.
# ===================================================================
"""Self-test suite for Crypto.Random.Fortuna.SHAd256"""
__revision__ = "$Id$"
from Crypto.Util.py3compat import *
# This is a list of (expected_result, input[, description]) tuples.
test_data = [
# I could not find any test vectors for SHAd256, so I made these vectors by
# feeding some sample data into several plain SHA256 implementations
# (including OpenSSL, the "sha256sum" tool, and this implementation).
# This is a subset of the resulting test vectors. The complete list can be
# found at: http://www.dlitz.net/crypto/shad256-test-vectors/
('5df6e0e2761359d30a8275058e299fcc0381534545f55cf43e41983f5d4c9456',
'', "'' (empty string)"),
('4f8b42c22dd3729b519ba6f68d2da7cc5b2d606d05daed5ad5128cc03e6c6358',
'abc'),
('0cffe17f68954dac3a84fb1458bd5ec99209449749b2b308b7cb55812f9563af',
'abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq')
]
def get_tests(config={}):
from Crypto.Random.Fortuna import SHAd256
from Crypto.SelfTest.Hash.common import make_hash_tests
return make_hash_tests(SHAd256, "SHAd256", test_data, 32)
if __name__ == '__main__':
import unittest
suite = lambda: unittest.TestSuite(get_tests())
unittest.main(defaultTest='suite')
# vim:set ts=4 sw=4 sts=4 expandtab:
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
221,
23820,
774,
15,
3883,
15,
38,
361,
31627,
15,
396,
63,
3234,
2767,
3912,
14,
647,
26,
23820,
13,
396,
367,
314,
4410,
2767,
3912,
2631,
805,
199,
3,
199,
3,
27694,
315,
9079,
701,
577,
3316,
685,
445,
14,
491,
390,
5193,
605,
836,
665,
68,
29382,
32,
68,
29382,
14,
846,
30,
199,
3,
199,
3,
7819,
389,
199,
3,
710,
4072,
402,
642,
570,
787,
29711,
370,
314,
4575,
2881,
14,
221,
4005,
199,
3,
314,
13675,
626,
477,
21171,
370,
314,
4575,
2881,
365,
440,
2808,
12,
199,
3,
4036,
368,
365,
10009,
282,
6701,
13062,
12,
1126,
321,
1688,
12,
882,
89,
13248,
13,
4624,
12,
199,
3,
2222,
13,
12730,
4190,
370,
26511,
1006,
4481,
4568,
543,
314,
199,
3,
4072,
402,
642,
570,
367,
1263,
12016,
4052,
1152,
5907,
14,
199,
3,
3091,
4481,
787,
4644,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
199,
3,
7168,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
199,
3,
3169,
12,
3092,
2381,
437,
3115,
3104,
2401,
199,
3,
13229,
14,
1621,
4825,
6461,
7000,
2334,
10610,
1549,
5877,
8164,
199,
3,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
7061,
1621,
1261,
199,
3,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
5738,
1634,
1549,
1621,
199,
3,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
2334,
199,
3,
4141,
14,
199,
3,
7819,
389,
199,
199,
624,
12887,
13,
396,
5241,
367,
18855,
14,
3883,
14,
38,
361,
31627,
14,
3234,
2767,
3912,
624,
199,
199,
363,
5792,
363,
275,
7880,
1304,
17351,
199,
504,
18855,
14,
9562,
14,
647,
19,
5819,
492,
627,
199,
199,
3,
961,
365,
282,
769,
402,
334,
2062,
63,
1099,
12,
1324,
14675,
1369,
566,
6346,
14,
199,
396,
63,
576,
275,
359,
272,
327,
473,
4293,
440,
2342,
1263,
511,
11102,
367,
4410,
2767,
3912,
12,
880,
473,
6326,
3520,
11102,
701,
272,
327,
4733,
316,
2005,
2690,
666,
1901,
9978,
8971,
12002,
3912,
12591,
272,
327,
334,
15768,
14296,
12,
314,
298,
4835,
3912,
1838,
2,
4744,
12,
436,
642,
4514,
680,
272,
327,
961,
365,
282,
10026,
402,
314,
9183,
511,
11102,
14,
221,
710,
4890,
769,
883,
506,
272,
327,
1911,
737,
26,
1455,
921,
1544,
14,
68,
29382,
14,
846,
15,
10316,
15,
609,
350,
3912,
13,
396,
13,
12280,
15,
272,
661,
21,
1587,
22,
69,
16,
69,
13319,
969,
1427,
68,
1216,
65,
32096,
1400,
2010,
69,
10488,
70,
2055,
14273,
1046,
1082,
16981,
70,
1229,
2177,
2824,
69,
25230,
2658,
70,
21,
68,
20,
67,
2635,
1367,
297,
267,
3260,
17172,
334,
1667,
1059,
13185,
272,
661,
20,
70,
24,
66,
2260,
67,
1081,
617,
1401,
1398,
66,
30432,
2470,
22,
70,
2333,
68,
18,
983,
23,
2055,
21,
66,
18,
68,
16220,
68,
1717,
983,
379,
21,
350,
21,
3933,
2055,
1644,
69,
22,
67,
22,
14321,
297,
267,
283,
3175,
659,
272,
661,
16,
67,
2026,
1196,
70,
29114,
1477,
31811,
19,
65,
1349,
4675,
1079,
2010,
3691,
21,
825,
1020,
11303,
19738,
15971,
66,
18,
66,
12127,
66,
23,
2894,
17686,
713,
70,
25,
18199,
2756,
297,
267,
283,
3175,
16845,
7778,
318,
318,
303,
70,
3561,
70,
3561,
2056,
7879,
5812,
17421,
7879,
9503,
74,
9503,
3880,
14344,
7530,
10344,
676,
20443,
20443,
81,
358,
199,
61,
199,
199,
318,
664,
63,
2219,
8,
888,
16420,
272,
687,
18855,
14,
3883,
14,
38,
361,
31627,
492,
4410,
2767,
3912,
272,
687,
18855,
14,
12887,
774,
14,
3476,
14,
2330,
492,
1852,
63,
2227,
63,
2219,
272,
372,
1852,
63,
2227,
63,
2219,
8,
3234,
2767,
3912,
12,
298,
3234,
2767,
3912,
401,
511,
63,
576,
12,
4337,
9,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
492,
2882,
272,
5241,
275,
2400,
26,
2882,
14,
10591,
8,
362,
63,
2219,
1012,
272,
2882,
14,
973,
8,
885,
774,
534,
5768,
358,
199,
199,
3,
6695,
26,
409,
6714,
29,
20,
5584,
29,
20,
23014,
29,
20,
26414,
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
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
221,
23820,
774,
15,
3883,
15,
38,
361,
31627,
15,
396,
63,
3234,
2767,
3912,
14,
647,
26,
23820,
13,
396,
367,
314,
4410,
2767,
3912,
2631,
805,
199,
3,
199,
3,
27694,
315,
9079,
701,
577,
3316,
685,
445,
14,
491,
390,
5193,
605,
836,
665,
68,
29382,
32,
68,
29382,
14,
846,
30,
199,
3,
199,
3,
7819,
389,
199,
3,
710,
4072,
402,
642,
570,
787,
29711,
370,
314,
4575,
2881,
14,
221,
4005,
199,
3,
314,
13675,
626,
477,
21171,
370,
314,
4575,
2881,
365,
440,
2808,
12,
199,
3,
4036,
368,
365,
10009,
282,
6701,
13062,
12,
1126,
321,
1688,
12,
882,
89,
13248,
13,
4624,
12,
199,
3,
2222,
13,
12730,
4190,
370,
26511,
1006,
4481,
4568,
543,
314,
199,
3,
4072,
402,
642,
570,
367,
1263,
12016,
4052,
1152,
5907,
14,
199,
3,
3091,
4481,
787,
4644,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
199,
3,
7168,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
199,
3,
3169,
12,
3092,
2381,
437,
3115,
3104,
2401,
199,
3,
13229,
14,
1621,
4825,
6461,
7000,
2334,
10610,
1549,
5877,
8164,
199,
3,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
7061,
1621,
1261,
199,
3,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
5738,
1634,
1549,
1621,
199,
3,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
2334,
199,
3,
4141,
14,
199,
3,
7819,
389,
199,
199,
624,
12887,
13,
396,
5241,
367,
18855,
14,
3883,
14,
38,
361,
31627,
14,
3234,
2767,
3912,
624,
199,
199,
363,
5792,
363,
275,
7880,
1304,
17351,
199,
504,
18855,
14,
9562,
14,
647,
19,
5819,
492,
627,
199,
199,
3,
961,
365,
282,
769,
402,
334,
2062,
63,
1099,
12,
1324,
14675,
1369,
566,
6346,
14,
199,
396,
63,
576,
275,
359,
272,
327,
473,
4293,
440,
2342,
1263,
511,
11102,
367,
4410,
2767,
3912,
12,
880,
473,
6326,
3520,
11102,
701,
272,
327,
4733,
316,
2005,
2690,
666,
1901,
9978,
8971,
12002,
3912,
12591,
272,
327,
334,
15768,
14296,
12,
314,
298,
4835,
3912,
1838,
2,
4744,
12,
436,
642,
4514,
680,
272,
327,
961,
365,
282,
10026,
402,
314,
9183,
511,
11102,
14,
221,
710,
4890,
769,
883,
506,
272,
327,
1911,
737,
26,
1455,
921,
1544,
14,
68,
29382,
14,
846,
15,
10316,
15,
609,
350,
3912,
13,
396,
13,
12280,
15,
272,
661,
21,
1587,
22,
69,
16,
69,
13319,
969,
1427,
68,
1216,
65,
32096,
1400,
2010,
69,
10488,
70,
2055,
14273,
1046,
1082,
16981,
70,
1229,
2177,
2824,
69,
25230,
2658,
70,
21,
68,
20,
67,
2635,
1367,
297,
267,
3260,
17172,
334,
1667,
1059,
13185,
272,
661,
20,
70,
24,
66,
2260,
67,
1081,
617,
1401,
1398,
66,
30432,
2470,
22,
70,
2333,
68,
18,
983,
23,
2055,
21,
66,
18,
68,
16220,
68,
1717,
983,
379,
21,
350,
21,
3933,
2055,
1644,
69,
22,
67,
22,
14321,
297,
267,
283,
3175,
659,
272,
661,
16,
67,
2026,
1196,
70,
29114,
1477,
31811,
19,
65,
1349,
4675,
1079,
2010,
3691,
21,
825,
1020,
11303,
19738,
15971,
66,
18,
66,
12127,
66,
23,
2894,
17686,
713,
70,
25,
18199,
2756,
297,
267,
283,
3175,
16845,
7778,
318,
318,
303,
70,
3561,
70,
3561,
2056,
7879,
5812,
17421,
7879,
9503,
74,
9503,
3880,
14344,
7530,
10344,
676,
20443,
20443,
81,
358,
199,
61,
199,
199,
318,
664,
63,
2219,
8,
888,
16420,
272,
687,
18855,
14,
3883,
14,
38,
361,
31627,
492,
4410,
2767,
3912,
272,
687,
18855,
14,
12887,
774,
14,
3476,
14,
2330,
492,
1852,
63,
2227,
63,
2219,
272,
372,
1852,
63,
2227,
63,
2219,
8,
3234,
2767,
3912,
12,
298,
3234,
2767,
3912,
401,
511,
63,
576,
12,
4337,
9,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
492,
2882,
272,
5241,
275,
2400,
26,
2882,
14,
10591,
8,
362,
63,
2219,
1012,
272,
2882,
14,
973,
8,
885,
774,
534,
5768,
358,
199,
199,
3,
6695,
26,
409,
6714,
29,
20,
5584,
29,
20,
23014,
29,
20,
26414,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
maciekcc/tensorflow
|
tensorflow/contrib/timeseries/python/timeseries/state_space_models/filtering_postprocessor_test.py
|
67
|
3176
|
# Copyright 2017 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Tests for filtering postprocessors."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from tensorflow.contrib.timeseries.python.timeseries.state_space_models import filtering_postprocessor
from tensorflow.python.framework import constant_op
from tensorflow.python.framework import dtypes
from tensorflow.python.platform import test
class FilteringStepPostprocessorTest(test.TestCase):
def test_gaussian_alternative(self):
for float_dtype in [dtypes.float32, dtypes.float64]:
detector = filtering_postprocessor.StateInterpolatingAnomalyDetector(
anomaly_log_likelihood=(filtering_postprocessor
.cauchy_alternative_to_gaussian),
responsibility_scaling=10.)
predicted_state = [
constant_op.constant(
[[40.], [20.]], dtype=float_dtype), constant_op.constant(
[3., 6.], dtype=float_dtype), constant_op.constant([-1, -2])
]
filtered_state = [
constant_op.constant(
[[80.], [180.]], dtype=float_dtype), constant_op.constant(
[1., 2.], dtype=float_dtype), constant_op.constant([-1, -2])
]
interpolated_state, updated_outputs = detector.process_filtering_step(
current_times=constant_op.constant([1, 2]),
current_values=constant_op.constant([[0.], [1.]], dtype=float_dtype),
predicted_state=predicted_state,
filtered_state=filtered_state,
outputs={
"mean":
constant_op.constant([[0.1], [10.]], dtype=float_dtype),
"covariance":
constant_op.constant([[[1.0]], [[1.0]]], dtype=float_dtype),
"log_likelihood":
constant_op.constant([-1., -40.], dtype=float_dtype)
})
# The first batch element is not anomalous, and so should use the inferred
# state. The second is anomalous, and should use the predicted state.
expected_state = [[[80.], [20.]],
[1., 6.],
[-1, -2]]
with self.test_session():
for interpolated, expected in zip(interpolated_state, expected_state):
self.assertAllClose(expected, interpolated.eval())
self.assertGreater(0., updated_outputs["anomaly_score"][0].eval())
self.assertLess(0., updated_outputs["anomaly_score"][1].eval())
if __name__ == "__main__":
test.main()
|
apache-2.0
|
[
3,
1898,
9708,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
2925,
367,
14545,
2963,
10547,
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,
2828,
14,
28551,
14,
1548,
14,
28551,
14,
929,
63,
2638,
63,
992,
492,
14545,
63,
1932,
6459,
199,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4413,
63,
411,
199,
504,
3228,
14,
1548,
14,
4857,
492,
6674,
199,
504,
3228,
14,
1548,
14,
3246,
492,
511,
421,
199,
533,
9388,
316,
7801,
6564,
6459,
774,
8,
396,
14,
1746,
304,
819,
347,
511,
63,
22911,
63,
19389,
8,
277,
304,
272,
367,
2069,
63,
2271,
315,
359,
5717,
14,
1609,
708,
12,
6674,
14,
1609,
772,
2189,
489,
17842,
275,
14545,
63,
1932,
6459,
14,
2223,
22713,
1958,
2493,
16523,
24402,
8,
881,
28813,
63,
793,
63,
20704,
2687,
24133,
63,
1932,
6459,
3303,
1275,
696,
30074,
63,
19389,
63,
475,
63,
22911,
395,
881,
9163,
4783,
63,
12153,
29,
709,
4959,
489,
14746,
63,
929,
275,
359,
881,
4413,
63,
411,
14,
4083,
8,
1598,
3474,
2167,
8333,
359,
1165,
24245,
2152,
29,
1609,
63,
2271,
395,
4413,
63,
411,
14,
4083,
8,
2116,
359,
19,
2020,
1227,
8333,
2152,
29,
1609,
63,
2271,
395,
4413,
63,
411,
14,
4083,
11468,
17,
12,
446,
18,
566,
489,
1622,
489,
9806,
63,
929,
275,
359,
881,
4413,
63,
411,
14,
4083,
8,
1598,
3474,
1257,
8333,
359,
7663,
24245,
2152,
29,
1609,
63,
2271,
395,
4413,
63,
411,
14,
4083,
8,
2116,
359,
17,
2020,
499,
8333,
2152,
29,
1609,
63,
2271,
395,
4413,
63,
411,
14,
4083,
11468,
17,
12,
446,
18,
566,
489,
1622,
489,
23005,
972,
63,
929,
12,
4588,
63,
4467,
275,
17842,
14,
1412,
63,
24133,
63,
2926,
8,
881,
1453,
63,
4508,
29,
4083,
63,
411,
14,
4083,
779,
17,
12,
499,
2522,
881,
1453,
63,
1459,
29,
4083,
63,
411,
14,
4083,
4038,
16,
8333,
359,
17,
24245,
2152,
29,
1609,
63,
2271,
395,
881,
14746,
63,
929,
29,
21118,
63,
929,
12,
881,
9806,
63,
929,
29,
11142,
63,
929,
12,
881,
4704,
3126,
1598,
298,
3670,
582,
2116,
4413,
63,
411,
14,
4083,
4038,
16,
14,
17,
467,
359,
709,
24245,
2152,
29,
1609,
63,
2271,
395,
1598,
298,
15024,
582,
2116,
4413,
63,
411,
14,
4083,
23930,
17,
14,
16,
2365,
3474,
17,
14,
16,
15559,
2152,
29,
1609,
63,
2271,
395,
1598,
298,
793,
63,
20704,
582,
2116,
4413,
63,
411,
14,
4083,
11468,
17,
2020,
446,
2167,
8333,
2152,
29,
1609,
63,
2271,
9,
881,
3828,
489,
327,
710,
1642,
3522,
1819,
365,
440,
376,
676,
279,
1785,
12,
436,
880,
1077,
675,
314,
22515,
489,
327,
1174,
14,
710,
3499,
365,
376,
676,
279,
1785,
12,
436,
1077,
675,
314,
14746,
1174,
14,
489,
1420,
63,
929,
275,
19819,
1257,
8333,
359,
1165,
24245,
717,
359,
17,
2020,
1227,
8333,
717,
5243,
17,
12,
446,
18,
2677,
489,
543,
291,
14,
396,
63,
1730,
837,
267,
367,
23005,
972,
12,
1420,
315,
3482,
8,
29690,
972,
63,
929,
12,
1420,
63,
929,
304,
881,
291,
14,
7260,
8,
2062,
12,
23005,
972,
14,
2579,
1012,
267,
291,
14,
15070,
8,
16,
2020,
4588,
63,
4467,
905,
32048,
63,
3397,
9210,
16,
1055,
2579,
1012,
267,
291,
14,
15625,
8,
16,
2020,
4588,
63,
4467,
905,
32048,
63,
3397,
9210,
17,
1055,
2579,
1012,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
523,
511,
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
] |
[
1898,
9708,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
2925,
367,
14545,
2963,
10547,
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,
2828,
14,
28551,
14,
1548,
14,
28551,
14,
929,
63,
2638,
63,
992,
492,
14545,
63,
1932,
6459,
199,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4413,
63,
411,
199,
504,
3228,
14,
1548,
14,
4857,
492,
6674,
199,
504,
3228,
14,
1548,
14,
3246,
492,
511,
421,
199,
533,
9388,
316,
7801,
6564,
6459,
774,
8,
396,
14,
1746,
304,
819,
347,
511,
63,
22911,
63,
19389,
8,
277,
304,
272,
367,
2069,
63,
2271,
315,
359,
5717,
14,
1609,
708,
12,
6674,
14,
1609,
772,
2189,
489,
17842,
275,
14545,
63,
1932,
6459,
14,
2223,
22713,
1958,
2493,
16523,
24402,
8,
881,
28813,
63,
793,
63,
20704,
2687,
24133,
63,
1932,
6459,
3303,
1275,
696,
30074,
63,
19389,
63,
475,
63,
22911,
395,
881,
9163,
4783,
63,
12153,
29,
709,
4959,
489,
14746,
63,
929,
275,
359,
881,
4413,
63,
411,
14,
4083,
8,
1598,
3474,
2167,
8333,
359,
1165,
24245,
2152,
29,
1609,
63,
2271,
395,
4413,
63,
411,
14,
4083,
8,
2116,
359,
19,
2020,
1227,
8333,
2152,
29,
1609,
63,
2271,
395,
4413,
63,
411,
14,
4083,
11468,
17,
12,
446,
18,
566,
489,
1622,
489,
9806,
63,
929,
275,
359,
881,
4413,
63,
411,
14,
4083,
8,
1598,
3474,
1257,
8333,
359,
7663,
24245,
2152,
29,
1609,
63,
2271,
395,
4413,
63,
411,
14,
4083,
8,
2116,
359,
17,
2020,
499,
8333,
2152,
29,
1609,
63,
2271,
395,
4413,
63,
411,
14,
4083,
11468,
17,
12,
446,
18,
566,
489,
1622,
489,
23005,
972,
63,
929,
12,
4588,
63,
4467,
275,
17842,
14,
1412,
63,
24133,
63,
2926,
8,
881,
1453,
63,
4508,
29,
4083,
63,
411,
14,
4083,
779,
17,
12,
499,
2522,
881,
1453,
63,
1459,
29,
4083,
63,
411,
14,
4083,
4038,
16,
8333,
359,
17,
24245,
2152,
29,
1609,
63,
2271,
395,
881,
14746,
63,
929,
29,
21118,
63,
929,
12,
881,
9806,
63,
929,
29,
11142,
63,
929,
12,
881,
4704,
3126,
1598,
298,
3670,
582,
2116,
4413,
63,
411,
14,
4083,
4038,
16,
14,
17,
467,
359,
709,
24245,
2152,
29,
1609,
63,
2271,
395,
1598,
298,
15024,
582,
2116,
4413,
63,
411,
14,
4083,
23930,
17,
14,
16,
2365,
3474,
17,
14,
16,
15559,
2152,
29,
1609,
63,
2271,
395,
1598,
298,
793,
63,
20704,
582,
2116,
4413,
63,
411,
14,
4083,
11468,
17,
2020,
446,
2167,
8333,
2152,
29,
1609,
63,
2271,
9,
881,
3828,
489,
327,
710,
1642,
3522,
1819,
365,
440,
376,
676,
279,
1785,
12,
436,
880,
1077,
675,
314,
22515,
489,
327,
1174,
14,
710,
3499,
365,
376,
676,
279,
1785,
12,
436,
1077,
675,
314,
14746,
1174,
14,
489,
1420,
63,
929,
275,
19819,
1257,
8333,
359,
1165,
24245,
717,
359,
17,
2020,
1227,
8333,
717,
5243,
17,
12,
446,
18,
2677,
489,
543,
291,
14,
396,
63,
1730,
837,
267,
367,
23005,
972,
12,
1420,
315,
3482,
8,
29690,
972,
63,
929,
12,
1420,
63,
929,
304,
881,
291,
14,
7260,
8,
2062,
12,
23005,
972,
14,
2579,
1012,
267,
291,
14,
15070,
8,
16,
2020,
4588,
63,
4467,
905,
32048,
63,
3397,
9210,
16,
1055,
2579,
1012,
267,
291,
14,
15625,
8,
16,
2020,
4588,
63,
4467,
905,
32048,
63,
3397,
9210,
17,
1055,
2579,
1012,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
523,
511,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
megakevin/single-authored-code-evolution-analysis
|
fix_bug_commits.py
|
1
|
6318
|
__author__ = 'kevin'
from datetime import datetime
from subprocess import call, check_output
import sys
import os
import csv
import copy
import tag_lists
class GitTag():
"""Represents a Tag in a git repository"""
def __init__(self, line):
raw_tag, raw_hash, raw_date, raw_timestamp = line.split("|")
# process the hash:
self.tag_hash = raw_hash.strip()
# process the timestamp
self.tag_timestamp = float(raw_timestamp.strip())
# process the datetime
self.date = raw_date.strip()
raw_tag = raw_tag.split("tag:")[1]
# get the git-tag
if "," in raw_tag:
self.name = raw_tag.split(",")[0].strip()
else:
self.name = raw_tag.replace(")", "").strip()
def date_to_string(self, time):
"""Returns: A string representation of a UNIX timestamp"""
return str(datetime.fromtimestamp(time))
def __str__(self):
return str({'name': self.name, 'date': self.date})
class GitRepository():
git_folder = ".git/"
def __init__(self, repo_path):
"""Constructor for GitRepository"""
self.repo_path = repo_path
def get_tags(self):
"""Returns: List of all the tags in the repository"""
cmd_get_tags = 'cd {0}; git log --tags --simplify-by-decoration --pretty="format:%d | %H | %ai | %at" |grep "tag:"'.format(self.repo_path)
results_cmd = check_output(cmd_get_tags, shell=True).decode("utf-8")
tags = [GitTag(str(line)) for line in results_cmd.splitlines()]
# tags.sort(key=lambda t: t.date)
return tags
def distinct(l, field_selector=None):
# order preserving
if field_selector is None:
def field_selector(x):
return x
seen = {}
result = []
for item in l:
comparison_field = field_selector(item)
if comparison_field in seen:
continue
else:
seen[comparison_field] = True
result.append(item)
return result
def get_interesting_releases(git_repo):
ordered_tags = []
if 'apache-avro' in git_repo:
ordered_tags = tag_lists.apache_avro_releases
elif 'apache-mahout' in git_repo:
ordered_tags = tag_lists.apache_mahout_releases
elif 'apache-tika' in git_repo:
ordered_tags = tag_lists.apache_tika_releases
elif 'vrapper' in git_repo:
ordered_tags = tag_lists.vrapper_releases
elif 'apache-zookeeper' in git_repo:
ordered_tags = tag_lists.apache_zookeeper_releases
elif 'facebook-android-sdk' in git_repo:
ordered_tags = tag_lists.facebook_android_sdk_releases
elif 'github-android-app' in git_repo:
ordered_tags = tag_lists.github_android_app_releases
elif 'wordpress-android' in git_repo:
ordered_tags = tag_lists.wordpress_android_app
return ordered_tags
def sort_tags(git_repo, tags):
result = []
ordered_tags = get_interesting_releases(git_repo)
# tags_copy = copy.deepcopy(tags)
# for i, tag in enumerate(ordered_tags):
for tag in ordered_tags:
# tags[i] = [t for t in tags_copy if t.name == tag][0]
result.append([t for t in tags if t.name == tag][0])
# del tags[len(ordered_tags):]
return result
def handle_negative(value, actual_version, past_version):
# return value
if value < 0:
if actual_version['loc'] == past_version['loc']:
return 0
else:
return int(actual_version['commit_num'])
else:
return value
csv_header = ['file_name', 'release', 'is_sac', 'loc', 'commit_num', 'bug_commit_num', 'bug_commit_ratio']
def main():
git_repo = sys.argv[1]
stats_file = sys.argv[2]
output_file = sys.argv[3]
repo = GitRepository(git_repo)
tags = sort_tags(git_repo, repo.get_tags())
with open(stats_file, "r") as stats_file:
# 'file_name', 'release', 'is_sac', 'loc', 'commit_num', 'bug_commit_num', 'bug_commit_ratio'
stats = [row for row in csv.DictReader(stats_file) if row['release'] in get_interesting_releases(git_repo)]
unique_files = distinct(stats, field_selector=lambda f: f['file_name'])
for file in unique_files:
# print("Processing file: " + file['file_name'])
file_versions = [f for f in stats if f['file_name'] == file['file_name']]
file_tags = [t for t in tags if t.name in [f['release'] for f in file_versions]]
# file_tags.sort(key=lambda t: t.date)
# file_tags = file_tags[::-1]
fixed_values = {}
for i, tag in enumerate(file_tags):
# print("Processing tag: " + tag.name)
if i + 1 < len(file_tags):
# if not tag.date == file_tags[i + 1].date:
actual_version = [f for f in file_versions if f['release'] == tag.name][0]
past_version = [f for f in file_versions if f['release'] == file_tags[i + 1].name][0]
commit_num = handle_negative(int(actual_version['commit_num']) - int(past_version['commit_num']),
actual_version,
past_version)
bug_commit_num = handle_negative(int(actual_version['bug_commit_num']) - int(past_version['bug_commit_num']),
actual_version,
past_version)
bug_commit_ratio = (bug_commit_num / commit_num) if commit_num != 0 else 0
fixed_values[tag.name] = {'commit_num': commit_num,
'bug_commit_num': bug_commit_num,
'bug_commit_ratio': bug_commit_ratio}
for tag, data in fixed_values.items():
actual_version = [f for f in file_versions if f['release'] == tag][0]
actual_version['commit_num'] = data['commit_num']
actual_version['bug_commit_num'] = data['bug_commit_num']
actual_version['bug_commit_ratio'] = data['bug_commit_ratio']
with open(output_file, 'w', newline='') as output_file:
writer = csv.DictWriter(output_file, csv_header)
writer.writeheader()
writer.writerows(stats)
if __name__ == "__main__":
main()
|
mit
|
[
363,
2502,
363,
275,
283,
415,
11908,
7,
199,
199,
504,
2197,
492,
2197,
199,
504,
3873,
492,
1240,
12,
1104,
63,
1199,
199,
646,
984,
199,
646,
747,
199,
646,
7392,
199,
646,
1331,
199,
199,
646,
1947,
63,
6717,
199,
199,
533,
12579,
1931,
837,
272,
408,
18089,
282,
8053,
315,
282,
6135,
7611,
624,
339,
347,
636,
826,
721,
277,
12,
1004,
304,
267,
3066,
63,
1450,
12,
3066,
63,
2227,
12,
3066,
63,
602,
12,
3066,
63,
3954,
275,
1004,
14,
1294,
25795,
531,
398,
327,
2112,
314,
2631,
26,
267,
291,
14,
1450,
63,
2227,
275,
3066,
63,
2227,
14,
1913,
342,
398,
327,
2112,
314,
4913,
267,
291,
14,
1450,
63,
3954,
275,
2069,
8,
1773,
63,
3954,
14,
1913,
1012,
398,
327,
2112,
314,
2197,
267,
291,
14,
602,
275,
3066,
63,
602,
14,
1913,
342,
398,
3066,
63,
1450,
275,
3066,
63,
1450,
14,
1294,
480,
1450,
9107,
59,
17,
61,
267,
327,
664,
314,
6135,
13,
1450,
267,
340,
21147,
315,
3066,
63,
1450,
26,
288,
291,
14,
354,
275,
3066,
63,
1450,
14,
1294,
11854,
9981,
16,
1055,
1913,
342,
267,
587,
26,
288,
291,
14,
354,
275,
3066,
63,
1450,
14,
1814,
480,
4186,
25354,
1913,
342,
339,
347,
1434,
63,
475,
63,
875,
8,
277,
12,
900,
304,
267,
408,
3407,
26,
437,
1059,
6025,
402,
282,
22242,
4913,
624,
267,
372,
620,
8,
2083,
14,
18531,
8,
521,
430,
339,
347,
636,
495,
721,
277,
304,
267,
372,
620,
3252,
354,
356,
291,
14,
354,
12,
283,
602,
356,
291,
14,
602,
1552,
421,
199,
533,
12579,
15614,
837,
339,
6135,
63,
3741,
275,
3680,
3187,
6687,
339,
347,
636,
826,
721,
277,
12,
3831,
63,
515,
304,
267,
408,
11447,
367,
12579,
15614,
624,
267,
291,
14,
3417,
63,
515,
275,
3831,
63,
515,
339,
347,
664,
63,
2969,
8,
277,
304,
267,
408,
3407,
26,
3820,
402,
1006,
314,
3762,
315,
314,
7611,
624,
398,
2088,
63,
362,
63,
2969,
275,
283,
2866,
469,
16,
12084,
6135,
943,
1553,
2969,
1553,
19084,
13,
991,
13,
6518,
425,
1553,
9118,
628,
908,
2689,
68,
1204,
450,
40,
1204,
450,
5789,
1204,
450,
292,
2,
1204,
25914,
298,
1450,
5424,
1370,
908,
8,
277,
14,
3417,
63,
515,
9,
267,
2058,
63,
1760,
275,
1104,
63,
1199,
8,
1760,
63,
362,
63,
2969,
12,
5218,
29,
549,
680,
2708,
480,
1624,
13,
24,
531,
398,
3762,
275,
359,
14686,
1931,
8,
495,
8,
604,
430,
367,
1004,
315,
2058,
63,
1760,
14,
7644,
5106,
398,
327,
3762,
14,
3191,
8,
498,
29,
2734,
307,
26,
307,
14,
602,
9,
421,
398,
372,
3762,
421,
199,
318,
15392,
8,
76,
12,
901,
63,
6662,
29,
403,
304,
272,
327,
1865,
876,
14717,
272,
340,
901,
63,
6662,
365,
488,
26,
267,
347,
901,
63,
6662,
8,
88,
304,
288,
372,
671,
339,
6775,
275,
1052,
272,
754,
275,
942,
339,
367,
1242,
315,
634,
26,
267,
9132,
63,
698,
275,
901,
63,
6662,
8,
1053,
9,
398,
340,
9132,
63,
698,
315,
6775,
26,
288,
1980,
267,
587,
26,
288,
6775,
59,
8547,
63,
698,
61,
275,
715,
288,
754,
14,
740,
8,
1053,
9,
339,
372,
754,
421,
199,
318,
664,
63,
30267,
63,
11840,
8,
3187,
63,
3417,
304,
339,
7741,
63,
2969,
275,
942,
339,
340,
283,
3796,
13,
1214,
293,
7,
315,
6135,
63,
3417,
26,
267,
7741,
63,
2969,
275,
1947,
63,
6717,
14,
3796,
63,
1214,
293,
63,
11840,
272,
916,
283,
3796,
13,
391,
20267,
7,
315,
6135,
63,
3417,
26,
267,
7741,
63,
2969,
275,
1947,
63,
6717,
14,
3796,
63,
391,
20267,
63,
11840,
272,
916,
283,
3796,
13,
280,
7351,
7,
315,
6135,
63,
3417,
26,
267,
7741,
63,
2969,
275,
1947,
63,
6717,
14,
3796,
63,
280,
7351,
63,
11840,
272,
916,
283,
86,
2369,
7,
315,
6135,
63,
3417,
26,
267,
7741,
63,
2969,
275,
1947,
63,
6717,
14,
86,
2369,
63,
11840,
272,
916,
283,
3796,
13,
90,
23479,
7,
315,
6135,
63,
3417,
26,
267,
7741,
63,
2969,
275,
1947,
63,
6717,
14,
3796,
63,
90,
23479,
63,
11840,
272,
916,
283,
16652,
13,
6238,
13,
9277,
7,
315,
6135,
63,
3417,
26,
267,
7741,
63,
2969,
275,
1947,
63,
6717,
14,
16652,
63,
6238,
63,
9277,
63,
11840,
272,
916,
283,
5031,
13,
6238,
13,
571,
7,
315,
6135,
63,
3417,
26,
267,
7741,
63,
2969,
275,
1947,
63,
6717,
14,
5031,
63,
6238,
63,
571,
63,
11840,
272,
916,
283,
1027,
2915,
13,
6238,
7,
315,
6135,
63,
3417,
26,
267,
7741,
63,
2969,
275,
1947,
63,
6717,
14,
1027,
2915,
63,
6238,
63,
571,
339,
372,
7741,
63,
2969,
421,
199,
318,
4069,
63,
2969,
8,
3187,
63,
3417,
12,
3762,
304,
339,
754,
275,
942,
272,
7741,
63,
2969,
275,
664,
63,
30267,
63,
11840,
8,
3187,
63,
3417,
9,
339,
327,
3762,
63,
1574,
275,
1331,
14,
8293,
8,
2969,
9,
339,
327,
367,
284,
12,
1947,
315,
3874,
8,
8235,
63,
2969,
304,
272,
367,
1947,
315,
7741,
63,
2969,
26,
267,
327,
3762,
59,
73,
61,
275,
359,
84,
367,
307,
315,
3762,
63,
1574,
340,
307,
14,
354,
508,
1947,
1527,
16,
61,
267,
754,
14,
740,
779,
84,
367,
307,
315,
3762,
340,
307,
14,
354,
508,
1947,
1527,
16,
566,
339,
327,
2150,
3762,
59,
552,
8,
8235,
63,
2969,
15405,
272,
372,
754,
421,
199,
318,
2429,
63,
7371,
8,
585,
12,
3503,
63,
1023,
12,
13541,
63,
1023,
304,
272,
327,
372,
574,
339,
340,
574,
665,
378,
26,
267,
340,
3503,
63,
1023,
459,
2102,
418,
508,
13541,
63,
1023,
459,
2102,
2565,
288,
372,
378,
267,
587,
26,
288,
372,
1109,
8,
6514,
63,
1023,
459,
3543,
63,
1507,
1105,
272,
587,
26,
267,
372,
574,
199,
199,
4737,
63,
1291,
275,
788,
493,
63,
354,
297,
283,
3221,
297,
283,
374,
63,
83,
645,
297,
283,
2102,
297,
283,
3543,
63,
1507,
297,
283,
1266,
63,
3543,
63,
1507,
297,
283,
1266,
63,
3543,
63,
6884,
418,
421,
199,
318,
2446,
837,
272
] |
[
2502,
363,
275,
283,
415,
11908,
7,
199,
199,
504,
2197,
492,
2197,
199,
504,
3873,
492,
1240,
12,
1104,
63,
1199,
199,
646,
984,
199,
646,
747,
199,
646,
7392,
199,
646,
1331,
199,
199,
646,
1947,
63,
6717,
199,
199,
533,
12579,
1931,
837,
272,
408,
18089,
282,
8053,
315,
282,
6135,
7611,
624,
339,
347,
636,
826,
721,
277,
12,
1004,
304,
267,
3066,
63,
1450,
12,
3066,
63,
2227,
12,
3066,
63,
602,
12,
3066,
63,
3954,
275,
1004,
14,
1294,
25795,
531,
398,
327,
2112,
314,
2631,
26,
267,
291,
14,
1450,
63,
2227,
275,
3066,
63,
2227,
14,
1913,
342,
398,
327,
2112,
314,
4913,
267,
291,
14,
1450,
63,
3954,
275,
2069,
8,
1773,
63,
3954,
14,
1913,
1012,
398,
327,
2112,
314,
2197,
267,
291,
14,
602,
275,
3066,
63,
602,
14,
1913,
342,
398,
3066,
63,
1450,
275,
3066,
63,
1450,
14,
1294,
480,
1450,
9107,
59,
17,
61,
267,
327,
664,
314,
6135,
13,
1450,
267,
340,
21147,
315,
3066,
63,
1450,
26,
288,
291,
14,
354,
275,
3066,
63,
1450,
14,
1294,
11854,
9981,
16,
1055,
1913,
342,
267,
587,
26,
288,
291,
14,
354,
275,
3066,
63,
1450,
14,
1814,
480,
4186,
25354,
1913,
342,
339,
347,
1434,
63,
475,
63,
875,
8,
277,
12,
900,
304,
267,
408,
3407,
26,
437,
1059,
6025,
402,
282,
22242,
4913,
624,
267,
372,
620,
8,
2083,
14,
18531,
8,
521,
430,
339,
347,
636,
495,
721,
277,
304,
267,
372,
620,
3252,
354,
356,
291,
14,
354,
12,
283,
602,
356,
291,
14,
602,
1552,
421,
199,
533,
12579,
15614,
837,
339,
6135,
63,
3741,
275,
3680,
3187,
6687,
339,
347,
636,
826,
721,
277,
12,
3831,
63,
515,
304,
267,
408,
11447,
367,
12579,
15614,
624,
267,
291,
14,
3417,
63,
515,
275,
3831,
63,
515,
339,
347,
664,
63,
2969,
8,
277,
304,
267,
408,
3407,
26,
3820,
402,
1006,
314,
3762,
315,
314,
7611,
624,
398,
2088,
63,
362,
63,
2969,
275,
283,
2866,
469,
16,
12084,
6135,
943,
1553,
2969,
1553,
19084,
13,
991,
13,
6518,
425,
1553,
9118,
628,
908,
2689,
68,
1204,
450,
40,
1204,
450,
5789,
1204,
450,
292,
2,
1204,
25914,
298,
1450,
5424,
1370,
908,
8,
277,
14,
3417,
63,
515,
9,
267,
2058,
63,
1760,
275,
1104,
63,
1199,
8,
1760,
63,
362,
63,
2969,
12,
5218,
29,
549,
680,
2708,
480,
1624,
13,
24,
531,
398,
3762,
275,
359,
14686,
1931,
8,
495,
8,
604,
430,
367,
1004,
315,
2058,
63,
1760,
14,
7644,
5106,
398,
327,
3762,
14,
3191,
8,
498,
29,
2734,
307,
26,
307,
14,
602,
9,
421,
398,
372,
3762,
421,
199,
318,
15392,
8,
76,
12,
901,
63,
6662,
29,
403,
304,
272,
327,
1865,
876,
14717,
272,
340,
901,
63,
6662,
365,
488,
26,
267,
347,
901,
63,
6662,
8,
88,
304,
288,
372,
671,
339,
6775,
275,
1052,
272,
754,
275,
942,
339,
367,
1242,
315,
634,
26,
267,
9132,
63,
698,
275,
901,
63,
6662,
8,
1053,
9,
398,
340,
9132,
63,
698,
315,
6775,
26,
288,
1980,
267,
587,
26,
288,
6775,
59,
8547,
63,
698,
61,
275,
715,
288,
754,
14,
740,
8,
1053,
9,
339,
372,
754,
421,
199,
318,
664,
63,
30267,
63,
11840,
8,
3187,
63,
3417,
304,
339,
7741,
63,
2969,
275,
942,
339,
340,
283,
3796,
13,
1214,
293,
7,
315,
6135,
63,
3417,
26,
267,
7741,
63,
2969,
275,
1947,
63,
6717,
14,
3796,
63,
1214,
293,
63,
11840,
272,
916,
283,
3796,
13,
391,
20267,
7,
315,
6135,
63,
3417,
26,
267,
7741,
63,
2969,
275,
1947,
63,
6717,
14,
3796,
63,
391,
20267,
63,
11840,
272,
916,
283,
3796,
13,
280,
7351,
7,
315,
6135,
63,
3417,
26,
267,
7741,
63,
2969,
275,
1947,
63,
6717,
14,
3796,
63,
280,
7351,
63,
11840,
272,
916,
283,
86,
2369,
7,
315,
6135,
63,
3417,
26,
267,
7741,
63,
2969,
275,
1947,
63,
6717,
14,
86,
2369,
63,
11840,
272,
916,
283,
3796,
13,
90,
23479,
7,
315,
6135,
63,
3417,
26,
267,
7741,
63,
2969,
275,
1947,
63,
6717,
14,
3796,
63,
90,
23479,
63,
11840,
272,
916,
283,
16652,
13,
6238,
13,
9277,
7,
315,
6135,
63,
3417,
26,
267,
7741,
63,
2969,
275,
1947,
63,
6717,
14,
16652,
63,
6238,
63,
9277,
63,
11840,
272,
916,
283,
5031,
13,
6238,
13,
571,
7,
315,
6135,
63,
3417,
26,
267,
7741,
63,
2969,
275,
1947,
63,
6717,
14,
5031,
63,
6238,
63,
571,
63,
11840,
272,
916,
283,
1027,
2915,
13,
6238,
7,
315,
6135,
63,
3417,
26,
267,
7741,
63,
2969,
275,
1947,
63,
6717,
14,
1027,
2915,
63,
6238,
63,
571,
339,
372,
7741,
63,
2969,
421,
199,
318,
4069,
63,
2969,
8,
3187,
63,
3417,
12,
3762,
304,
339,
754,
275,
942,
272,
7741,
63,
2969,
275,
664,
63,
30267,
63,
11840,
8,
3187,
63,
3417,
9,
339,
327,
3762,
63,
1574,
275,
1331,
14,
8293,
8,
2969,
9,
339,
327,
367,
284,
12,
1947,
315,
3874,
8,
8235,
63,
2969,
304,
272,
367,
1947,
315,
7741,
63,
2969,
26,
267,
327,
3762,
59,
73,
61,
275,
359,
84,
367,
307,
315,
3762,
63,
1574,
340,
307,
14,
354,
508,
1947,
1527,
16,
61,
267,
754,
14,
740,
779,
84,
367,
307,
315,
3762,
340,
307,
14,
354,
508,
1947,
1527,
16,
566,
339,
327,
2150,
3762,
59,
552,
8,
8235,
63,
2969,
15405,
272,
372,
754,
421,
199,
318,
2429,
63,
7371,
8,
585,
12,
3503,
63,
1023,
12,
13541,
63,
1023,
304,
272,
327,
372,
574,
339,
340,
574,
665,
378,
26,
267,
340,
3503,
63,
1023,
459,
2102,
418,
508,
13541,
63,
1023,
459,
2102,
2565,
288,
372,
378,
267,
587,
26,
288,
372,
1109,
8,
6514,
63,
1023,
459,
3543,
63,
1507,
1105,
272,
587,
26,
267,
372,
574,
199,
199,
4737,
63,
1291,
275,
788,
493,
63,
354,
297,
283,
3221,
297,
283,
374,
63,
83,
645,
297,
283,
2102,
297,
283,
3543,
63,
1507,
297,
283,
1266,
63,
3543,
63,
1507,
297,
283,
1266,
63,
3543,
63,
6884,
418,
421,
199,
318,
2446,
837,
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,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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
] |
afrolov1/nova
|
nova/openstack/common/report/utils.py
|
79
|
1404
|
# Copyright 2013 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""Various utilities for report generation
This module includes various utilities
used in generating reports.
"""
import gc
class StringWithAttrs(str):
"""A String that can have arbitrary attributes
"""
pass
def _find_objects(t):
"""Find Objects in the GC State
This horribly hackish method locates objects of a
given class in the current python instance's garbage
collection state. In case you couldn't tell, this is
horribly hackish, but is necessary for locating all
green threads, since they don't keep track of themselves
like normal threads do in python.
:param class t: the class of object to locate
:rtype: list
:returns: a list of objects of the given type
"""
return [o for o in gc.get_objects() if isinstance(o, t)]
|
apache-2.0
|
[
3,
1898,
6171,
9572,
13002,
12,
3277,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
624,
9958,
1785,
15841,
367,
3622,
10152,
199,
199,
2765,
859,
6952,
7750,
15841,
199,
2972,
315,
12999,
13924,
14,
199,
624,
199,
199,
646,
9486,
421,
199,
533,
2624,
3007,
21368,
8,
495,
304,
272,
408,
33,
2624,
626,
883,
1172,
9697,
3004,
272,
408,
339,
986,
421,
199,
318,
485,
1623,
63,
1462,
8,
84,
304,
272,
408,
6591,
26794,
315,
314,
31555,
8511,
339,
961,
394,
269,
30759,
590,
11176,
2453,
1083,
16592,
83,
2251,
402,
282,
272,
1627,
1021,
315,
314,
1453,
2366,
1256,
1159,
17516,
272,
3245,
1174,
14,
221,
1010,
1930,
1265,
21554,
1133,
11480,
12,
642,
365,
272,
394,
269,
30759,
590,
11176,
2453,
12,
1325,
365,
5784,
367,
4355,
1958,
1006,
272,
12431,
7183,
12,
3967,
2985,
2793,
1133,
4215,
4426,
402,
17279,
272,
2839,
3293,
7183,
886,
315,
2366,
14,
339,
520,
635,
1021,
307,
26,
314,
1021,
402,
909,
370,
16592,
272,
520,
4500,
26,
769,
272,
520,
5808,
26,
282,
769,
402,
2251,
402,
314,
1627,
730,
272,
408,
339,
372,
359,
79,
367,
312,
315,
9486,
14,
362,
63,
1462,
342,
340,
1228,
8,
79,
12,
307,
1874,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
6171,
9572,
13002,
12,
3277,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
624,
9958,
1785,
15841,
367,
3622,
10152,
199,
199,
2765,
859,
6952,
7750,
15841,
199,
2972,
315,
12999,
13924,
14,
199,
624,
199,
199,
646,
9486,
421,
199,
533,
2624,
3007,
21368,
8,
495,
304,
272,
408,
33,
2624,
626,
883,
1172,
9697,
3004,
272,
408,
339,
986,
421,
199,
318,
485,
1623,
63,
1462,
8,
84,
304,
272,
408,
6591,
26794,
315,
314,
31555,
8511,
339,
961,
394,
269,
30759,
590,
11176,
2453,
1083,
16592,
83,
2251,
402,
282,
272,
1627,
1021,
315,
314,
1453,
2366,
1256,
1159,
17516,
272,
3245,
1174,
14,
221,
1010,
1930,
1265,
21554,
1133,
11480,
12,
642,
365,
272,
394,
269,
30759,
590,
11176,
2453,
12,
1325,
365,
5784,
367,
4355,
1958,
1006,
272,
12431,
7183,
12,
3967,
2985,
2793,
1133,
4215,
4426,
402,
17279,
272,
2839,
3293,
7183,
886,
315,
2366,
14,
339,
520,
635,
1021,
307,
26,
314,
1021,
402,
909,
370,
16592,
272,
520,
4500,
26,
769,
272,
520,
5808,
26,
282,
769,
402,
2251,
402,
314,
1627,
730,
272,
408,
339,
372,
359,
79,
367,
312,
315,
9486,
14,
362,
63,
1462,
342,
340,
1228,
8,
79,
12,
307,
1874,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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
] |
jimi-c/ansible
|
lib/ansible/modules/utilities/logic/assert.py
|
44
|
2015
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright 2012 Dag Wieers <dag@wieers.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': ['stableinterface'],
'supported_by': 'core'}
DOCUMENTATION = '''
---
module: assert
short_description: Asserts given expressions are true
description:
- This module asserts that given expressions are true with an optional custom message.
- This module is also supported for Windows targets.
version_added: "1.5"
options:
that:
description:
- "A string expression of the same form that can be passed to the 'when' statement"
- "Alternatively, a list of string expressions"
required: true
fail_msg:
version_added: "2.7"
description:
- "The customized message used for a failing assertion"
- "This argument was called 'msg' before version 2.7, now it's renamed to 'fail_msg' with alias 'msg'"
aliases:
- msg
success_msg:
version_added: "2.7"
description:
- "The customized message used for a successful assertion"
notes:
- This module is also supported for Windows targets.
author:
- "Ansible Core Team"
- "Michael DeHaan"
'''
EXAMPLES = '''
- assert: { that: "ansible_os_family != 'RedHat'" }
- assert:
that:
- "'foo' in some_command_result.stdout"
- "number_of_the_counting == 3"
- name: after version 2.7 both 'msg' and 'fail_msg' can customize failing assertion message
assert:
that:
- "my_param <= 100"
- "my_param >= 0"
fail_msg: "'my_param' must be between 0 and 100"
success_msg: "'my_param' is between 0 and 100"
- name: please use 'msg' when ansible version is smaller than 2.7
assert:
that:
- "my_param <= 100"
- "my_param >= 0"
msg: "'my_param' must be between 0 and 100"
'''
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
1898,
6029,
26110,
644,
1873,
1192,
665,
7406,
32,
87,
1873,
1192,
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,
421,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
490,
283,
1205,
356,
788,
11989,
3266,
995,
490,
283,
4946,
63,
991,
356,
283,
1018,
936,
421,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
702,
199,
3612,
63,
1802,
26,
10716,
83,
1627,
8455,
787,
2549,
199,
1802,
26,
1362,
446,
961,
859,
702,
83,
626,
1627,
8455,
787,
2549,
543,
376,
2716,
3537,
1245,
14,
1362,
446,
961,
859,
365,
2597,
3748,
367,
5417,
4545,
14,
199,
1023,
63,
3270,
26,
298,
17,
14,
21,
2,
199,
1419,
26,
523,
626,
26,
272,
1369,
26,
489,
446,
298,
33,
1059,
3965,
402,
314,
2011,
1824,
626,
883,
506,
3032,
370,
314,
283,
6526,
7,
5164,
2,
489,
446,
298,
19978,
17330,
12,
282,
769,
402,
1059,
8455,
2,
272,
1415,
26,
2549,
523,
2449,
63,
1328,
26,
272,
1015,
63,
3270,
26,
298,
18,
14,
23,
2,
272,
1369,
26,
489,
446,
298,
1918,
26707,
1245,
1202,
367,
282,
18648,
14412,
2,
489,
446,
298,
2765,
1423,
1990,
2797,
283,
1328,
7,
2544,
1015,
499,
14,
23,
12,
3063,
652,
1159,
17864,
370,
283,
1633,
63,
1328,
7,
543,
5162,
283,
1328,
4065,
272,
5481,
26,
489,
446,
1499,
523,
3182,
63,
1328,
26,
272,
1015,
63,
3270,
26,
298,
18,
14,
23,
2,
272,
1369,
26,
489,
446,
298,
1918,
26707,
1245,
1202,
367,
282,
9512,
14412,
2,
199,
5983,
26,
1362,
446,
961,
859,
365,
2597,
3748,
367,
5417,
4545,
14,
199,
2502,
26,
272,
446,
298,
10047,
11672,
11682,
2,
272,
446,
298,
45,
11781,
22453,
2,
199,
2344,
199,
199,
8918,
275,
1449,
199,
13,
702,
26,
469,
626,
26,
298,
4853,
63,
736,
63,
6606,
1137,
283,
10858,
40,
292,
4065,
789,
199,
199,
13,
702,
26,
272,
626,
26,
489,
446,
3546,
1421,
7,
315,
2005,
63,
1531,
63,
1099,
14,
2703,
2,
489,
446,
298,
1955,
63,
1618,
63,
1589,
63,
835,
316,
508,
650,
2,
199,
199,
13,
536,
26,
2410,
1015,
499,
14,
23,
3865,
283,
1328,
7,
436,
283,
1633,
63,
1328,
7,
883,
17551,
18648,
14412,
1245,
523,
702,
26,
272,
626,
26,
489,
446,
298,
1662,
63,
635,
2695,
2948,
2,
489,
446,
298,
1662,
63,
635,
2356,
378,
2,
272,
2449,
63,
1328,
26,
3546,
1662,
63,
635,
7,
1471,
506,
3382,
378,
436,
2948,
2,
272,
3182,
63,
1328,
26,
3546,
1662,
63,
635,
7,
365,
3382,
378,
436,
2948,
2,
199,
199,
13,
536,
26,
8749,
675,
283,
1328,
7,
1380,
3242,
1015,
365,
12700,
2419,
499,
14,
23,
523,
702,
26,
272,
626,
26,
489,
446,
298,
1662,
63,
635,
2695,
2948,
2,
489,
446,
298,
1662,
63,
635,
2356,
378,
2,
272,
1499,
26,
3546,
1662,
63,
635,
7,
1471,
506,
3382,
378,
436,
2948,
2,
199,
2344,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
1898,
6029,
26110,
644,
1873,
1192,
665,
7406,
32,
87,
1873,
1192,
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,
421,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
490,
283,
1205,
356,
788,
11989,
3266,
995,
490,
283,
4946,
63,
991,
356,
283,
1018,
936,
421,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
702,
199,
3612,
63,
1802,
26,
10716,
83,
1627,
8455,
787,
2549,
199,
1802,
26,
1362,
446,
961,
859,
702,
83,
626,
1627,
8455,
787,
2549,
543,
376,
2716,
3537,
1245,
14,
1362,
446,
961,
859,
365,
2597,
3748,
367,
5417,
4545,
14,
199,
1023,
63,
3270,
26,
298,
17,
14,
21,
2,
199,
1419,
26,
523,
626,
26,
272,
1369,
26,
489,
446,
298,
33,
1059,
3965,
402,
314,
2011,
1824,
626,
883,
506,
3032,
370,
314,
283,
6526,
7,
5164,
2,
489,
446,
298,
19978,
17330,
12,
282,
769,
402,
1059,
8455,
2,
272,
1415,
26,
2549,
523,
2449,
63,
1328,
26,
272,
1015,
63,
3270,
26,
298,
18,
14,
23,
2,
272,
1369,
26,
489,
446,
298,
1918,
26707,
1245,
1202,
367,
282,
18648,
14412,
2,
489,
446,
298,
2765,
1423,
1990,
2797,
283,
1328,
7,
2544,
1015,
499,
14,
23,
12,
3063,
652,
1159,
17864,
370,
283,
1633,
63,
1328,
7,
543,
5162,
283,
1328,
4065,
272,
5481,
26,
489,
446,
1499,
523,
3182,
63,
1328,
26,
272,
1015,
63,
3270,
26,
298,
18,
14,
23,
2,
272,
1369,
26,
489,
446,
298,
1918,
26707,
1245,
1202,
367,
282,
9512,
14412,
2,
199,
5983,
26,
1362,
446,
961,
859,
365,
2597,
3748,
367,
5417,
4545,
14,
199,
2502,
26,
272,
446,
298,
10047,
11672,
11682,
2,
272,
446,
298,
45,
11781,
22453,
2,
199,
2344,
199,
199,
8918,
275,
1449,
199,
13,
702,
26,
469,
626,
26,
298,
4853,
63,
736,
63,
6606,
1137,
283,
10858,
40,
292,
4065,
789,
199,
199,
13,
702,
26,
272,
626,
26,
489,
446,
3546,
1421,
7,
315,
2005,
63,
1531,
63,
1099,
14,
2703,
2,
489,
446,
298,
1955,
63,
1618,
63,
1589,
63,
835,
316,
508,
650,
2,
199,
199,
13,
536,
26,
2410,
1015,
499,
14,
23,
3865,
283,
1328,
7,
436,
283,
1633,
63,
1328,
7,
883,
17551,
18648,
14412,
1245,
523,
702,
26,
272,
626,
26,
489,
446,
298,
1662,
63,
635,
2695,
2948,
2,
489,
446,
298,
1662,
63,
635,
2356,
378,
2,
272,
2449,
63,
1328,
26,
3546,
1662,
63,
635,
7,
1471,
506,
3382,
378,
436,
2948,
2,
272,
3182,
63,
1328,
26,
3546,
1662,
63,
635,
7,
365,
3382,
378,
436,
2948,
2,
199,
199,
13,
536,
26,
8749,
675,
283,
1328,
7,
1380,
3242,
1015,
365,
12700,
2419,
499,
14,
23,
523,
702,
26,
272,
626,
26,
489,
446,
298,
1662,
63,
635,
2695,
2948,
2,
489,
446,
298,
1662,
63,
635,
2356,
378,
2,
272,
1499,
26,
3546,
1662,
63,
635,
7,
1471,
506,
3382,
378,
436,
2948,
2,
199,
2344,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
zhengyongbo/phantomjs
|
src/qt/qtwebkit/Tools/Scripts/webkitpy/layout_tests/models/test_run_results.py
|
118
|
11747
|
# Copyright (C) 2010 Google Inc. All rights reserved.
# Copyright (C) 2010 Gabor Rapcsanyi (rgabor@inf.u-szeged.hu), University of Szeged
#
# 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.
import logging
from webkitpy.layout_tests.models import test_expectations
from webkitpy.layout_tests.models import test_failures
_log = logging.getLogger(__name__)
class TestRunResults(object):
def __init__(self, expectations, num_tests):
self.total = num_tests
self.remaining = self.total
self.expectations = expectations
self.expected = 0
self.unexpected = 0
self.unexpected_failures = 0
self.unexpected_crashes = 0
self.unexpected_timeouts = 0
self.tests_by_expectation = {}
self.tests_by_timeline = {}
self.results_by_name = {} # Map of test name to the last result for the test.
self.all_results = [] # All results from a run, including every iteration of every test.
self.unexpected_results_by_name = {}
self.failures_by_name = {}
self.total_failures = 0
self.expected_skips = 0
for expectation in test_expectations.TestExpectations.EXPECTATIONS.values():
self.tests_by_expectation[expectation] = set()
for timeline in test_expectations.TestExpectations.TIMELINES.values():
self.tests_by_timeline[timeline] = expectations.get_tests_with_timeline(timeline)
self.slow_tests = set()
self.interrupted = False
def add(self, test_result, expected, test_is_slow):
self.tests_by_expectation[test_result.type].add(test_result.test_name)
self.results_by_name[test_result.test_name] = test_result
if test_result.type != test_expectations.SKIP:
self.all_results.append(test_result)
self.remaining -= 1
if len(test_result.failures):
self.total_failures += 1
self.failures_by_name[test_result.test_name] = test_result.failures
if expected:
self.expected += 1
if test_result.type == test_expectations.SKIP:
self.expected_skips += 1
else:
self.unexpected_results_by_name[test_result.test_name] = test_result
self.unexpected += 1
if len(test_result.failures):
self.unexpected_failures += 1
if test_result.type == test_expectations.CRASH:
self.unexpected_crashes += 1
elif test_result.type == test_expectations.TIMEOUT:
self.unexpected_timeouts += 1
if test_is_slow:
self.slow_tests.add(test_result.test_name)
class RunDetails(object):
def __init__(self, exit_code, summarized_results=None, initial_results=None, retry_results=None, enabled_pixel_tests_in_retry=False):
self.exit_code = exit_code
self.summarized_results = summarized_results
self.initial_results = initial_results
self.retry_results = retry_results
self.enabled_pixel_tests_in_retry = enabled_pixel_tests_in_retry
def _interpret_test_failures(failures):
test_dict = {}
failure_types = [type(failure) for failure in failures]
# FIXME: get rid of all this is_* values once there is a 1:1 map between
# TestFailure type and test_expectations.EXPECTATION.
if test_failures.FailureMissingAudio in failure_types:
test_dict['is_missing_audio'] = True
if test_failures.FailureMissingResult in failure_types:
test_dict['is_missing_text'] = True
if test_failures.FailureMissingImage in failure_types or test_failures.FailureMissingImageHash in failure_types:
test_dict['is_missing_image'] = True
if 'image_diff_percent' not in test_dict:
for failure in failures:
if isinstance(failure, test_failures.FailureImageHashMismatch) or isinstance(failure, test_failures.FailureReftestMismatch):
test_dict['image_diff_percent'] = failure.diff_percent
return test_dict
def summarize_results(port_obj, expectations, initial_results, retry_results, enabled_pixel_tests_in_retry):
"""Returns a dictionary containing a summary of the test runs, with the following fields:
'version': a version indicator
'fixable': The number of fixable tests (NOW - PASS)
'skipped': The number of skipped tests (NOW & SKIPPED)
'num_regressions': The number of non-flaky failures
'num_flaky': The number of flaky failures
'num_missing': The number of tests with missing results
'num_passes': The number of unexpected passes
'tests': a dict of tests -> {'expected': '...', 'actual': '...'}
"""
results = {}
results['version'] = 3
tbe = initial_results.tests_by_expectation
tbt = initial_results.tests_by_timeline
results['fixable'] = len(tbt[test_expectations.NOW] - tbe[test_expectations.PASS])
results['skipped'] = len(tbt[test_expectations.NOW] & tbe[test_expectations.SKIP])
num_passes = 0
num_flaky = 0
num_missing = 0
num_regressions = 0
keywords = {}
for expecation_string, expectation_enum in test_expectations.TestExpectations.EXPECTATIONS.iteritems():
keywords[expectation_enum] = expecation_string.upper()
for modifier_string, modifier_enum in test_expectations.TestExpectations.MODIFIERS.iteritems():
keywords[modifier_enum] = modifier_string.upper()
tests = {}
for test_name, result in initial_results.results_by_name.iteritems():
# Note that if a test crashed in the original run, we ignore
# whether or not it crashed when we retried it (if we retried it),
# and always consider the result not flaky.
expected = expectations.get_expectations_string(test_name)
result_type = result.type
actual = [keywords[result_type]]
if result_type == test_expectations.SKIP:
continue
test_dict = {}
if result.has_stderr:
test_dict['has_stderr'] = True
if result.reftest_type:
test_dict.update(reftest_type=list(result.reftest_type))
if expectations.has_modifier(test_name, test_expectations.WONTFIX):
test_dict['wontfix'] = True
if result_type == test_expectations.PASS:
num_passes += 1
# FIXME: include passing tests that have stderr output.
if expected == 'PASS':
continue
elif result_type == test_expectations.CRASH:
if test_name in initial_results.unexpected_results_by_name:
num_regressions += 1
elif result_type == test_expectations.MISSING:
if test_name in initial_results.unexpected_results_by_name:
num_missing += 1
elif test_name in initial_results.unexpected_results_by_name:
if retry_results and test_name not in retry_results.unexpected_results_by_name:
actual.extend(expectations.get_expectations_string(test_name).split(" "))
num_flaky += 1
elif retry_results:
retry_result_type = retry_results.unexpected_results_by_name[test_name].type
if result_type != retry_result_type:
if enabled_pixel_tests_in_retry and result_type == test_expectations.TEXT and retry_result_type == test_expectations.IMAGE_PLUS_TEXT:
num_regressions += 1
else:
num_flaky += 1
actual.append(keywords[retry_result_type])
else:
num_regressions += 1
else:
num_regressions += 1
test_dict['expected'] = expected
test_dict['actual'] = " ".join(actual)
test_dict.update(_interpret_test_failures(result.failures))
if retry_results:
retry_result = retry_results.unexpected_results_by_name.get(test_name)
if retry_result:
test_dict.update(_interpret_test_failures(retry_result.failures))
# Store test hierarchically by directory. e.g.
# foo/bar/baz.html: test_dict
# foo/bar/baz1.html: test_dict
#
# becomes
# foo: {
# bar: {
# baz.html: test_dict,
# baz1.html: test_dict
# }
# }
parts = test_name.split('/')
current_map = tests
for i, part in enumerate(parts):
if i == (len(parts) - 1):
current_map[part] = test_dict
break
if part not in current_map:
current_map[part] = {}
current_map = current_map[part]
results['tests'] = tests
results['num_passes'] = num_passes
results['num_flaky'] = num_flaky
results['num_missing'] = num_missing
results['num_regressions'] = num_regressions
results['uses_expectations_file'] = port_obj.uses_test_expectations_file()
results['interrupted'] = initial_results.interrupted # Does results.html have enough information to compute this itself? (by checking total number of results vs. total number of tests?)
results['layout_tests_dir'] = port_obj.layout_tests_dir()
results['has_wdiff'] = port_obj.wdiff_available()
results['has_pretty_patch'] = port_obj.pretty_patch_available()
results['pixel_tests_enabled'] = port_obj.get_option('pixel_tests')
try:
# We only use the svn revision for using trac links in the results.html file,
# Don't do this by default since it takes >100ms.
# FIXME: Do we really need to populate this both here and in the json_results_generator?
if port_obj.get_option("builder_name"):
port_obj.host.initialize_scm()
results['revision'] = port_obj.host.scm().head_svn_revision()
except Exception, e:
_log.warn("Failed to determine svn revision for checkout (cwd: %s, webkit_base: %s), leaving 'revision' key blank in full_results.json.\n%s" % (port_obj._filesystem.getcwd(), port_obj.path_from_webkit_base(), e))
# Handle cases where we're running outside of version control.
import traceback
_log.debug('Failed to learn head svn revision:')
_log.debug(traceback.format_exc())
results['revision'] = ""
return results
|
bsd-3-clause
|
[
3,
1898,
334,
35,
9,
7129,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
1898,
334,
35,
9,
7129,
598,
371,
269,
820,
439,
1259,
1629,
73,
334,
12430,
371,
269,
32,
4904,
14,
85,
13,
83,
806,
3046,
14,
10616,
395,
15904,
402,
428,
806,
3046,
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,
646,
2050,
199,
199,
504,
18007,
14,
4209,
63,
2219,
14,
992,
492,
511,
63,
15752,
199,
504,
18007,
14,
4209,
63,
2219,
14,
992,
492,
511,
63,
9968,
421,
199,
63,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
1379,
2540,
6579,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
21851,
12,
1967,
63,
2219,
304,
267,
291,
14,
2923,
275,
1967,
63,
2219,
267,
291,
14,
11266,
275,
291,
14,
2923,
267,
291,
14,
15752,
275,
21851,
267,
291,
14,
2062,
275,
378,
267,
291,
14,
8953,
275,
378,
267,
291,
14,
8953,
63,
9968,
275,
378,
267,
291,
14,
8953,
63,
1556,
9030,
275,
378,
267,
291,
14,
8953,
63,
30182,
275,
378,
267,
291,
14,
2219,
63,
991,
63,
20838,
275,
1052,
267,
291,
14,
2219,
63,
991,
63,
19369,
275,
1052,
267,
291,
14,
2604,
63,
991,
63,
354,
275,
1052,
221,
327,
9672,
402,
511,
536,
370,
314,
2061,
754,
367,
314,
511,
14,
267,
291,
14,
452,
63,
2604,
275,
942,
221,
327,
2900,
2058,
687,
282,
1255,
12,
5893,
4036,
8494,
402,
4036,
511,
14,
267,
291,
14,
8953,
63,
2604,
63,
991,
63,
354,
275,
1052,
267,
291,
14,
9968,
63,
991,
63,
354,
275,
1052,
267,
291,
14,
2923,
63,
9968,
275,
378,
267,
291,
14,
2062,
63,
2759,
83,
275,
378,
267,
367,
17513,
315,
511,
63,
15752,
14,
774,
31323,
14,
16957,
12969,
14,
1459,
837,
288,
291,
14,
2219,
63,
991,
63,
20838,
59,
20838,
61,
275,
663,
342,
267,
367,
20780,
315,
511,
63,
15752,
14,
774,
31323,
14,
11342,
2901,
568,
654,
14,
1459,
837,
288,
291,
14,
2219,
63,
991,
63,
19369,
59,
19369,
61,
275,
21851,
14,
362,
63,
2219,
63,
1045,
63,
19369,
8,
19369,
9,
267,
291,
14,
14362,
63,
2219,
275,
663,
342,
267,
291,
14,
1058,
15692,
275,
756,
339,
347,
1050,
8,
277,
12,
511,
63,
1099,
12,
1420,
12,
511,
63,
374,
63,
14362,
304,
267,
291,
14,
2219,
63,
991,
63,
20838,
59,
396,
63,
1099,
14,
466,
1055,
525,
8,
396,
63,
1099,
14,
396,
63,
354,
9,
267,
291,
14,
2604,
63,
991,
63,
354,
59,
396,
63,
1099,
14,
396,
63,
354,
61,
275,
511,
63,
1099,
267,
340,
511,
63,
1099,
14,
466,
1137,
511,
63,
15752,
14,
13525,
26,
288,
291,
14,
452,
63,
2604,
14,
740,
8,
396,
63,
1099,
9,
267,
291,
14,
11266,
4862,
413,
267,
340,
822,
8,
396,
63,
1099,
14,
9968,
304,
288,
291,
14,
2923,
63,
9968,
847,
413,
288,
291,
14,
9968,
63,
991,
63,
354,
59,
396,
63,
1099,
14,
396,
63,
354,
61,
275,
511,
63,
1099,
14,
9968,
267,
340,
1420,
26,
288,
291,
14,
2062,
847,
413,
288,
340,
511,
63,
1099,
14,
466,
508,
511,
63,
15752,
14,
13525,
26,
355,
291,
14,
2062,
63,
2759,
83,
847,
413,
267,
587,
26,
288,
291,
14,
8953,
63,
2604,
63,
991,
63,
354,
59,
396,
63,
1099,
14,
396,
63,
354,
61,
275,
511,
63,
1099,
288,
291,
14,
8953,
847,
413,
288,
340,
822,
8,
396,
63,
1099,
14,
9968,
304,
355,
291,
14,
8953,
63,
9968,
847,
413,
288,
340,
511,
63,
1099,
14,
466,
508,
511,
63,
15752,
14,
2944,
8100,
26,
355,
291,
14,
8953,
63,
1556,
9030,
847,
413,
288,
916,
511,
63,
1099,
14,
466,
508,
511,
63,
15752,
14,
8899,
26,
355,
291,
14,
8953,
63,
30182,
847,
413,
267,
340,
511,
63,
374,
63,
14362,
26,
288,
291,
14,
14362,
63,
2219,
14,
525,
8,
396,
63,
1099,
14,
396,
63,
354,
9,
421,
199,
533,
3378,
11347,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
4458,
63,
600,
12,
3089,
4584,
1759,
63,
2604,
29,
403,
12,
2536,
63,
2604,
29,
403,
12,
7269,
63,
2604,
29,
403,
12,
5223,
63,
8435,
63,
2219,
63,
262,
63,
7154,
29,
797,
304,
267,
291,
14,
2224,
63,
600,
275,
4458,
63
] |
[
1898,
334,
35,
9,
7129,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
1898,
334,
35,
9,
7129,
598,
371,
269,
820,
439,
1259,
1629,
73,
334,
12430,
371,
269,
32,
4904,
14,
85,
13,
83,
806,
3046,
14,
10616,
395,
15904,
402,
428,
806,
3046,
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,
646,
2050,
199,
199,
504,
18007,
14,
4209,
63,
2219,
14,
992,
492,
511,
63,
15752,
199,
504,
18007,
14,
4209,
63,
2219,
14,
992,
492,
511,
63,
9968,
421,
199,
63,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
1379,
2540,
6579,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
21851,
12,
1967,
63,
2219,
304,
267,
291,
14,
2923,
275,
1967,
63,
2219,
267,
291,
14,
11266,
275,
291,
14,
2923,
267,
291,
14,
15752,
275,
21851,
267,
291,
14,
2062,
275,
378,
267,
291,
14,
8953,
275,
378,
267,
291,
14,
8953,
63,
9968,
275,
378,
267,
291,
14,
8953,
63,
1556,
9030,
275,
378,
267,
291,
14,
8953,
63,
30182,
275,
378,
267,
291,
14,
2219,
63,
991,
63,
20838,
275,
1052,
267,
291,
14,
2219,
63,
991,
63,
19369,
275,
1052,
267,
291,
14,
2604,
63,
991,
63,
354,
275,
1052,
221,
327,
9672,
402,
511,
536,
370,
314,
2061,
754,
367,
314,
511,
14,
267,
291,
14,
452,
63,
2604,
275,
942,
221,
327,
2900,
2058,
687,
282,
1255,
12,
5893,
4036,
8494,
402,
4036,
511,
14,
267,
291,
14,
8953,
63,
2604,
63,
991,
63,
354,
275,
1052,
267,
291,
14,
9968,
63,
991,
63,
354,
275,
1052,
267,
291,
14,
2923,
63,
9968,
275,
378,
267,
291,
14,
2062,
63,
2759,
83,
275,
378,
267,
367,
17513,
315,
511,
63,
15752,
14,
774,
31323,
14,
16957,
12969,
14,
1459,
837,
288,
291,
14,
2219,
63,
991,
63,
20838,
59,
20838,
61,
275,
663,
342,
267,
367,
20780,
315,
511,
63,
15752,
14,
774,
31323,
14,
11342,
2901,
568,
654,
14,
1459,
837,
288,
291,
14,
2219,
63,
991,
63,
19369,
59,
19369,
61,
275,
21851,
14,
362,
63,
2219,
63,
1045,
63,
19369,
8,
19369,
9,
267,
291,
14,
14362,
63,
2219,
275,
663,
342,
267,
291,
14,
1058,
15692,
275,
756,
339,
347,
1050,
8,
277,
12,
511,
63,
1099,
12,
1420,
12,
511,
63,
374,
63,
14362,
304,
267,
291,
14,
2219,
63,
991,
63,
20838,
59,
396,
63,
1099,
14,
466,
1055,
525,
8,
396,
63,
1099,
14,
396,
63,
354,
9,
267,
291,
14,
2604,
63,
991,
63,
354,
59,
396,
63,
1099,
14,
396,
63,
354,
61,
275,
511,
63,
1099,
267,
340,
511,
63,
1099,
14,
466,
1137,
511,
63,
15752,
14,
13525,
26,
288,
291,
14,
452,
63,
2604,
14,
740,
8,
396,
63,
1099,
9,
267,
291,
14,
11266,
4862,
413,
267,
340,
822,
8,
396,
63,
1099,
14,
9968,
304,
288,
291,
14,
2923,
63,
9968,
847,
413,
288,
291,
14,
9968,
63,
991,
63,
354,
59,
396,
63,
1099,
14,
396,
63,
354,
61,
275,
511,
63,
1099,
14,
9968,
267,
340,
1420,
26,
288,
291,
14,
2062,
847,
413,
288,
340,
511,
63,
1099,
14,
466,
508,
511,
63,
15752,
14,
13525,
26,
355,
291,
14,
2062,
63,
2759,
83,
847,
413,
267,
587,
26,
288,
291,
14,
8953,
63,
2604,
63,
991,
63,
354,
59,
396,
63,
1099,
14,
396,
63,
354,
61,
275,
511,
63,
1099,
288,
291,
14,
8953,
847,
413,
288,
340,
822,
8,
396,
63,
1099,
14,
9968,
304,
355,
291,
14,
8953,
63,
9968,
847,
413,
288,
340,
511,
63,
1099,
14,
466,
508,
511,
63,
15752,
14,
2944,
8100,
26,
355,
291,
14,
8953,
63,
1556,
9030,
847,
413,
288,
916,
511,
63,
1099,
14,
466,
508,
511,
63,
15752,
14,
8899,
26,
355,
291,
14,
8953,
63,
30182,
847,
413,
267,
340,
511,
63,
374,
63,
14362,
26,
288,
291,
14,
14362,
63,
2219,
14,
525,
8,
396,
63,
1099,
14,
396,
63,
354,
9,
421,
199,
533,
3378,
11347,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
4458,
63,
600,
12,
3089,
4584,
1759,
63,
2604,
29,
403,
12,
2536,
63,
2604,
29,
403,
12,
7269,
63,
2604,
29,
403,
12,
5223,
63,
8435,
63,
2219,
63,
262,
63,
7154,
29,
797,
304,
267,
291,
14,
2224,
63,
600,
275,
4458,
63,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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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
] |
rtruxal/metagoofil
|
extractors/metadataMSOfficeXML.py
|
16
|
7833
|
import unzip
import zipfile
import sys
import re
import os
import random
import myparser
class metaInfoMS:
def __init__(self):
self.template =""
self.totalTime =""
self.pages =""
self.words =""
self.characters =""
self.application =""
self.docSecurity =""
self.lines =""
self.paragraphs =""
self.scaleCrop =""
self.company =""
self.linksUpToDate =""
self.charactersWithSpaces =""
self.shareDoc =""
self.hyperlinksChanged =""
self.appVersion =""
self.title =""
self.subject =""
self.creator =""
self.keywords =""
self.lastModifiedBy =""
self.revision =""
self.createdDate =""
self.modifiedDate =""
self.userscomments =""
self.thumbnailPath =""
self.comments= "ok"
self.text=""
def __init__(self,filepath):
self.template =""
self.totalTime =""
self.pages =""
self.words =""
self.characters =""
self.application =""
self.docSecurity =""
self.lines =""
self.paragraphs =""
self.scaleCrop =""
self.company =""
self.linksUpToDate =""
self.charactersWithSpaces =""
self.shareDoc =""
self.hyperlinksChanged =""
self.appVersion =""
self.title =""
self.subject =""
self.creator =""
self.keywords =""
self.lastModifiedBy =""
self.revision =""
self.createdDate =""
self.modifiedDate =""
self.thumbnailPath =""
rnd = str(random.randrange(0, 1001, 3))
zip = zipfile.ZipFile(filepath, 'r')
file('app'+rnd+'.xml', 'w').write(zip.read('docProps/app.xml'))
file('core'+rnd+'.xml', 'w').write(zip.read('docProps/core.xml'))
file('docu'+rnd+'.xml', 'w').write(zip.read('word/document.xml'))
try:
file('comments'+rnd+'.xml', 'w').write(zip.read('word/comments.xml'))
self.comments="ok"
except:
self.comments="error"
thumbnailPath = ""
#try:
#file('thumbnail'+rnd+'.jpeg', 'w').write(zip.read('docProps/thumbnail.jpeg'))
#thumbnailPath = 'thumbnail'+rnd+'.jpeg'
#except:
# pass
zip.close()
# primero algunas estadisticas del soft usado para la edicion y del documento
f = open ('app'+rnd+'.xml','r')
app = f.read()
self.cargaApp(app)
f.close()
if self.comments=="ok":
f = open ('comments'+rnd+'.xml','r')
comm = f.read()
self.cargaComm(comm)
f.close()
# document content
f = open ('docu'+rnd+'.xml','r')
docu = f.read()
self.text = docu
f.close()
# datos respecto a autor, etc
f = open ('core'+rnd+'.xml','r')
core = f.read()
self.cargaCore(core)
self.thumbnailPath = thumbnailPath
f.close()
# borramos todo menos el thumbnail
os.remove('app'+rnd+'.xml')
os.remove('core'+rnd+'.xml')
os.remove('comments'+rnd+'.xml')
os.remove('docu'+rnd+'.xml')
#self.toString()
def toString(self):
print "--- Metadata app ---"
print " template: " + str(self.template)
print " totalTime: " + str(self.totalTime)
print " pages: "+ str(self.pages)
print " words: "+ str(self.words)
print " characters: "+ str(self.characters)
print " application: "+ str(self.application)
print " docSecurity: "+ str(self.docSecurity)
print " lines: "+ str(self.lines)
print " paragraphs: "+ str(self.paragraphs)
print " scaleCrop: " + str(self.scaleCrop)
print " company: "+ str(self.company)
print " linksUpToDate: " + str(self.linksUpToDate)
print " charactersWithSpaces: "+ str(self.charactersWithSpaces)
print " shareDoc:" + str(self.shareDoc)
print " hyperlinksChanged:" + str(self.hyperlinksChanged)
print " appVersion:" + str(self.appVersion)
print "\n --- Metadata core ---"
print " title:" + str(self.title)
print " subject:" + str(self.subject)
print " creator:" + str(self.creator)
print " keywords:" + str(self.keywords)
print " lastModifiedBy:" + str(self.lastModifiedBy)
print " revision:" + str(self.revision)
print " createdDate:" + str(self.createdDate)
print " modifiedDate:" + str(self.modifiedDate)
print "\n thumbnailPath:" + str(self.thumbnailPath)
def cargaComm(self,datos):
try:
p = re.compile('w:author="(.*?)" w')
self.userscomments = p.findall(datos)
except:
pass
def cargaApp(self,datos):
try:
p = re.compile('<Template>(.*)</Template>')
self.template = str (p.findall(datos)[0])
except:
pass
try:
p = re.compile('<TotalTime>(.*)</TotalTime>')
self.totalTime = str (p.findall(datos)[0])
except:
pass
try:
p = re.compile('<Pages>(.*)</Pages>')
self.pages = str (p.findall(datos)[0])
except:
pass
try:
p = re.compile('<Words>(.*)</Words>')
self.words = str (p.findall(datos)[0])
except:
pass
try:
p = re.compile('<Characters>(.*)</Characters>')
self.characters = str (p.findall(datos)[0])
except:
pass
try:
p = re.compile('<Application>(.*)</Application>')
self.application = str (p.findall(datos)[0])
except:
pass
try:
p = re.compile('<DocSecurity>(.*)</DocSecurity>')
self.docSecurity = str (p.findall(datos)[0])
except:
pass
try:
p = re.compile('<Lines>(.*)</Lines>')
self.lines = str (p.findall(datos)[0])
except:
pass
try:
p = re.compile('<Paragraphs>(.*)</Paragraphs>')
self.paragraphs = str (p.findall(datos)[0])
except:
pass
try:
p = re.compile('<ScaleCrop>(.*)</ScaleCrop>')
self.scaleCrop = str (p.findall(datos)[0])
except:
pass
try:
p = re.compile('<Company>(.*)</Company>')
self.company = str (p.findall(datos)[0])
except:
pass
try:
p = re.compile('<LinksUpToDate>(.*)</LinksUpToDate>')
self.linksUpToDate = str (p.findall(datos)[0])
except:
pass
try:
p = re.compile('<CharactersWithSpaces>(.*)</CharactersWithSpaces>')
self.charactersWithSpaces = str (p.findall(datos)[0])
except:
pass
try:
p = re.compile('<SharedDoc>(.*)</SharedDoc>')
self.sharedDoc = str (p.findall(datos)[0])
except:
pass
try:
p = re.compile('<HyperlinksChanged>(.*)</HyperlinksChanged>')
self.hyperlinksChanged = str (p.findall(datos)[0])
except:
pass
try:
p = re.compile('<AppVersion>(.*)</AppVersion>')
self.appVersion = str (p.findall(datos)[0])
except:
pass
def cargaCore(self,datos):
try:
p = re.compile('<dc:title>(.*)</dc:title>')
self.title = str (p.findall(datos)[0])
except:
pass
try:
p = re.compile('<dc:subject>(.*)</dc:subject>')
self.subject = str (p.findall(datos)[0])
except:
pass
try:
p = re.compile('<dc:creator>(.*)</dc:creator>')
self.creator = str (p.findall(datos)[0])
except:
pass
try:
p = re.compile('<cp:keywords>(.*)</cp:keywords>')
self.keywords = str (p.findall(datos)[0])
except:
pass
try:
p = re.compile('<cp:lastModifiedBy>(.*)</cp:lastModifiedBy>')
self.lastModifiedBy = str (p.findall(datos)[0])
except:
pass
try:
p = re.compile('<cp:revision>(.*)</cp:revision>')
self.revision = str (p.findall(datos)[0])
except:
pass
try:
p = re.compile('<dcterms:created xsi:type=".*">(.*)</dcterms:created>')
self.createdDate = str (p.findall(datos)[0])
except:
pass
try:
p = re.compile('<dcterms:modified xsi:type=".*">(.*)</dcterms:modified>')
self.modifiedDate = str (p.findall(datos)[0])
except:
pass
def getData(self):
return "ok"
def getTexts(self):
return "ok"
def getRaw(self):
raw = "Not implemented yet"
return raw
def getUsers(self):
res=[]
temporal=[]
res.append(self.creator)
res.append(self.lastModifiedBy)
if self.comments == "ok":
res.extend(self.userscomments)
else:
pass
for x in res:
if temporal.count(x) ==0:
temporal.append(x)
else:
pass
return temporal
def getEmails(self):
res=myparser.parser(self.text)
return res.emails()
def getPaths(self):
res=[]
#res.append(self.revision)
return res
def getSoftware(self):
res=[]
res.append(self.application)
return res
|
gpl-2.0
|
[
646,
29379,
199,
646,
10392,
199,
646,
984,
199,
646,
295,
199,
646,
747,
199,
646,
2196,
199,
646,
3002,
2087,
199,
199,
533,
3404,
2354,
3053,
26,
199,
198,
318,
636,
826,
721,
277,
304,
507,
198,
277,
14,
1160,
275,
341,
507,
198,
277,
14,
2923,
1366,
275,
341,
507,
198,
277,
14,
5856,
275,
341,
507,
198,
277,
14,
3148,
275,
341,
507,
198,
277,
14,
16516,
275,
341,
507,
198,
277,
14,
3578,
275,
341,
507,
198,
277,
14,
1301,
7676,
275,
341,
507,
198,
277,
14,
1278,
275,
341,
507,
198,
277,
14,
12400,
83,
275,
341,
507,
198,
277,
14,
3467,
35,
2675,
275,
341,
507,
198,
277,
14,
4627,
275,
341,
507,
198,
277,
14,
4614,
1721,
1378,
2506,
275,
341,
507,
198,
277,
14,
16516,
3007,
23415,
275,
341,
507,
198,
277,
14,
6251,
3768,
275,
341,
507,
198,
277,
14,
9547,
4614,
6970,
275,
341,
507,
198,
277,
14,
571,
3353,
275,
341,
198,
507,
198,
277,
14,
1213,
275,
341,
507,
198,
277,
14,
5875,
275,
341,
507,
198,
277,
14,
9986,
275,
341,
507,
198,
277,
14,
7511,
275,
341,
507,
198,
277,
14,
2019,
11911,
2175,
275,
341,
507,
198,
277,
14,
5792,
275,
341,
507,
198,
277,
14,
3966,
2506,
275,
341,
507,
198,
277,
14,
5540,
2506,
275,
341,
9622,
507,
198,
277,
14,
3707,
6223,
275,
341,
507,
198,
277,
14,
8311,
2042,
275,
341,
507,
198,
277,
14,
6223,
29,
298,
745,
2,
507,
198,
277,
14,
505,
9287,
18118,
198,
318,
636,
826,
721,
277,
12,
7218,
304,
507,
198,
277,
14,
1160,
275,
341,
507,
198,
277,
14,
2923,
1366,
275,
341,
507,
198,
277,
14,
5856,
275,
341,
507,
198,
277,
14,
3148,
275,
341,
507,
198,
277,
14,
16516,
275,
341,
507,
198,
277,
14,
3578,
275,
341,
507,
198,
277,
14,
1301,
7676,
275,
341,
507,
198,
277,
14,
1278,
275,
341,
507,
198,
277,
14,
12400,
83,
275,
341,
507,
198,
277,
14,
3467,
35,
2675,
275,
341,
507,
198,
277,
14,
4627,
275,
341,
507,
198,
277,
14,
4614,
1721,
1378,
2506,
275,
341,
507,
198,
277,
14,
16516,
3007,
23415,
275,
341,
507,
198,
277,
14,
6251,
3768,
275,
341,
507,
198,
277,
14,
9547,
4614,
6970,
275,
341,
507,
198,
277,
14,
571,
3353,
275,
341,
198,
507,
198,
277,
14,
1213,
275,
341,
507,
198,
277,
14,
5875,
275,
341,
507,
198,
277,
14,
9986,
275,
341,
507,
198,
277,
14,
7511,
275,
341,
507,
198,
277,
14,
2019,
11911,
2175,
275,
341,
507,
198,
277,
14,
5792,
275,
341,
507,
198,
277,
14,
3966,
2506,
275,
341,
507,
198,
277,
14,
5540,
2506,
275,
341,
9622,
507,
198,
277,
14,
8311,
2042,
275,
341,
198,
507,
198,
30006,
221,
275,
620,
8,
2355,
14,
20539,
8,
16,
12,
2948,
17,
12,
650,
430,
507,
198,
3065,
275,
10392,
14,
15016,
8,
7218,
12,
283,
82,
358,
507,
198,
493,
360,
571,
6828,
30006,
18098,
1652,
297,
283,
87,
1959,
952,
8,
3065,
14,
739,
360,
1301,
24188,
15,
571,
14,
1652,
1333,
507,
198,
493,
360,
1018,
6828,
30006,
18098,
1652,
297,
283,
87,
1959,
952,
8,
3065,
14,
739,
360,
1301,
24188,
15,
1018,
14,
1652,
1333,
507,
198,
493,
360,
1301,
85,
6828,
30006,
18098,
1652,
297,
283,
87,
1959,
952,
8,
3065,
14,
739,
360,
1027,
15,
3554,
14,
1652,
1333,
507,
198,
893,
26,
686,
198,
493,
360,
6223,
6828,
30006,
18098,
1652,
297,
283,
87,
1959,
952,
8,
3065,
14,
739,
360,
1027,
15,
6223,
14,
1652,
1333,
686,
198,
277,
14,
6223,
628,
745,
2,
507,
198,
2590,
26,
686,
198,
277,
14,
6223,
628,
705,
2,
507,
198,
8311,
2042,
275,
3087,
507,
198,
3,
893,
26,
686,
198,
3,
493,
360,
8311,
6828,
30006,
18098,
14230,
297,
283,
87,
1959,
952,
8,
3065,
14,
739,
360,
1301,
24188,
15,
8311,
14,
14230,
1333,
29294,
198,
3,
8311,
2042,
275,
283,
8311,
6828,
30006,
18098,
14230,
7,
507,
198,
3,
2590,
26,
507,
198,
3,
198,
1529,
1585,
507,
198,
3065,
14,
1600,
342,
507,
198,
3,
21619,
293,
15760,
324,
305,
325,
1207,
2686,
530,
305,
2150,
11620,
2739,
5129,
12665,
1127,
7860,
9718,
612,
2150,
2213,
79,
507,
198,
70,
275,
1551,
661,
571,
6828,
30006,
18098,
1652,
1673,
82,
358,
507,
198,
571,
275,
289,
14,
739,
342,
507,
198,
277,
14,
67,
1273,
65,
2640,
8,
571,
9,
507,
198,
70,
14,
1600,
342,
507,
198,
692,
291,
14,
6223,
11800,
745,
582,
686,
198,
70,
275,
1551,
661,
6223,
6828,
30006,
18098,
1652,
1673,
82,
358,
686,
198,
1404,
275,
289,
14,
739,
342,
686,
198,
277,
14,
67,
1273,
65,
5150,
8,
1404,
9,
686,
198,
70,
14,
1600,
342,
9068,
198,
3,
2213,
1564,
507,
198,
70,
275,
1551,
661,
1301,
85,
6828,
30006,
18098,
1652,
1673,
82,
358,
507,
198,
1301,
85,
275,
289,
14,
739,
342,
507,
198,
277,
14,
505,
275,
1382,
85,
507,
198,
70,
14,
1600,
342,
507,
198,
3,
6394,
736,
14021,
79,
282,
282,
4139,
12,
5423,
2742,
198,
70,
275,
1551,
661,
1018,
6828,
30006,
18098,
1652,
1673,
82,
358,
507,
198,
1018,
275,
289,
14,
739,
342,
507,
198,
277,
14,
67,
1273,
65,
5402,
8,
1018,
9,
507,
198,
277,
14,
8311,
2042,
275,
10062,
2042,
507,
198,
70,
14,
1600,
342,
2742,
198,
3,
330,
269,
345,
16908,
11386,
562,
12712,
579,
10062,
9068,
198,
736,
14,
2168,
360,
571,
6828,
30006,
18098,
1652,
358,
507,
198,
736,
14,
2168,
360,
1018,
6828,
30006,
18098,
1652,
358,
198,
507,
198,
736,
14,
2168,
360,
6223,
6828,
30006,
18098,
1652,
358,
198,
507,
198,
736,
14,
2168,
360,
1301,
85,
6828,
30006,
18098,
1652,
358,
507,
198,
3,
277,
14,
16695,
342,
18118,
198,
318,
370,
1558,
8,
277,
304,
507,
198,
1361,
298,
2595,
16160,
1145,
10894,
2,
507,
198,
1361,
298,
1978,
26,
298,
435,
620,
8,
277,
14,
1160,
9,
507,
198,
1361,
298,
3141,
1366,
26,
298,
435,
620,
8,
277,
14,
2923,
1366,
9,
507,
198,
1361,
298
] |
[
29379,
199,
646,
10392,
199,
646,
984,
199,
646,
295,
199,
646,
747,
199,
646,
2196,
199,
646,
3002,
2087,
199,
199,
533,
3404,
2354,
3053,
26,
199,
198,
318,
636,
826,
721,
277,
304,
507,
198,
277,
14,
1160,
275,
341,
507,
198,
277,
14,
2923,
1366,
275,
341,
507,
198,
277,
14,
5856,
275,
341,
507,
198,
277,
14,
3148,
275,
341,
507,
198,
277,
14,
16516,
275,
341,
507,
198,
277,
14,
3578,
275,
341,
507,
198,
277,
14,
1301,
7676,
275,
341,
507,
198,
277,
14,
1278,
275,
341,
507,
198,
277,
14,
12400,
83,
275,
341,
507,
198,
277,
14,
3467,
35,
2675,
275,
341,
507,
198,
277,
14,
4627,
275,
341,
507,
198,
277,
14,
4614,
1721,
1378,
2506,
275,
341,
507,
198,
277,
14,
16516,
3007,
23415,
275,
341,
507,
198,
277,
14,
6251,
3768,
275,
341,
507,
198,
277,
14,
9547,
4614,
6970,
275,
341,
507,
198,
277,
14,
571,
3353,
275,
341,
198,
507,
198,
277,
14,
1213,
275,
341,
507,
198,
277,
14,
5875,
275,
341,
507,
198,
277,
14,
9986,
275,
341,
507,
198,
277,
14,
7511,
275,
341,
507,
198,
277,
14,
2019,
11911,
2175,
275,
341,
507,
198,
277,
14,
5792,
275,
341,
507,
198,
277,
14,
3966,
2506,
275,
341,
507,
198,
277,
14,
5540,
2506,
275,
341,
9622,
507,
198,
277,
14,
3707,
6223,
275,
341,
507,
198,
277,
14,
8311,
2042,
275,
341,
507,
198,
277,
14,
6223,
29,
298,
745,
2,
507,
198,
277,
14,
505,
9287,
18118,
198,
318,
636,
826,
721,
277,
12,
7218,
304,
507,
198,
277,
14,
1160,
275,
341,
507,
198,
277,
14,
2923,
1366,
275,
341,
507,
198,
277,
14,
5856,
275,
341,
507,
198,
277,
14,
3148,
275,
341,
507,
198,
277,
14,
16516,
275,
341,
507,
198,
277,
14,
3578,
275,
341,
507,
198,
277,
14,
1301,
7676,
275,
341,
507,
198,
277,
14,
1278,
275,
341,
507,
198,
277,
14,
12400,
83,
275,
341,
507,
198,
277,
14,
3467,
35,
2675,
275,
341,
507,
198,
277,
14,
4627,
275,
341,
507,
198,
277,
14,
4614,
1721,
1378,
2506,
275,
341,
507,
198,
277,
14,
16516,
3007,
23415,
275,
341,
507,
198,
277,
14,
6251,
3768,
275,
341,
507,
198,
277,
14,
9547,
4614,
6970,
275,
341,
507,
198,
277,
14,
571,
3353,
275,
341,
198,
507,
198,
277,
14,
1213,
275,
341,
507,
198,
277,
14,
5875,
275,
341,
507,
198,
277,
14,
9986,
275,
341,
507,
198,
277,
14,
7511,
275,
341,
507,
198,
277,
14,
2019,
11911,
2175,
275,
341,
507,
198,
277,
14,
5792,
275,
341,
507,
198,
277,
14,
3966,
2506,
275,
341,
507,
198,
277,
14,
5540,
2506,
275,
341,
9622,
507,
198,
277,
14,
8311,
2042,
275,
341,
198,
507,
198,
30006,
221,
275,
620,
8,
2355,
14,
20539,
8,
16,
12,
2948,
17,
12,
650,
430,
507,
198,
3065,
275,
10392,
14,
15016,
8,
7218,
12,
283,
82,
358,
507,
198,
493,
360,
571,
6828,
30006,
18098,
1652,
297,
283,
87,
1959,
952,
8,
3065,
14,
739,
360,
1301,
24188,
15,
571,
14,
1652,
1333,
507,
198,
493,
360,
1018,
6828,
30006,
18098,
1652,
297,
283,
87,
1959,
952,
8,
3065,
14,
739,
360,
1301,
24188,
15,
1018,
14,
1652,
1333,
507,
198,
493,
360,
1301,
85,
6828,
30006,
18098,
1652,
297,
283,
87,
1959,
952,
8,
3065,
14,
739,
360,
1027,
15,
3554,
14,
1652,
1333,
507,
198,
893,
26,
686,
198,
493,
360,
6223,
6828,
30006,
18098,
1652,
297,
283,
87,
1959,
952,
8,
3065,
14,
739,
360,
1027,
15,
6223,
14,
1652,
1333,
686,
198,
277,
14,
6223,
628,
745,
2,
507,
198,
2590,
26,
686,
198,
277,
14,
6223,
628,
705,
2,
507,
198,
8311,
2042,
275,
3087,
507,
198,
3,
893,
26,
686,
198,
3,
493,
360,
8311,
6828,
30006,
18098,
14230,
297,
283,
87,
1959,
952,
8,
3065,
14,
739,
360,
1301,
24188,
15,
8311,
14,
14230,
1333,
29294,
198,
3,
8311,
2042,
275,
283,
8311,
6828,
30006,
18098,
14230,
7,
507,
198,
3,
2590,
26,
507,
198,
3,
198,
1529,
1585,
507,
198,
3065,
14,
1600,
342,
507,
198,
3,
21619,
293,
15760,
324,
305,
325,
1207,
2686,
530,
305,
2150,
11620,
2739,
5129,
12665,
1127,
7860,
9718,
612,
2150,
2213,
79,
507,
198,
70,
275,
1551,
661,
571,
6828,
30006,
18098,
1652,
1673,
82,
358,
507,
198,
571,
275,
289,
14,
739,
342,
507,
198,
277,
14,
67,
1273,
65,
2640,
8,
571,
9,
507,
198,
70,
14,
1600,
342,
507,
198,
692,
291,
14,
6223,
11800,
745,
582,
686,
198,
70,
275,
1551,
661,
6223,
6828,
30006,
18098,
1652,
1673,
82,
358,
686,
198,
1404,
275,
289,
14,
739,
342,
686,
198,
277,
14,
67,
1273,
65,
5150,
8,
1404,
9,
686,
198,
70,
14,
1600,
342,
9068,
198,
3,
2213,
1564,
507,
198,
70,
275,
1551,
661,
1301,
85,
6828,
30006,
18098,
1652,
1673,
82,
358,
507,
198,
1301,
85,
275,
289,
14,
739,
342,
507,
198,
277,
14,
505,
275,
1382,
85,
507,
198,
70,
14,
1600,
342,
507,
198,
3,
6394,
736,
14021,
79,
282,
282,
4139,
12,
5423,
2742,
198,
70,
275,
1551,
661,
1018,
6828,
30006,
18098,
1652,
1673,
82,
358,
507,
198,
1018,
275,
289,
14,
739,
342,
507,
198,
277,
14,
67,
1273,
65,
5402,
8,
1018,
9,
507,
198,
277,
14,
8311,
2042,
275,
10062,
2042,
507,
198,
70,
14,
1600,
342,
2742,
198,
3,
330,
269,
345,
16908,
11386,
562,
12712,
579,
10062,
9068,
198,
736,
14,
2168,
360,
571,
6828,
30006,
18098,
1652,
358,
507,
198,
736,
14,
2168,
360,
1018,
6828,
30006,
18098,
1652,
358,
198,
507,
198,
736,
14,
2168,
360,
6223,
6828,
30006,
18098,
1652,
358,
198,
507,
198,
736,
14,
2168,
360,
1301,
85,
6828,
30006,
18098,
1652,
358,
507,
198,
3,
277,
14,
16695,
342,
18118,
198,
318,
370,
1558,
8,
277,
304,
507,
198,
1361,
298,
2595,
16160,
1145,
10894,
2,
507,
198,
1361,
298,
1978,
26,
298,
435,
620,
8,
277,
14,
1160,
9,
507,
198,
1361,
298,
3141,
1366,
26,
298,
435,
620,
8,
277,
14,
2923,
1366,
9,
507,
198,
1361,
298,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ogrisel/scipy
|
scipy/linalg/benchmarks/bench_decom.py
|
18
|
2472
|
""" Benchmark functions for linalg.decomp module
"""
from __future__ import division, print_function, absolute_import
import sys
from numpy import linalg as nl
from scipy import linalg as sl
from numpy.testing import measure, rand, assert_
def random(size):
return rand(*size)
def bench_eigvals():
numpy_eigvals = nl.eigvals
scipy_eigvals = sl.eigvals
print()
print(' Finding matrix eigenvalues')
print(' ==================================')
print(' | contiguous | non-contiguous ')
print('----------------------------------------------')
print(' size | scipy | numpy | scipy | numpy ')
for size,repeat in [(20,150),(100,7),(200,2)]:
repeat *= 1
print('%5s' % size, end=' ')
sys.stdout.flush()
a = random([size,size])
print('| %6.2f ' % measure('scipy_eigvals(a)',repeat), end=' ')
sys.stdout.flush()
print('| %6.2f ' % measure('numpy_eigvals(a)',repeat), end=' ')
sys.stdout.flush()
a = a[-1::-1,-1::-1] # turn into a non-contiguous array
assert_(not a.flags['CONTIGUOUS'])
print('| %6.2f ' % measure('scipy_eigvals(a)',repeat), end=' ')
sys.stdout.flush()
print('| %6.2f ' % measure('numpy_eigvals(a)',repeat), end=' ')
sys.stdout.flush()
print(' (secs for %s calls)' % (repeat))
def bench_svd():
numpy_svd = nl.svd
scipy_svd = sl.svd
print()
print(' Finding the SVD decomposition')
print(' ==================================')
print(' | contiguous | non-contiguous ')
print('----------------------------------------------')
print(' size | scipy | numpy | scipy | numpy ')
for size,repeat in [(20,150),(100,7),(200,2)]:
repeat *= 1
print('%5s' % size, end=' ')
sys.stdout.flush()
a = random([size,size])
print('| %6.2f ' % measure('scipy_svd(a)',repeat), end=' ')
sys.stdout.flush()
print('| %6.2f ' % measure('numpy_svd(a)',repeat), end=' ')
sys.stdout.flush()
a = a[-1::-1,-1::-1] # turn into a non-contiguous array
assert_(not a.flags['CONTIGUOUS'])
print('| %6.2f ' % measure('scipy_svd(a)',repeat), end=' ')
sys.stdout.flush()
print('| %6.2f ' % measure('numpy_svd(a)',repeat), end=' ')
sys.stdout.flush()
print(' (secs for %s calls)' % (repeat))
|
bsd-3-clause
|
[
624,
27067,
3423,
367,
16727,
14,
271,
863,
859,
199,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
4629,
12,
870,
63,
1593,
12,
3679,
63,
646,
199,
199,
646,
984,
199,
199,
504,
2680,
492,
16727,
465,
12992,
199,
504,
7026,
492,
16727,
465,
5340,
199,
504,
2680,
14,
4776,
492,
9775,
12,
10261,
12,
702,
63,
421,
199,
318,
2196,
8,
890,
304,
272,
372,
10261,
2031,
890,
9,
421,
199,
318,
26456,
63,
22129,
3643,
837,
272,
2680,
63,
22129,
3643,
275,
12992,
14,
22129,
3643,
272,
7026,
63,
22129,
3643,
275,
5340,
14,
22129,
3643,
272,
870,
342,
272,
870,
360,
3698,
6668,
316,
3634,
22953,
358,
272,
870,
360,
420,
19469,
14619,
272,
870,
360,
420,
1204,
259,
26611,
258,
1204,
257,
2222,
13,
16583,
5320,
272,
870,
360,
1444,
10965,
358,
272,
870,
360,
1568,
1204,
221,
7026,
221,
1204,
2680,
257,
1204,
221,
7026,
221,
1204,
2680,
5320,
339,
367,
1568,
12,
8755,
315,
3842,
1165,
12,
8251,
11865,
1960,
12,
23,
11865,
1840,
12,
18,
19532,
267,
11982,
9000,
413,
267,
870,
3508,
21,
83,
7,
450,
1568,
12,
1284,
534,
5320,
267,
984,
14,
2703,
14,
4939,
342,
398,
282,
275,
2196,
779,
890,
12,
890,
566,
398,
870,
20137,
450,
22,
14,
18,
70,
283,
450,
9775,
360,
14248,
63,
22129,
3643,
8,
65,
3196,
8755,
395,
1284,
534,
5320,
267,
984,
14,
2703,
14,
4939,
342,
398,
870,
20137,
450,
22,
14,
18,
70,
283,
450,
9775,
360,
4714,
63,
22129,
3643,
8,
65,
3196,
8755,
395,
1284,
534,
5320,
267,
984,
14,
2703,
14,
4939,
342,
398,
282,
275,
282,
1988,
17,
21123,
17,
3057,
17,
21123,
17,
61,
221,
327,
7485,
1901,
282,
2222,
13,
16583,
1625,
267,
702,
2531,
1397,
282,
14,
2469,
459,
5801,
1277,
32504,
1105,
398,
870,
20137,
450,
22,
14,
18,
70,
283,
450,
9775,
360,
14248,
63,
22129,
3643,
8,
65,
3196,
8755,
395,
1284,
534,
5320,
267,
984,
14,
2703,
14,
4939,
342,
398,
870,
20137,
450,
22,
14,
18,
70,
283,
450,
9775,
360,
4714,
63,
22129,
3643,
8,
65,
3196,
8755,
395,
1284,
534,
5320,
267,
984,
14,
2703,
14,
4939,
342,
398,
870,
360,
257,
334,
4855,
367,
450,
83,
4882,
3171,
450,
334,
8755,
430,
421,
199,
318,
26456,
63,
18675,
837,
272,
2680,
63,
18675,
275,
12992,
14,
18675,
272,
7026,
63,
18675,
275,
5340,
14,
18675,
272,
870,
342,
272,
870,
360,
3698,
6668,
316,
314,
14056,
36,
22706,
358,
272,
870,
360,
420,
19469,
14619,
272,
870,
360,
420,
1204,
259,
26611,
258,
1204,
257,
2222,
13,
16583,
5320,
272,
870,
360,
1444,
10965,
358,
272,
870,
360,
1568,
1204,
221,
7026,
221,
1204,
2680,
257,
1204,
221,
7026,
221,
1204,
2680,
5320,
339,
367,
1568,
12,
8755,
315,
3842,
1165,
12,
8251,
11865,
1960,
12,
23,
11865,
1840,
12,
18,
19532,
267,
11982,
9000,
413,
267,
870,
3508,
21,
83,
7,
450,
1568,
12,
1284,
534,
5320,
267,
984,
14,
2703,
14,
4939,
342,
398,
282,
275,
2196,
779,
890,
12,
890,
566,
398,
870,
20137,
450,
22,
14,
18,
70,
283,
450,
9775,
360,
14248,
63,
18675,
8,
65,
3196,
8755,
395,
1284,
534,
5320,
267,
984,
14,
2703,
14,
4939,
342,
398,
870,
20137,
450,
22,
14,
18,
70,
283,
450,
9775,
360,
4714,
63,
18675,
8,
65,
3196,
8755,
395,
1284,
534,
5320,
267,
984,
14,
2703,
14,
4939,
342,
398,
282,
275,
282,
1988,
17,
21123,
17,
3057,
17,
21123,
17,
61,
221,
327,
7485,
1901,
282,
2222,
13,
16583,
1625,
267,
702,
2531,
1397,
282,
14,
2469,
459,
5801,
1277,
32504,
1105,
398,
870,
20137,
450,
22,
14,
18,
70,
283,
450,
9775,
360,
14248,
63,
18675,
8,
65,
3196,
8755,
395,
1284,
534,
5320,
267,
984,
14,
2703,
14,
4939,
342,
398,
870,
20137,
450,
22,
14,
18,
70,
283,
450,
9775,
360,
4714,
63,
18675,
8,
65,
3196,
8755,
395,
1284,
534,
5320,
267,
984,
14,
2703,
14,
4939,
342,
398,
870,
360,
257,
334,
4855,
367,
450,
83,
4882,
3171,
450,
334,
8755,
430,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
27067,
3423,
367,
16727,
14,
271,
863,
859,
199,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
4629,
12,
870,
63,
1593,
12,
3679,
63,
646,
199,
199,
646,
984,
199,
199,
504,
2680,
492,
16727,
465,
12992,
199,
504,
7026,
492,
16727,
465,
5340,
199,
504,
2680,
14,
4776,
492,
9775,
12,
10261,
12,
702,
63,
421,
199,
318,
2196,
8,
890,
304,
272,
372,
10261,
2031,
890,
9,
421,
199,
318,
26456,
63,
22129,
3643,
837,
272,
2680,
63,
22129,
3643,
275,
12992,
14,
22129,
3643,
272,
7026,
63,
22129,
3643,
275,
5340,
14,
22129,
3643,
272,
870,
342,
272,
870,
360,
3698,
6668,
316,
3634,
22953,
358,
272,
870,
360,
420,
19469,
14619,
272,
870,
360,
420,
1204,
259,
26611,
258,
1204,
257,
2222,
13,
16583,
5320,
272,
870,
360,
1444,
10965,
358,
272,
870,
360,
1568,
1204,
221,
7026,
221,
1204,
2680,
257,
1204,
221,
7026,
221,
1204,
2680,
5320,
339,
367,
1568,
12,
8755,
315,
3842,
1165,
12,
8251,
11865,
1960,
12,
23,
11865,
1840,
12,
18,
19532,
267,
11982,
9000,
413,
267,
870,
3508,
21,
83,
7,
450,
1568,
12,
1284,
534,
5320,
267,
984,
14,
2703,
14,
4939,
342,
398,
282,
275,
2196,
779,
890,
12,
890,
566,
398,
870,
20137,
450,
22,
14,
18,
70,
283,
450,
9775,
360,
14248,
63,
22129,
3643,
8,
65,
3196,
8755,
395,
1284,
534,
5320,
267,
984,
14,
2703,
14,
4939,
342,
398,
870,
20137,
450,
22,
14,
18,
70,
283,
450,
9775,
360,
4714,
63,
22129,
3643,
8,
65,
3196,
8755,
395,
1284,
534,
5320,
267,
984,
14,
2703,
14,
4939,
342,
398,
282,
275,
282,
1988,
17,
21123,
17,
3057,
17,
21123,
17,
61,
221,
327,
7485,
1901,
282,
2222,
13,
16583,
1625,
267,
702,
2531,
1397,
282,
14,
2469,
459,
5801,
1277,
32504,
1105,
398,
870,
20137,
450,
22,
14,
18,
70,
283,
450,
9775,
360,
14248,
63,
22129,
3643,
8,
65,
3196,
8755,
395,
1284,
534,
5320,
267,
984,
14,
2703,
14,
4939,
342,
398,
870,
20137,
450,
22,
14,
18,
70,
283,
450,
9775,
360,
4714,
63,
22129,
3643,
8,
65,
3196,
8755,
395,
1284,
534,
5320,
267,
984,
14,
2703,
14,
4939,
342,
398,
870,
360,
257,
334,
4855,
367,
450,
83,
4882,
3171,
450,
334,
8755,
430,
421,
199,
318,
26456,
63,
18675,
837,
272,
2680,
63,
18675,
275,
12992,
14,
18675,
272,
7026,
63,
18675,
275,
5340,
14,
18675,
272,
870,
342,
272,
870,
360,
3698,
6668,
316,
314,
14056,
36,
22706,
358,
272,
870,
360,
420,
19469,
14619,
272,
870,
360,
420,
1204,
259,
26611,
258,
1204,
257,
2222,
13,
16583,
5320,
272,
870,
360,
1444,
10965,
358,
272,
870,
360,
1568,
1204,
221,
7026,
221,
1204,
2680,
257,
1204,
221,
7026,
221,
1204,
2680,
5320,
339,
367,
1568,
12,
8755,
315,
3842,
1165,
12,
8251,
11865,
1960,
12,
23,
11865,
1840,
12,
18,
19532,
267,
11982,
9000,
413,
267,
870,
3508,
21,
83,
7,
450,
1568,
12,
1284,
534,
5320,
267,
984,
14,
2703,
14,
4939,
342,
398,
282,
275,
2196,
779,
890,
12,
890,
566,
398,
870,
20137,
450,
22,
14,
18,
70,
283,
450,
9775,
360,
14248,
63,
18675,
8,
65,
3196,
8755,
395,
1284,
534,
5320,
267,
984,
14,
2703,
14,
4939,
342,
398,
870,
20137,
450,
22,
14,
18,
70,
283,
450,
9775,
360,
4714,
63,
18675,
8,
65,
3196,
8755,
395,
1284,
534,
5320,
267,
984,
14,
2703,
14,
4939,
342,
398,
282,
275,
282,
1988,
17,
21123,
17,
3057,
17,
21123,
17,
61,
221,
327,
7485,
1901,
282,
2222,
13,
16583,
1625,
267,
702,
2531,
1397,
282,
14,
2469,
459,
5801,
1277,
32504,
1105,
398,
870,
20137,
450,
22,
14,
18,
70,
283,
450,
9775,
360,
14248,
63,
18675,
8,
65,
3196,
8755,
395,
1284,
534,
5320,
267,
984,
14,
2703,
14,
4939,
342,
398,
870,
20137,
450,
22,
14,
18,
70,
283,
450,
9775,
360,
4714,
63,
18675,
8,
65,
3196,
8755,
395,
1284,
534,
5320,
267,
984,
14,
2703,
14,
4939,
342,
398,
870,
360,
257,
334,
4855,
367,
450,
83,
4882,
3171,
450,
334,
8755,
430,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Nick-Hall/gramps
|
gramps/gui/filters/sidebar/_eventsidebarfilter.py
|
10
|
7167
|
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2002-2006 Donald N. Allingham
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
#-------------------------------------------------------------------------
#
# Python modules
#
#-------------------------------------------------------------------------
from gramps.gen.const import GRAMPS_LOCALE as glocale
_ = glocale.translation.gettext
#-------------------------------------------------------------------------
#
# gtk
#
#-------------------------------------------------------------------------
from gi.repository import Gtk
#-------------------------------------------------------------------------
#
# Gramps modules
#
#-------------------------------------------------------------------------
from ... import widgets
from gramps.gen.lib import Event, EventType
from .. import build_filter_model
from . import SidebarFilter
from gramps.gen.filters import GenericFilterFactory, rules
from gramps.gen.filters.rules.event import (RegExpIdOf, HasNoteRegexp,
MatchesFilter, HasEvent, HasTag)
GenericEventFilter = GenericFilterFactory('Event')
#-------------------------------------------------------------------------
#
# EventSidebarFilter class
#
#-------------------------------------------------------------------------
class EventSidebarFilter(SidebarFilter):
def __init__(self, dbstate, uistate, clicked):
self.clicked_func = clicked
self.filter_id = widgets.BasicEntry()
self.filter_desc = widgets.BasicEntry()
self.filter_event = Event()
self.filter_event.set_type((EventType.CUSTOM, ''))
self.etype = Gtk.ComboBox(has_entry=True)
if dbstate.is_open():
self.custom_types = dbstate.db.get_event_types()
else:
self.custom_types = []
self.event_menu = widgets.MonitoredDataType(
self.etype,
self.filter_event.set_type,
self.filter_event.get_type,
custom_values=self.custom_types)
self.filter_mainparts = widgets.BasicEntry()
self.filter_date = widgets.DateEntry(uistate, [])
self.filter_place = widgets.BasicEntry()
self.filter_note = widgets.BasicEntry()
self.filter_regex = Gtk.CheckButton(label=_('Use regular expressions'))
self.tag = Gtk.ComboBox()
self.generic = Gtk.ComboBox()
SidebarFilter.__init__(self, dbstate, uistate, "Event")
def create_widget(self):
cell = Gtk.CellRendererText()
cell.set_property('width', self._FILTER_WIDTH)
cell.set_property('ellipsize', self._FILTER_ELLIPSIZE)
self.generic.pack_start(cell, True)
self.generic.add_attribute(cell, 'text', 0)
self.on_filters_changed('Event')
cell = Gtk.CellRendererText()
cell.set_property('width', self._FILTER_WIDTH)
cell.set_property('ellipsize', self._FILTER_ELLIPSIZE)
self.tag.pack_start(cell, True)
self.tag.add_attribute(cell, 'text', 0)
self.etype.get_child().set_width_chars(5)
self.add_text_entry(_('ID'), self.filter_id)
self.add_text_entry(_('Description'), self.filter_desc)
self.add_entry(_('Type'), self.etype)
self.add_text_entry(_('Participants'), self.filter_mainparts)
self.add_text_entry(_('Date'), self.filter_date)
self.add_text_entry(_('Place'), self.filter_place)
self.add_text_entry(_('Note'), self.filter_note)
self.add_entry(_('Tag'), self.tag)
self.add_filter_entry(_('Custom filter'), self.generic)
self.add_regex_entry(self.filter_regex)
def clear(self, obj):
self.filter_id.set_text('')
self.filter_desc.set_text('')
self.filter_mainparts.set_text('')
self.filter_date.set_text('')
self.filter_place.set_text('')
self.filter_note.set_text('')
self.etype.get_child().set_text('')
self.tag.set_active(0)
self.generic.set_active(0)
def get_filter(self):
gid = str(self.filter_id.get_text()).strip()
desc = str(self.filter_desc.get_text()).strip()
mainparts = str(self.filter_mainparts.get_text()).strip()
date = str(self.filter_date.get_text()).strip()
place = str(self.filter_place.get_text()).strip()
note = str(self.filter_note.get_text()).strip()
regex = self.filter_regex.get_active()
tag = self.tag.get_active() > 0
generic = self.generic.get_active() > 0
etype = self.filter_event.get_type().xml_str()
empty = not (gid or desc or mainparts or date or place or note
or etype or regex or tag or generic)
if empty:
generic_filter = None
else:
generic_filter = GenericEventFilter()
if gid:
rule = RegExpIdOf([gid], use_regex=regex)
generic_filter.add_rule(rule)
rule = HasEvent([etype, date, place, desc, mainparts],
use_regex=regex)
generic_filter.add_rule(rule)
if note:
rule = HasNoteRegexp([note], use_regex=regex)
generic_filter.add_rule(rule)
# check the Tag
if tag:
model = self.tag.get_model()
node = self.tag.get_active_iter()
attr = model.get_value(node, 0)
rule = HasTag([attr])
generic_filter.add_rule(rule)
if self.generic.get_active() != 0:
model = self.generic.get_model()
node = self.generic.get_active_iter()
obj = str(model.get_value(node, 0))
rule = MatchesFilter([obj])
generic_filter.add_rule(rule)
return generic_filter
def on_filters_changed(self, name_space):
if name_space == 'Event':
all_filter = GenericEventFilter()
all_filter.set_name(_("None"))
all_filter.add_rule(rules.event.AllEvents([]))
self.generic.set_model(build_filter_model('Event', [all_filter]))
self.generic.set_active(0)
def on_tags_changed(self, tag_list):
"""
Update the list of tags in the tag filter.
"""
model = Gtk.ListStore(str)
model.append(('',))
for tag_name in tag_list:
model.append((tag_name,))
self.tag.set_model(model)
self.tag.set_active(0)
|
gpl-2.0
|
[
3,
199,
3,
10268,
13408,
446,
282,
598,
15263,
19616,
39,
2826,
3635,
4079,
15599,
2548,
89,
2240,
199,
3,
199,
3,
1898,
334,
35,
9,
14790,
13,
7968,
221,
7529,
27075,
653,
14,
2900,
316,
10670,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
11315,
13,
10067,
8217,
14,
199,
3,
199,
199,
25812,
199,
3,
199,
3,
2018,
4621,
199,
3,
199,
25812,
199,
504,
1999,
13408,
14,
2268,
14,
1297,
492,
21772,
1156,
5067,
63,
20828,
465,
486,
5508,
199,
63,
275,
486,
5508,
14,
6893,
14,
5152,
199,
199,
25812,
199,
3,
199,
3,
8116,
199,
3,
199,
25812,
199,
504,
18895,
14,
8421,
492,
11424,
199,
199,
25812,
199,
3,
199,
3,
10268,
13408,
4621,
199,
3,
199,
25812,
199,
504,
2263,
492,
11114,
199,
504,
1999,
13408,
14,
2268,
14,
773,
492,
6763,
12,
6763,
804,
199,
504,
2508,
492,
1900,
63,
1541,
63,
1238,
199,
504,
1275,
492,
428,
2655,
1700,
4131,
199,
504,
1999,
13408,
14,
2268,
14,
4273,
492,
8307,
4131,
2927,
12,
4713,
199,
504,
1999,
13408,
14,
2268,
14,
4273,
14,
4423,
14,
1430,
492,
334,
2872,
4527,
1304,
3466,
12,
13481,
7443,
8357,
12,
4490,
21682,
4131,
12,
13481,
2390,
12,
13481,
1931,
9,
199,
199,
9417,
2390,
4131,
275,
8307,
4131,
2927,
360,
2390,
358,
199,
25812,
199,
3,
199,
3,
6763,
15414,
1700,
4131,
1021,
199,
3,
199,
25812,
199,
533,
6763,
15414,
1700,
4131,
8,
15414,
1700,
4131,
304,
339,
347,
636,
826,
721,
277,
12,
1592,
929,
12,
399,
631,
323,
12,
28614,
304,
267,
291,
14,
11276,
63,
1532,
275,
28614,
267,
291,
14,
1541,
63,
344,
275,
11114,
14,
6845,
3900,
342,
267,
291,
14,
1541,
63,
3257,
275,
11114,
14,
6845,
3900,
342,
267,
291,
14,
1541,
63,
1430,
275,
6763,
342,
267,
291,
14,
1541,
63,
1430,
14,
409,
63,
466,
1332,
30051,
14,
20519,
12,
12381,
267,
291,
14,
29232,
275,
11424,
14,
17491,
8,
1989,
63,
2373,
29,
549,
9,
267,
340,
1592,
929,
14,
374,
63,
1490,
837,
288,
291,
14,
4229,
63,
1313,
275,
1592,
929,
14,
697,
14,
362,
63,
1430,
63,
1313,
342,
267,
587,
26,
288,
291,
14,
4229,
63,
1313,
275,
942,
398,
291,
14,
1430,
63,
4470,
275,
11114,
14,
6671,
17043,
23516,
8,
288,
291,
14,
29232,
12,
288,
291,
14,
1541,
63,
1430,
14,
409,
63,
466,
12,
288,
291,
14,
1541,
63,
1430,
14,
362,
63,
466,
12,
288,
3537,
63,
1459,
29,
277,
14,
4229,
63,
1313,
9,
398,
291,
14,
1541,
63,
973,
4181,
275,
11114,
14,
6845,
3900,
342,
267,
291,
14,
1541,
63,
602,
275,
11114,
14,
2506,
3900,
8,
85,
631,
323,
12,
3073,
267,
291,
14,
1541,
63,
2778,
275,
11114,
14,
6845,
3900,
342,
267,
291,
14,
1541,
63,
4610,
275,
11114,
14,
6845,
3900,
342,
398,
291,
14,
1541,
63,
3821,
275,
11424,
14,
1799,
4259,
8,
1302,
12397,
6119,
5578,
8455,
1333,
398,
291,
14,
1450,
275,
11424,
14,
17491,
342,
267,
291,
14,
6767,
275,
11424,
14,
17491,
342,
398,
428,
2655,
1700,
4131,
855,
826,
721,
277,
12,
1592,
929,
12,
399,
631,
323,
12,
298,
2390,
531,
339,
347,
1218,
63,
3440,
8,
277,
304,
267,
4917,
275,
11424,
14,
8108,
11355,
1872,
342,
267,
4917,
14,
409,
63,
1829,
360,
2063,
297,
291,
423,
9905,
63,
11139,
9,
267,
4917,
14,
409,
63,
1829,
360,
16514,
890,
297,
291,
423,
9905,
63,
14952,
1772,
4305,
9,
267,
291,
14,
6767,
14,
1389,
63,
928,
8,
3890,
12,
715,
9,
267,
291,
14,
6767,
14,
525,
63,
3215,
8,
3890,
12,
283,
505,
297,
378,
9,
267,
291,
14,
265,
63,
4273,
63,
2489,
360,
2390,
358,
398,
4917,
275,
11424,
14,
8108,
11355,
1872,
342,
267,
4917,
14,
409,
63,
1829,
360,
2063,
297,
291,
423,
9905,
63,
11139,
9,
267,
4917,
14,
409,
63,
1829,
360,
16514,
890,
297,
291,
423,
9905,
63,
14952,
1772,
4305,
9,
267,
291,
14,
1450,
14,
1389,
63,
928,
8,
3890,
12,
715,
9,
267,
291,
14,
1450,
14,
525,
63,
3215,
8,
3890,
12,
283,
505,
297,
378,
9,
398,
291,
14,
29232,
14,
362,
63,
1739,
1252,
409,
63,
2063,
63,
6574,
8,
21,
9,
398,
291,
14,
525,
63,
505,
63,
2373,
6723,
998,
659,
291,
14,
1541,
63,
344,
9,
267,
291,
14,
525,
63,
505,
63,
2373,
6723,
5831,
659,
291,
14,
1541,
63,
3257,
9,
267,
291,
14,
525,
63,
2373,
6723,
804,
659,
291,
14,
29232,
9,
267,
291,
14,
525,
63,
505,
63,
2373,
6723,
1262,
20989,
659,
291,
14,
1541,
63,
973,
4181,
9,
267,
291,
14,
525,
63,
505,
63,
2373,
6723,
2506,
659,
291,
14,
1541,
63,
602,
9,
267,
291,
14,
525,
63,
505,
63,
2373,
6723,
11613,
659,
291,
14,
1541,
63,
2778,
9,
267,
291,
14,
525,
63,
505,
63,
2373,
6723,
7443,
659,
291,
14,
1541,
63,
4610,
9,
267,
291,
14,
525,
63,
2373,
6723,
1931,
659,
291,
14,
1450,
9,
267,
291,
14,
525,
63,
1541,
63,
2373,
6723,
7223,
2457,
659,
291,
14,
6767,
9,
267,
291,
14,
525,
63,
3821,
63,
2373,
8,
277,
14,
1541,
63,
3821,
9,
339,
347,
5436
] |
[
199,
3,
10268,
13408,
446,
282,
598,
15263,
19616,
39,
2826,
3635,
4079,
15599,
2548,
89,
2240,
199,
3,
199,
3,
1898,
334,
35,
9,
14790,
13,
7968,
221,
7529,
27075,
653,
14,
2900,
316,
10670,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
11315,
13,
10067,
8217,
14,
199,
3,
199,
199,
25812,
199,
3,
199,
3,
2018,
4621,
199,
3,
199,
25812,
199,
504,
1999,
13408,
14,
2268,
14,
1297,
492,
21772,
1156,
5067,
63,
20828,
465,
486,
5508,
199,
63,
275,
486,
5508,
14,
6893,
14,
5152,
199,
199,
25812,
199,
3,
199,
3,
8116,
199,
3,
199,
25812,
199,
504,
18895,
14,
8421,
492,
11424,
199,
199,
25812,
199,
3,
199,
3,
10268,
13408,
4621,
199,
3,
199,
25812,
199,
504,
2263,
492,
11114,
199,
504,
1999,
13408,
14,
2268,
14,
773,
492,
6763,
12,
6763,
804,
199,
504,
2508,
492,
1900,
63,
1541,
63,
1238,
199,
504,
1275,
492,
428,
2655,
1700,
4131,
199,
504,
1999,
13408,
14,
2268,
14,
4273,
492,
8307,
4131,
2927,
12,
4713,
199,
504,
1999,
13408,
14,
2268,
14,
4273,
14,
4423,
14,
1430,
492,
334,
2872,
4527,
1304,
3466,
12,
13481,
7443,
8357,
12,
4490,
21682,
4131,
12,
13481,
2390,
12,
13481,
1931,
9,
199,
199,
9417,
2390,
4131,
275,
8307,
4131,
2927,
360,
2390,
358,
199,
25812,
199,
3,
199,
3,
6763,
15414,
1700,
4131,
1021,
199,
3,
199,
25812,
199,
533,
6763,
15414,
1700,
4131,
8,
15414,
1700,
4131,
304,
339,
347,
636,
826,
721,
277,
12,
1592,
929,
12,
399,
631,
323,
12,
28614,
304,
267,
291,
14,
11276,
63,
1532,
275,
28614,
267,
291,
14,
1541,
63,
344,
275,
11114,
14,
6845,
3900,
342,
267,
291,
14,
1541,
63,
3257,
275,
11114,
14,
6845,
3900,
342,
267,
291,
14,
1541,
63,
1430,
275,
6763,
342,
267,
291,
14,
1541,
63,
1430,
14,
409,
63,
466,
1332,
30051,
14,
20519,
12,
12381,
267,
291,
14,
29232,
275,
11424,
14,
17491,
8,
1989,
63,
2373,
29,
549,
9,
267,
340,
1592,
929,
14,
374,
63,
1490,
837,
288,
291,
14,
4229,
63,
1313,
275,
1592,
929,
14,
697,
14,
362,
63,
1430,
63,
1313,
342,
267,
587,
26,
288,
291,
14,
4229,
63,
1313,
275,
942,
398,
291,
14,
1430,
63,
4470,
275,
11114,
14,
6671,
17043,
23516,
8,
288,
291,
14,
29232,
12,
288,
291,
14,
1541,
63,
1430,
14,
409,
63,
466,
12,
288,
291,
14,
1541,
63,
1430,
14,
362,
63,
466,
12,
288,
3537,
63,
1459,
29,
277,
14,
4229,
63,
1313,
9,
398,
291,
14,
1541,
63,
973,
4181,
275,
11114,
14,
6845,
3900,
342,
267,
291,
14,
1541,
63,
602,
275,
11114,
14,
2506,
3900,
8,
85,
631,
323,
12,
3073,
267,
291,
14,
1541,
63,
2778,
275,
11114,
14,
6845,
3900,
342,
267,
291,
14,
1541,
63,
4610,
275,
11114,
14,
6845,
3900,
342,
398,
291,
14,
1541,
63,
3821,
275,
11424,
14,
1799,
4259,
8,
1302,
12397,
6119,
5578,
8455,
1333,
398,
291,
14,
1450,
275,
11424,
14,
17491,
342,
267,
291,
14,
6767,
275,
11424,
14,
17491,
342,
398,
428,
2655,
1700,
4131,
855,
826,
721,
277,
12,
1592,
929,
12,
399,
631,
323,
12,
298,
2390,
531,
339,
347,
1218,
63,
3440,
8,
277,
304,
267,
4917,
275,
11424,
14,
8108,
11355,
1872,
342,
267,
4917,
14,
409,
63,
1829,
360,
2063,
297,
291,
423,
9905,
63,
11139,
9,
267,
4917,
14,
409,
63,
1829,
360,
16514,
890,
297,
291,
423,
9905,
63,
14952,
1772,
4305,
9,
267,
291,
14,
6767,
14,
1389,
63,
928,
8,
3890,
12,
715,
9,
267,
291,
14,
6767,
14,
525,
63,
3215,
8,
3890,
12,
283,
505,
297,
378,
9,
267,
291,
14,
265,
63,
4273,
63,
2489,
360,
2390,
358,
398,
4917,
275,
11424,
14,
8108,
11355,
1872,
342,
267,
4917,
14,
409,
63,
1829,
360,
2063,
297,
291,
423,
9905,
63,
11139,
9,
267,
4917,
14,
409,
63,
1829,
360,
16514,
890,
297,
291,
423,
9905,
63,
14952,
1772,
4305,
9,
267,
291,
14,
1450,
14,
1389,
63,
928,
8,
3890,
12,
715,
9,
267,
291,
14,
1450,
14,
525,
63,
3215,
8,
3890,
12,
283,
505,
297,
378,
9,
398,
291,
14,
29232,
14,
362,
63,
1739,
1252,
409,
63,
2063,
63,
6574,
8,
21,
9,
398,
291,
14,
525,
63,
505,
63,
2373,
6723,
998,
659,
291,
14,
1541,
63,
344,
9,
267,
291,
14,
525,
63,
505,
63,
2373,
6723,
5831,
659,
291,
14,
1541,
63,
3257,
9,
267,
291,
14,
525,
63,
2373,
6723,
804,
659,
291,
14,
29232,
9,
267,
291,
14,
525,
63,
505,
63,
2373,
6723,
1262,
20989,
659,
291,
14,
1541,
63,
973,
4181,
9,
267,
291,
14,
525,
63,
505,
63,
2373,
6723,
2506,
659,
291,
14,
1541,
63,
602,
9,
267,
291,
14,
525,
63,
505,
63,
2373,
6723,
11613,
659,
291,
14,
1541,
63,
2778,
9,
267,
291,
14,
525,
63,
505,
63,
2373,
6723,
7443,
659,
291,
14,
1541,
63,
4610,
9,
267,
291,
14,
525,
63,
2373,
6723,
1931,
659,
291,
14,
1450,
9,
267,
291,
14,
525,
63,
1541,
63,
2373,
6723,
7223,
2457,
659,
291,
14,
6767,
9,
267,
291,
14,
525,
63,
3821,
63,
2373,
8,
277,
14,
1541,
63,
3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,
1,
1,
1,
1,
1,
1,
1
] |
catsop/CATMAID
|
django/applications/catmaid/apps.py
|
1
|
10359
|
import logging
from catmaid import history
from django.apps import AppConfig
from django.conf import settings
from django.core.checks import Warning, register
from django.core.exceptions import ImproperlyConfigured
from django.db import connection
from django.db.utils import ProgrammingError
from django.db.models import signals
from django.db.backends import signals as db_signals
from django.contrib import auth
from django.contrib.auth.management.commands import createsuperuser
import custom_rest_swagger_apis
def get_system_user(user_model=None):
"""Return a User instance of a superuser. This is either the superuser
having the ID configured in SYSTEM_USER_ID or the superuser with the lowest
ID."""
if not user_model:
user_model = auth.get_user_model()
if hasattr(settings, "SYSTEM_USER_ID"):
try:
return user_model.objects.get(id=settings.SYSTEM_USER_ID, is_superuser=True)
except user_model.DoesNotExist:
raise ImproperlyConfigured("Could not find any super user with ID "
"configured in SYSTEM_USER_ID (%s), "
"please fix this in settings.py" % settings.SYSTEM_USER_ID)
else:
# Find admin user with lowest id
users = user_model.objects.filter(is_superuser=True).order_by('id')
if not len(users):
raise ImproperlyConfigured("Couldn't find any super user, " +
"please make sure you have one")
return users[0]
def check_old_version(sender, **kwargs):
"""Make sure this migration system starts with all South migrations applied,
in case there are already existing tables."""
# Only validate after catmaid was migrated
if type(sender) != CATMAIDConfig:
return
cursor = connection.cursor()
def table_exists(name):
cursor.execute("""
SELECT EXISTS (
SELECT 1
FROM information_schema.tables
WHERE table_schema = 'public'
AND table_name = %s
);
""", (name,))
result = cursor.fetchone()
return result[0]
def catmaid_was_migrated():
cursor.execute("""
SELECT count(*) FROM django_migrations WHERE app = 'catmaid';
""")
result = cursor.fetchone()
return result[0] > 0
# Don't check for old the existing database state if Django 1.7 migrations
# have been applied already.
if table_exists("django_migrations") and catmaid_was_migrated():
return
# Check if there are existing CATMAID 2015.12.21 tables by testing if the
# project table exists. If it does, expect that the result of the last South
# migration (#61) was applied---the apikey table was removed. Fail if it
# wasn't and tell the user to bring the database to this expected state.
if table_exists("project") and table_exists("catmaid_apikey"):
raise ImproperlyConfigured("Can not apply initial database migration. "
"You seem to update from an existing CATMAID version. Please "
"make sure this existing version was updated to version "
"2015.12.21 (with all migrations applied) and then move on to "
"the next version. Note that you have to fake the initial "
"migration of the newer version, i.e. before you do the "
"regular update steps call 'manage.py migrate --fake catmaid "
"0001_initial'.")
def check_history_setup(app_configs, **kwargs):
messages = []
# Enable or disable history tracking, depending on the configuration.
# Ignore silently, if the database wasn't migrated yet.
if getattr(settings, 'HISTORY_TRACKING', True):
run = history.enable_history_tracking(True)
else:
run = history.disable_history_tracking(True)
if not run:
messages.append(Warning(
"Couldn't check history setup, missing database functions",
hint="Migrate CATMAID"))
return messages
def validate_environment(sender, **kwargs):
"""Make sure CATMAID is set up correctly."""
# Only validate after catmaid was migrated
if type(sender) != CATMAIDConfig:
return
sender.validate_projects()
sender.init_classification()
class CATMAIDConfig(AppConfig):
name = 'catmaid'
verbose_name = "CATMAID"
def ready(self):
"""Perform initialization for back-end"""
self.validate_configuration()
self.check_superuser()
# Make sure the existing version is what we expect
signals.pre_migrate.connect(check_old_version, sender=self)
# Validate CATMAID environment after all migrations have been run
signals.post_migrate.connect(validate_environment, sender=self)
# Register history checks
register(check_history_setup)
# Monkey patch django-rest-swagger so that it can handle our URLs
custom_rest_swagger_apis.patch()
# A list of settings that are expected to be available.
required_setting_fields = {
"VERSION": str,
"CATMAID_URL": str,
"ONTOLOGY_DUMMY_PROJECT_ID": int,
"PROFILE_INDEPENDENT_ONTOLOGY_WORKSPACE_IS_DEFAULT": bool,
"PROFILE_SHOW_TEXT_LABEL_TOOL": bool,
"PROFILE_SHOW_TAGGING_TOOL": bool,
"PROFILE_SHOW_CROPPING_TOOL": bool,
"PROFILE_SHOW_SEGMENTATION_TOOL": bool,
"PROFILE_SHOW_TRACING_TOOL": bool,
"PROFILE_SHOW_ONTOLOGY_TOOL": bool,
"PROFILE_SHOW_ROI_TOOL": bool,
"ROI_AUTO_CREATE_IMAGE": bool,
"NODE_LIST_MAXIMUM_COUNT": int,
"IMPORTER_DEFAULT_TILE_WIDTH": int,
"IMPORTER_DEFAULT_TILE_HEIGHT": int,
"IMPORTER_DEFAULT_TILE_SOURCE_TYPE": int,
"IMPORTER_DEFAULT_IMAGE_BASE": str,
"MEDIA_HDF5_SUBDIRECTORY": str,
"MEDIA_CROPPING_SUBDIRECTORY": str,
"MEDIA_ROI_SUBDIRECTORY": str,
"MEDIA_TREENODE_SUBDIRECTORY": str,
"GENERATED_FILES_MAXIMUM_SIZE": int,
"USER_REGISTRATION_ALLOWED": bool,
"NEW_USER_DEFAULT_GROUPS": list,
"STATIC_EXTENSION_FILES": list,
"STATIC_EXTENSION_ROOT": str,
}
def validate_configuration(self):
"""Make sure CATMAID is configured properly and raise an error if not.
"""
# Make sure all expected settings are available.
for field, data_type in CATMAIDConfig.required_setting_fields.iteritems():
if not hasattr(settings, field):
raise ImproperlyConfigured(
"Please add the %s settings field" % field)
if type(getattr(settings, field)) != data_type:
raise ImproperlyConfigured("Please make sure settings field %s "
"is of type %s" % (field, data_type))
# Make sure swagger (API doc) knows about a potential sub-directory
if not hasattr(settings, 'SWAGGER_SETTINGS'):
settings.SWAGGER_SETTINGS = {}
if 'api_path' not in settings.SWAGGER_SETTINGS:
settings.SWAGGER_SETTINGS['api_path'] = settings.CATMAID_URL
def check_superuser(self):
"""Make sure there is at least one superuser available and, if configured,
SYSTEM_USER_ID points to a superuser. Expects database to be set up.
"""
try:
User = auth.get_user_model()
Project = self.get_model("Project")
has_users = User.objects.all().exists()
has_projects = Project.objects.exclude(pk=settings.ONTOLOGY_DUMMY_PROJECT_ID).exists()
if not (has_users and has_projects):
# In case there is no user and only no project except thei ontology
# dummy project, don't do the check. Otherwise, setting up CATMAID
# initially will not be possible without raising the errors below.
return
if not User.objects.filter(is_superuser=True).count():
raise ImproperlyConfigured("You need to have at least one superuser "
"configured to start CATMAID.")
if hasattr(settings, "SYSTEM_USER_ID"):
try:
user = User.objects.get(id=settings.SYSTEM_USER_ID)
except User.DoesNotExist:
raise ImproperlyConfigured("Could not find any super user with the "
"ID configured in SYSTEM_USER_ID")
if not user.is_superuser:
raise ImproperlyConfigured("The user configured in SYSTEM_USER_ID "
"is no superuser")
except ProgrammingError:
# This error is raised if the database is not set up when the code
# above is executed. This can safely be ignored.
pass
def init_classification(self):
""" Creates a dummy project to store classification graphs in.
"""
Project = self.get_model("Project")
try:
Project.objects.get(pk=settings.ONTOLOGY_DUMMY_PROJECT_ID)
except Project.DoesNotExist:
logging.getLogger(__name__).info("Creating ontology dummy project")
Project.objects.create(pk=settings.ONTOLOGY_DUMMY_PROJECT_ID,
title="Classification dummy project")
def validate_projects(self):
"""Make sure all projects have the relations and classes available they
expect."""
from catmaid.control.project import validate_project_setup
User = auth.get_user_model()
Project = self.get_model("Project")
has_users = User.objects.all().exists()
has_projects = Project.objects.exclude(
pk=settings.ONTOLOGY_DUMMY_PROJECT_ID).exists()
if not (has_users and has_projects):
# In case there is no user and only no project except thei ontology
# dummy project, don't do the check. Otherwise, getting a system user
# will fail.
return
Class = self.get_model("Class")
Relation = self.get_model("Relation")
user = get_system_user(User)
for p in Project.objects.all():
validate_project_setup(p.id, user.id, True, Class, Relation)
|
gpl-3.0
|
[
646,
2050,
199,
199,
504,
6230,
391,
344,
492,
7994,
199,
199,
504,
1639,
14,
5181,
492,
4693,
2028,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1018,
14,
8625,
492,
15902,
12,
2274,
199,
504,
1639,
14,
1018,
14,
3924,
492,
11897,
199,
504,
1639,
14,
697,
492,
1950,
199,
504,
1639,
14,
697,
14,
1208,
492,
2165,
9258,
547,
199,
504,
1639,
14,
697,
14,
992,
492,
10166,
199,
504,
1639,
14,
697,
14,
7765,
492,
10166,
465,
1592,
63,
10458,
199,
504,
1639,
14,
2828,
492,
1790,
199,
504,
1639,
14,
2828,
14,
1178,
14,
8110,
14,
4405,
492,
1218,
11434,
199,
199,
646,
3537,
63,
3911,
63,
29940,
63,
12662,
421,
199,
318,
664,
63,
2253,
63,
751,
8,
751,
63,
1238,
29,
403,
304,
272,
408,
1767,
282,
2876,
1256,
402,
282,
32590,
14,
961,
365,
1902,
314,
32590,
272,
9445,
314,
2870,
7526,
315,
20859,
63,
3791,
63,
998,
503,
314,
32590,
543,
314,
18966,
272,
2870,
1041,
272,
340,
440,
922,
63,
1238,
26,
267,
922,
63,
1238,
275,
1790,
14,
362,
63,
751,
63,
1238,
342,
339,
340,
2688,
8,
1751,
12,
298,
12711,
63,
3791,
63,
998,
2349,
267,
862,
26,
288,
372,
922,
63,
1238,
14,
1462,
14,
362,
8,
344,
29,
1751,
14,
12711,
63,
3791,
63,
998,
12,
365,
63,
11434,
29,
549,
9,
267,
871,
922,
63,
1238,
14,
7400,
26,
288,
746,
11897,
480,
6531,
440,
2342,
1263,
1613,
922,
543,
2870,
298,
4318,
298,
11786,
315,
20859,
63,
3791,
63,
998,
4366,
83,
395,
298,
4318,
298,
27567,
5325,
642,
315,
2202,
14,
647,
2,
450,
2202,
14,
12711,
63,
3791,
63,
998,
9,
272,
587,
26,
267,
327,
6668,
4628,
922,
543,
18966,
1305,
267,
4390,
275,
922,
63,
1238,
14,
1462,
14,
1541,
8,
374,
63,
11434,
29,
549,
680,
1648,
63,
991,
360,
344,
358,
267,
340,
440,
822,
8,
3707,
304,
288,
746,
11897,
480,
20485,
1133,
2342,
1263,
1613,
922,
12,
298,
435,
4318,
298,
27567,
1852,
3238,
1265,
1172,
1373,
531,
267,
372,
4390,
59,
16,
61,
421,
199,
318,
1104,
63,
1753,
63,
1023,
8,
8114,
12,
1011,
958,
304,
272,
408,
5483,
3238,
642,
8367,
2656,
9174,
543,
1006,
23150,
6180,
6781,
12,
272,
315,
1930,
2337,
787,
2575,
3411,
6716,
1041,
272,
327,
5972,
4107,
2410,
6230,
391,
344,
1990,
28322,
272,
340,
730,
8,
8114,
9,
1137,
445,
619,
2054,
998,
2028,
26,
267,
372,
339,
3920,
275,
1950,
14,
3937,
342,
339,
347,
1817,
63,
2444,
8,
354,
304,
267,
3920,
14,
2526,
4852,
288,
10468,
23875,
334,
2049,
10468,
413,
2049,
4442,
257,
2556,
63,
3629,
14,
5987,
2049,
6038,
221,
1817,
63,
3629,
275,
283,
3455,
7,
2049,
2401,
259,
1817,
63,
354,
275,
450,
83,
288,
20682,
267,
10327,
334,
354,
4641,
267,
754,
275,
3920,
14,
11591,
342,
267,
372,
754,
59,
16,
61,
339,
347,
6230,
391,
344,
63,
10274,
63,
31544,
837,
267,
3920,
14,
2526,
4852,
1779,
10468,
2338,
21565,
4442,
1639,
63,
7685,
6038,
1145,
275,
283,
3385,
391,
344,
13619,
267,
7857,
267,
754,
275,
3920,
14,
11591,
342,
267,
372,
754,
59,
16,
61,
690,
378,
339,
327,
7529,
1133,
1104,
367,
2269,
314,
3411,
3050,
1174,
340,
5634,
413,
14,
23,
6180,
272,
327,
1172,
2757,
6781,
2575,
14,
272,
340,
1817,
63,
2444,
480,
1176,
63,
7685,
531,
436,
6230,
391,
344,
63,
10274,
63,
31544,
837,
267,
372,
339,
327,
2670,
340,
2337,
787,
3411,
445,
619,
2054,
998,
6900,
14,
713,
14,
2025,
6716,
701,
5343,
340,
314,
272,
327,
2199,
1817,
3495,
14,
982,
652,
1630,
12,
4282,
626,
314,
754,
402,
314,
2061,
23150,
272,
327,
8367,
15196,
2976,
9,
1990,
6781,
2595,
1589,
2986,
498,
1817,
1990,
4829,
14,
12176,
340,
652,
272,
327,
17373,
1133,
436,
11480,
314,
922,
370,
330,
5985,
314,
3050,
370,
642,
1420,
1174,
14,
272,
340,
1817,
63,
2444,
480,
1715,
531,
436,
1817,
63,
2444,
480,
3385,
391,
344,
63,
28181,
2349,
267,
746,
11897,
480,
6049,
440,
4838,
2536,
3050,
8367,
14,
298,
355,
298,
5556,
17021,
370,
1678,
687,
376,
3411,
445,
619,
2054,
998,
1015,
14,
7754,
298,
355,
298,
1875,
3238,
642,
3411,
1015,
1990,
4588,
370,
1015,
298,
355,
298,
7806,
14,
713,
14,
2025,
334,
1045,
1006,
6180,
6781,
9,
436,
2066,
4057,
641,
370,
298,
355,
298,
1589,
2163,
1015,
14,
3390,
626,
1265,
1172,
370,
4026,
314,
2536,
298,
355,
298,
8998,
402,
314,
15666,
1015,
12,
284,
14,
69,
14,
2544,
1265,
886,
314,
298,
355,
298,
7898,
1678,
7124,
1240,
283,
9053,
14,
647,
12810,
1553,
3183,
6230,
391,
344,
298,
355,
298,
4183,
63,
2747,
29435,
199,
199,
318,
1104,
63,
5570,
63,
2758,
8,
571,
63,
7532,
12,
1011,
958,
304,
272,
3788,
275,
942,
272,
327,
12030,
503,
3507,
7994,
15161,
12,
10298,
641,
314,
2897,
14,
272,
327,
14092,
18030,
12,
340,
314,
3050,
17373,
1133,
28322,
5966,
14,
272,
340,
2519,
8,
1751,
12,
283,
30895,
63,
19755,
1206,
297,
715,
304,
267,
1255,
275,
7994,
14,
4296,
63,
5570,
63,
14428,
8,
549,
9,
272,
587,
26,
267,
1255,
275,
7994,
14,
5993,
63,
5570,
63,
14428,
8,
549,
9,
339,
340,
440,
1255,
26,
267,
3788,
14,
740,
8,
3849,
8,
288,
298,
20485,
1133,
1104,
7994,
3272,
12,
4124,
3050,
3423,
401,
288,
8328,
628,
26641,
445,
619,
2054,
998,
2237,
272,
372,
3788,
199,
199,
318,
4107,
63,
5418,
8,
8114,
12,
1011,
958,
304,
272,
408,
5483,
3238,
445,
619,
2054,
998,
365,
663,
1536,
6657,
1041,
272,
327,
5972,
4107,
2410,
6230,
391,
344,
1990,
28322,
272,
340,
730,
8,
8114,
9,
1137,
445,
619,
2054,
998,
2028,
26,
267,
372,
339,
8904,
14,
3502,
63,
6776,
342,
272,
8904,
14,
826,
63,
14368,
342,
199,
199,
533,
445,
619,
2054,
998,
2028,
8,
2640,
2028,
304,
272,
536,
275,
283,
3385,
391,
344,
7,
272,
3376,
63,
354,
275,
298,
11206,
2054,
998,
2,
339,
347,
10144,
8,
277,
304,
267,
408,
20906,
11097,
367,
1771,
13,
500,
624
] |
[
2050,
199,
199,
504,
6230,
391,
344,
492,
7994,
199,
199,
504,
1639,
14,
5181,
492,
4693,
2028,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1018,
14,
8625,
492,
15902,
12,
2274,
199,
504,
1639,
14,
1018,
14,
3924,
492,
11897,
199,
504,
1639,
14,
697,
492,
1950,
199,
504,
1639,
14,
697,
14,
1208,
492,
2165,
9258,
547,
199,
504,
1639,
14,
697,
14,
992,
492,
10166,
199,
504,
1639,
14,
697,
14,
7765,
492,
10166,
465,
1592,
63,
10458,
199,
504,
1639,
14,
2828,
492,
1790,
199,
504,
1639,
14,
2828,
14,
1178,
14,
8110,
14,
4405,
492,
1218,
11434,
199,
199,
646,
3537,
63,
3911,
63,
29940,
63,
12662,
421,
199,
318,
664,
63,
2253,
63,
751,
8,
751,
63,
1238,
29,
403,
304,
272,
408,
1767,
282,
2876,
1256,
402,
282,
32590,
14,
961,
365,
1902,
314,
32590,
272,
9445,
314,
2870,
7526,
315,
20859,
63,
3791,
63,
998,
503,
314,
32590,
543,
314,
18966,
272,
2870,
1041,
272,
340,
440,
922,
63,
1238,
26,
267,
922,
63,
1238,
275,
1790,
14,
362,
63,
751,
63,
1238,
342,
339,
340,
2688,
8,
1751,
12,
298,
12711,
63,
3791,
63,
998,
2349,
267,
862,
26,
288,
372,
922,
63,
1238,
14,
1462,
14,
362,
8,
344,
29,
1751,
14,
12711,
63,
3791,
63,
998,
12,
365,
63,
11434,
29,
549,
9,
267,
871,
922,
63,
1238,
14,
7400,
26,
288,
746,
11897,
480,
6531,
440,
2342,
1263,
1613,
922,
543,
2870,
298,
4318,
298,
11786,
315,
20859,
63,
3791,
63,
998,
4366,
83,
395,
298,
4318,
298,
27567,
5325,
642,
315,
2202,
14,
647,
2,
450,
2202,
14,
12711,
63,
3791,
63,
998,
9,
272,
587,
26,
267,
327,
6668,
4628,
922,
543,
18966,
1305,
267,
4390,
275,
922,
63,
1238,
14,
1462,
14,
1541,
8,
374,
63,
11434,
29,
549,
680,
1648,
63,
991,
360,
344,
358,
267,
340,
440,
822,
8,
3707,
304,
288,
746,
11897,
480,
20485,
1133,
2342,
1263,
1613,
922,
12,
298,
435,
4318,
298,
27567,
1852,
3238,
1265,
1172,
1373,
531,
267,
372,
4390,
59,
16,
61,
421,
199,
318,
1104,
63,
1753,
63,
1023,
8,
8114,
12,
1011,
958,
304,
272,
408,
5483,
3238,
642,
8367,
2656,
9174,
543,
1006,
23150,
6180,
6781,
12,
272,
315,
1930,
2337,
787,
2575,
3411,
6716,
1041,
272,
327,
5972,
4107,
2410,
6230,
391,
344,
1990,
28322,
272,
340,
730,
8,
8114,
9,
1137,
445,
619,
2054,
998,
2028,
26,
267,
372,
339,
3920,
275,
1950,
14,
3937,
342,
339,
347,
1817,
63,
2444,
8,
354,
304,
267,
3920,
14,
2526,
4852,
288,
10468,
23875,
334,
2049,
10468,
413,
2049,
4442,
257,
2556,
63,
3629,
14,
5987,
2049,
6038,
221,
1817,
63,
3629,
275,
283,
3455,
7,
2049,
2401,
259,
1817,
63,
354,
275,
450,
83,
288,
20682,
267,
10327,
334,
354,
4641,
267,
754,
275,
3920,
14,
11591,
342,
267,
372,
754,
59,
16,
61,
339,
347,
6230,
391,
344,
63,
10274,
63,
31544,
837,
267,
3920,
14,
2526,
4852,
1779,
10468,
2338,
21565,
4442,
1639,
63,
7685,
6038,
1145,
275,
283,
3385,
391,
344,
13619,
267,
7857,
267,
754,
275,
3920,
14,
11591,
342,
267,
372,
754,
59,
16,
61,
690,
378,
339,
327,
7529,
1133,
1104,
367,
2269,
314,
3411,
3050,
1174,
340,
5634,
413,
14,
23,
6180,
272,
327,
1172,
2757,
6781,
2575,
14,
272,
340,
1817,
63,
2444,
480,
1176,
63,
7685,
531,
436,
6230,
391,
344,
63,
10274,
63,
31544,
837,
267,
372,
339,
327,
2670,
340,
2337,
787,
3411,
445,
619,
2054,
998,
6900,
14,
713,
14,
2025,
6716,
701,
5343,
340,
314,
272,
327,
2199,
1817,
3495,
14,
982,
652,
1630,
12,
4282,
626,
314,
754,
402,
314,
2061,
23150,
272,
327,
8367,
15196,
2976,
9,
1990,
6781,
2595,
1589,
2986,
498,
1817,
1990,
4829,
14,
12176,
340,
652,
272,
327,
17373,
1133,
436,
11480,
314,
922,
370,
330,
5985,
314,
3050,
370,
642,
1420,
1174,
14,
272,
340,
1817,
63,
2444,
480,
1715,
531,
436,
1817,
63,
2444,
480,
3385,
391,
344,
63,
28181,
2349,
267,
746,
11897,
480,
6049,
440,
4838,
2536,
3050,
8367,
14,
298,
355,
298,
5556,
17021,
370,
1678,
687,
376,
3411,
445,
619,
2054,
998,
1015,
14,
7754,
298,
355,
298,
1875,
3238,
642,
3411,
1015,
1990,
4588,
370,
1015,
298,
355,
298,
7806,
14,
713,
14,
2025,
334,
1045,
1006,
6180,
6781,
9,
436,
2066,
4057,
641,
370,
298,
355,
298,
1589,
2163,
1015,
14,
3390,
626,
1265,
1172,
370,
4026,
314,
2536,
298,
355,
298,
8998,
402,
314,
15666,
1015,
12,
284,
14,
69,
14,
2544,
1265,
886,
314,
298,
355,
298,
7898,
1678,
7124,
1240,
283,
9053,
14,
647,
12810,
1553,
3183,
6230,
391,
344,
298,
355,
298,
4183,
63,
2747,
29435,
199,
199,
318,
1104,
63,
5570,
63,
2758,
8,
571,
63,
7532,
12,
1011,
958,
304,
272,
3788,
275,
942,
272,
327,
12030,
503,
3507,
7994,
15161,
12,
10298,
641,
314,
2897,
14,
272,
327,
14092,
18030,
12,
340,
314,
3050,
17373,
1133,
28322,
5966,
14,
272,
340,
2519,
8,
1751,
12,
283,
30895,
63,
19755,
1206,
297,
715,
304,
267,
1255,
275,
7994,
14,
4296,
63,
5570,
63,
14428,
8,
549,
9,
272,
587,
26,
267,
1255,
275,
7994,
14,
5993,
63,
5570,
63,
14428,
8,
549,
9,
339,
340,
440,
1255,
26,
267,
3788,
14,
740,
8,
3849,
8,
288,
298,
20485,
1133,
1104,
7994,
3272,
12,
4124,
3050,
3423,
401,
288,
8328,
628,
26641,
445,
619,
2054,
998,
2237,
272,
372,
3788,
199,
199,
318,
4107,
63,
5418,
8,
8114,
12,
1011,
958,
304,
272,
408,
5483,
3238,
445,
619,
2054,
998,
365,
663,
1536,
6657,
1041,
272,
327,
5972,
4107,
2410,
6230,
391,
344,
1990,
28322,
272,
340,
730,
8,
8114,
9,
1137,
445,
619,
2054,
998,
2028,
26,
267,
372,
339,
8904,
14,
3502,
63,
6776,
342,
272,
8904,
14,
826,
63,
14368,
342,
199,
199,
533,
445,
619,
2054,
998,
2028,
8,
2640,
2028,
304,
272,
536,
275,
283,
3385,
391,
344,
7,
272,
3376,
63,
354,
275,
298,
11206,
2054,
998,
2,
339,
347,
10144,
8,
277,
304,
267,
408,
20906,
11097,
367,
1771,
13,
500,
624,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
jay-tyler/ansible
|
v1/ansible/runner/lookup_plugins/password.py
|
144
|
4766
|
# (c) 2012, Daniel Hokka Zakrisson <daniel@hozac.com>
# (c) 2013, Javier Candeira <javier@candeira.com>
# (c) 2013, Maykel Moya <mmoya@speedyrails.com>
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
from ansible import utils, errors
import os
import errno
from string import ascii_letters, digits
import string
import random
class LookupModule(object):
LENGTH = 20
def __init__(self, length=None, encrypt=None, basedir=None, **kwargs):
self.basedir = basedir
def random_salt(self):
salt_chars = ascii_letters + digits + './'
return utils.random_password(length=8, chars=salt_chars)
def run(self, terms, inject=None, **kwargs):
terms = utils.listify_lookup_plugin_terms(terms, self.basedir, inject)
ret = []
for term in terms:
# you can't have escaped spaces in yor pathname
params = term.split()
relpath = params[0]
paramvals = {
'length': LookupModule.LENGTH,
'encrypt': None,
'chars': ['ascii_letters','digits',".,:-_"],
}
# get non-default parameters if specified
try:
for param in params[1:]:
name, value = param.split('=')
assert(name in paramvals)
if name == 'length':
paramvals[name] = int(value)
elif name == 'chars':
use_chars=[]
if ",," in value:
use_chars.append(',')
use_chars.extend(value.replace(',,',',').split(','))
paramvals['chars'] = use_chars
else:
paramvals[name] = value
except (ValueError, AssertionError), e:
raise errors.AnsibleError(e)
length = paramvals['length']
encrypt = paramvals['encrypt']
use_chars = paramvals['chars']
# get password or create it if file doesn't exist
path = utils.path_dwim(self.basedir, relpath)
if not os.path.exists(path):
pathdir = os.path.dirname(path)
if not os.path.isdir(pathdir):
try:
os.makedirs(pathdir, mode=0700)
except OSError, e:
raise errors.AnsibleError("cannot create the path for the password lookup: %s (error was %s)" % (pathdir, str(e)))
chars = "".join([getattr(string,c,c) for c in use_chars]).replace('"','').replace("'",'')
password = ''.join(random.choice(chars) for _ in range(length))
if encrypt is not None:
salt = self.random_salt()
content = '%s salt=%s' % (password, salt)
else:
content = password
with open(path, 'w') as f:
os.chmod(path, 0600)
f.write(content + '\n')
else:
content = open(path).read().rstrip()
sep = content.find(' ')
if sep >= 0:
password = content[:sep]
salt = content[sep+1:].split('=')[1]
else:
password = content
salt = None
# crypt requested, add salt if missing
if (encrypt is not None and not salt):
salt = self.random_salt()
content = '%s salt=%s' % (password, salt)
with open(path, 'w') as f:
os.chmod(path, 0600)
f.write(content + '\n')
# crypt not requested, remove salt if present
elif (encrypt is None and salt):
with open(path, 'w') as f:
os.chmod(path, 0600)
f.write(password + '\n')
if encrypt:
password = utils.do_encrypt(password, encrypt, salt=salt)
ret.append(password)
return ret
|
gpl-3.0
|
[
3,
334,
67,
9,
6029,
12,
24747,
14769,
869,
745,
7351,
3107,
1151,
322,
385,
265,
665,
24863,
14769,
32,
526,
90,
645,
14,
957,
30,
199,
3,
334,
67,
9,
6171,
12,
1603,
7194,
281,
6855,
271,
20936,
665,
3387,
26645,
32,
2425,
271,
20936,
14,
957,
30,
199,
3,
334,
67,
9,
6171,
12,
10162,
75,
352,
3930,
11552,
665,
77,
573,
11552,
32,
7625,
89,
345,
17841,
14,
957,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
504,
3242,
492,
3778,
12,
2552,
199,
646,
747,
199,
646,
7554,
199,
504,
1059,
492,
13294,
63,
16415,
12,
7576,
199,
646,
1059,
199,
646,
2196,
421,
199,
533,
12785,
2377,
8,
785,
304,
339,
491,
32106,
275,
3388,
339,
347,
636,
826,
721,
277,
12,
2582,
29,
403,
12,
14645,
29,
403,
12,
19380,
29,
403,
12,
1011,
958,
304,
267,
291,
14,
12484,
275,
19380,
339,
347,
2196,
63,
12597,
8,
277,
304,
267,
10105,
63,
6574,
275,
13294,
63,
16415,
435,
7576,
435,
1987,
4805,
267,
372,
3778,
14,
2355,
63,
2060,
8,
1267,
29,
24,
12,
8365,
29,
12597,
63,
6574,
9,
339,
347,
1255,
8,
277,
12,
2895,
12,
16182,
29,
403,
12,
1011,
958,
304,
398,
2895,
275,
3778,
14,
513,
2021,
63,
3892,
63,
2718,
63,
9187,
8,
9187,
12,
291,
14,
12484,
12,
16182,
9,
24807,
2203,
275,
942,
398,
367,
6707,
315,
2895,
26,
288,
327,
1265,
883,
1133,
1172,
11077,
7883,
315,
612,
269,
11776,
288,
1862,
275,
6707,
14,
1294,
342,
288,
20700,
275,
1862,
59,
16,
61,
953,
1215,
3643,
275,
469,
355,
283,
1267,
356,
12785,
2377,
14,
9127,
12,
355,
283,
11929,
356,
488,
12,
355,
283,
6574,
356,
788,
4371,
63,
16415,
1673,
7022,
297,
1674,
12,
6809,
63,
2255,
288,
789,
953,
327,
664,
2222,
13,
885,
2633,
340,
2013,
288,
862,
26,
355,
367,
1215,
315,
1862,
59,
17,
10688,
490,
536,
12,
574,
275,
1215,
14,
1294,
23917,
490,
702,
8,
354,
315,
1215,
3643,
9,
490,
340,
536,
508,
283,
1267,
356,
717,
1215,
3643,
59,
354,
61,
275,
1109,
8,
585,
9,
490,
916,
536,
508,
283,
6574,
356,
717,
675,
63,
6574,
9811,
717,
340,
3872,
4589,
315,
574,
26,
29157,
675,
63,
6574,
14,
740,
11917,
717,
675,
63,
6574,
14,
2880,
8,
585,
14,
1814,
5102,
12,
23324,
1959,
1294,
5102,
1333,
717,
1215,
3643,
459,
6574,
418,
275,
675,
63,
6574,
490,
587,
26,
717,
1215,
3643,
59,
354,
61,
275,
574,
288,
871,
334,
3393,
12,
9070,
395,
325,
26,
355,
746,
2552,
14,
29107,
8,
69,
9,
953,
2582,
221,
275,
1215,
3643,
459,
1267,
418,
288,
14645,
275,
1215,
3643,
459,
11929,
418,
288,
675,
63,
6574,
275,
1215,
3643,
459,
6574,
418,
953,
327,
664,
2505,
503,
1218,
652,
340,
570,
3181,
1133,
2187,
288,
931,
275,
3778,
14,
515,
63,
10772,
1017,
8,
277,
14,
12484,
12,
20700,
9,
288,
340,
440,
747,
14,
515,
14,
2444,
8,
515,
304,
355,
931,
694,
275,
747,
14,
515,
14,
3475,
8,
515,
9,
355,
340,
440,
747,
14,
515,
14,
6027,
8,
515,
694,
304,
490,
862,
26,
717,
747,
14,
8347,
8,
515,
694,
12,
818,
29,
1780,
383,
9,
490,
871,
6440,
12,
325,
26,
717,
746,
2552,
14,
29107,
480,
11250,
1218,
314,
931,
367,
314,
2505,
4237,
26,
450,
83,
334,
705,
1990,
450,
83,
2924,
450,
334,
515,
694,
12,
620,
8,
69,
1724,
2234,
8365,
275,
10587,
904,
779,
5675,
8,
875,
12,
67,
12,
67,
9,
367,
286,
315,
675,
63,
6574,
6575,
1814,
14088,
26516,
1814,
27769,
17483,
355,
2505,
275,
6522,
904,
8,
2355,
14,
5095,
8,
6574,
9,
367,
485,
315,
1425,
8,
1267,
430,
2234,
340,
14645,
365,
440,
488,
26,
490,
10105,
275,
291,
14,
2355,
63,
12597,
342,
490,
1564,
275,
1543,
83,
10105,
2458,
83,
7,
450,
334,
2060,
12,
10105,
9,
355,
587,
26,
490,
1564,
275,
2505,
355,
543,
1551,
8,
515,
12,
283,
87,
358,
465,
289,
26,
490,
747,
14,
11693,
8,
515,
12,
378,
6683,
9,
490,
289,
14,
952,
8,
1317,
435,
1557,
78,
358,
288,
587,
26,
355,
1564,
275,
1551,
8,
515,
680,
739,
1252,
6735,
342,
355,
7375,
275,
1564,
14,
1623,
360,
5320,
2234,
340,
7375,
2356,
378,
26,
490,
2505,
275,
1564,
1491,
4127,
61,
490,
10105,
275,
1564,
59,
4127,
11,
17,
11455,
1294,
26800,
5832,
17,
61,
355,
587,
26,
490,
2505,
275,
1564,
490,
10105,
275,
488,
2234,
327,
21570,
5839,
12,
1050,
10105,
340,
4124,
355,
340,
334,
11929,
365,
440,
488,
436,
440,
10105,
304,
490,
10105,
275,
291,
14,
2355,
63,
12597,
342,
490,
1564,
275,
1543,
83,
10105,
2458,
83,
7,
450,
334,
2060,
12,
10105,
9,
490,
543,
1551,
8,
515,
12,
283,
87,
358,
465,
289,
26,
717,
747,
14,
11693,
8,
515,
12,
378,
6683,
9,
717,
289,
14,
952,
8,
1317,
435,
1557,
78,
358,
355,
327,
21570,
440,
5839,
12,
2813,
10105,
340,
3451,
355,
916,
334,
11929,
365,
488,
436,
10105,
304,
490,
543,
1551,
8,
515,
12,
283,
87,
358,
465,
289,
26,
717,
747,
14,
11693,
8,
515,
12,
378,
6683,
9
] |
[
334,
67,
9,
6029,
12,
24747,
14769,
869,
745,
7351,
3107,
1151,
322,
385,
265,
665,
24863,
14769,
32,
526,
90,
645,
14,
957,
30,
199,
3,
334,
67,
9,
6171,
12,
1603,
7194,
281,
6855,
271,
20936,
665,
3387,
26645,
32,
2425,
271,
20936,
14,
957,
30,
199,
3,
334,
67,
9,
6171,
12,
10162,
75,
352,
3930,
11552,
665,
77,
573,
11552,
32,
7625,
89,
345,
17841,
14,
957,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
504,
3242,
492,
3778,
12,
2552,
199,
646,
747,
199,
646,
7554,
199,
504,
1059,
492,
13294,
63,
16415,
12,
7576,
199,
646,
1059,
199,
646,
2196,
421,
199,
533,
12785,
2377,
8,
785,
304,
339,
491,
32106,
275,
3388,
339,
347,
636,
826,
721,
277,
12,
2582,
29,
403,
12,
14645,
29,
403,
12,
19380,
29,
403,
12,
1011,
958,
304,
267,
291,
14,
12484,
275,
19380,
339,
347,
2196,
63,
12597,
8,
277,
304,
267,
10105,
63,
6574,
275,
13294,
63,
16415,
435,
7576,
435,
1987,
4805,
267,
372,
3778,
14,
2355,
63,
2060,
8,
1267,
29,
24,
12,
8365,
29,
12597,
63,
6574,
9,
339,
347,
1255,
8,
277,
12,
2895,
12,
16182,
29,
403,
12,
1011,
958,
304,
398,
2895,
275,
3778,
14,
513,
2021,
63,
3892,
63,
2718,
63,
9187,
8,
9187,
12,
291,
14,
12484,
12,
16182,
9,
24807,
2203,
275,
942,
398,
367,
6707,
315,
2895,
26,
288,
327,
1265,
883,
1133,
1172,
11077,
7883,
315,
612,
269,
11776,
288,
1862,
275,
6707,
14,
1294,
342,
288,
20700,
275,
1862,
59,
16,
61,
953,
1215,
3643,
275,
469,
355,
283,
1267,
356,
12785,
2377,
14,
9127,
12,
355,
283,
11929,
356,
488,
12,
355,
283,
6574,
356,
788,
4371,
63,
16415,
1673,
7022,
297,
1674,
12,
6809,
63,
2255,
288,
789,
953,
327,
664,
2222,
13,
885,
2633,
340,
2013,
288,
862,
26,
355,
367,
1215,
315,
1862,
59,
17,
10688,
490,
536,
12,
574,
275,
1215,
14,
1294,
23917,
490,
702,
8,
354,
315,
1215,
3643,
9,
490,
340,
536,
508,
283,
1267,
356,
717,
1215,
3643,
59,
354,
61,
275,
1109,
8,
585,
9,
490,
916,
536,
508,
283,
6574,
356,
717,
675,
63,
6574,
9811,
717,
340,
3872,
4589,
315,
574,
26,
29157,
675,
63,
6574,
14,
740,
11917,
717,
675,
63,
6574,
14,
2880,
8,
585,
14,
1814,
5102,
12,
23324,
1959,
1294,
5102,
1333,
717,
1215,
3643,
459,
6574,
418,
275,
675,
63,
6574,
490,
587,
26,
717,
1215,
3643,
59,
354,
61,
275,
574,
288,
871,
334,
3393,
12,
9070,
395,
325,
26,
355,
746,
2552,
14,
29107,
8,
69,
9,
953,
2582,
221,
275,
1215,
3643,
459,
1267,
418,
288,
14645,
275,
1215,
3643,
459,
11929,
418,
288,
675,
63,
6574,
275,
1215,
3643,
459,
6574,
418,
953,
327,
664,
2505,
503,
1218,
652,
340,
570,
3181,
1133,
2187,
288,
931,
275,
3778,
14,
515,
63,
10772,
1017,
8,
277,
14,
12484,
12,
20700,
9,
288,
340,
440,
747,
14,
515,
14,
2444,
8,
515,
304,
355,
931,
694,
275,
747,
14,
515,
14,
3475,
8,
515,
9,
355,
340,
440,
747,
14,
515,
14,
6027,
8,
515,
694,
304,
490,
862,
26,
717,
747,
14,
8347,
8,
515,
694,
12,
818,
29,
1780,
383,
9,
490,
871,
6440,
12,
325,
26,
717,
746,
2552,
14,
29107,
480,
11250,
1218,
314,
931,
367,
314,
2505,
4237,
26,
450,
83,
334,
705,
1990,
450,
83,
2924,
450,
334,
515,
694,
12,
620,
8,
69,
1724,
2234,
8365,
275,
10587,
904,
779,
5675,
8,
875,
12,
67,
12,
67,
9,
367,
286,
315,
675,
63,
6574,
6575,
1814,
14088,
26516,
1814,
27769,
17483,
355,
2505,
275,
6522,
904,
8,
2355,
14,
5095,
8,
6574,
9,
367,
485,
315,
1425,
8,
1267,
430,
2234,
340,
14645,
365,
440,
488,
26,
490,
10105,
275,
291,
14,
2355,
63,
12597,
342,
490,
1564,
275,
1543,
83,
10105,
2458,
83,
7,
450,
334,
2060,
12,
10105,
9,
355,
587,
26,
490,
1564,
275,
2505,
355,
543,
1551,
8,
515,
12,
283,
87,
358,
465,
289,
26,
490,
747,
14,
11693,
8,
515,
12,
378,
6683,
9,
490,
289,
14,
952,
8,
1317,
435,
1557,
78,
358,
288,
587,
26,
355,
1564,
275,
1551,
8,
515,
680,
739,
1252,
6735,
342,
355,
7375,
275,
1564,
14,
1623,
360,
5320,
2234,
340,
7375,
2356,
378,
26,
490,
2505,
275,
1564,
1491,
4127,
61,
490,
10105,
275,
1564,
59,
4127,
11,
17,
11455,
1294,
26800,
5832,
17,
61,
355,
587,
26,
490,
2505,
275,
1564,
490,
10105,
275,
488,
2234,
327,
21570,
5839,
12,
1050,
10105,
340,
4124,
355,
340,
334,
11929,
365,
440,
488,
436,
440,
10105,
304,
490,
10105,
275,
291,
14,
2355,
63,
12597,
342,
490,
1564,
275,
1543,
83,
10105,
2458,
83,
7,
450,
334,
2060,
12,
10105,
9,
490,
543,
1551,
8,
515,
12,
283,
87,
358,
465,
289,
26,
717,
747,
14,
11693,
8,
515,
12,
378,
6683,
9,
717,
289,
14,
952,
8,
1317,
435,
1557,
78,
358,
355,
327,
21570,
440,
5839,
12,
2813,
10105,
340,
3451,
355,
916,
334,
11929,
365,
488,
436,
10105,
304,
490,
543,
1551,
8,
515,
12,
283,
87,
358,
465,
289,
26,
717,
747,
14,
11693,
8,
515,
12,
378,
6683,
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,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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
] |
JCROM-Android/jcrom_external_chromium_org
|
chrome/test/functional/perf.py
|
47
|
107008
|
#!/usr/bin/env python
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Basic pyauto performance tests.
For tests that need to be run for multiple iterations (e.g., so that average
and standard deviation values can be reported), the default number of iterations
run for each of these tests is specified by |_DEFAULT_NUM_ITERATIONS|.
That value can optionally be tweaked by setting an environment variable
'NUM_ITERATIONS' to a positive integer, representing the number of iterations
to run. An additional, initial iteration will also be run to "warm up" the
environment, and the result from that initial iteration will be ignored.
Some tests rely on repeatedly appending tabs to Chrome. Occasionally, these
automation calls time out, thereby affecting the timing measurements (see issue
crosbug.com/20503). To work around this, the tests discard timing measurements
that involve automation timeouts. The value |_DEFAULT_MAX_TIMEOUT_COUNT|
specifies the threshold number of timeouts that can be tolerated before the test
fails. To tweak this value, set environment variable 'MAX_TIMEOUT_COUNT' to the
desired threshold value.
"""
import BaseHTTPServer
import commands
import errno
import itertools
import logging
import math
import os
import posixpath
import re
import SimpleHTTPServer
import SocketServer
import signal
import subprocess
import sys
import tempfile
import threading
import time
import timeit
import urllib
import urllib2
import urlparse
import pyauto_functional # Must be imported before pyauto.
import pyauto
import simplejson # Must be imported after pyauto; located in third_party.
from netflix import NetflixTestHelper
import pyauto_utils
import test_utils
import webpagereplay
from youtube import YoutubeTestHelper
_CHROME_BASE_DIR = os.path.abspath(os.path.join(
os.path.dirname(__file__), os.pardir, os.pardir, os.pardir, os.pardir))
def FormatChromePath(posix_path, **kwargs):
"""Convert a path relative to the Chromium root into an OS-specific path.
Args:
posix_path: a path string that may be a format().
Example: 'src/third_party/{module_name}/__init__.py'
kwargs: args for the format replacement.
Example: {'module_name': 'pylib'}
Returns:
an absolute path in the current Chromium tree with formatting applied.
"""
formated_path = posix_path.format(**kwargs)
path_parts = formated_path.split('/')
return os.path.join(_CHROME_BASE_DIR, *path_parts)
def StandardDeviation(values):
"""Returns the standard deviation of |values|."""
avg = Mean(values)
if len(values) < 2 or not avg:
return 0.0
temp_vals = [math.pow(x - avg, 2) for x in values]
return math.sqrt(sum(temp_vals) / (len(temp_vals) - 1))
def Mean(values):
"""Returns the arithmetic mean of |values|."""
if not values or None in values:
return None
return sum(values) / float(len(values))
def GeometricMean(values):
"""Returns the geometric mean of |values|."""
if not values or None in values or [x for x in values if x < 0.0]:
return None
if 0.0 in values:
return 0.0
return math.exp(Mean([math.log(x) for x in values]))
class BasePerfTest(pyauto.PyUITest):
"""Base class for performance tests."""
_DEFAULT_NUM_ITERATIONS = 10 # Keep synced with desktopui_PyAutoPerfTests.py.
_DEFAULT_MAX_TIMEOUT_COUNT = 10
_PERF_OUTPUT_MARKER_PRE = '_PERF_PRE_'
_PERF_OUTPUT_MARKER_POST = '_PERF_POST_'
def setUp(self):
"""Performs necessary setup work before running each test."""
self._num_iterations = self._DEFAULT_NUM_ITERATIONS
if 'NUM_ITERATIONS' in os.environ:
self._num_iterations = int(os.environ['NUM_ITERATIONS'])
self._max_timeout_count = self._DEFAULT_MAX_TIMEOUT_COUNT
if 'MAX_TIMEOUT_COUNT' in os.environ:
self._max_timeout_count = int(os.environ['MAX_TIMEOUT_COUNT'])
self._timeout_count = 0
# For users who want to see local perf graphs for Chrome when running the
# tests on their own machines.
self._local_perf_dir = None
if 'LOCAL_PERF_DIR' in os.environ:
self._local_perf_dir = os.environ['LOCAL_PERF_DIR']
if not os.path.exists(self._local_perf_dir):
self.fail('LOCAL_PERF_DIR environment variable specified as %s, '
'but this directory does not exist.' % self._local_perf_dir)
# When outputting perf graph information on-the-fly for Chrome, this
# variable lets us know whether a perf measurement is for a new test
# execution, or the current test execution.
self._seen_graph_lines = {}
pyauto.PyUITest.setUp(self)
# Flush all buffers to disk and wait until system calms down. Must be done
# *after* calling pyauto.PyUITest.setUp, since that is where Chrome is
# killed and re-initialized for a new test.
# TODO(dennisjeffrey): Implement wait for idle CPU on Windows/Mac.
if self.IsLinux(): # IsLinux() also implies IsChromeOS().
os.system('sync')
self._WaitForIdleCPU(60.0, 0.05)
def _IsPIDRunning(self, pid):
"""Checks if a given process id is running.
Args:
pid: The process id of the process to check.
Returns:
True if the process is running. False if not.
"""
try:
# Note that this sends the signal 0, which should not interfere with the
# process.
os.kill(pid, 0)
except OSError, err:
if err.errno == errno.ESRCH:
return False
try:
with open('/proc/%s/status' % pid) as proc_file:
if 'zombie' in proc_file.read():
return False
except IOError:
return False
return True
def _GetAllDescendentProcesses(self, pid):
pstree_out = subprocess.check_output(['pstree', '-p', '%s' % pid])
children = re.findall('\((\d+)\)', pstree_out)
return [int(pid) for pid in children]
def _WaitForChromeExit(self, browser_info, timeout):
pid = browser_info['browser_pid']
chrome_pids = self._GetAllDescendentProcesses(pid)
initial_time = time.time()
while time.time() - initial_time < timeout:
if any([self._IsPIDRunning(pid) for pid in chrome_pids]):
time.sleep(1)
else:
logging.info('_WaitForChromeExit() took: %s seconds',
time.time() - initial_time)
return
self.fail('_WaitForChromeExit() did not finish within %s seconds' %
timeout)
def tearDown(self):
if self._IsPGOMode():
browser_info = self.GetBrowserInfo()
pid = browser_info['browser_pid']
# session_manager kills chrome without waiting for it to cleanly exit.
# Until that behavior is changed, we stop it and wait for Chrome to exit
# cleanly before restarting it. See:
# crbug.com/264717
subprocess.call(['sudo', 'pkill', '-STOP', 'session_manager'])
os.kill(pid, signal.SIGINT)
self._WaitForChromeExit(browser_info, 120)
subprocess.call(['sudo', 'pkill', '-CONT', 'session_manager'])
pyauto.PyUITest.tearDown(self)
def _IsPGOMode(self):
return 'USE_PGO' in os.environ
def _WaitForIdleCPU(self, timeout, utilization):
"""Waits for the CPU to become idle (< utilization).
Args:
timeout: The longest time in seconds to wait before throwing an error.
utilization: The CPU usage below which the system should be considered
idle (between 0 and 1.0 independent of cores/hyperthreads).
"""
time_passed = 0.0
fraction_non_idle_time = 1.0
logging.info('Starting to wait up to %fs for idle CPU...', timeout)
while fraction_non_idle_time >= utilization:
cpu_usage_start = self._GetCPUUsage()
time.sleep(2)
time_passed += 2.0
cpu_usage_end = self._GetCPUUsage()
fraction_non_idle_time = \
self._GetFractionNonIdleCPUTime(cpu_usage_start, cpu_usage_end)
logging.info('Current CPU utilization = %f.', fraction_non_idle_time)
if time_passed > timeout:
self._LogProcessActivity()
message = ('CPU did not idle after %fs wait (utilization = %f).' % (
time_passed, fraction_non_idle_time))
# crosbug.com/37389
if self._IsPGOMode():
logging.info(message)
logging.info('Still continuing because we are in PGO mode.')
return
self.fail(message)
logging.info('Wait for idle CPU took %fs (utilization = %f).',
time_passed, fraction_non_idle_time)
def _LogProcessActivity(self):
"""Logs the output of top on Linux/Mac/CrOS.
TODO: use taskmgr or similar on Windows.
"""
if self.IsLinux() or self.IsMac(): # IsLinux() also implies IsChromeOS().
logging.info('Logging current process activity using top.')
cmd = 'top -b -d1 -n1'
if self.IsMac():
cmd = 'top -l1'
p = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT, close_fds=True)
output = p.stdout.read()
logging.info(output)
else:
logging.info('Process activity logging not implemented on this OS.')
def _AppendTab(self, url):
"""Appends a tab and increments a counter if the automation call times out.
Args:
url: The string url to which the appended tab should be navigated.
"""
if not self.AppendTab(pyauto.GURL(url)):
self._timeout_count += 1
def _MeasureElapsedTime(self, python_command, num_invocations=1):
"""Measures time (in msec) to execute a python command one or more times.
Args:
python_command: A callable.
num_invocations: An integer number of times to invoke the given command.
Returns:
The time required to execute the python command the specified number of
times, in milliseconds as a float.
"""
assert callable(python_command)
def RunCommand():
for _ in range(num_invocations):
python_command()
timer = timeit.Timer(stmt=RunCommand)
return timer.timeit(number=1) * 1000 # Convert seconds to milliseconds.
def _OutputPerfForStandaloneGraphing(self, graph_name, description, value,
units, units_x, is_stacked):
"""Outputs perf measurement data to a local folder to be graphed.
This function only applies to Chrome desktop, and assumes that environment
variable 'LOCAL_PERF_DIR' has been specified and refers to a valid directory
on the local machine.
Args:
graph_name: A string name for the graph associated with this performance
value.
description: A string description of the performance value. Should not
include spaces.
value: Either a single numeric value representing a performance
measurement, or else a list of (x, y) tuples representing one or more
long-running performance measurements, where 'x' is an x-axis value
(such as an iteration number) and 'y' is the corresponding performance
measurement. If a list of tuples is given, then the |units_x|
argument must also be specified.
units: A string representing the units of the performance measurement(s).
Should not include spaces.
units_x: A string representing the units of the x-axis values associated
with the performance measurements, such as 'iteration' if the x values
are iteration numbers. If this argument is specified, then the
|value| argument must be a list of (x, y) tuples.
is_stacked: True to draw a "stacked" graph. First-come values are
stacked at bottom by default.
"""
revision_num_file = os.path.join(self._local_perf_dir, 'last_revision.dat')
if os.path.exists(revision_num_file):
with open(revision_num_file) as f:
revision = int(f.read())
else:
revision = 0
if not self._seen_graph_lines:
# We're about to output data for a new test run.
revision += 1
# Update graphs.dat.
existing_graphs = []
graphs_file = os.path.join(self._local_perf_dir, 'graphs.dat')
if os.path.exists(graphs_file):
with open(graphs_file) as f:
existing_graphs = simplejson.loads(f.read())
is_new_graph = True
for graph in existing_graphs:
if graph['name'] == graph_name:
is_new_graph = False
break
if is_new_graph:
new_graph = {
'name': graph_name,
'units': units,
'important': False,
}
if units_x:
new_graph['units_x'] = units_x
existing_graphs.append(new_graph)
with open(graphs_file, 'w') as f:
f.write(simplejson.dumps(existing_graphs))
os.chmod(graphs_file, 0755)
# Update data file for this particular graph.
existing_lines = []
data_file = os.path.join(self._local_perf_dir, graph_name + '-summary.dat')
if os.path.exists(data_file):
with open(data_file) as f:
existing_lines = f.readlines()
existing_lines = map(
simplejson.loads, map(lambda x: x.strip(), existing_lines))
seen_key = graph_name
# We assume that the first line |existing_lines[0]| is the latest.
if units_x:
new_line = {
'rev': revision,
'traces': { description: [] }
}
if seen_key in self._seen_graph_lines:
# We've added points previously for this graph line in the current
# test execution, so retrieve the original set of points specified in
# the most recent revision in the data file.
new_line = existing_lines[0]
if not description in new_line['traces']:
new_line['traces'][description] = []
for x_value, y_value in value:
new_line['traces'][description].append([str(x_value), str(y_value)])
else:
new_line = {
'rev': revision,
'traces': { description: [str(value), str(0.0)] }
}
if is_stacked:
new_line['stack'] = True
if 'stack_order' not in new_line:
new_line['stack_order'] = []
if description not in new_line['stack_order']:
new_line['stack_order'].append(description)
if seen_key in self._seen_graph_lines:
# Update results for the most recent revision.
existing_lines[0] = new_line
else:
# New results for a new revision.
existing_lines.insert(0, new_line)
self._seen_graph_lines[seen_key] = True
existing_lines = map(simplejson.dumps, existing_lines)
with open(data_file, 'w') as f:
f.write('\n'.join(existing_lines))
os.chmod(data_file, 0755)
with open(revision_num_file, 'w') as f:
f.write(str(revision))
def _OutputPerfGraphValue(self, description, value, units,
graph_name, units_x=None, is_stacked=False):
"""Outputs a performance value to have it graphed on the performance bots.
The output format differs, depending on whether the current platform is
Chrome desktop or ChromeOS.
For ChromeOS, the performance bots have a 30-character limit on the length
of the key associated with a performance value. A key on ChromeOS is
considered to be of the form "units_description" (for example,
"milliseconds_NewTabPage"), and is created from the |units| and
|description| passed as input to this function. Any characters beyond the
length 30 limit are truncated before results are stored in the autotest
database.
Args:
description: A string description of the performance value. Should not
include spaces.
value: Either a numeric value representing a performance measurement, or
a list of values to be averaged. Lists may also contain (x, y) tuples
representing one or more performance measurements, where 'x' is an
x-axis value (such as an iteration number) and 'y' is the
corresponding performance measurement. If a list of tuples is given,
the |units_x| argument must also be specified.
units: A string representing the units of the performance measurement(s).
Should not include spaces.
graph_name: A string name for the graph associated with this performance
value. Only used on Chrome desktop.
units_x: A string representing the units of the x-axis values associated
with the performance measurements, such as 'iteration' if the x values
are iteration numbers. If this argument is specified, then the
|value| argument must be a list of (x, y) tuples.
is_stacked: True to draw a "stacked" graph. First-come values are
stacked at bottom by default.
"""
if (isinstance(value, list) and value[0] is not None and
isinstance(value[0], tuple)):
assert units_x
if units_x:
assert isinstance(value, list)
if self.IsChromeOS():
# Autotest doesn't support result lists.
autotest_value = value
if (isinstance(value, list) and value[0] is not None and
not isinstance(value[0], tuple)):
autotest_value = Mean(value)
if units_x:
# TODO(dennisjeffrey): Support long-running performance measurements on
# ChromeOS in a way that can be graphed: crosbug.com/21881.
pyauto_utils.PrintPerfResult(graph_name, description, autotest_value,
units + ' ' + units_x)
else:
# Output short-running performance results in a format understood by
# autotest.
perf_key = '%s_%s' % (units, description)
if len(perf_key) > 30:
logging.warning('The description "%s" will be truncated to "%s" '
'(length 30) when added to the autotest database.',
perf_key, perf_key[:30])
print '\n%s(\'%s\', %f)%s' % (self._PERF_OUTPUT_MARKER_PRE,
perf_key, autotest_value,
self._PERF_OUTPUT_MARKER_POST)
# Also output results in the format recognized by buildbot, for cases
# in which these tests are run on chromeOS through buildbot. Since
# buildbot supports result lists, it's ok for |value| to be a list here.
pyauto_utils.PrintPerfResult(graph_name, description, value, units)
sys.stdout.flush()
else:
# TODO(dmikurube): Support stacked graphs in PrintPerfResult.
# See http://crbug.com/122119.
if units_x:
pyauto_utils.PrintPerfResult(graph_name, description, value,
units + ' ' + units_x)
else:
pyauto_utils.PrintPerfResult(graph_name, description, value, units)
if self._local_perf_dir:
self._OutputPerfForStandaloneGraphing(
graph_name, description, value, units, units_x, is_stacked)
def _OutputEventForStandaloneGraphing(self, description, event_list):
"""Outputs event information to a local folder to be graphed.
See function _OutputEventGraphValue below for a description of an event.
This function only applies to Chrome Endure tests running on Chrome desktop,
and assumes that environment variable 'LOCAL_PERF_DIR' has been specified
and refers to a valid directory on the local machine.
Args:
description: A string description of the event. Should not include
spaces.
event_list: A list of (x, y) tuples representing one or more events
occurring during an endurance test, where 'x' is the time of the event
(in seconds since the start of the test), and 'y' is a dictionary
representing relevant data associated with that event (as key/value
pairs).
"""
revision_num_file = os.path.join(self._local_perf_dir, 'last_revision.dat')
if os.path.exists(revision_num_file):
with open(revision_num_file) as f:
revision = int(f.read())
else:
revision = 0
if not self._seen_graph_lines:
# We're about to output data for a new test run.
revision += 1
existing_lines = []
data_file = os.path.join(self._local_perf_dir, '_EVENT_-summary.dat')
if os.path.exists(data_file):
with open(data_file) as f:
existing_lines = f.readlines()
existing_lines = map(eval, map(lambda x: x.strip(), existing_lines))
seen_event_type = description
value_list = []
if seen_event_type in self._seen_graph_lines:
# We've added events previously for this event type in the current
# test execution, so retrieve the original set of values specified in
# the most recent revision in the data file.
value_list = existing_lines[0]['events'][description]
for event_time, event_data in event_list:
value_list.append([str(event_time), event_data])
new_events = {
description: value_list
}
new_line = {
'rev': revision,
'events': new_events
}
if seen_event_type in self._seen_graph_lines:
# Update results for the most recent revision.
existing_lines[0] = new_line
else:
# New results for a new revision.
existing_lines.insert(0, new_line)
self._seen_graph_lines[seen_event_type] = True
existing_lines = map(str, existing_lines)
with open(data_file, 'w') as f:
f.write('\n'.join(existing_lines))
os.chmod(data_file, 0755)
with open(revision_num_file, 'w') as f:
f.write(str(revision))
def _OutputEventGraphValue(self, description, event_list):
"""Outputs a set of events to have them graphed on the Chrome Endure bots.
An "event" can be anything recorded by a performance test that occurs at
particular times during a test execution. For example, a garbage collection
in the v8 heap can be considered an event. An event is distinguished from a
regular perf measurement in two ways: (1) an event is depicted differently
in the performance graphs than performance measurements; (2) an event can
be associated with zero or more data fields describing relevant information
associated with the event. For example, a garbage collection event will
occur at a particular time, and it may be associated with data such as
the number of collected bytes and/or the length of time it took to perform
the garbage collection.
This function only applies to Chrome Endure tests running on Chrome desktop.
Args:
description: A string description of the event. Should not include
spaces.
event_list: A list of (x, y) tuples representing one or more events
occurring during an endurance test, where 'x' is the time of the event
(in seconds since the start of the test), and 'y' is a dictionary
representing relevant data associated with that event (as key/value
pairs).
"""
pyauto_utils.PrintPerfResult('_EVENT_', description, event_list, '')
if self._local_perf_dir:
self._OutputEventForStandaloneGraphing(description, event_list)
def _PrintSummaryResults(self, description, values, units, graph_name):
"""Logs summary measurement information.
This function computes and outputs the average and standard deviation of
the specified list of value measurements. It also invokes
_OutputPerfGraphValue() with the computed *average* value, to ensure the
average value can be plotted in a performance graph.
Args:
description: A string description for the specified results.
values: A list of numeric value measurements.
units: A string specifying the units for the specified measurements.
graph_name: A string name for the graph associated with this performance
value. Only used on Chrome desktop.
"""
logging.info('Overall results for: %s', description)
if values:
logging.info(' Average: %f %s', Mean(values), units)
logging.info(' Std dev: %f %s', StandardDeviation(values), units)
self._OutputPerfGraphValue(description, values, units, graph_name)
else:
logging.info('No results to report.')
def _RunNewTabTest(self, description, open_tab_command, graph_name,
num_tabs=1):
"""Runs a perf test that involves opening new tab(s).
This helper function can be called from different tests to do perf testing
with different types of tabs. It is assumed that the |open_tab_command|
will open up a single tab.
Args:
description: A string description of the associated tab test.
open_tab_command: A callable that will open a single tab.
graph_name: A string name for the performance graph associated with this
test. Only used on Chrome desktop.
num_tabs: The number of tabs to open, i.e., the number of times to invoke
the |open_tab_command|.
"""
assert callable(open_tab_command)
timings = []
for iteration in range(self._num_iterations + 1):
orig_timeout_count = self._timeout_count
elapsed_time = self._MeasureElapsedTime(open_tab_command,
num_invocations=num_tabs)
# Only count the timing measurement if no automation call timed out.
if self._timeout_count == orig_timeout_count:
# Ignore the first iteration.
if iteration:
timings.append(elapsed_time)
logging.info('Iteration %d of %d: %f milliseconds', iteration,
self._num_iterations, elapsed_time)
self.assertTrue(self._timeout_count <= self._max_timeout_count,
msg='Test exceeded automation timeout threshold.')
self.assertEqual(1 + num_tabs, self.GetTabCount(),
msg='Did not open %d new tab(s).' % num_tabs)
for _ in range(num_tabs):
self.CloseTab(tab_index=1)
self._PrintSummaryResults(description, timings, 'milliseconds', graph_name)
def _GetConfig(self):
"""Load perf test configuration file.
Returns:
A dictionary that represents the config information.
"""
config_file = os.path.join(os.path.dirname(__file__), 'perf.cfg')
config = {'username': None,
'password': None,
'google_account_url': 'https://accounts.google.com/',
'gmail_url': 'https://www.gmail.com',
'plus_url': 'https://plus.google.com',
'docs_url': 'https://docs.google.com'}
if os.path.exists(config_file):
try:
new_config = pyauto.PyUITest.EvalDataFrom(config_file)
for key in new_config:
if new_config.get(key) is not None:
config[key] = new_config.get(key)
except SyntaxError, e:
logging.info('Could not read %s: %s', config_file, str(e))
return config
def _LoginToGoogleAccount(self, account_key='test_google_account'):
"""Logs in to a test Google account.
Login with user-defined credentials if they exist.
Else login with private test credentials if they exist.
Else fail.
Args:
account_key: The string key in private_tests_info.txt which is associated
with the test account login credentials to use. It will only
be used when fail to load user-defined credentials.
Raises:
RuntimeError: if could not get credential information.
"""
private_file = os.path.join(pyauto.PyUITest.DataDir(), 'pyauto_private',
'private_tests_info.txt')
config_file = os.path.join(os.path.dirname(__file__), 'perf.cfg')
config = self._GetConfig()
google_account_url = config.get('google_account_url')
username = config.get('username')
password = config.get('password')
if username and password:
logging.info(
'Using google account credential from %s',
os.path.join(os.path.dirname(__file__), 'perf.cfg'))
elif os.path.exists(private_file):
creds = self.GetPrivateInfo()[account_key]
username = creds['username']
password = creds['password']
logging.info(
'User-defined credentials not found,' +
' using private test credentials instead.')
else:
message = 'No user-defined or private test ' \
'credentials could be found. ' \
'Please specify credential information in %s.' \
% config_file
raise RuntimeError(message)
test_utils.GoogleAccountsLogin(
self, username, password, url=google_account_url)
self.NavigateToURL('about:blank') # Clear the existing tab.
def _GetCPUUsage(self):
"""Returns machine's CPU usage.
This function uses /proc/stat to identify CPU usage, and therefore works
only on Linux/ChromeOS.
Returns:
A dictionary with 'user', 'nice', 'system' and 'idle' values.
Sample dictionary:
{
'user': 254544,
'nice': 9,
'system': 254768,
'idle': 2859878,
}
"""
try:
f = open('/proc/stat')
cpu_usage_str = f.readline().split()
f.close()
except IOError, e:
self.fail('Could not retrieve CPU usage: ' + str(e))
return {
'user': int(cpu_usage_str[1]),
'nice': int(cpu_usage_str[2]),
'system': int(cpu_usage_str[3]),
'idle': int(cpu_usage_str[4])
}
def _GetFractionNonIdleCPUTime(self, cpu_usage_start, cpu_usage_end):
"""Computes the fraction of CPU time spent non-idling.
This function should be invoked using before/after values from calls to
_GetCPUUsage().
"""
time_non_idling_end = (cpu_usage_end['user'] + cpu_usage_end['nice'] +
cpu_usage_end['system'])
time_non_idling_start = (cpu_usage_start['user'] + cpu_usage_start['nice'] +
cpu_usage_start['system'])
total_time_end = (cpu_usage_end['user'] + cpu_usage_end['nice'] +
cpu_usage_end['system'] + cpu_usage_end['idle'])
total_time_start = (cpu_usage_start['user'] + cpu_usage_start['nice'] +
cpu_usage_start['system'] + cpu_usage_start['idle'])
return ((float(time_non_idling_end) - time_non_idling_start) /
(total_time_end - total_time_start))
def ExtraChromeFlags(self):
"""Ensures Chrome is launched with custom flags.
Returns:
A list of extra flags to pass to Chrome when it is launched.
"""
flags = super(BasePerfTest, self).ExtraChromeFlags()
# Window size impacts a variety of perf tests, ensure consistency.
flags.append('--window-size=1024,768')
if self._IsPGOMode():
flags = flags + ['--child-clean-exit', '--no-sandbox']
return flags
class TabPerfTest(BasePerfTest):
"""Tests that involve opening tabs."""
def testNewTab(self):
"""Measures time to open a new tab."""
self._RunNewTabTest('NewTabPage',
lambda: self._AppendTab('chrome://newtab'), 'open_tab')
def testNewTabFlash(self):
"""Measures time to open a new tab navigated to a flash page."""
self.assertTrue(
os.path.exists(os.path.join(self.ContentDataDir(), 'plugin',
'flash.swf')),
msg='Missing required flash data file.')
url = self.GetFileURLForContentDataPath('plugin', 'flash.swf')
self._RunNewTabTest('NewTabFlashPage', lambda: self._AppendTab(url),
'open_tab')
def test20Tabs(self):
"""Measures time to open 20 tabs."""
self._RunNewTabTest('20TabsNewTabPage',
lambda: self._AppendTab('chrome://newtab'),
'open_20_tabs', num_tabs=20)
class BenchmarkPerfTest(BasePerfTest):
"""Benchmark performance tests."""
def testV8BenchmarkSuite(self):
"""Measures score from v8 benchmark suite."""
url = self.GetFileURLForDataPath('v8_benchmark_v6', 'run.html')
def _RunBenchmarkOnce(url):
"""Runs the v8 benchmark suite once and returns the results in a dict."""
self.assertTrue(self.AppendTab(pyauto.GURL(url)),
msg='Failed to append tab for v8 benchmark suite.')
js_done = """
var val = document.getElementById("status").innerHTML;
window.domAutomationController.send(val);
"""
self.assertTrue(
self.WaitUntil(
lambda: 'Score:' in self.ExecuteJavascript(js_done, tab_index=1),
timeout=300, expect_retval=True, retry_sleep=1),
msg='Timed out when waiting for v8 benchmark score.')
js_get_results = """
var result = {};
result['final_score'] = document.getElementById("status").innerHTML;
result['all_results'] = document.getElementById("results").innerHTML;
window.domAutomationController.send(JSON.stringify(result));
"""
results = eval(self.ExecuteJavascript(js_get_results, tab_index=1))
score_pattern = '(\w+): (\d+)'
final_score = re.search(score_pattern, results['final_score']).group(2)
result_dict = {'final_score': int(final_score)}
for match in re.finditer(score_pattern, results['all_results']):
benchmark_name = match.group(1)
benchmark_score = match.group(2)
result_dict[benchmark_name] = int(benchmark_score)
self.CloseTab(tab_index=1)
return result_dict
timings = {}
for iteration in xrange(self._num_iterations + 1):
result_dict = _RunBenchmarkOnce(url)
# Ignore the first iteration.
if iteration:
for key, val in result_dict.items():
timings.setdefault(key, []).append(val)
logging.info('Iteration %d of %d:\n%s', iteration,
self._num_iterations, self.pformat(result_dict))
for key, val in timings.items():
if key == 'final_score':
self._PrintSummaryResults('V8Benchmark', val, 'score',
'v8_benchmark_final')
else:
self._PrintSummaryResults('V8Benchmark-%s' % key, val, 'score',
'v8_benchmark_individual')
def testSunSpider(self):
"""Runs the SunSpider javascript benchmark suite."""
url = self.GetFileURLForDataPath('sunspider', 'sunspider-driver.html')
self.assertTrue(self.AppendTab(pyauto.GURL(url)),
msg='Failed to append tab for SunSpider benchmark suite.')
js_is_done = """
var done = false;
if (document.getElementById("console"))
done = true;
window.domAutomationController.send(JSON.stringify(done));
"""
self.assertTrue(
self.WaitUntil(
lambda: self.ExecuteJavascript(js_is_done, tab_index=1),
timeout=300, expect_retval='true', retry_sleep=1),
msg='Timed out when waiting for SunSpider benchmark score.')
js_get_results = """
window.domAutomationController.send(
document.getElementById("console").innerHTML);
"""
# Append '<br>' to the result to simplify regular expression matching.
results = self.ExecuteJavascript(js_get_results, tab_index=1) + '<br>'
total = re.search('Total:\s*([\d.]+)ms', results).group(1)
logging.info('Total: %f ms', float(total))
self._OutputPerfGraphValue('SunSpider-total', float(total), 'ms',
'sunspider_total')
for match_category in re.finditer('\s\s(\w+):\s*([\d.]+)ms.+?<br><br>',
results):
category_name = match_category.group(1)
category_result = match_category.group(2)
logging.info('Benchmark "%s": %f ms', category_name,
float(category_result))
self._OutputPerfGraphValue('SunSpider-' + category_name,
float(category_result), 'ms',
'sunspider_individual')
for match_result in re.finditer('<br>\s\s\s\s([\w-]+):\s*([\d.]+)ms',
match_category.group(0)):
result_name = match_result.group(1)
result_value = match_result.group(2)
logging.info(' Result "%s-%s": %f ms', category_name, result_name,
float(result_value))
self._OutputPerfGraphValue(
'SunSpider-%s-%s' % (category_name, result_name),
float(result_value), 'ms', 'sunspider_individual')
def testDromaeoSuite(self):
"""Measures results from Dromaeo benchmark suite."""
url = self.GetFileURLForDataPath('dromaeo', 'index.html')
self.assertTrue(self.AppendTab(pyauto.GURL(url + '?dromaeo')),
msg='Failed to append tab for Dromaeo benchmark suite.')
js_is_ready = """
var val = document.getElementById('pause').value;
window.domAutomationController.send(val);
"""
self.assertTrue(
self.WaitUntil(
lambda: self.ExecuteJavascript(js_is_ready, tab_index=1),
timeout=30, expect_retval='Run', retry_sleep=1),
msg='Timed out when waiting for Dromaeo benchmark to load.')
js_run = """
$('#pause').val('Run').click();
window.domAutomationController.send('done');
"""
self.ExecuteJavascript(js_run, tab_index=1)
js_is_done = """
var val = document.getElementById('timebar').innerHTML;
window.domAutomationController.send(val);
"""
self.assertTrue(
self.WaitUntil(
lambda: 'Total' in self.ExecuteJavascript(js_is_done, tab_index=1),
timeout=900, expect_retval=True, retry_sleep=2),
msg='Timed out when waiting for Dromaeo benchmark to complete.')
js_get_results = """
var result = {};
result['total_result'] = $('#timebar strong').html();
result['all_results'] = {};
$('.result-item.done').each(function (i) {
var group_name = $(this).find('.test b').html().replace(':', '');
var group_results = {};
group_results['result'] =
$(this).find('span').html().replace('runs/s', '')
group_results['sub_groups'] = {}
$(this).find('li').each(function (i) {
var sub_name = $(this).find('b').html().replace(':', '');
group_results['sub_groups'][sub_name] =
$(this).text().match(/: ([\d.]+)/)[1]
});
result['all_results'][group_name] = group_results;
});
window.domAutomationController.send(JSON.stringify(result));
"""
results = eval(self.ExecuteJavascript(js_get_results, tab_index=1))
total_result = results['total_result']
logging.info('Total result: ' + total_result)
self._OutputPerfGraphValue('Dromaeo-total', float(total_result),
'runsPerSec', 'dromaeo_total')
for group_name, group in results['all_results'].iteritems():
logging.info('Benchmark "%s": %s', group_name, group['result'])
self._OutputPerfGraphValue('Dromaeo-' + group_name.replace(' ', ''),
float(group['result']), 'runsPerSec',
'dromaeo_individual')
for benchmark_name, benchmark_score in group['sub_groups'].iteritems():
logging.info(' Result "%s": %s', benchmark_name, benchmark_score)
def testSpaceport(self):
"""Measures results from Spaceport benchmark suite."""
# TODO(tonyg): Test is failing on bots. Diagnose and re-enable.
pass
# url = self.GetFileURLForDataPath('third_party', 'spaceport', 'index.html')
# self.assertTrue(self.AppendTab(pyauto.GURL(url + '?auto')),
# msg='Failed to append tab for Spaceport benchmark suite.')
#
# # The test reports results to console.log in the format "name: value".
# # Inject a bit of JS to intercept those.
# js_collect_console_log = """
# window.__pyautoresult = {};
# window.console.log = function(str) {
# if (!str) return;
# var key_val = str.split(': ');
# if (!key_val.length == 2) return;
# __pyautoresult[key_val[0]] = key_val[1];
# };
# window.domAutomationController.send('done');
# """
# self.ExecuteJavascript(js_collect_console_log, tab_index=1)
#
# def _IsDone():
# expected_num_results = 30 # The number of tests in benchmark.
# results = eval(self.ExecuteJavascript(js_get_results, tab_index=1))
# return expected_num_results == len(results)
#
# js_get_results = """
# window.domAutomationController.send(
# JSON.stringify(window.__pyautoresult));
# """
# self.assertTrue(
# self.WaitUntil(_IsDone, timeout=1200, expect_retval=True,
# retry_sleep=5),
# msg='Timed out when waiting for Spaceport benchmark to complete.')
# results = eval(self.ExecuteJavascript(js_get_results, tab_index=1))
#
# for key in results:
# suite, test = key.split('.')
# value = float(results[key])
# self._OutputPerfGraphValue(test, value, 'ObjectsAt30FPS', suite)
# self._PrintSummaryResults('Overall', [float(x) for x in results.values()],
# 'ObjectsAt30FPS', 'Overall')
class LiveWebappLoadTest(BasePerfTest):
"""Tests that involve performance measurements of live webapps.
These tests connect to live webpages (e.g., Gmail, Calendar, Docs) and are
therefore subject to network conditions. These tests are meant to generate
"ball-park" numbers only (to see roughly how long things take to occur from a
user's perspective), and are not expected to be precise.
"""
def testNewTabGmail(self):
"""Measures time to open a tab to a logged-in Gmail account.
Timing starts right before the new tab is opened, and stops as soon as the
webpage displays the substring 'Last account activity:'.
"""
EXPECTED_SUBSTRING = 'Last account activity:'
def _SubstringExistsOnPage():
js = """
var frame = document.getElementById("canvas_frame");
var divs = frame.contentDocument.getElementsByTagName("div");
for (var i = 0; i < divs.length; ++i) {
if (divs[i].innerHTML.indexOf("%s") >= 0)
window.domAutomationController.send("true");
}
window.domAutomationController.send("false");
""" % EXPECTED_SUBSTRING
return self.ExecuteJavascript(js, tab_index=1)
def _RunSingleGmailTabOpen():
self._AppendTab('http://www.gmail.com')
self.assertTrue(self.WaitUntil(_SubstringExistsOnPage, timeout=120,
expect_retval='true', retry_sleep=0.10),
msg='Timed out waiting for expected Gmail string.')
self._LoginToGoogleAccount()
self._RunNewTabTest('NewTabGmail', _RunSingleGmailTabOpen,
'open_tab_live_webapp')
def testNewTabCalendar(self):
"""Measures time to open a tab to a logged-in Calendar account.
Timing starts right before the new tab is opened, and stops as soon as the
webpage displays the calendar print button (title 'Print my calendar').
"""
EXPECTED_SUBSTRING = 'Month'
def _DivTitleStartsWith():
js = """
var divs = document.getElementsByTagName("div");
for (var i = 0; i < divs.length; ++i) {
if (divs[i].innerHTML == "%s")
window.domAutomationController.send("true");
}
window.domAutomationController.send("false");
""" % EXPECTED_SUBSTRING
return self.ExecuteJavascript(js, tab_index=1)
def _RunSingleCalendarTabOpen():
self._AppendTab('http://calendar.google.com')
self.assertTrue(self.WaitUntil(_DivTitleStartsWith, timeout=120,
expect_retval='true', retry_sleep=0.10),
msg='Timed out waiting for expected Calendar string.')
self._LoginToGoogleAccount()
self._RunNewTabTest('NewTabCalendar', _RunSingleCalendarTabOpen,
'open_tab_live_webapp')
def testNewTabDocs(self):
"""Measures time to open a tab to a logged-in Docs account.
Timing starts right before the new tab is opened, and stops as soon as the
webpage displays the expected substring 'last modified' (case insensitive).
"""
EXPECTED_SUBSTRING = 'sort'
def _SubstringExistsOnPage():
js = """
var divs = document.getElementsByTagName("div");
for (var i = 0; i < divs.length; ++i) {
if (divs[i].innerHTML.toLowerCase().indexOf("%s") >= 0)
window.domAutomationController.send("true");
}
window.domAutomationController.send("false");
""" % EXPECTED_SUBSTRING
return self.ExecuteJavascript(js, tab_index=1)
def _RunSingleDocsTabOpen():
self._AppendTab('http://docs.google.com')
self.assertTrue(self.WaitUntil(_SubstringExistsOnPage, timeout=120,
expect_retval='true', retry_sleep=0.10),
msg='Timed out waiting for expected Docs string.')
self._LoginToGoogleAccount()
self._RunNewTabTest('NewTabDocs', _RunSingleDocsTabOpen,
'open_tab_live_webapp')
class NetflixPerfTest(BasePerfTest, NetflixTestHelper):
"""Test Netflix video performance."""
def __init__(self, methodName='runTest', **kwargs):
pyauto.PyUITest.__init__(self, methodName, **kwargs)
NetflixTestHelper.__init__(self, self)
def tearDown(self):
self.SignOut()
pyauto.PyUITest.tearDown(self)
def testNetflixDroppedFrames(self):
"""Measures the Netflix video dropped frames/second. Runs for 60 secs."""
self.LoginAndStartPlaying()
self.CheckNetflixPlaying(self.IS_PLAYING,
'Player did not start playing the title.')
# Ignore first 10 seconds of video playing so we get smooth videoplayback.
time.sleep(10)
init_dropped_frames = self._GetVideoDroppedFrames()
dropped_frames = []
prev_dropped_frames = 0
for iteration in xrange(60):
# Ignoring initial dropped frames of first 10 seconds.
total_dropped_frames = self._GetVideoDroppedFrames() - init_dropped_frames
dropped_frames_last_sec = total_dropped_frames - prev_dropped_frames
dropped_frames.append(dropped_frames_last_sec)
logging.info('Iteration %d of %d: %f dropped frames in the last second',
iteration + 1, 60, dropped_frames_last_sec)
prev_dropped_frames = total_dropped_frames
# Play the video for some time.
time.sleep(1)
self._PrintSummaryResults('NetflixDroppedFrames', dropped_frames, 'frames',
'netflix_dropped_frames')
def testNetflixCPU(self):
"""Measures the Netflix video CPU usage. Runs for 60 seconds."""
self.LoginAndStartPlaying()
self.CheckNetflixPlaying(self.IS_PLAYING,
'Player did not start playing the title.')
# Ignore first 10 seconds of video playing so we get smooth videoplayback.
time.sleep(10)
init_dropped_frames = self._GetVideoDroppedFrames()
init_video_frames = self._GetVideoFrames()
cpu_usage_start = self._GetCPUUsage()
total_shown_frames = 0
# Play the video for some time.
time.sleep(60)
total_video_frames = self._GetVideoFrames() - init_video_frames
total_dropped_frames = self._GetVideoDroppedFrames() - init_dropped_frames
cpu_usage_end = self._GetCPUUsage()
fraction_non_idle_time = \
self._GetFractionNonIdleCPUTime(cpu_usage_start, cpu_usage_end)
# Counting extrapolation for utilization to play the video.
extrapolation_value = fraction_non_idle_time * \
(float(total_video_frames) + total_dropped_frames) / total_video_frames
logging.info('Netflix CPU extrapolation: %f', extrapolation_value)
self._OutputPerfGraphValue('NetflixCPUExtrapolation', extrapolation_value,
'extrapolation', 'netflix_cpu_extrapolation')
class YoutubePerfTest(BasePerfTest, YoutubeTestHelper):
"""Test Youtube video performance."""
def __init__(self, methodName='runTest', **kwargs):
pyauto.PyUITest.__init__(self, methodName, **kwargs)
YoutubeTestHelper.__init__(self, self)
def _VerifyVideoTotalBytes(self):
"""Returns true if video total bytes information is available."""
return self.GetVideoTotalBytes() > 0
def _VerifyVideoLoadedBytes(self):
"""Returns true if video loaded bytes information is available."""
return self.GetVideoLoadedBytes() > 0
def StartVideoForPerformance(self, video_id='zuzaxlddWbk'):
"""Start the test video with all required buffering."""
self.PlayVideoAndAssert(video_id)
self.ExecuteJavascript("""
ytplayer.setPlaybackQuality('hd720');
window.domAutomationController.send('');
""")
self.AssertPlayerState(state=self.is_playing,
msg='Player did not enter the playing state')
self.assertTrue(
self.WaitUntil(self._VerifyVideoTotalBytes, expect_retval=True),
msg='Failed to get video total bytes information.')
self.assertTrue(
self.WaitUntil(self._VerifyVideoLoadedBytes, expect_retval=True),
msg='Failed to get video loaded bytes information')
loaded_video_bytes = self.GetVideoLoadedBytes()
total_video_bytes = self.GetVideoTotalBytes()
self.PauseVideo()
logging.info('total_video_bytes: %f', total_video_bytes)
# Wait for the video to finish loading.
while total_video_bytes > loaded_video_bytes:
loaded_video_bytes = self.GetVideoLoadedBytes()
logging.info('loaded_video_bytes: %f', loaded_video_bytes)
time.sleep(1)
self.PlayVideo()
# Ignore first 10 seconds of video playing so we get smooth videoplayback.
time.sleep(10)
def testYoutubeDroppedFrames(self):
"""Measures the Youtube video dropped frames/second. Runs for 60 secs.
This test measures Youtube video dropped frames for three different types
of videos like slow, normal and fast motion.
"""
youtube_video = {'Slow': 'VT1-sitWRtY',
'Normal': '2tqK_3mKQUw',
'Fast': '8ETDE0VGJY4',
}
for video_type in youtube_video:
logging.info('Running %s video.', video_type)
self.StartVideoForPerformance(youtube_video[video_type])
init_dropped_frames = self.GetVideoDroppedFrames()
total_dropped_frames = 0
dropped_fps = []
for iteration in xrange(60):
frames = self.GetVideoDroppedFrames() - init_dropped_frames
current_dropped_frames = frames - total_dropped_frames
dropped_fps.append(current_dropped_frames)
logging.info('Iteration %d of %d: %f dropped frames in the last '
'second', iteration + 1, 60, current_dropped_frames)
total_dropped_frames = frames
# Play the video for some time
time.sleep(1)
graph_description = 'YoutubeDroppedFrames' + video_type
self._PrintSummaryResults(graph_description, dropped_fps, 'frames',
'youtube_dropped_frames')
def testYoutubeCPU(self):
"""Measures the Youtube video CPU usage. Runs for 60 seconds.
Measures the Youtube video CPU usage (between 0 and 1), extrapolated to
totalframes in the video by taking dropped frames into account. For smooth
videoplayback this number should be < 0.5..1.0 on a hyperthreaded CPU.
"""
self.StartVideoForPerformance()
init_dropped_frames = self.GetVideoDroppedFrames()
logging.info('init_dropped_frames: %f', init_dropped_frames)
cpu_usage_start = self._GetCPUUsage()
total_shown_frames = 0
for sec_num in xrange(60):
# Play the video for some time.
time.sleep(1)
total_shown_frames = total_shown_frames + self.GetVideoFrames()
logging.info('total_shown_frames: %f', total_shown_frames)
total_dropped_frames = self.GetVideoDroppedFrames() - init_dropped_frames
logging.info('total_dropped_frames: %f', total_dropped_frames)
cpu_usage_end = self._GetCPUUsage()
fraction_non_idle_time = self._GetFractionNonIdleCPUTime(
cpu_usage_start, cpu_usage_end)
logging.info('fraction_non_idle_time: %f', fraction_non_idle_time)
total_frames = total_shown_frames + total_dropped_frames
# Counting extrapolation for utilization to play the video.
extrapolation_value = (fraction_non_idle_time *
(float(total_frames) / total_shown_frames))
logging.info('Youtube CPU extrapolation: %f', extrapolation_value)
# Video is still running so log some more detailed data.
self._LogProcessActivity()
self._OutputPerfGraphValue('YoutubeCPUExtrapolation', extrapolation_value,
'extrapolation', 'youtube_cpu_extrapolation')
class FlashVideoPerfTest(BasePerfTest):
"""General flash video performance tests."""
def FlashVideo1080P(self):
"""Measures total dropped frames and average FPS for a 1080p flash video.
This is a temporary test to be run manually for now, needed to collect some
performance statistics across different ChromeOS devices.
"""
# Open up the test webpage; it's assumed the test will start automatically.
webpage_url = 'http://www/~arscott/fl/FlashVideoTests.html'
self.assertTrue(self.AppendTab(pyauto.GURL(webpage_url)),
msg='Failed to append tab for webpage.')
# Wait until the test is complete.
js_is_done = """
window.domAutomationController.send(JSON.stringify(tests_done));
"""
self.assertTrue(
self.WaitUntil(
lambda: self.ExecuteJavascript(js_is_done, tab_index=1) == 'true',
timeout=300, expect_retval=True, retry_sleep=1),
msg='Timed out when waiting for test result.')
# Retrieve and output the test results.
js_results = """
window.domAutomationController.send(JSON.stringify(tests_results));
"""
test_result = eval(self.ExecuteJavascript(js_results, tab_index=1))
test_result[0] = test_result[0].replace('true', 'True')
test_result = eval(test_result[0]) # Webpage only does 1 test right now.
description = 'FlashVideo1080P'
result = test_result['averageFPS']
logging.info('Result for %s: %f FPS (average)', description, result)
self._OutputPerfGraphValue(description, result, 'FPS',
'flash_video_1080p_fps')
result = test_result['droppedFrames']
logging.info('Result for %s: %f dropped frames', description, result)
self._OutputPerfGraphValue(description, result, 'DroppedFrames',
'flash_video_1080p_dropped_frames')
class WebGLTest(BasePerfTest):
"""Tests for WebGL performance."""
def _RunWebGLTest(self, url, description, graph_name):
"""Measures FPS using a specified WebGL demo.
Args:
url: The string URL that, once loaded, will run the WebGL demo (default
WebGL demo settings are used, since this test does not modify any
settings in the demo).
description: A string description for this demo, used as a performance
value description. Should not contain any spaces.
graph_name: A string name for the performance graph associated with this
test. Only used on Chrome desktop.
"""
self.assertTrue(self.AppendTab(pyauto.GURL(url)),
msg='Failed to append tab for %s.' % description)
get_fps_js = """
var fps_field = document.getElementById("fps");
var result = -1;
if (fps_field)
result = fps_field.innerHTML;
window.domAutomationController.send(JSON.stringify(result));
"""
# Wait until we start getting FPS values.
self.assertTrue(
self.WaitUntil(
lambda: self.ExecuteJavascript(get_fps_js, tab_index=1) != '-1',
timeout=300, retry_sleep=1),
msg='Timed out when waiting for FPS values to be available.')
# Let the experiment run for 5 seconds before we start collecting perf
# measurements.
time.sleep(5)
# Collect the current FPS value each second for the next 30 seconds. The
# final result of this test will be the average of these FPS values.
fps_vals = []
for iteration in xrange(30):
fps = self.ExecuteJavascript(get_fps_js, tab_index=1)
fps = float(fps.replace('"', ''))
fps_vals.append(fps)
logging.info('Iteration %d of %d: %f FPS', iteration + 1, 30, fps)
time.sleep(1)
self._PrintSummaryResults(description, fps_vals, 'fps', graph_name)
def testWebGLAquarium(self):
"""Measures performance using the WebGL Aquarium demo."""
self._RunWebGLTest(
self.GetFileURLForDataPath('pyauto_private', 'webgl', 'aquarium',
'aquarium.html'),
'WebGLAquarium', 'webgl_demo')
def testWebGLField(self):
"""Measures performance using the WebGL Field demo."""
self._RunWebGLTest(
self.GetFileURLForDataPath('pyauto_private', 'webgl', 'field',
'field.html'),
'WebGLField', 'webgl_demo')
def testWebGLSpaceRocks(self):
"""Measures performance using the WebGL SpaceRocks demo."""
self._RunWebGLTest(
self.GetFileURLForDataPath('pyauto_private', 'webgl', 'spacerocks',
'spacerocks.html'),
'WebGLSpaceRocks', 'webgl_demo')
class GPUPerfTest(BasePerfTest):
"""Tests for GPU performance."""
def setUp(self):
"""Performs necessary setup work before running each test in this class."""
self._gpu_info_dict = self.EvalDataFrom(os.path.join(self.DataDir(),
'gpu', 'gpuperf.txt'))
self._demo_name_url_dict = self._gpu_info_dict['demo_info']
pyauto.PyUITest.setUp(self)
def _MeasureFpsOverTime(self, tab_index=0):
"""Measures FPS using a specified demo.
This function assumes that the demo is already loaded in the specified tab
index.
Args:
tab_index: The tab index, default is 0.
"""
# Let the experiment run for 5 seconds before we start collecting FPS
# values.
time.sleep(5)
# Collect the current FPS value each second for the next 10 seconds.
# Then return the average FPS value from among those collected.
fps_vals = []
for iteration in xrange(10):
fps = self.GetFPS(tab_index=tab_index)
fps_vals.append(fps['fps'])
time.sleep(1)
return Mean(fps_vals)
def _GetStdAvgAndCompare(self, avg_fps, description, ref_dict):
"""Computes the average and compare set of values with reference data.
Args:
avg_fps: Average fps value.
description: A string description for this demo, used as a performance
value description.
ref_dict: Dictionary which contains reference data for this test case.
Returns:
True, if the actual FPS value is within 10% of the reference FPS value,
or False, otherwise.
"""
std_fps = 0
status = True
# Load reference data according to platform.
platform_ref_dict = None
if self.IsWin():
platform_ref_dict = ref_dict['win']
elif self.IsMac():
platform_ref_dict = ref_dict['mac']
elif self.IsLinux():
platform_ref_dict = ref_dict['linux']
else:
self.assertFail(msg='This platform is unsupported.')
std_fps = platform_ref_dict[description]
# Compare reference data to average fps.
# We allow the average FPS value to be within 10% of the reference
# FPS value.
if avg_fps < (0.9 * std_fps):
logging.info('FPS difference exceeds threshold for: %s', description)
logging.info(' Average: %f fps', avg_fps)
logging.info('Reference Average: %f fps', std_fps)
status = False
else:
logging.info('Average FPS is actually greater than 10 percent '
'more than the reference FPS for: %s', description)
logging.info(' Average: %f fps', avg_fps)
logging.info(' Reference Average: %f fps', std_fps)
return status
def testLaunchDemosParallelInSeparateTabs(self):
"""Measures performance of demos in different tabs in same browser."""
# Launch all the demos parallel in separate tabs
counter = 0
all_demos_passed = True
ref_dict = self._gpu_info_dict['separate_tab_ref_data']
# Iterate through dictionary and append all url to browser
for url in self._demo_name_url_dict.iterkeys():
self.assertTrue(
self.AppendTab(pyauto.GURL(self._demo_name_url_dict[url])),
msg='Failed to append tab for %s.' % url)
counter += 1
# Assert number of tab count is equal to number of tabs appended.
self.assertEqual(self.GetTabCount(), counter + 1)
# Measures performance using different demos and compare it golden
# reference.
for url in self._demo_name_url_dict.iterkeys():
avg_fps = self._MeasureFpsOverTime(tab_index=counter)
# Get the reference value of fps and compare the results
if not self._GetStdAvgAndCompare(avg_fps, url, ref_dict):
all_demos_passed = False
counter -= 1
self.assertTrue(
all_demos_passed,
msg='One or more demos failed to yield an acceptable FPS value')
def testLaunchDemosInSeparateBrowser(self):
"""Measures performance by launching each demo in a separate tab."""
# Launch demos in the browser
ref_dict = self._gpu_info_dict['separate_browser_ref_data']
all_demos_passed = True
for url in self._demo_name_url_dict.iterkeys():
self.NavigateToURL(self._demo_name_url_dict[url])
# Measures performance using different demos.
avg_fps = self._MeasureFpsOverTime()
self.RestartBrowser()
# Get the standard value of fps and compare the rseults
if not self._GetStdAvgAndCompare(avg_fps, url, ref_dict):
all_demos_passed = False
self.assertTrue(
all_demos_passed,
msg='One or more demos failed to yield an acceptable FPS value')
def testLaunchDemosBrowseForwardBackward(self):
"""Measures performance of various demos in browser going back and forth."""
ref_dict = self._gpu_info_dict['browse_back_forward_ref_data']
url_array = []
desc_array = []
all_demos_passed = True
# Get URL/Description from dictionary and put in individual array
for url in self._demo_name_url_dict.iterkeys():
url_array.append(self._demo_name_url_dict[url])
desc_array.append(url)
for index in range(len(url_array) - 1):
# Launch demo in the Browser
if index == 0:
self.NavigateToURL(url_array[index])
# Measures performance using the first demo.
avg_fps = self._MeasureFpsOverTime()
status1 = self._GetStdAvgAndCompare(avg_fps, desc_array[index],
ref_dict)
# Measures performance using the second demo.
self.NavigateToURL(url_array[index + 1])
avg_fps = self._MeasureFpsOverTime()
status2 = self._GetStdAvgAndCompare(avg_fps, desc_array[index + 1],
ref_dict)
# Go Back to previous demo
self.TabGoBack()
# Measures performance for first demo when moved back
avg_fps = self._MeasureFpsOverTime()
status3 = self._GetStdAvgAndCompare(
avg_fps, desc_array[index] + '_backward',
ref_dict)
# Go Forward to previous demo
self.TabGoForward()
# Measures performance for second demo when moved forward
avg_fps = self._MeasureFpsOverTime()
status4 = self._GetStdAvgAndCompare(
avg_fps, desc_array[index + 1] + '_forward',
ref_dict)
if not all([status1, status2, status3, status4]):
all_demos_passed = False
self.assertTrue(
all_demos_passed,
msg='One or more demos failed to yield an acceptable FPS value')
class HTML5BenchmarkTest(BasePerfTest):
"""Tests for HTML5 performance."""
def testHTML5Benchmark(self):
"""Measures performance using the benchmark at html5-benchmark.com."""
self.NavigateToURL('http://html5-benchmark.com')
start_benchmark_js = """
benchmark();
window.domAutomationController.send("done");
"""
self.ExecuteJavascript(start_benchmark_js)
js_final_score = """
var score = "-1";
var elem = document.getElementById("score");
if (elem)
score = elem.innerHTML;
window.domAutomationController.send(score);
"""
# Wait for the benchmark to complete, which is assumed to be when the value
# of the 'score' DOM element changes to something other than '87485'.
self.assertTrue(
self.WaitUntil(
lambda: self.ExecuteJavascript(js_final_score) != '87485',
timeout=900, retry_sleep=1),
msg='Timed out when waiting for final score to be available.')
score = self.ExecuteJavascript(js_final_score)
logging.info('HTML5 Benchmark final score: %f', float(score))
self._OutputPerfGraphValue('HTML5Benchmark', float(score), 'score',
'html5_benchmark')
class FileUploadDownloadTest(BasePerfTest):
"""Tests that involve measuring performance of upload and download."""
def setUp(self):
"""Performs necessary setup work before running each test in this class."""
self._temp_dir = tempfile.mkdtemp()
self._test_server = PerfTestServer(self._temp_dir)
self._test_server_port = self._test_server.GetPort()
self._test_server.Run()
self.assertTrue(self.WaitUntil(self._IsTestServerRunning),
msg='Failed to start local performance test server.')
BasePerfTest.setUp(self)
def tearDown(self):
"""Performs necessary cleanup work after running each test in this class."""
BasePerfTest.tearDown(self)
self._test_server.ShutDown()
pyauto_utils.RemovePath(self._temp_dir)
def _IsTestServerRunning(self):
"""Determines whether the local test server is ready to accept connections.
Returns:
True, if a connection can be made to the local performance test server, or
False otherwise.
"""
conn = None
try:
conn = urllib2.urlopen('http://localhost:%d' % self._test_server_port)
return True
except IOError, e:
return False
finally:
if conn:
conn.close()
def testDownload100MBFile(self):
"""Measures the time to download a 100 MB file from a local server."""
CREATE_100MB_URL = (
'http://localhost:%d/create_file_of_size?filename=data&mb=100' %
self._test_server_port)
DOWNLOAD_100MB_URL = 'http://localhost:%d/data' % self._test_server_port
DELETE_100MB_URL = ('http://localhost:%d/delete_file?filename=data' %
self._test_server_port)
# Tell the local server to create a 100 MB file.
self.NavigateToURL(CREATE_100MB_URL)
# Cleaning up downloaded files is done in the same way as in downloads.py.
# We first identify all existing downloaded files, then remove only those
# new downloaded files that appear during the course of this test.
download_dir = self.GetDownloadDirectory().value()
orig_downloads = []
if os.path.isdir(download_dir):
orig_downloads = os.listdir(download_dir)
def _CleanupAdditionalFilesInDir(directory, orig_files):
"""Removes the additional files in the specified directory.
This function will remove all files from |directory| that are not
specified in |orig_files|.
Args:
directory: A string directory path.
orig_files: A list of strings representing the original set of files in
the specified directory.
"""
downloads_to_remove = []
if os.path.isdir(directory):
downloads_to_remove = [os.path.join(directory, name)
for name in os.listdir(directory)
if name not in orig_files]
for file_name in downloads_to_remove:
pyauto_utils.RemovePath(file_name)
def _DownloadFile(url):
self.DownloadAndWaitForStart(url)
self.WaitForAllDownloadsToComplete(timeout=2 * 60 * 1000) # 2 minutes.
timings = []
for iteration in range(self._num_iterations + 1):
elapsed_time = self._MeasureElapsedTime(
lambda: _DownloadFile(DOWNLOAD_100MB_URL), num_invocations=1)
# Ignore the first iteration.
if iteration:
timings.append(elapsed_time)
logging.info('Iteration %d of %d: %f milliseconds', iteration,
self._num_iterations, elapsed_time)
self.SetDownloadShelfVisible(False)
_CleanupAdditionalFilesInDir(download_dir, orig_downloads)
self._PrintSummaryResults('Download100MBFile', timings, 'milliseconds',
'download_file')
# Tell the local server to delete the 100 MB file.
self.NavigateToURL(DELETE_100MB_URL)
def testUpload50MBFile(self):
"""Measures the time to upload a 50 MB file to a local server."""
# TODO(dennisjeffrey): Replace the use of XMLHttpRequest in this test with
# FileManager automation to select the upload file when crosbug.com/17903
# is complete.
START_UPLOAD_URL = (
'http://localhost:%d/start_upload?mb=50' % self._test_server_port)
EXPECTED_SUBSTRING = 'Upload complete'
def _IsUploadComplete():
js = """
result = "";
var div = document.getElementById("upload_result");
if (div)
result = div.innerHTML;
window.domAutomationController.send(result);
"""
return self.ExecuteJavascript(js).find(EXPECTED_SUBSTRING) >= 0
def _RunSingleUpload():
self.NavigateToURL(START_UPLOAD_URL)
self.assertTrue(
self.WaitUntil(_IsUploadComplete, timeout=120, expect_retval=True,
retry_sleep=0.10),
msg='Upload failed to complete before the timeout was hit.')
timings = []
for iteration in range(self._num_iterations + 1):
elapsed_time = self._MeasureElapsedTime(_RunSingleUpload)
# Ignore the first iteration.
if iteration:
timings.append(elapsed_time)
logging.info('Iteration %d of %d: %f milliseconds', iteration,
self._num_iterations, elapsed_time)
self._PrintSummaryResults('Upload50MBFile', timings, 'milliseconds',
'upload_file')
class ScrollResults(object):
"""Container for ScrollTest results."""
def __init__(self, first_paint_seconds, results_list):
assert len(results_list) == 2, 'Expecting initial and repeat results.'
self._first_paint_time = 1000.0 * first_paint_seconds
self._results_list = results_list
def GetFirstPaintTime(self):
return self._first_paint_time
def GetFrameCount(self, index):
results = self._results_list[index]
return results.get('numFramesSentToScreen', results['numAnimationFrames'])
def GetFps(self, index):
return (self.GetFrameCount(index) /
self._results_list[index]['totalTimeInSeconds'])
def GetMeanFrameTime(self, index):
return (self._results_list[index]['totalTimeInSeconds'] /
self.GetFrameCount(index))
def GetPercentBelow60Fps(self, index):
return (float(self._results_list[index]['droppedFrameCount']) /
self.GetFrameCount(index))
class BaseScrollTest(BasePerfTest):
"""Base class for tests measuring scrolling performance."""
def setUp(self):
"""Performs necessary setup work before running each test."""
super(BaseScrollTest, self).setUp()
scroll_file = os.path.join(self.DataDir(), 'scroll', 'scroll.js')
with open(scroll_file) as f:
self._scroll_text = f.read()
def ExtraChromeFlags(self):
"""Ensures Chrome is launched with custom flags.
Returns:
A list of extra flags to pass to Chrome when it is launched.
"""
# Extra flag used by scroll performance tests.
return (super(BaseScrollTest, self).ExtraChromeFlags() +
['--enable-gpu-benchmarking'])
def RunSingleInvocation(self, url, is_gmail_test=False):
"""Runs a single invocation of the scroll test.
Args:
url: The string url for the webpage on which to run the scroll test.
is_gmail_test: True iff the test is a GMail test.
Returns:
Instance of ScrollResults.
"""
self.assertTrue(self.AppendTab(pyauto.GURL(url)),
msg='Failed to append tab for webpage.')
timeout = pyauto.PyUITest.ActionTimeoutChanger(self, 300 * 1000) # ms
test_js = """%s;
new __ScrollTest(function(results) {
var stringify = JSON.stringify || JSON.encode;
window.domAutomationController.send(stringify(results));
}, %s);
""" % (self._scroll_text, 'true' if is_gmail_test else 'false')
results = simplejson.loads(self.ExecuteJavascript(test_js, tab_index=1))
first_paint_js = ('window.domAutomationController.send('
'(chrome.loadTimes().firstPaintTime - '
'chrome.loadTimes().requestTime).toString());')
first_paint_time = float(self.ExecuteJavascript(first_paint_js,
tab_index=1))
self.CloseTab(tab_index=1)
return ScrollResults(first_paint_time, results)
def RunScrollTest(self, url, description, graph_name, is_gmail_test=False):
"""Runs a scroll performance test on the specified webpage.
Args:
url: The string url for the webpage on which to run the scroll test.
description: A string description for the particular test being run.
graph_name: A string name for the performance graph associated with this
test. Only used on Chrome desktop.
is_gmail_test: True iff the test is a GMail test.
"""
results = []
for iteration in range(self._num_iterations + 1):
result = self.RunSingleInvocation(url, is_gmail_test)
# Ignore the first iteration.
if iteration:
fps = result.GetFps(1)
assert fps, '%s did not scroll' % url
logging.info('Iteration %d of %d: %f fps', iteration,
self._num_iterations, fps)
results.append(result)
self._PrintSummaryResults(
description, [r.GetFps(1) for r in results],
'FPS', graph_name)
class PopularSitesScrollTest(BaseScrollTest):
"""Measures scrolling performance on recorded versions of popular sites."""
def ExtraChromeFlags(self):
"""Ensures Chrome is launched with custom flags.
Returns:
A list of extra flags to pass to Chrome when it is launched.
"""
return super(PopularSitesScrollTest,
self).ExtraChromeFlags() + PageCyclerReplay.CHROME_FLAGS
def _GetUrlList(self, test_name):
"""Returns list of recorded sites."""
sites_path = PageCyclerReplay.Path('page_sets', test_name=test_name)
with open(sites_path) as f:
sites_text = f.read()
js = """
%s
window.domAutomationController.send(JSON.stringify(pageSets));
""" % sites_text
page_sets = eval(self.ExecuteJavascript(js))
return list(itertools.chain(*page_sets))[1:] # Skip first.
def _PrintScrollResults(self, results):
self._PrintSummaryResults(
'initial', [r.GetMeanFrameTime(0) for r in results],
'ms', 'FrameTimes')
self._PrintSummaryResults(
'repeat', [r.GetMeanFrameTime(1) for r in results],
'ms', 'FrameTimes')
self._PrintSummaryResults(
'initial',
[r.GetPercentBelow60Fps(0) for r in results],
'percent', 'PercentBelow60FPS')
self._PrintSummaryResults(
'repeat',
[r.GetPercentBelow60Fps(1) for r in results],
'percent', 'PercentBelow60FPS')
self._PrintSummaryResults(
'first_paint_time', [r.GetFirstPaintTime() for r in results],
'ms', 'FirstPaintTime')
def test2012Q3(self):
test_name = '2012Q3'
urls = self._GetUrlList(test_name)
results = []
with PageCyclerReplay.ReplayServer(test_name) as replay_server:
if replay_server.is_record_mode:
self._num_iterations = 1
for iteration in range(self._num_iterations):
for url in urls:
result = self.RunSingleInvocation(url)
fps = result.GetFps(0)
assert fps, '%s did not scroll' % url
logging.info('Iteration %d of %d: %f fps', iteration + 1,
self._num_iterations, fps)
results.append(result)
self._PrintScrollResults(results)
class ScrollTest(BaseScrollTest):
"""Tests to measure scrolling performance."""
def ExtraChromeFlags(self):
"""Ensures Chrome is launched with custom flags.
Returns:
A list of extra flags to pass to Chrome when it is launched.
"""
# Extra flag needed by scroll performance tests.
return super(ScrollTest, self).ExtraChromeFlags() + ['--disable-gpu-vsync']
def testBlankPageScroll(self):
"""Runs the scroll test on a blank page."""
self.RunScrollTest(
self.GetFileURLForDataPath('scroll', 'blank.html'), 'ScrollBlankPage',
'scroll_fps')
def testTextScroll(self):
"""Runs the scroll test on a text-filled page."""
self.RunScrollTest(
self.GetFileURLForDataPath('scroll', 'text.html'), 'ScrollTextPage',
'scroll_fps')
def testGooglePlusScroll(self):
"""Runs the scroll test on a Google Plus anonymized page."""
self.RunScrollTest(
self.GetFileURLForDataPath('scroll', 'plus.html'),
'ScrollGooglePlusPage', 'scroll_fps')
def testGmailScroll(self):
"""Runs the scroll test using the live Gmail site."""
self._LoginToGoogleAccount(account_key='test_google_account_gmail')
self.RunScrollTest('http://www.gmail.com', 'ScrollGmail',
'scroll_fps', True)
class FlashTest(BasePerfTest):
"""Tests to measure flash performance."""
def _RunFlashTestForAverageFPS(self, webpage_url, description, graph_name):
"""Runs a single flash test that measures an average FPS value.
Args:
webpage_url: The string URL to a webpage that will run the test.
description: A string description for this test.
graph_name: A string name for the performance graph associated with this
test. Only used on Chrome desktop.
"""
# Open up the test webpage; it's assumed the test will start automatically.
self.assertTrue(self.AppendTab(pyauto.GURL(webpage_url)),
msg='Failed to append tab for webpage.')
# Wait until the final result is computed, then retrieve and output it.
js = """
window.domAutomationController.send(
JSON.stringify(final_average_fps));
"""
self.assertTrue(
self.WaitUntil(
lambda: self.ExecuteJavascript(js, tab_index=1) != '-1',
timeout=300, expect_retval=True, retry_sleep=1),
msg='Timed out when waiting for test result.')
result = float(self.ExecuteJavascript(js, tab_index=1))
logging.info('Result for %s: %f FPS (average)', description, result)
self._OutputPerfGraphValue(description, result, 'FPS', graph_name)
def testFlashGaming(self):
"""Runs a simple flash gaming benchmark test."""
webpage_url = self.GetHttpURLForDataPath('pyauto_private', 'flash',
'FlashGamingTest2.html')
self._RunFlashTestForAverageFPS(webpage_url, 'FlashGaming', 'flash_fps')
def testFlashText(self):
"""Runs a simple flash text benchmark test."""
webpage_url = self.GetHttpURLForDataPath('pyauto_private', 'flash',
'FlashTextTest2.html')
self._RunFlashTestForAverageFPS(webpage_url, 'FlashText', 'flash_fps')
def testScimarkGui(self):
"""Runs the ScimarkGui benchmark tests."""
webpage_url = self.GetHttpURLForDataPath('pyauto_private', 'flash',
'scimarkGui.html')
self.assertTrue(self.AppendTab(pyauto.GURL(webpage_url)),
msg='Failed to append tab for webpage.')
js = 'window.domAutomationController.send(JSON.stringify(tests_done));'
self.assertTrue(
self.WaitUntil(
lambda: self.ExecuteJavascript(js, tab_index=1), timeout=300,
expect_retval='true', retry_sleep=1),
msg='Timed out when waiting for tests to complete.')
js_result = """
var result = {};
for (var i = 0; i < tests_results.length; ++i) {
var test_name = tests_results[i][0];
var mflops = tests_results[i][1];
var mem = tests_results[i][2];
result[test_name] = [mflops, mem]
}
window.domAutomationController.send(JSON.stringify(result));
"""
result = eval(self.ExecuteJavascript(js_result, tab_index=1))
for benchmark in result:
mflops = float(result[benchmark][0])
mem = float(result[benchmark][1])
if benchmark.endswith('_mflops'):
benchmark = benchmark[:benchmark.find('_mflops')]
logging.info('Results for ScimarkGui_%s:', benchmark)
logging.info(' %f MFLOPS', mflops)
logging.info(' %f MB', mem)
self._OutputPerfGraphValue('ScimarkGui-%s-MFLOPS' % benchmark, mflops,
'MFLOPS', 'scimark_gui_mflops')
self._OutputPerfGraphValue('ScimarkGui-%s-Mem' % benchmark, mem, 'MB',
'scimark_gui_mem')
class LiveGamePerfTest(BasePerfTest):
"""Tests to measure performance of live gaming webapps."""
def _RunLiveGamePerfTest(self, url, url_title_substring,
description, graph_name):
"""Measures performance metrics for the specified live gaming webapp.
This function connects to the specified URL to launch the gaming webapp,
waits for a period of time for the webapp to run, then collects some
performance metrics about the running webapp.
Args:
url: The string URL of the gaming webapp to analyze.
url_title_substring: A string that is expected to be a substring of the
webpage title for the specified gaming webapp. Used to verify that
the webapp loads correctly.
description: A string description for this game, used in the performance
value description. Should not contain any spaces.
graph_name: A string name for the performance graph associated with this
test. Only used on Chrome desktop.
"""
self.NavigateToURL(url)
loaded_tab_title = self.GetActiveTabTitle()
self.assertTrue(url_title_substring in loaded_tab_title,
msg='Loaded tab title missing "%s": "%s"' %
(url_title_substring, loaded_tab_title))
cpu_usage_start = self._GetCPUUsage()
# Let the app run for 1 minute.
time.sleep(60)
cpu_usage_end = self._GetCPUUsage()
fraction_non_idle_time = self._GetFractionNonIdleCPUTime(
cpu_usage_start, cpu_usage_end)
logging.info('Fraction of CPU time spent non-idle: %f',
fraction_non_idle_time)
self._OutputPerfGraphValue(description + 'CpuBusy', fraction_non_idle_time,
'Fraction', graph_name + '_cpu_busy')
v8_heap_stats = self.GetV8HeapStats()
v8_heap_size = v8_heap_stats['v8_memory_used'] / (1024.0 * 1024.0)
logging.info('Total v8 heap size: %f MB', v8_heap_size)
self._OutputPerfGraphValue(description + 'V8HeapSize', v8_heap_size, 'MB',
graph_name + '_v8_heap_size')
def testAngryBirds(self):
"""Measures performance for Angry Birds."""
self._RunLiveGamePerfTest('http://chrome.angrybirds.com', 'Angry Birds',
'AngryBirds', 'angry_birds')
class BasePageCyclerTest(BasePerfTest):
"""Page class for page cycler tests.
Derived classes must implement StartUrl().
Environment Variables:
PC_NO_AUTO: if set, avoids automatically loading pages.
"""
MAX_ITERATION_SECONDS = 60
TRIM_PERCENT = 20
DEFAULT_USE_AUTO = True
# Page Cycler lives in src/data/page_cycler rather than src/chrome/test/data
DATA_PATH = os.path.abspath(
os.path.join(BasePerfTest.DataDir(), os.pardir, os.pardir,
os.pardir, 'data', 'page_cycler'))
def setUp(self):
"""Performs necessary setup work before running each test."""
super(BasePageCyclerTest, self).setUp()
self.use_auto = 'PC_NO_AUTO' not in os.environ
@classmethod
def DataPath(cls, subdir):
return os.path.join(cls.DATA_PATH, subdir)
def ExtraChromeFlags(self):
"""Ensures Chrome is launched with custom flags.
Returns:
A list of extra flags to pass to Chrome when it is launched.
"""
# Extra flags required to run these tests.
# The first two are needed for the test.
# The plugins argument is to prevent bad scores due to pop-ups from
# running an old version of something (like Flash).
return (super(BasePageCyclerTest, self).ExtraChromeFlags() +
['--js-flags="--expose_gc"',
'--enable-file-cookies',
'--allow-outdated-plugins'])
def WaitUntilStarted(self, start_url):
"""Check that the test navigates away from the start_url."""
js_is_started = """
var is_started = document.location.href !== "%s";
window.domAutomationController.send(JSON.stringify(is_started));
""" % start_url
self.assertTrue(
self.WaitUntil(lambda: self.ExecuteJavascript(js_is_started) == 'true',
timeout=10),
msg='Timed out when waiting to leave start page.')
def WaitUntilDone(self, url, iterations):
"""Check cookies for "__pc_done=1" to know the test is over."""
def IsDone():
cookies = self.GetCookie(pyauto.GURL(url)) # window 0, tab 0
return '__pc_done=1' in cookies
self.assertTrue(
self.WaitUntil(
IsDone,
timeout=(self.MAX_ITERATION_SECONDS * iterations),
retry_sleep=1),
msg='Timed out waiting for page cycler test to complete.')
def CollectPagesAndTimes(self, url):
"""Collect the results from the cookies."""
pages, times = None, None
cookies = self.GetCookie(pyauto.GURL(url)) # window 0, tab 0
for cookie in cookies.split(';'):
if '__pc_pages' in cookie:
pages_str = cookie.split('=', 1)[1]
pages = pages_str.split(',')
elif '__pc_timings' in cookie:
times_str = cookie.split('=', 1)[1]
times = [float(t) for t in times_str.split(',')]
self.assertTrue(pages and times,
msg='Unable to find test results in cookies: %s' % cookies)
return pages, times
def IteratePageTimes(self, pages, times, iterations):
"""Regroup the times by the page.
Args:
pages: the list of pages
times: e.g. [page1_iter1, page2_iter1, ..., page1_iter2, page2_iter2, ...]
iterations: the number of times for each page
Yields:
(pageN, [pageN_iter1, pageN_iter2, ...])
"""
num_pages = len(pages)
num_times = len(times)
expected_num_times = num_pages * iterations
self.assertEqual(
expected_num_times, num_times,
msg=('num_times != num_pages * iterations: %s != %s * %s, times=%s' %
(num_times, num_pages, iterations, times)))
for i, page in enumerate(pages):
yield page, list(itertools.islice(times, i, None, num_pages))
def CheckPageTimes(self, pages, times, iterations):
"""Assert that all the times are greater than zero."""
failed_pages = []
for page, times in self.IteratePageTimes(pages, times, iterations):
failed_times = [t for t in times if t <= 0.0]
if failed_times:
failed_pages.append((page, failed_times))
if failed_pages:
self.fail('Pages with unexpected times: %s' % failed_pages)
def TrimTimes(self, times, percent):
"""Return a new list with |percent| number of times trimmed for each page.
Removes the largest and smallest values.
"""
iterations = len(times)
times = sorted(times)
num_to_trim = int(iterations * float(percent) / 100.0)
logging.debug('Before trimming %d: %s' % (num_to_trim, times))
a = num_to_trim / 2
b = iterations - (num_to_trim / 2 + num_to_trim % 2)
trimmed_times = times[a:b]
logging.debug('After trimming: %s', trimmed_times)
return trimmed_times
def ComputeFinalResult(self, pages, times, iterations):
"""The final score that is calculated is a geometric mean of the
arithmetic means of each page's load time, and we drop the
upper/lower 20% of the times for each page so they don't skew the
mean. The geometric mean is used for the final score because the
time range for any given site may be very different, and we don't
want slower sites to weight more heavily than others.
"""
self.CheckPageTimes(pages, times, iterations)
page_means = [
Mean(self.TrimTimes(times, percent=self.TRIM_PERCENT))
for _, times in self.IteratePageTimes(pages, times, iterations)]
return GeometricMean(page_means)
def StartUrl(self, test_name, iterations):
"""Return the URL to used to start the test.
Derived classes must implement this.
"""
raise NotImplemented
def RunPageCyclerTest(self, name, description):
"""Runs the specified PageCycler test.
Args:
name: the page cycler test name (corresponds to a directory or test file)
description: a string description for the test
"""
iterations = self._num_iterations
start_url = self.StartUrl(name, iterations)
self.NavigateToURL(start_url)
if self.use_auto:
self.WaitUntilStarted(start_url)
self.WaitUntilDone(start_url, iterations)
pages, times = self.CollectPagesAndTimes(start_url)
final_result = self.ComputeFinalResult(pages, times, iterations)
logging.info('%s page cycler final result: %f' %
(description, final_result))
self._OutputPerfGraphValue(description + '_PageCycler', final_result,
'milliseconds', graph_name='PageCycler')
class PageCyclerTest(BasePageCyclerTest):
"""Tests to run various page cyclers.
Environment Variables:
PC_NO_AUTO: if set, avoids automatically loading pages.
"""
def _PreReadDataDir(self, subdir):
"""This recursively reads all of the files in a given url directory.
The intent is to get them into memory before they are used by the benchmark.
Args:
subdir: a subdirectory of the page cycler data directory.
"""
def _PreReadDir(dirname, names):
for rfile in names:
with open(os.path.join(dirname, rfile)) as fp:
fp.read()
for root, dirs, files in os.walk(self.DataPath(subdir)):
_PreReadDir(root, files)
def StartUrl(self, test_name, iterations):
# Must invoke GetFileURLForPath before appending parameters to the URL,
# otherwise those parameters will get quoted.
start_url = self.GetFileURLForPath(self.DataPath(test_name), 'start.html')
start_url += '?iterations=%d' % iterations
if self.use_auto:
start_url += '&auto=1'
return start_url
def RunPageCyclerTest(self, dirname, description):
"""Runs the specified PageCycler test.
Args:
dirname: directory containing the page cycler test
description: a string description for the test
"""
self._PreReadDataDir('common')
self._PreReadDataDir(dirname)
super(PageCyclerTest, self).RunPageCyclerTest(dirname, description)
def testMoreJSFile(self):
self.RunPageCyclerTest('morejs', 'MoreJSFile')
def testAlexaFile(self):
self.RunPageCyclerTest('alexa_us', 'Alexa_usFile')
def testBloatFile(self):
self.RunPageCyclerTest('bloat', 'BloatFile')
def testDHTMLFile(self):
self.RunPageCyclerTest('dhtml', 'DhtmlFile')
def testIntl1File(self):
self.RunPageCyclerTest('intl1', 'Intl1File')
def testIntl2File(self):
self.RunPageCyclerTest('intl2', 'Intl2File')
def testMozFile(self):
self.RunPageCyclerTest('moz', 'MozFile')
def testMoz2File(self):
self.RunPageCyclerTest('moz2', 'Moz2File')
class PageCyclerReplay(object):
"""Run page cycler tests with network simulation via Web Page Replay.
Web Page Replay is a proxy that can record and "replay" web pages with
simulated network characteristics -- without having to edit the pages
by hand. With WPR, tests can use "real" web content, and catch
performance issues that may result from introducing network delays and
bandwidth throttling.
"""
_PATHS = {
'archive': 'src/data/page_cycler/webpagereplay/{test_name}.wpr',
'page_sets': 'src/tools/page_cycler/webpagereplay/tests/{test_name}.js',
'start_page': 'src/tools/page_cycler/webpagereplay/start.html',
'extension': 'src/tools/page_cycler/webpagereplay/extension',
}
WEBPAGEREPLAY_HOST = '127.0.0.1'
WEBPAGEREPLAY_HTTP_PORT = 8080
WEBPAGEREPLAY_HTTPS_PORT = 8413
CHROME_FLAGS = webpagereplay.GetChromeFlags(
WEBPAGEREPLAY_HOST,
WEBPAGEREPLAY_HTTP_PORT,
WEBPAGEREPLAY_HTTPS_PORT) + [
'--log-level=0',
'--disable-background-networking',
'--enable-experimental-extension-apis',
'--enable-logging',
'--enable-benchmarking',
'--enable-net-benchmarking',
'--metrics-recording-only',
'--activate-on-launch',
'--no-first-run',
'--no-proxy-server',
]
@classmethod
def Path(cls, key, **kwargs):
return FormatChromePath(cls._PATHS[key], **kwargs)
@classmethod
def ReplayServer(cls, test_name, replay_options=None):
archive_path = cls.Path('archive', test_name=test_name)
return webpagereplay.ReplayServer(archive_path,
cls.WEBPAGEREPLAY_HOST,
cls.WEBPAGEREPLAY_HTTP_PORT,
cls.WEBPAGEREPLAY_HTTPS_PORT,
replay_options)
class PageCyclerNetSimTest(BasePageCyclerTest):
"""Tests to run Web Page Replay backed page cycler tests."""
MAX_ITERATION_SECONDS = 180
def ExtraChromeFlags(self):
"""Ensures Chrome is launched with custom flags.
Returns:
A list of extra flags to pass to Chrome when it is launched.
"""
flags = super(PageCyclerNetSimTest, self).ExtraChromeFlags()
flags.append('--load-extension=%s' % PageCyclerReplay.Path('extension'))
flags.extend(PageCyclerReplay.CHROME_FLAGS)
return flags
def StartUrl(self, test_name, iterations):
start_path = PageCyclerReplay.Path('start_page')
start_url = 'file://%s?test=%s&iterations=%d' % (
start_path, test_name, iterations)
if self.use_auto:
start_url += '&auto=1'
return start_url
def RunPageCyclerTest(self, test_name, description):
"""Runs the specified PageCycler test.
Args:
test_name: name for archive (.wpr) and config (.js) files.
description: a string description for the test
"""
replay_options = None
with PageCyclerReplay.ReplayServer(test_name, replay_options) as server:
if server.is_record_mode:
self._num_iterations = 1
super_self = super(PageCyclerNetSimTest, self)
super_self.RunPageCyclerTest(test_name, description)
def test2012Q2(self):
self.RunPageCyclerTest('2012Q2', '2012Q2')
class MemoryTest(BasePerfTest):
"""Tests to measure memory consumption under different usage scenarios."""
def ExtraChromeFlags(self):
"""Launches Chrome with custom flags.
Returns:
A list of extra flags to pass to Chrome when it is launched.
"""
# Ensure Chrome assigns one renderer process to each tab.
return super(MemoryTest, self).ExtraChromeFlags() + ['--process-per-tab']
def _RecordMemoryStats(self, description, when, duration):
"""Outputs memory statistics to be graphed.
Args:
description: A string description for the test. Should not contain
spaces. For example, 'MemCtrl'.
when: A string description of when the memory stats are being recorded
during test execution (since memory stats may be recorded multiple
times during a test execution at certain "interesting" times). Should
not contain spaces.
duration: The number of seconds to sample data before outputting the
memory statistics.
"""
mem = self.GetMemoryStatsChromeOS(duration)
measurement_types = [
('gem_obj', 'GemObj'),
('gtt', 'GTT'),
('mem_free', 'MemFree'),
('mem_available', 'MemAvail'),
('mem_shared', 'MemShare'),
('mem_cached', 'MemCache'),
('mem_anon', 'MemAnon'),
('mem_file', 'MemFile'),
('mem_slab', 'MemSlab'),
('browser_priv', 'BrowPriv'),
('browser_shared', 'BrowShar'),
('gpu_priv', 'GpuPriv'),
('gpu_shared', 'GpuShar'),
('renderer_priv', 'RendPriv'),
('renderer_shared', 'RendShar'),
]
for type_key, type_string in measurement_types:
if type_key not in mem:
continue
self._OutputPerfGraphValue(
'%s-Min%s-%s' % (description, type_string, when),
mem[type_key]['min'], 'KB', '%s-%s' % (description, type_string))
self._OutputPerfGraphValue(
'%s-Max%s-%s' % (description, type_string, when),
mem[type_key]['max'], 'KB', '%s-%s' % (description, type_string))
self._OutputPerfGraphValue(
'%s-End%s-%s' % (description, type_string, when),
mem[type_key]['end'], 'KB', '%s-%s' % (description, type_string))
def _RunTest(self, tabs, description, duration):
"""Runs a general memory test.
Args:
tabs: A list of strings representing the URLs of the websites to open
during this test.
description: A string description for the test. Should not contain
spaces. For example, 'MemCtrl'.
duration: The number of seconds to sample data before outputting memory
statistics.
"""
self._RecordMemoryStats(description, '0Tabs0', duration)
for iteration_num in xrange(2):
for site in tabs:
self.AppendTab(pyauto.GURL(site))
self._RecordMemoryStats(description,
'%dTabs%d' % (len(tabs), iteration_num + 1),
duration)
for _ in xrange(len(tabs)):
self.CloseTab(tab_index=1)
self._RecordMemoryStats(description, '0Tabs%d' % (iteration_num + 1),
duration)
def testOpenCloseTabsControl(self):
"""Measures memory usage when opening/closing tabs to about:blank."""
tabs = ['about:blank'] * 10
self._RunTest(tabs, 'MemCtrl', 15)
def testOpenCloseTabsLiveSites(self):
"""Measures memory usage when opening/closing tabs to live sites."""
tabs = [
'http://www.google.com/gmail',
'http://www.google.com/calendar',
'http://www.google.com/plus',
'http://www.google.com/youtube',
'http://www.nytimes.com',
'http://www.cnn.com',
'http://www.facebook.com/zuck',
'http://www.techcrunch.com',
'http://www.theverge.com',
'http://www.yahoo.com',
]
# Log in to a test Google account to make connections to the above Google
# websites more interesting.
self._LoginToGoogleAccount()
self._RunTest(tabs, 'MemLive', 20)
class PerfTestServerRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
"""Request handler for the local performance test server."""
def _IgnoreHandler(self, unused_args):
"""A GET request handler that simply replies with status code 200.
Args:
unused_args: A dictionary of arguments for the current GET request.
The arguments are ignored.
"""
self.send_response(200)
self.end_headers()
def _CreateFileOfSizeHandler(self, args):
"""A GET handler that creates a local file with the specified size.
Args:
args: A dictionary of arguments for the current GET request. Must
contain 'filename' and 'mb' keys that refer to the name of the file
to create and its desired size, respectively.
"""
megabytes = None
filename = None
try:
megabytes = int(args['mb'][0])
filename = args['filename'][0]
except (ValueError, KeyError, IndexError), e:
logging.exception('Server error creating file: %s', e)
assert megabytes and filename
with open(os.path.join(self.server.docroot, filename), 'wb') as f:
f.write('X' * 1024 * 1024 * megabytes)
self.send_response(200)
self.end_headers()
def _DeleteFileHandler(self, args):
"""A GET handler that deletes the specified local file.
Args:
args: A dictionary of arguments for the current GET request. Must
contain a 'filename' key that refers to the name of the file to
delete, relative to the server's document root.
"""
filename = None
try:
filename = args['filename'][0]
except (KeyError, IndexError), e:
logging.exception('Server error deleting file: %s', e)
assert filename
try:
os.remove(os.path.join(self.server.docroot, filename))
except OSError, e:
logging.warning('OS error removing file: %s', e)
self.send_response(200)
self.end_headers()
def _StartUploadHandler(self, args):
"""A GET handler to serve a page that uploads the given amount of data.
When the page loads, the specified amount of data is automatically
uploaded to the same local server that is handling the current request.
Args:
args: A dictionary of arguments for the current GET request. Must
contain an 'mb' key that refers to the size of the data to upload.
"""
megabytes = None
try:
megabytes = int(args['mb'][0])
except (ValueError, KeyError, IndexError), e:
logging.exception('Server error starting upload: %s', e)
assert megabytes
script = """
<html>
<head>
<script type='text/javascript'>
function startUpload() {
var megabytes = %s;
var data = Array((1024 * 1024 * megabytes) + 1).join('X');
var boundary = '***BOUNDARY***';
var xhr = new XMLHttpRequest();
xhr.open('POST', 'process_upload', true);
xhr.setRequestHeader(
'Content-Type',
'multipart/form-data; boundary="' + boundary + '"');
xhr.setRequestHeader('Content-Length', data.length);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) {
document.getElementById('upload_result').innerHTML =
xhr.responseText;
}
};
var body = '--' + boundary + '\\r\\n';
body += 'Content-Disposition: form-data;' +
'file_contents=' + data;
xhr.send(body);
}
</script>
</head>
<body onload="startUpload();">
<div id='upload_result'>Uploading...</div>
</body>
</html>
""" % megabytes
self.send_response(200)
self.end_headers()
self.wfile.write(script)
def _ProcessUploadHandler(self, form):
"""A POST handler that discards uploaded data and sends a response.
Args:
form: A dictionary containing posted form data, as returned by
urlparse.parse_qs().
"""
upload_processed = False
file_size = 0
if 'file_contents' in form:
file_size = len(form['file_contents'][0])
upload_processed = True
self.send_response(200)
self.end_headers()
if upload_processed:
self.wfile.write('Upload complete (%d bytes)' % file_size)
else:
self.wfile.write('No file contents uploaded')
GET_REQUEST_HANDLERS = {
'create_file_of_size': _CreateFileOfSizeHandler,
'delete_file': _DeleteFileHandler,
'start_upload': _StartUploadHandler,
'favicon.ico': _IgnoreHandler,
}
POST_REQUEST_HANDLERS = {
'process_upload': _ProcessUploadHandler,
}
def translate_path(self, path):
"""Ensures files are served from the given document root.
Overridden from SimpleHTTPServer.SimpleHTTPRequestHandler.
"""
path = urlparse.urlparse(path)[2]
path = posixpath.normpath(urllib.unquote(path))
words = path.split('/')
words = filter(None, words) # Remove empty strings from |words|.
path = self.server.docroot
for word in words:
_, word = os.path.splitdrive(word)
_, word = os.path.split(word)
if word in (os.curdir, os.pardir):
continue
path = os.path.join(path, word)
return path
def do_GET(self):
"""Processes a GET request to the local server.
Overridden from SimpleHTTPServer.SimpleHTTPRequestHandler.
"""
split_url = urlparse.urlsplit(self.path)
base_path = split_url[2]
if base_path.startswith('/'):
base_path = base_path[1:]
args = urlparse.parse_qs(split_url[3])
if base_path in self.GET_REQUEST_HANDLERS:
self.GET_REQUEST_HANDLERS[base_path](self, args)
else:
SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)
def do_POST(self):
"""Processes a POST request to the local server.
Overridden from SimpleHTTPServer.SimpleHTTPRequestHandler.
"""
form = urlparse.parse_qs(
self.rfile.read(int(self.headers.getheader('Content-Length'))))
path = urlparse.urlparse(self.path)[2]
if path.startswith('/'):
path = path[1:]
if path in self.POST_REQUEST_HANDLERS:
self.POST_REQUEST_HANDLERS[path](self, form)
else:
self.send_response(200)
self.send_header('Content-Type', 'text/plain')
self.end_headers()
self.wfile.write('No handler for POST request "%s".' % path)
class ThreadedHTTPServer(SocketServer.ThreadingMixIn,
BaseHTTPServer.HTTPServer):
def __init__(self, server_address, handler_class):
BaseHTTPServer.HTTPServer.__init__(self, server_address, handler_class)
class PerfTestServer(object):
"""Local server for use by performance tests."""
def __init__(self, docroot):
"""Initializes the performance test server.
Args:
docroot: The directory from which to serve files.
"""
# The use of 0 means to start the server on an arbitrary available port.
self._server = ThreadedHTTPServer(('', 0),
PerfTestServerRequestHandler)
self._server.docroot = docroot
self._server_thread = threading.Thread(target=self._server.serve_forever)
def Run(self):
"""Starts the server thread."""
self._server_thread.start()
def ShutDown(self):
"""Shuts down the server."""
self._server.shutdown()
self._server_thread.join()
def GetPort(self):
"""Identifies the port number to which the server is currently bound.
Returns:
The numeric port number to which the server is currently bound.
"""
return self._server.server_address[1]
if __name__ == '__main__':
pyauto_functional.Main()
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1898,
334,
67,
9,
6029,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
6845,
1134,
2495,
10238,
2295,
14,
199,
199,
1858,
2295,
626,
1929,
370,
506,
1255,
367,
3663,
10615,
334,
69,
14,
71,
2020,
880,
626,
8095,
199,
460,
4465,
18458,
1338,
883,
506,
14581,
395,
314,
849,
1329,
402,
10615,
199,
1065,
367,
1924,
402,
3520,
2295,
365,
2013,
701,
1204,
63,
3472,
63,
7125,
63,
11084,
12969,
18257,
199,
17231,
574,
883,
14190,
506,
32464,
379,
701,
4260,
376,
3734,
1750,
199,
7,
7125,
63,
11084,
12969,
7,
370,
282,
7317,
3000,
12,
6144,
314,
1329,
402,
10615,
199,
475,
1255,
14,
221,
1626,
4722,
12,
2536,
8494,
911,
2597,
506,
1255,
370,
298,
10669,
1536,
2,
314,
199,
5418,
12,
436,
314,
754,
687,
626,
2536,
8494,
911,
506,
5525,
14,
199,
199,
7700,
2295,
19687,
641,
27714,
24373,
12187,
370,
16776,
14,
221,
593,
2055,
305,
1636,
1183,
12,
3520,
199,
23867,
4882,
900,
734,
12,
2337,
991,
12787,
316,
314,
20542,
32619,
334,
3239,
4976,
199,
20363,
1266,
14,
957,
15,
1165,
15773,
680,
221,
4005,
1736,
6818,
642,
12,
314,
2295,
16895,
20542,
32619,
199,
9099,
4572,
3344,
25461,
25870,
14,
221,
710,
574,
1204,
63,
3472,
63,
4283,
63,
8899,
63,
8760,
92,
199,
3017,
5604,
314,
8765,
1329,
402,
25870,
626,
883,
506,
370,
1435,
972,
2544,
314,
511,
199,
15762,
14,
221,
4005,
32464,
642,
574,
12,
663,
3734,
1750,
283,
4283,
63,
8899,
63,
8760,
7,
370,
314,
199,
16035,
8765,
574,
14,
199,
624,
199,
199,
646,
3523,
14938,
199,
646,
3718,
199,
646,
7554,
199,
646,
7975,
199,
646,
2050,
199,
646,
3473,
199,
646,
747,
199,
646,
15454,
199,
646,
295,
199,
646,
5870,
14938,
199,
646,
17766,
3120,
199,
646,
4673,
199,
646,
3873,
199,
646,
984,
199,
646,
5549,
199,
646,
5796,
199,
646,
900,
199,
646,
900,
390,
199,
646,
4011,
199,
646,
4011,
18,
199,
646,
7097,
199,
199,
646,
1134,
2495,
63,
15481,
221,
327,
9498,
506,
8439,
2544,
1134,
2495,
14,
199,
646,
1134,
2495,
199,
646,
13804,
221,
327,
9498,
506,
8439,
2410,
1134,
2495,
27,
16180,
315,
10919,
63,
7522,
14,
199,
199,
504,
1851,
70,
20528,
492,
5365,
70,
20528,
774,
4433,
199,
646,
1134,
2495,
63,
1208,
199,
646,
511,
63,
1208,
199,
646,
9248,
19540,
199,
504,
22378,
492,
1488,
7715,
774,
4433,
421,
199,
63,
1244,
31364,
63,
5825,
63,
3022,
275,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
904,
8,
272,
747,
14,
515,
14,
3475,
3460,
493,
10139,
747,
14,
21386,
12,
747,
14,
21386,
12,
747,
14,
21386,
12,
747,
14,
21386,
430,
421,
199,
318,
9701,
18083,
2042,
8,
9228,
63,
515,
12,
1011,
958,
304,
523,
408,
7306,
282,
931,
3847,
370,
314,
12051,
1738,
1901,
376,
4403,
13,
6100,
931,
14,
819,
3033,
26,
272,
10694,
63,
515,
26,
282,
931,
1059,
626,
1443,
506,
282,
1475,
1252,
489,
5679,
26,
283,
2164,
15,
11470,
63,
7522,
5321,
578,
63,
354,
5995,
363,
826,
4343,
647,
7,
272,
2074,
26,
1249,
367,
314,
1475,
8343,
14,
489,
5679,
26,
791,
578,
63,
354,
356,
283,
24111,
936,
819,
1803,
26,
272,
376,
3679,
931,
315,
314,
1453,
12051,
3123,
543,
10803,
6781,
14,
523,
408,
523,
1824,
972,
63,
515,
275,
10694,
63,
515,
14,
908,
3682,
958,
9,
523,
931,
63,
4181,
275,
1824,
972,
63,
515,
14,
1294,
7825,
523,
372,
747,
14,
515,
14,
904,
1547,
1244,
31364,
63,
5825,
63,
3022,
12,
627,
515,
63,
4181,
9,
421,
199,
318,
9739,
872,
12337,
8,
1459,
304,
523,
408,
3407,
314,
4465,
18458,
402,
1204,
1459,
92,
1041,
523,
12402,
275,
25136,
8,
1459,
9,
523,
340,
822,
8,
1459,
9,
665,
499,
503,
440,
12402,
26,
272,
372,
378,
14,
16,
523,
2388,
63,
3643,
275,
359,
3442,
14,
8278,
8,
88,
446,
12402,
12,
499,
9,
367,
671,
315,
1338,
61,
523,
372,
3473,
14,
5079,
8,
1838,
8,
808,
63,
3643,
9,
1182,
334,
552,
8,
808,
63,
3643,
9,
446,
413,
430,
421,
199,
318,
25136,
8,
1459,
304,
523,
408,
3407,
314,
24166,
4615,
402,
1204,
1459,
92,
1041,
523,
340,
440,
1338,
503,
488,
315,
1338,
26,
272,
372,
488,
523,
372,
3089,
8,
1459,
9,
1182,
2069,
8,
552,
8,
1459,
430,
421,
199,
318,
5346,
15890,
14825,
8,
1459,
304,
523,
408,
3407,
314,
2312,
15890,
4615,
402,
1204,
1459,
92,
1041,
523,
340,
440,
1338,
503,
488,
315,
1338,
503,
359,
88,
367,
671,
315,
1338,
340,
671,
665,
378,
14,
16,
2189,
272,
372,
488,
523,
340,
378,
14,
16,
315,
1338,
26,
272,
372,
378,
14,
16,
523,
372,
3473,
14,
1474,
8,
14825,
779,
3442,
14,
793,
8,
88,
9,
367,
671,
315,
1338,
2459,
421,
199,
533,
3523,
12387,
774,
8,
647,
2495,
14,
2713,
28666,
597,
304,
523,
408,
1563,
1021,
367,
10238,
2295,
1041,
819,
485,
3472,
63,
7125,
63,
11084,
12969,
275,
1616,
221,
327,
14797,
9560,
6867,
543,
19763,
1907,
63,
2713,
3358,
12387,
2925,
14,
647,
14,
523,
485,
3472,
63,
4283,
63,
8899,
63,
8760,
275,
1616,
523,
485,
17038,
63,
8414,
63,
18997,
63,
4225,
275,
2513,
17038,
63,
4225,
8650,
523,
485,
17038,
63,
8414,
63,
18997,
63,
4030,
275,
2513,
17038,
63,
4030,
8650,
819,
347,
3613,
8,
277,
304,
272,
408,
2623,
3351,
5784,
3272,
1736,
2544,
3879,
1924,
511,
1041,
272,
291,
423,
1507,
63,
13570,
275,
291,
423,
3472,
63,
7125,
63,
11084,
12969,
272,
340,
283,
7125,
63,
11084,
12969,
7,
315,
747,
14,
2314,
26,
489,
291,
423,
1507,
63,
13570,
275,
1109,
8,
736,
14,
2314,
459,
7125,
63,
11084,
12969,
1105,
272,
291,
423,
988,
63,
2593,
63,
835,
275,
291,
423,
3472,
63,
4283,
63,
8899,
63,
8760,
272,
340,
283,
4283,
63,
8899,
63,
8760,
7
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1898,
334,
67,
9,
6029,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
6845,
1134,
2495,
10238,
2295,
14,
199,
199,
1858,
2295,
626,
1929,
370,
506,
1255,
367,
3663,
10615,
334,
69,
14,
71,
2020,
880,
626,
8095,
199,
460,
4465,
18458,
1338,
883,
506,
14581,
395,
314,
849,
1329,
402,
10615,
199,
1065,
367,
1924,
402,
3520,
2295,
365,
2013,
701,
1204,
63,
3472,
63,
7125,
63,
11084,
12969,
18257,
199,
17231,
574,
883,
14190,
506,
32464,
379,
701,
4260,
376,
3734,
1750,
199,
7,
7125,
63,
11084,
12969,
7,
370,
282,
7317,
3000,
12,
6144,
314,
1329,
402,
10615,
199,
475,
1255,
14,
221,
1626,
4722,
12,
2536,
8494,
911,
2597,
506,
1255,
370,
298,
10669,
1536,
2,
314,
199,
5418,
12,
436,
314,
754,
687,
626,
2536,
8494,
911,
506,
5525,
14,
199,
199,
7700,
2295,
19687,
641,
27714,
24373,
12187,
370,
16776,
14,
221,
593,
2055,
305,
1636,
1183,
12,
3520,
199,
23867,
4882,
900,
734,
12,
2337,
991,
12787,
316,
314,
20542,
32619,
334,
3239,
4976,
199,
20363,
1266,
14,
957,
15,
1165,
15773,
680,
221,
4005,
1736,
6818,
642,
12,
314,
2295,
16895,
20542,
32619,
199,
9099,
4572,
3344,
25461,
25870,
14,
221,
710,
574,
1204,
63,
3472,
63,
4283,
63,
8899,
63,
8760,
92,
199,
3017,
5604,
314,
8765,
1329,
402,
25870,
626,
883,
506,
370,
1435,
972,
2544,
314,
511,
199,
15762,
14,
221,
4005,
32464,
642,
574,
12,
663,
3734,
1750,
283,
4283,
63,
8899,
63,
8760,
7,
370,
314,
199,
16035,
8765,
574,
14,
199,
624,
199,
199,
646,
3523,
14938,
199,
646,
3718,
199,
646,
7554,
199,
646,
7975,
199,
646,
2050,
199,
646,
3473,
199,
646,
747,
199,
646,
15454,
199,
646,
295,
199,
646,
5870,
14938,
199,
646,
17766,
3120,
199,
646,
4673,
199,
646,
3873,
199,
646,
984,
199,
646,
5549,
199,
646,
5796,
199,
646,
900,
199,
646,
900,
390,
199,
646,
4011,
199,
646,
4011,
18,
199,
646,
7097,
199,
199,
646,
1134,
2495,
63,
15481,
221,
327,
9498,
506,
8439,
2544,
1134,
2495,
14,
199,
646,
1134,
2495,
199,
646,
13804,
221,
327,
9498,
506,
8439,
2410,
1134,
2495,
27,
16180,
315,
10919,
63,
7522,
14,
199,
199,
504,
1851,
70,
20528,
492,
5365,
70,
20528,
774,
4433,
199,
646,
1134,
2495,
63,
1208,
199,
646,
511,
63,
1208,
199,
646,
9248,
19540,
199,
504,
22378,
492,
1488,
7715,
774,
4433,
421,
199,
63,
1244,
31364,
63,
5825,
63,
3022,
275,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
904,
8,
272,
747,
14,
515,
14,
3475,
3460,
493,
10139,
747,
14,
21386,
12,
747,
14,
21386,
12,
747,
14,
21386,
12,
747,
14,
21386,
430,
421,
199,
318,
9701,
18083,
2042,
8,
9228,
63,
515,
12,
1011,
958,
304,
523,
408,
7306,
282,
931,
3847,
370,
314,
12051,
1738,
1901,
376,
4403,
13,
6100,
931,
14,
819,
3033,
26,
272,
10694,
63,
515,
26,
282,
931,
1059,
626,
1443,
506,
282,
1475,
1252,
489,
5679,
26,
283,
2164,
15,
11470,
63,
7522,
5321,
578,
63,
354,
5995,
363,
826,
4343,
647,
7,
272,
2074,
26,
1249,
367,
314,
1475,
8343,
14,
489,
5679,
26,
791,
578,
63,
354,
356,
283,
24111,
936,
819,
1803,
26,
272,
376,
3679,
931,
315,
314,
1453,
12051,
3123,
543,
10803,
6781,
14,
523,
408,
523,
1824,
972,
63,
515,
275,
10694,
63,
515,
14,
908,
3682,
958,
9,
523,
931,
63,
4181,
275,
1824,
972,
63,
515,
14,
1294,
7825,
523,
372,
747,
14,
515,
14,
904,
1547,
1244,
31364,
63,
5825,
63,
3022,
12,
627,
515,
63,
4181,
9,
421,
199,
318,
9739,
872,
12337,
8,
1459,
304,
523,
408,
3407,
314,
4465,
18458,
402,
1204,
1459,
92,
1041,
523,
12402,
275,
25136,
8,
1459,
9,
523,
340,
822,
8,
1459,
9,
665,
499,
503,
440,
12402,
26,
272,
372,
378,
14,
16,
523,
2388,
63,
3643,
275,
359,
3442,
14,
8278,
8,
88,
446,
12402,
12,
499,
9,
367,
671,
315,
1338,
61,
523,
372,
3473,
14,
5079,
8,
1838,
8,
808,
63,
3643,
9,
1182,
334,
552,
8,
808,
63,
3643,
9,
446,
413,
430,
421,
199,
318,
25136,
8,
1459,
304,
523,
408,
3407,
314,
24166,
4615,
402,
1204,
1459,
92,
1041,
523,
340,
440,
1338,
503,
488,
315,
1338,
26,
272,
372,
488,
523,
372,
3089,
8,
1459,
9,
1182,
2069,
8,
552,
8,
1459,
430,
421,
199,
318,
5346,
15890,
14825,
8,
1459,
304,
523,
408,
3407,
314,
2312,
15890,
4615,
402,
1204,
1459,
92,
1041,
523,
340,
440,
1338,
503,
488,
315,
1338,
503,
359,
88,
367,
671,
315,
1338,
340,
671,
665,
378,
14,
16,
2189,
272,
372,
488,
523,
340,
378,
14,
16,
315,
1338,
26,
272,
372,
378,
14,
16,
523,
372,
3473,
14,
1474,
8,
14825,
779,
3442,
14,
793,
8,
88,
9,
367,
671,
315,
1338,
2459,
421,
199,
533,
3523,
12387,
774,
8,
647,
2495,
14,
2713,
28666,
597,
304,
523,
408,
1563,
1021,
367,
10238,
2295,
1041,
819,
485,
3472,
63,
7125,
63,
11084,
12969,
275,
1616,
221,
327,
14797,
9560,
6867,
543,
19763,
1907,
63,
2713,
3358,
12387,
2925,
14,
647,
14,
523,
485,
3472,
63,
4283,
63,
8899,
63,
8760,
275,
1616,
523,
485,
17038,
63,
8414,
63,
18997,
63,
4225,
275,
2513,
17038,
63,
4225,
8650,
523,
485,
17038,
63,
8414,
63,
18997,
63,
4030,
275,
2513,
17038,
63,
4030,
8650,
819,
347,
3613,
8,
277,
304,
272,
408,
2623,
3351,
5784,
3272,
1736,
2544,
3879,
1924,
511,
1041,
272,
291,
423,
1507,
63,
13570,
275,
291,
423,
3472,
63,
7125,
63,
11084,
12969,
272,
340,
283,
7125,
63,
11084,
12969,
7,
315,
747,
14,
2314,
26,
489,
291,
423,
1507,
63,
13570,
275,
1109,
8,
736,
14,
2314,
459,
7125,
63,
11084,
12969,
1105,
272,
291,
423,
988,
63,
2593,
63,
835,
275,
291,
423,
3472,
63,
4283,
63,
8899,
63,
8760,
272,
340,
283,
4283,
63,
8899,
63,
8760,
7,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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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
] |
juanjosegzl/learningpygame
|
ezmenu.py
|
1
|
2298
|
#! /usr/bin/env python
# I found this file inside Super Mario Bros python
# written by HJ https://sourceforge.net/projects/supermariobrosp/
# the complete work is licensed under GPL3 although I can not determine# license of this file
# maybe this is the original author, we can contact him/her http://www.pygame.org/project-EzMeNu-855-.html
import pygame
class EzMenu:
def __init__(self, *options):
self.options = options
self.x = 0
self.y = 0
self.font = pygame.font.Font(None, 32)
self.option = 0
self.width = 1
self.color = [0, 0, 0]
self.hcolor = [255, 0, 0]
self.height = len(self.options)*self.font.get_height()
for o in self.options:
text = o[0]
ren = self.font.render(text, 2, (0, 0, 0))
if ren.get_width() > self.width:
self.width = ren.get_width()
def draw(self, surface):
i=0
for o in self.options:
if i==self.option:
clr = self.hcolor
else:
clr = self.color
text = o[0]
ren = self.font.render(text, 2, clr)
if ren.get_width() > self.width:
self.width = ren.get_width()
surface.blit(ren, ((self.x+self.width/2) - ren.get_width()/2, self.y + i*(self.font.get_height()+4)))
i+=1
def update(self, events):
for e in events:
if e.type == pygame.KEYDOWN:
if e.key == pygame.K_DOWN:
self.option += 1
if e.key == pygame.K_UP:
self.option -= 1
if e.key == pygame.K_RETURN:
self.options[self.option][1]()
if self.option > len(self.options)-1:
self.option = 0
if self.option < 0:
self.option = len(self.options)-1
def set_pos(self, x, y):
self.x = x
self.y = y
def set_font(self, font):
self.font = font
def set_highlight_color(self, color):
self.hcolor = color
def set_normal_color(self, color):
self.color = color
def center_at(self, x, y):
self.x = x-(self.width/2)
self.y = y-(self.height/2)
|
gpl-3.0
|
[
3168,
1182,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
473,
1911,
642,
570,
6272,
17897,
603,
6936,
699,
4796,
2366,
199,
3,
5313,
701,
869,
42,
4178,
921,
22943,
14,
846,
15,
6776,
15,
4792,
77,
759,
2873,
293,
681,
15,
199,
3,
314,
4890,
1736,
365,
18233,
1334,
14629,
19,
22160,
473,
883,
440,
6705,
3,
4190,
402,
642,
570,
199,
3,
11703,
642,
365,
314,
3379,
4132,
12,
781,
883,
8966,
26457,
15,
2523,
1455,
921,
1544,
14,
22278,
14,
1308,
15,
1715,
13,
37,
90,
1352,
21988,
13,
12593,
30858,
1360,
199,
199,
646,
9193,
421,
199,
533,
662,
90,
5977,
26,
339,
347,
636,
826,
721,
277,
12,
627,
1419,
304,
398,
291,
14,
1419,
275,
1511,
267,
291,
14,
88,
275,
378,
267,
291,
14,
89,
275,
378,
267,
291,
14,
4246,
275,
9193,
14,
4246,
14,
6986,
8,
403,
12,
4337,
9,
267,
291,
14,
1422,
275,
378,
267,
291,
14,
2063,
275,
413,
267,
291,
14,
2326,
275,
359,
16,
12,
378,
12,
378,
61,
267,
291,
14,
72,
2326,
275,
359,
2299,
12,
378,
12,
378,
61,
267,
291,
14,
3333,
275,
822,
8,
277,
14,
1419,
3342,
277,
14,
4246,
14,
362,
63,
3333,
342,
267,
367,
312,
315,
291,
14,
1419,
26,
288,
1318,
275,
312,
59,
16,
61,
288,
2903,
275,
291,
14,
4246,
14,
3352,
8,
505,
12,
499,
12,
334,
16,
12,
378,
12,
378,
430,
288,
340,
2903,
14,
362,
63,
2063,
342,
690,
291,
14,
2063,
26,
355,
291,
14,
2063,
275,
2903,
14,
362,
63,
2063,
342,
339,
347,
5954,
8,
277,
12,
13195,
304,
267,
284,
29,
16,
267,
367,
312,
315,
291,
14,
1419,
26,
288,
340,
284,
389,
277,
14,
1422,
26,
355,
824,
82,
275,
291,
14,
72,
2326,
288,
587,
26,
355,
824,
82,
275,
291,
14,
2326,
288,
1318,
275,
312,
59,
16,
61,
288,
2903,
275,
291,
14,
4246,
14,
3352,
8,
505,
12,
499,
12,
824,
82,
9,
288,
340,
2903,
14,
362,
63,
2063,
342,
690,
291,
14,
2063,
26,
355,
291,
14,
2063,
275,
2903,
14,
362,
63,
2063,
342,
288,
13195,
14,
15574,
8,
828,
12,
3666,
277,
14,
88,
11,
277,
14,
2063,
15,
18,
9,
446,
2903,
14,
362,
63,
2063,
29728,
18,
12,
291,
14,
89,
435,
284,
5830,
277,
14,
4246,
14,
362,
63,
3333,
24543,
20,
1724,
288,
284,
10365,
17,
15567,
347,
1678,
8,
277,
12,
4474,
304,
267,
367,
325,
315,
4474,
26,
288,
340,
325,
14,
466,
508,
9193,
14,
3078,
8819,
26,
355,
340,
325,
14,
498,
508,
9193,
14,
43,
63,
8819,
26,
490,
291,
14,
1422,
847,
413,
355,
340,
325,
14,
498,
508,
9193,
14,
43,
63,
2160,
26,
490,
291,
14,
1422,
4862,
413,
355,
340,
325,
14,
498,
508,
9193,
14,
43,
63,
9677,
26,
258,
490,
291,
14,
1419,
59,
277,
14,
1422,
1527,
17,
32702,
267,
340,
291,
14,
1422,
690,
822,
8,
277,
14,
1419,
7216,
17,
26,
288,
291,
14,
1422,
275,
378,
267,
340,
291,
14,
1422,
665,
378,
26,
288,
291,
14,
1422,
275,
822,
8,
277,
14,
1419,
7216,
17,
339,
347,
663,
63,
1712,
8,
277,
12,
671,
12,
612,
304,
420,
267,
291,
14,
88,
275,
671,
267,
291,
14,
89,
275,
612,
5493,
347,
663,
63,
4246,
8,
277,
12,
5023,
304,
267,
291,
14,
4246,
275,
5023,
5493,
347,
663,
63,
14337,
63,
2326,
8,
277,
12,
3164,
304,
267,
291,
14,
72,
2326,
275,
3164,
5493,
347,
663,
63,
3302,
63,
2326,
8,
277,
12,
3164,
304,
267,
291,
14,
2326,
275,
3164,
5493,
347,
8126,
63,
292,
8,
277,
12,
671,
12,
612,
304,
267,
291,
14,
88,
275,
671,
15426,
277,
14,
2063,
15,
18,
9,
267,
291,
14,
89,
275,
612,
15426,
277,
14,
3333,
15,
18,
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
] |
[
1182,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
473,
1911,
642,
570,
6272,
17897,
603,
6936,
699,
4796,
2366,
199,
3,
5313,
701,
869,
42,
4178,
921,
22943,
14,
846,
15,
6776,
15,
4792,
77,
759,
2873,
293,
681,
15,
199,
3,
314,
4890,
1736,
365,
18233,
1334,
14629,
19,
22160,
473,
883,
440,
6705,
3,
4190,
402,
642,
570,
199,
3,
11703,
642,
365,
314,
3379,
4132,
12,
781,
883,
8966,
26457,
15,
2523,
1455,
921,
1544,
14,
22278,
14,
1308,
15,
1715,
13,
37,
90,
1352,
21988,
13,
12593,
30858,
1360,
199,
199,
646,
9193,
421,
199,
533,
662,
90,
5977,
26,
339,
347,
636,
826,
721,
277,
12,
627,
1419,
304,
398,
291,
14,
1419,
275,
1511,
267,
291,
14,
88,
275,
378,
267,
291,
14,
89,
275,
378,
267,
291,
14,
4246,
275,
9193,
14,
4246,
14,
6986,
8,
403,
12,
4337,
9,
267,
291,
14,
1422,
275,
378,
267,
291,
14,
2063,
275,
413,
267,
291,
14,
2326,
275,
359,
16,
12,
378,
12,
378,
61,
267,
291,
14,
72,
2326,
275,
359,
2299,
12,
378,
12,
378,
61,
267,
291,
14,
3333,
275,
822,
8,
277,
14,
1419,
3342,
277,
14,
4246,
14,
362,
63,
3333,
342,
267,
367,
312,
315,
291,
14,
1419,
26,
288,
1318,
275,
312,
59,
16,
61,
288,
2903,
275,
291,
14,
4246,
14,
3352,
8,
505,
12,
499,
12,
334,
16,
12,
378,
12,
378,
430,
288,
340,
2903,
14,
362,
63,
2063,
342,
690,
291,
14,
2063,
26,
355,
291,
14,
2063,
275,
2903,
14,
362,
63,
2063,
342,
339,
347,
5954,
8,
277,
12,
13195,
304,
267,
284,
29,
16,
267,
367,
312,
315,
291,
14,
1419,
26,
288,
340,
284,
389,
277,
14,
1422,
26,
355,
824,
82,
275,
291,
14,
72,
2326,
288,
587,
26,
355,
824,
82,
275,
291,
14,
2326,
288,
1318,
275,
312,
59,
16,
61,
288,
2903,
275,
291,
14,
4246,
14,
3352,
8,
505,
12,
499,
12,
824,
82,
9,
288,
340,
2903,
14,
362,
63,
2063,
342,
690,
291,
14,
2063,
26,
355,
291,
14,
2063,
275,
2903,
14,
362,
63,
2063,
342,
288,
13195,
14,
15574,
8,
828,
12,
3666,
277,
14,
88,
11,
277,
14,
2063,
15,
18,
9,
446,
2903,
14,
362,
63,
2063,
29728,
18,
12,
291,
14,
89,
435,
284,
5830,
277,
14,
4246,
14,
362,
63,
3333,
24543,
20,
1724,
288,
284,
10365,
17,
15567,
347,
1678,
8,
277,
12,
4474,
304,
267,
367,
325,
315,
4474,
26,
288,
340,
325,
14,
466,
508,
9193,
14,
3078,
8819,
26,
355,
340,
325,
14,
498,
508,
9193,
14,
43,
63,
8819,
26,
490,
291,
14,
1422,
847,
413,
355,
340,
325,
14,
498,
508,
9193,
14,
43,
63,
2160,
26,
490,
291,
14,
1422,
4862,
413,
355,
340,
325,
14,
498,
508,
9193,
14,
43,
63,
9677,
26,
258,
490,
291,
14,
1419,
59,
277,
14,
1422,
1527,
17,
32702,
267,
340,
291,
14,
1422,
690,
822,
8,
277,
14,
1419,
7216,
17,
26,
288,
291,
14,
1422,
275,
378,
267,
340,
291,
14,
1422,
665,
378,
26,
288,
291,
14,
1422,
275,
822,
8,
277,
14,
1419,
7216,
17,
339,
347,
663,
63,
1712,
8,
277,
12,
671,
12,
612,
304,
420,
267,
291,
14,
88,
275,
671,
267,
291,
14,
89,
275,
612,
5493,
347,
663,
63,
4246,
8,
277,
12,
5023,
304,
267,
291,
14,
4246,
275,
5023,
5493,
347,
663,
63,
14337,
63,
2326,
8,
277,
12,
3164,
304,
267,
291,
14,
72,
2326,
275,
3164,
5493,
347,
663,
63,
3302,
63,
2326,
8,
277,
12,
3164,
304,
267,
291,
14,
2326,
275,
3164,
5493,
347,
8126,
63,
292,
8,
277,
12,
671,
12,
612,
304,
267,
291,
14,
88,
275,
671,
15426,
277,
14,
2063,
15,
18,
9,
267,
291,
14,
89,
275,
612,
15426,
277,
14,
3333,
15,
18,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
spring-week-topos/cinder-week
|
cinder/api/contrib/types_manage.py
|
4
|
4787
|
# Copyright (c) 2011 Zadara Storage Inc.
# Copyright (c) 2011 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.
"""The volume types manage extension."""
import six
import webob
from cinder.api import extensions
from cinder.api.openstack import wsgi
from cinder.api.v1 import types
from cinder.api.views import types as views_types
from cinder import exception
from cinder import rpc
from cinder.volume import volume_types
authorize = extensions.extension_authorizer('volume', 'types_manage')
class VolumeTypesManageController(wsgi.Controller):
"""The volume types API controller for the OpenStack API."""
_view_builder_class = views_types.ViewBuilder
def _notify_volume_type_error(self, context, method, payload):
rpc.get_notifier('volumeType').error(context, method, payload)
@wsgi.action("create")
@wsgi.serializers(xml=types.VolumeTypeTemplate)
def _create(self, req, body):
"""Creates a new volume type."""
context = req.environ['cinder.context']
authorize(context)
if not self.is_valid_body(body, 'volume_type'):
raise webob.exc.HTTPBadRequest()
vol_type = body['volume_type']
name = vol_type.get('name', None)
specs = vol_type.get('extra_specs', {})
if name is None or name == "":
raise webob.exc.HTTPBadRequest()
try:
volume_types.create(context, name, specs)
vol_type = volume_types.get_volume_type_by_name(context, name)
notifier_info = dict(volume_types=vol_type)
rpc.get_notifier('volumeType').info(context, 'volume_type.create',
notifier_info)
except exception.VolumeTypeExists as err:
notifier_err = dict(volume_types=vol_type, error_message=err)
self._notify_volume_type_error(context,
'volume_type.create',
notifier_err)
raise webob.exc.HTTPConflict(explanation=six.text_type(err))
except exception.NotFound as err:
notifier_err = dict(volume_types=vol_type, error_message=err)
self._notify_volume_type_error(context,
'volume_type.create',
notifier_err)
raise webob.exc.HTTPNotFound()
return self._view_builder.show(req, vol_type)
@wsgi.action("delete")
def _delete(self, req, id):
"""Deletes an existing volume type."""
context = req.environ['cinder.context']
authorize(context)
try:
vol_type = volume_types.get_volume_type(context, id)
volume_types.destroy(context, vol_type['id'])
notifier_info = dict(volume_types=vol_type)
rpc.get_notifier('volumeType').info(context,
'volume_type.delete',
notifier_info)
except exception.VolumeTypeInUse as err:
notifier_err = dict(id=id, error_message=err)
self._notify_volume_type_error(context,
'volume_type.delete',
notifier_err)
msg = _('Target volume type is still in use.')
raise webob.exc.HTTPBadRequest(explanation=msg)
except exception.NotFound as err:
notifier_err = dict(id=id, error_message=err)
self._notify_volume_type_error(context,
'volume_type.delete',
notifier_err)
raise webob.exc.HTTPNotFound()
return webob.Response(status_int=202)
class Types_manage(extensions.ExtensionDescriptor):
"""Types manage support."""
name = "TypesManage"
alias = "os-types-manage"
namespace = "http://docs.openstack.org/volume/ext/types-manage/api/v1"
updated = "2011-08-24T00:00:00+00:00"
def get_controller_extensions(self):
controller = VolumeTypesManageController()
extension = extensions.ControllerExtension(self, 'types', controller)
return [extension]
|
apache-2.0
|
[
3,
1898,
334,
67,
9,
7760,
3107,
350,
17956,
10533,
3277,
14,
199,
3,
1898,
334,
67,
9,
7760,
14260,
2752,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
624,
1918,
3301,
2943,
9635,
3329,
1041,
199,
199,
646,
3816,
199,
646,
14568,
199,
199,
504,
13069,
14,
1246,
492,
5478,
199,
504,
13069,
14,
1246,
14,
8512,
492,
12464,
199,
504,
13069,
14,
1246,
14,
86,
17,
492,
2943,
199,
504,
13069,
14,
1246,
14,
4196,
492,
2943,
465,
6858,
63,
1313,
199,
504,
13069,
492,
1919,
199,
504,
13069,
492,
8985,
199,
504,
13069,
14,
2405,
492,
3301,
63,
1313,
421,
199,
14204,
275,
5478,
14,
3435,
63,
2502,
1793,
360,
2405,
297,
283,
1313,
63,
9053,
358,
421,
199,
533,
15018,
4100,
20588,
7506,
8,
6508,
14,
7506,
304,
272,
408,
1918,
3301,
2943,
3261,
7614,
367,
314,
14260,
3261,
1041,
339,
485,
1345,
63,
5649,
63,
533,
275,
6858,
63,
1313,
14,
2768,
6437,
339,
347,
485,
6814,
63,
2405,
63,
466,
63,
705,
8,
277,
12,
1067,
12,
1083,
12,
4886,
304,
267,
8985,
14,
362,
63,
18031,
360,
2405,
804,
1959,
705,
8,
1100,
12,
1083,
12,
4886,
9,
339,
768,
6508,
14,
1287,
480,
981,
531,
272,
768,
6508,
14,
12844,
8,
1652,
29,
1313,
14,
6464,
804,
4231,
9,
272,
347,
485,
981,
8,
277,
12,
2648,
12,
2396,
304,
267,
408,
10607,
282,
892,
3301,
730,
1041,
267,
1067,
275,
2648,
14,
2314,
459,
12372,
14,
1100,
418,
267,
20210,
8,
1100,
9,
398,
340,
440,
291,
14,
374,
63,
1078,
63,
2030,
8,
2030,
12,
283,
2405,
63,
466,
735,
288,
746,
14568,
14,
2804,
14,
21070,
342,
398,
5236,
63,
466,
275,
2396,
459,
2405,
63,
466,
418,
267,
536,
275,
5236,
63,
466,
14,
362,
360,
354,
297,
488,
9,
267,
15941,
275,
5236,
63,
466,
14,
362,
360,
2911,
63,
7273,
297,
5009,
398,
340,
536,
365,
488,
503,
536,
508,
10812,
288,
746,
14568,
14,
2804,
14,
21070,
342,
398,
862,
26,
288,
3301,
63,
1313,
14,
981,
8,
1100,
12,
536,
12,
15941,
9,
288,
5236,
63,
466,
275,
3301,
63,
1313,
14,
362,
63,
2405,
63,
466,
63,
991,
63,
354,
8,
1100,
12,
536,
9,
288,
30154,
63,
815,
275,
1211,
8,
2405,
63,
1313,
29,
5650,
63,
466,
9,
288,
8985,
14,
362,
63,
18031,
360,
2405,
804,
1959,
815,
8,
1100,
12,
283,
2405,
63,
466,
14,
981,
297,
6059,
30154,
63,
815,
9,
398,
871,
1919,
14,
6464,
804,
7965,
465,
2329,
26,
288,
30154,
63,
1508,
275,
1211,
8,
2405,
63,
1313,
29,
5650,
63,
466,
12,
1125,
63,
1188,
29,
1508,
9,
288,
291,
423,
6814,
63,
2405,
63,
466,
63,
705,
8,
1100,
12,
5644,
283,
2405,
63,
466,
14,
981,
297,
5644,
30154,
63,
1508,
9,
953,
746,
14568,
14,
2804,
14,
2856,
15919,
8,
15228,
29,
4174,
14,
505,
63,
466,
8,
1508,
430,
267,
871,
1919,
14,
4667,
465,
2329,
26,
288,
30154,
63,
1508,
275,
1211,
8,
2405,
63,
1313,
29,
5650,
63,
466,
12,
1125,
63,
1188,
29,
1508,
9,
288,
291,
423,
6814,
63,
2405,
63,
466,
63,
705,
8,
1100,
12,
5644,
283,
2405,
63,
466,
14,
981,
297,
5644,
30154,
63,
1508,
9,
288,
746,
14568,
14,
2804,
14,
26553,
342,
398,
372,
291,
423,
1345,
63,
5649,
14,
2384,
8,
2103,
12,
5236,
63,
466,
9,
339,
768,
6508,
14,
1287,
480,
1807,
531,
272,
347,
485,
1807,
8,
277,
12,
2648,
12,
1305,
304,
267,
408,
26372,
376,
3411,
3301,
730,
1041,
267,
1067,
275,
2648,
14,
2314,
459,
12372,
14,
1100,
418,
267,
20210,
8,
1100,
9,
398,
862,
26,
288,
5236,
63,
466,
275,
3301,
63,
1313,
14,
362,
63,
2405,
63,
466,
8,
1100,
12,
1305,
9,
288,
3301,
63,
1313,
14,
7237,
8,
1100,
12,
5236,
63,
466,
459,
344,
1105,
288,
30154,
63,
815,
275,
1211,
8,
2405,
63,
1313,
29,
5650,
63,
466,
9,
288,
8985,
14,
362,
63,
18031,
360,
2405,
804,
1959,
815,
8,
1100,
12,
6059,
283,
2405,
63,
466,
14,
1807,
297,
6059,
30154,
63,
815,
9,
267,
871,
1919,
14,
6464,
804,
31425,
465,
2329,
26,
288,
30154,
63,
1508,
275,
1211,
8,
344,
29,
344,
12,
1125,
63,
1188,
29,
1508,
9,
288,
291,
423,
6814,
63,
2405,
63,
466,
63,
705,
8,
1100,
12,
5644,
283,
2405,
63,
466,
14,
1807,
297,
5644,
30154,
63,
1508,
9,
288,
1499,
275,
4018,
4277,
3301,
730,
365,
5139,
315,
675,
2659,
288,
746,
14568,
14,
2804,
14,
21070,
8,
15228,
29,
1328,
9,
267,
871,
1919,
14,
4667,
465,
2329,
26,
288,
30154,
63,
1508,
275,
1211,
8,
344,
29,
344,
12,
1125,
63,
1188,
29,
1508,
9,
288,
291,
423,
6814,
63,
2405,
63,
466,
63,
705,
8,
1100,
12,
5644,
283,
2405,
63,
466,
14,
1807,
297,
5644,
30154,
63,
1508,
9,
953,
746,
14568,
14,
2804,
14,
26553,
342,
398,
372,
14568,
14,
2364,
8,
1205,
63,
442,
29,
4999,
9,
421,
199,
533,
18851,
63,
9053,
8,
5359,
14,
6382,
4311,
304,
272,
408,
4100,
9635,
2291,
1041,
339,
536,
275,
298,
4100,
20588,
2,
272,
5162,
275,
298,
736,
13,
1313,
13,
9053,
2,
272,
3231,
275,
298,
1014,
921,
4757,
14,
8512,
14,
1308,
15,
2405,
15,
832,
15,
1313,
13
] |
[
1898,
334,
67,
9,
7760,
3107,
350,
17956,
10533,
3277,
14,
199,
3,
1898,
334,
67,
9,
7760,
14260,
2752,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
624,
1918,
3301,
2943,
9635,
3329,
1041,
199,
199,
646,
3816,
199,
646,
14568,
199,
199,
504,
13069,
14,
1246,
492,
5478,
199,
504,
13069,
14,
1246,
14,
8512,
492,
12464,
199,
504,
13069,
14,
1246,
14,
86,
17,
492,
2943,
199,
504,
13069,
14,
1246,
14,
4196,
492,
2943,
465,
6858,
63,
1313,
199,
504,
13069,
492,
1919,
199,
504,
13069,
492,
8985,
199,
504,
13069,
14,
2405,
492,
3301,
63,
1313,
421,
199,
14204,
275,
5478,
14,
3435,
63,
2502,
1793,
360,
2405,
297,
283,
1313,
63,
9053,
358,
421,
199,
533,
15018,
4100,
20588,
7506,
8,
6508,
14,
7506,
304,
272,
408,
1918,
3301,
2943,
3261,
7614,
367,
314,
14260,
3261,
1041,
339,
485,
1345,
63,
5649,
63,
533,
275,
6858,
63,
1313,
14,
2768,
6437,
339,
347,
485,
6814,
63,
2405,
63,
466,
63,
705,
8,
277,
12,
1067,
12,
1083,
12,
4886,
304,
267,
8985,
14,
362,
63,
18031,
360,
2405,
804,
1959,
705,
8,
1100,
12,
1083,
12,
4886,
9,
339,
768,
6508,
14,
1287,
480,
981,
531,
272,
768,
6508,
14,
12844,
8,
1652,
29,
1313,
14,
6464,
804,
4231,
9,
272,
347,
485,
981,
8,
277,
12,
2648,
12,
2396,
304,
267,
408,
10607,
282,
892,
3301,
730,
1041,
267,
1067,
275,
2648,
14,
2314,
459,
12372,
14,
1100,
418,
267,
20210,
8,
1100,
9,
398,
340,
440,
291,
14,
374,
63,
1078,
63,
2030,
8,
2030,
12,
283,
2405,
63,
466,
735,
288,
746,
14568,
14,
2804,
14,
21070,
342,
398,
5236,
63,
466,
275,
2396,
459,
2405,
63,
466,
418,
267,
536,
275,
5236,
63,
466,
14,
362,
360,
354,
297,
488,
9,
267,
15941,
275,
5236,
63,
466,
14,
362,
360,
2911,
63,
7273,
297,
5009,
398,
340,
536,
365,
488,
503,
536,
508,
10812,
288,
746,
14568,
14,
2804,
14,
21070,
342,
398,
862,
26,
288,
3301,
63,
1313,
14,
981,
8,
1100,
12,
536,
12,
15941,
9,
288,
5236,
63,
466,
275,
3301,
63,
1313,
14,
362,
63,
2405,
63,
466,
63,
991,
63,
354,
8,
1100,
12,
536,
9,
288,
30154,
63,
815,
275,
1211,
8,
2405,
63,
1313,
29,
5650,
63,
466,
9,
288,
8985,
14,
362,
63,
18031,
360,
2405,
804,
1959,
815,
8,
1100,
12,
283,
2405,
63,
466,
14,
981,
297,
6059,
30154,
63,
815,
9,
398,
871,
1919,
14,
6464,
804,
7965,
465,
2329,
26,
288,
30154,
63,
1508,
275,
1211,
8,
2405,
63,
1313,
29,
5650,
63,
466,
12,
1125,
63,
1188,
29,
1508,
9,
288,
291,
423,
6814,
63,
2405,
63,
466,
63,
705,
8,
1100,
12,
5644,
283,
2405,
63,
466,
14,
981,
297,
5644,
30154,
63,
1508,
9,
953,
746,
14568,
14,
2804,
14,
2856,
15919,
8,
15228,
29,
4174,
14,
505,
63,
466,
8,
1508,
430,
267,
871,
1919,
14,
4667,
465,
2329,
26,
288,
30154,
63,
1508,
275,
1211,
8,
2405,
63,
1313,
29,
5650,
63,
466,
12,
1125,
63,
1188,
29,
1508,
9,
288,
291,
423,
6814,
63,
2405,
63,
466,
63,
705,
8,
1100,
12,
5644,
283,
2405,
63,
466,
14,
981,
297,
5644,
30154,
63,
1508,
9,
288,
746,
14568,
14,
2804,
14,
26553,
342,
398,
372,
291,
423,
1345,
63,
5649,
14,
2384,
8,
2103,
12,
5236,
63,
466,
9,
339,
768,
6508,
14,
1287,
480,
1807,
531,
272,
347,
485,
1807,
8,
277,
12,
2648,
12,
1305,
304,
267,
408,
26372,
376,
3411,
3301,
730,
1041,
267,
1067,
275,
2648,
14,
2314,
459,
12372,
14,
1100,
418,
267,
20210,
8,
1100,
9,
398,
862,
26,
288,
5236,
63,
466,
275,
3301,
63,
1313,
14,
362,
63,
2405,
63,
466,
8,
1100,
12,
1305,
9,
288,
3301,
63,
1313,
14,
7237,
8,
1100,
12,
5236,
63,
466,
459,
344,
1105,
288,
30154,
63,
815,
275,
1211,
8,
2405,
63,
1313,
29,
5650,
63,
466,
9,
288,
8985,
14,
362,
63,
18031,
360,
2405,
804,
1959,
815,
8,
1100,
12,
6059,
283,
2405,
63,
466,
14,
1807,
297,
6059,
30154,
63,
815,
9,
267,
871,
1919,
14,
6464,
804,
31425,
465,
2329,
26,
288,
30154,
63,
1508,
275,
1211,
8,
344,
29,
344,
12,
1125,
63,
1188,
29,
1508,
9,
288,
291,
423,
6814,
63,
2405,
63,
466,
63,
705,
8,
1100,
12,
5644,
283,
2405,
63,
466,
14,
1807,
297,
5644,
30154,
63,
1508,
9,
288,
1499,
275,
4018,
4277,
3301,
730,
365,
5139,
315,
675,
2659,
288,
746,
14568,
14,
2804,
14,
21070,
8,
15228,
29,
1328,
9,
267,
871,
1919,
14,
4667,
465,
2329,
26,
288,
30154,
63,
1508,
275,
1211,
8,
344,
29,
344,
12,
1125,
63,
1188,
29,
1508,
9,
288,
291,
423,
6814,
63,
2405,
63,
466,
63,
705,
8,
1100,
12,
5644,
283,
2405,
63,
466,
14,
1807,
297,
5644,
30154,
63,
1508,
9,
953,
746,
14568,
14,
2804,
14,
26553,
342,
398,
372,
14568,
14,
2364,
8,
1205,
63,
442,
29,
4999,
9,
421,
199,
533,
18851,
63,
9053,
8,
5359,
14,
6382,
4311,
304,
272,
408,
4100,
9635,
2291,
1041,
339,
536,
275,
298,
4100,
20588,
2,
272,
5162,
275,
298,
736,
13,
1313,
13,
9053,
2,
272,
3231,
275,
298,
1014,
921,
4757,
14,
8512,
14,
1308,
15,
2405,
15,
832,
15,
1313,
13,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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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
] |
2014c2g1/c2g1
|
w2/static/Brython2.0.0-20140209-164925/Lib/xml/sax/saxutils.py
|
730
|
11688
|
"""\
A library of useful helper classes to the SAX classes, for the
convenience of application and driver writers.
"""
import os, urllib.parse, urllib.request
import io
from . import handler
from . import xmlreader
def __dict_replace(s, d):
"""Replace substrings of a string using a dictionary."""
for key, value in d.items():
s = s.replace(key, value)
return s
def escape(data, entities={}):
"""Escape &, <, and > in a string of data.
You can escape other strings of data by passing a dictionary as
the optional entities parameter. The keys and values must all be
strings; each key will be replaced with its corresponding value.
"""
# must do ampersand first
data = data.replace("&", "&")
data = data.replace(">", ">")
data = data.replace("<", "<")
if entities:
data = __dict_replace(data, entities)
return data
def unescape(data, entities={}):
"""Unescape &, <, and > in a string of data.
You can unescape other strings of data by passing a dictionary as
the optional entities parameter. The keys and values must all be
strings; each key will be replaced with its corresponding value.
"""
data = data.replace("<", "<")
data = data.replace(">", ">")
if entities:
data = __dict_replace(data, entities)
# must do ampersand last
return data.replace("&", "&")
def quoteattr(data, entities={}):
"""Escape and quote an attribute value.
Escape &, <, and > in a string of data, then quote it for use as
an attribute value. The \" character will be escaped as well, if
necessary.
You can escape other strings of data by passing a dictionary as
the optional entities parameter. The keys and values must all be
strings; each key will be replaced with its corresponding value.
"""
entities = entities.copy()
entities.update({'\n': ' ', '\r': ' ', '\t':'	'})
data = escape(data, entities)
if '"' in data:
if "'" in data:
data = '"%s"' % data.replace('"', """)
else:
data = "'%s'" % data
else:
data = '"%s"' % data
return data
def _gettextwriter(out, encoding):
if out is None:
import sys
return sys.stdout
if isinstance(out, io.TextIOBase):
# use a text writer as is
return out
# wrap a binary writer with TextIOWrapper
if isinstance(out, io.RawIOBase):
# Keep the original file open when the TextIOWrapper is
# destroyed
class _wrapper:
__class__ = out.__class__
def __getattr__(self, name):
return getattr(out, name)
buffer = _wrapper()
buffer.close = lambda: None
else:
# This is to handle passed objects that aren't in the
# IOBase hierarchy, but just have a write method
buffer = io.BufferedIOBase()
buffer.writable = lambda: True
buffer.write = out.write
try:
# TextIOWrapper uses this methods to determine
# if BOM (for UTF-16, etc) should be added
buffer.seekable = out.seekable
buffer.tell = out.tell
except AttributeError:
pass
return io.TextIOWrapper(buffer, encoding=encoding,
errors='xmlcharrefreplace',
newline='\n',
write_through=True)
class XMLGenerator(handler.ContentHandler):
def __init__(self, out=None, encoding="iso-8859-1", short_empty_elements=False):
handler.ContentHandler.__init__(self)
out = _gettextwriter(out, encoding)
self._write = out.write
self._flush = out.flush
self._ns_contexts = [{}] # contains uri -> prefix dicts
self._current_context = self._ns_contexts[-1]
self._undeclared_ns_maps = []
self._encoding = encoding
self._short_empty_elements = short_empty_elements
self._pending_start_element = False
def _qname(self, name):
"""Builds a qualified name from a (ns_url, localname) pair"""
if name[0]:
# Per http://www.w3.org/XML/1998/namespace, The 'xml' prefix is
# bound by definition to http://www.w3.org/XML/1998/namespace. It
# does not need to be declared and will not usually be found in
# self._current_context.
if 'http://www.w3.org/XML/1998/namespace' == name[0]:
return 'xml:' + name[1]
# The name is in a non-empty namespace
prefix = self._current_context[name[0]]
if prefix:
# If it is not the default namespace, prepend the prefix
return prefix + ":" + name[1]
# Return the unqualified name
return name[1]
def _finish_pending_start_element(self,endElement=False):
if self._pending_start_element:
self._write('>')
self._pending_start_element = False
# ContentHandler methods
def startDocument(self):
self._write('<?xml version="1.0" encoding="%s"?>\n' %
self._encoding)
def endDocument(self):
self._flush()
def startPrefixMapping(self, prefix, uri):
self._ns_contexts.append(self._current_context.copy())
self._current_context[uri] = prefix
self._undeclared_ns_maps.append((prefix, uri))
def endPrefixMapping(self, prefix):
self._current_context = self._ns_contexts[-1]
del self._ns_contexts[-1]
def startElement(self, name, attrs):
self._finish_pending_start_element()
self._write('<' + name)
for (name, value) in attrs.items():
self._write(' %s=%s' % (name, quoteattr(value)))
if self._short_empty_elements:
self._pending_start_element = True
else:
self._write(">")
def endElement(self, name):
if self._pending_start_element:
self._write('/>')
self._pending_start_element = False
else:
self._write('</%s>' % name)
def startElementNS(self, name, qname, attrs):
self._finish_pending_start_element()
self._write('<' + self._qname(name))
for prefix, uri in self._undeclared_ns_maps:
if prefix:
self._write(' xmlns:%s="%s"' % (prefix, uri))
else:
self._write(' xmlns="%s"' % uri)
self._undeclared_ns_maps = []
for (name, value) in attrs.items():
self._write(' %s=%s' % (self._qname(name), quoteattr(value)))
if self._short_empty_elements:
self._pending_start_element = True
else:
self._write(">")
def endElementNS(self, name, qname):
if self._pending_start_element:
self._write('/>')
self._pending_start_element = False
else:
self._write('</%s>' % self._qname(name))
def characters(self, content):
if content:
self._finish_pending_start_element()
self._write(escape(content))
def ignorableWhitespace(self, content):
if content:
self._finish_pending_start_element()
self._write(content)
def processingInstruction(self, target, data):
self._finish_pending_start_element()
self._write('<?%s %s?>' % (target, data))
class XMLFilterBase(xmlreader.XMLReader):
"""This class is designed to sit between an XMLReader and the
client application's event handlers. By default, it does nothing
but pass requests up to the reader and events on to the handlers
unmodified, but subclasses can override specific methods to modify
the event stream or the configuration requests as they pass
through."""
def __init__(self, parent = None):
xmlreader.XMLReader.__init__(self)
self._parent = parent
# ErrorHandler methods
def error(self, exception):
self._err_handler.error(exception)
def fatalError(self, exception):
self._err_handler.fatalError(exception)
def warning(self, exception):
self._err_handler.warning(exception)
# ContentHandler methods
def setDocumentLocator(self, locator):
self._cont_handler.setDocumentLocator(locator)
def startDocument(self):
self._cont_handler.startDocument()
def endDocument(self):
self._cont_handler.endDocument()
def startPrefixMapping(self, prefix, uri):
self._cont_handler.startPrefixMapping(prefix, uri)
def endPrefixMapping(self, prefix):
self._cont_handler.endPrefixMapping(prefix)
def startElement(self, name, attrs):
self._cont_handler.startElement(name, attrs)
def endElement(self, name):
self._cont_handler.endElement(name)
def startElementNS(self, name, qname, attrs):
self._cont_handler.startElementNS(name, qname, attrs)
def endElementNS(self, name, qname):
self._cont_handler.endElementNS(name, qname)
def characters(self, content):
self._cont_handler.characters(content)
def ignorableWhitespace(self, chars):
self._cont_handler.ignorableWhitespace(chars)
def processingInstruction(self, target, data):
self._cont_handler.processingInstruction(target, data)
def skippedEntity(self, name):
self._cont_handler.skippedEntity(name)
# DTDHandler methods
def notationDecl(self, name, publicId, systemId):
self._dtd_handler.notationDecl(name, publicId, systemId)
def unparsedEntityDecl(self, name, publicId, systemId, ndata):
self._dtd_handler.unparsedEntityDecl(name, publicId, systemId, ndata)
# EntityResolver methods
def resolveEntity(self, publicId, systemId):
return self._ent_handler.resolveEntity(publicId, systemId)
# XMLReader methods
def parse(self, source):
self._parent.setContentHandler(self)
self._parent.setErrorHandler(self)
self._parent.setEntityResolver(self)
self._parent.setDTDHandler(self)
self._parent.parse(source)
def setLocale(self, locale):
self._parent.setLocale(locale)
def getFeature(self, name):
return self._parent.getFeature(name)
def setFeature(self, name, state):
self._parent.setFeature(name, state)
def getProperty(self, name):
return self._parent.getProperty(name)
def setProperty(self, name, value):
self._parent.setProperty(name, value)
# XMLFilter methods
def getParent(self):
return self._parent
def setParent(self, parent):
self._parent = parent
# --- Utility functions
def prepare_input_source(source, base=""):
"""This function takes an InputSource and an optional base URL and
returns a fully resolved InputSource object ready for reading."""
if isinstance(source, str):
source = xmlreader.InputSource(source)
elif hasattr(source, "read"):
f = source
source = xmlreader.InputSource()
source.setByteStream(f)
if hasattr(f, "name"):
source.setSystemId(f.name)
if source.getByteStream() is None:
sysid = source.getSystemId()
basehead = os.path.dirname(os.path.normpath(base))
sysidfilename = os.path.join(basehead, sysid)
if os.path.isfile(sysidfilename):
source.setSystemId(sysidfilename)
f = open(sysidfilename, "rb")
else:
source.setSystemId(urllib.parse.urljoin(base, sysid))
f = urllib.request.urlopen(source.getSystemId())
source.setByteStream(f)
return source
|
gpl-2.0
|
[
19659,
199,
33,
3555,
402,
2997,
5922,
3992,
370,
314,
19310,
3992,
12,
367,
314,
199,
388,
23329,
402,
4223,
436,
5253,
2211,
878,
14,
199,
624,
199,
199,
646,
747,
12,
4011,
14,
1122,
12,
4011,
14,
1069,
199,
646,
5890,
199,
504,
1275,
492,
3016,
199,
504,
1275,
492,
2748,
5503,
199,
199,
318,
636,
807,
63,
1814,
8,
83,
12,
366,
304,
272,
408,
11328,
1007,
5465,
402,
282,
1059,
1808,
282,
2600,
1041,
272,
367,
790,
12,
574,
315,
366,
14,
1744,
837,
267,
308,
275,
308,
14,
1814,
8,
498,
12,
574,
9,
272,
372,
308,
199,
199,
318,
4772,
8,
576,
12,
9045,
16420,
272,
408,
10260,
17181,
665,
12,
436,
690,
315,
282,
1059,
402,
666,
14,
339,
2047,
883,
4772,
1163,
3326,
402,
666,
701,
9476,
282,
2600,
465,
272,
314,
2716,
9045,
2725,
14,
221,
710,
2883,
436,
1338,
1471,
1006,
506,
272,
3326,
27,
1924,
790,
911,
506,
8717,
543,
2399,
5226,
574,
14,
272,
408,
339,
327,
1471,
886,
15204,
1192,
460,
1642,
272,
666,
275,
666,
14,
1814,
22077,
401,
11746,
5282,
15027,
272,
666,
275,
666,
14,
1814,
480,
7166,
11746,
3308,
15027,
272,
666,
275,
666,
14,
1814,
6757,
401,
11746,
4116,
15027,
272,
340,
9045,
26,
267,
666,
275,
636,
807,
63,
1814,
8,
576,
12,
9045,
9,
272,
372,
666,
199,
199,
318,
22221,
8,
576,
12,
9045,
16420,
272,
408,
1358,
3765,
1253,
5282,
27031,
1253,
4116,
27031,
436,
1253,
3308,
27,
315,
282,
1059,
402,
666,
14,
339,
2047,
883,
22221,
1163,
3326,
402,
666,
701,
9476,
282,
2600,
465,
272,
314,
2716,
9045,
2725,
14,
221,
710,
2883,
436,
1338,
1471,
1006,
506,
272,
3326,
27,
1924,
790,
911,
506,
8717,
543,
2399,
5226,
574,
14,
272,
408,
272,
666,
275,
666,
14,
1814,
22077,
4116,
17259,
3886,
531,
272,
666,
275,
666,
14,
1814,
22077,
3308,
17259,
298,
9579,
272,
340,
9045,
26,
267,
666,
275,
636,
807,
63,
1814,
8,
576,
12,
9045,
9,
272,
327,
1471,
886,
15204,
1192,
460,
2061,
272,
372,
666,
14,
1814,
22077,
5282,
17259,
11746,
531,
199,
199,
318,
6313,
962,
8,
576,
12,
9045,
16420,
272,
408,
10260,
436,
6313,
376,
2225,
574,
14,
339,
21067,
17181,
665,
12,
436,
690,
315,
282,
1059,
402,
666,
12,
2066,
6313,
652,
367,
675,
465,
272,
376,
2225,
574,
14,
221,
710,
8441,
4528,
911,
506,
11077,
465,
5521,
12,
340,
272,
5784,
14,
339,
2047,
883,
4772,
1163,
3326,
402,
666,
701,
9476,
282,
2600,
465,
272,
314,
2716,
9045,
2725,
14,
221,
710,
2883,
436,
1338,
1471,
1006,
506,
272,
3326,
27,
1924,
790,
911,
506,
8717,
543,
2399,
5226,
574,
14,
272,
408,
272,
9045,
275,
9045,
14,
1574,
342,
272,
9045,
14,
873,
2561,
1154,
78,
356,
7673,
3,
709,
10805,
1557,
82,
356,
7673,
3,
969,
10805,
1557,
84,
5242,
7997,
25,
27,
3071,
272,
666,
275,
4772,
8,
576,
12,
9045,
9,
272,
340,
14788,
315,
666,
26,
267,
340,
21673,
315,
666,
26,
288,
666,
275,
18253,
83,
4507,
450,
666,
14,
1814,
20630,
11746,
5184,
15027,
267,
587,
26,
288,
666,
275,
17648,
83,
4065,
450,
666,
272,
587,
26,
267,
666,
275,
18253,
83,
4507,
450,
666,
272,
372,
666,
421,
199,
318,
485,
5152,
5491,
8,
548,
12,
2644,
304,
272,
340,
734,
365,
488,
26,
267,
492,
984,
267,
372,
984,
14,
2703,
339,
340,
1228,
8,
548,
12,
5890,
14,
1872,
23413,
304,
267,
327,
675,
282,
1318,
7060,
465,
365,
267,
372,
734,
339,
327,
4816,
282,
3366,
7060,
543,
4516,
29365,
272,
340,
1228,
8,
548,
12,
5890,
14,
7963,
23413,
304,
267,
327,
14797,
314,
3379,
570,
1551,
1380,
314,
4516,
29365,
365,
267,
327,
28924,
267,
1021,
485,
5029,
26,
288,
636,
533,
363,
275,
734,
855,
533,
363,
288,
347,
636,
5675,
721,
277,
12,
536,
304,
355,
372,
2519,
8,
548,
12,
536,
9,
267,
3335,
275,
485,
5029,
342,
267,
3335,
14,
1600,
275,
2400,
26,
488,
272,
587,
26,
267,
327,
961,
365,
370,
2429,
3032,
2251,
626,
10621,
1133,
315,
314,
267,
327,
5004,
1563,
14446,
12,
1325,
2951,
1172,
282,
2218,
1083,
267,
3335,
275,
5890,
14,
23139,
23413,
342,
267,
3335,
14,
15053,
275,
2400,
26,
715,
267,
3335,
14,
952,
275,
734,
14,
952,
267,
862,
26,
288,
327,
4516,
29365,
4440,
642,
3102,
370,
6705,
288,
327,
340,
17720,
334,
509,
9094,
13,
975,
12,
5423,
9,
1077,
506,
3483,
288,
3335,
14,
25895,
275,
734,
14,
25895,
288,
3335,
14,
9974,
275,
734,
14,
9974,
267,
871,
4281,
26,
288,
986,
272,
372,
5890,
14,
1872,
29365,
8,
2738,
12,
2644,
29,
2991,
12,
1169,
2552,
534,
1652,
24253,
1814,
297,
1169,
8057,
17115,
78,
297,
1169,
2218,
63,
8304,
29,
549,
9,
199,
199,
533,
4692,
7599,
8,
2232,
14,
2714,
2461,
304,
339,
347,
636,
826,
721,
277,
12,
734,
29,
403,
12,
2644,
628,
4595,
13,
4830,
13,
17,
401,
3974,
63,
1667,
63,
5527,
29,
797,
304,
267,
3016,
14,
2714,
2461,
855,
826,
721,
277,
9,
267,
734,
275,
485,
5152,
5491,
8,
548,
12,
2644,
9,
267,
291,
423,
952,
275,
734,
14,
952,
267,
291,
423,
4939,
275,
734,
14,
4939,
267,
291,
423,
561,
63,
19010,
275,
359,
27922,
327,
3509,
5108,
1035,
2403,
10809,
267,
291,
423,
1818,
63,
1100,
275,
291,
423,
561,
63,
19010,
1988,
17,
61,
267,
291,
423,
31531,
63,
561,
63,
8919,
275,
942,
267,
291,
423,
2991,
275,
2644,
267,
291,
423,
3612,
63,
1667,
63,
5527,
275,
3974,
63,
1667,
63,
5527,
267,
291,
423,
6455,
63,
928,
63,
2108,
275,
756,
339,
347,
485,
12333,
8,
277,
12,
536,
304,
267,
408,
27856,
282,
12313,
536,
687,
282,
334,
561,
63,
633,
12,
2257,
354,
9,
4092,
624,
267,
340,
536,
59,
16,
2189,
288,
327,
3492,
1455,
921,
1544,
14,
87,
19,
14,
1308,
15,
4317,
15,
23756,
15,
3251,
12,
710,
283,
1652,
7,
2403,
365,
288,
327,
3914,
701,
5492,
370,
1455,
921,
1544,
14,
87,
19,
14,
1308,
15,
4317,
15
] |
[
199,
33,
3555,
402,
2997,
5922,
3992,
370,
314,
19310,
3992,
12,
367,
314,
199,
388,
23329,
402,
4223,
436,
5253,
2211,
878,
14,
199,
624,
199,
199,
646,
747,
12,
4011,
14,
1122,
12,
4011,
14,
1069,
199,
646,
5890,
199,
504,
1275,
492,
3016,
199,
504,
1275,
492,
2748,
5503,
199,
199,
318,
636,
807,
63,
1814,
8,
83,
12,
366,
304,
272,
408,
11328,
1007,
5465,
402,
282,
1059,
1808,
282,
2600,
1041,
272,
367,
790,
12,
574,
315,
366,
14,
1744,
837,
267,
308,
275,
308,
14,
1814,
8,
498,
12,
574,
9,
272,
372,
308,
199,
199,
318,
4772,
8,
576,
12,
9045,
16420,
272,
408,
10260,
17181,
665,
12,
436,
690,
315,
282,
1059,
402,
666,
14,
339,
2047,
883,
4772,
1163,
3326,
402,
666,
701,
9476,
282,
2600,
465,
272,
314,
2716,
9045,
2725,
14,
221,
710,
2883,
436,
1338,
1471,
1006,
506,
272,
3326,
27,
1924,
790,
911,
506,
8717,
543,
2399,
5226,
574,
14,
272,
408,
339,
327,
1471,
886,
15204,
1192,
460,
1642,
272,
666,
275,
666,
14,
1814,
22077,
401,
11746,
5282,
15027,
272,
666,
275,
666,
14,
1814,
480,
7166,
11746,
3308,
15027,
272,
666,
275,
666,
14,
1814,
6757,
401,
11746,
4116,
15027,
272,
340,
9045,
26,
267,
666,
275,
636,
807,
63,
1814,
8,
576,
12,
9045,
9,
272,
372,
666,
199,
199,
318,
22221,
8,
576,
12,
9045,
16420,
272,
408,
1358,
3765,
1253,
5282,
27031,
1253,
4116,
27031,
436,
1253,
3308,
27,
315,
282,
1059,
402,
666,
14,
339,
2047,
883,
22221,
1163,
3326,
402,
666,
701,
9476,
282,
2600,
465,
272,
314,
2716,
9045,
2725,
14,
221,
710,
2883,
436,
1338,
1471,
1006,
506,
272,
3326,
27,
1924,
790,
911,
506,
8717,
543,
2399,
5226,
574,
14,
272,
408,
272,
666,
275,
666,
14,
1814,
22077,
4116,
17259,
3886,
531,
272,
666,
275,
666,
14,
1814,
22077,
3308,
17259,
298,
9579,
272,
340,
9045,
26,
267,
666,
275,
636,
807,
63,
1814,
8,
576,
12,
9045,
9,
272,
327,
1471,
886,
15204,
1192,
460,
2061,
272,
372,
666,
14,
1814,
22077,
5282,
17259,
11746,
531,
199,
199,
318,
6313,
962,
8,
576,
12,
9045,
16420,
272,
408,
10260,
436,
6313,
376,
2225,
574,
14,
339,
21067,
17181,
665,
12,
436,
690,
315,
282,
1059,
402,
666,
12,
2066,
6313,
652,
367,
675,
465,
272,
376,
2225,
574,
14,
221,
710,
8441,
4528,
911,
506,
11077,
465,
5521,
12,
340,
272,
5784,
14,
339,
2047,
883,
4772,
1163,
3326,
402,
666,
701,
9476,
282,
2600,
465,
272,
314,
2716,
9045,
2725,
14,
221,
710,
2883,
436,
1338,
1471,
1006,
506,
272,
3326,
27,
1924,
790,
911,
506,
8717,
543,
2399,
5226,
574,
14,
272,
408,
272,
9045,
275,
9045,
14,
1574,
342,
272,
9045,
14,
873,
2561,
1154,
78,
356,
7673,
3,
709,
10805,
1557,
82,
356,
7673,
3,
969,
10805,
1557,
84,
5242,
7997,
25,
27,
3071,
272,
666,
275,
4772,
8,
576,
12,
9045,
9,
272,
340,
14788,
315,
666,
26,
267,
340,
21673,
315,
666,
26,
288,
666,
275,
18253,
83,
4507,
450,
666,
14,
1814,
20630,
11746,
5184,
15027,
267,
587,
26,
288,
666,
275,
17648,
83,
4065,
450,
666,
272,
587,
26,
267,
666,
275,
18253,
83,
4507,
450,
666,
272,
372,
666,
421,
199,
318,
485,
5152,
5491,
8,
548,
12,
2644,
304,
272,
340,
734,
365,
488,
26,
267,
492,
984,
267,
372,
984,
14,
2703,
339,
340,
1228,
8,
548,
12,
5890,
14,
1872,
23413,
304,
267,
327,
675,
282,
1318,
7060,
465,
365,
267,
372,
734,
339,
327,
4816,
282,
3366,
7060,
543,
4516,
29365,
272,
340,
1228,
8,
548,
12,
5890,
14,
7963,
23413,
304,
267,
327,
14797,
314,
3379,
570,
1551,
1380,
314,
4516,
29365,
365,
267,
327,
28924,
267,
1021,
485,
5029,
26,
288,
636,
533,
363,
275,
734,
855,
533,
363,
288,
347,
636,
5675,
721,
277,
12,
536,
304,
355,
372,
2519,
8,
548,
12,
536,
9,
267,
3335,
275,
485,
5029,
342,
267,
3335,
14,
1600,
275,
2400,
26,
488,
272,
587,
26,
267,
327,
961,
365,
370,
2429,
3032,
2251,
626,
10621,
1133,
315,
314,
267,
327,
5004,
1563,
14446,
12,
1325,
2951,
1172,
282,
2218,
1083,
267,
3335,
275,
5890,
14,
23139,
23413,
342,
267,
3335,
14,
15053,
275,
2400,
26,
715,
267,
3335,
14,
952,
275,
734,
14,
952,
267,
862,
26,
288,
327,
4516,
29365,
4440,
642,
3102,
370,
6705,
288,
327,
340,
17720,
334,
509,
9094,
13,
975,
12,
5423,
9,
1077,
506,
3483,
288,
3335,
14,
25895,
275,
734,
14,
25895,
288,
3335,
14,
9974,
275,
734,
14,
9974,
267,
871,
4281,
26,
288,
986,
272,
372,
5890,
14,
1872,
29365,
8,
2738,
12,
2644,
29,
2991,
12,
1169,
2552,
534,
1652,
24253,
1814,
297,
1169,
8057,
17115,
78,
297,
1169,
2218,
63,
8304,
29,
549,
9,
199,
199,
533,
4692,
7599,
8,
2232,
14,
2714,
2461,
304,
339,
347,
636,
826,
721,
277,
12,
734,
29,
403,
12,
2644,
628,
4595,
13,
4830,
13,
17,
401,
3974,
63,
1667,
63,
5527,
29,
797,
304,
267,
3016,
14,
2714,
2461,
855,
826,
721,
277,
9,
267,
734,
275,
485,
5152,
5491,
8,
548,
12,
2644,
9,
267,
291,
423,
952,
275,
734,
14,
952,
267,
291,
423,
4939,
275,
734,
14,
4939,
267,
291,
423,
561,
63,
19010,
275,
359,
27922,
327,
3509,
5108,
1035,
2403,
10809,
267,
291,
423,
1818,
63,
1100,
275,
291,
423,
561,
63,
19010,
1988,
17,
61,
267,
291,
423,
31531,
63,
561,
63,
8919,
275,
942,
267,
291,
423,
2991,
275,
2644,
267,
291,
423,
3612,
63,
1667,
63,
5527,
275,
3974,
63,
1667,
63,
5527,
267,
291,
423,
6455,
63,
928,
63,
2108,
275,
756,
339,
347,
485,
12333,
8,
277,
12,
536,
304,
267,
408,
27856,
282,
12313,
536,
687,
282,
334,
561,
63,
633,
12,
2257,
354,
9,
4092,
624,
267,
340,
536,
59,
16,
2189,
288,
327,
3492,
1455,
921,
1544,
14,
87,
19,
14,
1308,
15,
4317,
15,
23756,
15,
3251,
12,
710,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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
] |
MonsieurBlutbad/furzarsch-muss-scheissen
|
api/vendor/doctrine/orm/docs/en/conf.py
|
2448
|
6497
|
# -*- coding: utf-8 -*-
#
# Doctrine 2 ORM documentation build configuration file, created by
# sphinx-quickstart on Fri Dec 3 18:10:24 2010.
#
# This file is execfile()d with the current directory set to its containing dir.
#
# Note that not all possible configuration values are present in this
# autogenerated file.
#
# All configuration values have a default; values that are commented out
# serve to show the default.
import sys, os
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
sys.path.append(os.path.abspath('_exts'))
# -- General configuration -----------------------------------------------------
# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = ['configurationblock']
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
# The suffix of source filenames.
source_suffix = '.rst'
# The encoding of source files.
#source_encoding = 'utf-8'
# The master toctree document.
master_doc = 'index'
# General information about the project.
project = u'Doctrine 2 ORM'
copyright = u'2010-12, Doctrine Project Team'
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = '2'
# The full version, including alpha/beta/rc tags.
release = '2'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
language = 'en'
# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
#today = ''
# Else, today_fmt is used as the format for a strftime call.
#today_fmt = '%B %d, %Y'
# List of documents that shouldn't be included in the build.
#unused_docs = []
# List of directories, relative to source directory, that shouldn't be searched
# for source files.
exclude_trees = ['_build']
# The reST default role (used for this markup: `text`) to use for all documents.
#default_role = None
# If true, '()' will be appended to :func: etc. cross-reference text.
#add_function_parentheses = True
# If true, the current module name will be prepended to all description
# unit titles (such as .. function::).
#add_module_names = True
# If true, sectionauthor and moduleauthor directives will be shown in the
# output. They are ignored by default.
show_authors = True
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
# A list of ignored prefixes for module index sorting.
#modindex_common_prefix = []
# -- Options for HTML output ---------------------------------------------------
# The theme to use for HTML and HTML Help pages. Major themes that come with
# Sphinx are currently 'default' and 'sphinxdoc'.
html_theme = 'doctrine'
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#html_theme_options = {}
# Add any paths that contain custom themes here, relative to this directory.
html_theme_path = ['_theme']
# The name for this set of Sphinx documents. If None, it defaults to
# "<project> v<release> documentation".
#html_title = None
# A shorter title for the navigation bar. Default is the same as html_title.
#html_short_title = None
# The name of an image file (relative to this directory) to place at the top
# of the sidebar.
#html_logo = None
# The name of an image file (within the static path) to use as favicon of the
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
# pixels large.
#html_favicon = None
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
#html_last_updated_fmt = '%b %d, %Y'
# If true, SmartyPants will be used to convert quotes and dashes to
# typographically correct entities.
#html_use_smartypants = True
# Custom sidebar templates, maps document names to template names.
#html_sidebars = {}
# Additional templates that should be rendered to pages, maps page names to
# template names.
#html_additional_pages = {}
# If false, no module index is generated.
#html_use_modindex = True
# If false, no index is generated.
#html_use_index = True
# If true, the index is split into individual pages for each letter.
#html_split_index = False
# If true, links to the reST sources are added to the pages.
#html_show_sourcelink = True
# If true, an OpenSearch description file will be output, and all pages will
# contain a <link> tag referring to it. The value of this option must be the
# base URL from which the finished HTML is served.
#html_use_opensearch = ''
# If nonempty, this is the file name suffix for HTML files (e.g. ".xhtml").
#html_file_suffix = ''
# Output file base name for HTML help builder.
htmlhelp_basename = 'Doctrine2ORMdoc'
# -- Options for LaTeX output --------------------------------------------------
# The paper size ('letter' or 'a4').
#latex_paper_size = 'letter'
# The font size ('10pt', '11pt' or '12pt').
#latex_font_size = '10pt'
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
('index', 'Doctrine2ORM.tex', u'Doctrine 2 ORM Documentation',
u'Doctrine Project Team', 'manual'),
]
# The name of an image file (relative to this directory) to place at the top of
# the title page.
#latex_logo = None
# For "manual" documents, if this is true, then toplevel headings are parts,
# not chapters.
#latex_use_parts = False
# Additional stuff for the LaTeX preamble.
#latex_preamble = ''
# Documents to append as an appendix to all manuals.
#latex_appendices = []
# If false, no module index is generated.
#latex_use_modindex = True
primary_domain = "dcorm"
def linkcode_resolve(domain, info):
if domain == 'dcorm':
return 'http://'
return None
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
4226,
18548,
1132,
499,
23383,
3794,
1900,
2897,
570,
12,
2737,
701,
199,
3,
15882,
13,
28957,
641,
31712,
13966,
221,
650,
6155,
26,
709,
26,
1194,
7129,
14,
199,
3,
199,
3,
961,
570,
365,
22711,
342,
68,
543,
314,
1453,
2082,
663,
370,
2399,
3035,
2935,
14,
199,
3,
199,
3,
3390,
626,
440,
1006,
3962,
2897,
1338,
787,
3451,
315,
642,
199,
3,
18392,
570,
14,
199,
3,
199,
3,
2900,
2897,
1338,
1172,
282,
849,
27,
1338,
626,
787,
21804,
734,
199,
3,
14062,
370,
2498,
314,
849,
14,
199,
199,
646,
984,
12,
747,
199,
199,
3,
982,
5478,
334,
269,
4621,
370,
2213,
543,
29973,
9,
787,
315,
4573,
2082,
12,
199,
3,
1050,
3520,
6602,
370,
984,
14,
515,
2348,
14,
982,
314,
2082,
365,
3847,
370,
314,
199,
3,
3794,
1738,
12,
675,
747,
14,
515,
14,
4832,
370,
1852,
652,
3679,
12,
2839,
9164,
2348,
14,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
515,
14,
4832,
6412,
25752,
1333,
199,
199,
3,
1553,
1696,
2897,
9527,
9858,
199,
199,
3,
2654,
1263,
10229,
3329,
859,
1561,
2348,
12,
465,
3326,
14,
9322,
883,
506,
5478,
199,
3,
17262,
543,
10229,
334,
4579,
283,
8008,
14,
832,
24915,
503,
2195,
3537,
7869,
14,
199,
5359,
275,
788,
4758,
1457,
418,
199,
199,
3,
2654,
1263,
3792,
626,
1395,
7009,
2348,
12,
3847,
370,
642,
2082,
14,
199,
5876,
63,
515,
275,
4044,
5876,
418,
199,
199,
3,
710,
4739,
402,
1350,
6203,
14,
199,
1365,
63,
4511,
275,
1987,
8332,
7,
199,
199,
3,
710,
2644,
402,
1350,
1584,
14,
199,
3,
1365,
63,
2991,
275,
283,
1624,
13,
24,
7,
199,
199,
3,
710,
5288,
28310,
2213,
14,
199,
4133,
63,
1301,
275,
283,
1080,
7,
199,
199,
3,
1696,
2556,
3595,
314,
2199,
14,
199,
1715,
275,
399,
7,
2585,
18548,
1132,
499,
23383,
7,
199,
7307,
275,
399,
7,
6542,
13,
713,
12,
4226,
18548,
1132,
7290,
11682,
7,
199,
199,
3,
710,
1015,
2256,
367,
314,
2199,
1265,
3984,
29904,
12,
17795,
465,
8343,
367,
199,
3,
1204,
1023,
92,
436,
1204,
3221,
18712,
2597,
1202,
315,
7750,
1163,
9825,
23088,
314,
199,
3,
6137,
8247,
14,
199,
3,
199,
3,
710,
3974,
1323,
14,
57,
1015,
14,
199,
1023,
275,
283,
18,
7,
199,
3,
710,
2615,
1015,
12,
5893,
5131,
15,
5683,
15,
1195,
3762,
14,
199,
3221,
275,
283,
18,
7,
199,
199,
3,
710,
2637,
367,
1564,
18392,
701,
10229,
14,
21751,
370,
3794,
199,
3,
367,
282,
769,
402,
3748,
10815,
14,
199,
3671,
275,
283,
287,
7,
199,
199,
3,
6006,
787,
2877,
1511,
367,
15810,
1204,
8136,
25004,
1902,
12,
1265,
663,
11168,
370,
2005,
199,
3,
2222,
13,
3910,
574,
12,
2066,
652,
365,
1202,
26,
199,
3,
8136,
275,
2125,
199,
3,
19524,
12,
11168,
63,
5045,
365,
1202,
465,
314,
1475,
367,
282,
14053,
1240,
14,
199,
3,
8136,
63,
5045,
275,
1543,
34,
450,
68,
12,
450,
57,
7,
199,
199,
3,
3820,
402,
8247,
626,
9296,
1133,
506,
5120,
315,
314,
1900,
14,
199,
3,
8618,
63,
4757,
275,
942,
199,
199,
3,
3820,
402,
6602,
12,
3847,
370,
1350,
2082,
12,
626,
9296,
1133,
506,
17543,
199,
3,
367,
1350,
1584,
14,
199,
5473,
63,
14635,
275,
4044,
1506,
418,
199,
199,
3,
710,
20883,
849,
4719,
334,
2972,
367,
642,
9189,
26,
658,
505,
10522,
370,
675,
367,
1006,
8247,
14,
199,
3,
885,
63,
3756,
275,
488,
199,
199,
3,
982,
2549,
12,
26380,
911,
506,
11544,
370,
520,
1532,
26,
5423,
14,
8059,
13,
4443,
1318,
14,
199,
3,
525,
63,
1593,
63,
25510,
275,
715,
199,
199,
3,
982,
2549,
12,
314,
1453,
859,
536,
911,
506,
20247,
370,
1006,
1369,
199,
3,
4137,
16194,
334,
10180,
465,
2508,
805,
32469,
199,
3,
525,
63,
578,
63,
1247,
275,
715,
199,
199,
3,
982,
2549,
12,
3420,
2502,
436,
28966,
13502,
911,
506,
9164,
315,
314,
199,
3,
1072,
14,
9322,
787,
5525,
701,
849,
14,
199,
2384,
63,
8149,
275,
715,
199,
199,
3,
710,
536,
402,
314,
14493,
334,
7093,
22437,
9,
3449,
370,
675,
14,
199,
12173,
63,
2487,
275,
283,
8008,
7,
199,
199,
3,
437,
769,
402,
5525,
13158,
367,
859,
1478,
13351,
14,
199,
3,
27555,
63,
2330,
63,
1861,
275,
942,
421,
199,
3,
1553,
8394,
367,
4163,
1072,
9527,
2595,
199,
199,
3,
710,
8879,
370,
675,
367,
4163,
436,
4163,
15456,
6497,
14,
221,
16593,
5857,
17915,
626,
11492,
543,
199,
3,
10229,
787,
5544,
283,
885,
7,
436,
283,
8008,
1301,
1370,
199,
1360,
63,
7915,
275,
283,
1117,
18548,
1132,
7,
199,
199,
3,
23978,
1511,
787,
8879,
13,
6100,
436,
17551,
314,
3648,
436,
23109,
402,
282,
8879,
199,
3,
9848,
14,
221,
2104,
282,
769,
402,
1511,
2808,
367,
1924,
8879,
12,
1937,
314,
199,
3,
3794,
14,
199,
3,
1360,
63,
7915,
63,
1419,
275,
1052,
199,
199,
3,
2654,
1263,
3792,
626,
1395,
3537,
17915,
2348,
12,
3847,
370,
642,
2082,
14,
199,
1360,
63,
7915,
63,
515,
275,
4044,
7915,
418,
199,
199,
3,
710,
536,
367,
642,
663,
402,
10229,
8247,
14,
221,
982,
488,
12,
652,
4243,
370,
199,
3,
3886,
1715,
30,
373,
28,
3221,
30,
3794,
1674,
199,
3,
1360,
63,
1213,
275,
488,
199,
199,
3,
437,
18299,
2538,
367,
314,
19191,
4681,
14,
221,
3758,
365,
314,
2011,
465,
3517,
63,
1213,
14,
199,
3,
1360,
63,
3612,
63,
1213,
275,
488,
199,
199,
3,
710,
536,
402,
376,
1834,
570,
334,
6188,
370,
642,
2082,
9,
370,
4192,
737,
314,
2746,
199,
3,
402,
314,
18437,
14,
199,
3,
1360,
63,
9733,
275,
488,
199,
199,
3,
710,
536,
402,
376,
1834,
570,
334,
12541,
314,
2955,
931,
9,
370,
675,
465,
29139,
402,
314,
199,
3,
9149,
14,
221,
961,
570,
1077,
506,
282,
5417,
7016,
570,
17048,
12802,
9,
3769,
3193,
88,
975,
503,
4337,
88,
708,
199,
3,
11094,
7031,
14,
199,
3,
1360,
63
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
4226,
18548,
1132,
499,
23383,
3794,
1900,
2897,
570,
12,
2737,
701,
199,
3,
15882,
13,
28957,
641,
31712,
13966,
221,
650,
6155,
26,
709,
26,
1194,
7129,
14,
199,
3,
199,
3,
961,
570,
365,
22711,
342,
68,
543,
314,
1453,
2082,
663,
370,
2399,
3035,
2935,
14,
199,
3,
199,
3,
3390,
626,
440,
1006,
3962,
2897,
1338,
787,
3451,
315,
642,
199,
3,
18392,
570,
14,
199,
3,
199,
3,
2900,
2897,
1338,
1172,
282,
849,
27,
1338,
626,
787,
21804,
734,
199,
3,
14062,
370,
2498,
314,
849,
14,
199,
199,
646,
984,
12,
747,
199,
199,
3,
982,
5478,
334,
269,
4621,
370,
2213,
543,
29973,
9,
787,
315,
4573,
2082,
12,
199,
3,
1050,
3520,
6602,
370,
984,
14,
515,
2348,
14,
982,
314,
2082,
365,
3847,
370,
314,
199,
3,
3794,
1738,
12,
675,
747,
14,
515,
14,
4832,
370,
1852,
652,
3679,
12,
2839,
9164,
2348,
14,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
515,
14,
4832,
6412,
25752,
1333,
199,
199,
3,
1553,
1696,
2897,
9527,
9858,
199,
199,
3,
2654,
1263,
10229,
3329,
859,
1561,
2348,
12,
465,
3326,
14,
9322,
883,
506,
5478,
199,
3,
17262,
543,
10229,
334,
4579,
283,
8008,
14,
832,
24915,
503,
2195,
3537,
7869,
14,
199,
5359,
275,
788,
4758,
1457,
418,
199,
199,
3,
2654,
1263,
3792,
626,
1395,
7009,
2348,
12,
3847,
370,
642,
2082,
14,
199,
5876,
63,
515,
275,
4044,
5876,
418,
199,
199,
3,
710,
4739,
402,
1350,
6203,
14,
199,
1365,
63,
4511,
275,
1987,
8332,
7,
199,
199,
3,
710,
2644,
402,
1350,
1584,
14,
199,
3,
1365,
63,
2991,
275,
283,
1624,
13,
24,
7,
199,
199,
3,
710,
5288,
28310,
2213,
14,
199,
4133,
63,
1301,
275,
283,
1080,
7,
199,
199,
3,
1696,
2556,
3595,
314,
2199,
14,
199,
1715,
275,
399,
7,
2585,
18548,
1132,
499,
23383,
7,
199,
7307,
275,
399,
7,
6542,
13,
713,
12,
4226,
18548,
1132,
7290,
11682,
7,
199,
199,
3,
710,
1015,
2256,
367,
314,
2199,
1265,
3984,
29904,
12,
17795,
465,
8343,
367,
199,
3,
1204,
1023,
92,
436,
1204,
3221,
18712,
2597,
1202,
315,
7750,
1163,
9825,
23088,
314,
199,
3,
6137,
8247,
14,
199,
3,
199,
3,
710,
3974,
1323,
14,
57,
1015,
14,
199,
1023,
275,
283,
18,
7,
199,
3,
710,
2615,
1015,
12,
5893,
5131,
15,
5683,
15,
1195,
3762,
14,
199,
3221,
275,
283,
18,
7,
199,
199,
3,
710,
2637,
367,
1564,
18392,
701,
10229,
14,
21751,
370,
3794,
199,
3,
367,
282,
769,
402,
3748,
10815,
14,
199,
3671,
275,
283,
287,
7,
199,
199,
3,
6006,
787,
2877,
1511,
367,
15810,
1204,
8136,
25004,
1902,
12,
1265,
663,
11168,
370,
2005,
199,
3,
2222,
13,
3910,
574,
12,
2066,
652,
365,
1202,
26,
199,
3,
8136,
275,
2125,
199,
3,
19524,
12,
11168,
63,
5045,
365,
1202,
465,
314,
1475,
367,
282,
14053,
1240,
14,
199,
3,
8136,
63,
5045,
275,
1543,
34,
450,
68,
12,
450,
57,
7,
199,
199,
3,
3820,
402,
8247,
626,
9296,
1133,
506,
5120,
315,
314,
1900,
14,
199,
3,
8618,
63,
4757,
275,
942,
199,
199,
3,
3820,
402,
6602,
12,
3847,
370,
1350,
2082,
12,
626,
9296,
1133,
506,
17543,
199,
3,
367,
1350,
1584,
14,
199,
5473,
63,
14635,
275,
4044,
1506,
418,
199,
199,
3,
710,
20883,
849,
4719,
334,
2972,
367,
642,
9189,
26,
658,
505,
10522,
370,
675,
367,
1006,
8247,
14,
199,
3,
885,
63,
3756,
275,
488,
199,
199,
3,
982,
2549,
12,
26380,
911,
506,
11544,
370,
520,
1532,
26,
5423,
14,
8059,
13,
4443,
1318,
14,
199,
3,
525,
63,
1593,
63,
25510,
275,
715,
199,
199,
3,
982,
2549,
12,
314,
1453,
859,
536,
911,
506,
20247,
370,
1006,
1369,
199,
3,
4137,
16194,
334,
10180,
465,
2508,
805,
32469,
199,
3,
525,
63,
578,
63,
1247,
275,
715,
199,
199,
3,
982,
2549,
12,
3420,
2502,
436,
28966,
13502,
911,
506,
9164,
315,
314,
199,
3,
1072,
14,
9322,
787,
5525,
701,
849,
14,
199,
2384,
63,
8149,
275,
715,
199,
199,
3,
710,
536,
402,
314,
14493,
334,
7093,
22437,
9,
3449,
370,
675,
14,
199,
12173,
63,
2487,
275,
283,
8008,
7,
199,
199,
3,
437,
769,
402,
5525,
13158,
367,
859,
1478,
13351,
14,
199,
3,
27555,
63,
2330,
63,
1861,
275,
942,
421,
199,
3,
1553,
8394,
367,
4163,
1072,
9527,
2595,
199,
199,
3,
710,
8879,
370,
675,
367,
4163,
436,
4163,
15456,
6497,
14,
221,
16593,
5857,
17915,
626,
11492,
543,
199,
3,
10229,
787,
5544,
283,
885,
7,
436,
283,
8008,
1301,
1370,
199,
1360,
63,
7915,
275,
283,
1117,
18548,
1132,
7,
199,
199,
3,
23978,
1511,
787,
8879,
13,
6100,
436,
17551,
314,
3648,
436,
23109,
402,
282,
8879,
199,
3,
9848,
14,
221,
2104,
282,
769,
402,
1511,
2808,
367,
1924,
8879,
12,
1937,
314,
199,
3,
3794,
14,
199,
3,
1360,
63,
7915,
63,
1419,
275,
1052,
199,
199,
3,
2654,
1263,
3792,
626,
1395,
3537,
17915,
2348,
12,
3847,
370,
642,
2082,
14,
199,
1360,
63,
7915,
63,
515,
275,
4044,
7915,
418,
199,
199,
3,
710,
536,
367,
642,
663,
402,
10229,
8247,
14,
221,
982,
488,
12,
652,
4243,
370,
199,
3,
3886,
1715,
30,
373,
28,
3221,
30,
3794,
1674,
199,
3,
1360,
63,
1213,
275,
488,
199,
199,
3,
437,
18299,
2538,
367,
314,
19191,
4681,
14,
221,
3758,
365,
314,
2011,
465,
3517,
63,
1213,
14,
199,
3,
1360,
63,
3612,
63,
1213,
275,
488,
199,
199,
3,
710,
536,
402,
376,
1834,
570,
334,
6188,
370,
642,
2082,
9,
370,
4192,
737,
314,
2746,
199,
3,
402,
314,
18437,
14,
199,
3,
1360,
63,
9733,
275,
488,
199,
199,
3,
710,
536,
402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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
] |
EUDAT-B2SHARE/invenio-old
|
modules/miscutil/lib/inveniocfg_dumperloader.py
|
27
|
16700
|
# -*- coding: utf-8 -*-
##
## This file is part of Invenio.
## Copyright (C) 2010, 2011 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.
"""
*** HIGHLY EXPERIMENTAL; PLEASE DO NOT USE. ***
Invenio configuration dumper and loader CLI tool.
Usage: python inveniocfg_dumperloader.py [options]
General options:
-h, --help print this help
-V, --version print version number
Dumper options:
-d file dump the collections into a INI file
-col COLLECTION1,COLLECTION2... collection/s to dump
-all dump all the collections
--force-ids also dump the ids of the tables to the file
--output print the file in the screen
Loader options:
-l file load a file into the database
-mode i|c|r select the mode to load(insert, correct, replace)
"""
__revision__ = "$Id$"
import sys
import random
import re
import datetime
import StringIO
from string import Template
from invenio.dbquery import run_sql, wash_table_column_name
from configobj import ConfigObj
IDENT_TYPE = " " #Identation in the *.INI file can be a tab/spaces/etc...
MESSAGES = [] #List of messages to display to the user at the end of the execution
LOAD_DEFAULT_MODE = 'i'
SEPARATOR = '.'
#Dict of blacklisted fields and the message to display
BLACKLIST_TABLE_COLUMNS = {
'collection.reclist': '#INFO Please rerun webcoll.',
'accROLE.firefole_def_ser': '#INFO Please rerun webaccessadmin -c.',
'score':'#INFO Run whatever relevant',
'tag.value':'#INFO Please run inveniocfg --do-something',
'field_tag.score':'#INFO please run inveniocfg --fill-scores'
}
COLLECTIONS = {
'FIELD' : {
'tables':{
'field':'extend(field.id=fieldname.id_field,fieldname.$ln.$type = $value)',
'field_tag':'field_tag.id_field = field.id, field_tag.id_tag = tag.id',
'tag':'normal'},
'relations':'field-field_tag-tag',
},
'COLLECTION' : {
'tables':{
'collection':'normal',
'collection_example':'collection_example.id_example = example.id, collection_example.id_collection = collection.id',
'example':'normal'},
'relations':'collection-collection_example-example',
},
'PORTALBOX' : {
'tables':{
'collection':'normal',
'collection_portalbox':'collection_portalbox.id_portalbox = portalbox.id, collection_portalbox.id_collection = collection.id',
'portalbox':'normal',
},
'relations':'collection-collection_portalbox-portalbox',
},
}
def print_usage():
"""Print help."""
print __doc__
def create_section_id(num, with_date=True):
"""
Generate a unique section id.
Convert the given number in base 18 and append a 5 digit random string
If with_date=True append the date at the beginnig so it can be ordered.
Estructure:
if with_date:
date . base18(id) . 5 random chars e.g. tag.2010-07-30.ddcbz2lf
else:
base18(id) . 5 random chars e.g. field.ddcbz2lf
"""
digits = "abcdefghijklmnopqrstuvwxyz0123456789"
str_id = ""
tail = ''.join([random.choice(digits) for x in range(4)])
while 1:
rest = num % 18
str_id = digits[rest] + str_id
num = num / 18
if num == 0:
break
if with_date == True:
date = str(datetime.date.today())
return date + "." + str_id + tail
return str_id + tail
def dict2db(table_name, dict_data, mode):
"""
Load the dict values into the database
Three modes of operation:
i - insert
r - replace
c - correct
"""
#Escape all the content in dict data to avoid " and '
for data in dict_data:
dict_data[data] = re.escape(dict_data[data])
if mode == 'i': #Insert mode
query_fields = " , " .join(dict_data.keys())
query_values = "' , '" .join(dict_data.values())
query = "INSERT IGNORE INTO %s(%s) VALUES ('%s')" % (wash_table_column_name(table_name),
query_fields,
query_values)
elif mode == 'c': #Correct mode
if '_' in table_name:
query = "SELECT * FROM %s" % table_name#FIXIT Trick to execute something instead of giving error
else:
tbl_id = get_primary_keys(table_name)[0]
del dict_data[tbl_id]
query_update = " , " .join(["%s=\'%s\'" % (field, dict_data[field]) for field in dict_data])
query = "UPDATE %s SET %s" % (wash_table_column_name(table_name),
query_update)
else: #Try in the default mode
dict2db(table_name, dict_data, LOAD_DEFAULT_MODE)
try:
run_sql(query)
except:
print "VALUES: %s ALREADY EXIST IN TABLE %s. SKIPPING" % (query_values, table_name)
pass
def query2list(query, table_name):
"""Given a SQL query return a list of dictionaries with the results"""
results = run_sql(query, with_desc=True)
lst_results = []
dict_results = {}
for section_id, result in enumerate(results[0]):
dict_results = {}
for index, field in enumerate(results[1]):
if not is_blacklisted(table_name, field[0]):
dict_results[field[0]] = result[index]
lst_results.append(dict_results)
return lst_results
def get_primary_keys(table_name):
"""
Get the primary keys from the table with the DESC mysql function
"""
lst_keys = []
query = "DESC %s" % wash_table_column_name(table_name)
results = run_sql(query)
for field in results:
if field[3] == 'PRI':
lst_keys.append(field[0])
return lst_keys
def get_unused_primary_key(table_name):
"""
Returns the first free id from a table
"""
table_id = get_primary_keys(table_name)[0]#FIXIT the table can have more than an id
query = "SELECT %s FROM %s" % (table_id, table_name)
results = query2list(query, table_name)
list_used_ids = [result[table_id] for result in results]
for unused_id in range(1, len(list_used_ids)+2):
if not unused_id in list_used_ids:
return str(unused_id)
def is_blacklisted(table, field):
"""
Check if the current field is blacklisted, if so add the message to the messages list
"""
if (table+ "." + field) in BLACKLIST_TABLE_COLUMNS.keys():
msg = BLACKLIST_TABLE_COLUMNS[(table + "." + field)]
if not msg in MESSAGES:
MESSAGES.append(msg)
return True
return False
def get_relationship(collection, table, field_id):
"""Return the name of the related field"""
tbl_field = table + "." + field_id
dict_relationship = {}
for tbl in collection['tables'].values():
if tbl_field in tbl:
for foo in tbl.split(","):
dict_value, dict_key = foo.split("=")
dict_relationship[dict_key.strip()] = dict_value
return dict_relationship
def delete_keys_from_dict(dict_del, lst_keys):
"""
Delete the keys present in the lst_keys from the dictionary.
Loops recursively over nested dictionaries.
"""
for k in lst_keys:
try:
del dict_del[k]
except KeyError:
pass
for v in dict_del.values():
if isinstance(v, dict):
delete_keys_from_dict(v, lst_keys)
return dict_del
def extract_from_template(template, str_data):
"""
Extract the values from a string given the template
If the template and the string are different, this function may fail
Return a dictionary with the keys from the template and the values from the string
"""
#FIXIT this code can be more elegant
lst_str_data = []
dict_result = {}
pattern = re.compile("\$\w*")
patt_match = pattern.findall(template)
lst_foo = str_data.split("=")
for data in lst_foo:
lst_str_data.extend(data.split("."))
for index, data in enumerate(patt_match):
data = data.replace('$','')
dict_result[data] = lst_str_data[index+1].strip()
return dict_result
def delete_ids(dict_fields, lst_tables):
"""
Remove the ids of the tables from the dictionary
"""
lst_primary = []
for tbl in lst_tables:
lst_primary.extend(get_primary_keys(tbl))
return delete_keys_from_dict(dict_fields, lst_primary)
def add_special_field(collection, tbl_name , dict_data):
"""Add the value for the translation to the dictionary"""
str_template = collection['tables'][tbl_name].split(",")[1][:-1]#FIXIT if the final character is other?
template_key, template_value = str_template.split("=")
template_key = Template(template_key.strip())
template_value = Template(template_value.strip())
id_field = dict_data['id']
query = "SELECT * FROM %s WHERE %s=%s" % ("fieldname", "id_field", id_field)
result = query2list(query, "fieldname")
if result:
for res in result:
dict_data[template_key.safe_substitute(res)] = template_value.safe_substitute(res)
def dump_collection(collection, config, force_ids, print_to_screen=False):
"""
Dump the current collection
Note: there are a special notation, ori(origin) - rel(relation) - fin(final)
For example in the relation field-field_tag-tag:
ori(origin): field table
rel(relation): field_tag
fin(final): tag
"""
tbl_ori, tbl_rel, tbl_fin = collection['relations'].split("-")
query = "SELECT * FROM %s" % (wash_table_column_name(tbl_ori))
lst_ori = query2list(query, tbl_ori)
tbl_ori_id = get_primary_keys(tbl_ori)[0]
for index_ori, result_ori in enumerate(lst_ori):
dict_rels = get_relationship(collection, tbl_ori, tbl_ori_id)
query = "SELECT * FROM %s WHERE %s=%s" % (wash_table_column_name(tbl_rel),
dict_rels[tbl_ori+"."+tbl_ori_id],
result_ori[tbl_ori_id])
if collection['tables'][tbl_ori].startswith('extend'):
add_special_field(collection, tbl_ori, result_ori)
lst_rel = query2list(query, tbl_rel)
for result_rel in lst_rel:
tbl_fin_id = get_primary_keys(tbl_fin)[0]
tbl_rel_id = dict_rels[tbl_fin+"."+tbl_fin_id].split(".")[1].strip()
query = "SELECT * FROM %s WHERE %s=%s" % (wash_table_column_name(tbl_fin),
tbl_fin_id, result_rel[tbl_rel_id])
lst_fin = query2list(query, tbl_fin)
for index_fin, result_fin in enumerate(lst_fin):
result_ori[tbl_fin+"."+create_section_id(index_fin, with_date=False)] = result_fin
section_name = tbl_ori + "." + create_section_id(index_ori)
if force_ids == False:#Remove the ids from the dict
results = delete_ids(result_ori, collection['relations'].split("-"))
config[section_name] = results
else:
config[section_name] = result_ori
if print_to_screen == True:
output = StringIO.StringIO()
config.write(output)#Write to the output string instead of the file
print output.getvalue()
else:
config.write()
def get_collection(table_name):
"""Get the collection asociated with the section"""
for collection in COLLECTIONS.items():
if table_name in collection[1]['relations'].split("-")[0]:
return COLLECTIONS[collection[0]]#this is the collection to load
def load_section(section_name, dict_data, mode):
"""
Load the section back into the database
table_name is the name of the main section
There are some special notation: ori(origin) - rel(related) - fin(final) - ext(extended)
For example for the field-tag collection:
ori: field
ext: fieldname
rel: field_tag
fin:tag
"""
table_ori = section_name.split(".")[0]
collection = get_collection(table_ori)
ori_definition = collection['tables'][table_ori]
if ori_definition.startswith("extend"):
tbl_ext_name = ori_definition.split(",")[1].split(SEPARATOR)[0]
lst_tables = collection['relations'].split("-")
ori_id = get_primary_keys(lst_tables[0])[0]
ori_id_value = get_unused_primary_key(lst_tables[0])
dict_data[ori_id] = ori_id_value#Add the calculated id to the dictionary
#I will separate the dict_data into these 3 dicts corresponding to 3 different tables
dict_ori = {}
dict_rel = {}
dict_ext = {}
for field in dict_data:
if type(dict_data[field]) == str:#the field is a string
if "tbl_ext_name" in locals() and field.startswith(tbl_ext_name):#is extended table
dict2db("fieldname",
extract_from_template("fieldname.$ln.$type = $value",
str(field) + " = " + str(dict_data[field])),
mode)
else:
dict_ori[field] = dict_data[field]
else:#if the field is a dictionary
fin_id = get_primary_keys(lst_tables[2])[0]
fin_id_value = get_unused_primary_key(lst_tables[2])
dict_data[field][fin_id] = fin_id_value
dict2db(lst_tables[2], dict_data[field], mode)#Insert the final into the DB
fieldtag_ids = get_primary_keys(lst_tables[1])
dict_rel[fieldtag_ids[0]] = ori_id_value
dict_rel[fieldtag_ids[1]] = fin_id_value
dict2db(lst_tables[1], dict_rel, mode)#Insert the relation into the DB
dict2db(lst_tables[0], dict_ori, mode)
def cli_cmd_dump_config():
"""Dump the selected collection/s"""
config = ConfigObj(indent_type=IDENT_TYPE)
config.initial_comment = [
str(datetime.datetime.now()),
"This file is automatically generated by Invenio, running:",
" ".join(sys.argv) ,
"" ]
force_ids = False
if "--force-ids" in sys.argv:
force_ids = True
print_to_screen = False
if '--output' in sys.argv:
print_to_screen = True
try:
config.filename = sys.argv[sys.argv.index('-d') + 1]
except:
print_usage()
if '-col' in sys.argv:
try:
collection = COLLECTIONS[sys.argv[sys.argv.index('-col') + 1].upper()]
dump_collection(collection, config, force_ids, print_to_screen)
except:
print "ERROR: you must especify the collection to dump with the -col COLLECTION_NAME option"
elif '-all' in sys.argv:
for collection in COLLECTIONS:
dump_collection(COLLECTIONS[collection], config, force_ids, print_to_screen)
else:
print "Please specify the collection to dump"
def cli_cmd_load_config():
"""Load all the config sections back into the database"""
config = ConfigObj(sys.argv[sys.argv.index('-l') + 1])
mode = "r"
if '-mode' in sys.argv:
try:
mode = sys.argv[sys.argv.index('-mode') + 1]
if mode not in ['i', 'c', 'r']:
print "Not valid mode please select one of the following (i)nsert, (c)orrect or (r)eplace"
sys.exit(1)
except IndexError:
print "You must especify the mode with the -mode option"
sys.exit(1)
for section in config.sections:
load_section(section, config[section], mode)
def main():
"""
Main section, makes the calls to all the functions
"""
if "-d" in sys.argv:
cli_cmd_dump_config()
elif "-l" in sys.argv:
cli_cmd_load_config()
elif "-h" in sys.argv:
print_usage()
else:
print_usage()
for message in MESSAGES:
print message
if __name__ == '__main__':
main()
|
gpl-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
309,
199,
309,
961,
570,
365,
1777,
402,
12235,
14,
199,
309,
1898,
334,
35,
9,
7129,
12,
7760,
24354,
14,
199,
309,
199,
309,
12235,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
309,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
199,
309,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
199,
309,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
309,
199,
309,
12235,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
199,
309,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
309,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
309,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
309,
199,
309,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
309,
3180,
543,
12235,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
2752,
12,
3277,
2020,
199,
309,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
15673,
13,
13421,
12,
8217,
14,
199,
199,
624,
199,
9153,
869,
13454,
6084,
3651,
25731,
1309,
748,
27,
510,
17177,
3506,
2845,
4815,
14,
19688,
199,
199,
607,
7597,
2897,
5461,
281,
436,
5077,
14214,
4744,
14,
199,
199,
7692,
26,
2366,
315,
1856,
73,
679,
9681,
63,
2724,
281,
3422,
14,
647,
359,
1419,
61,
199,
199,
14109,
1511,
26,
2043,
446,
72,
12,
1553,
3437,
14960,
870,
642,
1720,
2043,
446,
54,
12,
1553,
1023,
12793,
870,
1015,
1329,
199,
199,
28593,
1511,
26,
2043,
446,
68,
570,
17388,
5461,
314,
5055,
1901,
282,
1621,
41,
570,
2126,
446,
761,
13513,
3923,
1075,
17,
12,
29374,
18,
1396,
257,
3245,
15,
83,
370,
5461,
2126,
446,
452,
19242,
5461,
1006,
314,
5055,
2126,
1553,
3990,
13,
1580,
9668,
2597,
5461,
314,
2762,
402,
314,
6716,
370,
314,
570,
2126,
1553,
1199,
14516,
870,
314,
570,
315,
314,
6426,
199,
199,
5455,
1511,
26,
2043,
446,
76,
570,
17388,
2248,
282,
570,
1901,
314,
3050,
489,
446,
632,
284,
92,
67,
92,
82,
12788,
3504,
314,
818,
370,
2248,
8,
3176,
12,
3211,
12,
3350,
9,
199,
624,
199,
199,
363,
5792,
363,
275,
7880,
1304,
17351,
199,
199,
646,
984,
199,
646,
2196,
199,
646,
295,
199,
646,
2197,
199,
646,
5228,
199,
504,
1059,
492,
5458,
199,
504,
13640,
14,
697,
1131,
492,
1255,
63,
3009,
12,
29050,
63,
1224,
63,
2301,
63,
354,
199,
199,
504,
1101,
1113,
492,
4094,
5665,
199,
199,
7466,
63,
2711,
275,
298,
259,
298,
327,
41,
1326,
425,
315,
314,
23588,
568,
41,
570,
883,
506,
282,
5174,
15,
10749,
15,
6839,
1396,
199,
199,
23229,
275,
942,
327,
1296,
402,
3788,
370,
2929,
370,
314,
922,
737,
314,
1284,
402,
314,
6451,
199,
199,
7405,
63,
3472,
63,
6963,
275,
283,
73,
7,
199,
199,
15828,
275,
7815,
199,
199,
3,
2141,
402,
12136,
15023,
1504,
436,
314,
1245,
370,
2929,
199,
23113,
4924,
63,
8723,
63,
28427,
275,
469,
523,
283,
3627,
14,
2761,
513,
356,
3943,
4531,
7754,
295,
1065,
3330,
15772,
3130,
523,
283,
5470,
15468,
14,
8935,
545,
274,
63,
318,
63,
332,
356,
3943,
4531,
7754,
295,
1065,
3330,
2732,
2113,
446,
67,
3130,
523,
283,
3397,
5242,
3,
4531,
3378,
15685,
12082,
297,
523,
283,
1450,
14,
585,
5242,
3,
4531,
7754,
1255,
315,
1856,
73,
679,
9681,
1553,
1117,
13,
10297,
297,
523,
283,
698,
63,
1450,
14,
3397,
5242,
3,
4531,
8749,
1255,
315,
1856,
73,
679,
9681,
1553,
4498,
13,
7107,
7,
199,
93,
199,
199,
23037,
2823,
275,
469,
339,
283,
8609,
7,
520,
469,
2151,
283,
5987,
356,
91,
2151,
283,
698,
5242,
2880,
8,
698,
14,
344,
29,
13646,
14,
344,
63,
698,
12,
13646,
14,
4,
6066,
14,
4,
466,
275,
2672,
585,
3196,
2151,
283,
698,
63,
1450,
5242,
698,
63,
1450,
14,
344,
63,
698,
275,
901,
14,
344,
12,
901,
63,
1450,
14,
344,
63,
1450,
275,
1947,
14,
344,
297,
2151,
283,
1450,
5242,
3302,
2267,
2151,
283,
15741,
5242,
698,
13,
698,
63,
1450,
13,
1450,
297,
2151,
1660,
272,
283,
29374,
7,
520,
469,
267,
283,
5987,
356,
91,
288,
283,
3627,
5242,
3302,
297,
288,
283,
3627,
63,
2694,
5242,
3627,
63,
2694,
14,
344,
63,
2694,
275,
2893,
14,
344,
12,
3245,
63,
2694,
14,
344,
63,
3627,
275,
3245,
14,
344,
297,
288,
283,
2694,
5242,
3302,
2267,
267,
283,
15741,
5242,
3627,
13,
3627,
63,
2694,
13,
2694,
297,
267,
1660,
272,
283,
3657,
748,
15694,
7,
520,
469,
267,
283,
5987,
356,
91,
288,
283,
3627,
5242,
3302,
297,
288,
283,
3627,
63,
8707,
1977,
5242,
3627,
63,
8707,
1977,
14,
344,
63,
8707,
1977,
275,
18428,
1977,
14,
344,
12,
3245,
63,
8707,
1977,
14,
344,
63,
3627,
275,
3245,
14,
344,
297,
288,
283,
8707,
1977,
5242,
3302,
297,
267,
1660,
267,
283,
15741,
5242,
3627,
13,
3627,
63,
8707,
1977,
13,
8707,
1977,
297,
1362,
1660,
199,
93,
421,
199,
318,
870,
63,
3807,
837,
272,
408,
5375,
1720,
1041,
272,
870,
636,
1301,
363,
199,
199,
318,
1218,
63,
2792,
63,
344,
8,
1507,
12,
543,
63,
602,
29,
549,
304,
272,
408,
272,
7958,
282,
3747,
3420,
1305,
14,
272,
7905,
314,
1627,
1329,
315,
1300,
6155,
436,
5666,
282,
959,
10964,
2196,
1059,
272,
982,
543,
63,
602,
29,
549,
5666,
314,
1434,
737,
314,
5386,
78,
528,
880,
652,
883,
506,
7741,
14,
272,
662,
6976,
26,
272,
340,
543,
63,
602,
26,
1779,
1434,
1275,
1300,
1085,
8,
344,
9,
1275,
959,
2196,
8365,
259,
325,
14,
71,
14,
1947,
14,
6542,
13,
1780,
13,
1216,
14,
617,
2894,
90,
18,
276,
272,
587,
26,
1779,
1300,
1085,
8,
344,
9,
1275,
959,
2196,
8365,
257,
325,
14,
71,
14,
901,
14,
617,
2894,
90,
18,
276,
272,
408,
272,
7576,
275,
298,
23459,
11371,
2,
272,
620,
63,
344,
275,
3087,
272,
9483,
275,
6522,
904,
779,
2355,
14,
5095,
8,
7022,
9
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
309,
199,
309,
961,
570,
365,
1777,
402,
12235,
14,
199,
309,
1898,
334,
35,
9,
7129,
12,
7760,
24354,
14,
199,
309,
199,
309,
12235,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
309,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
199,
309,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
199,
309,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
309,
199,
309,
12235,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
199,
309,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
309,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
309,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
309,
199,
309,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
309,
3180,
543,
12235,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
2752,
12,
3277,
2020,
199,
309,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
15673,
13,
13421,
12,
8217,
14,
199,
199,
624,
199,
9153,
869,
13454,
6084,
3651,
25731,
1309,
748,
27,
510,
17177,
3506,
2845,
4815,
14,
19688,
199,
199,
607,
7597,
2897,
5461,
281,
436,
5077,
14214,
4744,
14,
199,
199,
7692,
26,
2366,
315,
1856,
73,
679,
9681,
63,
2724,
281,
3422,
14,
647,
359,
1419,
61,
199,
199,
14109,
1511,
26,
2043,
446,
72,
12,
1553,
3437,
14960,
870,
642,
1720,
2043,
446,
54,
12,
1553,
1023,
12793,
870,
1015,
1329,
199,
199,
28593,
1511,
26,
2043,
446,
68,
570,
17388,
5461,
314,
5055,
1901,
282,
1621,
41,
570,
2126,
446,
761,
13513,
3923,
1075,
17,
12,
29374,
18,
1396,
257,
3245,
15,
83,
370,
5461,
2126,
446,
452,
19242,
5461,
1006,
314,
5055,
2126,
1553,
3990,
13,
1580,
9668,
2597,
5461,
314,
2762,
402,
314,
6716,
370,
314,
570,
2126,
1553,
1199,
14516,
870,
314,
570,
315,
314,
6426,
199,
199,
5455,
1511,
26,
2043,
446,
76,
570,
17388,
2248,
282,
570,
1901,
314,
3050,
489,
446,
632,
284,
92,
67,
92,
82,
12788,
3504,
314,
818,
370,
2248,
8,
3176,
12,
3211,
12,
3350,
9,
199,
624,
199,
199,
363,
5792,
363,
275,
7880,
1304,
17351,
199,
199,
646,
984,
199,
646,
2196,
199,
646,
295,
199,
646,
2197,
199,
646,
5228,
199,
504,
1059,
492,
5458,
199,
504,
13640,
14,
697,
1131,
492,
1255,
63,
3009,
12,
29050,
63,
1224,
63,
2301,
63,
354,
199,
199,
504,
1101,
1113,
492,
4094,
5665,
199,
199,
7466,
63,
2711,
275,
298,
259,
298,
327,
41,
1326,
425,
315,
314,
23588,
568,
41,
570,
883,
506,
282,
5174,
15,
10749,
15,
6839,
1396,
199,
199,
23229,
275,
942,
327,
1296,
402,
3788,
370,
2929,
370,
314,
922,
737,
314,
1284,
402,
314,
6451,
199,
199,
7405,
63,
3472,
63,
6963,
275,
283,
73,
7,
199,
199,
15828,
275,
7815,
199,
199,
3,
2141,
402,
12136,
15023,
1504,
436,
314,
1245,
370,
2929,
199,
23113,
4924,
63,
8723,
63,
28427,
275,
469,
523,
283,
3627,
14,
2761,
513,
356,
3943,
4531,
7754,
295,
1065,
3330,
15772,
3130,
523,
283,
5470,
15468,
14,
8935,
545,
274,
63,
318,
63,
332,
356,
3943,
4531,
7754,
295,
1065,
3330,
2732,
2113,
446,
67,
3130,
523,
283,
3397,
5242,
3,
4531,
3378,
15685,
12082,
297,
523,
283,
1450,
14,
585,
5242,
3,
4531,
7754,
1255,
315,
1856,
73,
679,
9681,
1553,
1117,
13,
10297,
297,
523,
283,
698,
63,
1450,
14,
3397,
5242,
3,
4531,
8749,
1255,
315,
1856,
73,
679,
9681,
1553,
4498,
13,
7107,
7,
199,
93,
199,
199,
23037,
2823,
275,
469,
339,
283,
8609,
7,
520,
469,
2151,
283,
5987,
356,
91,
2151,
283,
698,
5242,
2880,
8,
698,
14,
344,
29,
13646,
14,
344,
63,
698,
12,
13646,
14,
4,
6066,
14,
4,
466,
275,
2672,
585,
3196,
2151,
283,
698,
63,
1450,
5242,
698,
63,
1450,
14,
344,
63,
698,
275,
901,
14,
344,
12,
901,
63,
1450,
14,
344,
63,
1450,
275,
1947,
14,
344,
297,
2151,
283,
1450,
5242,
3302,
2267,
2151,
283,
15741,
5242,
698,
13,
698,
63,
1450,
13,
1450,
297,
2151,
1660,
272,
283,
29374,
7,
520,
469,
267,
283,
5987,
356,
91,
288,
283,
3627,
5242,
3302,
297,
288,
283,
3627,
63,
2694,
5242,
3627,
63,
2694,
14,
344,
63,
2694,
275,
2893,
14,
344,
12,
3245,
63,
2694,
14,
344,
63,
3627,
275,
3245,
14,
344,
297,
288,
283,
2694,
5242,
3302,
2267,
267,
283,
15741,
5242,
3627,
13,
3627,
63,
2694,
13,
2694,
297,
267,
1660,
272,
283,
3657,
748,
15694,
7,
520,
469,
267,
283,
5987,
356,
91,
288,
283,
3627,
5242,
3302,
297,
288,
283,
3627,
63,
8707,
1977,
5242,
3627,
63,
8707,
1977,
14,
344,
63,
8707,
1977,
275,
18428,
1977,
14,
344,
12,
3245,
63,
8707,
1977,
14,
344,
63,
3627,
275,
3245,
14,
344,
297,
288,
283,
8707,
1977,
5242,
3302,
297,
267,
1660,
267,
283,
15741,
5242,
3627,
13,
3627,
63,
8707,
1977,
13,
8707,
1977,
297,
1362,
1660,
199,
93,
421,
199,
318,
870,
63,
3807,
837,
272,
408,
5375,
1720,
1041,
272,
870,
636,
1301,
363,
199,
199,
318,
1218,
63,
2792,
63,
344,
8,
1507,
12,
543,
63,
602,
29,
549,
304,
272,
408,
272,
7958,
282,
3747,
3420,
1305,
14,
272,
7905,
314,
1627,
1329,
315,
1300,
6155,
436,
5666,
282,
959,
10964,
2196,
1059,
272,
982,
543,
63,
602,
29,
549,
5666,
314,
1434,
737,
314,
5386,
78,
528,
880,
652,
883,
506,
7741,
14,
272,
662,
6976,
26,
272,
340,
543,
63,
602,
26,
1779,
1434,
1275,
1300,
1085,
8,
344,
9,
1275,
959,
2196,
8365,
259,
325,
14,
71,
14,
1947,
14,
6542,
13,
1780,
13,
1216,
14,
617,
2894,
90,
18,
276,
272,
587,
26,
1779,
1300,
1085,
8,
344,
9,
1275,
959,
2196,
8365,
257,
325,
14,
71,
14,
901,
14,
617,
2894,
90,
18,
276,
272,
408,
272,
7576,
275,
298,
23459,
11371,
2,
272,
620,
63,
344,
275,
3087,
272,
9483,
275,
6522,
904,
779,
2355,
14,
5095,
8,
7022,
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,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
bradleyayers/suds-htj
|
suds/soaparray.py
|
205
|
2262
|
# This program is free software; you can redistribute it and/or modify
# it under the terms of the (LGPL) GNU Lesser General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Library Lesser General Public License for more details at
# ( http://www.gnu.org/licenses/lgpl.html ).
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# written by: Jeff Ortel ( jortel@redhat.com )
"""
The I{soaparray} module provides XSD extensions for handling
soap (section 5) encoded arrays.
"""
from suds import *
from logging import getLogger
from suds.xsd.sxbasic import Factory as SXFactory
from suds.xsd.sxbasic import Attribute as SXAttribute
class Attribute(SXAttribute):
"""
Represents an XSD <attribute/> that handles special
attributes that are extensions for WSDLs.
@ivar aty: Array type information.
@type aty: The value of wsdl:arrayType.
"""
def __init__(self, schema, root, aty):
"""
@param aty: Array type information.
@type aty: The value of wsdl:arrayType.
"""
SXAttribute.__init__(self, schema, root)
if aty.endswith('[]'):
self.aty = aty[:-2]
else:
self.aty = aty
def autoqualified(self):
aqs = SXAttribute.autoqualified(self)
aqs.append('aty')
return aqs
def description(self):
d = SXAttribute.description(self)
d = d+('aty',)
return d
#
# Builder function, only builds Attribute when arrayType
# attribute is defined on root.
#
def __fn(x, y):
ns = (None, "http://schemas.xmlsoap.org/wsdl/")
aty = y.get('arrayType', ns=ns)
if aty is None:
return SXAttribute(x, y)
else:
return Attribute(x, y, aty)
#
# Remap <xs:attrbute/> tags to __fn() builder.
#
SXFactory.maptag('attribute', __fn)
|
lgpl-3.0
|
[
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
334,
44,
12006,
9,
1664,
6401,
1696,
1684,
844,
465,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
650,
402,
314,
221,
199,
3,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
11243,
6401,
1696,
1684,
844,
367,
1655,
2436,
737,
199,
3,
334,
1455,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
9783,
1168,
14,
1360,
7092,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8155,
15630,
10902,
446,
14453,
13540,
12,
8226,
12,
4828,
15673,
13,
13421,
12,
8217,
14,
199,
3,
5313,
701,
26,
1603,
3609,
4236,
14146,
334,
1335,
269,
14146,
32,
17164,
14,
957,
776,
199,
199,
624,
199,
1918,
473,
91,
21818,
1144,
93,
859,
6571,
1323,
3693,
5478,
367,
7252,
199,
21818,
334,
2792,
959,
9,
5737,
6572,
14,
199,
624,
199,
199,
504,
30713,
492,
627,
199,
504,
2050,
492,
28138,
199,
504,
30713,
14,
10515,
14,
83,
1774,
2484,
492,
23616,
465,
428,
56,
2927,
199,
504,
30713,
14,
10515,
14,
83,
1774,
2484,
492,
3882,
465,
428,
56,
1646,
421,
199,
533,
3882,
8,
29768,
1646,
304,
272,
408,
272,
21591,
376,
1323,
3693,
665,
3215,
3133,
626,
10022,
4539,
272,
3004,
626,
787,
5478,
367,
644,
14029,
83,
14,
272,
768,
7725,
282,
369,
26,
8725,
730,
2556,
14,
272,
768,
466,
282,
369,
26,
710,
574,
402,
336,
22837,
26,
1144,
804,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
4177,
12,
1738,
12,
282,
369,
304,
267,
408,
267,
768,
635,
282,
369,
26,
8725,
730,
2556,
14,
267,
768,
466,
282,
369,
26,
710,
574,
402,
336,
22837,
26,
1144,
804,
14,
267,
408,
267,
428,
56,
1646,
855,
826,
721,
277,
12,
4177,
12,
1738,
9,
267,
340,
282,
369,
14,
4130,
360,
8607,
735,
288,
291,
14,
292,
89,
275,
282,
369,
4439,
18,
61,
267,
587,
26,
288,
291,
14,
292,
89,
275,
282,
369,
5493,
347,
2599,
11661,
8,
277,
304,
267,
282,
6177,
275,
428,
56,
1646,
14,
2495,
11661,
8,
277,
9,
267,
282,
6177,
14,
740,
360,
292,
89,
358,
267,
372,
282,
6177,
2286,
347,
1369,
8,
277,
304,
267,
366,
275,
428,
56,
1646,
14,
1802,
8,
277,
9,
267,
366,
275,
366,
11,
360,
292,
89,
9538,
267,
372,
366,
199,
199,
3,
199,
3,
19286,
805,
12,
1454,
14723,
3882,
1380,
1625,
804,
199,
3,
2225,
365,
3247,
641,
1738,
14,
199,
3,
199,
318,
636,
2324,
8,
88,
12,
612,
304,
272,
700,
275,
334,
403,
12,
298,
1014,
921,
9482,
14,
10198,
5770,
439,
14,
1308,
15,
21452,
13589,
272,
282,
369,
275,
612,
14,
362,
360,
1144,
804,
297,
700,
29,
561,
9,
272,
340,
282,
369,
365,
488,
26,
267,
372,
428,
56,
1646,
8,
88,
12,
612,
9,
272,
587,
26,
267,
372,
3882,
8,
88,
12,
612,
12,
282,
369,
9,
199,
199,
3,
199,
3,
799,
1130,
665,
7977,
26,
962,
26583,
3133,
3762,
370,
636,
2324,
342,
6545,
14,
199,
3,
199,
29768,
2927,
14,
1130,
1450,
360,
3215,
297,
636,
2324,
9,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
334,
44,
12006,
9,
1664,
6401,
1696,
1684,
844,
465,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
650,
402,
314,
221,
199,
3,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
11243,
6401,
1696,
1684,
844,
367,
1655,
2436,
737,
199,
3,
334,
1455,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
9783,
1168,
14,
1360,
7092,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8155,
15630,
10902,
446,
14453,
13540,
12,
8226,
12,
4828,
15673,
13,
13421,
12,
8217,
14,
199,
3,
5313,
701,
26,
1603,
3609,
4236,
14146,
334,
1335,
269,
14146,
32,
17164,
14,
957,
776,
199,
199,
624,
199,
1918,
473,
91,
21818,
1144,
93,
859,
6571,
1323,
3693,
5478,
367,
7252,
199,
21818,
334,
2792,
959,
9,
5737,
6572,
14,
199,
624,
199,
199,
504,
30713,
492,
627,
199,
504,
2050,
492,
28138,
199,
504,
30713,
14,
10515,
14,
83,
1774,
2484,
492,
23616,
465,
428,
56,
2927,
199,
504,
30713,
14,
10515,
14,
83,
1774,
2484,
492,
3882,
465,
428,
56,
1646,
421,
199,
533,
3882,
8,
29768,
1646,
304,
272,
408,
272,
21591,
376,
1323,
3693,
665,
3215,
3133,
626,
10022,
4539,
272,
3004,
626,
787,
5478,
367,
644,
14029,
83,
14,
272,
768,
7725,
282,
369,
26,
8725,
730,
2556,
14,
272,
768,
466,
282,
369,
26,
710,
574,
402,
336,
22837,
26,
1144,
804,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
4177,
12,
1738,
12,
282,
369,
304,
267,
408,
267,
768,
635,
282,
369,
26,
8725,
730,
2556,
14,
267,
768,
466,
282,
369,
26,
710,
574,
402,
336,
22837,
26,
1144,
804,
14,
267,
408,
267,
428,
56,
1646,
855,
826,
721,
277,
12,
4177,
12,
1738,
9,
267,
340,
282,
369,
14,
4130,
360,
8607,
735,
288,
291,
14,
292,
89,
275,
282,
369,
4439,
18,
61,
267,
587,
26,
288,
291,
14,
292,
89,
275,
282,
369,
5493,
347,
2599,
11661,
8,
277,
304,
267,
282,
6177,
275,
428,
56,
1646,
14,
2495,
11661,
8,
277,
9,
267,
282,
6177,
14,
740,
360,
292,
89,
358,
267,
372,
282,
6177,
2286,
347,
1369,
8,
277,
304,
267,
366,
275,
428,
56,
1646,
14,
1802,
8,
277,
9,
267,
366,
275,
366,
11,
360,
292,
89,
9538,
267,
372,
366,
199,
199,
3,
199,
3,
19286,
805,
12,
1454,
14723,
3882,
1380,
1625,
804,
199,
3,
2225,
365,
3247,
641,
1738,
14,
199,
3,
199,
318,
636,
2324,
8,
88,
12,
612,
304,
272,
700,
275,
334,
403,
12,
298,
1014,
921,
9482,
14,
10198,
5770,
439,
14,
1308,
15,
21452,
13589,
272,
282,
369,
275,
612,
14,
362,
360,
1144,
804,
297,
700,
29,
561,
9,
272,
340,
282,
369,
365,
488,
26,
267,
372,
428,
56,
1646,
8,
88,
12,
612,
9,
272,
587,
26,
267,
372,
3882,
8,
88,
12,
612,
12,
282,
369,
9,
199,
199,
3,
199,
3,
799,
1130,
665,
7977,
26,
962,
26583,
3133,
3762,
370,
636,
2324,
342,
6545,
14,
199,
3,
199,
29768,
2927,
14,
1130,
1450,
360,
3215,
297,
636,
2324,
9,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
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,
0
] |
Zac-HD/home-assistant
|
homeassistant/components/lock/nuki.py
|
10
|
2093
|
"""
Nuki.io lock platform.
For more details about this platform, please refer to the documentation
https://home-assistant.io/components/lock.nuki/
"""
from datetime import timedelta
import logging
import voluptuous as vol
from homeassistant.components.lock import (LockDevice, PLATFORM_SCHEMA)
from homeassistant.const import (CONF_HOST, CONF_PORT, CONF_TOKEN)
from homeassistant.util import Throttle
import homeassistant.helpers.config_validation as cv
REQUIREMENTS = ['pynuki==1.2.2']
_LOGGER = logging.getLogger(__name__)
DEFAULT_PORT = 8080
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_HOST): cv.string,
vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
vol.Required(CONF_TOKEN): cv.string
})
MIN_TIME_BETWEEN_SCANS = timedelta(seconds=30)
MIN_TIME_BETWEEN_FORCED_SCANS = timedelta(seconds=5)
# pylint: disable=unused-argument
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup the Demo lock platform."""
from pynuki import NukiBridge
bridge = NukiBridge(config.get(CONF_HOST), config.get(CONF_TOKEN))
add_devices([NukiLock(lock) for lock in bridge.locks])
class NukiLock(LockDevice):
"""Representation of a Nuki lock."""
def __init__(self, nuki_lock):
"""Initialize the lock."""
self._nuki_lock = nuki_lock
self._locked = nuki_lock.is_locked
self._name = nuki_lock.name
@property
def name(self):
"""Return the name of the lock."""
return self._name
@property
def is_locked(self):
"""Return true if lock is locked."""
return self._locked
@Throttle(MIN_TIME_BETWEEN_SCANS, MIN_TIME_BETWEEN_FORCED_SCANS)
def update(self):
"""Update the nuki lock properties."""
self._nuki_lock.update(aggressive=False)
self._name = self._nuki_lock.name
self._locked = self._nuki_lock.is_locked
def lock(self, **kwargs):
"""Lock the device."""
self._nuki_lock.lock()
def unlock(self, **kwargs):
"""Unlock the device."""
self._nuki_lock.unlock()
|
apache-2.0
|
[
624,
199,
46,
3210,
73,
14,
2308,
4650,
4298,
14,
199,
199,
1858,
1655,
2436,
3595,
642,
4298,
12,
8749,
10618,
370,
314,
3794,
199,
2859,
921,
4219,
13,
7310,
14,
2308,
15,
4608,
15,
831,
14,
78,
3210,
73,
15,
199,
624,
199,
504,
2197,
492,
6871,
199,
646,
2050,
199,
646,
30291,
465,
5236,
199,
199,
504,
8846,
14,
4608,
14,
831,
492,
334,
6432,
2510,
12,
21966,
63,
10926,
9,
199,
504,
8846,
14,
1297,
492,
334,
3103,
63,
5449,
12,
6392,
63,
3657,
12,
6392,
63,
8803,
9,
199,
504,
8846,
14,
1974,
492,
3868,
12301,
199,
646,
8846,
14,
7546,
14,
888,
63,
6136,
465,
6277,
421,
199,
29168,
20967,
275,
788,
647,
78,
3210,
73,
389,
17,
14,
18,
14,
18,
418,
199,
199,
63,
10186,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
3472,
63,
3657,
275,
30220,
199,
199,
17805,
63,
10926,
275,
21966,
63,
10926,
14,
2880,
2561,
272,
5236,
14,
8030,
8,
3103,
63,
5449,
304,
6277,
14,
875,
12,
272,
5236,
14,
7012,
8,
3103,
63,
3657,
12,
849,
29,
3472,
63,
3657,
304,
6277,
14,
719,
12,
272,
5236,
14,
8030,
8,
3103,
63,
8803,
304,
6277,
14,
875,
199,
1552,
421,
199,
4896,
63,
4961,
63,
34,
29056,
63,
5153,
5622,
275,
6871,
8,
4515,
29,
1216,
9,
199,
4896,
63,
4961,
63,
34,
29056,
63,
2707,
25927,
63,
5153,
5622,
275,
6871,
8,
4515,
29,
21,
9,
421,
199,
3,
4287,
26,
3507,
29,
8618,
13,
2094,
199,
318,
3272,
63,
3246,
8,
5387,
12,
1101,
12,
1050,
63,
6410,
12,
13172,
63,
815,
29,
403,
304,
272,
408,
8555,
314,
28939,
4650,
4298,
1041,
272,
687,
1134,
78,
3210,
73,
492,
653,
3210,
73,
14491,
272,
13928,
275,
653,
3210,
73,
14491,
8,
888,
14,
362,
8,
3103,
63,
5449,
395,
1101,
14,
362,
8,
3103,
63,
8803,
430,
272,
1050,
63,
6410,
779,
46,
3210,
73,
6432,
8,
831,
9,
367,
4650,
315,
13928,
14,
20218,
566,
421,
199,
533,
653,
3210,
73,
6432,
8,
6432,
2510,
304,
272,
408,
20609,
402,
282,
653,
3210,
73,
4650,
1041,
339,
347,
636,
826,
721,
277,
12,
302,
3210,
73,
63,
831,
304,
267,
408,
9345,
314,
4650,
1041,
267,
291,
423,
78,
3210,
73,
63,
831,
275,
302,
3210,
73,
63,
831,
267,
291,
423,
9325,
275,
302,
3210,
73,
63,
831,
14,
374,
63,
9325,
267,
291,
423,
354,
275,
302,
3210,
73,
63,
831,
14,
354,
339,
768,
1829,
272,
347,
536,
8,
277,
304,
267,
408,
1767,
314,
536,
402,
314,
4650,
1041,
267,
372,
291,
423,
354,
339,
768,
1829,
272,
347,
365,
63,
9325,
8,
277,
304,
267,
408,
1767,
2549,
340,
4650,
365,
14233,
1041,
267,
372,
291,
423,
9325,
339,
768,
26192,
8,
4896,
63,
4961,
63,
34,
29056,
63,
5153,
5622,
12,
15861,
63,
4961,
63,
34,
29056,
63,
2707,
25927,
63,
5153,
5622,
9,
272,
347,
1678,
8,
277,
304,
267,
408,
4152,
314,
302,
3210,
73,
4650,
4382,
1041,
267,
291,
423,
78,
3210,
73,
63,
831,
14,
873,
8,
643,
25787,
29,
797,
9,
267,
291,
423,
354,
275,
291,
423,
78,
3210,
73,
63,
831,
14,
354,
267,
291,
423,
9325,
275,
291,
423,
78,
3210,
73,
63,
831,
14,
374,
63,
9325,
339,
347,
4650,
8,
277,
12,
1011,
958,
304,
267,
408,
6432,
314,
2243,
1041,
267,
291,
423,
78,
3210,
73,
63,
831,
14,
831,
342,
339,
347,
28451,
8,
277,
12,
1011,
958,
304,
267,
408,
1358,
831,
314,
2243,
1041,
267,
291,
423,
78,
3210,
73,
63,
831,
14,
17966,
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
] |
[
199,
46,
3210,
73,
14,
2308,
4650,
4298,
14,
199,
199,
1858,
1655,
2436,
3595,
642,
4298,
12,
8749,
10618,
370,
314,
3794,
199,
2859,
921,
4219,
13,
7310,
14,
2308,
15,
4608,
15,
831,
14,
78,
3210,
73,
15,
199,
624,
199,
504,
2197,
492,
6871,
199,
646,
2050,
199,
646,
30291,
465,
5236,
199,
199,
504,
8846,
14,
4608,
14,
831,
492,
334,
6432,
2510,
12,
21966,
63,
10926,
9,
199,
504,
8846,
14,
1297,
492,
334,
3103,
63,
5449,
12,
6392,
63,
3657,
12,
6392,
63,
8803,
9,
199,
504,
8846,
14,
1974,
492,
3868,
12301,
199,
646,
8846,
14,
7546,
14,
888,
63,
6136,
465,
6277,
421,
199,
29168,
20967,
275,
788,
647,
78,
3210,
73,
389,
17,
14,
18,
14,
18,
418,
199,
199,
63,
10186,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
3472,
63,
3657,
275,
30220,
199,
199,
17805,
63,
10926,
275,
21966,
63,
10926,
14,
2880,
2561,
272,
5236,
14,
8030,
8,
3103,
63,
5449,
304,
6277,
14,
875,
12,
272,
5236,
14,
7012,
8,
3103,
63,
3657,
12,
849,
29,
3472,
63,
3657,
304,
6277,
14,
719,
12,
272,
5236,
14,
8030,
8,
3103,
63,
8803,
304,
6277,
14,
875,
199,
1552,
421,
199,
4896,
63,
4961,
63,
34,
29056,
63,
5153,
5622,
275,
6871,
8,
4515,
29,
1216,
9,
199,
4896,
63,
4961,
63,
34,
29056,
63,
2707,
25927,
63,
5153,
5622,
275,
6871,
8,
4515,
29,
21,
9,
421,
199,
3,
4287,
26,
3507,
29,
8618,
13,
2094,
199,
318,
3272,
63,
3246,
8,
5387,
12,
1101,
12,
1050,
63,
6410,
12,
13172,
63,
815,
29,
403,
304,
272,
408,
8555,
314,
28939,
4650,
4298,
1041,
272,
687,
1134,
78,
3210,
73,
492,
653,
3210,
73,
14491,
272,
13928,
275,
653,
3210,
73,
14491,
8,
888,
14,
362,
8,
3103,
63,
5449,
395,
1101,
14,
362,
8,
3103,
63,
8803,
430,
272,
1050,
63,
6410,
779,
46,
3210,
73,
6432,
8,
831,
9,
367,
4650,
315,
13928,
14,
20218,
566,
421,
199,
533,
653,
3210,
73,
6432,
8,
6432,
2510,
304,
272,
408,
20609,
402,
282,
653,
3210,
73,
4650,
1041,
339,
347,
636,
826,
721,
277,
12,
302,
3210,
73,
63,
831,
304,
267,
408,
9345,
314,
4650,
1041,
267,
291,
423,
78,
3210,
73,
63,
831,
275,
302,
3210,
73,
63,
831,
267,
291,
423,
9325,
275,
302,
3210,
73,
63,
831,
14,
374,
63,
9325,
267,
291,
423,
354,
275,
302,
3210,
73,
63,
831,
14,
354,
339,
768,
1829,
272,
347,
536,
8,
277,
304,
267,
408,
1767,
314,
536,
402,
314,
4650,
1041,
267,
372,
291,
423,
354,
339,
768,
1829,
272,
347,
365,
63,
9325,
8,
277,
304,
267,
408,
1767,
2549,
340,
4650,
365,
14233,
1041,
267,
372,
291,
423,
9325,
339,
768,
26192,
8,
4896,
63,
4961,
63,
34,
29056,
63,
5153,
5622,
12,
15861,
63,
4961,
63,
34,
29056,
63,
2707,
25927,
63,
5153,
5622,
9,
272,
347,
1678,
8,
277,
304,
267,
408,
4152,
314,
302,
3210,
73,
4650,
4382,
1041,
267,
291,
423,
78,
3210,
73,
63,
831,
14,
873,
8,
643,
25787,
29,
797,
9,
267,
291,
423,
354,
275,
291,
423,
78,
3210,
73,
63,
831,
14,
354,
267,
291,
423,
9325,
275,
291,
423,
78,
3210,
73,
63,
831,
14,
374,
63,
9325,
339,
347,
4650,
8,
277,
12,
1011,
958,
304,
267,
408,
6432,
314,
2243,
1041,
267,
291,
423,
78,
3210,
73,
63,
831,
14,
831,
342,
339,
347,
28451,
8,
277,
12,
1011,
958,
304,
267,
408,
1358,
831,
314,
2243,
1041,
267,
291,
423,
78,
3210,
73,
63,
831,
14,
17966,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
justathoughtor2/atomicApe
|
cygwin/lib/python2.7/site-packages/unidecode/x081.py
|
252
|
4673
|
data = (
'Cheng ', # 0x00
'Tiao ', # 0x01
'Zhi ', # 0x02
'Cui ', # 0x03
'Mei ', # 0x04
'Xie ', # 0x05
'Cui ', # 0x06
'Xie ', # 0x07
'Mo ', # 0x08
'Mai ', # 0x09
'Ji ', # 0x0a
'Obiyaakasu ', # 0x0b
'[?] ', # 0x0c
'Kuai ', # 0x0d
'Sa ', # 0x0e
'Zang ', # 0x0f
'Qi ', # 0x10
'Nao ', # 0x11
'Mi ', # 0x12
'Nong ', # 0x13
'Luan ', # 0x14
'Wan ', # 0x15
'Bo ', # 0x16
'Wen ', # 0x17
'Guan ', # 0x18
'Qiu ', # 0x19
'Jiao ', # 0x1a
'Jing ', # 0x1b
'Rou ', # 0x1c
'Heng ', # 0x1d
'Cuo ', # 0x1e
'Lie ', # 0x1f
'Shan ', # 0x20
'Ting ', # 0x21
'Mei ', # 0x22
'Chun ', # 0x23
'Shen ', # 0x24
'Xie ', # 0x25
'De ', # 0x26
'Zui ', # 0x27
'Cu ', # 0x28
'Xiu ', # 0x29
'Xin ', # 0x2a
'Tuo ', # 0x2b
'Pao ', # 0x2c
'Cheng ', # 0x2d
'Nei ', # 0x2e
'Fu ', # 0x2f
'Dou ', # 0x30
'Tuo ', # 0x31
'Niao ', # 0x32
'Noy ', # 0x33
'Pi ', # 0x34
'Gu ', # 0x35
'Gua ', # 0x36
'Li ', # 0x37
'Lian ', # 0x38
'Zhang ', # 0x39
'Cui ', # 0x3a
'Jie ', # 0x3b
'Liang ', # 0x3c
'Zhou ', # 0x3d
'Pi ', # 0x3e
'Biao ', # 0x3f
'Lun ', # 0x40
'Pian ', # 0x41
'Guo ', # 0x42
'Kui ', # 0x43
'Chui ', # 0x44
'Dan ', # 0x45
'Tian ', # 0x46
'Nei ', # 0x47
'Jing ', # 0x48
'Jie ', # 0x49
'La ', # 0x4a
'Yi ', # 0x4b
'An ', # 0x4c
'Ren ', # 0x4d
'Shen ', # 0x4e
'Chuo ', # 0x4f
'Fu ', # 0x50
'Fu ', # 0x51
'Ju ', # 0x52
'Fei ', # 0x53
'Qiang ', # 0x54
'Wan ', # 0x55
'Dong ', # 0x56
'Pi ', # 0x57
'Guo ', # 0x58
'Zong ', # 0x59
'Ding ', # 0x5a
'Wu ', # 0x5b
'Mei ', # 0x5c
'Ruan ', # 0x5d
'Zhuan ', # 0x5e
'Zhi ', # 0x5f
'Cou ', # 0x60
'Gua ', # 0x61
'Ou ', # 0x62
'Di ', # 0x63
'An ', # 0x64
'Xing ', # 0x65
'Nao ', # 0x66
'Yu ', # 0x67
'Chuan ', # 0x68
'Nan ', # 0x69
'Yun ', # 0x6a
'Zhong ', # 0x6b
'Rou ', # 0x6c
'E ', # 0x6d
'Sai ', # 0x6e
'Tu ', # 0x6f
'Yao ', # 0x70
'Jian ', # 0x71
'Wei ', # 0x72
'Jiao ', # 0x73
'Yu ', # 0x74
'Jia ', # 0x75
'Duan ', # 0x76
'Bi ', # 0x77
'Chang ', # 0x78
'Fu ', # 0x79
'Xian ', # 0x7a
'Ni ', # 0x7b
'Mian ', # 0x7c
'Wa ', # 0x7d
'Teng ', # 0x7e
'Tui ', # 0x7f
'Bang ', # 0x80
'Qian ', # 0x81
'Lu ', # 0x82
'Wa ', # 0x83
'Sou ', # 0x84
'Tang ', # 0x85
'Su ', # 0x86
'Zhui ', # 0x87
'Ge ', # 0x88
'Yi ', # 0x89
'Bo ', # 0x8a
'Liao ', # 0x8b
'Ji ', # 0x8c
'Pi ', # 0x8d
'Xie ', # 0x8e
'Gao ', # 0x8f
'Lu ', # 0x90
'Bin ', # 0x91
'Ou ', # 0x92
'Chang ', # 0x93
'Lu ', # 0x94
'Guo ', # 0x95
'Pang ', # 0x96
'Chuai ', # 0x97
'Piao ', # 0x98
'Jiang ', # 0x99
'Fu ', # 0x9a
'Tang ', # 0x9b
'Mo ', # 0x9c
'Xi ', # 0x9d
'Zhuan ', # 0x9e
'Lu ', # 0x9f
'Jiao ', # 0xa0
'Ying ', # 0xa1
'Lu ', # 0xa2
'Zhi ', # 0xa3
'Tara ', # 0xa4
'Chun ', # 0xa5
'Lian ', # 0xa6
'Tong ', # 0xa7
'Peng ', # 0xa8
'Ni ', # 0xa9
'Zha ', # 0xaa
'Liao ', # 0xab
'Cui ', # 0xac
'Gui ', # 0xad
'Xiao ', # 0xae
'Teng ', # 0xaf
'Fan ', # 0xb0
'Zhi ', # 0xb1
'Jiao ', # 0xb2
'Shan ', # 0xb3
'Wu ', # 0xb4
'Cui ', # 0xb5
'Run ', # 0xb6
'Xiang ', # 0xb7
'Sui ', # 0xb8
'Fen ', # 0xb9
'Ying ', # 0xba
'Tan ', # 0xbb
'Zhua ', # 0xbc
'Dan ', # 0xbd
'Kuai ', # 0xbe
'Nong ', # 0xbf
'Tun ', # 0xc0
'Lian ', # 0xc1
'Bi ', # 0xc2
'Yong ', # 0xc3
'Jue ', # 0xc4
'Chu ', # 0xc5
'Yi ', # 0xc6
'Juan ', # 0xc7
'La ', # 0xc8
'Lian ', # 0xc9
'Sao ', # 0xca
'Tun ', # 0xcb
'Gu ', # 0xcc
'Qi ', # 0xcd
'Cui ', # 0xce
'Bin ', # 0xcf
'Xun ', # 0xd0
'Ru ', # 0xd1
'Huo ', # 0xd2
'Zang ', # 0xd3
'Xian ', # 0xd4
'Biao ', # 0xd5
'Xing ', # 0xd6
'Kuan ', # 0xd7
'La ', # 0xd8
'Yan ', # 0xd9
'Lu ', # 0xda
'Huo ', # 0xdb
'Zang ', # 0xdc
'Luo ', # 0xdd
'Qu ', # 0xde
'Zang ', # 0xdf
'Luan ', # 0xe0
'Ni ', # 0xe1
'Zang ', # 0xe2
'Chen ', # 0xe3
'Qian ', # 0xe4
'Wo ', # 0xe5
'Guang ', # 0xe6
'Zang ', # 0xe7
'Lin ', # 0xe8
'Guang ', # 0xe9
'Zi ', # 0xea
'Jiao ', # 0xeb
'Nie ', # 0xec
'Chou ', # 0xed
'Ji ', # 0xee
'Gao ', # 0xef
'Chou ', # 0xf0
'Mian ', # 0xf1
'Nie ', # 0xf2
'Zhi ', # 0xf3
'Zhi ', # 0xf4
'Ge ', # 0xf5
'Jian ', # 0xf6
'Die ', # 0xf7
'Zhi ', # 0xf8
'Xiu ', # 0xf9
'Tai ', # 0xfa
'Zhen ', # 0xfb
'Jiu ', # 0xfc
'Xian ', # 0xfd
'Yu ', # 0xfe
'Cha ', # 0xff
)
|
gpl-3.0
|
[
576,
275,
334,
199,
7,
1049,
7420,
1656,
259,
327,
378,
88,
383,
199,
7,
52,
18939,
1656,
259,
327,
378,
88,
614,
199,
7,
58,
5812,
1656,
259,
327,
378,
88,
996,
199,
7,
35,
1907,
1656,
259,
327,
378,
88,
1644,
199,
7,
1352,
73,
1656,
259,
327,
378,
88,
966,
199,
7,
56,
1873,
1656,
259,
327,
378,
88,
1717,
199,
7,
35,
1907,
1656,
259,
327,
378,
88,
1690,
199,
7,
56,
1873,
1656,
259,
327,
378,
88,
1780,
199,
7,
3716,
1656,
259,
327,
378,
88,
2036,
199,
7,
45,
5789,
1656,
259,
327,
378,
88,
1643,
199,
7,
16911,
1656,
259,
327,
378,
88,
16,
65,
199,
7,
47,
4492,
11552,
1151,
305,
85,
1656,
259,
327,
378,
88,
16,
66,
199,
17892,
1656,
259,
327,
378,
88,
16,
67,
199,
7,
43,
1458,
73,
1656,
259,
327,
378,
88,
16,
68,
199,
7,
12226,
1656,
259,
327,
378,
88,
16,
69,
199,
7,
58,
621,
1656,
259,
327,
378,
88,
16,
70,
199,
7,
19910,
1656,
259,
327,
378,
88,
709,
199,
7,
46,
8035,
1656,
259,
327,
378,
88,
845,
199,
7,
14738,
1656,
259,
327,
378,
88,
713,
199,
7,
46,
951,
1656,
259,
327,
378,
88,
969,
199,
7,
44,
7856,
1656,
259,
327,
378,
88,
1079,
199,
7,
55,
290,
1656,
259,
327,
378,
88,
1046,
199,
7,
2208,
1656,
259,
327,
378,
88,
975,
199,
7,
55,
287,
1656,
259,
327,
378,
88,
1196,
199,
7,
39,
7856,
1656,
259,
327,
378,
88,
1085,
199,
7,
19910,
85,
1656,
259,
327,
378,
88,
1167,
199,
7,
42,
18939,
1656,
259,
327,
378,
88,
17,
65,
199,
7,
42,
316,
1656,
259,
327,
378,
88,
17,
66,
199,
7,
5407,
1656,
259,
327,
378,
88,
17,
67,
199,
7,
40,
7420,
1656,
259,
327,
378,
88,
17,
68,
199,
7,
35,
13780,
1656,
259,
327,
378,
88,
17,
69,
199,
7,
44,
1873,
1656,
259,
327,
378,
88,
17,
70,
199,
7,
2662,
290,
1656,
259,
327,
378,
88,
1165,
199,
7,
52,
316,
1656,
259,
327,
378,
88,
2025,
199,
7,
1352,
73,
1656,
259,
327,
378,
88,
1081,
199,
7,
1049,
324,
1656,
259,
327,
378,
88,
1789,
199,
7,
2662,
287,
1656,
259,
327,
378,
88,
1194,
199,
7,
56,
1873,
1656,
259,
327,
378,
88,
821,
199,
7,
872,
1656,
259,
327,
378,
88,
1479,
199,
7,
58,
1907,
1656,
259,
327,
378,
88,
1465,
199,
7,
35,
85,
1656,
259,
327,
378,
88,
1651,
199,
7,
14828,
85,
1656,
259,
327,
378,
88,
1398,
199,
7,
56,
262,
1656,
259,
327,
378,
88,
18,
65,
199,
7,
52,
13780,
1656,
259,
327,
378,
88,
18,
66,
199,
7,
4232,
79,
1656,
259,
327,
378,
88,
18,
67,
199,
7,
1049,
7420,
1656,
259,
327,
378,
88,
18,
68,
199,
7,
4698,
73,
1656,
259,
327,
378,
88,
18,
69,
199,
7,
19590,
1656,
259,
327,
378,
88,
18,
70,
199,
7,
36,
810,
1656,
259,
327,
378,
88,
1216,
199,
7,
52,
13780,
1656,
259,
327,
378,
88,
2192,
199,
7,
46,
18939,
1656,
259,
327,
378,
88,
708,
199,
7,
1944,
89,
1656,
259,
327,
378,
88,
1153,
199,
7,
10542,
1656,
259,
327,
378,
88,
1082,
199,
7,
11548,
1656,
259,
327,
378,
88,
1276,
199,
7,
39,
1458,
1656,
259,
327,
378,
88,
1344,
199,
7,
13009,
1656,
259,
327,
378,
88,
1401,
199,
7,
44,
5653,
1656,
259,
327,
378,
88,
1703,
199,
7,
12674,
621,
1656,
259,
327,
378,
88,
1355,
199,
7,
35,
1907,
1656,
259,
327,
378,
88,
19,
65,
199,
7,
42,
1873,
1656,
259,
327,
378,
88,
19,
66,
199,
7,
13009,
621,
1656,
259,
327,
378,
88,
19,
67,
199,
7,
58,
11586,
1656,
259,
327,
378,
88,
19,
68,
199,
7,
10542,
1656,
259,
327,
378,
88,
19,
69,
199,
7,
34,
18939,
1656,
259,
327,
378,
88,
19,
70,
199,
7,
44,
324,
1656,
259,
327,
378,
88,
2167,
199,
7,
48,
5653,
1656,
259,
327,
378,
88,
2953,
199,
7,
11548,
79,
1656,
259,
327,
378,
88,
2260,
199,
7,
43,
1907,
1656,
259,
327,
378,
88,
2824,
199,
7,
1049,
1907,
1656,
259,
327,
378,
88,
1602,
199,
7,
29336,
1656,
259,
327,
378,
88,
2322,
199,
7,
52,
5653,
1656,
259,
327,
378,
88,
2466,
199,
7,
4698,
73,
1656,
259,
327,
378,
88,
2417,
199,
7,
42,
316,
1656,
259,
327,
378,
88,
2006,
199,
7,
42,
1873,
1656,
259,
327,
378,
88,
1887,
199,
7,
7833,
1656,
259,
327,
378,
88,
20,
65,
199,
7,
21001,
1656,
259,
327,
378,
88,
20,
66,
199,
7,
2493,
1656,
259,
327,
378,
88,
20,
67,
199,
7,
5349,
1656,
259,
327,
378,
88,
20,
68,
199,
7,
2662,
287,
1656,
259,
327,
378,
88,
20,
69,
199,
7,
1049,
13780,
1656,
259,
327,
378,
88,
20,
70,
199,
7,
19590,
1656,
259,
327,
378,
88,
1400,
199,
7,
19590,
1656,
259,
327,
378,
88,
2869,
199,
7,
24783,
1656,
259,
327,
378,
88,
2528,
199,
7,
3456,
73,
1656,
259,
327,
378,
88,
2481,
199,
7,
19910,
621,
1656,
259,
327,
378,
88,
1477,
199,
7,
55,
290,
1656,
259,
327,
378,
88,
1229,
199,
7,
36,
951,
1656,
259,
327,
378,
88,
1367,
199,
7,
10542,
1656,
259,
327,
378,
88,
1641,
199,
7,
11548,
79,
1656,
259,
327,
378,
88,
2010,
199,
7,
58,
951,
1656,
259,
327,
378,
88,
1427,
199,
7,
36,
316,
1656,
259,
327,
378,
88,
21,
65,
199,
7,
25728,
1656,
259,
327,
378,
88,
21,
66,
199,
7,
1352,
73,
1656,
259,
327,
378,
88,
21,
67,
199,
7,
50,
7856,
1656,
259,
327,
378,
88,
21,
68,
199,
7,
12674,
7856,
1656,
259,
327,
378,
88,
21,
69,
199,
7,
58,
5812,
1656,
259,
327,
378,
88,
21,
70,
199,
7,
35,
810,
1656,
259,
327,
378,
88,
2259,
199,
7,
39,
1458,
1656,
259,
327,
378,
88,
2976,
199,
7,
47,
85,
1656,
259,
327,
378,
88,
2789,
199,
7,
1341,
1656,
259,
327,
378,
88,
2766,
199,
7,
2493,
1656,
259,
327
] |
[
275,
334,
199,
7,
1049,
7420,
1656,
259,
327,
378,
88,
383,
199,
7,
52,
18939,
1656,
259,
327,
378,
88,
614,
199,
7,
58,
5812,
1656,
259,
327,
378,
88,
996,
199,
7,
35,
1907,
1656,
259,
327,
378,
88,
1644,
199,
7,
1352,
73,
1656,
259,
327,
378,
88,
966,
199,
7,
56,
1873,
1656,
259,
327,
378,
88,
1717,
199,
7,
35,
1907,
1656,
259,
327,
378,
88,
1690,
199,
7,
56,
1873,
1656,
259,
327,
378,
88,
1780,
199,
7,
3716,
1656,
259,
327,
378,
88,
2036,
199,
7,
45,
5789,
1656,
259,
327,
378,
88,
1643,
199,
7,
16911,
1656,
259,
327,
378,
88,
16,
65,
199,
7,
47,
4492,
11552,
1151,
305,
85,
1656,
259,
327,
378,
88,
16,
66,
199,
17892,
1656,
259,
327,
378,
88,
16,
67,
199,
7,
43,
1458,
73,
1656,
259,
327,
378,
88,
16,
68,
199,
7,
12226,
1656,
259,
327,
378,
88,
16,
69,
199,
7,
58,
621,
1656,
259,
327,
378,
88,
16,
70,
199,
7,
19910,
1656,
259,
327,
378,
88,
709,
199,
7,
46,
8035,
1656,
259,
327,
378,
88,
845,
199,
7,
14738,
1656,
259,
327,
378,
88,
713,
199,
7,
46,
951,
1656,
259,
327,
378,
88,
969,
199,
7,
44,
7856,
1656,
259,
327,
378,
88,
1079,
199,
7,
55,
290,
1656,
259,
327,
378,
88,
1046,
199,
7,
2208,
1656,
259,
327,
378,
88,
975,
199,
7,
55,
287,
1656,
259,
327,
378,
88,
1196,
199,
7,
39,
7856,
1656,
259,
327,
378,
88,
1085,
199,
7,
19910,
85,
1656,
259,
327,
378,
88,
1167,
199,
7,
42,
18939,
1656,
259,
327,
378,
88,
17,
65,
199,
7,
42,
316,
1656,
259,
327,
378,
88,
17,
66,
199,
7,
5407,
1656,
259,
327,
378,
88,
17,
67,
199,
7,
40,
7420,
1656,
259,
327,
378,
88,
17,
68,
199,
7,
35,
13780,
1656,
259,
327,
378,
88,
17,
69,
199,
7,
44,
1873,
1656,
259,
327,
378,
88,
17,
70,
199,
7,
2662,
290,
1656,
259,
327,
378,
88,
1165,
199,
7,
52,
316,
1656,
259,
327,
378,
88,
2025,
199,
7,
1352,
73,
1656,
259,
327,
378,
88,
1081,
199,
7,
1049,
324,
1656,
259,
327,
378,
88,
1789,
199,
7,
2662,
287,
1656,
259,
327,
378,
88,
1194,
199,
7,
56,
1873,
1656,
259,
327,
378,
88,
821,
199,
7,
872,
1656,
259,
327,
378,
88,
1479,
199,
7,
58,
1907,
1656,
259,
327,
378,
88,
1465,
199,
7,
35,
85,
1656,
259,
327,
378,
88,
1651,
199,
7,
14828,
85,
1656,
259,
327,
378,
88,
1398,
199,
7,
56,
262,
1656,
259,
327,
378,
88,
18,
65,
199,
7,
52,
13780,
1656,
259,
327,
378,
88,
18,
66,
199,
7,
4232,
79,
1656,
259,
327,
378,
88,
18,
67,
199,
7,
1049,
7420,
1656,
259,
327,
378,
88,
18,
68,
199,
7,
4698,
73,
1656,
259,
327,
378,
88,
18,
69,
199,
7,
19590,
1656,
259,
327,
378,
88,
18,
70,
199,
7,
36,
810,
1656,
259,
327,
378,
88,
1216,
199,
7,
52,
13780,
1656,
259,
327,
378,
88,
2192,
199,
7,
46,
18939,
1656,
259,
327,
378,
88,
708,
199,
7,
1944,
89,
1656,
259,
327,
378,
88,
1153,
199,
7,
10542,
1656,
259,
327,
378,
88,
1082,
199,
7,
11548,
1656,
259,
327,
378,
88,
1276,
199,
7,
39,
1458,
1656,
259,
327,
378,
88,
1344,
199,
7,
13009,
1656,
259,
327,
378,
88,
1401,
199,
7,
44,
5653,
1656,
259,
327,
378,
88,
1703,
199,
7,
12674,
621,
1656,
259,
327,
378,
88,
1355,
199,
7,
35,
1907,
1656,
259,
327,
378,
88,
19,
65,
199,
7,
42,
1873,
1656,
259,
327,
378,
88,
19,
66,
199,
7,
13009,
621,
1656,
259,
327,
378,
88,
19,
67,
199,
7,
58,
11586,
1656,
259,
327,
378,
88,
19,
68,
199,
7,
10542,
1656,
259,
327,
378,
88,
19,
69,
199,
7,
34,
18939,
1656,
259,
327,
378,
88,
19,
70,
199,
7,
44,
324,
1656,
259,
327,
378,
88,
2167,
199,
7,
48,
5653,
1656,
259,
327,
378,
88,
2953,
199,
7,
11548,
79,
1656,
259,
327,
378,
88,
2260,
199,
7,
43,
1907,
1656,
259,
327,
378,
88,
2824,
199,
7,
1049,
1907,
1656,
259,
327,
378,
88,
1602,
199,
7,
29336,
1656,
259,
327,
378,
88,
2322,
199,
7,
52,
5653,
1656,
259,
327,
378,
88,
2466,
199,
7,
4698,
73,
1656,
259,
327,
378,
88,
2417,
199,
7,
42,
316,
1656,
259,
327,
378,
88,
2006,
199,
7,
42,
1873,
1656,
259,
327,
378,
88,
1887,
199,
7,
7833,
1656,
259,
327,
378,
88,
20,
65,
199,
7,
21001,
1656,
259,
327,
378,
88,
20,
66,
199,
7,
2493,
1656,
259,
327,
378,
88,
20,
67,
199,
7,
5349,
1656,
259,
327,
378,
88,
20,
68,
199,
7,
2662,
287,
1656,
259,
327,
378,
88,
20,
69,
199,
7,
1049,
13780,
1656,
259,
327,
378,
88,
20,
70,
199,
7,
19590,
1656,
259,
327,
378,
88,
1400,
199,
7,
19590,
1656,
259,
327,
378,
88,
2869,
199,
7,
24783,
1656,
259,
327,
378,
88,
2528,
199,
7,
3456,
73,
1656,
259,
327,
378,
88,
2481,
199,
7,
19910,
621,
1656,
259,
327,
378,
88,
1477,
199,
7,
55,
290,
1656,
259,
327,
378,
88,
1229,
199,
7,
36,
951,
1656,
259,
327,
378,
88,
1367,
199,
7,
10542,
1656,
259,
327,
378,
88,
1641,
199,
7,
11548,
79,
1656,
259,
327,
378,
88,
2010,
199,
7,
58,
951,
1656,
259,
327,
378,
88,
1427,
199,
7,
36,
316,
1656,
259,
327,
378,
88,
21,
65,
199,
7,
25728,
1656,
259,
327,
378,
88,
21,
66,
199,
7,
1352,
73,
1656,
259,
327,
378,
88,
21,
67,
199,
7,
50,
7856,
1656,
259,
327,
378,
88,
21,
68,
199,
7,
12674,
7856,
1656,
259,
327,
378,
88,
21,
69,
199,
7,
58,
5812,
1656,
259,
327,
378,
88,
21,
70,
199,
7,
35,
810,
1656,
259,
327,
378,
88,
2259,
199,
7,
39,
1458,
1656,
259,
327,
378,
88,
2976,
199,
7,
47,
85,
1656,
259,
327,
378,
88,
2789,
199,
7,
1341,
1656,
259,
327,
378,
88,
2766,
199,
7,
2493,
1656,
259,
327,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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~~
Lexers for Erlang.
:copyright: Copyright 2006-2019 by the Pygments team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
import re
from pygments.lexer import Lexer, RegexLexer, bygroups, words, do_insertions, \
include, default
from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
Number, Punctuation, Generic
__all__ = ['ErlangLexer', 'ErlangShellLexer', 'ElixirConsoleLexer',
'ElixirLexer']
line_re = re.compile('.*?\n')
class ErlangLexer(RegexLexer):
"""
For the Erlang functional programming language.
Blame Jeremy Thurgood (http://jerith.za.net/).
.. versionadded:: 0.9
"""
name = 'Erlang'
aliases = ['erlang']
filenames = ['*.erl', '*.hrl', '*.es', '*.escript']
mimetypes = ['text/x-erlang']
keywords = (
'after', 'begin', 'case', 'catch', 'cond', 'end', 'fun', 'if',
'let', 'of', 'query', 'receive', 'try', 'when',
)
builtins = ( # See erlang(3) man page
'abs', 'append_element', 'apply', 'atom_to_list', 'binary_to_list',
'bitstring_to_list', 'binary_to_term', 'bit_size', 'bump_reductions',
'byte_size', 'cancel_timer', 'check_process_code', 'delete_module',
'demonitor', 'disconnect_node', 'display', 'element', 'erase', 'exit',
'float', 'float_to_list', 'fun_info', 'fun_to_list',
'function_exported', 'garbage_collect', 'get', 'get_keys',
'group_leader', 'hash', 'hd', 'integer_to_list', 'iolist_to_binary',
'iolist_size', 'is_atom', 'is_binary', 'is_bitstring', 'is_boolean',
'is_builtin', 'is_float', 'is_function', 'is_integer', 'is_list',
'is_number', 'is_pid', 'is_port', 'is_process_alive', 'is_record',
'is_reference', 'is_tuple', 'length', 'link', 'list_to_atom',
'list_to_binary', 'list_to_bitstring', 'list_to_existing_atom',
'list_to_float', 'list_to_integer', 'list_to_pid', 'list_to_tuple',
'load_module', 'localtime_to_universaltime', 'make_tuple', 'md5',
'md5_final', 'md5_update', 'memory', 'module_loaded', 'monitor',
'monitor_node', 'node', 'nodes', 'open_port', 'phash', 'phash2',
'pid_to_list', 'port_close', 'port_command', 'port_connect',
'port_control', 'port_call', 'port_info', 'port_to_list',
'process_display', 'process_flag', 'process_info', 'purge_module',
'put', 'read_timer', 'ref_to_list', 'register', 'resume_process',
'round', 'send', 'send_after', 'send_nosuspend', 'set_cookie',
'setelement', 'size', 'spawn', 'spawn_link', 'spawn_monitor',
'spawn_opt', 'split_binary', 'start_timer', 'statistics',
'suspend_process', 'system_flag', 'system_info', 'system_monitor',
'system_profile', 'term_to_binary', 'tl', 'trace', 'trace_delivered',
'trace_info', 'trace_pattern', 'trunc', 'tuple_size', 'tuple_to_list',
'universaltime_to_localtime', 'unlink', 'unregister', 'whereis'
)
operators = r'(\+\+?|--?|\*|/|<|>|/=|=:=|=/=|=<|>=|==?|<-|!|\?)'
word_operators = (
'and', 'andalso', 'band', 'bnot', 'bor', 'bsl', 'bsr', 'bxor',
'div', 'not', 'or', 'orelse', 'rem', 'xor'
)
atom_re = r"(?:[a-z]\w*|'[^\n']*[^\\]')"
variable_re = r'(?:[A-Z_]\w*)'
esc_char_re = r'[bdefnrstv\'"\\]'
esc_octal_re = r'[0-7][0-7]?[0-7]?'
esc_hex_re = r'(?:x[0-9a-fA-F]{2}|x\{[0-9a-fA-F]+\})'
esc_ctrl_re = r'\^[a-zA-Z]'
escape_re = r'(?:\\(?:'+esc_char_re+r'|'+esc_octal_re+r'|'+esc_hex_re+r'|'+esc_ctrl_re+r'))'
macro_re = r'(?:'+variable_re+r'|'+atom_re+r')'
base_re = r'(?:[2-9]|[12][0-9]|3[0-6])'
tokens = {
'root': [
(r'\s+', Text),
(r'%.*\n', Comment),
(words(keywords, suffix=r'\b'), Keyword),
(words(builtins, suffix=r'\b'), Name.Builtin),
(words(word_operators, suffix=r'\b'), Operator.Word),
(r'^-', Punctuation, 'directive'),
(operators, Operator),
(r'"', String, 'string'),
(r'<<', Name.Label),
(r'>>', Name.Label),
('(' + atom_re + ')(:)', bygroups(Name.Namespace, Punctuation)),
('(?:^|(?<=:))(' + atom_re + r')(\s*)(\()',
bygroups(Name.Function, Text, Punctuation)),
(r'[+-]?' + base_re + r'#[0-9a-zA-Z]+', Number.Integer),
(r'[+-]?\d+', Number.Integer),
(r'[+-]?\d+.\d+', Number.Float),
(r'[]\[:_@\".{}()|;,]', Punctuation),
(variable_re, Name.Variable),
(atom_re, Name),
(r'\?'+macro_re, Name.Constant),
(r'\$(?:'+escape_re+r'|\\[ %]|[^\\])', String.Char),
(r'#'+atom_re+r'(:?\.'+atom_re+r')?', Name.Label),
# Erlang script shebang
(r'\A#!.+\n', Comment.Hashbang),
# EEP 43: Maps
# http://www.erlang.org/eeps/eep-0043.html
(r'#\{', Punctuation, 'map_key'),
],
'string': [
(escape_re, String.Escape),
(r'"', String, '#pop'),
(r'~[0-9.*]*[~#+BPWXb-ginpswx]', String.Interpol),
(r'[^"\\~]+', String),
(r'~', String),
],
'directive': [
(r'(define)(\s*)(\()('+macro_re+r')',
bygroups(Name.Entity, Text, Punctuation, Name.Constant), '#pop'),
(r'(record)(\s*)(\()('+macro_re+r')',
bygroups(Name.Entity, Text, Punctuation, Name.Label), '#pop'),
(atom_re, Name.Entity, '#pop'),
],
'map_key': [
include('root'),
(r'=>', Punctuation, 'map_val'),
(r':=', Punctuation, 'map_val'),
(r'\}', Punctuation, '#pop'),
],
'map_val': [
include('root'),
(r',', Punctuation, '#pop'),
(r'(?=\})', Punctuation, '#pop'),
],
}
class ErlangShellLexer(Lexer):
"""
Shell sessions in erl (for Erlang code).
.. versionadded:: 1.1
"""
name = 'Erlang erl session'
aliases = ['erl']
filenames = ['*.erl-sh']
mimetypes = ['text/x-erl-shellsession']
_prompt_re = re.compile(r'(?:\([\w@_.]+\))?\d+>(?=\s|\Z)')
def get_tokens_unprocessed(self, text):
erlexer = ErlangLexer(**self.options)
curcode = ''
insertions = []
for match in line_re.finditer(text):
line = match.group()
m = self._prompt_re.match(line)
if m is not None:
end = m.end()
insertions.append((len(curcode),
[(0, Generic.Prompt, line[:end])]))
curcode += line[end:]
else:
if curcode:
for item in do_insertions(insertions,
erlexer.get_tokens_unprocessed(curcode)):
yield item
curcode = ''
insertions = []
if line.startswith('*'):
yield match.start(), Generic.Traceback, line
else:
yield match.start(), Generic.Output, line
if curcode:
for item in do_insertions(insertions,
erlexer.get_tokens_unprocessed(curcode)):
yield item
def gen_elixir_string_rules(name, symbol, token):
states = {}
states['string_' + name] = [
(r'[^#%s\\]+' % (symbol,), token),
include('escapes'),
(r'\\.', token),
(r'(%s)' % (symbol,), bygroups(token), "#pop"),
include('interpol')
]
return states
def gen_elixir_sigstr_rules(term, token, interpol=True):
if interpol:
return [
(r'[^#%s\\]+' % (term,), token),
include('escapes'),
(r'\\.', token),
(r'%s[a-zA-Z]*' % (term,), token, '#pop'),
include('interpol')
]
else:
return [
(r'[^%s\\]+' % (term,), token),
(r'\\.', token),
(r'%s[a-zA-Z]*' % (term,), token, '#pop'),
]
class ElixirLexer(RegexLexer):
"""
For the `Elixir language <http://elixir-lang.org>`_.
.. versionadded:: 1.5
"""
name = 'Elixir'
aliases = ['elixir', 'ex', 'exs']
filenames = ['*.ex', '*.eex', '*.exs']
mimetypes = ['text/x-elixir']
KEYWORD = ('fn', 'do', 'end', 'after', 'else', 'rescue', 'catch')
KEYWORD_OPERATOR = ('not', 'and', 'or', 'when', 'in')
BUILTIN = (
'case', 'cond', 'for', 'if', 'unless', 'try', 'receive', 'raise',
'quote', 'unquote', 'unquote_splicing', 'throw', 'super',
)
BUILTIN_DECLARATION = (
'def', 'defp', 'defmodule', 'defprotocol', 'defmacro', 'defmacrop',
'defdelegate', 'defexception', 'defstruct', 'defimpl', 'defcallback',
)
BUILTIN_NAMESPACE = ('import', 'require', 'use', 'alias')
CONSTANT = ('nil', 'true', 'false')
PSEUDO_VAR = ('_', '__MODULE__', '__DIR__', '__ENV__', '__CALLER__')
OPERATORS3 = (
'<<<', '>>>', '|||', '&&&', '^^^', '~~~', '===', '!==',
'~>>', '<~>', '|~>', '<|>',
)
OPERATORS2 = (
'==', '!=', '<=', '>=', '&&', '||', '<>', '++', '--', '|>', '=~',
'->', '<-', '|', '.', '=', '~>', '<~',
)
OPERATORS1 = ('<', '>', '+', '-', '*', '/', '!', '^', '&')
PUNCTUATION = (
'\\\\', '<<', '>>', '=>', '(', ')', ':', ';', ',', '[', ']',
)
def get_tokens_unprocessed(self, text):
for index, token, value in RegexLexer.get_tokens_unprocessed(self, text):
if token is Name:
if value in self.KEYWORD:
yield index, Keyword, value
elif value in self.KEYWORD_OPERATOR:
yield index, Operator.Word, value
elif value in self.BUILTIN:
yield index, Keyword, value
elif value in self.BUILTIN_DECLARATION:
yield index, Keyword.Declaration, value
elif value in self.BUILTIN_NAMESPACE:
yield index, Keyword.Namespace, value
elif value in self.CONSTANT:
yield index, Name.Constant, value
elif value in self.PSEUDO_VAR:
yield index, Name.Builtin.Pseudo, value
else:
yield index, token, value
else:
yield index, token, value
def gen_elixir_sigil_rules():
# all valid sigil terminators (excluding heredocs)
terminators = [
(r'\{', r'\}', 'cb'),
(r'\[', r'\]', 'sb'),
(r'\(', r'\)', 'pa'),
(r'<', r'>', 'ab'),
(r'/', r'/', 'slas'),
(r'\|', r'\|', 'pipe'),
('"', '"', 'quot'),
("'", "'", 'apos'),
]
# heredocs have slightly different rules
triquotes = [(r'"""', 'triquot'), (r"'''", 'triapos')]
token = String.Other
states = {'sigils': []}
for term, name in triquotes:
states['sigils'] += [
(r'(~[a-z])(%s)' % (term,), bygroups(token, String.Heredoc),
(name + '-end', name + '-intp')),
(r'(~[A-Z])(%s)' % (term,), bygroups(token, String.Heredoc),
(name + '-end', name + '-no-intp')),
]
states[name + '-end'] = [
(r'[a-zA-Z]+', token, '#pop'),
default('#pop'),
]
states[name + '-intp'] = [
(r'^\s*' + term, String.Heredoc, '#pop'),
include('heredoc_interpol'),
]
states[name + '-no-intp'] = [
(r'^\s*' + term, String.Heredoc, '#pop'),
include('heredoc_no_interpol'),
]
for lterm, rterm, name in terminators:
states['sigils'] += [
(r'~[a-z]' + lterm, token, name + '-intp'),
(r'~[A-Z]' + lterm, token, name + '-no-intp'),
]
states[name + '-intp'] = gen_elixir_sigstr_rules(rterm, token)
states[name + '-no-intp'] = \
gen_elixir_sigstr_rules(rterm, token, interpol=False)
return states
op3_re = "|".join(re.escape(s) for s in OPERATORS3)
op2_re = "|".join(re.escape(s) for s in OPERATORS2)
op1_re = "|".join(re.escape(s) for s in OPERATORS1)
ops_re = r'(?:%s|%s|%s)' % (op3_re, op2_re, op1_re)
punctuation_re = "|".join(re.escape(s) for s in PUNCTUATION)
alnum = r'\w'
name_re = r'(?:\.\.\.|[a-z_]%s*[!?]?)' % alnum
modname_re = r'[A-Z]%(alnum)s*(?:\.[A-Z]%(alnum)s*)*' % {'alnum': alnum}
complex_name_re = r'(?:%s|%s|%s)' % (name_re, modname_re, ops_re)
special_atom_re = r'(?:\.\.\.|<<>>|%\{\}|%|\{\})'
long_hex_char_re = r'(\\x\{)([\da-fA-F]+)(\})'
hex_char_re = r'(\\x[\da-fA-F]{1,2})'
escape_char_re = r'(\\[abdefnrstv])'
tokens = {
'root': [
(r'\s+', Text),
(r'#.*$', Comment.Single),
# Various kinds of characters
(r'(\?)' + long_hex_char_re,
bygroups(String.Char,
String.Escape, Number.Hex, String.Escape)),
(r'(\?)' + hex_char_re,
bygroups(String.Char, String.Escape)),
(r'(\?)' + escape_char_re,
bygroups(String.Char, String.Escape)),
(r'\?\\?.', String.Char),
# '::' has to go before atoms
(r':::', String.Symbol),
(r'::', Operator),
# atoms
(r':' + special_atom_re, String.Symbol),
(r':' + complex_name_re, String.Symbol),
(r':"', String.Symbol, 'string_double_atom'),
(r":'", String.Symbol, 'string_single_atom'),
# [keywords: ...]
(r'(%s|%s)(:)(?=\s|\n)' % (special_atom_re, complex_name_re),
bygroups(String.Symbol, Punctuation)),
# @attributes
(r'@' + name_re, Name.Attribute),
# identifiers
(name_re, Name),
(r'(%%?)(%s)' % (modname_re,), bygroups(Punctuation, Name.Class)),
# operators and punctuation
(op3_re, Operator),
(op2_re, Operator),
(punctuation_re, Punctuation),
(r'&\d', Name.Entity), # anon func arguments
(op1_re, Operator),
# numbers
(r'0b[01]+', Number.Bin),
(r'0o[0-7]+', Number.Oct),
(r'0x[\da-fA-F]+', Number.Hex),
(r'\d(_?\d)*\.\d(_?\d)*([eE][-+]?\d(_?\d)*)?', Number.Float),
(r'\d(_?\d)*', Number.Integer),
# strings and heredocs
(r'"""\s*', String.Heredoc, 'heredoc_double'),
(r"'''\s*$", String.Heredoc, 'heredoc_single'),
(r'"', String.Double, 'string_double'),
(r"'", String.Single, 'string_single'),
include('sigils'),
(r'%\{', Punctuation, 'map_key'),
(r'\{', Punctuation, 'tuple'),
],
'heredoc_double': [
(r'^\s*"""', String.Heredoc, '#pop'),
include('heredoc_interpol'),
],
'heredoc_single': [
(r"^\s*'''", String.Heredoc, '#pop'),
include('heredoc_interpol'),
],
'heredoc_interpol': [
(r'[^#\\\n]+', String.Heredoc),
include('escapes'),
(r'\\.', String.Heredoc),
(r'\n+', String.Heredoc),
include('interpol'),
],
'heredoc_no_interpol': [
(r'[^\\\n]+', String.Heredoc),
(r'\\.', String.Heredoc),
(r'\n+', String.Heredoc),
],
'escapes': [
(long_hex_char_re,
bygroups(String.Escape, Number.Hex, String.Escape)),
(hex_char_re, String.Escape),
(escape_char_re, String.Escape),
],
'interpol': [
(r'#\{', String.Interpol, 'interpol_string'),
],
'interpol_string': [
(r'\}', String.Interpol, "#pop"),
include('root')
],
'map_key': [
include('root'),
(r':', Punctuation, 'map_val'),
(r'=>', Punctuation, 'map_val'),
(r'\}', Punctuation, '#pop'),
],
'map_val': [
include('root'),
(r',', Punctuation, '#pop'),
(r'(?=\})', Punctuation, '#pop'),
],
'tuple': [
include('root'),
(r'\}', Punctuation, '#pop'),
],
}
tokens.update(gen_elixir_string_rules('double', '"', String.Double))
tokens.update(gen_elixir_string_rules('single', "'", String.Single))
tokens.update(gen_elixir_string_rules('double_atom', '"', String.Symbol))
tokens.update(gen_elixir_string_rules('single_atom', "'", String.Symbol))
tokens.update(gen_elixir_sigil_rules())
class ElixirConsoleLexer(Lexer):
"""
For Elixir interactive console (iex) output like:
.. sourcecode:: iex
iex> [head | tail] = [1,2,3]
[1,2,3]
iex> head
1
iex> tail
[2,3]
iex> [head | tail]
[1,2,3]
iex> length [head | tail]
3
.. versionadded:: 1.5
"""
name = 'Elixir iex session'
aliases = ['iex']
mimetypes = ['text/x-elixir-shellsession']
_prompt_re = re.compile(r'(iex|\.{3})((?:\([\w@_.]+\))?\d+|\(\d+\))?> ')
def get_tokens_unprocessed(self, text):
exlexer = ElixirLexer(**self.options)
curcode = ''
in_error = False
insertions = []
for match in line_re.finditer(text):
line = match.group()
if line.startswith(u'** '):
in_error = True
insertions.append((len(curcode),
[(0, Generic.Error, line[:-1])]))
curcode += line[-1:]
else:
m = self._prompt_re.match(line)
if m is not None:
in_error = False
end = m.end()
insertions.append((len(curcode),
[(0, Generic.Prompt, line[:end])]))
curcode += line[end:]
else:
if curcode:
for item in do_insertions(
insertions, exlexer.get_tokens_unprocessed(curcode)):
yield item
curcode = ''
insertions = []
token = Generic.Error if in_error else Generic.Output
yield match.start(), token, line
if curcode:
for item in do_insertions(
insertions, exlexer.get_tokens_unprocessed(curcode)):
yield item
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
13277,
14,
12245,
14,
281,
4159,
272,
18294,
2878,
1714,
339,
491,
476,
1192,
367,
221,
23223,
14,
339,
520,
7307,
26,
1898,
8315,
13,
14982,
701,
314,
14493,
8099,
12,
1937,
10610,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
2436,
14,
199,
624,
199,
199,
646,
295,
199,
199,
504,
13277,
14,
11729,
492,
21125,
12,
12939,
5838,
12,
10259,
12,
5932,
12,
886,
63,
262,
13049,
12,
971,
272,
2387,
12,
849,
199,
504,
13277,
14,
1418,
492,
4516,
12,
6819,
12,
11013,
12,
6431,
12,
2812,
12,
2624,
12,
971,
272,
4860,
12,
10357,
12,
8307,
199,
199,
363,
452,
363,
275,
788,
23223,
5838,
297,
283,
23223,
8529,
5838,
297,
283,
37,
20528,
723,
9270,
5838,
297,
1779,
283,
37,
20528,
723,
5838,
418,
421,
199,
604,
63,
264,
275,
295,
14,
2014,
360,
21040,
78,
358,
421,
199,
533,
221,
23223,
5838,
8,
19856,
304,
272,
408,
272,
2104,
314,
221,
23223,
22380,
31768,
2637,
14,
339,
699,
76,
313,
1603,
69,
264,
1662,
3868,
300,
8302,
334,
1014,
921,
74,
281,
448,
14,
8076,
14,
846,
15,
680,
339,
2508,
7445,
447,
378,
14,
25,
272,
408,
339,
536,
275,
283,
23223,
7,
272,
5481,
275,
788,
281,
4159,
418,
272,
6203,
275,
17855,
281,
76,
297,
11937,
72,
4308,
297,
11937,
397,
297,
11937,
397,
1669,
418,
272,
13290,
275,
788,
505,
15,
88,
13,
281,
4159,
418,
339,
7681,
275,
334,
267,
283,
4399,
297,
283,
5037,
297,
283,
2546,
297,
283,
9341,
297,
283,
2067,
297,
283,
500,
297,
283,
7036,
297,
283,
692,
297,
267,
283,
2723,
297,
283,
1618,
297,
283,
1131,
297,
283,
9391,
297,
283,
893,
297,
283,
6526,
297,
272,
776,
339,
12963,
275,
334,
221,
327,
1666,
9266,
4159,
8,
19,
9,
2169,
2034,
267,
283,
2101,
297,
283,
740,
63,
2108,
297,
283,
4998,
297,
283,
4188,
63,
475,
63,
513,
297,
283,
3008,
63,
475,
63,
513,
297,
267,
283,
2075,
875,
63,
475,
63,
513,
297,
283,
3008,
63,
475,
63,
5125,
297,
283,
2075,
63,
890,
297,
283,
25397,
63,
19493,
2452,
297,
267,
283,
4414,
63,
890,
297,
283,
6406,
63,
7414,
297,
283,
1074,
63,
1412,
63,
600,
297,
283,
1807,
63,
578,
297,
267,
283,
271,
7157,
297,
283,
10673,
63,
932,
297,
283,
2918,
297,
283,
2108,
297,
283,
22087,
297,
283,
2224,
297,
267,
283,
1609,
297,
283,
1609,
63,
475,
63,
513,
297,
283,
7036,
63,
815,
297,
283,
7036,
63,
475,
63,
513,
297,
267,
283,
1593,
63,
23028,
297,
283,
28737,
63,
7112,
297,
283,
362,
297,
283,
362,
63,
1612,
297,
267,
283,
923,
63,
18498,
297,
283,
2227,
297,
283,
7952,
297,
283,
4115,
63,
475,
63,
513,
297,
283,
2308,
513,
63,
475,
63,
3008,
297,
267,
283,
2308,
513,
63,
890,
297,
283,
374,
63,
4188,
297,
283,
374,
63,
3008,
297,
283,
374,
63,
2075,
875,
297,
283,
374,
63,
4871,
297,
267,
283,
374,
63,
5351,
297,
283,
374,
63,
1609,
297,
283,
374,
63,
1593,
297,
283,
374,
63,
4115,
297,
283,
374,
63,
513,
297,
267,
283,
374,
63,
1955,
297,
283,
374,
63,
3150,
297,
283,
374,
63,
719,
297,
283,
374,
63,
1412,
63,
9631,
297,
283,
374,
63,
3059,
297,
267,
283,
374,
63,
4443,
297,
283,
374,
63,
2960,
297,
283,
1267,
297,
283,
1073,
297,
283,
513,
63,
475,
63,
4188,
297,
267,
283,
513,
63,
475,
63,
3008,
297,
283,
513,
63,
475,
63,
2075,
875,
297,
283,
513,
63,
475,
63,
5952,
63,
4188,
297,
267,
283,
513,
63,
475,
63,
1609,
297,
283,
513,
63,
475,
63,
4115,
297,
283,
513,
63,
475,
63,
3150,
297,
283,
513,
63,
475,
63,
2960,
297,
267,
283,
912,
63,
578,
297,
283,
15198,
63,
475,
63,
24866,
521,
297,
283,
1875,
63,
2960,
297,
283,
1064,
21,
297,
267,
283,
1064,
21,
63,
5094,
297,
283,
1064,
21,
63,
873,
297,
283,
4844,
297,
283,
578,
63,
4591,
297,
283,
7157,
297,
267,
283,
7157,
63,
932,
297,
283,
932,
297,
283,
2415,
297,
283,
1490,
63,
719,
297,
283,
838,
1119,
297,
283,
838,
1119,
18,
297,
267,
283,
3150,
63,
475,
63,
513,
297,
283,
719,
63,
1600,
297,
283,
719,
63,
1531,
297,
283,
719,
63,
2242,
297,
267,
283,
719,
63,
2785,
297,
283,
719,
63,
1250,
297,
283,
719,
63,
815,
297,
283,
719,
63,
475,
63,
513,
297,
267,
283,
1412,
63,
2918,
297,
283,
1412,
63,
4173,
297,
283,
1412,
63,
815,
297,
283,
18254,
63,
578,
297,
267,
283,
524,
297,
283,
739,
63,
7414,
297,
283,
1121,
63,
475,
63,
513,
297,
283,
2683,
297,
283,
9964,
63,
1412,
297,
267,
283,
2363,
297,
283,
2254,
297,
283,
2254,
63,
4399,
297,
283,
2254,
63,
12712,
9145,
297,
283,
409,
63,
5306,
297,
267,
283,
30563,
968,
297,
283,
890,
297,
283,
10212,
297,
283,
10212,
63,
1073,
297,
283,
10212,
63,
7157,
297,
267,
283,
10212,
63,
2992,
297,
283,
1294,
63,
3008,
297,
283,
928,
63,
7414,
297,
283,
13724,
297,
267,
283,
14480,
63,
1412,
297,
283,
2253,
63,
4173,
297,
283,
2253,
63,
815,
297,
283,
2253,
63,
7157,
297,
267,
283,
2253,
63,
2913,
297,
283,
5125,
63,
475,
63,
3008,
297,
283,
5019,
297,
283,
3446,
297,
283,
3446,
63,
30480,
297,
267,
283,
3446,
63,
815,
297,
283,
3446,
63,
3401,
297,
283,
8208,
297,
283,
2960,
63,
890,
297,
283,
2960,
63,
475,
63,
513,
297,
267,
283,
24866,
521,
63,
475,
63,
15198,
297,
283,
7162,
297,
283,
18408,
297,
283,
4509,
374,
7,
272,
776,
339,
10211,
275,
519,
13445,
7896,
11,
20910,
306,
31,
6113,
10,
92,
15,
92,
28,
92,
21521,
15,
26777,
29,
26,
26777,
13043,
26777,
18987,
92,
8119,
92,
389,
20910,
28,
13,
92,
1,
6113,
31,
3171,
272,
4349,
63,
12688,
275,
334,
267,
283,
460,
297,
283,
460,
12344,
297,
283,
7877,
297,
283,
66,
1397,
297,
283,
31938,
297,
283,
1533,
76
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
13277,
14,
12245,
14,
281,
4159,
272,
18294,
2878,
1714,
339,
491,
476,
1192,
367,
221,
23223,
14,
339,
520,
7307,
26,
1898,
8315,
13,
14982,
701,
314,
14493,
8099,
12,
1937,
10610,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
2436,
14,
199,
624,
199,
199,
646,
295,
199,
199,
504,
13277,
14,
11729,
492,
21125,
12,
12939,
5838,
12,
10259,
12,
5932,
12,
886,
63,
262,
13049,
12,
971,
272,
2387,
12,
849,
199,
504,
13277,
14,
1418,
492,
4516,
12,
6819,
12,
11013,
12,
6431,
12,
2812,
12,
2624,
12,
971,
272,
4860,
12,
10357,
12,
8307,
199,
199,
363,
452,
363,
275,
788,
23223,
5838,
297,
283,
23223,
8529,
5838,
297,
283,
37,
20528,
723,
9270,
5838,
297,
1779,
283,
37,
20528,
723,
5838,
418,
421,
199,
604,
63,
264,
275,
295,
14,
2014,
360,
21040,
78,
358,
421,
199,
533,
221,
23223,
5838,
8,
19856,
304,
272,
408,
272,
2104,
314,
221,
23223,
22380,
31768,
2637,
14,
339,
699,
76,
313,
1603,
69,
264,
1662,
3868,
300,
8302,
334,
1014,
921,
74,
281,
448,
14,
8076,
14,
846,
15,
680,
339,
2508,
7445,
447,
378,
14,
25,
272,
408,
339,
536,
275,
283,
23223,
7,
272,
5481,
275,
788,
281,
4159,
418,
272,
6203,
275,
17855,
281,
76,
297,
11937,
72,
4308,
297,
11937,
397,
297,
11937,
397,
1669,
418,
272,
13290,
275,
788,
505,
15,
88,
13,
281,
4159,
418,
339,
7681,
275,
334,
267,
283,
4399,
297,
283,
5037,
297,
283,
2546,
297,
283,
9341,
297,
283,
2067,
297,
283,
500,
297,
283,
7036,
297,
283,
692,
297,
267,
283,
2723,
297,
283,
1618,
297,
283,
1131,
297,
283,
9391,
297,
283,
893,
297,
283,
6526,
297,
272,
776,
339,
12963,
275,
334,
221,
327,
1666,
9266,
4159,
8,
19,
9,
2169,
2034,
267,
283,
2101,
297,
283,
740,
63,
2108,
297,
283,
4998,
297,
283,
4188,
63,
475,
63,
513,
297,
283,
3008,
63,
475,
63,
513,
297,
267,
283,
2075,
875,
63,
475,
63,
513,
297,
283,
3008,
63,
475,
63,
5125,
297,
283,
2075,
63,
890,
297,
283,
25397,
63,
19493,
2452,
297,
267,
283,
4414,
63,
890,
297,
283,
6406,
63,
7414,
297,
283,
1074,
63,
1412,
63,
600,
297,
283,
1807,
63,
578,
297,
267,
283,
271,
7157,
297,
283,
10673,
63,
932,
297,
283,
2918,
297,
283,
2108,
297,
283,
22087,
297,
283,
2224,
297,
267,
283,
1609,
297,
283,
1609,
63,
475,
63,
513,
297,
283,
7036,
63,
815,
297,
283,
7036,
63,
475,
63,
513,
297,
267,
283,
1593,
63,
23028,
297,
283,
28737,
63,
7112,
297,
283,
362,
297,
283,
362,
63,
1612,
297,
267,
283,
923,
63,
18498,
297,
283,
2227,
297,
283,
7952,
297,
283,
4115,
63,
475,
63,
513,
297,
283,
2308,
513,
63,
475,
63,
3008,
297,
267,
283,
2308,
513,
63,
890,
297,
283,
374,
63,
4188,
297,
283,
374,
63,
3008,
297,
283,
374,
63,
2075,
875,
297,
283,
374,
63,
4871,
297,
267,
283,
374,
63,
5351,
297,
283,
374,
63,
1609,
297,
283,
374,
63,
1593,
297,
283,
374,
63,
4115,
297,
283,
374,
63,
513,
297,
267,
283,
374,
63,
1955,
297,
283,
374,
63,
3150,
297,
283,
374,
63,
719,
297,
283,
374,
63,
1412,
63,
9631,
297,
283,
374,
63,
3059,
297,
267,
283,
374,
63,
4443,
297,
283,
374,
63,
2960,
297,
283,
1267,
297,
283,
1073,
297,
283,
513,
63,
475,
63,
4188,
297,
267,
283,
513,
63,
475,
63,
3008,
297,
283,
513,
63,
475,
63,
2075,
875,
297,
283,
513,
63,
475,
63,
5952,
63,
4188,
297,
267,
283,
513,
63,
475,
63,
1609,
297,
283,
513,
63,
475,
63,
4115,
297,
283,
513,
63,
475,
63,
3150,
297,
283,
513,
63,
475,
63,
2960,
297,
267,
283,
912,
63,
578,
297,
283,
15198,
63,
475,
63,
24866,
521,
297,
283,
1875,
63,
2960,
297,
283,
1064,
21,
297,
267,
283,
1064,
21,
63,
5094,
297,
283,
1064,
21,
63,
873,
297,
283,
4844,
297,
283,
578,
63,
4591,
297,
283,
7157,
297,
267,
283,
7157,
63,
932,
297,
283,
932,
297,
283,
2415,
297,
283,
1490,
63,
719,
297,
283,
838,
1119,
297,
283,
838,
1119,
18,
297,
267,
283,
3150,
63,
475,
63,
513,
297,
283,
719,
63,
1600,
297,
283,
719,
63,
1531,
297,
283,
719,
63,
2242,
297,
267,
283,
719,
63,
2785,
297,
283,
719,
63,
1250,
297,
283,
719,
63,
815,
297,
283,
719,
63,
475,
63,
513,
297,
267,
283,
1412,
63,
2918,
297,
283,
1412,
63,
4173,
297,
283,
1412,
63,
815,
297,
283,
18254,
63,
578,
297,
267,
283,
524,
297,
283,
739,
63,
7414,
297,
283,
1121,
63,
475,
63,
513,
297,
283,
2683,
297,
283,
9964,
63,
1412,
297,
267,
283,
2363,
297,
283,
2254,
297,
283,
2254,
63,
4399,
297,
283,
2254,
63,
12712,
9145,
297,
283,
409,
63,
5306,
297,
267,
283,
30563,
968,
297,
283,
890,
297,
283,
10212,
297,
283,
10212,
63,
1073,
297,
283,
10212,
63,
7157,
297,
267,
283,
10212,
63,
2992,
297,
283,
1294,
63,
3008,
297,
283,
928,
63,
7414,
297,
283,
13724,
297,
267,
283,
14480,
63,
1412,
297,
283,
2253,
63,
4173,
297,
283,
2253,
63,
815,
297,
283,
2253,
63,
7157,
297,
267,
283,
2253,
63,
2913,
297,
283,
5125,
63,
475,
63,
3008,
297,
283,
5019,
297,
283,
3446,
297,
283,
3446,
63,
30480,
297,
267,
283,
3446,
63,
815,
297,
283,
3446,
63,
3401,
297,
283,
8208,
297,
283,
2960,
63,
890,
297,
283,
2960,
63,
475,
63,
513,
297,
267,
283,
24866,
521,
63,
475,
63,
15198,
297,
283,
7162,
297,
283,
18408,
297,
283,
4509,
374,
7,
272,
776,
339,
10211,
275,
519,
13445,
7896,
11,
20910,
306,
31,
6113,
10,
92,
15,
92,
28,
92,
21521,
15,
26777,
29,
26,
26777,
13043,
26777,
18987,
92,
8119,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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
] |
kobotoolbox/kobocat
|
onadata/apps/logger/xform_instance_parser.py
|
1
|
12334
|
# coding: utf-8
import logging
import re
import sys
import dateutil.parser
import six
from django.utils.encoding import smart_str
from django.utils.translation import ugettext as _
from django.utils.six import text_type
from xml.dom import minidom, Node
from onadata.libs.utils.common_tags import XFORM_ID_STRING
class XLSFormError(Exception):
pass
class DuplicateInstance(Exception):
def __str__(self):
return _("Duplicate Instance")
class InstanceInvalidUserError(Exception):
def __str__(self):
return _("Could not determine the user.")
class InstanceParseError(Exception):
def __str__(self):
return _("The instance could not be parsed.")
class InstanceEmptyError(InstanceParseError):
def __str__(self):
return _("Empty instance")
class InstanceMultipleNodeError(Exception):
pass
def get_meta_from_xml(xml_str, meta_name):
xml = clean_and_parse_xml(xml_str)
children = xml.childNodes
# children ideally contains a single element
# that is the parent of all survey elements
if children.length == 0:
raise ValueError(_("XML string must have a survey element."))
survey_node = children[0]
meta_tags = [n for n in survey_node.childNodes if
n.nodeType == Node.ELEMENT_NODE and
(n.tagName.lower() == "meta" or
n.tagName.lower() == "orx:meta")]
if len(meta_tags) == 0:
return None
# get the requested tag
meta_tag = meta_tags[0]
uuid_tags = [n for n in meta_tag.childNodes if
n.nodeType == Node.ELEMENT_NODE and
(n.tagName.lower() == meta_name.lower() or
n.tagName.lower() == 'orx:%s' % meta_name.lower())]
if len(uuid_tags) == 0:
return None
uuid_tag = uuid_tags[0]
return uuid_tag.firstChild.nodeValue.strip() if uuid_tag.firstChild\
else None
def get_uuid_from_xml(xml):
def _uuid_only(uuid, regex):
matches = regex.match(uuid)
if matches and len(matches.groups()) > 0:
return matches.groups()[0]
return None
uuid = get_meta_from_xml(xml, "instanceID")
regex = re.compile(r"uuid:(.*)")
if uuid:
return _uuid_only(uuid, regex)
# check in survey_node attributes
xml = clean_and_parse_xml(xml)
children = xml.childNodes
# children ideally contains a single element
# that is the parent of all survey elements
if children.length == 0:
raise ValueError(_("XML string must have a survey element."))
survey_node = children[0]
uuid = survey_node.getAttribute('instanceID')
if uuid != '':
return _uuid_only(uuid, regex)
return None
def get_submission_date_from_xml(xml):
# check in survey_node attributes
xml = clean_and_parse_xml(xml)
children = xml.childNodes
# children ideally contains a single element
# that is the parent of all survey elements
if children.length == 0:
raise ValueError(_("XML string must have a survey element."))
survey_node = children[0]
submissionDate = survey_node.getAttribute('submissionDate')
if submissionDate != '':
return dateutil.parser.parse(submissionDate)
return None
def get_deprecated_uuid_from_xml(xml):
uuid = get_meta_from_xml(xml, "deprecatedID")
regex = re.compile(r"uuid:(.*)")
if uuid:
matches = regex.match(uuid)
if matches and len(matches.groups()) > 0:
return matches.groups()[0]
return None
def clean_and_parse_xml(xml_string):
clean_xml_str = xml_string.strip()
clean_xml_str = re.sub(r">\s+<", "><", smart_str(clean_xml_str))
xml_obj = minidom.parseString(clean_xml_str)
return xml_obj
def _xml_node_to_dict(node, repeats=[]):
assert isinstance(node, minidom.Node)
if len(node.childNodes) == 0:
# there's no data for this leaf node
return None
elif len(node.childNodes) == 1 and \
node.childNodes[0].nodeType == node.TEXT_NODE:
# there is data for this leaf node
return {node.nodeName: node.childNodes[0].nodeValue}
else:
# this is an internal node
value = {}
for child in node.childNodes:
# handle CDATA text section
if child.nodeType == child.CDATA_SECTION_NODE:
return {child.parentNode.nodeName: child.nodeValue}
d = _xml_node_to_dict(child, repeats)
if d is None:
continue
child_name = child.nodeName
child_xpath = xpath_from_xml_node(child)
assert list(d) == [child_name]
node_type = dict
# check if name is in list of repeats and make it a list if so
if child_xpath in repeats:
node_type = list
if node_type == dict:
if child_name not in value:
value[child_name] = d[child_name]
else:
# Duplicate Ona solution when repeating group is not present,
# but some nodes are still making references to it.
# Ref: https://github.com/onaio/onadata/commit/7d65fd30348b2f9c6ed6379c7bf79a523cc5750d
node_value = value[child_name]
# 1. check if the node values is a list
if not isinstance(node_value, list):
# if not a list, create one
value[child_name] = [node_value]
# 2. parse the node
d = _xml_node_to_dict(child, repeats)
# 3. aggregate
value[child_name].append(d[child_name])
else:
if child_name not in value:
value[child_name] = [d[child_name]]
else:
value[child_name].append(d[child_name])
if value == {}:
return None
else:
return {node.nodeName: value}
def _flatten_dict(d, prefix):
"""
Return a list of XPath, value pairs.
"""
assert type(d) == dict
assert type(prefix) == list
for key, value in d.items():
new_prefix = prefix + [key]
if type(value) == dict:
for pair in _flatten_dict(value, new_prefix):
yield pair
elif type(value) == list:
for i, item in enumerate(value):
item_prefix = list(new_prefix) # make a copy
# note on indexing xpaths: IE5 and later has
# implemented that [0] should be the first node, but
# according to the W3C standard it should have been
# [1]. I'm adding 1 to i to start at 1.
if i > 0:
# hack: removing [1] index to be consistent across
# surveys that have a single repitition of the
# loop versus mutliple.
item_prefix[-1] += "[%s]" % text_type(i + 1)
if type(item) == dict:
for pair in _flatten_dict(item, item_prefix):
yield pair
else:
yield item_prefix, item
else:
yield new_prefix, value
def _flatten_dict_nest_repeats(d, prefix):
"""
Return a list of XPath, value pairs.
"""
assert type(d) == dict
assert type(prefix) == list
for key, value in d.items():
new_prefix = prefix + [key]
if type(value) == dict:
for pair in _flatten_dict_nest_repeats(value, new_prefix):
yield pair
elif type(value) == list:
repeats = []
for i, item in enumerate(value):
item_prefix = list(new_prefix) # make a copy
if type(item) == dict:
repeat = {}
for path, value in \
_flatten_dict_nest_repeats(item, item_prefix):
# TODO: this only considers the first level of repeats
repeat.update({"/".join(path[1:]): value})
repeats.append(repeat)
else:
repeats.append({"/".join(item_prefix[1:]): item})
yield (new_prefix, repeats)
else:
yield (new_prefix, value)
def _gather_parent_node_list(node):
node_names = []
# also check for grand-parent node to skip document element
if node.parentNode and node.parentNode.parentNode:
node_names.extend(_gather_parent_node_list(node.parentNode))
node_names.extend([node.nodeName])
return node_names
def xpath_from_xml_node(node):
node_names = _gather_parent_node_list(node)
return "/".join(node_names[1:])
def _get_all_attributes(node):
"""
Go through an XML document returning all the attributes we see.
"""
if hasattr(node, "hasAttributes") and node.hasAttributes():
for key in node.attributes.keys():
yield key, node.getAttribute(key)
for child in node.childNodes:
for pair in _get_all_attributes(child):
yield pair
class XFormInstanceParser:
def __init__(self, xml_str, data_dictionary):
self.dd = data_dictionary
# The two following variables need to be initialized in the constructor, in case parsing fails.
self._flat_dict = {}
self._attributes = {}
try:
self.parse(xml_str)
except Exception as e:
logger = logging.getLogger("console_logger")
logger.error(
"Failed to parse instance '%s'" % xml_str, exc_info=True)
# `self.parse()` has been wrapped in to try/except but it makes the
# exception silently ignored.
# `logger_tool.py::safe_create_instance()` needs the exception
# to return the correct HTTP code
six.reraise(*sys.exc_info())
def parse(self, xml_str):
self._xml_obj = clean_and_parse_xml(xml_str)
self._root_node = self._xml_obj.documentElement
repeats = [e.get_abbreviated_xpath()
for e in self.dd.get_survey_elements_of_type("repeat")]
self._dict = _xml_node_to_dict(self._root_node, repeats)
if self._dict is None:
raise InstanceEmptyError
for path, value in _flatten_dict_nest_repeats(self._dict, []):
self._flat_dict["/".join(path[1:])] = value
self._set_attributes()
def get_root_node(self):
return self._root_node
def get_root_node_name(self):
return self._root_node.nodeName
def get(self, abbreviated_xpath):
return self.to_flat_dict()[abbreviated_xpath]
def to_dict(self):
return self._dict
def to_flat_dict(self):
return self._flat_dict
def get_attributes(self):
return self._attributes
def _set_attributes(self):
all_attributes = list(_get_all_attributes(self._root_node))
for key, value in all_attributes:
# commented since enketo forms may have the template attribute in
# multiple xml tags and I dont see the harm in overiding
# attributes at this point
try:
assert key not in self._attributes
except AssertionError:
logger = logging.getLogger("console_logger")
logger.debug("Skipping duplicate attribute: %s"
" with value %s" % (key, value))
logger.debug(str(all_attributes))
else:
self._attributes[key] = value
def get_xform_id_string(self):
return self._attributes.get("id")
def get_flat_dict_with_attributes(self):
result = self.to_flat_dict().copy()
result[XFORM_ID_STRING] = self.get_xform_id_string()
return result
def xform_instance_to_dict(xml_str, data_dictionary):
parser = XFormInstanceParser(xml_str, data_dictionary)
return parser.to_dict()
def xform_instance_to_flat_dict(xml_str, data_dictionary):
parser = XFormInstanceParser(xml_str, data_dictionary)
return parser.to_flat_dict()
def parse_xform_instance(xml_str, data_dictionary):
parser = XFormInstanceParser(xml_str, data_dictionary)
return parser.get_flat_dict_with_attributes()
|
bsd-2-clause
|
[
3,
2803,
26,
2774,
13,
24,
199,
646,
2050,
199,
646,
295,
199,
646,
984,
199,
199,
646,
22208,
14,
2087,
199,
646,
3816,
199,
504,
1639,
14,
1208,
14,
2991,
492,
11179,
63,
495,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
465,
485,
199,
504,
1639,
14,
1208,
14,
4174,
492,
1318,
63,
466,
199,
504,
2748,
14,
4556,
492,
19165,
12,
5013,
199,
199,
504,
641,
1517,
14,
8450,
14,
1208,
14,
2330,
63,
2969,
492,
1323,
3516,
63,
998,
63,
5353,
421,
199,
533,
1323,
5296,
2821,
547,
8,
1726,
304,
272,
986,
421,
199,
533,
23942,
3244,
8,
1726,
304,
272,
347,
636,
495,
721,
277,
304,
267,
372,
3824,
14773,
10066,
531,
421,
199,
533,
10066,
3364,
1899,
547,
8,
1726,
304,
272,
347,
636,
495,
721,
277,
304,
267,
372,
3824,
6531,
440,
6705,
314,
922,
2685,
421,
199,
533,
10066,
9123,
8,
1726,
304,
272,
347,
636,
495,
721,
277,
304,
267,
372,
3824,
1918,
1256,
4293,
440,
506,
4565,
2685,
421,
199,
533,
10066,
4699,
547,
8,
3244,
9123,
304,
272,
347,
636,
495,
721,
277,
304,
267,
372,
3824,
4699,
1256,
531,
421,
199,
533,
10066,
8433,
1716,
547,
8,
1726,
304,
272,
986,
421,
199,
318,
664,
63,
2024,
63,
504,
63,
1652,
8,
1652,
63,
495,
12,
3404,
63,
354,
304,
272,
2748,
275,
3633,
63,
460,
63,
1122,
63,
1652,
8,
1652,
63,
495,
9,
272,
4978,
275,
2748,
14,
10626,
272,
327,
4978,
9979,
1183,
3509,
282,
2849,
1819,
272,
327,
626,
365,
314,
1676,
402,
1006,
16576,
4008,
272,
340,
4978,
14,
1267,
508,
378,
26,
267,
746,
1722,
6115,
4317,
1059,
1471,
1172,
282,
16576,
1819,
13853,
272,
16576,
63,
932,
275,
4978,
59,
16,
61,
272,
3404,
63,
2969,
275,
359,
78,
367,
302,
315,
16576,
63,
932,
14,
10626,
340,
326,
302,
14,
12412,
508,
5013,
14,
12535,
63,
8063,
436,
326,
334,
78,
14,
20183,
14,
2325,
342,
508,
298,
2024,
2,
503,
2151,
302,
14,
20183,
14,
2325,
342,
508,
298,
269,
88,
26,
2024,
11323,
272,
340,
822,
8,
2024,
63,
2969,
9,
508,
378,
26,
267,
372,
488,
339,
327,
664,
314,
5839,
1947,
272,
3404,
63,
1450,
275,
3404,
63,
2969,
59,
16,
61,
272,
5377,
63,
2969,
275,
359,
78,
367,
302,
315,
3404,
63,
1450,
14,
10626,
340,
326,
302,
14,
12412,
508,
5013,
14,
12535,
63,
8063,
436,
326,
334,
78,
14,
20183,
14,
2325,
342,
508,
3404,
63,
354,
14,
2325,
342,
503,
2116,
302,
14,
20183,
14,
2325,
342,
508,
283,
269,
88,
2689,
83,
7,
450,
3404,
63,
354,
14,
2325,
24821,
272,
340,
822,
8,
2580,
63,
2969,
9,
508,
378,
26,
267,
372,
488,
339,
5377,
63,
1450,
275,
5377,
63,
2969,
59,
16,
61,
272,
372,
5377,
63,
1450,
14,
22262,
14,
17240,
14,
1913,
342,
340,
5377,
63,
1450,
14,
22262,
60,
267,
587,
488,
421,
199,
318,
664,
63,
2580,
63,
504,
63,
1652,
8,
1652,
304,
272,
347,
485,
2580,
63,
2118,
8,
2580,
12,
5163,
304,
267,
4450,
275,
5163,
14,
1431,
8,
2580,
9,
267,
340,
4450,
436,
822,
8,
6742,
14,
2634,
1012,
690,
378,
26,
288,
372,
4450,
14,
2634,
3430,
16,
61,
267,
372,
488,
272,
5377,
275,
664,
63,
2024,
63,
504,
63,
1652,
8,
1652,
12,
298,
842,
998,
531,
272,
5163,
275,
295,
14,
2014,
8,
82,
2,
2580,
26,
19276,
6320,
272,
340,
5377,
26,
267,
372,
485,
2580,
63,
2118,
8,
2580,
12,
5163,
9,
272,
327,
1104,
315,
16576,
63,
932,
3004,
272,
2748,
275,
3633,
63,
460,
63,
1122,
63,
1652,
8,
1652,
9,
272,
4978,
275,
2748,
14,
10626,
272,
327,
4978,
9979,
1183,
3509,
282,
2849,
1819,
272,
327,
626,
365,
314,
1676,
402,
1006,
16576,
4008,
272,
340,
4978,
14,
1267,
508,
378,
26,
267,
746,
1722,
6115,
4317,
1059,
1471,
1172,
282,
16576,
1819,
13853,
272,
16576,
63,
932,
275,
4978,
59,
16,
61,
272,
5377,
275,
16576,
63,
932,
14,
12956,
360,
842,
998,
358,
272,
340,
5377,
1137,
8061,
267,
372,
485,
2580,
63,
2118,
8,
2580,
12,
5163,
9,
272,
372,
488,
421,
199,
318,
664,
63,
12542,
63,
602,
63,
504,
63,
1652,
8,
1652,
304,
272,
327,
1104,
315,
16576,
63,
932,
3004,
272,
2748,
275,
3633,
63,
460,
63,
1122,
63,
1652,
8,
1652,
9,
272,
4978,
275,
2748,
14,
10626,
272,
327,
4978,
9979,
1183,
3509,
282,
2849,
1819,
272,
327,
626,
365,
314,
1676,
402,
1006,
16576,
4008,
272,
340,
4978,
14,
1267,
508,
378,
26,
267,
746,
1722,
6115,
4317,
1059,
1471,
1172,
282,
16576,
1819,
13853,
272,
16576,
63,
932,
275,
4978,
59,
16,
61,
272,
13071,
2506,
275,
16576,
63,
932,
14,
12956,
360,
12542,
2506,
358,
272,
340,
13071,
2506,
1137,
8061,
267,
372,
22208,
14,
2087,
14,
1122,
8,
12542,
2506,
9,
272,
372,
488,
421,
199,
318,
664,
63,
6667,
63,
2580,
63,
504,
63,
1652,
8,
1652,
304,
272,
5377,
275,
664,
63,
2024,
63,
504,
63,
1652,
8,
1652,
12,
298,
6667,
998,
531,
272,
5163,
275,
295,
14,
2014,
8,
82,
2,
2580,
26,
19276,
6320,
272,
340,
5377,
26,
267,
4450,
275,
5163,
14,
1431,
8,
2580,
9,
267,
340,
4450,
436,
822,
8,
6742,
14,
2634,
1012,
690,
378,
26,
288,
372,
4450,
14,
2634,
3430,
16,
61,
272,
372,
488,
421,
199,
318,
3633,
63,
460,
63,
1122,
63,
1652,
8,
1652,
63,
875,
304,
272,
3633,
63,
1652,
63,
495,
275,
2748,
63,
875,
14,
1913,
342,
272,
3633,
63,
1652,
63,
495,
275,
295,
14,
954,
8,
82,
14559,
83,
11,
28,
401,
298,
2535,
401,
11179,
63,
495,
8,
3118,
63,
1652,
63,
495,
430,
272,
2748,
63,
1113,
275,
19165,
14,
14934,
8,
3118,
63,
1652,
63,
495,
9,
272,
372,
2748,
63,
1113,
421,
199,
318,
485,
1652,
63,
932,
63,
475,
63,
807,
8,
932,
12,
28908,
17894,
272,
702,
1228,
8,
932,
12,
19165,
14,
1716,
9,
272,
340,
822,
8,
932,
14,
10626,
9,
508,
378,
26,
267,
327,
2337,
1159,
949,
666,
367
] |
[
2803,
26,
2774,
13,
24,
199,
646,
2050,
199,
646,
295,
199,
646,
984,
199,
199,
646,
22208,
14,
2087,
199,
646,
3816,
199,
504,
1639,
14,
1208,
14,
2991,
492,
11179,
63,
495,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
465,
485,
199,
504,
1639,
14,
1208,
14,
4174,
492,
1318,
63,
466,
199,
504,
2748,
14,
4556,
492,
19165,
12,
5013,
199,
199,
504,
641,
1517,
14,
8450,
14,
1208,
14,
2330,
63,
2969,
492,
1323,
3516,
63,
998,
63,
5353,
421,
199,
533,
1323,
5296,
2821,
547,
8,
1726,
304,
272,
986,
421,
199,
533,
23942,
3244,
8,
1726,
304,
272,
347,
636,
495,
721,
277,
304,
267,
372,
3824,
14773,
10066,
531,
421,
199,
533,
10066,
3364,
1899,
547,
8,
1726,
304,
272,
347,
636,
495,
721,
277,
304,
267,
372,
3824,
6531,
440,
6705,
314,
922,
2685,
421,
199,
533,
10066,
9123,
8,
1726,
304,
272,
347,
636,
495,
721,
277,
304,
267,
372,
3824,
1918,
1256,
4293,
440,
506,
4565,
2685,
421,
199,
533,
10066,
4699,
547,
8,
3244,
9123,
304,
272,
347,
636,
495,
721,
277,
304,
267,
372,
3824,
4699,
1256,
531,
421,
199,
533,
10066,
8433,
1716,
547,
8,
1726,
304,
272,
986,
421,
199,
318,
664,
63,
2024,
63,
504,
63,
1652,
8,
1652,
63,
495,
12,
3404,
63,
354,
304,
272,
2748,
275,
3633,
63,
460,
63,
1122,
63,
1652,
8,
1652,
63,
495,
9,
272,
4978,
275,
2748,
14,
10626,
272,
327,
4978,
9979,
1183,
3509,
282,
2849,
1819,
272,
327,
626,
365,
314,
1676,
402,
1006,
16576,
4008,
272,
340,
4978,
14,
1267,
508,
378,
26,
267,
746,
1722,
6115,
4317,
1059,
1471,
1172,
282,
16576,
1819,
13853,
272,
16576,
63,
932,
275,
4978,
59,
16,
61,
272,
3404,
63,
2969,
275,
359,
78,
367,
302,
315,
16576,
63,
932,
14,
10626,
340,
326,
302,
14,
12412,
508,
5013,
14,
12535,
63,
8063,
436,
326,
334,
78,
14,
20183,
14,
2325,
342,
508,
298,
2024,
2,
503,
2151,
302,
14,
20183,
14,
2325,
342,
508,
298,
269,
88,
26,
2024,
11323,
272,
340,
822,
8,
2024,
63,
2969,
9,
508,
378,
26,
267,
372,
488,
339,
327,
664,
314,
5839,
1947,
272,
3404,
63,
1450,
275,
3404,
63,
2969,
59,
16,
61,
272,
5377,
63,
2969,
275,
359,
78,
367,
302,
315,
3404,
63,
1450,
14,
10626,
340,
326,
302,
14,
12412,
508,
5013,
14,
12535,
63,
8063,
436,
326,
334,
78,
14,
20183,
14,
2325,
342,
508,
3404,
63,
354,
14,
2325,
342,
503,
2116,
302,
14,
20183,
14,
2325,
342,
508,
283,
269,
88,
2689,
83,
7,
450,
3404,
63,
354,
14,
2325,
24821,
272,
340,
822,
8,
2580,
63,
2969,
9,
508,
378,
26,
267,
372,
488,
339,
5377,
63,
1450,
275,
5377,
63,
2969,
59,
16,
61,
272,
372,
5377,
63,
1450,
14,
22262,
14,
17240,
14,
1913,
342,
340,
5377,
63,
1450,
14,
22262,
60,
267,
587,
488,
421,
199,
318,
664,
63,
2580,
63,
504,
63,
1652,
8,
1652,
304,
272,
347,
485,
2580,
63,
2118,
8,
2580,
12,
5163,
304,
267,
4450,
275,
5163,
14,
1431,
8,
2580,
9,
267,
340,
4450,
436,
822,
8,
6742,
14,
2634,
1012,
690,
378,
26,
288,
372,
4450,
14,
2634,
3430,
16,
61,
267,
372,
488,
272,
5377,
275,
664,
63,
2024,
63,
504,
63,
1652,
8,
1652,
12,
298,
842,
998,
531,
272,
5163,
275,
295,
14,
2014,
8,
82,
2,
2580,
26,
19276,
6320,
272,
340,
5377,
26,
267,
372,
485,
2580,
63,
2118,
8,
2580,
12,
5163,
9,
272,
327,
1104,
315,
16576,
63,
932,
3004,
272,
2748,
275,
3633,
63,
460,
63,
1122,
63,
1652,
8,
1652,
9,
272,
4978,
275,
2748,
14,
10626,
272,
327,
4978,
9979,
1183,
3509,
282,
2849,
1819,
272,
327,
626,
365,
314,
1676,
402,
1006,
16576,
4008,
272,
340,
4978,
14,
1267,
508,
378,
26,
267,
746,
1722,
6115,
4317,
1059,
1471,
1172,
282,
16576,
1819,
13853,
272,
16576,
63,
932,
275,
4978,
59,
16,
61,
272,
5377,
275,
16576,
63,
932,
14,
12956,
360,
842,
998,
358,
272,
340,
5377,
1137,
8061,
267,
372,
485,
2580,
63,
2118,
8,
2580,
12,
5163,
9,
272,
372,
488,
421,
199,
318,
664,
63,
12542,
63,
602,
63,
504,
63,
1652,
8,
1652,
304,
272,
327,
1104,
315,
16576,
63,
932,
3004,
272,
2748,
275,
3633,
63,
460,
63,
1122,
63,
1652,
8,
1652,
9,
272,
4978,
275,
2748,
14,
10626,
272,
327,
4978,
9979,
1183,
3509,
282,
2849,
1819,
272,
327,
626,
365,
314,
1676,
402,
1006,
16576,
4008,
272,
340,
4978,
14,
1267,
508,
378,
26,
267,
746,
1722,
6115,
4317,
1059,
1471,
1172,
282,
16576,
1819,
13853,
272,
16576,
63,
932,
275,
4978,
59,
16,
61,
272,
13071,
2506,
275,
16576,
63,
932,
14,
12956,
360,
12542,
2506,
358,
272,
340,
13071,
2506,
1137,
8061,
267,
372,
22208,
14,
2087,
14,
1122,
8,
12542,
2506,
9,
272,
372,
488,
421,
199,
318,
664,
63,
6667,
63,
2580,
63,
504,
63,
1652,
8,
1652,
304,
272,
5377,
275,
664,
63,
2024,
63,
504,
63,
1652,
8,
1652,
12,
298,
6667,
998,
531,
272,
5163,
275,
295,
14,
2014,
8,
82,
2,
2580,
26,
19276,
6320,
272,
340,
5377,
26,
267,
4450,
275,
5163,
14,
1431,
8,
2580,
9,
267,
340,
4450,
436,
822,
8,
6742,
14,
2634,
1012,
690,
378,
26,
288,
372,
4450,
14,
2634,
3430,
16,
61,
272,
372,
488,
421,
199,
318,
3633,
63,
460,
63,
1122,
63,
1652,
8,
1652,
63,
875,
304,
272,
3633,
63,
1652,
63,
495,
275,
2748,
63,
875,
14,
1913,
342,
272,
3633,
63,
1652,
63,
495,
275,
295,
14,
954,
8,
82,
14559,
83,
11,
28,
401,
298,
2535,
401,
11179,
63,
495,
8,
3118,
63,
1652,
63,
495,
430,
272,
2748,
63,
1113,
275,
19165,
14,
14934,
8,
3118,
63,
1652,
63,
495,
9,
272,
372,
2748,
63,
1113,
421,
199,
318,
485,
1652,
63,
932,
63,
475,
63,
807,
8,
932,
12,
28908,
17894,
272,
702,
1228,
8,
932,
12,
19165,
14,
1716,
9,
272,
340,
822,
8,
932,
14,
10626,
9,
508,
378,
26,
267,
327,
2337,
1159,
949,
666,
367,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
burakbayramli/classnotes
|
stat/stat_065_powerlaw/powerlaw.py
|
2
|
106244
|
#The MIT License (MIT)
#
#Copyright (c) 2013 Jeff Alstott
#
#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.
# as described in https://docs.python.org/2/library/functions.html#print
from __future__ import print_function
import sys
__version__ = "1.3.4"
class Fit(object):
"""
A fit of a data set to various probability distributions, namely power
laws. For fits to power laws, the methods of Clauset et al. 2007 are used.
These methods identify the portion of the tail of the distribution that
follows a power law, beyond a value xmin. If no xmin is
provided, the optimal one is calculated and assigned at initialization.
Parameters
----------
data : list or array
discrete : boolean, optional
Whether the data is discrete (integers).
xmin : int or float, optional
The data value beyond which distributions should be fitted. If
None an optimal one will be calculated.
xmax : int or float, optional
The maximum value of the fitted distributions.
estimate_discrete : bool, optional
Whether to estimate the fit of a discrete power law using fast
analytical methods, instead of calculating the fit exactly with
slow numerical methods. Very accurate with xmin>6
sigma_threshold : float, optional
Upper limit on the standard error of the power law fit. Used after
fitting, when identifying valid xmin values.
parameter_range : dict, optional
Dictionary of valid parameter ranges for fitting. Formatted as a
dictionary of parameter names ('alpha' and/or 'sigma') and tuples
of their lower and upper limits (ex. (1.5, 2.5), (None, .1)
"""
def __init__(self, data,
discrete=False,
xmin=None, xmax=None,
fit_method='Likelihood',
estimate_discrete=True,
discrete_approximation='round',
sigma_threshold=None,
parameter_range=None,
fit_optimizer=None,
xmin_distance='D',
**kwargs):
self.data_original = data
# import logging
from numpy import asarray
self.data = asarray(self.data_original, dtype='float')
self.discrete = discrete
self.fit_method = fit_method
self.estimate_discrete = estimate_discrete
self.discrete_approximation = discrete_approximation
self.sigma_threshold = sigma_threshold
self.parameter_range = parameter_range
self.given_xmin = xmin
self.given_xmax = xmax
self.xmin = self.given_xmin
self.xmax = self.given_xmax
self.xmin_distance = xmin_distance
if 0 in self.data:
print("Values less than or equal to 0 in data. Throwing out 0 or negative values", file=sys.stderr)
self.data = self.data[self.data>0]
if self.xmax:
self.xmax = float(self.xmax)
self.fixed_xmax = True
n_above_max = sum(self.data>self.xmax)
self.data = self.data[self.data<=self.xmax]
else:
n_above_max = 0
self.fixed_xmax = False
if not all(self.data[i] <= self.data[i+1] for i in range(len(self.data)-1)):
from numpy import sort
self.data = sort(self.data)
self.fitting_cdf_bins, self.fitting_cdf = cdf(self.data, xmin=None, xmax=self.xmax)
if xmin and type(xmin)!=tuple and type(xmin)!=list:
self.fixed_xmin = True
self.xmin = float(xmin)
self.noise_flag = None
pl = Power_Law(xmin=self.xmin,
xmax=self.xmax,
discrete=self.discrete,
fit_method=self.fit_method,
estimate_discrete=self.estimate_discrete,
data=self.data,
parameter_range=self.parameter_range)
setattr(self,self.xmin_distance, getattr(pl, self.xmin_distance))
self.alpha = pl.alpha
self.sigma = pl.sigma
#self.power_law = pl
else:
self.fixed_xmin=False
print("Calculating best minimal value for power law fit", file=sys.stderr)
self.find_xmin()
self.data = self.data[self.data>=self.xmin]
self.n = float(len(self.data))
self.n_tail = self.n + n_above_max
self.supported_distributions = {'power_law': Power_Law,
'lognormal': Lognormal,
'exponential': Exponential,
'truncated_power_law': Truncated_Power_Law,
'stretched_exponential': Stretched_Exponential,
}
#'gamma': None}
def __getattr__(self, name):
if name in self.supported_distributions.keys():
#from string import capwords
#dist = capwords(name, '_')
#dist = globals()[dist] #Seems a hack. Might try import powerlaw; getattr(powerlaw, dist)
dist = self.supported_distributions[name]
if dist == Power_Law:
parameter_range = self.parameter_range
else:
parameter_range = None
setattr(self,
name,
dist(data=self.data,
xmin=self.xmin,
xmax=self.xmax,
discrete=self.discrete,
fit_method=self.fit_method,
estimate_discrete=self.estimate_discrete,
discrete_approximation=self.discrete_approximation,
parameter_range=parameter_range,
parent_Fit=self))
return getattr(self, name)
else:
raise AttributeError(name)
def find_xmin(self, xmin_distance=None):
"""
Returns the optimal xmin beyond which the scaling regime of the power
law fits best. The attribute self.xmin of the Fit object is also set.
The optimal xmin beyond which the scaling regime of the power law fits
best is identified by minimizing the Kolmogorov-Smirnov distance
between the data and the theoretical power law fit.
This is the method of Clauset et al. 2007.
"""
from numpy import unique, asarray, argmin
#Much of the rest of this function was inspired by Adam Ginsburg's plfit code,
#specifically the mapping and sigma threshold behavior:
#http://code.google.com/p/agpy/source/browse/trunk/plfit/plfit.py?spec=svn359&r=357
if not self.given_xmin:
possible_xmins = self.data
else:
possible_ind = min(self.given_xmin)<=self.data
possible_ind *= self.data<=max(self.given_xmin)
possible_xmins = self.data[possible_ind]
xmins, xmin_indices = unique(possible_xmins, return_index=True)
#Don't look at last xmin, as that's also the xmax, and we want to at least have TWO points to fit!
xmins = xmins[:-1]
xmin_indices = xmin_indices[:-1]
if xmin_distance is None:
xmin_distance = self.xmin_distance
if len(xmins)<=0:
print("Less than 2 unique data values left after xmin and xmax "
"options! Cannot fit. Returning nans.", file=sys.stderr)
from numpy import nan, array
self.xmin = nan
self.D = nan
self.V = nan
self.Asquare = nan
self.Kappa = nan
self.alpha = nan
self.sigma = nan
self.n_tail = nan
setattr(self, xmin_distance+'s', array([nan]))
self.alphas = array([nan])
self.sigmas = array([nan])
self.in_ranges = array([nan])
self.xmins = array([nan])
self.noise_flag = True
return self.xmin
def fit_function(xmin):
pl = Power_Law(xmin=xmin,
xmax=self.xmax,
discrete=self.discrete,
estimate_discrete=self.estimate_discrete,
fit_method=self.fit_method,
data=self.data,
parameter_range=self.parameter_range,
parent_Fit=self)
return getattr(pl, xmin_distance), pl.alpha, pl.sigma, pl.in_range()
fits = asarray(list(map(fit_function, xmins)))
# logging.warning(fits.shape)
setattr(self, xmin_distance+'s', fits[:,0])
self.alphas = fits[:,1]
self.sigmas = fits[:,2]
self.in_ranges = fits[:,3].astype(bool)
self.xmins = xmins
good_values = self.in_ranges
if self.sigma_threshold:
good_values = good_values * (self.sigmas < self.sigma_threshold)
if good_values.all():
min_D_index = argmin(getattr(self, xmin_distance+'s'))
self.noise_flag = False
elif not good_values.any():
min_D_index = argmin(getattr(self, xmin_distance+'s'))
self.noise_flag = True
else:
from numpy.ma import masked_array
masked_Ds = masked_array(getattr(self, xmin_distance+'s'), mask=-good_values)
min_D_index = masked_Ds.argmin()
self.noise_flag = False
if self.noise_flag:
print("No valid fits found.", file=sys.stderr)
#Set the Fit's xmin to the optimal xmin
self.xmin = xmins[min_D_index]
setattr(self, xmin_distance, getattr(self, xmin_distance+'s')[min_D_index])
self.alpha = self.alphas[min_D_index]
self.sigma = self.sigmas[min_D_index]
#Update the fitting CDF given the new xmin, in case other objects, like
#Distributions, want to use it for fitting (like if they do KS fitting)
self.fitting_cdf_bins, self.fitting_cdf = self.cdf()
return self.xmin
def nested_distribution_compare(self, dist1, dist2, nested=True, **kwargs):
"""
Returns the loglikelihood ratio, and its p-value, between the two
distribution fits, assuming the candidate distributions are nested.
Parameters
----------
dist1 : string
Name of the first candidate distribution (ex. 'power_law')
dist2 : string
Name of the second candidate distribution (ex. 'exponential')
nested : bool or None, optional
Whether to assume the candidate distributions are nested versions
of each other. None assumes not unless the name of one distribution
is a substring of the other. True by default.
Returns
-------
R : float
Loglikelihood ratio of the two distributions' fit to the data. If
greater than 0, the first distribution is preferred. If less than
0, the second distribution is preferred.
p : float
Significance of R
"""
return self.distribution_compare(dist1, dist2, nested=nested, **kwargs)
def distribution_compare(self, dist1, dist2, nested=None, **kwargs):
"""
Returns the loglikelihood ratio, and its p-value, between the two
distribution fits, assuming the candidate distributions are nested.
Parameters
----------
dist1 : string
Name of the first candidate distribution (ex. 'power_law')
dist2 : string
Name of the second candidate distribution (ex. 'exponential')
nested : bool or None, optional
Whether to assume the candidate distributions are nested versions
of each other. None assumes not unless the name of one distribution
is a substring of the other.
Returns
-------
R : float
Loglikelihood ratio of the two distributions' fit to the data. If
greater than 0, the first distribution is preferred. If less than
0, the second distribution is preferred.
p : float
Significance of R
"""
if (dist1 in dist2) or (dist2 in dist1) and nested is None:
print("Assuming nested distributions", file=sys.stderr)
nested = True
dist1 = getattr(self, dist1)
dist2 = getattr(self, dist2)
loglikelihoods1 = dist1.loglikelihoods(self.data)
loglikelihoods2 = dist2.loglikelihoods(self.data)
return loglikelihood_ratio(
loglikelihoods1, loglikelihoods2,
nested=nested,
**kwargs)
def loglikelihood_ratio(self, dist1, dist2, nested=None, **kwargs):
"""
Another name for distribution_compare.
"""
return self.distribution_compare(dist1, dist2, nested=nested, **kwargs)
def cdf(self, original_data=False, survival=False, **kwargs):
"""
Returns the cumulative distribution function of the data.
Parameters
----------
original_data : bool, optional
Whether to use all of the data initially passed to the Fit object.
If False, uses only the data used for the fit (within xmin and
xmax.)
survival : bool, optional
Whether to return the complementary cumulative distribution
function, 1-CDF, also known as the survival function.
Returns
-------
X : array
The sorted, unique values in the data.
probabilities : array
The portion of the data that is less than or equal to X.
"""
if original_data:
data = self.data_original
xmin = None
xmax = None
else:
data = self.data
xmin = self.xmin
xmax = self.xmax
return cdf(data, xmin=xmin, xmax=xmax, survival=survival,
**kwargs)
def ccdf(self, original_data=False, survival=True, **kwargs):
"""
Returns the complementary cumulative distribution function of the data.
Parameters
----------
original_data : bool, optional
Whether to use all of the data initially passed to the Fit object.
If False, uses only the data used for the fit (within xmin and
xmax.)
survival : bool, optional
Whether to return the complementary cumulative distribution
function, also known as the survival function, or the cumulative
distribution function, 1-CCDF.
Returns
-------
X : array
The sorted, unique values in the data.
probabilities : array
The portion of the data that is greater than or equal to X.
"""
if original_data:
data = self.data_original
xmin = None
xmax = None
else:
data = self.data
xmin = self.xmin
xmax = self.xmax
return cdf(data, xmin=xmin, xmax=xmax, survival=survival,
**kwargs)
def pdf(self, original_data=False, **kwargs):
"""
Returns the probability density function (normalized histogram) of the
data.
Parameters
----------
original_data : bool, optional
Whether to use all of the data initially passed to the Fit object.
If False, uses only the data used for the fit (within xmin and
xmax.)
Returns
-------
bin_edges : array
The edges of the bins of the probability density function.
probabilities : array
The portion of the data that is within the bin. Length 1 less than
bin_edges, as it corresponds to the spaces between them.
"""
if original_data:
data = self.data_original
xmin = None
xmax = None
else:
data = self.data
xmin = self.xmin
xmax = self.xmax
edges, hist = pdf(data, xmin=xmin, xmax=xmax, **kwargs)
return edges, hist
def plot_cdf(self, ax=None, original_data=False, survival=False, **kwargs):
"""
Plots the CDF to a new figure or to axis ax if provided.
Parameters
----------
ax : matplotlib axis, optional
The axis to which to plot. If None, a new figure is created.
original_data : bool, optional
Whether to use all of the data initially passed to the Fit object.
If False, uses only the data used for the fit (within xmin and
xmax.)
survival : bool, optional
Whether to plot a CDF (False) or CCDF (True). False by default.
Returns
-------
ax : matplotlib axis
The axis to which the plot was made.
"""
if original_data:
data = self.data_original
else:
data = self.data
return plot_cdf(data, ax=ax, survival=survival, **kwargs)
def plot_ccdf(self, ax=None, original_data=False, survival=True, **kwargs):
"""
Plots the CCDF to a new figure or to axis ax if provided.
Parameters
----------
ax : matplotlib axis, optional
The axis to which to plot. If None, a new figure is created.
original_data : bool, optional
Whether to use all of the data initially passed to the Fit object.
If False, uses only the data used for the fit (within xmin and
xmax.)
survival : bool, optional
Whether to plot a CDF (False) or CCDF (True). True by default.
Returns
-------
ax : matplotlib axis
The axis to which the plot was made.
"""
if original_data:
data = self.data_original
else:
data = self.data
return plot_cdf(data, ax=ax, survival=survival, **kwargs)
def plot_pdf(self, ax=None, original_data=False,
linear_bins=False, **kwargs):
"""
Plots the probability density function (PDF) or the data to a new figure
or to axis ax if provided.
Parameters
----------
ax : matplotlib axis, optional
The axis to which to plot. If None, a new figure is created.
original_data : bool, optional
Whether to use all of the data initially passed to the Fit object.
If False, uses only the data used for the fit (within xmin and
xmax.)
linear_bins : bool, optional
Whether to use linearly spaced bins (True) or logarithmically
spaced bins (False). False by default.
Returns
-------
ax : matplotlib axis
The axis to which the plot was made.
"""
if original_data:
data = self.data_original
else:
data = self.data
return plot_pdf(data, ax=ax, linear_bins=linear_bins, **kwargs)
class Distribution(object):
"""
An abstract class for theoretical probability distributions. Can be created
with particular parameter values, or fitted to a dataset. Fitting is
by maximum likelihood estimation by default.
Parameters
----------
xmin : int or float, optional
The data value beyond which distributions should be fitted. If
None an optimal one will be calculated.
xmax : int or float, optional
The maximum value of the fitted distributions.
discrete : boolean, optional
Whether the distribution is discrete (integers).
data : list or array, optional
The data to which to fit the distribution. If provided, the fit will
be created at initialization.
fit_method : "Likelihood" or "KS", optional
Method for fitting the distribution. "Likelihood" is maximum Likelihood
estimation. "KS" is minimial distance estimation using The
Kolmogorov-Smirnov test.
parameters : tuple or list, optional
The parameters of the distribution. Will be overridden if data is
given or the fit method is called.
parameter_range : dict, optional
Dictionary of valid parameter ranges for fitting. Formatted as a
dictionary of parameter names ('alpha' and/or 'sigma') and tuples
of their lower and upper limits (ex. (1.5, 2.5), (None, .1)
initial_parameters : tuple or list, optional
Initial values for the parameter in the fitting search.
discrete_approximation : "round", "xmax" or int, optional
If the discrete form of the theoeretical distribution is not known,
it can be estimated. One estimation method is "round", which sums
the probability mass from x-.5 to x+.5 for each data point. The other
option is to calculate the probability for each x from 1 to N and
normalize by their sum. N can be "xmax" or an integer.
parent_Fit : Fit object, optional
A Fit object from which to use data, if it exists.
"""
def __init__(self,
xmin=1, xmax=None,
discrete=False,
fit_method='Likelihood',
data=None,
parameters=None,
parameter_range=None,
initial_parameters=None,
discrete_approximation='round',
parent_Fit=None,
**kwargs):
self.xmin = xmin
self.xmax = xmax
self.discrete = discrete
self.fit_method = fit_method
self.discrete_approximation = discrete_approximation
self.parameter1 = None
self.parameter2 = None
self.parameter3 = None
self.parameter1_name = None
self.parameter2_name = None
self.parameter3_name = None
if parent_Fit:
self.parent_Fit = parent_Fit
if parameters is not None:
self.parameters(parameters)
if parameter_range:
self.parameter_range(parameter_range)
if initial_parameters:
self._given_initial_parameters(initial_parameters)
if (data is not None) and not (parameter_range and self.parent_Fit):
self.fit(data)
def fit(self, data=None, suppress_output=False):
"""
Fits the parameters of the distribution to the data. Uses options set
at initialization.
"""
if data is None and hasattr(self, 'parent_Fit'):
data = self.parent_Fit.data
data = trim_to_range(data, xmin=self.xmin, xmax=self.xmax)
if self.fit_method=='Likelihood':
def fit_function(params):
self.parameters(params)
return -sum(self.loglikelihoods(data))
elif self.fit_method=='KS':
def fit_function(params):
self.parameters(params)
self.KS(data)
return self.D
from scipy.optimize import fmin
parameters, negative_loglikelihood, iter, funcalls, warnflag, = \
fmin(
lambda params: fit_function(params),
self.initial_parameters(data),
full_output=1,
disp=False)
self.parameters(parameters)
if not self.in_range():
self.noise_flag=True
else:
self.noise_flag=False
if self.noise_flag and not suppress_output:
print("No valid fits found.", file=sys.stderr)
self.loglikelihood =-negative_loglikelihood
self.KS(data)
def KS(self, data=None):
"""
Returns the Kolmogorov-Smirnov distance D between the distribution and
the data. Also sets the properties D+, D-, V (the Kuiper testing
statistic), and Kappa (1 + the average difference between the
theoretical and empirical distributions).
Parameters
----------
data : list or array, optional
If not provided, attempts to use the data from the Fit object in
which the Distribution object is contained.
"""
if data is None and hasattr(self, 'parent_Fit'):
data = self.parent_Fit.data
data = trim_to_range(data, xmin=self.xmin, xmax=self.xmax)
if len(data)<2:
print("Not enough data. Returning nan", file=sys.stderr)
from numpy import nan
self.D = nan
self.D_plus = nan
self.D_minus = nan
self.Kappa = nan
self.V = nan
self.Asquare = nan
return self.D
if hasattr(self, 'parent_Fit'):
bins = self.parent_Fit.fitting_cdf_bins
Actual_CDF = self.parent_Fit.fitting_cdf
ind = bins>=self.xmin
bins = bins[ind]
Actual_CDF = Actual_CDF[ind]
dropped_probability = Actual_CDF[0]
Actual_CDF -= dropped_probability
Actual_CDF /= 1-dropped_probability
else:
bins, Actual_CDF = cdf(data)
Theoretical_CDF = self.cdf(bins)
CDF_diff = Theoretical_CDF - Actual_CDF
self.D_plus = CDF_diff.max()
self.D_minus = -1.0*CDF_diff.min()
from numpy import mean
self.Kappa = 1 + mean(CDF_diff)
self.V = self.D_plus + self.D_minus
self.D = max(self.D_plus, self.D_minus)
self.Asquare = sum((
(CDF_diff**2) /
(Theoretical_CDF * (1 - Theoretical_CDF))
)[1:]
)
return self.D
def ccdf(self,data=None, survival=True):
"""
The complementary cumulative distribution function (CCDF) of the
theoretical distribution. Calculated for the values given in data
within xmin and xmax, if present.
Parameters
----------
data : list or array, optional
If not provided, attempts to use the data from the Fit object in
which the Distribution object is contained.
survival : bool, optional
Whether to calculate a CDF (False) or CCDF (True).
True by default.
Returns
-------
X : array
The sorted, unique values in the data.
probabilities : array
The portion of the data that is less than or equal to X.
"""
return self.cdf(data=data, survival=survival)
def cdf(self,data=None, survival=False):
"""
The cumulative distribution function (CDF) of the theoretical
distribution. Calculated for the values given in data within xmin and
xmax, if present.
Parameters
----------
data : list or array, optional
If not provided, attempts to use the data from the Fit object in
which the Distribution object is contained.
survival : bool, optional
Whether to calculate a CDF (False) or CCDF (True).
False by default.
Returns
-------
X : array
The sorted, unique values in the data.
probabilities : array
The portion of the data that is less than or equal to X.
"""
if data is None and hasattr(self, 'parent_Fit'):
data = self.parent_Fit.data
data = trim_to_range(data, xmin=self.xmin, xmax=self.xmax)
n = len(data)
from sys import float_info
if not self.in_range():
from numpy import tile
return tile(10**float_info.min_10_exp, n)
if self._cdf_xmin==1:
#If cdf_xmin is 1, it means we don't have the numerical accuracy to
#calculate this tail. So we make everything 1, indicating
#we're at the end of the tail. Such an xmin should be thrown
#out by the KS test.
from numpy import ones
CDF = ones(n)
return CDF
CDF = self._cdf_base_function(data) - self._cdf_xmin
norm = 1 - self._cdf_xmin
if self.xmax:
norm = norm - (1 - self._cdf_base_function(self.xmax))
CDF = CDF/norm
if survival:
CDF = 1 - CDF
possible_numerical_error = False
from numpy import isnan, min
if isnan(min(CDF)):
print("'nan' in fit cumulative distribution values.", file=sys.stderr)
possible_numerical_error = True
#if 0 in CDF or 1 in CDF:
# print("0 or 1 in fit cumulative distribution values.", file=sys.stderr)
# possible_numerical_error = True
if possible_numerical_error:
print("Likely underflow or overflow error: the optimal fit for this distribution gives values that are so extreme that we lack the numerical precision to calculate them.", file=sys.stderr)
return CDF
@property
def _cdf_xmin(self):
return self._cdf_base_function(self.xmin)
def pdf(self, data=None):
"""
Returns the probability density function (normalized histogram) of the
theoretical distribution for the values in data within xmin and xmax,
if present.
Parameters
----------
data : list or array, optional
If not provided, attempts to use the data from the Fit object in
which the Distribution object is contained.
Returns
-------
probabilities : array
"""
if data is None and hasattr(self, 'parent_Fit'):
data = self.parent_Fit.data
data = trim_to_range(data, xmin=self.xmin, xmax=self.xmax)
n = len(data)
from sys import float_info
if not self.in_range():
from numpy import tile
return tile(10**float_info.min_10_exp, n)
if not self.discrete:
f = self._pdf_base_function(data)
C = self._pdf_continuous_normalizer
likelihoods = f*C
else:
if self._pdf_discrete_normalizer:
f = self._pdf_base_function(data)
C = self._pdf_discrete_normalizer
likelihoods = f*C
elif self.discrete_approximation=='round':
lower_data = data-.5
upper_data = data+.5
#Temporarily expand xmin and xmax to be able to grab the extra bit of
#probability mass beyond the (integer) values of xmin and xmax
#Note this is a design decision. One could also say this extra
#probability "off the edge" of the distribution shouldn't be included,
#and that implementation is retained below, commented out. Note, however,
#that such a cliff means values right at xmin and xmax have half the width to
#grab probability from, and thus are lower probability than they would otherwise
#be. This is particularly concerning for values at xmin, which are typically
#the most likely and greatly influence the distribution's fit.
self.xmin -= .5
if self.xmax:
self.xmax += .5
#Clean data for invalid values before handing to cdf, which will purge them
#lower_data[lower_data<self.xmin] +=.5
#if self.xmax:
# upper_data[upper_data>self.xmax] -=.5
likelihoods = self.cdf(upper_data)-self.cdf(lower_data)
self.xmin +=.5
if self.xmax:
self.xmax -= .5
else:
if self.discrete_approximation=='xmax':
upper_limit = self.xmax
else:
upper_limit = self.discrete_approximation
# from mpmath import exp
from numpy import arange
X = arange(self.xmin, upper_limit+1)
PDF = self._pdf_base_function(X)
PDF = (PDF/sum(PDF)).astype(float)
likelihoods = PDF[(data-self.xmin).astype(int)]
likelihoods[likelihoods==0] = 10**float_info.min_10_exp
return likelihoods
@property
def _pdf_continuous_normalizer(self):
C = 1 - self._cdf_xmin
if self.xmax:
C -= 1 - self._cdf_base_function(self.xmax+1)
C = 1.0/C
return C
@property
def _pdf_discrete_normalizer(self):
return False
def parameter_range(self, r, initial_parameters=None):
"""
Set the limits on the range of valid parameters to be considered while
fitting.
Parameters
----------
r : dict
A dictionary of the parameter range. Restricted parameter
names are keys, and with tuples of the form (lower_bound,
upper_bound) as values.
initial_parameters : tuple or list, optional
Initial parameter values to start the fitting search from.
"""
from types import FunctionType
if type(r)==FunctionType:
self._in_given_parameter_range = r
else:
self._range_dict = r
if initial_parameters:
self._given_initial_parameters = initial_parameters
if self.parent_Fit:
self.fit(self.parent_Fit.data)
def in_range(self):
"""
Whether the current parameters of the distribution are within the range
of valid parameters.
"""
try:
r = self._range_dict
result = True
for k in r.keys():
#For any attributes we've specificed, make sure we're above the lower bound
#and below the lower bound (if they exist). This must be true of all of them.
lower_bound, upper_bound = r[k]
if upper_bound is not None:
result *= getattr(self, k) < upper_bound
if lower_bound is not None:
result *= getattr(self, k) > lower_bound
return result
except AttributeError:
try:
in_range = self._in_given_parameter_range(self)
except AttributeError:
in_range = self._in_standard_parameter_range()
return bool(in_range)
def initial_parameters(self, data):
"""
Return previously user-provided initial parameters or, if never
provided, calculate new ones. Default initial parameter estimates are
unique to each theoretical distribution.
"""
try:
return self._given_initial_parameters
except AttributeError:
return self._initial_parameters(data)
def likelihoods(self, data):
"""
The likelihoods of the observed data from the theoretical distribution.
Another name for the probabilities or probability density function.
"""
return self.pdf(data)
def loglikelihoods(self, data):
"""
The logarithm of the likelihoods of the observed data from the
theoretical distribution.
"""
from numpy import log
return log(self.likelihoods(data))
def plot_ccdf(self, data=None, ax=None, survival=True, **kwargs):
"""
Plots the complementary cumulative distribution function (CDF) of the
theoretical distribution for the values given in data within xmin and
xmax, if present. Plots to a new figure or to axis ax if provided.
Parameters
----------
data : list or array, optional
If not provided, attempts to use the data from the Fit object in
which the Distribution object is contained.
ax : matplotlib axis, optional
The axis to which to plot. If None, a new figure is created.
survival : bool, optional
Whether to plot a CDF (False) or CCDF (True). True by default.
Returns
-------
ax : matplotlib axis
The axis to which the plot was made.
"""
return self.plot_cdf(data, ax=None, survival=survival, **kwargs)
def plot_cdf(self, data=None, ax=None, survival=False, **kwargs):
"""
Plots the cumulative distribution function (CDF) of the
theoretical distribution for the values given in data within xmin and
xmax, if present. Plots to a new figure or to axis ax if provided.
Parameters
----------
data : list or array, optional
If not provided, attempts to use the data from the Fit object in
which the Distribution object is contained.
ax : matplotlib axis, optional
The axis to which to plot. If None, a new figure is created.
survival : bool, optional
Whether to plot a CDF (False) or CCDF (True). False by default.
Returns
-------
ax : matplotlib axis
The axis to which the plot was made.
"""
if data is None and hasattr(self, 'parent_Fit'):
data = self.parent_Fit.data
from numpy import unique
bins = unique(trim_to_range(data, xmin=self.xmin, xmax=self.xmax))
CDF = self.cdf(bins, survival=survival)
if not ax:
import matplotlib.pyplot as plt
plt.plot(bins, CDF, **kwargs)
ax = plt.gca()
else:
ax.plot(bins, CDF, **kwargs)
ax.set_xscale("log")
ax.set_yscale("log")
return ax
def plot_pdf(self, data=None, ax=None, **kwargs):
"""
Plots the probability density function (PDF) of the
theoretical distribution for the values given in data within xmin and
xmax, if present. Plots to a new figure or to axis ax if provided.
Parameters
----------
data : list or array, optional
If not provided, attempts to use the data from the Fit object in
which the Distribution object is contained.
ax : matplotlib axis, optional
The axis to which to plot. If None, a new figure is created.
Returns
-------
ax : matplotlib axis
The axis to which the plot was made.
"""
if data is None and hasattr(self, 'parent_Fit'):
data = self.parent_Fit.data
from numpy import unique
bins = unique(trim_to_range(data, xmin=self.xmin, xmax=self.xmax))
PDF = self.pdf(bins)
from numpy import nan
PDF[PDF==0] = nan
if not ax:
import matplotlib.pyplot as plt
plt.plot(bins, PDF, **kwargs)
ax = plt.gca()
else:
ax.plot(bins, PDF, **kwargs)
ax.set_xscale("log")
ax.set_yscale("log")
return ax
def generate_random(self,n=1, estimate_discrete=None):
"""
Generates random numbers from the theoretical probability distribution.
If xmax is present, it is currently ignored.
Parameters
----------
n : int or float
The number of random numbers to generate
estimate_discrete : boolean
For discrete distributions, whether to use a faster approximation of
the random number generator. If None, attempts to inherit
the estimate_discrete behavior used for fitting from the Distribution
object or the parent Fit object, if present. Approximations only
exist for some distributions (namely the power law). If an
approximation does not exist an estimate_discrete setting of True
will not be inherited.
Returns
-------
r : array
Random numbers drawn from the distribution
"""
from numpy.random import rand
from numpy import array
r = rand(n)
if not self.discrete:
x = self._generate_random_continuous(r)
else:
if (estimate_discrete and not hasattr(self, '_generate_random_discrete_estimate') ):
raise AttributeError("This distribution does not have an "
"estimation of the discrete form for generating simulated "
"data. Try the exact form with estimate_discrete=False.")
if estimate_discrete is None:
if not hasattr(self, '_generate_random_discrete_estimate'):
estimate_discrete = False
elif hasattr(self, 'estimate_discrete'):
estimate_discrete = self.estimate_discrete
elif hasattr('parent_Fit'):
estimate_discrete = self.parent_Fit.estimate_discrete
else:
estimate_discrete = False
if estimate_discrete:
x = self._generate_random_discrete_estimate(r)
else:
x = array([self._double_search_discrete(R) for R in r],
dtype='float')
return x
def _double_search_discrete(self, r):
#Find a range from x1 to x2 that our random probability fits between
x2 = int(self.xmin)
while self.ccdf(data=[x2]) >= (1 - r):
x1 = x2
x2 = 2*x1
#Use binary search within that range to find the exact answer, up to
#the limit of being between two integers.
x = bisect_map(x1, x2, self.ccdf, 1-r)
return x
class Power_Law(Distribution):
def __init__(self, estimate_discrete=True, **kwargs):
self.estimate_discrete = estimate_discrete
Distribution.__init__(self, **kwargs)
def parameters(self, params):
self.alpha = params[0]
self.parameter1 = self.alpha
self.parameter1_name = 'alpha'
@property
def name(self):
return "power_law"
@property
def sigma(self):
#Only is calculable after self.fit is started, when the number of data points is
#established
from numpy import sqrt
return (self.alpha - 1) / sqrt(self.n)
def _in_standard_parameter_range(self):
return self.alpha>1
def fit(self, data=None):
if data is None and hasattr(self, 'parent_Fit'):
data = self.parent_Fit.data
data = trim_to_range(data, xmin=self.xmin, xmax=self.xmax)
self.n = len(data)
from numpy import log, sum
if not self.discrete and not self.xmax:
self.alpha = 1 + (self.n / sum(log(data/self.xmin)))
if not self.in_range():
Distribution.fit(self, data, suppress_output=True)
self.KS(data)
elif self.discrete and self.estimate_discrete and not self.xmax:
self.alpha = 1 + (self.n / sum(log(data / (self.xmin - .5))))
if not self.in_range():
Distribution.fit(self, data, suppress_output=True)
self.KS(data)
else:
Distribution.fit(self, data, suppress_output=True)
if not self.in_range():
self.noise_flag=True
else:
self.noise_flag=False
def _initial_parameters(self, data):
from numpy import log, sum
return 1 + len(data)/sum(log(data / (self.xmin)))
def _cdf_base_function(self, x):
if self.discrete:
from scipy.special import zeta
CDF = 1 - zeta(self.alpha, x)
else:
#Can this be reformulated to not reference xmin? Removal of the probability
#before xmin and after xmax is handled in Distribution.cdf(), so we don't
#strictly need this element. It doesn't hurt, for the moment.
CDF = 1-(x/self.xmin)**(-self.alpha+1)
return CDF
def _pdf_base_function(self, x):
return x**-self.alpha
@property
def _pdf_continuous_normalizer(self):
return (self.alpha-1) * self.xmin**(self.alpha-1)
@property
def _pdf_discrete_normalizer(self):
C = 1.0 - self._cdf_xmin
if self.xmax:
C -= 1 - self._cdf_base_function(self.xmax+1)
C = 1.0/C
return C
def _generate_random_continuous(self, r):
return self.xmin * (1 - r) ** (-1/(self.alpha - 1))
def _generate_random_discrete_estimate(self, r):
x = (self.xmin - 0.5) * (1 - r) ** (-1/(self.alpha - 1)) + 0.5
from numpy import around
return around(x)
class Exponential(Distribution):
def parameters(self, params):
self.Lambda = params[0]
self.parameter1 = self.Lambda
self.parameter1_name = 'lambda'
@property
def name(self):
return "exponential"
def _initial_parameters(self, data):
from numpy import mean
return 1/mean(data)
def _in_standard_parameter_range(self):
return self.Lambda>0
def _cdf_base_function(self, x):
from numpy import exp
CDF = 1 - exp(-self.Lambda*x)
return CDF
def _pdf_base_function(self, x):
from numpy import exp
return exp(-self.Lambda * x)
@property
def _pdf_continuous_normalizer(self):
from numpy import exp
return self.Lambda * exp(self.Lambda * self.xmin)
@property
def _pdf_discrete_normalizer(self):
from numpy import exp
C = (1 - exp(-self.Lambda)) * exp(self.Lambda * self.xmin)
if self.xmax:
Cxmax = (1 - exp(-self.Lambda)) * exp(self.Lambda * self.xmax)
C = 1.0/C - 1.0/Cxmax
C = 1.0/C
return C
def pdf(self, data=None):
if data is None and hasattr(self, 'parent_Fit'):
data = self.parent_Fit.data
if not self.discrete and self.in_range() and not self.xmax:
data = trim_to_range(data, xmin=self.xmin, xmax=self.xmax)
from numpy import exp
# likelihoods = exp(-Lambda*data)*\
# Lambda*exp(Lambda*xmin)
likelihoods = self.Lambda*exp(self.Lambda*(self.xmin-data))
#Simplified so as not to throw a nan from infs being divided by each other
from sys import float_info
likelihoods[likelihoods==0] = 10**float_info.min_10_exp
else:
likelihoods = Distribution.pdf(self, data)
return likelihoods
def loglikelihoods(self, data=None):
if data is None and hasattr(self, 'parent_Fit'):
data = self.parent_Fit.data
if not self.discrete and self.in_range() and not self.xmax:
data = trim_to_range(data, xmin=self.xmin, xmax=self.xmax)
from numpy import log
# likelihoods = exp(-Lambda*data)*\
# Lambda*exp(Lambda*xmin)
loglikelihoods = log(self.Lambda) + (self.Lambda*(self.xmin-data))
#Simplified so as not to throw a nan from infs being divided by each other
from sys import float_info
loglikelihoods[loglikelihoods==0] = log(10**float_info.min_10_exp)
else:
loglikelihoods = Distribution.loglikelihoods(self, data)
return loglikelihoods
def _generate_random_continuous(self, r):
from numpy import log
return self.xmin - (1/self.Lambda) * log(1-r)
class Stretched_Exponential(Distribution):
def parameters(self, params):
self.Lambda = params[0]
self.parameter1 = self.Lambda
self.parameter1_name = 'lambda'
self.beta = params[1]
self.parameter2 = self.beta
self.parameter2_name = 'beta'
@property
def name(self):
return "stretched_exponential"
def _initial_parameters(self, data):
from numpy import mean
return (1/mean(data), 1)
def _in_standard_parameter_range(self):
return self.Lambda>0 and self.beta>0
def _cdf_base_function(self, x):
from numpy import exp
CDF = 1 - exp(-(self.Lambda*x)**self.beta)
return CDF
def _pdf_base_function(self, x):
from numpy import exp
return (((x*self.Lambda)**(self.beta-1)) *
exp(-((self.Lambda*x)**self.beta)))
@property
def _pdf_continuous_normalizer(self):
from numpy import exp
C = self.beta*self.Lambda*exp((self.Lambda*self.xmin)**self.beta)
return C
@property
def _pdf_discrete_normalizer(self):
return False
def pdf(self, data=None):
if data is None and hasattr(self, 'parent_Fit'):
data = self.parent_Fit.data
if not self.discrete and self.in_range() and not self.xmax:
data = trim_to_range(data, xmin=self.xmin, xmax=self.xmax)
from numpy import exp
likelihoods = ((data*self.Lambda)**(self.beta-1) *
self.beta * self.Lambda *
exp((self.Lambda*self.xmin)**self.beta -
(self.Lambda*data)**self.beta))
#Simplified so as not to throw a nan from infs being divided by each other
from sys import float_info
likelihoods[likelihoods==0] = 10**float_info.min_10_exp
else:
likelihoods = Distribution.pdf(self, data)
return likelihoods
def loglikelihoods(self, data=None):
if data is None and hasattr(self, 'parent_Fit'):
data = self.parent_Fit.data
if not self.discrete and self.in_range() and not self.xmax:
data = trim_to_range(data, xmin=self.xmin, xmax=self.xmax)
from numpy import log
loglikelihoods = (
log((data*self.Lambda)**(self.beta-1) *
self.beta * self. Lambda) +
(self.Lambda*self.xmin)**self.beta -
(self.Lambda*data)**self.beta)
#Simplified so as not to throw a nan from infs being divided by each other
from sys import float_info
from numpy import inf
loglikelihoods[loglikelihoods==-inf] = log(10**float_info.min_10_exp)
else:
loglikelihoods = Distribution.loglikelihoods(self, data)
return loglikelihoods
def _generate_random_continuous(self, r):
from numpy import log
# return ( (self.xmin**self.beta) -
# (1/self.Lambda) * log(1-r) )**(1/self.beta)
return (1/self.Lambda)* ( (self.Lambda*self.xmin)**self.beta -
log(1-r) )**(1/self.beta)
class Truncated_Power_Law(Distribution):
def parameters(self, params):
self.alpha = params[0]
self.parameter1 = self.alpha
self.parameter1_name = 'alpha'
self.Lambda = params[1]
self.parameter2 = self.Lambda
self.parameter2_name = 'lambda'
@property
def name(self):
return "truncated_power_law"
def _initial_parameters(self, data):
from numpy import log, sum, mean
alpha = 1 + len(data)/sum( log( data / (self.xmin) ))
Lambda = 1/mean(data)
return (alpha, Lambda)
def _in_standard_parameter_range(self):
return self.Lambda>0 and self.alpha>1
def _cdf_base_function(self, x):
from mpmath import gammainc
from numpy import vectorize
gammainc = vectorize(gammainc)
CDF = ( (gammainc(1-self.alpha,self.Lambda*x)).astype('float') /
self.Lambda**(1-self.alpha)
)
CDF = 1 -CDF
return CDF
def _pdf_base_function(self, x):
from numpy import exp
return x**(-self.alpha) * exp(-self.Lambda * x)
@property
def _pdf_continuous_normalizer(self):
from mpmath import gammainc
C = ( self.Lambda**(1-self.alpha) /
float(gammainc(1-self.alpha,self.Lambda*self.xmin)))
return C
@property
def _pdf_discrete_normalizer(self):
if 0:
return False
from mpmath import lerchphi
from mpmath import exp # faster /here/ than numpy.exp
C = ( float(exp(self.xmin * self.Lambda) /
lerchphi(exp(-self.Lambda), self.alpha, self.xmin)) )
if self.xmax:
Cxmax = ( float(exp(self.xmax * self.Lambda) /
lerchphi(exp(-self.Lambda), self.alpha, self.xmax)) )
C = 1.0/C - 1.0/Cxmax
C = 1.0/C
return C
def pdf(self, data=None):
if data is None and hasattr(self, 'parent_Fit'):
data = self.parent_Fit.data
if not self.discrete and self.in_range() and False:
data = trim_to_range(data, xmin=self.xmin, xmax=self.xmax)
from numpy import exp
from mpmath import gammainc
# likelihoods = (data**-alpha)*exp(-Lambda*data)*\
# (Lambda**(1-alpha))/\
# float(gammainc(1-alpha,Lambda*xmin))
likelihoods = ( self.Lambda**(1-self.alpha) /
(data**self.alpha *
exp(self.Lambda*data) *
gammainc(1-self.alpha,self.Lambda*self.xmin)
).astype(float)
)
#Simplified so as not to throw a nan from infs being divided by each other
from sys import float_info
likelihoods[likelihoods==0] = 10**float_info.min_10_exp
else:
likelihoods = Distribution.pdf(self, data)
return likelihoods
def _generate_random_continuous(self, r):
def helper(r):
from numpy import log
from numpy.random import rand
while 1:
x = self.xmin - (1/self.Lambda) * log(1-r)
p = ( x/self.xmin )**-self.alpha
if rand()<p:
return x
r = rand()
from numpy import array
return array(list(map(helper, r)))
class Lognormal(Distribution):
def parameters(self, params):
self.mu = params[0]
self.parameter1 = self.mu
self.parameter1_name = 'mu'
self.sigma = params[1]
self.parameter2 = self.sigma
self.parameter2_name = 'sigma'
@property
def name(self):
return "lognormal"
def pdf(self, data=None):
"""
Returns the probability density function (normalized histogram) of the
theoretical distribution for the values in data within xmin and xmax,
if present.
Parameters
----------
data : list or array, optional
If not provided, attempts to use the data from the Fit object in
which the Distribution object is contained.
Returns
-------
probabilities : array
"""
if data is None and hasattr(self, 'parent_Fit'):
data = self.parent_Fit.data
data = trim_to_range(data, xmin=self.xmin, xmax=self.xmax)
n = len(data)
from sys import float_info
from numpy import tile
if not self.in_range():
return tile(10**float_info.min_10_exp, n)
if not self.discrete:
f = self._pdf_base_function(data)
C = self._pdf_continuous_normalizer
if C > 0:
likelihoods = f/C
else:
likelihoods = tile(10**float_info.min_10_exp, n)
else:
if self._pdf_discrete_normalizer:
f = self._pdf_base_function(data)
C = self._pdf_discrete_normalizer
likelihoods = f*C
elif self.discrete_approximation=='round':
likelihoods = self._round_discrete_approx(data)
else:
if self.discrete_approximation=='xmax':
upper_limit = self.xmax
else:
upper_limit = self.discrete_approximation
# from mpmath import exp
from numpy import arange
X = arange(self.xmin, upper_limit+1)
PDF = self._pdf_base_function(X)
PDF = (PDF/sum(PDF)).astype(float)
likelihoods = PDF[(data-self.xmin).astype(int)]
likelihoods[likelihoods==0] = 10**float_info.min_10_exp
return likelihoods
def _round_discrete_approx(self, data):
"""
This function reformulates the calculation to avoid underflow errors
with the erf function. As implemented, erf(x) quickly approaches 1
while erfc(x) is more accurate. Since erfc(x) = 1 - erf(x),
calculations can be written using erfc(x)
"""
import numpy as np
import scipy.special as ss
""" Temporarily expand xmin and xmax to be able to grab the extra bit of
probability mass beyond the (integer) values of xmin and xmax
Note this is a design decision. One could also say this extra
probability "off the edge" of the distribution shouldn't be included,
and that implementation is retained below, commented out. Note, however,
that such a cliff means values right at xmin and xmax have half the width to
grab probability from, and thus are lower probability than they would otherwise
be. This is particularly concerning for values at xmin, which are typically
the most likely and greatly influence the distribution's fit.
"""
lower_data = data-.5
upper_data = data+.5
self.xmin -= .5
if self.xmax:
self.xmax += .5
# revised calculation written to avoid underflow errors
arg1 = (np.log(lower_data)-self.mu) / (np.sqrt(2)*self.sigma)
arg2 = (np.log(upper_data)-self.mu) / (np.sqrt(2)*self.sigma)
likelihoods = 0.5*(ss.erfc(arg1) - ss.erfc(arg2))
if not self.xmax:
norm = 0.5*ss.erfc((np.log(self.xmin)-self.mu) / (np.sqrt(2)*self.sigma))
else:
# may still need to be fixed
norm = - self._cdf_xmin + self._cdf_base_function(self.xmax)
self.xmin +=.5
if self.xmax:
self.xmax -= .5
return likelihoods/norm
def cdf(self, data=None, survival=False):
"""
The cumulative distribution function (CDF) of the lognormal
distribution. Calculated for the values given in data within xmin and
xmax, if present. Calculation was reformulated to avoid underflow
errors
Parameters
----------
data : list or array, optional
If not provided, attempts to use the data from the Fit object in
which the Distribution object is contained.
survival : bool, optional
Whether to calculate a CDF (False) or CCDF (True).
False by default.
Returns
-------
X : array
The sorted, unique values in the data.
probabilities : array
The portion of the data that is less than or equal to X.
"""
from numpy import log, sqrt
import scipy.special as ss
if data is None and hasattr(self, 'parent_Fit'):
data = self.parent_Fit.data
data = trim_to_range(data, xmin=self.xmin, xmax=self.xmax)
n = len(data)
from sys import float_info
if not self.in_range():
from numpy import tile
return tile(10**float_info.min_10_exp, n)
val_data = (log(data)-self.mu) / (sqrt(2)*self.sigma)
val_xmin = (log(self.xmin)-self.mu) / (sqrt(2)*self.sigma)
CDF = 0.5 * (ss.erfc(val_xmin) - ss.erfc(val_data))
norm = 0.5 * ss.erfc(val_xmin)
if self.xmax:
# TO DO: Improve this line further for better numerical accuracy?
norm = norm - (1 - self._cdf_base_function(self.xmax))
CDF = CDF/norm
if survival:
CDF = 1 - CDF
possible_numerical_error = False
from numpy import isnan, min
if isnan(min(CDF)):
print("'nan' in fit cumulative distribution values.", file=sys.stderr)
possible_numerical_error = True
#if 0 in CDF or 1 in CDF:
# print("0 or 1 in fit cumulative distribution values.", file=sys.stderr)
# possible_numerical_error = True
if possible_numerical_error:
print("Likely underflow or overflow error: the optimal fit for this distribution gives values that are so extreme that we lack the numerical precision to calculate them.", file=sys.stderr)
return CDF
def _initial_parameters(self, data):
from numpy import mean, std, log
logdata = log(data)
return (mean(logdata), std(logdata))
def _in_standard_parameter_range(self):
#The standard deviation can't be negative
return self.sigma>0
def _cdf_base_function(self, x):
from numpy import sqrt, log
from scipy.special import erf
return 0.5 + ( 0.5 *
erf((log(x)-self.mu) / (sqrt(2)*self.sigma)))
def _pdf_base_function(self, x):
from numpy import exp, log
return ((1.0/x) *
exp(-( (log(x) - self.mu)**2 )/(2*self.sigma**2)))
@property
def _pdf_continuous_normalizer(self):
from mpmath import erfc
# from scipy.special import erfc
from scipy.constants import pi
from numpy import sqrt, log
C = (erfc((log(self.xmin) - self.mu) / (sqrt(2) * self.sigma)) /
sqrt(2/(pi*self.sigma**2)))
return float(C)
@property
def _pdf_discrete_normalizer(self):
return False
def _generate_random_continuous(self, r):
from numpy import exp, sqrt, log, frompyfunc
from mpmath import erf, erfinv
#This is a long, complicated function broken into parts.
#We use mpmath to maintain numerical accuracy as we run through
#erf and erfinv, until we get to more sane numbers. Thanks to
#Wolfram Alpha for producing the appropriate inverse of the CCDF
#for me, which is what we need to calculate these things.
erfinv = frompyfunc(erfinv,1,1)
Q = erf( ( log(self.xmin) - self.mu ) / (sqrt(2)*self.sigma))
Q = Q*r - r + 1.0
Q = erfinv(Q).astype('float')
return exp(self.mu + sqrt(2)*self.sigma*Q)
# def _generate_random_continuous(self, r1, r2=None):
# from numpy import log, sqrt, exp, sin, cos
# from scipy.constants import pi
# if r2==None:
# from numpy.random import rand
# r2 = rand(len(r1))
# r2_provided = False
# else:
# r2_provided = True
#
# rho = sqrt(-2.0 * self.sigma**2.0 * log(1-r1))
# theta = 2.0 * pi * r2
# x1 = exp(rho * sin(theta))
# x2 = exp(rho * cos(theta))
#
# if r2_provided:
# return x1, x2
# else:
# return x1
def nested_loglikelihood_ratio(loglikelihoods1, loglikelihoods2, **kwargs):
"""
Calculates a loglikelihood ratio and the p-value for testing which of two
probability distributions is more likely to have created a set of
observations. Assumes one of the probability distributions is a nested
version of the other.
Parameters
----------
loglikelihoods1 : list or array
The logarithms of the likelihoods of each observation, calculated from
a particular probability distribution.
loglikelihoods2 : list or array
The logarithms of the likelihoods of each observation, calculated from
a particular probability distribution.
nested : bool, optional
Whether one of the two probability distributions that generated the
likelihoods is a nested version of the other. True by default.
normalized_ratio : bool, optional
Whether to return the loglikelihood ratio, R, or the normalized
ratio R/sqrt(n*variance)
Returns
-------
R : float
The loglikelihood ratio of the two sets of likelihoods. If positive,
the first set of likelihoods is more likely (and so the probability
distribution that produced them is a better fit to the data). If
negative, the reverse is true.
p : float
The significance of the sign of R. If below a critical values
(typically .05) the sign of R is taken to be significant. If above the
critical value the sign of R is taken to be due to statistical
fluctuations.
"""
return loglikelihood_ratio(loglikelihoods1, loglikelihoods2,
nested=True, **kwargs)
def loglikelihood_ratio(loglikelihoods1, loglikelihoods2,
nested=False, normalized_ratio=False):
"""
Calculates a loglikelihood ratio and the p-value for testing which of two
probability distributions is more likely to have created a set of
observations.
Parameters
----------
loglikelihoods1 : list or array
The logarithms of the likelihoods of each observation, calculated from
a particular probability distribution.
loglikelihoods2 : list or array
The logarithms of the likelihoods of each observation, calculated from
a particular probability distribution.
nested: bool, optional
Whether one of the two probability distributions that generated the
likelihoods is a nested version of the other. False by default.
normalized_ratio : bool, optional
Whether to return the loglikelihood ratio, R, or the normalized
ratio R/sqrt(n*variance)
Returns
-------
R : float
The loglikelihood ratio of the two sets of likelihoods. If positive,
the first set of likelihoods is more likely (and so the probability
distribution that produced them is a better fit to the data). If
negative, the reverse is true.
p : float
The significance of the sign of R. If below a critical values
(typically .05) the sign of R is taken to be significant. If above the
critical value the sign of R is taken to be due to statistical
fluctuations.
"""
from numpy import sqrt
from scipy.special import erfc
n = float(len(loglikelihoods1))
if n==0:
R = 0
p = 1
return R, p
from numpy import asarray
loglikelihoods1 = asarray(loglikelihoods1)
loglikelihoods2 = asarray(loglikelihoods2)
#Clean for extreme values, if any
from numpy import inf, log
from sys import float_info
min_val = log(10**float_info.min_10_exp)
loglikelihoods1[loglikelihoods1==-inf] = min_val
loglikelihoods2[loglikelihoods2==-inf] = min_val
R = sum(loglikelihoods1-loglikelihoods2)
from numpy import mean
mean_diff = mean(loglikelihoods1)-mean(loglikelihoods2)
variance = sum(
( (loglikelihoods1-loglikelihoods2) - mean_diff)**2
)/n
if nested:
from scipy.stats import chi2
p = 1 - chi2.cdf(abs(2*R), 1)
else:
p = erfc( abs(R) / sqrt(2*n*variance))
if normalized_ratio:
R = R/sqrt(n*variance)
return R, p
def cdf(data, survival=False, **kwargs):
"""
The cumulative distribution function (CDF) of the data.
Parameters
----------
data : list or array, optional
survival : bool, optional
Whether to calculate a CDF (False) or CCDF (True). False by default.
Returns
-------
X : array
The sorted, unique values in the data.
probabilities : array
The portion of the data that is less than or equal to X.
"""
return cumulative_distribution_function(data, survival=survival, **kwargs)
def ccdf(data, survival=True, **kwargs):
"""
The complementary cumulative distribution function (CCDF) of the data.
Parameters
----------
data : list or array, optional
survival : bool, optional
Whether to calculate a CDF (False) or CCDF (True). True by default.
Returns
-------
X : array
The sorted, unique values in the data.
probabilities : array
The portion of the data that is less than or equal to X.
"""
return cumulative_distribution_function(data, survival=survival, **kwargs)
def cumulative_distribution_function(data,
xmin=None, xmax=None,
survival=False, **kwargs):
"""
The cumulative distribution function (CDF) of the data.
Parameters
----------
data : list or array, optional
survival : bool, optional
Whether to calculate a CDF (False) or CCDF (True). False by default.
xmin : int or float, optional
The minimum data size to include. Values less than xmin are excluded.
xmax : int or float, optional
The maximum data size to include. Values greater than xmin are
excluded.
Returns
-------
X : array
The sorted, unique values in the data.
probabilities : array
The portion of the data that is less than or equal to X.
"""
from numpy import array
data = array(data)
if not data.any():
from numpy import nan
return array([nan]), array([nan])
data = trim_to_range(data, xmin=xmin, xmax=xmax)
n = float(len(data))
from numpy import sort
data = sort(data)
all_unique = not( any( data[:-1]==data[1:] ) )
if all_unique:
from numpy import arange
CDF = arange(n)/n
else:
#This clever bit is a way of using searchsorted to rapidly calculate the
#CDF of data with repeated values comes from Adam Ginsburg's plfit code,
#specifically https://github.com/keflavich/plfit/commit/453edc36e4eb35f35a34b6c792a6d8c7e848d3b5#plfit/plfit.py
from numpy import searchsorted, unique
CDF = searchsorted(data, data,side='left')/n
unique_data, unique_indices = unique(data, return_index=True)
data=unique_data
CDF = CDF[unique_indices]
if survival:
CDF = 1-CDF
return data, CDF
def is_discrete(data):
"""Checks if every element of the array is an integer."""
from numpy import floor
return (floor(data)==data.astype(float)).all()
def trim_to_range(data, xmin=None, xmax=None, **kwargs):
"""
Removes elements of the data that are above xmin or below xmax (if present)
"""
from numpy import asarray
data = asarray(data)
if xmin:
data = data[data>=xmin]
if xmax:
data = data[data<=xmax]
return data
def pdf(data, xmin=None, xmax=None, linear_bins=False, **kwargs):
"""
Returns the probability density function (normalized histogram) of the
data.
Parameters
----------
data : list or array
xmin : float, optional
Minimum value of the PDF. If None, uses the smallest value in the data.
xmax : float, optional
Maximum value of the PDF. If None, uses the largest value in the data.
linear_bins : float, optional
Whether to use linearly spaced bins, as opposed to logarithmically
spaced bins (recommended for log-log plots).
Returns
-------
bin_edges : array
The edges of the bins of the probability density function.
probabilities : array
The portion of the data that is within the bin. Length 1 less than
bin_edges, as it corresponds to the spaces between them.
"""
from numpy import logspace, histogram, floor, unique
from math import ceil, log10
if not xmax:
xmax = max(data)
if not xmin:
xmin = min(data)
if linear_bins:
bins = range(int(xmin), int(xmax))
else:
log_min_size = log10(xmin)
log_max_size = log10(xmax)
number_of_bins = ceil((log_max_size-log_min_size)*10)
bins=unique(
floor(
logspace(
log_min_size, log_max_size, num=number_of_bins)))
hist, edges = histogram(data, bins, density=True)
return edges, hist
def checkunique(data):
"""Quickly checks if a sorted array is all unique elements."""
for i in range(len(data)-1):
if data[i]==data[i+1]:
return False
return True
#def checksort(data):
# """
# Checks if the data is sorted, in O(n) time. If it isn't sorted, it then
# sorts it in O(nlogn) time. Expectation is that the data will typically
# be sorted. Presently slower than numpy's sort, even on large arrays, and
# so is useless.
# """
#
# n = len(data)
# from numpy import arange
# if not all(data[i] <= data[i+1] for i in arange(n-1)):
# from numpy import sort
# data = sort(data)
# return data
def plot_ccdf(data, ax=None, survival=False, **kwargs):
return plot_cdf(data, ax=ax, survival=True, **kwargs)
"""
Plots the complementary cumulative distribution function (CDF) of the data
to a new figure or to axis ax if provided.
Parameters
----------
data : list or array
ax : matplotlib axis, optional
The axis to which to plot. If None, a new figure is created.
survival : bool, optional
Whether to plot a CDF (False) or CCDF (True). True by default.
Returns
-------
ax : matplotlib axis
The axis to which the plot was made.
"""
def plot_cdf(data, ax=None, survival=False, **kwargs):
"""
Plots the cumulative distribution function (CDF) of the data to a new
figure or to axis ax if provided.
Parameters
----------
data : list or array
ax : matplotlib axis, optional
The axis to which to plot. If None, a new figure is created.
survival : bool, optional
Whether to plot a CDF (False) or CCDF (True). False by default.
Returns
-------
ax : matplotlib axis
The axis to which the plot was made.
"""
bins, CDF = cdf(data, survival=survival, **kwargs)
if not ax:
import matplotlib.pyplot as plt
plt.plot(bins, CDF, **kwargs)
ax = plt.gca()
else:
ax.plot(bins, CDF, **kwargs)
ax.set_xscale("log")
ax.set_yscale("log")
return ax
def plot_pdf(data, ax=None, linear_bins=False, **kwargs):
"""
Plots the probability density function (PDF) to a new figure or to axis ax
if provided.
Parameters
----------
data : list or array
ax : matplotlib axis, optional
The axis to which to plot. If None, a new figure is created.
linear_bins : bool, optional
Whether to use linearly spaced bins (True) or logarithmically
spaced bins (False). False by default.
Returns
-------
ax : matplotlib axis
The axis to which the plot was made.
"""
edges, hist = pdf(data, linear_bins=linear_bins, **kwargs)
bin_centers = (edges[1:]+edges[:-1])/2.0
from numpy import nan
hist[hist==0] = nan
if not ax:
import matplotlib.pyplot as plt
plt.plot(bin_centers, hist, **kwargs)
ax = plt.gca()
else:
ax.plot(bin_centers, hist, **kwargs)
ax.set_xscale("log")
ax.set_yscale("log")
return ax
def bisect_map(mn, mx, function, target):
"""
Uses binary search to find the target solution to a function, searching in
a given ordered sequence of integer values.
Parameters
----------
seq : list or array, monotonically increasing integers
function : a function that takes a single integer input, which monotonically
decreases over the range of seq.
target : the target value of the function
Returns
-------
value : the input value that yields the target solution. If there is no
exact solution in the input sequence, finds the nearest value k such that
function(k) <= target < function(k+1). This is similar to the behavior of
bisect_left in the bisect package. If even the first, leftmost value of seq
does not satisfy this condition, -1 is returned.
"""
if function([mn]) < target or function([mx]) > target:
return -1
while 1:
if mx==mn+1:
return mn
m = (mn + mx) / 2
value = function([m])[0]
if value > target:
mn = m
elif value < target:
mx = m
else:
return m
######################
#What follows are functional programming forms of the above code, which are more
#clunky and have somewhat less functionality. However, they are here if your
#really want them.
class Distribution_Fit(object):
def __init__(self, data, name, xmin, discrete=False, xmax=None, method='Likelihood', estimate_discrete=True):
self.data = data
self.discrete = discrete
self.xmin = xmin
self.xmax = xmax
self.method = method
self.name = name
self.estimate_discrete = estimate_discrete
return
def __getattr__(self, name):
param_names = {'lognormal': ('mu', 'sigma', None),
'exponential': ('Lambda', None, None),
'truncated_power_law': ('alpha', 'Lambda', None),
'power_law': ('alpha', None, None),
'negative_binomial': ('r', 'p', None),
'stretched_exponential': ('Lambda', 'beta', None),
'gamma': ('k', 'theta', None)}
param_names = param_names[self.name]
if name in param_names:
if name == param_names[0]:
setattr(self, name, self.parameter1)
elif name == param_names[1]:
setattr(self, name, self.parameter2)
elif name == param_names[2]:
setattr(self, name, self.parameter3)
return getattr(self, name)
elif name in ['parameters',
'parameter1_name',
'parameter1',
'parameter2_name',
'parameter2',
'parameter3_name',
'parameter3',
'loglikelihood']:
self.parameters, self.loglikelihood = distribution_fit(self.data, distribution=self.name, discrete=self.discrete,
xmin=self.xmin, xmax=self.xmax, search_method=self.method, estimate_discrete=self.estimate_discrete)
self.parameter1 = self.parameters[0]
if len(self.parameters) < 2:
self.parameter2 = None
else:
self.parameter2 = self.parameters[1]
if len(self.parameters) < 3:
self.parameter3 = None
else:
self.parameter3 = self.parameters[2]
self.parameter1_name = param_names[0]
self.parameter2_name = param_names[1]
self.parameter3_name = param_names[2]
if name == 'parameters':
return self.parameters
elif name == 'parameter1_name':
return self.parameter1_name
elif name == 'parameter2_name':
return self.parameter2_name
elif name == 'parameter3_name':
return self.parameter3_name
elif name == 'parameter1':
return self.parameter1
elif name == 'parameter2':
return self.parameter2
elif name == 'parameter3':
return self.parameter3
elif name == 'loglikelihood':
return self.loglikelihood
if name == 'D':
if self.name != 'power_law':
self.D = None
else:
self.D = power_law_ks_distance(self.data, self.parameter1, xmin=self.xmin, xmax=self.xmax, discrete=self.discrete)
return self.D
if name == 'p':
print("A p value outside of a loglihood ratio comparison to another candidate distribution is not currently supported.\n \
If your data set is particularly large and has any noise in it at all, using such statistical tools as the Monte Carlo method\n\
can lead to erroneous results anyway; the presence of the noise means the distribution will obviously not perfectly fit the\n\
candidate distribution, and the very large number of samples will make the Monte Carlo simulations very close to a perfect\n\
fit. As such, such a test will always fail, unless your candidate distribution perfectly describes all elements of the\n\
system, including the noise. A more helpful analysis is the comparison between multiple, specific candidate distributions\n\
(the loglikelihood ratio test), which tells you which is the best fit of these distributions.", file=sys.stderr)
self.p = None
return self.p
#
# elif name in ['power_law_loglikelihood_ratio',
# 'power_law_p']:
# pl_R, pl_p = distribution_compare(self.data, 'power_law', self.power_law.parameters, name, self.parameters, self.discrete, self.xmin, self.xmax)
# self.power_law_loglikelihood_ratio = pl_R
# self.power_law_p = pl_p
# if name=='power_law_loglikelihood_ratio':
# return self.power_law_loglikelihood_ratio
# if name=='power_law_p':
# return self.power_law_p
# elif name in ['truncated_power_law_loglikelihood_ratio',
# 'truncated_power_law_p']:
# tpl_R, tpl_p = distribution_compare(self.data, 'truncated_power_law', self.truncated_power_law.parameters, name, self.parameters, self.discrete, self.xmin, self.xmax)
# self.truncated_power_law_loglikelihood_ratio = tpl_R
# self.truncated_power_law_p = tpl_p
# if name=='truncated_power_law_loglikelihood_ratio':
# return self.truncated_power_law_loglikelihood_ratio
# if name=='truncated_power_law_p':
# return self.truncated_power_law_p
else:
raise AttributeError(name)
def distribution_fit(data, distribution='all', discrete=False, xmin=None, xmax=None, \
comparison_alpha=None, search_method='Likelihood', estimate_discrete=True):
from numpy import log
if distribution == 'negative_binomial' and not is_discrete(data):
print("Rounding to integer values for negative binomial fit.", file=sys.stderr)
from numpy import around
data = around(data)
discrete = True
#If we aren't given an xmin, calculate the best possible one for a power law. This can take awhile!
if xmin is None or xmin == 'find' or type(xmin) == tuple or type(xmin) == list:
print("Calculating best minimal value", file=sys.stderr)
if 0 in data:
print("Value 0 in data. Throwing out 0 values", file=sys.stderr)
data = data[data != 0]
xmin, D, alpha, loglikelihood, n_tail, noise_flag = find_xmin(data, discrete=discrete, xmax=xmax, search_method=search_method, estimate_discrete=estimate_discrete, xmin_range=xmin)
else:
alpha = None
if distribution == 'power_law' and alpha:
return [alpha], loglikelihood
xmin = float(xmin)
data = data[data >= xmin]
if xmax:
xmax = float(xmax)
data = data[data <= xmax]
#Special case where we call distribution_fit multiple times to do all comparisons
if distribution == 'all':
print("Analyzing all distributions", file=sys.stderr)
print("Calculating power law fit", file=sys.stderr)
if alpha:
pl_parameters = [alpha]
else:
pl_parameters, loglikelihood = distribution_fit(data, 'power_law', discrete, xmin, xmax, search_method=search_method, estimate_discrete=estimate_discrete)
results = {}
results['xmin'] = xmin
results['xmax'] = xmax
results['discrete'] = discrete
results['fits'] = {}
results['fits']['power_law'] = (pl_parameters, loglikelihood)
print("Calculating truncated power law fit", file=sys.stderr)
tpl_parameters, loglikelihood, R, p = distribution_fit(data, 'truncated_power_law', discrete, xmin, xmax, comparison_alpha=pl_parameters[0], search_method=search_method, estimate_discrete=estimate_discrete)
results['fits']['truncated_power_law'] = (tpl_parameters, loglikelihood)
results['power_law_comparison'] = {}
results['power_law_comparison']['truncated_power_law'] = (R, p)
results['truncated_power_law_comparison'] = {}
supported_distributions = ['exponential', 'lognormal', 'stretched_exponential', 'gamma']
for i in supported_distributions:
print("Calculating %s fit" % (i,), file=sys.stderr)
parameters, loglikelihood, R, p = distribution_fit(data, i, discrete, xmin, xmax, comparison_alpha=pl_parameters[0], search_method=search_method, estimate_discrete=estimate_discrete)
results['fits'][i] = (parameters, loglikelihood)
results['power_law_comparison'][i] = (R, p)
R, p = distribution_compare(data, 'truncated_power_law', tpl_parameters, i, parameters, discrete, xmin, xmax)
results['truncated_power_law_comparison'][i] = (R, p)
return results
#Handle edge case where we don't have enough data
no_data = False
if xmax and all((data > xmax) + (data < xmin)):
#Everything is beyond the bounds of the xmax and xmin
no_data = True
if all(data < xmin):
no_data = True
if len(data) < 2:
no_data = True
if no_data:
from numpy import array
from sys import float_info
parameters = array([0, 0, 0])
if search_method == 'Likelihood':
loglikelihood = -10 ** float_info.max_10_exp
if search_method == 'KS':
loglikelihood = 1
if comparison_alpha is None:
return parameters, loglikelihood
R = 10 ** float_info.max_10_exp
p = 1
return parameters, loglikelihood, R, p
n = float(len(data))
#Initial search parameters, estimated from the data
# print("Calculating initial parameters for search", file=sys.stderr)
if distribution == 'power_law' and not alpha:
initial_parameters = [1 + n / sum(log(data / (xmin)))]
elif distribution == 'exponential':
from numpy import mean
initial_parameters = [1 / mean(data)]
elif distribution == 'stretched_exponential':
from numpy import mean
initial_parameters = [1 / mean(data), 1]
elif distribution == 'truncated_power_law':
from numpy import mean
initial_parameters = [1 + n / sum(log(data / xmin)), 1 / mean(data)]
elif distribution == 'lognormal':
from numpy import mean, std
logdata = log(data)
initial_parameters = [mean(logdata), std(logdata)]
elif distribution == 'negative_binomial':
initial_parameters = [1, .5]
elif distribution == 'gamma':
from numpy import mean
initial_parameters = [n / sum(log(data / xmin)), mean(data)]
if search_method == 'Likelihood':
# print("Searching using maximum likelihood method", file=sys.stderr)
#If the distribution is a continuous power law without an xmax, and we're using the maximum likelihood method, we can compute the parameters and likelihood directly
if distribution == 'power_law' and not discrete and not xmax and not alpha:
from numpy import array, nan
alpha = 1 + n /\
sum(log(data / xmin))
loglikelihood = n * log(alpha - 1.0) - n * log(xmin) - alpha * sum(log(data / xmin))
if loglikelihood == nan:
loglikelihood = 0
parameters = array([alpha])
return parameters, loglikelihood
elif distribution == 'power_law' and discrete and not xmax and not alpha and estimate_discrete:
from numpy import array, nan
alpha = 1 + n /\
sum(log(data / (xmin - .5)))
loglikelihood = n * log(alpha - 1.0) - n * log(xmin) - alpha * sum(log(data / xmin))
if loglikelihood == nan:
loglikelihood = 0
parameters = array([alpha])
return parameters, loglikelihood
#Otherwise, we set up a likelihood function
likelihood_function = likelihood_function_generator(distribution, discrete=discrete, xmin=xmin, xmax=xmax)
#Search for the best fit parameters for the target distribution, on this data
from scipy.optimize import fmin
parameters, negative_loglikelihood, iter, funcalls, warnflag, = \
fmin(
lambda p: -sum(log(likelihood_function(p, data))),
initial_parameters, full_output=1, disp=False)
loglikelihood = -negative_loglikelihood
if comparison_alpha:
R, p = distribution_compare(data, 'power_law', [comparison_alpha], distribution, parameters, discrete, xmin, xmax)
return parameters, loglikelihood, R, p
else:
return parameters, loglikelihood
elif search_method == 'KS':
print("Not yet supported. Sorry.", file=sys.stderr)
return
# #Search for the best fit parameters for the target distribution, on this data
# from scipy.optimize import fmin
# parameters, KS, iter, funcalls, warnflag, = \
# fmin(\
# lambda p: -sum(log(likelihood_function(p, data))),\
# initial_parameters, full_output=1, disp=False)
# loglikelihood =-negative_loglikelihood
#
# if comparison_alpha:
# R, p = distribution_compare(data, 'power_law',[comparison_alpha], distribution, parameters, discrete, xmin, xmax)
# return parameters, loglikelihood, R, p
# else:
# return parameters, loglikelihood
def distribution_compare(data, distribution1, parameters1,
distribution2, parameters2,
discrete, xmin, xmax, nested=None, **kwargs):
no_data = False
if xmax and all((data > xmax) + (data < xmin)):
#Everything is beyond the bounds of the xmax and xmin
no_data = True
if all(data < xmin):
no_data = True
if no_data:
R = 0
p = 1
return R, p
likelihood_function1 = likelihood_function_generator(distribution1, discrete, xmin, xmax)
likelihood_function2 = likelihood_function_generator(distribution2, discrete, xmin, xmax)
likelihoods1 = likelihood_function1(parameters1, data)
likelihoods2 = likelihood_function2(parameters2, data)
if ((distribution1 in distribution2) or
(distribution2 in distribution1)
and nested is None):
print("Assuming nested distributions", file=sys.stderr)
nested = True
from numpy import log
R, p = loglikelihood_ratio(log(likelihoods1), log(likelihoods2),
nested=nested, **kwargs)
return R, p
def likelihood_function_generator(distribution_name, discrete=False, xmin=1, xmax=None):
if distribution_name == 'power_law':
likelihood_function = lambda parameters, data:\
power_law_likelihoods(
data, parameters[0], xmin, xmax, discrete)
elif distribution_name == 'exponential':
likelihood_function = lambda parameters, data:\
exponential_likelihoods(
data, parameters[0], xmin, xmax, discrete)
elif distribution_name == 'stretched_exponential':
likelihood_function = lambda parameters, data:\
stretched_exponential_likelihoods(
data, parameters[0], parameters[1], xmin, xmax, discrete)
elif distribution_name == 'truncated_power_law':
likelihood_function = lambda parameters, data:\
truncated_power_law_likelihoods(
data, parameters[0], parameters[1], xmin, xmax, discrete)
elif distribution_name == 'lognormal':
likelihood_function = lambda parameters, data:\
lognormal_likelihoods(
data, parameters[0], parameters[1], xmin, xmax, discrete)
elif distribution_name == 'negative_binomial':
likelihood_function = lambda parameters, data:\
negative_binomial_likelihoods(
data, parameters[0], parameters[1], xmin, xmax)
elif distribution_name == 'gamma':
likelihood_function = lambda parameters, data:\
gamma_likelihoods(
data, parameters[0], parameters[1], xmin, xmax)
return likelihood_function
def find_xmin(data, discrete=False, xmax=None, search_method='Likelihood', return_all=False, estimate_discrete=True, xmin_range=None):
from numpy import sort, unique, asarray, argmin, vstack, arange, sqrt
if 0 in data:
print("Value 0 in data. Throwing out 0 values", file=sys.stderr)
data = data[data != 0]
if xmax:
data = data[data <= xmax]
#Much of the rest of this function was inspired by Adam Ginsburg's plfit code, specifically around lines 131-143 of this version: http://code.google.com/p/agpy/source/browse/trunk/plfit/plfit.py?spec=svn359&r=357
if not all(data[i] <= data[i + 1] for i in range(len(data) - 1)):
data = sort(data)
if xmin_range == 'find' or xmin_range is None:
possible_xmins = data
else:
possible_xmins = data[data <= max(xmin_range)]
possible_xmins = possible_xmins[possible_xmins >= min(xmin_range)]
xmins, xmin_indices = unique(possible_xmins, return_index=True)
xmins = xmins[:-1]
if len(xmins) < 2:
from sys import float_info
xmin = 1
D = 1
alpha = 0
loglikelihood = -10 ** float_info.max_10_exp
n_tail = 1
noise_flag = True
Ds = 1
alphas = 0
sigmas = 1
if not return_all:
return xmin, D, alpha, loglikelihood, n_tail, noise_flag
else:
return xmin, D, alpha, loglikelihood, n_tail, noise_flag, xmins, Ds, alphas, sigmas
xmin_indices = xmin_indices[:-1] # Don't look at last xmin, as that's also the xmax, and we want to at least have TWO points to fit!
if search_method == 'Likelihood':
alpha_MLE_function = lambda xmin: distribution_fit(data, 'power_law', xmin=xmin, xmax=xmax, discrete=discrete, search_method='Likelihood', estimate_discrete=estimate_discrete)
fits = asarray(list(map(alpha_MLE_function, xmins)))
elif search_method == 'KS':
alpha_KS_function = lambda xmin: distribution_fit(data, 'power_law', xmin=xmin, xmax=xmax, discrete=discrete, search_method='KS', estimate_discrete=estimate_discrete)[0]
fits = asarray(list(map(alpha_KS_function, xmins)))
params = fits[:, 0]
alphas = vstack(params)[:, 0]
loglikelihoods = fits[:, 1]
ks_function = lambda index: power_law_ks_distance(data, alphas[index], xmins[index], xmax=xmax, discrete=discrete)
Ds = asarray(list(map(ks_function, arange(len(xmins)))))
sigmas = (alphas - 1) / sqrt(len(data) - xmin_indices + 1)
good_values = sigmas < .1
#Find the last good value (The first False, where sigma > .1):
xmin_max = argmin(good_values)
if good_values.all(): # If there are no fits beyond the noise threshold
min_D_index = argmin(Ds)
noise_flag = False
elif xmin_max > 0:
min_D_index = argmin(Ds[:xmin_max])
noise_flag = False
else:
min_D_index = argmin(Ds)
noise_flag = True
xmin = xmins[min_D_index]
D = Ds[min_D_index]
alpha = alphas[min_D_index]
loglikelihood = loglikelihoods[min_D_index]
n_tail = sum(data >= xmin)
if not return_all:
return xmin, D, alpha, loglikelihood, n_tail, noise_flag
else:
return xmin, D, alpha, loglikelihood, n_tail, noise_flag, xmins, Ds, alphas, sigmas
def power_law_ks_distance(data, alpha, xmin, xmax=None, discrete=False, kuiper=False):
from numpy import arange, sort, mean
data = data[data >= xmin]
if xmax:
data = data[data <= xmax]
n = float(len(data))
if n < 2:
if kuiper:
return 1, 1, 2
return 1
if not all(data[i] <= data[i + 1] for i in arange(n - 1)):
data = sort(data)
if not discrete:
Actual_CDF = arange(n) / n
Theoretical_CDF = 1 - (data / xmin) ** (-alpha + 1)
if discrete:
from scipy.special import zeta
if xmax:
bins, Actual_CDF = cumulative_distribution_function(data,xmin=xmin,xmax=xmax)
Theoretical_CDF = 1 - ((zeta(alpha, bins) - zeta(alpha, xmax+1)) /\
(zeta(alpha, xmin)-zeta(alpha,xmax+1)))
if not xmax:
bins, Actual_CDF = cumulative_distribution_function(data,xmin=xmin)
Theoretical_CDF = 1 - (zeta(alpha, bins) /\
zeta(alpha, xmin))
D_plus = max(Theoretical_CDF - Actual_CDF)
D_minus = max(Actual_CDF - Theoretical_CDF)
Kappa = 1 + mean(Theoretical_CDF - Actual_CDF)
if kuiper:
return D_plus, D_minus, Kappa
D = max(D_plus, D_minus)
return D
def power_law_likelihoods(data, alpha, xmin, xmax=False, discrete=False):
if alpha < 0:
from numpy import tile
from sys import float_info
return tile(10 ** float_info.min_10_exp, len(data))
xmin = float(xmin)
data = data[data >= xmin]
if xmax:
data = data[data <= xmax]
if not discrete:
likelihoods = (data ** -alpha) *\
((alpha - 1) * xmin ** (alpha - 1))
if discrete:
if alpha < 1:
from numpy import tile
from sys import float_info
return tile(10 ** float_info.min_10_exp, len(data))
if not xmax:
from scipy.special import zeta
likelihoods = (data ** -alpha) /\
zeta(alpha, xmin)
if xmax:
from scipy.special import zeta
likelihoods = (data ** -alpha) /\
(zeta(alpha, xmin) - zeta(alpha, xmax + 1))
from sys import float_info
likelihoods[likelihoods == 0] = 10 ** float_info.min_10_exp
return likelihoods
def negative_binomial_likelihoods(data, r, p, xmin=0, xmax=False):
#Better to make this correction earlier on in distribution_fit, so as to not recheck for discreteness and reround every time fmin is used.
#if not is_discrete(data):
# print("Rounding to nearest integer values for negative binomial fit.", file=sys.stderr)
# from numpy import around
# data = around(data)
xmin = float(xmin)
data = data[data >= xmin]
if xmax:
data = data[data <= xmax]
from numpy import asarray
from scipy.misc import comb
pmf = lambda k: comb(k + r - 1, k) * (1 - p) ** r * p ** k
likelihoods = asarray(list(map(pmf, data))).flatten()
if xmin != 0 or xmax:
xmax = max(data)
from numpy import arange
normalization_constant = sum(list(map(pmf, arange(xmin, xmax + 1))))
likelihoods = likelihoods / normalization_constant
from sys import float_info
likelihoods[likelihoods == 0] = 10 ** float_info.min_10_exp
return likelihoods
def exponential_likelihoods(data, Lambda, xmin, xmax=False, discrete=False):
if Lambda < 0:
from numpy import tile
from sys import float_info
return tile(10 ** float_info.min_10_exp, len(data))
data = data[data >= xmin]
if xmax:
data = data[data <= xmax]
from numpy import exp
if not discrete:
# likelihoods = exp(-Lambda*data)*\
# Lambda*exp(Lambda*xmin)
likelihoods = Lambda * exp(Lambda * (xmin - data)) # Simplified so as not to throw a nan from infs being divided by each other
if discrete:
if not xmax:
likelihoods = exp(-Lambda * data) *\
(1 - exp(-Lambda)) * exp(Lambda * xmin)
if xmax:
likelihoods = exp(-Lambda * data) * (1 - exp(-Lambda))\
/ (exp(-Lambda * xmin) - exp(-Lambda * (xmax + 1)))
from sys import float_info
likelihoods[likelihoods == 0] = 10 ** float_info.min_10_exp
return likelihoods
def stretched_exponential_likelihoods(data, Lambda, beta, xmin, xmax=False, discrete=False):
if Lambda < 0:
from numpy import tile
from sys import float_info
return tile(10 ** float_info.min_10_exp, len(data))
data = data[data >= xmin]
if xmax:
data = data[data <= xmax]
from numpy import exp
if not discrete:
# likelihoods = (data**(beta-1) * exp(-Lambda*(data**beta)))*\
# (beta*Lambda*exp(Lambda*(xmin**beta)))
likelihoods = data ** (beta - 1) * beta * Lambda * exp(Lambda * (xmin ** beta - data ** beta)) # Simplified so as not to throw a nan from infs being divided by each other
if discrete:
if not xmax:
xmax = max(data)
if xmax:
from numpy import arange
X = arange(xmin, xmax + 1)
PDF = X ** (beta - 1) * beta * Lambda * exp(Lambda * (xmin ** beta - X ** beta)) # Simplified so as not to throw a nan from infs being divided by each other
PDF = PDF / sum(PDF)
likelihoods = PDF[(data - xmin).astype(int)]
from sys import float_info
likelihoods[likelihoods == 0] = 10 ** float_info.min_10_exp
return likelihoods
def gamma_likelihoods(data, k, theta, xmin, xmax=False, discrete=False):
if k <= 0 or theta <= 0:
from numpy import tile
from sys import float_info
return tile(10 ** float_info.min_10_exp, len(data))
data = data[data >= xmin]
if xmax:
data = data[data <= xmax]
from numpy import exp
from mpmath import gammainc
# from scipy.special import gamma, gammainc #Not NEARLY numerically accurate enough for the job
if not discrete:
likelihoods = (data ** (k - 1)) / (exp(data / theta) * (theta ** k) * float(gammainc(k)))
#Calculate how much probability mass is beyond xmin, and normalize by it
normalization_constant = 1 - float(gammainc(k, 0, xmin / theta, regularized=True)) # Mpmath's regularized option divides by gamma(k)
likelihoods = likelihoods / normalization_constant
if discrete:
if not xmax:
xmax = max(data)
if xmax:
from numpy import arange
X = arange(xmin, xmax + 1)
PDF = (X ** (k - 1)) / (exp(X / theta) * (theta ** k) * float(gammainc(k)))
PDF = PDF / sum(PDF)
likelihoods = PDF[(data - xmin).astype(int)]
from sys import float_info
likelihoods[likelihoods == 0] = 10 ** float_info.min_10_exp
return likelihoods
def truncated_power_law_likelihoods(data, alpha, Lambda, xmin, xmax=False, discrete=False):
if alpha < 0 or Lambda < 0:
from numpy import tile
from sys import float_info
return tile(10 ** float_info.min_10_exp, len(data))
data = data[data >= xmin]
if xmax:
data = data[data <= xmax]
from numpy import exp
if not discrete:
from mpmath import gammainc
# from scipy.special import gamma, gammaincc #Not NEARLY accurate enough to do the job
# likelihoods = (data**-alpha)*exp(-Lambda*data)*\
# (Lambda**(1-alpha))/\
# float(gammaincc(1-alpha,Lambda*xmin))
#Simplified so as not to throw a nan from infs being divided by each other
likelihoods = (Lambda ** (1 - alpha)) /\
((data ** alpha) * exp(Lambda * data) * gammainc(1 - alpha, Lambda * xmin)).astype(float)
if discrete:
if not xmax:
xmax = max(data)
if xmax:
from numpy import arange
X = arange(xmin, xmax + 1)
PDF = (X ** -alpha) * exp(-Lambda * X)
PDF = PDF / sum(PDF)
likelihoods = PDF[(data - xmin).astype(int)]
from sys import float_info
likelihoods[likelihoods == 0] = 10 ** float_info.min_10_exp
return likelihoods
def lognormal_likelihoods(data, mu, sigma, xmin, xmax=False, discrete=False):
from numpy import log
if sigma <= 0 or mu < log(xmin):
#The standard deviation can't be negative, and the mean of the logarithm of the distribution can't be smaller than the log of the smallest member of the distribution!
from numpy import tile
from sys import float_info
return tile(10 ** float_info.min_10_exp, len(data))
data = data[data >= xmin]
if xmax:
data = data[data <= xmax]
if not discrete:
from numpy import sqrt, exp
# from mpmath import erfc
from scipy.special import erfc
from scipy.constants import pi
likelihoods = (1.0 / data) * exp(-((log(data) - mu) ** 2) / (2 * sigma ** 2)) *\
sqrt(2 / (pi * sigma ** 2)) / erfc((log(xmin) - mu) / (sqrt(2) * sigma))
# likelihoods = likelihoods.astype(float)
if discrete:
if not xmax:
xmax = max(data)
if xmax:
from numpy import arange, exp
# from mpmath import exp
X = arange(xmin, xmax + 1)
# PDF_function = lambda x: (1.0/x)*exp(-( (log(x) - mu)**2 ) / 2*sigma**2)
# PDF = asarray(list(map(PDF_function,X)))
PDF = (1.0 / X) * exp(-((log(X) - mu) ** 2) / (2 * (sigma ** 2)))
PDF = (PDF / sum(PDF)).astype(float)
likelihoods = PDF[(data - xmin).astype(int)]
from sys import float_info
likelihoods[likelihoods == 0] = 10 ** float_info.min_10_exp
return likelihoods
|
gpl-3.0
|
[
3,
1918,
10697,
844,
334,
13965,
9,
199,
3,
199,
3,
7384,
334,
67,
9,
6171,
1603,
3609,
4580,
270,
357,
84,
199,
3,
199,
3,
7980,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
1331,
199,
3,
1618,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
298,
10337,
1288,
370,
7962,
199,
3,
262,
314,
2290,
1928,
10588,
12,
5893,
1928,
12305,
314,
4481,
199,
3,
475,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
11207,
12,
13473,
12,
436,
15,
269,
12743,
199,
3,
16847,
402,
314,
2290,
12,
436,
370,
11291,
12103,
370,
12676,
314,
2290,
365,
199,
3,
70,
13399,
370,
886,
880,
12,
5420,
370,
314,
2569,
3704,
26,
199,
3,
199,
3,
1918,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
315,
199,
3,
452,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
18061,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
1549,
199,
3,
8947,
5177,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
3169,
12,
199,
3,
38,
3061,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
7000,
2334,
199,
3,
5580,
4149,
1549,
5877,
8164,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
199,
3,
2673,
2477,
12,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
199,
3,
1877,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
199,
3,
18061,
4141,
14,
199,
199,
3,
465,
11736,
315,
4178,
921,
4757,
14,
1548,
14,
1308,
15,
18,
15,
4342,
15,
5777,
14,
1360,
3,
1361,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
646,
984,
199,
199,
363,
1023,
363,
275,
298,
17,
14,
19,
14,
20,
2,
199,
199,
533,
25971,
8,
785,
304,
272,
408,
272,
437,
5542,
402,
282,
666,
663,
370,
7750,
12224,
10208,
12,
536,
590,
7074,
272,
1127,
3569,
14,
2104,
20147,
370,
7074,
1127,
3569,
12,
314,
3102,
402,
24433,
29589,
10844,
741,
14,
10219,
787,
1202,
14,
272,
5723,
3102,
10405,
314,
18046,
402,
314,
9483,
402,
314,
4084,
626,
272,
11924,
282,
7074,
4179,
12,
20561,
282,
574,
22036,
14,
982,
949,
22036,
365,
272,
2741,
12,
314,
22081,
1373,
365,
12950,
436,
7943,
737,
11097,
14,
339,
3897,
272,
4143,
272,
666,
520,
769,
503,
1625,
272,
24635,
520,
5046,
12,
2716,
267,
7480,
314,
666,
365,
24635,
334,
23931,
680,
272,
22036,
520,
1109,
503,
2069,
12,
2716,
267,
710,
666,
574,
20561,
1314,
10208,
1077,
506,
26093,
14,
982,
267,
488,
376,
22081,
1373,
911,
506,
12950,
14,
272,
19906,
520,
1109,
503,
2069,
12,
2716,
267,
710,
5696,
574,
402,
314,
26093,
10208,
14,
272,
14497,
63,
23591,
520,
2155,
12,
2716,
267,
7480,
370,
14497,
314,
5542,
402,
282,
24635,
7074,
4179,
1808,
7377,
267,
5909,
3294,
3102,
12,
3140,
402,
26079,
314,
5542,
8840,
543,
267,
11999,
15470,
3102,
14,
812,
994,
23189,
543,
22036,
30,
22,
272,
10819,
63,
7227,
520,
2069,
12,
2716,
267,
4949,
529,
2304,
641,
314,
4465,
1125,
402,
314,
7074,
4179,
5542,
14,
8051,
2410,
267,
21774,
12,
1380,
21119,
1686,
22036,
1338,
14,
272,
2725,
63,
1842,
520,
1211,
12,
2716,
267,
11932,
402,
1686,
2725,
12271,
367,
21774,
14,
9701,
471,
465,
282,
267,
2600,
402,
2725,
1561,
661,
4468,
7,
436,
15,
269,
283,
9412,
358,
436,
6346,
267,
402,
3932,
5117,
436,
7008,
10976,
334,
476,
14,
334,
17,
14,
21,
12,
499,
14,
21,
395,
334,
403,
12,
1275,
17,
9,
272,
408,
339,
347,
636,
826,
721,
277,
12,
666,
12,
326,
24635,
29,
797,
12,
326,
22036,
29,
403,
12,
19906,
29,
403,
12,
326,
5542,
63,
765,
534,
12545,
12761,
297,
326,
14497,
63,
23591,
29,
549,
12,
326,
24635,
63,
11227,
20030,
534,
2363,
297,
326,
10819,
63,
7227,
29,
403,
12,
326,
2725,
63,
1842,
29,
403,
12,
326,
5542,
63,
12290,
29,
403,
12,
326,
22036,
63,
5590,
534,
36,
297,
326,
1011,
958,
304,
398,
291,
14,
576,
63,
5043,
275,
666,
267,
327,
492,
2050,
267,
687,
2680,
492,
24144,
267,
291,
14,
576,
275,
24144,
8,
277,
14,
576,
63,
5043,
12,
2152,
534,
1609,
358,
398,
291,
14,
23591,
275,
24635,
398,
291,
14,
3269,
63,
765,
275,
5542,
63,
765,
267,
291,
14,
21196,
63,
23591,
275,
14497,
63,
23591,
267,
291,
14,
23591,
63,
11227,
20030,
275,
24635,
63,
11227,
20030,
267,
291,
14,
9412,
63,
7227,
275,
10819,
63,
7227,
267,
291,
14,
5329,
63,
1842,
275,
2725,
63,
1842,
398,
291,
14,
11809,
63,
21601,
275,
22036,
267,
291,
14,
11809,
63,
28961,
275,
19906,
267,
291,
14,
21601,
275,
291,
14,
11809,
63,
21601,
267,
291,
14,
28961,
275,
291,
14,
11809,
63,
28961,
398,
291,
14,
21601,
63,
5590,
275,
22036,
63,
5590,
398,
340,
378,
315,
291,
14,
576,
26,
288,
870,
480,
6550,
6656,
2419,
503,
4472,
370,
378,
315,
666,
14,
3868,
1143,
316,
734,
378,
503,
6946,
1338,
401,
570,
29,
1274,
14,
3083,
9,
288,
291,
14,
576,
275,
291,
14,
576,
59,
277,
14,
576,
30,
16,
61,
398,
340,
291,
14,
28961,
26,
288,
291,
14,
28961,
275,
2069,
8,
277,
14,
28961,
9,
288,
291,
14,
5964,
63,
28961,
275,
715,
288,
302,
63,
16181,
63,
988,
275,
3089,
8,
277,
14,
576,
30,
277,
14,
28961,
9,
288,
291,
14,
576,
275,
291,
14,
576,
59,
277,
14,
576,
12932,
277,
14,
28961,
61,
267,
587,
26,
288,
302,
63,
16181,
63,
988,
275,
378,
288,
291,
14,
5964,
63,
28961,
275,
756,
398,
340,
440,
1006,
8,
277,
14,
576,
59,
73,
61,
2695,
291,
14,
576,
59,
73,
11,
17,
61,
367,
284,
315,
1425,
8,
552,
8,
277,
14,
576,
7216,
17,
2298,
288,
687,
2680,
492,
4069,
288,
291,
14,
576,
275,
4069,
8,
277,
14,
576,
9,
398,
291,
14,
3269,
1337,
63,
10790,
63,
11329,
12,
291,
14,
3269,
1337,
63,
10790,
275,
26037,
8,
277,
14,
576,
12,
22036,
29
] |
[
1918,
10697,
844,
334,
13965,
9,
199,
3,
199,
3,
7384,
334,
67,
9,
6171,
1603,
3609,
4580,
270,
357,
84,
199,
3,
199,
3,
7980,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
1331,
199,
3,
1618,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
298,
10337,
1288,
370,
7962,
199,
3,
262,
314,
2290,
1928,
10588,
12,
5893,
1928,
12305,
314,
4481,
199,
3,
475,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
11207,
12,
13473,
12,
436,
15,
269,
12743,
199,
3,
16847,
402,
314,
2290,
12,
436,
370,
11291,
12103,
370,
12676,
314,
2290,
365,
199,
3,
70,
13399,
370,
886,
880,
12,
5420,
370,
314,
2569,
3704,
26,
199,
3,
199,
3,
1918,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
315,
199,
3,
452,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
18061,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
1549,
199,
3,
8947,
5177,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
3169,
12,
199,
3,
38,
3061,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
7000,
2334,
199,
3,
5580,
4149,
1549,
5877,
8164,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
199,
3,
2673,
2477,
12,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
199,
3,
1877,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
199,
3,
18061,
4141,
14,
199,
199,
3,
465,
11736,
315,
4178,
921,
4757,
14,
1548,
14,
1308,
15,
18,
15,
4342,
15,
5777,
14,
1360,
3,
1361,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
646,
984,
199,
199,
363,
1023,
363,
275,
298,
17,
14,
19,
14,
20,
2,
199,
199,
533,
25971,
8,
785,
304,
272,
408,
272,
437,
5542,
402,
282,
666,
663,
370,
7750,
12224,
10208,
12,
536,
590,
7074,
272,
1127,
3569,
14,
2104,
20147,
370,
7074,
1127,
3569,
12,
314,
3102,
402,
24433,
29589,
10844,
741,
14,
10219,
787,
1202,
14,
272,
5723,
3102,
10405,
314,
18046,
402,
314,
9483,
402,
314,
4084,
626,
272,
11924,
282,
7074,
4179,
12,
20561,
282,
574,
22036,
14,
982,
949,
22036,
365,
272,
2741,
12,
314,
22081,
1373,
365,
12950,
436,
7943,
737,
11097,
14,
339,
3897,
272,
4143,
272,
666,
520,
769,
503,
1625,
272,
24635,
520,
5046,
12,
2716,
267,
7480,
314,
666,
365,
24635,
334,
23931,
680,
272,
22036,
520,
1109,
503,
2069,
12,
2716,
267,
710,
666,
574,
20561,
1314,
10208,
1077,
506,
26093,
14,
982,
267,
488,
376,
22081,
1373,
911,
506,
12950,
14,
272,
19906,
520,
1109,
503,
2069,
12,
2716,
267,
710,
5696,
574,
402,
314,
26093,
10208,
14,
272,
14497,
63,
23591,
520,
2155,
12,
2716,
267,
7480,
370,
14497,
314,
5542,
402,
282,
24635,
7074,
4179,
1808,
7377,
267,
5909,
3294,
3102,
12,
3140,
402,
26079,
314,
5542,
8840,
543,
267,
11999,
15470,
3102,
14,
812,
994,
23189,
543,
22036,
30,
22,
272,
10819,
63,
7227,
520,
2069,
12,
2716,
267,
4949,
529,
2304,
641,
314,
4465,
1125,
402,
314,
7074,
4179,
5542,
14,
8051,
2410,
267,
21774,
12,
1380,
21119,
1686,
22036,
1338,
14,
272,
2725,
63,
1842,
520,
1211,
12,
2716,
267,
11932,
402,
1686,
2725,
12271,
367,
21774,
14,
9701,
471,
465,
282,
267,
2600,
402,
2725,
1561,
661,
4468,
7,
436,
15,
269,
283,
9412,
358,
436,
6346,
267,
402,
3932,
5117,
436,
7008,
10976,
334,
476,
14,
334,
17,
14,
21,
12,
499,
14,
21,
395,
334,
403,
12,
1275,
17,
9,
272,
408,
339,
347,
636,
826,
721,
277,
12,
666,
12,
326,
24635,
29,
797,
12,
326,
22036,
29,
403,
12,
19906,
29,
403,
12,
326,
5542,
63,
765,
534,
12545,
12761,
297,
326,
14497,
63,
23591,
29,
549,
12,
326,
24635,
63,
11227,
20030,
534,
2363,
297,
326,
10819,
63,
7227,
29,
403,
12,
326,
2725,
63,
1842,
29,
403,
12,
326,
5542,
63,
12290,
29,
403,
12,
326,
22036,
63,
5590,
534,
36,
297,
326,
1011,
958,
304,
398,
291,
14,
576,
63,
5043,
275,
666,
267,
327,
492,
2050,
267,
687,
2680,
492,
24144,
267,
291,
14,
576,
275,
24144,
8,
277,
14,
576,
63,
5043,
12,
2152,
534,
1609,
358,
398,
291,
14,
23591,
275,
24635,
398,
291,
14,
3269,
63,
765,
275,
5542,
63,
765,
267,
291,
14,
21196,
63,
23591,
275,
14497,
63,
23591,
267,
291,
14,
23591,
63,
11227,
20030,
275,
24635,
63,
11227,
20030,
267,
291,
14,
9412,
63,
7227,
275,
10819,
63,
7227,
267,
291,
14,
5329,
63,
1842,
275,
2725,
63,
1842,
398,
291,
14,
11809,
63,
21601,
275,
22036,
267,
291,
14,
11809,
63,
28961,
275,
19906,
267,
291,
14,
21601,
275,
291,
14,
11809,
63,
21601,
267,
291,
14,
28961,
275,
291,
14,
11809,
63,
28961,
398,
291,
14,
21601,
63,
5590,
275,
22036,
63,
5590,
398,
340,
378,
315,
291,
14,
576,
26,
288,
870,
480,
6550,
6656,
2419,
503,
4472,
370,
378,
315,
666,
14,
3868,
1143,
316,
734,
378,
503,
6946,
1338,
401,
570,
29,
1274,
14,
3083,
9,
288,
291,
14,
576,
275,
291,
14,
576,
59,
277,
14,
576,
30,
16,
61,
398,
340,
291,
14,
28961,
26,
288,
291,
14,
28961,
275,
2069,
8,
277,
14,
28961,
9,
288,
291,
14,
5964,
63,
28961,
275,
715,
288,
302,
63,
16181,
63,
988,
275,
3089,
8,
277,
14,
576,
30,
277,
14,
28961,
9,
288,
291,
14,
576,
275,
291,
14,
576,
59,
277,
14,
576,
12932,
277,
14,
28961,
61,
267,
587,
26,
288,
302,
63,
16181,
63,
988,
275,
378,
288,
291,
14,
5964,
63,
28961,
275,
756,
398,
340,
440,
1006,
8,
277,
14,
576,
59,
73,
61,
2695,
291,
14,
576,
59,
73,
11,
17,
61,
367,
284,
315,
1425,
8,
552,
8,
277,
14,
576,
7216,
17,
2298,
288,
687,
2680,
492,
4069,
288,
291,
14,
576,
275,
4069,
8,
277,
14,
576,
9,
398,
291,
14,
3269,
1337,
63,
10790,
63,
11329,
12,
291,
14,
3269,
1337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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
cyiops/easybuild-easyblocks
|
easybuild/easyblocks/s/samtools.py
|
2
|
5782
|
##
# This file is an EasyBuild reciPY as per https://github.com/easybuilders/easybuild
#
# Copyright:: Copyright 2012-2018 Uni.Lu/LCSB, NTUA
# Authors:: Cedric Laczny <cedric.laczny@uni.lu>, Fotis Georgatos <fotis@cern.ch>, Kenneth Hoste
# License:: MIT/GPL
# $Id$
#
# This work implements a part of the HPCBIOS project and is a component of the policy:
# http://hpcbios.readthedocs.org/en/latest/HPCBIOS_2012-94.html
##
"""
EasyBuild support for building SAMtools (SAM - Sequence Alignment/Map), implemented as an easyblock
@author: Cedric Laczny (Uni.Lu)
@author: Fotis Georgatos (Uni.Lu)
@author: Kenneth Hoste (Ghent University)
"""
from distutils.version import LooseVersion
import os
import shutil
import stat
from easybuild.easyblocks.generic.configuremake import ConfigureMake
from easybuild.tools.build_log import EasyBuildError
from easybuild.tools.filetools import adjust_permissions, copy_file
class EB_SAMtools(ConfigureMake):
"""
Support for building SAMtools; SAM (Sequence Alignment/Map) format
is a generic format for storing large nucleotide sequence alignments.
"""
def __init__(self, *args, **kwargs):
"""Define lists of files to install."""
super(EB_SAMtools, self).__init__(*args, **kwargs)
self.bin_files = ["misc/blast2sam.pl",
"misc/bowtie2sam.pl", "misc/export2sam.pl", "misc/interpolate_sam.pl",
"misc/novo2sam.pl", "misc/psl2sam.pl", "misc/sam2vcf.pl", "misc/samtools.pl",
"misc/soap2sam.pl", "misc/varfilter.py", "misc/wgsim_eval.pl",
"misc/zoom2sam.pl", "misc/md5sum-lite", "misc/md5fa", "misc/maq2sam-short",
"misc/maq2sam-long", "misc/wgsim", "samtools"]
self.include_files = ["bam.h", "bam2bcf.h", "bam_endian.h",
"sam.h", "sam_header.h", "sample.h"]
if LooseVersion(self.version) == LooseVersion('0.1.18'):
# seqtk is no longer there in v0.1.19 and seqtk is not in 0.1.17
self.bin_files += ["misc/seqtk"]
elif LooseVersion(self.version) >= LooseVersion('0.1.19'):
# new tools in v0.1.19
self.bin_files += ["misc/ace2sam", "misc/r2plot.lua",
"misc/vcfutils.lua"]
if LooseVersion(self.version) >= LooseVersion('0.1.19') and LooseVersion(self.version) < LooseVersion('1.0'):
self.bin_files += ["misc/bamcheck", "misc/plot-bamcheck"]
if LooseVersion(self.version) < LooseVersion('1.0'):
self.bin_files += ["bcftools/vcfutils.pl", "bcftools/bcftools"]
self.include_files += [ "bgzf.h", "faidx.h", "khash.h", "klist.h", "knetfile.h", "razf.h",
"kseq.h", "ksort.h", "kstring.h"]
elif LooseVersion(self.version) >= LooseVersion('1.0'):
self.bin_files += ["misc/plot-bamstats","misc/seq_cache_populate.pl"]
if LooseVersion(self.version) < LooseVersion('1.2'):
# kaln aligner removed in 1.2 (commit 19c9f6)
self.include_files += ["kaln.h"]
if LooseVersion(self.version) < LooseVersion('1.4'):
# errmod.h and kprobaln.h removed from 1.4
self.include_files += ["errmod.h", "kprobaln.h"]
self.lib_files = ["libbam.a"]
def configure_step(self):
"""Ensure correct compiler command & flags are used via arguments to 'make' build command"""
for var in ['CC', 'CXX', 'CFLAGS', 'CXXFLAGS']:
if var in os.environ:
self.cfg.update('buildopts', '%s="%s"' % (var, os.getenv(var)))
# configuring with --prefix only supported with v1.3 and more recent
if LooseVersion(self.version) >= LooseVersion('1.3'):
super(EB_SAMtools, self).configure_step()
def install_step(self):
"""
Install by copying files to install dir
"""
install_files = [
('include/bam', self.include_files),
('lib', self.lib_files),
]
# v1.3 and more recent supports 'make install', but this only installs (some of) the binaries...
if LooseVersion(self.version) >= LooseVersion('1.3'):
super(EB_SAMtools, self).install_step()
# figure out which bin files are missing, and try copying them
missing_bin_files = []
for binfile in self.bin_files:
if not os.path.exists(os.path.join(self.installdir, 'bin', os.path.basename(binfile))):
missing_bin_files.append(binfile)
install_files.append(('bin', missing_bin_files))
else:
# copy binaries manually for older versions
install_files.append(('bin', self.bin_files))
self.log.debug("Installing files by copying them 'manually': %s", install_files)
for (destdir, files) in install_files:
for fn in files:
dest = os.path.join(self.installdir, destdir, os.path.basename(fn))
copy_file(os.path.join(self.cfg['start_dir'], fn), dest)
# enable r-x permissions for group/others
perms = stat.S_IRGRP|stat.S_IXGRP|stat.S_IROTH|stat.S_IXOTH
adjust_permissions(self.installdir, perms, add=True, recursive=True)
def sanity_check_step(self):
"""Custom sanity check for SAMtools."""
custom_paths = {
'files': [os.path.join('bin', os.path.basename(f)) for f in self.bin_files] +
[os.path.join('include', 'bam', f) for f in self.include_files] +
[os.path.join('lib', f) for f in self.lib_files],
'dirs': []
}
super(EB_SAMtools, self).sanity_check_step(custom_paths=custom_paths)
|
gpl-2.0
|
[
309,
199,
3,
961,
570,
365,
376,
30025,
295,
559,
4521,
465,
1126,
4178,
921,
5031,
14,
957,
15,
13581,
20968,
15,
13581,
1506,
199,
3,
199,
3,
1898,
447,
1898,
6029,
13,
12682,
1910,
73,
14,
18176,
15,
44,
3298,
34,
12,
653,
21364,
33,
199,
3,
6642,
447,
257,
445,
379,
1567,
491,
645,
90,
9745,
665,
6867,
1567,
14,
416,
16823,
9745,
32,
5411,
14,
10836,
6244,
481,
79,
16753,
5346,
1308,
292,
736,
665,
545,
16753,
32,
22082,
14,
335,
6244,
1804,
287,
685,
273,
869,
736,
266,
199,
3,
844,
447,
257,
10697,
15,
12006,
199,
3,
2672,
1304,
4,
199,
3,
199,
3,
961,
1736,
9031,
282,
1777,
402,
314,
869,
4222,
34,
13532,
2199,
436,
365,
282,
3931,
402,
314,
4592,
26,
199,
3,
1455,
921,
72,
2352,
29673,
14,
25085,
14,
1308,
15,
287,
15,
7410,
15,
40,
4222,
34,
13532,
63,
7409,
13,
2635,
14,
1360,
199,
309,
199,
624,
199,
28326,
3425,
2291,
367,
10015,
428,
1156,
2537,
334,
51,
1156,
446,
10975,
15170,
784,
434,
15,
2956,
395,
6366,
465,
376,
8837,
1457,
199,
199,
32,
2502,
26,
445,
379,
1567,
491,
645,
90,
9745,
334,
27921,
14,
18176,
9,
199,
32,
2502,
26,
481,
79,
16753,
5346,
1308,
292,
736,
334,
27921,
14,
18176,
9,
199,
32,
2502,
26,
1804,
287,
685,
273,
869,
736,
266,
334,
39,
72,
484,
15904,
9,
199,
624,
199,
504,
7065,
14,
1023,
492,
18462,
199,
646,
747,
199,
646,
5145,
199,
646,
5672,
199,
199,
504,
8837,
1506,
14,
13581,
4166,
14,
6767,
14,
6472,
1875,
492,
15453,
5483,
199,
504,
8837,
1506,
14,
2537,
14,
1506,
63,
793,
492,
30025,
547,
199,
504,
8837,
1506,
14,
2537,
14,
493,
2537,
492,
11311,
63,
6060,
12,
1331,
63,
493,
199,
199,
533,
662,
34,
63,
51,
1156,
2537,
8,
17324,
5483,
304,
272,
408,
272,
12502,
367,
10015,
428,
1156,
2537,
27,
428,
1156,
334,
5826,
15170,
784,
434,
15,
2956,
9,
1475,
272,
365,
282,
7809,
1475,
367,
16915,
7031,
302,
947,
274,
79,
280,
271,
3414,
6998,
1470,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
408,
16213,
5548,
402,
1584,
370,
3907,
1041,
267,
1613,
8,
14138,
63,
51,
1156,
2537,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
398,
291,
14,
1393,
63,
1725,
275,
2097,
9923,
15,
66,
2019,
18,
21660,
14,
1168,
401,
2079,
298,
9923,
15,
22856,
23958,
18,
21660,
14,
1168,
401,
298,
9923,
15,
3790,
18,
21660,
14,
1168,
401,
298,
9923,
15,
21294,
63,
21660,
14,
1168,
401,
2079,
298,
9923,
15,
889,
2392,
18,
21660,
14,
1168,
401,
298,
9923,
15,
1190,
76,
18,
21660,
14,
1168,
401,
298,
9923,
15,
21660,
18,
27288,
14,
1168,
401,
298,
9923,
15,
21660,
2537,
14,
1168,
401,
2079,
298,
9923,
15,
21818,
18,
21660,
14,
1168,
401,
298,
9923,
15,
1391,
1541,
14,
647,
401,
298,
9923,
15,
23596,
5206,
63,
2579,
14,
1168,
401,
2079,
298,
9923,
15,
10598,
18,
21660,
14,
1168,
401,
298,
9923,
15,
1064,
21,
1838,
13,
5333,
401,
298,
9923,
15,
1064,
21,
667,
401,
298,
9923,
15,
391,
81,
18,
21660,
13,
3612,
401,
2079,
298,
9923,
15,
391,
81,
18,
21660,
13,
2809,
401,
298,
9923,
15,
23596,
5206,
401,
298,
21660,
2537,
937,
398,
291,
14,
2613,
63,
1725,
275,
2097,
21112,
14,
72,
401,
298,
21112,
18,
66,
2177,
14,
72,
401,
298,
21112,
63,
15009,
14,
72,
401,
221,
2892,
298,
21660,
14,
72,
401,
298,
21660,
63,
1291,
14,
72,
401,
298,
3271,
14,
72,
937,
398,
340,
18462,
8,
277,
14,
1023,
9,
508,
18462,
360,
16,
14,
17,
14,
1085,
735,
288,
327,
5412,
2663,
365,
949,
8088,
2337,
315,
373,
16,
14,
17,
14,
1167,
436,
5412,
2663,
365,
440,
315,
378,
14,
17,
14,
1196,
288,
291,
14,
1393,
63,
1725,
847,
2097,
9923,
15,
3610,
2663,
937,
267,
916,
18462,
8,
277,
14,
1023,
9,
2356,
18462,
360,
16,
14,
17,
14,
1167,
735,
288,
327,
892,
7249,
315,
373,
16,
14,
17,
14,
1167,
288,
291,
14,
1393,
63,
1725,
847,
2097,
9923,
15,
7984,
18,
21660,
401,
298,
9923,
15,
82,
18,
2798,
14,
76,
1458,
401,
3044,
298,
9923,
15,
27288,
1208,
14,
76,
1458,
937,
398,
340,
18462,
8,
277,
14,
1023,
9,
2356,
18462,
360,
16,
14,
17,
14,
1167,
358,
436,
18462,
8,
277,
14,
1023,
9,
665,
18462,
360,
17,
14,
16,
735,
288,
291,
14,
1393,
63,
1725,
847,
2097,
9923,
15,
21112,
1074,
401,
298,
9923,
15,
2798,
13,
21112,
1074,
937,
398,
340,
18462,
8,
277,
14,
1023,
9,
665,
18462,
360,
17,
14,
16,
735,
288,
291,
14,
1393,
63,
1725,
847,
2097,
66,
2177,
2537,
15,
27288,
1208,
14,
1168,
401,
298,
66,
2177,
2537,
15,
66,
2177,
2537,
937,
288,
291,
14,
2613,
63,
1725,
847,
359,
298,
66,
6838,
70,
14,
72,
401,
298,
667,
2996,
14,
72,
401,
221,
298,
75,
2227,
14,
72,
401,
298,
75,
513,
14,
72,
401,
298,
75,
846,
493,
14,
72,
401,
298,
345,
20127,
14,
72,
401,
2511,
298,
75,
3610,
14,
72,
401,
298,
75,
3191,
14,
72,
401,
298,
75,
875,
14,
72,
937,
267,
916,
18462,
8,
277,
14,
1023,
9,
2356,
18462,
360,
17,
14,
16,
735,
288,
291,
14,
1393,
63,
1725,
847,
2097,
9923,
15,
2798,
13,
21112,
3200,
2266,
9923,
15,
3610,
63,
1637,
63,
13817,
14,
1168,
937,
398,
340,
18462,
8,
277,
14,
1023,
9,
665,
18462,
360,
17,
14,
18,
735,
288,
327,
1022,
279,
78,
6998,
281,
4829,
315,
413,
14,
18,
334,
3543,
5851,
67,
25,
70,
22,
9,
288,
291,
14,
2613,
63,
1725,
847,
2097,
26446,
78,
14,
72,
937,
398,
340,
18462,
8,
277,
14,
1023,
9,
665,
18462,
360,
17,
14,
20,
735,
288,
327,
2329,
1494,
14,
72,
436,
1022,
496,
4982,
78,
14,
72,
4829,
687,
413,
14,
20,
288,
291,
14,
2613,
63,
1725,
847,
2097,
1508,
1494,
14,
72,
401,
298,
75,
496,
4982,
78,
14
] |
[
199,
3,
961,
570,
365,
376,
30025,
295,
559,
4521,
465,
1126,
4178,
921,
5031,
14,
957,
15,
13581,
20968,
15,
13581,
1506,
199,
3,
199,
3,
1898,
447,
1898,
6029,
13,
12682,
1910,
73,
14,
18176,
15,
44,
3298,
34,
12,
653,
21364,
33,
199,
3,
6642,
447,
257,
445,
379,
1567,
491,
645,
90,
9745,
665,
6867,
1567,
14,
416,
16823,
9745,
32,
5411,
14,
10836,
6244,
481,
79,
16753,
5346,
1308,
292,
736,
665,
545,
16753,
32,
22082,
14,
335,
6244,
1804,
287,
685,
273,
869,
736,
266,
199,
3,
844,
447,
257,
10697,
15,
12006,
199,
3,
2672,
1304,
4,
199,
3,
199,
3,
961,
1736,
9031,
282,
1777,
402,
314,
869,
4222,
34,
13532,
2199,
436,
365,
282,
3931,
402,
314,
4592,
26,
199,
3,
1455,
921,
72,
2352,
29673,
14,
25085,
14,
1308,
15,
287,
15,
7410,
15,
40,
4222,
34,
13532,
63,
7409,
13,
2635,
14,
1360,
199,
309,
199,
624,
199,
28326,
3425,
2291,
367,
10015,
428,
1156,
2537,
334,
51,
1156,
446,
10975,
15170,
784,
434,
15,
2956,
395,
6366,
465,
376,
8837,
1457,
199,
199,
32,
2502,
26,
445,
379,
1567,
491,
645,
90,
9745,
334,
27921,
14,
18176,
9,
199,
32,
2502,
26,
481,
79,
16753,
5346,
1308,
292,
736,
334,
27921,
14,
18176,
9,
199,
32,
2502,
26,
1804,
287,
685,
273,
869,
736,
266,
334,
39,
72,
484,
15904,
9,
199,
624,
199,
504,
7065,
14,
1023,
492,
18462,
199,
646,
747,
199,
646,
5145,
199,
646,
5672,
199,
199,
504,
8837,
1506,
14,
13581,
4166,
14,
6767,
14,
6472,
1875,
492,
15453,
5483,
199,
504,
8837,
1506,
14,
2537,
14,
1506,
63,
793,
492,
30025,
547,
199,
504,
8837,
1506,
14,
2537,
14,
493,
2537,
492,
11311,
63,
6060,
12,
1331,
63,
493,
199,
199,
533,
662,
34,
63,
51,
1156,
2537,
8,
17324,
5483,
304,
272,
408,
272,
12502,
367,
10015,
428,
1156,
2537,
27,
428,
1156,
334,
5826,
15170,
784,
434,
15,
2956,
9,
1475,
272,
365,
282,
7809,
1475,
367,
16915,
7031,
302,
947,
274,
79,
280,
271,
3414,
6998,
1470,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
408,
16213,
5548,
402,
1584,
370,
3907,
1041,
267,
1613,
8,
14138,
63,
51,
1156,
2537,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
398,
291,
14,
1393,
63,
1725,
275,
2097,
9923,
15,
66,
2019,
18,
21660,
14,
1168,
401,
2079,
298,
9923,
15,
22856,
23958,
18,
21660,
14,
1168,
401,
298,
9923,
15,
3790,
18,
21660,
14,
1168,
401,
298,
9923,
15,
21294,
63,
21660,
14,
1168,
401,
2079,
298,
9923,
15,
889,
2392,
18,
21660,
14,
1168,
401,
298,
9923,
15,
1190,
76,
18,
21660,
14,
1168,
401,
298,
9923,
15,
21660,
18,
27288,
14,
1168,
401,
298,
9923,
15,
21660,
2537,
14,
1168,
401,
2079,
298,
9923,
15,
21818,
18,
21660,
14,
1168,
401,
298,
9923,
15,
1391,
1541,
14,
647,
401,
298,
9923,
15,
23596,
5206,
63,
2579,
14,
1168,
401,
2079,
298,
9923,
15,
10598,
18,
21660,
14,
1168,
401,
298,
9923,
15,
1064,
21,
1838,
13,
5333,
401,
298,
9923,
15,
1064,
21,
667,
401,
298,
9923,
15,
391,
81,
18,
21660,
13,
3612,
401,
2079,
298,
9923,
15,
391,
81,
18,
21660,
13,
2809,
401,
298,
9923,
15,
23596,
5206,
401,
298,
21660,
2537,
937,
398,
291,
14,
2613,
63,
1725,
275,
2097,
21112,
14,
72,
401,
298,
21112,
18,
66,
2177,
14,
72,
401,
298,
21112,
63,
15009,
14,
72,
401,
221,
2892,
298,
21660,
14,
72,
401,
298,
21660,
63,
1291,
14,
72,
401,
298,
3271,
14,
72,
937,
398,
340,
18462,
8,
277,
14,
1023,
9,
508,
18462,
360,
16,
14,
17,
14,
1085,
735,
288,
327,
5412,
2663,
365,
949,
8088,
2337,
315,
373,
16,
14,
17,
14,
1167,
436,
5412,
2663,
365,
440,
315,
378,
14,
17,
14,
1196,
288,
291,
14,
1393,
63,
1725,
847,
2097,
9923,
15,
3610,
2663,
937,
267,
916,
18462,
8,
277,
14,
1023,
9,
2356,
18462,
360,
16,
14,
17,
14,
1167,
735,
288,
327,
892,
7249,
315,
373,
16,
14,
17,
14,
1167,
288,
291,
14,
1393,
63,
1725,
847,
2097,
9923,
15,
7984,
18,
21660,
401,
298,
9923,
15,
82,
18,
2798,
14,
76,
1458,
401,
3044,
298,
9923,
15,
27288,
1208,
14,
76,
1458,
937,
398,
340,
18462,
8,
277,
14,
1023,
9,
2356,
18462,
360,
16,
14,
17,
14,
1167,
358,
436,
18462,
8,
277,
14,
1023,
9,
665,
18462,
360,
17,
14,
16,
735,
288,
291,
14,
1393,
63,
1725,
847,
2097,
9923,
15,
21112,
1074,
401,
298,
9923,
15,
2798,
13,
21112,
1074,
937,
398,
340,
18462,
8,
277,
14,
1023,
9,
665,
18462,
360,
17,
14,
16,
735,
288,
291,
14,
1393,
63,
1725,
847,
2097,
66,
2177,
2537,
15,
27288,
1208,
14,
1168,
401,
298,
66,
2177,
2537,
15,
66,
2177,
2537,
937,
288,
291,
14,
2613,
63,
1725,
847,
359,
298,
66,
6838,
70,
14,
72,
401,
298,
667,
2996,
14,
72,
401,
221,
298,
75,
2227,
14,
72,
401,
298,
75,
513,
14,
72,
401,
298,
75,
846,
493,
14,
72,
401,
298,
345,
20127,
14,
72,
401,
2511,
298,
75,
3610,
14,
72,
401,
298,
75,
3191,
14,
72,
401,
298,
75,
875,
14,
72,
937,
267,
916,
18462,
8,
277,
14,
1023,
9,
2356,
18462,
360,
17,
14,
16,
735,
288,
291,
14,
1393,
63,
1725,
847,
2097,
9923,
15,
2798,
13,
21112,
3200,
2266,
9923,
15,
3610,
63,
1637,
63,
13817,
14,
1168,
937,
398,
340,
18462,
8,
277,
14,
1023,
9,
665,
18462,
360,
17,
14,
18,
735,
288,
327,
1022,
279,
78,
6998,
281,
4829,
315,
413,
14,
18,
334,
3543,
5851,
67,
25,
70,
22,
9,
288,
291,
14,
2613,
63,
1725,
847,
2097,
26446,
78,
14,
72,
937,
398,
340,
18462,
8,
277,
14,
1023,
9,
665,
18462,
360,
17,
14,
20,
735,
288,
327,
2329,
1494,
14,
72,
436,
1022,
496,
4982,
78,
14,
72,
4829,
687,
413,
14,
20,
288,
291,
14,
2613,
63,
1725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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
SUMPaul/dblog
|
dblog/settings.py
|
1
|
3991
|
"""
Django settings for dblog project.
Generated by 'django-admin startproject' using Django 1.10.6.
For more information on this file, see
https://docs.djangoproject.com/en/1.10/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.10/ref/settings/
"""
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '$&ptnh^8^^=7u$jym@)#c@fgl*idyyp!ajmzp#xe_hcs3+)+0n'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
#DEBUG = False
ALLOWED_HOSTS = [
'127.0.0.1',
'119.29.183.29',
'www.v4gk.com',
]
# Application definition
INSTALLED_APPS = [
'grappelli', #grappelli is backend manage app
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'blog',
'upload',
]
MIDDLEWARE_CLASSES = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
# 'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
# 'django.contrib.auth.middleware.SessionAuthenticationMessageMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'dblog.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
os.path.join(BASE_DIR,'templates').replace('\\','/'),
os.path.join(BASE_DIR,'templates/blog').replace('\\','/'),
os.path.join(BASE_DIR,'templates/upload').replace('\\','/'),
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'dblog.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.10/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Password validation
# https://docs.djangoproject.com/en/1.10/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/1.10/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.10/howto/static-files/
STATIC_URL = '/static/'
STATIC_ROOT =os.path.join(BASE_DIR, 'static').replace('\\','/')
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'blog/static').replace('\\','/'),
# os.path.join('/home/paul/WorkSpace/dblog/blog/static').replace('\\','/'),
# os.path.join(HERE,'app/static/').replace('\\','/'),
)
MEDIA_URL = '/media/'
MEDIA_ROOT =os.path.join(BASE_DIR, 'media').replace('\\','/')
MEDIA_DIRS = (
os.path.join(BASE_DIR, 'media').replace('\\','/'),
)
|
mit
|
[
624,
199,
9323,
2202,
367,
1592,
793,
2199,
14,
199,
199,
12706,
701,
283,
1176,
13,
2113,
1343,
1715,
7,
1808,
5634,
413,
14,
709,
14,
22,
14,
199,
199,
1858,
1655,
2556,
641,
642,
570,
12,
1937,
199,
2859,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
709,
15,
11299,
15,
1751,
15,
199,
199,
1858,
314,
2615,
769,
402,
2202,
436,
3932,
1338,
12,
1937,
199,
2859,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
709,
15,
1121,
15,
1751,
15,
199,
624,
199,
199,
646,
747,
199,
199,
3,
6516,
3792,
6272,
314,
2199,
2839,
642,
26,
747,
14,
515,
14,
904,
8,
5825,
63,
3022,
12,
19172,
199,
5825,
63,
3022,
275,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
3460,
493,
29658,
421,
199,
3,
27534,
13,
928,
16367,
2202,
446,
625,
83,
10020,
367,
9920,
199,
3,
1666,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
709,
15,
21232,
15,
13605,
15,
1074,
513,
15,
199,
199,
3,
24143,
32712,
14750,
26,
4215,
314,
7565,
790,
1202,
315,
9920,
7565,
1,
199,
12961,
63,
3078,
275,
4505,
6,
541,
29199,
62,
24,
11871,
29,
23,
85,
4,
74,
12828,
32,
28017,
67,
32,
70,
3528,
10,
344,
89,
2279,
1,
9091,
28808,
80,
3,
1845,
63,
72,
1259,
19,
11,
6393,
16,
78,
7,
199,
199,
3,
24143,
32712,
14750,
26,
2793,
1133,
1255,
543,
3105,
19136,
641,
315,
9920,
1,
199,
5287,
275,
715,
199,
3,
5287,
275,
756,
199,
17350,
63,
23775,
275,
359,
2043,
283,
4195,
14,
16,
14,
16,
14,
17,
297,
2043,
283,
7119,
14,
1398,
14,
12363,
14,
1398,
297,
2043,
283,
1544,
14,
86,
20,
71,
75,
14,
957,
297,
199,
61,
421,
199,
3,
13515,
5492,
199,
199,
15942,
63,
14219,
275,
359,
339,
283,
926,
80,
321,
13876,
297,
8295,
327,
926,
80,
321,
13876,
365,
4865,
9635,
1145,
339,
283,
1176,
14,
2828,
14,
2113,
297,
272,
283,
1176,
14,
2828,
14,
1178,
297,
272,
283,
1176,
14,
2828,
14,
10778,
297,
272,
283,
1176,
14,
2828,
14,
11676,
297,
272,
283,
1176,
14,
2828,
14,
3431,
297,
272,
283,
1176,
14,
2828,
14,
18373,
297,
339,
283,
11486,
297,
272,
283,
5064,
297,
199,
61,
199,
199,
19987,
63,
13748,
275,
359,
272,
283,
1176,
14,
5754,
14,
4416,
14,
7676,
6608,
297,
272,
283,
1176,
14,
2828,
14,
11676,
14,
5754,
14,
4434,
6608,
297,
272,
283,
1176,
14,
5754,
14,
2330,
14,
7844,
6608,
297,
199,
3,
259,
283,
1176,
14,
5754,
14,
10088,
14,
13912,
25322,
297,
272,
283,
1176,
14,
2828,
14,
1178,
14,
5754,
14,
10348,
6608,
297,
199,
3,
259,
283,
1176,
14,
2828,
14,
1178,
14,
5754,
14,
4434,
10348,
2209,
6608,
297,
272,
283,
1176,
14,
2828,
14,
3431,
14,
5754,
14,
2209,
6608,
297,
272,
283,
1176,
14,
5754,
14,
4891,
19193,
316,
14,
56,
3160,
4558,
6608,
297,
199,
61,
199,
199,
5441,
63,
18125,
275,
283,
697,
793,
14,
3603,
7,
199,
199,
25437,
275,
359,
272,
469,
267,
283,
18145,
356,
283,
1176,
14,
1160,
14,
7765,
14,
1176,
14,
9323,
17969,
297,
267,
283,
14455,
356,
359,
267,
747,
14,
515,
14,
904,
8,
5825,
63,
3022,
2584,
5876,
1959,
1814,
11671,
1673,
20467,
267,
747,
14,
515,
14,
904,
8,
5825,
63,
3022,
2584,
5876,
15,
11486,
1959,
1814,
11671,
1673,
20467,
199,
198,
736,
14,
515,
14,
904,
8,
5825,
63,
3022,
2584,
5876,
15,
5064,
1959,
1814,
11671,
1673,
20467,
267,
2156,
267,
283,
7121,
63,
14455,
356,
715,
12,
267,
283,
8808,
356,
469,
288,
283,
1100,
63,
10547,
356,
359,
355,
283,
1176,
14,
1160,
14,
1100,
63,
10547,
14,
1757,
297,
355,
283,
1176,
14,
1160,
14,
1100,
63,
10547,
14,
1069,
297,
355,
283,
1176,
14,
2828,
14,
1178,
14,
1100,
63,
10547,
14,
1178,
297,
355,
283,
1176,
14,
2828,
14,
3431,
14,
1100,
63,
10547,
14,
3431,
297,
288,
2156,
267,
1660,
272,
1660,
199,
61,
199,
199,
16828,
63,
24051,
275,
283,
697,
793,
14,
6508,
14,
3578,
7,
421,
199,
3,
8692,
199,
3,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
709,
15,
1121,
15,
1751,
12645,
17439,
199,
199,
27260,
275,
469,
272,
283,
885,
356,
469,
267,
283,
15956,
356,
283,
1176,
14,
697,
14,
7765,
14,
10659,
19,
297,
267,
283,
2339,
356,
747,
14,
515,
14,
904,
8,
5825,
63,
3022,
12,
283,
697,
14,
10659,
19,
659,
272,
789,
199,
93,
421,
199,
3,
13635,
6411,
199,
3,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
709,
15,
1121,
15,
1751,
12645,
1178,
13,
2060,
13,
11346,
199,
199,
5580,
63,
9032,
63,
5600,
19033,
275,
359,
272,
469,
267,
283,
2339,
356,
283,
1176,
14,
2828,
14,
1178,
14,
2060,
63,
6136,
14,
1899,
1646,
7467,
13093,
8640,
297,
272,
1660,
272,
469,
267,
283,
2339,
356,
283,
1176,
14,
2828,
14,
1178,
14,
2060,
63,
6136,
14,
12092,
4625,
8640,
297,
272,
1660,
272,
469,
267,
283,
2339,
356,
283,
1176,
14,
2828,
14,
1178,
14,
2060,
63,
6136,
14,
7844,
6139,
8640,
297,
272,
1660,
272,
469,
267,
283,
2339,
356,
283,
1176,
14,
2828,
14,
1178,
14,
2060,
63,
6136,
14,
14687,
6139,
8640,
297,
272,
1660,
199,
61,
421,
199,
3,
28220,
2072,
199,
3,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
709,
15,
11299,
15,
73,
1085,
78,
15,
199,
199,
13947,
63,
6012,
275,
283,
287,
13,
527,
7,
199,
199,
4961,
63,
15353,
275,
283,
11288,
7,
199,
199,
4701,
63,
41,
1085,
46,
275,
715,
199,
199,
4701,
63,
44,
709,
46,
275,
715,
199,
199,
4701,
63,
14226,
275,
715,
421,
199,
3,
13599,
1584,
334,
14391,
12,
15250,
12,
32658,
9,
199,
3,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
709,
15,
21232,
15,
1986,
13,
1725,
15,
199,
199,
10449,
63,
2632,
275,
1994,
1986,
4805,
199,
10449
] |
[
199,
9323,
2202,
367,
1592,
793,
2199,
14,
199,
199,
12706,
701,
283,
1176,
13,
2113,
1343,
1715,
7,
1808,
5634,
413,
14,
709,
14,
22,
14,
199,
199,
1858,
1655,
2556,
641,
642,
570,
12,
1937,
199,
2859,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
709,
15,
11299,
15,
1751,
15,
199,
199,
1858,
314,
2615,
769,
402,
2202,
436,
3932,
1338,
12,
1937,
199,
2859,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
709,
15,
1121,
15,
1751,
15,
199,
624,
199,
199,
646,
747,
199,
199,
3,
6516,
3792,
6272,
314,
2199,
2839,
642,
26,
747,
14,
515,
14,
904,
8,
5825,
63,
3022,
12,
19172,
199,
5825,
63,
3022,
275,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
3460,
493,
29658,
421,
199,
3,
27534,
13,
928,
16367,
2202,
446,
625,
83,
10020,
367,
9920,
199,
3,
1666,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
709,
15,
21232,
15,
13605,
15,
1074,
513,
15,
199,
199,
3,
24143,
32712,
14750,
26,
4215,
314,
7565,
790,
1202,
315,
9920,
7565,
1,
199,
12961,
63,
3078,
275,
4505,
6,
541,
29199,
62,
24,
11871,
29,
23,
85,
4,
74,
12828,
32,
28017,
67,
32,
70,
3528,
10,
344,
89,
2279,
1,
9091,
28808,
80,
3,
1845,
63,
72,
1259,
19,
11,
6393,
16,
78,
7,
199,
199,
3,
24143,
32712,
14750,
26,
2793,
1133,
1255,
543,
3105,
19136,
641,
315,
9920,
1,
199,
5287,
275,
715,
199,
3,
5287,
275,
756,
199,
17350,
63,
23775,
275,
359,
2043,
283,
4195,
14,
16,
14,
16,
14,
17,
297,
2043,
283,
7119,
14,
1398,
14,
12363,
14,
1398,
297,
2043,
283,
1544,
14,
86,
20,
71,
75,
14,
957,
297,
199,
61,
421,
199,
3,
13515,
5492,
199,
199,
15942,
63,
14219,
275,
359,
339,
283,
926,
80,
321,
13876,
297,
8295,
327,
926,
80,
321,
13876,
365,
4865,
9635,
1145,
339,
283,
1176,
14,
2828,
14,
2113,
297,
272,
283,
1176,
14,
2828,
14,
1178,
297,
272,
283,
1176,
14,
2828,
14,
10778,
297,
272,
283,
1176,
14,
2828,
14,
11676,
297,
272,
283,
1176,
14,
2828,
14,
3431,
297,
272,
283,
1176,
14,
2828,
14,
18373,
297,
339,
283,
11486,
297,
272,
283,
5064,
297,
199,
61,
199,
199,
19987,
63,
13748,
275,
359,
272,
283,
1176,
14,
5754,
14,
4416,
14,
7676,
6608,
297,
272,
283,
1176,
14,
2828,
14,
11676,
14,
5754,
14,
4434,
6608,
297,
272,
283,
1176,
14,
5754,
14,
2330,
14,
7844,
6608,
297,
199,
3,
259,
283,
1176,
14,
5754,
14,
10088,
14,
13912,
25322,
297,
272,
283,
1176,
14,
2828,
14,
1178,
14,
5754,
14,
10348,
6608,
297,
199,
3,
259,
283,
1176,
14,
2828,
14,
1178,
14,
5754,
14,
4434,
10348,
2209,
6608,
297,
272,
283,
1176,
14,
2828,
14,
3431,
14,
5754,
14,
2209,
6608,
297,
272,
283,
1176,
14,
5754,
14,
4891,
19193,
316,
14,
56,
3160,
4558,
6608,
297,
199,
61,
199,
199,
5441,
63,
18125,
275,
283,
697,
793,
14,
3603,
7,
199,
199,
25437,
275,
359,
272,
469,
267,
283,
18145,
356,
283,
1176,
14,
1160,
14,
7765,
14,
1176,
14,
9323,
17969,
297,
267,
283,
14455,
356,
359,
267,
747,
14,
515,
14,
904,
8,
5825,
63,
3022,
2584,
5876,
1959,
1814,
11671,
1673,
20467,
267,
747,
14,
515,
14,
904,
8,
5825,
63,
3022,
2584,
5876,
15,
11486,
1959,
1814,
11671,
1673,
20467,
199,
198,
736,
14,
515,
14,
904,
8,
5825,
63,
3022,
2584,
5876,
15,
5064,
1959,
1814,
11671,
1673,
20467,
267,
2156,
267,
283,
7121,
63,
14455,
356,
715,
12,
267,
283,
8808,
356,
469,
288,
283,
1100,
63,
10547,
356,
359,
355,
283,
1176,
14,
1160,
14,
1100,
63,
10547,
14,
1757,
297,
355,
283,
1176,
14,
1160,
14,
1100,
63,
10547,
14,
1069,
297,
355,
283,
1176,
14,
2828,
14,
1178,
14,
1100,
63,
10547,
14,
1178,
297,
355,
283,
1176,
14,
2828,
14,
3431,
14,
1100,
63,
10547,
14,
3431,
297,
288,
2156,
267,
1660,
272,
1660,
199,
61,
199,
199,
16828,
63,
24051,
275,
283,
697,
793,
14,
6508,
14,
3578,
7,
421,
199,
3,
8692,
199,
3,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
709,
15,
1121,
15,
1751,
12645,
17439,
199,
199,
27260,
275,
469,
272,
283,
885,
356,
469,
267,
283,
15956,
356,
283,
1176,
14,
697,
14,
7765,
14,
10659,
19,
297,
267,
283,
2339,
356,
747,
14,
515,
14,
904,
8,
5825,
63,
3022,
12,
283,
697,
14,
10659,
19,
659,
272,
789,
199,
93,
421,
199,
3,
13635,
6411,
199,
3,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
709,
15,
1121,
15,
1751,
12645,
1178,
13,
2060,
13,
11346,
199,
199,
5580,
63,
9032,
63,
5600,
19033,
275,
359,
272,
469,
267,
283,
2339,
356,
283,
1176,
14,
2828,
14,
1178,
14,
2060,
63,
6136,
14,
1899,
1646,
7467,
13093,
8640,
297,
272,
1660,
272,
469,
267,
283,
2339,
356,
283,
1176,
14,
2828,
14,
1178,
14,
2060,
63,
6136,
14,
12092,
4625,
8640,
297,
272,
1660,
272,
469,
267,
283,
2339,
356,
283,
1176,
14,
2828,
14,
1178,
14,
2060,
63,
6136,
14,
7844,
6139,
8640,
297,
272,
1660,
272,
469,
267,
283,
2339,
356,
283,
1176,
14,
2828,
14,
1178,
14,
2060,
63,
6136,
14,
14687,
6139,
8640,
297,
272,
1660,
199,
61,
421,
199,
3,
28220,
2072,
199,
3,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
709,
15,
11299,
15,
73,
1085,
78,
15,
199,
199,
13947,
63,
6012,
275,
283,
287,
13,
527,
7,
199,
199,
4961,
63,
15353,
275,
283,
11288,
7,
199,
199,
4701,
63,
41,
1085,
46,
275,
715,
199,
199,
4701,
63,
44,
709,
46,
275,
715,
199,
199,
4701,
63,
14226,
275,
715,
421,
199,
3,
13599,
1584,
334,
14391,
12,
15250,
12,
32658,
9,
199,
3,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
709,
15,
21232,
15,
1986,
13,
1725,
15,
199,
199,
10449,
63,
2632,
275,
1994,
1986,
4805,
199,
10449,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
tomkralidis/inasafe
|
safe/impact_functions/base.py
|
4
|
17208
|
# coding=utf-8
"""
InaSAFE Disaster risk assessment tool developed by AusAid -
**Impact Function Base Class**
Contact : ole.moller.nielsen@gmail.com
.. note:: 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.
"""
__author__ = 'akbargumbira@gmail.com'
__revision__ = '$Format:%H$'
__date__ = '15/03/15'
__copyright__ = ('Copyright 2012, Australia Indonesia Facility for '
'Disaster Reduction')
from socket import gethostname
import getpass
from safe.impact_functions.impact_function_metadata import \
ImpactFunctionMetadata
from safe.common.exceptions import (
InvalidExtentError, FunctionParametersError)
from safe.common.utilities import get_non_conflicting_attribute_name
from safe.utilities.i18n import tr
from safe.utilities.gis import convert_to_safe_layer
from safe.storage.safe_layer import SafeLayer
class ImpactFunction(object):
"""Abstract base class for all impact functions."""
# Class properties
_metadata = ImpactFunctionMetadata
def __init__(self):
"""Base class constructor.
All derived classes should normally call this constructor e.g.::
def __init__(self):
super(FloodImpactFunction, self).__init__()
"""
# User who runs this
self._user = getpass.getuser().replace(' ', '_')
# The host that runs this
self._host_name = gethostname()
# Requested extent to use
self._requested_extent = None
# Requested extent's CRS as EPSG number
self._requested_extent_crs = 4326
# Actual extent to use - Read Only
# For 'old-style' IF we do some manipulation to the requested extent
self._actual_extent = None
# Actual extent's CRS as EPSG number - Read Only
self._actual_extent_crs = 4326
# set this to a gui call back / web callback etc as needed.
self._callback = self.console_progress_callback
# Set the default parameters
self._parameters = self._metadata.parameters()
# Layer representing hazard e.g. flood
self._hazard = None
# Layer representing people / infrastructure that are exposed
self._exposure = None
# Layer used for aggregating results by area / district
self._aggregation = None
# Layer produced by the impact function
self._impact = None
# The question of the impact function
self._question = None
# Post analysis Result dictionary (suitable to conversion to json etc.)
self._tabulated_impact = None
# Style information for the impact layer - at some point we should
# formalise this into a more natural model
# ABC's will normally set this property.
self._impact_style = None
# The target field for vector impact layer
self._target_field = 'safe_ag'
# The string to mark not affected value in the vector impact layer
self._not_affected_value = 'Not Affected'
@classmethod
def metadata(cls):
"""Get the metadata class of this impact function."""
return cls._metadata
@classmethod
def function_type(cls):
"""Property for the type of impact function ('old-style' or 'qgis2.0').
QGIS2 impact functions are using the QGIS api and have more
dependencies. Legacy IF's use only numpy, gdal etc. and can be
used in contexts where no QGIS is present.
"""
return cls.metadata().as_dict().get('function_type', None)
@classmethod
def function_category(cls):
"""Property for function category based on hazard categories.
Function category could be 'single_event' or/and 'multiple_event'.
Single event data type means that the data is captured by a
single observation, while 'multiple_event' has been aggregated for
some observations.
:returns: The hazard categories that this function supports.
:rtype: list
"""
return cls.metadata().as_dict().get('layer_requirements').get(
'hazard').get('hazard_categories')
@property
def user(self):
"""Property for the user who runs this.
:returns: User who runs this
:rtype: basestring
"""
return self._user
@property
def host_name(self):
"""Property for the host name that runs this.
:returns: The host name.
:rtype: basestring
"""
return self._host_name
@property
def requested_extent(self):
"""Property for the extent of impact function analysis.
:returns: A list in the form [xmin, ymin, xmax, ymax].
:rtype: list
"""
return self._requested_extent
@requested_extent.setter
def requested_extent(self, extent):
"""Setter for extent property.
:param extent: Analysis boundaries expressed as
[xmin, ymin, xmax, ymax]. The extent CRS should match the
extent_crs property of this IF instance.
:type extent: list
"""
# add more robust checks here
if len(extent) != 4:
raise InvalidExtentError('%s is not a valid extent.' % extent)
self._requested_extent = extent
@property
def requested_extent_crs(self):
"""Property for the extent CRS of impact function analysis.
:returns: A number representing the EPSG code for the CRS. e.g. 4326
:rtype: int
"""
return self._requested_extent_crs
@requested_extent_crs.setter
def requested_extent_crs(self, crs):
"""Setter for extent_crs property.
.. note:: We break our rule here on not allowing acronyms for
parameter names.
:param crs: Analysis boundary EPSG CRS expressed as an integer.
:type crs: int
"""
self._requested_extent_crs = crs
@property
def actual_extent(self):
"""Property for the actual extent for analysis.
:returns: A list in the form [xmin, ymin, xmax, ymax].
:rtype: list
"""
return self._actual_extent
@property
def actual_extent_crs(self):
"""Property for the actual extent crs for analysis.
:returns: A number representing the EPSG code for the CRS. e.g. 4326
:rtype: int
"""
return self._actual_extent_crs
@property
def callback(self):
"""Property for the callback used to relay processing progress.
:returns: A callback function. The callback function will have the
following parameter requirements.
progress_callback(current, maximum, message=None)
:rtype: function
.. seealso:: console_progress_callback
"""
return self._callback
@callback.setter
def callback(self, callback):
"""Setter for callback property.
:param callback: A callback function reference that provides the
following signature:
progress_callback(current, maximum, message=None)
:type callback: function
"""
self._callback = callback
@classmethod
def instance(cls):
"""Make an instance of the impact function."""
return cls()
@property
def hazard(self):
"""Property for the hazard layer to be used for the analysis.
:returns: A map layer.
:rtype: SafeLayer
"""
return self._hazard
@hazard.setter
def hazard(self, layer):
"""Setter for hazard layer property.
:param layer: Hazard layer to be used for the analysis.
:type layer: SafeLayer, Layer, QgsMapLayer
"""
if isinstance(layer, SafeLayer):
self._hazard = layer
else:
if self.function_type() == 'old-style':
self._hazard = SafeLayer(convert_to_safe_layer(layer))
elif self.function_type() == 'qgis2.0':
# convert for new style impact function
self._hazard = SafeLayer(layer)
else:
message = tr('Error: Impact Function has unknown style.')
raise Exception(message)
# Update the target field to a non-conflicting one
if self._hazard.is_qgsvectorlayer():
self._target_field = get_non_conflicting_attribute_name(
self.target_field,
self._hazard.layer.dataProvider().fieldNameMap().keys()
)
@property
def exposure(self):
"""Property for the exposure layer to be used for the analysis.
:returns: A map layer.
:rtype: SafeLayer
"""
return self._exposure
@exposure.setter
def exposure(self, layer):
"""Setter for exposure layer property.
:param layer: exposure layer to be used for the analysis.
:type layer: SafeLayer
"""
if isinstance(layer, SafeLayer):
self._exposure = layer
else:
if self.function_type() == 'old-style':
self._exposure = SafeLayer(convert_to_safe_layer(layer))
elif self.function_type() == 'qgis2.0':
# convert for new style impact function
self._exposure = SafeLayer(layer)
else:
message = tr('Error: Impact Function has unknown style.')
raise Exception(message)
# Update the target field to a non-conflicting one
if self.exposure.is_qgsvectorlayer():
self._target_field = get_non_conflicting_attribute_name(
self.target_field,
self.exposure.layer.dataProvider().fieldNameMap().keys()
)
@property
def aggregation(self):
"""Property for the aggregation layer to be used for the analysis.
:returns: A map layer.
:rtype: SafeLayer
"""
return self._aggregation
@aggregation.setter
def aggregation(self, layer):
"""Setter for aggregation layer property.
:param layer: Aggregation layer to be used for the analysis.
:type layer: SafeLayer
"""
# add more robust checks here
self._aggregation = layer
@property
def parameters(self):
"""Get the parameter."""
return self._parameters
@parameters.setter
def parameters(self, parameters):
"""Set the parameter.
:param parameters: IF parameters.
:type parameters: dict
"""
self._parameters = parameters
@property
def impact(self):
"""Property for the impact layer generated by the analysis.
.. note:: It is not guaranteed that all impact functions produce a
spatial layer.
:returns: A map layer.
:rtype: QgsMapLayer, QgsVectorLayer, QgsRasterLayer
"""
return self._impact
@property
def requires_clipping(self):
"""Check to clip or not to clip layers.
If function type is a 'qgis2.0' impact function, then
return False -- clipping is unnecessary, else return True.
:returns: To clip or not to clip.
:rtype: bool
"""
if self.function_type() == 'old-style':
return True
elif self.function_type() == 'qgis2.0':
return False
else:
message = tr('Error: Impact Function has unknown style.')
raise Exception(message)
@property
def target_field(self):
"""Property for the target_field of the impact layer.
:returns: The target field in the impact layer in case it's a vector.
:rtype: basestring
"""
return self._target_field
@property
def tabulated_impact(self):
"""Property for the result (excluding GIS layer) of the analysis.
This property is read only.
:returns: A dictionary containing the analysis results. The format of
the dictionary may vary between impact function but the following
sections are expected:
* title: A brief title for the results
* headings: column headings for the results
* totals: totals for all rows in the tabulation area
* tabulation: detailed line items for the tabulation
The returned dictionary is probably best described with a simple
example::
Example to follow here....
:rtype: dict
"""
return self._tabulated_impact
@property
def style(self):
"""Property for the style for the impact layer.
This property is read only.
:returns: A dictionary containing the analysis style. Generally this
should be an adjunct to the qml style applied to the impact layer
so that other types of style (e.g. SLD) can be generated for the
impact layer.
:rtype: dict
"""
return self._impact_style
@property
def question(self):
"""Formulate the question for this impact function.
This method produces a natural language question for this impact
function derived from the following three inputs:
* descriptive name of the hazard layer e.g. 'a flood like in
January 2004'
* descriptive name of the exposure layer e.g. 'people'
* question statement in the impact function metadata e.g.
'will be affected'.
These inputs will be concatenated into a string e.g.:
"In the event of a flood like in January 2004, how many people
will be affected."
"""
if self._question is None:
function_title = self.metadata().as_dict()['title']
return (tr('In the event of %(hazard)s how many '
'%(exposure)s might %(impact)s')
% {'hazard': self.hazard.name.lower(),
'exposure': self.exposure.name.lower(),
'impact': function_title.lower()})
else:
return self._question
@question.setter
def question(self, question):
"""Setter of the question.
:param question: The question for the impact function.
:type question: basestring
"""
if isinstance(question, basestring):
self._question = question
else:
raise Exception('The question should be a basestring instance.')
@staticmethod
def console_progress_callback(current, maximum, message=None):
"""Simple console based callback implementation for tests.
:param current: Current progress.
:type current: int
:param maximum: Maximum range (point at which task is complete.
:type maximum: int
:param message: Optional message to display in the progress bar
:type message: str, QString
"""
# noinspection PyChainedComparisons
if maximum > 1000 and current % 1000 != 0 and current != maximum:
return
if message is not None:
print message
print 'Task progress: %i of %i' % (current, maximum)
def validate(self):
"""Validate things needed before running the analysis."""
# Validate that input layers are valid
if (self.hazard is None) or (self.exposure is None):
message = tr(
'Ensure that hazard and exposure layers are all set before '
'trying to run the impact function.')
raise FunctionParametersError(message)
# Validate extent, with the QGIS IF, we need requested_extent set
if self.function_type() == 'qgis2.0' and self.requested_extent is None:
message = tr(
'Impact Function with QGIS function type is used, but no '
'extent is provided.')
raise InvalidExtentError(message)
def prepare(self):
"""Prepare this impact function for running the analysis.
This method should normally be called in your concrete class's
run method before it attempts to do any real processing. This
method will do any needed house keeping such as:
* checking that the exposure and hazard layers sufficiently
overlap (post 3.1)
* clipping or subselecting features from both layers such that
only features / coverage within the actual analysis extent
will be analysed (post 3.1)
* raising errors if any untenable condition exists e.g. extent has
no valid CRS. (post 3.1)
We suggest to overload this method in your concrete class
implementation so that it includes any impact function specific checks
too.
..note: For 3.1, we will still do those preprocessing in analysis
class. We will just need to check if the function_type is
'qgis2.0', it needs to have the extent set.
# """
pass
|
gpl-3.0
|
[
3,
2803,
29,
1624,
13,
24,
199,
624,
199,
607,
65,
27657,
5289,
2311,
22633,
28273,
4744,
477,
27813,
701,
437,
527,
33,
344,
446,
199,
538,
8499,
2442,
6801,
3523,
8089,
538,
199,
199,
14499,
520,
312,
274,
14,
16924,
1435,
14,
8445,
352,
2464,
32,
6799,
14,
957,
199,
199,
703,
5317,
447,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
1362,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
1362,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
1362,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
624,
199,
199,
363,
2502,
363,
275,
283,
1151,
66,
1273,
4295,
20936,
32,
6799,
14,
957,
7,
199,
363,
5792,
363,
275,
4505,
3484,
2689,
40,
12913,
199,
363,
602,
363,
275,
283,
1046,
15,
1644,
15,
1046,
7,
199,
363,
7307,
363,
275,
661,
7384,
6029,
12,
437,
22306,
473,
977,
368,
10971,
10859,
12498,
367,
283,
326,
283,
2825,
2311,
820,
24095,
358,
199,
199,
504,
2838,
492,
2312,
15157,
354,
199,
646,
18354,
199,
199,
504,
5048,
14,
31822,
63,
5777,
14,
31822,
63,
1593,
63,
2343,
492,
971,
272,
8362,
2442,
3481,
5142,
199,
504,
5048,
14,
2330,
14,
3924,
492,
334,
272,
6378,
19808,
547,
12,
6801,
5976,
547,
9,
199,
504,
5048,
14,
2330,
14,
16355,
492,
664,
63,
2865,
63,
15207,
316,
63,
3215,
63,
354,
199,
504,
5048,
14,
16355,
14,
73,
1085,
78,
492,
5651,
199,
504,
5048,
14,
16355,
14,
5668,
492,
3957,
63,
475,
63,
3489,
63,
1897,
199,
504,
5048,
14,
3494,
14,
3489,
63,
1897,
492,
14969,
5003,
421,
199,
533,
8362,
2442,
3481,
8,
785,
304,
272,
408,
8458,
1300,
1021,
367,
1006,
25568,
3423,
1041,
339,
327,
8089,
4382,
272,
485,
2343,
275,
8362,
2442,
3481,
5142,
339,
347,
636,
826,
721,
277,
304,
267,
408,
1563,
1021,
3787,
14,
398,
2900,
7131,
3992,
1077,
12252,
1240,
642,
3787,
325,
14,
71,
28383,
953,
347,
636,
826,
721,
277,
304,
355,
1613,
8,
38,
21703,
8499,
2442,
3481,
12,
291,
2843,
826,
4533,
398,
408,
267,
327,
2876,
3963,
7858,
642,
267,
291,
423,
751,
275,
18354,
14,
362,
751,
1252,
1814,
360,
1656,
18962,
267,
327,
710,
1591,
626,
7858,
642,
267,
291,
423,
1102,
63,
354,
275,
2312,
15157,
354,
342,
398,
327,
799,
4522,
13675,
370,
675,
267,
291,
423,
11151,
63,
11599,
275,
488,
267,
327,
799,
4522,
13675,
1159,
445,
15062,
465,
31922,
4254,
1329,
267,
291,
423,
11151,
63,
11599,
63,
19034,
275,
26719,
267,
327,
18982,
1061,
13675,
370,
675,
446,
5574,
5972,
267,
327,
2104,
283,
1753,
13,
2487,
7,
8036,
781,
886,
2005,
26212,
370,
314,
5839,
13675,
267,
291,
423,
6514,
63,
11599,
275,
488,
267,
327,
18982,
1061,
13675,
1159,
445,
15062,
465,
31922,
4254,
1329,
446,
5574,
5972,
267,
291,
423,
6514,
63,
11599,
63,
19034,
275,
26719,
267,
327,
663,
642,
370,
282,
11621,
1240,
1771,
1182,
3330,
3233,
5423,
465,
4346,
14,
267,
291,
423,
3058,
275,
291,
14,
6614,
63,
5734,
63,
3058,
267,
327,
2494,
314,
849,
2633,
267,
291,
423,
3214,
275,
291,
423,
2343,
14,
3214,
342,
267,
327,
11915,
6144,
394,
32145,
325,
14,
71,
14,
289,
21703,
267,
291,
423,
22133,
1005,
275,
488,
267,
327,
11915,
6144,
13135,
1182,
28890,
6976,
626,
787,
19282,
267,
291,
423,
28480,
275,
488,
267,
327,
11915,
1202,
367,
10454,
1958,
2058,
701,
9150,
1182,
487,
4768,
267,
291,
423,
21016,
275,
488,
267,
327,
11915,
13584,
701,
314,
25568,
805,
267,
291,
423,
31822,
275,
488,
267,
327,
710,
7894,
402,
314,
25568,
805,
267,
291,
423,
4790,
275,
488,
267,
327,
7711,
11284,
10695,
2600,
334,
83,
10020,
370,
8603,
370,
2022,
5423,
4959,
267,
291,
423,
2902,
8097,
63,
31822,
275,
488,
267,
327,
19442,
2556,
367,
314,
25568,
4045,
446,
737,
2005,
2376,
781,
1077,
267,
327,
1824,
279,
572,
642,
1901,
282,
1655,
19981,
1402,
267,
327,
17281,
1159,
911,
12252,
663,
642,
3324,
14,
267,
291,
423,
31822,
63,
2487,
275,
488,
267,
327,
710,
1347,
901,
367,
5477,
25568,
4045,
267,
291,
423,
1375,
63,
698,
275,
283,
3489,
63,
643,
7,
267,
327,
710,
1059,
370,
2216,
440,
16955,
574,
315,
314,
5477,
25568,
4045,
267,
291,
423,
1397,
63,
26653,
63,
585,
275,
283,
1763,
31030,
6201,
7,
339,
768,
3744,
272,
347,
3341,
8,
1886,
304,
267,
408,
1002,
314,
3341,
1021,
402,
642,
25568,
805,
1041,
267,
372,
843,
423,
2343,
339,
768,
3744,
272,
347,
805,
63,
466,
8,
1886,
304,
267,
408,
3697,
367,
314,
730,
402,
25568,
805,
661,
1753,
13,
2487,
7,
503,
283,
25325,
18,
14,
16,
1959,
398,
27024,
18,
25568,
3423,
787,
1808,
314,
27024,
2986,
436,
1172,
1655,
267,
5124,
14,
26251,
8036,
1159,
675,
1454,
2680,
12,
15834,
5423,
14,
436,
883,
506,
267,
1202,
315,
18191,
2382,
949,
27024,
365,
3451,
14,
267,
408,
267,
372,
843,
14,
2343,
1252,
305,
63,
807,
1252,
362,
360,
1593,
63,
466,
297,
488,
9,
339,
768,
3744,
272,
347,
805,
63,
3710,
8,
1886,
304,
267,
408,
3697,
367,
805,
4637,
4079,
641,
394,
32145,
9695,
14,
13359,
6801,
4637,
4293,
506,
283,
4780,
63,
1430,
7,
503,
15,
460,
283,
6048,
63,
1430,
1370,
268,
13050,
1566,
666,
730,
4910,
626,
314,
666,
365,
17487,
701,
282,
268,
2849,
20038,
12,
1830,
283,
6048,
63,
1430,
7,
965,
2757,
26913,
367,
268,
2005,
19739,
14,
13359,
520,
5808,
26,
710,
394,
32145,
9695,
626,
642,
805,
5171,
14,
268,
520,
4500,
26,
769,
267,
408,
267,
372,
843,
14,
2343,
1252,
305,
63,
807,
1252,
362,
360,
1897,
63,
7538,
1959,
362,
8,
288,
283,
22133,
1005,
1959,
362,
360,
22133,
1005,
63,
8906,
358,
339,
768,
1829,
272,
347,
922,
8,
277,
304,
267,
408,
3697,
367,
314,
922,
3963,
7858,
642,
14,
398,
520,
5808,
26,
2876,
3963,
7858,
642,
267,
520,
4500,
26,
7116,
267,
408,
267,
372,
291,
423,
751,
339,
768,
1829,
272,
347,
1591,
63,
354,
8
] |
[
2803,
29,
1624,
13,
24,
199,
624,
199,
607,
65,
27657,
5289,
2311,
22633,
28273,
4744,
477,
27813,
701,
437,
527,
33,
344,
446,
199,
538,
8499,
2442,
6801,
3523,
8089,
538,
199,
199,
14499,
520,
312,
274,
14,
16924,
1435,
14,
8445,
352,
2464,
32,
6799,
14,
957,
199,
199,
703,
5317,
447,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
1362,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
1362,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
1362,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
624,
199,
199,
363,
2502,
363,
275,
283,
1151,
66,
1273,
4295,
20936,
32,
6799,
14,
957,
7,
199,
363,
5792,
363,
275,
4505,
3484,
2689,
40,
12913,
199,
363,
602,
363,
275,
283,
1046,
15,
1644,
15,
1046,
7,
199,
363,
7307,
363,
275,
661,
7384,
6029,
12,
437,
22306,
473,
977,
368,
10971,
10859,
12498,
367,
283,
326,
283,
2825,
2311,
820,
24095,
358,
199,
199,
504,
2838,
492,
2312,
15157,
354,
199,
646,
18354,
199,
199,
504,
5048,
14,
31822,
63,
5777,
14,
31822,
63,
1593,
63,
2343,
492,
971,
272,
8362,
2442,
3481,
5142,
199,
504,
5048,
14,
2330,
14,
3924,
492,
334,
272,
6378,
19808,
547,
12,
6801,
5976,
547,
9,
199,
504,
5048,
14,
2330,
14,
16355,
492,
664,
63,
2865,
63,
15207,
316,
63,
3215,
63,
354,
199,
504,
5048,
14,
16355,
14,
73,
1085,
78,
492,
5651,
199,
504,
5048,
14,
16355,
14,
5668,
492,
3957,
63,
475,
63,
3489,
63,
1897,
199,
504,
5048,
14,
3494,
14,
3489,
63,
1897,
492,
14969,
5003,
421,
199,
533,
8362,
2442,
3481,
8,
785,
304,
272,
408,
8458,
1300,
1021,
367,
1006,
25568,
3423,
1041,
339,
327,
8089,
4382,
272,
485,
2343,
275,
8362,
2442,
3481,
5142,
339,
347,
636,
826,
721,
277,
304,
267,
408,
1563,
1021,
3787,
14,
398,
2900,
7131,
3992,
1077,
12252,
1240,
642,
3787,
325,
14,
71,
28383,
953,
347,
636,
826,
721,
277,
304,
355,
1613,
8,
38,
21703,
8499,
2442,
3481,
12,
291,
2843,
826,
4533,
398,
408,
267,
327,
2876,
3963,
7858,
642,
267,
291,
423,
751,
275,
18354,
14,
362,
751,
1252,
1814,
360,
1656,
18962,
267,
327,
710,
1591,
626,
7858,
642,
267,
291,
423,
1102,
63,
354,
275,
2312,
15157,
354,
342,
398,
327,
799,
4522,
13675,
370,
675,
267,
291,
423,
11151,
63,
11599,
275,
488,
267,
327,
799,
4522,
13675,
1159,
445,
15062,
465,
31922,
4254,
1329,
267,
291,
423,
11151,
63,
11599,
63,
19034,
275,
26719,
267,
327,
18982,
1061,
13675,
370,
675,
446,
5574,
5972,
267,
327,
2104,
283,
1753,
13,
2487,
7,
8036,
781,
886,
2005,
26212,
370,
314,
5839,
13675,
267,
291,
423,
6514,
63,
11599,
275,
488,
267,
327,
18982,
1061,
13675,
1159,
445,
15062,
465,
31922,
4254,
1329,
446,
5574,
5972,
267,
291,
423,
6514,
63,
11599,
63,
19034,
275,
26719,
267,
327,
663,
642,
370,
282,
11621,
1240,
1771,
1182,
3330,
3233,
5423,
465,
4346,
14,
267,
291,
423,
3058,
275,
291,
14,
6614,
63,
5734,
63,
3058,
267,
327,
2494,
314,
849,
2633,
267,
291,
423,
3214,
275,
291,
423,
2343,
14,
3214,
342,
267,
327,
11915,
6144,
394,
32145,
325,
14,
71,
14,
289,
21703,
267,
291,
423,
22133,
1005,
275,
488,
267,
327,
11915,
6144,
13135,
1182,
28890,
6976,
626,
787,
19282,
267,
291,
423,
28480,
275,
488,
267,
327,
11915,
1202,
367,
10454,
1958,
2058,
701,
9150,
1182,
487,
4768,
267,
291,
423,
21016,
275,
488,
267,
327,
11915,
13584,
701,
314,
25568,
805,
267,
291,
423,
31822,
275,
488,
267,
327,
710,
7894,
402,
314,
25568,
805,
267,
291,
423,
4790,
275,
488,
267,
327,
7711,
11284,
10695,
2600,
334,
83,
10020,
370,
8603,
370,
2022,
5423,
4959,
267,
291,
423,
2902,
8097,
63,
31822,
275,
488,
267,
327,
19442,
2556,
367,
314,
25568,
4045,
446,
737,
2005,
2376,
781,
1077,
267,
327,
1824,
279,
572,
642,
1901,
282,
1655,
19981,
1402,
267,
327,
17281,
1159,
911,
12252,
663,
642,
3324,
14,
267,
291,
423,
31822,
63,
2487,
275,
488,
267,
327,
710,
1347,
901,
367,
5477,
25568,
4045,
267,
291,
423,
1375,
63,
698,
275,
283,
3489,
63,
643,
7,
267,
327,
710,
1059,
370,
2216,
440,
16955,
574,
315,
314,
5477,
25568,
4045,
267,
291,
423,
1397,
63,
26653,
63,
585,
275,
283,
1763,
31030,
6201,
7,
339,
768,
3744,
272,
347,
3341,
8,
1886,
304,
267,
408,
1002,
314,
3341,
1021,
402,
642,
25568,
805,
1041,
267,
372,
843,
423,
2343,
339,
768,
3744,
272,
347,
805,
63,
466,
8,
1886,
304,
267,
408,
3697,
367,
314,
730,
402,
25568,
805,
661,
1753,
13,
2487,
7,
503,
283,
25325,
18,
14,
16,
1959,
398,
27024,
18,
25568,
3423,
787,
1808,
314,
27024,
2986,
436,
1172,
1655,
267,
5124,
14,
26251,
8036,
1159,
675,
1454,
2680,
12,
15834,
5423,
14,
436,
883,
506,
267,
1202,
315,
18191,
2382,
949,
27024,
365,
3451,
14,
267,
408,
267,
372,
843,
14,
2343,
1252,
305,
63,
807,
1252,
362,
360,
1593,
63,
466,
297,
488,
9,
339,
768,
3744,
272,
347,
805,
63,
3710,
8,
1886,
304,
267,
408,
3697,
367,
805,
4637,
4079,
641,
394,
32145,
9695,
14,
13359,
6801,
4637,
4293,
506,
283,
4780,
63,
1430,
7,
503,
15,
460,
283,
6048,
63,
1430,
1370,
268,
13050,
1566,
666,
730,
4910,
626,
314,
666,
365,
17487,
701,
282,
268,
2849,
20038,
12,
1830,
283,
6048,
63,
1430,
7,
965,
2757,
26913,
367,
268,
2005,
19739,
14,
13359,
520,
5808,
26,
710,
394,
32145,
9695,
626,
642,
805,
5171,
14,
268,
520,
4500,
26,
769,
267,
408,
267,
372,
843,
14,
2343,
1252,
305,
63,
807,
1252,
362,
360,
1897,
63,
7538,
1959,
362,
8,
288,
283,
22133,
1005,
1959,
362,
360,
22133,
1005,
63,
8906,
358,
339,
768,
1829,
272,
347,
922,
8,
277,
304,
267,
408,
3697,
367,
314,
922,
3963,
7858,
642,
14,
398,
520,
5808,
26,
2876,
3963,
7858,
642,
267,
520,
4500,
26,
7116,
267,
408,
267,
372,
291,
423,
751,
339,
768,
1829,
272,
347,
1591,
63,
354,
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,
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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
] |
chennan47/osf.io
|
api_tests/institutions/views/test_institution_relationship_nodes.py
|
8
|
22416
|
import pytest
from api.base.settings.defaults import API_BASE
from osf_tests.factories import (
WithdrawnRegistrationFactory,
RegistrationFactory,
InstitutionFactory,
AuthUserFactory,
NodeFactory,
)
from osf.utils import permissions
def make_payload(*node_ids):
data = [
{'type': 'nodes', 'id': id_} for id_ in node_ids
]
return {'data': data}
def make_registration_payload(*node_ids):
data = [
{'type': 'registrations', 'id': id_} for id_ in node_ids
]
return {'data': data}
@pytest.mark.django_db
class TestInstitutionRelationshipNodes:
@pytest.fixture()
def institution(self):
return InstitutionFactory()
@pytest.fixture()
def node(self):
return NodeFactory()
@pytest.fixture()
def user(self, institution):
user = AuthUserFactory()
user.affiliated_institutions.add(institution)
user.save()
return user
@pytest.fixture()
def node_one(self, user, institution):
node = NodeFactory(creator=user)
node.affiliated_institutions.add(institution)
node.save()
return node
@pytest.fixture()
def node_two(self, user):
return NodeFactory(creator=user)
@pytest.fixture()
def node_public(self, user, institution):
node_public = NodeFactory(is_public=True)
node_public.affiliated_institutions.add(institution)
node_public.save()
return node_public
@pytest.fixture()
def node_private(self, user, institution):
node_private = NodeFactory()
node_private.affiliated_institutions.add(institution)
node_private.save()
return node_private
@pytest.fixture()
def url_institution_nodes(self, institution):
return '/{}institutions/{}/relationships/nodes/'.format(
API_BASE, institution._id)
def test_auth_get_nodes(
self, app, user, node_one, node_public,
node_private, url_institution_nodes
):
# test_get_nodes_no_auth
res = app.get(url_institution_nodes)
assert res.status_code == 200
node_ids = [node_['id'] for node_ in res.json['data']]
assert node_one._id not in node_ids
assert node_public._id in node_ids
assert node_private._id not in node_ids
# test_get_nodes_with_auth
res = app.get(url_institution_nodes, auth=user.auth)
assert res.status_code == 200
node_ids = [node_['id'] for node_ in res.json['data']]
assert node_one._id in node_ids
assert node_public._id in node_ids
assert node_private._id not in node_ids
def test_node_or_type_does_not_exist(
self, app, user, node_two, url_institution_nodes):
# test_node_does_not_exist
res = app.post_json_api(
url_institution_nodes,
make_payload('notIdatAll'),
expect_errors=True, auth=user.auth
)
assert res.status_code == 404
# test_node_type_does_not_exist
res = app.post_json_api(
url_institution_nodes,
{'data': [{'type': 'dugtrio', 'id': node_two._id}]},
expect_errors=True, auth=user.auth
)
assert res.status_code == 409
def test_user_with_nodes_and_permissions(
self, user, app, node_two,
url_institution_nodes, institution
):
res = app.post_json_api(
url_institution_nodes,
make_payload(node_two._id),
auth=user.auth
)
assert res.status_code == 201
node_ids = [node_['id'] for node_ in res.json['data']]
assert node_two._id in node_ids
node_two.reload()
assert institution in node_two.affiliated_institutions.all()
def test_user_does_not_have_node(
self, app, node,
url_institution_nodes, user,
institution
):
res = app.post_json_api(
url_institution_nodes,
make_payload(node._id),
expect_errors=True, auth=user.auth
)
assert res.status_code == 403
node.reload()
assert institution not in node.affiliated_institutions.all()
def test_user_is_admin(
self, app, node_two,
url_institution_nodes, user,
institution
):
res = app.post_json_api(
url_institution_nodes,
make_payload(node_two._id),
auth=user.auth
)
assert res.status_code == 201
node_two.reload()
assert institution in node_two.affiliated_institutions.all()
def test_user_is_read_write(
self, app, node,
url_institution_nodes,
institution
):
user = AuthUserFactory()
user.affiliated_institutions.add(institution)
node.add_contributor(user)
node.save()
res = app.post_json_api(
url_institution_nodes,
make_payload(node._id),
auth=user.auth
)
assert res.status_code == 201
node.reload()
assert institution in node.affiliated_institutions.all()
def test_user_is_read_only(
self, app, node,
url_institution_nodes,
institution
):
user = AuthUserFactory()
user.affiliated_institutions.add(institution)
node.add_contributor(user, permissions=[permissions.READ])
node.save()
res = app.post_json_api(
url_institution_nodes,
make_payload(node._id),
auth=user.auth, expect_errors=True
)
assert res.status_code == 403
node.reload()
assert institution not in node.affiliated_institutions.all()
def test_user_is_admin_but_not_affiliated(
self, app, url_institution_nodes, institution):
user = AuthUserFactory()
node = NodeFactory(creator=user)
res = app.post_json_api(
url_institution_nodes,
make_payload(node._id),
expect_errors=True, auth=user.auth
)
assert res.status_code == 403
node.reload()
assert institution not in node.affiliated_institutions.all()
def test_add_some_with_permissions_others_without(
self, user, node, node_two, app, url_institution_nodes, institution):
res = app.post_json_api(
url_institution_nodes,
make_payload(node_two._id, node._id),
expect_errors=True, auth=user.auth
)
assert res.status_code == 403
node_two.reload()
node.reload()
assert institution not in node_two.affiliated_institutions.all()
assert institution not in node.affiliated_institutions.all()
def test_add_some_existant_others_not(
self, institution, node_one, user,
node_two, app, url_institution_nodes
):
assert institution in node_one.affiliated_institutions.all()
res = app.post_json_api(
url_institution_nodes,
make_payload(node_two._id, node_one._id),
auth=user.auth
)
assert res.status_code == 201
node_one.reload()
node_two.reload()
assert institution in node_one.affiliated_institutions.all()
assert institution in node_two.affiliated_institutions.all()
def test_only_add_existent_with_mixed_permissions(
self, institution, node_one, node_public,
app, url_institution_nodes, user
):
assert institution in node_one.affiliated_institutions.all()
assert institution in node_public.affiliated_institutions.all()
res = app.post_json_api(
url_institution_nodes,
make_payload(node_public._id, node_one._id),
expect_errors=True, auth=user.auth
)
assert res.status_code == 403
node_one.reload()
node_public.reload()
assert institution in node_one.affiliated_institutions.all()
assert institution in node_public.affiliated_institutions.all()
def test_only_add_existent_with_permissions(
self, user, node_one, node_two,
institution, app,
url_institution_nodes
):
node_two.affiliated_institutions.add(institution)
node_two.save()
assert institution in node_one.affiliated_institutions.all()
assert institution in node_two.affiliated_institutions.all()
res = app.post_json_api(
url_institution_nodes,
make_payload(node_two._id, node_one._id),
auth=user.auth
)
assert res.status_code == 204
def test_delete_user_is_admin(
self, app, url_institution_nodes,
node_one, user, institution
):
res = app.delete_json_api(
url_institution_nodes,
make_payload(node_one._id),
auth=user.auth
)
node_one.reload()
assert res.status_code == 204
assert institution not in node_one.affiliated_institutions.all()
def test_delete_user_is_read_write(
self, app, node_private,
user, url_institution_nodes,
institution
):
node_private.add_contributor(user)
node_private.save()
res = app.delete_json_api(
url_institution_nodes,
make_payload(node_private._id),
auth=user.auth
)
node_private.reload()
assert res.status_code == 204
assert institution not in node_private.affiliated_institutions.all()
def test_delete_user_is_read_only(
self, node_private, user,
app, url_institution_nodes,
institution):
node_private.add_contributor(user, permissions='read')
node_private.save()
res = app.delete_json_api(
url_institution_nodes,
make_payload(node_private._id),
auth=user.auth, expect_errors=True
)
node_private.reload()
assert res.status_code == 403
assert institution in node_private.affiliated_institutions.all()
def test_delete_user_is_admin_and_affiliated_with_inst(
self, institution, node_one, app, url_institution_nodes, user):
assert institution in node_one.affiliated_institutions.all()
res = app.delete_json_api(
url_institution_nodes,
make_payload(node_one._id),
auth=user.auth
)
assert res.status_code == 204
node_one.reload()
assert institution not in node_one.affiliated_institutions.all()
def test_delete_user_is_admin_but_not_affiliated_with_inst(
self, institution, app, url_institution_nodes):
user = AuthUserFactory()
node = NodeFactory(creator=user)
node.affiliated_institutions.add(institution)
node.save()
assert institution in node.affiliated_institutions.all()
res = app.delete_json_api(
url_institution_nodes,
make_payload(node._id),
auth=user.auth
)
assert res.status_code == 204
node.reload()
assert institution not in node.affiliated_institutions.all()
def test_delete_user_is_affiliated_with_inst_and_mixed_permissions_on_nodes(
self, app, url_institution_nodes, node_one, node_public, user):
res = app.delete_json_api(
url_institution_nodes,
make_payload(node_one._id, node_public._id),
expect_errors=True, auth=user.auth
)
assert res.status_code == 403
def test_add_non_node(self, app, user, institution, url_institution_nodes):
registration = RegistrationFactory(creator=user, is_public=True)
registration.affiliated_institutions.add(institution)
registration.save()
res = app.post_json_api(
url_institution_nodes,
make_payload(registration._id),
expect_errors=True, auth=user.auth
)
assert res.status_code == 404
@pytest.mark.django_db
class TestInstitutionRelationshipRegistrations:
@pytest.fixture()
def institution(self):
return InstitutionFactory()
@pytest.fixture()
def admin(self, institution):
user = AuthUserFactory()
user.affiliated_institutions.add(institution)
user.save()
return user
@pytest.fixture()
def user(self, institution):
return AuthUserFactory()
@pytest.fixture()
def affiliated_user(self, institution):
user = AuthUserFactory()
user.affiliated_institutions.add(institution)
user.save()
return user
@pytest.fixture()
def registration_no_owner(self):
return RegistrationFactory(is_public=True)
@pytest.fixture()
def registration_no_affiliation(self, admin):
return RegistrationFactory(creator=admin)
@pytest.fixture()
def registration_pending(self, admin, institution):
registration = RegistrationFactory(creator=admin)
registration.affiliated_institutions.add(institution)
registration.save()
return registration
@pytest.fixture()
def registration_public(self, admin, institution):
registration = RegistrationFactory(creator=admin, is_public=True)
registration.affiliated_institutions.add(institution)
registration.save()
return registration
@pytest.fixture()
def url_institution_registrations(self, institution):
return '/{}institutions/{}/relationships/registrations/'.format(
API_BASE, institution._id)
def test_auth_get_registrations(
self, app, admin, registration_no_owner,
registration_no_affiliation,
registration_pending, registration_public,
url_institution_registrations
):
# test getting registrations without auth (for complete registrations)
res = app.get(url_institution_registrations)
assert res.status_code == 200
registration_ids = [reg['id'] for reg in res.json['data']]
assert registration_no_affiliation._id not in registration_ids
assert registration_pending._id not in registration_ids
assert registration_no_owner._id not in registration_ids
assert registration_public._id in registration_ids
# Withdraw a registration, make sure it still shows up
WithdrawnRegistrationFactory(
registration=registration_public, user=admin)
# test getting registrations with auth (for embargoed and pending)
res = app.get(url_institution_registrations, auth=admin.auth)
assert res.status_code == 200
registration_ids = [reg['id'] for reg in res.json['data']]
assert registration_no_affiliation._id not in registration_ids
assert registration_pending._id in registration_ids
assert registration_public._id in registration_ids
assert registration_no_owner._id not in registration_ids
def test_add_incorrect_permissions(
self, app, admin, user, affiliated_user,
registration_no_affiliation,
url_institution_registrations,
institution
):
# No authentication
res = app.post_json_api(
url_institution_registrations,
make_registration_payload(registration_no_affiliation._id),
expect_errors=True,
)
assert res.status_code == 401
# User has no permission
res = app.post_json_api(
url_institution_registrations,
make_registration_payload(registration_no_affiliation._id),
expect_errors=True, auth=AuthUserFactory().auth
)
assert res.status_code == 403
# User has read permission
registration_no_affiliation.add_contributor(
affiliated_user, permissions=[permissions.READ])
registration_no_affiliation.save()
res = app.post_json_api(
url_institution_registrations,
make_registration_payload(registration_no_affiliation._id),
auth=user.auth, expect_errors=True
)
assert res.status_code == 403
# User is admin but not affiliated
registration = RegistrationFactory(creator=user)
res = app.post_json_api(
url_institution_registrations,
make_registration_payload(registration._id),
expect_errors=True, auth=user.auth
)
assert res.status_code == 403
registration.reload()
assert institution not in registration.affiliated_institutions.all()
# Registration does not exist
res = app.post_json_api(
url_institution_registrations,
make_registration_payload('notIdatAll'),
expect_errors=True, auth=admin.auth
)
assert res.status_code == 404
# Attempt to use endpoint on Node
res = app.post_json_api(
url_institution_registrations,
{'data': [{'type': 'nodes', 'id': NodeFactory(creator=admin)._id}]},
expect_errors=True, auth=admin.auth
)
assert res.status_code == 409
registration_no_affiliation.reload()
assert institution not in registration_no_affiliation.affiliated_institutions.all()
def test_add_some_with_permissions_others_without(
self, admin, app,
registration_no_affiliation,
registration_no_owner,
url_institution_registrations,
institution
):
res = app.post_json_api(
url_institution_registrations,
make_registration_payload(
registration_no_owner._id,
registration_no_affiliation._id),
expect_errors=True,
auth=admin.auth)
assert res.status_code == 403
registration_no_owner.reload()
registration_no_affiliation.reload()
assert institution not in registration_no_owner.affiliated_institutions.all()
assert institution not in registration_no_affiliation.affiliated_institutions.all()
def test_add_user_is_admin(
self, admin, app,
registration_no_affiliation,
url_institution_registrations,
institution
):
res = app.post_json_api(
url_institution_registrations,
make_registration_payload(registration_no_affiliation._id),
auth=admin.auth
)
assert res.status_code == 201
registration_no_affiliation.reload()
assert institution in registration_no_affiliation.affiliated_institutions.all()
def test_add_withdrawn_registration(
self, app, url_institution_registrations,
admin, registration_no_affiliation,
institution
):
WithdrawnRegistrationFactory(
registration=registration_no_affiliation, user=admin)
res = app.post_json_api(
url_institution_registrations,
make_registration_payload(registration_no_affiliation._id),
auth=admin.auth
)
assert res.status_code == 201
registration_no_affiliation.reload()
assert institution in registration_no_affiliation.affiliated_institutions.all()
def test_add_user_is_read_write(
self, app, affiliated_user,
registration_no_affiliation,
url_institution_registrations,
institution
):
registration_no_affiliation.add_contributor(affiliated_user)
registration_no_affiliation.save()
res = app.post_json_api(
url_institution_registrations,
make_registration_payload(registration_no_affiliation._id),
auth=affiliated_user.auth
)
assert res.status_code == 201
registration_no_affiliation.reload()
assert institution in registration_no_affiliation.affiliated_institutions.all()
def test_add_already_added(
self, admin, app,
registration_pending,
url_institution_registrations,
institution
):
res = app.post_json_api(
url_institution_registrations,
make_registration_payload(registration_pending._id),
auth=admin.auth
)
assert res.status_code == 204
registration_pending.reload()
assert institution in registration_pending.affiliated_institutions.all()
def test_delete_user_is_admin(
self, app,
url_institution_registrations,
registration_pending,
admin, institution
):
res = app.delete_json_api(
url_institution_registrations,
make_registration_payload(registration_pending._id),
auth=admin.auth
)
registration_pending.reload()
assert res.status_code == 204
assert institution not in registration_pending.affiliated_institutions.all()
def test_delete_user_is_read_write(
self, app, affiliated_user,
registration_pending,
url_institution_registrations,
institution
):
registration_pending.add_contributor(affiliated_user)
registration_pending.save()
res = app.delete_json_api(
url_institution_registrations,
make_registration_payload(registration_pending._id),
auth=affiliated_user.auth
)
registration_pending.reload()
assert res.status_code == 204
assert institution not in registration_pending.affiliated_institutions.all()
def test_delete_user_is_admin_but_not_affiliated_with_inst(
self, user, institution, app, url_institution_registrations):
registration = RegistrationFactory(creator=user)
registration.affiliated_institutions.add(institution)
registration.save()
assert institution in registration.affiliated_institutions.all()
res = app.delete_json_api(
url_institution_registrations,
make_registration_payload(registration._id),
auth=user.auth
)
assert res.status_code == 204
registration.reload()
assert institution not in registration.affiliated_institutions.all()
|
apache-2.0
|
[
646,
4613,
199,
199,
504,
2986,
14,
1095,
14,
1751,
14,
4322,
492,
3261,
63,
5825,
199,
504,
747,
70,
63,
2219,
14,
15406,
492,
334,
272,
8777,
5485,
78,
11757,
2927,
12,
272,
20764,
2927,
12,
272,
1010,
26575,
2927,
12,
272,
3590,
24594,
12,
272,
5013,
2927,
12,
199,
9,
199,
504,
747,
70,
14,
1208,
492,
3443,
421,
199,
318,
1852,
63,
4749,
2031,
932,
63,
1580,
304,
272,
666,
275,
359,
267,
791,
466,
356,
283,
2415,
297,
283,
344,
356,
1305,
63,
93,
367,
1305,
63,
315,
1031,
63,
1580,
272,
1622,
272,
372,
791,
576,
356,
666,
93,
421,
199,
318,
1852,
63,
8054,
63,
4749,
2031,
932,
63,
1580,
304,
272,
666,
275,
359,
267,
791,
466,
356,
283,
29440,
297,
283,
344,
356,
1305,
63,
93,
367,
1305,
63,
315,
1031,
63,
1580,
272,
1622,
272,
372,
791,
576,
356,
666,
93,
421,
199,
32,
4462,
14,
1657,
14,
1176,
63,
697,
199,
533,
1379,
607,
26575,
21096,
6300,
26,
339,
768,
4462,
14,
5997,
342,
272,
347,
2727,
28433,
8,
277,
304,
267,
372,
1010,
26575,
2927,
342,
339,
768,
4462,
14,
5997,
342,
272,
347,
1031,
8,
277,
304,
267,
372,
5013,
2927,
342,
339,
768,
4462,
14,
5997,
342,
272,
347,
922,
8,
277,
12,
2727,
28433,
304,
267,
922,
275,
3590,
24594,
342,
267,
922,
14,
27054,
317,
972,
63,
3615,
390,
8653,
14,
525,
8,
3615,
28433,
9,
267,
922,
14,
2117,
342,
267,
372,
922,
339,
768,
4462,
14,
5997,
342,
272,
347,
1031,
63,
368,
8,
277,
12,
922,
12,
2727,
28433,
304,
267,
1031,
275,
5013,
2927,
8,
9986,
29,
751,
9,
267,
1031,
14,
27054,
317,
972,
63,
3615,
390,
8653,
14,
525,
8,
3615,
28433,
9,
267,
1031,
14,
2117,
342,
267,
372,
1031,
339,
768,
4462,
14,
5997,
342,
272,
347,
1031,
63,
5601,
8,
277,
12,
922,
304,
267,
372,
5013,
2927,
8,
9986,
29,
751,
9,
339,
768,
4462,
14,
5997,
342,
272,
347,
1031,
63,
3455,
8,
277,
12,
922,
12,
2727,
28433,
304,
267,
1031,
63,
3455,
275,
5013,
2927,
8,
374,
63,
3455,
29,
549,
9,
267,
1031,
63,
3455,
14,
27054,
317,
972,
63,
3615,
390,
8653,
14,
525,
8,
3615,
28433,
9,
267,
1031,
63,
3455,
14,
2117,
342,
267,
372,
1031,
63,
3455,
339,
768,
4462,
14,
5997,
342,
272,
347,
1031,
63,
4239,
8,
277,
12,
922,
12,
2727,
28433,
304,
267,
1031,
63,
4239,
275,
5013,
2927,
342,
267,
1031,
63,
4239,
14,
27054,
317,
972,
63,
3615,
390,
8653,
14,
525,
8,
3615,
28433,
9,
267,
1031,
63,
4239,
14,
2117,
342,
267,
372,
1031,
63,
4239,
339,
768,
4462,
14,
5997,
342,
272,
347,
1166,
63,
3615,
28433,
63,
2415,
8,
277,
12,
2727,
28433,
304,
267,
372,
1994,
2440,
3615,
390,
8653,
19655,
24034,
15,
2415,
15,
1370,
908,
8,
288,
3261,
63,
5825,
12,
2727,
28433,
423,
344,
9,
339,
347,
511,
63,
1178,
63,
362,
63,
2415,
8,
288,
291,
12,
1145,
12,
922,
12,
1031,
63,
368,
12,
1031,
63,
3455,
12,
288,
1031,
63,
4239,
12,
1166,
63,
3615,
28433,
63,
2415,
272,
3461,
267,
327,
511,
63,
362,
63,
2415,
63,
889,
63,
1178,
267,
522,
275,
1145,
14,
362,
8,
633,
63,
3615,
28433,
63,
2415,
9,
398,
702,
522,
14,
1205,
63,
600,
508,
1926,
267,
1031,
63,
1580,
275,
359,
932,
32395,
344,
418,
367,
1031,
63,
315,
522,
14,
1001,
459,
576,
6538,
267,
702,
1031,
63,
368,
423,
344,
440,
315,
1031,
63,
1580,
267,
702,
1031,
63,
3455,
423,
344,
315,
1031,
63,
1580,
267,
702,
1031,
63,
4239,
423,
344,
440,
315,
1031,
63,
1580,
398,
327,
511,
63,
362,
63,
2415,
63,
1045,
63,
1178,
267,
522,
275,
1145,
14,
362,
8,
633,
63,
3615,
28433,
63,
2415,
12,
1790,
29,
751,
14,
1178,
9,
398,
702,
522,
14,
1205,
63,
600,
508,
1926,
267,
1031,
63,
1580,
275,
359,
932,
32395,
344,
418,
367,
1031,
63,
315,
522,
14,
1001,
459,
576,
6538,
267,
702,
1031,
63,
368,
423,
344,
315,
1031,
63,
1580,
267,
702,
1031,
63,
3455,
423,
344,
315,
1031,
63,
1580,
267,
702,
1031,
63,
4239,
423,
344,
440,
315,
1031,
63,
1580,
339,
347,
511,
63,
932,
63,
269,
63,
466,
63,
9105,
63,
1397,
63,
4494,
8,
288,
291,
12,
1145,
12,
922,
12,
1031,
63,
5601,
12,
1166,
63,
3615,
28433,
63,
2415,
304,
267,
327,
511,
63,
932,
63,
9105,
63,
1397,
63,
4494,
267,
522,
275,
1145,
14,
1932,
63,
1001,
63,
1246,
8,
288,
1166,
63,
3615,
28433,
63,
2415,
12,
288,
1852,
63,
4749,
360,
1397,
1304,
292,
2422,
659,
288,
4282,
63,
2550,
29,
549,
12,
1790,
29,
751,
14,
1178,
267,
776,
398,
702,
522,
14,
1205,
63,
600,
508,
7901,
398,
327,
511,
63,
932,
63,
466,
63,
9105,
63,
1397,
63,
4494,
267,
522,
275,
1145,
14,
1932,
63,
1001,
63,
1246,
8,
288,
1166,
63,
3615,
28433,
63,
2415,
12,
288,
791,
576,
356,
9016,
466,
356,
283,
68,
1518,
599,
79,
297,
283,
344,
356,
1031,
63,
5601,
423,
344,
11049,
1386,
288,
4282,
63,
2550,
29,
549,
12,
1790,
29,
751,
14,
1178,
267,
776,
398,
702,
522,
14,
1205,
63,
600,
508,
21292,
339,
347,
511,
63,
751,
63,
1045,
63,
2415,
63,
460,
63,
6060,
8,
288,
291,
12,
922,
12,
1145,
12,
1031,
63,
5601,
12,
288,
1166,
63,
3615,
28433,
63,
2415,
12,
2727,
28433,
272,
3461,
267,
522,
275,
1145,
14,
1932,
63,
1001,
63,
1246,
8,
288,
1166,
63,
3615,
28433,
63,
2415,
12,
288,
1852,
63,
4749,
8,
932,
63,
5601,
423,
344,
395,
288,
1790,
29,
751,
14,
1178,
267,
776,
398,
702,
522,
14,
1205,
63,
600,
508,
1784,
267,
1031,
63,
1580,
275,
359,
932,
32395,
344,
418,
367,
1031,
63,
315,
522,
14,
1001,
459,
576,
6538,
267,
702,
1031,
63,
5601,
423,
344,
315,
1031,
63,
1580,
398,
1031,
63,
5601,
14,
9233,
342,
267,
702,
2727,
28433,
315,
1031,
63,
5601,
14,
27054,
317,
972,
63,
3615
] |
[
4613,
199,
199,
504,
2986,
14,
1095,
14,
1751,
14,
4322,
492,
3261,
63,
5825,
199,
504,
747,
70,
63,
2219,
14,
15406,
492,
334,
272,
8777,
5485,
78,
11757,
2927,
12,
272,
20764,
2927,
12,
272,
1010,
26575,
2927,
12,
272,
3590,
24594,
12,
272,
5013,
2927,
12,
199,
9,
199,
504,
747,
70,
14,
1208,
492,
3443,
421,
199,
318,
1852,
63,
4749,
2031,
932,
63,
1580,
304,
272,
666,
275,
359,
267,
791,
466,
356,
283,
2415,
297,
283,
344,
356,
1305,
63,
93,
367,
1305,
63,
315,
1031,
63,
1580,
272,
1622,
272,
372,
791,
576,
356,
666,
93,
421,
199,
318,
1852,
63,
8054,
63,
4749,
2031,
932,
63,
1580,
304,
272,
666,
275,
359,
267,
791,
466,
356,
283,
29440,
297,
283,
344,
356,
1305,
63,
93,
367,
1305,
63,
315,
1031,
63,
1580,
272,
1622,
272,
372,
791,
576,
356,
666,
93,
421,
199,
32,
4462,
14,
1657,
14,
1176,
63,
697,
199,
533,
1379,
607,
26575,
21096,
6300,
26,
339,
768,
4462,
14,
5997,
342,
272,
347,
2727,
28433,
8,
277,
304,
267,
372,
1010,
26575,
2927,
342,
339,
768,
4462,
14,
5997,
342,
272,
347,
1031,
8,
277,
304,
267,
372,
5013,
2927,
342,
339,
768,
4462,
14,
5997,
342,
272,
347,
922,
8,
277,
12,
2727,
28433,
304,
267,
922,
275,
3590,
24594,
342,
267,
922,
14,
27054,
317,
972,
63,
3615,
390,
8653,
14,
525,
8,
3615,
28433,
9,
267,
922,
14,
2117,
342,
267,
372,
922,
339,
768,
4462,
14,
5997,
342,
272,
347,
1031,
63,
368,
8,
277,
12,
922,
12,
2727,
28433,
304,
267,
1031,
275,
5013,
2927,
8,
9986,
29,
751,
9,
267,
1031,
14,
27054,
317,
972,
63,
3615,
390,
8653,
14,
525,
8,
3615,
28433,
9,
267,
1031,
14,
2117,
342,
267,
372,
1031,
339,
768,
4462,
14,
5997,
342,
272,
347,
1031,
63,
5601,
8,
277,
12,
922,
304,
267,
372,
5013,
2927,
8,
9986,
29,
751,
9,
339,
768,
4462,
14,
5997,
342,
272,
347,
1031,
63,
3455,
8,
277,
12,
922,
12,
2727,
28433,
304,
267,
1031,
63,
3455,
275,
5013,
2927,
8,
374,
63,
3455,
29,
549,
9,
267,
1031,
63,
3455,
14,
27054,
317,
972,
63,
3615,
390,
8653,
14,
525,
8,
3615,
28433,
9,
267,
1031,
63,
3455,
14,
2117,
342,
267,
372,
1031,
63,
3455,
339,
768,
4462,
14,
5997,
342,
272,
347,
1031,
63,
4239,
8,
277,
12,
922,
12,
2727,
28433,
304,
267,
1031,
63,
4239,
275,
5013,
2927,
342,
267,
1031,
63,
4239,
14,
27054,
317,
972,
63,
3615,
390,
8653,
14,
525,
8,
3615,
28433,
9,
267,
1031,
63,
4239,
14,
2117,
342,
267,
372,
1031,
63,
4239,
339,
768,
4462,
14,
5997,
342,
272,
347,
1166,
63,
3615,
28433,
63,
2415,
8,
277,
12,
2727,
28433,
304,
267,
372,
1994,
2440,
3615,
390,
8653,
19655,
24034,
15,
2415,
15,
1370,
908,
8,
288,
3261,
63,
5825,
12,
2727,
28433,
423,
344,
9,
339,
347,
511,
63,
1178,
63,
362,
63,
2415,
8,
288,
291,
12,
1145,
12,
922,
12,
1031,
63,
368,
12,
1031,
63,
3455,
12,
288,
1031,
63,
4239,
12,
1166,
63,
3615,
28433,
63,
2415,
272,
3461,
267,
327,
511,
63,
362,
63,
2415,
63,
889,
63,
1178,
267,
522,
275,
1145,
14,
362,
8,
633,
63,
3615,
28433,
63,
2415,
9,
398,
702,
522,
14,
1205,
63,
600,
508,
1926,
267,
1031,
63,
1580,
275,
359,
932,
32395,
344,
418,
367,
1031,
63,
315,
522,
14,
1001,
459,
576,
6538,
267,
702,
1031,
63,
368,
423,
344,
440,
315,
1031,
63,
1580,
267,
702,
1031,
63,
3455,
423,
344,
315,
1031,
63,
1580,
267,
702,
1031,
63,
4239,
423,
344,
440,
315,
1031,
63,
1580,
398,
327,
511,
63,
362,
63,
2415,
63,
1045,
63,
1178,
267,
522,
275,
1145,
14,
362,
8,
633,
63,
3615,
28433,
63,
2415,
12,
1790,
29,
751,
14,
1178,
9,
398,
702,
522,
14,
1205,
63,
600,
508,
1926,
267,
1031,
63,
1580,
275,
359,
932,
32395,
344,
418,
367,
1031,
63,
315,
522,
14,
1001,
459,
576,
6538,
267,
702,
1031,
63,
368,
423,
344,
315,
1031,
63,
1580,
267,
702,
1031,
63,
3455,
423,
344,
315,
1031,
63,
1580,
267,
702,
1031,
63,
4239,
423,
344,
440,
315,
1031,
63,
1580,
339,
347,
511,
63,
932,
63,
269,
63,
466,
63,
9105,
63,
1397,
63,
4494,
8,
288,
291,
12,
1145,
12,
922,
12,
1031,
63,
5601,
12,
1166,
63,
3615,
28433,
63,
2415,
304,
267,
327,
511,
63,
932,
63,
9105,
63,
1397,
63,
4494,
267,
522,
275,
1145,
14,
1932,
63,
1001,
63,
1246,
8,
288,
1166,
63,
3615,
28433,
63,
2415,
12,
288,
1852,
63,
4749,
360,
1397,
1304,
292,
2422,
659,
288,
4282,
63,
2550,
29,
549,
12,
1790,
29,
751,
14,
1178,
267,
776,
398,
702,
522,
14,
1205,
63,
600,
508,
7901,
398,
327,
511,
63,
932,
63,
466,
63,
9105,
63,
1397,
63,
4494,
267,
522,
275,
1145,
14,
1932,
63,
1001,
63,
1246,
8,
288,
1166,
63,
3615,
28433,
63,
2415,
12,
288,
791,
576,
356,
9016,
466,
356,
283,
68,
1518,
599,
79,
297,
283,
344,
356,
1031,
63,
5601,
423,
344,
11049,
1386,
288,
4282,
63,
2550,
29,
549,
12,
1790,
29,
751,
14,
1178,
267,
776,
398,
702,
522,
14,
1205,
63,
600,
508,
21292,
339,
347,
511,
63,
751,
63,
1045,
63,
2415,
63,
460,
63,
6060,
8,
288,
291,
12,
922,
12,
1145,
12,
1031,
63,
5601,
12,
288,
1166,
63,
3615,
28433,
63,
2415,
12,
2727,
28433,
272,
3461,
267,
522,
275,
1145,
14,
1932,
63,
1001,
63,
1246,
8,
288,
1166,
63,
3615,
28433,
63,
2415,
12,
288,
1852,
63,
4749,
8,
932,
63,
5601,
423,
344,
395,
288,
1790,
29,
751,
14,
1178,
267,
776,
398,
702,
522,
14,
1205,
63,
600,
508,
1784,
267,
1031,
63,
1580,
275,
359,
932,
32395,
344,
418,
367,
1031,
63,
315,
522,
14,
1001,
459,
576,
6538,
267,
702,
1031,
63,
5601,
423,
344,
315,
1031,
63,
1580,
398,
1031,
63,
5601,
14,
9233,
342,
267,
702,
2727,
28433,
315,
1031,
63,
5601,
14,
27054,
317,
972,
63,
3615,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
marma/rdflib
|
examples/smushing.py
|
8
|
1532
|
"""
A FOAF smushing example.
Filter a graph by normalizing all ``foaf:Persons`` into URIs based on
their ``mbox_sha1sum``.
Suppose I got two `FOAF <http://xmlns.com/foaf/0.1>`_ documents each
talking about the same person (according to ``mbox_sha1sum``) but they
each used a :class:`rdflib.term.BNode` for the subject. For this demo
I've combined those two documents into one file:
This filters a graph by changing every subject with a
``foaf:mbox_sha1sum`` into a new subject whose URI is based on the
``sha1sum``. This new graph might be easier to do some operations on.
An advantage of this approach over other methods for collapsing BNodes
is that I can incrementally process new FOAF documents as they come in
without having to access my ever-growing archive. Even if another
``65b983bb397fb71849da910996741752ace8369b`` document comes in next
year, I would still give it the same stable subject URI that merges
with my existing data.
"""
from rdflib import Graph, Namespace
from rdflib.namespace import FOAF
STABLE = Namespace("http://example.com/person/mbox_sha1sum/")
if __name__=='__main__':
g = Graph()
g.parse("smushingdemo.n3", format="n3")
newURI = {} # old subject : stable uri
for s,p,o in g.triples((None, FOAF['mbox_sha1sum'], None)):
newURI[s] = STABLE[o]
out = Graph()
out.bind('foaf', FOAF)
for s,p,o in g:
s = newURI.get(s, s)
o = newURI.get(o, o) # might be linked to another person
out.add((s,p,o))
print out.serialize(format="n3")
|
bsd-3-clause
|
[
624,
199,
33,
481,
47,
5699,
4383,
2084,
316,
2893,
14,
199,
199,
4131,
282,
3343,
701,
3293,
9147,
1006,
1124,
545,
2756,
26,
7344,
83,
1040,
1901,
30143,
4079,
641,
199,
1589,
723,
1124,
27201,
63,
4835,
17,
1838,
4345,
199,
199,
4710,
4070,
473,
4788,
2877,
658,
3230,
5699,
665,
1014,
921,
13991,
14,
957,
15,
545,
2756,
15,
16,
14,
17,
18740,
8247,
1924,
199,
21890,
316,
3595,
314,
2011,
4954,
334,
645,
5422,
370,
1124,
27201,
63,
4835,
17,
1838,
16580,
1325,
2985,
199,
10885,
1202,
282,
520,
533,
1705,
17120,
773,
14,
5125,
14,
34,
1716,
64,
367,
314,
5420,
14,
2104,
642,
14779,
199,
41,
9064,
12149,
5204,
2877,
8247,
1901,
1373,
570,
26,
199,
199,
2765,
4766,
282,
3343,
701,
13729,
4036,
5420,
543,
282,
199,
1040,
545,
2756,
26,
27201,
63,
4835,
17,
1838,
1040,
1901,
282,
892,
5420,
7447,
9022,
365,
4079,
641,
314,
199,
1040,
4835,
17,
1838,
4345,
961,
892,
3343,
5594,
506,
14905,
370,
886,
2005,
5331,
641,
14,
199,
199,
2493,
30268,
402,
642,
18140,
1806,
1163,
3102,
367,
1048,
4762,
1044,
699,
6300,
199,
374,
626,
473,
883,
11609,
1183,
2112,
892,
481,
47,
5699,
8247,
465,
2985,
11492,
315,
199,
7395,
9445,
370,
2879,
3002,
14433,
13,
22890,
316,
6359,
14,
22207,
340,
4573,
199,
1040,
2182,
66,
25,
2658,
2501,
13145,
4675,
26948,
1887,
983,
25,
709,
1020,
10393,
1196,
2528,
7984,
24,
11939,
66,
1040,
2213,
12477,
315,
2163,
199,
3403,
12,
473,
3955,
5139,
8120,
652,
314,
2011,
17830,
5420,
9022,
626,
32716,
199,
1045,
3002,
3411,
666,
14,
199,
199,
624,
199,
199,
504,
18148,
773,
492,
11513,
12,
19317,
199,
504,
18148,
773,
14,
3251,
492,
481,
47,
5699,
199,
199,
840,
2617,
275,
19317,
480,
1014,
921,
2694,
14,
957,
15,
5484,
15,
27201,
63,
4835,
17,
1838,
13589,
199,
199,
692,
636,
354,
363,
6803,
363,
973,
3706,
272,
486,
275,
11513,
342,
272,
486,
14,
1122,
480,
3300,
2084,
316,
8768,
14,
78,
19,
401,
1475,
628,
78,
19,
531,
339,
892,
7639,
275,
1052,
327,
2269,
5420,
520,
17830,
5108,
272,
367,
308,
12,
80,
12,
79,
315,
486,
14,
7254,
2978,
1332,
403,
12,
481,
47,
5699,
459,
27201,
63,
4835,
17,
1838,
995,
488,
2298,
267,
892,
7639,
59,
83,
61,
275,
4384,
2617,
59,
79,
61,
2378,
734,
275,
11513,
342,
272,
734,
14,
3409,
360,
545,
2756,
297,
481,
47,
5699,
9,
339,
367,
308,
12,
80,
12,
79,
315,
486,
26,
267,
308,
275,
892,
7639,
14,
362,
8,
83,
12,
308,
9,
267,
312,
275,
892,
7639,
14,
362,
8,
79,
12,
312,
9,
327,
5594,
506,
10632,
370,
4573,
4954,
267,
734,
14,
525,
1332,
83,
12,
80,
12,
79,
430,
339,
870,
734,
14,
3549,
8,
908,
628,
78,
19,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
33,
481,
47,
5699,
4383,
2084,
316,
2893,
14,
199,
199,
4131,
282,
3343,
701,
3293,
9147,
1006,
1124,
545,
2756,
26,
7344,
83,
1040,
1901,
30143,
4079,
641,
199,
1589,
723,
1124,
27201,
63,
4835,
17,
1838,
4345,
199,
199,
4710,
4070,
473,
4788,
2877,
658,
3230,
5699,
665,
1014,
921,
13991,
14,
957,
15,
545,
2756,
15,
16,
14,
17,
18740,
8247,
1924,
199,
21890,
316,
3595,
314,
2011,
4954,
334,
645,
5422,
370,
1124,
27201,
63,
4835,
17,
1838,
16580,
1325,
2985,
199,
10885,
1202,
282,
520,
533,
1705,
17120,
773,
14,
5125,
14,
34,
1716,
64,
367,
314,
5420,
14,
2104,
642,
14779,
199,
41,
9064,
12149,
5204,
2877,
8247,
1901,
1373,
570,
26,
199,
199,
2765,
4766,
282,
3343,
701,
13729,
4036,
5420,
543,
282,
199,
1040,
545,
2756,
26,
27201,
63,
4835,
17,
1838,
1040,
1901,
282,
892,
5420,
7447,
9022,
365,
4079,
641,
314,
199,
1040,
4835,
17,
1838,
4345,
961,
892,
3343,
5594,
506,
14905,
370,
886,
2005,
5331,
641,
14,
199,
199,
2493,
30268,
402,
642,
18140,
1806,
1163,
3102,
367,
1048,
4762,
1044,
699,
6300,
199,
374,
626,
473,
883,
11609,
1183,
2112,
892,
481,
47,
5699,
8247,
465,
2985,
11492,
315,
199,
7395,
9445,
370,
2879,
3002,
14433,
13,
22890,
316,
6359,
14,
22207,
340,
4573,
199,
1040,
2182,
66,
25,
2658,
2501,
13145,
4675,
26948,
1887,
983,
25,
709,
1020,
10393,
1196,
2528,
7984,
24,
11939,
66,
1040,
2213,
12477,
315,
2163,
199,
3403,
12,
473,
3955,
5139,
8120,
652,
314,
2011,
17830,
5420,
9022,
626,
32716,
199,
1045,
3002,
3411,
666,
14,
199,
199,
624,
199,
199,
504,
18148,
773,
492,
11513,
12,
19317,
199,
504,
18148,
773,
14,
3251,
492,
481,
47,
5699,
199,
199,
840,
2617,
275,
19317,
480,
1014,
921,
2694,
14,
957,
15,
5484,
15,
27201,
63,
4835,
17,
1838,
13589,
199,
199,
692,
636,
354,
363,
6803,
363,
973,
3706,
272,
486,
275,
11513,
342,
272,
486,
14,
1122,
480,
3300,
2084,
316,
8768,
14,
78,
19,
401,
1475,
628,
78,
19,
531,
339,
892,
7639,
275,
1052,
327,
2269,
5420,
520,
17830,
5108,
272,
367,
308,
12,
80,
12,
79,
315,
486,
14,
7254,
2978,
1332,
403,
12,
481,
47,
5699,
459,
27201,
63,
4835,
17,
1838,
995,
488,
2298,
267,
892,
7639,
59,
83,
61,
275,
4384,
2617,
59,
79,
61,
2378,
734,
275,
11513,
342,
272,
734,
14,
3409,
360,
545,
2756,
297,
481,
47,
5699,
9,
339,
367,
308,
12,
80,
12,
79,
315,
486,
26,
267,
308,
275,
892,
7639,
14,
362,
8,
83,
12,
308,
9,
267,
312,
275,
892,
7639,
14,
362,
8,
79,
12,
312,
9,
327,
5594,
506,
10632,
370,
4573,
4954,
267,
734,
14,
525,
1332,
83,
12,
80,
12,
79,
430,
339,
870,
734,
14,
3549,
8,
908,
628,
78,
19,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
steebchen/youtube-dl
|
youtube_dl/extractor/bandcamp.py
|
15
|
12472
|
from __future__ import unicode_literals
import json
import random
import re
import time
from .common import InfoExtractor
from ..compat import (
compat_str,
compat_urlparse,
)
from ..utils import (
ExtractorError,
float_or_none,
int_or_none,
KNOWN_EXTENSIONS,
parse_filesize,
unescapeHTML,
update_url_query,
unified_strdate,
)
class BandcampIE(InfoExtractor):
_VALID_URL = r'https?://.*?\.bandcamp\.com/track/(?P<title>[^/?#&]+)'
_TESTS = [{
'url': 'http://youtube-dl.bandcamp.com/track/youtube-dl-test-song',
'md5': 'c557841d5e50261777a6585648adf439',
'info_dict': {
'id': '1812978515',
'ext': 'mp3',
'title': "youtube-dl \"'/\\\u00e4\u21ad - youtube-dl test song \"'/\\\u00e4\u21ad",
'duration': 9.8485,
},
'_skip': 'There is a limit of 200 free downloads / month for the test song'
}, {
'url': 'http://benprunty.bandcamp.com/track/lanius-battle',
'md5': '0369ace6b939f0927e62c67a1a8d9fa7',
'info_dict': {
'id': '2650410135',
'ext': 'aiff',
'title': 'Ben Prunty - Lanius (Battle)',
'uploader': 'Ben Prunty',
},
}]
def _real_extract(self, url):
mobj = re.match(self._VALID_URL, url)
title = mobj.group('title')
webpage = self._download_webpage(url, title)
thumbnail = self._html_search_meta('og:image', webpage, default=None)
m_download = re.search(r'freeDownloadPage: "(.*?)"', webpage)
if not m_download:
m_trackinfo = re.search(r'trackinfo: (.+),\s*?\n', webpage)
if m_trackinfo:
json_code = m_trackinfo.group(1)
data = json.loads(json_code)[0]
track_id = compat_str(data['id'])
if not data.get('file'):
raise ExtractorError('Not streamable', video_id=track_id, expected=True)
formats = []
for format_id, format_url in data['file'].items():
ext, abr_str = format_id.split('-', 1)
formats.append({
'format_id': format_id,
'url': self._proto_relative_url(format_url, 'http:'),
'ext': ext,
'vcodec': 'none',
'acodec': ext,
'abr': int_or_none(abr_str),
})
self._sort_formats(formats)
return {
'id': track_id,
'title': data['title'],
'thumbnail': thumbnail,
'formats': formats,
'duration': float_or_none(data.get('duration')),
}
else:
raise ExtractorError('No free songs found')
download_link = m_download.group(1)
video_id = self._search_regex(
r'(?ms)var TralbumData = .*?[{,]\s*id: (?P<id>\d+),?$',
webpage, 'video id')
download_webpage = self._download_webpage(
download_link, video_id, 'Downloading free downloads page')
blob = self._parse_json(
self._search_regex(
r'data-blob=(["\'])(?P<blob>{.+?})\1', download_webpage,
'blob', group='blob'),
video_id, transform_source=unescapeHTML)
info = blob['digital_items'][0]
downloads = info['downloads']
track = info['title']
artist = info.get('artist')
title = '%s - %s' % (artist, track) if artist else track
download_formats = {}
for f in blob['download_formats']:
name, ext = f.get('name'), f.get('file_extension')
if all(isinstance(x, compat_str) for x in (name, ext)):
download_formats[name] = ext.strip('.')
formats = []
for format_id, f in downloads.items():
format_url = f.get('url')
if not format_url:
continue
# Stat URL generation algorithm is reverse engineered from
# download_*_bundle_*.js
stat_url = update_url_query(
format_url.replace('/download/', '/statdownload/'), {
'.rand': int(time.time() * 1000 * random.random()),
})
format_id = f.get('encoding_name') or format_id
stat = self._download_json(
stat_url, video_id, 'Downloading %s JSON' % format_id,
transform_source=lambda s: s[s.index('{'):s.rindex('}') + 1],
fatal=False)
if not stat:
continue
retry_url = stat.get('retry_url')
if not isinstance(retry_url, compat_str):
continue
formats.append({
'url': self._proto_relative_url(retry_url, 'http:'),
'ext': download_formats.get(format_id),
'format_id': format_id,
'format_note': f.get('description'),
'filesize': parse_filesize(f.get('size_mb')),
'vcodec': 'none',
})
self._sort_formats(formats)
return {
'id': video_id,
'title': title,
'thumbnail': info.get('thumb_url') or thumbnail,
'uploader': info.get('artist'),
'artist': artist,
'track': track,
'formats': formats,
}
class BandcampAlbumIE(InfoExtractor):
IE_NAME = 'Bandcamp:album'
_VALID_URL = r'https?://(?:(?P<subdomain>[^.]+)\.)?bandcamp\.com(?:/album/(?P<album_id>[^/?#&]+))?'
_TESTS = [{
'url': 'http://blazo.bandcamp.com/album/jazz-format-mixtape-vol-1',
'playlist': [
{
'md5': '39bc1eded3476e927c724321ddf116cf',
'info_dict': {
'id': '1353101989',
'ext': 'mp3',
'title': 'Intro',
}
},
{
'md5': '1a2c32e2691474643e912cc6cd4bffaa',
'info_dict': {
'id': '38097443',
'ext': 'mp3',
'title': 'Kero One - Keep It Alive (Blazo remix)',
}
},
],
'info_dict': {
'title': 'Jazz Format Mixtape vol.1',
'id': 'jazz-format-mixtape-vol-1',
'uploader_id': 'blazo',
},
'params': {
'playlistend': 2
},
'skip': 'Bandcamp imposes download limits.'
}, {
'url': 'http://nightbringer.bandcamp.com/album/hierophany-of-the-open-grave',
'info_dict': {
'title': 'Hierophany of the Open Grave',
'uploader_id': 'nightbringer',
'id': 'hierophany-of-the-open-grave',
},
'playlist_mincount': 9,
}, {
'url': 'http://dotscale.bandcamp.com',
'info_dict': {
'title': 'Loom',
'id': 'dotscale',
'uploader_id': 'dotscale',
},
'playlist_mincount': 7,
}, {
# with escaped quote in title
'url': 'https://jstrecords.bandcamp.com/album/entropy-ep',
'info_dict': {
'title': '"Entropy" EP',
'uploader_id': 'jstrecords',
'id': 'entropy-ep',
},
'playlist_mincount': 3,
}, {
# not all tracks have songs
'url': 'https://insulters.bandcamp.com/album/we-are-the-plague',
'info_dict': {
'id': 'we-are-the-plague',
'title': 'WE ARE THE PLAGUE',
'uploader_id': 'insulters',
},
'playlist_count': 2,
}]
@classmethod
def suitable(cls, url):
return (False
if BandcampWeeklyIE.suitable(url) or BandcampIE.suitable(url)
else super(BandcampAlbumIE, cls).suitable(url))
def _real_extract(self, url):
mobj = re.match(self._VALID_URL, url)
uploader_id = mobj.group('subdomain')
album_id = mobj.group('album_id')
playlist_id = album_id or uploader_id
webpage = self._download_webpage(url, playlist_id)
track_elements = re.findall(
r'(?s)<div[^>]*>(.*?<a[^>]+href="([^"]+?)"[^>]+itemprop="url"[^>]*>.*?)</div>', webpage)
if not track_elements:
raise ExtractorError('The page doesn\'t contain any tracks')
# Only tracks with duration info have songs
entries = [
self.url_result(
compat_urlparse.urljoin(url, t_path),
ie=BandcampIE.ie_key(),
video_title=self._search_regex(
r'<span\b[^>]+\bitemprop=["\']name["\'][^>]*>([^<]+)',
elem_content, 'track title', fatal=False))
for elem_content, t_path in track_elements
if self._html_search_meta('duration', elem_content, default=None)]
title = self._html_search_regex(
r'album_title\s*:\s*"((?:\\.|[^"\\])+?)"',
webpage, 'title', fatal=False)
if title:
title = title.replace(r'\"', '"')
return {
'_type': 'playlist',
'uploader_id': uploader_id,
'id': playlist_id,
'title': title,
'entries': entries,
}
class BandcampWeeklyIE(InfoExtractor):
IE_NAME = 'Bandcamp:weekly'
_VALID_URL = r'https?://(?:www\.)?bandcamp\.com/?\?(?:.*?&)?show=(?P<id>\d+)'
_TESTS = [{
'url': 'https://bandcamp.com/?show=224',
'md5': 'b00df799c733cf7e0c567ed187dea0fd',
'info_dict': {
'id': '224',
'ext': 'opus',
'title': 'BC Weekly April 4th 2017 - Magic Moments',
'description': 'md5:5d48150916e8e02d030623a48512c874',
'duration': 5829.77,
'release_date': '20170404',
'series': 'Bandcamp Weekly',
'episode': 'Magic Moments',
'episode_number': 208,
'episode_id': '224',
}
}, {
'url': 'https://bandcamp.com/?blah/blah@&show=228',
'only_matching': True
}]
def _real_extract(self, url):
video_id = self._match_id(url)
webpage = self._download_webpage(url, video_id)
blob = self._parse_json(
self._search_regex(
r'data-blob=(["\'])(?P<blob>{.+?})\1', webpage,
'blob', group='blob'),
video_id, transform_source=unescapeHTML)
show = blob['bcw_show']
# This is desired because any invalid show id redirects to `bandcamp.com`
# which happens to expose the latest Bandcamp Weekly episode.
show_id = int_or_none(show.get('show_id')) or int_or_none(video_id)
formats = []
for format_id, format_url in show['audio_stream'].items():
if not isinstance(format_url, compat_str):
continue
for known_ext in KNOWN_EXTENSIONS:
if known_ext in format_id:
ext = known_ext
break
else:
ext = None
formats.append({
'format_id': format_id,
'url': format_url,
'ext': ext,
'vcodec': 'none',
})
self._sort_formats(formats)
title = show.get('audio_title') or 'Bandcamp Weekly'
subtitle = show.get('subtitle')
if subtitle:
title += ' - %s' % subtitle
episode_number = None
seq = blob.get('bcw_seq')
if seq and isinstance(seq, list):
try:
episode_number = next(
int_or_none(e.get('episode_number'))
for e in seq
if isinstance(e, dict) and int_or_none(e.get('id')) == show_id)
except StopIteration:
pass
return {
'id': video_id,
'title': title,
'description': show.get('desc') or show.get('short_desc'),
'duration': float_or_none(show.get('audio_duration')),
'is_live': False,
'release_date': unified_strdate(show.get('published_date')),
'series': 'Bandcamp Weekly',
'episode': show.get('subtitle'),
'episode_number': episode_number,
'episode_id': compat_str(video_id),
'formats': formats
}
|
unlicense
|
[
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
2022,
199,
646,
2196,
199,
646,
295,
199,
646,
900,
199,
199,
504,
1275,
2330,
492,
21298,
199,
504,
2508,
5819,
492,
334,
272,
8434,
63,
495,
12,
272,
8434,
63,
10290,
12,
199,
9,
199,
504,
2508,
1208,
492,
334,
272,
19783,
12,
272,
2069,
63,
269,
63,
3592,
12,
272,
1109,
63,
269,
63,
3592,
12,
272,
1804,
9165,
63,
18451,
12,
272,
2198,
63,
19233,
12,
272,
22221,
4943,
12,
272,
1678,
63,
633,
63,
1131,
12,
272,
25344,
63,
495,
602,
12,
199,
9,
421,
199,
533,
27709,
20290,
4332,
8,
18283,
304,
272,
485,
5600,
63,
2632,
275,
519,
7,
2859,
14144,
6697,
4537,
7877,
20290,
4537,
957,
15,
3885,
9448,
48,
28,
1213,
13489,
10197,
3,
6,
29716,
272,
485,
7569,
275,
8910,
267,
283,
633,
356,
283,
1014,
921,
9788,
13,
5030,
14,
7877,
20290,
14,
957,
15,
3885,
15,
9788,
13,
5030,
13,
396,
13,
19351,
297,
267,
283,
1064,
21,
356,
283,
67,
18725,
19211,
68,
21,
69,
24653,
2976,
11956,
65,
22,
15959,
10552,
24642,
28429,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
1085,
7263,
19312,
1046,
297,
288,
283,
832,
356,
283,
311,
19,
297,
288,
283,
1213,
356,
298,
9788,
13,
5030,
221,
971,
4507,
15,
9780,
85,
383,
69,
20,
60,
85,
2025,
350,
446,
22378,
13,
5030,
511,
20178,
971,
4507,
15,
9780,
85,
383,
69,
20,
60,
85,
2025,
350,
401,
288,
283,
5553,
356,
1749,
14,
1349,
2426,
12,
267,
1660,
267,
2513,
2759,
356,
283,
10924,
365,
282,
2304,
402,
1926,
2867,
28242,
1182,
5794,
367,
314,
511,
20178,
7,
272,
1660,
469,
267,
283,
633,
356,
283,
1014,
921,
18486,
28461,
369,
14,
7877,
20290,
14,
957,
15,
3885,
15,
1502,
73,
527,
13,
29787,
297,
267,
283,
1064,
21,
356,
283,
16,
11939,
7984,
22,
66,
31281,
70,
1643,
1465,
69,
2789,
67,
1822,
65,
17,
65,
24,
68,
25,
667,
23,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
13730,
966,
4893,
1276,
297,
288,
283,
832,
356,
283,
5789,
556,
297,
288,
283,
1213,
356,
283,
31231,
510,
1065,
369,
446,
491,
26455,
527,
334,
34,
29274,
3196,
288,
283,
13671,
356,
283,
31231,
510,
1065,
369,
297,
267,
1660,
272,
14877,
339,
347,
485,
3093,
63,
5005,
8,
277,
12,
1166,
304,
267,
14208,
275,
295,
14,
1431,
8,
277,
423,
5600,
63,
2632,
12,
1166,
9,
267,
2538,
275,
14208,
14,
923,
360,
1213,
358,
267,
9248,
275,
291,
423,
4249,
63,
12022,
8,
633,
12,
2538,
9,
267,
10062,
275,
291,
423,
1360,
63,
1733,
63,
2024,
360,
974,
26,
1569,
297,
9248,
12,
849,
29,
403,
9,
267,
333,
63,
4249,
275,
295,
14,
1733,
8,
82,
7,
4624,
11950,
3276,
26,
7340,
6697,
32691,
9248,
9,
267,
340,
440,
333,
63,
4249,
26,
288,
333,
63,
3885,
815,
275,
295,
14,
1733,
8,
82,
1133,
8085,
815,
26,
334,
6977,
26323,
83,
10,
8995,
78,
297,
9248,
9,
288,
340,
333,
63,
3885,
815,
26,
355,
2022,
63,
600,
275,
333,
63,
3885,
815,
14,
923,
8,
17,
9,
355,
666,
275,
2022,
14,
3640,
8,
1001,
63,
600,
2788,
16,
61,
355,
4426,
63,
344,
275,
8434,
63,
495,
8,
576,
459,
344,
1105,
2234,
340,
440,
666,
14,
362,
360,
493,
735,
490,
746,
19783,
360,
1763,
2547,
461,
297,
3991,
63,
344,
29,
3885,
63,
344,
12,
1420,
29,
549,
9,
2234,
6752,
275,
942,
355,
367,
1475,
63,
344,
12,
1475,
63,
633,
315,
666,
459,
493,
2278,
1744,
837,
490,
1599,
12,
2236,
82,
63,
495,
275,
1475,
63,
344,
14,
1294,
13858,
413,
9,
490,
6752,
14,
740,
2561,
717,
283,
908,
63,
344,
356,
1475,
63,
344,
12,
717,
283,
633,
356,
291,
423,
2625,
63,
6188,
63,
633,
8,
908,
63,
633,
12,
283,
1014,
26,
659,
717,
283,
832,
356,
1599,
12,
717,
283,
86,
9276,
356,
283,
3592,
297,
717,
283,
65,
9276,
356,
1599,
12,
717,
283,
371,
82,
356,
1109,
63,
269,
63,
3592,
8,
371,
82,
63,
495,
395,
490,
3828,
2234,
291,
423,
3191,
63,
6321,
8,
6321,
9,
2234,
372,
469,
490,
283,
344,
356,
4426,
63,
344,
12,
490,
283,
1213,
356,
666,
459,
1213,
995,
490,
283,
8311,
356,
10062,
12,
490,
283,
6321,
356,
6752,
12,
490,
283,
5553,
356,
2069,
63,
269,
63,
3592,
8,
576,
14,
362,
360,
5553,
3855,
355,
789,
288,
587,
26,
355,
746,
19783,
360,
1944,
2867,
308,
12358,
1911,
358,
398,
5235,
63,
1073,
275,
333,
63,
4249,
14,
923,
8,
17,
9,
267,
3991,
63,
344,
275,
291,
423,
1733,
63,
3821,
8,
288,
519,
10120,
706,
9,
1391,
28814,
12110,
1451,
275,
1275,
15279,
59,
91,
12,
7272,
83,
10,
344,
26,
7558,
48,
28,
344,
3072,
68,
11,
395,
31,
4268,
288,
9248,
12,
283,
3722,
1305,
358,
398,
5235,
63,
12022,
275,
291,
423,
4249,
63,
12022,
8,
288,
5235,
63,
1073,
12,
3991,
63,
344,
12,
283,
18085,
2867,
28242,
2034,
358,
398,
9182,
275,
291,
423,
1122,
63,
1001,
8,
288,
291,
423,
1733,
63,
3821,
8,
355,
519,
5121,
419,
13,
6582,
30982,
3212,
1105,
2229,
48,
28,
6582,
22266,
11198,
30446,
17,
297,
5235,
63,
12022,
12,
355,
283,
6582,
297,
1572,
534,
6582,
659,
288,
3991,
63,
344,
12,
5793,
63,
1365,
29,
22726,
4943,
9,
398,
2256,
275,
9182,
459,
25888,
63,
1744,
3488,
16,
61,
398,
28242,
275,
2256,
459,
20373,
418,
267,
4426,
275,
2256,
459,
1213,
418,
398,
16459,
275,
2256,
14,
362,
360,
11215,
358,
267,
2538,
275,
1543,
83,
446,
450,
83,
7,
450,
334,
11215,
12,
4426,
9,
340,
16459,
587,
4426,
398,
5235,
63,
6321,
275,
1052,
267,
367,
289,
315,
9182,
459,
4249,
63,
6321,
2565,
288,
536,
12,
1599,
275,
289,
14,
362,
360,
354,
659,
289,
14,
362,
360,
493,
63,
3435,
358,
288,
340,
1006,
8,
6074,
8,
88,
12,
8434,
63,
495,
9,
367,
671,
315,
334,
354,
12
] |
[
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
2022,
199,
646,
2196,
199,
646,
295,
199,
646,
900,
199,
199,
504,
1275,
2330,
492,
21298,
199,
504,
2508,
5819,
492,
334,
272,
8434,
63,
495,
12,
272,
8434,
63,
10290,
12,
199,
9,
199,
504,
2508,
1208,
492,
334,
272,
19783,
12,
272,
2069,
63,
269,
63,
3592,
12,
272,
1109,
63,
269,
63,
3592,
12,
272,
1804,
9165,
63,
18451,
12,
272,
2198,
63,
19233,
12,
272,
22221,
4943,
12,
272,
1678,
63,
633,
63,
1131,
12,
272,
25344,
63,
495,
602,
12,
199,
9,
421,
199,
533,
27709,
20290,
4332,
8,
18283,
304,
272,
485,
5600,
63,
2632,
275,
519,
7,
2859,
14144,
6697,
4537,
7877,
20290,
4537,
957,
15,
3885,
9448,
48,
28,
1213,
13489,
10197,
3,
6,
29716,
272,
485,
7569,
275,
8910,
267,
283,
633,
356,
283,
1014,
921,
9788,
13,
5030,
14,
7877,
20290,
14,
957,
15,
3885,
15,
9788,
13,
5030,
13,
396,
13,
19351,
297,
267,
283,
1064,
21,
356,
283,
67,
18725,
19211,
68,
21,
69,
24653,
2976,
11956,
65,
22,
15959,
10552,
24642,
28429,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
1085,
7263,
19312,
1046,
297,
288,
283,
832,
356,
283,
311,
19,
297,
288,
283,
1213,
356,
298,
9788,
13,
5030,
221,
971,
4507,
15,
9780,
85,
383,
69,
20,
60,
85,
2025,
350,
446,
22378,
13,
5030,
511,
20178,
971,
4507,
15,
9780,
85,
383,
69,
20,
60,
85,
2025,
350,
401,
288,
283,
5553,
356,
1749,
14,
1349,
2426,
12,
267,
1660,
267,
2513,
2759,
356,
283,
10924,
365,
282,
2304,
402,
1926,
2867,
28242,
1182,
5794,
367,
314,
511,
20178,
7,
272,
1660,
469,
267,
283,
633,
356,
283,
1014,
921,
18486,
28461,
369,
14,
7877,
20290,
14,
957,
15,
3885,
15,
1502,
73,
527,
13,
29787,
297,
267,
283,
1064,
21,
356,
283,
16,
11939,
7984,
22,
66,
31281,
70,
1643,
1465,
69,
2789,
67,
1822,
65,
17,
65,
24,
68,
25,
667,
23,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
13730,
966,
4893,
1276,
297,
288,
283,
832,
356,
283,
5789,
556,
297,
288,
283,
1213,
356,
283,
31231,
510,
1065,
369,
446,
491,
26455,
527,
334,
34,
29274,
3196,
288,
283,
13671,
356,
283,
31231,
510,
1065,
369,
297,
267,
1660,
272,
14877,
339,
347,
485,
3093,
63,
5005,
8,
277,
12,
1166,
304,
267,
14208,
275,
295,
14,
1431,
8,
277,
423,
5600,
63,
2632,
12,
1166,
9,
267,
2538,
275,
14208,
14,
923,
360,
1213,
358,
267,
9248,
275,
291,
423,
4249,
63,
12022,
8,
633,
12,
2538,
9,
267,
10062,
275,
291,
423,
1360,
63,
1733,
63,
2024,
360,
974,
26,
1569,
297,
9248,
12,
849,
29,
403,
9,
267,
333,
63,
4249,
275,
295,
14,
1733,
8,
82,
7,
4624,
11950,
3276,
26,
7340,
6697,
32691,
9248,
9,
267,
340,
440,
333,
63,
4249,
26,
288,
333,
63,
3885,
815,
275,
295,
14,
1733,
8,
82,
1133,
8085,
815,
26,
334,
6977,
26323,
83,
10,
8995,
78,
297,
9248,
9,
288,
340,
333,
63,
3885,
815,
26,
355,
2022,
63,
600,
275,
333,
63,
3885,
815,
14,
923,
8,
17,
9,
355,
666,
275,
2022,
14,
3640,
8,
1001,
63,
600,
2788,
16,
61,
355,
4426,
63,
344,
275,
8434,
63,
495,
8,
576,
459,
344,
1105,
2234,
340,
440,
666,
14,
362,
360,
493,
735,
490,
746,
19783,
360,
1763,
2547,
461,
297,
3991,
63,
344,
29,
3885,
63,
344,
12,
1420,
29,
549,
9,
2234,
6752,
275,
942,
355,
367,
1475,
63,
344,
12,
1475,
63,
633,
315,
666,
459,
493,
2278,
1744,
837,
490,
1599,
12,
2236,
82,
63,
495,
275,
1475,
63,
344,
14,
1294,
13858,
413,
9,
490,
6752,
14,
740,
2561,
717,
283,
908,
63,
344,
356,
1475,
63,
344,
12,
717,
283,
633,
356,
291,
423,
2625,
63,
6188,
63,
633,
8,
908,
63,
633,
12,
283,
1014,
26,
659,
717,
283,
832,
356,
1599,
12,
717,
283,
86,
9276,
356,
283,
3592,
297,
717,
283,
65,
9276,
356,
1599,
12,
717,
283,
371,
82,
356,
1109,
63,
269,
63,
3592,
8,
371,
82,
63,
495,
395,
490,
3828,
2234,
291,
423,
3191,
63,
6321,
8,
6321,
9,
2234,
372,
469,
490,
283,
344,
356,
4426,
63,
344,
12,
490,
283,
1213,
356,
666,
459,
1213,
995,
490,
283,
8311,
356,
10062,
12,
490,
283,
6321,
356,
6752,
12,
490,
283,
5553,
356,
2069,
63,
269,
63,
3592,
8,
576,
14,
362,
360,
5553,
3855,
355,
789,
288,
587,
26,
355,
746,
19783,
360,
1944,
2867,
308,
12358,
1911,
358,
398,
5235,
63,
1073,
275,
333,
63,
4249,
14,
923,
8,
17,
9,
267,
3991,
63,
344,
275,
291,
423,
1733,
63,
3821,
8,
288,
519,
10120,
706,
9,
1391,
28814,
12110,
1451,
275,
1275,
15279,
59,
91,
12,
7272,
83,
10,
344,
26,
7558,
48,
28,
344,
3072,
68,
11,
395,
31,
4268,
288,
9248,
12,
283,
3722,
1305,
358,
398,
5235,
63,
12022,
275,
291,
423,
4249,
63,
12022,
8,
288,
5235,
63,
1073,
12,
3991,
63,
344,
12,
283,
18085,
2867,
28242,
2034,
358,
398,
9182,
275,
291,
423,
1122,
63,
1001,
8,
288,
291,
423,
1733,
63,
3821,
8,
355,
519,
5121,
419,
13,
6582,
30982,
3212,
1105,
2229,
48,
28,
6582,
22266,
11198,
30446,
17,
297,
5235,
63,
12022,
12,
355,
283,
6582,
297,
1572,
534,
6582,
659,
288,
3991,
63,
344,
12,
5793,
63,
1365,
29,
22726,
4943,
9,
398,
2256,
275,
9182,
459,
25888,
63,
1744,
3488,
16,
61,
398,
28242,
275,
2256,
459,
20373,
418,
267,
4426,
275,
2256,
459,
1213,
418,
398,
16459,
275,
2256,
14,
362,
360,
11215,
358,
267,
2538,
275,
1543,
83,
446,
450,
83,
7,
450,
334,
11215,
12,
4426,
9,
340,
16459,
587,
4426,
398,
5235,
63,
6321,
275,
1052,
267,
367,
289,
315,
9182,
459,
4249,
63,
6321,
2565,
288,
536,
12,
1599,
275,
289,
14,
362,
360,
354,
659,
289,
14,
362,
360,
493,
63,
3435,
358,
288,
340,
1006,
8,
6074,
8,
88,
12,
8434,
63,
495,
9,
367,
671,
315,
334,
354,
12,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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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
] |
Bachaco-ve/odoo
|
addons/website/models/test_models.py
|
335
|
1386
|
# -*- coding: utf-8 -*-
from openerp.osv import orm, fields
class test_converter(orm.Model):
_name = 'website.converter.test'
# disable translation export for those brilliant field labels and values
_translate = False
_columns = {
'char': fields.char(),
'integer': fields.integer(),
'float': fields.float(),
'numeric': fields.float(digits=(16, 2)),
'many2one': fields.many2one('website.converter.test.sub'),
'binary': fields.binary(),
'date': fields.date(),
'datetime': fields.datetime(),
'selection': fields.selection([
(1, "réponse A"),
(2, "réponse B"),
(3, "réponse C"),
(4, "réponse D"),
]),
'selection_str': fields.selection([
('A', "Qu'il n'est pas arrivé à Toronto"),
('B', "Qu'il était supposé arriver à Toronto"),
('C', "Qu'est-ce qu'il fout ce maudit pancake, tabernacle ?"),
('D', "La réponse D"),
], string=u"Lorsqu'un pancake prend l'avion à destination de Toronto et "
u"qu'il fait une escale technique à St Claude, on dit:"),
'html': fields.html(),
'text': fields.text(),
}
class test_converter_sub(orm.Model):
_name = 'website.converter.test.sub'
_columns = {
'name': fields.char(),
}
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
5166,
14,
4795,
492,
9813,
12,
1504,
199,
199,
533,
511,
63,
11256,
8,
1025,
14,
1685,
304,
272,
485,
354,
275,
283,
7360,
14,
11256,
14,
396,
7,
339,
327,
3507,
7761,
4843,
367,
5204,
330,
10363,
22676,
901,
3628,
436,
1338,
272,
485,
5275,
275,
756,
339,
485,
3406,
275,
469,
267,
283,
1560,
356,
1504,
14,
1560,
1062,
267,
283,
4115,
356,
1504,
14,
4115,
1062,
267,
283,
1609,
356,
1504,
14,
1609,
1062,
267,
283,
6677,
356,
1504,
14,
1609,
8,
7022,
2687,
975,
12,
499,
1826,
267,
283,
3479,
18,
368,
356,
1504,
14,
3479,
18,
368,
360,
7360,
14,
11256,
14,
396,
14,
954,
659,
267,
283,
3008,
356,
1504,
14,
3008,
1062,
267,
283,
602,
356,
1504,
14,
602,
1062,
267,
283,
2083,
356,
1504,
14,
2083,
1062,
267,
283,
5592,
356,
1504,
14,
5592,
779,
288,
334,
17,
12,
298,
82,
5741,
732,
437,
1288,
288,
334,
18,
12,
298,
82,
5741,
732,
699,
1288,
288,
334,
19,
12,
298,
82,
5741,
732,
445,
1288,
288,
334,
20,
12,
298,
82,
5741,
732,
577,
1288,
267,
17318,
267,
283,
5592,
63,
495,
356,
1504,
14,
5592,
779,
288,
661,
33,
297,
298,
2371,
7,
382,
302,
7,
597,
19099,
601,
322,
86,
5741,
26031,
29659,
26296,
1288,
288,
661,
34,
297,
298,
2371,
7,
382,
26785,
502,
390,
1029,
1712,
5741,
601,
2046,
26031,
29659,
26296,
1288,
288,
661,
35,
297,
298,
2371,
7,
597,
13,
301,
2173,
7,
382,
17863,
10142,
610,
85,
1741,
21379,
696,
415,
12,
5174,
27569,
12550,
5805,
1288,
288,
661,
36,
297,
298,
7833,
519,
5741,
732,
577,
1288,
267,
2156,
1059,
29,
85,
2,
44,
1384,
392,
7,
324,
21379,
696,
415,
299,
16479,
634,
7,
7194,
265,
26031,
5724,
477,
29659,
26296,
10844,
298,
2116,
399,
2,
392,
7,
382,
1433,
390,
625,
69,
325,
3467,
32414,
26031,
1933,
24433,
3786,
12,
641,
487,
84,
26,
1288,
267,
283,
1360,
356,
1504,
14,
1360,
1062,
267,
283,
505,
356,
1504,
14,
505,
1062,
272,
789,
421,
199,
533,
511,
63,
11256,
63,
954,
8,
1025,
14,
1685,
304,
272,
485,
354,
275,
283,
7360,
14,
11256,
14,
396,
14,
954,
7,
339,
485,
3406,
275,
469,
267,
283,
354,
356,
1504,
14,
1560,
1062,
272,
789,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
5166,
14,
4795,
492,
9813,
12,
1504,
199,
199,
533,
511,
63,
11256,
8,
1025,
14,
1685,
304,
272,
485,
354,
275,
283,
7360,
14,
11256,
14,
396,
7,
339,
327,
3507,
7761,
4843,
367,
5204,
330,
10363,
22676,
901,
3628,
436,
1338,
272,
485,
5275,
275,
756,
339,
485,
3406,
275,
469,
267,
283,
1560,
356,
1504,
14,
1560,
1062,
267,
283,
4115,
356,
1504,
14,
4115,
1062,
267,
283,
1609,
356,
1504,
14,
1609,
1062,
267,
283,
6677,
356,
1504,
14,
1609,
8,
7022,
2687,
975,
12,
499,
1826,
267,
283,
3479,
18,
368,
356,
1504,
14,
3479,
18,
368,
360,
7360,
14,
11256,
14,
396,
14,
954,
659,
267,
283,
3008,
356,
1504,
14,
3008,
1062,
267,
283,
602,
356,
1504,
14,
602,
1062,
267,
283,
2083,
356,
1504,
14,
2083,
1062,
267,
283,
5592,
356,
1504,
14,
5592,
779,
288,
334,
17,
12,
298,
82,
5741,
732,
437,
1288,
288,
334,
18,
12,
298,
82,
5741,
732,
699,
1288,
288,
334,
19,
12,
298,
82,
5741,
732,
445,
1288,
288,
334,
20,
12,
298,
82,
5741,
732,
577,
1288,
267,
17318,
267,
283,
5592,
63,
495,
356,
1504,
14,
5592,
779,
288,
661,
33,
297,
298,
2371,
7,
382,
302,
7,
597,
19099,
601,
322,
86,
5741,
26031,
29659,
26296,
1288,
288,
661,
34,
297,
298,
2371,
7,
382,
26785,
502,
390,
1029,
1712,
5741,
601,
2046,
26031,
29659,
26296,
1288,
288,
661,
35,
297,
298,
2371,
7,
597,
13,
301,
2173,
7,
382,
17863,
10142,
610,
85,
1741,
21379,
696,
415,
12,
5174,
27569,
12550,
5805,
1288,
288,
661,
36,
297,
298,
7833,
519,
5741,
732,
577,
1288,
267,
2156,
1059,
29,
85,
2,
44,
1384,
392,
7,
324,
21379,
696,
415,
299,
16479,
634,
7,
7194,
265,
26031,
5724,
477,
29659,
26296,
10844,
298,
2116,
399,
2,
392,
7,
382,
1433,
390,
625,
69,
325,
3467,
32414,
26031,
1933,
24433,
3786,
12,
641,
487,
84,
26,
1288,
267,
283,
1360,
356,
1504,
14,
1360,
1062,
267,
283,
505,
356,
1504,
14,
505,
1062,
272,
789,
421,
199,
533,
511,
63,
11256,
63,
954,
8,
1025,
14,
1685,
304,
272,
485,
354,
275,
283,
7360,
14,
11256,
14,
396,
14,
954,
7,
339,
485,
3406,
275,
469,
267,
283,
354,
356,
1504,
14,
1560,
1062,
272,
789,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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